Heim  >  Artikel  >  Datenbank  >  mysql优化之路----hash索引优化

mysql优化之路----hash索引优化

WBOY
WBOYOriginal
2016-06-07 16:28:351091Durchsuche

创建表 CREATE TABLE `t1` (`id` int(11) NOT NULL AUTO_INCREMENT,`msg` varchar(20) NOT NULL DEFAULT '',`crcmsg` int(15) NOT NULL DEFAULT '0',PRIMARY KEY (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 //插入数据 insert into t1 (m

创建表

CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`msg` varchar(20) NOT NULL DEFAULT '',
`crcmsg` int(15) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8

//插入数据

insert into t1 (msg) values('www.baidu.com'),('www.sina.com');

分别给msg, crcmsg 字段添加索引

alter table t1 add index msg(msg(5));

update t1 set crcmsg=crc32(msg);

alter table t1 add index crcmsg(crcmsg);

开始做测试

最后数据表结构

根据key_len的长度的大小从而给数据库查询提高速度。

自己做的小测试,希望能够给您带来收获,祝您工作愉快。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn