Wednesday, March 7, 2012

Join Small Table to Big Table or Vice Versa, does it matter?

If I join Table1 to Table2 with a WHERE condition, is
it the same if I would join Table2 to Table1 considering
that the size of the tables are different.

Let's assume Table2 is much bigger than Table1.

I've never used MERGE, HASH JOINs etc, do any of
these help in this scenario?

Thank youserge (sergea@.nospam.ehmail.com) writes:
> If I join Table1 to Table2 with a WHERE condition, is
> it the same if I would join Table2 to Table1 considering
> that the size of the tables are different.
> Let's assume Table2 is much bigger than Table1.

For an inner join the order does not matter.

> I've never used MERGE, HASH JOINs etc, do any of
> these help in this scenario?

These are optimizer hints, and you should use them if you can get
good performance in any other way.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||> If I join Table1 to Table2 with a WHERE condition, is
> it the same if I would join Table2 to Table1 considering
> that the size of the tables are different.

Yes.

> I've never used MERGE, HASH JOINs etc, do any of
> these help in this scenario?

No.

--
David Portas
SQL Server MVP
--

"serge" <sergea@.nospam.ehmail.com> wrote in message
news:7_%te.82758$Jk6.1151808@.wagner.videotron.net. ..
> If I join Table1 to Table2 with a WHERE condition, is
> it the same if I would join Table2 to Table1 considering
> that the size of the tables are different.
> Let's assume Table2 is much bigger than Table1.
> I've never used MERGE, HASH JOINs etc, do any of
> these help in this scenario?
>
> Thank you|||On Tue, 21 Jun 2005 17:52:02 -0400, serge wrote:

> If I join Table1 to Table2 with a WHERE condition, is
> it the same if I would join Table2 to Table1 considering
> that the size of the tables are different.
> Let's assume Table2 is much bigger than Table1.

It doesn't matter because the query optimizer will go through thousands of
optimization iterations and choose the best plan it found so far in the
time frame it knows it should not spend any further.

> I've never used MERGE, HASH JOINs etc, do any of
> these help in this scenario?

no.. The query optimizer is smart enough to choose the best plan.

Tony
--
http://www.dotnet-hosting.com
Free web hosting with ASP.NET & SQL Server

No comments:

Post a Comment