生成環境,同一條sql在不一樣的從庫執行,產生的執行計劃不一樣,一個使用了索引,一個未使用索引html
explain SELECT * FROM `database`.`table` FORCE INDEX(create_time) WHERE create_time >= 1508360400 and create_time <= 1508444806 ORDER BY create_time asc LIMIT 4000, 1000;
OPTIMIZE TABLE
修復碎片或者執行ALTER TABLE foo ENGINE=InnoDB
,以上兩種操做都會鎖表,對於數據量大,且業務高峯期執行須要慎重方案2:強制索引,也就是FORCE index create_time
,強制mysql 引擎使用索引,這裏須要注意一下,當使用強制索引時,存儲引擎會檢查強制索引是否可用,若是不可用,還須要掃描表來判斷那種執行計劃,官方說明:mysql
The FORCE INDEX hint acts like USE INDEX (index_list), with the addition that a table scan is assumed to be very expensive. In other words, a table scan is used only if there is no way to use one of the named indexes to find rows in the table.
也不用擔憂有反作用,若是強制索引可用,正好能提要索引選擇的效率sql
參考連接:.net