SlideShare a Scribd company logo
1 of 22
CHAPTER 11:
DATABASE PERFORMANCE
TUNING AND QUERY
OPTIMIZATION
Jonathan Weinberg
Andrew Casteen
OBJECTIVES
 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
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 (you
can't polish a turd)
PERFORMANCE TUNING:
CLIENT AND SERVER
 Client side
• Generate a SQL query that returns the correct answer in the least amount
of time
• Using the minimum amount of resources at the server end
• SQL performance tuning – The activities required to achieve that goal
 Server side
• DBMS environment configured to respond to the clients’ requests as fast
as possible
• Optimum use of existing resources
• DBMS performance tuning – The activities required to achieve that
goal
DBMS ARCHITECTURE
 All data in database are stored in data files
 Data files
• Can 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
DBMS ARCHITECTURE
CONT.
 Data cache or buffer cache
• Shared, reserved memory area that stores the most recently accessed
data blocks in RAM
 SQL cache or procedure cache
• Shared, reserved memory area that stores the most recently executed
SQL statements or PL/SQL procedures, including triggers and
functions
 DBMS retrieves data from permanent storage and places it in
RAM
DBMS ARCHITECTURE
CONT.
 Input/output (I/O) request: low-level data access operation to and
from computer devices
 Data cache is faster than data in data files because the DBMS does not
wait for hard disk to retrieve data
 Majority of performance-tuning activities focus on minimizing the
number of I/O operations
 Typical DBMS processes:
• Listener, user, scheduler, lock manager, optimizer
DBMS PROCESSES
 Listener: Takes clients’ requests and handles the processing
of the SQL requests to other DBMS processes. Once
received, the request is passes to appropriate user process
 User: Created to manage each client session and handles all
requests submitted to the server
 Scheduler: Organizes the concurrent execution of SQL requests
DBMS PROCESSES CONT.
 Lock Manager: Manages all locks placed on database objects
 Optimizer: Analyzes SQL queries and finds the most efficient way
to access the data
DATABASE STATISTICS
 Number of measurements about database objects and available
resources:
• 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
QUERY PROCESS
 DBMS processes queries in three phases
• Parsing
• DBMS parses the SQL query and chooses the most efficient
access/execution plan
• Execution
• DBMS executes the SQL query using chosen execution plan
• Fetching
• DBMS fetches the data and sends the result back to the client
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
SQL PARSING PHASE CONT.
 Query optimizer: Analyzes SQL query and finds most efficient
way to access data
• Validated for syntax compliance
• Validated against data dictionary
• Tables and column names are correct
• User has proper access rights
• Analyzed and decomposed into components
• Optimized into a fully equivalent but more efficient SQL query
• Prepared for execution by determining the most efficient execution
SQL PARSING PHASE CONT.
 Access plans: Result of parsing a SQL statement
• DBMS-Specific
• Translate client’s SQL query into a 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 it doesn’t, the optimizer evaluates various plans
• Chosen plan placed in SQL cache
SQL EXECUTION PHASE
 All I/O operations indicated in access plan are executed
• Locks acquired
• Data retrieved and placed in data cache
• Transaction management commands processed
SQL FETCHING PHASE
 All rows that match the specified condition(s) are
retrieved, sorted, grouped, and/or aggregated and results are
returned to the client
 DBMS might use temporary table space to store temporary data
QUERY PROCESSING
BOTTLENECKS
 Delay introduced in the processing of an I/O operation that slows
the system
• CPU
• RAM
• Hard disk
• Network
• Application code
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
INDEXES AND QUERY
OPTIMIZATION CONT.
 Data sparsity: number of different values a column could
possibly have
 Indexes implemented using:
• Hash indexes
• B-tree indexes
• Bitmap indexes
 DBMSs determine best type of index to use
ACCESS VS ORACLE
INDEXING

More Related Content

What's hot

Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
Simon Huang
 
Sql architecture
Sql architectureSql architecture
Sql architecture
rchakra
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
Narendra_Oracle DBA_4.1 years of expriances_Bangalore
Narendra_Oracle DBA_4.1 years of expriances_BangaloreNarendra_Oracle DBA_4.1 years of expriances_Bangalore
Narendra_Oracle DBA_4.1 years of expriances_Bangalore
Naremdra L
 
Is accurate system-level power measurement challenging? Check this out!
Is accurate system-level power measurement challenging? Check this out!Is accurate system-level power measurement challenging? Check this out!
Is accurate system-level power measurement challenging? Check this out!
Deepak Shankar
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance Tuning
OracleTrainings
 

What's hot (19)

SQL Server Performance Tuning Baseline
SQL Server Performance Tuning BaselineSQL Server Performance Tuning Baseline
SQL Server Performance Tuning Baseline
 
SQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database PerformanceSQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database Performance
 
SQL Server Query Optimization, Execution and Debugging Query Performance
SQL Server Query Optimization, Execution and Debugging Query PerformanceSQL Server Query Optimization, Execution and Debugging Query Performance
SQL Server Query Optimization, Execution and Debugging Query Performance
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
 
Sql architecture
Sql architectureSql architecture
Sql architecture
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
 
Oracle dba training in Canada|Oracle dba training From Canada phno 09705612767
Oracle dba training in Canada|Oracle dba training From Canada phno 09705612767Oracle dba training in Canada|Oracle dba training From Canada phno 09705612767
Oracle dba training in Canada|Oracle dba training From Canada phno 09705612767
 
Performance tuning in sql server
Performance tuning in sql serverPerformance tuning in sql server
Performance tuning in sql server
 
Evolutionary database design
Evolutionary database designEvolutionary database design
Evolutionary database design
 
Sql server performance tuning and optimization
Sql server performance tuning and optimizationSql server performance tuning and optimization
Sql server performance tuning and optimization
 
Sap hana training in hyderabad
Sap hana training in hyderabadSap hana training in hyderabad
Sap hana training in hyderabad
 
Presentation maximizing database performance performance tuning with db time
Presentation    maximizing database performance performance tuning with db timePresentation    maximizing database performance performance tuning with db time
Presentation maximizing database performance performance tuning with db time
 
Narendra_Oracle DBA_4.1 years of expriances_Bangalore
Narendra_Oracle DBA_4.1 years of expriances_BangaloreNarendra_Oracle DBA_4.1 years of expriances_Bangalore
Narendra_Oracle DBA_4.1 years of expriances_Bangalore
 
Is accurate system-level power measurement challenging? Check this out!
Is accurate system-level power measurement challenging? Check this out!Is accurate system-level power measurement challenging? Check this out!
Is accurate system-level power measurement challenging? Check this out!
 
Performance Tuning And Optimization Microsoft SQL Database
Performance Tuning And Optimization Microsoft SQL DatabasePerformance Tuning And Optimization Microsoft SQL Database
Performance Tuning And Optimization Microsoft SQL Database
 
2016 may-countdown-to-postgres-v96-parallel-query
2016 may-countdown-to-postgres-v96-parallel-query2016 may-countdown-to-postgres-v96-parallel-query
2016 may-countdown-to-postgres-v96-parallel-query
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance Tuning
 
Rolta’s application testing services for handling ever changing environment.
Rolta’s application testing services for handling ever changing environment.   Rolta’s application testing services for handling ever changing environment.
Rolta’s application testing services for handling ever changing environment.
 

Viewers also liked

CS 542 -- Query Optimization
CS 542 -- Query OptimizationCS 542 -- Query Optimization
CS 542 -- Query Optimization
J Singh
 
MarketLine Country Statistics Database
MarketLine Country Statistics DatabaseMarketLine Country Statistics Database
MarketLine Country Statistics Database
MarketLine
 
Oracle hard and soft parsing
Oracle hard and soft parsingOracle hard and soft parsing
Oracle hard and soft parsing
Ishaan Guliani
 

Viewers also liked (20)

project in DBMS
project in DBMSproject in DBMS
project in DBMS
 
CS 542 -- Query Optimization
CS 542 -- Query OptimizationCS 542 -- Query Optimization
CS 542 -- Query Optimization
 
Lesson4 Protect and maintain databases
Lesson4 Protect and maintain databases Lesson4 Protect and maintain databases
Lesson4 Protect and maintain databases
 
التحدى 6 الإستعلام بطريقة المعالج
التحدى 6 الإستعلام بطريقة المعالجالتحدى 6 الإستعلام بطريقة المعالج
التحدى 6 الإستعلام بطريقة المعالج
 
Lesson11 Create Query
Lesson11 Create QueryLesson11 Create Query
Lesson11 Create Query
 
Lesson8 Manage Records
Lesson8 Manage RecordsLesson8 Manage Records
Lesson8 Manage Records
 
Trabalho fitos digitais
Trabalho fitos digitaisTrabalho fitos digitais
Trabalho fitos digitais
 
MarketLine Country Statistics Database
MarketLine Country Statistics DatabaseMarketLine Country Statistics Database
MarketLine Country Statistics Database
 
Oracle hard and soft parsing
Oracle hard and soft parsingOracle hard and soft parsing
Oracle hard and soft parsing
 
Lesson5 Print and export databases
Lesson5 Print and export databases Lesson5 Print and export databases
Lesson5 Print and export databases
 
Performance Tuning Azure SQL Database
Performance Tuning Azure SQL DatabasePerformance Tuning Azure SQL Database
Performance Tuning Azure SQL Database
 
الوحدة التاسعة - قاعدة البيانات وادارتها
الوحدة التاسعة - قاعدة البيانات وادارتهاالوحدة التاسعة - قاعدة البيانات وادارتها
الوحدة التاسعة - قاعدة البيانات وادارتها
 
Oracle 11g PL/SQL proqramlamlaşdırma yenilikləri
Oracle 11g PL/SQL proqramlamlaşdırma yenilikləri Oracle 11g PL/SQL proqramlamlaşdırma yenilikləri
Oracle 11g PL/SQL proqramlamlaşdırma yenilikləri
 
أساسيات التأمين
أساسيات التأمينأساسيات التأمين
أساسيات التأمين
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
 
Top frinds-انشاء-استعلام-بطريقه-المعالج-6-copy
Top frinds-انشاء-استعلام-بطريقه-المعالج-6-copyTop frinds-انشاء-استعلام-بطريقه-المعالج-6-copy
Top frinds-انشاء-استعلام-بطريقه-المعالج-6-copy
 
Database system concepts and architecture
Database system concepts and architectureDatabase system concepts and architecture
Database system concepts and architecture
 
Webinar: Performance Tuning + Optimization
Webinar: Performance Tuning + OptimizationWebinar: Performance Tuning + Optimization
Webinar: Performance Tuning + Optimization
 
الوحدة الخامسة - قاعدة البيانات وادارتها
الوحدة الخامسة - قاعدة البيانات وادارتهاالوحدة الخامسة - قاعدة البيانات وادارتها
الوحدة الخامسة - قاعدة البيانات وادارتها
 
الوحدة الثامنة - قاعدة البيانات وادارتها
الوحدة الثامنة - قاعدة البيانات وادارتهاالوحدة الثامنة - قاعدة البيانات وادارتها
الوحدة الثامنة - قاعدة البيانات وادارتها
 

Similar to Chapter 11new

Database Systems Design, Implementation, and Management
Database Systems Design, Implementation, and ManagementDatabase Systems Design, Implementation, and Management
Database Systems Design, Implementation, and Management
OllieShoresna
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1
sqlserver.co.il
 

Similar to Chapter 11new (20)

Database Systems Design, Implementation, and Management
Database Systems Design, Implementation, and ManagementDatabase Systems Design, Implementation, and Management
Database Systems Design, Implementation, and Management
 
Dbms 3 sem
Dbms 3 semDbms 3 sem
Dbms 3 sem
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1
 
Unit 2 oracle9i
Unit 2  oracle9i Unit 2  oracle9i
Unit 2 oracle9i
 
high performance databases
high performance databaseshigh performance databases
high performance databases
 
Remote DBA Experts SQL Server 2008 New Features
Remote DBA Experts SQL Server 2008 New FeaturesRemote DBA Experts SQL Server 2008 New Features
Remote DBA Experts SQL Server 2008 New Features
 
Presentation cloud control enterprise manager 12c
Presentation   cloud control enterprise manager 12cPresentation   cloud control enterprise manager 12c
Presentation cloud control enterprise manager 12c
 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
 
Database performance tuning and query optimization
Database performance tuning and query optimizationDatabase performance tuning and query optimization
Database performance tuning and query optimization
 
Best storage engine for MySQL
Best storage engine for MySQLBest storage engine for MySQL
Best storage engine for MySQL
 
ECMDay2015 - Kent Agerlund – Configuration Manager 2012 – A Site Review
ECMDay2015 - Kent Agerlund – Configuration Manager 2012 – A Site ReviewECMDay2015 - Kent Agerlund – Configuration Manager 2012 – A Site Review
ECMDay2015 - Kent Agerlund – Configuration Manager 2012 – A Site Review
 
Monitorando performance no Azure SQL Database
Monitorando performance no Azure SQL DatabaseMonitorando performance no Azure SQL Database
Monitorando performance no Azure SQL Database
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdf
 
Product Update: EDB Postgres Platform 2017
Product Update: EDB Postgres Platform 2017Product Update: EDB Postgres Platform 2017
Product Update: EDB Postgres Platform 2017
 
Exchange Server 2013 : les mécanismes de haute disponibilité et la redondance...
Exchange Server 2013 : les mécanismes de haute disponibilité et la redondance...Exchange Server 2013 : les mécanismes de haute disponibilité et la redondance...
Exchange Server 2013 : les mécanismes de haute disponibilité et la redondance...
 
Time Travelling With DB2 10 For zOS
Time Travelling With DB2 10 For zOSTime Travelling With DB2 10 For zOS
Time Travelling With DB2 10 For zOS
 
Azure data platform overview
Azure data platform overviewAzure data platform overview
Azure data platform overview
 
Database performance monitoring:Key to seamless application performance
Database performance monitoring:Key to seamless application performanceDatabase performance monitoring:Key to seamless application performance
Database performance monitoring:Key to seamless application performance
 
Tarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshooting
Tarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshootingTarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshooting
Tarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshooting
 

Recently uploaded

+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
Health
 
+97470301568>>buy weed in qatar,buy thc oil in qatar doha>>buy cannabis oil i...
+97470301568>>buy weed in qatar,buy thc oil in qatar doha>>buy cannabis oil i...+97470301568>>buy weed in qatar,buy thc oil in qatar doha>>buy cannabis oil i...
+97470301568>>buy weed in qatar,buy thc oil in qatar doha>>buy cannabis oil i...
Health
 

Recently uploaded (20)

Business Principles, Tools, and Techniques in Participating in Various Types...
Business Principles, Tools, and Techniques  in Participating in Various Types...Business Principles, Tools, and Techniques  in Participating in Various Types...
Business Principles, Tools, and Techniques in Participating in Various Types...
 
Famous Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist i...
Famous Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist i...Famous Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist i...
Famous Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist i...
 
Black magic specialist in Canada (Kala ilam specialist in UK) Bangali Amil ba...
Black magic specialist in Canada (Kala ilam specialist in UK) Bangali Amil ba...Black magic specialist in Canada (Kala ilam specialist in UK) Bangali Amil ba...
Black magic specialist in Canada (Kala ilam specialist in UK) Bangali Amil ba...
 
Lion One Corporate Presentation May 2024
Lion One Corporate Presentation May 2024Lion One Corporate Presentation May 2024
Lion One Corporate Presentation May 2024
 
FE Credit and SMBC Acquisition Case Studies
FE Credit and SMBC Acquisition Case StudiesFE Credit and SMBC Acquisition Case Studies
FE Credit and SMBC Acquisition Case Studies
 
+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
 
劳伦森大学毕业证
劳伦森大学毕业证劳伦森大学毕业证
劳伦森大学毕业证
 
uk-no 1 kala ilam expert specialist in uk and qatar kala ilam expert speciali...
uk-no 1 kala ilam expert specialist in uk and qatar kala ilam expert speciali...uk-no 1 kala ilam expert specialist in uk and qatar kala ilam expert speciali...
uk-no 1 kala ilam expert specialist in uk and qatar kala ilam expert speciali...
 
Strategic Resources May 2024 Corporate Presentation
Strategic Resources May 2024 Corporate PresentationStrategic Resources May 2024 Corporate Presentation
Strategic Resources May 2024 Corporate Presentation
 
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...
 
Seeman_Fiintouch_LLP_Newsletter_May-2024.pdf
Seeman_Fiintouch_LLP_Newsletter_May-2024.pdfSeeman_Fiintouch_LLP_Newsletter_May-2024.pdf
Seeman_Fiintouch_LLP_Newsletter_May-2024.pdf
 
Avoidable Errors in Payroll Compliance for Payroll Services Providers - Globu...
Avoidable Errors in Payroll Compliance for Payroll Services Providers - Globu...Avoidable Errors in Payroll Compliance for Payroll Services Providers - Globu...
Avoidable Errors in Payroll Compliance for Payroll Services Providers - Globu...
 
cost-volume-profit analysis.ppt(managerial accounting).pptx
cost-volume-profit analysis.ppt(managerial accounting).pptxcost-volume-profit analysis.ppt(managerial accounting).pptx
cost-volume-profit analysis.ppt(managerial accounting).pptx
 
Pension dashboards forum 1 May 2024 (1).pdf
Pension dashboards forum 1 May 2024 (1).pdfPension dashboards forum 1 May 2024 (1).pdf
Pension dashboards forum 1 May 2024 (1).pdf
 
NO1 Verified Online Love Vashikaran Specialist Kala Jadu Expert Specialist In...
NO1 Verified Online Love Vashikaran Specialist Kala Jadu Expert Specialist In...NO1 Verified Online Love Vashikaran Specialist Kala Jadu Expert Specialist In...
NO1 Verified Online Love Vashikaran Specialist Kala Jadu Expert Specialist In...
 
Group 8 - Goldman Sachs & 1MDB Case Studies
Group 8 - Goldman Sachs & 1MDB Case StudiesGroup 8 - Goldman Sachs & 1MDB Case Studies
Group 8 - Goldman Sachs & 1MDB Case Studies
 
Collecting banker, Capacity of collecting Banker, conditions under section 13...
Collecting banker, Capacity of collecting Banker, conditions under section 13...Collecting banker, Capacity of collecting Banker, conditions under section 13...
Collecting banker, Capacity of collecting Banker, conditions under section 13...
 
+97470301568>>buy weed in qatar,buy thc oil in qatar doha>>buy cannabis oil i...
+97470301568>>buy weed in qatar,buy thc oil in qatar doha>>buy cannabis oil i...+97470301568>>buy weed in qatar,buy thc oil in qatar doha>>buy cannabis oil i...
+97470301568>>buy weed in qatar,buy thc oil in qatar doha>>buy cannabis oil i...
 
logistics industry development power point ppt.pdf
logistics industry development power point ppt.pdflogistics industry development power point ppt.pdf
logistics industry development power point ppt.pdf
 
Test bank for advanced assessment interpreting findings and formulating diffe...
Test bank for advanced assessment interpreting findings and formulating diffe...Test bank for advanced assessment interpreting findings and formulating diffe...
Test bank for advanced assessment interpreting findings and formulating diffe...
 

Chapter 11new

  • 1. CHAPTER 11: DATABASE PERFORMANCE TUNING AND QUERY OPTIMIZATION Jonathan Weinberg Andrew Casteen
  • 2. OBJECTIVES  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
  • 3. 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 (you can't polish a turd)
  • 4. PERFORMANCE TUNING: CLIENT AND SERVER  Client side • Generate a SQL query that returns the correct answer in the least amount of time • Using the minimum amount of resources at the server end • SQL performance tuning – The activities required to achieve that goal  Server side • DBMS environment configured to respond to the clients’ requests as fast as possible • Optimum use of existing resources • DBMS performance tuning – The activities required to achieve that goal
  • 5. DBMS ARCHITECTURE  All data in database are stored in data files  Data files • Can 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
  • 6. DBMS ARCHITECTURE CONT.  Data cache or buffer cache • Shared, reserved memory area that stores the most recently accessed data blocks in RAM  SQL cache or procedure cache • Shared, reserved memory area that stores the most recently executed SQL statements or PL/SQL procedures, including triggers and functions  DBMS retrieves data from permanent storage and places it in RAM
  • 7. DBMS ARCHITECTURE CONT.  Input/output (I/O) request: low-level data access operation to and from computer devices  Data cache is faster than data in data files because the DBMS does not wait for hard disk to retrieve data  Majority of performance-tuning activities focus on minimizing the number of I/O operations  Typical DBMS processes: • Listener, user, scheduler, lock manager, optimizer
  • 8.
  • 9. DBMS PROCESSES  Listener: Takes clients’ requests and handles the processing of the SQL requests to other DBMS processes. Once received, the request is passes to appropriate user process  User: Created to manage each client session and handles all requests submitted to the server  Scheduler: Organizes the concurrent execution of SQL requests
  • 10. DBMS PROCESSES CONT.  Lock Manager: Manages all locks placed on database objects  Optimizer: Analyzes SQL queries and finds the most efficient way to access the data
  • 11. DATABASE STATISTICS  Number of measurements about database objects and available resources: • 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
  • 12. QUERY PROCESS  DBMS processes queries in three phases • Parsing • DBMS parses the SQL query and chooses the most efficient access/execution plan • Execution • DBMS executes the SQL query using chosen execution plan • Fetching • DBMS fetches the data and sends the result back to the client
  • 13.
  • 14. 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
  • 15. SQL PARSING PHASE CONT.  Query optimizer: Analyzes SQL query and finds most efficient way to access data • Validated for syntax compliance • Validated against data dictionary • Tables and column names are correct • User has proper access rights • Analyzed and decomposed into components • Optimized into a fully equivalent but more efficient SQL query • Prepared for execution by determining the most efficient execution
  • 16. SQL PARSING PHASE CONT.  Access plans: Result of parsing a SQL statement • DBMS-Specific • Translate client’s SQL query into a 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 it doesn’t, the optimizer evaluates various plans • Chosen plan placed in SQL cache
  • 17. SQL EXECUTION PHASE  All I/O operations indicated in access plan are executed • Locks acquired • Data retrieved and placed in data cache • Transaction management commands processed
  • 18. SQL FETCHING PHASE  All rows that match the specified condition(s) are retrieved, sorted, grouped, and/or aggregated and results are returned to the client  DBMS might use temporary table space to store temporary data
  • 19. QUERY PROCESSING BOTTLENECKS  Delay introduced in the processing of an I/O operation that slows the system • CPU • RAM • Hard disk • Network • Application code
  • 20. 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
  • 21. INDEXES AND QUERY OPTIMIZATION CONT.  Data sparsity: number of different values a column could possibly have  Indexes implemented using: • Hash indexes • B-tree indexes • Bitmap indexes  DBMSs determine best type of index to use