create table t1
as
with generator as (
select --+ materialize
rownum id
from dual
connect by
level <= 10000
)
select
trunc((rownum-1)/2) product_id,
mod(rownum-1,2) flag1,
mod(rownum-1,3) flag2,
rownum n1,
lpad(rownum,30) v1
from
generator v1,
generator v2
where
rownum <= 1000000
;
alter table t1 add constraint t1_pk primary key (product_id,flag1, flag2)
using index (
create unique index t1_pk on t1(product_id, flag1, flag2)
);
create index t1_i1 on t1(product_id, flag2, flag1, n1,v1);
exec dbms_stats.gather_table_stats(ownname=>USER, tabname=>'t1',Estimate_Percent => NULL);
SQL> set autotrace traceonly
SQL> select rowid from t1 where product_id = 2500 ;
Execution Plan
----------------------------------------------------------
Plan hash value: 3836157954
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 34 | 3 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| T1_I1 | 2 | 34 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("PRODUCT_ID"=2500)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
605 bytes sent via SQL*Net to client
519 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed
SQL> select /*+ index(t1 t1_pk) */ rowid from t1 where product_id = 2500 ;
Execution Plan
----------------------------------------------------------
Plan hash value: 1838269289
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 34 | 3 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| T1_PK | 2 | 34 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("PRODUCT_ID"=2500)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
605 bytes sent via SQL*Net to client
519 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed
SQL> SELECT index_name, blevel, leaf_blocks, clustering_factor, distinct_keys FROM dba_indexes
WHERE table_name = 'T1';
INDEX_NAME BLEVEL LEAF_BLOCKS CLUSTERING_FACTOR DISTINCT_KEYS
------------------------------ ---------- ----------- ----------------- -------------
T1_I1 2 7996 7154 1000000
T1_PK 2 2807 7088 1000000
SQL> alter index "SCOTT"."T1_I1" rename to T1_XX;
SQL> set autotrace traceonly
SQL> sElect rowid from t1 where product_id = 2500 ;
Execution Plan
----------------------------------------------------------
Plan hash value: 1838269289
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 34 | 3 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| T1_PK | 2 | 34 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("PRODUCT_ID"=2500)Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
605 bytes sent via SQL*Net to client
519 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-717334/ ,如需转载,请注明出处,否则将追究法律责任。