MySQL 5.0 – Source Documentation

Wow what a hectic month – just logged on and noticed I haven’t updated the site in a month! I have a part done entry on triggers that I haven’t had time to finish yet, look out for that in a couple of days. Work has been hectic, a lot of work going in to the MySQL Module of NORAD (a system/database monitoring tool that we distribute.. But that’s a story for another day), which I’m responsible for building the collections / window definitions for at the moment.

One of the windows I was building today was for “Open Tables” – sourced from SHOW OPEN TABLES; – yet I wasn’t entirely sure on what all of the output meant. Specifically “Name_locked”. The documentation doesn’t comment on this at all (the documentation for SHOW OPEN TABLES is particularly poor, even noting a “Comment” field that simply doesn’t exist (on 4.1 at least). “In_use” was not entirely clear either at first glance, “Does it mean being selected/inserted etc. from, waiting for a lock..?“.

After a little testing it’s easy to see that “In_use” is incremented for each current table lock, or lock request against each table. For instance, if you “LOCK TABLE t1 WRITE;” in session 1, and then “LOCK TABLE t1 READ;” in session 2, “In_use” will show a value of 2 for t1, even though session 2 is still hanging waiting to actually use the table. Fair enough..

However, through all of the playing around I did, I couldn’t get “Name_locked” to deviate from 0. So I had a chat with Dean (Therion) Ellis to see if he might know, who messed around in the source, and had a chat with some of the other MySQL AB guys, and eventually came to the conclusion all round that Name_locked is used for specific operations such as RENAME TABLE – when they need a totally exclusive lock against the table to perform the administrative function.

This peeked my interest, and to get back to the title of this entry, tired of poking around “blindly” in the source I decided to load up Doxygen, a GPL documentation system for C, C++ etc. projects, and run the MySQL source through it for a better look around. Rather than having copies of this at work and home, I’ve decided to upload it here, and provide a link so that the community can use it as well. You can browse it here.

I’ll try to keep this as up to date as possible, following fully released beta versions. If I don’t have the latest version feel free to send me an email (leithal at cool-tools.co.uk), and I’ll fire an update up. It’s currently about 450mb, with ~9500 files, so we’ll see what bandwidth usage is like as well πŸ˜‰

So did it help?” – “Yup!

Here’s where the open table list is generated. I’ll let you poke around to see if you can figure out how locked_by_name is set. Some interesting files to look at, to start with, are /sql/lock.cc, and going back to RENAME TABLE /sql/sql_rename.cc

Hopefully it helps all of you other curious people out there!