0

私は、特定の言語を話し、有効な場所または教師の主要な場所で将来的に空きがある教師を見つける必要があります。複数の教師が同じ場所にいる場合があります。このクエリは機能しますが、非常に低速です。どのインデックスを使用すればよいですか?

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 != ""
4

1 に答える 1

1

まず、これがより良い結果をもたらすかどうかを試してください。

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 
Left Join
  tdb_availability As locAvail
    On locAvail.teacher_id = teachers.teacher_id And
Join
  tdb_locations AS teacherLocations
    On (
      teacherLocations.location_id = locAvail.location_id Or
      teacherLocations.location_id = teachers.location_id
   ) 
WHERE
   teacherLocations.latitude != "" 
   And teacherLocations.longitude != ""
   AND locAvail.end_date >= 1381449600
   And teacherLanguages.language_id = 33

次に、null 以外のフィールドにインデックスを追加します。tdb_teacher_languages.end_date と tdb_teacher_languages.language_id が最適な候補です。その後、説明計画をここに貼り付けてみてください。

于 2013-10-11T20:45:01.793 に答える