Skip to content

[Bug] Fix IVFFLAT BIT primary-key membership - #29282

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/29047-ivfflat-bit-pk
Sep 25, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/29047-ivfflat-bit-pk

Conversation

@iamlinjunhong

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #29047

What this PR does / why we need it:

IVFFLAT runtime membership keeps the primary-key type when building an IN predicate. The generic IN and NOT IN registries lacked BIT overloads, so PRE binding failed for BIT primary keys and AUTO's correctness retry then failed as well.

Append BIT overloads backed by the existing uint64 membership executor, preserving existing encoded overload positions. Add coverage for widths 1/8/16/64, uint64 boundaries, SQL NULL semantics, typed IVFFLAT lowering, and public PRE/AUTO results with FORCE, POST, and INCLUDE controls.

Validation:

  • Full pkg/sql/plan/function CGo test package passed; focused IVFFLAT runtime-expression test passed.
  • The vector_ivf_retry.sql BVT passed with 123/123 result comparisons; FORCE, PRE, AUTO, and INCLUDE returned keys 196–200, and POST returned empty.
  • Scoped go vet and golangci-lint passed for both changed Go packages (0 issues).

Performance: uses the existing uint64 map executor, with no extra runtime conversion or IVFFLAT scan work.

Remaining validation: the reported 2-CN topology was not run locally; standard CI remains pending.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Sep 23, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 23, 2026
@iamlinjunhong
iamlinjunhong force-pushed the fix/29047-ivfflat-bit-pk branch from bcaca22 to 53212c5 Compare September 23, 2026 11:45
@iamlinjunhong
iamlinjunhong force-pushed the fix/29047-ivfflat-bit-pk branch from 53212c5 to f78099d Compare September 25, 2026 04:15

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed current head f78099d. The added BIT/BIT IN and NOT IN overloads use the existing fixed-width uint64 implementation, preserving NULL and three-valued semantics. Planner tests cover widths 1/8/16/64 and no implicit cast; direct evaluator tests cover high-bit, max-value, NULL-list, and NOT IN cases. The IVFFLAT retry BVT adds a FORCE control and verifies PRE/AUTO/INCLUDE against the filter case where POST yields no candidates. Current-head UT, SCA, and multi-CN BVT checks pass. No blocking findings.

@mergify mergify Bot added the queued label Sep 25, 2026
@mergify

mergify Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-25 05:56 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-25 05:56 UTC · at fdfbea4fb7125d538d8675d725ace17811760023 · squash

This pull request spent 12 seconds in the queue, including 1 second running CI.

Required conditions to merge

@mergify
mergify Bot merged commit fdfbea4 into matrixorigin:main Sep 25, 2026
28 of 29 checks passed
@mergify mergify Bot removed the queued label Sep 25, 2026
XuPeng-SH pushed a commit that referenced this pull request Oct 10, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

- #29077

#29047 was already addressed by merged upstream PR #29282 and is
included here only as related context.

## What this PR does / why we need it:

IVFFLAT can leave an unrecognized distance predicate, such as `BETWEEN`,
on the base scan while truncating the vector-index candidate stream to
Top-K. Qualifying rows outside that prefix are then lost. This change
detects residual predicates on the indexed distance expression before
building PRE, POST, INCLUDE, or AUTO rewrites and falls back to the
exact plan. The check covers exact and lossy entries, preserves SQL
three-valued logic, validates the scan relation binding, and keeps
canonical range pushdown unchanged.

The regression case covers literal and prepared `BETWEEN` queries across
force, PRE, POST, and AUTO modes. The issue should be verified by the
reporter after the PR is merged.

## Validation

- `GOWORK=off .agents/skills/mo-dev/scripts/mo-cgo-test -count=1
-timeout=300s ./pkg/sql/plan`
- `GOWORK=off go vet -mod=readonly ./pkg/sql/plan`
- Go 1.27.1-built `golangci-lint v2.14.0 --new-from-rev origin/main
./pkg/sql/plan` (`0 issues`)
- Task-owned mo-service with `vector_ivf_prepare_dist_range.sql`: normal
comparison passed 84/84 twice on the same instance after reviewing
generated result output.

## Performance and compatibility

Canonical recognized distance ranges retain the existing vector-index
pushdown. Queries with residual distance predicates now use the exact
scan to preserve correctness; this is a deliberate conservative tradeoff
for unsupported predicate shapes and lossy scores.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: IVFFLAT PRE rejects BIT primary keys and AUTO retry fails with 20631

4 participants