Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Index Not Used with Parameterized Query
The following query returns its results from our database in well
under a second-
SELECT
DISTINCT I.COL1,
I.COL2,
E.COL3,
E.COL1
FROM
TABLE1 I,
TABLE2 E
WHERE
I.COL1 = E.COL1 AND
I.COL2 LIKE 'AVALUE%'
If we convert the query to use a bind variable-
SELECT
DISTINCT I.COL1,
I.COL2,
E.COL3,
E.COL1
FROM
TABLE1 I,
TABLE2 E
WHERE
I.COL1 = E.COL1 AND
I.COL2 LIKE :LastName
and specify the parameter as 'AVALUE%' we get the same resultset, but the query takes 25-50 seconds. Running a trace on the server reveals that the index on E.COL1 is being used in the first case and is not used in the second case. Can anyone explain to me why the index isn't used in the latter example and what changes I can make to ensure that it is used?
Thanks,
Biff Gaut
Gaithersburg, MD
Received on Tue Dec 23 2003 - 19:18:06 CST