ibatis mysql 效能 Ibatis 優化

2021-10-18 06:02:26 字數 1247 閱讀 4374

大概一年左右的時間裡club資料庫的cpu一直處於很高的負荷中,從40%一直攀公升到如今的80%,隨著資料量的增加,負擔越來越重,已經頻繁超時,且瀕臨無法服務的邊緣。

經長期的調查發現這是ibatis.net的乙個效能問題(同樣適用於ibatis)。

問題是這樣的:club的主要業務表是comment表,其中的主鍵是乙個varchar(36)型別的guid,當每次搜尋一條記錄時我們會使用這樣的乙個statement:

select id, referenceid, referencename, referencetype, referenceimage, referencetime, title, pros, cons, content, score, viewcount, replycount, usefulvotecount, uselessvotecount, userid, userimage, userlevelid, userregistertime, userprovince, userip, creationtime, status, remark

from comment with (nolock)

where id = #value# and status >= 0

雖然看著十分正常,但是卻是問題的關鍵,因為parameterclass是string,當ibatis.net動態組成的sql語句會將其預設定為乙個nvchar(36)來對資料庫進行查詢,這樣與原有資料庫的型別不一樣,

造成了全表掃瞄,解決辦法是制定傳入型別的dbtype(inline方法為):

select id, referenceid, referencename, referencetype, referenceimage, referencetime, title, pros, cons, content, score, viewcount, replycount, usefulvotecount, uselessvotecount, userid, userimage, userlevelid, userregistertime, userprovince, userip, creationtime, status, remark

from comment with (nolock)

where id = #value:varchar# and status >= 0

當然也可以使用parametermap來解決(具體參考ibatis手冊)。通過這個辦法club資料庫壓力已經只有17%左右,非常有效。我認為在string作為引數且資料庫欄位是乙個varchar的時候都可以使用該方法,且效率很高。

ibatis mysql批量查詢

最近寫到的功能,牽扯到批量查詢,使用的一般的分頁查詢,步驟如下 integer pagesize 3000 1.先查詢記錄數 select count from table name where batch no 2.獲取記錄數並使用在業務層做分頁 integer pagenum count pag...

ibatis mysql使用sql函式注意點

1 前奏 select getcataid pid 2 問題描述 在function操作一次之後 假設輸入引數為1000000000 再次操作 輸入2000000000 就發生異常。檢視異常 無發現getcataid 1000000000 colume 3 分析 原來ibatis這裡多此一舉,把底層...

修改IB中view的frame

問題案例 自定義cell用xib定義,cell子檢視中某個label的內容由網路獲取,因為這個label加了邊框,在獲取資料後需要調整寬度 用sizetofit方法即可 實測發現,這個label有時候寬度確實根據內容變化了,邊框顯示良好,但有時候還是ib裡定義的寬度。原因 想到的解決方案 2.ib裡...