View previous topic :: View next topic |
Author |
Message |
satyenderd Beginner
Joined: 26 Aug 2005 Posts: 144 Topics: 73
|
Posted: Thu Jul 24, 2008 4:33 pm Post subject: Query Performance of Join and Nested Query |
|
|
Hi all,
Could anyone please tell me if a Join query will take more time to get the data or a nested query.
Thanks in advance. _________________ Satya |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12380 Topics: 75 Location: San Jose
|
Posted: Thu Jul 24, 2008 7:03 pm Post subject: |
|
|
satyenderd,
Joins should always be faster - theoretically and realistically. Subqueries particularly correlated can be very difficult to optimise. If you think about it you will see why - technically, the subquery could be executed once for each row of the outer query
Subqueries such as that described are one instance of the way that SQL implements relational calculus (you will see that it is basically an "Exists" type of
operation). Joins are an implementation of relational algebra. The optimisation
of relational algebraic operations is *very* well understood, while the calculus
is much more difficult to optimise.
Realistically, most good DBMSs will optimise a query such as yours to use a join instead, thus converting the implementation from calculus to algebra. In general, subqueries - particularly correlated - should be avoided unless absolutely necessary. It makes the query harder to read/maintain, pushes more work onto the server, and is generally just a far less appropriate style of SQL.
Kolusu |
|
Back to top |
|
 |
satyenderd Beginner
Joined: 26 Aug 2005 Posts: 144 Topics: 73
|
Posted: Mon Jul 28, 2008 4:48 pm Post subject: |
|
|
Thanks Kolusu. _________________ Satya |
|
Back to top |
|
 |
|
|