plan
Group aggregate
Processes consecutive groups of ordered input. Input ordering can be supplied by an index or a sort; use ORDER BY for guaranteed result order. PostgreSQL 17. Plan shape depends on statistics, configuration and data; example settings are laboratory aids, not production advice.
Formal Syntax & Structure
sql syntaxsql
EXPLAIN SELECT key, SUM(value) FROM table GROUP BY keyWorking Example
Example Snippetsql
CREATE TABLE items(id integer PRIMARY KEY, category integer, price integer); INSERT INTO items VALUES (1,1,10),(2,1,20),(3,2,30); CREATE TABLE categories(id integer PRIMARY KEY, label text); INSERT INTO categories VALUES (1,'A'),(2,'B');SET enable_hashagg=off;EXPLAIN (FORMAT JSON) SELECT category,SUM(price) FROM items GROUP BY category ORDER BY category;SELECT category,SUM(price) FROM items GROUP BY category ORDER BY category;