正如已建议的那样,进行基准测试。一个简单的 - 2 个具有 10 和 300k 行的表 - 向我们展示了在您的条件具有高度选择性的情况下,没有巨大的差异(通过查询读取的 2 对 4 个数据库块)。
15:22:14 HR@sandbox> ed
Wrote file S:\spool\sandbox\BUFFER_HR_42.sql
1 create table table1 as
2 select decode(rownum, 5, 6, 10, 6, mod(rownum, 5)) as value from dual
3* connect by rownum <= 10
15:22:26 HR@sandbox> /
Table created.
Elapsed: 00:00:00.16
15:23:52 HR@sandbox> ed
Wrote file S:\spool\sandbox\BUFFER_HR_42.sql
1 create table table2 as
2 select decode(rownum, 1e3, 6, 5e4, 6, mod(rownum, 5)) as value from dual
3* connect by rownum <= 3e5
15:23:59 HR@sandbox> /
Table created.
Elapsed: 00:00:03.10
15:24:03 HR@sandbox> create index ix_t2_val on table2(value);
Index created.
Elapsed: 00:00:02.11
15:24:12 HR@sandbox> create index ix_t1_val on table1(value);
Index created.
Elapsed: 00:00:00.05
15:24:16 HR@sandbox> exec dbms_stats.gather_table_stats('hr','table1');
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.93
15:25:14 HR@sandbox> exec dbms_stats.gather_table_stats('hr','table2');
PL/SQL procedure successfully completed.
Elapsed: 00:00:02.19
15:25:18 HR@sandbox> select /*+index(table1 ix_t1_val)*/ * from table1 where value = 6;
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 1719610244
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 6 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IX_T1_VAL | 2 | 6 | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("VALUE"=6)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
2 consistent gets
0 physical reads
0 redo size
369 bytes sent via SQL*Net to client
363 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed
15:25:34 HR@sandbox> select /*+index(table1 ix_t2_val)*/ * from table2 where value = 6;
Elapsed: 00:00:00.02
Execution Plan
----------------------------------------------------------
Plan hash value: 4026617716
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 50000 | 146K| 99 (0)| 00:00:02 |
|* 1 | INDEX RANGE SCAN| IX_T2_VAL | 50000 | 146K| 99 (0)| 00:00:02 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("VALUE"=6)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
4 consistent gets
1 physical reads
0 redo size
369 bytes sent via SQL*Net to client
363 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed