I hope you could share your time to help me on this.
Currently, I'm using 3 tables to compare performance in getting data. These 3 tables have the same columns (LocInvID, ActivityDate,ItemID,StoreID,CustomerID), same data (around 13 million records):
Table LocInv1: Using Clustered Index at LocInvID (it's primary key too). Using Partition Table for ActivityDate. And 3 columns (ItemID, StoreID, CustomerID) are Non-Clustered Index.
Table LocInv2: Using Clustered Index at LocInvID (it's primary key too). Not using Partition Table.
Table LocInv3: Using Clustered Index at LocInvID (it's primary key too). And 3 columns (ItemID, StoreID, CustomerID) are Non-Clustered Index. Not using Partition Table.
CREATE NONCLUSTERED INDEX [IX_LocInv3] ON [LocInv3] ( [ItemID] ASC ,[StoreID] ASC, [CustomerID] ASC ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO
And when I run this query string (in 3 tables)
select ActivityDate,ItemID,StoreID,CustomerID from LocInv1 WITH (INDEX(IX_LocInv)) where ItemID=43
select ActivityDate,ItemID,StoreID,CustomerID from LocInv2 where ItemID=43
select ActivityDate,ItemID,StoreID,CustomerID from LocInv3 where ItemID=43
the result is quite weird:
Table LocInv1 got slowest. Is it possible? my query string is incorrect?
Table LocInv3 uses Non-Clustered Index, but at Actual Execution Plan, it is Clustered Index Scan. I don't understand, I query with ItemID, why it is Clustered Index Scan?
Table LocInv2 uses only Clustered Index for LocInvID, but it got fastest result. Is it correct?
Please advise.
Thanks.
ItemID
that includes theActivityDate, StoreID, CustomerID
columns - in that case, this covering nonclustered index will most likely be used – marc_s