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) > 312 ) 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=10154555.93..10154558.68 rows=100 width=39) (actual time=80551.285..80551.618 rows=100 loops=1) Buffers: shared hit=1447344 read=974418 dirtied=910 written=857 -> GroupAggregate (cost=10154555.93..10980186.07 rows=30022914 width=39) (actual time=80551.280..80551.603 rows=100 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1447344 read=974418 dirtied=910 written=857 -> Sort (cost=10154555.93..10229613.22 rows=30022914 width=39) (actual time=80551.264..80551.307 rows=701 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 85kB Buffers: shared hit=1447344 read=974418 dirtied=910 written=857 -> Hash Join (cost=2887098.17..5604833.46 rows=30022914 width=39) (actual time=58011.782..80549.436 rows=777 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1447332 read=974418 dirtied=910 written=857 -> Seq Scan on lineitem (cost=0.00..1666933.29 rows=60045829 width=8) (actual time=0.017..12484.006 rows=59985329 loops=1) Buffers: shared hit=612167 read=454308 dirtied=909 written=846 -> Hash (cost=2793254.52..2793254.52 rows=7507492 width=39) (actual time=57519.692..57519.692 rows=111 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65544kB Buffers: shared hit=835165 read=520110 dirtied=1 written=11 -> Hash Join (cost=2179669.96..2793254.52 rows=7507492 width=39) (actual time=50314.056..57518.952 rows=111 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=835165 read=520110 dirtied=1 written=11 -> Hash Join (cost=2110641.96..2611614.14 rows=7507492 width=20) (actual time=49146.211..56343.891 rows=111 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=800376 read=519621 dirtied=1 written=11 -> Seq Scan on orders (cost=0.00..403671.84 rows=15014984 width=16) (actual time=0.012..4017.719 rows=15000000 loops=1) Buffers: shared hit=155657 read=97865 written=5 -> Hash (cost=2059399.27..2059399.27 rows=4099415 width=4) (actual time=48974.143..48974.143 rows=111 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=644719 read=421756 dirtied=1 written=6 -> HashAggregate (cost=1967162.44..2018405.12 rows=4099415 width=8) (actual time=42776.259..48973.361 rows=111 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 312::double precision) Rows Removed by Filter: 14999889 Buffers: shared hit=644719 read=421756 dirtied=1 written=6 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1666933.29 rows=60045829 width=8) (actual time=0.019..13112.033 rows=59985329 loops=1) Buffers: shared hit=644719 read=421756 dirtied=1 written=6 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1160.202..1160.202 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=34789 read=489 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.019..516.214 rows=1500000 loops=1) Buffers: shared hit=34789 read=489 Planning time: 3.965 ms Execution time: 80701.321 ms (42 rows) COMMIT; COMMIT