Skip to content

Add structured MySQL CREATE TABLE partition parsing - #2521

Open
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/mysql-create-table-partition-1668
Open

Add structured MySQL CREATE TABLE partition parsing#2521
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/mysql-create-table-partition-1668

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

What

  • Parse MySQL CREATE TABLE ... PARTITION BY for HASH, KEY, RANGE, and LIST partitioning.
  • Support LINEAR, ALGORITHM, PARTITIONS, RANGE/LIST COLUMNS, subpartitioning, partition definitions, MAXVALUE, VALUES IN, and documented partition options.
  • Expose the result through CreateTable.getPartitioning() and the new TablePartitioning model.
  • Extend PartitionDefinition while retaining its existing constructor and accessors.
  • Preserve Oracle-style trailing partition options through TablePartitioning.getPartitionOptions().

Why

Valid MySQL partitioned table DDL currently either fails parsing or is consumed as unstructured table-option strings. This makes partition metadata unavailable to library users. The implemented grammar follows the MySQL 8.4 CREATE TABLE partition syntax: https://dev.mysql.com/doc/refman/8.4/en/create-table.html

How

The parser now stops generic table-option capture at PARTITION BY, builds a structured partitioning model, and renders it through both CreateTable.toString() and CreateTableDeParser. Partition definitions support VALUES LESS THAN, VALUES IN, unparenthesized MAXVALUE, explicit subpartitions, and ENGINE/COMMENT/DIRECTORY/MAX_ROWS/MIN_ROWS/TABLESPACE options.

Testing

  • ./gradlew check --no-daemon --no-build-cache -Dorg.gradle.vfs.watch=false
  • 5,033 project tests passed, 25 skipped.
  • 12 parser/deparser cases plus AST assertions in MySQLCreateTablePartitionTest.
  • The same 12 CREATE TABLE statements were executed successfully on MySQL 8.4.11. information_schema.PARTITIONS confirmed HASH, LINEAR HASH, KEY, LINEAR KEY, RANGE, RANGE COLUMNS, LIST, LIST COLUMNS, and HASH/LINEAR KEY subpartition methods.

Partially addresses #1668. ALTER TABLE partition operations remain a separate follow-up scope.

AI assistance

OpenAI Codex was used to audit syntax coverage, draft the implementation, and run validation. The changes and generated tests were reviewed against the MySQL 8.4 documentation and a MySQL 8.4.11 server.

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