基本上,我有一个简单的查询:
UPDATE beststat
SET rawView = rawView + 1
WHERE bestid = 139664 AND period = 201205
LIMIT 1
,1秒,。
此表(beststat)目前具有~100万记录,其大小为:68 is。我有4GB内存和innodb buffer pool size
=:Mysql:5.1.49-3
这是我的数据库中唯一的InnoDB表(其他表是MyISAM)
当然,我有关于兽人和周期的unique key index
:
CREATE TABLE `beststat` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`bestid` int(11) unsigned NOT NULL,
`period` mediumint(8) unsigned NOT NULL,
`view` mediumint(8) unsigned NOT NULL DEFAULT '0',
`rawView` mediumint(8) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `bestid` (`bestid`,`period`)
) ENGINE=InnoDB AUTO_INCREMENT=2020577 DEFAULT CHARSET=utf8
EXPLAIN SELECT rawView FROM beststat WHERE bestid =139664 AND period =201205 LIMIT 1
给予:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE beststat const bestid bestid 7 const,const 1
有什么帮助吗?
发布于 2012-05-12 15:09:39
为了执行更新,您的查询必须扫描整个表。
在(bestid,句点)上添加一个复合索引,或者将查询更改为使用id。
https://stackoverflow.com/questions/10562271
复制相似问题