Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Performance question - query with OR
On 9 Apr 1998 20:21:50 GMT, "KenParis" <KenParis_at_prodigy.net> wrote:
>I need help on Oracle performance. I don't have direct access to
>Oracle - it's all being done by a remote associate.
>
>We are executing a query of the form:
>
>SELECT columns
>FROM table
>
>WHERE (column_1 = value1
> AND column_2 = value2
> AND column_3 = value3)
>
>OR (column_1 = value1
> AND column_2 > value2)
>
>OR (column_1 > value1)
>
>ORDER BY column_1, column_2, column_3
>
>Even though we have an index on column_1, column_2 and column_3, Oracle
>still
>does a sort (I'm told it doesn't like the OR). We tried rewriting this
>using the more
>complicated but equivalent version replacing the ORs with AND NOTs (among
>other
>changes), but this was worse.
Hi Ken,
queries with or-expressions often give bad performance because the optimized chose to do a full table scan. You can replace such constructs with an equivalent union-all statement:
SELECT columns
FROM table WHERE ( column_1 = value1 AND column_2 = value2 AND column_3 = value3 )
FROM table WHERE ( column_1 = value1 AND column_2 > value2 )
FROM table WHERE ( column_1 > value1 )
This query should give better performance. If not, don't blame it on me :-) - instead check the following:
What is your optimizer mode ? If it is CBO you need to have recent statistics for your tables and indexes. Is your sort_area_size configured suffiently large ? Have you distributed data and indexes properly to different physical disk drives ?
HTH
Peter
--
Peter Schneider
peter.schneider_at_okay.net
Received on Thu Apr 09 1998 - 18:45:20 CDT
![]() |
![]() |