Sql tuning guideline

2,059 views

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,059
On SlideShare
0
From Embeds
0
Number of Embeds
68
Actions
Shares
0
Downloads
99
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Sql tuning guideline

  1. 1. SQL Tuning Guideline <ul><ul><ul><ul><ul><li>Sidney · 2011 Feb 16 </li></ul></ul></ul></ul></ul>
  2. 2. Agenda <ul><li>The Guideline to tune sql </li></ul><ul><ul><ul><li>Application Logic </li></ul></ul></ul><ul><ul><ul><li>Table/Column statistics </li></ul></ul></ul><ul><ul><ul><li>SQL access path </li></ul></ul></ul><ul><ul><ul><li>SQL join NL or hash Join </li></ul></ul></ul>
  3. 3. Response Time <ul><li>The core of user experience </li></ul>
  4. 4. Why? So Slow! <ul><ul><ul><li>Application Logic </li></ul></ul></ul><ul><ul><ul><li>Tune at sql level </li></ul></ul></ul>
  5. 5. How to review sql <ul><li>Verifying Optimizer Statistics </li></ul><ul><li>Reviewing the Execution Plan </li></ul><ul><li>Restructuring the SQL Statements(code change) </li></ul><ul><li>Restructuring the Indexes </li></ul>
  6. 6. SQLT: Nice tool review top sql <ul><li>Statistics:Tables/Indexes/Columns </li></ul><ul><li>Execution plan </li></ul><ul><ul><li>Predication </li></ul></ul><ul><ul><li>Bind value </li></ul></ul><ul><ul><li>SQL profile </li></ul></ul>
  7. 7. Table/Index stats <ul><li>Table stats </li></ul><ul><ul><li>Last_Analyzed </li></ul></ul><ul><ul><li>Num_Rows </li></ul></ul><ul><ul><li>Sample_Size </li></ul></ul><ul><li>Index stats </li></ul><ul><ul><li>Last_Analyzed </li></ul></ul><ul><ul><li>Num_Rows </li></ul></ul><ul><ul><li>Sample_Size </li></ul></ul><ul><ul><li>DISTINCT_KEYS </li></ul></ul><ul><ul><li>BLEVEL </li></ul></ul><ul><ul><li>Clustering_Factor </li></ul></ul>
  8. 8. Column statistics <ul><li>num_rows </li></ul><ul><li>num_distinct </li></ul><ul><li>density </li></ul><ul><li>num_nulls </li></ul><ul><li>num_buckets </li></ul><ul><li>histogram </li></ul><ul><li>low_value </li></ul><ul><li>high_value </li></ul>
  9. 9. How to gather Table/Column statistics <ul><li>Using auto method </li></ul><ul><ul><li>exec dbms_stats.gather_table_stats('CS2_PARTY_OWNER','CS2_BKG_RQST',method_opt=>' for all columns size auto', cascade=>true); </li></ul></ul><ul><li>For specific columns </li></ul><ul><ul><li>exec dbms_stats.gather_table_stats('CS2_PARTY_OWNER','CS2_BKG_RQST',method_opt=>' for columns size 254 SP_COMPANY_ID', cascade=>true); </li></ul></ul>
  10. 10. Column Histogram
  11. 11. Review execution plan <ul><li>Driving table has the best filter </li></ul><ul><li>Join method: Nested Loop or Hash Join </li></ul><ul><li>Join order: Fewest number of rows are being returned to the next step </li></ul><ul><li>Each table is being accessed efficiently </li></ul><ul><ul><li>index scan </li></ul></ul><ul><ul><li>full table scan </li></ul></ul>
  12. 12. Nested Loop For small number of rows(< 1000 ), with a good driving condition between the two tables
  13. 13. Hash Function
  14. 14. Hash Join For large data set(> 1000 ): The optimizer uses the smaller of two tables or data sources to build a hash table on the join key in memory
  15. 15. Access Path <ul><li>Full Table Scans </li></ul><ul><li>Index Scans </li></ul><ul><ul><li>Index Unique Scans </li></ul></ul><ul><ul><li>Index Range Scans </li></ul></ul><ul><ul><li>Full Scans </li></ul></ul><ul><ul><li>Fast Full Index Scans </li></ul></ul><ul><ul><li>Index Joins </li></ul></ul>
  16. 16. SQL Profile <ul><li>SQL Profiles are the new feature from 10g which is managed by Oracle Enterprise Manager as part of the Automatic SQL Tuning process. Apart from OEM, SQL Profiles can be managed through the DBMS_SQLTUNE package. </li></ul>
  17. 17. normal usage of SQL Profile <ul><li>Run the SQL Tuning Advisor </li></ul><ul><li>Accept the recommended SQL Profile </li></ul>
  18. 18. advance usage: coe_xfr_sql_profile.sql <ul><li>coe_xfr_sql_profile.sql is from SQLT tool </li></ul><ul><li>An easy way to lock the sql plan as outline </li></ul>
  19. 20. Output sql format <ul><li>coe_xfr_sql_profile_<SID>_<PLAN_Hash_value>.SQL </li></ul><ul><li>coe_xfr_sql_profile_chpub18xajb2w_1020905707.SQL </li></ul>
  20. 21. Q&A

×