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=10196679.05..10196681.80 rows=100 width=39) (actual time=79056.157..79056.386 rows=75 loops=1) Buffers: shared hit=1434619 read=996685 dirtied=1 written=130 -> GroupAggregate (cost=10196679.05..11025610.72 rows=30142970 width=39) (actual time=79056.154..79056.377 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1434619 read=996685 dirtied=1 written=130 -> Sort (cost=10196679.05..10272036.47 rows=30142970 width=39) (actual time=79056.139..79056.161 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=1434619 read=996685 dirtied=1 written=130 -> Hash Join (cost=2899295.27..5627898.64 rows=30142970 width=39) (actual time=59742.800..79055.130 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1434607 read=996685 dirtied=1 written=130 -> Seq Scan on lineitem (cost=0.00..1673599.41 rows=60285941 width=8) (actual time=0.052..10640.831 rows=60046221 loops=1) Buffers: shared hit=653012 read=417728 dirtied=1 -> Hash (cost=2805077.02..2805077.02 rows=7537460 width=39) (actual time=59560.640..59560.640 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=781595 read=578957 written=130 -> Hash Join (cost=2188835.67..2805077.02 rows=7537460 width=39) (actual time=53187.685..59560.382 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=781595 read=578957 written=130 -> Hash Join (cost=2119807.67..2622987.12 rows=7537460 width=20) (actual time=52262.086..58634.542 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=746418 read=578856 written=130 -> Seq Scan on orders (cost=0.00..405283.20 rows=15074920 width=16) (actual time=0.008..3486.241 rows=15015000 loops=1) Buffers: shared hit=148235 read=106299 written=124 -> Hash (cost=2068101.04..2068101.04 rows=4136530 width=4) (actual time=51797.994..51797.994 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=598183 read=472557 written=6 -> HashAggregate (cost=1975029.12..2026735.74 rows=4136530 width=8) (actual time=42514.230..51797.610 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=598183 read=472557 written=6 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1673599.41 rows=60285941 width=8) (actual time=0.019..12236.394 rows=60046221 loops=1) Buffers: shared hit=598183 read=472557 written=6 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=910.104..910.104 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35177 read=101 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.017..471.558 rows=1500000 loops=1) Buffers: shared hit=35177 read=101 Planning time: 3.983 ms Execution time: 79349.218 ms (42 rows) COMMIT; COMMIT