Skip to content

Commit 9feb775

Browse files
committed
Propage vector properties into in-memory vector indexes.
1 parent ea88909 commit 9feb775

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

memory/table.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,11 @@ func (t *Table) createIndex(data *TableData, name string, columns []sql.IndexCol
20122012
}
20132013
}
20142014

2015+
var vectorFunction vector.DistanceType
2016+
if constraint == sql.IndexConstraint_Vector {
2017+
vectorFunction = vector.DistanceL2Squared{}
2018+
}
2019+
20152020
return &Index{
20162021
DB: t.dbName(),
20172022
DriverName: "",
@@ -2022,7 +2027,7 @@ func (t *Table) createIndex(data *TableData, name string, columns []sql.IndexCol
20222027
Unique: constraint == sql.IndexConstraint_Unique,
20232028
Spatial: constraint == sql.IndexConstraint_Spatial,
20242029
Fulltext: constraint == sql.IndexConstraint_Fulltext,
2025-
SupportedVectorFunction: nil,
2030+
SupportedVectorFunction: vectorFunction,
20262031
CommentStr: comment,
20272032
PrefixLens: prefixLengths,
20282033
}, nil

sql/analyzer/replace_order_by_distance.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ func replaceIdxOrderByDistanceHelper(ctx *sql.Context, scope *plan.Scope, node s
4141
if err != nil {
4242
return nil, transform.SameTree, err
4343
}
44+
45+
// Column references have not been assigned their final indexes yet, so do that for the ORDER BY expression now.
46+
// We can safely do this because an expression that references other tables won't pass `isSortFieldsValidPrefix` below.
47+
sortNode = offsetAssignIndexes(sortNode).(plan.Sortable)
48+
4449
sfExprs := normalizeExpressions(tableAliases, sortNode.GetSortFields().ToExpressions()...)
4550
sfAliases := aliasedExpressionsInNode(sortNode)
4651

0 commit comments

Comments
 (0)