0

I'm testing a method with quite huge sql query. I has about 15 joins, one subquery with 2 joins, so it is complex. But each running takes different time. Once it is 4 second, sometimes 80, or even 200 seconds. It is standard unit test, with preparing data with FactoryGirl, and data is always the same.

Is there any mysql profilers, mysql options or other tools, that can figure for me why there are so big running time differences? How to figure it out?

shingara
  • 46,608
  • 11
  • 99
  • 105
Sławosz
  • 11,187
  • 15
  • 73
  • 106

1 Answers1

1

There's a good chance that MySQL is caching the results of some of the subqueries and/or joins, which would easily account for the variations you're seeing in your response times.

As for a profiler, doing a quick google for "mysql profiler" came up with this link, as well as a previous question here on SO asking much the same question.

Community
  • 1
  • 1
Spudley
  • 166,037
  • 39
  • 233
  • 307
  • there is SQL_NO_CACHE in SELECT and first run can take 2 sec and second 150 sec.... – Sławosz Sep 29 '10 at 13:57
  • 1
    Also try built-in `EXPLAIN`. Just put `EXPLAIN` in front of your query and it will give you some idea how mysql intends to go about fetching your data. – Carl Manaster Sep 29 '10 at 14:15