phpMyAdmin 想要添加多个索引作为一个多列索引

发布于 2024-09-28 14:03:04 字数 403 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗忘曾经 2024-10-05 14:03:04

仅当索引的第一列与查询中使用的列匹配时,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 since contract_number is not the first column in that key. The composite index could be used for a query where offer_number is used, however.

似梦非梦 2024-10-05 14:03:04

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文