Tuesday, January 27, 2009

Starting place for debugging Mysql

This post gives some brief tips for debugging Mysql.

First of all you can run Mysql on many different platforms. So start by choosing the platform that will make your particular debugging task easier. For memory leaks I would run the server on linux so that I can take advantage of the Valgrind tool, for memory leak checking, which is only available on linux. For bugs where you want to use a debugger to step into the code, Windows is a surprisingly great option due the ease of use of the debugger that comes with Visual C++.

Now that you have your debugger of choice up and running, you want to see what is Mysql doing in some scenario. Mysql code is quite complex so finding the right place to put the breakpoint can be a challenge. If I don't know what function calls mysql is making, normally I would start with a breakpoint in sql_parse.cc in the mysql_execute_command function at the point where the code says:

switch (lex->sql_command) {

which in my install is on sql_parse.cc line 2125

Once the code reaches this breakpoint then I usually add watches for the variables thd->query which gives the full text of the query currently being handled and also lex->sql_command which gives the enum of the command type that is being executed. From this point you can step through the code and see what Mysql is doing for each command.

This is just the very beginning, I hope to add more posts in the future with additional details.


1 comment:

  1. Buying a piece of jewelry for him is thpmas sabo not as tricky as it might seem.thoughtfully-picked piece of jewelry. thomas sabo charms Here are five suggestions for when you are considering buying thomas sabo bracelets jewelry for him:A timepiece: Every man needs a reliable timepiece. thomas sabo charm carriers You have three different options to work with: thomas sabo watches A dress watch: Men with office thomas sabo charm pearl jobs need a watch that complements their suits.