Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

swapnilnandgave's avatar

Memory allocation error: 1038

I am getting below error.

SQLSTATE[HY001]: Memory allocation error: 1038 Out of sort memory, consider increasing server sort buffer size

SQL: select * from program_versions where program_versions.program_id = 93 and program_versions.program_id is not null and program_versions.deleted_at is null order by created_at desc limit 1

How would we solve this issue?

0 likes
9 replies
StephanieSy's avatar

Please provide enough code so others can better understand or reproduce the problem

rodrigo.pedra's avatar

consider increasing server sort buffer size

First three results in DuckDuckGo for search string: SQLSTATE[HY001]: Memory allocation error: 1038 Out of sort memory, consider increasing server sort buffer size

Next time inform which database server and version you are using

rodrigo.pedra's avatar
Level 56

@swapnilnandgave By code level you mean from PHP?

Because changing config to a program is kind of code level, isn't it?

From PHP I don't think so, this is a config needed to be changed in MySQL and MySQL needs to be restarted to make it work.

I see you run it on Digital Ocean droplet, it should be possible to have ssh shell and change this.

swapnilnandgave's avatar

I am using mysql 8.0 version and it is digital ocean deployment.

Sinnbeck's avatar

@swapnilnandgave Ok a few questions that might give us some insights.

  1. Why do you need to check if the program_id is not null? You are already checking if its a specific ID.
  2. Are there multiple items with there same program_id? You are sorting but only getting 1 record?
  3. How many records are in that table? Based on the error, I would assume you have many millions
swapnilnandgave's avatar

@Sinnbeck

  1. It is important for starting point. It is like parent and child relation
  2. Yes. One program has multiple program versions
  3. Program Table has only 99 Records and 287 in program versions.

Program version has one json column

hivokas's avatar

I had the same issue with MySQL 8.0.27. Upgrading to newer version fixed the issue for me.

Please or to participate in this conversation.