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=236750.231..236750.486 rows=75 loops=1) Buffers: shared hit=1044003 read=1389672 dirtied=184 written=171 -> GroupAggregate (cost=10373915.91..11203654.54 rows=30172314 width=39) (actual time=236750.226..236750.475 rows=75 loops=1) Buffers: shared hit=1044003 read=1389672 dirtied=184 written=171 -> Sort (cost=10373915.91..10449346.69 rows=30172314 width=39) (actual time=236750.210..236750.253 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=1044003 read=1389672 dirtied=184 written=171 -> Hash Join (cost=3069198.11..5800473.42 rows=30172314 width=39) (actual time=153971.931..236746.826 rows=525 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1043989 read=1389672 dirtied=184 written=171 -> Seq Scan on lineitem (cost=0.00..1675244.29 rows=60344629 width=8) (actual time=0.027..67559.198 rows=60045826 loops=1) Buffers: shared hit=387096 read=684702 dirtied=184 written=171 -> Hash (cost=2974886.21..2974886.21 rows=7544952 width=39) (actual time=153161.152..153161.152 rows=75 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=656893 read=704970 -> Hash Join (cost=2188859.13..2974886.21 rows=7544952 width=39) (actual time=139431.218..153160.618 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=656893 read=704970 -> Hash Join (cost=2119831.13..2754959.17 rows=7544952 width=20) (actual time=137549.523..151276.624 rows=75 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=622661 read=703924 -> Seq Scan on orders (cost=0.00..405686.04 rows=15089904 width=16) (actual time=0.037..8277.910 rows=15015000 loops=1) Buffers: shared hit=254787 -> Hash (cost=2068808.39..2068808.39 rows=4081820 width=4) (actual time=137249.319..137249.319 rows=75 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=367874 read=703924 -> HashAggregate (cost=1976967.44..2027990.19 rows=4081820 width=8) (actual time=128647.814..137248.647 rows=75 loops=1) Filter: (sum(public.lineitem.l_quantity) > 315::double precision) Rows Removed by Filter: 15014925 Buffers: shared hit=367874 read=703924 -> Seq Scan on lineitem (cost=0.00..1675244.29 rows=60344629 width=8) (actual time=0.014..73673.075 rows=60045826 loops=1) Buffers: shared hit=367874 read=703924 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1879.378..1879.378 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=34232 read=1046 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.020..1115.447 rows=1500000 loops=1) Buffers: shared hit=34232 read=1046 Total runtime: 236964.875 ms (39 rows) COMMIT; COMMIT