I have a query which returns me the result after more than one minute:
select distinct o.OMS_IDTOPO,e.TYPEQPTL,e.LIBUPR, o.OMS_SITEA,o.OMS_SITEB, siteA.Code_Postal as CPA, siteB.Code_Postal as CPB, siteA.Nom_court as NomA, siteB.Nom_court as NomB, siteA.Commune as ComA,siteB.Commune as ComB, siteA.Lat_GPS as latA,siteA.Long_GPS as longA, siteB.Lat_GPS as latB,siteB.Long_GPS as longB from occ_wdm_oms as o left join noeud_dico_traitement as siteA on o.OMS_IDNOEUDA=siteA.Code_DICO left join noeud_dico_traitement as siteB on o.OMS_IDNOEUDB=siteB.Code_DICO left join occ_wdm_eqpt as e on o.OMS_IDTOPO=e.OMS_IDTOPO where o.OMS_IDTOPO NOT LIKE '%.VP%' and siteA.Lat_GPS != 0 and siteA.Long_GPS != 0 and siteB.Lat_GPS != 0 and siteB.Long_GPS != 0; However, if I make a projection like
select distinct o.OMS_IDTOPO,e.TYPEQPTL,e.LIBUPR, o.OMS_SITEA,o.OMS_SITEB, siteA.Code_Postal as CPA, siteB.Code_Postal as CPB, siteA.Nom_court as NomA, siteB.Nom_court as NomB, siteA.Commune as ComA,siteB.Commune as ComB, siteA.Lat_GPS as latA,siteA.Long_GPS as longA, siteB.Lat_GPS as latB,siteB.Long_GPS as longB from occ_wdm_oms as o left join noeud_dico_traitement as siteA on o.OMS_IDNOEUDA=siteA.Code_DICO left join noeud_dico_traitement as siteB on o.OMS_IDNOEUDB=siteB.Code_DICO left join (select distinct LIBUPR,TYPEQPTL,OMS_IDTOPO from occ_wdm_eqpt) as e on o.OMS_IDTOPO=e.OMS_IDTOPO where o.OMS_IDTOPO NOT LIKE '%.VP%' and siteA.Lat_GPS != 0 and siteA.Long_GPS != 0 and siteB.Lat_GPS != 0 and siteB.Long_GPS != 0; It takes just 10 seconds.
I've found two similar questions :Which MySQL JOIN query is more efficient? and Optimizing join in vertica.
The answers tell me that normally the first version is more efficient.
And I explain the two query, the result looks like tell me the same thing.
I'm confused because in reality I get the result more quickly by the query with projection, if there are something I've missed ?