Solved

How to create index as suggested by execution plan.

Posted on 2013-01-10
4
403 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
query help 18 50
Group by and order by clause 28 35
GRANT, REVOKE, DENY 4 16
Script to randomly create characters in MS SQL 6 15
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

11 Experts available now in Live!

Get 1:1 Help Now