@@ -13,9 +13,9 @@ func replaceIdxOrderByDistance(ctx *sql.Context, a *Analyzer, n sql.Node, scope
1313 return replaceIdxOrderByDistanceHelper (ctx , scope , n , nil )
1414}
1515
16- func replaceIdxOrderByDistanceHelper (ctx * sql.Context , scope * plan.Scope , node sql.Node , sortNode plan.Sortable ) (sql.Node , transform.TreeIdentity , error ) {
16+ func replaceIdxOrderByDistanceHelper (ctx * sql.Context , scope * plan.Scope , node sql.Node , sortNode * plan.TopN ) (sql.Node , transform.TreeIdentity , error ) {
1717 switch n := node .(type ) {
18- case plan.Sortable :
18+ case * plan.TopN :
1919 sortNode = n // lowest parent sort node
2020 case * plan.ResolvedTable :
2121 if sortNode == nil {
@@ -44,7 +44,7 @@ func replaceIdxOrderByDistanceHelper(ctx *sql.Context, scope *plan.Scope, node s
4444
4545 // Column references have not been assigned their final indexes yet, so do that for the ORDER BY expression now.
4646 // We can safely do this because an expression that references other tables won't pass `isSortFieldsValidPrefix` below.
47- sortNode = offsetAssignIndexes (sortNode ).(plan.Sortable )
47+ sortNode = offsetAssignIndexes (sortNode ).(* plan.TopN )
4848
4949 sfExprs := normalizeExpressions (tableAliases , sortNode .GetSortFields ().ToExpressions ()... )
5050 sfAliases := aliasedExpressionsInNode (sortNode )
@@ -91,10 +91,7 @@ func replaceIdxOrderByDistanceHelper(ctx *sql.Context, scope *plan.Scope, node s
9191 return n , transform .SameTree , nil
9292 }
9393
94- var limit sql.Expression
95- if topn , ok := sortNode .(* plan.TopN ); ok {
96- limit = topn .Limit
97- }
94+ limit := sortNode .Limit
9895
9996 lookup := sql.IndexLookup {
10097 Index : idx ,
0 commit comments