<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Query Debugging &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/query-debugging/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 16 Apr 2018 18:21:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>PostgreSQL: Use RAISE Statements to debug your Query and Function performance</title>
		<link>https://www.dbrnd.com/2018/04/postgresql-use-raise-statements-to-debug-your-query-and-function-performance/</link>
					<comments>https://www.dbrnd.com/2018/04/postgresql-use-raise-statements-to-debug-your-query-and-function-performance/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 14 Apr 2018 16:16:15 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[Query Debugging]]></category>
		<category><![CDATA[RAISE EXCEPTION]]></category>
		<category><![CDATA[RAISE INFO]]></category>
		<category><![CDATA[RAISE NOTICE]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4253</guid>

					<description><![CDATA[You can use the RAISE Statements for the report messages and raise errors. Different level of RAISE statements are INFO, NOTICE, and EXCEPTION. By default, NOTICE is always returning to the client only. We should use RAISE INFO for our internal query or function debugging. We should break down our code into smaller parts and [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&#038;title=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" data-a2a-url="https://www.dbrnd.com/2018/04/postgresql-use-raise-statements-to-debug-your-query-and-function-performance/" data-a2a-title="PostgreSQL: Use RAISE Statements to debug your Query and Function performance"></a></p><p>You can use the RAISE Statements for the report messages and raise errors.<br />
Different level of RAISE statements are INFO, NOTICE, and EXCEPTION.</p>
<p>By default, NOTICE is always returning to the client only. We should use RAISE INFO for our internal query or function debugging. </p>
<p>We should break down our code into smaller parts and add RAISE statement with clock_timestamp(). </p>
<p>We can compare the execution time difference between the code blocks and can find a slow running code block.<br />
We can also add parameter and variable to the RAISE statement. We can print the current value of our parameter and variable.</p>
<p><strong>Few examples: </strong></p>
<pre class="crayon-plain-tag">RAISE INFO 'Hello World !';
RAISE NOTICE '%', variable_name;
RAISE NOTICE 'Current value of parameter (%)', my_var;
RAISE EXCEPTION '% cannot have null salary', EmpName;</pre> </p>
<p><strong>One Practical Demonstration:</strong></p>
<p><strong>Create a table with Sample Data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE Employee
(
	 EmpID SERIAL
	 ,EmpName CHARACTER VARYING(50)
	 ,Gender CHAR(1)
	 ,AGE SMALLINT
);
INSERT INTO Employee 
(
	 EmpName 
	 ,Gender 
	 ,AGE 
)
VALUES 
 ('Anvesh','M',27)
 ,('Mohan','M',30)
 ,('Roy','M',31)
 ,('Meera','F',27)
 ,('Richa','F',26)
 ,('Martin','M',35)
 ,('Mahesh','M',38)
 ,('Paresh','M',22)
 ,('Alina','F',21)
 ,('Alex','M',24);</pre> </p>
<p><strong>Sample function for Custome Paging with the use of RAISE:</strong></p>
<pre class="crayon-plain-tag">CREATE OR REPLACE FUNCTION fn_GetEmployeeData
(
	Paging_PageSize INTEGER = NULL
	,Paging_PageNumber INTEGER = NULL   
)
RETURNS TABLE 
( 
	outEmpID INTEGER
	,outEmpName CHARACTER VARYING
	,outGender CHAR(1)
	,outAge SMALLINT
) AS
$BODY$
DECLARE PageNumber BIGINT;
DECLARE TempINT INTEGER;
 
BEGIN
	/* ***************************************************************
	Construct Custom paging parameter...
	**************************************************************** */
	IF (paging_pagesize IS NOT NULL AND paging_pagenumber IS NOT NULL) THEN
		PageNumber := (Paging_PageSize * (Paging_PageNumber-1)); 
	END IF; 

	RAISE INFO '%','Construction of Custom Paging Parameter -  DONE '|| clock_timestamp();
	/* ************************************************
	Custome paging SQL Query construction.......
	************************************************ */
	TempINT := 10000;
	WHILE (TempINT &gt; 0)	
	LOOP		
		TempINT = TempINT - 1;
		RAISE INFO '%','The current value of TempINT ' || TempINT; 
	END LOOP;
	
	RETURN QUERY
	SELECT
		EmpID
		,EmpName
		,Gender
		,Age
	FROM public.Employee
	ORDER BY EmpID
	LIMIT Paging_PageSize
	OFFSET PageNumber; 

	RAISE INFO '%','Final result set of main query -  DONE ' || clock_timestamp(); 
	 
	EXCEPTION WHEN OTHERS THEN 
	RAISE;
END;
$BODY$
LANGUAGE 'plpgsql';</pre> </p>
<p><strong>Execute this function and check the query message window:</strona g><br />
You will find list of RAISE INFO messages that we mentioned in above function.</p>
<pre class="crayon-plain-tag">SELECT *FROM public.fn_GetEmployeeData(4,2);</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/04/postgresql-use-raise-statements-to-debug-your-query-and-function-performance/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server 2016: Introduced Live Query Statistics, Monitor Live Query Execution</title>
		<link>https://www.dbrnd.com/2018/01/sql-server-2016-introduced-live-query-statistics-monitor-live-query-execution-debug-sql-query/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 13 Jan 2018 16:16:44 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Actual Execution Plan]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Estimated Execution Plan]]></category>
		<category><![CDATA[Live Query Statistics]]></category>
		<category><![CDATA[Query Debugging]]></category>
		<category><![CDATA[Query Execution]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4226</guid>

					<description><![CDATA[SQL Server 2016 came with a lot of great features which will help us in our day to day activities. It introduced a fantastic feature to monitor live query execution using Live Query Statistics option. We knew about the Actual Execution Plan and Estimated Execution Plan, which gives us the full execution plan of the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-live-query-statistics-monitor-live-query-execution-debug-sql-query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Live%20Query%20Statistics%2C%20Monitor%20Live%20Query%20Execution" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-live-query-statistics-monitor-live-query-execution-debug-sql-query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Live%20Query%20Statistics%2C%20Monitor%20Live%20Query%20Execution" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-live-query-statistics-monitor-live-query-execution-debug-sql-query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Live%20Query%20Statistics%2C%20Monitor%20Live%20Query%20Execution" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-live-query-statistics-monitor-live-query-execution-debug-sql-query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Live%20Query%20Statistics%2C%20Monitor%20Live%20Query%20Execution" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-live-query-statistics-monitor-live-query-execution-debug-sql-query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Live%20Query%20Statistics%2C%20Monitor%20Live%20Query%20Execution" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-live-query-statistics-monitor-live-query-execution-debug-sql-query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Live%20Query%20Statistics%2C%20Monitor%20Live%20Query%20Execution" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-live-query-statistics-monitor-live-query-execution-debug-sql-query%2F&#038;title=SQL%20Server%202016%3A%20Introduced%20Live%20Query%20Statistics%2C%20Monitor%20Live%20Query%20Execution" data-a2a-url="https://www.dbrnd.com/2018/01/sql-server-2016-introduced-live-query-statistics-monitor-live-query-execution-debug-sql-query/" data-a2a-title="SQL Server 2016: Introduced Live Query Statistics, Monitor Live Query Execution"></a></p><p>SQL Server 2016 came with a lot of great features which will help us in our day to day activities.<br />
It introduced a fantastic feature to monitor live query execution using Live Query Statistics option.</p>
<blockquote><p>We knew about the Actual Execution Plan and Estimated Execution Plan, which gives us the full execution plan of the query.<br />
Now, we have one more option in this category, which is Live Query Statistics.</p></blockquote>
<p>As per the MSDN,</p>
<blockquote><p>SQL Server Management Studio provides the ability to view the live execution plan of an active query.<br />
This live query plan provides real-time insights into the query execution process as the controls flow from one query plan operator to another.</p></blockquote>
<blockquote><p>We can get overall query progress in real time without needing to wait for the query to complete.<br />
When we are debugging the overall query execution, it helps a lot to debug every block of the query.
</p></blockquote>
<p><strong>How to enable Live Query Statistics option for the SQL Query?</strong></p>
<p><strong>Using SSMS:</strong></p>
<blockquote><p>In the SQL Editor toolbar, you can find one new button called &#8220;Include Live Query Statistics&#8221; which is immediately next to &#8220;Include Actual Execution Plan&#8221; button.
</p></blockquote>
<p><strong>Right click on SQL Query:</strong></p>
<blockquote><p>Select your query and right click on it. You can select an option like: &#8220;Include Live Query Statistics&#8221; for that particular query execution. </p></blockquote>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
