SQL Log Middleware is here: http://www.djangosnippets.org/snippets/344/
Working solution proposition:
The main reason why I'm using the debug toolbar is to reduce the number of DB queries and increase the site performance.
This feature would be very handy!
I have implemented this feature in my fork (mikery@27cfc7b). Once I have made it a bit more flexible I will try making a pull request to see if we can get this feature in the official master branch. If you try it out, please let me know if you have any comments or suggestions.
I've closed a stale pull request. This issue doesn't look entirely straightforward to me. For instance, how do we collapse queries that only differ by the value of some parameter? How do we handle repeated series of queries: A, B, C, A, B, C, A, etc.?
If you want to tackle this ticket, I suggest discussing a design with a maintainer before developing a solution.
The idea I had many years ago was that in the debug cursor the sql and params arguments are separate. So anywhere where the sql was the same increment a counter on that sql. The SQL parameters could be different, no problem. This might help to see that you're doing hundreds of SQL queries for the same table and that SQL is querying by ID -- which could give you a clue that you might need a select_related to avoid all those single pk lookups, e.g.