↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / Plan Nodes

Aggregate

Computes aggregate results using the selected grouping strategy and aggregation stage.

Reading PG 18·Select a recorded version

Core node tag
T_Agg
Structured EXPLAIN Node Type
Aggregate
Inputs
One child plan
Output
Aggregate result tuples
Executor initializer
ExecInitAgg
Memory mechanism
aggregate-spill
EXPLAIN strategies
Plain, Sorted, Hashed, Mixed
Aggregation stages
Partial, Finalize, Simple
evidence kind
source and documentation
explain names
Aggregate, GroupAggregate, HashAggregate, MixedAggregate
explain prefixes
Parallel, Async
node tag
T_Agg
parallel callbacks
ExecAggEstimate, ExecAggInitializeDSM, ExecAggInitializeWorker, ExecAggRetrieveInstrumentation
partial modes
Partial, Finalize, Simple
runtime verified
false
strategies
Plain, Sorted, Hashed, Mixed

Definition PG 18

Computes aggregate results using the selected grouping strategy and aggregation stage.

EXPLAIN labels in this source build

Text-format labelStructured node identity
AggregateAggregate
GroupAggregateAggregate
HashAggregateAggregate
MixedAggregateAggregate

Compare versions

Complete source facts

memory

{"description":"This implementation contains a disk-spill path for hashed aggregation. Aggregate input sorting and transition-state allocations have their own behavior; one spill policy does not describe every aggregation strategy.","evidence":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeAgg.c","path":"src/backend/executor/nodeAgg.c","sha256":"8719569a73f054e9026c0a00c814f60b6c7879753c58e4e6dcc38fee333c45c5","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}],"mechanism":"aggregate-spill","source_notes":["When performing hash aggregation, if the hash table memory exceeds the limit (see hash_agg_check_limits()), we enter \"spill mode\". In spill mode, we advance the transition states only for groups already in the hash table. For tuples that would need to create a new hash table entries (and initialize new transition states), we instead spill them to disk to be processed later. The tuples are spilled in a partitioned manner, so that subsequent batches are smaller and less likely to exceed hash_mem (if a batch does exceed hash_mem, it must be spilled recursively).","Spilled data is written to logical tapes. These provide better control over memory usage, disk space, and the number of files than if we were to use a BufFile for each spill. We don't know the number of tapes needed at the start of the algorithm (because it can recurse), so a tape set is allocated at the beginning, and individual tapes are created as needed. As a particular tape is read, logtape.c recycles its disk space. When a tape is read to completion, it is destroyed entirely.","Control how many partitions are created when spilling HashAgg to disk.","We also specify a min and max number of partitions per spill. Too few might mean a lot of wasted I/O from repeated spilling of the same tuples. Too many will result in lots of memory wasted buffering the spill files (which could instead be spent on a larger hash table)."]}

source inventory

{"executor":"src/backend/executor/execProcnode.c","explain":"src/backend/commands/explain.c","implementation":"src/backend/executor/nodeAgg.c"}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · 555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f

Text language: en · 555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f