Skip to main content

Posts

Showing posts from February, 2012

Controlling the Query Optimizer

The task of the query optimizer is to find an optimal plan for executing an SQL query. Because the difference in performance between “ good ” and “ bad ” plans can be orders of magnitude (that is, seconds versus hours or even days), most query optimizers, including that of MySQL, perform a more or less exhaustive search for an optimal plan among all possible query evaluation plans. For join queries, the number of possible plans investigated by the MySQL optimizer grows exponentially with the number of tables referenced in a query. For small numbers of tables (typically less than 7 to 10) this is not a problem. However, when larger queries are submitted, the time spent in query optimization may easily become the major bottleneck in the server's performance. The behavior of the optimizer with respect to the number of plans it evaluates can be controlled using two system variables: The  optimizer_prune_level  variable tells the optimizer to skip certain plans based on es...

MySQL Backup and Recovery

MySQL backup There are many paths you can take to create a MySQL backup. However, no matter which application, control panel tool, or SSH script you use, all of the backups will fit into two types of backups: a dump or raw backup. MySQL Dump A MySQL dump is a bit slower than a raw backup because it creates all the SQL queries required to create the tables of that database, as well as all the insert queries required to place the information back into the database's tables. If you want to perform the mysql dump manually, without the assistance of your hosts control panel, then run SSH to your web server and do the following  mysqldump --tab=/path/to/some/dir --opt db_name If you were to open up a MySQL dump file you would see a slew of SQL queries that you would probably be able to understand (if you've already read through this whole tutorial!). MySQL Raw Backup A MySQL Raw Backup is quicker because it does not translate the contents of the database into human rea...