Repository navigation
fix(memory): PartiQL pages continue after the last item the page read - #120
Merged
kalaspuff merged 1 commit intoOct 31, 2026
Conversation
SELECT pages of the in-memory backend continued at an offset into the list of results (NextToken "offset:N"), so rows deleted before the position made the next page skip rows and rows inserted before it were returned again: a "select a page, delete it, continue" loop missed items. LastEvaluatedKey was never set either. NextToken now encodes the key of the last item the page evaluated (the table key, and the index key for index reads), the page returns it as last_evaluated_key, and the next page continues after that position in the read's order, ORDER BY included. Fixes #91 Co-authored-by: Carl Oscar Aaro <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
PartiQL
SELECTpages of the in-memory DynamoDB continued at an offset into the list of results (NextTokenwasoffset:N), not after the last item the page read. WithLimit=2, page 1 returned sk 0 and 1; delete those two rows, and page 2 returned sk 4 and 5, where DynamoDB returns 2 and 3. Rows inserted before the position were returned again. A "select a page, delete it, continue" cleanup loop missed items on the in-memory backend.last_evaluated_keywas never set onSELECTpages either.NextTokennow encodes the key of the last item the page evaluated: the table key, plus the index key for index reads, asLastEvaluatedKeyholds it. The page also returns that key aslast_evaluated_key, and the next page continues after its position in the read's order (the table's or index's key order, or theORDER BYorder), wherever the item is now. A token that does not decode into a key of the read raisesValidationException: Invalid NextToken, as before.Verified with a memory backend test that pages through a table, a local index, a global index, a scan and an
ORDER BY ... DESCread, deletes each first page's rows before the second page and writes them again before the third, and checkslast_evaluated_keyand invalid tokens; and a Python integration test of the cleanup loop on the in-memory backend and MiniStack. Both fail without the fix.make checkpasses.Fixes #91
Checklist
make checkpasses locally (lint, types, clippy, consistency, tests)fctl session
Note
Low risk. It changes only how the in-memory test backend pages PartiQL
SELECTresults; the AWS adapter and the Python API are untouched, and the existing page tests and CI pass on both backends.What it does. PartiQL
SELECTpages of the in-memory DynamoDB used to continue at an offset into the result list, so deleting a page's rows before asking for the next page skipped rows, and inserting rows before the position repeated them.NextTokennow encodes the key of the last item the page evaluated (the table key, plus the index key for index reads), the page also returns it aslast_evaluated_key, and the next page continues after that key in the read's order, includingORDER BYreads. A token that does not decode into a key of the read still raisesInvalid NextToken.Token format. The in-memory
NextTokenchanges fromoffset:Nto akey:...string, so tokens saved from an earlier run of the in-memory backend are refused withInvalid NextToken.fctl review's first look at
0b4d04c· 4 files, +201 −24 · Review agent settings