RE: Query Performance ~ Split the SP.

From: SQLCatz (SQLCatz_at_discussions.microsoft.com)
Date: 09/07/04


Date: Tue, 7 Sep 2004 06:45:05 -0700

Hello Heidi,

Solution below does not involve checking / optimizing indexes.

We had a problem similar to what you are facing. A part of the problem was
that our stored procedure was too generic. Based on the values of the input
parameters - It could execute 1 of 4 different queries.
I re-wrote the functionality in a different way.
Split the single SP into a 2 level hierarchy.
The top level wrapper SP would check the input parameters and then decide on
which 2nd level SP to call. Since there were 3 2nd level SPs - which were
specific - SQL server would create a plan for each one of them - which would
get cached and re-used.
In the earlier scenario - where there was one massive generic SP - SQL
Server would create a plan for the first path that the query would take. When
the parameters changed and the flow inside the SP had to take another route -
the existing plan was not efficient - so SQL Server would create another
plan.
Same process continues for each of the 3 different queries. Very inefficient.

The small change (splitting the SP) itself gave us quite a big performance
gain.
Added advantage - the code was more manageable too.
Our DBA was OK with having dependencies between SPs in his DB!

Try this approach first, before you move onto the indexes.

Cheers!



Relevant Pages

  • RE: Query Performance ~ Split the SP.
    ... Solution below does not involve checking / optimizing indexes. ... specific - SQL server would create a plan for each one of them - which would ... Server would create a plan for the first path that the query would take. ...
    (microsoft.public.sqlserver.programming)
  • Re: Slow UPDATE and DELETE on SQL Server 2000
    ... databases: one on the new machine and one on the old machine (by the ... The plan from the old machine was more complex and has PARALLELISM ... > wrong with the SQL Server installation and unlikely that there are sub-system ... > linked-server driver parameters are not properly set. ...
    (microsoft.public.sqlserver.server)
  • Re: insert..select
    ... Parameter sniffing. ... > The execution plan is vastly different. ... trigger on the target table. ... >> Tibor Karaszi, SQL Server MVP ...
    (microsoft.public.sqlserver.server)
  • Re: Problem with Transaction backups
    ... You may need to drop and recreate the plan altogether if it doesn't save it by just editing it. ... Basically we have an SQL server that was running full backups and hourly ... a test database and tried the same thing and got the same results. ... Microsoft Analysis Services Client Tools 2005.090.3042.00 ...
    (microsoft.public.sqlserver.server)
  • Re: Reindex doesnt work
    ... The answer is that the whole affair with maintenance plan and reindexing ... SQL Server builds a query plan for the first time, ... passing a high-water mark as parameter. ...
    (microsoft.public.sqlserver.tools)