Home > Support > WebMail Support Home > Optimize mySQL with WebMail

How to Optimize mySQL with WebMail

We recommend the use of mySQL for the database backend of WebMail. Our tests show it is faster and easier to setup then any other SQL database backend for WebMail. The WebMail software was designed with mySQL in mind, although since WebMail uses the standard Perl DBI library the software is compatible with any other SQL server.

The most common question regarding WebMail and mySQL is how to I optimize the software to perform at it's best? Learn more by reading the following FAQ!

What one can and should optimize
Optimizing hardware for MySQL
Optimizing disks
Optimizing OS
If you need more speed, you should: Don't be afraid to make the first version of your application not perfectly portable; when you have solved your problem, you can always optimize it later.
Compiling and installing MySQL
Maintenance
Speed difference between different SQL servers (times in seconds)

Reading 2000000 rows by key: NT Linux
mysql 367 249
mysql_odbc 464  
db2_odbc 1206  
informix_odbc 121126  
ms-sql_odbc 1634  
oracle_odbc 20800  
solid_odbc 877  
sybase_odbc 17614  
 
Inserting (350768) rows: NT Linux
mysql 381 206
mysql_odbc 619  
db2_odbc 3460  
informix_odbc 2692  
ms-sql_odbc 4012  
oracle_odbc 11291  
solid_odbc 1801  
sybase_odbc 4802

In the above test, MySQL was run with a 8M cache; the other databases were run with installations defaults.


Important MySQL startup options

back_log Change if you do a lot of new connections.
thread_cache_size Change if you do a lot of new connections.
key_buffer_size Pool for index pages; Can be made very big
bdb_cache_size Record and key cache used by BDB tables.
table_cache Change if you have many tables or simultaneous connections
delay_key_write Set if you need to buffer all key writes
log_slow_queries Find queries that takes a lot of time
max_heap_table_size Used with GROUP BY
sort_buffer Used with ORDER BY and GROUP BY
myisam_sort_buffer_size Used with REPAIR TABLE
join_buffer_size When doing a join without keys

Optimizing tables
How MySQL stores data
MySQL table types

MySQL row types (only relevant for ISAM/MyISAM tables)
MySQL caches (shared between all threads, allocated once) Note that MySQL doesn't have a row cache, but lets the OS handle this!
MySQL buffer variables (not shared, allocated on demand)
How the MySQL table cache works
Learn to use EXPLAIN - Use EXPLAIN on every query that you think is too slow!
mysql> explain select t3.DateOfAction, t1.TransactionID
    -> from t1 join t2 join t3
    -> where t2.ID = t1.TransactionID and t3.ID = t2.GroupID
    -> order by t3.DateOfAction, t1.TransactionID;
+-------+--------+---------------+---------+---------+------------------+------+---------------------------------+
| table | type   | possible_keys | key     | key_len | ref              | rows | Extra                           |
+-------+--------+---------------+---------+---------+------------------+------+---------------------------------+
| t1    | ALL    | NULL          | NULL    |    NULL | NULL             |   11 | Using temporary; Using filesort |
| t2    | ref    | ID            | ID      |       4 | t1.TransactionID |   13 |                                 |
| t3    | eq_ref | PRIMARY       | PRIMARY |       4 | t2.GroupID       |    1 |                                 |
+-------+--------+---------------+---------+---------+------------------+------+---------------------------------+
  
Types ALL and range signal a potential problem.
Learn to use SHOW PROCESSLIST - Use SHOW processlist to find out what is going on:
+----+-------+-----------+----+---------+------+--------------+-------------------------------------+
| Id | User  | Host      | db | Command | Time | State        | Info                                |
+----+-------+-----------+----+---------+------+--------------+-------------------------------------+
| 6  | monty | localhost | bp | Query   | 15   | Sending data | select * from station,station as s1 |
| 8  | monty | localhost |    | Query   | 0    |              | show processlist                    |
+----+-------+-----------+----+---------+------+--------------+-------------------------------------+
  
Use KILL in mysql or mysqladmin to kill off runaway threads.
How to find out how MySQL solves a query - Run the following commands and try to understand the output:
MySQL is extremely good
Things to avoid with MySQL
Tricks to give MySQL more information to solve things better - Note that you can always comment out a MySQL feature to make the query portable:
SELECT /*! SQL_BUFFER_RESULTS */ ...
  

General tips
  SELECT * FROM table_name WHERE hash=MD5(concat(col1,col2)) AND
  col_1='constant' AND col_2='constant'
  

 

Search: