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) > 313 ) 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=10188704.15..10188706.90 rows=100 width=39) (actual time=107280.264..107280.598 rows=99 loops=1) Buffers: shared hit=1593308 read=836433 written=1670 -> GroupAggregate (cost=10188704.15..11017124.33 rows=30124370 width=39) (actual time=107280.261..107280.586 rows=99 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1593308 read=836433 written=1670 -> Sort (cost=10188704.15..10264015.08 rows=30124370 width=39) (actual time=107280.228..107280.276 rows=693 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 79kB Buffers: shared hit=1593308 read=836433 written=1670 -> Hash Join (cost=2895950.61..5622875.98 rows=30124370 width=39) (actual time=82046.280..107278.711 rows=693 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1593296 read=836433 written=1670 -> Seq Scan on lineitem (cost=0.00..1672572.41 rows=60248741 width=8) (actual time=0.047..13501.706 rows=59985781 loops=1) Buffers: shared hit=758075 read=312010 -> Hash (cost=2801826.01..2801826.01 rows=7529968 width=39) (actual time=81957.830..81957.830 rows=99 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65543kB Buffers: shared hit=835221 read=524423 written=1670 -> Hash Join (cost=2186481.98..2801826.01 rows=7529968 width=39) (actual time=72175.912..81954.701 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=835221 read=524423 written=1670 -> Hash Join (cost=2117453.98..2619848.49 rows=7529968 width=20) (actual time=70584.637..80357.077 rows=99 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=835219 read=489147 written=15 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.016..3813.793 rows=15000000 loops=1) Buffers: shared hit=207140 read=47141 written=8 -> Hash (cost=2066154.74..2066154.74 rows=4103939 width=4) (actual time=70365.917..70365.917 rows=99 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=628079 read=442006 written=7 -> HashAggregate (cost=1973816.12..2025115.35 rows=4103939 width=8) (actual time=57886.724..70363.013 rows=99 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 313::double precision) Rows Removed by Filter: 14999901 Buffers: shared hit=628079 read=442006 written=7 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1672572.41 rows=60248741 width=8) (actual time=0.048..16490.334 rows=59985781 loops=1) Buffers: shared hit=628079 read=442006 written=7 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1439.959..1439.959 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=2 read=35276 written=1655 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.038..916.011 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 written=1655 Planning time: 5.627 ms Execution time: 107733.960 ms (42 rows) COMMIT; COMMIT