Hi,
I am on Oracle 9.2 on HP Unix and getting more confused about the optimizer.
Please have a look at following steps I performed,
-- ----- Created empty table ---------
SQL> create table r1 as select * from all_objects where 1=2 ;
Table created.
SQL> select count(*) from r1 ;
COUNT(*)
----------
0
SQL> create index r1_ind1 on r1 (object_id) ;
Index created.
-- ----- I am collecting the stats when the table is empty -------
SQL> exec dbms_stats.gather_table_stats('USER1','R1');
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.gather_index_stats('USER1','R1_IND1');
PL/SQL procedure successfully completed.
-- ---- Putting some data -----------
SQL> insert into r1 select * from all_objects ;
43107 rows created.
SQL> commit ;
Commit complete.
-- --- data in the table and stats do not match ---
SQL> set autotrace traceonly explain
SQL> select * from r1 where object_id=311098;
Execution Plan
----------------------------------------------------------
0
SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=128)
1 0
TABLE ACCESS (BY INDEX ROWID) OF 'R1' (Cost=1 Card=1 Bytes=128)
2 1
INDEX (RANGE SCAN) OF 'R1_IND1' (NON-UNIQUE) (Cost=1 Card=1)
SQL> set autotrace off
SQL> l
1* select num_rows from user_tables where table_name='R1'
SQL> /
NUM_ROWS
----------
0
I was expecting that Oracle will go for full table scan, but it used index.
Also, look at the cardinality in the plan, "Card=1", still the index is used. How very confusing ???
Can anybody help ?
Regards
I am on Oracle 9.2 on HP Unix and getting more confused about the optimizer.
Please have a look at following steps I performed,
-- ----- Created empty table ---------
SQL> create table r1 as select * from all_objects where 1=2 ;
Table created.
SQL> select count(*) from r1 ;
COUNT(*)
----------
0
SQL> create index r1_ind1 on r1 (object_id) ;
Index created.
-- ----- I am collecting the stats when the table is empty -------
SQL> exec dbms_stats.gather_table_stats('USER1','R1');
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.gather_index_stats('USER1','R1_IND1');
PL/SQL procedure successfully completed.
-- ---- Putting some data -----------
SQL> insert into r1 select * from all_objects ;
43107 rows created.
SQL> commit ;
Commit complete.
-- --- data in the table and stats do not match ---
SQL> set autotrace traceonly explain
SQL> select * from r1 where object_id=311098;
Execution Plan
----------------------------------------------------------
0
SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=128)
1 0
TABLE ACCESS (BY INDEX ROWID) OF 'R1' (Cost=1 Card=1 Bytes=128)
2 1
INDEX (RANGE SCAN) OF 'R1_IND1' (NON-UNIQUE) (Cost=1 Card=1)
SQL> set autotrace off
SQL> l
1* select num_rows from user_tables where table_name='R1'
SQL> /
NUM_ROWS
----------
0
I was expecting that Oracle will go for full table scan, but it used index.
Also, look at the cardinality in the plan, "Card=1", still the index is used. How very confusing ???
Can anybody help ?
Regards