SlideShare a Scribd company logo
© Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 1
Partition and Conquer large data in
PostgreSQL 10
• Ashutosh Bapat | 2017.02.03 @ PGConf India
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 2
• Manageability
– Smaller data is easier to manage
– Partition-wise utility commands
– Easy bulk load and deletes
• Query/DML Performance
– Partition elimination (pruning)
– Partition-wise joins, aggregate
– Distribute DMLs across partitions
• Data storages based on partition properties
– “hot” and “cold” partitions
– Foreign partitions
Why to partition tables?
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 3
• Maintenance
– No triggers, rules or constraints to maintain
– Adding/deleting partition does not require more than a
single command
• Faster queries and DMLs
– No trigger execution overhead
●
DMLs are 10-20 times faster
– Simpler partition bounds representation
– Faster partition pruning
– Partition-wise join, aggregation
Why declarative partitioning?
(instead of inheritance based partitioning)
© Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 4
Declarative partitioning in
PostgreSQL 10
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 5
●
Partitioning methods: List, range, (WIP. hash)
●
Partition key: Single or multiple columns, expressions
●
Sub-partitioning
– Partitioned partitions
– Mixed sub-partitioning
●
Development efforts
– Several previous attempts by many people
– Amit Langote proposed first patch in August 2015
– Got committed in Dec 2016, bug fixes, doc changes continue ...
PostgreSQL Declarative partitioning
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 6
CREATE TABLE part_tab (c1 int, c2 int, …) PARTITION BY RANGE (c1);
Creating partitioned table
part_tab (c1 int, c2 int, ...)
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 7
CREATE TABLE part_tab (c1 int, c2 int, …) PARTITION BY RANGE (c1);
CREATE TABLE part1 PARTITION OF part_tab FOR VALUES FROM (0) TO (100);
CREATE TABLE part2 PARTITION OF part_tab FOR VALUES FROM (100) TO (200);
Creating partitioned table
part_tab (c1 int, c2 int, ...)
Part1
0 to 100
Part2
100 to 200
Tablespaces
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 8
ALTER TABLE part_tab ATTACH PARTITION ext_part FOR VALUES FROM (400) to (500);
ATTACH partition
part_tab (c1 int, c2 int, ...)
Part1
0 to 100
Part2
100 to 200
ext_part
400 to 500
ext_part (c1 int, c2 int, ...)
CHECK c1 >= 400 AND c1 < 500
Bulk load
data.csv
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 9
ALTER TABLE part_tab DETACH PARTITION ext_part;
DETACH partition
part_tab (c1 int, c2 int, ...)
Part1
0 to 100
Part2
100 to 200
ext_part (c1 int, c2 int, ...)
CHECK c1 >= 400 AND c1 < 500
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 10
●
Same columns as parent table
●
Partition specific constraints, defaults, indexes,
storage parameters
●
Tablespace separate from that of parent
– “hot” and “cold” partitions
●
VACUUM, ANALYZE, CLUSTER can be run
separately
– Utilities don't block the whole table
– Work where it's required
Partitions are tables
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 11
CREATE TABLE part_tab (c1 int, c2 int, …) PARTITION BY RANGE (c1);
...
CREATE FOREIGN TABLE part3 PARTITION OF part_tab FOR VALUES FROM (300) TO
(400) SERVER xyz_server;
CREATE FOREIGN TABLE part4 PARTITION OF part_tab FOR VALUES FROM (400) TO
(500) SERVER abc_server;
Foreign partitions
part_tab (c1 int, c2 int, ...)
Part1
0 to 100
Part2
100 to 200
Part3
300 to 400
fpart3 (c1 int, c2 int, ...)
c1 >= 300 AND c1 < 400
xyz_server
xyz_fdw
Part4
400 to 500
fpart3 (c1 int, c2 int, ...)
c1 >= 400 AND c1 < 500
abc_server
abc_fdw
© Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 12
Query optimizations
partition pruning
partition-wise join
partition-wise aggregation
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 13
Query optimization: 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;
Constraintexclusion
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 14
Query optimization: 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, 2017. All Rights Reserved. 15
Query optimization: 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
Agg/Group
Agg/Group
Agg/Group
Agg/Group
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 16
• Bad partitioning is worse than no partitioning
• Query optimization
– Partition key is the key to success
– Columns in conditions
– include it in the query
• Storage management
– Columns that decide the storage
– Usually timestamp of the row
– Easy to add and drop partitions
• Keep an eye on current limitations
– Expected to reduce with next few releases
Choosing partitioning scheme
© Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 17
• We have just begun …
• No triggers on partitioned table
– Need to create those for each of the partitions
• No SPLIT, MERGE, EXCHANGE partition
• No global indexes
– No primary key, unique constraints
• Foreign partitions
– INSERTs via parent table not supported
– No ACID support for transactions involving multiple foreign servers
Limitations
Partition and conquer large data in PostgreSQL 10

More Related Content

What's hot (19)

ODP
Scaling PostgreSQL With GridSQL
Jim Mlodgenski
 
PDF
Developers' mDay 2017. - Bogdan Kecman Oracle
mCloud
 
PDF
How to analyze and tune sql queries for better performance
oysteing
 
PDF
クラウドDWHとしても進化を続けるPivotal Greenplumご紹介
Masayuki Matsushita
 
PDF
Fun with click house window functions webinar slides 2021-08-19
Altinity Ltd
 
PDF
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
Insight Technology, Inc.
 
PDF
Common Table Expressions in MariaDB 10.2
Sergey Petrunya
 
PDF
Spatial query on vanilla databases
Julian Hyde
 
PPTX
Faster transactions & analytics with the new SQL2016 In-memory technologies
Henk van der Valk
 
PDF
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Sergey Petrunya
 
PDF
SQL window functions for MySQL
Dag H. Wanvik
 
PDF
Efficient spatial queries on vanilla databases
Julian Hyde
 
PDF
Scaling PostreSQL with Stado
Jim Mlodgenski
 
PDF
Migration from mysql to elasticsearch
Ryosuke Nakamura
 
PDF
Using histograms to get better performance
Sergey Petrunya
 
PDF
Table partitioning in PostgreSQL + Rails
Agnieszka Figiel
 
PPTX
Cluto presentation
Roseline Antai
 
ODP
Basic Query Tuning Primer - Pg West 2009
mattsmiley
 
PPTX
Lazy beats Smart and Fast
Julian Hyde
 
Scaling PostgreSQL With GridSQL
Jim Mlodgenski
 
Developers' mDay 2017. - Bogdan Kecman Oracle
mCloud
 
How to analyze and tune sql queries for better performance
oysteing
 
クラウドDWHとしても進化を続けるPivotal Greenplumご紹介
Masayuki Matsushita
 
Fun with click house window functions webinar slides 2021-08-19
Altinity Ltd
 
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
Insight Technology, Inc.
 
Common Table Expressions in MariaDB 10.2
Sergey Petrunya
 
Spatial query on vanilla databases
Julian Hyde
 
Faster transactions & analytics with the new SQL2016 In-memory technologies
Henk van der Valk
 
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Sergey Petrunya
 
SQL window functions for MySQL
Dag H. Wanvik
 
Efficient spatial queries on vanilla databases
Julian Hyde
 
Scaling PostreSQL with Stado
Jim Mlodgenski
 
Migration from mysql to elasticsearch
Ryosuke Nakamura
 
Using histograms to get better performance
Sergey Petrunya
 
Table partitioning in PostgreSQL + Rails
Agnieszka Figiel
 
Cluto presentation
Roseline Antai
 
Basic Query Tuning Primer - Pg West 2009
mattsmiley
 
Lazy beats Smart and Fast
Julian Hyde
 

Viewers also liked (19)

PDF
Atomicity for transactions involving foreign server in PostgreSQL
Ashutosh Bapat
 
PDF
Postgres_9.0 vs MySQL_5.5
Trieu Dao Minh
 
PDF
EnterpriseDB Postgres Survey Results - 2013
EDB
 
PDF
NoSQL on ACID - Meet Unstructured Postgres
EDB
 
PDF
Top 10 Tips for an Effective Postgres Deployment
EDB
 
PPTX
PGEncryption_Tutorial
Vibhor Kumar
 
PDF
Aikakausmediat somessa / kesäkuu 2016
Aikakausmedia
 
PPT
Харчування у профілактиці серцево-судинних захворювань
MyHelix
 
PDF
Afaceri interactive de robert kiyosaki
Cotoflea Simona-Roxana
 
PDF
Getting Started with PostGIS
EDB
 
PDF
PostgreSQL Internals (1) for PostgreSQL 9.6 (English)
Noriyoshi Shinoda
 
PPS
Hechos de los Apóstoles
deliagatocasado
 
PDF
Migrating from Oracle to Postgres
EDB
 
PPT
Family members game
Fernando garza
 
PDF
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
Wei Shan Ang
 
PDF
Puppet Camp Singapore 2015 - 19th Nov 2015 Presentation (1)
Wei Shan Ang
 
PDF
SP DIT Bonding Day - 05062015
Wei Shan Ang
 
PDF
PUGS Meetup Presentation - 11062015
Wei Shan Ang
 
PPTX
Security Automation Approach #1: Workflow
Lauren Kersanske
 
Atomicity for transactions involving foreign server in PostgreSQL
Ashutosh Bapat
 
Postgres_9.0 vs MySQL_5.5
Trieu Dao Minh
 
EnterpriseDB Postgres Survey Results - 2013
EDB
 
NoSQL on ACID - Meet Unstructured Postgres
EDB
 
Top 10 Tips for an Effective Postgres Deployment
EDB
 
PGEncryption_Tutorial
Vibhor Kumar
 
Aikakausmediat somessa / kesäkuu 2016
Aikakausmedia
 
Харчування у профілактиці серцево-судинних захворювань
MyHelix
 
Afaceri interactive de robert kiyosaki
Cotoflea Simona-Roxana
 
Getting Started with PostGIS
EDB
 
PostgreSQL Internals (1) for PostgreSQL 9.6 (English)
Noriyoshi Shinoda
 
Hechos de los Apóstoles
deliagatocasado
 
Migrating from Oracle to Postgres
EDB
 
Family members game
Fernando garza
 
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
Wei Shan Ang
 
Puppet Camp Singapore 2015 - 19th Nov 2015 Presentation (1)
Wei Shan Ang
 
SP DIT Bonding Day - 05062015
Wei Shan Ang
 
PUGS Meetup Presentation - 11062015
Wei Shan Ang
 
Security Automation Approach #1: Workflow
Lauren Kersanske
 
Ad

Similar to Partition and conquer large data in PostgreSQL 10 (20)

PDF
The Truth About Partitioning
EDB
 
PDF
Practical Partitioning in Production with Postgres
Jimmy Angelakos
 
PDF
Practical Partitioning in Production with Postgres
EDB
 
PDF
PostgreSQL - Decoding Partitions
Beena Emerson
 
PPTX
Sql server lesson7
Ala Qunaibi
 
PDF
PostgreSQL Table Partitioning / Sharding
Amir Reza Hashemi
 
PDF
Partitioning tables and indexing them
Hemant K Chitale
 
PDF
MySQL partitions tutorial
Giuseppe Maxia
 
PDF
PostgreSQL 13 is Coming - Find Out What's New!
EDB
 
PPTX
Partitioning kendralittle
ngupt28
 
PPTX
New and Improved Features in PostgreSQL 13
EDB
 
PDF
Optimizing Queries over Partitioned Tables in MPP Systems
EMC
 
PPT
Informix partitioning interval_rolling_window_table
Keshav Murthy
 
PPTX
Partitioning 101
Connor McDonald
 
PPTX
Postgres db performance improvements
Mahesh Chopker
 
PDF
Table Partitioning: Secret Weapon for Big Data Problems
John Sterrett
 
PDF
Introducing Postgres Plus Advanced Server 9.4
EDB
 
PDF
Table Partitioning in SQL Server: A Magic Solution for Better Performance? (P...
Cathrine Wilhelmsen
 
PPTX
Hypothetical Partitioning for PostgreSQL
Yuzuko Hosoya
 
ODP
Chetan postgresql partitioning
suniltomar04
 
The Truth About Partitioning
EDB
 
Practical Partitioning in Production with Postgres
Jimmy Angelakos
 
Practical Partitioning in Production with Postgres
EDB
 
PostgreSQL - Decoding Partitions
Beena Emerson
 
Sql server lesson7
Ala Qunaibi
 
PostgreSQL Table Partitioning / Sharding
Amir Reza Hashemi
 
Partitioning tables and indexing them
Hemant K Chitale
 
MySQL partitions tutorial
Giuseppe Maxia
 
PostgreSQL 13 is Coming - Find Out What's New!
EDB
 
Partitioning kendralittle
ngupt28
 
New and Improved Features in PostgreSQL 13
EDB
 
Optimizing Queries over Partitioned Tables in MPP Systems
EMC
 
Informix partitioning interval_rolling_window_table
Keshav Murthy
 
Partitioning 101
Connor McDonald
 
Postgres db performance improvements
Mahesh Chopker
 
Table Partitioning: Secret Weapon for Big Data Problems
John Sterrett
 
Introducing Postgres Plus Advanced Server 9.4
EDB
 
Table Partitioning in SQL Server: A Magic Solution for Better Performance? (P...
Cathrine Wilhelmsen
 
Hypothetical Partitioning for PostgreSQL
Yuzuko Hosoya
 
Chetan postgresql partitioning
suniltomar04
 
Ad

Recently uploaded (20)

PPTX
美国史蒂文斯理工学院毕业证书{SIT学费发票SIT录取通知书}哪里购买
Taqyea
 
PDF
Group 5_RMB Final Project on circular economy
pgban24anmola
 
PDF
1750162332_Snapshot-of-Indias-oil-Gas-data-May-2025.pdf
sandeep718278
 
PDF
Business implication of Artificial Intelligence.pdf
VishalChugh12
 
PPTX
Comparative Study of ML Techniques for RealTime Credit Card Fraud Detection S...
Debolina Ghosh
 
PDF
Using AI/ML for Space Biology Research
VICTOR MAESTRE RAMIREZ
 
PDF
Unlocking Insights: Introducing i-Metrics Asia-Pacific Corporation and Strate...
Janette Toral
 
PDF
OOPs with Java_unit2.pdf. sarthak bookkk
Sarthak964187
 
PDF
NIS2 Compliance for MSPs: Roadmap, Benefits & Cybersecurity Trends (2025 Guide)
GRC Kompas
 
PDF
apidays Singapore 2025 - The API Playbook for AI by Shin Wee Chuang (PAND AI)
apidays
 
PPT
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
PPTX
BinarySearchTree in datastructures in detail
kichokuttu
 
PDF
The Best NVIDIA GPUs for LLM Inference in 2025.pdf
Tamanna36
 
PPTX
big data eco system fundamentals of data science
arivukarasi
 
PDF
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
PPTX
Powerful Uses of Data Analytics You Should Know
subhashenia
 
PDF
Data Science Course Certificate by Sigma Software University
Stepan Kalika
 
PDF
Research Methodology Overview Introduction
ayeshagul29594
 
PPTX
03_Ariane BERCKMOES_Ethias.pptx_AIBarometer_release_event
FinTech Belgium
 
PDF
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 
美国史蒂文斯理工学院毕业证书{SIT学费发票SIT录取通知书}哪里购买
Taqyea
 
Group 5_RMB Final Project on circular economy
pgban24anmola
 
1750162332_Snapshot-of-Indias-oil-Gas-data-May-2025.pdf
sandeep718278
 
Business implication of Artificial Intelligence.pdf
VishalChugh12
 
Comparative Study of ML Techniques for RealTime Credit Card Fraud Detection S...
Debolina Ghosh
 
Using AI/ML for Space Biology Research
VICTOR MAESTRE RAMIREZ
 
Unlocking Insights: Introducing i-Metrics Asia-Pacific Corporation and Strate...
Janette Toral
 
OOPs with Java_unit2.pdf. sarthak bookkk
Sarthak964187
 
NIS2 Compliance for MSPs: Roadmap, Benefits & Cybersecurity Trends (2025 Guide)
GRC Kompas
 
apidays Singapore 2025 - The API Playbook for AI by Shin Wee Chuang (PAND AI)
apidays
 
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
BinarySearchTree in datastructures in detail
kichokuttu
 
The Best NVIDIA GPUs for LLM Inference in 2025.pdf
Tamanna36
 
big data eco system fundamentals of data science
arivukarasi
 
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
Powerful Uses of Data Analytics You Should Know
subhashenia
 
Data Science Course Certificate by Sigma Software University
Stepan Kalika
 
Research Methodology Overview Introduction
ayeshagul29594
 
03_Ariane BERCKMOES_Ethias.pptx_AIBarometer_release_event
FinTech Belgium
 
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 

Partition and conquer large data in PostgreSQL 10

  • 1. © Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 1 Partition and Conquer large data in PostgreSQL 10 • Ashutosh Bapat | 2017.02.03 @ PGConf India
  • 2. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 2 • Manageability – Smaller data is easier to manage – Partition-wise utility commands – Easy bulk load and deletes • Query/DML Performance – Partition elimination (pruning) – Partition-wise joins, aggregate – Distribute DMLs across partitions • Data storages based on partition properties – “hot” and “cold” partitions – Foreign partitions Why to partition tables?
  • 3. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 3 • Maintenance – No triggers, rules or constraints to maintain – Adding/deleting partition does not require more than a single command • Faster queries and DMLs – No trigger execution overhead ● DMLs are 10-20 times faster – Simpler partition bounds representation – Faster partition pruning – Partition-wise join, aggregation Why declarative partitioning? (instead of inheritance based partitioning)
  • 4. © Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 4 Declarative partitioning in PostgreSQL 10
  • 5. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 5 ● Partitioning methods: List, range, (WIP. hash) ● Partition key: Single or multiple columns, expressions ● Sub-partitioning – Partitioned partitions – Mixed sub-partitioning ● Development efforts – Several previous attempts by many people – Amit Langote proposed first patch in August 2015 – Got committed in Dec 2016, bug fixes, doc changes continue ... PostgreSQL Declarative partitioning
  • 6. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 6 CREATE TABLE part_tab (c1 int, c2 int, …) PARTITION BY RANGE (c1); Creating partitioned table part_tab (c1 int, c2 int, ...)
  • 7. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 7 CREATE TABLE part_tab (c1 int, c2 int, …) PARTITION BY RANGE (c1); CREATE TABLE part1 PARTITION OF part_tab FOR VALUES FROM (0) TO (100); CREATE TABLE part2 PARTITION OF part_tab FOR VALUES FROM (100) TO (200); Creating partitioned table part_tab (c1 int, c2 int, ...) Part1 0 to 100 Part2 100 to 200 Tablespaces
  • 8. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 8 ALTER TABLE part_tab ATTACH PARTITION ext_part FOR VALUES FROM (400) to (500); ATTACH partition part_tab (c1 int, c2 int, ...) Part1 0 to 100 Part2 100 to 200 ext_part 400 to 500 ext_part (c1 int, c2 int, ...) CHECK c1 >= 400 AND c1 < 500 Bulk load data.csv
  • 9. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 9 ALTER TABLE part_tab DETACH PARTITION ext_part; DETACH partition part_tab (c1 int, c2 int, ...) Part1 0 to 100 Part2 100 to 200 ext_part (c1 int, c2 int, ...) CHECK c1 >= 400 AND c1 < 500
  • 10. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 10 ● Same columns as parent table ● Partition specific constraints, defaults, indexes, storage parameters ● Tablespace separate from that of parent – “hot” and “cold” partitions ● VACUUM, ANALYZE, CLUSTER can be run separately – Utilities don't block the whole table – Work where it's required Partitions are tables
  • 11. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 11 CREATE TABLE part_tab (c1 int, c2 int, …) PARTITION BY RANGE (c1); ... CREATE FOREIGN TABLE part3 PARTITION OF part_tab FOR VALUES FROM (300) TO (400) SERVER xyz_server; CREATE FOREIGN TABLE part4 PARTITION OF part_tab FOR VALUES FROM (400) TO (500) SERVER abc_server; Foreign partitions part_tab (c1 int, c2 int, ...) Part1 0 to 100 Part2 100 to 200 Part3 300 to 400 fpart3 (c1 int, c2 int, ...) c1 >= 300 AND c1 < 400 xyz_server xyz_fdw Part4 400 to 500 fpart3 (c1 int, c2 int, ...) c1 >= 400 AND c1 < 500 abc_server abc_fdw
  • 12. © Copyright EnterpriseDB Corporation, 2015. All Rights Reserved. 12 Query optimizations partition pruning partition-wise join partition-wise aggregation
  • 13. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 13 Query optimization: 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; Constraintexclusion
  • 14. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 14 Query optimization: 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)
  • 15. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 15 Query optimization: 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 Agg/Group Agg/Group Agg/Group Agg/Group
  • 16. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 16 • Bad partitioning is worse than no partitioning • Query optimization – Partition key is the key to success – Columns in conditions – include it in the query • Storage management – Columns that decide the storage – Usually timestamp of the row – Easy to add and drop partitions • Keep an eye on current limitations – Expected to reduce with next few releases Choosing partitioning scheme
  • 17. © Copyright EnterpriseDB Corporation, 2017. All Rights Reserved. 17 • We have just begun … • No triggers on partitioned table – Need to create those for each of the partitions • No SPLIT, MERGE, EXCHANGE partition • No global indexes – No primary key, unique constraints • Foreign partitions – INSERTs via parent table not supported – No ACID support for transactions involving multiple foreign servers Limitations