vb.net - SQL Server Stored Procedure parameters affect speed of query - Why? -


i running stored procedure on sql server 2005 , calling vb.net application.

this stored procedure taking on 3 minutes run , started working on way speed up. quite accident stumbled on solution reduced run time 3 minutes 3 seconds (no joke, i'm dead serious).

but don't understand why.

the 2 parameters pass start date , end date (used in where clause) so:

alter procedure get_orderlinessbyregion      @datefrom datetime,      @dateto datetime begin     -- set nocount on added prevent result sets     -- interfering select statements.     set nocount on;  blah, blah, blah 

though testing found when hard coded dates in stored procedure run times cut 3 minutes 3 seconds.

i ended this:

alter procedure get_orderlinessbyregion   @datefrom datetime,   @dateto datetime begin     -- set nocount on added prevent result sets     -- interfering select statements.     set nocount on;         declare @startdate datetime        declare @enddate datetime         set @startdate = @datefrom        set @enddate = @dateto        blah, blah, blah 

can tell me why second version runs faster ?

thanks !!

this sounds case of bad parameter sniffing. can read article detailed explanation. http://sqlinthewild.co.za/index.php/2007/11/27/parameter-sniffing/


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -