MySQL Optimization

  • use ENUM whenever possible
  • do not be too generous with the varchar length
  • NULL columns take more space and make computation harder – avoid using them, use empty strings or zeros.
  • InnoDB-specific. Use a surrogate key which is a primary key whose value is not derived from application data; it is simply an AUTO-INCREMENT integer
  • use indexes wisely (accordingly to the queries you are going to use). Benchmark your choice.
  • chopping up query – if a query takes too long to execute (for example a query for purging) you should do it bit by bit in a loop. In this way you will avoid to lock tables for long time
  • sometimes 3 one-table queries performs better that a query with 3 joins. This is called in-application join. In this way you have more change to use cache, locks will be shorter, you can store the tables on different servers (scalability) and you can reduce row access (it is not always easy for MySQL to optimize complex queries)
This entry was posted in MySQL. Bookmark the permalink.

Leave a Reply