December 6, 2017 at 10:53 am
Hi All,
Need a suggestion on Index creation. Suppose, If wanted to create a covering index on table "T2" how does it look like?
IF i had to take full advantage of the index, what should be the order of the columns while creating the index??
Please suggest.
Sample workload query:
========================
declare @userid int
set @userid = 90
SELECT
t1.c1,
t1.c2,
t2.address
FROM t1 samp
JOIN t2
ON t1.componentid = t2.componentid
AND t2.userid = @userid
AND t2.isreportassociation = 1
which one of the below ones will be beneficial for above query?
1. create index on t2(componentid) include(userid,isreportassociation,address);
2. create index on t2(componentid,userid,isreportassociation) include(address);
3. create index on t2(componentid,userid,isreportassociation,address)
4. or multiple single individual indexes on all the columns ?
Thanks,
Sam
December 6, 2017 at 10:59 am
vsamantha35 - Wednesday, December 6, 2017 10:53 AMHi All,Need a suggestion on Index creation. Suppose, If wanted to create a covering index on table "T2" how does it look like?
IF i had to take full advantage of the index, what should be the order of the columns while creating the index??
Please suggest.Sample workload query:
========================
declare @userid int
set @userid = 90SELECT
t1.c1,
t1.c2,
t2.address
FROM t1 samp
JOIN t2
ON t1.componentid = t2.componentid
AND t2.userid = @userid
AND t2.isreportassociation = 1which one of the below ones will be beneficial for above query?
1. create index on t2(componentid) include(userid,isreportassociation,address);
2. create index on t2(componentid,userid,isreportassociation) include(address);
3. create index on t2(componentid,userid,isreportassociation,address)
4. or multiple single individual indexes on all the columns ?Thanks,
Sam
First, stay away from #4.
Without knowing the full schema on table t2, I would go with #2.
December 6, 2017 at 11:19 am
Thanks Lynn. One follow up question. How does the schema of the tables make a difference in creating an index?
December 6, 2017 at 11:48 am
Determining whether I need a non-clustered index or a clustered index (there can be only one clustered index so choose wisely). You also need to look at how is the data being accessed.
December 6, 2017 at 11:59 am
Lynn Pettis - Wednesday, December 6, 2017 11:48 AMDetermining whether I need a non-clustered index or a clustered index (there can be only one clustered index so choose wisely). You also need to look at how is the data being accessed.
One more thing that could affect the index definition is the data distribution on each column.
Before implementing a covering index, we need to know if there's a clustered index in place, if it has different keys, if there are multiple bit flags, etc.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply