MySQL: UNIQUE constraint without index

夙愿已清 提交于 2019-12-22 06:56:26

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/19907766/mysql-unique-constraint-without-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!