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=10454329.83..10454332.58 rows=100 width=39) (actual time=131875.140..131875.424 rows=86 loops=1) Buffers: shared hit=2001236 read=451507 dirtied=40 written=35 -> GroupAggregate (cost=10454329.83..11290680.18 rows=30412740 width=39) (actual time=131875.135..131875.410 rows=86 loops=1) Buffers: shared hit=2001236 read=451507 dirtied=40 written=35 -> Sort (cost=10454329.83..10530361.68 rows=30412740 width=39) (actual time=131875.116..131875.146 rows=602 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 72kB Buffers: shared hit=2001236 read=451507 dirtied=40 written=35 -> Hash Join (cost=3089684.46..5842704.14 rows=30412740 width=39) (actual time=104230.097..131871.924 rows=602 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=2001222 read=451507 dirtied=40 written=35 -> Seq Scan on lineitem (cost=0.00..1688573.79 rows=60825479 width=8) (actual time=0.080..15241.453 rows=60045033 loops=1) Buffers: shared hit=998189 read=82130 dirtied=40 written=29 -> Hash (cost=2994622.61..2994622.61 rows=7604948 width=39) (actual time=104201.036..104201.036 rows=86 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 7kB Buffers: shared hit=1003033 read=369377 written=6 -> Hash Join (cost=2203097.16..2994622.61 rows=7604948 width=39) (actual time=92516.487..104200.394 rows=86 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1003033 read=369377 written=6 -> Hash Join (cost=2134069.16..2773495.65 rows=7604948 width=20) (actual time=90735.807..102416.599 rows=86 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=967756 read=369376 written=6 -> Seq Scan on orders (cost=0.00..408911.95 rows=15209895 width=16) (actual time=0.020..6092.580 rows=15015000 loops=1) Buffers: shared hit=222448 read=34365 -> Hash (cost=2083580.60..2083580.60 rows=4039085 width=4) (actual time=90616.185..90616.185 rows=86 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=745308 read=335011 written=6 -> HashAggregate (cost=1992701.19..2043189.75 rows=4039085 width=8) (actual time=81317.260..90614.832 rows=86 loops=1) Filter: (sum(public.lineitem.l_quantity) > 314::double precision) Rows Removed by Filter: 15014914 Buffers: shared hit=745308 read=335011 written=6 -> Seq Scan on lineitem (cost=0.00..1688573.79 rows=60825479 width=8) (actual time=0.029..24721.142 rows=60045033 loops=1) Buffers: shared hit=745308 read=335011 written=6 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1778.409..1778.409 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35277 read=1 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.017..902.120 rows=1500000 loops=1) Buffers: shared hit=35277 read=1 Total runtime: 132126.149 ms (39 rows) COMMIT; COMMIT