<?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>Execution Plan &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/execution-plan/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>Fri, 22 Sep 2017 20:45:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Server: Not Good &#8211; Cost Threshold for Parallelism Default is Five</title>
		<link>https://www.dbrnd.com/2017/11/sql-server-not-good-cost-threshold-for-parallelism-default-is-five/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 29 Nov 2017 16:16:32 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Execution Plan]]></category>
		<category><![CDATA[MAXDOP]]></category>
		<category><![CDATA[parallelism]]></category>
		<category><![CDATA[Query Optimizer]]></category>
		<category><![CDATA[sp_configure]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[threshold]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6150</guid>

					<description><![CDATA[<div><img width="640" height="426" src="https://www.dbrnd.com/wp-content/uploads/2017/09/ParallelProcessing2.jpg" class="attachment-post-image size-post-image wp-post-image" alt="ParallelProcessing2" decoding="async" fetchpriority="high" /></div>As per the Microsoft, Use the cost threshold for parallelism option to specify the threshold at which Microsoft SQL Server creates and runs parallel plans for queries. The Cost Threshold for Parallelism parameter is very important for Query Optimizer to prepare the query execution plan. I wrote a title like Not Good &#8211; Because the [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="640" height="426" src="https://www.dbrnd.com/wp-content/uploads/2017/09/ParallelProcessing2.jpg" class="attachment-post-image size-post-image wp-post-image" alt="ParallelProcessing2" decoding="async" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-server-not-good-cost-threshold-for-parallelism-default-is-five%2F&amp;linkname=SQL%20Server%3A%20Not%20Good%20%E2%80%93%20Cost%20Threshold%20for%20Parallelism%20Default%20is%20Five" 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%2F2017%2F11%2Fsql-server-not-good-cost-threshold-for-parallelism-default-is-five%2F&amp;linkname=SQL%20Server%3A%20Not%20Good%20%E2%80%93%20Cost%20Threshold%20for%20Parallelism%20Default%20is%20Five" 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%2F2017%2F11%2Fsql-server-not-good-cost-threshold-for-parallelism-default-is-five%2F&amp;linkname=SQL%20Server%3A%20Not%20Good%20%E2%80%93%20Cost%20Threshold%20for%20Parallelism%20Default%20is%20Five" 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%2F2017%2F11%2Fsql-server-not-good-cost-threshold-for-parallelism-default-is-five%2F&amp;linkname=SQL%20Server%3A%20Not%20Good%20%E2%80%93%20Cost%20Threshold%20for%20Parallelism%20Default%20is%20Five" 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%2F2017%2F11%2Fsql-server-not-good-cost-threshold-for-parallelism-default-is-five%2F&amp;linkname=SQL%20Server%3A%20Not%20Good%20%E2%80%93%20Cost%20Threshold%20for%20Parallelism%20Default%20is%20Five" 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%2F2017%2F11%2Fsql-server-not-good-cost-threshold-for-parallelism-default-is-five%2F&amp;linkname=SQL%20Server%3A%20Not%20Good%20%E2%80%93%20Cost%20Threshold%20for%20Parallelism%20Default%20is%20Five" 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%2F2017%2F11%2Fsql-server-not-good-cost-threshold-for-parallelism-default-is-five%2F&#038;title=SQL%20Server%3A%20Not%20Good%20%E2%80%93%20Cost%20Threshold%20for%20Parallelism%20Default%20is%20Five" data-a2a-url="https://www.dbrnd.com/2017/11/sql-server-not-good-cost-threshold-for-parallelism-default-is-five/" data-a2a-title="SQL Server: Not Good – Cost Threshold for Parallelism Default is Five"></a></p><p>As per the Microsoft, Use the cost threshold for parallelism option to specify the threshold at which Microsoft SQL Server creates and runs parallel plans for queries.</p>
<p>The Cost Threshold for Parallelism parameter is very important for Query Optimizer to prepare the query execution plan.</p>
<blockquote><p>I wrote a title like Not Good &#8211; Because the default value of Cost Threshold for Parallelism is 5 which is very less now a day.</p>
<p>The value you define here which is for query optimizer where it finds a cheaper parallel execution plan, and if it fails to find parallel execution plan in given cost, it chooses the serial execution plan which degrades the query performance.</p>
<p>Now a day, we are dealing with millions/billions of data, so parallel query execution plan is good for big/complex queries so the default value 5 which is a tiny number.</p></blockquote>
<p>The parallel execution plans will give you more suggestion on missing indexes which we can take for further query optimization.</p>
<p><em>I would suggest to change the value of Cost Threshold for Parallelism from 5 to 50 or even more.</em></p>
<p><strong>How to change?</strong></p>
<p><strong>Using Script:</strong></p><pre class="crayon-plain-tag">sp_configure 'show advanced options', 1;
GO
reconfigure;
GO
sp_configure 'cost threshold for parallelism', 50;
GO
reconfigure;
GO</pre><p>
<strong>Using SSMS:</strong></p>
<p><img decoding="async" class="alignnone size-full wp-image-6152" src="https://www.dbrnd.com/wp-content/uploads/2017/09/CostThresholdForParallelism.png" alt="Cost Threshold For Parallelism" width="694" height="630" srcset="https://www.dbrnd.com/wp-content/uploads/2017/09/CostThresholdForParallelism.png 694w, https://www.dbrnd.com/wp-content/uploads/2017/09/CostThresholdForParallelism-679x616.png 679w" sizes="(max-width: 694px) 100vw, 694px" /></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Increase Query Performance using a Forced Parameterization</title>
		<link>https://www.dbrnd.com/2016/12/sql-server-increase-query-performance-using-a-forced-parameterization-simple-parameterization/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 27 Dec 2016 17:39:30 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Execution Plan]]></category>
		<category><![CDATA[Forced Parameterization]]></category>
		<category><![CDATA[OUT Parameters]]></category>
		<category><![CDATA[Parameter]]></category>
		<category><![CDATA[parse query plan]]></category>
		<category><![CDATA[query performance]]></category>
		<category><![CDATA[simple parameterization]]></category>
		<category><![CDATA[SQL Query]]></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=4146</guid>

					<description><![CDATA[Since SQL Server 2005, we have a concept of Forced Parameterization of SQL Query. It looks like a very old concept, but the use of Forced Parameterization improves the performance of Query Optimizer which responsible for the best execution plan. SQL Server provides two types of query parameterization, one is Simple Parameterization and second is [&#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%2F2016%2F12%2Fsql-server-increase-query-performance-using-a-forced-parameterization-simple-parameterization%2F&amp;linkname=SQL%20Server%3A%20Increase%20Query%20Performance%20using%20a%20Forced%20Parameterization" 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%2F2016%2F12%2Fsql-server-increase-query-performance-using-a-forced-parameterization-simple-parameterization%2F&amp;linkname=SQL%20Server%3A%20Increase%20Query%20Performance%20using%20a%20Forced%20Parameterization" 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%2F2016%2F12%2Fsql-server-increase-query-performance-using-a-forced-parameterization-simple-parameterization%2F&amp;linkname=SQL%20Server%3A%20Increase%20Query%20Performance%20using%20a%20Forced%20Parameterization" 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%2F2016%2F12%2Fsql-server-increase-query-performance-using-a-forced-parameterization-simple-parameterization%2F&amp;linkname=SQL%20Server%3A%20Increase%20Query%20Performance%20using%20a%20Forced%20Parameterization" 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%2F2016%2F12%2Fsql-server-increase-query-performance-using-a-forced-parameterization-simple-parameterization%2F&amp;linkname=SQL%20Server%3A%20Increase%20Query%20Performance%20using%20a%20Forced%20Parameterization" 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%2F2016%2F12%2Fsql-server-increase-query-performance-using-a-forced-parameterization-simple-parameterization%2F&amp;linkname=SQL%20Server%3A%20Increase%20Query%20Performance%20using%20a%20Forced%20Parameterization" 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%2F2016%2F12%2Fsql-server-increase-query-performance-using-a-forced-parameterization-simple-parameterization%2F&#038;title=SQL%20Server%3A%20Increase%20Query%20Performance%20using%20a%20Forced%20Parameterization" data-a2a-url="https://www.dbrnd.com/2016/12/sql-server-increase-query-performance-using-a-forced-parameterization-simple-parameterization/" data-a2a-title="SQL Server: Increase Query Performance using a Forced Parameterization"></a></p><p>Since SQL Server 2005, we have a concept of Forced Parameterization of SQL Query.</p>
<blockquote><p>It looks like a very old concept, but the use of Forced Parameterization improves the performance of Query Optimizer which responsible for the best execution plan.</p></blockquote>
<blockquote><p>SQL Server provides two types of query parameterization, one is Simple Parameterization and second is Forced Parameterization.</p></blockquote>
<p><strong>Why it is important and How it works?</strong></p>
<blockquote><p>When you are executing any query, SQL Server Query Optimizer analyzes your query and prepares the best execution plan for it.</p></blockquote>
<blockquote><p>If you are executing the same query again, previously generated execution plan may use for the same query. We can also say that It caches your query execution plan.</p>
<p>It is doing this using a Simple Parameterization which is default in SQL Server.</p></blockquote>
<blockquote><p>Let me add one more thing,<br />
Your frequent SQL Query uses the cache query plan, but what If you change the value in WHERE clause.</p>
<p>If you are changing just column filter value in WHERE clause, It uses the cache query plan and If you are modifying your parameter list, It requires to generate a new query plan.</p>
<p>This is about the Simple Parameterization.</p></blockquote>
<p><strong>You can see in the below image:</strong></p>
<blockquote><p>I have executed two different queries with passing different values for TrackingEventID.</p></blockquote>
<blockquote><p>But You can see TrackingEventID = @1 in query execution plan, means It uses same query plan for both the query which increase your query performance.</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-4152 size-full" title="sql server simple parameterization" src="https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerSimpleParameterization.png" alt="sql server simple parameterization" width="558" height="341" srcset="https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerSimpleParameterization.png 558w, https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerSimpleParameterization-300x183.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerSimpleParameterization-150x92.png 150w" sizes="auto, (max-width: 558px) 100vw, 558px" /></p></blockquote>
<p><strong>Now check below image:</strong></p>
<blockquote><p>I have used ISNULL() in query and It skipped to put parameter in the query of execution plan.<br />
You can see static date value instead of parameter values.</p></blockquote>
<blockquote><p>If you are executing this kind of queries frequently, It prepares and generates an execution plan every time which decreases the query performance.</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-4153 size-full" title="sql server simple parameterization without parameter" src="https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerSimpleParameterization2.png" alt="sql server simple parameterization without parameter" width="756" height="236" srcset="https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerSimpleParameterization2.png 756w, https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerSimpleParameterization2-300x94.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerSimpleParameterization2-750x234.png 750w, https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerSimpleParameterization2-150x47.png 150w" sizes="auto, (max-width: 756px) 100vw, 756px" /></p>
</blockquote>
<p><strong>Now, enable the Force Parameterization and check the same query.<br />
</strong></p>
<blockquote><p>You can check below image where you can see parameter values instead of static date value.</p></blockquote>
<blockquote><p>Once you enable Force Parameterization, It forcefully adds the parameter in the query of execution plan.</p>
<p>Which improves the query performance by reducing the cost of preparing and compiling an execution plan again and again.</p></blockquote>
<blockquote><p>But we should also take care about this because It might generate SQL Parameter Sniffing Issue so we should keep database statistics up to date.</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-4150 size-full" title="sql server force parameterization" src="https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerForceParameterization.png" alt="sql server force parameterization" width="641" height="322" srcset="https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerForceParameterization.png 641w, https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerForceParameterization-300x151.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/12/SQLServerForceParameterization-150x75.png 150w" sizes="auto, (max-width: 641px) 100vw, 641px" /></p></blockquote>
<p><strong>Script to change the database in Forced Parameterization:<br />
</strong></p>
<pre class="crayon-plain-tag">ALTER DATABASE Database_Name
SET PARAMETERIZATION FORCED
GO</pre> </p>
<p><strong>Script to change the database in Simple Parameterization:<br />
</strong></p>
<pre class="crayon-plain-tag">ALTER DATABASE Database_Name
SET PARAMETERIZATION Simple
GO</pre> </p>
<p><strong>Other related articles:</strong></p>
<blockquote class="wp-embedded-content" data-secret="tkyOSwf91D"><p><a href="https://www.dbrnd.com/2016/12/sql-server-the-importance-of-statistics-and-why-it-is-important/">SQL Server: The Importance of Statistics and Why It is important</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/12/sql-server-the-importance-of-statistics-and-why-it-is-important/embed/#?secret=tkyOSwf91D" data-secret="tkyOSwf91D" width="600" height="338" title="&#8220;SQL Server: The Importance of Statistics and Why It is important&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="y1mqbDz6n7"><p><a href="https://www.dbrnd.com/2015/05/sql-server-parameter-sniffing/">SQL Server Parameter Sniffing</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/05/sql-server-parameter-sniffing/embed/#?secret=y1mqbDz6n7" data-secret="y1mqbDz6n7" width="600" height="338" title="&#8220;SQL Server Parameter Sniffing&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Force on Planner to use Sequential Scan or Index Scan</title>
		<link>https://www.dbrnd.com/2016/11/postgresql-force-on-planner-to-use-sequential-scan-or-index-scan-enable_seqscan-enable_indexscan/</link>
					<comments>https://www.dbrnd.com/2016/11/postgresql-force-on-planner-to-use-sequential-scan-or-index-scan-enable_seqscan-enable_indexscan/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 22 Nov 2016 19:00:50 +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[enable_indexscan]]></category>
		<category><![CDATA[enable_seqscan]]></category>
		<category><![CDATA[Execution Plan]]></category>
		<category><![CDATA[Force index scan]]></category>
		<category><![CDATA[Index Hint]]></category>
		<category><![CDATA[Index Seek]]></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 Planner]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3898</guid>

					<description><![CDATA[Every day If you are doing performance optimization related stuff, sometime you also confuse on the decision of the Query Planner because It might be choose a wrong plan. The SQL Server and MySQL provide features like: Index force or Index hint for SQL query, but PostgreSQL does not provide such feature because Once you [&#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%2F2016%2F11%2Fpostgresql-force-on-planner-to-use-sequential-scan-or-index-scan-enable_seqscan-enable_indexscan%2F&amp;linkname=PostgreSQL%3A%20Force%20on%20Planner%20to%20use%20Sequential%20Scan%20or%20Index%20Scan" 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%2F2016%2F11%2Fpostgresql-force-on-planner-to-use-sequential-scan-or-index-scan-enable_seqscan-enable_indexscan%2F&amp;linkname=PostgreSQL%3A%20Force%20on%20Planner%20to%20use%20Sequential%20Scan%20or%20Index%20Scan" 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%2F2016%2F11%2Fpostgresql-force-on-planner-to-use-sequential-scan-or-index-scan-enable_seqscan-enable_indexscan%2F&amp;linkname=PostgreSQL%3A%20Force%20on%20Planner%20to%20use%20Sequential%20Scan%20or%20Index%20Scan" 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%2F2016%2F11%2Fpostgresql-force-on-planner-to-use-sequential-scan-or-index-scan-enable_seqscan-enable_indexscan%2F&amp;linkname=PostgreSQL%3A%20Force%20on%20Planner%20to%20use%20Sequential%20Scan%20or%20Index%20Scan" 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%2F2016%2F11%2Fpostgresql-force-on-planner-to-use-sequential-scan-or-index-scan-enable_seqscan-enable_indexscan%2F&amp;linkname=PostgreSQL%3A%20Force%20on%20Planner%20to%20use%20Sequential%20Scan%20or%20Index%20Scan" 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%2F2016%2F11%2Fpostgresql-force-on-planner-to-use-sequential-scan-or-index-scan-enable_seqscan-enable_indexscan%2F&amp;linkname=PostgreSQL%3A%20Force%20on%20Planner%20to%20use%20Sequential%20Scan%20or%20Index%20Scan" 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%2F2016%2F11%2Fpostgresql-force-on-planner-to-use-sequential-scan-or-index-scan-enable_seqscan-enable_indexscan%2F&#038;title=PostgreSQL%3A%20Force%20on%20Planner%20to%20use%20Sequential%20Scan%20or%20Index%20Scan" data-a2a-url="https://www.dbrnd.com/2016/11/postgresql-force-on-planner-to-use-sequential-scan-or-index-scan-enable_seqscan-enable_indexscan/" data-a2a-title="PostgreSQL: Force on Planner to use Sequential Scan or Index Scan"></a></p><p>Every day If you are doing performance optimization related stuff, sometime you also confuse on the decision of the Query Planner because It might be choose a wrong plan. </p>
<blockquote><p>The SQL Server and MySQL provide features like: Index force or Index hint for SQL query, but PostgreSQL does not provide such feature because Once you set Index hint on the query, in future data is increasing and your Index hint might be not working accordingly. </p></blockquote>
<blockquote class="wp-embedded-content" data-secret="H7FLBLiKCa"><p><a href="https://www.dbrnd.com/2016/04/database-theory-table-scan-vs-index-scan-vs-index-seek/">Database Theory: Table Scan vs Index Scan vs Index Seek</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/database-theory-table-scan-vs-index-scan-vs-index-seek/embed/#?secret=H7FLBLiKCa" data-secret="H7FLBLiKCa" width="600" height="338" title="&#8220;Database Theory: Table Scan vs Index Scan vs Index Seek&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote><p>In the PostgreSQL, Query Planner takes the decision base on the updated statistics and choose the Table Scan or Index Scan. </p></blockquote>
<blockquote><p>For smaller table, sequential scan is always faster compare to Index scanning. But sometimes what I have found is: due to invalid parameter PostgreSQL skips the indexes and start the table scanning which leads to poor performance. </p>
<p>In this situation, we should disable the Sequential Scan option so that Query Planner force to use available Indexes and execute the Query. </p></blockquote>
<blockquote><p>In PostgreSQL, We cannot enable / disable Index Scan or Table Scan at individual query level. </p></blockquote>
<p><strong>PostgreSQL provides two main parameters for Index Scan or Table Scan:</strong><br />
By default, this both parameters are ON, but as per the your requirement you can change the value.<br />
You can find these parameters in postgresql.conf file. </p>
<blockquote><p>enable_seqscan<br />
enable_indexscan</p></blockquote>
<p><em><strong>You should never make the force on Query Planner because Forcing is a very bad idea. It might be useful to check if it will be faster, but production code should never use such tricks.</strong></em></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/11/postgresql-force-on-planner-to-use-sequential-scan-or-index-scan-enable_seqscan-enable_indexscan/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server:Warning in Query Execution Plan, &#8220;Operator used tempdb to spill data during execution with spill level 2&#8221;</title>
		<link>https://www.dbrnd.com/2016/11/sql-serverwarning-in-query-execution-plan-operator-used-tempdb-to-spill-data-during-execution-with-spill-level-2-sql-update-statistics-sp_updatestats/</link>
					<comments>https://www.dbrnd.com/2016/11/sql-serverwarning-in-query-execution-plan-operator-used-tempdb-to-spill-data-during-execution-with-spill-level-2-sql-update-statistics-sp_updatestats/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 18 Nov 2016 18:07:18 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[AUTO_CREATE_STATISTICS]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Execution Plan]]></category>
		<category><![CDATA[Query Optimizer]]></category>
		<category><![CDATA[SQL Query]]></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[TempDB]]></category>
		<category><![CDATA[TempDB Spill error]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3869</guid>

					<description><![CDATA[Before a few days ago, When I was performing query optimization at that time I have seen one warning in the result of SQL Server Query Execution Plan like: &#8220;Operator used tempdb to spill data during execution with spill level 2&#8221;. I performed RND on this and came to know very interesting reason this warning. [&#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%2F2016%2F11%2Fsql-serverwarning-in-query-execution-plan-operator-used-tempdb-to-spill-data-during-execution-with-spill-level-2-sql-update-statistics-sp_updatestats%2F&amp;linkname=SQL%20Server%3AWarning%20in%20Query%20Execution%20Plan%2C%20%E2%80%9COperator%20used%20tempdb%20to%20spill%20data%20during%20execution%20with%20spill%20level%202%E2%80%9D" 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%2F2016%2F11%2Fsql-serverwarning-in-query-execution-plan-operator-used-tempdb-to-spill-data-during-execution-with-spill-level-2-sql-update-statistics-sp_updatestats%2F&amp;linkname=SQL%20Server%3AWarning%20in%20Query%20Execution%20Plan%2C%20%E2%80%9COperator%20used%20tempdb%20to%20spill%20data%20during%20execution%20with%20spill%20level%202%E2%80%9D" 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%2F2016%2F11%2Fsql-serverwarning-in-query-execution-plan-operator-used-tempdb-to-spill-data-during-execution-with-spill-level-2-sql-update-statistics-sp_updatestats%2F&amp;linkname=SQL%20Server%3AWarning%20in%20Query%20Execution%20Plan%2C%20%E2%80%9COperator%20used%20tempdb%20to%20spill%20data%20during%20execution%20with%20spill%20level%202%E2%80%9D" 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%2F2016%2F11%2Fsql-serverwarning-in-query-execution-plan-operator-used-tempdb-to-spill-data-during-execution-with-spill-level-2-sql-update-statistics-sp_updatestats%2F&amp;linkname=SQL%20Server%3AWarning%20in%20Query%20Execution%20Plan%2C%20%E2%80%9COperator%20used%20tempdb%20to%20spill%20data%20during%20execution%20with%20spill%20level%202%E2%80%9D" 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%2F2016%2F11%2Fsql-serverwarning-in-query-execution-plan-operator-used-tempdb-to-spill-data-during-execution-with-spill-level-2-sql-update-statistics-sp_updatestats%2F&amp;linkname=SQL%20Server%3AWarning%20in%20Query%20Execution%20Plan%2C%20%E2%80%9COperator%20used%20tempdb%20to%20spill%20data%20during%20execution%20with%20spill%20level%202%E2%80%9D" 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%2F2016%2F11%2Fsql-serverwarning-in-query-execution-plan-operator-used-tempdb-to-spill-data-during-execution-with-spill-level-2-sql-update-statistics-sp_updatestats%2F&amp;linkname=SQL%20Server%3AWarning%20in%20Query%20Execution%20Plan%2C%20%E2%80%9COperator%20used%20tempdb%20to%20spill%20data%20during%20execution%20with%20spill%20level%202%E2%80%9D" 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%2F2016%2F11%2Fsql-serverwarning-in-query-execution-plan-operator-used-tempdb-to-spill-data-during-execution-with-spill-level-2-sql-update-statistics-sp_updatestats%2F&#038;title=SQL%20Server%3AWarning%20in%20Query%20Execution%20Plan%2C%20%E2%80%9COperator%20used%20tempdb%20to%20spill%20data%20during%20execution%20with%20spill%20level%202%E2%80%9D" data-a2a-url="https://www.dbrnd.com/2016/11/sql-serverwarning-in-query-execution-plan-operator-used-tempdb-to-spill-data-during-execution-with-spill-level-2-sql-update-statistics-sp_updatestats/" data-a2a-title="SQL Server:Warning in Query Execution Plan, “Operator used tempdb to spill data during execution with spill level 2”"></a></p><p>Before a few days ago, When I was performing query optimization at that time I have seen one warning in the result of SQL Server Query Execution Plan like:<strong> &#8220;Operator used tempdb to spill data during execution with spill level 2&#8221;.</strong><br />
I performed RND on this and came to know very interesting reason this warning. </p>
<blockquote><p>If you don&#8217;t know, please note that Database Statistics are playing main to prepare and generate the Query Execution Plan. </p></blockquote>
<blockquote><p>SQL Server Statistics contain different types of meta data information like total number records, indexes, access path and others. </p></blockquote>
<blockquote><p>This warning occurred because my database Statistics are not updated.<br />
For example, my table has total 50000 records and Statistics contains only 5000 records information so the planner prepares the query execution plan according to 5000 records only. </p></blockquote>
<blockquote><p>While executing the query, If it finds more than 5000 records, It transfers other additional records first into TempDB and continue further process using TempDB. Because It calculated processing capacity only for 5000 records. </p></blockquote>
<blockquote><p>This process degrades the overall query performance and that&#8217;s why you can see a warning like: &#8220;Operator used tempdb to spill data during execution with spill level 2&#8221;.</p></blockquote>
<p><strong>The solution is:</strong></p>
<blockquote><p>Find Statistics data for tables and indexes and If Statistics data are not updated, update your Statistics data, so that Query Optimizer can prepare the best Query Execution Plan.
</p></blockquote>
<p><strong>Check the Statistics for particular index: </strong><br />
If you find difference between Rows and Rows Sampled, Statistics is not updated. </p>
<pre class="crayon-plain-tag">DBCC SHOW_STATISTICS ("TableName", IndexName);</pre> </p>
<p><strong>Update all Statistics for Database: </strong></p>
<pre class="crayon-plain-tag">EXEC sp_updatestats;</pre> </p>
<p><strong>Update Statistics for Table:</strong></p>
<pre class="crayon-plain-tag">UPDATE STATISTICS TABLE_NAME;</pre> </p>
<p><strong>Update Statistics for Index:</strong></p>
<pre class="crayon-plain-tag">UPDATE STATISTICS TABLE_NAME INDEX_NAME;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/11/sql-serverwarning-in-query-execution-plan-operator-used-tempdb-to-spill-data-during-execution-with-spill-level-2-sql-update-statistics-sp_updatestats/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>MySQL: Controlling Query Optimizer to choose the Best Execution Plan</title>
		<link>https://www.dbrnd.com/2016/10/mysql-controlling-query-optimizer-to-choose-the-best-execution-plan-optimizer_prune_level-optimizer_search_depth/</link>
					<comments>https://www.dbrnd.com/2016/10/mysql-controlling-query-optimizer-to-choose-the-best-execution-plan-optimizer_prune_level-optimizer_search_depth/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 20 Oct 2016 16:16:18 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Execution Plan]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<category><![CDATA[optimizer_prune_level]]></category>
		<category><![CDATA[optimizer_search_depth]]></category>
		<category><![CDATA[Query Optimizer]]></category>
		<category><![CDATA[Query Planner]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3785</guid>

					<description><![CDATA[In this post, I am sharing two important parameters which might be useful to improve query execution process in MySQL Server. The Query Optimizer is playing the main role in the Query Execution Process. It is responsible to choose best Query Execution Plan among the list of Plans. In MySQL, we can control the task [&#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%2F2016%2F10%2Fmysql-controlling-query-optimizer-to-choose-the-best-execution-plan-optimizer_prune_level-optimizer_search_depth%2F&amp;linkname=MySQL%3A%20Controlling%20Query%20Optimizer%20to%20choose%20the%20Best%20Execution%20Plan" 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%2F2016%2F10%2Fmysql-controlling-query-optimizer-to-choose-the-best-execution-plan-optimizer_prune_level-optimizer_search_depth%2F&amp;linkname=MySQL%3A%20Controlling%20Query%20Optimizer%20to%20choose%20the%20Best%20Execution%20Plan" 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%2F2016%2F10%2Fmysql-controlling-query-optimizer-to-choose-the-best-execution-plan-optimizer_prune_level-optimizer_search_depth%2F&amp;linkname=MySQL%3A%20Controlling%20Query%20Optimizer%20to%20choose%20the%20Best%20Execution%20Plan" 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%2F2016%2F10%2Fmysql-controlling-query-optimizer-to-choose-the-best-execution-plan-optimizer_prune_level-optimizer_search_depth%2F&amp;linkname=MySQL%3A%20Controlling%20Query%20Optimizer%20to%20choose%20the%20Best%20Execution%20Plan" 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%2F2016%2F10%2Fmysql-controlling-query-optimizer-to-choose-the-best-execution-plan-optimizer_prune_level-optimizer_search_depth%2F&amp;linkname=MySQL%3A%20Controlling%20Query%20Optimizer%20to%20choose%20the%20Best%20Execution%20Plan" 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%2F2016%2F10%2Fmysql-controlling-query-optimizer-to-choose-the-best-execution-plan-optimizer_prune_level-optimizer_search_depth%2F&amp;linkname=MySQL%3A%20Controlling%20Query%20Optimizer%20to%20choose%20the%20Best%20Execution%20Plan" 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%2F2016%2F10%2Fmysql-controlling-query-optimizer-to-choose-the-best-execution-plan-optimizer_prune_level-optimizer_search_depth%2F&#038;title=MySQL%3A%20Controlling%20Query%20Optimizer%20to%20choose%20the%20Best%20Execution%20Plan" data-a2a-url="https://www.dbrnd.com/2016/10/mysql-controlling-query-optimizer-to-choose-the-best-execution-plan-optimizer_prune_level-optimizer_search_depth/" data-a2a-title="MySQL: Controlling Query Optimizer to choose the Best Execution Plan"></a></p><p>In this post, I am sharing two important parameters which might be useful to improve query execution process in MySQL Server.</p>
<blockquote><p>The Query Optimizer is playing the main role in the Query Execution Process. It is responsible to choose best Query Execution Plan among the list of Plans.<br />
In MySQL, we can control the task of Query Optimizer by setting few parameters.
</p></blockquote>
<p><strong>Why because?</strong></p>
<blockquote><p>If you have one big SQL Query (included around 40 tables), Planner generates all possible plans mostly It generates 40+ query execution plan so now Query Optimizer will take more time to SELECT best plan. </p></blockquote>
<blockquote><p>We should tune this situation by knowing about optimizer_prune_level and optimizer_search_depth parameters. </p></blockquote>
<p><strong>optimizer_prune_level:</strong> Default is ON, It tells Query Optimizer to skip certain plans based on estimated number of rows. </p>
<blockquote><p>If we have total 40 tables, Planner generates all possible 40+ plans including individual table plan which might not be needed for Query Optimizer. </p></blockquote>
<blockquote><p>If you believe that the optimizer missed a better query plan, this option can be switched off (optimizer_prune_level=0) with the risk that query compilation may take much longer.<br />
This variable we can set both GLOBAL and Session level. </p>
<pre class="crayon-plain-tag">SHOW VARIABLES LIKE 'optimizer_prune_level';

SET GLOBAL optimizer_prune_level=0; -- For global change 
SET optimizer_prune_level=0; -- For session specific change</pre> </p></blockquote>
<p><strong>optimizer_search_depth:</strong> Default value is 62, the Planner is generating multiple plans, but sometimes It also generates an incomplete plan. </p>
<blockquote><p>When Query Optimizer starts to scan the plan, we can set optimizer_search_depth value to tell how far each incomplete plan the optimizer should look to evaluate.</p></blockquote>
<blockquote><p>If we set a higher value (Max 63), Query Optimizer try to evaluate all incomplete plans which will take more time to execute. If we set lower value, Query Optimizer can skip few incomplete generated plans.</p>
<p>This variable we can set both GLOBAL and Session level. </p>
<pre class="crayon-plain-tag">SHOW VARIABLES LIKE 'optimizer_search_depth';

SET GLOBAL optimizer_search_depth=40; -- For global change 
SET optimizer_search_depth=40; -- For session specific change</pre> </p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/10/mysql-controlling-query-optimizer-to-choose-the-best-execution-plan-optimizer_prune_level-optimizer_search_depth/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: Using EXPLAIN ANALYZE, Know your Query Execution Plan</title>
		<link>https://www.dbrnd.com/2016/09/postgresql-using-explain-analyze-know-your-query-execution-plan/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 08 Sep 2016 20:10:31 +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[Execution Plan]]></category>
		<category><![CDATA[EXPLAIN]]></category>
		<category><![CDATA[Explain Analyze]]></category>
		<category><![CDATA[Genetic Query Optimizer]]></category>
		<category><![CDATA[GEQO]]></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 Optimizer]]></category>
		<category><![CDATA[Query Plan]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3616</guid>

					<description><![CDATA[Like any other RDBMS, PostgreSQL generates a Query Execution Plan for each query that it receives. It is also used Genetic Query Optimizer (GEQO) that does query planning for heuristic search and It reduce query planning time for large and complex queries. An Optimizer always tries to choose a good Query Execution Plan. The structure [&#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%2F2016%2F09%2Fpostgresql-using-explain-analyze-know-your-query-execution-plan%2F&amp;linkname=PostgreSQL%3A%20Using%20EXPLAIN%20ANALYZE%2C%20Know%20your%20Query%20Execution%20Plan" 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%2F2016%2F09%2Fpostgresql-using-explain-analyze-know-your-query-execution-plan%2F&amp;linkname=PostgreSQL%3A%20Using%20EXPLAIN%20ANALYZE%2C%20Know%20your%20Query%20Execution%20Plan" 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%2F2016%2F09%2Fpostgresql-using-explain-analyze-know-your-query-execution-plan%2F&amp;linkname=PostgreSQL%3A%20Using%20EXPLAIN%20ANALYZE%2C%20Know%20your%20Query%20Execution%20Plan" 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%2F2016%2F09%2Fpostgresql-using-explain-analyze-know-your-query-execution-plan%2F&amp;linkname=PostgreSQL%3A%20Using%20EXPLAIN%20ANALYZE%2C%20Know%20your%20Query%20Execution%20Plan" 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%2F2016%2F09%2Fpostgresql-using-explain-analyze-know-your-query-execution-plan%2F&amp;linkname=PostgreSQL%3A%20Using%20EXPLAIN%20ANALYZE%2C%20Know%20your%20Query%20Execution%20Plan" 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%2F2016%2F09%2Fpostgresql-using-explain-analyze-know-your-query-execution-plan%2F&amp;linkname=PostgreSQL%3A%20Using%20EXPLAIN%20ANALYZE%2C%20Know%20your%20Query%20Execution%20Plan" 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%2F2016%2F09%2Fpostgresql-using-explain-analyze-know-your-query-execution-plan%2F&#038;title=PostgreSQL%3A%20Using%20EXPLAIN%20ANALYZE%2C%20Know%20your%20Query%20Execution%20Plan" data-a2a-url="https://www.dbrnd.com/2016/09/postgresql-using-explain-analyze-know-your-query-execution-plan/" data-a2a-title="PostgreSQL: Using EXPLAIN ANALYZE, Know your Query Execution Plan"></a></p><p>Like any other RDBMS, PostgreSQL generates a Query Execution Plan for each query that it receives. </p>
<blockquote><p>It is also used Genetic Query Optimizer (GEQO) that does query planning for heuristic search and It reduce query planning time for large and complex queries. </p></blockquote>
<p>An Optimizer always tries to choose a good Query Execution Plan.</p>
<blockquote><p>The structure of Query Execution Plan is like a Tree and It contains different information like: type of scan details, join details, sorting details, aggregation details, Estimated rows details, Estimated start-up cost, Estimated total cost and others.</p></blockquote>
<p>To know about the Query Execution Plan, is very important for all Database Professionals because It helps us to improve the Query Performance. </p>
<p>With the help of Query Execution Plan, We can make our decisions on Index tuning, Join tuning and other. </p>
<blockquote><p>In PostgreSQL, we have EXPLAIN and EXPLAIN ANALYZE command to know about the Query Execution Plan.</p></blockquote>
<p>Here, I have used one table tbl_itemtransactions which you can create using below post.</p>
<p><strong>Example of EXPLAIN: </strong>It generates the Estimated Query Execution Plan with out executing an actual SQL Query. </p>
<pre class="crayon-plain-tag">EXPLAIN SELECT COUNT(1) FROM tbl_itemtransactions;

/*
Result: 
"Aggregate  (cost=2555525.00..2555525.01 rows=1 width=0)"
"  -&gt;  Seq Scan on tbl_itemtransactions  
(cost=0.00..2216945.00 rows=135432000 width=0)"
*/</pre> </p>
<p><strong>Example of EXPLAIN ANALYZE:</strong> It first executes the SQL Query and than It generates the actual Query Execution Plan. </p>
<pre class="crayon-plain-tag">EXPLAIN ANALYZE SELECT COUNT(1) FROM tbl_itemtransactions;

/*
Result: 
"Aggregate  (cost=2555525.00..2555525.01 rows=1 width=0) 
(actual time=52660.132..52660.133 rows=1 loops=1)"
"  -&gt;  Seq Scan on tbl_itemtransactions  
(cost=0.00..2216945.00 rows=135432000 width=0) 
(actual time=0.027..46193.484 rows=135432001 loops=1)"
"Planning time: 0.204 ms"
"Execution time: 52660.237 ms"
*/</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
