sys用户下:
SQL> alter system flush shared_pool; SQL> alter system flush buffer_cache; SQL> select b.owner,b.object_name,sum(a.tch) acc_time 2 from x$bh a,dba_objects b 3 where a.obj=b.object_id 4 And b.owner='MOE' 5 And b.object_name='MOE' 6 group by b.owner,b.object_name 7 order by acc_time desc; OWNER OBJECT_NAM ACC_TIME ------------------------------ ---------- ---------- MOE MOE 0
moe用户下:
explain plan for select * from moe;
sys用户下:
SQL> select b.owner,b.object_name,sum(a.tch) acc_time 2 from x$bh a,dba_objects b 3 where a.obj=b.object_id 4 And b.owner='MOE' 5 And b.object_name='MOE' 6 group by b.owner,b.object_name 7 order by acc_time desc; OWNER OBJECT_NAM ACC_TIME ------------------------------ ---------- ---------- MOE MOE 6 SQL> select sql_text,executions,parse_calls from v$sqlarea where sql_text like '%select * from moe%'; SQL_TEXT EXECUTIONS PARSE_CALLS -------------------------------------------------------------------------------- ---------- ----------- select sql_text,executions,parse_calls from v$sqlarea where sql_text like '%sel 1 1 explain plan for select * from moe 1 1
使用explain plan for查询执行计划时,解析的语句是explain plan for xxxxxxxx
后面的xxxxxxxx语句并不真正执行,但是在解析过程中需要相关信息(统计信息或是动态采样)
DML测试如下:
sys:
SQL> alter system flush shared_pool; SQL> alter system flush buffer_cache; SQL> select b.owner,b.object_name,sum(a.tch) acc_time 2 from x$bh a,dba_objects b 3 where a.obj=b.object_id 4 And b.owner='MOE' 5 And b.object_name='MOE' 6 group by b.owner,b.object_name 7 order by acc_time desc; OWNER OBJECT_NAM ACC_TIME ------------------------------ ---------- ---------- MOE MOE 0
moe:
explain plan for insert into moe select * from moe;
sys:
SQL> select b.owner,b.object_name,sum(a.tch) acc_time 2 from x$bh a,dba_objects b 3 where a.obj=b.object_id 4 And b.owner='MOE' 5 And b.object_name='MOE' 6 group by b.owner,b.object_name 7 order by acc_time desc; OWNER OBJECT_NAM ACC_TIME ------------------------------ ---------- ---------- MOE MOE 8 SQL> select sql_text,executions,parse_calls from v$sqlarea where sql_text like '%select * from moe%'; SQL_TEXT EXECUTIONS PARSE_CALLS -------------------------------------------------------------------------------- ---------- ----------- select sql_text,executions,parse_calls from v$sqlarea where sql_text like '%sel 1 1 explain plan for insert into moe select * from moe 1 1