Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Systems, 8 th Edition 1 11.5 SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.

Similar presentations


Presentation on theme: "Database Systems, 8 th Edition 1 11.5 SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization."— Presentation transcript:

1 Database Systems, 8 th Edition 1 11.5 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 Rarely portable Majority of performance problems related to poorly written SQL code Carefully written query usually outperforms a poorly written query

2 Database Systems, 8 th Edition 2 Index Selectivity Indexes are used when: –Indexed column appears by itself in search criteria of WHERE or HAVING clause –Indexed column appears by itself in GROUP BY or ORDER BY clause –MAX or MIN function is applied to indexed column –Data sparsity on indexed column is high Index selectivity is a measure of how likely an index will be used in query processing

3 Database Systems, 8 th Edition 3 Index Selectivity (continued) General guidelines for indexes: –Create indexes for each attribute in WHERE, HAVING, ORDER BY, or GROUP BY clause –Do not use in small tables or tables with low sparsity –Declare primary and foreign keys so optimizer can use indexes in join operations –Declare indexes in join columns other than PK/FK

4 Database Systems, 8 th Edition 4 Conditional Expressions Normally expressed within WHERE or HAVING clauses of SQL statement Restricts output of query to only rows matching conditional criteria

5 Database Systems, 8 th Edition 5 Common practices for efficient SQL: –Use simple columns or literals in conditionals Avoid functions –Numeric field comparisons are faster than character, date, and NULL comparisons –Equality comparisons faster than inequality —the slowest is “LIKE” comparison –Transform conditional expressions to use literals –Write equality conditions first –AND: Use condition most likely to be false first –OR: Use condition most likely to be true first –Avoid NOT

6 Database Systems, 8 th Edition 6 11.6 Query Formulation Identify what columns and computations are required (p.459) –Expressions –Aggregate functions –Granularity of raw required Identify source tables Determine how to join tables Determine what selection criteria is needed –Simple comparison? IN? Nested Comparison? HAVING Determine in what order to display output

7 Database Systems, 8 th Edition 7 11.7 DBMS Performance Tuning Includes managing DBMS processes in primary memory and structures in physical storage DBMS performance tuning at server end focuses on setting parameters used for: –Data cache: large enough –SQL cache: same query may be submitted by many users –Sort cache –Optimizer mode

8 Database Systems, 8 th Edition 8 DBMS Performance Tuning Some general recommendations for creation of databases: –Use RAID (Redundant Array of Independent Disks) to provide balance between performance and fault tolerance –Minimize disk contention At least with the following table spaces: system table, user table, index table, temporary table, rollback segment table –Put high-usage tables in their own table spaces –Assign separate data files in separate storage volumes for indexes, system, high-usage tables

9 Database Systems, 8 th Edition 9 DBMS Performance Tuning Some general recommendations for creation of databases: (continued) –Take advantage of table storage organizations in database An indexed organized table stores the end user table and the index table in consecutive locations on permanent storage –Partition tables based on usage –Use denormalized tables where appropriate –Store computed and aggregate attributes in tables

10 Database Systems, 8 th Edition 10 Common RAID Configurations

11 Database Systems, 8 th Edition 11 11.8 Query Optimization Example Example illustrates how query optimizer works Based on QOVENDOR and QOPRODUCT tables Uses Oracle SQL*Plus (Skip)

12 Database Systems, 8 th Edition 12 請參考以下 SQL Server 的講義

13 Database Systems, 8 th Edition 13

14 Database Systems, 8 th Edition 14 Check the differences in query plan: 1.Before UPDATE STATISTICS QOVENDOR 2.After UPDATE STATISTICS QOVENDOR 3. CREATE INDEX QOV_NDX1 on QOVENDOR (V_AREACODE) UPDATE STATISTICS QOVENDOR 4. CREATE INDEX QOV_NDX2 on QOVENDOR (V_NAME) UPDATE STATISTICS QOVENDOR

15 Database Systems, 8 th Edition 15

16 Database Systems, 8 th Edition 16

17 Database Systems, 8 th Edition 17

18 Database Systems, 8 th Edition 18

19 Database Systems, 8 th Edition 19 Check the differences in query plan: 1.Before UPDATE STATISTICS QOPRODUCT 2.After UPDATE STATISTICS QOPRODUCT 3. CREATE INDEX QOP_NDX2 ON QOPRODUCT(P_PRICE) UPDATE STATISTICS QOPRODUCT

20 Database Systems, 8 th Edition 20 Summary Database performance tuning –Refers to activities to ensure query is processed in minimum amount of time SQL performance tuning –Refers to activities on client side to generate SQL code Returns correct answer in least amount of time Uses minimum amount of resources at server end DBMS architecture represented by processes and structures used to manage a database

21 Database Systems, 8 th Edition 21 Summary (continued) Database statistics refers to measurements gathered by the DBMS –Describe snapshot of database objects’ characteristics DBMS processes queries in three phases: parsing, execution, and fetching Indexes are crucial in process that speeds up data access

22 Database Systems, 8 th Edition 22 Summary (continued) During query optimization, DBMS chooses: –Indexes to use, how to perform join operations, table to use first, etc. Hints change optimizer mode for current SQL statement SQL performance tuning deals with writing queries that make good use of statistics Query formulation deals with translating business questions into specific SQL code


Download ppt "Database Systems, 8 th Edition 1 11.5 SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization."

Similar presentations


Ads by Google