Adding query analysis to CF’s built-in debug output (for MySQL)
I came across a cool plugin for Rails that allows you to analyze your queries in MySQL. It takes advantage of the EXPLAIN statement, which you can read about here if you aren’t already familiar with it. And if you aren’t familiar with it, you should get familiar with it :) It’s a really easy way to determine if you’re missing indexes, which, once added can improve performance ten fold. I thought it would be nice to have for CF, so I added it in.
ColdFusion’s debug output uses templates stored here:
C:\CFusionMX7\wwwroot\WEB-INF\debug
They aren’t encrypted so you can do whatever you like with them. I modified the ‘classic.cfm’ template but you could add it to the others as well.
This code is quick and dirty, but you’ll get the idea. It starts with the comment ‘mysql query analyzer.’ You’ll probably want to add in the ability to turn it on or off, maybe via a certain URL param, because it will slow down things a bit if you have a lot of queries being called. ‘Turning it on’ via an URL param would allow you to re-request a page when the regular debug output indicates a slow query and not use it all the time when your debug output is on.
Download it here. This file will replace your existing classic.cfm template. Be sure to back up your current file, of course. Please let me know if you take it and improve upon it
Post a Comment