Subject Re: Performance troubles
Author Ali Gökçen
Hi,

> select contactno from contacts c
> where
> state in (1,2)
> and
> (select sum(giftvalue) from gifts g where g.contactno =
c.contactno
> and someotherfield = 'somvalue') >= 100
>
> This takes several hours (contacts haves about 55,000 record and

several hours too much for this query, it shouldn't took so much.

is there index on sate? if not, FB will read all contacts * related
gifts.

is there too much gifts for a contact? if so index on someotherfield
will help for performance.


if indexes ok, this shouldnt be took several hours:

select contactno from contacts c
where state in(1,2)
exists(select sum(giftvalue)
from gifts
where contactno = c.contactno
and someotherfield = 'somevalue'
having sum(giftvalue)>=100
)

Regards.
Ali