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=10193692.40..10193695.15 rows=100 width=39) (actual time=79505.137..79505.376 rows=84 loops=1) Buffers: shared hit=1243850 read=1187454 dirtied=1271 written=224 -> GroupAggregate (cost=10193692.40..11022616.35 rows=30142689 width=39) (actual time=79505.134..79505.366 rows=84 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1243850 read=1187454 dirtied=1271 written=224 -> Sort (cost=10193692.40..10269049.12 rows=30142689 width=39) (actual time=79505.114..79505.148 rows=588 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 70kB Buffers: shared hit=1243850 read=1187454 dirtied=1271 written=224 -> Hash Join (cost=2896368.03..5624955.92 rows=30142689 width=39) (actual time=59901.123..79503.920 rows=588 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1243838 read=1187454 dirtied=1271 written=224 -> Seq Scan on lineitem (cost=0.00..1673593.78 rows=60285378 width=8) (actual time=0.058..10787.417 rows=60046221 loops=1) Buffers: shared hit=466026 read=604714 dirtied=228 written=216 -> Hash (cost=2802149.78..2802149.78 rows=7537460 width=39) (actual time=59417.511..59417.511 rows=84 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=777812 read=582740 dirtied=1043 written=8 -> Hash Join (cost=2186557.05..2802149.78 rows=7537460 width=39) (actual time=52764.787..59416.954 rows=84 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=777812 read=582740 dirtied=1043 written=8 -> Hash Join (cost=2117529.05..2620059.88 rows=7537460 width=20) (actual time=51818.372..58466.368 rows=84 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=742551 read=582723 dirtied=1043 written=8 -> Seq Scan on orders (cost=0.00..405283.20 rows=15074920 width=16) (actual time=0.009..3346.489 rows=15015000 loops=1) Buffers: shared hit=153735 read=100799 written=4 -> Hash (cost=2066633.20..2066633.20 rows=4071668 width=4) (actual time=51665.911..51665.911 rows=84 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=588816 read=481924 dirtied=1043 written=4 -> HashAggregate (cost=1975020.67..2025916.52 rows=4071668 width=8) (actual time=43455.444..51664.907 rows=84 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 314::double precision) Rows Removed by Filter: 15014916 Buffers: shared hit=588816 read=481924 dirtied=1043 written=4 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1673593.78 rows=60285378 width=8) (actual time=0.011..12066.026 rows=60046221 loops=1) Buffers: shared hit=588816 read=481924 dirtied=1043 written=4 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=936.543..936.543 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35261 read=17 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.030..480.318 rows=1500000 loops=1) Buffers: shared hit=35261 read=17 Planning time: 3.636 ms Execution time: 79749.424 ms (42 rows) COMMIT; COMMIT