Solved

How to create index as suggested by execution plan.

Posted on 2013-01-10
4
405 Views
Last Modified: 2013-01-14
Below inner select query taking lot of time and when i execute execution plan i got below suggestion.how to create below index as suggested by execution plan in sql server 2008 r2.

what is the syntax to create below and on which columns.

USER_LOGS
*********
DOCUMENT_ID,
TIME,
USERID,
USERTEXT

query
*****

SELECT MM.DOC_NUM,MM.TYPE
                   FROM
                   (
 SELECT  m.UOI_ID,m.DOC_NUM,m.ASSET_TYPE,
                   row_number() over(partition by l.DOCUMENT_ID order by TIME desc) RANK
                       FROM
                       [DOCUMENT_METADATA] m,
                         [USER_LOGS] l
                       where
                     m.META_ID=l.DOCUMENT_ID AND
                     m.DOC_NUM IS NOT NULL  AND
                    l.TIME > DATEADD (D, -1, GETDATE())            
)
 AS  IN1,[DOCUMENT_METADATA] MM
                       where
                       IN1.DOC_NUM=MM.DOC_NUM  
                         and RANK =1                   
                    
Missing Index Details from SQLQuery58.sql - not connected
The Query Processor estimates that implementing the following index could improve the query cost by 90.6913%.
*/

/*

GO
CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>]
ON [USER_LOGS] ([TIME])
INCLUDE ([DOCUMENT_ID])
GO
*/

 <MissingIndexes>
              <MissingIndexGroup Impact="90.6913">
                <MissingIndex Database="[XXXX]" Schema="[XX]" Table="[USER_LOGS]">
                  <ColumnGroup Usage="INEQUALITY">
                    <Column Name="[TIME]" ColumnId="5" />
                  </ColumnGroup>
                  <ColumnGroup Usage="INCLUDE">
                    <Column Name="[DOCUMENT_ID]" ColumnId="10" />
                  </ColumnGroup>
                </MissingIndex>
              </MissingIndexGroup>
0
Comment
Question by:chaitu chaitu
  • 2
4 Comments
 
LVL 26

Expert Comment

by:Chris Luttrell
ID: 38766106
Quick answer, change [<Name of Missing Index, sysname,>] to a real index name like ix_USER_LOGS_TIME and run it.
CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>]
ON [USER_LOGS] ([TIME])
INCLUDE ([DOCUMENT_ID])
GO

Open in new window

0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 38766114
like this

CREATE NONCLUSTERED INDEX [ix_USER_LOGS_TIME]
 ON [USER_LOGS] ([TIME])
INCLUDE ([DOCUMENT_ID])
GO
0
 
LVL 26

Accepted Solution

by:
Chris Luttrell earned 250 total points
ID: 38766123
yes, that will  create the index recommended by the execution plan.  Just a note, do not just create all indexes even if they are "recommended" by MS.  First test performance before and then again after to make sure it really helps, sometimes it still does not.  Also, the evaluation by the execution plan is in isolation, not taking everything else your system may do in consideration, so it is up to you to make the final decission on if it is really the best thing for your overall system.
0
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 250 total points
ID: 38767901
Definitely don't automatically create all indexes the query plan "tells" you to.

However, in the this case the index looks small so I would create it.

In fact, it might be best to consider clustering the table on time, but that would require more investigation to determine properly.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now