{"Entry":{"collection":"plan","key":"gather-merge","name":"Gather Merge","aliases":["Gather Merge","GatherMerge","T_GatherMerge"],"metadata":{"aliases":["Gather Merge","GatherMerge","T_GatherMerge"],"category":"Parallelism","content_hash":"60a783e74d1850b9432b5b97c5799704bd4e9d917faa54bb6fb742f37bf78f8d","imported_at":"2026-09-30T00:40:44.19904+08:00","name":"Gather Merge","name_zh":"GatherMerge","slug":"gather-merge","summary":"Merges ordered tuple streams from parallel workers and any participating leader execution."}},"Definition":{"Collection":"plan","Key":"gather-merge","SourceDatabase":"center","Version":"18","SourceTable":"plan_node","SourceKey":"gather-merge","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","Facts":{"comparison_data":{"initializer":"ExecInitGatherMerge","memory_mechanism":"unclassified","node_tag":"T_GatherMerge","parallel_callbacks":[],"partial_modes":[],"strategies":[],"text_names":["Gather Merge"]},"comparison_hash":"7a1c97656626af0791de9743def719924b5c292f47f0634adc2b0e6e4fd2ad21","description":["Merges ordered tuple streams from parallel workers and any participating leader execution."],"evidence_kind":"source and documentation","explain_names":["Gather Merge"],"explain_prefixes":["Parallel","Async"],"facts":[{"label":"Core node tag","value":"T_GatherMerge"},{"label":"Structured EXPLAIN Node Type","value":"Gather Merge"},{"label":"Inputs","value":"One ordered parallel child plan"},{"label":"Output","value":"Merged ordered tuples"},{"label":"Executor initializer","value":"ExecInitGatherMerge"},{"label":"Memory mechanism","value":"unclassified"}],"memory":{"description":"This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider.","evidence":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeGatherMerge.c","path":"src/backend/executor/nodeGatherMerge.c","sha256":"5d37ccad1d10d72a567a134bc92f044c584d794c09c9f5820e3ce8e0744d0b1a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}],"mechanism":"unclassified","source_notes":[]},"node_tag":"T_GatherMerge","parallel_callbacks":[],"partial_modes":[],"related":[{"label":"EXPLAIN","url":"/wiki/sql/explain/?v=18"},{"label":"Using EXPLAIN","url":"/docs/18/using-explain.html"},{"label":"Parallel plans","url":"/docs/18/parallel-plans.html"},{"label":"enable_gathermerge","url":"/wiki/guc/enable_gathermerge/?v=18"},{"label":"max_parallel_workers_per_gather","url":"/wiki/guc/max_parallel_workers_per_gather/?v=18"}],"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"runtime_verified":false,"sections":[{"paragraphs":["Structured formats use the Node Type above. Text-format spellings can also include operation, strategy, join type, scan direction or aggregation-stage attributes.","Text names recorded by this source: Gather Merge.","Parallel-aware and parallel-safe are different plan properties. A node running inside a parallel worker is not necessarily a parallel-aware node."],"title":"EXPLAIN names and attributes"},{"paragraphs":["This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider."],"title":"Memory and temporary storage"},{"paragraphs":["The source callbacks below can coordinate execution or collect worker instrumentation. Their presence is not a blanket claim that this node supports a shared parallel scan or shared state.","Callbacks in this build: none extracted from this node implementation."],"title":"Parallel execution and instrumentation"},{"paragraphs":["PostgreSQL supports parallel aggregation by aggregating in two stages. First, each process participating in the parallel portion of the query performs an aggregation step, producing a partial result for each group of which that process is aware. This is reflected in the plan as a Partial Aggregate node. Second, the partial results are transferred to the leader via Gather or Gather Merge . Finally, the leader re-aggregates the results across all workers in order to produce the final result. This is reflected in the plan as a Finalize Aggregate node."],"title":"Same-version manual discussion"},{"paragraphs":["nodeGatherMerge.c Scan a plan in multiple workers, and do order-preserving merge.","When we read tuples from workers, it's a good idea to read several at once for efficiency when possible: this minimizes context-switching overhead. But reading too many at a time wastes memory without improving performance. We'll read up to MAX_TUPLE_STORE tuples (in addition to the first one).","Pending-tuple array for each worker. This holds additional tuples that we were able to fetch from the worker, but can't process yet. In addition, this struct holds the \"done\" flag indicating the worker is known to have no more tuples. (We do not use this struct for the leader; we don't keep any pending tuples for the leader, and the need_to_scan_locally flag serves as its \"done\" indicator.)","GatherMerge doesn't support checking a qual (it's always more efficient to do it in the child node).","Leader may access ExecProcNode result directly (if need_to_scan_locally), or from workers via tuple queue. So we can't trivially rely on the slot type being fixed for expressions evaluated within this node."],"title":"Executor implementation notes"},{"code":"case T_GatherMerge:\n\t\t\tpname = sname = \"Gather Merge\";\n\t\t\tbreak;","title":"EXPLAIN identity in core source"}],"source_inventory":{"executor":"src/backend/executor/execProcnode.c","explain":"src/backend/commands/explain.c","implementation":"src/backend/executor/nodeGatherMerge.c"},"sources":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/commands/explain.c:1441","line":1441,"path":"src/backend/commands/explain.c","sha256":"34c86d6070224a0e981efef51f79101d6d505e5874f1684ace183034bab14bb4","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/execProcnode.c:360","line":360,"path":"src/backend/executor/execProcnode.c","sha256":"f8a06a3f539077249b20664b2812433db6d7bd12b2c0ca633525db43d06f112a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeGatherMerge.c","path":"src/backend/executor/nodeGatherMerge.c","sha256":"5d37ccad1d10d72a567a134bc92f044c584d794c09c9f5820e3ce8e0744d0b1a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/include/nodes/plannodes.h","path":"src/include/nodes/plannodes.h","sha256":"52422b327a8049fbbb20d8b96008a0fc0a6fafa60f7eff3c695d5b2e83830120","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"label":"PostgreSQL 18.6 · parallel-plans","path":"parallel-plans.html","sha256":"62207d207bead82b01b59dc119c4f95856f08655cc11d4699a05a40867ed2070","url":"/docs/18/parallel-plans.html#PARALLEL-AGGREGATION"}],"strategies":[],"tables":[{"columns":[{"key":"label","label":"Text-format label"},{"key":"identity","label":"Structured node identity"}],"key":"explain-labels","rows":[{"identity":"Gather Merge","label":"Gather Merge"}],"title":"EXPLAIN labels in this source build"}]},"ManualEvidence":{"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"sources":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/commands/explain.c:1441","line":1441,"path":"src/backend/commands/explain.c","sha256":"34c86d6070224a0e981efef51f79101d6d505e5874f1684ace183034bab14bb4","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/execProcnode.c:360","line":360,"path":"src/backend/executor/execProcnode.c","sha256":"f8a06a3f539077249b20664b2812433db6d7bd12b2c0ca633525db43d06f112a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeGatherMerge.c","path":"src/backend/executor/nodeGatherMerge.c","sha256":"5d37ccad1d10d72a567a134bc92f044c584d794c09c9f5820e3ce8e0744d0b1a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/include/nodes/plannodes.h","path":"src/include/nodes/plannodes.h","sha256":"52422b327a8049fbbb20d8b96008a0fc0a6fafa60f7eff3c695d5b2e83830120","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"label":"PostgreSQL 18.6 · parallel-plans","path":"parallel-plans.html","sha256":"62207d207bead82b01b59dc119c4f95856f08655cc11d4699a05a40867ed2070","url":"/docs/18/parallel-plans.html#PARALLEL-AGGREGATION"}]},"MeasuredEvidence":{"runtime_verified":false}},"Text":{"Collection":"plan","Key":"gather-merge","SourceDatabase":"center","Version":"18","Locale":"en","Title":"Gather Merge","Summary":"Merges ordered tuple streams from parallel workers and any participating leader execution.","BodyHTML":"\u003cp\u003eMerges ordered tuple streams from parallel workers and any participating leader execution.\u003c/p\u003e","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","ContentHash":"5a00589cae67dc24467b71da3df8aee805659578ac0a508a29746affca1d6b6f","Payload":{"description":["Merges ordered tuple streams from parallel workers and any participating leader execution."],"related":[{"label":"EXPLAIN","url":"/wiki/sql/explain/?v=18"},{"label":"Using EXPLAIN","url":"/docs/18/using-explain.html"},{"label":"Parallel plans","url":"/docs/18/parallel-plans.html"},{"label":"enable_gathermerge","url":"/wiki/guc/enable_gathermerge/?v=18"},{"label":"max_parallel_workers_per_gather","url":"/wiki/guc/max_parallel_workers_per_gather/?v=18"}],"sections":[{"paragraphs":["Structured formats use the Node Type above. Text-format spellings can also include operation, strategy, join type, scan direction or aggregation-stage attributes.","Text names recorded by this source: Gather Merge.","Parallel-aware and parallel-safe are different plan properties. A node running inside a parallel worker is not necessarily a parallel-aware node."],"title":"EXPLAIN names and attributes"},{"paragraphs":["This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider."],"title":"Memory and temporary storage"},{"paragraphs":["The source callbacks below can coordinate execution or collect worker instrumentation. Their presence is not a blanket claim that this node supports a shared parallel scan or shared state.","Callbacks in this build: none extracted from this node implementation."],"title":"Parallel execution and instrumentation"},{"paragraphs":["PostgreSQL supports parallel aggregation by aggregating in two stages. First, each process participating in the parallel portion of the query performs an aggregation step, producing a partial result for each group of which that process is aware. This is reflected in the plan as a Partial Aggregate node. Second, the partial results are transferred to the leader via Gather or Gather Merge . Finally, the leader re-aggregates the results across all workers in order to produce the final result. This is reflected in the plan as a Finalize Aggregate node."],"title":"Same-version manual discussion"},{"paragraphs":["nodeGatherMerge.c Scan a plan in multiple workers, and do order-preserving merge.","When we read tuples from workers, it's a good idea to read several at once for efficiency when possible: this minimizes context-switching overhead. But reading too many at a time wastes memory without improving performance. We'll read up to MAX_TUPLE_STORE tuples (in addition to the first one).","Pending-tuple array for each worker. This holds additional tuples that we were able to fetch from the worker, but can't process yet. In addition, this struct holds the \"done\" flag indicating the worker is known to have no more tuples. (We do not use this struct for the leader; we don't keep any pending tuples for the leader, and the need_to_scan_locally flag serves as its \"done\" indicator.)","GatherMerge doesn't support checking a qual (it's always more efficient to do it in the child node).","Leader may access ExecProcNode result directly (if need_to_scan_locally), or from workers via tuple queue. So we can't trivially rely on the slot type being fixed for expressions evaluated within this node."],"title":"Executor implementation notes"},{"code":"case T_GatherMerge:\n\t\t\tpname = sname = \"Gather Merge\";\n\t\t\tbreak;","title":"EXPLAIN identity in core source"}],"tables":[{"columns":[{"key":"label","label":"Text-format label"},{"key":"identity","label":"Structured node identity"}],"key":"explain-labels","rows":[{"identity":"Gather Merge","label":"Gather Merge"}],"title":"EXPLAIN labels in this source build"}]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
