SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Reducing execution time of sproc


Reducing execution time of sproc

Author
Message
MuditGupta
MuditGupta
SSC-Addicted
SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)

Group: General Forum Members
Points: 437 Visits: 581
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!
Christopher Stobbs
Christopher Stobbs
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2528 Visits: 2233
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

w00t
Posting Best Practices
Numbers / Tally Tables

SQL-4-Life
MuditGupta
MuditGupta
SSC-Addicted
SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)

Group: General Forum Members
Points: 437 Visits: 581
Its really long code .. approx 400 lines.
I was hoping to get some tips & tricks .. best practices when using temp tables in sproc
Christopher Stobbs
Christopher Stobbs
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2528 Visits: 2233
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

w00t
Posting Best Practices
Numbers / Tally Tables

SQL-4-Life
GSquared
GSquared
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24217 Visits: 9730
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
GilaMonster
GilaMonster
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89543 Visits: 45284
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, MVP, M.Sc (Comp Sci)
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


MuditGupta
MuditGupta
SSC-Addicted
SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)

Group: General Forum Members
Points: 437 Visits: 581
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
MuditGupta
MuditGupta
SSC-Addicted
SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)

Group: General Forum Members
Points: 437 Visits: 581
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.
GSquared
GSquared
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24217 Visits: 9730
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
alen teplitsky
alen teplitsky
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2854 Visits: 4674
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search