Fix bug #16784 in Disk-based Hash Aggregation.
authorJeff Davis <jdavis@postgresql.org>
Sun, 27 Dec 2020 01:25:30 +0000 (17:25 -0800)
committerJeff Davis <jdavis@postgresql.org>
Sun, 27 Dec 2020 01:27:50 +0000 (17:27 -0800)
commit7b8692eaf113a56933c77cf4c3993716ab37e763
tree15fbc51201588a8ee42e466e1e68d35d9354bb73
parent9f8a48bb2c0e5d6557d78d7cce34444b249fbead
Fix bug #16784 in Disk-based Hash Aggregation.

Before processing tuples, agg_refill_hash_table() was setting all
pergroup pointers to NULL to signal to advance_aggregates() that it
should not attempt to advance groups that had spilled.

The problem was that it also set the pergroups for sorted grouping
sets to NULL, which caused rescanning to fail.

Instead, change agg_refill_hash_table() to only set the pergroups for
hashed grouping sets to NULL; and when compiling the expression, pass
doSort=false.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/16784-7ff169bf2c3d1588%40postgresql.org
Backpatch-through: 13
src/backend/executor/nodeAgg.c
src/test/regress/expected/groupingsets.out
src/test/regress/sql/groupingsets.sql