Skip to content

docs: add DB query performance guidelines to CLAUDE.md#23196

Merged
RheagalFire merged 1 commit intoBerriAI:litellm_oss_staging_03_10_2026from
CAFxX:docs/claude-md-db-performance-guidelines
Mar 10, 2026
Merged

docs: add DB query performance guidelines to CLAUDE.md#23196
RheagalFire merged 1 commit intoBerriAI:litellm_oss_staging_03_10_2026from
CAFxX:docs/claude-md-db-performance-guidelines

Conversation

@CAFxX
Copy link
Contributor

@CAFxX CAFxX commented Mar 9, 2026

Summary

Test plan

  • N/A — documentation only

🤖 Generated with Claude Code

@vercel
Copy link

vercel bot commented Mar 9, 2026

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

Project Deployment Actions Updated (UTC)
litellm Error Error Mar 10, 2026 4:47am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 9, 2026

Greptile Summary

This documentation-only PR extends the CLAUDE.md "Proxy database access" section with 7 concrete database query performance guidelines, motivated by recurring production incidents (N+1 queries, full-table scans from distinct, missing indexes, deadlocks). The changes fit well with the existing Prisma-centric guidance already in the file.

Key additions:

  • N+1 prevention – batch-fetch with {"in": ids} instead of querying inside loops
  • Batch writes – prefer create_many/update_many/delete_many; correctly documents that these return counts only and that update_many/delete_many silently no-op on missing rows
  • Server-side work – prefer group_by over find_many(distinct=...) for server-side deduplication
  • Result-set bounding – paginate large results with cursor/take (preferred) or skip/take; correctly notes skip is O(n)
  • Column selection – use select on wide tables; correctly warns that it returns a partial object
  • Index guidance – prefer extending existing @@index unless it is a @@unique constraint
  • Schema sync – lists all four schema.prisma copies including litellm-js/spend-logs/ and directs migrations to litellm-proxy-extras/

One minor gap remains: create_many(skip_duplicates=True) silently ignores duplicate-key conflicts (analogous to the documented update_many/delete_many silent no-op), but this behavior is not called out in the batch-writes guideline.

Confidence Score: 4/5

  • Documentation-only change with no production code impact; safe to merge after addressing the minor create_many(skip_duplicates=True) caveat
  • Score of 4 reflects that this is a pure documentation PR with no runtime risk, and the guidelines are technically accurate. The only remaining gap is the undocumented silent-skip behavior of create_many(skip_duplicates=True), which is minor enough not to block the PR but worth fixing before merge to keep the guidance internally consistent.
  • No files require special attention — the single changed file (CLAUDE.md) is documentation only.

Important Files Changed

Filename Overview
CLAUDE.md Adds 7 database query performance guidelines to the "Proxy database access" section, covering N+1 queries, batch writes, server-side aggregation, result-set bounding, column selection, index coverage, and schema sync. Guidelines are largely accurate after multiple review rounds; one minor omission: create_many(skip_duplicates=True) silent-skip behavior is not documented alongside the analogous update_many/delete_many no-op caveat.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[New DB Operation] --> B{Multiple rows\nor loop?}
    B -->|Loop detected| C[Batch: find_many with 'in'\nor create_many/update_many/delete_many]
    B -->|Single op| D{Need aggregation\nor dedup?}
    C --> E{Return value\nneeded?}
    E -->|Yes| F[update / delete\nRaises RecordNotFoundError]
    E -->|No| G[update_many / delete_many\nSilently no-ops on missing rows]
    D -->|Yes| H[Push to DB: group_by,\naggregate in SQL\nNot find_many with distinct]
    D -->|No| I{Wide table?}
    I -->|Yes| J[Add select to limit columns\nNote: returns partial object]
    I -->|No| K{Large result set?}
    K -->|>~10 MB| L[Paginate with cursor+take\nor skip+take with explicit order]
    K -->|Small / bounded| M[find_many / find_unique directly]
    L --> N{Prefer cursor\npagination}
    N -->|cursor+take| O[Cursor must be unique field]
    N -->|skip+take| P[skip is O skip-value — avoid for large offsets]
Loading

Last reviewed commit: 9d2b011

@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from 676a4bd to cdeff82 Compare March 9, 2026 23:37
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from cdeff82 to 7963da5 Compare March 9, 2026 23:41
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from 7963da5 to 3496007 Compare March 10, 2026 00:06
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from 3496007 to 8eb8b8d Compare March 10, 2026 00:11
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from 4259acf to 217a647 Compare March 10, 2026 00:27
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from 217a647 to 5d5ee9d Compare March 10, 2026 00:29
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch 3 times, most recently from 1f7d184 to 648e8ec Compare March 10, 2026 00:36
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from 648e8ec to 12fd00f Compare March 10, 2026 00:46
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from 12fd00f to 1c117fd Compare March 10, 2026 00:54
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from 1c117fd to 1141b0b Compare March 10, 2026 01:00
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from 1141b0b to 4a7497b Compare March 10, 2026 01:06
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch 2 times, most recently from 30afe44 to b82c680 Compare March 10, 2026 03:00
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from fdedcb4 to 58a8531 Compare March 10, 2026 04:22
Extend the "Proxy database access" section with guidelines to prevent
common DB performance issues, tailored to actual Prisma usage patterns
in the litellm codebase: N+1 queries, client-side processing, batching
writes, bounding result sets, select on wide tables, index coverage,
and schema file sync.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CAFxX CAFxX force-pushed the docs/claude-md-db-performance-guidelines branch from 58a8531 to 9d2b011 Compare March 10, 2026 04:45
@RheagalFire RheagalFire changed the base branch from main to litellm_oss_staging_03_10_2026 March 10, 2026 13:37
@RheagalFire RheagalFire merged commit 2b093aa into BerriAI:litellm_oss_staging_03_10_2026 Mar 10, 2026
27 of 38 checks passed
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