Skip to content

perf(db): drop redundant single-column indexes#2893

Open
ZeroClover wants to merge 1 commit into
Wei-Shaw:mainfrom
ZeroClover:chore/drop-redundant-db-indexes
Open

perf(db): drop redundant single-column indexes#2893
ZeroClover wants to merge 1 commit into
Wei-Shaw:mainfrom
ZeroClover:chore/drop-redundant-db-indexes

Conversation

@ZeroClover
Copy link
Copy Markdown
Contributor

云数据库巡检标记的 13 个单列索引,其列均为既有复合/唯一索引的最左前缀,
PostgreSQL 可用更宽的索引服务相同查询,单列索引纯属冗余,只增加写放大与存储。

  • 新增迁移 143_drop_redundant_indexes_notx.sql:以 DROP INDEX CONCURRENTLY IF EXISTS 删除全部 13 个索引(usage_logs×6、两张 dashboard 去重表、 payment_audit_logs、channel_monitors、auth_identities、 auth_identity_migration_reports、user_provider_default_grants), 非事务幂等执行,避免在高写入的 usage_logs 上持有排他锁。
  • 同步移除 ent schema 中对应的 9 个单列索引声明并重新生成 ent 代码; 保留 usage_logs.group_id(线上为 group_id IS NOT NULL 的部分复合索引, 无法覆盖 NULL,未被标记为冗余)。
  • 修正迁移校验器以首关键字判定 CREATE/DROP,避免名称含 "created" 的 索引(如 idx_usage_logs_created_at)被误判为 CREATE 而要求 IF NOT EXISTS; 补充对应回归用例。

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@ZeroClover
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 29, 2026
云数据库巡检标记的 13 个单列索引,其列均为既有复合/唯一索引的最左前缀,
PostgreSQL 可用更宽的索引服务相同查询,单列索引纯属冗余,只增加写放大与存储。

- 新增迁移 143_drop_redundant_indexes_notx.sql:以 DROP INDEX CONCURRENTLY
  IF EXISTS 删除全部 13 个索引(usage_logs×6、两张 dashboard 去重表、
  payment_audit_logs、channel_monitors、auth_identities、
  auth_identity_migration_reports、user_provider_default_grants),
  非事务幂等执行,避免在高写入的 usage_logs 上持有排他锁。
- 同步移除 ent schema 中对应的 9 个单列索引声明并重新生成 ent 代码;
  保留 usage_logs.group_id(线上为 group_id IS NOT NULL 的部分复合索引,
  无法覆盖 NULL,未被标记为冗余)。
- 修正迁移校验器以首关键字判定 CREATE/DROP,避免名称含 "created" 的
  索引(如 idx_usage_logs_created_at)被误判为 CREATE 而要求 IF NOT EXISTS;
  补充对应回归用例。
@ZeroClover ZeroClover force-pushed the chore/drop-redundant-db-indexes branch from 043fdb2 to 0e73692 Compare May 29, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant