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=10226846.98..10226849.73 rows=100 width=39) (actual time=77532.010..77532.298 rows=100 loops=1) Buffers: shared hit=1498739 read=939682 written=37 -> GroupAggregate (cost=10226846.98..11058238.97 rows=30232436 width=39) (actual time=77532.007..77532.277 rows=100 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1498739 read=939682 written=37 -> Sort (cost=10226846.98..10302428.07 rows=30232436 width=39) (actual time=77531.990..77532.028 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=1498739 read=939682 written=37 -> Hash Join (cost=2907157.70..5643859.70 rows=30232436 width=39) (actual time=59105.501..77530.182 rows=777 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1498727 read=939682 written=37 -> Seq Scan on lineitem (cost=0.00..1678566.72 rows=60464872 width=8) (actual time=0.022..10737.561 rows=60044664 loops=1) Buffers: shared hit=551561 read=522357 -> Hash (cost=2812657.75..2812657.75 rows=7559996 width=39) (actual time=58962.162..58962.162 rows=111 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65544kB Buffers: shared hit=947166 read=417325 written=37 -> Hash Join (cost=2194697.63..2812657.75 rows=7559996 width=39) (actual time=53163.154..58961.617 rows=111 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=947166 read=417325 written=37 -> Hash Join (cost=2125669.63..2630229.81 rows=7559996 width=20) (actual time=52227.927..58025.980 rows=111 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=911888 read=417325 written=37 -> Seq Scan on orders (cost=0.00..406494.91 rows=15119991 width=16) (actual time=0.009..2968.543 rows=15015000 loops=1) Buffers: shared hit=214835 read=40460 written=27 -> Hash (cost=2073963.00..2073963.00 rows=4136530 width=4) (actual time=52120.812..52120.812 rows=111 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=697053 read=376865 written=10 -> HashAggregate (cost=1980891.08..2032597.70 rows=4136530 width=8) (actual time=43069.560..52120.289 rows=111 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 312::double precision) Rows Removed by Filter: 15014889 Buffers: shared hit=697053 read=376865 written=10 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1678566.72 rows=60464872 width=8) (actual time=0.006..12405.790 rows=60044664 loops=1) Buffers: shared hit=697053 read=376865 written=10 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=925.026..925.026 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.016..489.639 rows=1500000 loops=1) Buffers: shared hit=35278 Planning time: 3.854 ms Execution time: 77792.067 ms (42 rows) COMMIT; COMMIT