Skip to content

Commit 1cf412b

Browse files
authored
Added LINEAR HASH/KEY mysql compatibility (#11085) (#11340)
1 parent 0ab0b03 commit 1cf412b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

mysql-compatibility.md

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ In TiDB, all supported DDL changes are performed online. Compared with DDL opera
150150
* Table Partitioning supports `HASH`, `RANGE`, and `LIST` partitioning types. For the unsupported partition type, the `Warning: Unsupported partition type %s, treat as normal table` error might be output, where `%s` is a specific partition type.
151151
* Table Partitioning also supports `ADD`, `DROP`, and `TRUNCATE` operations. Other partition operations are ignored. The following Table Partition syntaxes are not supported:
152152
- `PARTITION BY KEY`
153+
- `PARTITION BY LINEAR KEY`
153154
- `SUBPARTITION`
154155
- `{CHECK|TRUNCATE|OPTIMIZE|REPAIR|IMPORT|DISCARD|REBUILD|REORGANIZE|COALESCE} PARTITION`
155156

partitioned-table.md

+10
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,16 @@ MOD(YEAR('2005-09-01'),4)
559559
= 1
560560
```
561561

562+
#### How TiDB handles Linear Hash partitions
563+
564+
Before v6.4.0, if you execute DDL statements of [MySQL Linear Hash](https://dev.mysql.com/doc/refman/5.7/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.
565+
566+
Since v6.4.0, TiDB supports parsing the MySQL `PARTITION BY LINEAR HASH` syntax but ignores the `LINEAR` keyword in it. If you have some existing DDL and DML statements of MySQL Linear Hash partitions, you can execute them in TiDB without modification:
567+
568+
- For a `CREATE` statement of MySQL Linear Hash partitions, TiDB will create a non-linear Hash partitioned table (note that there is no Linear Hash partitioned table in TiDB). If the number of partitions is a power of 2, the rows in the TiDB Hash partitioned table are distributed the same as that in the MySQL Linear Hash partitioned table. Otherwise, the distribution of these rows in TiDB is different from MySQL. This is because non-linear partitioned tables use a simple "modulus number of partition", while linear partitioned tables use "modulus next power of 2 and fold the values between the number of partitions and the next power of 2". For details, see [#38450](https://github.com/pingcap/tidb/issues/38450).
569+
570+
- For all other statements of MySQL Linear Hash partitions, they work in TiDB the same as that in MySQL, except that the rows are distributed differently if the number of partitions is not a power of 2, which will give different results for [partition selection](#partition-selection), `TRUNCATE PARTITION`, and `EXCHANGE PARTITION`.
571+
562572
### How TiDB partitioning handles NULL
563573

564574
It is allowed in TiDB to use `NULL` as the calculation result of a partitioning expression.

0 commit comments

Comments
 (0)