feat: inline enum filters that match a partial index predicate (0.20.0) - #15
Merged
HosseinNejatiJavaremi merged 1 commit intoOct 14, 2026
Conversation
asyncpg runs every query as a server-side prepared statement, and after a few executions Postgres may switch it to a generic plan. A generic plan cannot prove a partial index's WHERE predicate from a bound parameter, so a filter like `status IN ($1)` stops using `... WHERE status = 'PENDING'` indexes and falls back to a broader index or a full scan, with no error and usually no sign of it on a small development database. Add the pattern to using-archipy-adapters.mdc: render closed-enum values that match a partial index predicate with `literal(..., literal_execute=True)`, keep index-key columns and user input bound, and confirm with a forced generic plan. The archipy-reviewer flags bound filters on predicate columns as Should fix and does not flag the inlined enum literals as unparameterized SQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
asyncpg runs every query as a server-side prepared statement, and after a few executions Postgres may switch it to a generic plan. A generic plan cannot prove a partial index's WHERE predicate from a bound parameter, so a filter like
status IN ($1)stops using... WHERE status = 'PENDING'indexes and falls back to a broader index or a full scan, with no error and usually no sign of it on a small development database.Add the pattern to using-archipy-adapters.mdc: render closed-enum values that match a partial index predicate with
literal(..., literal_execute=True), keep index-key columns and user input bound, and confirm with a forced generic plan. The archipy-reviewer flags bound filters on predicate columns as Should fix and does not flag the inlined enum literals as unparameterized SQL.Summary
Checklist
python3 scripts/check_catalog.pypassespython3 -m unittest discover -s tests -vpassesCHANGELOG.mdupdated for user-facing changesversion(when releasing)Test plan