refactor: 重构分区索引策略,移除显式创建索引的方法并更新相关流程

This commit is contained in:
2026-03-02 11:49:02 +08:00
parent e7658dd3bd
commit 1eccc2e3aa
7 changed files with 32 additions and 140 deletions

View File

@@ -0,0 +1,11 @@
# Proposal: Refactor Partition Indexes
## Goal
利用 PostgreSQL 默认的支持,改变每日分区创立时的索引策略,不再在代码中对每个分区单独创建索引。
## Context
当前 `PartitionManager` 在动态创建子分区后,会隐式调用查询在子分区上创建六个单列索引。由于我们使用的是 PostgreSQL 11+,且我们在初始化脚本中的主分区表 `onoffline.onoffline_record` 上已经创建了所有的索引,此主表上的索引会自动应用于所有的子分区,不需要我们在创建分区时另外手动添加。
## Proposed Changes
1.`src/db/partitionManager.js` 中移除子分区显式创建索引的方法 `ensurePartitionIndexes` 以及针对已有子分区的循环索引检查函数 `ensureIndexesForExistingPartitions`
2. 在更新分区流程 `ensurePartitions` 以及 `ensurePartitionsForTimestamps` 中,移除对 `ensurePartitionIndexes` 的调用。

View File

@@ -0,0 +1,11 @@
# Spec Delta: onoffline-backend
## MODIFIED Requirements
### Requirement: 数据库分区策略
系统 SHALL 使用 Range Partitioning 按天分区,并自动维护未来 30 天的分区表,子表依赖 PostgreSQL 原生机制继承主表索引。
#### Scenario: 分区预创建
- **GIVEN** 系统启动或每日凌晨
- **WHEN** 运行分区维护任务
- **THEN** 确保数据库中存在未来 30 天的分区表,无需对子表显式创建单列表索引

View File

@@ -0,0 +1,6 @@
# Tasks: Refactor Partition Indexes
- [x] refactor `src/db/partitionManager.js`: remove `ensurePartitionIndexes` and `ensureIndexesForExistingPartitions`.
- [x] refactor `src/db/partitionManager.js`: update `ensurePartitions` and `ensurePartitionsForTimestamps` to remove calls to `ensurePartitionIndexes`.
- [x] refactor `src/db/initializer.js` (and any other occurrences) to reflect the removal.
- [x] update openspec requirements to clarify that index propagation relies on PostgreSQL parent-table indexes.