Re: Oracle Logical Operator order of execution

From: Wally <wallyraju_at_gmail.com>
Date: Tue, 1 Apr 2008 12:43:00 -0700 (PDT)
Message-ID: <27d7e4b2-f4c2-4c03-848f-29d85355f7eb@l42g2000hsc.googlegroups.com>


On Apr 1, 2:32 pm, hpuxrac <johnbhur..._at_sbcglobal.net> wrote:
> On Apr 1, 3:05 pm, Wally <wallyr..._at_gmail.com> wrote:
>
>
>
> > Oracle 10g R2
> > Win 2003
>
> > I have a select statement which is similar to
>
> > select * from test
> > where
> > a = v_number
> > or
> > b between v_date_low and v_date_high;
>
> > In my database , I know for a fact that only one of these conditions
> > will be true at any given time
>
> > Can someone tell me if Oracle calculates the left side of the OR
> > operator first or the right side because I don't want Oracle to waste
> > processor cycles calculating one condition when the other is already
> > true. I can change the query to the one below if need be
>
> > select * from test
> > where
> > b < v_date
> > or
> > a = v_num;
>
> > Thanks in advance.
>
> Oracle's cost based optimizer may not look at both sides of an or and
> there is no guarantee that it will always start on one side or the
> other. Similarly with an "and" condition it may use one side or
> another to use indexes and then eliminate rows after they are returned
> as possible hits.
>
> If you are running a recent release you may want to get familiar with
> dbms_xplan.display

Thanks hpuxrac. Received on Tue Apr 01 2008 - 14:43:00 CDT

Original text of this message