如何在内连接表上强制建立索引?
如何在与此类似的查询上强制索引。我需要分别对 foo 和 bar 强制建立索引。
SELECT foo.*, bar.*
FROM foo
INNER JOIN bar ON foo.rel_id = bar.rel_id
WHERE foo.status = 1
AND bar.status = 1
How do I force indexes on a query similar to this. I need to force an index on foo and bar individually.
SELECT foo.*, bar.*
FROM foo
INNER JOIN bar ON foo.rel_id = bar.rel_id
WHERE foo.status = 1
AND bar.status = 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设 foo 上存在索引 a,bar 上存在索引 b:
将强制在 MySql 上选择索引
Assuming index a exists on foo and index b on bar:
would force index selection on MySql
显而易见的事情是在两个表的
rel_id
和status
上创建覆盖索引以满足 join 和 where 要求。到目前为止你尝试过什么?
编辑
您提供 索引提示 但每个人的关键答案似乎是你不应该这样做。
The obvious thing would be to create a covering index on
rel_id
andstatus
of both tables to satisfy the join and where requirement.What have you tried so-far?
edit
You provide index hints but the crux of everyone answering seems to be that you shouldn't have to do that.