我有后续查询,我提交给MySQL服务器的麻烦。它需要25s ...为(COUNT(*)< 20k) - 表 - 只有功能有600k行。但是,索引是在它应该在的地方创建的(也就是说,对于ON子句中的相关列)。我试图删除GROUP BY,这改善了一些情况。但是这些查询仍然给出了一个慢速回应的一般规则。我做了那篇文章,因为我找不到找到到stackoverflow的各种案件的解决方案。任何建议?非常慢的MySQL查询(左连接,GROUP BY等?)
SELECT
doctor.id as doctor_id,
doctor.uuid as doctor_uuid,
doctor.firstname as doctor_firstname,
doctor.lastname as doctor_lastname,
doctor.cloudRdvMask as doctor_cloudRdvMask,
GROUP_CONCAT(recommendation.id SEPARATOR ' ') as recommendation_ids,
GROUP_CONCAT(recommendation.uuid SEPARATOR ' ') as recommendation_uuids,
GROUP_CONCAT(recommendation.disponibility SEPARATOR ' ') as recommendation_disponibilities,
GROUP_CONCAT(recommendation.user_id SEPARATOR ' ') as recommendation_user_ids,
GROUP_CONCAT(recommendation.user_uuid SEPARATOR ' ') as recommendation_user_uuids,
location.id as location_id,
location.uuid as location_uuid,
location.lat as location_lat,
location.lng as location_lng,
profession.id as profession_id,
profession.uuid as profession_uuid,
profession.name as profession_name
FROM featured as doctor
LEFT JOIN location as location
ON doctor.location_id = location.id
LEFT JOIN profession as profession
ON doctor.profession_id = profession.id
LEFT JOIN
(
SELECT
featured.id as id,
featured.uuid as uuid,
featured.doctor_id as doctor_id,
featured.disponibility as disponibility,
user.id as user_id,
user.uuid as user_uuid
FROM featured as featured
LEFT JOIN user as user
ON featured.user_id = user.id
WHERE discr = 'recommendation'
) as recommendation
ON recommendation.doctor_id = doctor.id
WHERE
doctor.discr = 'doctor'
AND
doctor.state = 'Publié'
GROUP BY doctor.uuid
这里谈到的EXPLAIN结果:
id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
1 | SIMPLE | doctor | NULL | ref | discr,state | discr | 767 | const | 194653 | 50.00 | Using where |
1 | SIMPLE | location | NULL | eq_ref | PRIMARY | PRIMARY | 4 | doctoome.doctor.location_id | 1 | 100.00 | NULL |
1 | SIMPLE | profession | NULL | eq_ref | PRIMARY | PRIMARY | 4 | doctoome.doctor.profession_id | 1 | 100.00 | NULL |
1 | SIMPLE | featured | NULL | ref | IDX_3C1359D487F4FB17,discr | IDX_3C1359D487F4FB17 | 5 | doctoome.doctor.id | 196 | 100.00 | Using where |
1 | SIMPLE | user | NULL | eq_ref | PRIMARY | PRIMARY | 4 | doctoome.featured.user_id | 1 | 100.00 | Using index |
编辑此链接帮助我,现在去与787-8。 https://www.percona.com/blog/2016/10/12/mysql-5-7-performance-tuning-immediately-after-installation/。但我仍然觉得它很慢,我只是让它在任何人都知道什么可以改进的情况下。由于
'索引应该在哪里创建'。究竟在哪里?你的硬件配置是什么? EXPLAIN查询结果在哪里? –
以下字段建立索引: doctor.location_id,location.id doctor.profession_id,profession.id featured.user_id,USER.ID recommendation.doctor_id,doctor.id doctor.discr doctor.uuid 什么信息可能在硬件部分有用? 谢谢! –
复合指标在某些情况下也非常重要。你用过吗?附:此外,你的数据库的转储会很好,所以我们可以测试查询更改和其他东西与真正的数据库。 –