sql - MySQL query with multiple INNER JOIN is too slow -


i have query:

$sql="select t1.*, t2.*, t3.*,t4.*,t5.*,t6.*,t7.*,t8.*,t9.asciiname asciiname_9, t10.asciiname asciiname_10,t11.*,t12.*         anunturi t1               inner join tip_proprietate t2                     on t1.tip = t2.id_prop              inner join anunt_preturi t3                     on t1.id_anunt = t3.ext              inner join anunturi_images t5                     on t1.id_anunt = t5.id_ext               inner join tranzactie t4                     on t1.tranzactie = t4.id_tranzactie              inner join anunt_descriere t6                     on t1.id_anunt = t6.ext              inner join anunt_locatie t7                     on t1.id_anunt = t7.ext              inner join zone t8                     on t7.zona = t8.id_zona              inner join locatii t9                     on t7.judet = t9.admin1_code                     , t9.feature_code='adm1'              inner join locatii t10                     on t7.oras = t10.geonameid              inner join anunt_suprafete t11                     on t1.id_anunt = t11.ext              inner join tip_locuinta t12                     on t1.tip2 = t12.id_loc     group t1.id_anunt         t1.status=0     order t1.id_anunt desc         limit 3";  

and use set sql_big_selects=1 before query. runs slow.

aside trying pull every column every table, , state have indexes, try ensuring following covering indexes

table          index locatii        ( feature_code, admin1_code, asciiname ) locatii        ( geonameid, asciiname )  <-- use when join via t10 anunt_locatie  ( judet, zona, oras, ext ) anunturi       ( id_anunt, status ) 

then, restructure query put t9 alias first if table expected have smaller set of records returned vs t1 alias based on status of zero... , add keyword "straight_join"

select straight_join       t1.*,        t2.*,        t3.*,       t4.*,       t5.*,       t6.*,       t7.*,       t8.*,       t9.asciiname asciiname_9,        t10.asciiname asciiname_10,       t11.*,       t12.*           locatii t9           inner join anunt_locatie t7              on t9.admin1_code = t7.judet              inner join zone t8                 on t7.zona = t8.id_zona              inner join locatii t10                 on t7.oras = t10.geonameid              inner join anunturi t1                 on t7.ext = t1.id_anunt               , t1.status = 0                   inner join tip_proprietate t2                    on t1.tip = t2.id_prop                inner join anunt_preturi t3                    on t1.id_anunt = t3.ext                inner join tranzactie t4                    on t1.tranzactie = t4.id_tranzactie                inner join anunturi_images t5                    on t1.id_anunt = t5.id_ext                 inner join anunt_descriere t6                    on t1.id_anunt = t6.ext                inner join anunt_suprafete t11                    on t1.id_anunt = t11.ext                inner join tip_locuinta t12                    on t1.tip2 = t12.id_loc    group        t1.id_anunt           t9.feature_code='adm1'    order        t1.id_anunt desc     limit 3 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -