Unexpected HY001: Memory allocation error after MySQL upgrade

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 v8.0.17 to 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`
    EXISTS (
        SELECT * FROM `updates`
            `messages`.`update_id` = `updates`.`id`
            AND `game_id` = 18
    AND `messages`.`deleted_at` IS NULL

In this query, all columns used in the order and 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.

Method 1

And you have large JSON or Geometry columns? (Always provide SHOW CREATE TABLE when asking a question.)

Either increase or decrease sort_buffer_size and innodb_sort_buffer_size.


Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply