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=10245533.92..10245536.67 rows=100 width=39) (actual time=110235.481..110236.027 rows=100 loops=1) Buffers: shared hit=1577338 read=865845 dirtied=1068 written=118 -> GroupAggregate (cost=10245533.92..11078568.90 rows=30292181 width=39) (actual time=110235.477..110235.999 rows=100 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1577338 read=865845 dirtied=1068 written=118 -> Sort (cost=10245533.92..10321264.37 rows=30292181 width=39) (actual time=110235.454..110235.523 rows=700 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=1577338 read=865845 dirtied=1068 written=118 -> Hash Join (cost=2910941.57..5653057.55 rows=30292181 width=39) (actual time=85713.184..110233.686 rows=700 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1577326 read=865845 dirtied=1068 written=118 -> Seq Scan on lineitem (cost=0.00..1681889.62 rows=60584362 width=8) (actual time=0.034..13421.540 rows=60044176 loops=1) Buffers: shared hit=718956 read=357090 written=17 -> Hash (cost=2816254.32..2816254.32 rows=7574980 width=39) (actual time=85471.760..85471.760 rows=100 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65544kB Buffers: shared hit=858370 read=508755 dirtied=1068 written=101 -> Hash Join (cost=2197477.29..2816254.32 rows=7574980 width=39) (actual time=75710.803..85471.052 rows=100 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=858370 read=508755 dirtied=1068 written=101 -> Hash Join (cost=2128449.29..2633601.62 rows=7574980 width=20) (actual time=74232.251..83986.057 rows=100 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=858368 read=473479 dirtied=1068 written=58 -> Seq Scan on orders (cost=0.00..407300.59 rows=15149959 width=16) (actual time=0.014..3965.106 rows=15015000 loops=1) Buffers: shared hit=216071 read=39730 written=52 -> Hash (cost=2077150.06..2077150.06 rows=4103939 width=4) (actual time=74062.648..74062.648 rows=100 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=642297 read=433749 dirtied=1068 written=6 -> HashAggregate (cost=1984811.43..2036110.67 rows=4103939 width=8) (actual time=61451.030..74061.700 rows=100 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 313::double precision) Rows Removed by Filter: 15014900 Buffers: shared hit=642297 read=433749 dirtied=1068 written=6 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1681889.62 rows=60584362 width=8) (actual time=59.713..15894.672 rows=60044176 loops=1) Buffers: shared hit=642297 read=433749 dirtied=1068 written=6 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1464.886..1464.886 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=2 read=35276 written=43 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.019..859.910 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 written=43 Planning time: 6.925 ms Execution time: 110561.866 ms (42 rows) COMMIT; COMMIT