Skip to content

pkg/executor, pkg/kv, pkg/store: propagate SQL digest for MPP task metadata#66763

Open
JaySon-Huang wants to merge 5 commits intopingcap:masterfrom
JaySon-Huang:feat/mpp-sql-digest-propagation
Open

pkg/executor, pkg/kv, pkg/store: propagate SQL digest for MPP task metadata#66763
JaySon-Huang wants to merge 5 commits intopingcap:masterfrom
JaySon-Huang:feat/mpp-sql-digest-propagation

Conversation

@JaySon-Huang
Copy link
Contributor

@JaySon-Huang JaySon-Huang commented Mar 7, 2026

What problem does this PR solve?

Issue Number: ref #66762

Problem Summary:
Short MPP queries (below slow log threshold) are hard to correlate between TiDB dispatch logs and TiFlash task logs because SQL digest is not propagated in mpp.TaskMeta.

What changed and how does it work?

  • Add SQLDigest to kv.MPPDispatchRequest.
  • Extract digest from StmtCtx.SQLDigest() in local MPP coordinator, log it in dispatch/retry/error paths, and carry it in dispatch requests.
  • Populate TaskMeta.SqlDigest in TiDB MPP client for dispatch/cancel/establish connection request metadata.
  • Update module wiring to consume the kvproto change (temporary replace to the branch containing TaskMeta.sql_digest) and refresh Bazel dependency metadata via make bazel_prepare.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Validation commands run:

  • go test ./pkg/kv -run TestNonExistent
  • go test ./pkg/store/copr -run TestNonExistent
  • go test ./pkg/executor/internal/mpp -run TestNonExistent
  • make lint
  • make bazel_prepare (with writable local Bazel cache/output paths in this environment)

Before this PR

# tidb.log
[2026/03/07 17:01:43.356 +08:00] [INFO] [local_mpp_coordinator.go:222] ["Dispatch mpp task"] [timestamp=464748308917911554] [ID=1] [QueryTs=1772874103272248530] [LocalQueryId=2] [ServerID=1445] [address=10.2.12.81:3930] [plan="Table(generic_entity)->Sel([eq(test.generic_entity.type_code, CNY) or(ne(test.generic_entity.attr_id_1, ), ne(test.generic_entity.attr_id_2, ))])->Send(-1, )"] [mpp-version=2] [exchange-compression-mode=NONE] [GatherID=1] [resource_group=default]
# tiflash.log
[2026/03/07 17:01:43.369 +08:00] [INFO] [MPPTaskStatistics.cpp:139] ["{\"query_tso\":464748308917911554,\"task_id\":1,\"is_root\":true,\"sender_executor_id\":\"ExchangeSender_18\",\"executors\":[...],...,"status\":\"FINISHED\",\"error_message\":\"\",\"cpu_ru\":0.6666666666666666,\"read_ru\":0.1273956298828125,\"memory_peak\":3059904,..."] [source="mpp_task_tracing MPP<gather_id:1, query_ts:1772874103272248530, local_query_id:2, server_id:1445, start_ts:464748308917911554,task_id:1>"] [thread_id=191]

After this PR, the sql digest is added to the logging

# tidb.log
[2026/03/08 14:41:45.458 +08:00] [INFO] [local_mpp_coordinator.go:244] ["Dispatch mpp task"] [timestamp=464768756710113282] [ID=1] [QueryTs=1772952105388643615] [LocalQueryId=2] [ServerID=1727] [address=10.2.12.81:3930] [plan="Table(generic_entity)->Sel([eq(test.generic_entity.type_code, CNY) or(ne(test.generic_entity.attr_id_1, ), ne(test.generic_entity.attr_id_2, ))])->Send(-1, )"] [mpp-version=3] [exchange-compression-mode=NONE] [GatherID=1] [resource_group=default] [sqlDigest=212e2a5dbe2a960ed1eb83e179cf830acfa105fe40a941c49699002fca309e74]
# tiflash.log
[2026/03/08 14:41:45.619 +08:00] [INFO] [MPPTaskStatistics.cpp:146] ["{\"query_tso\":464768756710113282,\"task_id\":1,\"is_root\":true,\"sender_executor_id\":\"ExchangeSender_19\",\"executors\":[...],...,\"connection_id\":3621781510,\"connection_alias\":\"\",\"sql_digest\":\"212e2a5dbe2a960ed1eb83e179cf830acfa105fe40a941c49699002fca309e74\",...\"status\":\"FINISHED\",\"error_message\":\"\",\"cpu_ru\":1,\"read_ru\":0.1273956298828125,\"memory_peak\":3060307,..."] [source="mpp_task_tracing MPP<gather_id:1, query_ts:1772952105388643615, local_query_id:2, server_id:1727, start_ts:464768756710113282,task_id:1>"] [thread_id=172]

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

Enhance MPP observability by propagating SQL digest in TiDB MPP task metadata and related dispatch logs.

Summary by CodeRabbit

  • New Features

    • Query execution now propagates SQL and plan digests across distributed execution paths for improved tracking and diagnostics.
    • Logs have been expanded to include these diagnostic identifiers to aid troubleshooting.
  • Chores

    • Vendored and build dependencies updated and expanded; build config adjusted for module resolution.

@ti-chi-bot ti-chi-bot bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Mar 7, 2026
@pantheon-ai
Copy link

pantheon-ai bot commented Mar 7, 2026

Review Complete

Findings: 1 issues
Posted: 0
Duplicates/Skipped: 1

ℹ️ Learn more details on Pantheon AI.

@ti-chi-bot ti-chi-bot bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Mar 7, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Mar 7, 2026

[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 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

@tiprow
Copy link

tiprow bot commented Mar 7, 2026

Hi @JaySon-Huang. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

@coderabbitai
Copy link

coderabbitai bot commented Mar 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 60b37ddd-9afe-4bb8-940a-3f61e8cfeae9

📥 Commits

Reviewing files that changed from the base of the PR and between 528b1a7 and 7b82377.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • go.mod
  • pkg/executor/internal/mpp/local_mpp_coordinator.go
  • pkg/kv/mpp.go
  • pkg/store/copr/mpp.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/kv/mpp.go

📝 Walkthrough

Walkthrough

Adds SQL/Plan digest propagation through the MPP pipeline (session → dispatch requests → task metadata → connection establishment), expands Bazel Go repository entries in DEPS.bzl, and adds a go.mod replacement for github.com/pingcap/kvproto.

Changes

Cohort / File(s) Summary
MPP SQL/Plan Digest propagation
pkg/executor/internal/mpp/local_mpp_coordinator.go, pkg/kv/mpp.go, pkg/store/copr/mpp.go
Extracts SQLDigest and PlanDigest from session context; adds SQLDigest/PlanDigest to kv.MPPDispatchRequest and SqlDigest/PlanDigest to mpp.TaskMeta; threads these fields into dispatch, cancel, and connection requests; minor comment fixes and logging updates.
Build configuration / dependencies
DEPS.bzl
Adds many new go_repository entries (specific versions, URLs, sha256, strip_prefix, some with patches/build tags) to vendor dependency declarations.
Go module mapping
go.mod
Adds a module replacement: github.com/pingcap/kvprotogithub.com/JaySon-Huang/kvproto v0.0.0-20260310145014-15cec242b951.

Sequence Diagram(s)

sequenceDiagram
  participant Session
  participant Coordinator
  participant KV as "KV Dispatcher"
  participant Store as "Coprocessor/Store"

  Session->>Coordinator: Start MPP execution (context contains SQLDigest, PlanDigest)
  Coordinator->>KV: Build MPPDispatchRequest (include SQLDigest, PlanDigest)
  KV->>Store: DispatchTask (TaskMeta with SqlDigest, PlanDigest)
  Store->>Store: Execute task (trace/log with digests)
  Store-->>KV: Task response / errors (include digests)
  KV-->>Coordinator: Dispatch response (propagate digests)
  Coordinator-->>Session: Report results / errors
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

lgtm

Poem

🐰 I sniffed the session, found the trace,
Hopped it through tasks to every place,
Digests tucked in each dispatch,
Logs now sing as they hop and attach,
Dependencies stocked — a tidy race!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: propagating SQL digest for MPP task metadata across the specified packages.
Description check ✅ Passed The description comprehensively covers the issue, changes, testing approach, validation commands, and includes a detailed before/after log comparison demonstrating the enhancement.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Command failed


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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
DEPS.bzl (1)

6816-6826: Track upstream merge for kvproto fork.

The kvproto dependency is temporarily pointing to a forked version (JaySon-Huang/kvproto) to consume the TaskMeta.sql_digest field before it's merged upstream. Ensure this is tracked (e.g., via a follow-up issue or the referenced #66762) so the dependency can be switched back to github.com/pingcap/kvproto once the upstream kvproto PR is merged.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@DEPS.bzl` around lines 6816 - 6826, The DEPS.bzl entry for
name="com_github_pingcap_kvproto" currently points to the JaySon-Huang fork to
consume TaskMeta.sql_digest; create a tracked follow-up (issue or link to
`#66762`) and add a TODO comment in the same DEPS.bzl entry referencing that
tracking issue/PR; when upstream kvproto is merged, update importpath back to
"github.com/pingcap/kvproto", replace strip_prefix, sha256 and the urls to the
official upstream release, and document the change in the follow-up so we can
revert the forked dependency cleanly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@go.mod`:
- Around line 378-379: The go.mod contains a temporary replace directive
pointing to a personal fork (github.com/JaySon-Huang/kvproto) which must be
removed before merge; once the upstream pingcap/kvproto contains the
TaskMeta.SqlDigest field, delete the replace line and update the module
dependency to the canonical github.com/pingcap/kvproto module (ensuring the
version includes TaskMeta.SqlDigest) so imports that reference
TaskMeta.SqlDigest resolve to the official upstream package rather than the
fork.

---

Nitpick comments:
In `@DEPS.bzl`:
- Around line 6816-6826: The DEPS.bzl entry for
name="com_github_pingcap_kvproto" currently points to the JaySon-Huang fork to
consume TaskMeta.sql_digest; create a tracked follow-up (issue or link to
`#66762`) and add a TODO comment in the same DEPS.bzl entry referencing that
tracking issue/PR; when upstream kvproto is merged, update importpath back to
"github.com/pingcap/kvproto", replace strip_prefix, sha256 and the urls to the
official upstream release, and document the change in the follow-up so we can
revert the forked dependency cleanly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 645f4ad1-6b39-4415-a206-04e789ae722a

📥 Commits

Reviewing files that changed from the base of the PR and between 999e8f4 and 528b1a7.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • DEPS.bzl
  • go.mod
  • pkg/executor/internal/mpp/local_mpp_coordinator.go
  • pkg/kv/mpp.go
  • pkg/store/copr/mpp.go

@JaySon-Huang
Copy link
Contributor Author

/cc @windtalker @gengliqi PTAL. Can we push forward the kvproto changes and these tidb changes?

@JaySon-Huang
Copy link
Contributor Author

@coderabbitai review

@ti-chi-bot
Copy link

ti-chi-bot bot commented Mar 10, 2026

@JaySon-Huang: 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-build-next-gen 7b82377 link true /test pull-build-next-gen
idc-jenkins-ci-tidb/build 7b82377 link true /test build
idc-jenkins-ci-tidb/unit-test 7b82377 link true /test unit-test
idc-jenkins-ci-tidb/check_dev 7b82377 link true /test check-dev
idc-jenkins-ci-tidb/check_dev_2 7b82377 link true /test check-dev2
pull-integration-realcluster-test-next-gen 7b82377 link true /test pull-integration-realcluster-test-next-gen
pull-unit-test-next-gen 7b82377 link true /test pull-unit-test-next-gen

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.

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

why this pr has many unrelated changes?

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

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants