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) > 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=10452091.77..10452094.52 rows=100 width=39) (actual time=175536.057..175536.565 rows=86 loops=1) Buffers: shared hit=1746151 read=706592 written=3 -> GroupAggregate (cost=10452091.77..11288433.54 rows=30412428 width=39) (actual time=175536.053..175536.552 rows=86 loops=1) Buffers: shared hit=1746151 read=706592 written=3 -> Sort (cost=10452091.77..10528122.84 rows=30412428 width=39) (actual time=175536.019..175536.111 rows=602 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 72kB Buffers: shared hit=1746151 read=706592 written=3 -> Hash Join (cost=3087511.59..5840514.12 rows=30412428 width=39) (actual time=121521.748..175531.446 rows=602 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1746137 read=706592 written=3 -> Seq Scan on lineitem (cost=0.00..1688567.55 rows=60824855 width=8) (actual time=0.030..38482.104 rows=60045033 loops=1) Buffers: shared hit=777306 read=303013 -> Hash (cost=2992449.74..2992449.74 rows=7604948 width=39) (actual time=121392.896..121392.896 rows=86 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 7kB Buffers: shared hit=968831 read=403579 written=3 -> Hash Join (cost=2201405.07..2992449.74 rows=7604948 width=39) (actual time=106775.541..121392.237 rows=86 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=968831 read=403579 written=3 -> Hash Join (cost=2132377.07..2771322.78 rows=7604948 width=20) (actual time=103558.970..118173.258 rows=86 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=968829 read=368303 written=3 -> Seq Scan on orders (cost=0.00..408911.95 rows=15209895 width=16) (actual time=0.012..7865.017 rows=15015000 loops=1) Buffers: shared hit=256810 read=3 -> Hash (cost=2082489.48..2082489.48 rows=3991007 width=4) (actual time=103490.886..103490.886 rows=86 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=712019 read=368300 written=3 -> HashAggregate (cost=1992691.82..2042579.41 rows=3991007 width=8) (actual time=94044.234..103489.890 rows=86 loops=1) Filter: (sum(public.lineitem.l_quantity) > 314::double precision) Rows Removed by Filter: 15014914 Buffers: shared hit=712019 read=368300 written=3 -> Seq Scan on lineitem (cost=0.00..1688567.55 rows=60824855 width=8) (actual time=0.011..38718.951 rows=60045033 loops=1) Buffers: shared hit=712019 read=368300 written=3 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=3214.584..3214.584 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=2 read=35276 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.693..2347.984 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 Total runtime: 175801.913 ms (39 rows) COMMIT; COMMIT