IN vs OR of Oracle, which faster?

前端 未结 5 1097
广开言路
广开言路 2020-12-03 20:44

I\'m developing an application which processes many data in Oracle database.
In some case, I have to get many object based on a given list of conditions, and I use

5条回答
  •  执念已碎
    2020-12-03 21:15

    If you create the table with a primary key:

    CREATE TABLE my_test (id NUMBER,
    CONSTRAINT PK PRIMARY KEY (id));
    

    and go through the same SELECTs to run the query with the multiple IN values, followed by retrieving the execution plan via hash value, what you get is:

    SELECT STATEMENT
    INLIST ITERATOR
    INDEX                  RANGE SCAN
    

    This seems to imply that when you have an IN list and are using this with a PK column, Oracle keeps the list internally as an "INLIST" because it is more efficient to process this, rather than converting it to ORs as in the case of an un-indexed table.

    I was using Oracle 10gR2 above.

提交回复
热议问题