mysql 5.1 分区 - 我是否必须删除索引/键元素?

发布于 2024-09-17 00:54:12 字数 133 浏览 3 评论 0原文

我有一个包含多个索引的表。它们都包含一个特定的整数列。 我正在迁移到 mysql 5.1,并将按此列对表进行分区。

我是否仍然需要将此列保留为索引中的键,或者我可以将其删除,因为分区将仅有效地在相关键数据中进行搜索,而无需将其指定为键?

I have a table with several indexes. All of them contain an specific integer column.
I'm moving to mysql 5.1 and about to partition the table by this column.

Do I still have to keep this column as key in my indexes or I can remove it since partitioning will take care of searching only in the relevant keys data efficiently without need to specify it as key?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

掩耳倾听 2024-09-24 00:54:12

分区字段必须是索引的一部分,因此答案是我必须将分区列保留在索引中。

Partition field must be part of index so the answer is that I kave to keep the partitioning column in my index.

薄荷港 2024-09-24 00:54:12

分区只会根据您的设置方式将该索引的值/范围分割成单独的分区。您仍然希望在该列上有索引,以便在分区修剪完成后可以使用索引。

请记住,这对您可以拥有的分区数量有很大影响,如果您有一个整数列,其中只有 4 个不同的值,您可能会创建 4 个分区,并且根据您的查询,索引可能不会给您带来太大好处。

如果您的整数列中有 10000 个不同的值,那么如果您尝试创建 10k 分区,就会达到系统限制 - 您必须在大范围内进行分区(例如 0-1000,1001-2000 等),在这种情况下,您将从索引中受益(同样取决于您查询表的方式)

Partitioning will only slice the values/ranges of that index into separate partitions according to how you set it up. You'd still want to have indexes on that column so the index can be used after partition pruning has been done.

Keep in mind there's a big impact on how many partitions you can have, if you have an integer column with only 4 distinct values in it, you might create 4 partitions, and an index would likely not benefit you much depending on your queries.

If you got 10000 distinct values in your integer column, you hit system limits if you try to create 10k partitions - you'll have to partition on large ranges (e.g. 0-1000,1001-2000, etc.) in such a case you'll benefit from an index (again depending on how you query the tables)

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