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=10192226.92..10192229.67 rows=100 width=39) (actual time=94225.632..94225.865 rows=75 loops=1) Buffers: shared hit=1362392 read=1068912 written=72 -> GroupAggregate (cost=10192226.92..11021151.22 rows=30142702 width=39) (actual time=94225.629..94225.854 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1362392 read=1068912 written=72 -> Sort (cost=10192226.92..10267583.67 rows=30142702 width=39) (actual time=94225.592..94225.625 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=1362392 read=1068912 written=72 -> Hash Join (cost=2894900.15..5623488.73 rows=30142702 width=39) (actual time=71396.432..94224.408 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1362380 read=1068912 written=72 -> Seq Scan on lineitem (cost=0.00..1673594.03 rows=60285403 width=8) (actual time=0.033..12059.966 rows=60046221 loops=1) Buffers: shared hit=517727 read=553013 written=14 -> Hash (cost=2800681.90..2800681.90 rows=7537460 width=39) (actual time=71085.533..71085.533 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=844653 read=515899 written=58 -> Hash Join (cost=2185415.45..2800681.90 rows=7537460 width=39) (actual time=61739.032..71081.452 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=844653 read=515899 written=58 -> Hash Join (cost=2116387.45..2618592.00 rows=7537460 width=20) (actual time=60749.100..70085.181 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=809410 read=515864 written=56 -> Seq Scan on orders (cost=0.00..405283.20 rows=15074920 width=16) (actual time=0.008..3553.994 rows=15015000 loops=1) Buffers: shared hit=194975 read=59559 written=55 -> Hash (cost=2065899.45..2065899.45 rows=4039040 width=4) (actual time=60579.094..60579.094 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=614435 read=456305 written=1 -> HashAggregate (cost=1975021.05..2025509.05 rows=4039040 width=8) (actual time=49834.222..60576.456 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=614435 read=456305 written=1 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1673594.03 rows=60285403 width=8) (actual time=0.009..13054.507 rows=60046221 loops=1) Buffers: shared hit=614435 read=456305 written=1 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=972.962..972.962 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35243 read=35 written=2 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.017..482.962 rows=1500000 loops=1) Buffers: shared hit=35243 read=35 written=2 Planning time: 4.136 ms Execution time: 94708.005 ms (42 rows) COMMIT; COMMIT