1 / 13

SQL Tuning Scripts

SQL Tuning Scripts. Bobby Durrett US Foodservice bobbyandmarielle@yahoo.com http://www.geocities.com/bobbyandmarielle/seouc.zip. Tuning a slow SQL statement. Create directory with tuning scripts Capture problem SQL Get execution plan Query DBA_ views Run select count(*) queries

tavia
Download Presentation

SQL Tuning Scripts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SQL Tuning Scripts Bobby Durrett US Foodservice bobbyandmarielle@yahoo.com http://www.geocities.com/bobbyandmarielle/seouc.zip

  2. Tuning a slow SQL statement • Create directory with tuning scripts • Capture problem SQL • Get execution plan • Query DBA_ views • Run select count(*) queries • Try different plans • Test execution of improved SQL

  3. Why these scripts? • DBA view columns used by optimizer • Tables in problem SQL only • Records current state of statistics • Readable format • Only needs SQL*Plus • Free!

  4. Script names • tablelist.sql – tables in query • tablestats.sql – table level statistics • indexstats.sql – index level statistics • indexcolumns.sql – columns in indexes • columnstats.sql – column level stats • histograms.sql – histogram details • all.sql – runs all of the above

  5. Example • Table TEST – 2,000,001 rows • Columns A, B – NUMBER • 1,000,000 rows (1,1) • 1,000,000 rows (2,2) • 1 row (1,2) • Query where condition A=1, B=2 chooses the one row

  6. tablelist.sql • Edit to include owner, table_name for each table in problem SQL • May have to expand views to get base tables • Can also get table names from plan

  7. tablestats.sql • OWNER • TABLE_NAME • NUM_ROWS • BLOCKS • AVG_ROW_LEN • SAMPLE_SIZE • LAST_ANALYZED

  8. indexstats.sql • TABLE_OWNER • TABLE_NAME • INDEX_NAME • NUM_ROWS • SAMPLE_SIZE • CLUSTERING_FACTOR • LAST_ANALYZED • LEAF_BLOCKS • DISTINCT_KEYS • AVG_LEAF_BLOCKS_PER_KEY • AVG_DATA_BLOCKS_PER_KEY • BLEVEL

  9. indexcolumns.sql • TABLE_NAME • INDEX_NAME • COLUMN_NAME • COLUMN_EXPRESSION

  10. columnstats.sql • TABLE_NAME • COLUMN_NAME • LO • HI • NUM_DISTINCT • NUM_BUCKETS • DENSITY • NUM_NULLS • AVG_COL_LEN • LAST_ANALYZED • SAMPLE_SIZE

  11. histograms.sql • HISTOGRAM • TABLE_NAME • COLUMN_NAME • ENDPOINT_NUMBER • ENDPOINT_VALUE • ENDPOINT_ACTUAL_VALUE

  12. References • http://www.geocities.com/bobbyandmarielle/sqltuning.zip - My talk on cardinality issues • Cost Based Optimizer Fundamentals, Jonathan Lewis • Metalink Note:212809.1, Limitations of the Oracle Cost Based Optimizer • Metalink Note:68992.1, Predicate Selectivity • Histograms – Myths and Facts, Wolfgang Breitling, Select Journal, Volume 13, Number 3

  13. SQL Tuning Scripts Bobby Durrett US Foodservice bobbyandmarielle@yahoo.com http://www.geocities.com/bobbyandmarielle/seouc.zip

More Related