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=10182043.94..10182046.69 rows=100 width=39) (actual time=103718.923..103719.157 rows=75 loops=1) Buffers: shared hit=1510724 read=918179 written=65 -> GroupAggregate (cost=10182043.94..11010136.78 rows=30112467 width=39) (actual time=103718.920..103719.144 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1510724 read=918179 written=65 -> Sort (cost=10182043.94..10257325.11 rows=30112467 width=39) (actual time=103718.896..103718.918 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=1510724 read=918179 written=65 -> Hash Join (cost=2892254.05..5618105.73 rows=30112467 width=39) (actual time=80122.831..103717.710 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1510712 read=918179 written=65 -> Seq Scan on lineitem (cost=0.00..1671915.34 rows=60224934 width=8) (actual time=0.026..12185.785 rows=60045303 loops=1) Buffers: shared hit=701915 read=367751 written=5 -> Hash (cost=2798129.45..2798129.45 rows=7529968 width=39) (actual time=77591.679..77591.679 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=808797 read=550428 written=60 -> Hash Join (cost=2183434.41..2798129.45 rows=7529968 width=39) (actual time=68347.302..77586.897 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=808797 read=550428 written=60 -> Hash Join (cost=2114406.41..2616151.93 rows=7529968 width=20) (actual time=67332.419..76566.210 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=773519 read=550428 written=60 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.010..3466.663 rows=15015000 loops=1) Buffers: shared hit=205177 read=49104 written=52 -> Hash (cost=2063918.41..2063918.41 rows=4039040 width=4) (actual time=67124.985..67124.985 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=568342 read=501324 written=8 -> HashAggregate (cost=1973040.01..2023528.01 rows=4039040 width=8) (actual time=57404.672..67121.584 rows=75 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 315::double precision) Rows Removed by Filter: 15014925 Buffers: shared hit=568342 read=501324 written=8 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1671915.34 rows=60224934 width=8) (actual time=0.028..13586.849 rows=60045303 loops=1) Buffers: shared hit=568342 read=501324 written=8 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=999.940..999.940 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35278 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.038..528.349 rows=1500000 loops=1) Buffers: shared hit=35278 Planning time: 4.474 ms Execution time: 103993.296 ms (42 rows) COMMIT; COMMIT