Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 245 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SQL Server: Query fast, but slow from procedure

#11
This may sound silly and seems obvious from the name SessionGUID, but is the column a uniqueidentifier on Report_Opener? If not, you may want to try casting it to the correct type and give it a shot or declare your variable to the correct type.

The plan created as part of the sproc may work unintuitively and do an internal cast on a large table.
Reply

#12
I was facing the same issue & this post was very helpful to me but none of the posted answers solved my specific issue. I wanted to post the solution that worked for me in hopes that it can help someone else.

[To see links please register here]


> At the end of your query, add OPTION (OPTIMIZE FOR (@now UNKNOWN))

Reply

#13
I had the same problem as the original poster but the quoted answer did not solve the problem for me. The query still ran really slow from a stored procedure.

I found another answer [here "Parameter Sniffing"][1], Thanks Omnibuzz. Boils down to using "local Variables" in your stored procedure queries, but read the original for more understanding, it's a great write up. e.g.

**Slow way:**

CREATE PROCEDURE GetOrderForCustomers(@CustID varchar(20))
AS
BEGIN
SELECT *
FROM orders
WHERE customerid = @CustID
END

**Fast way:**

CREATE PROCEDURE GetOrderForCustomersWithoutPS(@CustID varchar(20))
AS
BEGIN
DECLARE @LocCustID varchar(20)
SET @LocCustID = @CustID

SELECT *
FROM orders
WHERE customerid = @LocCustID
END

Doing this reduced my execution time from 5+ minutes to about 6-7 seconds.

[1]:

[To see links please register here]

"Parameter Sniffing"
Reply

#14
The solution i found was that the parameter was not declared with the same type as the actual column definition. Causing SQL Server to try to find the fastest way = Nested Loops.

ex. DECLARE MyParameter nvarchar(50)
Actual column: varchar(8)
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through