The error, insufficient memory reserved for statement (execHHashagg.c:845) occurs when the HashAgg operator's memory requirement exceeds the allocated amount.
This can occur with large partitioned tables when a sequential scan consumes significant portions of the statement_mem before the aggregation even begins.
For example:
Possible workaround:
Run query with `set optimizer_enable_orderedagg=on; set optimizer=on;`