Sub topic 2
Implicit conversions that disable an index
This chapter assumes you know basic SELECT, WHERE, and ORDER BY syntax, the Oracle types VARCHAR2 and NUMBER, and what a B-tree index is. You should be able to run EXPLAIN PLAN in SQL*Plus or SQL Developer.
Implicit conversions that disable an index
An implicit conversion happens when Oracle silently changes a value's data type so that both sides of a comparison match. If Oracle converts the column, the optimizer cannot search the index on that column by value. Every row must be converted before it is compared.
-- phone_number is VARCHAR2. Oracle converts the column, so the index is skipped.
SELECT customer_id FROM customers WHERE phone_number = 5551234;
-- A literal of the column's own type lets the index be used.
SELECT customer_id FROM customers WHERE phone_number = '5551234';LIKE and leading wildcards
A B-tree index stores values in order from the first character. A pattern with a fixed prefix can jump to the right starting point. A leading % forces Oracle to examine every index entry.
-- Fixed prefix: an index range scan is possible.
SELECT customer_id FROM customers WHERE last_name LIKE 'Smi%';
-- Leading wildcard: the index cannot narrow the search.
SELECT customer_id FROM customers WHERE last_name LIKE '%ith';NULLs and what B-tree indexes store
A standard B-tree index does not store an entry for a row whose indexed columns are all NULL. A predicate such as IS NULL therefore cannot use that index. Adding a non-null constant as a second column makes every row appear in the index.
CREATE INDEX employees_commission_nn_ix ON employees (commission_pct, 0);
SELECT employee_id FROM employees WHERE commission_pct IS NULL;Composite indexes and the leading column
A composite index sorts rows by its first column, then by the second column within each value of the first. A query that constrains the leading column can use the index for a range scan. A query that filters only on the second column generally cannot.
CREATE INDEX orders_cust_date_ix ON orders (customer_id, order_date);
-- Constrains the leading column: efficient range scan.
SELECT order_id FROM orders
WHERE customer_id = 42
AND order_date >= DATE '2026-01-01'
AND order_date < DATE '2026-02-01';Access and filter predicates in a plan
Run EXPLAIN PLAN, then display the result with DBMS_XPLAN. The Predicate Information section separates two kinds of predicates. Access predicates determine which index entries Oracle reads. Filter predicates are checked on rows after they are read.
Exercise
An index exists on orders (customerid, orderdate). Can a query that filters only on order_date use a range scan on this index?
Show answer
Generally no. The leading column, customer_id, is unconstrained, so Oracle cannot locate a starting point in the index.