在查询期间丢失了与mysql服务器的连接,有助于优化视图查询

时间:2017-10-19 15:04:44

标签: php mysql

我最近在从视图中加载结果时遇到了实验问题。 似乎耗时超过40秒并且与mysql的连接丢失了。 我配置了这个:

mysql.connect_timeout = -1
max_execution_time  700
max_input_time  700

跳来解决我的问题,但没有变化。 我的示例查询是:

SELECT usuario as 'Encargado', Fecha as 'Fecha', Periodo as 'Periodo', Area as 'Área', Profesor as 'Profesor', TemaAvanzado as 'Tema avanzado', Tarea,FechaPresentacion as 'Fecha de presentación' FROM tm_leccionario_view WHERE curso = 'S1A' ORDER BY fecha DESC, periodo ASC

我应该有171条记录。但我钢铁有错误"#2003:查询过程中与MySQL服务器连接丢失"。

然后我跑:

EXPLAIN SELECT usuario AS  'Encargado', Fecha AS  'Fecha', Periodo AS  'Periodo', Area AS  'Área', Profesor AS  'Profesor', TemaAvanzado AS  'Tema avanzado', Tarea, FechaPresentacion AS  'Fecha de presentación'
FROM tm_leccionario_view
WHERE curso =  'S1A'
ORDER BY fecha DESC , periodo ASC

并得到: enter image description here

我的观点定义是:

VIEW tm_leccionario_view AS select s.group_id AS group_id,
(select p.nombre from parametros p where ((p.valor = s.form_id) and (p.tipo = 'CURSO'))) AS Curso,
(select ss.element_value from wp_formmaker_submits ss where ((ss.form_id = s.form_id) and (ss.group_id = s.group_id) and (ss.element_label = 1))) AS Fecha,
(select substring_index(ss.element_value,' - ',1) from wp_formmaker_submits ss where ((ss.form_id = s.form_id) and (ss.group_id = s.group_id) and (ss.element_label = 2))) AS Area,
(select substring_index(ss.element_value,' - ',-(1)) from wp_formmaker_submits ss where ((ss.form_id = s.form_id) and (ss.group_id = s.group_id) and (ss.element_label = 2))) AS Profesor,
(select ss.element_value from wp_formmaker_submits ss where ((ss.form_id = s.form_id) and (ss.group_id = s.group_id) and (ss.element_label = 3))) AS Periodo,
(select ss.element_value from wp_formmaker_submits ss where ((ss.form_id = s.form_id) and (ss.group_id = s.group_id) and (ss.element_label = 4))) AS TemaAvanzado,
(select ss.element_value from wp_formmaker_submits ss where ((ss.form_id = s.form_id) and (ss.group_id = s.group_id) and (ss.element_label = 5))) AS Tarea,
(select ss.element_value from wp_formmaker_submits ss where ((ss.form_id = s.form_id) and (ss.group_id = s.group_id) and (ss.element_label = 6))) AS FechaPresentacion,
(select u.user_login from wp_users u where (u.ID = s.user_id_wd)) AS Usuario from wp_formmaker_submits s where (s.element_label = 1)

您认为问题出在我的查询定义上吗?如果是这样,我该如何优化呢?

上周,当我在主桌上有1000条记录时,我确实没有这个问题。

0 个答案:

没有答案