zoukankan      html  css  js  c++  java
  • 关于分页的研究

    在项目的开发当中,分页会经常使用到,尤其在数据的显示方面,但是海量数据时,分页的效率就值得去研究下,

    首先,大家都经常使用的一种分页方法,例如(以下以在sql中为例)

    select top 10 * from position_Carrier where id not in (select top ((2-1)*10) id from position_Carrier order by id  ) order by id

    这是获取第二页的数据,但是我们知道对于查询语句来说,存在not in这类关键字简直是对查询速度的一种扼杀,这个致命缺点虽然有top字段的弥补,但是还是略感不足,改造not in迫在眉睫,也就是让查询语句符合SARG形式

    改造方法一、

    select top 10 * from  position_Carrier where id>isnull((select max(id) from (select top ((2-1)*10) id  from position_Carrier order by id) t),0) order by id

    改造方法二、用到了row_number()这个sql自带的

    select top 10 * from (select row_number() over (order by id ) as 'rows',* from position_Carrier)  t where rows>((1-1)*10)

    方法一和方法二的查询速度,没有测试过,不过差别应该不大

  • 相关阅读:
    sqlalchemy 使用pymysql连接mysql 1366错误
    mysql之数据导出
    Go常见语句
    huffman code
    后缀数组,目前比较赶进度,而且有点难,所以放到以后再来看
    hash
    bipartite matching
    spanning tree
    拓扑排序
    Union Find
  • 原文地址:https://www.cnblogs.com/yinhaichao/p/2359246.html
Copyright © 2011-2022 走看看