Subject Re: Is "EXISTS()" cheap?
Author Ali Gökçen
Hi Bambang,
if you want to sure about using of the index then check it via any
tool.

select 'Yup i am the fastest!' from holiday
where cast('19.09.2005' as date) between startdate and enddate

take a look to the query plan.
if there is no index usage (should be two index) then warn Arno
about it. ;)
Thats all.

Regards,

-Ali

--- In firebird-support@yahoogroups.com, Bambang P <bpranoto@g...>
wrote:
> On Friday, September 16, 2005, 7:03:41 PM, Ali Gökçen wrote:
> > --- In firebird-support@yahoogroups.com, Bambang P
<bpranoto@g...>
> > wrote:
> >> In this stored procedure statement:
> >>
> >> if (exists(select 1 from HOLIDAYS where ADate>=DSTART and
> > AData<=DEND))
> >> then begin
> >> .....
> >> end
> >>
> >> Question:
> >>
> >> Does the select statement step through all records which meet
the
> > condition
> >> or does it return immediately after the first occurance of the
> > condition?
>
>
> > Hi,
> > it is not free but cheapest, if there is an index on ADate field.
>
> > ... where ADate between DSTART and DEND ..
> > isn't more clear?
>
> Sorry, I was wrong in my example. ADate is a variable while DSTART
and
> DEND is fields. Indexes on DSTART and DEND are available.
>
> I am rephrasing my example with your suggestion:
>
> if (exists(select 1 from HOLIDAYS where where :ADate between DSTART
> and DEND)) then begin
> ....
>
> The question remains:
>
> Does the select statement step through all records which meet the
> condition?
>
> or
>
> Does it return immediately after the first occurance of the
> condition?
>
> Thanks anyway.
>
> --
> Bambang P.
>
>
> I want to move to Theory...Everything works in Theory