- 可先使用explan查看可能有问题的select语句
explain显示了mysql如何使用索引来处理select语句以及连接表。可以帮助选择更好的索引和写出更优化的查询语句。
2.使用force index(idname)指定要使用的索引,提升性能。
insert into t_pre_nex (word, pre_nex, nature)
(select word, 'pre', nature from corpus_cut_word force index(case_id) where case_id = p_case_id and sentence_id = p_sentence_id and id < p_id order by id desc limit p_step)
union
(select word, 'nex', nature from corpus_cut_word force index(case_id) where case_id = p_case_id and sentence_id = p_sentence_id and id > p_id order by id limit p_step);
end;