Subject | Re: Why does this query take forever in FB?!?! |
---|---|
Author | Alexander V.Nevsky |
Post date | 2004-05-06T15:03:41Z |
--- In firebird-support@yahoogroups.com, "rjschappe" <rschappe@i...>
wrote:
Why. Because FB serves IN (Select ...) scanning table in main select
and performing subquery. Seemingly, MS SQL perform subselect once and
perhaps use indices on main table if it is possible.
How.
select LO.Color, LO.Width, LO.LamLength
from LamOrder LO join OrderItem OI on LO.CustOrder=OI.CustOrder
join LamColor LC on OI.Color = LC.ID
where (OI.ItemFlags=1 or OI.ItemFlags=3)
and LC.LamMaker=4
Best regards,
Alexander
wrote:
> I have what I thought was a fairly simple query, it runs in less thanRaymond, let me answer in descending order.
> 5 seconds on a very old MS SQL Server 7 box with very little RAM but
> it is _still_ running (30 mins) on my Firebird 1.5 box which is
> _much_ better equipt hardware wise.
> in FB here is the query
> ==================================
> select LamOrder.Color, LamOrder.Width, LamOrder.LamLength
> from LamOrder
> where LamOrder.CustOrder in (
> select OrderItem.CustOrder
> from OrderItem join LamColor on (OrderItem.Color = LamColor.ID)
> where ((OrderItem.ItemFlags=1) or (OrderItem.ItemFlags=3))
> and LamColor.LamMaker=4
> )
>
> I guess there are two questions here... one is how to optimize ths
> query, but the other is why is there such a difference between the
> same query running under MS SQL Server 7 and Firebird 1.5?
Why. Because FB serves IN (Select ...) scanning table in main select
and performing subquery. Seemingly, MS SQL perform subselect once and
perhaps use indices on main table if it is possible.
How.
select LO.Color, LO.Width, LO.LamLength
from LamOrder LO join OrderItem OI on LO.CustOrder=OI.CustOrder
join LamColor LC on OI.Color = LC.ID
where (OI.ItemFlags=1 or OI.ItemFlags=3)
and LC.LamMaker=4
Best regards,
Alexander