我們正在將mysql從5.5升級(jí)到5.6,現(xiàn)在某些查詢的速度非常慢.
以前需要0.005秒的查詢現(xiàn)在需要49秒.
對(duì)5.6的查詢似乎跳過了索引:
---- ------------- ------- ------- ---------------------------------------------------- --------- --------- ------ -------- ------------- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | ---- ------------- ------- ------- ---------------------------------------------------- --------- --------- ------ -------- ------------- | 1 | SIMPLE | pens | index | index_contents_on_slug,index_contents_on_slug_hash | PRIMARY | 4 | NULL | 471440 | Using where | ---- ------------- ------- ------- ---------------------------------------------------- --------- --------- ------ -------- ------------- 1 row in set (0.00 sec)
但是在5.5上并沒有被跳過:
---- ------------- ------- ------------- ---------------------------------------------------- ---------------------------------------------------- --------- ------ ------ ---------------------------------------------------------------------------------------------- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | ---- ------------- ------- ------------- ---------------------------------------------------- ---------------------------------------------------- --------- ------ ------ ---------------------------------------------------------------------------------------------- | 1 | SIMPLE | pens | index_merge | index_contents_on_slug,index_contents_on_slug_hash | index_contents_on_slug_hash,index_contents_on_slug | 768,768 | NULL | 2 | Using union(index_contents_on_slug_hash,index_contents_on_slug); Using where; Using filesort | ---- ------------- ------- ------------- ---------------------------------------------------- ---------------------------------------------------- --------- ------ ------ ---------------------------------------------------------------------------------------------- 1 row in set (0.00 sec)
兩個(gè)數(shù)據(jù)庫都是從相同的mysql轉(zhuǎn)儲(chǔ)創(chuàng)建的.
在5.6上進(jìn)行導(dǎo)入時(shí),是否不會(huì)構(gòu)建這些索引?如何強(qiáng)制創(chuàng)建索引?
查詢:
SELECT `pens`.* FROM `pens` WHERE (slug_hash = 'style' OR slug = 'style') ORDER BY `pens`.`id` DESC LIMIT 1
編輯:刪除架構(gòu)
解決方法:
最終,上面接受的答案是正確的.
@RandomSeed的幫助使我朝著正確的方向思考.基本上,在5.6中創(chuàng)建的優(yōu)化計(jì)劃與在5.5中創(chuàng)建的優(yōu)化計(jì)劃大不相同,因此您可能必須像我一樣對(duì)查詢進(jìn)行重新處理.
我沒有最終使用FORCE INDEX,而是刪除了查詢的一部分,直到我確定是什么導(dǎo)致5.6丟失索引.然后,我對(duì)應(yīng)用程序邏輯進(jìn)行了重新設(shè)計(jì)以解決該問題.
聯(lián)系客服