Skip to content

Parse MySQL CHECK, OPTIMIZE and REPAIR TABLE statements - #2788

Open
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/mysql-table-maintenance-20261013
Open

minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/mysql-table-maintenance-20261013

Conversation

@minleejae

@minleejae minleejae commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Parse the MySQL/MariaDB table maintenance statements CHECK TABLE, OPTIMIZE TABLE and REPAIR TABLE. They currently fail in every configuration, so tools that replicate or audit MySQL DDL cannot read, for example, OPTIMIZE TABLE t. ANALYZE TABLE from the same family is already modeled (#2542).

Current design (As-is)

The statement grammar has no alternative for these statements. CHECK, OPTIMIZE and REPAIR are only used inside other clauses, such as the ALTER TABLE partition actions.

Target design (To-be)

  • Add TableMaintenanceStatement, which records:
    • the Operation (CHECK, OPTIMIZE, REPAIR);
    • the NO_WRITE_TO_BINLOG/LOCAL modifier;
    • whether TABLE or TABLES was written;
    • the table list;
    • the options in source order.
  • Accept only the options that each operation defines:
    • CHECK: FOR UPGRADE, QUICK, FAST, MEDIUM, EXTENDED and CHANGED.
    • REPAIR: QUICK, EXTENDED and USE_FRM.
    • Only OPTIMIZE and REPAIR take a modifier.
    • Option words are matched without reserving new keywords.
  • Recognize the statement only when TABLE or TABLES follows. Like ANALYZE, it is available in every dialect. A CHECK TABLE statement that follows CREATE DOMAIN is no longer read as part of the domain's CHECK constraint list; this was the only grammar choice conflict the new statement introduced.
  • Wire the statement into:
    • StatementDeParser and TablesNamesFinder;
    • metadata validation, through the new Feature.tableMaintenance, which the MySQL and MariaDB capabilities enable;
    • statement feature analysis: READS_DATA and RETURNS_RESULT_SET; OPTIMIZE and REPAIR also MODIFIES_SCHEMA, and REPAIR possibly MODIFIES_DATA.
  • Document the API in the usage guide and list the statements in README and index.

Validation

  • 23 new tests cover:
    • every form: parse, deparse and reparse, plus the AST fields;
    • rejected combinations;
    • builder deparsing;
    • table discovery;
    • the MySQL and MariaDB dialects;
    • option words used as identifiers;
    • CREATE DOMAIN followed by CHECK TABLE;
    • statement features and validation capabilities.
  • Java 17 offline Gradle spotlessApply check: 10,120 tests, 10,095 passed, 25 skipped, zero failures/errors. The grammar choice conflict check passes.
  • Ran 11 statements on each of MySQL 8.4, MySQL 8.0 and MariaDB 11.4 (33 cases), in original and rendered form:
    • The 7 valid forms succeed both ways.
    • The 4 invalid combinations are rejected by both the servers and the parser: CHECK NO_WRITE_TO_BINLOG TABLE, OPTIMIZE TABLE t QUICK, REPAIR TABLE t FAST and CHECK TABLE t USE_FRM.

Integration validation

Applied #2788, #2789, #2790, #2791 and #2792 together on master (166f0a27):

Model the MySQL/MariaDB table maintenance statements as
TableMaintenanceStatement with its operation, NO_WRITE_TO_BINLOG/LOCAL
modifier, TABLE/TABLES spelling, table list and per-operation options.
Options outside an operation's definition are rejected, and the option
words remain ordinary identifiers elsewhere.

Wire the statement into the deparser, table finder, validator and
statement feature analysis, and keep a following CHECK TABLE statement
out of CREATE DOMAIN's CHECK constraint loop.

Signed-off-by: minleejae <mmj9808@gmail.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant