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=10373915.91..10373918.66 rows=100 width=39) (actual time=220102.329..220102.791 rows=75 loops=1) Buffers: shared hit=1382955 read=1050720 dirtied=964 written=760 -> GroupAggregate (cost=10373915.91..11203654.54 rows=30172314 width=39) (actual time=220102.324..220102.771 rows=75 loops=1) Buffers: shared hit=1382955 read=1050720 dirtied=964 written=760 -> Sort (cost=10373915.91..10449346.69 rows=30172314 width=39) (actual time=220102.295..220102.387 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=1382955 read=1050720 dirtied=964 written=760 -> Hash Join (cost=3069198.11..5800473.42 rows=30172314 width=39) (actual time=152281.214..220097.044 rows=525 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1382941 read=1050720 dirtied=964 written=760 -> Seq Scan on lineitem (cost=0.00..1675244.29 rows=60344629 width=8) (actual time=0.088..54352.818 rows=60045826 loops=1) Buffers: shared hit=453723 read=618075 written=1 -> Hash (cost=2974886.21..2974886.21 rows=7544952 width=39) (actual time=150781.423..150781.423 rows=75 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=929218 read=432645 dirtied=964 written=759 -> Hash Join (cost=2188859.13..2974886.21 rows=7544952 width=39) (actual time=132354.715..150780.991 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=929218 read=432645 dirtied=964 written=759 -> Hash Join (cost=2119831.13..2754959.17 rows=7544952 width=20) (actual time=129971.996..148396.497 rows=75 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=893944 read=432641 dirtied=964 written=759 -> Seq Scan on orders (cost=0.00..405686.04 rows=15089904 width=16) (actual time=0.016..11756.570 rows=15015000 loops=1) Buffers: shared hit=254787 dirtied=4 -> Hash (cost=2068808.39..2068808.39 rows=4081820 width=4) (actual time=129633.038..129633.038 rows=75 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=639157 read=432641 dirtied=960 written=759 -> HashAggregate (cost=1976967.44..2027990.19 rows=4081820 width=8) (actual time=120655.105..129631.989 rows=75 loops=1) Filter: (sum(public.lineitem.l_quantity) > 315::double precision) Rows Removed by Filter: 15014925 Buffers: shared hit=639157 read=432641 dirtied=960 written=759 -> Seq Scan on lineitem (cost=0.00..1675244.29 rows=60344629 width=8) (actual time=0.013..61575.804 rows=60045826 loops=1) Buffers: shared hit=639157 read=432641 dirtied=960 written=759 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=2380.542..2380.542 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35274 read=4 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.015..1555.999 rows=1500000 loops=1) Buffers: shared hit=35274 read=4 Total runtime: 220347.886 ms (39 rows) COMMIT; COMMIT