OR Usage

August 15, 2017 ยท View on GitHub

Consider using an IN predicate when querying an indexed column:

The IN-list predicate can be exploited for indexed retrieval and also, the optimizer can sort the IN-list to match the sort sequence of the index, leading to more efficient retrieval. Note that the IN-list must contain only constants, or values that are constant during one execution of the query block, such as outer references.

Example

SELECT s.* FROM SH.sales s WHERE s.prod_id = 14 OR s.prod_id = 17

can be rewritten as:

SELECT s.* FROM SH.sales s WHERE s.prod_id IN (14, 17)