Skip to content

opt: use filters from scanIndexIter in TryGenerateVectorSearch #146259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DrewKimball
Copy link
Collaborator

This commit modifies the TryGenerateVectorSearch exploration rule to use the filters provided by scanIndexIter.ForEach rather than those originally supplied to TryGenerateVectorSearch. This fixes two bugs:

  1. Now, each iteration no longer overwrites the filters, ensuring that the iteration for each index sees the correct set of filters.
  2. The rule can now apply when the filters exactly match the partial-index predicate, if any.

Fixes #146257
Fixes #146258

Release note (bug fix): Fixed a bug in v25.1.0 where a vector search operator could drop user-supplied filters if the same vector column was indexed twice and an index with no prefix columns was defined after one with prefix columns.

This commit modifies the `TryGenerateVectorSearch` exploration rule
to use the filters provided by `scanIndexIter.ForEach` rather than those
originally supplied to `TryGenerateVectorSearch`. This fixes two bugs:
1. Now, each iteration no longer overwrites the filters, ensuring that
   the iteration for each index sees the correct set of filters.
2. The rule can now apply when the filters exactly match the partial-index
   predicate, if any.

Fixes cockroachdb#146257
Fixes cockroachdb#146258

Release note (bug fix): Fixed a bug in v25.1.0 where a vector search
operator could drop user-supplied filters if the same vector column was
indexed twice and an index with no prefix columns was defined after one
with prefix columns.
@DrewKimball DrewKimball requested a review from a team May 7, 2025 05:15
@DrewKimball DrewKimball requested a review from a team as a code owner May 7, 2025 05:15
@DrewKimball DrewKimball requested review from yuzefovich and removed request for a team May 7, 2025 05:15
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@DrewKimball DrewKimball added the backport-25.2.x Flags PRs that need to be backported to 25.2 label May 7, 2025
Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Nice catch! :lgtm:

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)


-- commits line 15 at r1:
nit: s/25.1.0/25.2.0/.


pkg/sql/opt/xform/limit_funcs.go line 461 at r1 (raw file):

//  2. A lookup-join to retrieve the vector column and any other needed columns.
//  3. A projection of the distance between the vector column and query vector.
//  3. A top-k operator to perform re-ranking.

nit: should this be 4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-25.2.x Flags PRs that need to be backported to 25.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

opt: cannot plan a vector search with a partial-index predicate opt: vector index rule can drop filters
3 participants