1.分页的三种实现 速度最快 1 > 2 > 3
[color=red]2.先介绍常用的rownum[/color]
3.使用 rowid分页(如果查询里面有 排序了,在最外面也要排序)
4.采用分析函数
[color=red]5.介绍下rowid(为什么rowid比rownum快)[/color]
[table]
| 数据对象编号| 文件编号| 块编号|行编号
| OOOOOO| FFF| BBBBBB|RRR
| data_object_id#| rfile#| block#| row#
| 32bit| 12bit| 22bit| 16bit
[/table]
1.第一种采用rowid 4层
2.第二种是用 rownum分页 3 层 (oracle规定:每次查询中 rownum只能用一次)
3.第三种是 采用分析函数来实现[color=red]2.先介绍常用的rownum[/color]
select * from (select row_.*,rownum rn from (select empno,ename,sal from scott.emp where sal>800 order by sal ) row_ where rownum<11) where rn>5;3.使用 rowid分页(如果查询里面有 排序了,在最外面也要排序)
select * from emp where rowid in (select rid from (select rownum rn,rid from (select rowid rid,sal from emp where sal>800 order by sal) where rownum<11) where rn>5) order by sal; //发现不能和group by 使用,有人说是oracle的bug。所以 一般人都用 rownum分组4.采用分析函数
select * from (select e.*,row_number() over(order by sal) rk from emp e where e.sal>800) where rk<11 and rk>5 // 这个 在数据量比较多的时候 速度严重下降,所以一般人也不选这个.[color=red]5.介绍下rowid(为什么rowid比rownum快)[/color]
rowid 确定了每条记录在oracle中的那一个数据对象,那个数据文件,块,行上。相当于直接在磁盘上读取数据.rownum 相对于是一个映射值,还需要根据这个映射值去到磁盘上找。
rowid的格式如下: (有人说根据每个段的大小可以算出每个物理文件的大小。)[table]
| 数据对象编号| 文件编号| 块编号|行编号
| OOOOOO| FFF| BBBBBB|RRR
| data_object_id#| rfile#| block#| row#
| 32bit| 12bit| 22bit| 16bit
[/table]
本文介绍了Oracle数据库中的三种分页方法及其性能对比。首先讲解了使用ROWNUM进行分页的基本原理和实现方式,随后探讨了利用ROWID进行分页的优势及其实现细节,最后对比了分析函数ROW_NUMBER()在分页查询中的应用及其效率问题。
182

被折叠的 条评论
为什么被折叠?



