SQL: Show duplicate queries as in SQL Log Middleware #27

Closed
nleush opened this Issue Sep 21, 2009 · 4 comments

Projects

None yet

5 participants

@nleush
nleush commented Sep 21, 2009

SQL Log Middleware is here: http://www.djangosnippets.org/snippets/344/

Working solution proposition:

http://dumpz.org/12573/
http://dumpz.org/12575/

@twig
twig commented May 31, 2011

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!

@mikery
mikery commented Dec 13, 2011

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.

@aaugustin
Contributor

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.

@robhudson
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment