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 more table options in the CREATE TABLE statement #52

Closed
21 tasks
jackysp opened this issue Nov 26, 2018 · 2 comments
Closed
21 tasks

Support more table options in the CREATE TABLE statement #52

jackysp opened this issue Nov 26, 2018 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@jackysp
Copy link
Member

jackysp commented Nov 26, 2018

TiDB doesn't support all the syntax in CREATE TABLE statement, here is a related issue pingcap/tidb#7904.

If we improve the syntax support of CREATE TABLE statement in TiDB, it will be helpful for TiDB to compatiable with MySQL.
I list the MySQL syntax of CREATE TABLE statement and add a [TODO] flag at the end of the part which TiDB hasn't supported yet.
It is a huge work, but it is still easy to finish parts of it.

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    (create_definition,...)
    [table_options]
    [partition_options]

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    [(create_definition,...)]
    [table_options]
    [partition_options]
    [IGNORE | REPLACE]
    [AS] query_expression

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    { LIKE old_tbl_name | (LIKE old_tbl_name) }

create_definition:
    col_name column_definition
  | [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (key_part,...)
      [index_option] ...
  | {INDEX|KEY} [index_name] [index_type] (key_part,...)
      [index_option] ...
  | [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY]
      [index_name] [index_type] (key_part,...)
      [index_option] ...
  | {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name] (key_part,...) [TODO: SPATIAL not supported]
      [index_option] ...
  | [CONSTRAINT [symbol]] FOREIGN KEY
      [index_name] (col_name,...) reference_definition
  | CHECK (expr)

column_definition:
    data_type [NOT NULL | NULL] [DEFAULT default_value]
      [AUTO_INCREMENT] [UNIQUE [KEY]] [[PRIMARY] KEY]
      [COMMENT 'string']
      [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}] [TODO]
      [STORAGE {DISK|MEMORY|DEFAULT}] [TODO]
      [reference_definition]
  | data_type [GENERATED ALWAYS] AS (expression)
      [VIRTUAL | STORED] [NOT NULL | NULL]
      [UNIQUE [KEY]] [[PRIMARY] KEY]
      [COMMENT 'string']

data_type:
    (see Chapter 11, Data Types)

key_part:
    col_name [(length)] [ASC | DESC]

index_type:
    USING {BTREE | HASH}

index_option:
    KEY_BLOCK_SIZE [=] value
  | index_type
  | WITH PARSER parser_name [TODO]
  | COMMENT 'string'

reference_definition:
    REFERENCES tbl_name (key_part,...)
      [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE] [TODO]
      [ON DELETE reference_option]
      [ON UPDATE reference_option]

reference_option: [TODO]
    RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT

table_options:
    table_option [[,] table_option] ...

table_option:
    AUTO_INCREMENT [=] value
  | AVG_ROW_LENGTH [=] value
  | [DEFAULT] CHARACTER SET [=] charset_name
  | CHECKSUM [=] {0 | 1}
  | [DEFAULT] COLLATE [=] collation_name
  | COMMENT [=] 'string'
  | COMPRESSION [=] {'ZLIB'|'LZ4'|'NONE'}
  | CONNECTION [=] 'connect_string'
  | {DATA|INDEX} DIRECTORY [=] 'absolute path to directory' [TODO]
  | DELAY_KEY_WRITE [=] {0 | 1}
  | ENCRYPTION [=] {'Y' | 'N'} [TODO]
  | ENGINE [=] engine_name
  | INSERT_METHOD [=] { NO | FIRST | LAST } [TODO]
  | KEY_BLOCK_SIZE [=] value
  | MAX_ROWS [=] value
  | MIN_ROWS [=] value
  | PACK_KEYS [=] {0 | 1 | DEFAULT}
  | PASSWORD [=] 'string'
  | ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT}
  | STATS_AUTO_RECALC [=] {DEFAULT|0|1} [TODO]
  | STATS_PERSISTENT [=] {DEFAULT|0|1}
  | STATS_SAMPLE_PAGES [=] value [TODO]
  | TABLESPACE tablespace_name [STORAGE {DISK|MEMORY|DEFAULT}] [TODO]
  | UNION [=] (tbl_name[,tbl_name]...) [TODO]

partition_options:
    PARTITION BY
        { [LINEAR] HASH(expr) [TODO: LINEAR not supported]
        | [LINEAR] KEY [ALGORITHM={1|2}] (column_list) [TODO: LINEAR and ALGORITHM not supported]
        | RANGE{(expr) | COLUMNS(column_list)}
        | LIST{(expr) | COLUMNS(column_list)} } [TODO]
    [PARTITIONS num]
    [SUBPARTITION BY [TODO: not supported except RANGE partition]
        { [LINEAR] HASH(expr)
        | [LINEAR] KEY [ALGORITHM={1|2}] (column_list) }
      [SUBPARTITIONS num]
    ]
    [(partition_definition [, partition_definition] ...)]

partition_definition:
    PARTITION partition_name
        [VALUES
            {LESS THAN {(expr | value_list) | MAXVALUE}
            |
            IN (value_list)}] [TODO]
        [[STORAGE] ENGINE [=] engine_name] [TODO: STORAGE not supported]
        [COMMENT [=] 'string' ]
        [DATA DIRECTORY [=] 'data_dir'] [TODO]
        [INDEX DIRECTORY [=] 'index_dir'] [TODO]
        [MAX_ROWS [=] max_number_of_rows] [TODO]
        [MIN_ROWS [=] min_number_of_rows] [TODO]
        [TABLESPACE [=] tablespace_name]
        [(subpartition_definition [, subpartition_definition] ...)]

subpartition_definition:
    SUBPARTITION logical_name
        [[STORAGE] ENGINE [=] engine_name]
        [COMMENT [=] 'string' ]
        [DATA DIRECTORY [=] 'data_dir']
        [INDEX DIRECTORY [=] 'index_dir']
        [MAX_ROWS [=] max_number_of_rows]
        [MIN_ROWS [=] min_number_of_rows]
        [TABLESPACE [=] tablespace_name]

query_expression:
    SELECT ...   (Some valid select or union statement)
  • SPATIAL supports in create_definition.
  • COLUMN_FORMAT supports in column_definition.
  • STORAGE supports in column_definition.
  • WITH PARSER supports in index_option.
  • MATCH supports in reference_definition.
  • reference_option supports.
  • DIRECTORY supports in table_option.
  • INSERT_METHOD supports in table_option.
  • STATS_AUTO_RECALC supports in table_option.
  • STATS_SAMPLE_PAGES supports in table_option.
  • TABLESPACE supports in table_option.
  • UNION supports in table_option.
  • LINEAR and ALGORITHM supports in partition_options.
  • LIST supports in partition_options.
  • SUBPARTITION supports in partition_options.
  • IN supports in partition_definition.
  • [STORAGE] supports in partition_definition.
  • DATA DIRECTORY supports in partition_definition.
  • INDEX DIRECTORY supports in partition_definition.
  • MAX_ROWS supports in partition_definition.
  • MIN_ROWS supports in partition_definition.
@jackysp jackysp added the help wanted Extra attention is needed label Nov 26, 2018
@haplone
Copy link
Contributor

haplone commented Dec 17, 2018

I'd like to implement LINEAR and ALGORITHM supports in partition_options.
@jackysp

@zier-one
Copy link
Contributor

We are working on improving parser compatibility. pingcap/tidb#11486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants