Skip to content

Commit

Permalink
translate the pr#16576 from docs-cn
Browse files Browse the repository at this point in the history
translate the pr#16576 from docs-cn
  • Loading branch information
RobertCheng-956 committed Feb 23, 2024
1 parent dfdb5c0 commit 7426e64
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions partitioned-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,11 @@ PARTITION BY KEY(fname, store_id)
PARTITIONS 4;
```

Currently, TiDB does not support creating Key partitioned tables if the partition column list specified in `PARTITION BY KEY` is empty. For example, after you execute the following statement, TiDB will create a non-partitioned table and return an `Unsupported partition type KEY, treat as normal table` warning.
TiDB also supports creating Key partitioned tables with an empty partition column list specified in `PARTITION BY KEY`, just like MySQL. For example, the following statement will create a partitioned table with the primary key `id` as the partitioning key:

```sql
CREATE TABLE employees (
id INT NOT NULL,
id INT NOT NULL PRIMARY KEY,
fname VARCHAR(30),
lname VARCHAR(30),
hired DATE NOT NULL DEFAULT '1970-01-01',
Expand All @@ -682,6 +682,20 @@ PARTITION BY KEY()
PARTITIONS 4;
```

If there is no primary key but a unique key, the unique key will be used as the partitioning key:

```
CREATE TABLE k1 (
id INT NOT NULL,
name VARCHAR(20),
UNIQUE KEY (id)
)
PARTITION BY KEY()
PARTITIONS 2;
```

However, the previous statements will fail if the unique key column is not defined as `NOT NULL`.

#### How TiDB handles Linear Hash partitions

Before v6.4.0, if you execute DDL statements of [MySQL Linear Hash](https://dev.mysql.com/doc/refman/8.0/en/partitioning-linear-hash.html) partitions in TiDB, TiDB can only create non-partitioned tables. In this case, if you still want to use partitioned tables in TiDB, you need to modify the DDL statements.
Expand Down

0 comments on commit 7426e64

Please sign in to comment.