Interesting findings about one of the Go database drivers for MySQLFri, Dec 28, 2012 in Databases
Moral of the upcoming story: when your systems rely on someone else’s software, make sure you test it thoroughly to understand how it works.
I found a couple of interesting things about the go-mysql-driver driver for Go. One is that it prepares every query before executing it, and then closes it afterwards, if you’re just using the db.Query() or db.QueryRow() functionality. There is zero benefit to this; Bill Karwin has probably listed it as an antipattern somewhere. I asked for one query, but I got three.
The other is that it doesn’t open the database connection when you call db.Open(). You can call that function and get no error. The first query on the resulting “db” object will actually connect to MySQL. Thus it’s actually kind of like the other major opensource Go/MySQL driver (mymysql), which has an “autorc” interface that will automatically reconnect to the server. In normal usage, go-mysql-driver will reconnect more or less silently if you kill its connection to the server.
How did I discover these things? By tailing the general log, of course – and by running KILL on some connections. Good old-fashioned stuff. My manual version of Chaos Monkey :-)
I try to follow the principle of least surprise with my own software, but it’s good never to assume anything about anyone else’s.
I'm Baron Schwartz, the founder and CEO of VividCortex. I am the author of High Performance MySQL and lots of open-source software for performance analysis, monitoring, and system administration. I contribute to various database communities such as Oracle, PostgreSQL, Redis and MongoDB. More about me.