Optimize SQL Server query

I have created a view that returns data from more than one table using join. When I select from that view without using Order By clause, the time taken to execute that query is only about 1 second or less. But when I use order by with my select query, it takes about 27 seconds to return only the top(15) records from that view.

Here is my query that I run To get data from View

SELECT TOP(15) *
FROM V_transaction 
ORDER BY time_stamp DESC

Note : total number of records that view has is about 300000

What can I change in my view's design to get better performance?


First thing that pops into mind is creating an index on time_stamp in the view. If you don't want to/can't create an indexed view you could create an index on the column in the underlying table that you are getting that value from. This should increase your queries performance.

If you are still having issues post the execution plan - this should show you exactly where/why your query is experiencing performance problems.


为什么不创建一个额外的列来存储每个日期记录的天数+秒数,然后按该列排序。

链接地址: http://www.djcxy.com/p/93942.html

上一篇: MySQL查询关闭表

下一篇: 优化SQL Server查询