While playing around with large work_mem(or in that case a bit insane)
and maintenance_work_mem settings I noticed that EXPLAIN behaves quite
weird:
foo=# set work_mem to 200000;
SET
Time: 0.187 ms
foo=# explain select count(*) from testtable2 group by a;
QUERY PLAN
--------------------------------------------------------------------------------
---
GroupAggregate (cost=8845616.04..9731787.89 rows=37349188 width=4)
-> Sort (cost=8845616.04..8985385.04 rows=55907600 width=4)
Sort Key: a
-> Seq Scan on testtable2 (cost=0.00..1088488.00
rows=55907600 width=
4)
(4 rows)
Time: 0.364 ms
foo=# set work_mem to 2500000;
SET
Time: 0.195 ms
foo=# explain select count(*) from testtable2 group by a;
QUERY PLAN
-----------------------------------------------------------------------------
HashAggregate (cost=1368026.00..1834890.85 rows=37349188 width=4)
-> Seq Scan on testtable2 (cost=0.00..1088488.00 rows=55907600 width=4)
(2 rows)
Time: 615.108 ms
it looks like that postgresql is actually allocating the memory for the
hashtable of the HashAggregate which is a bit unexpected for a plain
EXPLAIN.
Stefan
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend