Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/10/2014, 14:57
gomezepor
 
Fecha de Ingreso: octubre-2014
Mensajes: 2
Antigüedad: 10 años, 1 mes
Puntos: 0
Optimizar consulta grande mysql

Buenas,

Alguna idea sobre como optimizar esta consulta en mysql para consultas con unas tablas grandes?? Gracias de antemano a todos!!

Código SQL:
Ver original
  1. SELECT DISTINCT
  2.       str.STR_LEVEL - 1 AS level,
  3.       str2.STR_LEVEL - 1 AS level2,
  4.       str3.STR_LEVEL - 1 AS level3,
  5.       str4.STR_LEVEL - 1 AS level4,
  6.       ELT(str.STR_LEVEL-1, dest.TEX_TEXT, dest2.TEX_TEXT, dest3.TEX_TEXT, dest4.TEX_TEXT) AS name1,
  7.       ELT(str.STR_LEVEL-1, str.STR_ID, str2.STR_ID, str3.STR_ID, str4.STR_ID) AS id1,
  8.       ELT(str.STR_LEVEL-2, dest.TEX_TEXT, dest2.TEX_TEXT, dest3.TEX_TEXT, dest4.TEX_TEXT) AS name2,
  9.       ELT(str.STR_LEVEL-2, str.STR_ID, str2.STR_ID, str3.STR_ID, str4.STR_ID) AS id2,
  10.       ELT(str.STR_LEVEL-3, dest.TEX_TEXT, dest2.TEX_TEXT, dest3.TEX_TEXT, dest4.TEX_TEXT) AS name3,
  11.       ELT(str.STR_LEVEL-3, str.STR_ID, str2.STR_ID, str3.STR_ID, str4.STR_ID) AS id3,
  12.       ELT(str.STR_LEVEL-4, dest.TEX_TEXT, dest2.TEX_TEXT, dest3.TEX_TEXT, dest4.TEX_TEXT) AS name4,
  13.       ELT(str.STR_LEVEL-4, str.STR_ID, str2.STR_ID, str3.STR_ID, str4.STR_ID) AS id4,
  14.       ELT(str.STR_LEVEL-1, str.STR_ID_PARENT, str2.STR_ID_PARENT, str3.STR_ID_PARENT, str4.STR_ID_PARENT) AS parent
  15.    
  16. FROM `tof_SEARCH_TREE` str
  17. LEFT JOIN `tof_SEARCH_TREE` `str2` ON (str2.STR_ID = str.STR_ID_PARENT)
  18. LEFT JOIN `tof_SEARCH_TREE` `str3` ON (str3.STR_ID = str2.STR_ID_PARENT)
  19. LEFT JOIN `tof_SEARCH_TREE` `str4` ON (str4.STR_ID = str3.STR_ID_PARENT)
  20. LEFT JOIN `tof_DESIGNATIONS` `des` ON (des.DES_ID = str.STR_DES_ID AND des.DES_LNG_ID = 8)
  21. LEFT JOIN `tof_DESIGNATIONS` `des2` ON (des2.DES_ID = str2.STR_DES_ID AND des2.DES_LNG_ID = 8)
  22. LEFT JOIN `tof_DESIGNATIONS` `des3` ON (des3.DES_ID = str3.STR_DES_ID AND des3.DES_LNG_ID = 8)
  23. LEFT JOIN `tof_DESIGNATIONS` `des4` ON (des4.DES_ID = str4.STR_DES_ID AND des4.DES_LNG_ID = 8)
  24. LEFT JOIN `tof_DES_TEXTS` `dest` ON (dest.TEX_ID = des.DES_TEX_ID)
  25. LEFT JOIN `tof_DES_TEXTS` `dest2` ON (dest2.TEX_ID = des2.DES_TEX_ID)
  26. LEFT JOIN `tof_DES_TEXTS` `dest3` ON (dest3.TEX_ID = des3.DES_TEX_ID)
  27. LEFT JOIN `tof_DES_TEXTS` `dest4` ON (dest4.TEX_ID = des4.DES_TEX_ID)
  28. INNER JOIN `tof_LINK_GA_STR` lgs ON (lgs.LGS_STR_ID = str.STR_ID)
  29. INNER JOIN `tof_LINK_LA_TYP` lat ON (lat.LAT_TYP_ID = 19224 AND lat.LAT_GA_ID = lgs.LGS_GA_ID)
  30. HAVING (parent = 10001)
  31. ORDER BY name1, name2, name3, name4

Última edición por gnzsoloyo; 22/10/2014 a las 16:43