I have attached a Stored Procedure (CleanupSP). This Stored Procedure takes 3.22 Hours to run. I would like to clean it up so it will run faster?. I did not create this, but someone told me that it deals with a vertical Table??? and that is why it is like it is???
How frequently does this sp have to be run?
The sp constructs five tables from complex data aggregation.
Presumably you can not alter the database structure using triggers to maintain an upto date.
Using views would sacrifice performance for seemingly an infrequent run of the query.
Checking the organization of the primary table does it include historic data or does it employ archiving where at the conclusion of the year? Does your db use partitioning based on the year??
If the data does not change, and if you can spare the storage, the sp coud create tables that include the @taxyear in the name removing the drop section.
EugeneZ
for start: make sure to add appropriate indexes (run exec sp_helpindex for the tables in the query)
and insure DB maint task ran: reindex; update stats;checkdb
---
and review the code for CTE usage ( looks like it is a good candidate)
Amour22015
ASKER
Hi and thanks
First let me say that I am new to Stored Procedures.
So I am at a loss on the comments made?
SP runs M, T, W at night
It was mentioned:
Checking the organization of the primary table does it include historic data or does it employ archiving where at the conclusion of the year? Does your db use partitioning based on the year??
If the data does not change, and if you can spare the storage, the sp coud create tables that include the @taxyear in the name removing the drop section
The primary table (Main Table)
does not use historic data it is based on Tax Year which in this case is 2012
the other parts I am not sure how to answer?
Mentioned:
for start: make sure to add appropriate indexes (run exec sp_helpindex for the tables in the query)
and insure DB maint task ran: reindex; update stats;checkdb
---
and review the code for CTE usage ( looks like it is a good candidate)
The sp constructs five tables from complex data aggregation.
Presumably you can not alter the database structure using triggers to maintain an upto date.
Using views would sacrifice performance for seemingly an infrequent run of the query.
Checking the organization of the primary table does it include historic data or does it employ archiving where at the conclusion of the year? Does your db use partitioning based on the year??
If the data does not change, and if you can spare the storage, the sp coud create tables that include the @taxyear in the name removing the drop section.