Indexing WHERE clause of OUTER/CROSS APPLY with INCLUDE

1.2k Views Asked by At

I have read that indexing columns should be used when using a WHERE clause to restrict returned records (i.e. SELECT * from Table1 WHERE Field1 = 'abc').

Does this rule apply when using APPLY, as in

SELECT t.Field1,x.Field2 from Table1 t OUTER APPLY (select * from Table2 x WHERE t.Field1 = x.Field1?

In other words, would putting an index on Table2.Field1 speed up the above query?

Sorry if the answer is obvious, I don't have a solid understanding of the mechanics of OUTER and CROSS APPLY, only that they can be used in place of JOINs.

EDIT A better question, based off of this thread (Hard and Fast Rules for include columns in Index) would be, should I use INCLUDE for all of the columns that I am pulling from the other table, and if so, is it more efficient to use OUTER APPLY (select Field1,Field2 instead of OUTER APPLY (select *

2

There are 2 best solutions below

0
On

Well, whenever you specify a condition for column then an index will help to speed up the search.

It comes at a cost though: During insert the index will have to be recalculated and of course you will need disk space. But apart from that indexes have (almost) only advantages.

0
On

The Column that is being used on OUTER Apply should be indexed and should be used for joining with main query which will improve the query retrieval process as that will be used as clustered index seek and it will make query faster and Execution plan will be reused on successful retrieval.