alter_drop_constr_hot.patch
text/x-patch
Filename: alter_drop_constr_hot.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: context
| File | + | − |
|---|---|---|
| src/backend/commands/tablecmds.c | 9 | 0 |
| src/test/regress/expected/alter_table.out | 7 | 0 |
| src/test/regress/sql/alter_table.sql | 7 | 0 |
*** a/src/backend/commands/tablecmds.c
--- b/src/backend/commands/tablecmds.c
***************
*** 6734,6739 **** ATExecDropConstraint(Relation rel, const char *constrName,
--- 6734,6740 ----
{
Oid childrelid = lfirst_oid(child);
Relation childrel;
+ bool updated = false;
/* find_inheritance_children already got lock */
childrel = heap_open(childrelid, NoLock);
***************
*** 6790,6798 **** ATExecDropConstraint(Relation rel, const char *constrName,
con->coninhcount--;
simple_heap_update(conrel, ©_tuple->t_self, copy_tuple);
CatalogUpdateIndexes(conrel, copy_tuple);
!
! /* Make update visible */
! CommandCounterIncrement();
}
}
else
--- 6791,6798 ----
con->coninhcount--;
simple_heap_update(conrel, ©_tuple->t_self, copy_tuple);
CatalogUpdateIndexes(conrel, copy_tuple);
! /* need to call CommandCounterIncrement() */
! updated = true;
}
}
else
***************
*** 6807,6815 **** ATExecDropConstraint(Relation rel, const char *constrName,
simple_heap_update(conrel, ©_tuple->t_self, copy_tuple);
CatalogUpdateIndexes(conrel, copy_tuple);
!
! /* Make update visible */
! CommandCounterIncrement();
}
heap_freetuple(copy_tuple);
--- 6807,6814 ----
simple_heap_update(conrel, ©_tuple->t_self, copy_tuple);
CatalogUpdateIndexes(conrel, copy_tuple);
! /* need to call CommandCounterIncrement() */
! updated = true;
}
heap_freetuple(copy_tuple);
***************
*** 6824,6829 **** ATExecDropConstraint(Relation rel, const char *constrName,
--- 6823,6832 ----
constrName,
RelationGetRelationName(childrel))));
+ /* Make update visible */
+ if (updated)
+ CommandCounterIncrement();
+
heap_close(childrel, NoLock);
}
*** a/src/test/regress/expected/alter_table.out
--- b/src/test/regress/expected/alter_table.out
***************
*** 2103,2105 **** ALTER TABLE tt7 NOT OF;
--- 2103,2112 ----
x | integer |
y | numeric(8,2) |
+ -- make sure we can drop a constraint on the parent but it remains on the child
+ create table test_drop_constr_parent (c text check (c is not null));
+ create table test_drop_constr_child () inherits (test_drop_constr_parent);
+ alter table only test_drop_constr_parent drop constraint "test_drop_constr_parent_c_check";
+ -- should fail
+ insert into test_drop_constr_child (c) values (NULL);
+ ERROR: new row for relation "test_drop_constr_child" violates check constraint "test_drop_constr_parent_c_check"
*** a/src/test/regress/sql/alter_table.sql
--- b/src/test/regress/sql/alter_table.sql
***************
*** 1456,1458 **** CREATE TYPE tt_t1 AS (x int, y numeric(8,2));
--- 1456,1465 ----
ALTER TABLE tt7 OF tt_t1; -- reassign an already-typed table
ALTER TABLE tt7 NOT OF;
\d tt7
+
+ -- make sure we can drop a constraint on the parent but it remains on the child
+ create table test_drop_constr_parent (c text check (c is not null));
+ create table test_drop_constr_child () inherits (test_drop_constr_parent);
+ alter table only test_drop_constr_parent drop constraint "test_drop_constr_parent_c_check";
+ -- should fail
+ insert into test_drop_constr_child (c) values (NULL);