sql tuning guideline
TRANSCRIPT
Agenda
• The Guideline to tune sql1. Application Logic
2. Table/Column statistics
3. SQL access path
4. SQL join NL or hash Join
How to review sql
• Verifying Optimizer Statistics
• Reviewing the Execution Plan
• Restructuring the SQL Statements(code change)
• Restructuring the Indexes
SQLT: Nice tool review top sql
• Statistics:Tables/Indexes/Columns
• Execution plan1. Predication
2. Bind value
3. SQL profile
Table/Index stats
• Table stats1. Last_Analyzed2. Num_Rows3. Sample_Size
• Index stats1. Last_Analyzed2. Num_Rows3. Sample_Size4. DISTINCT_KEYS5. BLEVEL6. Clustering_Factor
Column statistics
• num_rows
• num_distinct• density• num_nulls• num_buckets• histogram• low_value• high_value
How to gather Table/Column statistics
• Using auto method– exec
dbms_stats.gather_table_stats('CS2_PARTY_OWNER','CS2_BKG_RQST',method_opt=>'for all columns size auto',cascade=>true);
• For specific columns– exec
dbms_stats.gather_table_stats('CS2_PARTY_OWNER','CS2_BKG_RQST',method_opt=>'for columns size 254 SP_COMPANY_ID',cascade=>true);
Review execution plan
• Driving table has the best filter
• Join method: Nested Loop or Hash Join
• Join order: Fewest number of rows are being returned to the next step
• Each table is being accessed efficiently1. index scan2. full table scan
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
Access Path
• Full Table Scans
• Index Scans1. Index Unique Scans2. Index Range Scans3. Full Scans4. Fast Full Index Scans5. Index Joins
SQL Profile
• 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.
advance usage:coe_xfr_sql_profile.sql
• coe_xfr_sql_profile.sql is from SQLT tool
• An easy way to lock the sql plan as outline
Output sql format
• coe_xfr_sql_profile_<SID>_<PLAN_Hash_value>.SQL
• coe_xfr_sql_profile_chpub18xajb2w_1020905707.SQL