Scalar sub query in db2

This is a discussion on Scalar sub query in db2 within the ibm-db2 forums in Other Databases category; In oracle, there is a performance improvement if scalar subqueries are used instead of joins. Does this hold good for Db2 (8.2) too?...

Go Back   Database Forum > Other Databases > ibm-db2

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-26-2008, 04:51 AM
Default Scalar sub query in db2

In oracle, there is a performance improvement if scalar subqueries are
used instead of joins. Does this hold good for Db2 (8.2) too?

Reply With Quote
  #2  
Old 08-26-2008, 08:42 AM
Default Re: Scalar sub query in db2

nshishir-at-gmail.com wrote:
> In oracle, there is a performance improvement if scalar subqueries are
> used instead of joins. Does this hold good for Db2 (8.2) too?

Inherently a scalar subquery is not a join.
I.e. a scaar subquery will raise an error if more than one match is
found. You cannot (easily) model that with an OUTER JOIN (you need the
OUTER to handle the NULL)

DB2 will convert scalar subqueries to outer joins (with some spice added
for semantics as noted above) at its own discretion.
So obviously in DB2 a scalar subquery is far from "always better".

Cheers
Serge




--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Reply With Quote
  #3  
Old 08-27-2008, 12:47 PM
Default Re: Scalar sub query in db2

>> In Oracle, there is a performance improvement if scalar subqueries are used instead of joins. Does this hold good for Db2 (8.2) too? <<

I don't think that statement is true in general for any SQL product.
There are two kinds of scalar subqueries:

1) evaluates to a constant -- (SELECT MAX(a) FROM Foobar) AS big_a

2) correlated to a containing query -- (SELECT MAX(a) FROM Foobar AS F
WHERE F.x = G.x) AS big_a_in_G

Then you can put them in the FROM clause or the SELECT clause, etc. If
I have a clustered table in Oracle, joins are already done, etc. There
are too many options for a general statement like that.
Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 03:01 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.