Okay, now that I’ve griped at MySQL a bit, I need to say something nice about it: the toolset support (at least on RoR) is second-to-none. As a great example, check out assert_efficient_sql, a plug-in which allows you to write unit tests and check for inefficient SQL queries. At this point, it mainly looks for things like returning too many rows and writing to the file system to do a sort, but the idea is cool.
One catch that jumps out right away is that you’re going to have to run this against a DB that looks a lot like production, since MySQL will punt to full table scans on smaller tables, and your unit test data probably qualifies as “smaller tables”.
The other catch is that it doesn’t detect an excessive amount of queries in order to implement a piece of functionality. The fact that you could merge three or four queries into one or two, or move queries around to minimize trips to the database — those are developer-level decisions that (I think) it would be hard to programaticaly detect. I dare you to prove me wrong: just be sure to open source the plugin proving it. :-D
Related posts: