BEGIN; BEGIN EXPLAIN select c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) from customer, orders, lineitem where o_orderkey in ( select l_orderkey from lineitem group by l_orderkey having sum(l_quantity) > 314 ) and c_custkey = o_custkey and o_orderkey = l_orderkey group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice order by o_totalprice desc, o_orderdate LIMIT 100; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=3420212.61..3420212.86 rows=100 width=75) -> Sort (cost=3420212.61..3421564.64 rows=540811 width=75) Sort Key: orders.o_totalprice DESC, orders.o_orderdate -> Finalize GroupAggregate (cost=3331187.01..3399543.20 rows=540811 width=75) Group Key: customer.c_custkey, orders.o_orderkey -> Gather Merge (cost=3331187.01..3388276.31 rows=450676 width=75) Workers Planned: 2 -> Partial GroupAggregate (cost=3330186.99..3335257.09 rows=225338 width=75) Group Key: customer.c_custkey, orders.o_orderkey -> Sort (cost=3330186.99..3330750.33 rows=225338 width=48) Sort Key: customer.c_custkey, orders.o_orderkey -> Nested Loop (cost=2334262.78..3303218.99 rows=225338 width=48) -> Hash Join (cost=2334262.22..2884905.05 rows=56344 width=51) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) -> Parallel Hash Join (cost=53591.95..477447.04 rows=6249429 width=43) Hash Cond: (orders.o_custkey = customer.c_custkey) -> Parallel Seq Scan on orders (cost=0.00..330551.29 rows=6249429 width=24) -> Parallel Hash (cost=42116.20..42116.20 rows=625020 width=23) -> Parallel Seq Scan on customer (cost=0.00..42116.20 rows=625020 width=23) -> Hash (cost=2278450.94..2278450.94 rows=135226 width=8) -> GroupAggregate (cost=0.56..2277098.68 rows=135226 width=8) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > '314'::numeric) -> Index Only Scan using lineitem_l_orderkey_l_suppkey_l_quantity_idx on lineitem lineitem_1 (cost=0.56..1971092.28 rows=59984248 width=13) -> Index Only Scan using lineitem_l_orderkey_l_suppkey_l_quantity_idx on lineitem (cost=0.56..5.94 rows=148 width=13) Index Cond: (l_orderkey = orders.o_orderkey) (26 rows) COMMIT; COMMIT