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) > 314 ) 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=10186496.21..10186498.96 rows=100 width=39) (actual time=75171.388..75171.641 rows=84 loops=1) Buffers: shared hit=1426650 read=1002253 dirtied=570 written=863 -> GroupAggregate (cost=10186496.21..11014596.45 rows=30112736 width=39) (actual time=75171.384..75171.628 rows=84 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1426650 read=1002253 dirtied=570 written=863 -> Sort (cost=10186496.21..10261778.05 rows=30112736 width=39) (actual time=75171.370..75171.402 rows=588 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 70kB Buffers: shared hit=1426650 read=1002253 dirtied=570 written=863 -> Hash Join (cost=2896649.17..5622515.65 rows=30112736 width=39) (actual time=56723.749..75170.173 rows=588 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1426638 read=1002253 dirtied=570 written=863 -> Seq Scan on lineitem (cost=0.00..1671920.72 rows=60225472 width=8) (actual time=0.032..10535.159 rows=60045303 loops=1) Buffers: shared hit=608024 read=461642 dirtied=570 written=542 -> Hash (cost=2802524.57..2802524.57 rows=7529968 width=39) (actual time=56081.868..56081.868 rows=84 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=818614 read=540611 written=321 -> Hash Join (cost=2186854.63..2802524.57 rows=7529968 width=39) (actual time=50029.905..56081.546 rows=84 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=818614 read=540611 written=321 -> Hash Join (cost=2117826.63..2620547.05 rows=7529968 width=20) (actual time=48885.185..54936.526 rows=84 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=818612 read=505335 written=18 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.009..3166.132 rows=15015000 loops=1) Buffers: shared hit=177861 read=76420 written=15 -> Hash (cost=2066120.00..2066120.00 rows=4136530 width=4) (actual time=48742.663..48742.663 rows=84 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=640751 read=428915 written=3 -> HashAggregate (cost=1973048.08..2024754.70 rows=4136530 width=8) (actual time=40730.689..48742.170 rows=84 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 314::double precision) Rows Removed by Filter: 15014916 Buffers: shared hit=640751 read=428915 written=3 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1671920.72 rows=60225472 width=8) (actual time=0.007..12085.659 rows=60045303 loops=1) Buffers: shared hit=640751 read=428915 written=3 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1134.520..1134.520 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=2 read=35276 written=303 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.013..680.115 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 written=303 Planning time: 4.422 ms Execution time: 75419.684 ms (42 rows) COMMIT; COMMIT