executor, distsql, sessionctx, util: add adaptive limit scan profiles#69729
executor, distsql, sessionctx, util: add adaptive limit scan profiles#69729solotzg wants to merge 9 commits into
Conversation
…eaders Signed-off-by: Zhigao TONG <tongzhigao@pingcap.com>
…urrency cap Signed-off-by: Zhigao TONG <tongzhigao@pingcap.com>
Signed-off-by: Zhigao TONG <tongzhigao@pingcap.com>
…trics Signed-off-by: Zhigao TONG <tongzhigao@pingcap.com>
|
Skipping CI for Draft Pull Request. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…handling Signed-off-by: Zhigao TONG <tongzhigao@pingcap.com>
… stop profile metrics Signed-off-by: Zhigao TONG <tongzhigao@pingcap.com>
…move unused functions Signed-off-by: Zhigao TONG <tongzhigao@pingcap.com>
…adjust limit settings Signed-off-by: Zhigao TONG <tongzhigao@pingcap.com>
…an ratio bucket support Signed-off-by: Zhigao TONG <tongzhigao@pingcap.com>
What problem does this PR solve?
Issue Number: ref #66658
Problem Summary:
For
ORDER BY ... LIMITqueries that can stop early, especially when the plan uses keep-order scans andIndexJoin, TiDB may read far more rows than needed before the rootLimitstops the pipeline.When the system is under pressure, this over-read can amplify RPC work, queueing, memory usage, and downstream task fan-out. In bad cases, slower cancellation causes more prefetched work, which further increases system pressure.
What changed and how does it work?
This PR introduces adaptive limit scan profiles behind a new feature gate:
The variable is disabled by default.
Main changes:
IndexJoin, apply learned caps to:IndexLookUpbatch size/concurrencyThis PR also keeps the earlier static keep-order LIMIT cap path for reader executors and adds adaptive profile support around it.
Check List
Tests
Unit tests:
./tools/check/failpoint-go-test.sh pkg/executor -run 'TestAdaptiveIndexJoinLimitSettings|TestApplyAdaptiveIndexJoinLimitSettingsToLookupThroughProjection|TestObserveEarlyStopProfile|TestSelectEarlyStopProfileCandidate' -count=1Other local checks:
Manual E2E test steps:
outer_t: 400000 rowsinner_t: 400000 rowsidx_order_key(order_key)idx_join_key(join_key)order_key BETWEEN 1 AND 392857LIMIT 1000EXPLAIN ANALYZE.E2E result:
The ON case keeps the SQL result unchanged while reducing build-side over-read from
32906rows to3988rows, which is withinLIMIT * 4.Side effects
Documentation
Release note