Tuesday, October 16, 2007

List some SQL optimisation techniques.

- Do not use SELECT * unless you must
- Do not create indexes you are not going to use
- Indexes are good for reads, but bad for writes
- Use OPTIMIZE TABLE and ANALYZE TABLE regularly
- Create your tables with a fixed-table format if possible
- Use the most efficient table type for each table
- Use the best data type, including NOT NULL if appropriate
- Use default values for INSERT when you can
- Use temporary tables rather than heavy PHP work
- Use SELECT priorities for better control
- SELECT foo IN (list, of, constants) is very fast
- When joining tables, use numbers instead of strings if you can

No comments: