I have a query that runs extremely fast (1 sec) see below:
SELECT *
FROM ( select ROW_NUMBER() OVER ( ORDER BY [Rank] DESC ) AS RowNum, *
FROM [product].[FnSearchKeyword]('basic', null, null, null, null, null, null, null)
) AS RowConstrainedResult
WHERE RowNum = 1 AND RowNum < 30
Bad if I put this query inside a procedure it takes 15 seconds to run as follows:
CREATE anydata
@keywords nvarchar(4000),
@minimunRate int,
@priceFrom decimal,
@priceTo decimal,
@relaeseStart datetime,
@releaseEnd datetime,
@categoryList nvarchar(4000),
@storeList nvarchar(4000),
@rowBegin int,
@rowEnd int,
@orderBy int,
@isAdult bit = null
AS
SELECT *
FROM ( select ROW_NUMBER() OVER ( ORDER BY [Rank] DESC ) AS RowNum, *
FROM [product].[FnSearchKeyword]('basic', @minimunRate , @priceFrom , @priceTo , null, null, null, null)
) AS RowConstrainedResult
WHERE RowNum = 1 AND RowNum < 30
When I play the SQL, the return delay 15 sec:
exec anydata null, null, null, null, null, null, null, null, null, null, null
Note:
Parameters of Function FnSearchKeyword have the same declared type in AnyData Procedure.
I'm passing all values "NULL" in the exec procedure, just to have the same result as shown above query that runs fast. No changes in the scope of the parameters
Honestly, I noticed that the "Execution Plan" is changed when I run the query through the Procedure, but do not know how to solve this, since the parameters of the query are the same.
Unfortunately I need to be put inside a PROC query for other reasons not mentioned here not to further complicate the issue.
About Duplicated Message: Its question isn´t duplicated because it its slow running in anyone system (Query Analyzer, C# asp.net, others).