0

If you are trying to diagnose slow queries in your mysql backend and are using a Django frontend, how do you tie together the slow queries reported by the backend with specific querysets in the Django frontend code?

MikeN
  • 45,039
  • 49
  • 151
  • 227

2 Answers2

1

I think you has no alternative besides logging every django query for the suspicious querysets.

See this answer on how to access the actual query for a given queryset.

Community
  • 1
  • 1
Paulo Scardine
  • 73,447
  • 11
  • 124
  • 153
1

If you install django-devserver, it will show you the queries that are being run and the time they take in your shell when using runserver.

Another alternative is django-debug-toolbar, which will do the same in a side panel-overlay on your site.

Either way, you'll need to test it out in your development environment. However, neither really solves the issue of pinpointing you directly to the offending queries; they work on a per-request basis. As a result, you'll have to do a little thinking about which of your views are using the database most heavily and/or deal with exceptionally large amounts of data, but by cherry-picking likely-candidate views and inspecting the times for the queries to run on those pages, you should be able to get a handle on which particular queries are the worst.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444