Skip to content

Commit 1e48e6e

Browse files
committed
Fix: cursor pagination with null in columns and support for order by with nulls first or last
1 parent 99962b7 commit 1e48e6e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

core/internal/qcode/qcode.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,32 @@ func (co *Compiler) addSeekPredicate(sel *Select) {
898898
switch {
899899
case i > 0 && n != i:
900900
f.Op = OpEquals
901-
case ob.Order == OrderDesc:
901+
case ob.Order == OrderDesc ||
902+
ob.Order == OrderDescNullsFirst || ob.Order == OrderDescNullsLast:
902903
f.Op = OpLesserThan
904+
case ob.Order == OrderAsc ||
905+
ob.Order == OrderAscNullsLast || ob.Order == OrderAscNullsFirst:
906+
f.Op = OpGreaterThan
903907
default:
904908
f.Op = OpGreaterThan
905909
}
906910

911+
// could be null needs to be handled
912+
if !ob.Col.NotNull {
913+
isnull1 := newExpOp(OpIsNull)
914+
isnull1.Left.Table = "__cur"
915+
isnull1.Left.Col = ob.Col
916+
917+
isnull2 := newExpOp(OpIsNull)
918+
isnull2.Left.Col = ob.Col
919+
920+
or1 := newExpOp(OpOr)
921+
or1.Children = append(or.Children, isnull1, isnull2, f)
922+
923+
// now that f is added to the above or1 we can set f to or1
924+
f = or1
925+
}
926+
907927
if and != nil {
908928
and.Children = append(and.Children, f)
909929
} else {

0 commit comments

Comments
 (0)