Skip to content

fix: parse MySQL ADD PARTITION PARTITIONS and partition binlog modifiers - #2848

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/mysql-add-partition-count-20261023
Oct 23, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/mysql-add-partition-count-20261023

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

ALTER TABLE clients ADD PARTITION PARTITIONS 6, which adds partitions to a HASH or KEY partitioned table, parsed as an ADD COLUMN named PARTITION with PARTITIONS 6 as column options. NO_WRITE_TO_BINLOG and LOCAL failed on every partition operation that accepts them. MODIFY PARTITION (...) and ALTER PARTITION (...) were accepted and rewritten to ADD PARTITION.

ADD PARTITION [NO_WRITE_TO_BINLOG | LOCAL] {(definitions) | PARTITIONS n} is now parsed only after ADD. The modifier is accepted on COALESCE, REORGANIZE, ANALYZE, OPTIMIZE, REBUILD and REPAIR PARTITION, following MySQL's opt_no_write_to_binlog. The six name-list operations share one alternative. Before a comma, INTO or the end of the statement, local remains a partition name as before.

AlterExpressionPartition stores the ADD and COALESCE count in one partitionCount and exposes the modifier through getModifier(), reusing TableMaintenanceStatement.Modifier. It renders these operations itself. The COALESCE accessors delegate to the shared count.

Public method signatures are retained. MODIFY PARTITION (...) and ALTER PARTITION (...) no longer parse; MySQL rejects them too.

Syntax reference: MySQL 8.4 Management of HASH and KEY Partitions, ALTER TABLE Partition Operations, and opt_no_write_to_binlog in sql_yacc.yy.

Validation:

  • MySQLAlterTablePartitionTest adds 12 round-trip statements and tests for the count and modifier AST, local as a name, the ADD-only branch and the COALESCE accessors. On master, 11 of those statements fail to parse, ADD PARTITION PARTITIONS 6 becomes a column, and MODIFY PARTITION (...) becomes ADD PARTITION.
  • Java 17 Gradle check: 12,095 tests, 0 failures, 25 skipped; grammar ambiguity, formatting (Spotless ratchet against upstream/master), Checkstyle, PMD, SpotBugs and JaCoCo pass.
  • MySQL 8.4.11 with HASH and RANGE partitioned tables: 21 statements give the same results for the original and the rendered SQL. NO_WRITE_TO_BINLOG on the RANGE table fails with the same server error (1518) on both sides, and MODIFY PARTITION (...) is a syntax error on the server.

ALTER TABLE t ADD PARTITION PARTITIONS n, which adds partitions to a
HASH or KEY partitioned table, parsed as an ADD COLUMN named PARTITION
with PARTITIONS and n as column options. NO_WRITE_TO_BINLOG and LOCAL
(MySQL's opt_no_write_to_binlog) failed on every partition operation
that accepts them, and MODIFY or ALTER PARTITION (...) was accepted and
rewritten to ADD PARTITION.

Parse ADD PARTITION [NO_WRITE_TO_BINLOG | LOCAL] {(definitions) |
PARTITIONS n} only after ADD, and accept the modifier on COALESCE,
REORGANIZE, ANALYZE, OPTIMIZE, REBUILD and REPAIR PARTITION. The name
list operations share one alternative. Before a comma, INTO or the end
of the statement, LOCAL remains a partition name as before.

AlterExpressionPartition keeps the ADD and COALESCE count in one
partitionCount, reuses TableMaintenanceStatement.Modifier, and renders
these operations itself. The COALESCE accessors delegate to the shared
count.

Signed-off-by: minleejae <mmj9808@gmail.com>
@manticore-projects
manticore-projects merged commit 220d0ed into JSQLParser:master Oct 23, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

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