question

Palaniappan avatar image
Palaniappan asked

Performance Issue on View in SQL Server 2012

I am having performance issue on one of my view, issue is described as below; Original View CREATE VIEW TestView AS SELECT Name, Account Number, ProcessDate, Amount FROM TABLE1 The above was working fine, Modified View CREATE VIEW TestView AS SELECT Name, Account Number, ProcessDate, Amount FROM TABLE1 UNION ALL SELECT Name, Account Number, ProcessDate, Amount FROM TABLE2 After the modification the view is performing very poorly unexpected behavior. Issue: When I try to select the information using the views, Which is taking long time to produce the results(30+mins) using the UNION ALL on the view, without Union All and the second table the results are coming quickly. Below are approaches taken to improve the view: Verified the Indexes, Both tables are having Clustered Index on ProcessDate and Non Clustered Index on Account_Number and ProcessDate. To use the proper indexes during the data retrieval, I have created the separate views for both table and combined both and derived the new view. Then used the combined view, there is no improvements. Checked the execution plan of the existing view(TestView), Clustered Index Scan is appearing on the TABLE1 with cost of 99% and ProcessDate clustered index is used scan all the rows. Applied the Update Statistics to the Table1. Instructed the view to use the indexes forcibly using index hints. Now I am struck to improve the performance of the view and defrag percentage of the table is morethan 30% on TABLE1 and it has 80+ million records Please let me know your suggestions to improve the view.
view
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
I don't see any way to improve the view. It's returning all the records from two tables. It's going to be scanning those tables to retrieve the data. What you need is some sort of filtering criteria that will reduce the information being retrieved. Without that, the only real solution to speed things up is bigger faster hardware.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.