Skip to content

util: add support columnar scan details#69331

Merged
ti-chi-bot[bot] merged 4 commits into
pingcap:masterfrom
yongman:columnar-scan-details
Jun 24, 2026
Merged

util: add support columnar scan details#69331
ti-chi-bot[bot] merged 4 commits into
pingcap:masterfrom
yongman:columnar-scan-details

Conversation

@yongman

@yongman yongman commented Jun 18, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: close #69353

Problem Summary:
There is no execution stats summary when the query using columnar instead of tiflash.

What changed and how does it work?

Add columnarScanContext to TiflashStats and collect the stats from tipb::ColumnarScanContext.

TiDB root@localhost:test> explain analyze select * from t;
+----------------------+---------+---------+--------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+----------+------+
| id                   | estRows | actRows | task         | access object | execution info                                                                                                                                                                                                                                                                                                                                                                                                | operator info                             | memory   | disk |
+----------------------+---------+---------+--------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+----------+------+
| TableReader_12       | 8204.00 | 8204    | root         | partition:all | time:63.5ms, loops:10, RU:5.38, cop_task: {num: 2, max: 0s, min: 0s, avg: 0s, p95: 0s, copr_cache_hit_ratio: 0.00}                                                                                                                                                                                                                                                                                            | MppVersion: 2, data:ExchangeSender_11     | 192.7 KB | N/A  |
| └─ExchangeSender_11  | 8204.00 | 8204    | mpp[tiflash] |               | tiflash_task:{time:52.8ms, loops:1, threads:1}                                                                                                                                                                                                                                                                                                                                                                | ExchangeType: PassThrough                 | N/A      | N/A  |
|   └─TableFullScan_10 | 8204.00 | 8204    | mpp[tiflash] | table:t       | tiflash_task:{time:44.8ms, loops:1, threads:1}, columnar_scan:{mvcc_input_rows:8204, mvcc_input_bytes:360976, mvcc_output_rows:8204, regions:1, read_tasks:1, physical_tables:3, columns:3, user_read_bytes:155876, read_block:8ms, serialize_block:0ms, init_reader:12ms, prefetch:0ms, deserialize_block:4ms, rough_check:{total:0, selected:0, skipped:0, unknown:0}, remote_segments:0, total_segments:4} | keep order:false, PartitionTableScan:true | N/A      | N/A  |
+----------------------+---------+---------+--------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+----------+------+

3 rows in set
Time: 0.077s

Deps

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.

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

Summary by CodeRabbit

  • New Features

    • Added support for TiFlash columnar scan context tracking with detailed performance metrics including read/serialize/deserialization timings and segment statistics.
  • Chores

    • Updated dependencies to latest versions.
  • Tests

    • Added comprehensive test coverage for TiFlash columnar scan context statistics aggregation.

Signed-off-by: Ray Yan <yming0221@gmail.com>
@ti-chi-bot

ti-chi-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jun 18, 2026
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

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: c89115a3-6bc5-4479-99de-4cbc9f155c7c

📥 Commits

Reviewing files that changed from the base of the PR and between 3286fac and 5bf41d8.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • pkg/util/execdetails/execdetails_test.go
  • pkg/util/execdetails/tiflash_stats.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/util/execdetails/tiflash_stats.go
  • pkg/util/execdetails/execdetails_test.go

📝 Walkthrough

Walkthrough

The PR bumps the github.com/pingcap/tipb dependency to a new commit in both go.mod and DEPS.bzl, then adds a TiFlashColumnarScanContext struct with full Clone/Merge/String/Empty/mergeExecSummary methods in tiflash_stats.go, wires it into basicCopRuntimeStats Clone/Merge/mergeExecSummary and CopRuntimeStats.String in runtime_stats.go, and validates the end-to-end behavior with new tests.

Changes

TiFlash Columnar Scan Context Stats

Layer / File(s) Summary
tipb dependency bump and TiFlashColumnarScanContext type definition
go.mod, DEPS.bzl, pkg/util/execdetails/tiflash_stats.go
Updates go.mod and DEPS.bzl to the new tipb version. Adds columnarScanContext TiFlashColumnarScanContext field to TiflashStats and declares the TiFlashColumnarScanContext struct with hasStats, region/task/table/column counters, MVCC row/byte metrics, block timing breakdowns, rough-check pack counters, and segment/deserialization metrics.
TiFlashColumnarScanContext methods and runtime stats integration
pkg/util/execdetails/tiflash_stats.go, pkg/util/execdetails/runtime_stats.go
Implements Clone, String (emitting columnar_scan:{...}), Merge, mergeExecSummary, and Empty on TiFlashColumnarScanContext. Wires columnarScanContext into basicCopRuntimeStats.Clone, Merge, and mergeExecSummary, and updates CopRuntimeStats.String to prefer columnarScanContext over scanContext when non-empty.
Columnar scan context test helper and test case
pkg/util/execdetails/execdetails_test.go
Adds mockExecutorExecutionSummaryForTiFlashColumnar to build a ColumnarScanContext-populated ExecutorExecutionSummary. TestColumnarScanContextStats asserts that two recorded cop tasks produce a CopStats string containing columnar_scan:{...} with expected aggregated values and that zeroed columnar input still emits columnar_scan:{ while omitting tiflash_scan:{.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

size/M, approved, lgtm

Suggested reviewers

  • AilinKid

Poem

🐰 A columnar scan, so fast and bright,
New fields and methods brought to light.
Regions, tasks, and MVCC rows,
Timing blocks in tidy prose.
The rabbit merged them, row by row—
columnar_scan:{...} steals the show! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'util: add support columnar scan details' accurately summarizes the main change: adding columnar scan execution statistics support to the util package's execdetails module.
Description check ✅ Passed The PR description includes all required sections: linked issue (#69353), problem summary, detailed explanation of changes, test coverage (unit and manual tests documented), release notes, and side effects checklist properly filled.
Linked Issues check ✅ Passed The PR fully addresses issue #69353 by implementing columnar scan context tracking and reporting in TiflashStats with comprehensive metrics including MVCC stats, timing breakdowns, and rough check counters as required by the enhancement.
Out of Scope Changes check ✅ Passed All code changes are directly related to the linked issue objective: dependency updates to tipb (supporting the new ColumnarScanContext), and implementation of columnar scan statistics collection and formatting in the execdetails module.

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

✨ 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.

@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed do-not-merge/needs-tests-checked do-not-merge/needs-linked-issue labels Jun 18, 2026
@yongman yongman marked this pull request as ready for review June 22, 2026 06:44
@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 22, 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

🧹 Nitpick comments (1)
pkg/util/execdetails/execdetails_test.go (1)

754-783: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add one assertion for s.stats.String() to lock both TiFlash string paths.

This test currently covers CopRuntimeStats.String() only; adding the basicCopRuntimeStats.String() assertion here will catch columnar/reporting divergence earlier.

Suggested test addition
diff --git a/pkg/util/execdetails/execdetails_test.go b/pkg/util/execdetails/execdetails_test.go
@@
 	stats.RecordOneCopTask(1, kv.TiFlash, execSummary)
 	s := stats.GetCopStats(1)
 	require.Equal(t, "tiflash_task:{time:1ns, loops:2, threads:1}, columnar_scan:{mvcc_input_rows:100, mvcc_input_bytes:4096, mvcc_output_rows:80, regions:2, read_tasks:4, physical_tables:3, columns:5, user_read_bytes:2048, read_block:7ms, serialize_block:8ms, init_reader:9ms, prefetch:10ms, deserialize_block:17ms, rough_check:{total:11, selected:12, skipped:13, unknown:14}, remote_segments:15, total_segments:16}", s.String())
+	require.Contains(t, s.stats.String(), "columnar_scan:{")
+	require.NotContains(t, s.stats.String(), "tiflash_scan:{")
🤖 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/util/execdetails/execdetails_test.go` around lines 754 - 783, The test
function TestColumnarScanContextStats currently only validates the String()
output of the CopRuntimeStats object returned by GetCopStats, but does not test
the underlying basicCopRuntimeStats.String() representation. Add an additional
assertion after the first require.Equal call that validates s.stats.String() to
ensure both the columnar and basic reporting string paths are tested. This will
help catch any divergence between these two representations earlier in testing.
🤖 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/util/execdetails/runtime_stats.go`:
- Around line 170-175: The basicCopRuntimeStats.String method unconditionally
renders legacy scan stats via scanContext.String() even when columnarScanContext
is populated, which hides columnar metrics. Update the String method to check if
columnarScanContext exists and is non-nil, and if so, render
columnarScanContext.String() instead of scanContext.String(). This ensures
consistency with how CopRuntimeStats.String handles this scenario and prevents
columnar metrics from being hidden behind legacy scan stats.

---

Nitpick comments:
In `@pkg/util/execdetails/execdetails_test.go`:
- Around line 754-783: The test function TestColumnarScanContextStats currently
only validates the String() output of the CopRuntimeStats object returned by
GetCopStats, but does not test the underlying basicCopRuntimeStats.String()
representation. Add an additional assertion after the first require.Equal call
that validates s.stats.String() to ensure both the columnar and basic reporting
string paths are tested. This will help catch any divergence between these two
representations earlier in testing.
🪄 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: e9f7ae63-adeb-4707-b7f2-b9288df5a930

📥 Commits

Reviewing files that changed from the base of the PR and between b562c0e and 3286fac.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • DEPS.bzl
  • br/pkg/task/BUILD.bazel
  • br/pkg/task/operator/BUILD.bazel
  • go.mod
  • pkg/util/execdetails/execdetails_test.go
  • pkg/util/execdetails/runtime_stats.go
  • pkg/util/execdetails/tiflash_stats.go

Comment thread pkg/util/execdetails/runtime_stats.go
@yongman

yongman commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

/retest

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 148 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.1166%. Comparing base (5c9198e) to head (5bf41d8).
⚠️ Report is 11 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69331        +/-   ##
================================================
- Coverage   76.3197%   74.1166%   -2.2031%     
================================================
  Files          2041       2040         -1     
  Lines        561547     580049     +18502     
================================================
+ Hits         428571     429913      +1342     
- Misses       132072     149677     +17605     
+ Partials        904        459       -445     
Flag Coverage Δ
integration 40.7431% <0.0000%> (+1.1002%) ⬆️

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

Components Coverage Δ
dumpling 60.4610% <ø> (ø)
parser ∅ <ø> (∅)
br 44.6533% <ø> (-18.1633%) ⬇️
🚀 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 the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 22, 2026
Comment thread pkg/util/execdetails/tiflash_stats.go Outdated
Comment thread pkg/util/execdetails/tiflash_stats.go Outdated
Signed-off-by: Ray Yan <yming0221@gmail.com>
@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 Jun 23, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

@JaySon-Huang: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

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.

@yongman

yongman commented Jun 23, 2026

Copy link
Copy Markdown
Member Author

/retest-required

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 23, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-06-22 10:28:04.645970577 +0000 UTC m=+1992585.716287957: ☑️ agreed by coocood.
  • 2026-06-23 04:40:20.61004501 +0000 UTC m=+8904.273270523: ☑️ agreed by 3pointer.

@yongman

yongman commented Jun 23, 2026

Copy link
Copy Markdown
Member Author

/assign @bb7133

@bb7133 bb7133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot

ti-chi-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 3pointer, bb7133, coocood, JaySon-Huang

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

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [3pointer,bb7133,coocood]

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 approved label Jun 23, 2026
@dillon-zheng

Copy link
Copy Markdown
Contributor

/check-cla

@ti-chi-bot ti-chi-bot Bot merged commit 9f419ca into pingcap:master Jun 24, 2026
34 checks passed
@yongman

yongman commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

/cherry-pick release-nextgen-202603

@yongman yongman deleted the columnar-scan-details branch June 24, 2026 06:02
@ti-chi-bot

Copy link
Copy Markdown
Member

@yongman: new pull request created to branch release-nextgen-202603: #69424.
But this PR has conflicts, please resolve them!

Details

In response to this:

/cherry-pick release-nextgen-202603

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 ti-community-infra/tichi repository.

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

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

columnar: add execution stats summary in explain

7 participants