Subject | RE: [firebird-support] CTE performance |
---|---|
Author | Leyne, Sean |
Post date | 2009-08-16T19:55:48Z |
Hi, Vlad,
<SL> Actually, it was Sean who replied ;-)
salesperson, and compare it to CTE_3.VENDAS_MES_1, which is the total
sales in month 1, and so on. The final select would be like this:
<SL> I would suggest you try to replace the CTEs with temporary tables/GTTs to store some intermediate data values for the query. GTT would allow for the values to be placed into the appropriate month columns/slots and also have indexes added to facilitate appropriate joins.
Sean
P.S. I also think that you could merge CTE_1 and CTE_2 into a single step with appropriate GROUP BY clause
<SL> Actually, it was Sean who replied ;-)
> 3 - No elements/columns of CTE_3 is referenced anywhere in the final query... so why it is there?I get CTE_2.VENDAS_MES_1, which is the sales in month 1 for a
salesperson, and compare it to CTE_3.VENDAS_MES_1, which is the total
sales in month 1, and so on. The final select would be like this:
<SL> I would suggest you try to replace the CTEs with temporary tables/GTTs to store some intermediate data values for the query. GTT would allow for the values to be placed into the appropriate month columns/slots and also have indexes added to facilitate appropriate joins.
Sean
P.S. I also think that you could merge CTE_1 and CTE_2 into a single step with appropriate GROUP BY clause