日期:2014-05-17  浏览次数:20849 次

执行计划吗?
SQL> select count(*) from tb_clfb;

已用时间: 00: 00: 00.02

Statistics
----------------------
  0 recursive calls
  0 db block gets
  1112 consistent gets
  643 physical reads
  0 redo size
  375 bytes sent via SQL*Net to client
  503 bytes received via SQL*Net from client
  2 SQL*Net roundtrips to/from client
  0 sorts (memory)
  0 sorts (disk)
  1 rows processed

------解决方案--------------------
SQL code

SQL> select * from t where rownum=1;

       IDX
----------
CNAME
--------------------------------------------
         1
a



Execution Plan
----------------------
   0      SELECT STATEMENT Optimizer=CHOOSE
   1    0   COUNT (STOPKEY)
   2    1     TABLE ACCESS (FULL) OF 'T'




Statistics
----------------------
          0  recursive calls
          0  db block gets
          0  consistent gets
          0  physical reads
          0  redo size
          0  bytes sent via SQL*Net to client
          0  bytes received via SQL*Net from client
          0  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

------解决方案--------------------
要有
Execution Plan
----------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 COUNT (STOPKEY)
2 1 TABLE ACCESS (FULL) OF 'T'
才能看得出,
你是不是用的

set autotrace on statistics

这样看不到 Plan


直接set autotrace on看看信息

------解决方案--------------------
探讨
执行set autotrace on显示

SQL> set autotrace on;
SP2-0613: 无法验证 PLAN_TABLE 格式或实体
SP2-0611: 启用EXPLAIN报告时出错

------解决方案--------------------
SQL code
1: 打开PL\SQL Developer工具,按F5
2:SET AUTOTRACE TRACEONLY;   -- 安装执行计划 FYI: http://www.eygle.com/faq/AutoTrace.htm

如果想强制使用索引:

-- 查索引NAME:
SQL> SELECT TABLE_NAME,
  2         INDEX_NAME
  3    FROM ALL_INDEXES
  4   WHERE TABLE_OWNER = UPPER('SCOTT')
  5     AND TABLE_NAME = UPPER('EMP');

TABLE_NAME                     INDEX_NAME
------------------------------ ------------------------------
EMP                            PK_EMP

SQL> SELECT /*+ INDEX(EMP PK_EMP)*/ EMPNO,ENAME
  2    FROM EMP
  3   WHERE EMPNO >= '7782';

EMPNO ENAME
----- ----------
 7782 CLARK
 7788 SCOTT
 7839 KING
 7844 TURNER
 7876 ADAMS
 7900 JAMES
 7902 FORD
 7934 MILLER

8 rows selected