查看执行计划: 1.1.explain plan for 目标SQL 1.2 dbms_xplan包 dbms_xplan.display(先执行explain plan for 目标SQL)–可能不准确 dbms_xplan.display_cursor(null,null,‘ADVANCED’/‘ALL’)(先执行目标SQL,且执行计划未被age out出shared pool) dbms_xplan.display_cursor(目标SQL_ID/目标SQL的HASH_VALUE,目标SQL的child_number,‘ADVANCED’/‘ALL’) (先执行目标SQL,且执行计划未被age out出shared pool) dbms_xplan.display_awr(目标SQL_ID).(执行计划被age out出shared pool ,然后执行exec dbms_workload_repository.create_snapshot());
1.3 set autotrace/autot 参数 off on traceonly/trace traceonly explain/trace exp traceonly statistics/trace stat 然后执行目标SQL 1.4 10046事件与tkprof命令 alter session set events ‘10046 trace name context forever,level 12’ 执行目标SQL alter session set events’10046 trace name context off’ 或者 oradebug setmypid oradebug event 10046 trace name context forever,level 12 执行目标SQL oradebug event 10046 trace name context off oradebug tracefile_name
最后执行美化命令(oradebug tracefile_name 得到的trace文件地址) tkprof trace文件地址
得到真实的执行计划 10046事件比较准备 explain plan for 可能不准: dbms_xplan.display 可能不准 dbms_xplan.display_cursor(null,null,‘ADVANCED’/‘ALL’) 准 dbms_xplan.display_cursor(目标SQL_ID/目标SQL的HASH_VALUE,目标SQL的child_number,‘ADVANCED’/‘ALL’) 准 dbms_xplan.display_awr(目标SQL_ID) 准 set autotrace/autot 参数 都可能不准,(取决于explain plan for) off on 准 traceonly/trace 准 traceonly explain/trace exp select 不准,dml准 traceonly statistics/trace stat
常见的执行计划 TABLE ACCESS FULL TABLE ACCESS BY USER ROWID TABLE ACCESS BY INDEX ROWID INDEX UNIQUE SCAN INDEX FULL SCAN INDEX FAST FULL SCAN INDEX RANGE SCAN BITMAP INDEX SINGLE VALUE BITMAP INDEX RANGE SCAN BITMAP INDEX FULL SCAN BITMAP INDEX FAST FULL SCAN BITMAP AND BITMAP OR BITMAP MINUS BITMAP CONVERSION TO ROWIDS MERGE JOIN NESTED LOOPS HASH JOIN HASH JOIN ANTI MERGE JOIN ANTI NESTED LOOPS ANTI HASH JOIN SEMI MERGE JOIN SEMI NESTED LOOPS SEMI AND-EQUAL(INDEX MERGE) INDEX JOIN VIEW FILTER(改良的NESTED LOOPS) SORT AGGREGATE SORT UNIQUE SORT JOIN SORT GROUP BY SORT ORDER BY BUFFER SORT(不一定会排序,statistics中的sorts(memory)和sorts(disk)有可能不准,要看Column Projection Information 中#keys的值) 排序可以通过10032事件("Comparisons performed by in-memory sort”和“Total number of comparisons performed"的值来具体查看) UNION(UNION-ALL和“SORT UNIQUE”)/UNION ALL CONCAT(IN-List扩展(IN-List Expansion)或OR扩展(OR Expansion) CONNECT BY