拥有多个索引或带有多列的索引以用于JOIN查询的索引更好,其中一列使用了AT at'而另一个使用的是'?

发布于 2025-02-07 20:22:56 字数 191 浏览 1 评论 0原文

如果有的

Select *  
from tbl_x x  
left join tbl_y y on x.a = y.a  
where y.b = 'iwantthisvalue'

话,我为每个IDX(YA)和IDX2(YB)创建单独的索引 还是我应该只创建一个使用2列IDX(YA,YB)创建一个?

If I have

Select *  
from tbl_x x  
left join tbl_y y on x.a = y.a  
where y.b = 'iwantthisvalue'

should I create separate index for each idx(y.a) and idx2(y.b)
or should I create only one with 2 columns idx(y.a, y.b)?

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

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

发布评论

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

评论(1

与酒说心事 2025-02-14 20:22:56

如果在ya中有相同值的多行,而在yb中具有相同值的多行,则可以为两个在y上创建一个索引,b asc)。执行人将首先查找JOIN,然后在加入结果中 。如果选择> 中的其他列中 include 中的其他列中有汇总函数。如果在查询中使用 列的组列也可以“添加”(不包含在“包含”)中。因此,执行人将查找join之后whend, 和select> select> select“随附”。

If there are multiple rows with same value in y.a and multiple rows with same value in y.b - you can create one index for both create index on y(a asc, b asc). The executor will look up first for join and then for where in joined result. If there are aggregate functions in select - add other columns in include of the index. The group by columns could also be "added" (not "included") to the index if it is used in the query. So the executor will look up for join after that for where, for group by and for select of "included".

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