mysql innodb indexing confused
I am building a mysql table: ID (auto int), cc char(9), tt int(11), mm char(3)
Now I have set the ID to be the primary index.
Every query will be either select or update with WHERE开发者_如何学C id='numberhere' LIMIT 1. (so its just 1 row at a timw ever needed)
Now, To get the correct performance benifit from using innodb, do I just leave ID as primary and only index in the table? or should I set everything as an index? I am unsure...
EDIT: no joins in the table, it is literally SELECT * FROM table WHERE id='2341...' everytime or same but with update...
You might set everything you join
on as an index. Maybe even everything you use in a where
. Too many indexes slow insertions/updates, as you have to create them, so it's down to use.
As Nanne responded, if you are always dealing with a specific key, having that column as its own index is perfectly fine and always have that table as the first table in your SQL-Select statements and the first condition in your WHERE clause as you sampled... If you ARE ever doing a JOIN to another table, make sure the OTHER table has an index on the column you would be matching to for optimizing THAT join portion...
精彩评论