3

Postgres now has parallel queries. Are parallel queries used when the table is partitioned, the query is on the master table, and more than one partitions (child tables) are involved.

For example, I partition by the hour of the day. Then I want to count a type of event over more than one hour. The aggregation can be done on each partition, with the results added up at the end.

The alternative is to use a union between the partitions (child tables). In this case Postgres does parallel execution.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
rwfbc
  • 900
  • 1
  • 10
  • 22
  • PostgreSQL 9.5 and older: no. PostgreSQL 9.6 and newer: check the query plan. Where's the `explain analyze`? Edit your post to add it please. – Craig Ringer Nov 25 '16 at 04:20

1 Answers1

0

No, partitions are not queried in parallel. At this time (9.6) only table scans use parallel execution. The table is divided among the available workers, and each worker scans part of the table. At the end the primary worker combines the partial results.

A side effect of this is that the optimizer is more likely to chose a full table scan when parallel query execution is enabled.

As far as I can tell, there is no plan to parallelize execution based on partitions (or union all). A suggestion to add this has been added here.

Edit: My original answer was wrong. This answer has been completely revised.

rwfbc
  • 900
  • 1
  • 10
  • 22
  • Hello there, I have and issue and presented [here](http://stackoverflow.com/questions/41876256/can-i-split-a-query-in-multiple-queries-or-create-parallelism-to-speed-a-query?noredirect=1#41876256) I wonder if this paralelism can help me in a table scan when a field is a function (also table scan) is included. Currently Im using 9.5 so Im considering migrating to 9.6 just for this. – Juan Carlos Oropeza Jan 27 '17 at 15:06