fix(repository): make filters match their indexes#788
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the PostgreSQL repository query builder so output filters structurally match the schema’s expression/partial indexes (enabling index scans instead of sequential scans), and tightens the voucher-address filter to only apply to voucher-typed outputs.
Changes:
- Change
SubstrByteato emitsubstring(col FROM n FOR m)with inline literal offsets to match expression indexes. - Add
ByteaLiteraland use an inline-literal selectorINlist when filtering by voucher address, so the planner can prove the partial-index predicate. - Extend repository tests to ensure non-voucher outputs with “lookalike” payloads don’t match the voucher-address filter.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/repository/repotest/output_test_cases.go | Strengthens the voucher-address filter test by adding a non-voucher lookalike payload case. |
| internal/repository/postgres/util.go | Makes substring rendering index-compatible and introduces inline bytea literal rendering for partial-index predicate implication. |
| internal/repository/postgres/output.go | Restricts voucher-address filtering to voucher selectors and uses inline selector literals to enable partial index usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ea7cc3e to
af4a865
Compare
renatomaia
approved these changes
Jul 2, 2026
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.
The query builder emitted
SUBSTR(col, $1, $2)with bind parameterswhile the schema defines its expression indexes over
substring(col FROM n FOR m)with literal offsets. PostgreSQL matchesexpression indexes structurally (by function identity and argument
tree), so every filter routed through
SubstrByteabypassed the fourindexes written for it and fell back to sequential scans. Emit the
substringform with inline literal offsets instead.Also require the
Voucher/DelegateCallVoucherselector when filteringby voucher address: bytes 17..36 of other output types are arbitrary
payload, so the old filter could match notices, and the selector IN
list (inline literals) is what lets the planner prove the partial
predicate of
output_raw_data_address_idx, even under generic plans.Verified with
EXPLAINon PostgreSQL 17.10: both filters now produceindex scans; the voucher-address query uses the partial index with a
bound address parameter under force_generic_plan.