Hardcore MySQL query optimisation

ahh nice one :) got a few bits to do today but I will have a look as soon as I get a chance, thanks for the responses!
 
Not sure if you're still needing help with this, but here goes...

Dude :) Nice one, trying to puzzle this out at the mo, its returning 0 at the mo but I am sure thats because of my original explanation rather than your solution, thanks muchly!
 
Ahh, the inner join needed to be a.site_id = b.site_id :) Thanks again Hambut_Bulge, you are an SQL machine :D

EXPLAIN BEFORE

id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY mgroups ALL PRIMARY,mg_id NULL NULL NULL 9 Using temporary; Using filesort
1 PRIMARY mgroups_explicit ref me_mg_id me_mg_id 4 engine_4.mgroups.mg_id 8750
1 PRIMARY contacts ALL PRIMARY,c_id NULL NULL NULL 86012 Using where; Using join buffer
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const table..

EXPLAIN AFTER

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE d system NULL NULL NULL NULL 0 const row not found
1 SIMPLE b const PRIMARY,mg_id PRIMARY 4 const 1
1 SIMPLE c system me_mg_id NULL NULL NULL 1
1 SIMPLE a ref site_id site_id 4 const 8155 Using where

Win :D
 
Last edited:
Back
Top Bottom