My Oracle Support Banner

Index Skip Scan Not Used When Using INLIST (Doc ID 2405538.1)

Last updated on AUGUST 04, 2018

Applies to:

Oracle Database - Enterprise Edition - Version 12.1.0.2 and later
Information in this document applies to any platform.

Goal

Why optimizer is not choosing the index skip scan in the below scenario?

Composite Index created for the two column for example S and S1 column of a table.

Why when query with more than one value in the predicate for the second column in the index which is S1, it is not choosing the index skip scan and choose the FULL Table Scan?

But when query with single value in the predicate for the second column in the index which is S1, it is choosing the index skip scan as expected.


Below is the example:

SQL> create table skipscan (s number, s1 number,s2 varchar2(100),s3 char(10),s4 varchar2(100),s5 number);

Table created.

SQL> create index sidx on skipscan (s,s1);

Index created.

SQL> insert into skipscan(s,s1) values(1,10);
insert into skipscan(s,s1) values(1,10);
insert into skipscan(s,s1) values(1,10);
insert into skipscan(s,s1) values(1,10);
insert into skipscan(s,s1) values(1,10);
insert into skipscan(s,s1) values(1,20);
insert into skipscan(s,s1) values(1,20);
insert into skipscan(s,s1) values(1,20);
insert into skipscan(s,s1) values(1,20);
insert into skipscan(s,s1) values(1,20);


SQL> commit;

Commit complete.

SQL> execute dbms_stats.gather_table_stats(user,'SKIPSCAN',method_opt=>'FOR ALL COLUMNS SIZE AUTO');

PL/SQL procedure successfully completed.

SQL> select s,s1 from skipscan;

  S S1
---------- ----------
  1 10
  1 10
  1 10
  1 10
  1 10
  1 20
  1 20
  1 20
  1 20
  1 20

10 rows selected.

SQL> select * from skipscan where s1 in (10);

  S S1
---------- ----------
S2
----------------------------------------------------------------------------------------------------
S3
----------
S4
----------------------------------------------------------------------------------------------------
  S5
----------
  1 10
  1 10 
  1 10
  1 10
  1 10

SQL> SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR);

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID 0076dwakt1q85, child number 0
-------------------------------------
select * from skipscan where s1 in (10)

Plan hash value: 1265725494

------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 2 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| SKIPSCAN | 5 | 30 | 2 (0)| 00:00:01 |
|* 2 | INDEX SKIP SCAN | SIDX | 5 | | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

  2 - access("S1"=10)
  filter("S1"=10)


20 rows selected.

SQL> select * from skipscan where s1 in (10,20);

  S S1
---------- ----------
S2
----------------------------------------------------------------------------------------------------
S3
----------
S4
----------------------------------------------------------------------------------------------------
  S5
----------
  1 10
  1 10
  1 10
  1 10
  1 10
  1 20
  1 20
  1 20
  1 20
  1 20
10 rows selected.

SQL> SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR);

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID b4xq0fkg1ptnj, child number 0
-------------------------------------
 select * from skipscan where s1 in (10,20)

Plan hash value: 604399050

------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 3 (100)| |
|* 1 | TABLE ACCESS FULL| SKIPSCAN | 10 | 60 | 3 (0)| 00:00:01 |
------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

  1 - filter(("S1"=10 OR "S1"=20))


18 rows selected
 

Solution

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!


My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.