<?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>horizontal partitioning &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/horizontal-partitioning/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>Wed, 31 Aug 2016 20:22:52 +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 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 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>
