Due to different order by fields, the indexes used in the table record_exten in the two queries are different. Obviously the index PRIMARY is more optimized than DeptID.
order by using index
1) The default is to take rownum first and then order by
2) If order by satisfies the situation of using index, order by first, and then take rownum
order by using index is conditional:
1) All columns in ORDER BY must be included in the same index and maintain the order in the index.
2) All columns in ORDER BY must be defined as non-null.
3) In addition, if the column in ORDER BY appears in the where condition, the index
Due to different order by fields, the indexes used in the table record_exten in the two queries are different. Obviously the index PRIMARY is more optimized than DeptID.
order by using index
1) The default is to take rownum first and then order by
2) If order by satisfies the situation of using index, order by first, and then take rownum
order by using index is conditional:
1) All columns in ORDER BY must be included in the same index and maintain the order in the index.
will also be used2) All columns in ORDER BY must be defined as non-null.
3) In addition, if the column in ORDER BY appears in the where condition, the index
Detailed view: http://happymen001.iteye.com/blog/674764