例子如下
首先建立环境
SQL> create table t nologging as select * from dba_objects;
表已创建。
SQL> insert /*+ append */into t select *from t;
已创建33599行。
SQL> commit;
提交完成。
SQL> insert /*+ append */into t select *from t;
已创建67198行。
SQL> commit;
提交完成。
SQL> insert /*+ append */into t select *from t;
已创建134396行。
SQL> commit;
提交完成。
SQL> update t set object_id=rownum;
已更新268792行。
SQL> alter table t add primary key(object_Id) nologging;
表已更改
SQL> create unique index tdix on t(object_type,created desc,object_id desc) nolo
gging;
索引已创建。
SQL> analyze table t compute statistics;
表已分析。
开始查询
按照索引排序的顺序
SQL> select /*+ first_rows */table_a.*,rownum from (select
2 /*+ first_rows */* FROM t
3 WHERE object_type='TABLE'
4 order by created desc,object_id desc ) table_a where rownum<=20
5 ;
已选择20行。
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=3791 Card=
20 Bytes=3540)
1 0 COUNT (STOPKEY)
2 1 VIEW (Cost=3791 Card=7906 Bytes=1399362)
3 2 TABLE ACCESS (BY INDEX ROWID) OF 'T' (Cost=3791 Card=7
906 Bytes=679916)
4 3 INDE