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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/sql/opt/xform/limit_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,15 @@ func (c *CustomFuncs) OrderingBySingleColAsc(ordering props.OrderingChoice, col
// 1. A vector-search operator which produces candidate PKs.
// 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.
// 4. A top-k operator to perform re-ranking.
//
// Note that TryGenerateVectorSearch does not handle additional filters beyond
// those used to constrain index prefix columns.
func (c *CustomFuncs) TryGenerateVectorSearch(
grp memo.RelExpr,
_ *physical.Required,
scanExpr *memo.ScanExpr,
filters memo.FiltersExpr,
originalFilters memo.FiltersExpr,
passthrough opt.ColSet,
vectorCol opt.ColumnID,
queryVector opt.ScalarExpr,
Expand All @@ -479,12 +479,12 @@ func (c *CustomFuncs) TryGenerateVectorSearch(
// Generate implicit filters from constraints and computed columns as
// optional filters to help constrain an index scan.
optionalFilters := c.checkConstraintFilters(sp.Table)
computedColFilters := c.ComputedColFilters(sp, filters, optionalFilters)
computedColFilters := c.ComputedColFilters(sp, originalFilters, optionalFilters)
optionalFilters = append(optionalFilters, computedColFilters...)

var iter scanIndexIter
iter.Init(c.e.evalCtx, c.e, c.e.mem, &c.im, sp, filters, rejectNonVectorIndexes)
iter.ForEach(func(index cat.Index, _ memo.FiltersExpr, _ opt.ColSet, _ bool, _ memo.ProjectionsExpr) {
iter.Init(c.e.evalCtx, c.e, c.e.mem, &c.im, sp, originalFilters, rejectNonVectorIndexes)
iter.ForEach(func(index cat.Index, filters memo.FiltersExpr, _ opt.ColSet, _ bool, _ memo.ProjectionsExpr) {
if sp.Table.ColumnID(index.VectorColumn().Ordinal()) != vectorCol {
// This index is for a different vector column.
return
Expand Down
Loading