`
xiaocao000
  • 浏览: 227429 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Pagging

阅读更多
1. Derby

http://db.apache.org/derby/faq.html#limit

Derby does not support the LIMIT syntax. However, Derby 10.4 added the ROW_NUMBER function and Derby 10.7 added the OFFSET and FETCH clauses.

Derby also supports limiting the number of rows returned by a query through JDBC. For example, to fetch the first 5 rows of a large table:

Statement stmt = con.createStatement(); 
stmt.setMaxRows(5); 
ResultSet rs = stmt.executeQuery("SELECT * FROM myLargeTable"); 


Some related tuning tips are available in this external article.

Starting with the 10.4.1.3 release Derby also supports limiting the number of rows using the ROW_NUMBER function.

For example, to fetch the first 5 rows of a large table:
SELECT * FROM ( 
    SELECT ROW_NUMBER() OVER() AS rownum, myLargeTable.* 
    FROM myLargeTable 
) AS tmp 
WHERE rownum <= 5; 


The ROW_NUMBER function can also be used to select a limited number of rows starting with an offset, for example:
SELECT * FROM ( 
    SELECT ROW_NUMBER() OVER() AS rownum, myLargeTable.* 
    FROM myLargeTable 
) AS tmp 
WHERE rownum > 200000 AND rownum <= 200005; 


For more information, refer to the ROW_NUMBER built-in function in the Derby Reference Manual (available from the Documentation page). Development notes are available on the OLAPRowNumber wiki page.

The LIMIT keyword is not defined in the SQL standard, and is currently not supported.

2. Oracle

http://www.cnblogs.com/hxw/archive/2005/09/11/234619.html

1.根据ROWID来分

select * from t_xiaoxi where rowid in(select rid from (select rownum rn,rid from(select rowid rid,cid from
t_xiaoxi  order by cid desc) where rownum<10000) where rn>9980) order by cid desc;


执行时间0.03秒

2.按分析函数来分

select * from (select t.*,row_number() over(order by cid desc) rk from t_xiaoxi t) where rk<10000 and rk>9980;


执行时间1.01秒

3.按ROWNUM来分

select * from(select t.*,rownum rn from(select * from t_xiaoxi order by cid desc) t where rownum<10000) where rn>9980; 



执行时间0.1秒

其中t_xiaoxi为表名称,cid为表的关键字段,取按CID降序排序后的第9981-9999条记录,t_xiaoxi表有70000多条记录
个人感觉1的效率最好,3次之,2最差

统计总数
select count(*) from myLargeTable;
select count(*) from (select * from myLargeTable);



3. MySQL

select * from myLargeTable limit m;
select * from myLargeTable limit m,n;
select count(*) from myLargeTable;




4. PostgreSQL

select * from myLargeTable  offset rowBegin limit size;
select count(*) from myLargeTable;
select count(*) from (select * from myLargeTable) as my_Large_Table;



分享到:
评论

相关推荐

    pagging:静态填充(简单)

    pagging ####static pagging (simple) 这是我自己写的一个简单的实现静态分页的小练习: 每触发一次点击事件,重写页面 停留在首页或者第一次进入页面时,下一页和末页可点击 这是停留在中间页面时显示的效果...

    分页和选择标签

    在给定的`pagging.tld`文件中,我们可以推测这是一个自定义的分页标签库(TLD,Tag Library Descriptor)定义,它提供了用于在JSP页面中实现分页功能的标签。这个库可能包含了如`&lt;paging:paginate&gt;`这样的标签,用于在...

    paging3:使用Kotlin Flow和RxJava实现Paging3

    分页3 使用Kotlin Flow和RxJava实现Paging3 由从TMDB加载影片的4部分组成: 标签1:使用Kotlin Flow使用PagingSource 标签2:使用Kotlin Flow使用RemoteMediator 标签3:使用RxJava使用RxPagingSource 选项卡4:...

    DeMonJetPack:JetPack组件学习及模块化使用示例

    Pagging 分页库 Hilt 依赖注入 DataStore 数据存储 WorkManager 异步任务调度 App Startup 应用启动 MotionLayout 运动和微件动画 框架 框架 说明 备注 ARouter 阿里路由框架 LiveEventBus 美团消息总线 MMKV 腾讯...

    Newsster:使用Paging3,Hilt,协程,Flow,Jetpack,MVVM架构的Android应用

    Newsster是一个使用MVVM模式和Android Jetpack的演示应用程序:带有后端API的Pagging 3库,用于ViewModel,LiveData,ViewBinding,Room,Dagger-Hilt和Navigations Components的Saved State模块。 该应用程序使用...

    dalgenx:dalgenX是对支付宝dalgen代码生成器的开源实现,freemarker版,可迭代开发生成器,同时支持ibatis和mybatis

    dalgen开源初级版最初由badqiu放在taocode上,badqiu大神我不认识,mybatis-plus-pagging.jar那个分页器有一个@author badqiu 我对本项目持续开发优化从2015年开始,对生产环境进行改造,特别是支持可迭代开发...

    操作系统篇-浅析分页机制.docx

    ### 操作系统篇-浅析分页机制 #### 一、引言 在现代软件开发过程中,程序员通常不需要直接管理内存资源,也不必担心内存不足的问题。这一切得益于操作系统的分页机制,它作为虚拟存储技术的核心组成部分,允许进程...

Global site tag (gtag.js) - Google Analytics