SlideShare a Scribd company logo
Database Systems
Design, Implementation, and Management
Coronel | Morris
11e
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Chapter 11
Database Performance Tuning and Query
Optimization
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Learning Objectives
 In this chapter, the student 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
2
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Database Performance-Tuning Concepts
 Goal of database performance is to execute queries as
fast as possible
 Database performance tuning: Set of activities and
procedures that reduce response time of database
system
 Fine-tuning the performance of a system requires that
all factors must operate at optimum level with
minimal bottlenecks
3
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Table 11.1 - General Guidelines for Better
System Performance
4
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Performance Tuning: Client and Server
 Client side
 SQL performance tuning: Generates SQL query that
returns correct answer in least amount of time
 Using minimum amount of resources at server
 Server side
 DBMS performance tuning: DBMS environment
configured to respond to clients’ requests as fast as
possible
 Optimum use of existing resources
5
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
DBMS Architecture
 All data in a database are stored in data files
 Data files automatically expand in predefined
increments known as extends
 Data files are grouped in file groups or table spaces
 Table space or file group: Logical grouping of several
data files that store data with similar characteristics
 Data cache or buffer cache: Shared, reserved
memory area
 Stores most recently accessed data blocks in RAM
6
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
DBMS Architecture
 SQL cache or procedure cache: Stores most recently
executed SQL statements or PL/SQL procedures
 DBMS retrieves data from permanent storage and
places them in RAM
 Input/output request: Low-level data access
operation that reads or writes data to and from
computer devices
 Data cache is faster than working with data files
 Majority of performance-tuning activities focus on
minimizing I/O operations
7
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Figure 11.1 - Basic DBMS
Architecture
8
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Database Query Optimization Modes
 Algorithms proposed for query optimization are
based on:
 Selection of the optimum order to achieve the fastest
execution time
 Selection of sites to be accessed to minimize
communication costs
 Evaluated on the basis of:
 Operation mode
 Timing of its optimization
9
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Classification of Operation Modes
 Automatic query optimization: DBMS finds the
most cost-effective access path without user
intervention
 Manual query optimization: Requires that the
optimization be selected and scheduled by the end
user or programmer
10
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Classification Based on Timing of
Optimization
 Static query optimization: best optimization
strategy is selected when the query is compiled by the
DBMS
 Takes place at compilation time
 Dynamic query optimization: Access strategy is
dynamically determined by the DBMS at run time,
using the most up-to-date information about the
database
 Takes place at execution time
11
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Classification Based on Type of
Information Used to Optimize the Query
 Statistically based query optimization algorithm:
Statistics are used by the DBMS to determine the best
access strategy
 Statistical information is generated by DBMS
through:
 Dynamic statistical generation mode
 Manual statistical generation mode
 Rule-based query optimization algorithm: based
on a set of user-defined rules to determine the best
query access strategy
12
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Table 11.2 - Sample Database Statistics
Measurements
13
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Query Processing
• DBMS parses the SQL query and chooses the
most efficient access/execution plan
Parsing
• DBMS executes the SQL query using the chosen
execution plan
Execution
• DBMS fetches the data and sends the result set
back to the client
Fetching
14
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
SQL Parsing Phase
 Query is broken down into smaller units
 Original SQL query is transformed into slightly
different version of the original SQL code which is
fully equivalent and more efficient
 Query optimizer: Analyzes SQL query and finds
most efficient way to access data
 Access plans: DBMS-specific and translate client’s
SQL query into a series of complex I/O operations
15
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
SQL Parsing Phase
 If access plan already exists for query in SQL cache,
DBMS reuses it
 If not, optimizer evaluates various plans and chooses
one to be placed in SQL cache for use
16
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
SQL Execution Phase
 All I/O operations indicated in the access plan are
executed
 Locks are acquired
 Data are retrieved and placed in data cache
 Transaction management commands are processed
17
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
SQL Fetching Phase
 Rows of resulting query result set are returned to
client
 DBMS may use temporary table space to store
temporary data
 Database server coordinates the movement of the result
set rows from the server cache to the client cache
18
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Query Processing Bottlenecks
 Delay introduced in the processing of an I/O
operation that slows the system
 Caused by the:
 CPU
 RAM
 Hard disk
 Network
 Application code
19
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Indexes and Query Optimization
 Indexes
 Help speed up data access
 Facilitate searching, sorting, using aggregate functions,
and join operations
 Ordered set of values that contain the index key and
pointers
 More efficient than a full table scan
20
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Indexes and Query Optimization
 Data sparsity: Number of different values a column
could have
 Data structures used to implement indexes:
 Hash indexes
 B-tree indexes
 Bitmap indexes
 DBMSs determine best type of index to use
21
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Optimizer Choices
 Rule-based optimizer: Uses preset rules and points
to determine the best approach to execute a query
 Cost-based optimizer: Uses algorithms based on
statistics about objects being accessed to determine
the best approach to execute a query
22
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Using Hints to Affect Optimizer
Choices
 Optimizer might not choose the best execution plan
 Makes decisions based on existing statistics, which
might be old
 Might choose less-efficient decisions
 Optimizer hints: Special instructions for the
optimizer, embedded in the SQL command text
23
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Table 11.5 - Optimizer Hints
24
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
SQL Performance Tuning
 Evaluated from client perspective
 Most current relational DBMSs perform automatic
query optimization at the server end
 Most SQL performance optimization techniques are
DBMS-specific and thus rarely portable
 Majority of performance problems are related to
poorly written SQL code
25
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Index Selectivity
 Measure of the likelihood that an index will be used
in query processing
 Indexes are used when a subset of rows from a large
table is to be selected based on a given condition
 Index cannot always be used to improve performance
 Function-based index: Based on a specific SQL
function or expression
26
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Conditional Expressions
 Expressed within WHERE or HAVING clauses of a
SQL statement
 Restricts the output of a query to only rows matching
conditional criteria
 Guidelines to write efficient conditional expressions
in SQL code
 Use simple columns or literals as operands
 Numeric field comparisons are faster than character,
date, and NULL comparisons
27
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Conditional Expressions
 Equality comparisons are faster than inequality
comparisons
 Transform conditional expressions to use literals
 Write equality conditions first when using multiple
conditional expressions
 When using multiple AND conditions, write the
condition most likely to be false first
 When using multiple OR conditions, put the condition
most likely to be true first
 Avoid the use of NOT logical operator
28
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Query Formulation
 Identify what columns and computations are required
 Identify source tables
 Determine how to join tables
 Determine what selection criteria are needed
 Determine the order in which to display the output
29
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
DBMS Performance Tuning
 Managing DBMS processes in primary memory and
the structures in physical storage
 DBMS performance tuning at server end focuses on
setting parameters used for:
 Data cache
 SQL cache
 Sort cache
 Optimizer mode
 In-memory database: Store large portions of the
database in primary storage
30
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
DBMS Performance Tuning
 Recommendations for physical storage of databases:
 Use RAID (Redundant Array of Independent Disks) to
provide a balance between performance improvement
and fault tolerance
 Minimize disk contention
 Put high-usage tables in their own table spaces
 Assign separate data files in separate storage volumes
for indexes, system, and high-usage tables
31
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
DBMS Performance Tuning
 Take advantage of the various table storage
organizations in the database
 Index-organized table or clustered index table: Stores
the end-user data and the index data in consecutive
locations in permanent storage
 Partition tables based on usage
 Use denormalized tables where appropriate
 Store computed and aggregate attributes in tables
32

More Related Content

Similar to Coronel_PPT_Ch11.ppt

Drupal performance optimization Best Practices
Drupal performance optimization Best PracticesDrupal performance optimization Best Practices
Drupal performance optimization Best Practices
Ratnesh kumar, CSM
 
Performace optimization (increase website speed)
Performace optimization (increase website speed)Performace optimization (increase website speed)
Performace optimization (increase website speed)
clickramanm
 
ASP.NET MVC Zero to Hero
ASP.NET MVC Zero to HeroASP.NET MVC Zero to Hero
ASP.NET MVC Zero to Hero
Md. Mahedee Hasan
 
Performance Optimization in Drupal 8
Performance Optimization in Drupal 8Performance Optimization in Drupal 8
Performance Optimization in Drupal 8
valuebound
 
Performance tuning and optimization (ppt)
Performance tuning and optimization (ppt)Performance tuning and optimization (ppt)
Performance tuning and optimization (ppt)
Harish Chand
 
Which Change Data Capture Strategy is Right for You?
Which Change Data Capture Strategy is Right for You?Which Change Data Capture Strategy is Right for You?
Which Change Data Capture Strategy is Right for You?
Precisely
 
C4 delivering database as a service within your organization
C4   delivering database as a service within your organizationC4   delivering database as a service within your organization
C4 delivering database as a service within your organizationDr. Wilfred Lin (Ph.D.)
 
Improve Your Frontend Agility with Proven Optimization Methods
Improve Your Frontend Agility with Proven Optimization MethodsImprove Your Frontend Agility with Proven Optimization Methods
Improve Your Frontend Agility with Proven Optimization Methods
Inexture Solutions
 
Introducing Elevate Capacity Management
Introducing Elevate Capacity ManagementIntroducing Elevate Capacity Management
Introducing Elevate Capacity Management
Precisely
 
Database AdministrationObjectivesDiscus.docx
Database AdministrationObjectivesDiscus.docxDatabase AdministrationObjectivesDiscus.docx
Database AdministrationObjectivesDiscus.docx
whittemorelucilla
 
Tuning database performance
Tuning database performanceTuning database performance
Tuning database performanceBinay Acharya
 
short presentation on caching Caching.ppt
short presentation on caching Caching.pptshort presentation on caching Caching.ppt
short presentation on caching Caching.ppt
yakashthapar2
 
BSAD 372 SPRING 2017 CH 8
BSAD 372 SPRING 2017 CH 8BSAD 372 SPRING 2017 CH 8
BSAD 372 SPRING 2017 CH 8
Janice Robinson
 
Performance tuning and optimization on client server
Performance tuning and optimization on client serverPerformance tuning and optimization on client server
Performance tuning and optimization on client server
Satya P. Joshi
 
Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02
Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02
Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02
malonzo
 
Tech Ed Africa Demystifying Backup Restore In Share Point 2007
Tech Ed Africa Demystifying Backup Restore In Share Point 2007Tech Ed Africa Demystifying Backup Restore In Share Point 2007
Tech Ed Africa Demystifying Backup Restore In Share Point 2007
Joel Oleson
 
Drupal 8 Lessons From the Field: Part 3 - The Drupal Backend
Drupal 8 Lessons From the Field: Part 3 - The Drupal BackendDrupal 8 Lessons From the Field: Part 3 - The Drupal Backend
Drupal 8 Lessons From the Field: Part 3 - The Drupal Backend
Acquia
 
Tips for Installing Cognos Analytics: Configuring and Installing the Server
Tips for Installing Cognos Analytics: Configuring and Installing the ServerTips for Installing Cognos Analytics: Configuring and Installing the Server
Tips for Installing Cognos Analytics: Configuring and Installing the Server
Senturus
 
Beginners guide to_optimizer
Beginners guide to_optimizerBeginners guide to_optimizer
Beginners guide to_optimizer
Maria Colgan
 

Similar to Coronel_PPT_Ch11.ppt (20)

Drupal performance optimization Best Practices
Drupal performance optimization Best PracticesDrupal performance optimization Best Practices
Drupal performance optimization Best Practices
 
Performace optimization (increase website speed)
Performace optimization (increase website speed)Performace optimization (increase website speed)
Performace optimization (increase website speed)
 
ASP.NET MVC Zero to Hero
ASP.NET MVC Zero to HeroASP.NET MVC Zero to Hero
ASP.NET MVC Zero to Hero
 
Pp 14-new
Pp 14-newPp 14-new
Pp 14-new
 
Performance Optimization in Drupal 8
Performance Optimization in Drupal 8Performance Optimization in Drupal 8
Performance Optimization in Drupal 8
 
Performance tuning and optimization (ppt)
Performance tuning and optimization (ppt)Performance tuning and optimization (ppt)
Performance tuning and optimization (ppt)
 
Which Change Data Capture Strategy is Right for You?
Which Change Data Capture Strategy is Right for You?Which Change Data Capture Strategy is Right for You?
Which Change Data Capture Strategy is Right for You?
 
C4 delivering database as a service within your organization
C4   delivering database as a service within your organizationC4   delivering database as a service within your organization
C4 delivering database as a service within your organization
 
Improve Your Frontend Agility with Proven Optimization Methods
Improve Your Frontend Agility with Proven Optimization MethodsImprove Your Frontend Agility with Proven Optimization Methods
Improve Your Frontend Agility with Proven Optimization Methods
 
Introducing Elevate Capacity Management
Introducing Elevate Capacity ManagementIntroducing Elevate Capacity Management
Introducing Elevate Capacity Management
 
Database AdministrationObjectivesDiscus.docx
Database AdministrationObjectivesDiscus.docxDatabase AdministrationObjectivesDiscus.docx
Database AdministrationObjectivesDiscus.docx
 
Tuning database performance
Tuning database performanceTuning database performance
Tuning database performance
 
short presentation on caching Caching.ppt
short presentation on caching Caching.pptshort presentation on caching Caching.ppt
short presentation on caching Caching.ppt
 
BSAD 372 SPRING 2017 CH 8
BSAD 372 SPRING 2017 CH 8BSAD 372 SPRING 2017 CH 8
BSAD 372 SPRING 2017 CH 8
 
Performance tuning and optimization on client server
Performance tuning and optimization on client serverPerformance tuning and optimization on client server
Performance tuning and optimization on client server
 
Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02
Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02
Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02
 
Tech Ed Africa Demystifying Backup Restore In Share Point 2007
Tech Ed Africa Demystifying Backup Restore In Share Point 2007Tech Ed Africa Demystifying Backup Restore In Share Point 2007
Tech Ed Africa Demystifying Backup Restore In Share Point 2007
 
Drupal 8 Lessons From the Field: Part 3 - The Drupal Backend
Drupal 8 Lessons From the Field: Part 3 - The Drupal BackendDrupal 8 Lessons From the Field: Part 3 - The Drupal Backend
Drupal 8 Lessons From the Field: Part 3 - The Drupal Backend
 
Tips for Installing Cognos Analytics: Configuring and Installing the Server
Tips for Installing Cognos Analytics: Configuring and Installing the ServerTips for Installing Cognos Analytics: Configuring and Installing the Server
Tips for Installing Cognos Analytics: Configuring and Installing the Server
 
Beginners guide to_optimizer
Beginners guide to_optimizerBeginners guide to_optimizer
Beginners guide to_optimizer
 

Recently uploaded

The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 

Recently uploaded (20)

The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 

Coronel_PPT_Ch11.ppt

  • 1. Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Chapter 11 Database Performance Tuning and Query Optimization
  • 2. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Learning Objectives  In this chapter, the student 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 2
  • 3. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Database Performance-Tuning Concepts  Goal of database performance is to execute queries as fast as possible  Database performance tuning: Set of activities and procedures that reduce response time of database system  Fine-tuning the performance of a system requires that all factors must operate at optimum level with minimal bottlenecks 3
  • 4. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Table 11.1 - General Guidelines for Better System Performance 4
  • 5. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Performance Tuning: Client and Server  Client side  SQL performance tuning: Generates SQL query that returns correct answer in least amount of time  Using minimum amount of resources at server  Server side  DBMS performance tuning: DBMS environment configured to respond to clients’ requests as fast as possible  Optimum use of existing resources 5
  • 6. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. DBMS Architecture  All data in a database are stored in data files  Data files automatically expand in predefined increments known as extends  Data files are grouped in file groups or table spaces  Table space or file group: Logical grouping of several data files that store data with similar characteristics  Data cache or buffer cache: Shared, reserved memory area  Stores most recently accessed data blocks in RAM 6
  • 7. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. DBMS Architecture  SQL cache or procedure cache: Stores most recently executed SQL statements or PL/SQL procedures  DBMS retrieves data from permanent storage and places them in RAM  Input/output request: Low-level data access operation that reads or writes data to and from computer devices  Data cache is faster than working with data files  Majority of performance-tuning activities focus on minimizing I/O operations 7
  • 8. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Figure 11.1 - Basic DBMS Architecture 8
  • 9. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Database Query Optimization Modes  Algorithms proposed for query optimization are based on:  Selection of the optimum order to achieve the fastest execution time  Selection of sites to be accessed to minimize communication costs  Evaluated on the basis of:  Operation mode  Timing of its optimization 9
  • 10. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Classification of Operation Modes  Automatic query optimization: DBMS finds the most cost-effective access path without user intervention  Manual query optimization: Requires that the optimization be selected and scheduled by the end user or programmer 10
  • 11. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Classification Based on Timing of Optimization  Static query optimization: best optimization strategy is selected when the query is compiled by the DBMS  Takes place at compilation time  Dynamic query optimization: Access strategy is dynamically determined by the DBMS at run time, using the most up-to-date information about the database  Takes place at execution time 11
  • 12. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Classification Based on Type of Information Used to Optimize the Query  Statistically based query optimization algorithm: Statistics are used by the DBMS to determine the best access strategy  Statistical information is generated by DBMS through:  Dynamic statistical generation mode  Manual statistical generation mode  Rule-based query optimization algorithm: based on a set of user-defined rules to determine the best query access strategy 12
  • 13. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Table 11.2 - Sample Database Statistics Measurements 13
  • 14. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Query Processing • DBMS parses the SQL query and chooses the most efficient access/execution plan Parsing • DBMS executes the SQL query using the chosen execution plan Execution • DBMS fetches the data and sends the result set back to the client Fetching 14
  • 15. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. SQL Parsing Phase  Query is broken down into smaller units  Original SQL query is transformed into slightly different version of the original SQL code which is fully equivalent and more efficient  Query optimizer: Analyzes SQL query and finds most efficient way to access data  Access plans: DBMS-specific and translate client’s SQL query into a series of complex I/O operations 15
  • 16. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. SQL Parsing Phase  If access plan already exists for query in SQL cache, DBMS reuses it  If not, optimizer evaluates various plans and chooses one to be placed in SQL cache for use 16
  • 17. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. SQL Execution Phase  All I/O operations indicated in the access plan are executed  Locks are acquired  Data are retrieved and placed in data cache  Transaction management commands are processed 17
  • 18. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. SQL Fetching Phase  Rows of resulting query result set are returned to client  DBMS may use temporary table space to store temporary data  Database server coordinates the movement of the result set rows from the server cache to the client cache 18
  • 19. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Query Processing Bottlenecks  Delay introduced in the processing of an I/O operation that slows the system  Caused by the:  CPU  RAM  Hard disk  Network  Application code 19
  • 20. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Indexes and Query Optimization  Indexes  Help speed up data access  Facilitate searching, sorting, using aggregate functions, and join operations  Ordered set of values that contain the index key and pointers  More efficient than a full table scan 20
  • 21. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Indexes and Query Optimization  Data sparsity: Number of different values a column could have  Data structures used to implement indexes:  Hash indexes  B-tree indexes  Bitmap indexes  DBMSs determine best type of index to use 21
  • 22. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Optimizer Choices  Rule-based optimizer: Uses preset rules and points to determine the best approach to execute a query  Cost-based optimizer: Uses algorithms based on statistics about objects being accessed to determine the best approach to execute a query 22
  • 23. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Using Hints to Affect Optimizer Choices  Optimizer might not choose the best execution plan  Makes decisions based on existing statistics, which might be old  Might choose less-efficient decisions  Optimizer hints: Special instructions for the optimizer, embedded in the SQL command text 23
  • 24. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Table 11.5 - Optimizer Hints 24
  • 25. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. SQL Performance Tuning  Evaluated from client perspective  Most current relational DBMSs perform automatic query optimization at the server end  Most SQL performance optimization techniques are DBMS-specific and thus rarely portable  Majority of performance problems are related to poorly written SQL code 25
  • 26. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Index Selectivity  Measure of the likelihood that an index will be used in query processing  Indexes are used when a subset of rows from a large table is to be selected based on a given condition  Index cannot always be used to improve performance  Function-based index: Based on a specific SQL function or expression 26
  • 27. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Conditional Expressions  Expressed within WHERE or HAVING clauses of a SQL statement  Restricts the output of a query to only rows matching conditional criteria  Guidelines to write efficient conditional expressions in SQL code  Use simple columns or literals as operands  Numeric field comparisons are faster than character, date, and NULL comparisons 27
  • 28. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Conditional Expressions  Equality comparisons are faster than inequality comparisons  Transform conditional expressions to use literals  Write equality conditions first when using multiple conditional expressions  When using multiple AND conditions, write the condition most likely to be false first  When using multiple OR conditions, put the condition most likely to be true first  Avoid the use of NOT logical operator 28
  • 29. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Query Formulation  Identify what columns and computations are required  Identify source tables  Determine how to join tables  Determine what selection criteria are needed  Determine the order in which to display the output 29
  • 30. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. DBMS Performance Tuning  Managing DBMS processes in primary memory and the structures in physical storage  DBMS performance tuning at server end focuses on setting parameters used for:  Data cache  SQL cache  Sort cache  Optimizer mode  In-memory database: Store large portions of the database in primary storage 30
  • 31. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. DBMS Performance Tuning  Recommendations for physical storage of databases:  Use RAID (Redundant Array of Independent Disks) to provide a balance between performance improvement and fault tolerance  Minimize disk contention  Put high-usage tables in their own table spaces  Assign separate data files in separate storage volumes for indexes, system, and high-usage tables 31
  • 32. ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. DBMS Performance Tuning  Take advantage of the various table storage organizations in the database  Index-organized table or clustered index table: Stores the end-user data and the index data in consecutive locations in permanent storage  Partition tables based on usage  Use denormalized tables where appropriate  Store computed and aggregate attributes in tables 32