Optimizing single-table queries
What about ORs
Not all of the plans used for AND can be adapted:
Query
select c
from R
where a = 1 or b = 10
Let's consider the possible plans:
- No index: TableScan followed
by SelectScan always works.
- Index on a: Don't bother! Still have to do a TableScan
for the predicate on b.
- Index on b: Same, TableScan still necessary.
- Index on (a, b) or (b, a): Could scan the index
for qualifying rows, but there is no useful search of the index.
- Combine indexes on a and b: This works, (see the
bitmap scan example).
- Covering indexes: Scan the index instead of the table.
|