Reducing execution time of sproc

  • 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!

  • 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[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • Its really long code .. approx 400 lines.

    I was hoping to get some tips & tricks .. best practices when using temp tables in sproc

  • 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[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • 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

  • 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
  • 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

  • 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.

  • 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

  • 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

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply