hi
i've got two tables
Localization (Localization_Id,Localization_Left,Localization_Right) - indexes on Localization_Id PRI and on (Localization_Left,Localization_Right)
Company (Company_Id,Localization_Id) - indexes on Company_Id PRI and another one for Localization_Id
I use this query to count companies in each localization and count it for all parents of localization
And then UPDATE each.
This is too slow because in Localization is over 55000 records and in Company about 39000
Have you any ideas how to repair this ?
i've got two tables
Localization (Localization_Id,Localization_Left,Localization_Right) - indexes on Localization_Id PRI and on (Localization_Left,Localization_Right)
Company (Company_Id,Localization_Id) - indexes on Company_Id PRI and another one for Localization_Id
I use this query to count companies in each localization and count it for all parents of localization
Code:
SELECT l1.Localization_Id,COUNT(f.Company_Id) FROM Localization AS l1 LEFT JOIN Localization AS l2 ON l2.Localization_Left > l1.Localization_Left AND l2.Localization_Right < l1.Localization_Right LEFT JOIN Company AS f ON f.Localization_Id=l2.Localization_Id AND f.Company_Status >= 10 GROUP BY l1.Localization_Id
And then UPDATE each.
This is too slow because in Localization is over 55000 records and in Company about 39000
Have you any ideas how to repair this ?