Slow performing Stored Procedure

MOHAN CHHAPADIA 1 Reputation point
2021-09-28T13:33:10.667+00:00

Hello,

I have a stored procedure which is running very very slow.

It fetches data from a very large table of about 10 million rows.

Issue is the SP used to take less time weeks before but now the execution time has increased to 4 fold.

Any suggestion how to improve the performance of this?

Thanks,
Mohan

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,697 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Ronen Ariely 15,096 Reputation points
    2021-09-28T14:05:54.833+00:00

    Good day,

    It fetches data from a very large table of about 10 million rows.

    10 million rows is far from being "very large table" for SQL Server

    I have a stored procedure which is running very very slow.

    Unfortunately we cannot read minds or connect your server and saying that you have an issue does not provide any information about the issue.

    If you have stored procedure or any other entity which is relevant to the question, then we need to see it or better to reproduce it i our server for testing and discussion about improvement.

    Issue is the SP used to take less time weeks before but now the execution time has increased to 4 fold.

    Your database changes over time and probably the data as well. It is perfectly normal for example that if you have more data and poor code and/or poor design then over time your system will work worse when you will have more data

    Any suggestion how to improve the performance of this?

    Yes, start with reading the stored procedure and if you need our help then we have the same need

    Please provide (1) the full code of the stored procedure, (2) DDL+DML for any relevant table including indexes, constraints, triggers, relations with other tables and any entity which might impact performance, (3) the actual Execution Plan in your server when you execute the SP - we need the XML full execution plan and not only the graphical image.

    Note: if you do not know how to provide one or more of the information then feel free to ask. We are here to help you but we do need the tools and the information which only you can provide

    0 comments No comments

  2. Erland Sommarskog 100.9K Reputation points MVP
    2021-09-28T21:21:40.207+00:00

    As Ronen says, with the amount of information you have provided, we cannot help you much.

    I like to point out that ff you are on SQL 2016 or later, and you have Query Store active for the database, you are in a lot better position, as you can find old query plans for the query, and maybe even force them.

    Else, well, as Ronen says, start with posting the store procedure so we know what you are working with. Then we will ask for more information once we have seen the procedure.

    0 comments No comments

  3. YufeiShao-msft 7,056 Reputation points
    2021-09-29T06:30:44.887+00:00

    Hi @MOHAN CHHAPADIA

    There are many factors to speeding up stored procedures, simple changes can be made to the code to optimize.
    This document can give you some tips:
    https://blog.sqlauthority.com/2010/02/16/sql-server-stored-procedure-optimization-tips-best-practices/

    0 comments No comments