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) > 313 ) 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=10149706.53..10149709.28 rows=100 width=39) (actual time=84420.376..84420.686 rows=99 loops=1) Buffers: shared hit=1517705 read=904057 written=13 -> GroupAggregate (cost=10149706.53..10975334.74 rows=30022844 width=39) (actual time=84420.371..84420.667 rows=99 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1517705 read=904057 written=13 -> Sort (cost=10149706.53..10224763.64 rows=30022844 width=39) (actual time=84420.349..84420.387 rows=693 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 79kB Buffers: shared hit=1517705 read=904057 written=13 -> Hash Join (cost=2882265.32..5599996.76 rows=30022844 width=39) (actual time=61928.392..84418.752 rows=693 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1517693 read=904057 written=13 -> Seq Scan on lineitem (cost=0.00..1666931.89 rows=60045689 width=8) (actual time=0.079..11959.528 rows=59985329 loops=1) Buffers: shared hit=572223 read=494252 written=3 -> Hash (cost=2788421.67..2788421.67 rows=7507492 width=39) (actual time=61439.815..61439.815 rows=99 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65543kB Buffers: shared hit=945470 read=409805 written=10 -> Hash Join (cost=2175910.61..2788421.67 rows=7507492 width=39) (actual time=51442.486..61439.125 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=945470 read=409805 written=10 -> Hash Join (cost=2106882.61..2606781.29 rows=7507492 width=20) (actual time=50092.056..60083.947 rows=99 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=910226 read=409771 written=10 -> Seq Scan on orders (cost=0.00..403671.84 rows=15014984 width=16) (actual time=0.013..4224.134 rows=15000000 loops=1) Buffers: shared hit=120916 read=132606 written=4 -> Hash (cost=2056981.80..2056981.80 rows=3992065 width=4) (actual time=49888.880..49888.880 rows=99 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=789310 read=277165 written=6 -> HashAggregate (cost=1967160.33..2017061.15 rows=3992065 width=8) (actual time=43901.901..49888.070 rows=99 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 313::double precision) Rows Removed by Filter: 14999901 Buffers: shared hit=789310 read=277165 written=6 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1666931.89 rows=60045689 width=8) (actual time=0.010..14256.703 rows=59985329 loops=1) Buffers: shared hit=789310 read=277165 written=6 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1343.104..1343.104 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35244 read=34 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.015..628.737 rows=1500000 loops=1) Buffers: shared hit=35244 read=34 Planning time: 3.458 ms Execution time: 84551.284 ms (42 rows) COMMIT; COMMIT