Pager usage is off. Output format is unaligned. [環境] PostgreSQL 19.0 on aarch64-apple-darwin27.2.0, compiled by Apple clang version 21.0.0 (clang-2100.3.34.2), 64-bit block_size|8192| cpu_operator_cost|0.0025| cpu_tuple_cost|0.01| effective_cache_size|524288|8kB hash_mem_multiplier|2| io_method|worker| max_repack_replication_slots|5| random_page_cost|4| seq_page_cost|1| shared_buffers|16384|8kB wal_level|replica| work_mem|4096|kB CREATE SCHEMA SET SET SET SET CREATE TABLE INSERT 0 100000 CREATE INDEX VACUUM [1a コスト] 1640|100000 Seq Scan on events (cost=0.00..2640.00 rows=100000 width=103) Seq Scan on events (cost=0.00..3140.00 rows=33333 width=103) Filter: (length(note) > 0) [1b loops] Nested Loop (cost=0.42..1.58 rows=6 width=12) (actual time=0.015..0.025 rows=6.00 loops=1) Buffers: shared hit=5 read=5 -> Values Scan on "*VALUES*" (cost=0.00..0.04 rows=3 width=4) (actual time=0.000..0.001 rows=3.00 loops=1) -> Limit (cost=0.42..0.49 rows=2 width=8) (actual time=0.007..0.007 rows=2.00 loops=3) Buffers: shared hit=5 read=5 -> Index Only Scan using events_tenant_time on events (cost=0.42..37.74 rows=990 width=8) (actual time=0.007..0.007 rows=2.00 loops=3) Index Cond: (tenant_id = "*VALUES*".column1) Heap Fetches: 0 Index Searches: 3 Buffers: shared hit=5 read=5 Settings: search_path = 'explain_lab, pg_catalog', max_parallel_workers_per_gather = '0' Planning: Buffers: shared hit=12 read=1 Planning Time: 0.058 ms Execution Time: 0.046 ms [2a 更新前] Limit (cost=0.42..1.17 rows=20 width=8) (actual time=0.002..0.003 rows=20.00 loops=1) Buffers: shared hit=4 -> Index Only Scan using events_tenant_time on events (cost=0.42..15.42 rows=400 width=8) (actual time=0.002..0.003 rows=20.00 loops=1) Index Cond: (tenant_id = 2) Heap Fetches: 0 Index Searches: 1 Buffers: shared hit=4 Planning Time: 0.011 ms Execution Time: 0.006 ms UPDATE 400 [2b 更新直後] Limit (cost=0.42..1.17 rows=20 width=8) (actual time=0.009..0.032 rows=20.00 loops=1) Buffers: shared hit=50 -> Index Only Scan using events_tenant_time on events (cost=0.42..15.42 rows=400 width=8) (actual time=0.009..0.032 rows=20.00 loops=1) Index Cond: (tenant_id = 2) Heap Fetches: 35 Index Searches: 1 Buffers: shared hit=50 Planning Time: 0.009 ms Execution Time: 0.036 ms VACUUM [2c VACUUM後] Limit (cost=0.42..1.17 rows=20 width=8) (actual time=0.007..0.008 rows=20.00 loops=1) Buffers: shared hit=4 -> Index Only Scan using events_tenant_time on events (cost=0.42..15.42 rows=400 width=8) (actual time=0.006..0.007 rows=20.00 loops=1) Index Cond: (tenant_id = 2) Heap Fetches: 0 Index Searches: 1 Buffers: shared hit=4 Planning: Buffers: shared hit=9 Planning Time: 0.056 ms Execution Time: 0.016 ms [3a 単列統計] f|open|40000 t|closed|59900 t|open|100 Index Only Scan using events_tenant_time on events (cost=0.42..2400.42 rows=24060 width=8) (actual time=0.016..2.344 rows=100.00 loops=1) Index Cond: (tenant_id = 1) Filter: (status = 'open'::text) Rows Removed by Filter: 59900 Heap Fetches: 0 Index Searches: 1 Buffers: shared hit=65 read=234 Planning Time: 0.032 ms Execution Time: 2.352 ms CREATE STATISTICS ANALYZE [3b 複数列統計] Index Only Scan using events_tenant_time on events (cost=0.42..2400.42 rows=100 width=8) (actual time=0.010..1.900 rows=100.00 loops=1) Index Cond: (tenant_id = 1) Filter: (status = 'open'::text) Rows Removed by Filter: 59900 Heap Fetches: 0 Index Searches: 1 Buffers: shared hit=299 Planning: Buffers: shared hit=22 Planning Time: 0.067 ms Execution Time: 1.919 ms [4 配置と順序] created_at|-1|0.996 tenant_id|101|0.361 Limit (cost=0.42..1.17 rows=20 width=8) (actual time=0.003..0.005 rows=20.00 loops=1) Buffers: shared hit=4 -> Index Only Scan using events_tenant_time on events (cost=0.42..15.42 rows=400 width=8) (actual time=0.003..0.003 rows=20.00 loops=1) Index Cond: (tenant_id = 2) Heap Fetches: 0 Index Searches: 1 Buffers: shared hit=4 Planning Time: 0.013 ms Execution Time: 0.007 ms [5 Skip Scan] SELECT 90000 CREATE INDEX VACUUM Index Only Scan using delivery_channel_ticket on delivery (cost=0.29..17.23 rows=3 width=4) (actual time=0.026..0.035 rows=3.00 loops=1) Index Cond: (ticket_no = 1234) Heap Fetches: 0 Index Searches: 5 Buffers: shared hit=8 read=6 Planning: Buffers: shared hit=12 Planning Time: 0.048 ms Execution Time: 0.042 ms [6 結合と集約] SELECT 101 ALTER TABLE ANALYZE Finalize GroupAggregate (cost=3399.74..3403.28 rows=101 width=12) (actual time=16.202..16.223 rows=101.00 loops=1) Group Key: t.id Buffers: shared hit=1641 -> Merge Join (cost=3399.74..3401.76 rows=101 width=12) (actual time=16.199..16.213 rows=101.00 loops=1) Merge Cond: (t.id = e.tenant_id) Buffers: shared hit=1641 -> Sort (cost=5.37..5.62 rows=101 width=4) (actual time=0.009..0.012 rows=101.00 loops=1) Sort Key: t.id Sort Method: quicksort Memory: 25kB Buffers: shared hit=1 -> Seq Scan on tenants t (cost=0.00..2.01 rows=101 width=4) (actual time=0.002..0.004 rows=101.00 loops=1) Buffers: shared hit=1 -> Sort (cost=3394.37..3394.62 rows=101 width=12) (actual time=16.188..16.189 rows=101.00 loops=1) Sort Key: e.tenant_id Sort Method: quicksort Memory: 28kB Buffers: shared hit=1640 -> Partial HashAggregate (cost=3390.00..3391.01 rows=101 width=12) (actual time=16.173..16.177 rows=101.00 loops=1) Group Key: e.tenant_id Batches: 1 Memory Usage: 32kB Buffers: shared hit=1640 -> Seq Scan on events e (cost=0.00..2640.00 rows=100000 width=84) (actual time=0.002..2.269 rows=100000.00 loops=1) Buffers: shared hit=1640 Planning: Buffers: shared hit=30 read=3 Planning Time: 0.110 ms Execution Time: 16.243 ms [7 並列集約・実験用にコストを変更] BEGIN SET SET SET SET Finalize Aggregate (cost=2265.02..2265.03 rows=1 width=8) (actual time=6.283..6.868 rows=1.00 loops=1) Output: sum(length(note)) Buffers: shared hit=1640 -> Gather (cost=2265.00..2265.01 rows=2 width=8) (actual time=6.233..6.865 rows=3.00 loops=1) Output: (PARTIAL sum(length(note))) Workers Planned: 2 Workers Launched: 2 Buffers: shared hit=1640 -> Partial Aggregate (cost=2265.00..2265.01 rows=1 width=8) (actual time=4.653..4.654 rows=1.00 loops=3) Output: PARTIAL sum(length(note)) Buffers: shared hit=1640 Worker 0: actual time=3.854..3.854 rows=1.00 loops=1 Buffers: shared hit=432 Worker 1: actual time=3.984..3.984 rows=1.00 loops=1 Buffers: shared hit=448 -> Parallel Seq Scan on explain_lab.events (cost=0.00..2056.67 rows=41667 width=80) (actual time=0.002..1.066 rows=33333.33 loops=3) Output: id, tenant_id, created_at, status, note Buffers: shared hit=1640 Worker 0: actual time=0.002..1.011 rows=26254.00 loops=1 Buffers: shared hit=432 Worker 1: actual time=0.002..1.045 rows=27242.00 loops=1 Buffers: shared hit=448 Planning Time: 0.032 ms Execution Time: 6.880 ms COMMIT [8 HASH分割] CREATE TABLE DO INSERT 0 100000 ANALYZE 2|event_p2|400 3|event_p1|400 4|event_p3|400 Aggregate (cost=258.00..258.01 rows=1 width=8) (actual time=0.494..0.494 rows=1.00 loops=1) Buffers: shared hit=62 -> Append (cost=0.00..255.00 rows=1200 width=0) (actual time=0.002..0.470 rows=1200.00 loops=1) Buffers: shared hit=62 -> Seq Scan on event_p1 event_parts_1 (cost=0.00..124.50 rows=400 width=0) (actual time=0.002..0.209 rows=400.00 loops=1) Filter: (tenant_id = ANY ('{2,3,4}'::integer[])) Rows Removed by Filter: 6400 Buffers: shared hit=31 -> Seq Scan on event_p2 event_parts_2 (cost=0.00..80.50 rows=400 width=0) (actual time=0.001..0.135 rows=400.00 loops=1) Filter: (tenant_id = ANY ('{2,3,4}'::integer[])) Rows Removed by Filter: 4000 Buffers: shared hit=20 -> Seq Scan on event_p3 event_parts_3 (cost=0.00..44.00 rows=400 width=0) (actual time=0.001..0.086 rows=400.00 loops=1) Filter: (tenant_id = ANY ('{2,3,4}'::integer[])) Rows Removed by Filter: 2000 Buffers: shared hit=11 Planning Time: 0.081 ms Execution Time: 0.503 ms BEGIN SET PREPARE Aggregate (cost=1971.88..1971.89 rows=1 width=8) (actual time=0.938..0.939 rows=1.00 loops=1) Buffers: shared hit=62 -> Append (cost=0.00..1921.59 rows=20118 width=0) (actual time=0.002..0.915 rows=1200.00 loops=1) Buffers: shared hit=62 Subplans Removed: 5 -> Seq Scan on event_p1 event_parts_1 (cost=0.00..124.50 rows=1200 width=0) (actual time=0.002..0.426 rows=400.00 loops=1) Filter: (tenant_id = ANY (ARRAY[$1, $2, $3])) Rows Removed by Filter: 6400 Buffers: shared hit=31 -> Seq Scan on event_p2 event_parts_2 (cost=0.00..80.50 rows=1200 width=0) (actual time=0.001..0.274 rows=400.00 loops=1) Filter: (tenant_id = ANY (ARRAY[$1, $2, $3])) Rows Removed by Filter: 4000 Buffers: shared hit=20 -> Seq Scan on event_p3 event_parts_3 (cost=0.00..44.00 rows=1200 width=0) (actual time=0.002..0.177 rows=400.00 loops=1) Filter: (tenant_id = ANY (ARRAY[$1, $2, $3])) Rows Removed by Filter: 2000 Buffers: shared hit=11 Planning: Buffers: shared hit=50 Planning Time: 0.156 ms Execution Time: 0.945 ms PREPARE Aggregate (cost=3065.47..3065.48 rows=1 width=8) (actual time=4.136..4.136 rows=1.00 loops=1) Buffers: shared hit=825 dirtied=5 written=5 -> Append (cost=0.00..2942.32 rows=49263 width=0) (actual time=2.554..4.114 rows=1200.00 loops=1) Buffers: shared hit=825 dirtied=5 written=5 -> Seq Scan on event_p0 event_parts_1 (cost=0.00..1788.00 rows=30186 width=0) (actual time=2.552..2.552 rows=0.00 loops=1) Filter: (tenant_id = ANY ($1)) Rows Removed by Filter: 66400 Buffers: shared hit=587 dirtied=1 written=1 -> Seq Scan on event_p1 event_parts_2 (cost=0.00..184.00 rows=3091 width=0) (actual time=0.002..0.190 rows=400.00 loops=1) Filter: (tenant_id = ANY ($1)) Rows Removed by Filter: 6400 Buffers: shared hit=31 -> Seq Scan on event_p2 event_parts_3 (cost=0.00..119.00 rows=2704 width=0) (actual time=0.001..0.134 rows=400.00 loops=1) Filter: (tenant_id = ANY ($1)) Rows Removed by Filter: 4000 Buffers: shared hit=20 -> Seq Scan on event_p3 event_parts_4 (cost=0.00..65.00 rows=2012 width=0) (actual time=0.001..0.078 rows=400.00 loops=1) Filter: (tenant_id = ANY ($1)) Rows Removed by Filter: 2000 Buffers: shared hit=11 -> Seq Scan on event_p4 event_parts_5 (cost=0.00..119.00 rows=2704 width=0) (actual time=0.271..0.271 rows=0.00 loops=1) Filter: (tenant_id = ANY ($1)) Rows Removed by Filter: 4400 Buffers: shared hit=39 dirtied=1 written=1 -> Seq Scan on event_p5 event_parts_6 (cost=0.00..151.00 rows=2931 width=0) (actual time=0.294..0.294 rows=0.00 loops=1) Filter: (tenant_id = ANY ($1)) Rows Removed by Filter: 5600 Buffers: shared hit=49 dirtied=1 written=1 -> Seq Scan on event_p6 event_parts_7 (cost=0.00..151.00 rows=2931 width=0) (actual time=0.311..0.311 rows=0.00 loops=1) Filter: (tenant_id = ANY ($1)) Rows Removed by Filter: 5600 Buffers: shared hit=49 dirtied=1 written=1 -> Seq Scan on event_p7 event_parts_8 (cost=0.00..119.00 rows=2704 width=0) (actual time=0.245..0.245 rows=0.00 loops=1) Filter: (tenant_id = ANY ($1)) Rows Removed by Filter: 4400 Buffers: shared hit=39 dirtied=1 written=1 Planning Time: 0.025 ms Execution Time: 4.143 ms DEALLOCATE DEALLOCATE COMMIT [9 大小のテナント] PREPARE BEGIN SET Aggregate (cost=946.83..946.84 rows=1 width=8) (actual time=0.221..0.221 rows=1.00 loops=1) Buffers: shared hit=407 -> Bitmap Heap Scan on events (cost=11.52..944.83 rows=400 width=80) (actual time=0.063..0.207 rows=400.00 loops=1) Recheck Cond: (tenant_id = 2) Heap Blocks: exact=400 Buffers: shared hit=407 -> Bitmap Index Scan on events_tenant_time (cost=0.00..11.42 rows=400 width=0) (actual time=0.040..0.040 rows=400.00 loops=1) Index Cond: (tenant_id = 2) Index Searches: 1 Buffers: shared hit=7 Planning Time: 0.030 ms Execution Time: 0.226 ms Aggregate (cost=3190.00..3190.01 rows=1 width=8) (actual time=8.662..8.662 rows=1.00 loops=1) Buffers: shared hit=1640 -> Seq Scan on events (cost=0.00..2890.00 rows=60000 width=80) (actual time=0.002..2.930 rows=60000.00 loops=1) Filter: (tenant_id = 1) Rows Removed by Filter: 40000 Buffers: shared hit=1640 Planning Time: 0.019 ms Execution Time: 8.666 ms SET Aggregate (cost=1534.25..1534.26 rows=1 width=8) (actual time=0.120..0.120 rows=1.00 loops=1) Buffers: shared hit=407 -> Bitmap Heap Scan on events (cost=28.09..1529.30 rows=990 width=80) (actual time=0.032..0.107 rows=400.00 loops=1) Recheck Cond: (tenant_id = $1) Heap Blocks: exact=400 Buffers: shared hit=407 -> Bitmap Index Scan on events_tenant_time (cost=0.00..27.84 rows=990 width=0) (actual time=0.016..0.016 rows=400.00 loops=1) Index Cond: (tenant_id = $1) Index Searches: 1 Buffers: shared hit=7 Planning Time: 0.026 ms Execution Time: 0.125 ms Aggregate (cost=1534.25..1534.26 rows=1 width=8) (actual time=9.117..9.117 rows=1.00 loops=1) Buffers: shared hit=1938 -> Bitmap Heap Scan on events (cost=28.09..1529.30 rows=990 width=80) (actual time=0.877..3.726 rows=60000.00 loops=1) Recheck Cond: (tenant_id = $1) Heap Blocks: exact=1640 Buffers: shared hit=1938 -> Bitmap Index Scan on events_tenant_time (cost=0.00..27.84 rows=990 width=0) (actual time=0.789..0.789 rows=60000.00 loops=1) Index Cond: (tenant_id = $1) Index Searches: 1 Buffers: shared hit=298 Planning Time: 0.001 ms Execution Time: 9.121 ms total_chars|2|2 COMMIT DEALLOCATE [10 ソートの作業領域] BEGIN SET Sort (cost=25308.82..25558.82 rows=100000 width=84) (actual time=65.363..69.922 rows=100000.00 loops=1) Sort Key: note, id Sort Method: external merge Disk: 9320kB Buffers: shared hit=1640, temp read=4643 written=4895 -> Seq Scan on events (cost=0.00..2640.00 rows=100000 width=84) (actual time=0.002..3.861 rows=100000.00 loops=1) Prefetch: avg=1.00 max=1 capacity=94 Buffers: shared hit=1640 Planning: Memory: used=18kB allocated=24kB Planning Time: 0.013 ms Execution Time: 72.997 ms SET Sort (cost=10944.82..11194.82 rows=100000 width=84) (actual time=63.648..65.319 rows=100000.00 loops=1) Sort Key: note, id Sort Method: quicksort Memory: 13201kB Buffers: shared hit=1640 -> Seq Scan on events (cost=0.00..2640.00 rows=100000 width=84) (actual time=0.004..3.673 rows=100000.00 loops=1) Prefetch: avg=1.00 max=1 capacity=94 Buffers: shared hit=1640 Planning: Memory: used=18kB allocated=24kB Planning Time: 0.028 ms Execution Time: 66.887 ms COMMIT [11 観測の入口] t|active|| [12 再編成] CREATE TABLE INSERT 0 20000 DELETE 16000 VACUUM 4000|4825088 REPACK 4000|1048576 [13a 最新の未処理イベント] Limit (cost=0.42..480.42 rows=20 width=8) (actual time=0.019..0.960 rows=20.00 loops=1) Buffers: shared hit=60 -> Index Only Scan using events_tenant_time on events (cost=0.42..2400.42 rows=100 width=8) (actual time=0.017..0.956 rows=20.00 loops=1) Index Cond: (tenant_id = 1) Filter: (status = 'open'::text) Rows Removed by Filter: 11381 Heap Fetches: 0 Index Searches: 1 Buffers: shared hit=60 Planning Time: 0.088 ms Execution Time: 0.971 ms SELECT 20 CREATE INDEX [13b 部分インデックス作成後] Limit (cost=0.29..158.90 rows=20 width=8) (actual time=0.073..0.075 rows=20.00 loops=1) Buffers: shared hit=1 read=2 -> Index Only Scan using events_open_recent on events (cost=0.29..793.34 rows=100 width=8) (actual time=0.072..0.073 rows=20.00 loops=1) Index Cond: (tenant_id = 1) Heap Fetches: 0 Index Searches: 1 Buffers: shared hit=1 read=2 Planning: Buffers: shared hit=20 read=1 Planning Time: 0.326 ms Execution Time: 0.087 ms t ALTER TABLE ALTER TABLE