我是程序员,而不是DBA.要温柔 :)
概观
> InnoDB,MySQL
> mod_perl脚本,持久连接
>数千名用户每20秒调用一次脚本
问题
>高磁盘IO(可能是由更新[?]引起的)会减慢一切,造成巨大的瓶颈.
查询
> UPDATE [single table] SET refreshTime to current timestamp,WHERE子句中有两个相同的表检查
> SELECT COUNT(*)[四个表连接,带索引],以及WHERE子句中的一堆AND(仍然非常简单)
>在WHERE子句中选择a,b [四个表连接,相同的四个表]和一堆AND(也很简单)
查询缓存已启用.
解决方案?
>我不是DBA,但我怀疑在RAM中有一个表定期(每10秒?)更新到磁盘上,如果发生灾难性故障,将自动从磁盘填充RAM表表重启,但我不知道它是否真的可能,如果它是最好的解决方案或其他选项.
>有什么想法或建议吗?再说一遍,我是一名程序员,所以如果有人知道有人这样做是收费的,或者可以指出我非常具体的资源,我会非常感激.
~~~~~~~
CREATE TABLE `openInvitations` (
`id` int(99) NOT NULL auto_increment,
`createTime` timestamp NULL default NULL,
`repAcceptTime` timestamp NULL default NULL,
`rep_id` varchar(64) NOT NULL default '',
`repRefreshTime` timestamp NULL default NULL,
`customer_macAddr` varchar(14) NOT NULL default '',
`customerRefreshTime` timestamp NULL default NULL,
`stage` char(1) NOT NULL default 'P',
`parent` varchar(25) default NULL,
`reason` varchar(64) default NULL,
PRIMARY KEY (`rep_id`,`customer_macAddr`),
UNIQUE KEY `id` (`id`),
KEY `customer_macAddr` (`customer_macAddr`),
CONSTRAINT `openInvitations_ibfk_1` FOREIGN KEY (`rep_id`) REFERENCES `rep` (`id`),
CONSTRAINT `openInvitations_ibfk_2` FOREIGN KEY (`customer_macAddr`) REFERENCES `customer` (`macAddr`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=latin1
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE oi ref PRIMARY,customer_macAddr customer_macAddr 16 const 1 Using where; Using index
1 SIMPLE r eq_ref PRIMARY,FK_rep_1 PRIMARY 66 xxx.oi.rep_id 1 Using where
1 SIMPLE s eq_ref PRIMARY,FK_subscriber_1 PRIMARY 27 xxx.r.subscriber_id 1 Using where
1 SIMPLE c eq_ref PRIMARY PRIMARY 4 xxx.s.charge_id 1 Using where
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE oi ref PRIMARY,customer_macAddr customer_macAddr 16 const 1 Using where
1 SIMPLE r eq_ref PRIMARY,FK_rep_1 PRIMARY 66 xxx.oi.rep_id 1 Using where
1 SIMPLE s eq_ref PRIMARY,FK_subscriber_1 PRIMARY 27 xxx.r.subscriber_id 1 Using where
1 SIMPLE c eq_ref PRIMARY PRIMARY 4 xxx.s.charge_id 1 Using where
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE openInvitations ALL customer_macAddr NULL NULL NULL 5258 Using where
修复查询后:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE openInvitations ref customer_macAddr customer_macAddr 16 const 1 Using where
解决方法:
正如DTest指出的那样,提供有关您的问题的更多信息.
关于缓存,您可以增加innodb缓冲池大小,以允许更多数据和索引缓存在内存中.如果您经常更新,您可能无法从查询缓存中受益,并且可能最好将该RAM用于innodb缓冲池.
如果您想将所有数据和索引放在RAM中,那么MySQL Cluster可能就是您的答案.
编辑
看起来您的SELECT语句正在使用适当的索引.你能为你的更新声明提供解释计划吗?您必须将其重写为SELECT语句才能执行此操作.执行SELECT * FROM相同的表并使用与UPDATE语句相同的where子句.
标签:mysql,innodb
来源: https://codeday.me/bug/20190805/1591957.html