feat(db): add performance indexes for 10x query latency improvement#1902
feat(db): add performance indexes for 10x query latency improvement#1902visnetodev wants to merge 1 commit intofarion1231:mainfrom
Conversation
- Add idx_provider_health_app on provider_health(app_type) - Add idx_provider_health_provider on provider_health(provider_id) - Add idx_providers_app_sort on providers(app_type, sort_index) - Add schema migration v6 -> v7 for existing databases Implements Section 3.2 of 10x-roadmap.md
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f52b41f66f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .map_err(|e| AppError::Database(format!("创建 provider_health app 索引失败: {e}")))?; | ||
|
|
||
| conn.execute( | ||
| "CREATE INDEX IF NOT EXISTS idx_provider_health_provider ON provider_health(provider_id)", |
There was a problem hiding this comment.
Remove duplicate provider_health provider_id index
provider_health already has PRIMARY KEY (provider_id, app_type), so SQLite maintains an index whose left-most key is provider_id; adding idx_provider_health_provider duplicates that access path and does not speed up any additional query patterns in this codebase (all provider_health lookups by provider also include app_type). This extra index adds write amplification and database bloat on every health upsert/delete, which is the hot path for proxy traffic.
Useful? React with 👍 / 👎.
Summary
Add database indexes to achieve 10x reduction in DB query latency as specified in
_docs/10x-roadmap.mdSection 3.2.Changes
idx_provider_health_apponprovider_health(app_type)idx_provider_health_provideronprovider_health(provider_id)idx_providers_app_sortonproviders(app_type, sort_index)Testing
All schema migration tests pass. The pre-existing
test_rollup_merges_with_existingtest failure is unrelated to this change.Related
Implements Section 3.2 of 10x-roadmap.md