Where 子句中的 ANDS 顺序以获得最佳性能 [英] Order of ANDS in Where clause for greatest performance

查看:31
本文介绍了Where 子句中的 ANDS 顺序以获得最佳性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的想法是,如果我将过滤掉更多行的 AND 放在过滤掉少数行的 AND 之前,我的查询应该运行得更快,因为 And 语句之间的选择集要小得多.

My thinking is that if I put my ANDs that filter out a greater number of rows before those that filter out just a few, my query should run quicker since that selection set is much smaller between And statements.

但是 SQL 语句的 WHERE 子句中 AND 的顺序是否真的对 SQL 的性能产生了如此大的影响,还是引擎已经为此进行了优化?

But does the order of AND in the WHERE clause of an SQL Statement really effect the performance of the SQL that much or are the engines optimized already for this?

推荐答案

这真的取决于优化器.

不应该重要,因为无论您如何描述,找出运行查询的最佳方式是优化者的工作.

It shouldn't matter because it's the optimiser's job to figure out the optimal way to run your query regardless of how you describe it.

在实践中,没有任何优化器是完美的,因此您可能会发现重新排序子句确实会对特定查询产生影响.唯一确定的方法是使用您自己的架构、数据等自行测试.

In practice, no optimiser is perfect so you might find that re-ordering the clauses does make a difference to particular queries. The only way to know for sure is to test it yourself with your own schema, data etc.

这篇关于Where 子句中的 ANDS 顺序以获得最佳性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆