您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么解決數據庫LOB字段帶來的性能影響”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“怎么解決數據庫LOB字段帶來的性能影響”吧!
今天開發人員反映一個SQL查詢時間大概2-3分鐘:
SELECT * FROM (SELECT ROWNUM AS ROWNUMBER__, T.* FROM (Select T1.CONSULTINGCODE AS "ConsultingCode", T1.CATEGORY AS "Category", T1.CUSCODE AS "CusCode", T1.ORDERCODE AS "OrderCode", T1.WARECODE AS "WareCode", DECRYPTBYKEY(T1.MOBILEPHONE) AS "MobilePhone", DECRYPTBYKEY(T1.EMAILENCRYPT) AS "EmailEncrypt", T1.ASSIGNTIME AS "AssignTime", T1.REPLIER AS "Replier", T1.REPLYCODE AS "ReplyCode", T1.REPLYDATE AS "ReplyDate", T1.BYWAY AS "ByWay", T1.CREATETIME AS "CreateTime", T1.EVALUATE AS "Evaluate", T1.EXPIREMAN AS "ExpireMan", T1.EXPIREREASON AS "ExpireReason", T1.CONSULTINGTYPEID AS "ConsultingTypeID", T1.STATUS AS "Status", T1.QUESTION AS "Question", T1.MAILCONTENTS AS "MailContents", T1.REPLYCONTENT AS "ReplyContent", T1.ENCEMAIL AS "EncEmail" From mbs7_crm.KH_Consulting T1 left Join mbs7_crm.KH_Customer T2 on T1.CUSCODE = T2.CUSCODE ORDER BY T1.STATUS ASC, T1.CREATETIME ASC) T WHERE "CreateTime" >= date '2013-9-1' AND "ReplyCode" IN ('128') AND "CreateTime" <= timestamp '2013-9-30 23:59:59' AND ROWNUM <= 10000) TEMP WHERE ROWNUMBER__ > 0
分析:
該語句從執行計劃來看,走了時間索引,返回記錄是1千多,如果全部查詢出來進度很慢(分頁的翻頁操作很慢),后來發現該語句的性能主要是消耗在:字段"Question",“MailContents”,"Category"和"ReplyContent"上,把這4個字段注釋小,查詢時間在5s內,后來發現這4個字段為CLOB字段類型,因為CLOB字段這種字段類型的存儲方式是比較復雜的,如果該CLOB字段內容超出一定值,會用指針指向另一個SEGMENT,把內容存放在新的SEGMENT; 這樣當訪問的時候,會出現IO次數增加,從而影響性能,并且CLOB類型有獨立的回滾機制,當一致性讀的行數較多時,響應時間很慢,而就算存儲的內容較小,CLOB本身也會調用系統內部的函數進行匹配和尋址,也是很消耗CPU時間的.
解決方案:
經與開發人員溝通,該表的此四個字段其實實際存儲內容遠沒有超出4000個字節(varchar2的最大長度),當初設計的時候沒有考慮精準,于是計劃把這些字段類型按照下列方法重新調整:
alter table mbs7_crm.KH_Consulting add (QUESTION2 varchar2(2000)); update mbs7_crm.KH_Consulting set QUESTION2=dbms_lob.substr(QUESTION,4000); alter table mbs7_crm.KH_Consulting drop column QUESTION; alter table mbs7_crm.KH_Consulting rename column QUESTION2 to QUESTION;
修改后,重新查詢,在5S內。
感謝各位的閱讀,以上就是“怎么解決數據庫LOB字段帶來的性能影響”的內容了,經過本文的學習后,相信大家對怎么解決數據庫LOB字段帶來的性能影響這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。