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=10235385.79..10235388.54 rows=100 width=39) (actual time=101454.549..101454.803 rows=75 loops=1) Buffers: shared hit=1506017 read=934773 written=246 -> GroupAggregate (cost=10235385.79..11067592.41 rows=30262059 width=39) (actual time=101454.545..101454.790 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1506017 read=934773 written=246 -> Sort (cost=10235385.79..10311040.94 rows=30262059 width=39) (actual time=101454.527..101454.570 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=1506017 read=934773 written=246 -> Hash Join (cost=2908302.85..5647692.12 rows=30262059 width=39) (actual time=76652.836..101453.343 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1506005 read=934773 written=246 -> Seq Scan on lineitem (cost=0.00..1680217.18 rows=60524118 width=8) (actual time=0.028..13762.503 rows=60044082 loops=1) Buffers: shared hit=727926 read=347050 written=1 -> Hash (cost=2813709.25..2813709.25 rows=7567488 width=39) (actual time=76483.645..76483.645 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=778079 read=587723 written=245 -> Hash Join (cost=2195503.63..2813709.25 rows=7567488 width=39) (actual time=66361.705..76483.134 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=778079 read=587723 written=245 -> Hash Join (cost=2126475.63..2631168.93 rows=7567488 width=20) (actual time=65043.845..75158.803 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=769194 read=561330 written=88 -> Seq Scan on orders (cost=0.00..406897.75 rows=15134975 width=16) (actual time=0.005..4044.561 rows=15015000 loops=1) Buffers: shared hit=194139 read=61409 written=87 -> Hash (cost=2075176.40..2075176.40 rows=4103939 width=4) (actual time=64858.242..64858.242 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=575055 read=499921 written=1 -> HashAggregate (cost=1982837.77..2034137.01 rows=4103939 width=8) (actual time=54997.328..64855.203 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=575055 read=499921 written=1 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1680217.18 rows=60524118 width=8) (actual time=0.036..16099.278 rows=60044082 loops=1) Buffers: shared hit=575055 read=499921 written=1 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1303.564..1303.564 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=8885 read=26393 written=157 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.009..697.150 rows=1500000 loops=1) Buffers: shared hit=8885 read=26393 written=157 Planning time: 6.614 ms Execution time: 101780.958 ms (42 rows) COMMIT; COMMIT