MS SQL Perofrmance issue with T-sql

Please find the screenshot and suggest us how to fine tune: This is SQL Server 2016
Key.jpg
VijayAsked:
Who is Participating?
 
Pawan KumarConnect With a Mentor Database ExpertCommented:
How much time the query is taking ?

The query is using an index but that index does not cover all the column the query needs so the query will have to go for that extra column using keylookup 50001 times which looks like an issue. If possible add(include) that extra column in that in that index itself so that we can ignore this key lookup part. Meaning we will get all the data at one place and do not have to traverse to get the additional data.

Also why we are specifying so many locks and an Index..(forced)
 [dbo].[BlobMigrationQueue] WITH(ROWLOCK, UPDLOCK, READPAST,Index=IX_BlobMigrationQueueGet)
0
 
Daniel_PLDB Expert/ArchitectCommented:
Hi,

You didn't provide us with the query. Basing on this screen only you are querying columns which are not included in an index and index has been choosen, therefore even if it has clusterd index key values in its leafs SQL is looking to PK for other columns.
Modify your index accordingly by adding columns (main or included - depends on query which we don't see) or create new covering index if query is worth doing that - is being frequently executed etc.

Regards,
Daniel
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Please tell us on what basis you believe we can answer your question without seeing the code that generated it, the schemas of the queried tables, or a full execution plan:   Mind reading, Seance, or 'The Force'.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
VijayAuthor Commented:
----This is the Query---

WITH [CTEOrderedUpdate]
		  AS
		  (
			SELECT TOP(@MaxRows)
			  [Uid],
			  [AgentName],
			  [Step],
			  [StepInProgress],
			  [ProcessCount],
			  [DateStarted],
			  [DateFinished]
			FROM
			  [dbo].[BlobMigrationQueue] WITH(ROWLOCK, UPDLOCK, READPAST,Index=IX_BlobMigrationQueueGet)
			WHERE
			  [Step] = 0 AND
			  [Failed] = 0 AND
			  [StepInProgress] = 0
		  )
		  UPDATE
			[CTEOrderedUpdate]
		  SET
			[StepInProgress]  = 1,
			[AgentName]         = @AgentName,
			[ProcessCount]    = [ProcessCount] + 1,
			[DateStarted]     = SYSDATETIME(),
			[DateFinished]    = NULL
		  OUTPUT
			inserted.[Uid]
		  INTO
			@Batch([Uid])

Open in new window

0
 
VijayAuthor Commented:
Thank you
0
 
VijayAuthor Commented:
Thank you Pawan.
We found the solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.