Oracle千万级数据分页查询优化

Oracle千万级数据分页查询优化

1. 未优化之前:

SELECT TMP.* FROM (SELECT ROWNUM AS "ROWNO",${tableId},
${columnName}
            FROM ${tableName}) TMP
            WHERE
                TMP.ROWNO <= #{end}
                AND TMP.ROWNO >= #{start}

2.优化之后:

SELECT T1.${tableId},T1.${columnName}
FROM ${tableName} T1, (SELECT RID
                       FROM (SELECT
                               ROWNUM RN,
                               T.RID
                             FROM (SELECT
                                     ROWID RID
                                   FROM ${tableName}
                                  ) T
                             WHERE ROWNUM <= #{END})
                       WHERE RN > #{START}) T2
WHERE T1.ROWID = T2.RID

转载于:https://my.oschina.net/vright/blog/1543709

你可能感兴趣的:(数据库)