我有下面的表格- 'element‘
CREATE TABLE `element` (
`eid` bigint(22) NOT NULL AUTO_INCREMENT,
`tag_name` varchar(45) COLLATE utf8_bin DEFAULT NULL,
`text` text COLLATE utf8_bin,
`depth` tinyint(2) DEFAULT NULL,
`classes` tinytext COLLATE utf8_bin,
`webarchiver_uniqueid` int(11) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`updated` datetime DEFAULT NULL,
`rowstatus` char(1) COLLATE utf8_bin DEFAULT 'A',
PRIMARY KEY (`eid`)
) ENGINE=InnoDB AUTO_INCREMENT=12090 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;列详细信息和当前索引详细信息如上所示。这个表上几乎90%的查询是这样的:
select * from element
where tag_name = 'XXX'
and text = 'YYYY'
and depth = 20
and classes = 'ZZZZZ'
and rowstatus = 'A'在这个表上创建索引的最佳方式是什么?该表大约有60k行。
发布于 2015-09-01 13:23:37
将classes从TINYTEXT更改为VARCHAR(255) (或更合理的大小),然后使用
INDEX(tag_name, depth, classes)列按任意顺序排列。我省略了rowstatus,因为它看起来像是一列可能会更改的列。(无论如何,标志不会给索引添加太多内容。)
不能在索引中包含TEXT或BLOB列。这是不值得做一个‘前缀’索引。
因为PRIMARY KEY是UNIQUE密钥,所以DROP INDEX eid_UNIQUE。
为所有字符字段选择"binary“/ "utf8_bin”有什么原因吗?
https://stackoverflow.com/questions/32323792
复制相似问题