data reads) are usually much more common than other statements (data
modifications, indexes are usually beneficial Only add an index that’ll be used frequently. Don’t bother indexing columns before you see what queries your users and your applications need. You can always add indexes afterward If all columns in an index are used in all queries, list the column with the highest number of duplicates at the left of the
KEY
clause. This minimizes index
size The smaller the index, the faster it’ll be. If you index large columns, you’ll get a larger index. This is a good reason to ensure your columns areas small as possible when you design your tables For long columns, you can use only a prefix of the values from a column to create the index. You can do this by adding a value in parentheses
after the column definition, such as KEY names (firstname(3), secondname(2), surname. This means that only the first three characters of firstname are indexed, then the first two characters of secondname
, and then 10 characters from surname. This is a significant saving over indexing 50 characters from each of the 3
columns When you do this, your index will be less able to uniquely identify rows, but it’ll be much smaller and still reasonably good at finding matching rows.
Share with your friends: