亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Why does mysql order by not use index sorting?
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-05-18 10:44:38
0
3
1125

order by city_id (primary key index)

order by country_id (no indexing!!!)

PHP中文網(wǎng)
PHP中文網(wǎng)

認(rèn)證0級(jí)講師

reply all(3)
漂亮男人

Your city_id is the primary key, and country_id is the composite primary key.

劉奇

changed to

SELECT * FROM city FORCE INDEX(idx_fk_country_id) ORDER BY country_id;

That’s it, you’re forcing the use of an index in SELECT中查詢了索引建以外的列,那么ORDER BY就不會(huì)使用索引了。你可以用FORCE INDEX.

Another point is the so-called covering index. The definition of a covering index is: MySQL can return the select field based on the index without querying the file again based on the index to get the result.

What happens when you use select *時(shí),你沒有強(qiáng)制指定索引,那么mysql為了得到你的查詢的字段而查詢文件,然后再進(jìn)行排序操作,這就沒有用到覆蓋索引。而你使用了force index就會(huì)強(qiáng)制使用覆蓋索引,這樣就不會(huì)出現(xiàn)filesort.

Ty80

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template