Skip to content

Commit

Permalink
Fix: cursor pagination with null in columns and support for order by …
Browse files Browse the repository at this point in the history
…with nulls first or last
  • Loading branch information
dosco committed Dec 10, 2023
1 parent 99962b7 commit 1e48e6e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion core/internal/qcode/qcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

1 comment on commit 1e48e6e

@vercel
Copy link

@vercel vercel bot commented on 1e48e6e Dec 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.