MySQL:无索引的UNIQUE约束 [英] MySQL: UNIQUE constraint without index
问题描述
可以添加一个约束,例如
Is it possible to add a constraint like
ALTER TABLE `t1` ADD UNIQUE(`col1`, `col2`);
索引不会用于任何查询,所以这将是一个浪费空间。
without creating an index? The index wouldn't be used for any queries so it would be a waste of space.
如果插入和更新会更慢,这不会是一个问题,因为表不会频繁更新。
It wouldn't be a problem if inserts and updates would be way slower, because the table doesn't get updated very often.
推荐答案
不,这是不可能的。 UNIQUE约束包含索引定义和I几乎没有想象如何实现而不创建索引(在DBMS术语中)。
No, this is not possible. A UNIQUE constraint contains an index definition and I barely imagine how it might be implemented without creating an index (in DBMS terms).
您应该意识到,索引不仅仅是精灵 - 它们是一个真实的数据结构,它需要空间,特殊的过程待处理等唯一约束本身是指唯一索引值,而不是唯一列值。
You should realize that indexes are not just 'wizardy' - they are a real data structure, which takes space to be placed, special procedures to be handled e.t.c. A unique constraint, itself, means unique index values, not unique column values.
这篇关于MySQL:无索引的UNIQUE约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!