mysql 5.1.37 查询索引未被使用
我有一个性能不佳的查询。服务器版本:5.1.37-1ubuntu5.1 (Ubuntu)
SELECT * FROM `influencers` WHERE (`influencers`.`twitter_id` = 86861293) LIMIT 1
show create table influencers
influencers CREATE TABLE `influencers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`twitter_id` varchar(255) DEFAULT NULL,
`display_name` varchar(255) DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`screen_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `index_influencers_on_twitter_id` (`twitter_id`),
KEY `influencers_screen_name` (`screen_name`)
) ENGINE=InnoDB AUTO_INCREMENT=504126 DEFAULT CHARSET=latin1
explain SELECT * FROM `influencers` WHERE (`influencers`.`twitter_id` = 86861293) LIMIT 1
id select_type table type possible_keys key key_len ref rows Extra
-- ----------- ----------- ---- ------------------------------- ------ ------- ------ ------ -----------
1 SIMPLE influencers ALL index_influencers_on_twitter_id (null) (null) (null) 553716 Using where
该表有 547545 行。
正如您所看到的,解释有可能的密钥,但没有使用实际的密钥来显示它。
有什么想法吗?看起来这应该可行,但我正在做一些愚蠢的事情。
I have a query that is performing poorly. Server version: 5.1.37-1ubuntu5.1 (Ubuntu)
SELECT * FROM `influencers` WHERE (`influencers`.`twitter_id` = 86861293) LIMIT 1
show create table influencers
influencers CREATE TABLE `influencers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`twitter_id` varchar(255) DEFAULT NULL,
`display_name` varchar(255) DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`screen_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `index_influencers_on_twitter_id` (`twitter_id`),
KEY `influencers_screen_name` (`screen_name`)
) ENGINE=InnoDB AUTO_INCREMENT=504126 DEFAULT CHARSET=latin1
explain SELECT * FROM `influencers` WHERE (`influencers`.`twitter_id` = 86861293) LIMIT 1
id select_type table type possible_keys key key_len ref rows Extra
-- ----------- ----------- ---- ------------------------------- ------ ------- ------ ------ -----------
1 SIMPLE influencers ALL index_influencers_on_twitter_id (null) (null) (null) 553716 Using where
The table has 547545 rows in it.
As you can see the explain has the possible key, but not showing it using the actual key.
Any ideas? Seems like this should work and im doing something dumb.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 twitter_id 是 VARCHAR,因此您应该将值放在 WHERE 子句中的引号中,以避免任何可能阻止 MySQL 使用最佳执行计划的隐式类型转换:
Since twitter_id is a VARCHAR, you should put the value in quotes in your WHERE clause to avoid any implicit type conversion that may prevent MySQL from using the optimal execution plan: