Skip to content

test: scan write-set merge is byte-order sorted and byte-range filtered (#331) - #550

Merged
s2x merged 1 commit into
masterfrom
fix/331-test-scan-ordering
Sep 9, 2026
Merged

test: scan write-set merge is byte-order sorted and byte-range filtered (#331)#550
s2x merged 1 commit into
masterfrom
fix/331-test-scan-ordering

Conversation

@s2x

@s2x s2x commented Sep 9, 2026

Copy link
Copy Markdown
Member

Description

The transaction scan() merge (TxnReader::finalizeScanResults()) sorted the merged key list with plain sort() (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. Since scan() 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 >= / < to strcmp() (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 correctly
  • makeScanResponse() test helper now accepts array<string|int, string> (PHP coerces numeric-string literal keys to int) and casts keys back to strings

Changelog

Code Review

  • Pending subagent code review

@s2x s2x self-assigned this Sep 9, 2026
@s2x
s2x force-pushed the fix/331-test-scan-ordering branch from 840650b to 161282b Compare September 9, 2026 19:54
…ed (#331)

sort() with SORT_REGULAR compared numeric strings numerically and the
write-set in-range filter used loose >=/< — both contradict TiKV's byte
order. Use sort(..., SORT_STRING) and strcmp(); add tests pinning byte
order for numeric-string and binary write-set keys (issue #331, TEST-11).
@s2x
s2x force-pushed the fix/331-test-scan-ordering branch from 161282b to 8cf50a4 Compare September 9, 2026 21:00
@s2x
s2x marked this pull request as ready for review September 9, 2026 21:00
@s2x
s2x merged commit 95f5258 into master Sep 9, 2026
9 checks passed
@s2x
s2x deleted the fix/331-test-scan-ordering branch September 9, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TEST-11] Add tests for scan result ordering when the write set is merged (byte order vs PHP sort)

1 participant