April 3, 2014 at 10:32 am
I've got a table that has a composite index on three of its fields. I don't want to create another index if I don't have to, but I'm trying to speed up some views that are taking a while.
I'm doing a rollup on PartNumber, which is the first field in the composite index.
Will it use that index to accomplish a search on PartNumber alone if needed? Will it do it for any field in the composite index?
April 3, 2014 at 11:36 am
It should use part number if you search for part number alone. I'm not sure about the rest. You could test by viewing the execution plans to be certain.
April 3, 2014 at 11:45 am
since you said the PartNumber is the first field, then yes; but it also depends on how selective that single column is.
if there's a lot of common values, SQL might just decide to do a clustered index scan instead.
so to confirm, if PartNumber is the leading column in your index that has three fields, would it be posible for a query to use the index.
so if the index is (PartNumber,SecondKey,ThirdKey) then yes.
if the index was created as (FirstKey,SecondKey,PartNumber) then no, you'd need an extra idnex.
Lowell
April 3, 2014 at 11:49 am
It's better to test by viewing the execution plans.
--
SQLBuddy
April 3, 2014 at 4:56 pm
It goes back to the histogram on the statistics. That is only build on the first column in the index key. The others are used to help establish the density (how selective the entire key is), but the histogram is only on that first one.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply