As a MySQL DBA I already know the data changes that happen on my system. I have logs for that.
However, it’s a common problem that several years into the life of an application, the current developers won’t know where in the codebase queries come from. It’s often hard for them to find the location in the code if queries are formed dynamically; the pattern I show them to optimize doesn’t match anything in the code.
I stumbled on a trick a couple years ago that has been invaluable in tracking down these problematic queries: query comments.
Here’s an example:
When a query generally shows up in a slow query log, it might look something like this:
# Time: 150217 10:26:01 # User@Host: comments[comments] @ localhost [] Id: 13 # Query_time: 0.000231 Lock_time: 0.000108 Rows_sent: 3 Rows_examined: 3 SET timestamp=1424186761; select * from cars;
That logging shows me who executed the query …
[Read more]