我就不吃芹菜

导航

 
/*
BEGIN
  CREATE TABLE APPUSER(IDS NUMBER(8),
                       USERNAME VARCHAR2(20),
                       PASSWORD VARCHAR2(20),
                       CTIME DATE);

  FOR S IN 1 .. 100000 LOOP
    INSERT INTO APPUSER
    VALUES
      (S,
       'username' || S,
       '123456abc',
       SYSDATE - DBMS_RANDOM.VALUE(300, 500));
  END LOOP;
  COMMIT;
END;
*/

--1.按分析函数来分(速度最慢)
SELECT *
  FROM (SELECT T.*, ROW_NUMBER() OVER(ORDER BY IDS DESC) RK FROM APPUSER T)
 WHERE RK <= 100000
   AND RK > 99990;
--2.按ROWNUM来分
SELECT *
  FROM (SELECT T.*, ROWNUM RN
          FROM (SELECT * FROM APPUSER ORDER BY IDS DESC) T
         WHERE ROWNUM <= 100000)
 WHERE RN > 99990;
--3.根据ROWID来分(速度最快)
SELECT *
  FROM APPUSER
 WHERE ROWID IN
       (SELECT RID
          FROM (SELECT ROWNUM RN, RID
                  FROM (SELECT ROWID RID, IDS FROM APPUSER ORDER BY IDS DESC)
                 WHERE ROWNUM <= 100000)
         WHERE RN > 99990)
 ORDER BY IDS DESC;

针对100000条数据取最后一页的内容, 查询10次, 总结三种分页方式, 各自的效率,

第一种平均时间0.243s

第二种平均时间0.163s

第三种平均时间0.144s

posted on 2017-12-17 00:42  我就不吃芹菜  阅读(131)  评论(0编辑  收藏  举报