diff --git a/core/internal/qcode/qcode.go b/core/internal/qcode/qcode.go index 02e514a2..8db64125 100644 --- a/core/internal/qcode/qcode.go +++ b/core/internal/qcode/qcode.go @@ -898,12 +898,32 @@ func (co *Compiler) addSeekPredicate(sel *Select) { switch { case i > 0 && n != i: f.Op = OpEquals - case ob.Order == OrderDesc: + case ob.Order == OrderDesc || + ob.Order == OrderDescNullsFirst || ob.Order == OrderDescNullsLast: f.Op = OpLesserThan + case ob.Order == OrderAsc || + ob.Order == OrderAscNullsLast || ob.Order == OrderAscNullsFirst: + f.Op = OpGreaterThan default: f.Op = OpGreaterThan } + // could be null needs to be handled + if !ob.Col.NotNull { + isnull1 := newExpOp(OpIsNull) + isnull1.Left.Table = "__cur" + isnull1.Left.Col = ob.Col + + isnull2 := newExpOp(OpIsNull) + isnull2.Left.Col = ob.Col + + or1 := newExpOp(OpOr) + or1.Children = append(or.Children, isnull1, isnull2, f) + + // now that f is added to the above or1 we can set f to or1 + f = or1 + } + if and != nil { and.Children = append(and.Children, f) } else {