test: scan write-set merge is byte-order sorted and byte-range filtered (#331) - #550
Merged
Conversation
s2x
force-pushed
the
fix/331-test-scan-ordering
branch
from
September 9, 2026 19:54
840650b to
161282b
Compare
s2x
force-pushed
the
fix/331-test-scan-ordering
branch
from
September 9, 2026 21:00
161282b to
8cf50a4
Compare
s2x
marked this pull request as ready for review
September 9, 2026 21:00
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.
Description
The transaction
scan()merge (TxnReader::finalizeScanResults()) sorted the merged key list with plainsort()(SORT_REGULAR), which compares numeric strings numerically ("9"before"10"), while TiKV orders keys bytewise ("10"before"9"). The in-range filter for write-set keys used the same loose>=/<operators. Sincescan()is contractually ordered and callers paginate on the last returned key, the numeric-order merge silently skipped in-between keys. Fixed to byte order (sort(..., SORT_STRING)+strcmp()) and pinned with the tests demanded by the issue.Closes #331
Changes
TxnReader::finalizeScanResults():sort($allKeys, SORT_STRING)(byte order, issue [TEST-11] Add tests for scan result ordering when the write set is merged (byte order vs PHP sort) #331) and write-set in-range filter switched from loose>=/<tostrcmp()(byte order)TransactionTest: 4 new tests — merged scan with numeric-string keys returns byte order (['10', '9', 'b']) and string-typed keys (fails on pre-fix master); write-set key'9'inside byte range['10', 'b')is kept after'10'(loose comparison dropped it); write-set key'19'numerically inside['2', '3')but bytewise outside is filtered out; binary write-set keys"\x00a"/"\xffz"sort and range-filter correctlymakeScanResponse()test helper now acceptsarray<string|int, string>(PHP coerces numeric-string literal keys to int) and casts keys back to stringsChangelog
[Unreleased] → Fixed:TxnReader::finalizeScanResults()now merges the transaction write set into scan results in byte order (SORT_STRINGsort +strcmp()range filter); numeric-string keys no longer sort numerically. ([TEST-11] Add tests for scan result ordering when the write set is merged (byte order vs PHP sort) #331)Code Review