我有一个很长的插入查询,它从表中的选择查询中插入数据。问题是选择查询执行时间太长。该表是 MyISAM,并且 select 锁定该表,这会影响也使用该表的其他用户。我发现查询的问题是连接。
当我删除这部分查询时,执行时间不到一秒,但当我离开这部分查询时,执行时间将超过 15 分钟:
LEFT JOIN enq_217 Pex_217
ON e.survey_panelId = Pex_217.survey_panelId
AND e.survey_respondentId = Pex_217.survey_respondentId
AND Pex_217.survey_respondentId != 0
db.table_1
包含 5,90,145 行,e
包含 4,703 行。
解释输出:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY e ALL survey_endTime,survey_type NULL NULL NULL 4703 Using where
1 PRIMARY Pex_217 ref survey_respondentId,idx_table_1 idx_table_1 8 e.survey_panelId,e.survey_respondentId 2 Using index
2 DEPENDENT SUBQUERY enq_11525_timing eq_ref code code 80 e.code 1
如何才能更快地编辑这部分查询?
最佳答案
我建议在表 db.table_1
上为字段 panelId
和 respondentId
创建索引
关于MySQL (MyISAM) SELECT 查询连接时间太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37748679/