Skip to content

Comments

planner: implements support for dumping multiple SQL statements in a single PLAN REPLAYER DUMP EXPLAIN command#66162

Merged
ti-chi-bot[bot] merged 5 commits intopingcap:masterfrom
qw4990:fix-66151
Feb 11, 2026
Merged

planner: implements support for dumping multiple SQL statements in a single PLAN REPLAYER DUMP EXPLAIN command#66162
ti-chi-bot[bot] merged 5 commits intopingcap:masterfrom
qw4990:fix-66151

Conversation

@qw4990
Copy link
Contributor

@qw4990 qw4990 commented Feb 9, 2026

What problem does this PR solve?

Issue Number: close #66151

Problem Summary: Implements support for dumping multiple SQL statements in a single PLAN REPLAYER DUMP EXPLAIN command, addressing issue #66151.

What changed and how does it work?

Parser

  • Added StmtList []string field to PlanReplayerStmt AST
  • Added grammar rules for PLAN REPLAYER DUMP EXPLAIN ( 'sql1', 'sql2', ... )
  • Updated Restore method to handle multi-SQL format

Planner/Executor

  • Added StmtList field to PlanReplayer plan
  • Executor builder parses SQL strings from StmtList into AST nodes

Dump Output

  • Single SQL (backward compatible): sql/sql0.sql + explain.txt
  • Multiple SQLs: sql/sql0.sql, sql/sql1.sql, ... + explain/explain0.txt, explain/explain1.txt, ...
  • Fixed table extraction to properly handle unqualified table names

Example

PLAN REPLAYER DUMP EXPLAIN (
    'SELECT * FROM t1 WHERE id = 1',
    'SELECT * FROM t1 WHERE id > 1',
    'SELECT * FROM t2 WHERE status = "active"'
);

Output zip contains:

  1. /sql/sql0.sql, /sql/sql1.sql, /sql/sql2.sql
  2. /explain/explain0.txt, /explain/explain1.txt, /explain/explain2.txt
  3. Schema/stats files for referenced tables (collected once)

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

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-tests-checked labels Feb 9, 2026
@pantheon-ai
Copy link

pantheon-ai bot commented Feb 9, 2026

This PR adds support for dumping multiple SQL statements in a single PLAN REPLAYER DUMP EXPLAIN by extending the parser/AST and wiring StmtList through the planner/executor to parse each SQL into AST nodes. It updates dump output to generate sql/sql0.sql, sql/sql1.sql, … and matching explain/explain0.txt, explain/explain1.txt, … while keeping single-SQL behavior backward compatible. It also fixes table extraction for unqualified table names.

Open in Web
Learn more about Pantheon AI

@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. sig/planner SIG: Planner labels Feb 9, 2026
@tiprow
Copy link

tiprow bot commented Feb 9, 2026

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

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 9, 2026

@pantheon-bot please review

@pantheon-ai
Copy link

pantheon-ai bot commented Feb 9, 2026

✅ Review Complete

I've completed a comprehensive review of PR #66162 (planner: implements support for dumping multiple SQL statements in a single PLAN REPLAYER DUMP EXPLAIN command).

Review Summary

  • Status: 1 issue found (P2)
  • P0/P1 Issues: None ✓
  • P2 Issues: 1 (usability concern)

Key Findings

P2: Misleading error for multi-SQL parse failures

  • Location: pkg/executor/builder.go:1189
  • Impact: When SQL statements in the multi-SQL list fail to parse, users receive a generic "plan replayer: sql is empty" error instead of the actual parse error, making debugging difficult
  • Details: Parse errors are only logged as warnings, and the executor creates an empty replayer file before failing
  • Recommendation: Propagate parse errors properly with statement index information

👉 View detailed review comments

Overall Assessment

No blocking issues found. The implementation correctly adds multi-SQL support to PLAN REPLAYER DUMP EXPLAIN with proper backward compatibility. The P2 issue is a usability improvement that can be addressed in a follow-up.

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 9, 2026

/test mysql-test

@tiprow
Copy link

tiprow bot commented Feb 9, 2026

@qw4990: 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.

Details

In response to this:

/test mysql-test

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.

@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.6517%. Comparing base (eb2cd22) to head (0b80fb7).
⚠️ Report is 20 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #66162        +/-   ##
================================================
+ Coverage   77.7712%   79.6517%   +1.8804%     
================================================
  Files          2001       1952        -49     
  Lines        546334     538542      -7792     
================================================
+ Hits         424891     428958      +4067     
+ Misses       119783     108102     -11681     
+ Partials       1660       1482       -178     
Flag Coverage Δ
integration 47.9114% <42.8571%> (-0.2824%) ⬇️
unit 76.8605% <90.9090%> (+0.4552%) ⬆️

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

Components Coverage Δ
dumpling 56.7974% <ø> (ø)
parser ∅ <ø> (∅)
br 65.7255% <ø> (+4.7727%) ⬆️
🚀 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.

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 9, 2026

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Feb 9, 2026
@hawkingrei
Copy link
Member

/retest

for i := 1; i <= numTables; i++ {
tableName := fmt.Sprintf("t_dump_multi_%d", i)
require.Contains(t, names, fmt.Sprintf("stats/test.%s.json", tableName))
require.Contains(t, names, fmt.Sprintf("schema/test.%s.schema.txt", tableName))
Copy link
Member

Choose a reason for hiding this comment

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

The tests are a bit thin; can we have AI generate some examples with multiple databases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more databases.

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Feb 10, 2026
ctx.WritePlain(")")
return nil
}
if n.Stmt == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: When will n.Stmt is nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like we can specify a SQL file, for example: plan replayer dump explain {sql.txt}:
image

{"plan replayer dump explain ('SELECT * FROM t1', 'SELECT * FROM t2')",
"PLAN REPLAYER DUMP EXPLAIN ('SELECT * FROM t1', 'SELECT * FROM t2')"},
{"plan replayer dump explain analyze ('SELECT * FROM t1')",
"PLAN REPLAYER DUMP EXPLAIN ANALYZE ('SELECT * FROM t1')"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add edge case that with empty and non empty in the stmt list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll error if it's empty. I added an test in TestPlanReplayerDumpMultiple:
image

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 10, 2026
@guo-shaoge
Copy link
Collaborator

/hold

@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 10, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-10 02:17:01.490163925 +0000 UTC m=+237637.184303765: ☑️ agreed by hawkingrei.
  • 2026-02-10 06:18:48.514536786 +0000 UTC m=+252144.208676626: ☑️ agreed by guo-shaoge.

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 10, 2026
@guo-shaoge
Copy link
Collaborator

guo-shaoge commented Feb 10, 2026

feel free to unhold if you're ready to merge

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 10, 2026

/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 Feb 10, 2026
@qw4990
Copy link
Contributor Author

qw4990 commented Feb 10, 2026

The doc PR: pingcap/docs#22429

Copy link
Contributor

@D3Hunter D3Hunter left a comment

Choose a reason for hiding this comment

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

/approve

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 10, 2026

/test build

@tiprow
Copy link

tiprow bot commented Feb 10, 2026

@qw4990: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

/test fast_test_tiprow
/test tidb_parser_test

Use /test all to run all jobs.

Details

In response to this:

/test build

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.

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 10, 2026

/test pull-build-next-gen

@tiprow
Copy link

tiprow bot commented Feb 10, 2026

@qw4990: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

/test fast_test_tiprow
/test tidb_parser_test

Use /test all to run all jobs.

Details

In response to this:

/test pull-build-next-gen

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.

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 10, 2026

/test check-dev2
/test pull-br-integration-test

@tiprow
Copy link

tiprow bot commented Feb 10, 2026

@qw4990: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

/test fast_test_tiprow
/test tidb_parser_test

Use /test all to run all jobs.

Details

In response to this:

/test check-dev2
/test pull-br-integration-test

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.

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 10, 2026

/test check-dev2

@tiprow
Copy link

tiprow bot commented Feb 10, 2026

@qw4990: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

/test fast_test_tiprow
/test tidb_parser_test

Use /test all to run all jobs.

Details

In response to this:

/test check-dev2

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.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 11, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: D3Hunter, guo-shaoge, hawkingrei, yudongusa

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 the approved label Feb 11, 2026
@qw4990
Copy link
Contributor Author

qw4990 commented Feb 11, 2026

/test pull-integration-realcluster-test-next-gen

@tiprow
Copy link

tiprow bot commented Feb 11, 2026

@qw4990: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

/test fast_test_tiprow
/test tidb_parser_test

Use /test all to run all jobs.

Details

In response to this:

/test pull-integration-realcluster-test-next-gen

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.

@ti-chi-bot ti-chi-bot bot merged commit 7f4c215 into pingcap:master Feb 11, 2026
32 checks passed
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.

planner: Plan Replayer supports dumping multiple SQL records at once

5 participants