MySQLサーバに提出する後続のクエリに問題があります。 25秒かかる...(COUNT(*)< 20k) - 表記は600k行しかありません。しかし、索引は、それがどこにあるべきか(つまり、ON句の関係する列に対して)作成されます。私はGROUP BYを削除しようとしましたが、これはケースを少し改善しました。しかし、クエリは依然として遅い応答に一般的なルールを与えます。私はstackoverflowに見つかったさまざまなケースの解決策を見つけることができなかったので、その投稿をしました。なにか提案を?MySQLのクエリが非常に遅い(Left-JOIN、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 |
EDITこのリンクは、私を助け、それが8秒で今行きます。 https://www.percona.com/blog/2016/10/12/mysql-5-7-performance-tuning-immediately-after-installation/。しかし、私はまだそれが遅いと思う、私はちょうど誰もが改善される可能性があることを知っている場合はそれを聞かせてください。そして、あなたはfeatured(discr, state, doctor_id, location_id, profession_id)
とfeatured(doctor_id, discr, user_id)
にインデックスをしたい
SELECT . . . -- you need to fix the `GROUP_CONCAT()` column references
FROM featured doctor LEFT JOIN
location location
ON doctor.location_id = location.id LEFT JOIN
profession profession
ON doctor.profession_id = profession.id LEFT JOIN
featured featured
ON featured.doctor_id = doctor.doctor_id LEFT JOIN
user user
ON featured.user_id = user.id
WHERE doctor.discr = 'doctor' AND
doctor.state = 'Publié' AND
featured.discr = 'recommendation'
GROUP BY doctor.uuid;
を:ありがとう
'インデックスはどこに作られるのですか '。正確にはどこで?あなたのハードウェア構成は何ですか? EXPLAINクエリの結果はどこですか? 何をdoctor.uuid、 doctor.location_id doctor.profession_idをlocation.id、 featured.user_idをprofession.id、 recommendation.doctor_idをUSER.ID、 doctor.discr をdoctor.id: –
次のフィールドがインデックス化されています情報はハードウェアの部分で役に立つでしょうか? ありがとうございます! –
複合インデックスは、場合によっては非常に重要です。あなたはそれらを使いましたか? p.s.また、データベースのダンプがうまくいくので、実際のdbでクエリの変更などをテストできます。 –