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

iftekhs's avatar
Level 13

Memory allocation error: 1038 Out of sort memory

Hi, I get this error

Memory allocation error: 1038 Out of sort memory, consider increasing server sort buffer size

So I think I have to increase the size of my mysql "sort buffer size" I'm using AWS RDS where can I do that from ?

0 likes
2 replies
Tray2's avatar

My guess here is that you have json fields in your table, and you are sorting on a none json column. I really suggest the you don't use json at all in the database, it is bad practice.

https://tray2.se/posts/database-design

Changing the sorting buffer size can cause other performance issues, so it's not recommended.

marsworks's avatar

I do agree with @tray2 about avoiding JSON columns...they seem like a great tool, and are in many ways, in our company we've used them a fair bit...but generally try to avoid them if possible.

The solution for us getting around this issue is to ->select() only the columns you need for the query and NOT the JSON columns. If you add that to your Eloquent query, we've found that error is resolve I believe in all cases.

Please or to participate in this conversation.