优化 SQL 连接语句
我正在加入两张桌子。第一个包含工作订单及其相关的零件号。第二个包含所有部件号的 BOM。它们都是大桌子。单独地,我可以在几秒钟内查询这两个表,甚至更短。当我执行连接时,需要几分钟的时间。这条语句末尾的where有可能是在join之后执行的吗?如果首先执行连接,我可能会发现这需要很长时间。但如果第一个表首先减少了 where,我认为这应该会很快。有没有办法编写更优化的查询?
SELECT Table2.ItemNum As ItemNum
FROM Table1
INNER Join Table2
ON Table1.PartNum = Table2.PartNum
WHERE Table1.WorkOrder = 10100314
I am joining two tables. The first contains work orders and their associated part numbers. The second contains the BOM for all of the part numbers. They are both large tables. Individually, I can query the two tables in seconds if not less. When I perform the join, it takes minutes. Is it possible that the where at the end of this statement is being performed after the join? If the join is performed first, I could see this taking a long time. But if the first table is reduced first by the where, I would think this should go fast. Is there someway to write a more optimized query?
SELECT Table2.ItemNum As ItemNum
FROM Table1
INNER Join Table2
ON Table1.PartNum = Table2.PartNum
WHERE Table1.WorkOrder = 10100314
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这会做得更好:
PartNum 字段上的索引也是必需的......
That will do a better job:
Indexes on PartNum fields are required too ...