SlideShare ist ein Scribd-Unternehmen logo
1 von 85
Downloaden Sie, um offline zu lesen
GROUPING SETS 
CCUBE, ROLLUP, and Friends 
SFPUG 2014/11/18 
Copyright© 2014 
David Fetter 
Tuesday, November 18, 14
Thanks, 
Tuesday, November 18, 14
Why?!? 
Tuesday, November 18, 14
Analyzing 
Tuesday, November 18, 14
Reporting 
Tuesday, November 18, 14
Tuesday, November 18, 14
• CUBE (Power set/Ring the changes) 
• ROLLUP (Hierarchy) 
• GROUPING SETS (Precision) 
Tuesday, November 18, 14
Shhh. A little code. 
Tuesday, November 18, 14
CREATE TABLE employee ( 
id SERIAL PRIMARY KEY, 
first_name TEXT, 
last_name TEXT 
); 
CREATE TABLE sales ( 
employee_id INTEGER NOT NULL, 
sale_closed TIMESTAMPTZ NOT NULL DEFAULT NOW(), 
sale_amount MONEY, /* We need to do fix this */ 
FOREIGN KEY(employee_id) REFERENCES employee(id) 
); 
Tables 
Tuesday, November 18, 14
Data 
INSERT INTO employee (first_name, last_name) 
VALUES ('Larry', 'Ellison'), 
('Bill', 'Gates'), 
('Vladimir', 'Yulianov'); 
Tuesday, November 18, 14
Moar Data 
INSERT INTO sales 
SELECT 
floor(random()*3)+1, /* Who */ 
'2014-01-01 00:00:00+00'::timestamptz + 
random() * interval '1 year', /* When */ 
(random() * 1000)::numeric(8,2)::MONEY /* ¿Cuando? */ 
FROM generate_series(1,1000); 
Tuesday, November 18, 14
How much did each sell each quarter? 
Tuesday, November 18, 14
SIMPLE! 
Tuesday, November 18, 14
SELECT 
employee_id, 
date_trunc('Quarter', sale_closed) AS "Quarter", 
SUM(sale_amount) 
FROM sales 
GROUP BY 
employee_id, 
date_trunc('Quarter', sale_closed) 
ORDER BY 
employee_id, 
date_trunc('Quarter', sale_closed); 
* I left out some formatting. 
Tuesday, November 18, 14
Results: 
!"""""""""""""#"""""""""#""""""""""""$ 
% employee_id % Quarter % sum % 
&"""""""""""""'"""""""""'""""""""""""( 
% 1 % 2014-Q1 % $42,227.43 % 
% 1 % 2014-Q2 % $42,974.71 % 
% 1 % 2014-Q3 % $41,364.66 % 
% 1 % 2014-Q4 % $33,910.34 % 
% 2 % 2014-Q1 % $38,733.24 % 
% 2 % 2014-Q2 % $40,480.96 % 
% 2 % 2014-Q3 % $43,875.72 % 
% 2 % 2014-Q4 % $42,041.28 % 
% 3 % 2014-Q1 % $45,351.14 % 
% 3 % 2014-Q2 % $36,672.08 % 
% 3 % 2014-Q3 % $33,468.46 % 
% 3 % 2014-Q4 % $42,793.36 % 
)"""""""""""""*"""""""""*""""""""""""+ 
(12 rows) 
Tuesday, November 18, 14
That's nice, BUT 
(We all grimace when we hear that) 
Tuesday, November 18, 14
How about annual totals? 
Tuesday, November 18, 14
Old way: 
UNION ALL 
Tuesday, November 18, 14
( 
SELECT employee_id, to_char(date_trunc('Quarter', sale_closed), 
'YYYY-"Q"Q') AS "Quarter", sum(sale_amount) 
FROM sales 
GROUP BY employee_id, date_trunc('Quarter', sale_closed) 
ORDER BY employee_id, date_trunc('Quarter', sale_closed) 
) 
UNION ALL 
( 
SELECT employee_id, to_char(date_trunc('Year', sale_closed), 
'YYYY') AS "Year", sum(sale_amount) 
FROM sales 
GROUP BY employee_id, date_trunc('Year', sale_closed) 
ORDER BY employee_id, date_trunc('Year', sale_closed) 
); 
Still Doable...Kinda 
Tuesday, November 18, 14
Results 
!"""""""""""""#"""""""""#"""""""""""""$ 
% employee_id % Quarter % sum % 
&"""""""""""""'"""""""""'"""""""""""""( 
% 1 % 2014-Q1 % $42,227.43 % 
% 1 % 2014-Q2 % $42,974.71 % 
% 1 % 2014-Q3 % $41,364.66 % 
% 1 % 2014-Q4 % $33,910.34 % 
% 2 % 2014-Q1 % $38,733.24 % 
% 2 % 2014-Q2 % $40,480.96 % 
% 2 % 2014-Q3 % $43,875.72 % 
% 2 % 2014-Q4 % $42,041.28 % 
% 3 % 2014-Q1 % $45,351.14 % 
% 3 % 2014-Q2 % $36,672.08 % 
% 3 % 2014-Q3 % $33,468.46 % 
% 3 % 2014-Q4 % $42,793.36 % 
% 1 % 2014 % $160,477.14 % 
% 2 % 2014 % $165,131.20 % 
% 3 % 2014 % $158,285.04 % 
)"""""""""""""*"""""""""*"""""""""""""+ 
(15 rows) 
Tuesday, November 18, 14
That's nice, BUT 
Tuesday, November 18, 14
Can't we look at each sales rep 
with each of their quarterly 
totals? 
Tuesday, November 18, 14
ARGHH!!!!!! 
Tuesday, November 18, 14
Tuesday, November 18, 14
These requests are reasonable! 
Tuesday, November 18, 14
But the code...not so much. 
Tuesday, November 18, 14
Take it from the top! 
Tuesday, November 18, 14
CUBE...ring the changes... 
Tuesday, November 18, 14
Quick stare 
SELECT 
employee_id, 
to_char( 
date_trunc('Quarter', sale_closed), 
'YYYY-"Q"Q' 
) AS "Quarter", 
sum(sale_amount) 
FROM sales 
GROUP BY CUBE ( 
employee_id, 
date_trunc('Quarter', sale_closed) 
) 
ORDER BY employee_id, date_trunc('Quarter', sale_closed); 
Tuesday, November 18, 14
Results: 
!"""""""""""""#"""""""""#"""""""""""""$ 
% employee_id % Quarter % sum % 
&"""""""""""""'"""""""""'"""""""""""""( 
% 1 % 2014-Q1 % $42,227.43 % 
% 1 % 2014-Q2 % $42,974.71 % 
% 1 % 2014-Q3 % $41,364.66 % 
% 1 % 2014-Q4 % $33,910.34 % 
% 1 % % $160,477.14 % 
% 2 % 2014-Q1 % $38,733.24 % 
% 2 % 2014-Q2 % $40,480.96 % 
% 2 % 2014-Q3 % $43,875.72 % 
% 2 % 2014-Q4 % $42,041.28 % 
% 2 % % $165,131.20 % 
% 3 % 2014-Q1 % $45,351.14 % 
% 3 % 2014-Q2 % $36,672.08 % 
% 3 % 2014-Q3 % $33,468.46 % 
% 3 % 2014-Q4 % $42,793.36 % 
% 3 % % $158,285.04 % 
% % 2014-Q1 % $126,311.81 % 
% % 2014-Q2 % $120,127.75 % 
% % 2014-Q3 % $118,708.84 % 
% % 2014-Q4 % $118,744.98 % 
% % % $483,893.38 % 
)"""""""""""""*"""""""""*"""""""""""""+ 
(20 rows) 
Tuesday, November 18, 14
That's nice, BUT 
Tuesday, November 18, 14
We don't care 
about undifferentiated 
quarterly totals. 
Tuesday, November 18, 14
Results: 
!"""""""""""""#"""""""""#"""""""""""""$ 
% employee_id % Quarter % sum % 
&"""""""""""""'"""""""""'"""""""""""""( 
% 1 % 2014-Q1 % $42,227.43 % 
% 1 % 2014-Q2 % $42,974.71 % 
% 1 % 2014-Q3 % $41,364.66 % 
% 1 % 2014-Q4 % $33,910.34 % 
% 1 % % $160,477.14 % 
% 2 % 2014-Q1 % $38,733.24 % 
% 2 % 2014-Q2 % $40,480.96 % 
% 2 % 2014-Q3 % $43,875.72 % 
% 2 % 2014-Q4 % $42,041.28 % 
% 2 % % $165,131.20 % 
% 3 % 2014-Q1 % $45,351.14 % 
% 3 % 2014-Q2 % $36,672.08 % 
% 3 % 2014-Q3 % $33,468.46 % 
% 3 % 2014-Q4 % $42,793.36 % 
% 3 % % $158,285.04 % 
% % 2014-Q1 % $126,311.81 % 
% % 2014-Q2 % $120,127.75 % 
% % 2014-Q3 % $118,708.84 % 
% % 2014-Q4 % $118,744.98 % 
% % % $483,893.38 % 
)"""""""""""""*"""""""""*"""""""""""""+ 
(20 rows) 
Tuesday, November 18, 14
ROLLUP...hierarchy... 
Tuesday, November 18, 14
Let's try that! 
Tuesday, November 18, 14
SELECT 
employee_id, 
to_char( 
date_trunc('Quarter', sale_closed), 
'YYYY-"Q"Q' 
) AS "Quarter", 
sum(sale_amount) 
FROM sales 
GROUP BY ROLLUP( 
employee_id, 
date_trunc('Quarter', sale_closed) 
) 
ORDER BY 
employee_id, 
date_trunc('Quarter', sale_closed); 
Tuesday, November 18, 14
Hmmm... 
!"""""""""""""#"""""""""#"""""""""""""$ 
% employee_id % Quarter % sum % 
&"""""""""""""'"""""""""'"""""""""""""( 
% 1 % 2014-Q1 % $42,227.43 % 
% 1 % 2014-Q2 % $42,974.71 % 
% 1 % 2014-Q3 % $41,364.66 % 
% 1 % 2014-Q4 % $33,910.34 % 
% 1 % % $160,477.14 % 
% 2 % 2014-Q1 % $38,733.24 % 
% 2 % 2014-Q2 % $40,480.96 % 
% 2 % 2014-Q3 % $43,875.72 % 
% 2 % 2014-Q4 % $42,041.28 % 
% 2 % % $165,131.20 % 
% 3 % 2014-Q1 % $45,351.14 % 
% 3 % 2014-Q2 % $36,672.08 % 
% 3 % 2014-Q3 % $33,468.46 % 
% 3 % 2014-Q4 % $42,793.36 % 
% 3 % % $158,285.04 % 
% % % $483,893.38 % 
)"""""""""""""*"""""""""*"""""""""""""+ 
(16 rows) 
Tuesday, November 18, 14
That's nice, BUT 
Tuesday, November 18, 14
There was an extra line. 
Tuesday, November 18, 14
!"""""""""""""#"""""""""#"""""""""""""$ 
% employee_id % Quarter % sum % 
&"""""""""""""'"""""""""'"""""""""""""( 
% 1 % 2014-Q1 % $42,227.43 % 
% 1 % 2014-Q2 % $42,974.71 % 
% 1 % 2014-Q3 % $41,364.66 % 
% 1 % 2014-Q4 % $33,910.34 % 
% 1 % % $160,477.14 % 
% 2 % 2014-Q1 % $38,733.24 % 
% 2 % 2014-Q2 % $40,480.96 % 
% 2 % 2014-Q3 % $43,875.72 % 
% 2 % 2014-Q4 % $42,041.28 % 
% 2 % % $165,131.20 % 
% 3 % 2014-Q1 % $45,351.14 % 
% 3 % 2014-Q2 % $36,672.08 % 
% 3 % 2014-Q3 % $33,468.46 % 
% 3 % 2014-Q4 % $42,793.36 % 
% 3 % % $158,285.04 % 
% % % $483,893.38 % 
)"""""""""""""*"""""""""*"""""""""""""+ 
(16 rows) 
Tuesday, November 18, 14
Hierarchies: 
Top to Bottom 
Tuesday, November 18, 14
We didn't want the top. 
Tuesday, November 18, 14
GROUPING SETS... 
Precision 
Tuesday, November 18, 14
SELECT 
employee_id, 
to_char( 
date_trunc('Quarter', sale_closed), 
'YYYY-"Q"Q' 
) AS "Quarter", 
sum(sale_amount) 
FROM sales 
GROUP BY GROUPING SETS( 
(employee_id, date_trunc('Quarter', sale_closed)), 
(employee_id) 
) 
ORDER BY employee_id, date_trunc('Quarter', sale_closed); 
Tuesday, November 18, 14
Results: 
!"""""""""""""#"""""""""#"""""""""""""$ 
% employee_id % Quarter % sum % 
&"""""""""""""'"""""""""'"""""""""""""( 
% 1 % 2014-Q1 % $42,227.43 % 
% 1 % 2014-Q2 % $42,974.71 % 
% 1 % 2014-Q3 % $41,364.66 % 
% 1 % 2014-Q4 % $33,910.34 % 
% 1 % % $160,477.14 % 
% 2 % 2014-Q1 % $38,733.24 % 
% 2 % 2014-Q2 % $40,480.96 % 
% 2 % 2014-Q3 % $43,875.72 % 
% 2 % 2014-Q4 % $42,041.28 % 
% 2 % % $165,131.20 % 
% 3 % 2014-Q1 % $45,351.14 % 
% 3 % 2014-Q2 % $36,672.08 % 
% 3 % 2014-Q3 % $33,468.46 % 
% 3 % 2014-Q4 % $42,793.36 % 
% 3 % % $158,285.04 % 
)"""""""""""""*"""""""""*"""""""""""""+ 
(15 rows) 
Tuesday, November 18, 14
There we go! 
Tuesday, November 18, 14
HOW?!? 
Tuesday, November 18, 14
Extant Planner/Executor 
Tuesday, November 18, 14
Extant Planner/Executor 
•HashAgg 
Tuesday, November 18, 14
Extant Planner/Executor 
•HashAgg 
•GroupAgg 
Tuesday, November 18, 14
HashAgg 
Result Group Intermediate State 
Tuesday, November 18, 14
HashAgg 
• One pass: 
• Update hash value for each row 
• Output final value at the end 
Tuesday, November 18, 14
HashAgg 
• Not yet in GROUPING SETS 
• Algorithmic speedup opportunity: 
• O(n) vs. O(n log n) 
Tuesday, November 18, 14
HashAgg-- :-( 
• Non-hashable data types 
• Aggregate functions with LOTS of state 
• Ordered aggs 
• Distinct aggs 
• No spill-to-disk 
Tuesday, November 18, 14
GroupAgg 
• Sorts all input to the agg node to 
• Detect group boundary 
• Output that group 
• Results before end-of-scan 
Tuesday, November 18, 14
Phase I 
Tuesday, November 18, 14
GroupAgg for ROLLUP 
Tuesday, November 18, 14
GroupAgg for ROLLUP 
• Sort for the heirarchy 
Tuesday, November 18, 14
GroupAgg for ROLLUP 
• Sort for the heirarchy 
• Output results at each boundary 
Tuesday, November 18, 14
GroupAgg for ROLLUP 
• Sort for the heirarchy 
• Output results at each boundary 
• k for the price of one! 
Tuesday, November 18, 14
Phase II 
Tuesday, November 18, 14
GroupAgg !ROLLUP 
Tuesday, November 18, 14
GroupAgg !ROLLUP 
Tuesday, November 18, 14
GroupAgg !ROLLUP 
• Re-plan input to sort with >1 order 
Tuesday, November 18, 14
GroupAgg !ROLLUP 
• Re-plan input to sort with >1 order 
• Plan keeps tons of global state 
Tuesday, November 18, 14
GroupAgg !ROLLUP 
• Re-plan input to sort with >1 order 
• Plan keeps tons of global state 
• Does NOT like to be called >1x/plan 
Tuesday, November 18, 14
Tuesday, November 18, 14
GROUPING SETS ~ 
WINDOW 
Tuesday, November 18, 14
WINDOW 
implementation 
Tuesday, November 18, 14
Shuffle a deck of WindowAgg and Sort nodes. 
Tuesday, November 18, 14
WindowAgg → Sort → WindowAgg → Sort ... 
Tuesday, November 18, 14
Similar pattern 
Tuesday, November 18, 14
Tuesday, November 18, 14
• Expand all GROUPING SETS 
Tuesday, November 18, 14
• Expand all GROUPING SETS 
• Arrange into fewest ROLLUPs 
Tuesday, November 18, 14
• Expand all GROUPING SETS 
• Arrange into fewest ROLLUPs 
• Shuffle Sort and ChainAgg 
Tuesday, November 18, 14
GroupAgg → 
Sort → 
ChainAgg → 
Sort → 
(input data) 
Tuesday, November 18, 14
ChainAgg?!? 
Tuesday, November 18, 14
ChainAgg Nodes 
• Pass input state through unchanged 
• Update aggregate state 
• Put rows into a chain-wide shared 
tuplestore when they hit a group boundary 
Tuesday, November 18, 14
The Last GroupAgg 
• Produces its normal output until end-of-data 
• Outputs the shared tuplestore 
Tuesday, November 18, 14
Phase III 
Tuesday, November 18, 14
Future 
Tuesday, November 18, 14
• HashAgg 
• Alone? 
• With ChainAggs? 
• Agg Associativity (A + B) + C = A + (B + C) 
• Make CUBE a reserved word? 
Tuesday, November 18, 14
Questions? 
Comments? 
Tuesday, November 18, 14
Thanks! 
SFPUG 2014/11/18 
Copyright© 2014 
David Fetter 
Tuesday, November 18, 14

Weitere ähnliche Inhalte

Mehr von David Fetter

PostgreSQL Hooks for Fun and Profit
PostgreSQL Hooks for Fun and ProfitPostgreSQL Hooks for Fun and Profit
PostgreSQL Hooks for Fun and ProfitDavid Fetter
 
Tree tricks osdc_melbourne_20101124
Tree tricks osdc_melbourne_20101124Tree tricks osdc_melbourne_20101124
Tree tricks osdc_melbourne_20101124David Fetter
 
Rdbms roadmap 20140130
Rdbms roadmap 20140130Rdbms roadmap 20140130
Rdbms roadmap 20140130David Fetter
 
Slides pg conf_eu_20131031
Slides pg conf_eu_20131031Slides pg conf_eu_20131031
Slides pg conf_eu_20131031David Fetter
 
Federation with foreign_data_wrappers_pg_conf_eu_20131031
Federation with foreign_data_wrappers_pg_conf_eu_20131031Federation with foreign_data_wrappers_pg_conf_eu_20131031
Federation with foreign_data_wrappers_pg_conf_eu_20131031David Fetter
 
Intergalactic data speak_highload++_20131028
Intergalactic data speak_highload++_20131028Intergalactic data speak_highload++_20131028
Intergalactic data speak_highload++_20131028David Fetter
 
G so c_and_commitfests_and_pointy_hair_oh_my_sfpug_20131008
G so c_and_commitfests_and_pointy_hair_oh_my_sfpug_20131008G so c_and_commitfests_and_pointy_hair_oh_my_sfpug_20131008
G so c_and_commitfests_and_pointy_hair_oh_my_sfpug_20131008David Fetter
 
Ct es past_present_future_nycpgday_20130322
Ct es past_present_future_nycpgday_20130322Ct es past_present_future_nycpgday_20130322
Ct es past_present_future_nycpgday_20130322David Fetter
 
Universal data access_with_sql_med
Universal data access_with_sql_medUniversal data access_with_sql_med
Universal data access_with_sql_medDavid Fetter
 
Lightning sf perl_mongers_20120327
Lightning sf perl_mongers_20120327Lightning sf perl_mongers_20120327
Lightning sf perl_mongers_20120327David Fetter
 
Threat modeling sf_perl_mongers_20130227
Threat modeling sf_perl_mongers_20130227Threat modeling sf_perl_mongers_20130227
Threat modeling sf_perl_mongers_20130227David Fetter
 
Security revolutionized fosdem_20120205
Security revolutionized fosdem_20120205Security revolutionized fosdem_20120205
Security revolutionized fosdem_20120205David Fetter
 
Writeable ct es_pgcon_may_2011
Writeable ct es_pgcon_may_2011Writeable ct es_pgcon_may_2011
Writeable ct es_pgcon_may_2011David Fetter
 
View triggers pg_east_20110325
View triggers pg_east_20110325View triggers pg_east_20110325
View triggers pg_east_20110325David Fetter
 
PL/Parrot San Francisco Perl Mongers 2010/05/25
PL/Parrot San Francisco Perl Mongers 2010/05/25PL/Parrot San Francisco Perl Mongers 2010/05/25
PL/Parrot San Francisco Perl Mongers 2010/05/25David Fetter
 

Mehr von David Fetter (15)

PostgreSQL Hooks for Fun and Profit
PostgreSQL Hooks for Fun and ProfitPostgreSQL Hooks for Fun and Profit
PostgreSQL Hooks for Fun and Profit
 
Tree tricks osdc_melbourne_20101124
Tree tricks osdc_melbourne_20101124Tree tricks osdc_melbourne_20101124
Tree tricks osdc_melbourne_20101124
 
Rdbms roadmap 20140130
Rdbms roadmap 20140130Rdbms roadmap 20140130
Rdbms roadmap 20140130
 
Slides pg conf_eu_20131031
Slides pg conf_eu_20131031Slides pg conf_eu_20131031
Slides pg conf_eu_20131031
 
Federation with foreign_data_wrappers_pg_conf_eu_20131031
Federation with foreign_data_wrappers_pg_conf_eu_20131031Federation with foreign_data_wrappers_pg_conf_eu_20131031
Federation with foreign_data_wrappers_pg_conf_eu_20131031
 
Intergalactic data speak_highload++_20131028
Intergalactic data speak_highload++_20131028Intergalactic data speak_highload++_20131028
Intergalactic data speak_highload++_20131028
 
G so c_and_commitfests_and_pointy_hair_oh_my_sfpug_20131008
G so c_and_commitfests_and_pointy_hair_oh_my_sfpug_20131008G so c_and_commitfests_and_pointy_hair_oh_my_sfpug_20131008
G so c_and_commitfests_and_pointy_hair_oh_my_sfpug_20131008
 
Ct es past_present_future_nycpgday_20130322
Ct es past_present_future_nycpgday_20130322Ct es past_present_future_nycpgday_20130322
Ct es past_present_future_nycpgday_20130322
 
Universal data access_with_sql_med
Universal data access_with_sql_medUniversal data access_with_sql_med
Universal data access_with_sql_med
 
Lightning sf perl_mongers_20120327
Lightning sf perl_mongers_20120327Lightning sf perl_mongers_20120327
Lightning sf perl_mongers_20120327
 
Threat modeling sf_perl_mongers_20130227
Threat modeling sf_perl_mongers_20130227Threat modeling sf_perl_mongers_20130227
Threat modeling sf_perl_mongers_20130227
 
Security revolutionized fosdem_20120205
Security revolutionized fosdem_20120205Security revolutionized fosdem_20120205
Security revolutionized fosdem_20120205
 
Writeable ct es_pgcon_may_2011
Writeable ct es_pgcon_may_2011Writeable ct es_pgcon_may_2011
Writeable ct es_pgcon_may_2011
 
View triggers pg_east_20110325
View triggers pg_east_20110325View triggers pg_east_20110325
View triggers pg_east_20110325
 
PL/Parrot San Francisco Perl Mongers 2010/05/25
PL/Parrot San Francisco Perl Mongers 2010/05/25PL/Parrot San Francisco Perl Mongers 2010/05/25
PL/Parrot San Francisco Perl Mongers 2010/05/25
 

Kürzlich hochgeladen

Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxfirstjob4
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 

Kürzlich hochgeladen (20)

Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptx
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 

Grouping sets sfpug_20141118

  • 1. GROUPING SETS CCUBE, ROLLUP, and Friends SFPUG 2014/11/18 Copyright© 2014 David Fetter Tuesday, November 18, 14
  • 7. • CUBE (Power set/Ring the changes) • ROLLUP (Hierarchy) • GROUPING SETS (Precision) Tuesday, November 18, 14
  • 8. Shhh. A little code. Tuesday, November 18, 14
  • 9. CREATE TABLE employee ( id SERIAL PRIMARY KEY, first_name TEXT, last_name TEXT ); CREATE TABLE sales ( employee_id INTEGER NOT NULL, sale_closed TIMESTAMPTZ NOT NULL DEFAULT NOW(), sale_amount MONEY, /* We need to do fix this */ FOREIGN KEY(employee_id) REFERENCES employee(id) ); Tables Tuesday, November 18, 14
  • 10. Data INSERT INTO employee (first_name, last_name) VALUES ('Larry', 'Ellison'), ('Bill', 'Gates'), ('Vladimir', 'Yulianov'); Tuesday, November 18, 14
  • 11. Moar Data INSERT INTO sales SELECT floor(random()*3)+1, /* Who */ '2014-01-01 00:00:00+00'::timestamptz + random() * interval '1 year', /* When */ (random() * 1000)::numeric(8,2)::MONEY /* ¿Cuando? */ FROM generate_series(1,1000); Tuesday, November 18, 14
  • 12. How much did each sell each quarter? Tuesday, November 18, 14
  • 14. SELECT employee_id, date_trunc('Quarter', sale_closed) AS "Quarter", SUM(sale_amount) FROM sales GROUP BY employee_id, date_trunc('Quarter', sale_closed) ORDER BY employee_id, date_trunc('Quarter', sale_closed); * I left out some formatting. Tuesday, November 18, 14
  • 15. Results: !"""""""""""""#"""""""""#""""""""""""$ % employee_id % Quarter % sum % &"""""""""""""'"""""""""'""""""""""""( % 1 % 2014-Q1 % $42,227.43 % % 1 % 2014-Q2 % $42,974.71 % % 1 % 2014-Q3 % $41,364.66 % % 1 % 2014-Q4 % $33,910.34 % % 2 % 2014-Q1 % $38,733.24 % % 2 % 2014-Q2 % $40,480.96 % % 2 % 2014-Q3 % $43,875.72 % % 2 % 2014-Q4 % $42,041.28 % % 3 % 2014-Q1 % $45,351.14 % % 3 % 2014-Q2 % $36,672.08 % % 3 % 2014-Q3 % $33,468.46 % % 3 % 2014-Q4 % $42,793.36 % )"""""""""""""*"""""""""*""""""""""""+ (12 rows) Tuesday, November 18, 14
  • 16. That's nice, BUT (We all grimace when we hear that) Tuesday, November 18, 14
  • 17. How about annual totals? Tuesday, November 18, 14
  • 18. Old way: UNION ALL Tuesday, November 18, 14
  • 19. ( SELECT employee_id, to_char(date_trunc('Quarter', sale_closed), 'YYYY-"Q"Q') AS "Quarter", sum(sale_amount) FROM sales GROUP BY employee_id, date_trunc('Quarter', sale_closed) ORDER BY employee_id, date_trunc('Quarter', sale_closed) ) UNION ALL ( SELECT employee_id, to_char(date_trunc('Year', sale_closed), 'YYYY') AS "Year", sum(sale_amount) FROM sales GROUP BY employee_id, date_trunc('Year', sale_closed) ORDER BY employee_id, date_trunc('Year', sale_closed) ); Still Doable...Kinda Tuesday, November 18, 14
  • 20. Results !"""""""""""""#"""""""""#"""""""""""""$ % employee_id % Quarter % sum % &"""""""""""""'"""""""""'"""""""""""""( % 1 % 2014-Q1 % $42,227.43 % % 1 % 2014-Q2 % $42,974.71 % % 1 % 2014-Q3 % $41,364.66 % % 1 % 2014-Q4 % $33,910.34 % % 2 % 2014-Q1 % $38,733.24 % % 2 % 2014-Q2 % $40,480.96 % % 2 % 2014-Q3 % $43,875.72 % % 2 % 2014-Q4 % $42,041.28 % % 3 % 2014-Q1 % $45,351.14 % % 3 % 2014-Q2 % $36,672.08 % % 3 % 2014-Q3 % $33,468.46 % % 3 % 2014-Q4 % $42,793.36 % % 1 % 2014 % $160,477.14 % % 2 % 2014 % $165,131.20 % % 3 % 2014 % $158,285.04 % )"""""""""""""*"""""""""*"""""""""""""+ (15 rows) Tuesday, November 18, 14
  • 21. That's nice, BUT Tuesday, November 18, 14
  • 22. Can't we look at each sales rep with each of their quarterly totals? Tuesday, November 18, 14
  • 25. These requests are reasonable! Tuesday, November 18, 14
  • 26. But the code...not so much. Tuesday, November 18, 14
  • 27. Take it from the top! Tuesday, November 18, 14
  • 28. CUBE...ring the changes... Tuesday, November 18, 14
  • 29. Quick stare SELECT employee_id, to_char( date_trunc('Quarter', sale_closed), 'YYYY-"Q"Q' ) AS "Quarter", sum(sale_amount) FROM sales GROUP BY CUBE ( employee_id, date_trunc('Quarter', sale_closed) ) ORDER BY employee_id, date_trunc('Quarter', sale_closed); Tuesday, November 18, 14
  • 30. Results: !"""""""""""""#"""""""""#"""""""""""""$ % employee_id % Quarter % sum % &"""""""""""""'"""""""""'"""""""""""""( % 1 % 2014-Q1 % $42,227.43 % % 1 % 2014-Q2 % $42,974.71 % % 1 % 2014-Q3 % $41,364.66 % % 1 % 2014-Q4 % $33,910.34 % % 1 % % $160,477.14 % % 2 % 2014-Q1 % $38,733.24 % % 2 % 2014-Q2 % $40,480.96 % % 2 % 2014-Q3 % $43,875.72 % % 2 % 2014-Q4 % $42,041.28 % % 2 % % $165,131.20 % % 3 % 2014-Q1 % $45,351.14 % % 3 % 2014-Q2 % $36,672.08 % % 3 % 2014-Q3 % $33,468.46 % % 3 % 2014-Q4 % $42,793.36 % % 3 % % $158,285.04 % % % 2014-Q1 % $126,311.81 % % % 2014-Q2 % $120,127.75 % % % 2014-Q3 % $118,708.84 % % % 2014-Q4 % $118,744.98 % % % % $483,893.38 % )"""""""""""""*"""""""""*"""""""""""""+ (20 rows) Tuesday, November 18, 14
  • 31. That's nice, BUT Tuesday, November 18, 14
  • 32. We don't care about undifferentiated quarterly totals. Tuesday, November 18, 14
  • 33. Results: !"""""""""""""#"""""""""#"""""""""""""$ % employee_id % Quarter % sum % &"""""""""""""'"""""""""'"""""""""""""( % 1 % 2014-Q1 % $42,227.43 % % 1 % 2014-Q2 % $42,974.71 % % 1 % 2014-Q3 % $41,364.66 % % 1 % 2014-Q4 % $33,910.34 % % 1 % % $160,477.14 % % 2 % 2014-Q1 % $38,733.24 % % 2 % 2014-Q2 % $40,480.96 % % 2 % 2014-Q3 % $43,875.72 % % 2 % 2014-Q4 % $42,041.28 % % 2 % % $165,131.20 % % 3 % 2014-Q1 % $45,351.14 % % 3 % 2014-Q2 % $36,672.08 % % 3 % 2014-Q3 % $33,468.46 % % 3 % 2014-Q4 % $42,793.36 % % 3 % % $158,285.04 % % % 2014-Q1 % $126,311.81 % % % 2014-Q2 % $120,127.75 % % % 2014-Q3 % $118,708.84 % % % 2014-Q4 % $118,744.98 % % % % $483,893.38 % )"""""""""""""*"""""""""*"""""""""""""+ (20 rows) Tuesday, November 18, 14
  • 35. Let's try that! Tuesday, November 18, 14
  • 36. SELECT employee_id, to_char( date_trunc('Quarter', sale_closed), 'YYYY-"Q"Q' ) AS "Quarter", sum(sale_amount) FROM sales GROUP BY ROLLUP( employee_id, date_trunc('Quarter', sale_closed) ) ORDER BY employee_id, date_trunc('Quarter', sale_closed); Tuesday, November 18, 14
  • 37. Hmmm... !"""""""""""""#"""""""""#"""""""""""""$ % employee_id % Quarter % sum % &"""""""""""""'"""""""""'"""""""""""""( % 1 % 2014-Q1 % $42,227.43 % % 1 % 2014-Q2 % $42,974.71 % % 1 % 2014-Q3 % $41,364.66 % % 1 % 2014-Q4 % $33,910.34 % % 1 % % $160,477.14 % % 2 % 2014-Q1 % $38,733.24 % % 2 % 2014-Q2 % $40,480.96 % % 2 % 2014-Q3 % $43,875.72 % % 2 % 2014-Q4 % $42,041.28 % % 2 % % $165,131.20 % % 3 % 2014-Q1 % $45,351.14 % % 3 % 2014-Q2 % $36,672.08 % % 3 % 2014-Q3 % $33,468.46 % % 3 % 2014-Q4 % $42,793.36 % % 3 % % $158,285.04 % % % % $483,893.38 % )"""""""""""""*"""""""""*"""""""""""""+ (16 rows) Tuesday, November 18, 14
  • 38. That's nice, BUT Tuesday, November 18, 14
  • 39. There was an extra line. Tuesday, November 18, 14
  • 40. !"""""""""""""#"""""""""#"""""""""""""$ % employee_id % Quarter % sum % &"""""""""""""'"""""""""'"""""""""""""( % 1 % 2014-Q1 % $42,227.43 % % 1 % 2014-Q2 % $42,974.71 % % 1 % 2014-Q3 % $41,364.66 % % 1 % 2014-Q4 % $33,910.34 % % 1 % % $160,477.14 % % 2 % 2014-Q1 % $38,733.24 % % 2 % 2014-Q2 % $40,480.96 % % 2 % 2014-Q3 % $43,875.72 % % 2 % 2014-Q4 % $42,041.28 % % 2 % % $165,131.20 % % 3 % 2014-Q1 % $45,351.14 % % 3 % 2014-Q2 % $36,672.08 % % 3 % 2014-Q3 % $33,468.46 % % 3 % 2014-Q4 % $42,793.36 % % 3 % % $158,285.04 % % % % $483,893.38 % )"""""""""""""*"""""""""*"""""""""""""+ (16 rows) Tuesday, November 18, 14
  • 41. Hierarchies: Top to Bottom Tuesday, November 18, 14
  • 42. We didn't want the top. Tuesday, November 18, 14
  • 43. GROUPING SETS... Precision Tuesday, November 18, 14
  • 44. SELECT employee_id, to_char( date_trunc('Quarter', sale_closed), 'YYYY-"Q"Q' ) AS "Quarter", sum(sale_amount) FROM sales GROUP BY GROUPING SETS( (employee_id, date_trunc('Quarter', sale_closed)), (employee_id) ) ORDER BY employee_id, date_trunc('Quarter', sale_closed); Tuesday, November 18, 14
  • 45. Results: !"""""""""""""#"""""""""#"""""""""""""$ % employee_id % Quarter % sum % &"""""""""""""'"""""""""'"""""""""""""( % 1 % 2014-Q1 % $42,227.43 % % 1 % 2014-Q2 % $42,974.71 % % 1 % 2014-Q3 % $41,364.66 % % 1 % 2014-Q4 % $33,910.34 % % 1 % % $160,477.14 % % 2 % 2014-Q1 % $38,733.24 % % 2 % 2014-Q2 % $40,480.96 % % 2 % 2014-Q3 % $43,875.72 % % 2 % 2014-Q4 % $42,041.28 % % 2 % % $165,131.20 % % 3 % 2014-Q1 % $45,351.14 % % 3 % 2014-Q2 % $36,672.08 % % 3 % 2014-Q3 % $33,468.46 % % 3 % 2014-Q4 % $42,793.36 % % 3 % % $158,285.04 % )"""""""""""""*"""""""""*"""""""""""""+ (15 rows) Tuesday, November 18, 14
  • 46. There we go! Tuesday, November 18, 14
  • 49. Extant Planner/Executor •HashAgg Tuesday, November 18, 14
  • 50. Extant Planner/Executor •HashAgg •GroupAgg Tuesday, November 18, 14
  • 51. HashAgg Result Group Intermediate State Tuesday, November 18, 14
  • 52. HashAgg • One pass: • Update hash value for each row • Output final value at the end Tuesday, November 18, 14
  • 53. HashAgg • Not yet in GROUPING SETS • Algorithmic speedup opportunity: • O(n) vs. O(n log n) Tuesday, November 18, 14
  • 54. HashAgg-- :-( • Non-hashable data types • Aggregate functions with LOTS of state • Ordered aggs • Distinct aggs • No spill-to-disk Tuesday, November 18, 14
  • 55. GroupAgg • Sorts all input to the agg node to • Detect group boundary • Output that group • Results before end-of-scan Tuesday, November 18, 14
  • 56. Phase I Tuesday, November 18, 14
  • 57. GroupAgg for ROLLUP Tuesday, November 18, 14
  • 58. GroupAgg for ROLLUP • Sort for the heirarchy Tuesday, November 18, 14
  • 59. GroupAgg for ROLLUP • Sort for the heirarchy • Output results at each boundary Tuesday, November 18, 14
  • 60. GroupAgg for ROLLUP • Sort for the heirarchy • Output results at each boundary • k for the price of one! Tuesday, November 18, 14
  • 61. Phase II Tuesday, November 18, 14
  • 62. GroupAgg !ROLLUP Tuesday, November 18, 14
  • 63. GroupAgg !ROLLUP Tuesday, November 18, 14
  • 64. GroupAgg !ROLLUP • Re-plan input to sort with >1 order Tuesday, November 18, 14
  • 65. GroupAgg !ROLLUP • Re-plan input to sort with >1 order • Plan keeps tons of global state Tuesday, November 18, 14
  • 66. GroupAgg !ROLLUP • Re-plan input to sort with >1 order • Plan keeps tons of global state • Does NOT like to be called >1x/plan Tuesday, November 18, 14
  • 68. GROUPING SETS ~ WINDOW Tuesday, November 18, 14
  • 70. Shuffle a deck of WindowAgg and Sort nodes. Tuesday, November 18, 14
  • 71. WindowAgg → Sort → WindowAgg → Sort ... Tuesday, November 18, 14
  • 72. Similar pattern Tuesday, November 18, 14
  • 74. • Expand all GROUPING SETS Tuesday, November 18, 14
  • 75. • Expand all GROUPING SETS • Arrange into fewest ROLLUPs Tuesday, November 18, 14
  • 76. • Expand all GROUPING SETS • Arrange into fewest ROLLUPs • Shuffle Sort and ChainAgg Tuesday, November 18, 14
  • 77. GroupAgg → Sort → ChainAgg → Sort → (input data) Tuesday, November 18, 14
  • 79. ChainAgg Nodes • Pass input state through unchanged • Update aggregate state • Put rows into a chain-wide shared tuplestore when they hit a group boundary Tuesday, November 18, 14
  • 80. The Last GroupAgg • Produces its normal output until end-of-data • Outputs the shared tuplestore Tuesday, November 18, 14
  • 81. Phase III Tuesday, November 18, 14
  • 83. • HashAgg • Alone? • With ChainAggs? • Agg Associativity (A + B) + C = A + (B + C) • Make CUBE a reserved word? Tuesday, November 18, 14
  • 84. Questions? Comments? Tuesday, November 18, 14
  • 85. Thanks! SFPUG 2014/11/18 Copyright© 2014 David Fetter Tuesday, November 18, 14