Subject | Re: index slows down the query |
---|---|
Author | Svein Erling |
Post date | 2004-02-24T13:18:22Z |
--- In firebird-support@yahoogroups.com, anand wrote:
several indexes covering "Client"."Client No" so that Arnos optimizer
gets confused?
By the way, if "Client No" is distinct for any record in client, then
you can simply do
select count(distinct "Client"."Client No")
FROM "Client"
JOIN "Booking" on "Booking"."Client No" = "Client"."Client No"
WHERE "Booking"."End Date" between '02-feb-2001' AND '02-may-2001' and
"Booking"."Start Date" '02-feb-2001' AND '02-may-2001'
distinct. No-one knows the optimizer better than him.
should be fast if your indexes are properly defined (though slow and
fast are relative terms - how slow is slow?).
Set
> select count(*)??? Why doesn't client use an index for "Client No"? Have you defined
> FROM "Client" WHERE "Client"."Client No" in
> (
> SELECT DISTINCT "Booking"."Client No" FROM "Booking"
> WHERE "Booking"."End Date" >= '02-feb-2001' AND
> "Booking"."Start Date" <= '02-may-2001'
> )
> Plan:
> PLAN (Booking INDEX (IDX_Booking3,IDX_Booking))
> PLAN (Client NATURAL)
several indexes covering "Client"."Client No" so that Arnos optimizer
gets confused?
By the way, if "Client No" is distinct for any record in client, then
you can simply do
select count(distinct "Client"."Client No")
FROM "Client"
JOIN "Booking" on "Booking"."Client No" = "Client"."Client No"
WHERE "Booking"."End Date" between '02-feb-2001' AND '02-may-2001' and
"Booking"."Start Date" '02-feb-2001' AND '02-may-2001'
> |> the DISTINCT is unneeded here.When Arno says you can remove the distinct, you can remove the
>
> there can be more than one booking for one client so
> distinct reomove the duplicate rec in the sub query.
distinct. No-one knows the optimizer better than him.
> i tried Exists it works similar to in statement veryShow us the definition of all indexes and keys in these tables, exists
> slow.
should be fast if your indexes are properly defined (though slow and
fast are relative terms - how slow is slow?).
Set