SlideShare a Scribd company logo
1 of 25
Download to read offline
© Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 1
Query Optimizations For Partitioned
Tables
Ashutosh Bapat
@PGCONF INDIA 2018
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 2
• Partition pruning
• Run-time partition pruning
• Partition-wise join
• Partition-wise aggregation
• Partition-wise sorting/ordering
Query Optimization Techniques
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 3
Partitioned Table
Partition 1
FOR VALUES
FROM (0) TO (100)
Partition 4
FOR VALUES
FROM (300) TO (400)
Partition 3
FOR VALUES
FROM (200) TO (300)
Partition 2
FOR VALUES
FROM (100) TO (200)
Unpartitioned table
t1 (c1 int, c2 int, …)
10, …, ...
90, …, ...
80, …, ...
325, …, …,
375, …, …,
Partitioned table
t1 (c1 int, c2 int, …)
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 4
Partition Pruning
SELECT * FROM t1 WHERE c1 = 350;
Partition 1
FOR VALUES
FROM (0) TO (100)
Partitioned table
t1 (c1 int, c2 int, …)
Partition 4
FOR VALUES
FROM (300) TO (400)
Partition 3
FOR VALUES
FROM (200) TO (300)
Partition 2
FOR VALUES
FROM (100) TO (200)
SELECT * FROM t1
WHERE c1 BETWEEN 150 AND 250;
Partitionboundsbasedelimination
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 5
Run-time Partition Pruning
EXEC scan_t1(350);
Partition 1
FOR VALUES
FROM (0) TO (100)
Partitioned table
t1 (c1 int, c2 int, …)
Partition 4
FOR VALUES
FROM (300) TO (400)
Partition 3
FOR VALUES
FROM (200) TO (300)
Partition 2
FOR VALUES
FROM (100) TO (200)
Partitionboundsbasedelimination
PREPARE scan_t1(int) AS
SELECT * FROM t1 WHERE c1 = $1;
© Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 7
Partition-wise Join
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 8
Partition-wise Join
Partition 1
FOR VALUES
(0) TO (100)
Partitioned table
t1 (c1 int, ...)
Partition 3
FOR VALUES
(200) TO (300)
Partition 2
FOR VALUES
(100) TO (200)
Partition 1
FOR VALUES
(0) TO (100)
Partition 3
FOR VALUES
(200) TO (300)
Partition 2
FOR VALUES
(100) TO (200)
Partition 1
FOR VALUES
(0) TO (100)
Partitioned table
t2 (c1 int, ...)
Partition 3
FOR VALUES
(200) TO (300)
Partition 2
FOR VALUES
(100) TO (200)
t1 JOIN t2
ON t1.c1 = t2.c1
Partitioned join
Partition 3
FOR VALUES
(200) TO (300)
Partition 1
FOR VALUES
(0) TO (100)
Partition 3
FOR VALUES
(200) TO (300)
Partition 2
FOR VALUES
(100) TO (200)
Partition 3
FOR VALUES
(200) TO (300)
Partition 1
FOR VALUES
(0) TO (100)
Partition 3
FOR VALUES
(200) TO (300)
Partition 2
FOR VALUES
(100) TO (200)
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 10
• Scale 20
• Schema changes
– lineitems PARTITION BY RANGE(l_orderkey)
– orders PARTITION BY RANGE(o_orderkey)
– Each with 17 partitions
• GUCs
– work_mem - 1GB
– effective_cache_size - 8GB
– shared_buffers - 8GB
– enable_partition_wise_join = on
TPCH Vs. Partition-wise Join (Scale 20)
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 11
TPCH Vs. Partition-wise Join (Scale 20)
(linear time scale)
Q3 Q4 Q5 Q7 Q10 Q12 Q18
0
100
200
300
400
500
600
700
800
Unpartitioned tables
Partitioned tables without PWJ
Partitioned tables with PWJ
TPCH queries (scale 20)
Queryexecutiontime(seconds)
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 12
TPCH Vs. Partition-wise Join (Scale 20)
(scaled execution time)
Q3 Q4 Q5 Q7 Q10 Q12 Q18
1
10
100
Unpartitioned tables
Partitioned tables without PWJ
Partitioned tables with PWJ
TPCH queries (scale 20)
scaledqueryexecutiontime
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 13
TPCH Vs. partition-wise join: observations
● Join strategy change from join between partitioned
tables to join between partitions
– MergeJoin to HashJoin
● Q3, Q5, Q10, Q12, Q18
– HashJoin to parameterized NestLoop join
● Q4
● Different join strategies for different partition-joins
● Q7
● Change in order of joining partitioned tables
– Q3, Q5, Q10, Q12, Q18, Q7
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 14
• Scale 300
• Schema changes
– lineitems PARTITION BY RANGE(l_orderkey)
– orders PARTITION BY RANGE(o_orderkey)
– Each with 106 partitions
• GUCs
– work_mem - 1GB
– effective_cache_size - 10GB
– shared_buffers - 10GB
– enable_partition_wise_join = on
– max_parallel_workers_per_gather = 4
TPCH Vs. Partition-wise Join (Scale 300)
Reported by Rafia Sabih
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 15
TPCH Vs. Partition-wise Join (Scale 300)
Q3 Q4 Q5 Q10 Q12
0
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
Unpartitioned tables
Partitioned tables without PWJ
Partitioned tables with PWJ
TPCH queries (scale 20)
Queryexecutiontime(seconds)
Partitioning makes queries faster
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 16
Partition pruning and Partition-wise Join
Partition 1
FOR VALUES
(0) TO (100)
Partitioned table
t1 (c1 int, ...)
Partition 3
FOR VALUES
(200) TO (300)
Partition 2
FOR VALUES
(100) TO (200)
Partition 1
FOR VALUES
(0) TO (100)
Partitioned table
t2 (c1 int, ...)
Partition 3
FOR VALUES
(200) TO (300)
Partition 2
FOR VALUES
(100) TO (200)
t1 JOIN t2
ON t1.c1 = t2.c1
SELECT … FROM t1 JOIN t2 ON t1.c1 = t2.c1
WHERE t1.c1 > 100 AND t2.c1 < 200
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 17
Partition pruning and Partition-wise Join
Partitioned join
Partition 1
FOR VALUES
(0) TO (100)
Partition 3
FOR VALUES
(200) TO (300)
Partition 2
FOR VALUES
(100) TO (200)
Partition 1
FOR VALUES
(0) TO (100)
Partition 3
FOR VALUES
(200) TO (300)
Partition 2
FOR VALUES
(100) TO (200)
Partitioned join
Partition 2
FOR VALUES
(100) TO (200)
Partition 2
FOR VALUES
(100) TO (200)
© Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 18
Partition-wise aggregation and
grouping
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 19
Full partition-wise aggregation
Partitioned table
t1 (c1 int, ...)
Partition 1
Partition 3
Partition 2
Partition 1
Partitioned table
t2 (c1 int, ...)
Partition 3
Partition 2
t1 JOIN t2
ON t1.c1 = t2.c1
Partition 1
Partition 3
Partition 2
Partition 1
Partition 3
Partition 2
Group by t1.c1
Group by t1.c1
Group by t1.c1
Group by t1.c1
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 20
Partial partition-wise aggregation
Partitioned table
t1 (c1 int, ...)
Partition 1
Partition 3
Partition 2
Partition 1
Partitioned table
t2 (c1 int, ...)
Partition 3
Partition 2
t1 JOIN t2
ON t1.c1 = t2.c1
Partition 1
Partition 3
Partition 2
Partition 1
Partition 3
Partition 2
Group by t1.c2
Partial Aggregation
Group by t1.c2
Partial Aggregation
Group by t1.c2
Partial Aggregation
Group by t1.c2
Full Aggregation
Group by t1.c2
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 22
Source: Jeevan Chalke's partition-wise aggregate proposal
Query: SELECT a, count(*) FROM plt1 GROUP BY a;
plt1: partitioned table with 3 foreign partitions, each with 1M rows
Query returns 30 rows, 10 rows per partition
enable_partition_wise_agg to false
QUERY PLAN
-------------------------------------
HashAggregate
Group Key: plt1.a
-> Append
-> Foreign Scan on fplt1_p1
-> Foreign Scan on fplt1_p2
-> Foreign Scan on fplt1_p3
Planning time: 0.251 ms
Execution time: 6499.018ms ~ 6.5s
enable_partition_wise_agg to true
QUERY PLAN
-------------------------------------------------------
Append
-> Foreign Scan: Aggregate on (public.fplt1_p1 plt1)
-> Foreign Scan: Aggregate on (public.fplt1_p2 plt1)
-> Foreign Scan: Aggregate on (public.fplt1_p3 plt1)
Planning time: 0.370ms
Execution time: 945.384ms ~ .9s
Example
7x faster
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 23
Partition-wise sorting
Partitioned table
t1 (c1 int, ...)
Partition 1
Partition 3
Partition 2
Partition 1
Partitioned table
t2 (c1 int, ...)
Partition 3
Partition 2
t1 JOIN t2
ON t1.c1 = t2.c1
Partition 1
Partition 3
Partition 2
Partition 1
Partition 3
Partition 2
Sort by c1
Sort by c1
Sort by c1
Sort by c1
© Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 24
Parallel Append and Partitioning
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 25
Parallel Append and Partitioning
Partition 1 Partition 3Partition 2Partition 1 Partition 3Partition 2
Group by t1.c1 Group by t1.c1 Group by t1.c1
Worker
Backend
1
Worker
Backend
2
Worker
Backend
1
Worker
Backend
3
Leader Backend
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 26
TPCH Vs. PWJ + PA
Q3 Q4 Q5 Q7 Q10 Q12 Q18
0
100
200
300
400
500
600
700
800
Unpartitioned tables
Partitioned tables without PWJ
Partitioned tables with PWJ
Partitioned tables with PWJ and
PA
TPCH queries (scale 20)
Queryexecutiontime(seconds)
© Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 27
• Committed patches
– Basic partition-wise join - Ashutosh Bapat (EDB)
– Parallel append – Amit Khandekar (EDB)
• Patches submitted on hackers and being reviewed
– Partition pruning – Amit Langote (NTT)
– Run-time partition pruning – Beena Emerson (EDB)
– Partition-wise aggregation – Jeevan Chalke (EDB)
– Partition-wise sorting/ordering – Ronan Dunklau, Julien
Rouhaud (Dalibo)
●
Benchmarking by Rafia Sabih (EDB)
Query Optimization Techniques - patches
Query optimization techniques for partitioned tables.

More Related Content

What's hot

MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table ExpressionsMySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressionsoysteing
 
Developers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OracleDevelopers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OraclemCloud
 
Multi-Master Replication with Slony
Multi-Master Replication with SlonyMulti-Master Replication with Slony
Multi-Master Replication with SlonyJim Mlodgenski
 
How to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceHow to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceoysteing
 
Scaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQLScaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQLJim Mlodgenski
 
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZEMySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZENorvald Ryeng
 
Fun with click house window functions webinar slides 2021-08-19
Fun with click house window functions webinar slides  2021-08-19Fun with click house window functions webinar slides  2021-08-19
Fun with click house window functions webinar slides 2021-08-19Altinity Ltd
 
クラウドDWHとしても進化を続けるPivotal Greenplumご紹介
クラウドDWHとしても進化を続けるPivotal Greenplumご紹介クラウドDWHとしても進化を続けるPivotal Greenplumご紹介
クラウドDWHとしても進化を続けるPivotal Greenplumご紹介Masayuki Matsushita
 
Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Sergey Petrunya
 
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Sergey Petrunya
 
SQL window functions for MySQL
SQL window functions for MySQLSQL window functions for MySQL
SQL window functions for MySQLDag H. Wanvik
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0Norvald Ryeng
 
Faster transactions & analytics with the new SQL2016 In-memory technologies
Faster transactions & analytics with the new SQL2016 In-memory technologiesFaster transactions & analytics with the new SQL2016 In-memory technologies
Faster transactions & analytics with the new SQL2016 In-memory technologiesHenk van der Valk
 
Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Sergey Petrunya
 
Using histograms to get better performance
Using histograms to get better performanceUsing histograms to get better performance
Using histograms to get better performanceSergey Petrunya
 
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~Insight Technology, Inc.
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearchRyosuke Nakamura
 
Efficient spatial queries on vanilla databases
Efficient spatial queries on vanilla databasesEfficient spatial queries on vanilla databases
Efficient spatial queries on vanilla databasesJulian Hyde
 
Programming the SQL Way with Common Table Expressions
Programming the SQL Way with Common Table ExpressionsProgramming the SQL Way with Common Table Expressions
Programming the SQL Way with Common Table ExpressionsEDB
 

What's hot (20)

MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table ExpressionsMySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions
 
Developers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OracleDevelopers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman Oracle
 
Multi-Master Replication with Slony
Multi-Master Replication with SlonyMulti-Master Replication with Slony
Multi-Master Replication with Slony
 
How to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceHow to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performance
 
Scaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQLScaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQL
 
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZEMySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
 
Fun with click house window functions webinar slides 2021-08-19
Fun with click house window functions webinar slides  2021-08-19Fun with click house window functions webinar slides  2021-08-19
Fun with click house window functions webinar slides 2021-08-19
 
クラウドDWHとしても進化を続けるPivotal Greenplumご紹介
クラウドDWHとしても進化を続けるPivotal Greenplumご紹介クラウドDWHとしても進化を続けるPivotal Greenplumご紹介
クラウドDWHとしても進化を続けるPivotal Greenplumご紹介
 
Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2
 
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
 
SQL window functions for MySQL
SQL window functions for MySQLSQL window functions for MySQL
SQL window functions for MySQL
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0
 
Faster transactions & analytics with the new SQL2016 In-memory technologies
Faster transactions & analytics with the new SQL2016 In-memory technologiesFaster transactions & analytics with the new SQL2016 In-memory technologies
Faster transactions & analytics with the new SQL2016 In-memory technologies
 
Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Window functions in MariaDB 10.2
Window functions in MariaDB 10.2
 
Using histograms to get better performance
Using histograms to get better performanceUsing histograms to get better performance
Using histograms to get better performance
 
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearch
 
Cluto presentation
Cluto presentationCluto presentation
Cluto presentation
 
Efficient spatial queries on vanilla databases
Efficient spatial queries on vanilla databasesEfficient spatial queries on vanilla databases
Efficient spatial queries on vanilla databases
 
Programming the SQL Way with Common Table Expressions
Programming the SQL Way with Common Table ExpressionsProgramming the SQL Way with Common Table Expressions
Programming the SQL Way with Common Table Expressions
 

Similar to Query optimization techniques for partitioned tables.

Innodb에서의 Purge 메커니즘 deep internal (by 이근오)
Innodb에서의 Purge 메커니즘 deep internal (by  이근오)Innodb에서의 Purge 메커니즘 deep internal (by  이근오)
Innodb에서의 Purge 메커니즘 deep internal (by 이근오)I Goo Lee.
 
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...EDB
 
Performance improvements in PostgreSQL 9.5 and beyond
Performance improvements in PostgreSQL 9.5 and beyondPerformance improvements in PostgreSQL 9.5 and beyond
Performance improvements in PostgreSQL 9.5 and beyondTomas Vondra
 
Metadata Matters
Metadata MattersMetadata Matters
Metadata Mattersafa reg
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performanceGuy Harrison
 
design-compiler.pdf
design-compiler.pdfdesign-compiler.pdf
design-compiler.pdfFrangoCamila
 
Oracle 122 partitioning_in_action_slide_share
Oracle 122 partitioning_in_action_slide_shareOracle 122 partitioning_in_action_slide_share
Oracle 122 partitioning_in_action_slide_shareThomas Teske
 
query-optimization-techniques_talk.pdf
query-optimization-techniques_talk.pdfquery-optimization-techniques_talk.pdf
query-optimization-techniques_talk.pdfgaros1
 
Recent Changes and Challenges for Future Presto
Recent Changes and Challenges for Future PrestoRecent Changes and Challenges for Future Presto
Recent Changes and Challenges for Future PrestoKai Sasaki
 
Demystifying cost based optimization
Demystifying cost based optimizationDemystifying cost based optimization
Demystifying cost based optimizationRiyaj Shamsudeen
 
MariaDB ColumnStore
MariaDB ColumnStoreMariaDB ColumnStore
MariaDB ColumnStoreMariaDB plc
 
G-Store: High-Performance Graph Store for Trillion-Edge Processing
G-Store: High-Performance Graph Store for Trillion-Edge ProcessingG-Store: High-Performance Graph Store for Trillion-Edge Processing
G-Store: High-Performance Graph Store for Trillion-Edge ProcessingPradeep Kumar
 
Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1Keshav Murthy
 
201809 DB tech showcase
201809 DB tech showcase201809 DB tech showcase
201809 DB tech showcaseKeisuke Suzuki
 
Thomas+Niewel+ +Oracletuning
Thomas+Niewel+ +OracletuningThomas+Niewel+ +Oracletuning
Thomas+Niewel+ +Oracletuningafa reg
 
Spark SQL Adaptive Execution Unleashes The Power of Cluster in Large Scale wi...
Spark SQL Adaptive Execution Unleashes The Power of Cluster in Large Scale wi...Spark SQL Adaptive Execution Unleashes The Power of Cluster in Large Scale wi...
Spark SQL Adaptive Execution Unleashes The Power of Cluster in Large Scale wi...Databricks
 
The Truth About Partitioning
The Truth About PartitioningThe Truth About Partitioning
The Truth About PartitioningEDB
 
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오PgDay.Seoul
 

Similar to Query optimization techniques for partitioned tables. (20)

Innodb에서의 Purge 메커니즘 deep internal (by 이근오)
Innodb에서의 Purge 메커니즘 deep internal (by  이근오)Innodb에서의 Purge 메커니즘 deep internal (by  이근오)
Innodb에서의 Purge 메커니즘 deep internal (by 이근오)
 
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...
 
Performance improvements in PostgreSQL 9.5 and beyond
Performance improvements in PostgreSQL 9.5 and beyondPerformance improvements in PostgreSQL 9.5 and beyond
Performance improvements in PostgreSQL 9.5 and beyond
 
Metadata Matters
Metadata MattersMetadata Matters
Metadata Matters
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performance
 
design-compiler.pdf
design-compiler.pdfdesign-compiler.pdf
design-compiler.pdf
 
Oracle 122 partitioning_in_action_slide_share
Oracle 122 partitioning_in_action_slide_shareOracle 122 partitioning_in_action_slide_share
Oracle 122 partitioning_in_action_slide_share
 
query-optimization-techniques_talk.pdf
query-optimization-techniques_talk.pdfquery-optimization-techniques_talk.pdf
query-optimization-techniques_talk.pdf
 
Recent Changes and Challenges for Future Presto
Recent Changes and Challenges for Future PrestoRecent Changes and Challenges for Future Presto
Recent Changes and Challenges for Future Presto
 
Demystifying cost based optimization
Demystifying cost based optimizationDemystifying cost based optimization
Demystifying cost based optimization
 
MariaDB ColumnStore
MariaDB ColumnStoreMariaDB ColumnStore
MariaDB ColumnStore
 
G-Store: High-Performance Graph Store for Trillion-Edge Processing
G-Store: High-Performance Graph Store for Trillion-Edge ProcessingG-Store: High-Performance Graph Store for Trillion-Edge Processing
G-Store: High-Performance Graph Store for Trillion-Edge Processing
 
Pt 3 xii cs final
Pt 3 xii cs finalPt 3 xii cs final
Pt 3 xii cs final
 
Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1
 
201809 DB tech showcase
201809 DB tech showcase201809 DB tech showcase
201809 DB tech showcase
 
Sql
SqlSql
Sql
 
Thomas+Niewel+ +Oracletuning
Thomas+Niewel+ +OracletuningThomas+Niewel+ +Oracletuning
Thomas+Niewel+ +Oracletuning
 
Spark SQL Adaptive Execution Unleashes The Power of Cluster in Large Scale wi...
Spark SQL Adaptive Execution Unleashes The Power of Cluster in Large Scale wi...Spark SQL Adaptive Execution Unleashes The Power of Cluster in Large Scale wi...
Spark SQL Adaptive Execution Unleashes The Power of Cluster in Large Scale wi...
 
The Truth About Partitioning
The Truth About PartitioningThe Truth About Partitioning
The Truth About Partitioning
 
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
 

Recently uploaded

High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
Predicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project PresentationPredicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project PresentationBoston Institute of Analytics
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
Digi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxDigi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxTanveerAhmed817946
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
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
 
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
 
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
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
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
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...Suhani Kapoor
 
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
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 

Recently uploaded (20)

High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
Predicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project PresentationPredicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project Presentation
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
Digi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxDigi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptx
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
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
 
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...
 
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
 
Decoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in ActionDecoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in Action
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
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
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
 
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
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 

Query optimization techniques for partitioned tables.

  • 1. © Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 1 Query Optimizations For Partitioned Tables Ashutosh Bapat @PGCONF INDIA 2018
  • 2. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 2 • Partition pruning • Run-time partition pruning • Partition-wise join • Partition-wise aggregation • Partition-wise sorting/ordering Query Optimization Techniques
  • 3. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 3 Partitioned Table Partition 1 FOR VALUES FROM (0) TO (100) Partition 4 FOR VALUES FROM (300) TO (400) Partition 3 FOR VALUES FROM (200) TO (300) Partition 2 FOR VALUES FROM (100) TO (200) Unpartitioned table t1 (c1 int, c2 int, …) 10, …, ... 90, …, ... 80, …, ... 325, …, …, 375, …, …, Partitioned table t1 (c1 int, c2 int, …)
  • 4. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 4 Partition Pruning SELECT * FROM t1 WHERE c1 = 350; Partition 1 FOR VALUES FROM (0) TO (100) Partitioned table t1 (c1 int, c2 int, …) Partition 4 FOR VALUES FROM (300) TO (400) Partition 3 FOR VALUES FROM (200) TO (300) Partition 2 FOR VALUES FROM (100) TO (200) SELECT * FROM t1 WHERE c1 BETWEEN 150 AND 250; Partitionboundsbasedelimination
  • 5. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 5 Run-time Partition Pruning EXEC scan_t1(350); Partition 1 FOR VALUES FROM (0) TO (100) Partitioned table t1 (c1 int, c2 int, …) Partition 4 FOR VALUES FROM (300) TO (400) Partition 3 FOR VALUES FROM (200) TO (300) Partition 2 FOR VALUES FROM (100) TO (200) Partitionboundsbasedelimination PREPARE scan_t1(int) AS SELECT * FROM t1 WHERE c1 = $1;
  • 6. © Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 7 Partition-wise Join
  • 7. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 8 Partition-wise Join Partition 1 FOR VALUES (0) TO (100) Partitioned table t1 (c1 int, ...) Partition 3 FOR VALUES (200) TO (300) Partition 2 FOR VALUES (100) TO (200) Partition 1 FOR VALUES (0) TO (100) Partition 3 FOR VALUES (200) TO (300) Partition 2 FOR VALUES (100) TO (200) Partition 1 FOR VALUES (0) TO (100) Partitioned table t2 (c1 int, ...) Partition 3 FOR VALUES (200) TO (300) Partition 2 FOR VALUES (100) TO (200) t1 JOIN t2 ON t1.c1 = t2.c1 Partitioned join Partition 3 FOR VALUES (200) TO (300) Partition 1 FOR VALUES (0) TO (100) Partition 3 FOR VALUES (200) TO (300) Partition 2 FOR VALUES (100) TO (200) Partition 3 FOR VALUES (200) TO (300) Partition 1 FOR VALUES (0) TO (100) Partition 3 FOR VALUES (200) TO (300) Partition 2 FOR VALUES (100) TO (200)
  • 8. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 10 • Scale 20 • Schema changes – lineitems PARTITION BY RANGE(l_orderkey) – orders PARTITION BY RANGE(o_orderkey) – Each with 17 partitions • GUCs – work_mem - 1GB – effective_cache_size - 8GB – shared_buffers - 8GB – enable_partition_wise_join = on TPCH Vs. Partition-wise Join (Scale 20)
  • 9. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 11 TPCH Vs. Partition-wise Join (Scale 20) (linear time scale) Q3 Q4 Q5 Q7 Q10 Q12 Q18 0 100 200 300 400 500 600 700 800 Unpartitioned tables Partitioned tables without PWJ Partitioned tables with PWJ TPCH queries (scale 20) Queryexecutiontime(seconds)
  • 10. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 12 TPCH Vs. Partition-wise Join (Scale 20) (scaled execution time) Q3 Q4 Q5 Q7 Q10 Q12 Q18 1 10 100 Unpartitioned tables Partitioned tables without PWJ Partitioned tables with PWJ TPCH queries (scale 20) scaledqueryexecutiontime
  • 11. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 13 TPCH Vs. partition-wise join: observations ● Join strategy change from join between partitioned tables to join between partitions – MergeJoin to HashJoin ● Q3, Q5, Q10, Q12, Q18 – HashJoin to parameterized NestLoop join ● Q4 ● Different join strategies for different partition-joins ● Q7 ● Change in order of joining partitioned tables – Q3, Q5, Q10, Q12, Q18, Q7
  • 12. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 14 • Scale 300 • Schema changes – lineitems PARTITION BY RANGE(l_orderkey) – orders PARTITION BY RANGE(o_orderkey) – Each with 106 partitions • GUCs – work_mem - 1GB – effective_cache_size - 10GB – shared_buffers - 10GB – enable_partition_wise_join = on – max_parallel_workers_per_gather = 4 TPCH Vs. Partition-wise Join (Scale 300) Reported by Rafia Sabih
  • 13. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 15 TPCH Vs. Partition-wise Join (Scale 300) Q3 Q4 Q5 Q10 Q12 0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 Unpartitioned tables Partitioned tables without PWJ Partitioned tables with PWJ TPCH queries (scale 20) Queryexecutiontime(seconds) Partitioning makes queries faster
  • 14. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 16 Partition pruning and Partition-wise Join Partition 1 FOR VALUES (0) TO (100) Partitioned table t1 (c1 int, ...) Partition 3 FOR VALUES (200) TO (300) Partition 2 FOR VALUES (100) TO (200) Partition 1 FOR VALUES (0) TO (100) Partitioned table t2 (c1 int, ...) Partition 3 FOR VALUES (200) TO (300) Partition 2 FOR VALUES (100) TO (200) t1 JOIN t2 ON t1.c1 = t2.c1 SELECT … FROM t1 JOIN t2 ON t1.c1 = t2.c1 WHERE t1.c1 > 100 AND t2.c1 < 200
  • 15. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 17 Partition pruning and Partition-wise Join Partitioned join Partition 1 FOR VALUES (0) TO (100) Partition 3 FOR VALUES (200) TO (300) Partition 2 FOR VALUES (100) TO (200) Partition 1 FOR VALUES (0) TO (100) Partition 3 FOR VALUES (200) TO (300) Partition 2 FOR VALUES (100) TO (200) Partitioned join Partition 2 FOR VALUES (100) TO (200) Partition 2 FOR VALUES (100) TO (200)
  • 16. © Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 18 Partition-wise aggregation and grouping
  • 17. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 19 Full partition-wise aggregation Partitioned table t1 (c1 int, ...) Partition 1 Partition 3 Partition 2 Partition 1 Partitioned table t2 (c1 int, ...) Partition 3 Partition 2 t1 JOIN t2 ON t1.c1 = t2.c1 Partition 1 Partition 3 Partition 2 Partition 1 Partition 3 Partition 2 Group by t1.c1 Group by t1.c1 Group by t1.c1 Group by t1.c1
  • 18. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 20 Partial partition-wise aggregation Partitioned table t1 (c1 int, ...) Partition 1 Partition 3 Partition 2 Partition 1 Partitioned table t2 (c1 int, ...) Partition 3 Partition 2 t1 JOIN t2 ON t1.c1 = t2.c1 Partition 1 Partition 3 Partition 2 Partition 1 Partition 3 Partition 2 Group by t1.c2 Partial Aggregation Group by t1.c2 Partial Aggregation Group by t1.c2 Partial Aggregation Group by t1.c2 Full Aggregation Group by t1.c2
  • 19. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 22 Source: Jeevan Chalke's partition-wise aggregate proposal Query: SELECT a, count(*) FROM plt1 GROUP BY a; plt1: partitioned table with 3 foreign partitions, each with 1M rows Query returns 30 rows, 10 rows per partition enable_partition_wise_agg to false QUERY PLAN ------------------------------------- HashAggregate Group Key: plt1.a -> Append -> Foreign Scan on fplt1_p1 -> Foreign Scan on fplt1_p2 -> Foreign Scan on fplt1_p3 Planning time: 0.251 ms Execution time: 6499.018ms ~ 6.5s enable_partition_wise_agg to true QUERY PLAN ------------------------------------------------------- Append -> Foreign Scan: Aggregate on (public.fplt1_p1 plt1) -> Foreign Scan: Aggregate on (public.fplt1_p2 plt1) -> Foreign Scan: Aggregate on (public.fplt1_p3 plt1) Planning time: 0.370ms Execution time: 945.384ms ~ .9s Example 7x faster
  • 20. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 23 Partition-wise sorting Partitioned table t1 (c1 int, ...) Partition 1 Partition 3 Partition 2 Partition 1 Partitioned table t2 (c1 int, ...) Partition 3 Partition 2 t1 JOIN t2 ON t1.c1 = t2.c1 Partition 1 Partition 3 Partition 2 Partition 1 Partition 3 Partition 2 Sort by c1 Sort by c1 Sort by c1 Sort by c1
  • 21. © Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 24 Parallel Append and Partitioning
  • 22. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 25 Parallel Append and Partitioning Partition 1 Partition 3Partition 2Partition 1 Partition 3Partition 2 Group by t1.c1 Group by t1.c1 Group by t1.c1 Worker Backend 1 Worker Backend 2 Worker Backend 1 Worker Backend 3 Leader Backend
  • 23. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 26 TPCH Vs. PWJ + PA Q3 Q4 Q5 Q7 Q10 Q12 Q18 0 100 200 300 400 500 600 700 800 Unpartitioned tables Partitioned tables without PWJ Partitioned tables with PWJ Partitioned tables with PWJ and PA TPCH queries (scale 20) Queryexecutiontime(seconds)
  • 24. © Copyright EnterpriseDB Corporation, 2018. All Rights Reserved. 27 • Committed patches – Basic partition-wise join - Ashutosh Bapat (EDB) – Parallel append – Amit Khandekar (EDB) • Patches submitted on hackers and being reviewed – Partition pruning – Amit Langote (NTT) – Run-time partition pruning – Beena Emerson (EDB) – Partition-wise aggregation – Jeevan Chalke (EDB) – Partition-wise sorting/ordering – Ronan Dunklau, Julien Rouhaud (Dalibo) ● Benchmarking by Rafia Sabih (EDB) Query Optimization Techniques - patches