3 ms·
In this case you're generally better off querying once to get the parent data, collecting all the child keys from it and queuing a second time to collect ALL th
by aidos 15y ago
In this case you're generally better off querying once to get the parent data, collecting all the child keys from it and queuing a second time to collect ALL the children.
The technique you've described is the reason early ORMs had a bad reputation wrt performance. I'd have seriously strong words with any of my developers I found querying inside a loop. Checkout the N+1 problem.
- ars 15y agoUnless you have 3 levels of tables to work through. Yes, you can get all the data from the third level in one query - but then you have to find the keys you want from it in your client, and without an index. (Alternately you may be building a hash-index on the fly each time you retrieve the data, which isn't optimal either. For example if you store the key in a PHP array.) Obviously you need to be smart about what you are doing. But simply always getting the data in bulk is not automatically correct.