0
私はこのSQLを持っていると思っていましたが、反復的な文章を避けてパフォーマンスを向上させるために書く方が良いと思います。MySQLの結合とユニオンの最適化
提案がありますか?
CREATE OR REPLACE VIEW tx_oriconvocatorias_consultas AS
SELECT pubs.*, pais.nombre_es as area,
GROUP_CONCAT(DISTINCT linea_es ORDER BY linea_es SEPARATOR '\n') as linea_es,
GROUP_CONCAT(DISTINCT modalidad_es ORDER BY modalidad_es SEPARATOR '\n') as modalidad_es,
GROUP_CONCAT(DISTINCT orgs.nombre_es ORDER BY orgs.nombre_es SEPARATOR '\n') as organizacion_es
FROM tx_oriconvocatorias_publicadas AS pubs
INNER JOIN tx_oriconvocatorias_publicadas_lineas_mm as ml
ON ml.uid_local=pubs.uid
INNER JOIN tx_oritablascomunes_lineas as lins
ON ml.uid_foreign=lins.uid
INNER JOIN tx_oriconvocatorias_publicadas_modalidades_mm as mm
ON mm.uid_local=pubs.uid
INNER JOIN tx_oritablascomunes_modalidades as mods
ON mm.uid_foreign=mods.uid
INNER JOIN tx_oriconvocatorias_publicadas_organizaciones_mm as mo
ON mo.uid_local=pubs.uid
INNER JOIN tx_oritablascomunes_organizaciones as orgs
ON mo.uid_foreign=orgs.uid
INNER JOIN tx_oritablascomunes_paises AS pais
ON pubs.carea = CONCAT('tx_oritablascomunes_paises_',pais.uid)
GROUP BY uid
UNION
SELECT pubs.*, regs.nombre_es as area,
GROUP_CONCAT(DISTINCT linea_es ORDER BY linea_es SEPARATOR '\n') as linea_es,
GROUP_CONCAT(DISTINCT modalidad_es ORDER BY modalidad_es SEPARATOR '\n') as modalidad_es,
GROUP_CONCAT(DISTINCT orgs.nombre_es ORDER BY orgs.nombre_es SEPARATOR '\n') as organizacion_es
FROM tx_oriconvocatorias_publicadas AS pubs
INNER JOIN tx_oriconvocatorias_publicadas_lineas_mm as ml
ON ml.uid_local=pubs.uid
INNER JOIN tx_oritablascomunes_lineas as lins
ON ml.uid_foreign=lins.uid
INNER JOIN tx_oriconvocatorias_publicadas_modalidades_mm as mm
ON mm.uid_local=pubs.uid
INNER JOIN tx_oritablascomunes_modalidades as mods
ON mm.uid_foreign=mods.uid
INNER JOIN tx_oriconvocatorias_publicadas_organizaciones_mm as mo
ON mo.uid_local=pubs.uid
INNER JOIN tx_oritablascomunes_organizaciones as orgs
ON mo.uid_foreign=orgs.uid
INNER JOIN tx_oritablascomunes_regiones AS regs
ON pubs.carea = CONCAT('tx_oritablascomunes_regiones_',regs.uid)
GROUP BY uid
感謝からあなたのUNION句クエリを構築
:両方のクエリーに共通するすべてのSQLを収集するためにビューを使用します。私はそれを行います。 – Memochipan