I set off down this path of enlightenment as I investigated a customer issue that “could never happen”.
If you are using an ORM in your projects, The N+1 query problem is definitely one of your issues. If you don't know that yet - well, may the Lord have mercy on your soul.
Database indexing is a development task. The most important information for indexing is not the storage system, or the configuration of the server - but instead how the application queries the data. This knowledge is not easily obtained from DBAs or external consultants - so it's on us, the developers.
In an earlier blog post, I touched upon the cardinal sin of performance issues - N+1 queries. In this blog post I am going to explain through a few examples what the N+1 query problem is, and also suggest how to fix each in your application code.
Honestly - the main reason I chose to move away from Wordpress and to GatsbyJS wasn't to upskill in the No. 2 Web Framework from 2020 (according to stackoverflow - but just because.. I liked it better.
When working with an ORM, it is essential that you inspect your generated queries. Often when doing so you will find they are not entirely what you expected. The CriteriaBuilder API can be very useful for building dynamic queries, but you must take great care – especially if you let your UI generate many _wonderful_ queries to fulfil all of its filtering/sorting/etc.