MySQL 索引创建
我有一个包含 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
分别为每个列创建索引。让 mysql 弄清楚如何使用它们。
另外,顺便说一句,养成使用
Between 运算符的习惯:
而不是:
它更容易阅读和输入,并且完全相同做同样的事情。
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:rather than:
It's easier to read and type and does exactly the same thing.
为查询中使用的所有列创建索引。
(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