INDEX RANGE SCAN and INDEX UNIQUE SCAN

Had some time to dwell on INDEX RANGE SCAN and INDEX UNIQUE SCAN when the number of rows in a table are unique.
Consider,
create table temp as
select object_id from dba_objects
/
Now, we create a unique index on this table
SQL> create unique index id1 on temp(object_id) compute statistics
2 /
Index created.
Now, if I give
SQL> select 'x' from temp where object_id='5642'
2 /
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=3)
1 0 INDEX (UNIQUE SCAN) OF 'ID1' (UNIQUE) (Cost=1 Card=1 Bytes
=3)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2 consistent gets
0 physical reads
0 redo size
211 bytes sent via SQL*Net to client
276 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
Now, If the unique index is dropped and a normal index is created, we get
SQL> create index id1 on temp(object_id) compute statistics
2 /
SQL> select 'x' from temp where object_id='5642'
2 /
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=3)
1 0 INDEX (RANGE SCAN) OF 'ID1' (NON-UNIQUE) (Cost=1 Card=1 By
tes=3)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
211 bytes sent via SQL*Net to client
276 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
Why do we have an additional '1' consistent gets in this case?

No comments:

Post a Comment