Make keyset cursor pagination NULL-aware
Cursor.SQLFragment emitted a seek predicate with no NULL handling, so once a page boundary landed on a NULL order value the WHERE matched no rows and pagination terminated early, silently dropping the remaining rows.
Rewrite SQLFragment to emit explicit NULLS placement and a null-aware, type-agnostic seek predicate, mirroring the direction and NULLS placement on the Head/Tail inversion so backward paging stays an exact inverse. For NOT NULL columns it reduces to the previous predicate.
Add white-box pagination tests that evaluate the generated SQL with three-valued logic and walk the whole set forward and backward across the NULL boundary.
Summary by cubic
Makes keyset cursor pagination NULL-aware so pages don’t truncate when the sort column has NULLs. Adds explicit NULLS placement and a null-aware seek; backward paging mirrors forward exactly.
Tests +785 -0
- Add Postgres-backed e2e walk over adversarial datasets (NULL blocks, ties) to confirm forward/backward paging reconstruct full order.
- Lock exact SQL and named args across direction/position/key cases;
@cursor_field_valueappears only for non-NULL seeks. - Add unit tests for
CursorKeyround-trip and invalid formats,OrderDirectiontext marshaling, andPagetrimming/HasNext/HasPrev for Head/Tail.
Service +67 -21
- Rewrite
Cursor.SQLFragmentvia a template that sets ASC/DESC, NULLS FIRST/LAST, and id tiebreak; Tail flips both for symmetry. - Use a null-aware, type-agnostic seek; bind
@cursor_field_valueonly when non-NULL.
Other +2 -2
- Run the new e2e suite in CI and Makefile by including
./e2e/page/....