Top 10 SQL Performance Tips

Voici un article très intéressant de la part de MySQL faisant référence à quelques astuces pour rendre ces requêtes plus performantes.

Voici un petit aperçu :

  • Use EXPLAIN to profile the query execution plan
  • Use Slow Query Log (always have it on!)
  • Don't use DISTINCT when you have or could use GROUP BY
  • Insert performance
    1. Batch INSERT and REPLACE
    2. Use LOAD DATA instead of INSERT
  • LIMIT m,n may not be as fast as it sounds
  • Don't use ORDER BY RAND() if you have > ~2K records
  • Use SQL_NO_CACHE when you are SELECTing frequently updated data or large sets of data
  • avoid wildcards at the start of LIKE queries
  • avoid correlated subqueries and in select and where clause (try to avoid in)
  • no calculated comparisons -- isolate indexed columns
  • ORDER BY and LIMIT work best with equalities and covered indexes
  • separate text/blobs from metadata, don't put text/blobs in results if you don't need them
1