我是程序员,不是 DBA。要温柔 :)
概述
问题
查询
查询缓存开启。
解决方案?
~~~~~~~
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
Run Code Online (Sandbox Code Playgroud)
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 使用 where; 使用索引 1 SIMPLE r eq_ref PRIMARY,FK_rep_1 PRIMARY 66 xxx.oi.rep_id 1 使用 where 1 SIMPLE s eq_ref PRIMARY,FK_subscriber_1 PRIMARY 27 xxx.r.subscriber_id 1 使用 where 1 简单 c eq_ref PRIMARY PRIMARY 4 xxx.s.charge_id 1 使用 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 使用 where 1 SIMPLE r eq_ref PRIMARY,FK_rep_1 PRIMARY 66 xxx.oi.rep_id 1 使用 where 1 SIMPLE s eq_ref PRIMARY,FK_subscriber_1 PRIMARY 27 xxx.r.subscriber_id 1 使用 where 1 简单 c eq_ref PRIMARY PRIMARY 4 xxx.s.charge_id 1 使用 where
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE openInvitations ALL customer_macAddr NULL NULL NULL 5258 使用 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 使用 where
正如 DTest 所指出的,请提供有关您的问题的更多信息。
关于缓存,您可能会增加 innodb 缓冲池的大小,以允许在内存中缓存更多数据和索引。如果您经常更新,您可能无法从查询缓存中受益,最好将该 RAM 用于 innodb 缓冲池。
如果您想将所有数据和索引放在 RAM 中,那么 MySQL Cluster 可能是您的答案。
编辑
看起来您的 SELECT 语句正在使用正确的索引。你能为你的更新声明提供一个解释计划吗?您必须将其重写为 SELECT 语句才能执行此操作。做一个SELECT * FROM
相同的表,并与同where子句作为您的UPDATE语句。
归档时间: |
|
查看次数: |
1515 次 |
最近记录: |