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=10351445.77..10351448.52 rows=100 width=39) (actual time=153157.183..153157.713 rows=84 loops=1) Buffers: shared hit=1240327 read=1188578 dirtied=1 -> GroupAggregate (cost=10351445.77..11179541.47 rows=30112571 width=39) (actual time=153157.180..153157.688 rows=84 loops=1) Buffers: shared hit=1240327 read=1188578 dirtied=1 -> Sort (cost=10351445.77..10426727.19 rows=30112571 width=39) (actual time=153157.148..153157.233 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=1240327 read=1188578 dirtied=1 -> Hash Join (cost=3061632.98..5787490.39 rows=30112571 width=39) (actual time=112091.041..153152.852 rows=588 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1240313 read=1188578 dirtied=1 -> Seq Scan on lineitem (cost=0.00..1671917.42 rows=60225142 width=8) (actual time=0.036..25626.562 rows=60045303 loops=1) Buffers: shared hit=359568 read=710098 -> Hash (cost=2967508.38..2967508.38 rows=7529968 width=39) (actual time=111495.980..111495.980 rows=84 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=880745 read=478480 dirtied=1 -> Hash Join (cost=2183399.83..2967508.38 rows=7529968 width=39) (actual time=99752.299..111495.483 rows=84 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=880745 read=478480 dirtied=1 -> Hash Join (cost=2114371.83..2747881.02 rows=7529968 width=20) (actual time=97696.343..109434.079 rows=84 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=845495 read=478452 dirtied=1 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.017..5944.627 rows=15015000 loops=1) Buffers: shared hit=247985 read=6296 dirtied=1 -> Hash (cost=2063897.30..2063897.30 rows=4037963 width=4) (actual time=97479.593..97479.593 rows=84 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=597510 read=472156 -> HashAggregate (cost=1973043.13..2023517.67 rows=4037963 width=8) (actual time=87725.792..97478.343 rows=84 loops=1) Filter: (sum(public.lineitem.l_quantity) > 314::double precision) Rows Removed by Filter: 15014916 Buffers: shared hit=597510 read=472156 -> Seq Scan on lineitem (cost=0.00..1671917.42 rows=60225142 width=8) (actual time=0.032..33176.675 rows=60045303 loops=1) Buffers: shared hit=597510 read=472156 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=2051.521..2051.521 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35250 read=28 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.015..1154.631 rows=1500000 loops=1) Buffers: shared hit=35250 read=28 Total runtime: 153452.083 ms (39 rows) COMMIT; COMMIT