Hi, While reading through the cost_agg() I found that startup cost for the group aggregate is not correctly assigned. Due to this explain plan is not printing the correct startup cost.
Without patch: postgres=# explain select aid, sum(abalance) from pgbench_accounts where filler like '%foo%' group by aid; QUERY PLAN ------------------------------------------------------------------------------------- GroupAggregate (cost=81634.33..85102.04 rows=198155 width=12) Group Key: aid -> Sort (cost=81634.33..82129.72 rows=198155 width=8) Sort Key: aid -> Seq Scan on pgbench_accounts (cost=0.00..61487.89 rows=198155 width=8) Filter: (filler ~~ '%foo%'::text) (6 rows) With patch: postgres=# explain select aid, sum(abalance) from pgbench_accounts where filler like '%foo%' group by aid; QUERY PLAN ------------------------------------------------------------------------------------- GroupAggregate (cost=82129.72..85102.04 rows=198155 width=12) Group Key: aid -> Sort (cost=81634.33..82129.72 rows=198155 width=8) Sort Key: aid -> Seq Scan on pgbench_accounts (cost=0.00..61487.89 rows=198155 width=8) Filter: (filler ~~ '%foo%'::text) (6 rows) PFA patch to correct the same. Regards, Rushabh Lathia www.EnterpriseDB.com
fix_startup_cost_cost_agg.patch
Description: application/download
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers