Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: support parsing all PARTITION BY syntax #345

Merged
merged 3 commits into from
Jun 11, 2019
Merged

Conversation

kennytm
Copy link
Contributor

@kennytm kennytm commented Jun 1, 2019

What problem does this PR solve?

Support all PARTITION BY syntax from MariaDB, since DM needs to use pingcap/parser to parse these upstream DDLs.

What is changed and how it works?

  1. Parses all 5 types of partitions supported by MariaDB, i.e.

    • HASH
    • KEY
    • RANGE — and the VALUES LESS THAN clauses
    • LIST — and the VALUES IN and DEFAULT clauses
    • SYSTEM_TIME — and the HISTORY and CURRENT clauses
  2. The parse result is now saved entirely into the AST. Constructs like SUBPARTITION and options like ENGINE are now part of the Restore text.

  3. As partitions options are a subset of table options, the following 4 new table options can now be parsed:

    • TABLESPACE = identifier
    • DATA DIRECTORY = string
    • INDEX DIRECTORY = string
    • NODEGROUP = number
  4. Support parsing and restoring ALTER TABLE ... PARTITION BY syntax. As a side effect, ALTER TABLE t1,; is no longer valid (ALTER TABLE t1; is still valid).

  5. In ALTER TABLE ... DROP PARTITION and TRUNCATION PARTITION, support parsing and restoring multiple partition names.

  6. Support restoring ALTER TABLE ... ENABLE KEYS and DISABLE KEYS (for easy testing).

Corresponding TiDB PR: pingcap/tidb#10672

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change
  • Has exported variable/fields change
  • Has interface methods change

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

@codecov

This comment has been minimized.

@kennytm
Copy link
Contributor Author

kennytm commented Jun 3, 2019

PTAL @tiancaiamao @winkyao cc @csuzhangxc

parser.y Outdated Show resolved Hide resolved

// there must be at least one column/partition/value inside (...)
{"create table t1 (a int) partition by hash (a) ()", false, ""},
{"create table t1 (a int primary key) partition by key ()", true, "CREATE TABLE `t1` (`a` INT PRIMARY KEY) PARTITION BY KEY () PARTITIONS 1"},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by key () ... is this a valid one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiancaiamao Yes it is valid, this means partition by the primary key or a non-null unique key.

https://dev.mysql.com/doc/refman/8.0/en/partitioning-key.html

Where no column name is specified as the partitioning key, the table's primary key is used, if there is one.

If there is no primary key but there is a unique key, then the unique key is used for the partitioning key:

However, if the unique key column were not defined as NOT NULL, then the previous statement would fail.

@tiancaiamao
Copy link
Collaborator

LGTM

parser.y Show resolved Hide resolved
@bb7133 bb7133 requested a review from zier-one June 11, 2019 08:58
Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bb7133 bb7133 merged commit 2bb2c0e into pingcap:master Jun 11, 2019
@kennytm kennytm deleted the partitions branch June 11, 2019 09:06
kennytm added a commit to kennytm/parser that referenced this pull request Jul 22, 2019
tiancaiamao pushed a commit to tiancaiamao/parser that referenced this pull request Apr 27, 2021
lyonzhi pushed a commit to lyonzhi/parser that referenced this pull request Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants