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) > 313 ) 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=10414434.91..10414437.66 rows=100 width=39) (actual time=129734.295..129734.851 rows=100 loops=1) Buffers: shared hit=1170494 read=1272691 dirtied=10 -> GroupAggregate (cost=10414434.91..11247469.23 rows=30292157 width=39) (actual time=129734.292..129734.829 rows=100 loops=1) Buffers: shared hit=1170494 read=1272691 dirtied=10 -> Sort (cost=10414434.91..10490165.30 rows=30292157 width=39) (actual time=129734.261..129734.360 rows=700 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 79kB Buffers: shared hit=1170494 read=1272691 dirtied=10 -> Hash Join (cost=3079847.04..5821961.69 rows=30292157 width=39) (actual time=92009.056..129729.211 rows=700 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1170480 read=1272691 dirtied=10 -> Seq Scan on lineitem (cost=0.00..1681889.14 rows=60584314 width=8) (actual time=0.028..22501.025 rows=60044176 loops=1) Buffers: shared hit=358197 read=717849 -> Hash (cost=2985159.79..2985159.79 rows=7574980 width=39) (actual time=91773.023..91773.023 rows=100 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 8kB Buffers: shared hit=812283 read=554842 dirtied=10 -> Hash Join (cost=2196285.91..2985159.79 rows=7574980 width=39) (actual time=80712.972..91772.470 rows=100 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=812283 read=554842 dirtied=10 -> Hash Join (cost=2127257.91..2764632.19 rows=7574980 width=20) (actual time=79095.844..90151.789 rows=100 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=777005 read=554842 dirtied=10 -> Seq Scan on orders (cost=0.00..407300.59 rows=15149959 width=16) (actual time=0.014..6022.764 rows=15015000 loops=1) Buffers: shared hit=191182 read=64619 -> Hash (cost=2076383.91..2076383.91 rows=4069920 width=4) (actual time=78953.061..78953.061 rows=100 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=585823 read=490223 dirtied=10 -> HashAggregate (cost=1984810.71..2035684.71 rows=4069920 width=8) (actual time=70493.786..78952.354 rows=100 loops=1) Filter: (sum(public.lineitem.l_quantity) > 313::double precision) Rows Removed by Filter: 15014900 Buffers: shared hit=585823 read=490223 dirtied=10 -> Seq Scan on lineitem (cost=0.00..1681889.14 rows=60584314 width=8) (actual time=0.045..22643.108 rows=60044176 loops=1) Buffers: shared hit=585823 read=490223 dirtied=10 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1615.412..1615.412 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.012..848.053 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 129989.475 ms (39 rows) COMMIT; COMMIT