-
I have a sql similar to the following:
select * from table a, table b
where a.pk = b.fk
and (a.code = 'X' and b.val > 1)
or (a.code = 'Y' and b.val < 1)
When I do the explain plan with the last line in there, I get full table scans. Why??
Is there a good book on how to tune up SQL and understanding the explain plan?
Thanks,
Paul
-
Does enclosing your OR-ed condition into parenthesis change the execution plan? It certainly does change the queries logic, and I'm sure it returns the resultset you actualy wanted. In other words, I think your original query does not return rows that you actualy want!
select * from table a, table b
where a.pk = b.fk
and
(
(a.code = 'X' and b.val > 1)
or (a.code = 'Y' and b.val < 1)
)
-
Thank you!!
That was my problem.
Explain plan now shows by index range scan.
Perfect.