phpMyAdmin 想要添加多个索引作为一个多列索引
我正在使用 phpMyAdmin 创建表,并希望定义两个不同的列作为索引。我不想创建多列索引,但 phpMyAdmin 会这样创建它们。这有什么可能的问题吗?这些字段彼此不直接关联,并且两个字段不会同时在 WHERE
子句中使用。
考虑:
ALTER TABLE `documents` ADD INDEX (`offer_number`, `contract_number`);
和:
ALTER TABLE `documents` ADD INDEX (`offer_number`);
ALTER TABLE `documents` ADD INDEX (`contract_number`);
有什么区别?
I'm creating tables using phpMyAdmin and want to define two different columns as indices. I'm not trying to create a multi-column index but phpMyAdmin creates them as such. Are there any possible issues with that? The fields don't relate to each other directly and both fields will not be used in WHERE
clauses simultaneously.
Consider:
ALTER TABLE `documents` ADD INDEX (`offer_number`, `contract_number`);
And:
ALTER TABLE `documents` ADD INDEX (`offer_number`);
ALTER TABLE `documents` ADD INDEX (`contract_number`);
What's the difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅当索引的第一列与查询中使用的列匹配时,MySQL 才能使用索引。换句话说,如果您执行可以使用
contract_number
索引的查询,则不会使用复合索引,因为contract_number
不是该键中的第一列。不过,复合索引可用于使用offer_number
的查询。MySQL can only make use of an index if the first column(s) of the index match the columns used in the query. In other words, if you perform a query where an index on
contract_number
could be used, the composite index won't be used sincecontract_number
is not the first column in that key. The composite index could be used for a query whereoffer_number
is used, however.http://dev.mysql.com/doc/refman /5.0/en/multiple-column-indexes.html
http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
鉴于您对这些字段的看法,它们不应该成为一个多列索引的一部分。
如果您想在 PhpMyAdmin 上创建单列索引,则需要一次创建一个。
http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html
http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
Given what you say about these fields, they should not be a part of one multi column index.
If you want to create single column indexes on PhpMyAdmin, you need to create them one at a time.