İlk Yöntem row_number ile:
SQL> create table pagination_test( x varchar2(128) );
Table created
Executed in 0,09 seconds
SQL> BEGIN
2 FOR i IN 1 .. 1000000 LOOP
3 INSERT INTO pagination_test VALUES ( 'aassddff' || i);
4 END LOOP;
5 COMMIT;
6 END;
7 /
PL/SQL procedure successfully completed
Executed in 64,693 seconds
SQL> SELECT inner_view.x
2 FROM (SELECT x, row_number() over( ORDER BY x ASC) row_num
3 FROM pagination_test) inner_view
4 WHERE inner_view.row_num BETWEEN 400500 AND 400510;
X
--------------------------------------------------------------------------------
aassddff460446
aassddff460447
aassddff460448
aassddff460449
aassddff46045
aassddff460450
aassddff460451
aassddff460452
aassddff460453
aassddff460454
aassddff460455
11 rows selected
Executed in 14,591 seconds
SQL>
İkinci Yöntem rownum ile:
SQL> drop table pagination_test;
Table dropped
Executed in 1,422 seconds
SQL> create table pagination_test( x varchar2(128) );
Table created
Executed in 0,02 seconds
SQL> BEGIN
2 FOR i IN 1 .. 1000000 LOOP
3 INSERT INTO pagination_test VALUES ( 'aassddff' || i);
4 END LOOP;
5 COMMIT;
6 END;
7 /
PL/SQL procedure successfully completed
Executed in 74,487 seconds
SQL> SELECT outer_view.x
2 FROM (SELECT inner_view.x, rownum inner_rownum
3 FROM (SELECT x FROM pagination_test ORDER BY x ASC) inner_view
4 WHERE rownum <= 400510) outer_view
5 WHERE outer_view.inner_rownum >= 400500;
X
--------------------------------------------------------------------------------
aassddff460446
aassddff460447
aassddff460448
aassddff460449
aassddff46045
aassddff460450
aassddff460451
aassddff460452
aassddff460453
aassddff460454
aassddff460455
11 rows selected
Executed in 7,631 seconds
SQL>
Table dropped
Executed in 1,422 seconds
SQL> create table pagination_test( x varchar2(128) );
Table created
Executed in 0,02 seconds
SQL> BEGIN
2 FOR i IN 1 .. 1000000 LOOP
3 INSERT INTO pagination_test VALUES ( 'aassddff' || i);
4 END LOOP;
5 COMMIT;
6 END;
7 /
PL/SQL procedure successfully completed
Executed in 74,487 seconds
SQL> SELECT outer_view.x
2 FROM (SELECT inner_view.x, rownum inner_rownum
3 FROM (SELECT x FROM pagination_test ORDER BY x ASC) inner_view
4 WHERE rownum <= 400510) outer_view
5 WHERE outer_view.inner_rownum >= 400500;
X
--------------------------------------------------------------------------------
aassddff460446
aassddff460447
aassddff460448
aassddff460449
aassddff46045
aassddff460450
aassddff460451
aassddff460452
aassddff460453
aassddff460454
aassddff460455
11 rows selected
Executed in 7,631 seconds
SQL>
Yukarıdaki sonuçlardan görüleceği üzere rownum ile içiçe 3 select ile yapılan sorgu daha hızlı çalışmıştır. Detaylar için her bir sorgunun execution plan ine bakılabilir
No comments:
Post a Comment