You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by in...@apache.org on 2017/11/13 10:07:26 UTC

incubator-hawq git commit: HAWQ-1544. prompt file count doesn't match hash bucket number when reorganize table

Repository: incubator-hawq
Updated Branches:
  refs/heads/master 72b719794 -> 4cb2a7ab9


HAWQ-1544. prompt file count doesn't match hash bucket number when reorganize table


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/4cb2a7ab
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/4cb2a7ab
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/4cb2a7ab

Branch: refs/heads/master
Commit: 4cb2a7ab957a53f818ec399c80b57a015249bbc9
Parents: 72b7197
Author: interma <in...@outlook.com>
Authored: Mon Nov 6 17:01:59 2017 +0800
Committer: interma <in...@outlook.com>
Committed: Mon Nov 13 18:06:22 2017 +0800

----------------------------------------------------------------------
 src/backend/cdb/cdbcat.c                        |  6 +++--
 src/backend/commands/tablecmds.c                | 11 +++++++++
 .../catalog/ans/alter-table-distributed.ans     | 10 ++++++++
 .../catalog/sql/alter-table-distributed.sql     |  1 +
 src/test/feature/catalog/test_alter_table.cpp   | 25 ++++++++++++++++++++
 5 files changed, 51 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/4cb2a7ab/src/backend/cdb/cdbcat.c
----------------------------------------------------------------------
diff --git a/src/backend/cdb/cdbcat.c b/src/backend/cdb/cdbcat.c
index 138c530..20d88f1 100644
--- a/src/backend/cdb/cdbcat.c
+++ b/src/backend/cdb/cdbcat.c
@@ -296,7 +296,6 @@ GpPolicyStore(Oid tbloid, const GpPolicy *policy)
 /*
  * Sets the policy of a table into the gp_distribution_policy table
  * from a GpPolicy structure.
- *
  */
 void
 GpPolicyReplace(Oid tbloid, const GpPolicy *policy)
@@ -354,7 +353,9 @@ GpPolicyReplace(Oid tbloid, const GpPolicy *policy)
 	repl[0] = false;
 	repl[1] = false;
 	repl[2] = true;
-
+	
+	if (policy->bucketnum > 0)
+		repl[1] = true;
 
 	/*
 	 * Select by value of the localoid field
@@ -534,3 +535,4 @@ checkPolicyForUniqueIndex(Relation rel, AttrNumber *indattr, int nidxatts,
 		}
 	}
 }
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/4cb2a7ab/src/backend/commands/tablecmds.c
----------------------------------------------------------------------
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index eb6944e..7172aef 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -7742,6 +7742,7 @@ ATExecDropColumn(List **wqueue, Relation rel, const char *colName,
 			if (attnum == policy->attrs[ia])
 			{
 				policy->nattrs = 0;
+				policy->bucketnum = 0;
 				rel->rd_cdbpolicy = GpPolicyCopy(GetMemoryChunkContext(rel), policy);
 				GpPolicyReplace(RelationGetRelid(rel), policy);
 				if (Gp_role != GP_ROLE_EXECUTE)
@@ -13078,6 +13079,11 @@ ATExecSetDistributedBy(Relation rel, Node *node, AlterTableCmd *cmd)
 			policy = (GpPolicy *) palloc(sizeof(GpPolicy));
 			policy->ptype = POLICYTYPE_PARTITIONED;
 			policy->nattrs = 0;
+			/**
+			 * consider user can modify default_hash_table_bucket_number in session,
+			 * should set bucketnum to the current hash_table_bucket_number during reorganize table
+			 */
+			policy->bucketnum = GetHashDistPartitionNum();
 
 			rel->rd_cdbpolicy = GpPolicyCopy(GetMemoryChunkContext(rel),
 										 policy);
@@ -13122,6 +13128,11 @@ ATExecSetDistributedBy(Relation rel, Node *node, AlterTableCmd *cmd)
 							sizeof(policy->attrs[0]) * list_length(ldistro));
 			policy->ptype = POLICYTYPE_PARTITIONED;
 			policy->nattrs = 0;
+			/**
+			 * consider user can modify default_hash_table_bucket_number in session,
+			 * should set bucketnum to the current hash_table_bucket_number during reorganize table
+			 */
+			policy->bucketnum = GetHashDistPartitionNum();
 
 			/* Step (a) */
 			if (!rand_pol)

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/4cb2a7ab/src/test/feature/catalog/ans/alter-table-distributed.ans
----------------------------------------------------------------------
diff --git a/src/test/feature/catalog/ans/alter-table-distributed.ans b/src/test/feature/catalog/ans/alter-table-distributed.ans
new file mode 100644
index 0000000..b92dea2
--- /dev/null
+++ b/src/test/feature/catalog/ans/alter-table-distributed.ans
@@ -0,0 +1,10 @@
+-- start_ignore
+SET SEARCH_PATH=TestAlterTable_TestAlterTableDistributed;
+SET
+-- end_ignore
+select count(*) from altable;
+ count 
+-------
+  1000
+(1 row)
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/4cb2a7ab/src/test/feature/catalog/sql/alter-table-distributed.sql
----------------------------------------------------------------------
diff --git a/src/test/feature/catalog/sql/alter-table-distributed.sql b/src/test/feature/catalog/sql/alter-table-distributed.sql
new file mode 100644
index 0000000..bc3d7df
--- /dev/null
+++ b/src/test/feature/catalog/sql/alter-table-distributed.sql
@@ -0,0 +1 @@
+select count(*) from altable;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/4cb2a7ab/src/test/feature/catalog/test_alter_table.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/catalog/test_alter_table.cpp b/src/test/feature/catalog/test_alter_table.cpp
index 03a13dd..ffae176 100644
--- a/src/test/feature/catalog/test_alter_table.cpp
+++ b/src/test/feature/catalog/test_alter_table.cpp
@@ -270,3 +270,28 @@ TEST_F(TestAlterTable, TestAlterTableAddColumn) {
   // cleanup
   util.execute("drop table tmp");
 }
+
+TEST_F(TestAlterTable, TestAlterTableDistributed) {
+	hawq::test::SQLUtility util;
+	// prepare
+	util.execute("drop table if exists altable");
+	util.execute("create table altable (a int)");
+	util.execute("insert into altable select generate_series(1,1000);");
+
+	// set bucket_number and do distributed
+	util.execute("set default_hash_table_bucket_number=8;");
+	util.execute("alter table altable set with(reorganize=true) distributed by (a);");
+	// check access ok
+	util.execSQLFile("catalog/sql/alter-table-distributed.sql",
+				   "catalog/ans/alter-table-distributed.ans");
+
+	// set another bucket_number and check again
+	util.execute("set default_hash_table_bucket_number=11;");
+	util.execute("alter table altable set with(reorganize=true) distributed by (a);");
+	// check access ok
+	util.execSQLFile("catalog/sql/alter-table-distributed.sql",
+				   "catalog/ans/alter-table-distributed.ans");
+
+	// cleanup
+	util.execute("drop table altable");
+}