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) > 315 ) 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=10220333.02..10220335.77 rows=100 width=39) (actual time=83768.267..83768.511 rows=75 loops=1) Buffers: shared hit=1519996 read=918425 written=119 -> GroupAggregate (cost=10220333.02..11051723.36 rows=30232376 width=39) (actual time=83768.264..83768.498 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1519996 read=918425 written=119 -> Sort (cost=10220333.02..10295913.96 rows=30232376 width=39) (actual time=83768.248..83768.280 rows=525 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 66kB Buffers: shared hit=1519996 read=918425 written=119 -> Hash Join (cost=2900654.96..5637353.62 rows=30232376 width=39) (actual time=62604.822..83767.237 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1519984 read=918425 written=119 -> Seq Scan on lineitem (cost=0.00..1678565.51 rows=60464751 width=8) (actual time=0.025..12661.915 rows=60044664 loops=1) Buffers: shared hit=640995 read=432923 -> Hash (cost=2806155.01..2806155.01 rows=7559996 width=39) (actual time=62335.925..62335.925 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=878989 read=485502 written=119 -> Hash Join (cost=2189639.54..2806155.01 rows=7559996 width=39) (actual time=55547.748..62335.673 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=878989 read=485502 written=119 -> Hash Join (cost=2120611.54..2623727.07 rows=7559996 width=20) (actual time=54425.998..61213.675 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=843711 read=485502 written=119 -> Seq Scan on orders (cost=0.00..406494.91 rows=15119991 width=16) (actual time=0.010..3649.872 rows=15015000 loops=1) Buffers: shared hit=193891 read=61404 written=117 -> Hash (cost=2070710.73..2070710.73 rows=3992065 width=4) (actual time=54280.064..54280.064 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=649820 read=424098 written=2 -> HashAggregate (cost=1980889.26..2030790.08 rows=3992065 width=8) (actual time=45772.706..54279.728 rows=75 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 315::double precision) Rows Removed by Filter: 15014925 Buffers: shared hit=649820 read=424098 written=2 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1678565.51 rows=60464751 width=8) (actual time=0.014..13996.478 rows=60044664 loops=1) Buffers: shared hit=649820 read=424098 written=2 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1109.180..1109.180 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.021..616.130 rows=1500000 loops=1) Buffers: shared hit=35278 Planning time: 4.511 ms Execution time: 84004.642 ms (42 rows) COMMIT; COMMIT