Home All Groups Group Topic Archive Search About

sql profiler vs. query analyzer

Author
7 Jan 2006 10:30 AM
Gerard
Hi,

I'm trying to improve on a query in one of my scripts and noticed that
execution time in query analyzer is several seconds where as in sql
profiler the start and end time of the statements (including
declaration of variables) is within the same millisecond. What am I to
make out of this (apart from that my query is slow)?

regards,

Gerard

Author
7 Jan 2006 10:47 AM
Gerard
correction the last sentence should read:

What am I to make out of this (apart from that my query is slow in QA)?
Author
7 Jan 2006 1:12 PM
Brian Selzer
If the query returns a large number of rows, QA must render these in the
Results Pane, which can make the query appear slower than it is.  To get a
better approximation of the query execution time, DECLARE a bunch of
variables and issue the query like this:

DECLARE @X INT, @Y INT, @Z INT, @Before DATETIME
SET @Before = GETDATE()
SELECT @X = X, @Y = Y, @Z = Z FROM ...
SELECT 'Before', @Before, 'After', GETDATE(), 'Duration', GETDATE() -
@Before

After execution the variables will contain the last row from the result set.
Be sure to include all of the columns from the original query.

Note that the actual production execution time will vary, depending on the
load on the server.

Show quote
"Gerard" <g.doesw***@gmail.com> wrote in message
news:1136630856.695948.246820@g44g2000cwa.googlegroups.com...
> correction the last sentence should read:
>
> What am I to make out of this (apart from that my query is slow in QA)?
>
Author
7 Jan 2006 1:19 PM
Gerard
Thanks for the tip Brian, I'll try this out. The query however only
returns 8 rows ( and 8 columns).

regards,

Gerard
Author
7 Jan 2006 8:47 PM
ML
That's exactly what Profiler is for - to show the performance of the server
not the client.

Test it on a table with columns of datatype text/ntext first with the
default setting of how many characters are returned in a character column
(256) and then the maximum (8192). The Profiler will show equal time while QA
will struggle in the latter case.


ML

---
http://milambda.blogspot.com/
Author
7 Jan 2006 11:38 PM
Erland Sommarskog
Gerard (g.doesw***@gmail.com) writes:
> I'm trying to improve on a query in one of my scripts and noticed that
> execution time in query analyzer is several seconds where as in sql
> profiler the start and end time of the statements (including
> declaration of variables) is within the same millisecond. What am I to
> make out of this (apart from that my query is slow)?

Other posters suggested that latency in QA is not captured in Profiler.
This is not my experience.

What events are are you tracing?

Add an extra batch before the real thing, and see where its StartTime
is. My guess is that the compilation of the query takes a long time.
This can also be investigated with running the query with SET STATISTICS
TIME ON; this adds output that separates compile time and execution time.

--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

AddThis Social Bookmark Button