Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Missing Index suggested by missing index script Expand / Collapse
Author
Message
Posted Monday, May 5, 2014 8:25 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, May 8, 2014 7:13 AM
Points: 22, Visits: 53
These index came from the query that reported missing indexes, but I’m just trying to get a better understanding and I have following questions: I would appreciate if anyone can help and provide guidance.


On the AddressLink indexes – do we need two separate indexes for AddressID, DefaultAddress where one includes CustomerID and one includes VendorID? The index on CustomerID includes AddressID, but the one on VendorID doesn’t include it?
CREATE INDEX [IX_New_index_AddressLink1] ON [dbo].[AddressLink] ([AddressID], [DefaultAddress]) INCLUDE ([CustomerID])
CREATE INDEX [IX_New_index_AddressLink2] ON [dbo].[AddressLink] ([AddressID], [DefaultAddress]) INCLUDE ([VendorID])
CREATE INDEX [IX_New_index_AddressLink3] ON [dbo].[AddressLink] ([CustomerID]) INCLUDE ([AddressID])
CREATE INDEX [IX_New_index_AddressLink4] ON [dbo].[AddressLink] ([VendorID])



On the AddressTaxLink indexes – both indexes are on AddressID, but one includes TaxID and the other doesn’t. Do we need two indexes here?
CREATE INDEX [IX_New_index_AddressTaxLink1] ON [dbo].[AddressTaxLink] ([AddressID])
CREATE INDEX [IX_New_index_AddressTaxLink2] ON [dbo].[AddressTaxLink] ([AddressID]) INCLUDE ([TaxID])

Similar questions for the indexes on ContactAddressLink – both are on ContactID, but one includes AddressID and the other doesn’t – are both needed?
CREATE INDEX [IX_New_index_ContactAddressLink1] ON [dbo].[ContactAddressLink] ([ContactID])
CREATE INDEX [IX_New_index_ContactAddressLink2] ON [dbo].[ContactAddressLink] ([ContactID]) INCLUDE ([AddressID])

On the ContactPhoneLink indexes – one of the indexes includes ID, PhoneID, PhoneTypeID, and DefaultPhone and one of the indexes includes three of those four fields – do we need both indexes or can we just create the one that has all four fields?
CREATE INDEX [IX_New_index_ContactPhoneLink2] ON [dbo].[ContactPhoneLink] ([ContactID]) INCLUDE ([ID], [PhoneID], [PhoneTypeID], [DefaultPhone])
CREATE INDEX [IX_New_index_ContactPhoneLink3] ON [dbo].[ContactPhoneLink] ([ContactID]) INCLUDE ([PhoneID], [PhoneTypeID], [DefaultPhone])

On the OrderCommission indexes – do we need both or could we create just the first one?
CREATE INDEX [IX_New_index_OrderCommission2] ON [dbo].[OrderCommission] ([OrderID], [PrimarySalesperson]) INCLUDE ([SalespersonID])
CREATE INDEX [IX_New_index_OrderCommission3] ON [dbo].[OrderCommission] ([PrimarySalesperson]) INCLUDE ([OrderID], [SalespersonID])

On the Orders indexes – do we need all three of these or could we create one that included ID, CustomerPO, OrderDate, OrderNumber?
CREATE INDEX [IX_New_index_Orders7] ON [dbo].[Orders] ([OrderTypeID]) INCLUDE ([ID], [CustomerPO])
CREATE INDEX [IX_New_index_Orders8] ON [dbo].[Orders] ([OrderTypeID]) INCLUDE ([ID], [OrderDate])
CREATE INDEX [IX_New_index_Orders9] ON [dbo].[Orders] ([OrderTypeID]) INCLUDE ([ID], [OrderNumber])
Post #1567529
Posted Monday, May 5, 2014 8:35 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 2:51 PM
Points: 42,756, Visits: 35,850
The missing index DMV always recommends the exact best index for a single query. It takes makes no consideration as to whether the index is a near-duplicate with an existing or already recommended index. The list from the DMV will frequently include multiple redundant indexes.

In your example, the only set that can't be consolidated without any reduction in performance is the two on OrderCommission.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1567538
Posted Monday, May 5, 2014 8:44 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 1:29 PM
Points: 4,343, Visits: 6,149
Some of the worst performance messes I have ever had to untangle at clients were due to the use of DTA by unqualified individuals. 2 clients made their systems essentially non-functional (and neither had the ability to unwind what they did).


Best,

Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru at GMail
Post #1567544
Posted Monday, May 5, 2014 8:54 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 3:34 PM
Points: 15,623, Visits: 28,007
So, other than just the size of the index, what's different about these two:

CREATE INDEX [IX_New_index_AddressLink1] ON [dbo].[AddressLink] ([AddressID], [DefaultAddress]) INCLUDE ([CustomerID])
CREATE INDEX [IX_New_index_AddressLink2] ON [dbo].[AddressLink] ([AddressID], [DefaultAddress]) INCLUDE ([VendorID])

And just doing this:

CREATE INDEX [IX_New_index_AddressLink1] ON [dbo].[AddressLink] ([AddressID], [DefaultAddress]) INCLUDE ([CustomerID],[VendorID])

The simple fact is, nothing. You'd be better off with that index than the two up above.

But, that doesn't address the fact that you don't have a clue which queries this index was suggested for. The missing index DMVs can be useful for suggestions, but if you really want to correlate queries to missing index suggestions, you need to query the procedure cache directly. And even then, you should test to validate that these index suggestions are actually helpful to the queries involved.

This is an introductory query I wrote for pulling information from the plan cache.


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1567549
Posted Monday, May 5, 2014 9:55 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, May 8, 2014 7:13 AM
Points: 22, Visits: 53
Thanks for the reply

"" you need to query the procedure cache directly.""


can you please clarify this as I am confuse about the about line.
Post #1567579
Posted Monday, May 5, 2014 10:39 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 3:34 PM
Points: 15,623, Visits: 28,007
Did you follow the link to the query I posted? It shows how to query the Dynamic Management Views that give you access to the plans in cache such as sys.dm_exec_query_stats and sys.dm_exec_query_plan. I introduced the query here, describing a bit more about why I originally wrote it. There are also links to other people's versions of the same type of query in the comments.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1567617
Posted Monday, May 5, 2014 10:43 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 4:28 PM
Points: 2,027, Visits: 3,023
As others have noted, never create indexes just because dta recommends them.

More importantly, though, the single most important performance factor is first getting the best clustered index. (Barring some emergency situation), Only after you get the best clustered index should you worry about nonclustered index(es).


SQL DBA,SQL Server MVP('07, '08, '09)
"In America, every man is innocent until proven broke!" Brant Parker
Post #1567621
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse