[英]mysql innodb indexing confused
I am building a mysql table: ID (auto int), cc char(9), tt int(11), mm char(3) 我正在建立一个mysql表:ID(auto int),cc char(9),tt int(11),mm char(3)
Now I have set the ID to be the primary index. 现在,我将ID设置为主索引。
Every query will be either select or update with WHERE id='numberhere' LIMIT 1. (so its just 1 row at a timw ever needed) 每个查询都可以选择,也可以使用WHERE id ='numberhere'LIMIT 1进行更新。(因此,只要有一行,它就只需要一行)
Now, To get the correct performance benifit from using innodb, do I just leave ID as primary and only index in the table? 现在,为了使用innodb获得正确的性能收益,我是否只将ID保留为主表,而仅保留表中的索引? 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... 编辑:在表中没有联接,实际上是SELECT * FROM table WHERE id ='2341 ...'每次或相同,但带有更新...
You might set everything you join
on as an index. 您可以将
join
所有内容设置为索引。 Maybe even everything you use in a where
. 甚至您在某个
where
使用的所有东西。 Too many indexes slow insertions/updates, as you have to create them, so it's down to use. 太多的索引会减慢插入/更新的速度,因为您必须创建它们,因此无法使用。
正如Nanne回答的那样,如果您始终在处理特定键,则将该列作为其自己的索引就很好了,并且在进行采样时,始终将该表作为SQL-Select语句中的第一个表以及WHERE子句中的第一个条件...如果您要对另一个表进行JOIN操作,请确保OTHER表在要匹配的列上具有索引,以优化该连接部分...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.