2

一个奇怪的 oracle 分页的问题

 3 years ago
source link: https://www.v2ex.com/t/798194
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

一个奇怪的 oracle 分页的问题

  fdgdbr · 8 小时 39 分钟前 · 238 次点击

有一个表,表名就叫 test_table 好了,数据量 600 多万,分页查询,我在代码里面执行 sql,sql 语句如下:

select a.* from ( select t.*,rownum rowno from test_table t where column1 = 'abc' and rownum < 11 ) a where a.rowno >= 1;

其中 column1 已经加了索引,不分页的情况下满足条件的数据量有 20 万条,然后发现查第一页的时候很慢,要 2 分钟,但是查询第二页就很快了,不到 1 秒钟,我把 sql 原样复制到 PL/SQL developer 里面执行,结果是一样的,还是第一页很慢,第二页很快。

这是第一个不理解的点

然后我想到 PL/SQL developer 在执行 sql 的时候默认就会分页显示,所以我就把上面 sql 里面 rownum 的条件去掉了,也就是我在 PL/SQL developer 里面执行下面的 sql:

select * from test_table where column1 = 'abc';

查询会返回大概 10 来条数据,但是很快了,这是第二个不理解的点,PL/SQL developer 底层去执行分页查询的时候到底是执行了怎么样的一句 sql


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK