Subject | Performance of long GROUP BY clause |
---|---|
Author | t.s. |
Post date | 2006-05-02T19:23:50Z |
Hello everyone,
I'm building several OLAP-type queries like this (for example) :
...
select m.trans_date, c.customer_code, d.product_code,
m.sales_code,
sum(qty), avg(unit_price), sum(d.qty * d.unit_price)
from sales_master m
join sales_detail d on (d.sales_master_id = m.sales_master_id)
join product p on (p.product_id = d.product_id)
join customer c on (c.customer_id = m.customer_id)
where (m.sales_date between :begin_date and :end_date)
group by m.trans_date, c.customer_code, d.product_code,
m.sales_code
...
Basically, this particular query returns the total sales grouped by
TRANS_DATE, CUSTOMER_CODE, PRODUCT_CODE, and SALES_CODE.
But to make the query more 'useful' i'd have to add more columns to the
SELECT clause, for example, i'd need the CUSTOMER_NAME, PRODUCT_NAME,
PRODUCT_DESCRIPTION, etc, etc. But this would mean that i'd also have to
add those fields to the GROUP BY clause.
My question is, given the original choice :
...
group by m.trans_date, c.customer_code, d.product_code, m.sales_code
...
vs. the expanded GROUP BY clause :
...
group by m.trans_date, c.customer_code, c.customer_name, c.address,
d.product_code, d.product_name, d.product_description,
m.sales_code, m.reference, etc, etc
...
Will the long GROUP BY clause will be a problem performance-wise?
Thank you very much in advance.
Regards,
t.s.
I'm building several OLAP-type queries like this (for example) :
...
select m.trans_date, c.customer_code, d.product_code,
m.sales_code,
sum(qty), avg(unit_price), sum(d.qty * d.unit_price)
from sales_master m
join sales_detail d on (d.sales_master_id = m.sales_master_id)
join product p on (p.product_id = d.product_id)
join customer c on (c.customer_id = m.customer_id)
where (m.sales_date between :begin_date and :end_date)
group by m.trans_date, c.customer_code, d.product_code,
m.sales_code
...
Basically, this particular query returns the total sales grouped by
TRANS_DATE, CUSTOMER_CODE, PRODUCT_CODE, and SALES_CODE.
But to make the query more 'useful' i'd have to add more columns to the
SELECT clause, for example, i'd need the CUSTOMER_NAME, PRODUCT_NAME,
PRODUCT_DESCRIPTION, etc, etc. But this would mean that i'd also have to
add those fields to the GROUP BY clause.
My question is, given the original choice :
...
group by m.trans_date, c.customer_code, d.product_code, m.sales_code
...
vs. the expanded GROUP BY clause :
...
group by m.trans_date, c.customer_code, c.customer_name, c.address,
d.product_code, d.product_name, d.product_description,
m.sales_code, m.reference, etc, etc
...
Will the long GROUP BY clause will be a problem performance-wise?
Thank you very much in advance.
Regards,
t.s.