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=10184828.20..10184830.95 rows=100 width=39) (actual time=92210.533..92210.783 rows=75 loops=1) Buffers: shared hit=1426413 read=1002490 written=25 -> GroupAggregate (cost=10184828.20..11012928.72 rows=30112746 width=39) (actual time=92210.530..92210.773 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1426413 read=1002490 written=25 -> Sort (cost=10184828.20..10260110.07 rows=30112746 width=39) (actual time=92210.511..92210.560 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=1426413 read=1002490 written=25 -> Hash Join (cost=2894979.29..5620846.32 rows=30112746 width=39) (actual time=69723.977..92209.319 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1426401 read=1002490 written=25 -> Seq Scan on lineitem (cost=0.00..1671920.92 rows=60225492 width=8) (actual time=0.042..11841.187 rows=60045303 loops=1) Buffers: shared hit=526337 read=543329 -> Hash (cost=2800854.69..2800854.69 rows=7529968 width=39) (actual time=68753.364..68753.364 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=900064 read=459161 written=25 -> Hash Join (cost=2185555.90..2800854.69 rows=7529968 width=39) (actual time=59863.061..68750.307 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=900064 read=459161 written=25 -> Hash Join (cost=2116527.90..2618877.17 rows=7529968 width=20) (actual time=58778.381..67660.378 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=877279 read=446668 written=25 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.010..3054.987 rows=15015000 loops=1) Buffers: shared hit=246095 read=8186 written=22 -> Hash (cost=2065285.22..2065285.22 rows=4099415 width=4) (actual time=58590.066..58590.066 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=631184 read=438482 written=3 -> HashAggregate (cost=1973048.38..2024291.07 rows=4099415 width=8) (actual time=47629.732..58587.921 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=631184 read=438482 written=3 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1671920.92 rows=60225492 width=8) (actual time=0.012..13193.912 rows=60045303 loops=1) Buffers: shared hit=631184 read=438482 written=3 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1071.555..1071.555 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=22785 read=12493 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.013..599.321 rows=1500000 loops=1) Buffers: shared hit=22785 read=12493 Planning time: 4.758 ms Execution time: 92632.598 ms (42 rows) COMMIT; COMMIT