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=10183783.72..10183786.47 rows=100 width=39) (actual time=96232.988..96233.302 rows=100 loops=1) Buffers: shared hit=1493495 read=935069 written=10 -> GroupAggregate (cost=10183783.72..11011850.96 rows=30111536 width=39) (actual time=96232.984..96233.288 rows=100 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1493495 read=935069 written=10 -> Sort (cost=10183783.72..10259062.56 rows=30111536 width=39) (actual time=96232.966..96233.003 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=1493495 read=935069 written=10 -> Hash Join (cost=2894234.92..5619992.38 rows=30111536 width=39) (actual time=74096.522..96231.292 rows=777 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1493483 read=935069 written=10 -> Seq Scan on lineitem (cost=0.00..1671853.71 rows=60223071 width=8) (actual time=0.029..11871.640 rows=59985653 loops=1) Buffers: shared hit=628707 read=440916 -> Hash (cost=2800203.97..2800203.97 rows=7522476 width=39) (actual time=73911.157..73911.157 rows=111 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65544kB Buffers: shared hit=864776 read=494153 written=10 -> Hash Join (cost=2185476.59..2800203.97 rows=7522476 width=39) (actual time=65390.829..73910.354 rows=111 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=864776 read=494153 written=10 -> Hash Join (cost=2116448.59..2618338.83 rows=7522476 width=20) (actual time=64341.471..72856.107 rows=111 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=829511 read=494140 written=9 -> Seq Scan on orders (cost=0.00..404477.52 rows=15044952 width=16) (actual time=0.009..3015.835 rows=15000000 loops=1) Buffers: shared hit=254028 -> Hash (cost=2065205.90..2065205.90 rows=4099415 width=4) (actual time=64160.995..64160.995 rows=111 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=575483 read=494140 written=9 -> HashAggregate (cost=1972969.06..2024211.75 rows=4099415 width=8) (actual time=52967.310..64158.371 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=575483 read=494140 written=9 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1671853.71 rows=60223071 width=8) (actual time=0.013..13623.312 rows=59985653 loops=1) Buffers: shared hit=575483 read=494140 written=9 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1035.768..1035.768 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35265 read=13 written=1 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.017..557.540 rows=1500000 loops=1) Buffers: shared hit=35265 read=13 written=1 Planning time: 4.375 ms Execution time: 96494.010 ms (42 rows) COMMIT; COMMIT