云数据库 MySQL 版
GIPK属性 | MySQL 8.0/MySQL 8.4 | MySQL 5.7 |
GIPK属性 | MySQL 8.0/MySQL 8.4 | MySQL 5.7 |
KEY 类型 | 主键索引(Primary Key) bigint(20), auto_increment | 唯一索引(Unique Index) bigint(20), auto_increment |
主键列名称 | my_row_id | byte_rds_ai_uk_row_id |
创建 GIPK 条件 | CREATE TABLE 语句无主键 | CREATE TABLE 语句无主键或唯一键 |
用户新增 PK 后,是否自动 DROP 主键列 | 是 | 是 |
用户 Select * 查询是否能选中 GIPK | 否 | 否 |
控制参数(session) | sql_generate_invisible_primary_key | loose_sql_generate_invisible_primary_key |
展示 GIPK 参数 | show_gipk_in_create_table_and_information_schema | loose_show_gipk_in_create_table_and_information_schema |
描述 | DDL 示例 | MySQL 5.7 | MySQL 8.0 | MySQL 8.4 |
描述 | DDL 示例 | MySQL 5.7 | MySQL 8.0 | MySQL 8.4 |
建表 DDL 中有用户定义的 auto_increment列(不定义为索引) | create table gipk_test(i int auto_increment, c varchar(255)); | 不允许。 ERROR 1075。 原生行为,auto inc 必须为索引。 | | |
建表 DDL 中有用户定义的 auto_increment 列(定义为索引) | create table gipk_test(i int auto_increment unique key, c varchar(255)); | 允许。 | | |
建表 DDL 中使用 GIPK 预留列名,不作为隐藏主键(非 bigint NOT NULL AUTO_INCREMENT) | create table gipk_test(`my_row_id` int auto_increment unique key, c varchar(255)); | 不允许。 不允许将byte_rds_ai_uk_row_id 作为列名。 | 允许,但输出告警 跳过 GIPK 创建,my_row_id 为普通列。 | |
使用 GIPK 相关 COMMENT | create table gipk_test(i int COMMENT 'Implicit Primary Key by RDS', c varchar(255)); | 允许。 | | |
创建无主键分区表 DDL | CREATE TABLE gipk_test ( sale_id INT NOT NULL, sale_date DATE NOT NULL, customer_id INT NOT NULL, amount DECIMAL(10,2) NOT NULL ) PARTITION BY RANGE (YEAR(sale_date)) ( PARTITION p2020 VALUES LESS THAN (2021), PARTITION p2021 VALUES LESS THAN (2022), PARTITION p2022 VALUES LESS THAN (2023), PARTITION p2023 VALUES LESS THAN (2024) ); | 允许。跳过 GIPK 创建。 | | |
binlog_format=statement 下 执行 Create table select | set binlog_format=statement; create table gipk_test as select * from t_gipk; | 不允许。无法修改为 SBR。 | | |
描述 | DDL 示例 | MySQL 5.7 | MySQL 8.0 | MySQL 8.4 |
描述 | DDL 示例 | MySQL 5.7 | MySQL 8.0 | MySQL 8.4 |
给 GIPK 主键表添加主键 | alter table gipk_test add column id int primary key; | 允许。 | | |
给无主键表添加了自增列 | alter table gipk_test add column id int auto_increment; | 不允许。 ERROR 1075 AUTO INC 必须为索引,原生行为。 | | |
给无主键表添加了自增列并作为 KEY | alter table gipk_test add column id int auto_increment key; | 允许。 | | |
用户给无主键表添加了自增列并作为 UNIQUE KEY | alter table gipk_test add column id int auto_increment unique key; | 允许。 | | |
Drop 表中的隐藏主键列 | alter table gipk_test drop column `my_row_id`; | 允许。 | | |
Drop 表中的主键列 | create table gipk_test(i int primary key, c varchar(255)); alter table gipk_test drop column i; | 允许。 变为无主键表。 | | |
Drop 表中的主键 | create table gipk_test(i int primary key, c varchar(255)); alter table gipk_test drop primary key; | 允许。 变为无主键表。 | | |
Drop 表中的隐藏主键 | alter table gipk_test drop key `my_row_id`; | 允许。 | | |
将表中的一列升级为主键 | create table gipk_test(f1 int , f2 int , f3 varchar(16) , c varchar(255)); alter table gipk_test add primary key (f1); | 允许。 | | |
GIPK 表将 GIPK 作为分区键 | CREATE TABLE gipk_test (f1 INT); ALTER TABLE gipk_test PARTITION BY KEY(byte_rds_ai_uk_row_id) PARTITIONS 10; | 不允许。 隐藏列不应作为分区键,DDL 报错。 | | |
GIPK 表将其他列作为分区键 | CREATE TABLE gipk_test (f1 INT); ALTER TABLE gipk_test PARTITION BY KEY(f1) PARTITIONS 10; | 允许。 同时 DROP GIPK 列。 | | |