v2-fix-alter-data-type-of-clustered-column.patch
text/x-patch
Filename: v2-fix-alter-data-type-of-clustered-column.patch
Type: text/x-patch
Part: 0
Patch
Format: unified
Series: patch v2
| File | + | − |
|---|---|---|
| src/backend/commands/tablecmds.c | 22 | 4 |
| src/test/regress/expected/alter_table.out | 13 | 0 |
| src/test/regress/sql/alter_table.sql | 16 | 0 |
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 3e83f375b5..4c0689d62e 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -12853,13 +12853,22 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
static void
RememberReplicaIdentityForRebuilding(Oid indoid, AlteredTableInfo *tab)
{
+ char *indname;
+
if (!get_index_isreplident(indoid))
return;
- if (tab->replicaIdentityIndex)
+ indname = get_rel_name(indoid);
+ if (tab->replicaIdentityIndex == NULL)
+ {
+ tab->replicaIdentityIndex = get_rel_name(indoid);
+ return;
+ }
+
+ if (strcmp(tab->replicaIdentityIndex, indname) != 0)
elog(ERROR, "relation %u has multiple indexes marked as replica identity", tab->relid);
- tab->replicaIdentityIndex = get_rel_name(indoid);
+ pfree(indname);
}
/*
@@ -12868,13 +12877,22 @@ RememberReplicaIdentityForRebuilding(Oid indoid, AlteredTableInfo *tab)
static void
RememberClusterOnForRebuilding(Oid indoid, AlteredTableInfo *tab)
{
+ char *indname;
+
if (!get_index_isclustered(indoid))
return;
- if (tab->clusterOnIndex)
+ indname = get_rel_name(indoid);
+ if (tab->clusterOnIndex == NULL)
+ {
+ tab->clusterOnIndex = indname;
+ return;
+ }
+
+ if (strcmp(tab->clusterOnIndex, indname) != 0)
elog(ERROR, "relation %u has multiple clustered indexes", tab->relid);
- tab->clusterOnIndex = get_rel_name(indoid);
+ pfree(indname);
}
/*
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index 16e0475663..53a19e38c9 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -4584,3 +4584,16 @@ drop publication pub1;
drop schema alter1 cascade;
NOTICE: drop cascades to table alter1.t1
drop schema alter2 cascade;
+/* Test case for bug #17409 */
+create table parent (p1 int constraint pk_parent primary key);
+create table child (c1 int, constraint fk_child foreign key (c1) references parent(p1));
+cluster parent using pk_parent;
+alter table parent alter column p1 set data type bigint;
+drop table child;
+drop table parent;
+create table parent (p1 int constraint pk_parent primary key);
+alter table parent replica identity using index pk_parent;
+create table child (c1 int, constraint fk_child foreign key (c1) references parent(p1));
+alter table parent alter column p1 set data type bigint;
+drop table child;
+drop table parent;
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index ac894c0602..38ed8a7134 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -3013,3 +3013,19 @@ alter table alter1.t1 set schema alter2; -- should fail
drop publication pub1;
drop schema alter1 cascade;
drop schema alter2 cascade;
+
+/* Test case for bug #17409 */
+
+create table parent (p1 int constraint pk_parent primary key);
+create table child (c1 int, constraint fk_child foreign key (c1) references parent(p1));
+cluster parent using pk_parent;
+alter table parent alter column p1 set data type bigint;
+drop table child;
+drop table parent;
+
+create table parent (p1 int constraint pk_parent primary key);
+alter table parent replica identity using index pk_parent;
+create table child (c1 int, constraint fk_child foreign key (c1) references parent(p1));
+alter table parent alter column p1 set data type bigint;
+drop table child;
+drop table parent;