SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Slow Query


Slow Query

Author
Message
wak_no1
wak_no1
SSC-Enthusiastic
SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)

Group: General Forum Members
Points: 169 Visits: 353
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.
sqlnaive
sqlnaive
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4291 Visits: 2774
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.
wak_no1
wak_no1
SSC-Enthusiastic
SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)SSC-Enthusiastic (169 reputation)

Group: General Forum Members
Points: 169 Visits: 353
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?
Alan.B
Alan.B
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5188 Visits: 7725
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



Best practices for getting help on SQLServerCentral
Need to split a string? Try DelimitedSplit8K or DelimitedSplit8K_LEAD (SQL 2012+)
Need a pattern-based splitter? Try PatternSplitCM
Need to remove or replace those unwanted characters? Try PatExclude8K and PatReplace8K.

"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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search