r/mysql • u/Stock-Dark-1663 • Oct 15 '26
question Question on Memory parameters
Hi,
Its aurora mysql serverless version 8.0, with Min ~8ACU and MAX ~80ACU.
We have a complex UI query with "union all" and other criterias and its avg response time is <1 sec. But we see many times the query runs for 15minutes+ causing the errors in app side. This query executed ~5k times per hour on an avg and most executions finishin <1sec.
We see this query creates on an avg ~5 temp tables internally because of its internal "union" operator etc.., thus suspects if the below two parameters are actually playing a role in making this query crawl intermittently from ~1sec till ~15minutes. i.e. "temptable_max_ram" and "temptable_max_mmap". As because we run the same query manually and it does finish in 1sec. So suspect if during peak its causing the issue for some high volume customers even the same runs fine manually when we runs in the database.
We see the swap usage is staying ~1-2GB (sometime spikes to 3GB). Free memory trend showing spiky , but at worst scenarios it shows ~40GB(not below that). So want to understand, if in this situation, its fine to bump up the above parameters to 2GB each from curent 1GB (which is default value)?
1
u/AnnaLeeCoop Oct 16 '26
Yes, bumping both
temptable_max_ramandtemptable_max_mmapto 2GB is completely safe if you consistently have 40GB of free memory sitting there. We run into this on our own production setups too. That massive 15-minute spike happens because once the result set exceeds the RAM limit, the engine spills those temp tables to disk, and the resulting I/O latency crushes the query.I'd also recommend double-checking the
EXPLAINplan during peak load, since sometimes aUNION ALLgets forced into a disk-based temp table anyway if an outer sort or grouping shifts unexpectedly.1
u/Significant_Tune9219 Oct 16 '26
I would not bump those two to 2GB hoping the 15 minute runs go away. Free memory that never drops under about 40GB, with swap sitting around 1-2GB, means the instance is not out of RAM when you look at it, so a cap of 1GB is probably not the cliff. Five internal temp tables on a query that runs thousands of times an hour can still spill, but a spill turns one second into a few, not fifteen, unless the plan itself changed. Compare a slow execution to a fast one before you touch the defaults: same plan, and the slow one converting the temptable to disk, then the cap matters. Different plan, or the slow ones lined up with the instance sitting at the 8 ACU floor, and raising temptable_max_ram just spends memory you didn't need.
1
u/Aggressive_Ad_5454 Oct 15 '26
What varies between these short and long query runs? Can you identify anything, maybe a difference in a WHERE, ON, or ORDER BY clause?
The parameters you mention will make a difference if you have a vast filesort step in your execution plan.
At any rate it will help us help you if you read this and then edit your post to tell us more.
1
u/razin_the_furious Oct 15 '26
Is optimization of the query out of the question? Or is it as optimized as it can be, and more memory is the next step?