未优化之前:
SELECT TMP.* FROM (SELECT ROWNUM AS "ROWNO",${tableId},${columnName} FROM ${tableName}) TMP WHERE TMP.ROWNO <= #{end} AND TMP.ROWNO >= #{start}
优化之后:
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
性能:懒得算了,单纯通过观察,第一条SQL查询耗时30s以上的很多,第二条几乎都维持在300ms,起步就相差几十倍到一百倍,数据越多,相差越大,几百倍或更多应该也会发生。
原文链接:https://www.f2er.com/oracle/207578.html