<?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 performance &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/query-performance/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>Tue, 03 Apr 2018 19:13:15 +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>PostgreSQL: Improve Query Performance by Extended Statistics</title>
		<link>https://www.dbrnd.com/2018/04/postgresql-improve-query-performance-by-extended-statistics/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 03 Apr 2018 19:13:15 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[correlated column]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[Database Statistics]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[extended statistics]]></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 Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[query performance]]></category>
		<category><![CDATA[statistic object]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6916</guid>

					<description><![CDATA[<div><img width="635" height="357" src="https://www.dbrnd.com/wp-content/uploads/2018/04/PostgreSQL-Performance.jpg" class="attachment-post-image size-post-image wp-post-image" alt="" decoding="async" fetchpriority="high" /></div>In this post, I am sharing an important demonstration on how to improve query performance by adding Extended Statistics in PostgreSQL. PostgreSQL: Important Statistics Table, Used by the Query Planner The database statistics are always important in any database system. Because query optimizer is creating Query Execution Plan basis on stored database statistics. Understand below [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="635" height="357" src="https://www.dbrnd.com/wp-content/uploads/2018/04/PostgreSQL-Performance.jpg" class="attachment-post-image size-post-image wp-post-image" alt="" decoding="async" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F04%2Fpostgresql-improve-query-performance-by-extended-statistics%2F&amp;linkname=PostgreSQL%3A%20Improve%20Query%20Performance%20by%20Extended%20Statistics" 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-improve-query-performance-by-extended-statistics%2F&amp;linkname=PostgreSQL%3A%20Improve%20Query%20Performance%20by%20Extended%20Statistics" 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-improve-query-performance-by-extended-statistics%2F&amp;linkname=PostgreSQL%3A%20Improve%20Query%20Performance%20by%20Extended%20Statistics" 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-improve-query-performance-by-extended-statistics%2F&amp;linkname=PostgreSQL%3A%20Improve%20Query%20Performance%20by%20Extended%20Statistics" 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-improve-query-performance-by-extended-statistics%2F&amp;linkname=PostgreSQL%3A%20Improve%20Query%20Performance%20by%20Extended%20Statistics" 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-improve-query-performance-by-extended-statistics%2F&amp;linkname=PostgreSQL%3A%20Improve%20Query%20Performance%20by%20Extended%20Statistics" 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-improve-query-performance-by-extended-statistics%2F&#038;title=PostgreSQL%3A%20Improve%20Query%20Performance%20by%20Extended%20Statistics" data-a2a-url="https://www.dbrnd.com/2018/04/postgresql-improve-query-performance-by-extended-statistics/" data-a2a-title="PostgreSQL: Improve Query Performance by Extended Statistics"></a></p><p>In this post, I am sharing an important demonstration on how to improve query performance by adding Extended Statistics in PostgreSQL. </p>
<blockquote class="wp-embedded-content" data-secret="5NUC2ue1WC"><p><a href="https://www.dbrnd.com/2016/09/postgresql-important-statistics-table-used-by-the-query-planner-pg_class-pg_stats-vacuum-analyze/">PostgreSQL: Important Statistics Table, Used by the Query Planner</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/09/postgresql-important-statistics-table-used-by-the-query-planner-pg_class-pg_stats-vacuum-analyze/embed/#?secret=5NUC2ue1WC" data-secret="5NUC2ue1WC" width="600" height="338" title="&#8220;PostgreSQL: Important Statistics Table, Used by the Query Planner&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>The database statistics are always important in any database system. Because query optimizer is creating Query Execution Plan basis on stored database statistics. </p>
<p>Understand below official note which copied from <a href="https://www.postgresql.org/docs/10/static/planner-stats.html#idm46428702517264" rel="noopener" target="_blank">here</a>.</p>
<blockquote><p>It is common to see slow queries running bad execution plans because multiple columns used in the query clauses are correlated. </p>
<p>The planner normally assumes that multiple conditions are independent of each other, an assumption that does not hold when column values are correlated. Regular statistics, because of their per-individual-column nature, cannot capture any knowledge about cross-column correlation. </p>
<p>Because the number of possible column combinations is very large, it&#8217;s impractical to compute multivariate statistics automatically. Instead, extended statistics objects, more often called just statistics objects.</p></blockquote>
<p>Let me explain, by my way, </p>
<blockquote><p>For example, you give two filters in a where condition like zip code and city_name.<br />
Now, zip code is unique for dataset, but one city has multiple zip codes.<br />
Now, this both conditions and columns called correlated columns. </p>
<p>To inform the planner about functional dependencies, ANALYZE can collect measurements of cross-column dependency.<br />
It is advisable to create dependencies statistics only for column groups that are strongly correlated, to avoid unnecessary overhead in both ANALYZE and later query planning.</p></blockquote>
<p>Check the below demonstration:</p>
<p><strong>Create a sample table:﻿</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestStats
 (
     ID SERIAL
     ,CodeDate TIMESTAMPTZ
     ,CodeName TEXT
 );</pre> </p>
<p><strong>Two sample insert for different series:</strong><br />
For example, 2016 year for code &#8216;abc&#8217; and 2017 year for code &#8216;xyz&#8217;</p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestStats 
(CodeDate, CodeName)
SELECT x, 'abc' 
FROM generate_series('2016-01-01 00:00:00'::timestamptz, '2016-12-31 00:00:00'::timestamptz,'10 seconds'::interval) a(x);


INSERT INTO tbl_TestStats 
(CodeDate, CodeName)
SELECT x, 'xyz' 
FROM generate_series('2017-01-01 00:00:00'::timestamptz, '2017-12-31 00:00:00'::timestamptz,'10 seconds'::interval) a(x);</pre> </p>
<p><strong>Total inserted records:</strong></p>
<pre class="crayon-plain-tag">SELECT COUNT(1) FROM tbl_TestStats
-- '6298562'</pre> </p>
<p><strong>Now, Execute ANALYZE:</strong></p>
<pre class="crayon-plain-tag">ANALYZE tbl_TestStats;</pre> </p>
<p><strong>Check the execution plan of the below query:</strong></p>
<pre class="crayon-plain-tag">EXPLAIN ANALYZE
SELECT *FROM tbl_TestStats
WHERE CodeDate = '2016-12-03'
	AND CodeName = 'abc'
    
'Gather  (cost=1000.00..80484.88 rows=1 width=16) (actual time=347.355..347.496 rows=1 loops=1)'
'  Workers Planned: 2'
'  Workers Launched: 2'
'  -&gt;  Parallel Seq Scan on tbl_teststats  (cost=0.00..79484.77 rows=1 width=16) (actual time=278.702..340.557 rows=0 loops=3)'
'        Filter: ((codedate = '2016-12-03 00:00:00+05:30'::timestamp with time zone) AND (codename = 'abc'::text))'
'        Rows Removed by Filter: 2099520'
'Planning time: 0.168 ms'
'Execution time: 353.298 ms'</pre> </p>
<p><strong>Now, Create an Extended Statistics for correlated columns: </strong></p>
<pre class="crayon-plain-tag">CREATE STATISTICS Ext_Stat_tbl_TestStats (dependencies) ON CodeDate, CodeName 
FROM tbl_TestStats;</pre> </p>
<p><strong>Now, Execute ANALYZE:</strong></p>
<pre class="crayon-plain-tag">ANALYZE tbl_TestStats;</pre> </p>
<p><strong>Check execution plan for the same query:</strong><br />
Comparing to first result, you can find slightly performance improvement in the second result. </p>
<pre class="crayon-plain-tag">EXPLAIN ANALYZE
SELECT *FROM tbl_TestStats
WHERE CodeDate = '2016-12-03'
	AND CodeName = 'abc'
    
'Gather  (cost=1000.00..80484.86 rows=1 width=16) (actual time=150.732..311.567 rows=1 loops=1)'
'  Workers Planned: 2'
'  Workers Launched: 2'
'  -&gt;  Parallel Seq Scan on tbl_teststats  (cost=0.00..79484.76 rows=1 width=16) (actual time=251.261..304.857 rows=0 loops=3)'
'        Filter: ((codedate = '2016-12-03 00:00:00+05:30'::timestamp with time zone) AND (codename = 'abc'::text))'
'        Rows Removed by Filter: 2099520'
'Planning time: 0.167 ms'
'Execution time: 316.685 ms'</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Create UNLOGGED Table for Good Performance</title>
		<link>https://www.dbrnd.com/2018/03/postgresql-create-unlogged-table-for-good-performance/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 28 Mar 2018 16:16:51 +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 Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[query performance]]></category>
		<category><![CDATA[UNLOGGED Table]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6922</guid>

					<description><![CDATA[Last month, we were testing huge data loading in PostgreSQL. We tried different options like COPY command, ETL Tool, CSV Load, and manual INSERT. While testing this load, got to know about one more option which is the UNLOGGED Table of PostgreSQL. Important notice: The UNLOGGED Table is not a safe because it is not [&#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%2F03%2Fpostgresql-create-unlogged-table-for-good-performance%2F&amp;linkname=PostgreSQL%3A%20Create%20UNLOGGED%20Table%20for%20Good%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%2F03%2Fpostgresql-create-unlogged-table-for-good-performance%2F&amp;linkname=PostgreSQL%3A%20Create%20UNLOGGED%20Table%20for%20Good%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%2F03%2Fpostgresql-create-unlogged-table-for-good-performance%2F&amp;linkname=PostgreSQL%3A%20Create%20UNLOGGED%20Table%20for%20Good%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%2F03%2Fpostgresql-create-unlogged-table-for-good-performance%2F&amp;linkname=PostgreSQL%3A%20Create%20UNLOGGED%20Table%20for%20Good%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%2F03%2Fpostgresql-create-unlogged-table-for-good-performance%2F&amp;linkname=PostgreSQL%3A%20Create%20UNLOGGED%20Table%20for%20Good%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%2F03%2Fpostgresql-create-unlogged-table-for-good-performance%2F&amp;linkname=PostgreSQL%3A%20Create%20UNLOGGED%20Table%20for%20Good%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%2F03%2Fpostgresql-create-unlogged-table-for-good-performance%2F&#038;title=PostgreSQL%3A%20Create%20UNLOGGED%20Table%20for%20Good%20Performance" data-a2a-url="https://www.dbrnd.com/2018/03/postgresql-create-unlogged-table-for-good-performance/" data-a2a-title="PostgreSQL: Create UNLOGGED Table for Good Performance"></a></p><p>Last month, we were testing huge data loading in PostgreSQL.<br />
We tried different options like COPY command, ETL Tool, CSV Load, and manual INSERT.</p>
<p>While testing this load, got to know about one more option which is the UNLOGGED Table of PostgreSQL. </p>
<p><strong>Important notice: The UNLOGGED Table is not a safe because it is not written to the write-ahead log, so it is not crash safe. </strong></p>
<blockquote><p>If your database crash or shutdown abnormally, the UNLOGGED table may lose or truncate automatically. </p>
<p>But in any database system, there are few tables which always for standby, backup and snapshot purpose.<br />
Sometimes, we need faster data loading on this kind of tables.<br />
When you create any indexes on the UNLOGGED table, those indexes also keep UNLOGGED. </p></blockquote>
<p><strong>Check the below sample table, and try it yourself:</strong></p>
<pre class="crayon-plain-tag">CREATE UNLOGGED TABLE tbl_TestUnlogged (ID INTEGER, Name Character Varying)</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server 2012: SORT_IN_TEMPDB used to Improve the Index Rebuild Performance</title>
		<link>https://www.dbrnd.com/2018/01/sql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb/</link>
					<comments>https://www.dbrnd.com/2018/01/sql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 09 Jan 2018 16:16:07 +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[Index Rebuild]]></category>
		<category><![CDATA[query performance]]></category>
		<category><![CDATA[Sort Operation]]></category>
		<category><![CDATA[SORT_IN_TEMPDB]]></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[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4209</guid>

					<description><![CDATA[<div><img width="679" height="382" src="https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance-679x382.jpg" class="attachment-post-image size-post-image wp-post-image" alt="SQL Database Performance" decoding="async" loading="lazy" srcset="https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance-679x382.jpg 679w, https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance.jpg 800w" sizes="auto, (max-width: 679px) 100vw, 679px" /></div>SQL Server 2012 enhanced the performance of INDEX REBUILD by introducing the SORT_IN_TEMPDB option. I observed that many SQL developers are not using this feature or maybe they don&#8217;t know about it. The INDEX REBUILD operation is removing the fragmentation of indexes which improves the query performance. It scans the data pages of base table [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="679" height="382" src="https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance-679x382.jpg" class="attachment-post-image size-post-image wp-post-image" alt="SQL Database Performance" decoding="async" loading="lazy" srcset="https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance-679x382.jpg 679w, https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance.jpg 800w" sizes="auto, (max-width: 679px) 100vw, 679px" /></div><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-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%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%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%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%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%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%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%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%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%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%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%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%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&#038;title=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%20Performance" data-a2a-url="https://www.dbrnd.com/2018/01/sql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb/" data-a2a-title="SQL Server 2012: SORT_IN_TEMPDB used to Improve the Index Rebuild Performance"></a></p><p>SQL Server 2012 enhanced the performance of INDEX REBUILD by introducing the SORT_IN_TEMPDB option.<br />
I observed that many SQL developers are not using this feature or maybe they don&#8217;t know about it. </p>
<blockquote><p>The INDEX REBUILD operation is removing the fragmentation of indexes which improves the query performance. It scans the data pages of base table to retrieve the key values and builds an index leaf row for each row.
</p></blockquote>
<blockquote><p>This process requires internal sorting which it stores in the buffer area.</p></blockquote>
<blockquote><p>Once the buffer filled with leaf index entries, it stores the sorted result into a disk as an intermediate sort run. Next, It again starts with the same process for further data pages.</p></blockquote>
<p>As per the MSDN,</p>
<blockquote><p>When you create or rebuild an index, by setting the SORT_IN_TEMPDB option to ON you can direct the SQL Server Database Engine to use tempdb to store the intermediate sort results that are used to build the index. </p>
<p>Although this option increases the amount of temporary disk space that is used to create an index, the option could reduce the time that is required to create or rebuild an index when tempdb is on a set of disks different from that of the user database.</p>
<p>If SORT_IN_TEMPDB is set to ON, there must be sufficient free space in tempdb to store the collection of sort runs for the largest index.</p></blockquote>
<p>When you are rebuilding the large size of Indexes, SORT_IN_TEMPDB helps you lot by reducing the operational execution time. </p>
<p><strong>Sample Script with option SORT_IN_TEMPDB:</strong></p>
<pre class="crayon-plain-tag">ALTER INDEX ALL ON MyTableName
REBUILD WITH 
(FILLFACTOR = 80, SORT_IN_TEMPDB = ON,
 STATISTICS_NORECOMPUTE = ON);
GO</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/01/sql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</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 9.5: Introduced BRIN &#8211; Block Range Index with Performance Report</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-9-5-introduced-brin-block-range-index-with-detail-performance-test-report-on-6gb-table/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 31 Aug 2016 20:22:52 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[block range index]]></category>
		<category><![CDATA[brin]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[horizontal partitioning]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[postgresql 9.5]]></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 performance]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3472</guid>

					<description><![CDATA[Please read this previous article, To Understand the Power of BRIN &#8211; Block Range Index. Database Theory: What is BRIN (Block Range Index), How is faster than BTREE Index PostgreSQL 9.5 introduced the powerful BRIN Index, which is performance much faster than the regular BTREE Index. The most important two lines of the BRIN are: [&#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%2F08%2Fpostgresql-9-5-introduced-brin-block-range-index-with-detail-performance-test-report-on-6gb-table%2F&amp;linkname=PostgreSQL%209.5%3A%20Introduced%20BRIN%20%E2%80%93%20Block%20Range%20Index%20with%20Performance%20Report" 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%2F08%2Fpostgresql-9-5-introduced-brin-block-range-index-with-detail-performance-test-report-on-6gb-table%2F&amp;linkname=PostgreSQL%209.5%3A%20Introduced%20BRIN%20%E2%80%93%20Block%20Range%20Index%20with%20Performance%20Report" 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%2F08%2Fpostgresql-9-5-introduced-brin-block-range-index-with-detail-performance-test-report-on-6gb-table%2F&amp;linkname=PostgreSQL%209.5%3A%20Introduced%20BRIN%20%E2%80%93%20Block%20Range%20Index%20with%20Performance%20Report" 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%2F08%2Fpostgresql-9-5-introduced-brin-block-range-index-with-detail-performance-test-report-on-6gb-table%2F&amp;linkname=PostgreSQL%209.5%3A%20Introduced%20BRIN%20%E2%80%93%20Block%20Range%20Index%20with%20Performance%20Report" 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%2F08%2Fpostgresql-9-5-introduced-brin-block-range-index-with-detail-performance-test-report-on-6gb-table%2F&amp;linkname=PostgreSQL%209.5%3A%20Introduced%20BRIN%20%E2%80%93%20Block%20Range%20Index%20with%20Performance%20Report" 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%2F08%2Fpostgresql-9-5-introduced-brin-block-range-index-with-detail-performance-test-report-on-6gb-table%2F&amp;linkname=PostgreSQL%209.5%3A%20Introduced%20BRIN%20%E2%80%93%20Block%20Range%20Index%20with%20Performance%20Report" 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%2F08%2Fpostgresql-9-5-introduced-brin-block-range-index-with-detail-performance-test-report-on-6gb-table%2F&#038;title=PostgreSQL%209.5%3A%20Introduced%20BRIN%20%E2%80%93%20Block%20Range%20Index%20with%20Performance%20Report" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-9-5-introduced-brin-block-range-index-with-detail-performance-test-report-on-6gb-table/" data-a2a-title="PostgreSQL 9.5: Introduced BRIN – Block Range Index with Performance Report"></a></p><p>Please read this previous article, To Understand the Power of BRIN &#8211; Block Range Index.</p>
<blockquote class="wp-embedded-content" data-secret="FKivrefXky"><p><a href="https://www.dbrnd.com/2016/08/database-theory-what-is-brin-block-range-index-how-is-faster-than-btree-index-horizontal-partition-index/">Database Theory: What is BRIN (Block Range Index), How is faster than BTREE Index</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/08/database-theory-what-is-brin-block-range-index-how-is-faster-than-btree-index-horizontal-partition-index/embed/#?secret=FKivrefXky" data-secret="FKivrefXky" width="600" height="338" title="&#8220;Database Theory: What is BRIN (Block Range Index), How is faster than BTREE Index&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote><p>PostgreSQL 9.5 introduced the powerful BRIN Index, which is performance much faster than the regular BTREE Index.<br />
The most important two lines of the BRIN are: It stores only minimum and maximum value per block so it does not require more space. For extremely large table It runs faster than any other Indexes.</p></blockquote>
<p>In this post, I am going to show the example of BRIN index with the full performance report (testing over the 6gb of Table Data).</p>
<p><strong>Below are steps:<br />
</strong><br />
<strong>First create one sample table:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_ItemTransactions 
 (
     TranID SERIAL
     ,TransactionDate TIMESTAMPTZ
     ,TransactionName TEXT
 );</pre><p>
<strong>Insert Millions of data to test the performance of BRIN Index:</strong></p><pre class="crayon-plain-tag">INSERT INTO tbl_ItemTransactions 
(TransactionDate, TransactionName)
SELECT x, 'dbrnd' 
FROM generate_series('2008-01-01 00:00:00'::timestamptz, '2016-08-01 00:00:00'::timestamptz,'2 seconds'::interval) a(x);</pre><p>
<strong>Check the total size of table:<br />
</strong></p><pre class="crayon-plain-tag">SELECT pg_size_pretty(pg_total_relation_size('tbl_ItemTransactions')) AS TableSize;

/*
    TableSize
------------------
    6741 MB
*/</pre><p>
<strong>Now Check the performance without any Index:<br />
</strong></p><pre class="crayon-plain-tag">EXPLAIN ANALYSE 
SELECT COUNT(1) FROM tbl_ItemTransactions 
WHERE TransactionDate BETWEEN '2012-01-01 00:00:00' and '2014-08-08 08:08:08';
/*
--Result:
			QueryPlan
-------------------------------------------------------------------------
Aggregate  (cost=2997896.81..2997896.82 rows=1 width=0) 
	(actual time=40651.793..40651.793 rows=1 loops=1)
  -&gt;  Seq Scan on tbl_itemtransactions  (cost=0.00..2894105.00 rows=41516724 width=0) 
	(actual time=0.009..38726.686 rows=41054645 loops=1)
        Filter: ((transactiondate &gt;= '2012-01-01 00:00:00+05:30'::timestamp with time zone) 
		AND (transactiondate &lt;= '2014-08-08 08:08:08+05:30'::timestamp with time zone))
        Rows Removed by Filter: 94377356
Planning time: 0.860 ms
Execution time: 80651.837 ms
*/</pre><p>
<strong>Create BRIN index on TransactionDate Column:</strong></p><pre class="crayon-plain-tag">CREATE INDEX idx_tbl_ItemTransactions_TransactionDate
ON tbl_ItemTransactions
USING BRIN (TransactionDate);</pre><p>
<p><strong>Now Check the performance of the same query which has BRIN index:<br />
</strong></p><pre class="crayon-plain-tag">EXPLAIN ANALYSE 
SELECT COUNT(1) FROM tbl_ItemTransactions 
WHERE TransactionDate BETWEEN '2012-01-01 00:00:00' and '2014-08-08 08:08:08';
/*
			QueryPlan
---------------------------------------------------------------------------
Aggregate  (cost=2014834.09..2014834.10 rows=1 width=0) 
	(actual time=7108.998..7108.998 rows=1 loops=1)
  -&gt;  Bitmap Heap Scan on tbl_itemtransactions  (cost=425666.42..1911042.28 rows=41516724 width=0) 
	(actual time=16.995..5415.086 rows=41054645 loops=1)
        Recheck Cond: ((transactiondate &gt;= '2012-01-01 00:00:00+05:30'::timestamp with time zone) 
		AND (transactiondate &lt;= '2014-08-08 08:08:08+05:30'::timestamp with time zone))
        Rows Removed by Index Recheck: 21579
        Heap Blocks: lossy=261632
        -&gt;  Bitmap Index Scan on idx_tbl_itemtransactions_transactiondate  
		(cost=0.00..415287.24 rows=41516724 width=0) (actual time=15.547..15.547 rows=2616320 loops=1)
              Index Cond: ((transactiondate &gt;= '2012-01-01 00:00:00+05:30'::timestamp with time zone) 
              AND (transactiondate &lt;= '2014-08-08 08:08:08+05:30'::timestamp with time zone))
Planning time: 0.059 ms
Execution time: 7109.060 ms
*/</pre><p>
<blockquote><p>Now, you can see the difference between the result of the above two queries.<br />
With the BRIN index same query took only 7 seconds and without BRIN it took around 80 seconds.</p></blockquote>
<p><strong>Create Partial BRIN index on TransactionDate Column:</strong><br />
You can also create Partial BRIN index for your individual range of data. The Partial BRIN index is also faster than normal BRIN index, but we should apply proper filter based on created Partial BRIN index. </p>
<pre class="crayon-plain-tag">CREATE INDEX idx_tbl_ItemTransactions_TransactionDate_2012
ON tbl_ItemTransactions
USING BRIN (TransactionDate)
WHERE TransactionDate BETWEEN '2012-01-01' AND '2012-12-31';</pre> </p>
<pre class="crayon-plain-tag">CREATE INDEX idx_tbl_ItemTransactions_TransactionDate_2013
ON tbl_ItemTransactions
USING BRIN (TransactionDate)
WHERE TransactionDate BETWEEN '2013-01-01' AND '2013-12-31';</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
