MySQL从5.5迁移到5.7的速度非常慢

MySQL从5.5迁移到5.7的速度非常慢,mysql,Mysql,正如标题中提到的,我正在从5.5迁移到5.7,我有一个查询完全崩溃了: SELECT COUNT(*) as count, detections.vendor FROM ( SELECT id FROM telemetry_user_agents WHERE date < DATE_SUB(NOW(), INTERVAL 0 DAY) AND date > DATE_SUB(NOW(), INTERVAL 7 DAY) ) agents LEFT

正如标题中提到的,我正在从5.5迁移到5.7,我有一个查询完全崩溃了:

SELECT
COUNT(*) as count, 
detections.vendor 
FROM (
    SELECT id FROM telemetry_user_agents 
    WHERE date < DATE_SUB(NOW(), INTERVAL 0 DAY) 
    AND date > DATE_SUB(NOW(), INTERVAL 7 DAY)  
) agents 
LEFT JOIN telemetry_detections detections on detections.user_id = agents.id
GROUP BY detections.vendor
ORDER BY count DESC
LIMIT 20
报告解释说:

5.5

有什么帮助吗?:)

编辑:在我创建了一组索引之后:

5.7:


你确定索引和主键是正确的吗?…在5.7中,查询似乎没有使用主键(完全扫描),我想你需要一个detections.user索引_id@Hackerman,它是从转储中获取的,所以我100%确定它们的结构和数据完全相同。@CptMisery已经有一个,如果你看一下结构。@Tigzy你能在这两种情况下显示子查询的解释输出吗?你确定索引和主键是正确的吗?…在5.7中,查询似乎没有使用主键(完全扫描),我想你需要一个关于检测的索引。user_id@Hackerman,是从垃圾场取的,因此,我100%确信它们的结构和数据完全相同。@CptMisery已经有一个了,如果你看一下结构的话。@Tigzy你能在这两种情况下显示子查询的解释输出吗?
CREATE TABLE `telemetry_user_agents` (
  `id` int(11) NOT NULL,
  `date` datetime NOT NULL,
  `program` text NOT NULL,
  `country` text NOT NULL,
  `ip` text NOT NULL,
  `operating_system` text NOT NULL,
  `bits` int(11) NOT NULL,
  `version` text NOT NULL,
  `license` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

ALTER TABLE `telemetry_user_agents`
  ADD PRIMARY KEY (`id`),
  ADD KEY `date` (`date`) USING BTREE;

ALTER TABLE `telemetry_user_agents`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;


CREATE TABLE `telemetry_detections` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `type` text NOT NULL,
  `vendor` text NOT NULL,
  `name` text NOT NULL,
  `value` text NOT NULL,
  `hash` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

ALTER TABLE `telemetry_detections`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

ALTER TABLE `telemetry_detections`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra   
1   PRIMARY     <derived2>  ALL     NULL    NULL    NULL    NULL    95286   Using temporary; Using filesort
1   PRIMARY     detections  ref     user_id     user_id     4   agents.id   19  
2   DERIVED     telemetry_user_agents   ALL     date    NULL    NULL    NULL    202047  Using where
id  select_type     table   partitions  type    possible_keys   key     key_len     ref     rows    filtered    Extra   
1   SIMPLE  telemetry_user_agents   NULL    ALL     date    NULL    NULL    NULL    200866  46.50   Using where; Using temporary; Using filesort
1   SIMPLE  detections  NULL    ref     user_id     user_id     4   adlice_stats.telemetry_user_agents.id   19  100.00  NULL
id  select_type     table   partitions  type    possible_keys   key     key_len     ref     rows    filtered    Extra   
1   SIMPLE  telemetry_user_agents   NULL    range   date,date_2     date_2  5   NULL    131741  100.00  Using where; Using index; Using temporary; Using f...
1   SIMPLE  detections  NULL    ref     user_id     user_id     4   adlice_stats.telemetry_user_agents.id   19  100.00  NULL