Skip to content

Commit bbd3a63

Browse files
committed
Allow using vector index with user variable.
1 parent 41a0994 commit bbd3a63

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sql/analyzer/replace_order_by_distance.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,22 @@ func replaceIdxOrderByDistanceHelper(ctx *sql.Context, scope *plan.Scope, node s
5959
if !isDistance {
6060
return n, transform.SameTree, nil
6161
}
62+
63+
isLiteral := func(expr sql.Expression) bool {
64+
switch expr.(type) {
65+
case *expression.Literal, *expression.UserVar:
66+
return true
67+
}
68+
return false
69+
}
70+
6271
var column sql.Expression
6372
var literal sql.Expression
64-
_, leftIsLiteral := distance.LeftChild.(*expression.Literal)
65-
if leftIsLiteral {
73+
if isLiteral(distance.LeftChild) {
6674
column = distance.RightChild
6775
literal = distance.LeftChild
6876
} else {
69-
_, rightIsLiteral := distance.RightChild.(*expression.Literal)
70-
if rightIsLiteral {
77+
if isLiteral(distance.RightChild) {
7178
column = distance.LeftChild
7279
literal = distance.RightChild
7380
} else {

0 commit comments

Comments
 (0)