[MDEV-24015] SQL Error (1038): Out of sort memory when enough memory for the sort buffer is provided Created: 2020-10-23 Updated: 2021-04-26 Resolved: 2020-10-28 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Configuration, Optimizer, Storage Engine - InnoDB |
| Affects Version/s: | 10.5.6 |
| Fix Version/s: | 10.5.7 |
| Type: | Bug | Priority: | Blocker |
| Reporter: | Andrej Piatnica | Assignee: | Varun Gupta (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | innodb, optimizer | ||
| Environment: |
Windows Server 2012R2 verson 6.3; Xeon E3-1225@3.2Ghz; 16GB ram |
||
| Attachments: |
|
| Description |
|
Decided to upgrade older 10.3.13 with the currently latest version 10.5.6. One of my sql selects started throwing SQL Error (1038): Out of sort memory. Versions are running on the same machine (sharing the same port, so just one instance is running at a time). Did mysqldump to have identical conditions. Using default settings (attached system variables for both versions). Need to set sort_buffer_size to ~120MB to make script working again while older one works well with default 2MB. I managed to simlify the script while still keeping an error (I understand it does not makes sense now, its really a shortened version so I could share something with you):
Is this behaviour correct? |
| Comments |
| Comment by Varun Gupta (Inactive) [ 2020-10-26 ] |
|
The patch is present in the branch 10.5-varun |
| Comment by Sergei Petrunia [ 2020-10-27 ] |
|
Review https://lists.launchpad.net/maria-developers/msg12451.html |
| Comment by Rick James [ 2021-04-24 ] |
|
I do not accept the answer of "change a setting because of an optimizer improvement". https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-20.html – "One effect of this enhancement is that it is now possible for Out of memory errors to occur when trying to sort rows containing very large (multi-megabtye) JSON or GEOMETRY column values if the sort buffers are of insufficient size; this can be compensated for in the usual fashion by increasing the value of the sort_buffer_size system variable. (Bug #30400985, Bug #30804356)" This error seems to be caused by an "improvement" in the Optimizer. The "right" way to deal with the error is to do one of these:
One reverts unnecessarily in some cases (where the stats are not precise enough); the other has to undo some work (making it slower). Here is another test case: https://stackoverflow.com/questions/67242726/mysql-8-order-by-created-at-out-of-sort-memory-error-1038 |
| Comment by Sergei Golubchik [ 2021-04-26 ] |
|
rjasdfiii, I don't understand. Are you complaining about what MySQL developers did? Then it seems to be a wrong bug tracker for that. Or are you saying that we should not do the same? We don't, didn't — this bug was fixed in 10.5.7 with the commit db56f9b852, at no point in time the message was "change a setting because of an optimizer improvement" (and it wouldn't have helped anyway). |
| Comment by Rick James [ 2021-04-26 ] |
|
Sergei - My apologies if I misspoke. I understood that Oracle and MariaDB sometimes "share" code or fixes. When I saw the MySQL regression, I went to MariaDB to see if the "improvement" had been also revise the optimizer), I wanted you to do a better job than that. I can't tell from this workflow whether the problem was really introduced, nor whether it was "fixed". |
| Comment by Sergei Golubchik [ 2021-04-26 ] |
|
No problem. Don't worry, this time it was our fix. The problem was really fixed and a new test will ensure it won't happen again. |