Skip to content

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

Open
JaySon-Huang wants to merge 3 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 3 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

    • SQL digest is now propagated throughout distributed query execution for enhanced query tracking and diagnostics.
    • Expanded logging in query execution to include diagnostic identifiers.
  • Chores

    • Updated dependencies and build configuration for Go modules.

@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

📝 Walkthrough

Walkthrough

The PR adds SQL digest tracking throughout the MPP (Massively Parallel Processing) execution pipeline, extracting SQL digests from session context and propagating them through dispatch requests and task metadata. It also expands Bazel dependencies and adds a Go module replacement for kvproto.

Changes

Cohort / File(s) Summary
MPP SQL Digest Propagation
pkg/executor/internal/mpp/local_mpp_coordinator.go, pkg/kv/mpp.go, pkg/store/copr/mpp.go
Adds SQLDigest/SqlDigest field to MPPDispatchRequest and TaskMeta, extracts digest from session context, and threads it through dispatch request creation, task metadata construction, and connection establishment. Includes minor comment corrections.
Build Configuration
DEPS.bzl, go.mod
Introduces multiple new go_repository entries for external Golang dependencies with specific versions, sha256 hashes, and URLs. Adds module replacement mapping for github.com/pingcap/kvproto to a fork version.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Through the MPP tunnels, digests now flow,
Each task bears a marker, just so,
SQL whispers traced with care,
Dependencies squared—a pair,
The digest hops forward, here we go!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: propagating SQL digest for MPP task metadata across the specified packages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description comprehensively addresses all required sections with clear problem statement, detailed change explanation, test validation, and release notes.

✏️ 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

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

Comment on lines +378 to +379

replace github.com/pingcap/kvproto => github.com/JaySon-Huang/kvproto v0.0.0-20260307160337-78644d3dc465
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if the upstream kvproto has the SqlDigest field in TaskMeta

# Search for SqlDigest in the kvproto mpp.proto or generated Go files
echo "Checking if SqlDigest exists in pingcap/kvproto master branch..."
curl -s "https://raw.githubusercontent.com/pingcap/kvproto/master/pkg/mpp/mpp.pb.go" | grep -i "SqlDigest" || echo "SqlDigest not found in upstream kvproto master"

Repository: pingcap/tidb

Length of output: 167


🏁 Script executed:

# Check what files were changed in this PR involving go.mod changes
# Look for Bazel-related metadata or BUILD files that may have been modified
git log -1 --name-only --pretty=format: | head -20

Repository: pingcap/tidb

Length of output: 1336


🏁 Script executed:

# Also check if there are any BUILD, BUILD.bazel files or bazel-related changes
fd -e BUILD -e BUILD.bazel -e WORKSPACE | head -20

Repository: pingcap/tidb

Length of output: 38


🏁 Script executed:

# Check the actual go.mod file to confirm the replace directive
if [ -f go.mod ]; then
  echo "=== go.mod content around lines 375-380 ==="
  sed -n '375,380p' go.mod
fi

Repository: pingcap/tidb

Length of output: 429


🏁 Script executed:

# Search for any bazel-related files or configuration
find . -type f \( -name "*.bazel" -o -name "BUILD*" -o -name "WORKSPACE*" \) 2>/dev/null | grep -v node_modules | head -20

Repository: pingcap/tidb

Length of output: 592


🏁 Script executed:

# Check if there are go_mod_* or bazel_* related changes
git status --short 2>/dev/null | grep -E "(bazel|BUILD|WORKSPACE|go\.(mod|sum))" || echo "No bazel/go.mod changes in current status"

Repository: pingcap/tidb

Length of output: 97


🏁 Script executed:

# Check if MODULE.bazel or other bazel files were modified
# Look at the git diff to see what changed with bazel files
git diff --name-only HEAD~1..HEAD 2>/dev/null | grep -E "(\.bazel|MODULE|go\.mod|go\.sum)" || echo "Cannot get git diff"

Repository: pingcap/tidb

Length of output: 75


🏁 Script executed:

# Alternative: Check git log to see what files were changed in the latest commit
git log -1 --name-status 2>/dev/null | grep -E "(\.bazel|MODULE|go\.mod|go\.sum)" || echo "Cannot get git log details"

Repository: pingcap/tidb

Length of output: 30429


Remove temporary kvproto replace directive before merge.

This replace directive points to a personal fork (github.com/JaySon-Huang/kvproto). Ensure the upstream kvproto PR containing the TaskMeta.SqlDigest field is merged into pingcap/kvproto, then update the canonical dependency and remove this replace directive.

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

In `@go.mod` around lines 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.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Mar 7, 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-unit-test-next-gen 528b1a7 link true /test pull-unit-test-next-gen
pull-build-next-gen 528b1a7 link true /test pull-build-next-gen
idc-jenkins-ci-tidb/unit-test 528b1a7 link true /test unit-test
idc-jenkins-ci-tidb/check_dev 528b1a7 link true /test check-dev
pull-integration-realcluster-test-next-gen 528b1a7 link true /test pull-integration-realcluster-test-next-gen
idc-jenkins-ci-tidb/check_dev_2 528b1a7 link true /test check-dev2
idc-jenkins-ci-tidb/build 528b1a7 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.

@JaySon-Huang
Copy link
Contributor Author

/cc @windtalker @gengliqi PTAL. Can we push forward the kvproto changes and these tidb 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.

1 participant