Rollups, Cubes, Grouping Sets and their inner working

Slides:



Advertisements
Similar presentations
Chapter 4 Joining Multiple Tables
Advertisements

Alles over groeperen Rollups, Cubes, Grouping Sets en hun interne werking Rob van Wijk 22 september 2014.
Optimizing and Simplifying Complex SQL with Advanced Grouping Presented by: Jared Still.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Group functions cannot be used in the WHERE clause: SELECT type_code FROM d_songs WHERE SUM (duration) = 100; (this will give an error)
Introduction To SQL Lynnwood Brown President System Managers LLC Copyright System Managers LLC 2003 all rights reserved.
Set operators (UNION, UNION ALL, MINUS, INTERSECT) [SQL]
Chapter 11 Group Functions
Chapter 11 Group Functions (up to p.402)
Introduction to Oracle9i: SQL1 Subqueries. Introduction to Oracle9i: SQL2 Chapter Objectives Determine when it is appropriate to use a subquery Identify.
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
1 Internal Table / DB Alternatives Analysis of Various Table Lookup Approaches.
SAGE Computing Services Customised Oracle Training Workshops and Consulting Are you making the most of PL/SQL? Hints and tricks and things you may have.
TOPIC : Introduction to Functional Modeling UNIT 1: Modeling Digital Circuits Module 1 : Functional Modeling.
Database Management 9. course. Execution of queries.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Chapter 9 Joining Data from Multiple Tables
Oracle Database 11g’s Result Cache Rob van Wijk 28 October 2010.
Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia.
Topic 1Topic 2Topic 3Topic 4Topic
Subqueries.
SELECT Statements Lecture Notes Sree Nilakanta Fall 2010 (rev)
Oracle University Live Virtual Seminar SQL Masterclass Rob van Wijk2011.
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
From Relational Algebra to SQL CS 157B Enrique Tang.
Introduction MySQL won't actually execute the query, just analyse it EXPLAIN helps us understand how and when MySQL will use indexes EXPLAIN returns a.
Complex Queries Dale Roberts, Lecturer Computer Science, IUPUI
Displaying Data from Multiple Tables (SQL99 Syntax with examples)
Query Processing – Query Trees. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying.
9-1 © Prentice Hall, 2007 Topic 9: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
1 SQL – IV Grouping data from tables in SQL –The concept of grouping –GROUP BY clause –HAVING Clause –Determining whether values are unique –Group by using.
Subqueries.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Grouping These slides are licensed under.
Query Processing – Implementing Set Operations and Joins Chap. 19.
Agenda for Class - 03/04/2014 Answer questions about HW#5 and HW#6 Review query syntax. Discuss group functions and summary output with the GROUP BY statement.
The Model Clause A case study at E.On. Introduction 2 A little about me, the company I work for, the team I work in and today’s.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Aggregator Stage : Definition : Aggregator classifies data rows from a single input link into groups and calculates totals or other aggregate functions.
1 Ch. 11: Grouping Things Together  ANSI standard SQL Group functions: AVG, COUNT, MAX, MIN, STDDEV, SUM, VARIANCE  Others: 8i: GROUPING (used with CUBE.
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
IFS180 Intro. to Data Management Chapter 10 - Unions.
Using Subqueries to Solve Queries
Multiple-Column Subqueries
Subqueries.
Subqueries Schedule: Timing Topic 25 minutes Lecture
Choosing Access Path The basic methods.
Query Processing and Optimization
Oracle Certified 1z0-047 Exam Questions
Interpreting Execution Plans
Dumps4Download Oracle 1z0-051 Exam Dumps - Oracle 1z0-051 Exam Dumps Questions
Using Subqueries to Solve Queries
Model Functions Input x 6 = Output Input x 3 = Output
Generalization.
Writing Correlated Subqueries
Chapter 15 QUERY EXECUTION.
XBRL in the Enterprise: Internal Reporting with XBRL
دانشگاه شهیدرجایی تهران
تعهدات مشتری در کنوانسیون بیع بین المللی
Rollups, Cubes, Grouping Sets and their inner working
Using Subqueries to Solve Queries

Subqueries Schedule: Timing Topic 25 minutes Lecture
Using Subqueries to Solve Queries
Using Subqueries to Solve Queries
Subqueries Schedule: Timing Topic 25 minutes Lecture
Warm-Up Study the patterns below to determine the next five numbers in each sequence. You may use the calculator to check your answers. 2, 4, 6, 8, 10...
Criterion Methods and Approximation Concepts
04 SQL & Relational Algebra
Pivoting and Grouping Sets
Presentation transcript:

Rollups, Cubes, Grouping Sets and their inner working All About Grouping November 23, 2018 Rollups, Cubes, Grouping Sets and their inner working Rob van Wijk

Who am I Database application developer 14 years with Oracle products Rob van Wijk Database application developer 14 years with Oracle products Utrecht November 23, 2018

All About Grouping Introduction GROUPING SETS ROLLUP CUBE Topics Introduction GROUPING SETS ROLLUP CUBE Combining and calculating Supporting functions Inner working November 23, 2018

All About Grouping Introduction aog1.sql November 23, 2018

All About Grouping GROUP BY expr1, …, exprn ≡ GROUP BY GROUPING SETS aog2.sql November 23, 2018

( (expr11, …, expr1n), …, (exprx1, …, exprxm) ) All About Grouping GROUPING SETS (2) GROUP BY GROUPING SETS ( (expr11, …, expr1n), …, (exprx1, …, exprxm) ) ≡ GROUP BY expr11, … expr1n UNION ALL … GROUP BY exprx1, …, exprxm aog3.sql November 23, 2018

All About Grouping GROUP BY ROLLUP ( set1, …, setn ) ≡ GROUP BY GROUPING SETS ( (set1, …, setn), (set1, …, setn-1), …, set1, () ) November 23, 2018

leads to N+1 GROUPING SETS All About Grouping ROLLUP (2) ROLLUP (set1, …, setN) with N ≥ 1 leads to N+1 GROUPING SETS November 23, 2018

All About Grouping Example: ROLLUP (3) Example: GROUP BY ROLLUP ( (deptno), (job,mgr), (empno) ) ≡ GROUP BY GROUPING SETS ( (deptno,job,mgr,empno) , (deptno,job,mgr) , (deptno) , () ) aog4.sql November 23, 2018

All About Grouping GROUP BY CUBE ( set1, …, setn ) ≡ GROUP BY GROUPING SETS (all possible combinations between () and (set1, …, setn) ) November 23, 2018

leads to 2N GROUPING SETS All About Grouping CUBE (2) CUBE (set1, …, setN) with N ≥ 1 leads to 2N GROUPING SETS November 23, 2018

Follows Pascal’s triangle All About Grouping CUBE (3) Follows Pascal’s triangle 0 sets X 1 set 2 sets 3 sets 4 sets November 23, 2018

All About Grouping Example: CUBE (4) Example: GROUP BY CUBE ( (deptno), (job,mgr), (empno) ) ≡ GROUP BY GROUPING SETS ( (deptno,job,mgr,empno) , (deptno,job,mgr), (deptno,empno), (job,mgr,empno) , (deptno), (job,mgr), (empno) , () ) aog5.sql November 23, 2018

GROUP BY deptno, ROLLUP(empno) All About Grouping Combining and calculating (1) GROUP BY deptno, ROLLUP(empno) ? November 23, 2018

All About Grouping GROUP BY deptno, ROLLUP(empno) ≡ Combining and calculating (2) GROUP BY deptno, ROLLUP(empno) ≡ GROUP BY GROUPING SETS (deptno) , GROUPING SETS ( empno, () ) November 23, 2018

All About Grouping Cartesian product ! GROUP BY deptno, ROLLUP(empno) Combining and calculating (3) Cartesian product ! GROUP BY deptno, ROLLUP(empno) ≡ GROUP BY GROUPING SETS (deptno) , GROUPING SETS ( (empno), () ) GROUP BY GROUPING SETS ( (deptno,empno), (deptno) ) aog6.sql November 23, 2018

All About Grouping Question: Combining and calculating (4) Question: How many grouping sets does the clause below yield? GROUP BY ROLLUP(deptno,job) , CUBE(mgr,hiredate) Answer: 3 * 4 = 12 aog7.sql November 23, 2018

All About Grouping GROUPING GROUPING_ID GROUP_ID aog8.sql Supporting functions GROUPING GROUPING_ID GROUP_ID aog8.sql November 23, 2018

All About Grouping SORT GROUP BY versus HASH GROUP BY Inner working November 23, 2018

+ + All About Grouping aog9.sql Inner working: ROLLUP (deptno,empno) incoming set grouping set ( (deptno,empno) ) SORT GROUP BY 10 7782 2450 7839 5000 7934 1300 20 7369 800 7566 2975 7788 3000 7876 1100 7902 30 7499 1600 7521 1250 7654 7698 2850 7844 1500 7900 950 grouping set ( (deptno) ) + 10 NULL 8750 20 NULL 10875 30 NULL 9400 SORT GROUP BY grouping set ( () ) + NULL 29025 SORT GROUP BY aog9.sql November 23, 2018

All About Grouping aog10.sql Inner working: CUBE(deptno,job) incoming set 14 rows grouping set (deptno,job) SORT GROUP BY 9 rows 36 rows GENERATE CUBE 18 rows SORT GROUP BY aog10.sql November 23, 2018

All About Grouping temporary input table SYS_TEMP_... temporary Inner working: GROUPING SETS (1) LOAD AS SELECT (into input table) TABLE ACCESS FULL (EMP) temporary input table SYS_TEMP_... LOAD AS SELECT (into outputtable) HASH GROUP BY TABLE ACCESS FULL (input table) iterate as much times as there are grouping sets temporary output table SYS_TEMP_... TEMP TABLE TRANSFORMATION VIEW TABLE ACCESS FULL (output table) aog11.sql November 23, 2018

Optimize towards a ROLLUP or CUBE execution, All About Grouping Inner working: GROUPING SETS (2) Optimize towards a ROLLUP or CUBE execution, if possible? aog12.sql November 23, 2018

All About Grouping Questions? November 23, 2018

Thanks for your attention! Blog: http://rwijk.blogspot.com All About Grouping Thanks for your attention! Email: rwijk72@gmail.com Blog: http://rwijk.blogspot.com November 23, 2018