database design - Composite Index vs. INCLUDE Covering Index in SQL Server -
i understand composite indexes used left right (e.g. if index on city, state, city = "blah" or city = "blah" , state = "aa" work fine state = "aa" not).
does same principle apply include indexes?
thanks in advance!
clay
include columns can used supply columns select
portion of query. cannot used part of index filtering.
edit: further clarify point, consider example:
i create simple table , populate it:
create table mytest ( id int, name char(10) ) insert mytest (id, name) select 1, 'joe' union select 2, 'alex'
now consider these 3 indexes , corresponding execution plans simple select.
select id, name mytest name = 'joe'
case 1: index on id results in table scan.
create index idx_mytest on mytest(id)
case 2: index on id including name. better because index covers query, still scan operation.
create index idx_mytest on mytest(id) include (name)
case 3: index on name including id. best. index built on column in clause, seek operation, , index covers query because of included column.
create index idx_mytest on mytest(name) include (id)
Comments
Post a Comment