基本上,我有一个简单的查询:
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=utf8EXPLAIN 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。
发布于 2012-05-12 15:29:37
当您第一次访问innodb表时,它显示的时间包括将索引数据加载到缓冲池所需的时间。考虑进一步解雇的时间表。
如果您发布的详细信息仅为秒及以后的查询执行时间线,
检查表是否是分段的。对于被碎片化的表,实际查找更新的次数要比预期的要多。
如果情况不是这样,请看下面的变量。
1) innodb_flush_log_at_trx_commit
In general there will be 30 - 40% degraded performance with
innodb_flush_log_at_trx_commit set to 1 than it is set to 2
2) innodb_flush_method.
Default fsync will perfrom worse than the O_DIRECT and O_SYNC最后,查找分析信息,并在使用SQL_NO_CACHE执行查询时在serversar或iostat上查看IO。
https://stackoverflow.com/questions/10562271
复制相似问题