MySQL Query Performance Tips

Richard Wong 14 October, 2008

Almost all of the modern web applications involve the use of relational database. So the performance of your applications are very much affected by the quality of the SQL queries you run. Here are some simple performance tips from MYSQL forge that you should consider when writing queries.

  1. Use EXPLAIN to profile the query execution plan
  2. Use Slow Query Log (always have it on!)
  3. Don’t use DISTINCT when you have or could use GROUP BY
  4. Insert performance
    1. Batch INSERT and REPLACE
    2. Use LOAD DATA instead of INSERT
  5. LIMIT m,n may not be as fast as it sounds
  6. Don’t use ORDER BY RAND() if you have > ~2K records
  7. Use SQL_NO_CACHE when you are SELECTing frequently updated data or large sets of data
  8. Avoid wildcards at the start of LIKE queries
  9. Avoid correlated subqueries and in select and where clause (try to avoid in)
  10. ORDER BY and LIMIT work best with equalities and covered indexes
  11. Separate text/blobs from metadata, don’t put text/blobs in results if you don’t need them
  12. Delete small amounts at a time if you can
  13. Make similar queries consistent so cache is used
  14. Don’t use deprecated features
  15. Turning OR on multiple index fields (<5.0) into UNION may speed things up (with LIMIT), after 5.0 the index_merge should pick stuff up.
  16. Use INSERT … ON DUPLICATE KEY update (INSERT IGNORE) to avoid having to SELECT

Now if you know all the above tips, then may be you want to start looking at database scaling, design and more from MYSQL forge.

Here are some more detailed articles about optimizing MySQL for those of you want to get your hands dirty:

New Look for 84 Bytes

Richard Wong 25 August, 2008

I have finally created my own theme for this blog. This is still a very early version which I will be busy updating for the coming weeks. The plan is to release often, release small :p

This is what the old design looks like

Old 84 Bytes Design Screenshot

And it was based on .

I hope everyone will like this new design. Feel free to leave some feedback.

Salary and Demand Trend for Javascript Developer in UK

Richard Wong 1 June, 2008

Interesting finding from ITJobsWatch. Although, the demand is rapidly increasing, the average salary is pretty stable. Is this because there are more Javascript developer out there?

The chart provides the 3-month moving total beginning in 2004 of permanent IT jobs citing JavaScript Developer within the UK as a proportion of the total demand within the Job Titles category.

The chart provides the 3-month moving average for salaries quoted in permanent IT jobs citing JavaScript Developer within the UK.

If you are a IT worker in the UK, go and find out whether you are above or below the curve now!