executor: add AQSort (adaptive quicksort) for SortExec #66004
+2,059
−8
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 problem does this PR solve?
Issue Number: close #xxx
What changed and how does it work?
This introduces AQSort: an adaptive sort optimized for byte-orderable keys with
long shared prefixes, inspired by US7680791B2 (“Method for sorting data using
common prefix bytes”).
Why:
per-type comparison functions and often re-scans shared key prefixes.
composite keys / encoded datums), making them a good fit for a
common-prefix-aware algorithm.
What’s included:
New
pkg/util/aqsort:first byte after the common prefix.
SortExec integration (in-memory path):
codec.EncodeKeyper row and sortPair{Key, Row}using
aqsort.PairSorter.to avoid per-key allocations where possible.
User-facing enablement:
tidb_enable_aqsort(default OFF) to opt into theAQSort execution path.
sortexec.SetAQSortEnabledtoggle for benchmarking /experimentation; it still forces AQSort independent of the sysvar.
Safety / observability:
SortExec and fall back to the original comparator-based sort so the query
still succeeds.
conn_id/executor_idandcontext (rows/worker_id) to aid debugging.
AQSortForceEncodeKeyErrorto deterministically test fallback.Tests:
row order for:
timestamp, duration, JSON), with NULLs and mixed ASC/DESC.
fallback behavior under forced encode errors.
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.