BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) 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) > 315 ) 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=10332424.74..10332427.49 rows=100 width=39) (actual time=133551.768..133552.012 rows=75 loops=1) Buffers: shared hit=1537757 read=886402 dirtied=1 -> GroupAggregate (cost=10332424.74..11158878.67 rows=30052870 width=39) (actual time=133551.764..133551.999 rows=75 loops=1) Buffers: shared hit=1537757 read=886402 dirtied=1 -> Sort (cost=10332424.74..10407556.92 rows=30052870 width=39) (actual time=133551.747..133551.784 rows=525 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 66kB Buffers: shared hit=1537757 read=886402 dirtied=1 -> Hash Join (cost=3057492.76..5777946.61 rows=30052870 width=39) (actual time=96420.910..133548.860 rows=525 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1537743 read=886402 dirtied=1 -> Seq Scan on lineitem (cost=0.00..1668603.40 rows=60105740 width=8) (actual time=0.057..21707.887 rows=60045603 loops=1) Buffers: shared hit=559483 read=508063 -> Hash (cost=2963555.46..2963555.46 rows=7514984 width=39) (actual time=96222.263..96222.263 rows=75 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=978260 read=378339 dirtied=1 -> Hash Join (cost=2180607.30..2963555.46 rows=7514984 width=39) (actual time=85423.364..96220.775 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=978260 read=378339 dirtied=1 -> Hash Join (cost=2111579.30..2744227.78 rows=7514984 width=20) (actual time=83957.877..94714.243 rows=75 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=944096 read=377225 dirtied=1 -> Seq Scan on orders (cost=0.00..404074.68 rows=15029968 width=16) (actual time=0.018..5113.015 rows=15015000 loops=1) Buffers: shared hit=250412 read=3363 -> Hash (cost=2060705.30..2060705.30 rows=4069920 width=4) (actual time=83834.632..83834.632 rows=75 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=693684 read=373862 dirtied=1 -> HashAggregate (cost=1969132.10..2020006.10 rows=4069920 width=8) (actual time=73279.774..83833.954 rows=75 loops=1) Filter: (sum(public.lineitem.l_quantity) > 315::double precision) Rows Removed by Filter: 15014925 Buffers: shared hit=693684 read=373862 dirtied=1 -> Seq Scan on lineitem (cost=0.00..1668603.40 rows=60105740 width=8) (actual time=0.027..21597.492 rows=60045603 loops=1) Buffers: shared hit=693684 read=373862 dirtied=1 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1463.941..1463.941 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=34164 read=1114 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.018..777.177 rows=1500000 loops=1) Buffers: shared hit=34164 read=1114 Total runtime: 133937.068 ms (39 rows) COMMIT; COMMIT