SlideShare a Scribd company logo
1 of 15
Database Systems: Design,
Implementation, and
Management
Eighth Edition
Chapter 11
Database Performance Tuning and
Query Optimization
Database Systems, 8th Edition 2
Objectives
• In this chapter, you will learn:
– Basic database performance-tuning concepts
– How a DBMS processes SQL queries
– About the importance of indexes in query processing
– About the types of decisions the query optimizer has
to make
– Some common practices used to write efficient SQL
code
– How to formulate queries and tune the DBMS for
optimal performance
– Performance tuning in SQL Server 2005
Database Systems, 8th Edition 3
11.1 Database Performance-Tuning Concepts
• Goal of database performance is to execute
queries as fast as possible
• Database performance tuning
– Set of activities and procedures designed to
reduce response time of database system
• All factors must operate at optimum level with
minimal bottlenecks
• Good database performance starts with
good database design
Database Systems, 8th Edition 4
Database Systems, 8th Edition 5
Performance Tuning: Client and Server
• Client side
– Generate SQL query that returns correct answer
in least amount of time
• Using minimum amount of resources at server
– SQL performance tuning
• Server side
– DBMS environment configured to respond to
clients’ requests as fast as possible
• Optimum use of existing resources
– DBMS performance tuning
Database Systems, 8th Edition 6
DBMS Architecture
• All data in database are stored in data files
• Data files
– Automatically expand in predefined increments
known as extends
– Grouped in file groups or table spaces
• Table space or file group:
– Logical grouping of several data files that store
data with similar characteristics
Database Systems, 8th Edition 7
Basic DBMS architecture
Database Systems, 8th Edition 8
DBMS Architecture (continued)
• Data cache or buffer cache: shared, reserved
memory area
– Stores most recently accessed data blocks in RAM
• SQL cache or procedure cache: stores most
recently executed SQL statements
– Also PL/SQL procedures, including triggers and
functions
• DBMS retrieves data from permanent storage and
places it in RAM
Database Systems, 8th Edition 9
DBMS Architecture (continued)
• Input/output request: low-level data access
operation to/from computer devices, such as
memory, hard disks, videos, and printers
• Data cache is faster than data in data files
– DBMS does not wait for hard disk to retrieve data
• Majority of performance-tuning activities focus on
minimizing I/O operations
• Typical DBMS processes:
– Listener, User, Scheduler, Lock manager, Optimizer
Database Systems, 8th Edition 10
Database Statistics
• Measurements about database objects and available
resources
– Tables, Indexes, Number of processors used,
Processor speed, Temporary space available
• Make critical decisions about improving query
processing efficiency
• Can be gathered manually by DBA or automatically by
DBMS
– UPDATE STATISTICS table_name [index_name]
– Auto-Update and Auto-Create Statistics option
• 資料庫屬性-> 自動更新統計資料
• 資料庫屬性-> 自動建立統計資料
Database Systems, 8th Edition 11
Database Systems, 8th Edition 12
Ch08: dbcc show_statistics (customer,
PK__CUSTOMER__24927208 )
Ch08: dbcc show_statistics (customer, CUS_UI1)
補充SQL Server 2005
Database Systems, 8th Edition 13
11.2 Query Processing
• DBMS processes queries in three phases
– Parsing
• DBMS parses the query and chooses the most
efficient access/execution plan
– Execution
• DBMS executes the query using chosen
execution plan
– Fetching
• DBMS fetches the data and sends the result back
to the client
Database Systems, 8th Edition 14
Query Processing
Database Systems, 8th Edition 15
SQL Parsing Phase
• Break down query into smaller units
• Transform original SQL query into slightly
different version of original SQL code
– Fully equivalent
• Optimized query results are always the same as
original query
– More efficient
• Optimized query will almost always execute faster
than original query
Database Systems, 8th Edition 16
SQL Parsing Phase (continued)
• Query optimizer analyzes SQL query and finds most
efficient way to access data
– Validated for syntax compliance
– Validated against data dictionary
• Tables, column names are correct
• User has proper access rights
– Analyzed and decomposed into more atomic components
– Optimized through transforming into a fully equivalent but
more efficient SQL query
– Prepared for execution by determining the execution or
access plan
Database Systems, 8th Edition 17
SQL Parsing Phase (continued)
• Access plans are DBMS-specific
– Translate client’s SQL query into series of
complex I/O operations
– Required to read the data from the physical data
files and generate result set
• DBMS checks if access plan already exists for
query in SQL cache
• DBMS reuses the access plan to save time
• If not, optimizer evaluates various plans
– Chosen plan placed in SQL cache
Database Systems, 8th Edition 18
Database Systems, 8th Edition 19
SQL Execution and Fetching Phase
• All I/O operations indicated in access plan are
executed
– Locks acquired
– Data retrieved and placed in data cache
– Transaction management commands processed
• Rows of resulting query result set are returned to
client
• DBMS may use temporary table space to store
temporary data
– The server may send only the first 100 rows of 9000 rows
Database Systems, 8th Edition 20
Query Processing Bottlenecks
• Delay introduced in the processing of an I/O
operation that slows the system
– CPU
– RAM
– Hard disk
– Network
– Application code
Database Systems, 8th Edition 21
SQL 敘述
輸入完成
後先不要
執行查
詢, 請按
下工具列
的顯示估
計執行計
劃鈕
:
Database Systems, 8th Edition 22
11.3 Indexes and Query Optimization
• Indexes
– Crucial in speeding up data access
– Facilitate searching, sorting, and using
aggregate functions as well as join operations
– Ordered set of values that contains index key
and pointers
• More efficient to use index to access table than
to scan all rows in table sequentially
Database Systems, 8th Edition 23
Indexes and Query Optimization
• Data sparsity: number of different values a column
could possibly have
• Indexes implemented using: ( 課本p. 453)
– Hash indexes
– B-tree indexes: most common index type. Used in tables in
which column values repeat a small number of times. The
leaves contain pointers to records It is self-balanced.
– Bitmap indexes: 0/1
• DBMSs determine best type of index to use
– Ex: CUST_LNAME with B-tree and REGION_CODE with
Bitmap indexes
Database Systems, 8th Edition 24B-tree and bitmap index
representation
25
Index Representation for the
CUSTOMER table
SELECT CUS_NAME
FROM CUSTOMER
WHERE CUS_STATE=‘FL’
Requires only 5 accesses to STATE_INDEX,
5 accesses to CUSTOMER
Database Systems, 8th Edition 26
11.4 Optimizer Choices
• Rule-based optimizer
– Preset rules and points
– Rules assign a fixed cost to each operation
• Cost-based optimizer
– Algorithms based on statistics about objects
being accessed
– Adds up processing cost, I/O costs, resource
costs to derive total cost
Example
Database Systems, 8th Edition 27
SELECT P_CODE, P_DESCRIPT, P_PRICE, V_NAME,
V_STATE
FROM PRODUCT P, VENDOR V
WHERE P.V_CODE=V.V_CODE
AND V.V_STATE=‘FL’;
• With the following database statistics:
– The PRODUCT table has 7000 rows
– The VENDOR table has 300 rows
– 10 vendors come from Florida
– 1000 products come from vendors in Florida
Database Systems, 8th Edition 28
Example
Database Systems, 8th Edition 29
• Assume the PRODUCT table has the index
PQOH_NDX in the P_QOH attribute
SELECT MIN(P_QOH) FROM PRODUCT
could be resolved by reading only the first entry in
the PQOH_NDX index
Database Systems, 8th Edition 30
Using Hints to Affect Optimizer Choices
• Optimizer might not choose best plan
• Makes decisions based on existing statistics
– Statistics may be old
– Might choose less efficient decisions
• Optimizer hints: special instructions for the
optimizer embedded in the SQL command text
Database Systems, 8th Edition 31
Oracle 版本
Database Systems, 8th Edition 32
MS SQL Server 的語法請參考:
http://msdn.microsoft.com/en-us/library/ms187713.aspx
SQL Server Query Hints Example
select o.customerid,companyname
from orders as o inner MERGE join customers as c
on o.customerid = c.customerid
select o.customerid,companyname
from orders as o inner HASH join customers as c
on o.customerid = c.customerid
select o.customerid,companyname
from orders as o inner LOOP join customers as c
on o.customerid = c.customerid
select city, count(*)
from customers
group by city
OPTION (HASH GROUP)
Database Systems: Design, Implementation, and Management
Eighth EditionObjectives11.1 Database Performance-Tuning
ConceptsPowerPoint PresentationPerformance Tuning: Client
and ServerDBMS ArchitectureSlide 7DBMS Architecture
(continued)Slide 9Database StatisticsSlide 11Slide 1211.2
Query ProcessingSlide 14SQL Parsing PhaseSQL Parsing Phase
(continued)Slide 17Slide 18SQL Execution and Fetching
PhaseQuery Processing BottlenecksSlide 2111.3 Indexes and
Query OptimizationIndexes and Query OptimizationSlide
24Slide 2511.4 Optimizer ChoicesExampleSlide 28Slide
29Using Hints to Affect Optimizer ChoicesSlide 31Slide 32
Database Systems Design, Implementation, and Management

More Related Content

Similar to Database Systems Design, Implementation, and Management

Optimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureOptimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureDAGEOP LTD
 
Database_Design.ppt
Database_Design.pptDatabase_Design.ppt
Database_Design.pptNadiSarj2
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsZohar Elkayam
 
How should I monitor my idaa
How should I monitor my idaaHow should I monitor my idaa
How should I monitor my idaaCuneyt Goksu
 
Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Lucas Jellema
 
Optimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxOptimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxJasonTuran2
 
Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introductionadryanbub
 
Best storage engine for MySQL
Best storage engine for MySQLBest storage engine for MySQL
Best storage engine for MySQLtomflemingh2
 
MySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMahesh Salaria
 
071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephenSteve Feldman
 
Dynamics ax performance tuning
Dynamics ax performance tuningDynamics ax performance tuning
Dynamics ax performance tuningOutsourceAX
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptxKareemBullard1
 
Best Practices – Extreme Performance with Data Warehousing on Oracle Databa...
Best Practices –  Extreme Performance with Data Warehousing  on Oracle Databa...Best Practices –  Extreme Performance with Data Warehousing  on Oracle Databa...
Best Practices – Extreme Performance with Data Warehousing on Oracle Databa...Edgar Alejandro Villegas
 
Database administration and security
Database administration and securityDatabase administration and security
Database administration and securityDhani Ahmad
 

Similar to Database Systems Design, Implementation, and Management (20)

Database design
Database designDatabase design
Database design
 
Optimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureOptimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser Architecture
 
Database_Design.ppt
Database_Design.pptDatabase_Design.ppt
Database_Design.ppt
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
 
How should I monitor my idaa
How should I monitor my idaaHow should I monitor my idaa
How should I monitor my idaa
 
Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)
 
Optimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxOptimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptx
 
Breaking data
Breaking dataBreaking data
Breaking data
 
Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introduction
 
Best storage engine for MySQL
Best storage engine for MySQLBest storage engine for MySQL
Best storage engine for MySQL
 
MySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMySQL: Know more about open Source Database
MySQL: Know more about open Source Database
 
071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen
 
Dynamics ax performance tuning
Dynamics ax performance tuningDynamics ax performance tuning
Dynamics ax performance tuning
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx
 
Oracle DBA
Oracle DBAOracle DBA
Oracle DBA
 
Unit 2 oracle9i
Unit 2  oracle9i Unit 2  oracle9i
Unit 2 oracle9i
 
Best Practices – Extreme Performance with Data Warehousing on Oracle Databa...
Best Practices –  Extreme Performance with Data Warehousing  on Oracle Databa...Best Practices –  Extreme Performance with Data Warehousing  on Oracle Databa...
Best Practices – Extreme Performance with Data Warehousing on Oracle Databa...
 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
 
Database administration and security
Database administration and securityDatabase administration and security
Database administration and security
 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
 

More from OllieShoresna

this assignment is about Mesopotamia and Egypt. Some of these cu.docx
this assignment is about Mesopotamia and Egypt. Some of these cu.docxthis assignment is about Mesopotamia and Egypt. Some of these cu.docx
this assignment is about Mesopotamia and Egypt. Some of these cu.docxOllieShoresna
 
This assignment has two goals 1) have students increase their under.docx
This assignment has two goals 1) have students increase their under.docxThis assignment has two goals 1) have students increase their under.docx
This assignment has two goals 1) have students increase their under.docxOllieShoresna
 
This assignment has two parts 1 paragraph per questionIn wh.docx
This assignment has two parts 1 paragraph per questionIn wh.docxThis assignment has two parts 1 paragraph per questionIn wh.docx
This assignment has two parts 1 paragraph per questionIn wh.docxOllieShoresna
 
This assignment is a minimum of 100 word all parts of each querstion.docx
This assignment is a minimum of 100 word all parts of each querstion.docxThis assignment is a minimum of 100 word all parts of each querstion.docx
This assignment is a minimum of 100 word all parts of each querstion.docxOllieShoresna
 
This assignment has three elements a traditional combination format.docx
This assignment has three elements a traditional combination format.docxThis assignment has three elements a traditional combination format.docx
This assignment has three elements a traditional combination format.docxOllieShoresna
 
This assignment has four partsWhat changes in business software p.docx
This assignment has four partsWhat changes in business software p.docxThis assignment has four partsWhat changes in business software p.docx
This assignment has four partsWhat changes in business software p.docxOllieShoresna
 
This assignment consists of two partsthe core evaluation, a.docx
This assignment consists of two partsthe core evaluation, a.docxThis assignment consists of two partsthe core evaluation, a.docx
This assignment consists of two partsthe core evaluation, a.docxOllieShoresna
 
This assignment asks you to analyze a significant textual elemen.docx
This assignment asks you to analyze a significant textual elemen.docxThis assignment asks you to analyze a significant textual elemen.docx
This assignment asks you to analyze a significant textual elemen.docxOllieShoresna
 
This assignment allows you to learn more about one key person in Jew.docx
This assignment allows you to learn more about one key person in Jew.docxThis assignment allows you to learn more about one key person in Jew.docx
This assignment allows you to learn more about one key person in Jew.docxOllieShoresna
 
This assignment allows you to explore the effects of social influe.docx
This assignment allows you to explore the effects of social influe.docxThis assignment allows you to explore the effects of social influe.docx
This assignment allows you to explore the effects of social influe.docxOllieShoresna
 
This assignment addresses pretrial procedures that occur prior to th.docx
This assignment addresses pretrial procedures that occur prior to th.docxThis assignment addresses pretrial procedures that occur prior to th.docx
This assignment addresses pretrial procedures that occur prior to th.docxOllieShoresna
 
This assignment allows you to learn more about one key person in J.docx
This assignment allows you to learn more about one key person in J.docxThis assignment allows you to learn more about one key person in J.docx
This assignment allows you to learn more about one key person in J.docxOllieShoresna
 
This assignment allows you to explore the effects of social infl.docx
This assignment allows you to explore the effects of social infl.docxThis assignment allows you to explore the effects of social infl.docx
This assignment allows you to explore the effects of social infl.docxOllieShoresna
 
this about communication please i eant you answer this question.docx
this about communication please i eant you answer this question.docxthis about communication please i eant you answer this question.docx
this about communication please i eant you answer this question.docxOllieShoresna
 
Think of a time when a company did not process an order or perform a.docx
Think of a time when a company did not process an order or perform a.docxThink of a time when a company did not process an order or perform a.docx
Think of a time when a company did not process an order or perform a.docxOllieShoresna
 
Think_Vision W5- Importance of VaccinationImportance of Vaccinatio.docx
Think_Vision W5- Importance of VaccinationImportance of Vaccinatio.docxThink_Vision W5- Importance of VaccinationImportance of Vaccinatio.docx
Think_Vision W5- Importance of VaccinationImportance of Vaccinatio.docxOllieShoresna
 
Thinks for both only 50 words as much for each one1-xxxxd, unf.docx
Thinks for both only 50 words as much for each one1-xxxxd, unf.docxThinks for both only 50 words as much for each one1-xxxxd, unf.docx
Thinks for both only 50 words as much for each one1-xxxxd, unf.docxOllieShoresna
 
Think of a specific change you would like to bring to your organizat.docx
Think of a specific change you would like to bring to your organizat.docxThink of a specific change you would like to bring to your organizat.docx
Think of a specific change you would like to bring to your organizat.docxOllieShoresna
 
Think of a possible change initiative in your selected organization..docx
Think of a possible change initiative in your selected organization..docxThink of a possible change initiative in your selected organization..docx
Think of a possible change initiative in your selected organization..docxOllieShoresna
 
Thinking About Research PaperConsider the research question and .docx
Thinking About Research PaperConsider the research question and .docxThinking About Research PaperConsider the research question and .docx
Thinking About Research PaperConsider the research question and .docxOllieShoresna
 

More from OllieShoresna (20)

this assignment is about Mesopotamia and Egypt. Some of these cu.docx
this assignment is about Mesopotamia and Egypt. Some of these cu.docxthis assignment is about Mesopotamia and Egypt. Some of these cu.docx
this assignment is about Mesopotamia and Egypt. Some of these cu.docx
 
This assignment has two goals 1) have students increase their under.docx
This assignment has two goals 1) have students increase their under.docxThis assignment has two goals 1) have students increase their under.docx
This assignment has two goals 1) have students increase their under.docx
 
This assignment has two parts 1 paragraph per questionIn wh.docx
This assignment has two parts 1 paragraph per questionIn wh.docxThis assignment has two parts 1 paragraph per questionIn wh.docx
This assignment has two parts 1 paragraph per questionIn wh.docx
 
This assignment is a minimum of 100 word all parts of each querstion.docx
This assignment is a minimum of 100 word all parts of each querstion.docxThis assignment is a minimum of 100 word all parts of each querstion.docx
This assignment is a minimum of 100 word all parts of each querstion.docx
 
This assignment has three elements a traditional combination format.docx
This assignment has three elements a traditional combination format.docxThis assignment has three elements a traditional combination format.docx
This assignment has three elements a traditional combination format.docx
 
This assignment has four partsWhat changes in business software p.docx
This assignment has four partsWhat changes in business software p.docxThis assignment has four partsWhat changes in business software p.docx
This assignment has four partsWhat changes in business software p.docx
 
This assignment consists of two partsthe core evaluation, a.docx
This assignment consists of two partsthe core evaluation, a.docxThis assignment consists of two partsthe core evaluation, a.docx
This assignment consists of two partsthe core evaluation, a.docx
 
This assignment asks you to analyze a significant textual elemen.docx
This assignment asks you to analyze a significant textual elemen.docxThis assignment asks you to analyze a significant textual elemen.docx
This assignment asks you to analyze a significant textual elemen.docx
 
This assignment allows you to learn more about one key person in Jew.docx
This assignment allows you to learn more about one key person in Jew.docxThis assignment allows you to learn more about one key person in Jew.docx
This assignment allows you to learn more about one key person in Jew.docx
 
This assignment allows you to explore the effects of social influe.docx
This assignment allows you to explore the effects of social influe.docxThis assignment allows you to explore the effects of social influe.docx
This assignment allows you to explore the effects of social influe.docx
 
This assignment addresses pretrial procedures that occur prior to th.docx
This assignment addresses pretrial procedures that occur prior to th.docxThis assignment addresses pretrial procedures that occur prior to th.docx
This assignment addresses pretrial procedures that occur prior to th.docx
 
This assignment allows you to learn more about one key person in J.docx
This assignment allows you to learn more about one key person in J.docxThis assignment allows you to learn more about one key person in J.docx
This assignment allows you to learn more about one key person in J.docx
 
This assignment allows you to explore the effects of social infl.docx
This assignment allows you to explore the effects of social infl.docxThis assignment allows you to explore the effects of social infl.docx
This assignment allows you to explore the effects of social infl.docx
 
this about communication please i eant you answer this question.docx
this about communication please i eant you answer this question.docxthis about communication please i eant you answer this question.docx
this about communication please i eant you answer this question.docx
 
Think of a time when a company did not process an order or perform a.docx
Think of a time when a company did not process an order or perform a.docxThink of a time when a company did not process an order or perform a.docx
Think of a time when a company did not process an order or perform a.docx
 
Think_Vision W5- Importance of VaccinationImportance of Vaccinatio.docx
Think_Vision W5- Importance of VaccinationImportance of Vaccinatio.docxThink_Vision W5- Importance of VaccinationImportance of Vaccinatio.docx
Think_Vision W5- Importance of VaccinationImportance of Vaccinatio.docx
 
Thinks for both only 50 words as much for each one1-xxxxd, unf.docx
Thinks for both only 50 words as much for each one1-xxxxd, unf.docxThinks for both only 50 words as much for each one1-xxxxd, unf.docx
Thinks for both only 50 words as much for each one1-xxxxd, unf.docx
 
Think of a specific change you would like to bring to your organizat.docx
Think of a specific change you would like to bring to your organizat.docxThink of a specific change you would like to bring to your organizat.docx
Think of a specific change you would like to bring to your organizat.docx
 
Think of a possible change initiative in your selected organization..docx
Think of a possible change initiative in your selected organization..docxThink of a possible change initiative in your selected organization..docx
Think of a possible change initiative in your selected organization..docx
 
Thinking About Research PaperConsider the research question and .docx
Thinking About Research PaperConsider the research question and .docxThinking About Research PaperConsider the research question and .docx
Thinking About Research PaperConsider the research question and .docx
 

Recently uploaded

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 

Recently uploaded (20)

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 

Database Systems Design, Implementation, and Management

  • 1. Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization Database Systems, 8th Edition 2 Objectives • In this chapter, you will learn: – Basic database performance-tuning concepts – How a DBMS processes SQL queries – About the importance of indexes in query processing – About the types of decisions the query optimizer has to make – Some common practices used to write efficient SQL code – How to formulate queries and tune the DBMS for optimal performance – Performance tuning in SQL Server 2005
  • 2. Database Systems, 8th Edition 3 11.1 Database Performance-Tuning Concepts • Goal of database performance is to execute queries as fast as possible • Database performance tuning – Set of activities and procedures designed to reduce response time of database system • All factors must operate at optimum level with minimal bottlenecks • Good database performance starts with good database design Database Systems, 8th Edition 4 Database Systems, 8th Edition 5 Performance Tuning: Client and Server • Client side – Generate SQL query that returns correct answer in least amount of time • Using minimum amount of resources at server
  • 3. – SQL performance tuning • Server side – DBMS environment configured to respond to clients’ requests as fast as possible • Optimum use of existing resources – DBMS performance tuning Database Systems, 8th Edition 6 DBMS Architecture • All data in database are stored in data files • Data files – Automatically expand in predefined increments known as extends – Grouped in file groups or table spaces • Table space or file group: – Logical grouping of several data files that store data with similar characteristics Database Systems, 8th Edition 7 Basic DBMS architecture
  • 4. Database Systems, 8th Edition 8 DBMS Architecture (continued) • Data cache or buffer cache: shared, reserved memory area – Stores most recently accessed data blocks in RAM • SQL cache or procedure cache: stores most recently executed SQL statements – Also PL/SQL procedures, including triggers and functions • DBMS retrieves data from permanent storage and places it in RAM Database Systems, 8th Edition 9 DBMS Architecture (continued) • Input/output request: low-level data access operation to/from computer devices, such as memory, hard disks, videos, and printers • Data cache is faster than data in data files – DBMS does not wait for hard disk to retrieve data • Majority of performance-tuning activities focus on minimizing I/O operations • Typical DBMS processes: – Listener, User, Scheduler, Lock manager, Optimizer
  • 5. Database Systems, 8th Edition 10 Database Statistics • Measurements about database objects and available resources – Tables, Indexes, Number of processors used, Processor speed, Temporary space available • Make critical decisions about improving query processing efficiency • Can be gathered manually by DBA or automatically by DBMS – UPDATE STATISTICS table_name [index_name] – Auto-Update and Auto-Create Statistics option • 資料庫屬性-> 自動更新統計資料 • 資料庫屬性-> 自動建立統計資料 Database Systems, 8th Edition 11 Database Systems, 8th Edition 12 Ch08: dbcc show_statistics (customer, PK__CUSTOMER__24927208 ) Ch08: dbcc show_statistics (customer, CUS_UI1)
  • 6. 補充SQL Server 2005 Database Systems, 8th Edition 13 11.2 Query Processing • DBMS processes queries in three phases – Parsing • DBMS parses the query and chooses the most efficient access/execution plan – Execution • DBMS executes the query using chosen execution plan – Fetching • DBMS fetches the data and sends the result back to the client Database Systems, 8th Edition 14 Query Processing Database Systems, 8th Edition 15 SQL Parsing Phase • Break down query into smaller units
  • 7. • Transform original SQL query into slightly different version of original SQL code – Fully equivalent • Optimized query results are always the same as original query – More efficient • Optimized query will almost always execute faster than original query Database Systems, 8th Edition 16 SQL Parsing Phase (continued) • Query optimizer analyzes SQL query and finds most efficient way to access data – Validated for syntax compliance – Validated against data dictionary • Tables, column names are correct • User has proper access rights – Analyzed and decomposed into more atomic components – Optimized through transforming into a fully equivalent but more efficient SQL query – Prepared for execution by determining the execution or access plan
  • 8. Database Systems, 8th Edition 17 SQL Parsing Phase (continued) • Access plans are DBMS-specific – Translate client’s SQL query into series of complex I/O operations – Required to read the data from the physical data files and generate result set • DBMS checks if access plan already exists for query in SQL cache • DBMS reuses the access plan to save time • If not, optimizer evaluates various plans – Chosen plan placed in SQL cache Database Systems, 8th Edition 18 Database Systems, 8th Edition 19 SQL Execution and Fetching Phase • All I/O operations indicated in access plan are executed – Locks acquired – Data retrieved and placed in data cache – Transaction management commands processed
  • 9. • Rows of resulting query result set are returned to client • DBMS may use temporary table space to store temporary data – The server may send only the first 100 rows of 9000 rows Database Systems, 8th Edition 20 Query Processing Bottlenecks • Delay introduced in the processing of an I/O operation that slows the system – CPU – RAM – Hard disk – Network – Application code Database Systems, 8th Edition 21 SQL 敘述 輸入完成 後先不要 執行查 詢, 請按 下工具列 的顯示估
  • 10. 計執行計 劃鈕 : Database Systems, 8th Edition 22 11.3 Indexes and Query Optimization • Indexes – Crucial in speeding up data access – Facilitate searching, sorting, and using aggregate functions as well as join operations – Ordered set of values that contains index key and pointers • More efficient to use index to access table than to scan all rows in table sequentially Database Systems, 8th Edition 23 Indexes and Query Optimization • Data sparsity: number of different values a column could possibly have • Indexes implemented using: ( 課本p. 453) – Hash indexes – B-tree indexes: most common index type. Used in tables in
  • 11. which column values repeat a small number of times. The leaves contain pointers to records It is self-balanced. – Bitmap indexes: 0/1 • DBMSs determine best type of index to use – Ex: CUST_LNAME with B-tree and REGION_CODE with Bitmap indexes Database Systems, 8th Edition 24B-tree and bitmap index representation 25 Index Representation for the CUSTOMER table SELECT CUS_NAME FROM CUSTOMER WHERE CUS_STATE=‘FL’ Requires only 5 accesses to STATE_INDEX, 5 accesses to CUSTOMER Database Systems, 8th Edition 26 11.4 Optimizer Choices • Rule-based optimizer – Preset rules and points
  • 12. – Rules assign a fixed cost to each operation • Cost-based optimizer – Algorithms based on statistics about objects being accessed – Adds up processing cost, I/O costs, resource costs to derive total cost Example Database Systems, 8th Edition 27 SELECT P_CODE, P_DESCRIPT, P_PRICE, V_NAME, V_STATE FROM PRODUCT P, VENDOR V WHERE P.V_CODE=V.V_CODE AND V.V_STATE=‘FL’; • With the following database statistics: – The PRODUCT table has 7000 rows – The VENDOR table has 300 rows – 10 vendors come from Florida – 1000 products come from vendors in Florida Database Systems, 8th Edition 28 Example
  • 13. Database Systems, 8th Edition 29 • Assume the PRODUCT table has the index PQOH_NDX in the P_QOH attribute SELECT MIN(P_QOH) FROM PRODUCT could be resolved by reading only the first entry in the PQOH_NDX index Database Systems, 8th Edition 30 Using Hints to Affect Optimizer Choices • Optimizer might not choose best plan • Makes decisions based on existing statistics – Statistics may be old – Might choose less efficient decisions • Optimizer hints: special instructions for the optimizer embedded in the SQL command text Database Systems, 8th Edition 31 Oracle 版本 Database Systems, 8th Edition 32
  • 14. MS SQL Server 的語法請參考: http://msdn.microsoft.com/en-us/library/ms187713.aspx SQL Server Query Hints Example select o.customerid,companyname from orders as o inner MERGE join customers as c on o.customerid = c.customerid select o.customerid,companyname from orders as o inner HASH join customers as c on o.customerid = c.customerid select o.customerid,companyname from orders as o inner LOOP join customers as c on o.customerid = c.customerid select city, count(*) from customers group by city OPTION (HASH GROUP) Database Systems: Design, Implementation, and Management Eighth EditionObjectives11.1 Database Performance-Tuning ConceptsPowerPoint PresentationPerformance Tuning: Client and ServerDBMS ArchitectureSlide 7DBMS Architecture (continued)Slide 9Database StatisticsSlide 11Slide 1211.2 Query ProcessingSlide 14SQL Parsing PhaseSQL Parsing Phase (continued)Slide 17Slide 18SQL Execution and Fetching PhaseQuery Processing BottlenecksSlide 2111.3 Indexes and Query OptimizationIndexes and Query OptimizationSlide 24Slide 2511.4 Optimizer ChoicesExampleSlide 28Slide 29Using Hints to Affect Optimizer ChoicesSlide 31Slide 32