mgutt
27.05.2008, 01:26:25
Hallo,
ich stoße öfter mal auf das gleiche Problem. Eine Abfrage ist mit Index langsamer oder wie hier ist der Subselect schneller.
Subselect ca. 0.1 Sekunden:
SELECT h.host_id, COUNT( u.user_id ) AS users, (
SELECT COUNT( hu.user_id )
FROM host_users hu
WHERE hu.host_id = h.host_id
AND hu.user_id = u.user_id
GROUP BY hu.host_id
) AS users2
FROM phpbb_users u, phpbb_hosts h
WHERE u.host_id = h.host_id
GROUP BY h.host_id
LIMIT 0 , 100
LEFT JOIN ca. 30 Sekunden:
SELECT h.host_id, COUNT(u.user_id) as users
FROM phpbb_users u, phpbb_hosts h
LEFT JOIN host_users hu
ON hu.user_id = u.user_id
WHERE u.host_id = h.host_id
OR hu.host_id = h.host_id
GROUP BY h.host_id, hu.host_id
Ist mein LEFT JOIN irgendwie falsch oder wieso kommt es zu diesem "Fehler"?
Gruß
ich stoße öfter mal auf das gleiche Problem. Eine Abfrage ist mit Index langsamer oder wie hier ist der Subselect schneller.
Subselect ca. 0.1 Sekunden:
SELECT h.host_id, COUNT( u.user_id ) AS users, (
SELECT COUNT( hu.user_id )
FROM host_users hu
WHERE hu.host_id = h.host_id
AND hu.user_id = u.user_id
GROUP BY hu.host_id
) AS users2
FROM phpbb_users u, phpbb_hosts h
WHERE u.host_id = h.host_id
GROUP BY h.host_id
LIMIT 0 , 100
LEFT JOIN ca. 30 Sekunden:
SELECT h.host_id, COUNT(u.user_id) as users
FROM phpbb_users u, phpbb_hosts h
LEFT JOIN host_users hu
ON hu.user_id = u.user_id
WHERE u.host_id = h.host_id
OR hu.host_id = h.host_id
GROUP BY h.host_id, hu.host_id
Ist mein LEFT JOIN irgendwie falsch oder wieso kommt es zu diesem "Fehler"?
Gruß