Subject | Re: [ib-support] Summarization Query Speed Issue |
---|---|
Author | Arno Brinkman |
Post date | 2003-03-03T10:08:21Z |
Hi,
In FB1.5 both will work.
SELECT
p.productID,
(select sum(o.qty) from orderdetail o where p.productid = o.productid)) AS
Sum_Qty
FROM
product p
GROUP BY
p.productID
Regards,
Arno Brinkman
> >CASE 2 : Same as CASE 1, Change JOIN to LEFT JOIN.where
> > select p.productID, sum(o.qty)
> > from product p
> > LEFT JOIN orderdetail o on (p.productid = o.productid)
> > group by p.productID
> >RESULT:
> >- PLAN SORT (JOIN (P NATURAL,O INDEX (FK_ORDERDET_REFERENCE_ITEMS)))
> >- First run: approx 32 seconds
> >- Subsequent runs: approx 20 seconds.
> >QUESTIONS:
> >1. I read somewhere in this list that any occurence of 'NATURAL' in a
> >plan means that the query is not optimized. Is it the case here?
> >2. The only difference with CASE 1 is the left join, but the performance
> >drops is unacceptable in this case. Is there anything I can do to speed
> >this up?
>
> There is nothing wrong with NATURAL in your plan, since you do not specify
> any WHERE clause, NATURAL is the quickest plan it can possibly use for the
> first table. It is far worse if NATURAL occurs in subsequent tables in the
> plan (e.g. you should definitely try to avoid NATURAL for O).
>
> What could be worth trying, is
>
> select distinct p.productID, (select sum(o.qty) from orderdetail o
> p.productid = o.productid)) AS Sum_QtyI think in FB1 this query doesn't work, maybe the next will.
> from product p
In FB1.5 both will work.
SELECT
p.productID,
(select sum(o.qty) from orderdetail o where p.productid = o.productid)) AS
Sum_Qty
FROM
product p
GROUP BY
p.productID
Regards,
Arno Brinkman