fix(indexer): drop redundant lower() on already-lowercase address columns (GitLab #165) #375

Closed
Brouie wants to merge 347 commits from fix/gitlab-165-referral-lower-predicates into main
Brouie commented 2026-05-06 02:17:23 +00:00 (Migrated from gitlab.com)

closes #165 — audit L-02 follow-up.

change

drop the lower() wrappers on 6 referral / kumbaya address predicates in indexer/src/api.rs. all addresses on both sides of the equation are stored / bound lowercase, so the wrap was wasted CPU and disabled the existing idx_timecurve_referral_applied_referrer btree.

affected

  • indexer/src/api.rs:422 — JOIN predicate in /v1/timecurve/buys LATERAL (kk.buyer and b.buyer both via addr_hex)
  • indexer/src/api.rs:1814 — /v1/referrals/applied (param addr_l is addr.to_lowercase() at line 1807)
  • indexer/src/api.rs:1971,1974,1977,1980 — 4 subqueries in /v1/referrals/wallet-charm-summary (param w is q.wallet.to_lowercase() at line 1965)

why this is safe

semantic-equivalent. both sides of every changed predicate are guaranteed lowercase by:

  • inserts: addr_hex(*addr) = format!("{:#x}", a) (alloy lowercase hex)
  • query bind: addr.to_lowercase() or bind_addr_lower()

grep -n 'lower(.*) = lower(' indexer/src/api.rs → 0 hits after this MR.

tests

cargo clippy --all-targets -- -D warnings  # clean
cargo test                                  # 40 unit + 0 doc + 2 integration = 42/42 PASS

no test diffs (predicate-equivalent change).

not in scope (flagged for triage in #165)

optional follow-up: CREATE INDEX idx_timecurve_referral_applied_buyer ON idx_timecurve_referral_applied (buyer) to mirror the existing referrer index — the referee_charm_wad and referee_buy_count subqueries scan without an index. left out of this MR to keep scope tight; happy to ship as a separate migration if you want it.

closes #165 — audit L-02 follow-up. ## change drop the `lower()` wrappers on 6 referral / kumbaya address predicates in `indexer/src/api.rs`. all addresses on both sides of the equation are stored / bound lowercase, so the wrap was wasted CPU and disabled the existing `idx_timecurve_referral_applied_referrer` btree. ## affected - `indexer/src/api.rs:422` — JOIN predicate in `/v1/timecurve/buys` LATERAL (`kk.buyer` and `b.buyer` both via `addr_hex`) - `indexer/src/api.rs:1814` — `/v1/referrals/applied` (param `addr_l` is `addr.to_lowercase()` at line 1807) - `indexer/src/api.rs:1971,1974,1977,1980` — 4 subqueries in `/v1/referrals/wallet-charm-summary` (param `w` is `q.wallet.to_lowercase()` at line 1965) ## why this is safe semantic-equivalent. both sides of every changed predicate are guaranteed lowercase by: - inserts: `addr_hex(*addr)` = `format!("{:#x}", a)` (alloy lowercase hex) - query bind: `addr.to_lowercase()` or `bind_addr_lower()` `grep -n 'lower(.*) = lower(' indexer/src/api.rs` → 0 hits after this MR. ## tests ``` cargo clippy --all-targets -- -D warnings # clean cargo test # 40 unit + 0 doc + 2 integration = 42/42 PASS ``` no test diffs (predicate-equivalent change). ## not in scope (flagged for triage in #165) optional follow-up: `CREATE INDEX idx_timecurve_referral_applied_buyer ON idx_timecurve_referral_applied (buyer)` to mirror the existing referrer index — the `referee_charm_wad` and `referee_buy_count` subqueries scan without an index. left out of this MR to keep scope tight; happy to ship as a separate migration if you want it.
Brouie commented 2026-05-07 02:36:45 +00:00 (Migrated from gitlab.com)

mentioned in issue #165

mentioned in issue #165
Brouie commented 2026-05-07 04:17:20 +00:00 (Migrated from gitlab.com)

@PlasticDigits — heads up, this MR is now stale. you shipped the fix on fix/glab-165-referral-index-predicates (commit a4ce4a7, merged via 18a771b) which lands the same SQL change plus the new buyer btree migration. my version here is effectively superseded.

no action needed from me — happy to close from my side if you want, otherwise feel free to close whenever you get a chance.

@PlasticDigits — heads up, this MR is now stale. you shipped the fix on `fix/glab-165-referral-index-predicates` (commit `a4ce4a7`, merged via `18a771b`) which lands the same SQL change plus the new buyer btree migration. my version here is effectively superseded. no action needed from me — happy to close from my side if you want, otherwise feel free to close whenever you get a chance.
PlasticDigits (Migrated from gitlab.com) closed this pull request 2026-05-07 11:59:21 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
code/yieldomega!375
No description provided.