以下のような質問があります
SELECT
t1.categoryId as level1Id, t2.categoryId as level2Id, t3.categoryId as level3Id, t4.categoryId as level4Id, t5.categoryId as level5Id, t6.categoryId as level6Id, t7.categoryId as level7Id
FROM `productCategories` as t1
LEFT JOIN productCategories as t2 ON t1.categoryId = t2.parentcategoryId
LEFT JOIN productCategories as t3 ON t2.categoryId = t3.parentcategoryId
LEFT JOIN productCategories as t4 ON t3.categoryId = t4.parentcategoryId
LEFT JOIN productCategories as t5 ON t4.categoryId = t5.parentcategoryId
LEFT JOIN productCategories as t6 ON t5.categoryId = t6.parentcategoryId
LEFT JOIN productCategories as t7 ON t6.categoryId = t7.parentcategoryId
WHERE t1.categoryId IN ('" . $categories . "')
productCategories には、約 15000 行と 2020 の一意の親 ID があります。配列内の一意のカテゴリ ID をすべて取得したら、新しいクエリを開始して、一致するカテゴリ ID を持つ製品を検索します。そのため、その時点で物事は少し遅くなります。このクエリを改善する方法やインデックスを作成する方法について何かアドバイスはありますか?