When it comes to write code you don't need to learn magic spells.
All you need is to take a look outside the window and solve your problem with patterns from the real world.
How to squeeze Wordpress/MySql to the bare minimum memory consumption - and survive.
Have you ever experienced a dockerized MySQL to stuck in low memory VPS? I did and luckily I found a solution! (yes, I googled it)"