Skip to content

feat(db): add performance indexes for 10x query latency improvement#1902

Open
visnetodev wants to merge 1 commit intofarion1231:mainfrom
visnetodev:feat/add-database-indexes
Open

feat(db): add performance indexes for 10x query latency improvement#1902
visnetodev wants to merge 1 commit intofarion1231:mainfrom
visnetodev:feat/add-database-indexes

Conversation

@visnetodev
Copy link
Copy Markdown

Summary

Add database indexes to achieve 10x reduction in DB query latency as specified in _docs/10x-roadmap.md Section 3.2.

Changes

  • 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

Testing

All schema migration tests pass. The pre-existing test_rollup_merges_with_existing test failure is unrelated to this change.

Related

Implements Section 3.2 of 10x-roadmap.md

- 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
@farion1231
Copy link
Copy Markdown
Owner

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

2 participants