Re: Filter in the Join vs Filter in the Where
- From: "Russell Fields" <russellfields@xxxxxxxxxx>
- Date: Wed, 28 Oct 2009 13:15:16 -0400
One thing to note is that there can be a difference in results when choosing between a filter in the WHERE and a filter in an OUTER JOIN. (Basically, you are either (WHERE) filtering the rows to be returned, or (OUTER JOIN) filtering the rows to be joined.) You want to be sure that Bob is aware of this.
For one discussion: http://www.sqlservercentral.com/Forums/Topic449462-338-1.aspx
RLF
"Mike H" <mike8675309@xxxxxxxxx> wrote in message news:57423f8d-e354-4b41-9f7f-b785e14e8103@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Oct 28, 6:27 am, "Dan Guzman" <guzma...@nospam-
online.sbcglobal.net> wrote:
> Bob's theory being that since the order of operations for sql
> databases is:
> 1. FROM clause
> 2. WHERE clause
> 3. GROUP BY clause
> 4. HAVING clause
> 5. SELECT clause
> 6. ORDER BY clause
> sticking any filtering conditions into the FROM clause is going to
> lead to higher performance through less data needing to be processed
> as it is filtered before the where needs to deal with it. I've found
> others preaching this as well:http://www.bennadel.com/blog/70-SQL-
> Query-Order-of-Operations.htm
This logical order of query processing is not necessarily the same as the
physical order. Like Tom said, it is the execution plan that will tell the
real story. Semantically identical queries often yield the same execution
plan since the optimizer's job is to plan the declared query as efficiently
as possible. Even if you do get different plans do to happenstance (this
can tends to happen for more complex queries and the optimizer isn't
perfect), the plan could very well change between service packs or SQL
Server versions as the optimizer improves.
Thank you for the feedback. I've done some testing with Query analyzer
and have found that for the most part, execution plans end up being
the same regardless, even on the more complex queries. It is Bob's
insistence that the order of operations dictate that you are
essentially a fool for using the where clause that prompted my
question. He seems so fixed in his position that I thought that maybe
I'm missing something so basic, folks don't even talk about it.
.
- References:
- Filter in the Join vs Filter in the Where
- From: Mike H
- Re: Filter in the Join vs Filter in the Where
- From: Dan Guzman
- Re: Filter in the Join vs Filter in the Where
- From: Mike H
- Filter in the Join vs Filter in the Where
- Prev by Date: RE: Using the result of a function as a column name.
- Next by Date: Re: Huge msdb backups
- Previous by thread: Re: Filter in the Join vs Filter in the Where
- Next by thread: Data Cleansing
- Index(es):
Relevant Pages
|