[20220517]toad使用gather_plan_statistics提示问题.txt

来源:这里教程网 时间:2026-03-03 17:38:59 作者:

[20220517]toad使用gather_plan_statistics提示问题.txt --//这个问题以前应该遇到过,再次做一次记录。 1.环境: SCOTT@book> @ ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- -------------------------------------------------------------------------------- x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 2.测试: --//在toad下执行: Select /*+ gather_plan_statistics */ * from dept --where rownum=1; --//在toad下查看执行计划: Plan hash value: 3383998547   --------------------------------------------------------------------------- | Id  | Operation         | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | --------------------------------------------------------------------------- |   0 | SELECT STATEMENT  |      |      4 |    80 |     3   (0)| 00:00:01 | |   1 |  TABLE ACCESS FULL| DEPT |      4 |    80 |     3   (0)| 00:00:01 | --------------------------------------------------------------------------- --//很明显这个不是打开gather_plan_statistics看到的执行计划。 --//使用toad自带的SQL Tracker跟踪发现: Timestamp: 2022/5/17 9:44:06 declare   v_ignore raw(100);   v_oldhash number;   v_hash number; begin   v_hash := dbms_utility.get_sql_hash(:SQLText || chr(0), v_ignore, v_oldhash);   :outHash := v_hash; end; SQLText=['Select /*+ gather_plan_statistics */ * from dept --where rownum=1'] outHash=[0.178956209e+010] Elapsed time: 0.006 -------------------------------------------------------------------------------- Timestamp: 2022/5/17 9:44:06 Select * from v$sql_plan Where hash_value = '1789562090' and child_number =0 order by id --//如果查询hash_value = '1789562090',没有结果,这样toad只能使用explain plan 解析执行计划。 --//为什么toad执行看不到打开gather_plan_statistics的真实执行计划呢。 --//如果扫描共享池子可以发现,实际上toad执行的是: SCOTT@book> select sql_id,sql_text from v$sqlarea where sql_text like '%gather_plan_statistics%'; SQL_ID        SQL_TEXT ------------- ------------------------------------------------------------ 0yb7hx933y5z0 Select /*+ gather_plan_statistics */ * from dept --where row               num=1;; daymukjvv6pxz select sql_id,sql_text from v$sqlarea where sql_text like '%               gather_plan_statistics%' --//注意看实际上toad在后面又加了1个分号,是两个分号。 SCOTT@book> @ dpc 0yb7hx933y5z0 '' '' PLAN_TABLE_OUTPUT ------------------------------------- SQL_ID  0yb7hx933y5z0, child number 0 ------------------------------------- Select /*+ gather_plan_statistics */ * from dept --where rownum=1;; Plan hash value: 3383998547 -------------------------------------------------------------------------------------------------------------------- | Id  | Operation         | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers | -------------------------------------------------------------------------------------------------------------------- |   0 | SELECT STATEMENT  |      |      1 |        |       |     3 (100)|          |      4 |00:00:00.01 |       6 | |   1 |  TABLE ACCESS FULL| DEPT |      1 |      4 |    80 |     3   (0)| 00:00:01 |      4 |00:00:00.01 |       6 | -------------------------------------------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): -------------------------------------------------------------    1 - SEL$1 / DEPT@SEL$1 --//这样看到才是打开gather_plan_statistics 的执行计划。 --//遇到这样的情况最简单的方法就是把分号单独一行,注意这样写还是不行。 Select /*+ gather_plan_statistics */ * from dept --where rownum=1; ; --//写成如下ok。 Select /*+ gather_plan_statistics */ * from dept --where rownum=1 ;

相关推荐