Showing posts with label profiler. Show all posts
Showing posts with label profiler. Show all posts

Friday, March 23, 2012

Number of Rows returned by sp

Is it possible to get the number of Rows returned by a stored procedure in a profiler ?
if yes, what parameters shud I be looking for?
THanks
HarshalDo you mean like:

USE Northwind
GO

CREATE PROC mySproc99 @.rs int OUTPUT
AS
SELECT * FROM Orders
SELECT @.rs = @.@.ROWCOUNT
GO

DECLARE @.rs int

EXEC mySproc99 @.rs OUTPUT

SELECT @.rs
GO

DROP PROC mySproc99
GO|||no.
the sps are not to be changed.
its like

create procedure test
as
begin
select * from table
end

suppose this is the existing sp which is being used by a application
I want to put the profiler to get the number of rows which are being selected by this sp.
since its the prod db I cant change the sp.|||You may want to look into sp_trace_generateevent and related topics, but I think you'd still need to alter your procedures.|||From books online...

Use the SP:StmtCompleted event, and trace the Integer Data.

It is a bit difficult to find in BOL, so I bookmarked it, for myself. Try searching on "Monitoring with SQL Profiler Event Categories" The quoted string, will get you the desired result|||I can find the topic, and I can find a table that shows that the integer counter returns something for a stored procedure's StmtCompleted event, but darned if I can find anywhere that it explicitly says what that integer is!

Good sleuthing!

-PatP|||Pat: There should be two links on the page. Following "Stored Procedures Data Columns" should bring you to a short description of all the data elements.|||Hey thank you guys !!
I got the required data by importing the required data to my box and altered the proc and ran it. :cool: Ok I agree this is not a professional way to do things but it was a show stopper bug in the system so had to find a way.
I'll check the profiler events that rdjabarov and MCrowley has suggested.

Thanks again.

Regards,
Harshal.

Number of reads in Profiler is not the same when running the same SP on different PCs

I'm running the same query on two different PCs and tracing results in Profiler on my PC. When executing the query on PC1 - the total number of reads is 200000. When executing the same query on PC2 - the toal number of reads is 13000. It is almost 15 times more reads when executing query on PC2. The executed query is same on PC1 and PC2. Any reason for this?

I'm trying to analyse that query and reduce the number of logical reads as it's is too high but then I get completly different result on different PC.

Thanks.

The question is whether you are running it against the same dataset on the two PCs and if so how you moved/synchronised that data between the PCs. Also it is worth looking at the query plans to determine if it is using different strategies.

Can you provide more information?

|||

Thanks your time and interest in this problem.

The dataset is the same as PC1 and PC2 are connected to the same server and same database. PC1 and PC2 are only client running on two different machines using the same backend.

PC1 is the server where an application is running and that application is running SP called ProcedureXX.

After I noticed huge number of reads is SQL Profiler, I executed the same procedure (ProcedureXX) in Query Analyzer

on PC2 (my PC) and I got completly different results.

Basicaly, both PCs are using same procedure on the same server and on the same database.

It's very strange. It looks like that application on PC1 is doing something extra but still reads are recorded against SQL statement.

Thanks

|||

Below is the queryplan if it helps:

Execution Tree
--
Compute Scalar(DEFINESad[RSCData].[ICText]=[RSCData].[ICText]))
|--Sort(ORDER BYSad[Expr1018] ASC, [Expr1014] ASC, [RSCData].[ManuscriptID] ASC))
|--Compute Scalar(DEFINESad[Expr1016]=rtrim(replace(replace(replace([ArticleTable].[FAuthor]+', '+[ArticleTable].[AddAuthors], ltrim(substring([ArticleTable].[FAuthor]+' , '+[ArticleTable].[AddAuthors], len([ArticleTable].[FAuthor]+' , '+[ArticleTable].[AddAuthors])-charindex(',', reverse([ArticleTable].[FAuthor]+' , '+[ArticleTable].[AddAuthors]), 1)+1, 1500)), replace(replace(' and '+substring([ArticleTable].[FAuthor]+', '+[ArticleTable].[AddAuthors], len([ArticleTable].[FAuthor]+', '+[ArticleTable].[AddAuthors])-charindex(',', reverse([ArticleTable].[FAuthor]+', '+[ArticleTable].[AddAuthors]), 1)+3, 1500)+'ICT_RSC', ' and ICT_RSC', ''), 'ICT_RSC', '')), '. and ', '.,'), 'and ,', '')), [Expr1018]=replace(replace(substring([RSCData].[ManuscriptID], 9, 1), 'X', '91'), 'P', '92')))
|--Nested Loops(Left Outer Join, OUTER REFERENCESSad[RSCData].[PriceCode]))
|--Compute Scalar(DEFINESad[Expr1014]=Convert(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace([ArticleTable].[FPage], 'E', ''), 'J', ''), 'm', ''), '1-', ''), 'i', ''), 'K', ''), 'L', ''), '2-', ''), 'A', ''), 'F', ''), 'X', ''), 'G', ''), 'N', ''), 'R', ''), 'I', ''), 'V', ''), 'H', ''), 'P', ''), 'C', ''), 'D', ''), 'B', ''), 'Q', ''), '`', ''), 'S', ''), 'O', ''), '-', ''), 'T', ''), 'U', ''))))
| |--Bookmark Lookup(BOOKMARKSad[Bmk1004]), OBJECTSad[XlinkV2].[dbo].[Journal]))
| |--Nested Loops(Inner Join, OUTER REFERENCESSad[ArticleTable].[JournalID]))
| |--Hash Match(Inner Join, HASHSad[RSCData].[ArticleType])=([Expr1030]), RESIDUALSad[RSCData].[ArticleType]=[Expr1030]))
| | |--Nested Loops(Inner Join, OUTER REFERENCESSad[ArticleTable].[ArticleID]))
| | | |--Nested Loops(Inner Join, OUTER REFERENCESSad[RSCData].[ArticleID]))
| | | | |--Bookmark Lookup(BOOKMARKSad[Bmk1002]), OBJECTSad[XlinkV2].[dbo].[RSCData]))
| | | | | |--Nested Loops(Inner Join, OUTER REFERENCESSad[ArticleTable].[ArticleID]))
| | | | | |--Filter(WHERESad[ArticleTable].[PubYear]=Convert([@.SubYear]) AND like([ArticleTable].[Volume], Convert([@.Volume]), NULL)))
| | | | | | |--Bookmark Lookup(BOOKMARKSad[Bmk1000]), OBJECTSad[XlinkV2].[dbo].[ArticleTable]))
| | | | | | |--Index Seek(OBJECTSad[XlinkV2].[dbo].[ArticleTable].[art_indx_linkexistandissue]), SEEKSad[ArticleTable].[LinkExists]=1 AND [ArticleTable].[Issue]=Convert([@.Issue])) ORDERED FORWARD)
| | | | | |--Index Seek(OBJECTSad[XlinkV2].[dbo].[RSCData].[ind_TST_1]), SEEKSad[RSCData].[ArticleID]=[ArticleTable].[ArticleID] AND [RSCData].[SubYear]=Convert([@.SubYear])) ORDERED FORWARD)
| | | | |--Index Seek(OBJECTSad[XlinkV2].[dbo].[ArticleTable].[ArticleTable11]), SEEKSad[ArticleTable].[ArticleID]=[RSCData].[ArticleID]) ORDERED FORWARD)
| | | |--Index Seek(OBJECTSad[XlinkV2].[dbo].[RSCData].[MSt_RSCData_ArticleID]), SEEKSad[RSCData].[ArticleID]=[ArticleTable].[ArticleID]) ORDERED FORWARD)
| | |--Compute Scalar(DEFINESad[Expr1030]=Convert([Manuscript_Code].[Manuscript_Code])))
| | |--Clustered Index Scan(OBJECTSad[XlinkV2].[dbo].[Manuscript_Code].[ind_Manuscript_Code]))
| |--Index Seek(OBJECTSad[XlinkV2].[dbo].[Journal].[Journal_JournalID_SerCode_CommonTitle_CorrectAbbrevTitle_ContentsPageURL]), SEEKSad[Journal].[JournalID]=[ArticleTable].[JournalID] AND [Journal].[SerCode]=Convert([@.sercode])) ORDERED FORWARD)
|--Clustered Index Seek(OBJECTSad[XlinkV2].[dbo].[PriceCodeLookup].[ind_PriceCode]), SEEKSad[PriceCodeLookup].[PriceCode]=[RSCData].[PriceCode]) ORDERED FORWARD)

|||

hi Alex,

can I suggest that you check the set options for each query to ensure that the values are the same, if not then very likely there are 2 different plans for this query. determine what options are set for each connection and replicate the options setup for the setopts value that works. this can be found in the syscacheobjects table in the master database

thanks

|||Thanks for your help. It was problem with the execution plan. The SP was dynamic and was executed from the same connection without RECOMPILE option.

Number of Reads in Profiler

Hi,

Can any of can explain, what the "Reads" column in Profiler exactly mean ? I'm not comfortable with the explanation given in BOL.

"The number of read operations on the logical disk that are performed by the server on behalf of the event. These read operations include all reads from tables and buffers during the statement's execution"

For the same procedure with same parameters, if the server is not loaded much, the Reads are in a few hundreds, but when there are more than 1000 concurrent users, why it is going to millions ? What other parameters affecting this reads ? And how can I reduce it ?

Environment: SQL Server 2005 64-bit Enterprise Edition on Windows Server 2003 R2 Server x64 Enterprise Edition SP2

Thanks in Advance.

Regards

Babu

This is a good question.

The reads column in the profiler represents the number of logical reads for a statement or batch.

What is a logical read?

SQL Server uses much of its virtual memory as a buffer to cache and reduce physical I/O. So SQL Server caches the physical I/O and then requests pages from the cache. Everytime your statement requests a page (pages are stored as 8K blocks) from the cache a "logical" read occurs.

The best way to reduce the number of logical reads is to tune your query. If you are using a lot of subqueries, aggregrates on subqueries, etc... this can lead to high logical i/o. One thing you should take a look at is to make sure your statements are utilizing indexes. Try using an index hint to force your statement to use a specific index. This can make a big difference in terms of performance.

Mike
|||

From the below mentioned Link

The I/O from an instance of SQL Server is divided into logical and physical I/O. A logical read occurs every time the database engine requests a page from the buffer cache. If the page is not currently in the buffer cache, a physical read is then performed to read the page into the buffer cache. If the page is currently in the cache, no physical read is generated; the buffer cache simply uses the page already in memory. A logical write occurs when data is modified in a page in memory. A physical write occurs when the page is written to disk. It is possible for a page to remain in memory long enough to have more than one logical write made before it is physically written to disk.

check this ...

http://msdn2.microsoft.com/en-US/library/aa224763(SQL.80).aspx

Madhu

|||

Hi Mike/Madhu,

Thanks for your interest in this topic.

I'm still not clear, what's the "unit" for the number represented in this column.

1. Is it number of Pages ? If so, why the number of Reads increases when I request for same volume of data when the number of users connectd are more.

2. Is it number of attempts made to read a Page or Record ? Is the Locks influencing the Reads.

Database is having all feasible indexes and the procedures are tuned for the level best possible ( by me :-) ).

Thanks once again.

Regards

Babu

|||

logical reads Number of pages read from the data cache. physical reads Number of pages read from disk.

Refer SET SET STATISTICS IO documentation in BOL. ITs clearly documented there

Madhu