mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +03:00
Don't error out when dropping constraint if relchecks is already zero
I have never seen this be a problem in practice, but it came up when purposely corrupting catalog contents to study the fix for a nearby bug: we'd try to decrement relchecks, but since it's zero we error out and fail to drop the constraint. The fix is to downgrade the error to warning, skip decrementing the counter, and otherwise proceed normally. Given lack of field complaints, no backpatch. Author: Álvaro Herrera <alvherre@kurilemu.de> Discussion: https://postgr.es/m/202508291058.q2zscdcs64fj@alvherre.pgsql
This commit is contained in:
@@ -937,10 +937,12 @@ RemoveConstraintById(Oid conId)
|
|||||||
con->conrelid);
|
con->conrelid);
|
||||||
classForm = (Form_pg_class) GETSTRUCT(relTup);
|
classForm = (Form_pg_class) GETSTRUCT(relTup);
|
||||||
|
|
||||||
if (classForm->relchecks == 0) /* should not happen */
|
if (classForm->relchecks > 0)
|
||||||
elog(ERROR, "relation \"%s\" has relchecks = 0",
|
classForm->relchecks--;
|
||||||
RelationGetRelationName(rel));
|
else
|
||||||
classForm->relchecks--;
|
/* should not happen */
|
||||||
|
elog(WARNING, "relation \"%s\" has relchecks = %d",
|
||||||
|
RelationGetRelationName(rel), classForm->relchecks);
|
||||||
|
|
||||||
CatalogTupleUpdate(pgrel, &relTup->t_self, relTup);
|
CatalogTupleUpdate(pgrel, &relTup->t_self, relTup);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user