Skip to content

Conversation

@YangKeao
Copy link
Member

@YangKeao YangKeao commented May 29, 2025

What problem does this PR solve?

Issue Number: close #61397, close #61396

Problem Summary:

  1. The CHANGE statement has been removed. It should be removed everywhere in TiDB.
  2. Add SEMCommand needed by the SEM feature. The SEM feature will use it to filter out the SQL.

For example, the new design of SEM may have the following config to restrict the SQL:

{
"restricted_SQL" : {
    "SQL": [
        "BACKUP",
        "RESTORE",
        "ALTER RESOURCE GROUP"
    ],
    "rule": [
        "select_into_file",
        "import_from_disk"
    ],
}
}

This PR implements methods to get "SQL" from a real sql statements. Then we can match them in the sem module.

What changed and how does it work?

  1. Add a SEMCommand method to StmtNode, and implement it for all StmtNode.
  2. Add tests to make sure every subcommand of ADMIN, SHOW, BRIE are included.
  3. Remove all codes related to CHANGE statement.

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. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 29, 2025

const (
// AlterDatabaseCommand represents ALTER DATABASE statement
AlterDatabaseCommand = "ALTER DATABASE"
Copy link
Member Author

Choose a reason for hiding this comment

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

Here are the SQL commands which we can use in the SEM. @songrijie PTAL

@YangKeao YangKeao force-pushed the add-sql-cmd-for-sem-v2 branch 2 times, most recently from 4416f66 to b8992eb Compare May 29, 2025 08:12
@codecov
Copy link

codecov bot commented May 29, 2025

Codecov Report

❌ Patch coverage is 46.51163% with 253 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.1916%. Comparing base (72d1d22) to head (4ac30d2).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #61402        +/-   ##
================================================
+ Coverage   72.8175%   73.1916%   +0.3741%     
================================================
  Files          1791       1792         +1     
  Lines        487149     487666       +517     
================================================
+ Hits         354730     356931      +2201     
+ Misses       110777     109127      -1650     
+ Partials      21642      21608        -34     
Flag Coverage Δ
integration 42.2636% <ø> (?)
unit 72.1793% <46.5116%> (-0.0109%) ⬇️

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

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

@YangKeao
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 30, 2025

// Show Statements

const (
Copy link
Member

Choose a reason for hiding this comment

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

I have some concerns about how can we maintain them...

For example, we support SHOW PROFILE in syntax only(it does nothing), so should we include it in this list?

Copy link
Member Author

Choose a reason for hiding this comment

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

For example, we support SHOW PROFILE in syntax only(it does nothing), so should we include it in this list?

I think we should include every syntax supported by the parser. This list is not exposed outside (to the user), so it's fine to have more commands than what TiDB actually supported.

@YangKeao YangKeao force-pushed the add-sql-cmd-for-sem-v2 branch 3 times, most recently from 3e051af to 1aeda0e Compare July 10, 2025 03:13
Copy link
Member

@bb7133 bb7133 left a comment

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 added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 5, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 5, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-06-30 00:49:22.164680374 +0000 UTC m=+1269614.887859356: ☑️ agreed by CbcWestwolf.
  • 2025-08-05 17:50:07.52782056 +0000 UTC m=+376917.670581745: ☑️ agreed by bb7133.

Copy link
Contributor

@fixdb fixdb left a comment

Choose a reason for hiding this comment

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

+1

@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 5, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, CbcWestwolf, fixdb

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 Aug 5, 2025
@YangKeao YangKeao force-pushed the add-sql-cmd-for-sem-v2 branch from 1aeda0e to 4ac30d2 Compare August 6, 2025 13:21
@ti-chi-bot ti-chi-bot bot merged commit 8887ce7 into pingcap:master Aug 6, 2025
25 checks passed
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. 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.

Add a method to StmtNode to give a more detailed label to a statement to fulfill the needs of SEM Remove the ChangeStmt codes in tidb

4 participants