我有表中有数以百万计的记录从我提取成千上万的行到临时表,即使查询临时表与简单的地方,它需要几小时才能得到结果,是否有任何知道我可以如何加快查询处理时间?加快查询执行速度
查询是这样的
Select col_name col1, col_name2 col2 from tbl_temp where col_name3 = 'value' and
col_name4 = 'value' order by col_name desc limit 2;
我有表中有数以百万计的记录从我提取成千上万的行到临时表,即使查询临时表与简单的地方,它需要几小时才能得到结果,是否有任何知道我可以如何加快查询处理时间?加快查询执行速度
查询是这样的
Select col_name col1, col_name2 col2 from tbl_temp where col_name3 = 'value' and
col_name4 = 'value' order by col_name desc limit 2;
一定col_name3,col_name4和COL_NAME有正确的索引,而且,如果可能的话,如果你还没有加入索引来临时日期
partritioned表,你应该。
雅我已经添加索引到临时表为col_name3 –
尝试explain
查询。它将为您提供有关查询执行方式的大量信息,包括需要查看的行数以及是否可以使用索引。
EXPLAIN Select col_name col1, col_name2 col2 from tbl_temp where col_name3 = 'value' and col_name4 = 'value' order by col_name desc limit 2;
雅试图解释还额外获得“where子句”。 –
不,我不能添加这些列索引他们包含重复的条目。 –
@ somu.web:只要您不尝试将它们设置为主要或唯一,您*可以*索引包含重复项的列。 – Kaivosukeltaja