Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Slow Query Expand / Collapse
Author
Message
Posted Tuesday, October 29, 2013 3:14 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, November 6, 2014 5:46 AM
Points: 70, Visits: 330
Hello

I'm a bit of newbie when it comes to analysing a slow query, using a trace. Effectively, a user has reported that when saving a invoice from within a application, it takes far too long to do so. We've ensured that when they are saving the form, no one else is connected to the DB (UAT Environment) but we still experience the problem.

We've ran a trace to see if a bottleneck can be highlighted, having reviewed the results I cannot see anything hanging (taking the start and end time of each query into consideration).

I have though noticed that the application uses sp_prepexec to query the database, does anyone know of any issues relating to this?

Should I be looking at other things from within the trace?

Thanks.
Post #1509230
Posted Tuesday, October 29, 2013 3:42 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, November 20, 2014 4:29 AM
Points: 3,559, Visits: 2,671
If you are not getting anything in profiler for blocking during the invoice update process, then you might want to check execution plan of the underlying procedure doing the update process and pin point where exactly it is getting stuck. That may give some lead.
Post #1509238
Posted Tuesday, October 29, 2013 8:18 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, November 6, 2014 5:46 AM
Points: 70, Visits: 330
What would be the best way to view the execution plan, seeing how the queries are executed from the application? Would I need to replicate the process and perhaps view the Activity Monitor from the Instance?
Post #1509371
Posted Tuesday, October 29, 2013 4:47 PM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: 2 days ago @ 8:59 AM
Points: 646, Visits: 2,992
First, is the application executing a stored procedure or an Ad Hoc SQL Query? If it's Ad Hoc SQL you will want to put the query into a stored procedure. This will enable SQL Server to re-use query plans instead of creating a new one each time the query is ran.

wak_no1 (10/29/2013)
What would be the best way to view the execution plan, seeing how the queries are executed from the application?


To look at the execution plan you could: find out what query/stored procedure and parameters are being used when an end-user saves an invoice via the application and run it in SQL Server Management Studio (SSMS) using the same parameters. In SSMS, when you right-click the query window there is an option to "display estimated execution plan"; check that box and run your query.

Performance tuning a query is a huge topic. Some of the basic tips include: making sure that indexes are setup correctly, using the correct data type, setting your columns to NOT NULL except where NULLs are required, letting the application handle sorting (e.g. adding SORT BY can really slow queries down).

Troubleshooting SQL Server: A Guide for the Accidental DBA is an excellent book for identifying and correcting performance issues.


-- Alan Burstein



Read this article for best practices on asking questions.
Need to split a string? Try this (Jeff Moden)
Need a pattern-based string spitter? Try this (Dwain Camps)

"I can't stress enough the importance of switching from a 'sequential files' mindset to 'set-based' thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code. " -- Itzek Ben-Gan 2001

My blog
Post #1509605
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse