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=10372009.04..10372011.79 rows=100 width=39) (actual time=139298.862..139299.391 rows=84 loops=1) Buffers: shared hit=1510154 read=923521 written=63 -> GroupAggregate (cost=10372009.04..11201755.26 rows=30172590 width=39) (actual time=139298.858..139299.375 rows=84 loops=1) Buffers: shared hit=1510154 read=923521 written=63 -> Sort (cost=10372009.04..10447440.51 rows=30172590 width=39) (actual time=139298.829..139298.926 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=1510154 read=923521 written=63 -> Hash Join (cost=3067232.81..5798523.26 rows=30172590 width=39) (actual time=95618.218..139294.546 rows=588 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1510140 read=923521 written=63 -> Seq Scan on lineitem (cost=0.00..1675249.80 rows=60345180 width=8) (actual time=0.028..28305.847 rows=60045826 loops=1) Buffers: shared hit=586644 read=485154 -> Hash (cost=2972920.92..2972920.92 rows=7544952 width=39) (actual time=95531.076..95531.076 rows=84 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=923496 read=438367 written=63 -> Hash Join (cost=2187332.40..2972920.92 rows=7544952 width=39) (actual time=83534.041..95530.322 rows=84 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=923496 read=438367 written=63 -> Hash Join (cost=2118304.40..2752993.88 rows=7544952 width=20) (actual time=81806.157..93791.130 rows=84 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=888218 read=438367 written=63 -> Seq Scan on orders (cost=0.00..405686.04 rows=15089904 width=16) (actual time=0.015..6645.738 rows=15015000 loops=1) Buffers: shared hit=254787 -> Hash (cost=2067829.87..2067829.87 rows=4037963 width=4) (actual time=81681.198..81681.198 rows=84 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=633431 read=438367 written=63 -> HashAggregate (cost=1976975.70..2027450.24 rows=4037963 width=8) (actual time=72263.354..81680.530 rows=84 loops=1) Filter: (sum(public.lineitem.l_quantity) > 314::double precision) Rows Removed by Filter: 15014916 Buffers: shared hit=633431 read=438367 written=63 -> Seq Scan on lineitem (cost=0.00..1675249.80 rows=60345180 width=8) (actual time=0.022..22772.831 rows=60045826 loops=1) Buffers: shared hit=633431 read=438367 written=63 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1725.917..1725.917 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35278 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.013..991.830 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 139536.418 ms (39 rows) COMMIT; COMMIT