That's exactly what is happening now. Lemmy is a very young codebase and up until very recently only had a tiny user base, so optimisation wasn't that important.
Over the last few months the Devs have been working hard to improve things, but there is a lot of ground to cover
Possibly not ideal for you as a data engineer, but you could try skimming down the GitHub database issues?