Skip to content

fix: enable vector index with single-row vector providers - #24394

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
ck89119:issue-23158
May 14, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
ck89119:issue-23158

Conversation

@ck89119

@ck89119 ck89119 commented May 14, 2026 •

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 #23158

What this PR does / why we need it:

This PR enables a conservative vector index rewrite when the query vector is provided by a single-row derived table in a trivial INNER JOIN.

Changes:

  • Recognize vector ORDER BY over a join shape where one side is the indexed table and the other side provides the query vector.
  • Limit the rewrite to trivial INNER JOIN cases where the provider side can be proven to produce at most one row by primary-key or unique-key equality filters.
  • Require the provider vector to be provably non-NULL before passing it to IVF/HNSW table functions.
  • Keep the provider subtree as the IVF/HNSW function scan child so the vector argument remains reachable.
  • Add planner tests for accepted and rejected rewrite cases plus coverage for the new helper branches.

Review safety updates:

  • SINGLE JOIN / scalar subquery shapes are no longer rewritten because the zero-row provider case must preserve NULL-extension semantics.
  • Bare LIMIT 1 is no longer accepted as a global single-row proof.
  • Nullable provider vectors fall back to the original plan unless non-NULL can be proven by column metadata or an isnotnull filter.

Tests:

  • go test ./pkg/sql/plan
  • go test ./pkg/sql/plan -covermode=set -coverprofile=/tmp/issue23158-plan.out
  • git diff --check
  • npx -y markdownlint-cli2 CLAUDE_TODO_2026-05-14.md
  • make
  • make static-check

@ck89119
ck89119 requested review from aunjgr and ouyuanning as code owners May 14, 2026 07:52
@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 →

@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label May 14, 2026
@mergify mergify Bot added kind/bug Something isn't working kind/test-ci labels May 14, 2026

@aunjgr aunjgr 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.

Upgrading to approve. On reflection my prior comment overstated the type-aliasing concerns:

  • The function binder enforces matching types on dist function args before the rewrite runs, so the distFnArgs[1].Typ = distFnArgs[0].Typ mutation is a no-op in practice.
  • Width-mismatch rejection happens earlier in the binder.
  • The pre-existing non-join getArgsFromDistFn uses the same pattern and has been in production.

The hardening notes (trivial-OnList strictness, dead Node_SORT branch, UK reasoning comment, IVF range-opt disabled on join path) and the test gaps (OUTER/composite-PK rejection, execution-level correctness) are genuine but non-blocking — please address as follow-ups.

LGTM.

@mergify mergify Bot added the queued label May 14, 2026
@mergify

mergify Bot commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-14 15:14 UTC · Rule: main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-05-14 16:14 UTC · at ea904e619c9867a4cd76a8784a3078505032f60b · squash

This pull request spent 1 hour 17 seconds in the queue, including 59 minutes 38 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@mergify
mergify Bot merged commit 8b18b39 into matrixorigin:main May 14, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label May 14, 2026
@ck89119
ck89119 deleted the issue-23158 branch May 15, 2026 04:06
mergify Bot pushed a commit that referenced this pull request May 25, 2026
…#24394) (#24561)

Cherry-pick of #24394 to 4.0-dev.

This PR enables a conservative vector index rewrite when the query vector is provided by a single-row derived table in a trivial INNER JOIN.

Approved by: @XuPeng-SH, @aunjgr
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#24394)

This PR enables a conservative vector index rewrite when the query vector is provided by a single-row derived table in a trivial INNER JOIN.

Changes:
- Recognize vector ORDER BY over a join shape where one side is the indexed table and the other side provides the query vector.
- Limit the rewrite to trivial INNER JOIN cases where the provider side can be proven to produce at most one row by primary-key or unique-key equality filters.
- Require the provider vector to be provably non-NULL before passing it to IVF/HNSW table functions.
- Keep the provider subtree as the IVF/HNSW function scan child so the vector argument remains reachable.
- Add planner tests for accepted and rejected rewrite cases plus coverage for the new helper branches.

Review safety updates:
- SINGLE JOIN / scalar subquery shapes are no longer rewritten because the zero-row provider case must preserve NULL-extension semantics.
- Bare LIMIT 1 is no longer accepted as a global single-row proof.
- Nullable provider vectors fall back to the original plan unless non-NULL can be proven by column metadata or an isnotnull filter.

Tests:
- go test ./pkg/sql/plan
- go test ./pkg/sql/plan -covermode=set -coverprofile=/tmp/issue23158-plan.out
- git diff --check
- npx -y markdownlint-cli2 CLAUDE_TODO_2026-05-14.md
- make
- make static-check

Approved by: @aunjgr
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#24394)

This PR enables a conservative vector index rewrite when the query vector is provided by a single-row derived table in a trivial INNER JOIN.

Changes:
- Recognize vector ORDER BY over a join shape where one side is the indexed table and the other side provides the query vector.
- Limit the rewrite to trivial INNER JOIN cases where the provider side can be proven to produce at most one row by primary-key or unique-key equality filters.
- Require the provider vector to be provably non-NULL before passing it to IVF/HNSW table functions.
- Keep the provider subtree as the IVF/HNSW function scan child so the vector argument remains reachable.
- Add planner tests for accepted and rejected rewrite cases plus coverage for the new helper branches.

Review safety updates:
- SINGLE JOIN / scalar subquery shapes are no longer rewritten because the zero-row provider case must preserve NULL-extension semantics.
- Bare LIMIT 1 is no longer accepted as a global single-row proof.
- Nullable provider vectors fall back to the original plan unless non-NULL can be proven by column metadata or an isnotnull filter.

Tests:
- go test ./pkg/sql/plan
- go test ./pkg/sql/plan -covermode=set -coverprofile=/tmp/issue23158-plan.out
- git diff --check
- npx -y markdownlint-cli2 CLAUDE_TODO_2026-05-14.md
- make
- make static-check

Approved by: @aunjgr

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 kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: vector index didn't take effect

3 participants