<?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>distribution key &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/distribution-key/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 24 Jul 2017 19:55:39 +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>Greenplum: Alter Table Distribution Key or Policy</title>
		<link>https://www.dbrnd.com/2017/07/greenplum-alter-table-distribution-key-or-policy-random-distribution/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 29 Jul 2017 16:16:14 +0000</pubDate>
				<category><![CDATA[Greenplum]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[distribution key]]></category>
		<category><![CDATA[Greenplum Administrator]]></category>
		<category><![CDATA[Greenplum Error]]></category>
		<category><![CDATA[Greenplum Monitoring]]></category>
		<category><![CDATA[Greenplum Performance Tuning]]></category>
		<category><![CDATA[Greenplum Programming]]></category>
		<category><![CDATA[Greenplum Query]]></category>
		<category><![CDATA[Greenplum Tips and Tricks]]></category>
		<category><![CDATA[PostgreSQL 8.2]]></category>
		<category><![CDATA[random distribution]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5717</guid>

					<description><![CDATA[The first important thing, we have to define Distribution key correctly which is a primary for distribution of data in Greenplum. Greenplum is a base on MPP architecture where data equally distributes across the child segments. Before creating a table, we should analyze the distribution logic and define distribution keys where data must be unique [&#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%2F2017%2F07%2Fgreenplum-alter-table-distribution-key-or-policy-random-distribution%2F&amp;linkname=Greenplum%3A%20Alter%20Table%20Distribution%20Key%20or%20Policy" 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%2F07%2Fgreenplum-alter-table-distribution-key-or-policy-random-distribution%2F&amp;linkname=Greenplum%3A%20Alter%20Table%20Distribution%20Key%20or%20Policy" 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%2F07%2Fgreenplum-alter-table-distribution-key-or-policy-random-distribution%2F&amp;linkname=Greenplum%3A%20Alter%20Table%20Distribution%20Key%20or%20Policy" 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%2F07%2Fgreenplum-alter-table-distribution-key-or-policy-random-distribution%2F&amp;linkname=Greenplum%3A%20Alter%20Table%20Distribution%20Key%20or%20Policy" 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%2F07%2Fgreenplum-alter-table-distribution-key-or-policy-random-distribution%2F&amp;linkname=Greenplum%3A%20Alter%20Table%20Distribution%20Key%20or%20Policy" 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%2F07%2Fgreenplum-alter-table-distribution-key-or-policy-random-distribution%2F&amp;linkname=Greenplum%3A%20Alter%20Table%20Distribution%20Key%20or%20Policy" 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%2F07%2Fgreenplum-alter-table-distribution-key-or-policy-random-distribution%2F&#038;title=Greenplum%3A%20Alter%20Table%20Distribution%20Key%20or%20Policy" data-a2a-url="https://www.dbrnd.com/2017/07/greenplum-alter-table-distribution-key-or-policy-random-distribution/" data-a2a-title="Greenplum: Alter Table Distribution Key or Policy"></a></p><p>The first important thing, we have to define Distribution key correctly which is a primary for distribution of data in Greenplum.</p>
<blockquote><p>Greenplum is a base on MPP architecture where data equally distributes across the child segments.<br />
Before creating a table, we should analyze the distribution logic and define distribution keys where data must be unique for equal distribution.</p></blockquote>
<p>My suggestion: Once you distribute your data basis on defined distribution key, you should not alter the distribution key.</p>
<p>Because data redistribution requires on disk which can be resource intensive, but still I am sharing the steps to ALTER the distribution key.</p>
<p><strong>Alter Distribution key:</strong></p>
<pre class="crayon-plain-tag">ALTER TABLE table_name SET DISTRIBUTED BY (column_name);</pre> </p>
<p><strong>For Random distribution:</strong><br />
For random distribution, you should do REORGANIZE=TRUE to remove unnecessary skewness of data.</p>
<pre class="crayon-plain-tag">ALTER TABLE table_name SET DISTRIBUTED RANDOMLY;
ALTER TABLE table_name SET WITH (REORGANIZE=TRUE);</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Greenplum: Script to find a list of DISTRIBUTED RANDOMLY Table</title>
		<link>https://www.dbrnd.com/2017/07/greenplum-script-to-find-a-list-of-distributed-randomly-table/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 09 Jul 2017 16:16:35 +0000</pubDate>
				<category><![CDATA[Greenplum]]></category>
		<category><![CDATA[Greenplum DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Distributed Randomly]]></category>
		<category><![CDATA[distribution key]]></category>
		<category><![CDATA[Greenplum Administrator]]></category>
		<category><![CDATA[Greenplum Error]]></category>
		<category><![CDATA[Greenplum Monitoring]]></category>
		<category><![CDATA[Greenplum Performance Tuning]]></category>
		<category><![CDATA[Greenplum Programming]]></category>
		<category><![CDATA[Greenplum Query]]></category>
		<category><![CDATA[Greenplum Tips and Tricks]]></category>
		<category><![CDATA[PostgreSQL 8.2]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5590</guid>

					<description><![CDATA[As Greenplum is a MPP architecture, so distribution of data in all segments is the first stuff. You can distribute your table data using Distributed BY , and if you are not sure about a particular column, you can create your table using Distributed Randomly. But tables which are distributed randomly, are not good for [&#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%2F2017%2F07%2Fgreenplum-script-to-find-a-list-of-distributed-randomly-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20a%20list%20of%20DISTRIBUTED%20RANDOMLY%20Table" 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%2F07%2Fgreenplum-script-to-find-a-list-of-distributed-randomly-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20a%20list%20of%20DISTRIBUTED%20RANDOMLY%20Table" 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%2F07%2Fgreenplum-script-to-find-a-list-of-distributed-randomly-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20a%20list%20of%20DISTRIBUTED%20RANDOMLY%20Table" 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%2F07%2Fgreenplum-script-to-find-a-list-of-distributed-randomly-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20a%20list%20of%20DISTRIBUTED%20RANDOMLY%20Table" 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%2F07%2Fgreenplum-script-to-find-a-list-of-distributed-randomly-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20a%20list%20of%20DISTRIBUTED%20RANDOMLY%20Table" 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%2F07%2Fgreenplum-script-to-find-a-list-of-distributed-randomly-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20a%20list%20of%20DISTRIBUTED%20RANDOMLY%20Table" 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%2F07%2Fgreenplum-script-to-find-a-list-of-distributed-randomly-table%2F&#038;title=Greenplum%3A%20Script%20to%20find%20a%20list%20of%20DISTRIBUTED%20RANDOMLY%20Table" data-a2a-url="https://www.dbrnd.com/2017/07/greenplum-script-to-find-a-list-of-distributed-randomly-table/" data-a2a-title="Greenplum: Script to find a list of DISTRIBUTED RANDOMLY Table"></a></p><p>As Greenplum is a MPP architecture, so distribution of data in all segments is the first stuff.</p>
<blockquote><p>You can distribute your table data using Distributed BY <ID>, and if you are not sure about a particular column, you can create your table using Distributed Randomly.</p></blockquote>
<p>But tables which are distributed randomly, are not good for table performance because query optimizer will take more time for Randomly distributed tables.<br />
Greenplum DBA can use below script to find randomly distributed tables.</p>
<pre class="crayon-plain-tag">with cte AS
(
	SELECT                 
		pgn.nspname as SchemaName                 
		,pgc.relname as TableName
		,pga.attname as DistributionType
	FROM
	(
		SELECT gdp.localoid,
			CASE
			WHEN ( Array_upper(gdp.attrnums, 1) &gt; 0 ) THEN
			Unnest(gdp.attrnums)
			ELSE NULL
			END AS attnum
		FROM gp_distribution_policy gdp
		ORDER BY gdp.localoid
	) AS distrokey
	INNER JOIN pg_class AS pgc
		ON distrokey.localoid = pgc.oid
	INNER JOIN pg_namespace pgn
		ON pgc.relnamespace = pgn.oid
	LEFT OUTER JOIN pg_attribute pga
		ON distrokey.attnum = pga.attnum
	AND distrokey.localoid = pga.attrelid      
)
select
	SchemaName
	,TableName      
	,COALESCE(DistributionType,'DISTRIBUTED RANDOMLY') AS DistributionType
from cte
where COALESCE(DistributionType,'DISTRIBUTED RANDOMLY')='DISTRIBUTED RANDOMLY'
ORDER BY SchemaName,TableName</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Greenplum: Script to find all Distribution Keys of Database tables</title>
		<link>https://www.dbrnd.com/2017/06/greenplum-script-to-find-all-distribution-keys-of-database-table/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 04 Jun 2017 16:16:49 +0000</pubDate>
				<category><![CDATA[Greenplum]]></category>
		<category><![CDATA[Greenplum DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[distributed database]]></category>
		<category><![CDATA[distribution key]]></category>
		<category><![CDATA[Greenplum Administrator]]></category>
		<category><![CDATA[Greenplum Error]]></category>
		<category><![CDATA[Greenplum Monitoring]]></category>
		<category><![CDATA[Greenplum Performance Tuning]]></category>
		<category><![CDATA[Greenplum Programming]]></category>
		<category><![CDATA[Greenplum Query]]></category>
		<category><![CDATA[Greenplum Tips and Tricks]]></category>
		<category><![CDATA[PostgreSQL 8.2]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5365</guid>

					<description><![CDATA[In this post, I am sharing a script to find a list of distribution keys of a database. In the Greenplum MPP architecture, distribution keys are playing a primary role in selecting data. If we define proper distribution key, we don&#8217;t require even table indexes. &#8216; Using below script, Greenplum DBA can get the list [&#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%2F2017%2F06%2Fgreenplum-script-to-find-all-distribution-keys-of-database-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20all%20Distribution%20Keys%20of%20Database%20tables" 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%2F06%2Fgreenplum-script-to-find-all-distribution-keys-of-database-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20all%20Distribution%20Keys%20of%20Database%20tables" 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%2F06%2Fgreenplum-script-to-find-all-distribution-keys-of-database-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20all%20Distribution%20Keys%20of%20Database%20tables" 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%2F06%2Fgreenplum-script-to-find-all-distribution-keys-of-database-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20all%20Distribution%20Keys%20of%20Database%20tables" 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%2F06%2Fgreenplum-script-to-find-all-distribution-keys-of-database-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20all%20Distribution%20Keys%20of%20Database%20tables" 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%2F06%2Fgreenplum-script-to-find-all-distribution-keys-of-database-table%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20all%20Distribution%20Keys%20of%20Database%20tables" 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%2F06%2Fgreenplum-script-to-find-all-distribution-keys-of-database-table%2F&#038;title=Greenplum%3A%20Script%20to%20find%20all%20Distribution%20Keys%20of%20Database%20tables" data-a2a-url="https://www.dbrnd.com/2017/06/greenplum-script-to-find-all-distribution-keys-of-database-table/" data-a2a-title="Greenplum: Script to find all Distribution Keys of Database tables"></a></p><p>In this post, I am sharing a script to find a list of distribution keys of a database. In the Greenplum MPP architecture, distribution keys are playing a primary role in selecting data.</p>
<p>If we define proper distribution key, we don&#8217;t require even table indexes.<br />
&#8216; Using below script, Greenplum DBA can get the list of all distribution keys which further they can use for ad-hoc database reporting as well.</p>
<pre class="crayon-plain-tag">SELECT
	pgn.nspname as table_owner
	,pgc.relname as table_name
	,COALESCE(pga.attname,'DISTRIBUTED RANDOMLY') as distribution_keys
FROM
(
	SELECT
		gdp.localoid,
		CASE
			WHEN ( Array_upper(gdp.attrnums, 1) &gt; 0 ) THEN
			Unnest(gdp.attrnums)
			ELSE NULL
		END AS attnum
	FROM gp_distribution_policy gdp
	ORDER BY gdp.localoid
) AS distrokey
INNER JOIN pg_class AS pgc
	ON distrokey.localoid = pgc.oid
INNER JOIN pg_namespace pgn
	ON pgc.relnamespace = pgn.oid
LEFT OUTER JOIN pg_attribute pga
	ON distrokey.attnum = pga.attnum
		and distrokey.localoid = pga.attrelid
ORDER BY pgn.nspname, pgc.relname;</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
