MySQL排序缓冲区溢出([HY001]; error code [1038],Out of sort memory, consider increasing server sort buffer )
背景
線上服務某些條件下的列表查詢失敗,報系統異常,查詢線上日志發現報了排序緩沖區溢出
### Cause: java.sql.SQLException: Out of sort memory, consider increasing server sort buffer size
; uncategorized SQLException; SQL state [HY001]; error code [1038]; Out of sort memory, consider increasing server sort buffer size; nested exception is java.sql.SQLException: Out of sort memory, consider increasing server sort buffer size
資料查找
mysql - Error "1038 Out of sort memory, consider increasing sort buffer size - Stack Overflowhttps://stackoverflow.com/questions/29575835/error-1038-out-of-sort-memory-consider-increasing-sort-buffer-size根據2021-04-26 12點19分Webnet的回答,即使只使用主鍵排序,但是select字段中含有超長字段就可能會觸發這個問題,我們線上的SQL就是只使用了主鍵排序,但是select字段中有個超長的text字段
根據該回答提及的MySQL問題鏈接,查看bug記錄
MySQL Bugs: #103225: "Out of sort memory error" has an inconsistent relationship with the buffer sizehttps://bugs.mysql.com/bug.php?id=103225可知道MySQL版本大于8.0.17且小于8.0.28的會存在此問題,此問題在8.0.28版本已修復,而我服務器MySQL的版本為8.0.25,根據bug評論,在問題版本區間內有兩種解決方案
1.在配置文件中配置sort_buffer_size,但是都不建議,因為這治標不治本,而且也不好估計設置多少合適
2.將大字段類型改為longtext,這樣可以走8.0.17版本的處理邏輯,就不會觸發這個bug
總結
以上是生活随笔為你收集整理的MySQL排序缓冲区溢出([HY001]; error code [1038],Out of sort memory, consider increasing server sort buffer )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 20几岁要懂点经济学【笔记】
- 下一篇: 有奖:说出你的网络安全故事