I'm trying to increase the efficiency in some of my queries. Due to the limitation of my knowledge I have always been using Right outer join to bring in a full dataset from multiple tables then culling them down through the where statement. However as I would like to add 'clustered index' to the follow query that is feeding one of my Schema binding view, I'm just wondering if there is a way to turn the following Right outer joins into 'inner join' instead so that the index can be created to decrease load time.
As I've been banging my head on this block for the last 2-3 days, any suggestions will be greatly appreciated!!
- Table1 has Client information
- Table 2 is a Junction table consisting composite key from Table1 and Table3
- Table3 has Account information
FROM dbo.Table1
RIGHT OUTER JOIN dbo.Table2
ON dbo.Table1.[Client ID] = dbo.Table2.[Client ID]
LEFT OUTER JOIN dbo.Table4
ON dbo.Table2.[Account Officer] = dbo.Table4.FullName
RIGHT OUTER JOIN dbo.Table3
ON dbo.Table2.[Account ID] = dbo.Table3.[Account ID]
WHERE (dbo.Table2.[Client Type] LIKE '%Customer 1%')
AND (dbo.Table3.ServiceDescription NOT LIKE '%Nil%')
AND (dbo.Table2.[Indicative outcome] IS NULL)
AND (dbo.Table2.[Finalised outcome] IS NULL)
AND (dbo.Table2.Outcome IS NULL)
AND (dbo.Table2.ReviewOutcome IS NULL)
AND (dbo.Table3.[Account Type] = 15)
AND (dbo.Table3.AccountReviewComplete = 1)
I have tried to rearrange it so that some of the where criteria goes into the join as I've seen on some of the articles I found (which would apparently limit the data size at the start), which is said to increase efficiency but after reviewing the 'Live Query Statistics' for before and after, there doesn't seem to be that much of a difference. Example below:
FROM dbo.Table1
RIGHT OUTER JOIN dbo.Table2
ON dbo.Table1.[Client ID] = dbo.Table2.[Client ID]
LEFT OUTER JOIN dbo.Table4
ON dbo.Table2.[Account Officer] = dbo.Table4.FullName
RIGHT OUTER JOIN dbo.Table3
ON dbo.Table2.[Account ID] = dbo.Table3.[Account ID]
AND (dbo.Table3.[Account Type] = 15)
AND (dbo.Table3.AccountReviewComplete = 1)
WHERE (dbo.Table2.[Client Type] LIKE '%Customer 1%')
AND (dbo.Table3.ServiceDescription NOT LIKE '%Nil%')
AND (dbo.Table2.[Indicative outcome] IS NULL)
AND (dbo.Table2.[Finalised outcome] IS NULL)
AND (dbo.Table2.Outcome IS NULL)
AND (dbo.Table2.ReviewOutcome IS NULL)