https://wiki.postgresql.org/api.php?action=feedcontributions&user=Floris&feedformat=atomPostgreSQL wiki - User contributions [en]2024-03-28T11:16:55ZUser contributionsMediaWiki 1.35.13https://wiki.postgresql.org/index.php?title=Parallel_Query_Execution&diff=21938Parallel Query Execution2014-03-11T12:59:11Z<p>Floris: /* related work */</p>
<hr />
<div><center>This is currently under development. See the [[Parallel Query Execution#ToDo|ToDo list]].</center><br />
----<br />
<br />
==Purpose==<br />
Postgres currently supports full parallelism in client-side code. Applications can open multiple database connections and manage them asyncronously, or via threads.<br />
<br />
On the server-side, there is already some parallelism:<br />
<br />
* [http://www.postgresql.org/docs/9.2/static/runtime-config-resource.html#RUNTIME-CONFIG-RESOURCE-ASYNC-BEHAVIOR effective_io_concurrency] allows table page prefetch requests to the kernel, for bitmap joins<br />
<br />
* Helper processes like [http://www.postgresql.org/docs/9.2/static/runtime-config-resource.html#RUNTIME-CONFIG-RESOURCE-BACKGROUND-WRITER background writer] and [http://www.postgresql.org/docs/9.2/static/runtime-config-wal.html#RUNTIME-CONFIG-WAL-SETTINGS wal writer] offload I/O requirements from the main query execution process<br />
<br />
* Server-side languages can potentially do parallel operations<br />
<br />
==Benefits==<br />
There are three possible benefits of parallelism:<br />
<br />
* Using multiple CPUs<br />
<br />
* Using multiple I/O channels (for sequential and random I/O)<br />
<br />
* Using multiple CPUs and I/O channels<br />
<br />
==Approaches==<br />
There are several methods to add parallelism:<br />
<br />
* Use fork (or a thread on Windows -- I think it would be a process, too not a thread; threads share address spaces, processes don't) and only call libc and parallel-specific functions to do parallel computation or I/O (isn't this only read operations?). This avoids the problem of trying to make the existing backend code thread-safe. Do we need to wait until we can share a transaction among back-end processes?<br />
<br />
* Same as above, but modify some existing backend modules to be fork/thread-safe, with or without shared memory access; this might allow entire executor node trees to be run in parallel<br />
<br />
* Create full backends that can execute parts of a query in parallel and return results<br />
<br />
* Create a pool of backends waiting for parallel requests<br />
<br />
* An initial approach might start by modifying individual plan nodes to run in parallel in the executor. Eventually we'd need to educate the planner and optimizer about how to model parallelizing queries.<br />
<br />
==Challenges==<br />
'''Finding Appropriate Tasks''': For parallelism to be added to a single-threaded task, the task must be able to be broken into sufficiently-large parts and executed independently. (If the sub-parts are too small, the overhead of doing parallelism overwhelms the benefits of parallelism.) Unfortunately, unlike a GUI application, the Postgres backend executes a query by performing many small tasks that must be executed in sequence, e.g. parser, planner, executor. -- could someone document where I get a quantification of how much time is spent in each of these three phases? Can we offer the users a participation in metrics collection?<br />
<br />
This means that databases allow parallelism only in limited situations, mostly for large queries that can become CPU or I/O bound. For example, it is unlikely that selecting a row based on a primary key would benefit from parallelism. In contrast, large queries can often benefit from parallelism.<br />
<br />
'''Returning Data''': Another challenge is returning data from the helper process/thread. For something like SUM(), it is easy, but passing a large volume of data back can be complex.<br />
<br />
'''Avoiding Overhead''': Parallelism has its own costs so there will need to be a way to control when parallel execution is used.<br />
<br />
'''Limiting Excessive Parallelism''': There also needs to be some mechnism that detects parallelism by other sessions so CPU and I/O resources are not exceeded.<br />
<br />
==Specific Opportunities==<br />
Parallel opportunities include:<br />
<br />
* [http://wiki.postgresql.org/wiki/Parallel_Sort Sorting]<br />
<br />
* Tablespaces<br />
<br />
* Partitions<br />
<br />
* Multi-table access<br />
<br />
* Joins (e.g. nested loop), CTEs<br />
<br />
* Sequential scans on 1GB segment files<br />
<br />
* Per-Page visibility checks and tuple filtering<br />
<br />
* [http://www.postgresql.org/message-id/CAGTBQpbRYp9GNe2JjbXXCAO1-OsYXdh2fUyZVka+GXY22dj+iQ@mail.gmail.com I/O and row processing]<br />
<br />
* Aggregates<br />
<br />
* Data import/export<br />
<br />
* COPY (to reduce the CPU overhead of parsing)<br />
<br />
* Index builds<br />
<br />
* Constraint checking<br />
<br />
* Expensive functions, e.g. PostGIS<br />
<br />
[[Category:Development]]<br />
<br />
== related work ==<br />
PargreSQL [http://ceur-ws.org/Vol-735/paper10.pdf] and [http://www.docstoc.com/docs/152845963/ZymblerP_slides_Heidelberg-12]<br />
The paper describes the architecture and the design of PargreSQL parallel database management system (DBMS) for distributed memory multiprocessors. PargreSQL is based upon PostgreSQL open-source DBMS and exploits partitioned parallelism</div>Florishttps://wiki.postgresql.org/index.php?title=Parallel_Query_Execution&diff=21937Parallel Query Execution2014-03-11T12:58:06Z<p>Floris: /* Specific Opportunities */</p>
<hr />
<div><center>This is currently under development. See the [[Parallel Query Execution#ToDo|ToDo list]].</center><br />
----<br />
<br />
==Purpose==<br />
Postgres currently supports full parallelism in client-side code. Applications can open multiple database connections and manage them asyncronously, or via threads.<br />
<br />
On the server-side, there is already some parallelism:<br />
<br />
* [http://www.postgresql.org/docs/9.2/static/runtime-config-resource.html#RUNTIME-CONFIG-RESOURCE-ASYNC-BEHAVIOR effective_io_concurrency] allows table page prefetch requests to the kernel, for bitmap joins<br />
<br />
* Helper processes like [http://www.postgresql.org/docs/9.2/static/runtime-config-resource.html#RUNTIME-CONFIG-RESOURCE-BACKGROUND-WRITER background writer] and [http://www.postgresql.org/docs/9.2/static/runtime-config-wal.html#RUNTIME-CONFIG-WAL-SETTINGS wal writer] offload I/O requirements from the main query execution process<br />
<br />
* Server-side languages can potentially do parallel operations<br />
<br />
==Benefits==<br />
There are three possible benefits of parallelism:<br />
<br />
* Using multiple CPUs<br />
<br />
* Using multiple I/O channels (for sequential and random I/O)<br />
<br />
* Using multiple CPUs and I/O channels<br />
<br />
==Approaches==<br />
There are several methods to add parallelism:<br />
<br />
* Use fork (or a thread on Windows -- I think it would be a process, too not a thread; threads share address spaces, processes don't) and only call libc and parallel-specific functions to do parallel computation or I/O (isn't this only read operations?). This avoids the problem of trying to make the existing backend code thread-safe. Do we need to wait until we can share a transaction among back-end processes?<br />
<br />
* Same as above, but modify some existing backend modules to be fork/thread-safe, with or without shared memory access; this might allow entire executor node trees to be run in parallel<br />
<br />
* Create full backends that can execute parts of a query in parallel and return results<br />
<br />
* Create a pool of backends waiting for parallel requests<br />
<br />
* An initial approach might start by modifying individual plan nodes to run in parallel in the executor. Eventually we'd need to educate the planner and optimizer about how to model parallelizing queries.<br />
<br />
==Challenges==<br />
'''Finding Appropriate Tasks''': For parallelism to be added to a single-threaded task, the task must be able to be broken into sufficiently-large parts and executed independently. (If the sub-parts are too small, the overhead of doing parallelism overwhelms the benefits of parallelism.) Unfortunately, unlike a GUI application, the Postgres backend executes a query by performing many small tasks that must be executed in sequence, e.g. parser, planner, executor. -- could someone document where I get a quantification of how much time is spent in each of these three phases? Can we offer the users a participation in metrics collection?<br />
<br />
This means that databases allow parallelism only in limited situations, mostly for large queries that can become CPU or I/O bound. For example, it is unlikely that selecting a row based on a primary key would benefit from parallelism. In contrast, large queries can often benefit from parallelism.<br />
<br />
'''Returning Data''': Another challenge is returning data from the helper process/thread. For something like SUM(), it is easy, but passing a large volume of data back can be complex.<br />
<br />
'''Avoiding Overhead''': Parallelism has its own costs so there will need to be a way to control when parallel execution is used.<br />
<br />
'''Limiting Excessive Parallelism''': There also needs to be some mechnism that detects parallelism by other sessions so CPU and I/O resources are not exceeded.<br />
<br />
==Specific Opportunities==<br />
Parallel opportunities include:<br />
<br />
* [http://wiki.postgresql.org/wiki/Parallel_Sort Sorting]<br />
<br />
* Tablespaces<br />
<br />
* Partitions<br />
<br />
* Multi-table access<br />
<br />
* Joins (e.g. nested loop), CTEs<br />
<br />
* Sequential scans on 1GB segment files<br />
<br />
* Per-Page visibility checks and tuple filtering<br />
<br />
* [http://www.postgresql.org/message-id/CAGTBQpbRYp9GNe2JjbXXCAO1-OsYXdh2fUyZVka+GXY22dj+iQ@mail.gmail.com I/O and row processing]<br />
<br />
* Aggregates<br />
<br />
* Data import/export<br />
<br />
* COPY (to reduce the CPU overhead of parsing)<br />
<br />
* Index builds<br />
<br />
* Constraint checking<br />
<br />
* Expensive functions, e.g. PostGIS<br />
<br />
[[Category:Development]]<br />
<br />
== related work ==<br />
PargreSQL [http://ceur-ws.org/Vol-735/paper10.pdf] and [http://www.docstoc.com/docs/152845963/ZymblerP_slides_Heidelberg-12]</div>Floris