Of course, a rather obvious answer presents itself the next day. After reviewing the actual environment that my colleague was working in, it popped quickly into mind.
What if the table has a compound primary key? See comments for a play-by-play.
drop table dbo.testclusteredinclude create table dbo.testclusteredinclude , text1 varchar(30) Not null , constraint pk_testclusteredincludeprimary key (id1, id2, id3)
insert into dbo.testclusteredinclude (id1, id2, id3, text1) values (1,2,3,'test1'); --put in our seed row --filler data of 10000 rows
with cte3pk (id1, id2, id3) as (select id1=2,id2=3,id3=4 select id1+1, id2+1, id3+1 insert into dbo.testclusteredinclude (id1, id2, id3, text1) select id1, id2, id3, 'test2' from cte3pk OPTION (MAXRECURSION 10000); alter index all on dbo.testclusteredinclude rebuild
--turn on show actual exec plan --Second key of the Clustered Key canbenefit, this easy to understand.
-- We're simply giving SQL a narrower set of data, via the nonclustered index.
select id2, text1 from dbo.testclusteredincludewhere
create nonclustered index idx_nc_testclusteredinclude_id2_text1 on dbo.testclusteredinclude (id2, text1) select id2, text1 from dbo.testclusteredincludewhere
drop index idx_nc_testclusteredinclude_id2_text1 on dbo.testclusteredinclude --Still, putting a subsequent key of acompound clustered key in the include column doesn't help.
-- SQL can still do an index seek onid2, even when the index doesn't contain it
(idx_nc_testclusteredinclude_text1).
select id2, text1 from dbo.testclusteredincludewhere
create nonclustered index idx_nc_testclusteredinclude_text1 on dbo.testclusteredinclude (text1) select id2, text1 from dbo.testclusteredincludewhere
create nonclustered index idx_nc_testclusteredinclude_text1_inc_id2 on dbo.testclusteredinclude (text1) include (id2) select id2, text1 from dbo.testclusteredincludewhere
drop index idx_nc_testclusteredinclude_text1 on dbo.testclusteredinclude drop index idx_nc_testclusteredinclude_text1_inc_id2 on dbo.testclusteredinclude One final note - none of the SELECT statements above generate any missing index suggestions in SQL 2012 SP1 or SQL 2008 SP2, even though without any nonclustered indexes they all generated Clustered Index Scans.