Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: SHOW CREATE TABLE结果显示engine=innodb的意义是什么,不太理解
Test Environment
Server version: 5.7.25-TiDB-v6.1.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible
tidb [test]>show create table t1\G
*************************** 1. row ***************************
Table: t1
Create Table: CREATE TABLE `t1` (
`id` int(11) NOT NULL,
`c1` int(11) DEFAULT NULL,
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
Isn’t TiDB’s underlying structure LSM? So what is the purpose of showing ENGINE=InnoDB here? I don’t quite understand.
Additionally, if you try to delete the PK of table t1 at this point, you will get the following error message:
tidb [test]>alter table t1 drop primary key;
ERROR 8200 (HY000): Unsupported drop primary key when the table's pkIsHandle is true
The phrase “when the table’s pkIsHandle is true” is also not easy to understand literally as to why deletion is not allowed.
Thank you.
First, let’s talk about why primary keys are not supported for deletion.
From the perspective of TiDB’s underlying data storage format,
the data is stored in a KV structure.
For CLUSTERED tables, the Key is the primary key, and the value is other columns. If you want to delete the primary key, the data cannot be stored.
Therefore, CLUSTERED tables do not support deleting primary keys.
Then for engine=innodb, I understand it is to be compatible with those metadata tables of innodb, such as the tables in the information_schema database, performance, and other such libraries.
Only compatible with MySQL display
The official documentation on clustered indexes, you’ll understand after reading it.
TiDB is compatible with MySQL, and the purpose of displaying ENGINE=InnoDB is for compatibility with the MySQL server layer.
Create NON CLUSTERED. You need to specify it when creating the table.
For point 1, if it automatically converts, that would be equivalent to rebuilding the table and re-planning the data format, which would be too costly in terms of impact.
For point 2, I’m a bit unclear, but simply put, it means you can use TiDB in the same way you operate MySQL.
It’s a more powerful MySQL, for example, there’s no need to use sharding middleware anymore.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.