tpch10s=# set enable_hashagg=off; tpch10s=# set optimizer=off; tpch10s=# explain select sum(l_quantity), l_partkey, l_suppkey from lineitem group by l_partkey, l_suppkey; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------ Gather Motion 8:1 (slice2; segments: 8) (cost=14249316.35..14444271.04 rows=5998606 width=40) -> GroupAggregate (cost=14249316.35..14444271.04 rows=749826 width=40) Group Key: lineitem.l_partkey, lineitem.l_suppkey -> Sort (cost=14249316.35..14264312.86 rows=749826 width=40) Sort Key: lineitem.l_partkey, lineitem.l_suppkey -> Redistribute Motion 8:8 (slice1; segments: 8) (cost=12175746.69..12970561.91 rows=749826 width=40) Hash Key: lineitem.l_partkey, lineitem.l_suppkey -> GroupAggregate (cost=12175746.69..12850589.79 rows=749826 width=40) Group Key: lineitem.l_partkey, lineitem.l_suppkey -> Sort (cost=12175746.69..12325711.82 rows=7498257 width=13) Sort Key: lineitem.l_partkey, lineitem.l_suppkey -> Seq Scan on lineitem (cost=0.00..654972.52 rows=7498257 width=13) Optimizer: Postgres query optimizer