私は、特定の言語を話し、有効な場所または教師の主要な場所で将来的に空きがある教師を見つける必要があります。複数の教師が同じ場所にいる場合があります。このクエリは機能しますが、非常に低速です。どのインデックスを使用すればよいですか?
Select
teachers.teacher_id,
teacherLocations.location_id
From
tdb_teachers AS teachers
Join
tdb_teacher_languages As teacherLanguages
On teacherLanguages.teacher_id = teachers.teacher_id And
teacherLanguages.language_id = 33
Left Join
tdb_availability As locAvail
On locAvail.teacher_id = teachers.teacher_id And
locAvail.end_date >= 1381449600
Join
tdb_locations AS teacherLocations
On (
teacherLocations.location_id = locAvail.location_id Or
teacherLocations.location_id = teachers.location_id
) And
teacherLocations.latitude != "" And
teacherLocations.longitude != ""