fix: add missing indexes for top CPU-consuming queries#23147
Merged
RheagalFire merged 2 commits intoBerriAI:litellm_oss_staging_03_10_2026from Mar 10, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Add indexes to eliminate full table scans on two of the top 5 queries by CPU usage: 1. LiteLLM_VerificationToken(key_alias) — for ORDER BY key_alias ASC queries when listing verification tokens 2. LiteLLM_SpendLogs(user, startTime) — for WHERE user = $1 AND startTime BETWEEN $2 AND $3 GROUP BY queries on the spend logs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9f8551c to
a0ec08f
Compare
Contributor
Greptile SummaryThis PR adds two database indexes to optimize CPU-consuming queries:
The migration correctly uses Confidence Score: 5/5
Last reviewed commit: 069ade2 |
1 task
RheagalFire
requested changes
Mar 10, 2026
...roxy-extras/litellm_proxy_extras/migrations/20260309115809_add_missing_indexes/migration.sql
Outdated
Show resolved
Hide resolved
e9d699b to
e220621
Compare
Both indexes are now created with CONCURRENTLY and IF NOT EXISTS to avoid blocking writes on large production tables. Uses -- SkipTransactionBlock for Prisma migrate compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e220621 to
069ade2
Compare
RheagalFire
approved these changes
Mar 10, 2026
323b473
into
BerriAI:litellm_oss_staging_03_10_2026
32 of 38 checks passed
yuneng-jiang
added a commit
that referenced
this pull request
Mar 12, 2026
This reverts commit 323b473.
7 tasks
yuneng-jiang
added a commit
that referenced
this pull request
Mar 12, 2026
Revert "fix: add missing indexes for top CPU-consuming queries (#23147)"
yuneng-jiang
added a commit
that referenced
this pull request
Mar 12, 2026
Revert "fix: add missing indexes for top CPU-consuming queries (#23147)"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LiteLLM_VerificationToken(key_alias): The virtual keys listing query filters onteam_idand sorts bykey_alias ASC. Theteam_idindex exists but there's no index to support theORDER BY, forcing a sort on every request.LiteLLM_SpendLogs(user, startTime): The spend summary query filters onuser = $1 AND startTime BETWEEN $2 AND $3and groups by multiple columns. There's astartTimeindex but no composite index withuseras the leading column, so Postgres can't efficiently seek to the right user's rows.Test plan
\diin psql🤖 Generated with Claude Code