Skip to content

WIP: *: batching analyze requests - #69686

Open
0xPoe wants to merge 3 commits into
pingcap:masterfrom
0xPoe:poe-batch-analyze
Open

WIP: *: batching analyze requests#69686
0xPoe wants to merge 3 commits into
pingcap:masterfrom
0xPoe:poe-batch-analyze

Conversation

@0xPoe

@0xPoe 0xPoe commented Jul 6, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: ref #67449

Problem Summary:

Full-sampling ANALYZE currently sends and receives one coprocessor result per region, causing avoidable RPC and response-merging overhead.

What changed and how does it work?

  • Apply tidb_store_batch_size to V2 full-sampling ANALYZE and allow batching without row-count hints; executor: remove unnecessary ordering from full-sampling Analyze requests #70275 removes the obsolete KeepOrder requirement.
  • Negotiate TiKV-side result merging with allow_batch_task_data_merge and explicit data_merged_into_response acknowledgements.
  • Retry every batched task without an explicit response or acknowledgement, preserving mixed-version compatibility.

Depends on #70275, pingcap/kvproto#1497, and the TiKV branch 0xPoe/tikv:batch-cleanup-no-hll.

Check List

Tests

  • Unit test
  • Integration test (TiKV: batched full-sampling ANALYZE through the real endpoint)
  • Manual test (20k rows, 8 regions, 1 store; batched and unbatched exact statistics matched)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. labels Jul 6, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign cfzjywxk, time-and-fate for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 6, 2026
@0xPoe 0xPoe changed the title *: batching analyze requests WIP: *: batching analyze requests Jul 6, 2026
@ti-chi-bot ti-chi-bot Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR enables store-batched coprocessor execution for Analyze requests by wiring StoreBatchSize into request construction, updating task and response handling, adjusting kvproto replacements, and adding batching and acknowledgement tests.

Changes

Analyze Request Store Batching

Layer / File(s) Summary
RequestBuilder setter and Analyze wiring
pkg/distsql/request_builder.go, pkg/executor/analyze_col.go
Adds SetStoreBatchSize and applies the session store batch size to Analyze requests while leaving KeepOrder unset.
Coprocessor Analyze batching and response handling
pkg/store/copr/coprocessor.go, DEPS.bzl, go.mod
Allows Analyze requests to use store batching, applies Analyze-specific task checks, handles merged responses, and updates kvproto replacement wiring.
Batching and acknowledgement validation
pkg/store/copr/copr_test/coprocessor_test.go, pkg/store/copr/coprocessor_ack_test.go
Verifies Analyze task grouping, merged acknowledgements, and redispatch of unanswered Analyze and DAG tasks.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AnalyzeColumnsExec
  participant RequestBuilder
  participant Coprocessor
  participant TiKV
  AnalyzeColumnsExec->>RequestBuilder: SetStoreBatchSize(SessionVars.StoreBatchSize)
  RequestBuilder->>Coprocessor: Build Analyze request
  Coprocessor->>Coprocessor: Group Analyze tasks for store batching
  Coprocessor->>TiKV: Send batched Analyze request
  TiKV-->>Coprocessor: Return merged acknowledgement or no task response
  Coprocessor-->>AnalyzeColumnsExec: Complete merged tasks or redispatch unanswered tasks
Loading

Possibly related PRs

  • pingcap/tidb#67676: Both affect Analyze request ordering and store-batched coprocessor behavior.
  • pingcap/tidb#69085: Both modify store-batched coprocessor task and response handling.

Suggested reviewers: cfzjywxk, wjhuang2016, zyguan

Poem

A rabbit hops through cop task queues,
Analyze batches bring good news.
Merged replies and retries align,
Three small tasks march in time.
Hop, hop, hooray—the tests agree! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: enabling batching for ANALYZE requests.
Description check ✅ Passed The description includes the issue reference, problem, implementation details, tests, side effects, documentation checks, and release note.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.21739% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.9461%. Comparing base (ed2376a) to head (f75bea4).
⚠️ Report is 1 commits behind head on master.

⚠️ Current head f75bea4 differs from pull request most recent head af66b65

Please upload reports for the commit af66b65 to get more accurate results.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69686        +/-   ##
================================================
- Coverage   76.3238%   73.9461%   -2.3778%     
================================================
  Files          2041       2058        +17     
  Lines        559771     579047     +19276     
================================================
+ Hits         427239     428183       +944     
- Misses       131631     150504     +18873     
+ Partials        901        360       -541     
Flag Coverage Δ
integration 40.9307% <65.2173%> (+1.2254%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 60.4471% <ø> (ø)
parser ∅ <ø> (∅)
br 47.4060% <ø> (-15.3154%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. do-not-merge/needs-tests-checked and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/needs-linked-issue labels Jul 14, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/store/copr/coprocessor_ack_test.go`:
- Around line 94-103: Extend the test around the merged task response to assert
that the worker’s collected execution metrics include the batched response’s
ScanDetail values, specifically ProcessedVersions of 7. Use the existing
worker.stats.ScanDetail or corresponding metrics container, ensuring the
assertion verifies metrics come from the batch ExecDetailsV2 rather than the
main response.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 659b7034-dd42-46e1-9c6b-fd140d8150e3

📥 Commits

Reviewing files that changed from the base of the PR and between 602f946 and d5904a1.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • DEPS.bzl
  • go.mod
  • pkg/executor/analyze_col.go
  • pkg/store/copr/coprocessor.go
  • pkg/store/copr/coprocessor_ack_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • go.mod
  • pkg/executor/analyze_col.go
  • DEPS.bzl

Comment thread pkg/store/copr/coprocessor_ack_test.go Outdated
Comment on lines +94 to +103
resp := &coprocessor.Response{
Data: []byte("merged-main-response-data"),
BatchResponses: []*coprocessor.StoreBatchTaskResponse{
{
TaskId: mergedTask.taskID,
DataMergedIntoResponse: true,
ExecDetailsV2: &kvrpcpb.ExecDetailsV2{
ScanDetailV2: &kvrpcpb.ScanDetailV2{ProcessedVersions: 7},
},
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert on the collection of execution details.

The test mock correctly provides ExecDetailsV2 for the merged task, but there are no assertions verifying that these metrics were actually collected by the worker. Adding an assertion to verify worker.stats.ScanDetail (or the corresponding execution metrics container) would enforce correctness and would have caught the bug where the main response was being used for execution details instead of the batched response.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/store/copr/coprocessor_ack_test.go` around lines 94 - 103, Extend the
test around the merged task response to assert that the worker’s collected
execution metrics include the batched response’s ScanDetail values, specifically
ProcessedVersions of 7. Use the existing worker.stats.ScanDetail or
corresponding metrics container, ensuring the assertion verifies metrics come
from the batch ExecDetailsV2 rather than the main response.

@0xPoe
0xPoe force-pushed the poe-batch-analyze branch from bb70719 to 8169233 Compare July 20, 2026 08:35
@0xPoe
0xPoe force-pushed the poe-batch-analyze branch 2 times, most recently from 6d5651b to 763e499 Compare July 23, 2026 09:10
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 23, 2026
@0xPoe
0xPoe force-pushed the poe-batch-analyze branch from 763e499 to ecba620 Compare July 23, 2026 10:29
@ti-chi-bot ti-chi-bot Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 23, 2026
0xPoe added 3 commits July 24, 2026 01:20
Capture the two boundaries that later commits must change or preserve:
analyze requests do not yet join store batching, while batched tasks
without a per-task response remain eligible for retry.

Signed-off-by: 0xPoe <poe.liu@pm.me>
Forward tidb_store_batch_size to V2 full-sampling Analyze and admit
those internal requests to store batching without row-count hints.
Leave KeepOrder unset because the consumers derive correlation and
other statistics from the collected samples rather than scan order.

Signed-off-by: 0xPoe <poe.liu@pm.me>
Opt Analyze into kvproto batch-task data merging and consume explicit
per-task acknowledgements without emitting empty responses. A task
without an acknowledgement remains on the existing retry path, so
mixed-version stores cannot cause silent statistics loss. The
acknowledgement path keeps each task's execution details as unconsumed
stats through a nil-safe runtime-stats append, extracted and shared
with the existing unconsumed-stats collection.

Temporarily replace kvproto with the revision from pingcap/kvproto#1497
until that protocol change merges.

Signed-off-by: 0xPoe <poe.liu@pm.me>
@0xPoe
0xPoe force-pushed the poe-batch-analyze branch from f75bea4 to af66b65 Compare July 23, 2026 23:21
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 23, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

@0xPoe: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-unit-test-next-gen af66b65 link true /test pull-unit-test-next-gen
pull-build-next-gen af66b65 link true /test pull-build-next-gen
idc-jenkins-ci-tidb/unit-test af66b65 link true /test unit-test
idc-jenkins-ci-tidb/build af66b65 link true /test build

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant