 |
|
Oracle SQL and-equal data access
method
Oracle Database Tips by Donald Burleson |
When Oracle prepares an
execution plan for SQL statements, he builds a costed decision tree with
different access methods. The and-equal is one such access method which
was widely used in the rule-based optimizer (RBO) but is now largely obsolete.
(the and-equal hint is still supported in the CBO).
Using ?and_equal? Hints To
Concatenate Indexes:
Index1
column1_primary key
Index2
column2
Index3
column1
column2 ?
Index4
column2
column1 ?
In this case index3 and 4 were created for multiple column queries with some
lead columns on 1 and some lead columns on 2.
In this case Index 3 and 4 could be removed and multi-column queries
that use column1 and 2 can use the ?and_equal? hint to cause the optimizer
to use index1 and index2 before accessing the table with rowids.
Using the ?and_equal? hint does have additional overhead since two
indexes must be read. You have
to balance the overhead of two reading two indexes against the overhead of
the additional indexes.
I also find cases where Index3 and Index4 were added to support queries that
contained both column1 and column2 in separate WHERE clauses.
These indexes were added because in some queries column1 is more
restrictive (so it is the lead column) and in other queries column2 is more
restrictive (and thus the lead column).
In fact either Index3 or Index4 (or using the ?and_equal? hint) will
satisfy the query and will have equivalent performance.
You are also relying on the optimizer to pick the correct index to
use, which is unlikely. Having
the lead column the most restrictive column will not affect the index
performance. In this case you
can drop either Index3 or Index4 and not affect query performance.
Remember that leading columns are only important in that they must be used
in the WHERE clause for the index to be used.
Oracle 9i introduced the index skip scan that allows you to use an
index where the lead column is
not in the where clause, but this requires more overhead than performance
benefit.
This page
has excellent notes on the and-equal access method:
SELECT *
FROM my_table
WHERE column5 = 230
AND column8 = 'BLORT'
SELECT STATEMENT
TABLE ACCESS MY_TABLE BY ROWID
AND-EQUAL
NON-UNIQUE INDEX RANGE SCAN MY_TABLE_I5
NON-UNIQUE INDEX RANGE SCAN MY_TABLE_I8
The and-equal access method
scans all nominated single column indexes used in AND col1 = xxx and col2=yyy,
where both col1 and col2 have non-unique single key indexes on
them.
The and-equal hint is specified
in this form:
/*+ AND_EQUAL ( table index index [index]
[index] [index] ) */
|
|
Get the Complete
Oracle SQL Tuning Information
The landmark book
"Advanced Oracle
SQL Tuning The Definitive Reference" is
filled with valuable information on Oracle SQL Tuning.
This book includes scripts and tools to hypercharge Oracle 11g
performance and you can
buy it
for 30% off directly from the publisher.
|