mysql - 使用 MyISAM 引擎在临时表上使用 MySQL 二级索引的结果不正确
问题描述
我在 Amazon RDS (Aurora) 中使用 MySql 5.7。问题在于临时表上的二级索引(用作存储过程的一部分):
create temporary table tmpDemo (
c1 varchar(50) NOT NULL, PRIMARY KEY(c1),
c2 varchar(100) NOT NULL,...
) Engine=MyIsam;
-- ... insert data into tmpDemo
select c1,c2 from tmpDemo;
create index ix_secondary on tmpDemo(c2) USING BTREE;
select c1,c2 from tmpDemo;
在最后一次选择时,C1 列中的数据被复制。就好像二级索引去掉了主键的唯一性约束:
11237357 00
11237357 00
11237357 00
下面的小程序重现了这个问题。如果您想知道我为什么使用 MyISAM 而不是 InnoDB,那是因为这是 AWS Aurora DB 上的只读集群,所以我别无选择。我不知道独立的 MySQL 实例是否会发生这种情况。
drop procedure if exists showIxBug;
DELIMITER $$
create procedure showIxBug()
BEGIN
drop temporary table if exists tmpDemo;
create temporary table tmpDemo (
c1 varchar(50) NOT NULL, PRIMARY KEY(c1),
c2 varchar(100) NOT NULL,
c3 int,
c4 datetime NOT NULL
) Engine=MyIsam;
set @i=0;
WHILE @i < 10000 DO
set @seed = FLOOR(RAND()*12121212);
set @c1 = convert(@seed,char);
set @c2 = convert(@seed % 100,char);
INSERT INTO tmpDemo VALUES (
@c1,concat(@c2,@c2),@seed,
utc_timestamp()
) on duplicate key update c3=100;
SET @i = @i + 1;
END WHILE;
select c1,c2 from tmpDemo;
create index ix_secondary on tmpDemo(c2) USING BTREE;
select c1,c2 from tmpDemo;
END$$
DELIMITER ;
call showIxBug();
解决方案
根据官方文档,我不确定那里发生了什么,但Aurora 根本不支持 MyISAM 。
推荐阅读
- react-native - Stacknavigatior 导航到已经在堆栈中的屏幕
- php - 在 Laravel 中提交 POST 表单后出现 302 错误
- xamarin - Azure OCR 识别PrintedTextInStreamAsync 无效图像
- java - 尝试在我的适配器类中的空对象引用上调用虚拟方法“void android.widget.TextView.setText(java.lang.CharSequence)”
- php - 如何将 XML 解析为 PHP
- python - “变量”在赋值之前定义
- docker - 如何在本地主机上保存来自 docker 容器的数据?
- php - 如何修复“PHP 警告:ftp_login():登录验证失败”
- reactjs - 由于 CORS,Axios 无法从 s3 下载图像
- firemonkey - iOS 上的屏幕方向