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

SQL:Stmt Completed v SQL:Batch Completed Expand / Collapse
Author
Message
Posted Tuesday, April 29, 2008 5:09 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, October 9, 2009 9:14 AM
Points: 14, Visits: 163
I'm troubleshooting a performance issue , Looking at Profiler - for the given statement, I'm getting the following figures , why would there be such a disparity between the figures. ? How can I go about finding out why there is such difference?


SQL:Stmt Completed:CPU = 31, Reads = 129 , Duration = 32
SQL:Batch Completed: CPU = 2531, Reads = 6087 , Duration = 2593


http://www.ITjobfeed.com
Post #491972
Posted Tuesday, April 29, 2008 5:48 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 4:14 PM
Points: 15,725, Visits: 28,130
A statement is a single piece of work, whereas a batch is a whole set of work.

So, for example:

DECLARE @Id INT;
SET @ID = 52;

SELECT *
FROM dbo.MyTable
WHERE Id = @Id;

That is one batch with three statements. You'll see a difference in execution results between the batch as a whole and the SET statement. Usually, unless you've got very specific troubleshooting going on, you don't want to collect statement level information using Profiler. It's very processor intensive.


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #491998
Posted Tuesday, April 29, 2008 5:53 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, October 9, 2009 9:14 AM
Points: 14, Visits: 163
Thanks for the reply , with the figures I sent across there is just the 1 sql server statement , which I'm confused about the disparity between the the statement completing and then the Batch completing.

http://www.ITjobfeed.com
Post #492004
Posted Tuesday, April 29, 2008 6:45 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 4:14 PM
Points: 15,725, Visits: 28,130
I'd have to see the procedure to understand why you're getting a difference. But I think, and I could be wrong about this, the batch includes the commit, but the statement doesn't.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #492038
Posted Tuesday, April 29, 2008 7:32 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, October 9, 2009 9:14 AM
Points: 14, Visits: 163
The statement I'm running from Query Analyzer is :
SELECT myCo1,myCol2 FROM myTable
INNER JOIN MyTable2 ON myTable.thecol = myTable2.thecol


Is there a specific event that would display the COMMIT ?


http://www.ITjobfeed.com
Post #492082
Posted Tuesday, April 29, 2008 9:12 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 4:14 PM
Points: 15,725, Visits: 28,130
No, it's an implicit commit. I just got the same results. I ran this query against Adventureworks:

SELECT  soh.[SalesOrderID]
,sod.[SalesOrderDetailID]
FROM Sales.[SalesOrderHeader] soh
INNER JOIN [Sales].[SalesOrderDetail] sod
ON soh.[SalesOrderID] = sod.[SalesOrderID]

I captured the batch and the statement. In the example, the statement had CPU = 16 and the batch had CPU = 31. The batch, I believe (I've looked at the documentation and can't find anything supporting that or denying it), simply includes all the time & cost to commit of the query where as the statement only has the minimal entries for the statement. Regardless, I would only use the statements if you had particular issues within a procedure or batch that you couldn't identify without having the full set of statements. The batch or rpc call events usually have all the data you need.


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #492233
Posted Wednesday, April 30, 2008 9:29 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 11, 2014 3:31 PM
Points: 358, Visits: 2,324
Would the batch-level include parsing and query plan determination / selection?


Post #493072
Posted Wednesday, April 30, 2008 9:34 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 4:14 PM
Points: 15,725, Visits: 28,130
Probably. I couldn't find good documentation on the detail of this, but my understanding is, the batch or rpc complete events include all the server side processing, beginning to end. Statement on the other hand only measures for that individual statement. I still wish I had a definitive answer, but that's my understanding.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #493079
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse