add_constraint_using_index_on_part_table.patch

text/plain

Filename: add_constraint_using_index_on_part_table.patch
Type: text/plain
Part: 0
Message: Re: Partitioned tables and [un]loggedness

Patch

Format: unified
File+
src/backend/commands/tablecmds.c 3 10
src/test/regress/expected/create_index.out 2 1
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 9966d1f53c..777de48c69 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -4922,7 +4922,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
 			pass = AT_PASS_ADD_CONSTR;
 			break;
 		case AT_AddIndexConstraint: /* ADD CONSTRAINT USING INDEX */
-			ATSimplePermissions(cmd->subtype, rel, ATT_TABLE | ATT_PARTITIONED_TABLE);
+			ATSimplePermissions(cmd->subtype, rel, ATT_TABLE);
 			/* This command never recurses */
 			/* No command-specific prep needed */
 			pass = AT_PASS_ADD_INDEXCONSTR;
@@ -5583,6 +5583,7 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
 				pass = AT_PASS_ADD_INDEX;
 				break;
 			case AT_AddIndexConstraint:
+				ATSimplePermissions(cmd2->subtype, rel, ATT_TABLE);
 				/* This command never recurses */
 				/* No command-specific prep needed */
 				pass = AT_PASS_ADD_INDEXCONSTR;
@@ -5596,6 +5597,7 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
 					case CONSTR_PRIMARY:
 					case CONSTR_UNIQUE:
 					case CONSTR_EXCLUSION:
+						ATSimplePermissions(cmd2->subtype, rel, ATT_TABLE);
 						pass = AT_PASS_ADD_INDEXCONSTR;
 						break;
 					default:
@@ -9208,15 +9210,6 @@ ATExecAddIndexConstraint(AlteredTableInfo *tab, Relation rel,
 	Assert(OidIsValid(index_oid));
 	Assert(stmt->isconstraint);
 
-	/*
-	 * Doing this on partitioned tables is not a simple feature to implement,
-	 * so let's punt for now.
-	 */
-	if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
-		ereport(ERROR,
-				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-				 errmsg("ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables")));
-
 	indexRel = index_open(index_oid, AccessShareLock);
 
 	indexName = pstrdup(RelationGetRelationName(indexRel));
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac5734..bdb7731543 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1593,7 +1593,8 @@ DROP TABLE cwi_test;
 CREATE TABLE cwi_test(a int) PARTITION BY hash (a);
 create unique index on cwi_test (a);
 alter table cwi_test add primary key using index cwi_test_a_idx ;
-ERROR:  ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables
+ERROR:  ALTER action ADD CONSTRAINT cannot be performed on relation "cwi_test"
+DETAIL:  This operation is not supported for partitioned tables.
 DROP TABLE cwi_test;
 -- PRIMARY KEY constraint cannot be backed by a NULLS NOT DISTINCT index
 CREATE TABLE cwi_test(a int, b int);