Helllo 我有这两张桌子:
当我把这个查询放在sql控制台中时,它看起来很慢(> 5分钟)
SELECT vc.phone_number, vc.lead_id, rl.location, rl.filename FROM `recording_log` as rl
INNER JOIN vicidial_list as vc ON vc.lead_id=rl.lead_id
WHERE vc.phone_number="000021125454" aND length > "550";
我在recording_log(lead_id)
中有索引
并在vicidial_list(lead_id)
CREATE TABLE recording_log (
recording_id int(10) unsigned NOT NULL AUTO_INCREMENT,
filename varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
lead_id int(9) unsigned DEFAULT NULL,
user varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
vicidial_id varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (recording_id),
KEY filename (filename),
KEY lead_id (lead_id),
KEY user (user),
KEY vicidial_id (vicidial_id)
) ENGINE=MyISAM AUTO_INCREMENT=3417340;
CREATE TABLE vicidial_list (
lead_id int(9) unsigned NOT NULL AUTO_INCREMENT,
phone_number varchar(18) COLLATE utf8_unicode_ci NOT NULL,
list_id bigint(14) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (lead_id),
KEY phone_number (phone_number),
KEY list_id (list_id)
) ENGINE=MyISAM AUTO_INCREMENT=3531081
答案 0 :(得分:0)
EXPLAIN
和CREATE TABLEs
都表示您拥有最佳索引,查询所需的时间不会超过一秒。
...然而
由于您使用的是MyISAM(而不是InnoDB),因此写入可以阻止读取,使得读取可能需要很长时间。还有什么同时在运行?
也许最好的解决方案是ALTER TABLE ... ENGINE=InnoDB;
。 (确保在执行此操作时有足够的额外磁盘空间。)您也可以为所有表格执行此操作。