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=10193692.40..10193695.15 rows=100 width=39) (actual time=79465.239..79465.541 rows=99 loops=1) Buffers: shared hit=1341004 read=1090300 dirtied=1 -> GroupAggregate (cost=10193692.40..11022616.35 rows=30142689 width=39) (actual time=79465.236..79465.528 rows=99 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1341004 read=1090300 dirtied=1 -> Sort (cost=10193692.40..10269049.12 rows=30142689 width=39) (actual time=79465.207..79465.245 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=1341004 read=1090300 dirtied=1 -> Hash Join (cost=2896368.03..5624955.92 rows=30142689 width=39) (actual time=58793.095..79463.440 rows=693 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1340992 read=1090300 dirtied=1 -> Seq Scan on lineitem (cost=0.00..1673593.78 rows=60285378 width=8) (actual time=0.037..10542.289 rows=59986308 loops=1) Buffers: shared hit=461087 read=609653 -> Hash (cost=2802149.78..2802149.78 rows=7537460 width=39) (actual time=58631.338..58631.338 rows=99 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65543kB Buffers: shared hit=879905 read=480647 dirtied=1 -> Hash Join (cost=2186557.05..2802149.78 rows=7537460 width=39) (actual time=50218.615..58626.419 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=879905 read=480647 dirtied=1 -> Hash Join (cost=2117529.05..2620059.88 rows=7537460 width=20) (actual time=49324.033..57724.827 rows=99 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=844627 read=480647 dirtied=1 -> Seq Scan on orders (cost=0.00..405283.20 rows=15074920 width=16) (actual time=0.011..3138.099 rows=15000000 loops=1) Buffers: shared hit=190166 read=64368 -> Hash (cost=2066633.20..2066633.20 rows=4071668 width=4) (actual time=49081.318..49081.318 rows=99 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=654461 read=416279 dirtied=1 -> HashAggregate (cost=1975020.67..2025916.52 rows=4071668 width=8) (actual time=42553.078..49079.390 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=654461 read=416279 dirtied=1 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1673593.78 rows=60285378 width=8) (actual time=0.028..12239.490 rows=59986308 loops=1) Buffers: shared hit=654461 read=416279 dirtied=1 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=848.738..848.738 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.039..455.223 rows=1500000 loops=1) Buffers: shared hit=35278 Planning time: 3.834 ms Execution time: 79688.867 ms (42 rows) COMMIT; COMMIT