I have a query where I select a few columns from each of 5 left outer joined tables.
I did an execution plan in SQL Server 2008, and there are basically table scans on all of the joined tables, but the cost is all 0% for them - I'm assuming because there aren't many records in these tables.
Then at the last 2 steps of the execution plan (the final merge join of all the tables and the actual SELECT statement), it says 55% of the cost is the merge join, and 45% of the cost is the select.
This seems strange to me...why is the cost for those final 2 "bring it all together" steps so high? I thought all these table scans or sort steps would have more substantial cost.
I'm trying to get one "summarized" record out of all these tables...maybe I'm taking the wrong approach in left joining everything?
Updated with SQL
SELECT
/* Names */
NM.EMPLID, NM.NAME_PREFIX, NM.LAST_NAME, NM.FIRST_NAME, NM.MIDDLE_NAME, NM.NAME_SUFFIX,
/* Directory Info */
DIR_PERSON.BIRTH_DT,
/* PERSDATA */
PERS.SEX, PERS.HIGHEST_EDUC_LVL,
/* DIVERS.ETHNIC */
ETHNIC.ETHNIC_GRP_CD,
/* TENURE */
TENURE.EMPLID, TENURE.TENURE_STATUS, TENURE.EG_GRANTED_DT, TENURE.EG_TENURE_HOME,
TENURE.EG_TRACK_HIRE_DT, TENURE.EG_MAND_REVW_DT, TENURE.CODE,
/* VISA */
VISA.VISA_PERMIT_TYPE
FROM NAMES NM
/* ----- Table Joins ----- */
/* Directory Join */
LEFT OUTER JOIN DIR_PERSON ON DIR_PERSON.ID = NM.EMPLID
/* PERS_DATA Join */
LEFT OUTER JOIN PERS ON PERS.EMPLID = NM.EMPLID
AND PERS.EFFDT =( SELECT MAX(PERS_CURRENT.EFFDT) FROM PERS_CURRENT
WHERE PERS.EMPLID = PERS_CURRENT.EMPLID
AND PERS_CURRENT.EFFDT <= GETDATE())
/* ETHNIC Join */
LEFT OUTER JOIN ETHNIC ON ETHNIC.EMPLID = NM.EMPLID
AND ETHNIC.PRIMARY_INDICATOR = 'Y'
/* TENURE Join */
LEFT OUTER JOIN TENURE ON TENURE.EMPLID = NM.EMPLID
/* VISA Join */
LEFT OUTER JOIN VISA ON VISA.EMPLID = NM.EMPLID
AND VISA.EFFDT = ( SELECT MAX(VISA_CURRENT.EFFDT) FROM VISA_CURRENT
WHERE VISA.EMPLID = VISA_CURRENT.EMPLID
AND VISA_CURRENT.EFFDT <= GETDATE())
/* ----- End Table Joins ----- */
WHERE NM.NAME_TYPE = 'PRI'
AND NM.EFFDT = (SELECT MAX(NM_CURRENT.EFFDT) FROM NM_CURRENT
WHERE NM.EMPLID = NM_CURRENT.EMPLID
AND NM.NAME_TYPE = NM_CURRENT.NAME_TYPE
AND NM_CURRENT.EFFDT <= GETDATE());