Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Reducing execution time of sproc Expand / Collapse
Author
Message
Posted Thursday, March 5, 2009 9:31 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, May 8, 2012 12:49 PM
Points: 339, Visits: 560
Hi there

I am working few SQL tables. I am using lots of temp tables to derive some columns. Finally, I am joining these temp tables to get desired result set. I have created a stored procedure for executing the sql script.
Though the execution time has decreased from earlier but I am trying to reduce it more. for which, I am seeking some tips/points for making sproc executes faster as in where it consists of lots of temp tables.

Please Suggest.

Thanks!
Post #669345
Posted Thursday, March 5, 2009 9:37 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, February 24, 2010 4:10 AM
Points: 1,550, Visits: 2,232
Almost impossible to help unless we can see some code.

please read the link below for for advice on posting


----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley


Posting Best Practices
Numbers / Tally Tables

SQL-4-Life
Post #669350
Posted Thursday, March 5, 2009 9:43 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, May 8, 2012 12:49 PM
Points: 339, Visits: 560
Its really long code .. approx 400 lines.
I was hoping to get some tips & tricks .. best practices when using temp tables in sproc
Post #669361
Posted Thursday, March 5, 2009 9:50 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, February 24, 2010 4:10 AM
Points: 1,550, Visits: 2,232
It's hard to say really,

The size of the tables is a factor.
The indexes on the tables are factors.

How many you have is also a factor.
And obviously how they used.

If you run the code and maybe post from looking at the execution plan the slowest section then maybe we can start there?


----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley


Posting Best Practices
Numbers / Tally Tables

SQL-4-Life
Post #669367
Posted Thursday, March 5, 2009 9:52 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 9:58 AM
Points: 13,872, Visits: 9,600
sql-oholic (3/5/2009)
Its really long code .. approx 400 lines.
I was hoping to get some tips & tricks .. best practices when using temp tables in sproc


Save it as a file and attach it to the thread (there's an option for "Edit Attachments" when you post a message). A 400-line proc generally isn't that big a deal, so long as it's reasonably well formatted.


- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #669370
Posted Thursday, March 5, 2009 10:07 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 8:36 AM
Points: 40,615, Visits: 37,080
sql-oholic (3/5/2009)
I was hoping to get some tips & tricks .. best practices when using temp tables in sproc


Without seeing code the best I can offer is very general advice.
Make sure all the queries are written as optimally as possible.
Make sure the indexes support the workload



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #669386
Posted Thursday, March 5, 2009 10:33 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, May 8, 2012 12:49 PM
Points: 339, Visits: 560
Sorry for delay.
I have attached two files. One has schema of all the tables used
& second one contains the SQL query which is body of sproc
Post #669421
Posted Friday, March 6, 2009 6:28 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, May 8, 2012 12:49 PM
Points: 339, Visits: 560
FYI,
I figured out lots of things in my code.
I have created proper indexes in my tables which has reduced the execution time.

BTW,Isn't there a way to delete own post from the forum? Yesterday, somehow, I posted this topic in two forum which created some confusion.
Post #670146
Posted Friday, March 6, 2009 7:44 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 9:58 AM
Points: 13,872, Visits: 9,600
sql-oholic (3/6/2009)
FYI,
I figured out lots of things in my code.
I have created proper indexes in my tables which has reduced the execution time.

BTW,Isn't there a way to delete own post from the forum? Yesterday, somehow, I posted this topic in two forum which created some confusion.


Don't worry about it. If it becomes enough of a problem to matter, you can have Steve close down the second copy.


- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #670212
Posted Friday, March 6, 2009 9:11 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, December 15, 2014 1:02 PM
Points: 1,414, Visits: 4,545
you can try views

we have a dev who wrote something similar except he loved using views and rarely used temp tables. write a view for every temp table insert. you can also create permanent tables that you truncate every time you run this and then insert data, build indexes and then run your report. or you can write the code to join everything without temp tables, but it will probably take a while and require a lot of QA


https://plus.google.com/100125998302068852885/posts?hl=en
http://twitter.com/alent1234
x-box live gamertag: i am null
[url=http://live.xbox.com/en-US/MyXbox/Profile[/url]
Post #670340
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse