有复合索引时是否需要正常的MySql索引 [英] Is normal MySql index required when we have Composite index
问题描述
我们的MySql表有2500万行
We have MySql table having 25 million rows
以下是表格中的列
c_id,c_name,s_id,l_type,l_time,message,domain
在上面,我们在c_id,c_name,s_id,l_type,域列上具有正常索引
among above we have normal indexes on c_id,c_name,s_id,l_type,domain columns
我打算在domain,l_time,l_type列上添加复合索引.所以现在我可以删除域上的单个索引了吗?
I'm planning to add composite index on domain, l_time, l_type columns. So now can I remove individual index on domain?
谢谢
推荐答案
复合索引的任何前缀也将单独用作索引.因此,如果在(domain, log_time, log_type)
上具有复合索引,则等效于在domain
和(domain, log_time)
上具有索引.无需分别设置这些索引,它们将是多余的并且浪费空间.
Any prefix of a composite index will be used as an index by itself as well. So if you have a composite index on (domain, log_time, log_type)
, it's equivalent to having indexes on domain
and (domain, log_time)
. There's no need to have these indexes separately as well, they will be redundant and waste space.
因此,当您添加此复合索引时,可以安全地删除domain
上的索引.
So you can safely remove the index on domain
when you add this composite index.
这篇关于有复合索引时是否需要正常的MySql索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!