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=10374500.96..10374503.71 rows=100 width=39) (actual time=120971.150..120971.425 rows=84 loops=1) Buffers: shared hit=1487152 read=946523 written=1 -> GroupAggregate (cost=10374500.96..11204241.88 rows=30172397 width=39) (actual time=120971.147..120971.414 rows=84 loops=1) Buffers: shared hit=1487152 read=946523 written=1 -> Sort (cost=10374500.96..10449931.95 rows=30172397 width=39) (actual time=120971.126..120971.166 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=1487152 read=946523 written=1 -> Hash Join (cost=3069767.73..5801047.56 rows=30172397 width=39) (actual time=89156.972..120968.144 rows=588 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1487138 read=946523 written=1 -> Seq Scan on lineitem (cost=0.00..1675245.94 rows=60344794 width=8) (actual time=0.031..18442.538 rows=60045826 loops=1) Buffers: shared hit=669866 read=401932 -> Hash (cost=2975455.83..2975455.83 rows=7544952 width=39) (actual time=89044.962..89044.962 rows=84 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=817272 read=544591 written=1 -> Hash Join (cost=2189302.72..2975455.83 rows=7544952 width=39) (actual time=79329.362..89044.532 rows=84 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=817272 read=544591 written=1 -> Hash Join (cost=2120274.72..2755528.79 rows=7544952 width=20) (actual time=77577.064..87290.259 rows=84 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=781994 read=544591 written=1 -> Seq Scan on orders (cost=0.00..405686.04 rows=15089904 width=16) (actual time=0.016..4579.701 rows=15015000 loops=1) Buffers: shared hit=254787 -> Hash (cost=2069094.43..2069094.43 rows=4094423 width=4) (actual time=77400.233..77400.233 rows=84 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=527207 read=544591 written=1 -> HashAggregate (cost=1976969.91..2028150.20 rows=4094423 width=8) (actual time=68100.521..77399.634 rows=84 loops=1) Filter: (sum(public.lineitem.l_quantity) > 314::double precision) Rows Removed by Filter: 15014916 Buffers: shared hit=527207 read=544591 written=1 -> Seq Scan on lineitem (cost=0.00..1675245.94 rows=60344794 width=8) (actual time=0.017..19625.177 rows=60045826 loops=1) Buffers: shared hit=527207 read=544591 written=1 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1750.227..1750.227 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.014..902.526 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 121187.765 ms (39 rows) COMMIT; COMMIT