MySQL 索引创建

发布于 2024-11-30 19:06:31 字数 283 浏览 8 评论 0原文

我有一个包含 10 列的表,我需要支持其中大部分的组合范围过滤器。

举例来说:

WHERE column_a >= a_min AND column_a <= a_max 
AND column_b >= b_min AND column_b <= b_max
...

但这还不是全部,我还需要支持按不同列对数据进行排序。

我的问题是,考虑到为了优化搜索而创建的可能索引组合是巨大的,我可能的选择是什么?

谢谢!

I have a table with 10 columns and I need to support combined range filters for most of them.

Let's say for example:

WHERE column_a >= a_min AND column_a <= a_max 
AND column_b >= b_min AND column_b <= b_max
...

But that is not all, I need also to support sorting data by different columns.

My question is, considering that the possible indexes combinations to create in order to optimize the searches is huge, which are my possible options?

Thanks!

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

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

发布评论

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

评论(2

毅然前行 2024-12-07 19:06:31

分别为每个列创建索引。让 mysql 弄清楚如何使用它们。

另外,顺便说一句,养成使用 Between 运算符的习惯:

column_a between a_min AND a_max

而不是:

column_a >= a_min AND column_a <= a_max -- ugly and the semantic is not as obvious

它更容易阅读和输入,并且完全相同做同样的事情。

Create indexes for each of the columns individually. Let mysql figure out how to use them.

Also, on a side note, get in the habit of using the between operator:

column_a between a_min AND a_max

rather than:

column_a >= a_min AND column_a <= a_max -- ugly and the semantic is not as obvious

It's easier to read and type and does exactly the same thing.

暗地喜欢 2024-12-07 19:06:31

为查询中使用的所有列创建索引。

(column_a,column_n)

请参阅此处的多部分索引的范围访问方法:http://dev.mysql.com/doc/refman/5.0/en/range-optimization.html

create an index for all the columns used in the query.

(column_a, column_n)

See The Range Access Method for Multiple-Part Indexes here: http://dev.mysql.com/doc/refman/5.0/en/range-optimization.html

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