The document discusses database performance tuning and query optimization, emphasizing the importance of efficient SQL query processing and the role of indexes. It outlines the phases of query processing, including parsing, execution, and fetching, while highlighting common bottlenecks that can affect performance. Additionally, it covers the types of indexes used to enhance data access and the differences between rule-based and cost-based optimizers in determining the best execution plans.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
0 views27 pages
Performance Optimization
The document discusses database performance tuning and query optimization, emphasizing the importance of efficient SQL query processing and the role of indexes. It outlines the phases of query processing, including parsing, execution, and fetching, while highlighting common bottlenecks that can affect performance. Additionally, it covers the types of indexes used to enhance data access and the differences between rule-based and cost-based optimizers in determining the best execution plans.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27
DATABASE PERFORMANCE
TUNING AND QUERY
OPTIMIZATION Objective • Basic database performance-tuning concepts • How a DBMS processes SQL queries • About the importance of indexes in query processing Database Performance-Tuning Concepts • Goalof 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 Performance Tuning: Client and Server Client side Server side
• Generate SQL query that • DBMS environment configured
returns correct answer in least to respond to clients’ requests amount of time as fast as possible • Using minimum amount of • Optimum use of existing resources at server resources • SQL performance tuning • DBMS performance tuning DBMS Architecture • All data in database are stored in data files • Data files • Automaticallyexpand 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 • Data cache or buffer cache: shared, reserved memory area • Stores most recently accessed data blocks in RAM • Index(es) Contents, System Catalog Data etc.
• •SQL cache or procedure cache: stores most recently
executed SQL statements • Also PL/SQL procedures, including triggers and functions • Don’t stores User SQL rather “Processed” form of SQL ready for execution. • DBMS retrieves data from permanent storage and places it in RAM • Input/outputrequest: low-level data access operation to/from computer devices, Page size matters at OS level • 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 (Transaction Mgt & Concurrency Mgt.), Lock manager, Optimizer Database Statistics Measurements about database objects and available resources • Tables • Indexes • Number of processors used • Processor speed • Temporary space available •Makecritical decisions about improving query processing efficiency •Canbe gathered manually by DBA or automatically by DBMS 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 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 • 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 components • Optimized • Prepared for execution • 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 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
• Generate Result Set, send record from Server Cache
to Client Cache • Rows of resulting query result set are returned to client, Server sends records as per client space • DBMS may 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 following: • searching, • sorting,and • aggregate functions (min, max) • 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 •Datasparsity: number of different values a column could possibly have •Indexes implemented using: •Hash indexes •B-tree indexes •Bitmap indexes •Cluster Index (Index Organized Table in Oracle) •B+ Tree Index
•DBMSs determine best type of index to use
Optimizer Choices Rule-based optimizer • Preset rules and points • Rules assign a fixed cost to each operation • No statistics required • e.g.: Full table scan has fix cost 10, table access by row id has 3 etc. Cost-based optimizer • Algorithms based on statistics about objects being accessed • Adds up processing cost, I/O costs, resource costs to derive total cost