sql - How to reduce scan count on table with a composite index? -
we have table (t) ~3 million rows , 2 int columns (id1 , id2), set composite clustered key.
early in stored procedure create table variable (@a) consists of list of ints.
the slow query following
select t.id1, t.id2 t inner join @a on a.id = t.id1
@a have few hundred rows, , t contains few million rows. problem t gets scan count of several hundred. don't know how make go away.
i have tried create index on t column id1 , id2 included, not (the execution planner shows new index used).
what can done reduce scan count on table t?
(we using sql server 2014, web edition)
try creating included (covering index):
create index idx_t_id1 on t(id1) include id2
this allow query find needs in index pages , not have search in main table. way there clustered index on table t?
Comments
Post a Comment