Skip to content

planner: use ExplainInfo/StringWithCtx for columns in EXPLAIN output paths - #67340

Merged
ti-chi-bot[bot] merged 4 commits into
pingcap:masterfrom
henrybw:migrate-explain-plantree-1
Mar 27, 2026
Merged

ti-chi-bot[bot] merged 4 commits into
pingcap:masterfrom
henrybw:migrate-explain-plantree-1

Conversation

@henrybw

@henrybw henrybw commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #67112

Problem Summary:

Five call sites in EXPLAIN rendering used Column.String() or %v to format columns, which always emits "Column#N" regardless of the explain format. Switch to ExplainInfo(ctx) or StringWithCtx(ctx, redact) so that "Column#N" is stripped when format='plan_tree'.

What changed and how does it work?

  • index_join_path.go: In indexJoinPathRangeInfo, use StringWithCtx to also respect tidb_redact_log, consistent with adjacent access condition rendering.
  • physical_plan_misc.go: In RuntimeFilter.ExplainInfo, add an EvalContext parameter, and use ExplainInfo(ctx) for source/target expressions.
  • physical_hash_join.go: Pass evalCtx to RuntimeFilter.ExplainInfo.
  • physical_table_scan.go: Pass ectx to RuntimeFilter.ExplainInfo; use ExplainInfo for ANN index distance projection column.
  • physical_window.go: Use ExplainInfo for window function output columns in FormatWindowFuncDescs.
  • Update existing test cases that relied on the incorrect output by encoding column numbers into format='plan_tree' output.

No functional changes for existing explain formats (brief, row, verbose) since shouldRemoveColumnNumbers only activates for plan_tree.

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

  • Refactor
    • EXPLAIN output now uses context-aware formatting for expressions and runtime filters, producing more consistent, readable plan descriptions.
  • Tests
    • Updated expected EXPLAIN/plan_tree outputs across test fixtures to remove numeric column-id suffixes from function and window-result renderings (e.g., "Column#N" → "Column").

…utput paths

Five call sites in `EXPLAIN` rendering used `Column.String()` or `%v` to
format columns, which always emits "Column#N" regardless of the explain
format. Switch to `ExplainInfo(ctx)` or `StringWithCtx(ctx, redact)` so
that "Column#N" is stripped when `format='plan_tree'`.

- index_join_path.go: In `indexJoinPathRangeInfo`, use `StringWithCtx` to
  also respect `tidb_redact_log`, consistent with adjacent access
  condition rendering.
- physical_plan_misc.go: In `RuntimeFilter.ExplainInfo`, add an
  `EvalContext` parameter, and use `ExplainInfo(ctx)` for source/target
  expressions.
- physical_hash_join.go: Pass `evalCtx` to `RuntimeFilter.ExplainInfo`.
- physical_table_scan.go: Pass `ectx` to `RuntimeFilter.ExplainInfo`;
  use `ExplainInfo` for ANN index distance projection column.
- physical_window.go: Use `ExplainInfo` for window function output
  columns in `FormatWindowFuncDescs`.

No functional changes for existing explain formats (brief, row, verbose)
since `shouldRemoveColumnNumbers` only activates for plan_tree.
@ti-chi-bot ti-chi-bot Bot added the release-note-none Denotes a PR that doesn't merit a release note. label Mar 27, 2026
@pantheon-ai

pantheon-ai Bot commented Mar 27, 2026 •

Copy link
Copy Markdown

Review Complete

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

ℹ️ Learn more details on Pantheon AI.

@ti-chi-bot ti-chi-bot Bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. sig/planner SIG: Planner labels Mar 27, 2026
@tiprow

tiprow Bot commented Mar 27, 2026

Copy link
Copy Markdown

Hi @henrybw. 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

coderabbitai Bot commented Mar 27, 2026 •

Copy link
Copy Markdown

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

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: 32c2f593-649e-4b36-96d5-dc7abc42d78c

📥 Commits

Reviewing files that changed from the base of the PR and between ac3aedc and 48576cb.

📒 Files selected for processing (7)
  • pkg/planner/core/casetest/hint/testdata/integration_suite_out.json
  • pkg/planner/core/casetest/hint/testdata/integration_suite_xut.json
  • pkg/planner/core/casetest/rule/rule_outer2inner_test.go
  • pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json
  • pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_xut.json
  • pkg/planner/core/casetest/windows/testdata/window_push_down_suite_out.json
  • pkg/planner/core/casetest/windows/testdata/window_push_down_suite_xut.json
✅ Files skipped from review due to trivial changes (3)
  • pkg/planner/core/casetest/rule/rule_outer2inner_test.go
  • pkg/planner/core/casetest/hint/testdata/integration_suite_xut.json
  • pkg/planner/core/casetest/windows/testdata/window_push_down_suite_out.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/planner/core/casetest/windows/testdata/window_push_down_suite_xut.json

📝 Walkthrough

Walkthrough

This PR threads evaluation context into planner explain rendering: ExplainInfo/StringWithCtx now receive an EvalContext, and various explain outputs (runtime filters, window function columns, index-join range predicates) are rendered with context-aware formatting; many test expectations were updated to remove #<id> suffixes from Column.

Changes

Cohort / File(s) Summary
Runtime filter core
pkg/planner/core/operator/physicalop/physical_plan_misc.go
RuntimeFilter.ExplainInfo signature extended to accept expression.EvalContext and uses it to render src/target expressions via context-aware explain calls.
Runtime filter call sites
pkg/planner/core/operator/physicalop/physical_hash_join.go, pkg/planner/core/operator/physicalop/physical_table_scan.go
Call sites updated to pass the evaluation context (evalCtx/ectx) into runtimeFilter.ExplainInfo; table-scan projection uses ExplainInfo(ectx) for column rendering.
Window explain formatting
pkg/planner/core/operator/physicalop/physical_window.go
Window function descriptor formatting switched from String() to ExplainInfo(ctx), affecting desc -> column text produced by FormatWindowFuncDescs.
Index-join range formatting
pkg/planner/core/index_join_path.go
Moved EvalContext/redaction setup outside loop; use StringWithCtx(ectx, redact) for chosen index column expressions and outer join keys when building equality predicates.
Test expectations (many files)
pkg/planner/core/casetest/..., pkg/planner/core/casetest/testdata/*, tests/integrationtest/..., pkg/planner/core/casetest/enforcempp/*, pkg/planner/core/casetest/windows/testdata/*, pkg/planner/core/casetest/vectorsearch/testdata/*
Bulk updates to JSON/result test fixtures to normalize explain output: remove #<id> suffixes from Column and adjust other explain strings to match context-aware rendering.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

size/M

Suggested reviewers

  • hawkingrei
  • qw4990
  • AilinKid
  • winoros

Poem

🐰 I hopped through explain trails with care,
Threaded context in strings with gentle flair,
Columns dropped numbers and learned to be clear,
Filters and windows now speak in one ear,
Snack on a carrot—plans cheerfully share 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the main change: switching to context-aware formatting methods (ExplainInfo/StringWithCtx) for columns in EXPLAIN output to properly handle plan_tree format.
Description check ✅ Passed The PR description follows the template structure with Issue Number, Problem Summary, What Changed sections, and includes a completed checklist indicating unit and integration tests were included. All required sections are present and adequately filled.

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

@hawkingrei

Copy link
Copy Markdown
Contributor

/ok-to-test

@ti-chi-bot ti-chi-bot Bot added the ok-to-test Indicates a PR is ready to be tested. label Mar 27, 2026
@terry1purcell
terry1purcell requested a review from Copilot March 27, 2026 00:27

Copilot AI 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.

Pull request overview

This PR standardizes how columns/expressions are formatted in planner EXPLAIN rendering paths by switching a few remaining call sites from Column.String() / %v to context-aware formatting (ExplainInfo(ctx) / StringWithCtx(ctx, redact)), which allows format='plan_tree' to omit synthetic Column#N suffixes.

Changes:

  • Use Column.ExplainInfo(ctx) for window output columns and ANN distance projection columns in EXPLAIN strings.
  • Update RuntimeFilter.ExplainInfo to accept an expression.EvalContext and render source/target expressions via ExplainInfo(ctx).
  • Ensure index-join range info uses StringWithCtx(ectx, redact) so output respects tidb_redact_log.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/planner/core/operator/physicalop/physical_window.go Render window function output columns via ExplainInfo(ctx) to support plan_tree formatting.
pkg/planner/core/operator/physicalop/physical_table_scan.go Pass eval context into runtime filter explain; use ExplainInfo for ANN distance projection column.
pkg/planner/core/operator/physicalop/physical_plan_misc.go Extend RuntimeFilter.ExplainInfo with eval context and use ExplainInfo(ctx) for columns.
pkg/planner/core/operator/physicalop/physical_hash_join.go Pass eval context into runtime filter explain rendering.
pkg/planner/core/index_join_path.go Use StringWithCtx(ectx, redact) for join key columns in range info, respecting redaction settings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pantheon-ai pantheon-ai 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.

✅ Code looks good. No issues found.

@henrybw

henrybw commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

Hmm, seems like I missed some test cases that need updating.

@henrybw

henrybw commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

/hold

@ti-chi-bot ti-chi-bot Bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 27, 2026
@henrybw
henrybw force-pushed the migrate-explain-plantree-1 branch from a6c8c19 to 0d76105 Compare March 27, 2026 01:38
@henrybw
henrybw force-pushed the migrate-explain-plantree-1 branch from 0d76105 to d2872a9 Compare March 27, 2026 01:41
@henrybw

henrybw commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 27, 2026
@codecov

codecov Bot commented Mar 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.6315%. Comparing base (23f315b) to head (48576cb).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #67340        +/-   ##
================================================
- Coverage   77.8320%   77.6315%   -0.2005%     
================================================
  Files          2023       1943        -80     
  Lines        556131     543641     -12490     
================================================
- Hits         432848     422037     -10811     
- Misses       121539     121602        +63     
+ Partials       1744          2      -1742     
Flag Coverage Δ
integration 41.0061% <40.0000%> (-7.1206%) ⬇️
unit 76.7615% <100.0000%> (+0.3907%) ⬆️

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

Components Coverage Δ
dumpling 61.5065% <ø> (ø)
parser ∅ <ø> (∅)
br 48.9203% <ø> (-11.9800%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 27, 2026
@henrybw

henrybw commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

/retest-required

@0xPoe 0xPoe 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.

Thanks! :shipit:

@ti-chi-bot

ti-chi-bot Bot commented Mar 27, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 0xPoe, hawkingrei

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:

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 27, 2026
@ti-chi-bot

ti-chi-bot Bot commented Mar 27, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-03-27 02:34:55.518325507 +0000 UTC m=+494891.554395767: ☑️ agreed by hawkingrei.
  • 2026-03-27 08:35:24.240738185 +0000 UTC m=+516520.276808455: ☑️ agreed by 0xPoe.

@0xPoe

0xPoe commented Mar 27, 2026

Copy link
Copy Markdown
Member

/test all

@hawkingrei

Copy link
Copy Markdown
Contributor

/retest

1 similar comment
@hawkingrei

Copy link
Copy Markdown
Contributor

/retest

@ti-chi-bot
ti-chi-bot Bot merged commit 63c135e into pingcap:master Mar 27, 2026
35 checks passed
@henrybw
henrybw deleted the migrate-explain-plantree-1 branch March 27, 2026 18:20
bitloi pushed a commit to bitloi/tidb that referenced this pull request Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner 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.

4 participants