查询优化-索引

索引与主键的区别

http://database.51cto.com/art/201108/279897.htm

WITH cr AS (SELECT ROW_NUMBER() OVER(ORDER BY Time_t desc) rownumber,Msg_id, modelid,infoId,Time_t,User_id FROM t_msg_info WITH(NOLOCK) WHERE Time_t<=GETDATE() and isShow=1 AND access_type_id=1 and [Type] IN (20,6,11,21,9,28,10,8))
SELECT * from cr WHERE rownumber > 10000 AND  rownumber < 10020

WITH cr AS (SELECT ROW_NUMBER() OVER(ORDER BY Msg_id desc) rownumber,Msg_id, modelid,infoId,Time_t,User_id FROM t_msg_info WITH(NOLOCK) WHERE Time_t<=GETDATE() and isShow=1 AND access_type_id=1 and [Type] IN (20,6,11,21,9,28,10,8))
SELECT * from cr WHERE rownumber > 10000 AND  rownumber < 10020

两句话,只一个order by 的字段发生了改变,其查询速度大幅度提升。

这就是主键(索引)带来的好处

另外 用 > <比用 between and快那么稍微一丢丢 。

分页排序的相关信息查看此文:http://www.cnblogs.com/iamowen/archive/2011/11/03/2235068.html

posted on 2017-06-17 10:39  落忆无痕  阅读(205)  评论(0编辑  收藏  举报

导航