首页 > 数据库 > 数据库开发技术 > 通用SQL优化经典等价改写【二】——分页优化
drop table test_rownum purge; create table test_rownum as select * from dba_objects; select count(*) from test_rownum; COUNT(*) ---------- 111052 alter session set statistics_level=all; set linesize 1000 set pagesize 500
select * from (select t.*, rownum as rn from test_rownum t) a where a.rn>=1 and a.rn<=10;
SQL_ID b3z5zu2apz8zu, child number 0 ------------------------------------- select * from (select t.*,rownum as rn from test_rownum t) a where a.rn>=1 and a.rn<=10 Plan hash value: 1157459331 -------------------------------------------------------------------------------------- | Id |Operation | Name |Starts |E-Rows |A-Rows | A-Time |Buffers | -------------------------------------------------------------------------------------- |* 1 | VIEW | | 1 | 101K| 10 |00:00:00.16| 1723 | | 2 | COUNT | | 1 | | 111K|00:00:00.01| 1723 | | 3 | TABLE ACCESS FULL| TEST_ROWNUM| 1 | 101K| 111K|00:00:00.01| 1723 | -------------------------------------------------------------------------------------- 0 sorts (disk)
select * from (select t.*, rownum as rn from test_rownum t where rownum<=10) a where a.rn>=1;
SQL_ID 5jvt2xsjrqc33, child number 0 ------------------------------------- select * from (select t.*,rownum as rn from test_rownum t where rownum<=10) a where a.rn>=1 Plan hash value: 2232708344 ------------------------------------------------------------------------------------ | Id |Operation |Name |Starts |E-Rows |A-Rows | A-Time |Buffers | ------------------------------------------------------------------------------------ |* 1| VIEW | | 1 | 10 | 10 |00:00:00.01| 5 | |* 2| COUNT STOPKEY | | 1 | | 10 |00:00:00.01| 5 | | 3| TABLE ACCESS FULL|TEST_ROWNUM| 1 | 101K| 10 |00:00:00.01| 5 | ------------------------------------------------------------------------------------
未完待续...
公众号:收获不止数据库
微信:ljbyxl1213
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9091385/viewspace-3082259/ ,如需转载,请注明出处,否则将追究法律责任。