Repository navigation
fix: parse MySQL partition options after ALTER TABLE actions - #2865
Merged
manticore-projects merged 1 commit intoOct 28, 2026
Merged
manticore-projects merged 1 commit into
manticore-projects merged 1 commit into
Conversation
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>
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MySQL lets
PARTITION BY …orREMOVE PARTITIONINGend theALTER TABLEaction list without a comma; in the manual's synopsispartition_optionsfollows thealter_optionlist. 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 4gave one ADD action whose column carriedPARTITION BY HASH (id) PARTITIONS 4as raw options, with no error and unchanged SQL. After a table option such asENGINE = InnoDB, afterADD INDEXand afterDROP COLUMN, the statement failed.A column definition in ALTER TABLE now stops before these two clauses, and
AlterTablereads one of them after the action list as a separateAlterExpressionPartition(PARTITION_BYorREMOVE_PARTITIONING). Both renderers write a space instead of a comma before it through the newAlter.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:
MySQLAlterTablePartitionTestadds 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 master5d07ba424, 6 of the 8 statements fail and the other 2 keep the clause as column options.check: 12,227 tests, 0 failures, 25 skipped; grammar ambiguity, formatting (Spotless ratchet againstupstream/master), Checkstyle, PMD, SpotBugs and JaCoCo pass. JaCoCo instrumentation headroom ofCCJSqlParser: 967 entries on master, 940 with this change.ALGORITHM=INPLACEcannot repartition. It rejectsALTER TABLE t1 ADD COLUMN z INT, PARTITION BY HASH (id)with syntax error 1064.AI assistance: prepared with Claude Code.