> [!NOTE] Distributed Gather > <table> > <tr> > <td width="25%"><img src="assets/ex_gather.png"></td> > <td>The entry point for parallel query execution. This node coordinates multiple 'Parallel Workers', collecting their individual results and merging them back into a single stream for the leader process to handle.</td> > </tr> > </table> > > ```sql > -- Forcing a parallel aggregation and gather > SET max_parallel_workers_per_gather = 2; > SET min_parallel_table_scan_size = 0; > SET parallel_setup_cost = 0; > > EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE) > SELECT count(*) FROM animals; > ``` > > ![Gather Plan Tree](assets/plan_tree_op_gather.svg) > > ```text > Finalize Aggregate (cost=126.30..126.31 rows=1 width=8) (actual time=2.388..3.092 rows=1 loops=1) > Output: count(*) > Buffers: shared hit=74 > -> Gather (cost=126.08..126.29 rows=2 width=8) (actual time=0.706..3.088 rows=3 loops=1) > Output: (PARTIAL count(*)) > Workers Planned: 2 > Workers Launched: 2 > Buffers: shared hit=74 > -> Partial Aggregate (cost=126.08..126.09 rows=1 width=8) (actual time=0.168..0.168 rows=1 loops=3) > Output: PARTIAL count(*) > Buffers: shared hit=74 > Worker 0: actual time=0.001..0.001 rows=1 loops=1 > Worker 1: actual time=0.001..0.001 rows=1 loops=1 > -> Parallel Seq Scan on public.animals (cost=0.00..115.67 rows=4167 width=0) (actual time=0.002..0.097 rows=3333 loops=3) > Output: id, name, species_id, created_at > Buffers: shared hit=74 > Worker 0: actual time=0.000..0.000 rows=0 loops=1 > Worker 1: actual time=0.000..0.000 rows=0 loops=1 > Planning: > Buffers: shared hit=77 > Planning Time: 0.168 ms > Execution Time: 3.126 ms > ``` > > ![Distributed Gather measured plan performance signature](assets/trace_op_gather.svg) > > <table> > <tr> > <td rowspan="2" width="25%"><img src="assets/ex_gather_motion.svg"></td> > <td><b>Performance</b></td><td>Can introduce a serialization bottleneck if a large volume of data must be shipped through the coordinator.</td> > </tr> > <tr><td><b>Cost</b></td><td><code>setup_cost + communication_cost * data_size</code></td></tr> > </table>