您好我的查询性能有问题,从我看来,group_concat似乎执行得非常慢。事实上,如果我评论它,速度增加上升100倍。无论如何,我可以更改查询,以便它可以更快?这是查询:
redirect_to thanks_subscription_path(@YourSavedObject), notice: 'Some message'
我在想,或许,我可以使用同步的ajax调用来获取group_concat给出的CSV所获得的信息,你认为会更好吗?
以下是EXPLAIN
的结果SELECT
g.id_gara,
( SELECT
GROUP_CONCAT( TIG.sigla, (' - '), Cl.sigla, (' ;'),
( SELECT color
FROM bootstrap_colors
where non_color = '0'
ORDER BY RAND()
LIMIT 1 ) ) AS class_sigla
FROM
associazione_gara_tipologiagara_classifica as A
INNER JOIN tipologie_gare AS TIG
ON A.id_tipologia_gara = TIG.ID
INNER JOIN classifiche_gare AS Cl
ON A.id_classifica = Cl.idclassifiche_gare
WHERE
A.id_gara = g.id_gara
GROUP BY
A.id_gara ) cat_class_list,
tg.bootstrap_description color_gara,
ta.bootstrap_description color_aggiudicazione
FROM
gara g
LEFT OUTER JOIN ente AS en
ON g.id_ente = en.ID
LEFT OUTER JOIN tipo_gara AS tg
ON g.tipo_gara = tg.idtipo_gara
LEFT OUTER JOIN admin AS ad
ON g.opElab = ad.id
LEFT OUTER JOIN ente_presso AS ep
ON g.indirizzo_ente = ep.idente_presso
LEFT OUTER JOIN tipo_aggiudicazione_gara AS ta
ON g.criterio_aggiudicazione = ta.idtipo_aggiudicazione_gara
WHERE
(en.e_prov LIKE '%bn%')
ORDER BY
g.id_gara DESC
LIMIT 10
答案 0 :(得分:0)
碰巧是mysql优化器没有高效执行。它无法轻松解决查询中存在的多个连接。因此,解决此问题的最佳方法是使用SELECT STRAIGHT_JOIN而不是SELECT,以便强制优化器“按原样”执行查询而不尝试优化它。
Saluti。