?
Solved

How to create index as suggested by execution plan.

Posted on 2013-01-10
4
Medium Priority
?
430 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 27

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 27

Accepted Solution

by:
Chris Luttrell earned 1000 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 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 1000 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

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

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

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

850 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