All we need is an easy explanation of the problem, so here it is.
Earlier today I upgraded a
db.t3.large MySQL instance on AWS from
8.0.20. I’ve seen a handful of cases where I’m seeing the error
SQLSTATE[HY001]: Memory allocation error: 1038 Out of sort memory, consider increasing server sort buffer size. I don’t expect such an error because the config or instance type didn’t change. An example of where I’m seeing this is on the following query:
SELECT * FROM `messages` WHERE EXISTS ( SELECT * FROM `updates` WHERE `messages`.`update_id` = `updates`.`id` AND `game_id` = 18 ) AND `messages`.`deleted_at` IS NULL ORDER BY `id` DESC LIMIT 6
In this query, all columns used in the
where clauses are either foreign or primary keys with
messages.deleted_at being the only exception.
In the meantime I’m going to adjust this setting in my prod environment to increase the size of the
sort_buffer_size, but this change is not recommend according to a lot of stuff I’m reading so I hope it’ll temporarily resolve the issue.
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
And you have large JSON or Geometry columns? (Always provide
SHOW CREATE TABLE when asking a question.)
Either increase or decrease
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂