Skip to content

fix: parse MySQL partition options after ALTER TABLE actions - #2865

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/mysql-alter-partition-options-20261027
Oct 28, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/mysql-alter-partition-options-20261027

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

MySQL lets PARTITION BY … or REMOVE PARTITIONING end the ALTER TABLE action list without a comma; in the manual's synopsis partition_options follows the alter_option list. The parser accepted them only as the first action or after a comma. After a column definition, the column options took the clause instead: ALTER TABLE t1 ADD COLUMN d INT PARTITION BY HASH (id) PARTITIONS 4 gave one ADD action whose column carried PARTITION BY HASH (id) PARTITIONS 4 as raw options, with no error and unchanged SQL. After a table option such as ENGINE = InnoDB, after ADD INDEX and after DROP COLUMN, the statement failed.

A column definition in ALTER TABLE now stops before these two clauses, and AlterTable reads one of them after the action list as a separate AlterExpressionPartition (PARTITION_BY or REMOVE_PARTITIONING). Both renderers write a space instead of a comma before it through the new Alter.separatorBefore, because MySQL rejects …, PARTITION BY. A statement written with that comma, which was already accepted, now renders without it.

Public method signatures are retained.

Syntax reference: MySQL 8.4 ALTER TABLE, ALTER TABLE partition operations.

Validation:

  • MySQLAlterTablePartitionTest adds 8 statements, parsed with and without the MySQL dialect, plus checks of the column definition, the separator and a rejected pair of trailing clauses. On master 5d07ba424, 6 of the 8 statements fail and the other 2 keep the clause as column options.
  • Java 17 Gradle check: 12,227 tests, 0 failures, 25 skipped; grammar ambiguity, formatting (Spotless ratchet against upstream/master), Checkstyle, PMD, SpotBugs and JaCoCo pass. JaCoCo instrumentation headroom of CCJSqlParser: 967 entries on master, 940 with this change.
  • MySQL 8.4.11 accepts the syntax of all 8 statements; one stops with error 1845 only because ALGORITHM=INPLACE cannot repartition. It rejects ALTER TABLE t1 ADD COLUMN z INT, PARTITION BY HASH (id) with syntax error 1064.

AI assistance: prepared with Claude Code.

MySQL lets PARTITION BY or REMOVE PARTITIONING end the ALTER TABLE
action list without a comma. The parser accepted them only as the
first action or after a comma. After a column definition the column
options took the clause, so ADD COLUMN d INT PARTITION BY HASH (id)
gave one ADD action with the clause as raw column options, without an
error. After a table option, ADD INDEX or DROP COLUMN it failed.

A column definition now stops before these clauses, and AlterTable
reads one of them after the action list as an AlterExpressionPartition.
Both renderers write a space instead of a comma before it through
Alter.separatorBefore, because MySQL rejects a comma there.

Signed-off-by: minleejae <mmj9808@gmail.com>
@manticore-projects
manticore-projects merged commit c84ad0e into JSQLParser:master Oct 28, 2026
7 of 8 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thanks!

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.

2 participants