Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Simple example:

You're using an ORM to query a record and as you're looping through the results you need to reference something in an association.

You get one query that returns 50 results, then loop through those 50 results and trigger a one off query for every result in the loop. Now you're executing 51 queries instead of the original one.

Now imagine you go another level deep or have multiple results from each of those sub queries to loop through. It can get out of control. In Rails and a lot of ORM's you can typically solve these by eager loading the nested associations with very little effort. The rest of the code will work the same but behind the scenes only 1 additional query will be triggered to fetch the records from the association.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: