Friday, February 24, 2012

Join Question

Sort of an esoteric question:

In a transaction with several joins that depend on the prior join statement, does the subsequence join attach to the previous table in its entirety or just the result of it's join?

Example:

INNER JOIN FS_COHeader HDR
ON DTL.COHeaderKey = HDR.COHeaderKey

INNER JOIN Mfg_SHIPDTL SHPDT
ON SHPDT.OMON = HDR.CONUMBER
AND SHPDT._DATESHIP_OwnRec = 11

LEFT OUTER JOIN Mfg_DFSHIP DFSHP
ON DFSHP._SHPLINE_OwnRow = SHPDT._Row

Now will this statement:

LEFT OUTER JOIN Mfg_DFSHIP DFSHP
ON DFSHP._SHPLINE_OwnRow = SHPDT._Row

JOIN with the results of this one:

INNER JOIN Mfg_SHIPDTL SHPDT
ON SHPDT.OMON = HDR.CONUMBER
AND SHPDT._DATESHIP_OwnRec = 11

Or will it JOIN to the entire (previous) table?Use Query Analyser's 'Display Estemated Execution Plan' (ctrl-l) and look for the joins doing table scans for your exact problem. I'd say it should use the subset from the previous join.

No comments:

Post a Comment