Skip to content

fix(repository): make filters match their indexes#788

Merged
vfusco merged 1 commit into
next/2.0from
fix/make-filters-match-index
Jul 2, 2026
Merged

fix(repository): make filters match their indexes#788
vfusco merged 1 commit into
next/2.0from
fix/make-filters-match-index

Conversation

@vfusco

@vfusco vfusco commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

The query builder emitted SUBSTR(col, $1, $2) with bind parameters
while the schema defines its expression indexes over
substring(col FROM n FOR m) with literal offsets. PostgreSQL matches
expression indexes structurally (by function identity and argument
tree), so every filter routed through SubstrBytea bypassed the four
indexes written for it and fell back to sequential scans. Emit the
substring form with inline literal offsets instead.

Also require the Voucher/DelegateCallVoucher selector when filtering
by 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 EXPLAIN on PostgreSQL 17.10: both filters now produce
index scans; the voucher-address query uses the partial index with a
bound address parameter under force_generic_plan.

@vfusco vfusco self-assigned this Jul 2, 2026
@vfusco vfusco added this to the 2.0.0 milestone Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 SubstrBytea to emit substring(col FROM n FOR m) with inline literal offsets to match expression indexes.
  • Add ByteaLiteral and use an inline-literal selector IN list 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.

Comment thread internal/repository/repotest/output_test_cases.go
Comment thread internal/repository/repotest/output_test_cases.go
@vfusco vfusco force-pushed the fix/make-filters-match-index branch from ea7cc3e to af4a865 Compare July 2, 2026 14:07
@github-project-automation github-project-automation Bot moved this from Todo to Waiting Merge in Rollups SDK Jul 2, 2026
@vfusco vfusco merged commit af4a865 into next/2.0 Jul 2, 2026
20 checks passed
@vfusco vfusco deleted the fix/make-filters-match-index branch July 2, 2026 15:22
@github-project-automation github-project-automation Bot moved this from Waiting Merge to Done in Rollups SDK Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants