April 18, 2005 at 4:42 am
hi
i have one simple top 100 select query ,which is running fine but when i give order by condition it is taking hell lot of time.
i have updated the statistics (by update statistics tablename)also but no relief.
please suggest something.
April 18, 2005 at 5:12 am
Are the column(s) you are ordering by indexed?
April 18, 2005 at 6:04 am
Basically it is fetching through view and yes order by column is with clustered index(primary key)
April 18, 2005 at 6:18 am
If you could post some DDL that would probably make it easier to look at this.
April 18, 2005 at 6:28 am
this is the view 'Interface'
select top 100 percent log.InterfaceID
, log.Component
, log.XmlMessage
, log.ErrorCode
from interface log (nolock)
Left Outer Join ErrorMessage err (nolock)
on log.errorCode = err.AppErrorCode
order by log.lastmodifieddate desc
and i am using
select top 100 * from interface order by interfaceid desc
and interfaceid is primary key
April 18, 2005 at 6:51 am
I think problem is with the view
as it is ordering by a date which is not a index key I supose
My Blog:
April 18, 2005 at 6:57 am
Why are you using TOP 100 PERCENT and ORDER BY LastModifiedDate in the view?? That means that the entire table must first be sorted on LastModifiedDate for the view to return it's results correctly. Then the sort on InterfaceID can take place, but the clustered index is of no use now since the input is already sorted in a different order. Remove the top and order by in the view and everything will go fast as lightning (well..)
April 18, 2005 at 9:50 am
thanks chris for your suggestion ,yes you are correct,but the issue is i cant modify the existing code.
but very thankful to you all
April 18, 2005 at 11:58 am
If you can't follow Chris Suggestions try to order the Cluster index in descending order like
Create clustered idx_name on interface (interfaceid desc) ...
I really would advice againt order by in views but this is just to try a hack!
BTW: You have also indexes on errorCode, AppErrorCode and lastmodifieddate ... right?
hth
* Noel
April 19, 2005 at 1:45 am
Can you throw away the view and just access the underlying tables directly?
April 19, 2005 at 1:57 am
Godd sugestion
if have to use a view due to secuirty reasons , try to create another view which will allign with your job!
My Blog:
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply