Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Optimization in this query
Message
 
 
To
18/02/2010 20:36:29
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01449844
Message ID:
01449846
Views:
36
This message has been marked as a message which has helped to the initial question of the thread.
>I have the following query:
>
>
>DECLARE @NoMember Integer
>DECLARE @AddDate DateTime
>
>SET @NoMember=1
>SET @AddDate='2009-02-18 18:47:00'
>
>SELECT TOP 10 Thread.AddDate,Thread.Numero,Thread.Title,Thread.Url
>FROM Thread (NOLOCK)
>WHERE Thread.NoMember=@NoMember AND Thread.AddDate>@AddDate ORDER BY Thread.Numero DESC 
>
>
>The execution plan gives as attached in this message.
>
>At the bottom, there is a 97% of the process. This query, despite the fact that it returns only 10 records and despite the fact that everything is indexed, can take up to 1 to 2 seconds to execute. That is way too long. This should be done instantly. By looking at the execution plan, how would someone knows exactly what to do to optimize this?

What is the PK of the table?

You may try
select Thread.AddDate,Thread.Numero,Thread.Title,Thread.Url from Thread (NOLOCK) 
inner join (select top (10) Numero from  Thread (NOLOCK)
WHERE Thread.NoMember=@NoMember AND Thread.AddDate>@AddDate 
ORDER BY Thread.Numero DESC) X on Thread. Numero = X.Numero -- Assuming Numero is a PK
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform