SlideShare a Scribd company logo
© 2013 EDB All rights reserved. 1
Query Parallelism In PostgreSQL
What’s coming next?
Dilip Kumar
(Principle Software Engineer)
© 2016 EDB All rights reserved. 2
❏ Infrastructure for parallelism
❏ Intra-query parallelism in v9.6
❏ Parallel aware executor nodes
❏ Performance on TPC-H
❏ Parallelism enhancements in v10
❏ More executor-nodes
❏ Performance on TPC-H
❏ Take away
© 2016 EDB All rights reserved. 3
❏ Groundwork for parallelism
❏ Dynamic background workers
❏ Dynamic shared memory
❏ Shared messaging capabilities
❏ Group locking
❏ Parallel context
❏ Intra-query parallel support
❏ Parallel executor
❏ Parallel-aware nodes
❏ seq scan,
❏ joins, and
❏ aggregates
© 2016 EDB All rights reserved. 4
Gather
nodeGather.c
Parallel-Aware
Executor Nodes
nodeSeqScan.c
nodeForeignScan.c
nodeCustom.c
Parallel Executor
Support
execParallel.c
Tuple Queue Reader
and DestReceiver
tqueue.c
Dynamic
Background Workers
bgworker.c
Dynamic Shared
Memory
dsm.c, dsm_impl.c
Shared Memory
Message Queue
shm_mq.c
Parallel Context
parallel.c
Shared Memory
Table of Contents
shm_toc.c
Error/Notice
Forwarding
pqmq.c
State Synchronization
dfmgr.c, guc.c, combocid.c,
snapmgr.c, xact.c
Group Locking
lock.c
© 2016 EDB All rights reserved. 5
❏ Dynamic background worker (shm_mq)
❏ Postmaster can launch the background worker processes
at run time
❏ Dynamic shared memory
❏ Allocate a chunk of memory that can be shared among
co-operating processes
❏ Shared memory table of contents
❏ A simple scheme for carving DSM into numbered chunks
❏ Shared messaging capabilities
❏ Shared memory message queue
❏ For error/notice forwarding
❏ Tuple queue reader and DestReceiver
© 2016 EDB All rights reserved. 6
❏ Parallel context
❏ Core toolkit for parallel operations
❏ Launch a number of workers, establish “useful”
state, run C code you specify and ensure timely
shutdown.
❏ State synchronization
❏ To ensure same GUC values, libraries, and
transactions with same snapshot across workers
❏ Group locking
❏ To solve the issue of undetected deadlock
❏ Leader and its workers are treated as one entity for
locking purposes
© 2016 EDB All rights reserved. 7
❏ Parallel executor support
❏ Execute a plan by a set of worker
❏ Pass instrumentation information to each worker
❏ Parallel aware executor nodes
❏ Different behaviour when run in parallel or otherwise
❏ Gather
❏ Collect results across all workers and merge them
into a single result stream
© 2016 EDB All rights reserved. 8
❏ Parallel access methods
❏ Seq scan is the only parallel access method
❏ No support for parallel index, index-only or
bitmap-heap scan
❏ Parallel joins
❏ NestedLoop and Hash joins are supported for parallel
execution
❏ For hash-join, each worker prepares its own copy of
hash-table
❏ Merge join cannot execute in parallel
❏ Parallel aggregates
❏ Each worker performs partial aggregate and finalize
aggregate is done by leader
© 2016 EDB All rights reserved. 9
❏ Experimental setup
❏ IBM power7 box (popularly known as Hydra in
community)
❏ Parameter settings
❏ Max_parallel_degree = 4
❏ Work_mem = 64 MB
❏ Shared_buffers = 8 GB
❏ Database setup
❏ Scale factor = 10
© 2016 EDB All rights reserved. 10
© 2016 EDB All rights reserved. 11
❏ Need parallel-index scan
❏ Q6, Q14
❏ Need parallel bitmap-heap scan
❏ Q4, Q15
❏ Need parallel merge-join
❏ Q2, Q3, Q9, Q20
❏ Need parallel hash table build
❏ Q3, Q5, Q7, Q8, Q21
❏ Need parallel subquery handling
❏ Q2, Q22


© 2016 EDB All rights reserved. 12
❏ More parallel executor nodes
❏ Access methods
❏ Parallel index, index-only, bitmap-heap
❏ Join methods
❏ Merge join
❏ Hash join with shared hash
❏ Other
❏ Gather-merge
❏ Relaxation for nodes using uncorrelated sub-plan, init-plan
❏ Improvements in parallel-append
❏ Parallel DDL/maintenance commands
❏ Index-creation
❏ Vacuum
© 2016 EDB All rights reserved. 13
❏ Parallel index scan
❏ Firstly, a worker will process the intermediate pages
of B-tree and determine the starting leaf page where
scan is to be started
❏ Next, all the workers start scanning the leaf pages
block by block
❏ Finally, all the filtered tuples are gathered by the
leader process
❏ This operator improves the performance significantly
when the database is in-memory
❏ Similar mechanism is built for index-only scans
© 2016 EDB All rights reserved. 14
❏ Parallel bitmap heap scan
❏ A bitmap scan fetches all the pointers from index in
one go, sort them using in-memory “bitmap”, finally,
visits the tuple in physical order
❏ Bitmap will be created by a single worker
❏ Next, all the workers will jointly scan the heap,
page by page
❏ For further improvement, we can also build bitmap by
multiple workers
© 2016 EDB All rights reserved. 15
❏ Parallel bitmap heap scan
Gather
Workers Planned: 2
-> Parallel Bitmap Heap Scan on foo
Recheck Cond: ((a < 100000) OR (b <
10000))
-> BitmapOr
-> Bitmap Index Scan on idx1
Index Cond: (a < 100000)
-> Bitmap Index Scan on idx2
Index Cond: (b < 10000)
© 2016 EDB All rights reserved. 16
❏ Parallel Merge Join
❏ If outer node is using parallelism then we consider
parallel merge-join
❏ Outer node will be scanned in parallel by multiple workers
❏ Inner node will be processed completely by individual workers
❏ There is still scope of improvements in this strategy
❏ Parallelise inner sort or materialize nodes
© 2016 EDB All rights reserved. 17
❏ Parallel shared hash
❏ Previously, each worker builds its own copy of hash
table
❏ This is particularly favourable to cases when hash
table is small
❏ Improved mechanism is to employ the workers for
building hash-table in parallel
❏ Once, hash-table is ready, parallel probing can be
done
❏ This facilitates the usage of parallel operators on
either sides of joins
© 2016 EDB All rights reserved. 18
Parallel shared-hash
Gather
Workers Planned: 2
Workers Launched: 2
-> Hash Join
Hash Cond (foo.b = bar.b)
-> Parallel Seq Scan on foo
-> Parallel Shared Hash
-> Parallel Seq Scan on bar
© 2016 EDB All rights reserved. 19
❏ Gather-merge
❏ Previously, there was only one option to collect the
result from parallel operators i.e gather, it does
not maintain interesting order
❏ Therefore, extra sort node is required on top for
ordered output
❏ Now, if workers are providing sorted result
specifically, output from parallel index, parallel
merge join, etc. then gather-merge will maintain the
sort-order in the final result
© 2016 EDB All rights reserved. 20
❏ Experimental setup
❏ RAM = 512 GB
❏ Number of cores = 32
❏ Parameter settings
❏ Work_mem = 64 MB
❏ Shared_buffers = 8 GB
❏ Effective_cache_size = 10 GB
❏ Random_page_cost = seq_page_cost = 0.1
❏ Max_parallel_workers_per_gather = 4
❏ Database setup
❏ Scale factors = 20, 300
❏ Additional indexes: l_shipmode, l_shipdate,
o_orderdate, o_comment
© 2016 EDB All rights reserved. 21
Results on scale factor 20
© 2016 EDB All rights reserved. 22
Results on scale factor 20
© 2016 EDB All rights reserved. 23
Results on scale factor 300
© 2016 EDB All rights reserved. 24
❏ Tuning parameters
❏ Max_parallel_workers_per_gather
❏ Recommended value 1 to 4
❏ Reduce following costs
❏ Parallel_tuple_cost: planner's estimate of the cost of transferring one tuple from a
parallel worker process to another process
❏ Parallel_setup_cost: planner's estimate for launching parallel workers and initializing
dynamic shared memory
❏ Min_parallel_table_scan_size: the minimum size of relations to be considered for
parallel sequence scan
❏ Min_parallel_index_scan_size: the minimum size of index to be considered for parallel
scan
❏ Random_page_cost: estimated cost of accessing a random page in disk
❏ Increase following parameters
❏ Work_mem
❏ Effective_cache_size
❏ Shared_buffers
© 2016 EDB All rights reserved. 25
❏ Adding intra-query parallelism improves per query response time
❏ Previously, overall throughput was the only focus
❏ This makes it more suitable for OLAP environments
❏ Till version 9.6, parallel support for sequence scan, hash join, nestloop join,
and aggregates is available
❏ Out of 22 queries of TPC-H, performance improved for 15 queries
❏ In which 3 queries are at least 4 times faster and 11 queries are 2
times faster
❏ More parallel executor nodes are planned for upcoming versions
❏ More parallel access methods - index, index-only are already
committed
❏ Improved parallel join mechanisms
❏ Gather with interesting order
❏ Removed restrictions for nodes using SubPlans(already committed) or
InitPlans
❏ Around 10 of 22 TPC-H queries show significant improvement in
performance
❏ In which around 4 queries show more than 2x improvement
© 2016 EDB All rights reserved. 26
27
Output: Thank You
Gather
Workers Planned: 2
Workers Launched: 2
-> Parallel Index Scan on Common_phrases
Index Cond: ( value = ‘Thank You’ )
Filter: Language = ‘English’
Slide credits:
[1] https://www.pgcon.org/2016/schedule/events/913.en.html
[2] https://www.postgresql.eu/events/schedule/pgconfeu2016/session/1360-parallel-query-in-postgresql/
[3] http://pgconf.in/schedule/query-parallelism-in-postgresql-expectations-and-opportunities/

More Related Content

PDF
Go faster with_native_compilation Part-2
PDF
Lessons PostgreSQL learned from commercial databases, and didn’t
PDF
PostgreSQL 9.6 Performance-Scalability Improvements
PDF
Big Data and PostgreSQL
PDF
PostgreSQL Enterprise Class Features and Capabilities
PDF
Oracle to Postgres Migration - part 2
PDF
Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)
PDF
Case Studies on PostgreSQL
Go faster with_native_compilation Part-2
Lessons PostgreSQL learned from commercial databases, and didn’t
PostgreSQL 9.6 Performance-Scalability Improvements
Big Data and PostgreSQL
PostgreSQL Enterprise Class Features and Capabilities
Oracle to Postgres Migration - part 2
Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)
Case Studies on PostgreSQL

What's hot (20)

PDF
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
PDF
TeraCache: Efficient Caching Over Fast Storage Devices
PPTX
Building Spark as Service in Cloud
PDF
Porting Oracle Applications to PostgreSQL
PPTX
Simple Works Best
 
PPTX
How to ensure Presto scalability ‹in multi use case
PDF
Technical Introduction to PostgreSQL and PPAS
PDF
PostgreSQL Replication High Availability Methods
PDF
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
PDF
Cascading - A Java Developer’s Companion to the Hadoop World
PDF
Online Upgrade Using Logical Replication.
 
PDF
20140120 presto meetup_en
PDF
Connecting Hadoop and Oracle
PPTX
Tez Shuffle Handler: Shuffling at Scale with Apache Hadoop
PDF
Get to know PostgreSQL!
PDF
PostgreSQL Rocks Indonesia
PPTX
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
PDF
Data Analysis with TensorFlow in PostgreSQL
 
PDF
Elephants in the Cloud
PDF
Presto At Treasure Data
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
TeraCache: Efficient Caching Over Fast Storage Devices
Building Spark as Service in Cloud
Porting Oracle Applications to PostgreSQL
Simple Works Best
 
How to ensure Presto scalability ‹in multi use case
Technical Introduction to PostgreSQL and PPAS
PostgreSQL Replication High Availability Methods
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
Cascading - A Java Developer’s Companion to the Hadoop World
Online Upgrade Using Logical Replication.
 
20140120 presto meetup_en
Connecting Hadoop and Oracle
Tez Shuffle Handler: Shuffling at Scale with Apache Hadoop
Get to know PostgreSQL!
PostgreSQL Rocks Indonesia
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
Data Analysis with TensorFlow in PostgreSQL
 
Elephants in the Cloud
Presto At Treasure Data
Ad

Viewers also liked (20)

PDF
PostgreSQL on Amazon RDS
PDF
PostgreSQL WAL for DBAs
PDF
Lightening Talk - PostgreSQL Worst Practices
PDF
How to teach an elephant to rock'n'roll
PDF
PostgreSQL: Past present Future
PDF
Why we love pgpool-II and why we hate it!
PDF
Introduction to Vacuum Freezing and XID
PDF
Security Best Practices for your Postgres Deployment
PDF
Swapping Pacemaker Corosync with repmgr
PDF
Use Case: PostGIS and Agribotics
PDF
Secure PostgreSQL deployment
PDF
(Ab)using 4d Indexing
PDF
Migration From Oracle to PostgreSQL
PDF
Past, Present, and Future Analysis of the Architectural & Engineering Design ...
PDF
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
PDF
pg_hba.conf 읎알Ʞ
PDF
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PDF
24/7 Monitoring and Alerting of PostgreSQL
PDF
Achieving Pci Compliace
PDF
PgDay Asia 2016 - Security Best Practices for your Postgres Deployment
PostgreSQL on Amazon RDS
PostgreSQL WAL for DBAs
Lightening Talk - PostgreSQL Worst Practices
How to teach an elephant to rock'n'roll
PostgreSQL: Past present Future
Why we love pgpool-II and why we hate it!
Introduction to Vacuum Freezing and XID
Security Best Practices for your Postgres Deployment
Swapping Pacemaker Corosync with repmgr
Use Case: PostGIS and Agribotics
Secure PostgreSQL deployment
(Ab)using 4d Indexing
Migration From Oracle to PostgreSQL
Past, Present, and Future Analysis of the Architectural & Engineering Design ...
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
pg_hba.conf 읎알Ʞ
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
24/7 Monitoring and Alerting of PostgreSQL
Achieving Pci Compliace
PgDay Asia 2016 - Security Best Practices for your Postgres Deployment
Ad

Similar to Query Parallelism in PostgreSQL: What's coming next? (20)

PDF
Implementing Parallelism in PostgreSQL - PGCon 2014
 
PDF
What’s new in 9.6, by PostgreSQL contributor
PPTX
Manjeet Singh.pptx
PPTX
database slide on modern techniques for optimizing database queries.pptx
PPTX
chapter21-parallel processing. computing
PDF
2016 may-countdown-to-postgres-v96-parallel-query
PDF
Parallel Query on Exadata
PDF
The Central View of your Data with Postgres
 
PDF
Understanding Presto - Presto meetup @ Tokyo #1
PDF
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
PPTX
The End of a Myth: Ultra-Scalable Transactional Management
PDF
Px execution in rac
PPTX
PostgreSQL 10: What to Look For
PDF
POLARDB for MySQL - Parallel Query
PPTX
Analysing and troubleshooting Parallel Execution IT Tage 2015
PDF
Properly Use Parallel DML for ETL
PDF
HPCC Presentation
PDF
What's New in PostgreSQL 9.6
 
PPTX
New enhancements for security and usability in EDB 13
 
PPT
Ch22 parallel d_bs_cs561
Implementing Parallelism in PostgreSQL - PGCon 2014
 
What’s new in 9.6, by PostgreSQL contributor
Manjeet Singh.pptx
database slide on modern techniques for optimizing database queries.pptx
chapter21-parallel processing. computing
2016 may-countdown-to-postgres-v96-parallel-query
Parallel Query on Exadata
The Central View of your Data with Postgres
 
Understanding Presto - Presto meetup @ Tokyo #1
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
The End of a Myth: Ultra-Scalable Transactional Management
Px execution in rac
PostgreSQL 10: What to Look For
POLARDB for MySQL - Parallel Query
Analysing and troubleshooting Parallel Execution IT Tage 2015
Properly Use Parallel DML for ETL
HPCC Presentation
What's New in PostgreSQL 9.6
 
New enhancements for security and usability in EDB 13
 
Ch22 parallel d_bs_cs561

More from PGConf APAC (18)

PDF
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PDF
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PDF
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PDF
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PDF
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
PDF
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PDF
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PDF
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PDF
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PDF
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PDF
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PDF
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PDF
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PDF
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
PDF
PGConf APAC 2018 - Tale from Trenches
PDF
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PDF
Amazon (AWS) Aurora
PDF
Go Faster With Native Compilation
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
PGConf APAC 2018 - Tale from Trenches
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
Amazon (AWS) Aurora
Go Faster With Native Compilation

Recently uploaded (20)

PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Softaken Excel to vCard Converter Software.pdf
PPT
Introduction Database Management System for Course Database
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
ai tools demonstartion for schools and inter college
PDF
System and Network Administration Chapter 2
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
Wondershare Filmora 15 Crack With Activation Key [2025
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PTS Company Brochure 2025 (1).pdf.......
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Upgrade and Innovation Strategies for SAP ERP Customers
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Migrate SBCGlobal Email to Yahoo Easily
CHAPTER 2 - PM Management and IT Context
Odoo POS Development Services by CandidRoot Solutions
Softaken Excel to vCard Converter Software.pdf
Introduction Database Management System for Course Database
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
2025 Textile ERP Trends: SAP, Odoo & Oracle
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
ai tools demonstartion for schools and inter college
System and Network Administration Chapter 2
Which alternative to Crystal Reports is best for small or large businesses.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development

Query Parallelism in PostgreSQL: What's coming next?

  • 1. © 2013 EDB All rights reserved. 1 Query Parallelism In PostgreSQL What’s coming next? Dilip Kumar (Principle Software Engineer)
  • 2. © 2016 EDB All rights reserved. 2 ❏ Infrastructure for parallelism ❏ Intra-query parallelism in v9.6 ❏ Parallel aware executor nodes ❏ Performance on TPC-H ❏ Parallelism enhancements in v10 ❏ More executor-nodes ❏ Performance on TPC-H ❏ Take away
  • 3. © 2016 EDB All rights reserved. 3 ❏ Groundwork for parallelism ❏ Dynamic background workers ❏ Dynamic shared memory ❏ Shared messaging capabilities ❏ Group locking ❏ Parallel context ❏ Intra-query parallel support ❏ Parallel executor ❏ Parallel-aware nodes ❏ seq scan, ❏ joins, and ❏ aggregates
  • 4. © 2016 EDB All rights reserved. 4 Gather nodeGather.c Parallel-Aware Executor Nodes nodeSeqScan.c nodeForeignScan.c nodeCustom.c Parallel Executor Support execParallel.c Tuple Queue Reader and DestReceiver tqueue.c Dynamic Background Workers bgworker.c Dynamic Shared Memory dsm.c, dsm_impl.c Shared Memory Message Queue shm_mq.c Parallel Context parallel.c Shared Memory Table of Contents shm_toc.c Error/Notice Forwarding pqmq.c State Synchronization dfmgr.c, guc.c, combocid.c, snapmgr.c, xact.c Group Locking lock.c
  • 5. © 2016 EDB All rights reserved. 5 ❏ Dynamic background worker (shm_mq) ❏ Postmaster can launch the background worker processes at run time ❏ Dynamic shared memory ❏ Allocate a chunk of memory that can be shared among co-operating processes ❏ Shared memory table of contents ❏ A simple scheme for carving DSM into numbered chunks ❏ Shared messaging capabilities ❏ Shared memory message queue ❏ For error/notice forwarding ❏ Tuple queue reader and DestReceiver
  • 6. © 2016 EDB All rights reserved. 6 ❏ Parallel context ❏ Core toolkit for parallel operations ❏ Launch a number of workers, establish “useful” state, run C code you specify and ensure timely shutdown. ❏ State synchronization ❏ To ensure same GUC values, libraries, and transactions with same snapshot across workers ❏ Group locking ❏ To solve the issue of undetected deadlock ❏ Leader and its workers are treated as one entity for locking purposes
  • 7. © 2016 EDB All rights reserved. 7 ❏ Parallel executor support ❏ Execute a plan by a set of worker ❏ Pass instrumentation information to each worker ❏ Parallel aware executor nodes ❏ Different behaviour when run in parallel or otherwise ❏ Gather ❏ Collect results across all workers and merge them into a single result stream
  • 8. © 2016 EDB All rights reserved. 8 ❏ Parallel access methods ❏ Seq scan is the only parallel access method ❏ No support for parallel index, index-only or bitmap-heap scan ❏ Parallel joins ❏ NestedLoop and Hash joins are supported for parallel execution ❏ For hash-join, each worker prepares its own copy of hash-table ❏ Merge join cannot execute in parallel ❏ Parallel aggregates ❏ Each worker performs partial aggregate and finalize aggregate is done by leader
  • 9. © 2016 EDB All rights reserved. 9 ❏ Experimental setup ❏ IBM power7 box (popularly known as Hydra in community) ❏ Parameter settings ❏ Max_parallel_degree = 4 ❏ Work_mem = 64 MB ❏ Shared_buffers = 8 GB ❏ Database setup ❏ Scale factor = 10
  • 10. © 2016 EDB All rights reserved. 10
  • 11. © 2016 EDB All rights reserved. 11 ❏ Need parallel-index scan ❏ Q6, Q14 ❏ Need parallel bitmap-heap scan ❏ Q4, Q15 ❏ Need parallel merge-join ❏ Q2, Q3, Q9, Q20 ❏ Need parallel hash table build ❏ Q3, Q5, Q7, Q8, Q21 ❏ Need parallel subquery handling ❏ Q2, Q22 

  • 12. © 2016 EDB All rights reserved. 12 ❏ More parallel executor nodes ❏ Access methods ❏ Parallel index, index-only, bitmap-heap ❏ Join methods ❏ Merge join ❏ Hash join with shared hash ❏ Other ❏ Gather-merge ❏ Relaxation for nodes using uncorrelated sub-plan, init-plan ❏ Improvements in parallel-append ❏ Parallel DDL/maintenance commands ❏ Index-creation ❏ Vacuum
  • 13. © 2016 EDB All rights reserved. 13 ❏ Parallel index scan ❏ Firstly, a worker will process the intermediate pages of B-tree and determine the starting leaf page where scan is to be started ❏ Next, all the workers start scanning the leaf pages block by block ❏ Finally, all the filtered tuples are gathered by the leader process ❏ This operator improves the performance significantly when the database is in-memory ❏ Similar mechanism is built for index-only scans
  • 14. © 2016 EDB All rights reserved. 14 ❏ Parallel bitmap heap scan ❏ A bitmap scan fetches all the pointers from index in one go, sort them using in-memory “bitmap”, finally, visits the tuple in physical order ❏ Bitmap will be created by a single worker ❏ Next, all the workers will jointly scan the heap, page by page ❏ For further improvement, we can also build bitmap by multiple workers
  • 15. © 2016 EDB All rights reserved. 15 ❏ Parallel bitmap heap scan Gather Workers Planned: 2 -> Parallel Bitmap Heap Scan on foo Recheck Cond: ((a < 100000) OR (b < 10000)) -> BitmapOr -> Bitmap Index Scan on idx1 Index Cond: (a < 100000) -> Bitmap Index Scan on idx2 Index Cond: (b < 10000)
  • 16. © 2016 EDB All rights reserved. 16 ❏ Parallel Merge Join ❏ If outer node is using parallelism then we consider parallel merge-join ❏ Outer node will be scanned in parallel by multiple workers ❏ Inner node will be processed completely by individual workers ❏ There is still scope of improvements in this strategy ❏ Parallelise inner sort or materialize nodes
  • 17. © 2016 EDB All rights reserved. 17 ❏ Parallel shared hash ❏ Previously, each worker builds its own copy of hash table ❏ This is particularly favourable to cases when hash table is small ❏ Improved mechanism is to employ the workers for building hash-table in parallel ❏ Once, hash-table is ready, parallel probing can be done ❏ This facilitates the usage of parallel operators on either sides of joins
  • 18. © 2016 EDB All rights reserved. 18 Parallel shared-hash Gather Workers Planned: 2 Workers Launched: 2 -> Hash Join Hash Cond (foo.b = bar.b) -> Parallel Seq Scan on foo -> Parallel Shared Hash -> Parallel Seq Scan on bar
  • 19. © 2016 EDB All rights reserved. 19 ❏ Gather-merge ❏ Previously, there was only one option to collect the result from parallel operators i.e gather, it does not maintain interesting order ❏ Therefore, extra sort node is required on top for ordered output ❏ Now, if workers are providing sorted result specifically, output from parallel index, parallel merge join, etc. then gather-merge will maintain the sort-order in the final result
  • 20. © 2016 EDB All rights reserved. 20 ❏ Experimental setup ❏ RAM = 512 GB ❏ Number of cores = 32 ❏ Parameter settings ❏ Work_mem = 64 MB ❏ Shared_buffers = 8 GB ❏ Effective_cache_size = 10 GB ❏ Random_page_cost = seq_page_cost = 0.1 ❏ Max_parallel_workers_per_gather = 4 ❏ Database setup ❏ Scale factors = 20, 300 ❏ Additional indexes: l_shipmode, l_shipdate, o_orderdate, o_comment
  • 21. © 2016 EDB All rights reserved. 21 Results on scale factor 20
  • 22. © 2016 EDB All rights reserved. 22 Results on scale factor 20
  • 23. © 2016 EDB All rights reserved. 23 Results on scale factor 300
  • 24. © 2016 EDB All rights reserved. 24 ❏ Tuning parameters ❏ Max_parallel_workers_per_gather ❏ Recommended value 1 to 4 ❏ Reduce following costs ❏ Parallel_tuple_cost: planner's estimate of the cost of transferring one tuple from a parallel worker process to another process ❏ Parallel_setup_cost: planner's estimate for launching parallel workers and initializing dynamic shared memory ❏ Min_parallel_table_scan_size: the minimum size of relations to be considered for parallel sequence scan ❏ Min_parallel_index_scan_size: the minimum size of index to be considered for parallel scan ❏ Random_page_cost: estimated cost of accessing a random page in disk ❏ Increase following parameters ❏ Work_mem ❏ Effective_cache_size ❏ Shared_buffers
  • 25. © 2016 EDB All rights reserved. 25 ❏ Adding intra-query parallelism improves per query response time ❏ Previously, overall throughput was the only focus ❏ This makes it more suitable for OLAP environments ❏ Till version 9.6, parallel support for sequence scan, hash join, nestloop join, and aggregates is available ❏ Out of 22 queries of TPC-H, performance improved for 15 queries ❏ In which 3 queries are at least 4 times faster and 11 queries are 2 times faster ❏ More parallel executor nodes are planned for upcoming versions ❏ More parallel access methods - index, index-only are already committed ❏ Improved parallel join mechanisms ❏ Gather with interesting order ❏ Removed restrictions for nodes using SubPlans(already committed) or InitPlans ❏ Around 10 of 22 TPC-H queries show significant improvement in performance ❏ In which around 4 queries show more than 2x improvement
  • 26. © 2016 EDB All rights reserved. 26
  • 27. 27 Output: Thank You Gather Workers Planned: 2 Workers Launched: 2 -> Parallel Index Scan on Common_phrases Index Cond: ( value = ‘Thank You’ ) Filter: Language = ‘English’ Slide credits: [1] https://www.pgcon.org/2016/schedule/events/913.en.html [2] https://www.postgresql.eu/events/schedule/pgconfeu2016/session/1360-parallel-query-in-postgresql/ [3] http://pgconf.in/schedule/query-parallelism-in-postgresql-expectations-and-opportunities/