One interviewer asked me this following question

  • Hi,

    One interviewer asked me this following question.

    A 200 lines stored procedure working fine till yesterday, but today morning it is taking long to run. How can you find where the problem is and what is the cause for this?

    I said the there may be network problem. He did not agree. Can you help?

  • First things first, look at the execution plan. See where it's hanging.

    If you don't see anything there, check for blocks while it executes.

    If that also looks fine, check CPU/IO usage and see if those are spiking for some reason on the box.

    If not, make sure the proc hasn't actually changed (compare to source control versions).

    If it hasn't, you can look into indexes/statistics/fragmentation on the tables it's pulling from. The only reason this isn't higher is because fragmentation usually doesn't happen out of the blue unless you have a huge data job on the tables..which I'm sure you would know about.

  • If the stored procedure does not connect to another server then it's very unlikely network problems would affect the performance.

    Assume the stored procedure only accesses databases on this server, what else could have changed?



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Thank you all for your replies.

    BMR

  • My guess would be statistics, but there are lots of possible causes and without more info it's impossible to say which.

    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
  • I was called in once where a procedure went from running in less than a second to many minutes. Since the procedure was called multiple times for each order picked and shipped it impacted getting products shipped.

    The problem turned out to be a bad record added to a lookup table. I don't have my notes handy to explain the details, but no one would believe me until they removed the bad record and the problem went away.

    I do agree with the previous comment that unless the procedure went across servers then network problems would not be a good answer.

  • Any DML operation held in the night which disturbed the indexes/statistics.this could be one cause

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Removed

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • It's now using a bad query plan from the cache.

    This exact scenario happened to us. As soon as the bad plan was removed; the sproc started running great again.

  • here would be my response, in order:

    1) dropped index. would do a schema compare from known good config for db

    2) new version of code rolled out - same as 1 to verify

    3) blocking - sp_whoisactive

    4) parameter sniffing issue

    5) stupid user input (like asking for 5 years worth of data in report that should do a day or week) 🙂

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • 1) check all process of corresponding database using sp_who.

    2) check any process is not suspended ?

    3) check query plan also

  • Please note: 3 year old thread

    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

Viewing 12 posts - 1 through 11 (of 11 total)

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