17,377
社区成员
发帖
与我相关
我的任务
分享
-- 这个实验结果,你还满意不
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.4.0
Connected as zc2bmes_user@10.255.30.9/test
SQL>
SQL> set timing on;
SQL> drop index ix_emp;
drop index ix_emp
ORA-01418: 指定的索引不存在
SQL> select count(*) from emp;
COUNT(*)
----------
14221312
Executed in 2.886 seconds
SQL> select count(*) from emp where deptno is null;
COUNT(*)
----------
819200
Executed in 2.366 seconds
SQL> select count(*) from emp where sal is null;
COUNT(*)
----------
6094848
Executed in 2.861 seconds
SQL> select count(*) from emp where deptno = 'DEV';
COUNT(*)
----------
7700480
Executed in 2.548 seconds
SQL> select count(*) from ind where table_name = 'EMP';
COUNT(*)
----------
0
Executed in 0.037 seconds
SQL> explain plan for SELECT * FROM
2 (SELECT rownum rn, emp.* FROM EMP WHERE DEPTNO='DEV' ORDER BY SAL DESC )
3 WHERE ROWNUM <= 20;
Explained
Executed in 0.015 seconds
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1035293170
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Ti
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 20 | 10740 | | 841K (1)| 02
|* 1 | COUNT STOPKEY | | | | | |
| 2 | VIEW | | 6401K| 3278M| | 841K (1)| 02
|* 3 | SORT ORDER BY STOPKEY| | 6401K| 3198M| 4167M| 841K (1)| 02
| 4 | COUNT | | | | | |
|* 5 | TABLE ACCESS FULL | EMP | 6401K| 3198M| | 132K (1)| 00
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM<=20)
3 - filter(ROWNUM<=20)
5 - filter("DEPTNO"='DEV')
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement (level=2)
23 rows selected
Executed in 0.213 seconds
SQL> rollback;
Rollback complete
Executed in 0.002 seconds
SQL> SELECT * FROM
2 (SELECT rownum rn, emp.* FROM EMP WHERE DEPTNO='DEV' ORDER BY SAL DESC )
3 WHERE ROWNUM <= 20;
-- 这里的数据我删除了
20 rows selected
Executed in 7.728 seconds
SQL> create index ix_emp on emp(deptno, sal);
Index created
Executed in 16.774 seconds
SQL> exec dbms_stats.gather_table_stats(user,'EMP',cascade => true);
PL/SQL procedure successfully completed
Executed in 16.812 seconds
SQL> explain plan for SELECT * FROM
2 (SELECT rownum rn, emp.* FROM EMP WHERE DEPTNO='DEV' ORDER BY SAL DESC )
3 WHERE ROWNUM <= 20;
Explained
Executed in 0.006 seconds
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 2189114292
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 20 | 10740 | 18 (0)|
|* 1 | COUNT STOPKEY | | | | |
| 2 | VIEW | | 20 | 10740 | 18 (0)|
| 3 | COUNT | | | | |
| 4 | TABLE ACCESS BY INDEX ROWID | EMP | 7714K| 1611M| 18 (0)|
|* 5 | INDEX RANGE SCAN DESCENDING| IX_EMP | 20 | | 3 (0)|
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM<=20)
5 - access("DEPTNO"='DEV')
18 rows selected
Executed in 0.194 seconds
SQL> rollback;
Rollback complete
Executed in 0.002 seconds
SQL> SELECT * FROM
2 (SELECT rownum rn, emp.* FROM EMP WHERE DEPTNO='DEV' ORDER BY SAL DESC )
3 WHERE ROWNUM <= 20;
-- 这里的数据我删除了
20 rows selected
Executed in 0.364 seconds
SQL>