MySQL Tips
1. Be familiar with MySQL's column types along with their ranges/lengths. You should use the smallest column type that will hold the data that you expect to store. Most of the time, you probably don't need INT, because MEDIUMINT, SMALLINT, or TINYINT have enough range. Using a smaller type saves space and speeds things up.
2. Declare all of your columns NOT NULL unless you need to store NULL values (NULL is not the same as 0 or the empty string). NOT NULL saves space and speeds things up.
3. Making INT-family columns UNSIGNED will effectively double the positive range with the same storage requirement. For example, TINYINT's highest value is 127. TINYINT UNSIGNED's highest value is 255.
4. When you have your indexes setup, use EXPLAIN on SELECT queries to make sure your indexes are actually being used.
|