|
Archives of the TeradataForumMessage Posted: Mon, 23 Jul 2007 @ 15:33:09 GMT
Anomy.Anom wrote:
Better than what? As soon as you have to access the same table more than once, the OLAP version will probably be more efficient, especially if you're using complex views. I once run some tests and i almost any case OLAP used a lot less CPU, but typically more Spool (Because of the two spools within that STAT FUNCTION step). And OLAP functions always need the same resources regardless of the date, i.e. lots or few rows per value, whereas aggregates might vary. And because there's a join involved, the plan might change with different table sizes and rows per value. And it's easier to write... And EXPLAIN is shorter... > /*QUERY A*/ > > select > AAG.* >>from > ddedwmig_vbdw.v_ACCOUNT_ACCOUNT_GROUP AAG > CROSS JOIN CPMS_CURR_PERIOD CCP > where > Source_System_Id = '10300' and > ACCOUNT_ASSOC_START_DT between CCP.START_DT and CCP.END_DT > > qualify > row_number() over (partition by account_num, account_modifier_num, > selection_criterion_id > order by account_num ,account_modifier_num, selection_criterion_id, > account_assoc_start_dt desc ) = 1 > ; You can get rid of the "order by account_num ,account_modifier_num, selection_criterion_id", because this is already the partitioning. And i don't know if the optimizer is smart enough to recognize that, if not you'll need more spool to order by 4 rows instead of 1. "order by account_assoc_start_dt desc" > /*QUERY B */ > sel * from ddedwmig_vbdw.v_ACCOUNT_ACCOUNT_GROUP > where > (account_num, account_modifier_num, selection_criterion_id, > ACCOUNT_ASSOC_START_DT) in > ( > sel account_num, account_modifier_num, selection_criterion_id, > max(ACCOUNT_ASSOC_START_DT) from > ddedwmig_vbdw.v_ACCOUNT_ACCOUNT_GROUP CROSS JOIN CPMS_CURR_PERIOD CCP > where > Source_System_Id = '10300' and > ACCOUNT_ASSOC_START_DT between CCP.START_DT and CCP.END_DT > group by 1, 2, 3 > ) and Source_System_Id = '10300' Be carefull, you usually have to repeat the same WHERE condition for the outer query or you get a different answer set. Dieter
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Copyright 2016 - All Rights Reserved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Last Modified: 15 Jun 2023 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||