oracle分頁查找時,start與size在ibatis中的設(shè)置
使用oracle + ibatis進行數(shù)據(jù)分頁查找時,對傳入的參數(shù)start與size,進行如下查找語句
因為ibatis會將#xxx#參數(shù)解析為PreparedStatement中的?,但是如果使用#start#+#size#,會產(chǎn)生?+?的語句,影響oracle語句動態(tài)解析,實際上這個參數(shù)在執(zhí)行時完全可以先計算和,再作為一個值傳入語句,采用$start$+$size$正是做到了這點,大大加快了執(zhí)行速度
select * from
(select t.*, romnum rn from
(select * from user
where score > #score#
order by $orderby$
) t
where rownum <= #start# + #size# )
where rn > #start#
在數(shù)據(jù)量較少時,以上語句沒有問題,但是在達到500w+數(shù)據(jù)量時,就會發(fā)生急劇的性能下降,經(jīng)過測試,發(fā)現(xiàn)應(yīng)該改為以下的語句,就可以避免,在千萬數(shù)據(jù)以上仍可以在百毫秒得出結(jié)果(select t.*, romnum rn from
(select * from user
where score > #score#
order by $orderby$
) t
where rownum <= #start# + #size# )
where rn > #start#
select * from
(select t.*, romnum rn from
(select * from user
where score > #score#
order by $orderby$
) t
where rownum <= $start$ + $end$ )
where rn > #start#
(select t.*, romnum rn from
(select * from user
where score > #score#
order by $orderby$
) t
where rownum <= $start$ + $end$ )
where rn > #start#
因為ibatis會將#xxx#參數(shù)解析為PreparedStatement中的?,但是如果使用#start#+#size#,會產(chǎn)生?+?的語句,影響oracle語句動態(tài)解析,實際上這個參數(shù)在執(zhí)行時完全可以先計算和,再作為一個值傳入語句,采用$start$+$size$正是做到了這點,大大加快了執(zhí)行速度
posted on 2012-07-13 14:41 初一七月 閱讀(822) 評論(0) 編輯 收藏 所屬分類: DB