Get the latest tech news
SQL performance improvements: finding the right queries to fix
This post covers tips and tricks for performance tweaking your SQL queries by first identifying which queries need work.
Most frameworks have the concept of a "debug bar" - in the case of Laravel applications, the most widely used is the barryvdh/laravel-debugbar package that offers excellent insights. The Laravel framework can warn you when you're (potentially) causing excessive queries by throwing an exception when you're lazy loading relationships. It'll throw an exception, because for every iteration through the loop, Laravel would perform an extra query to count the comments of that specific $post instead of loading them at once.
Or read this on Hacker News