Skip to content

Revert "fix: add missing indexes for top CPU-consuming queries (#23147)"#23402

Merged
yuneng-jiang merged 1 commit intomainfrom
litellm_proxy_extras_mar11
Mar 12, 2026
Merged

Revert "fix: add missing indexes for top CPU-consuming queries (#23147)"#23402
yuneng-jiang merged 1 commit intomainfrom
litellm_proxy_extras_mar11

Conversation

@yuneng-jiang
Copy link
Collaborator

@yuneng-jiang yuneng-jiang commented Mar 12, 2026

This reverts commit 323b473.

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🚄 Infrastructure

Changes

This is incompatible with our current workflow for adjusting the schema
image

@vercel
Copy link

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Error Error Mar 12, 2026 0:44am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 12, 2026

Greptile Summary

This PR reverts commit 323b473835550676b42eb72a290d11590055ad1d (PR #23147), which added two database indexes intended to improve performance on CPU-intensive queries. The revert removes the migration file and strips the corresponding @@index declarations from all three copies of schema.prisma.

Key changes:

  • Deletes 20260309115809_add_missing_indexes/migration.sql, which used CONCURRENTLY to create LiteLLM_VerificationToken_key_alias_idx and LiteLLM_SpendLogs_user_startTime_idx.
  • Removes @@index([key_alias]) from the LiteLLM_VerificationToken model across all schema files.
  • Removes @@index([user, startTime]) from the LiteLLM_SpendLogs model across all schema files.

Critical concern: The PR deletes the forward migration file but provides no new migration to drop the indexes from databases that already applied the original migration. Prisma tracks applied migrations in the _prisma_migrations table; if the migration was already deployed, Prisma will detect a drift between the recorded migration history and the missing file, breaking future prisma migrate deploy runs. A proper database revert requires adding a new migration file that issues DROP INDEX CONCURRENTLY IF EXISTS for both indexes.

Additionally, no explanation is provided for why the indexes are being reverted, nor is there any evidence (tests, benchmark data) that the original fix was harmful.

Confidence Score: 2/5

  • Unsafe to merge without a companion migration that drops the indexes from already-migrated databases.
  • The revert is structurally incomplete: it removes the migration file and schema definitions, but omits a new migration to clean up the indexes on databases where the original migration was already applied. This will cause Prisma migration-history drift and break prisma migrate deploy for any deployment that ran PR fix: add missing indexes for top CPU-consuming queries #23147. The PR also lacks any rationale or tests, making it difficult to assess intent or confirm correctness.
  • The deleted litellm-proxy-extras/litellm_proxy_extras/migrations/20260309115809_add_missing_indexes/migration.sql is the root issue — a corresponding drop migration must be added to the migrations directory.

Important Files Changed

Filename Overview
litellm-proxy-extras/litellm_proxy_extras/migrations/20260309115809_add_missing_indexes/migration.sql Migration file deleted without a corresponding new migration to drop the indexes — leaves any database that already applied this migration in a schema-drift state.
litellm-proxy-extras/litellm_proxy_extras/schema.prisma Removes @@index([key_alias]) from LiteLLM_VerificationToken and @@index([user, startTime]) from LiteLLM_SpendLogs; schema change is consistent with the deleted migration file but no drop migration accompanies it.
litellm/proxy/schema.prisma Mirror of the schema.prisma change — removes the same two index definitions; no independent migration concern here as this file is not the migration source.
schema.prisma Root schema.prisma mirror — removes the same two index definitions; consistent with the other schema files.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Original PR #23147\nAdds migration file\n+ schema index definitions] --> B[Migration Applied?\nDB has indexes\n_prisma_migrations records it]
    A --> C[Migration NOT Applied\nDB has no indexes]

    B --> D[This Revert PR #23402\nDeletes migration file\nRemoves schema index definitions\nNO drop migration added]
    C --> D

    D --> E{Was migration\nalready applied?}
    E -- Yes --> F[❌ Schema Drift\nDB still has indexes\n_prisma_migrations still records it\nPrisma detects file-history mismatch]
    E -- No --> G[✅ Clean state\nIndexes never created\nSchema consistent]

    F --> H[Fix: Add new migration\nDROP INDEX CONCURRENTLY IF EXISTS\nLiteLLM_VerificationToken_key_alias_idx\nLiteLLM_SpendLogs_user_startTime_idx]
Loading

Last reviewed commit: 64ed29d

Comment on lines 553 to 558
@@index([startTime, request_id])
@@index([end_user])
@@index([session_id])

// SELECT ... FROM "LiteLLM_SpendLogs" WHERE ("startTime" >= $1 AND "startTime" <= $2 AND "user" = $3) GROUP BY ...
@@index([user, startTime])
}

// View spend, model, api_key per request
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing revert migration to drop indexes

This PR deletes the migration file 20260309115809_add_missing_indexes/migration.sql and removes the index definitions from the schema, but does not add a new migration to DROP those indexes from databases where the original migration was already applied.

For any deployment that ran the original migration, Prisma's _prisma_migrations table will still record 20260309115809_add_missing_indexes as applied, but the file is now gone. This creates an irrecoverable migration state drift: Prisma will detect that the applied migration history no longer matches the migration files on disk and will refuse to run prisma migrate deploy / prisma migrate status correctly.

A proper revert should include a new migration file, e.g. 20260312_revert_missing_indexes/migration.sql, containing:

-- SkipTransactionBlock

-- Drop index added by 20260309115809_add_missing_indexes
DROP INDEX CONCURRENTLY IF EXISTS "LiteLLM_VerificationToken_key_alias_idx";

-- Drop index added by 20260309115809_add_missing_indexes
DROP INDEX CONCURRENTLY IF EXISTS "LiteLLM_SpendLogs_user_startTime_idx";

Without this, any existing deployment is left in an inconsistent state. The same concern applies to litellm/proxy/schema.prisma and the root schema.prisma.

@yuneng-jiang yuneng-jiang merged commit d39355d into main Mar 12, 2026
60 of 97 checks passed
yuneng-jiang added a commit that referenced this pull request Mar 12, 2026
Revert "fix: add missing indexes for top CPU-consuming queries (#23147)"
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