Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0dd0e28

Browse files
committed
Fix ALTER COLUMN TYPE bug: it sometimes tried to drop UNIQUE or PRIMARY KEY
constraints before FOREIGN KEY constraints that depended on them. Originallyreported by Neil Conway on 29-Jun-2005. Patch by Nakano Yoshihisa.
1 parent3276e91 commit0dd0e28

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.176 2005/11/2218:17:09 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.177 2006/01/30 16:18:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -4967,12 +4967,38 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
49674967

49684968
caseOCLASS_CONSTRAINT:
49694969
Assert(foundObject.objectSubId==0);
4970-
if (!list_member_oid(tab->changedConstraintOids,foundObject.objectId))
4970+
if (!list_member_oid(tab->changedConstraintOids,
4971+
foundObject.objectId))
49714972
{
4972-
tab->changedConstraintOids=lappend_oid(tab->changedConstraintOids,
4973-
foundObject.objectId);
4974-
tab->changedConstraintDefs=lappend(tab->changedConstraintDefs,
4975-
pg_get_constraintdef_string(foundObject.objectId));
4973+
char*defstring=pg_get_constraintdef_string(foundObject.objectId);
4974+
4975+
/*
4976+
* Put NORMAL dependencies at the front of the list and
4977+
* AUTO dependencies at the back. This makes sure that
4978+
* foreign-key constraints depending on this column will
4979+
* be dropped before unique or primary-key constraints of
4980+
* the column; which we must have because the FK
4981+
* constraints depend on the indexes belonging to the
4982+
* unique constraints.
4983+
*/
4984+
if (foundDep->deptype==DEPENDENCY_NORMAL)
4985+
{
4986+
tab->changedConstraintOids=
4987+
lcons_oid(foundObject.objectId,
4988+
tab->changedConstraintOids);
4989+
tab->changedConstraintDefs=
4990+
lcons(defstring,
4991+
tab->changedConstraintDefs);
4992+
}
4993+
else
4994+
{
4995+
tab->changedConstraintOids=
4996+
lappend_oid(tab->changedConstraintOids,
4997+
foundObject.objectId);
4998+
tab->changedConstraintDefs=
4999+
lappend(tab->changedConstraintDefs,
5000+
defstring);
5001+
}
49765002
}
49775003
break;
49785004

@@ -5140,9 +5166,11 @@ ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab)
51405166

51415167
/*
51425168
* Now we can drop the existing constraints and indexes --- constraints
5143-
* first, since some of them might depend on the indexes. It should be
5144-
* okay to use DROP_RESTRICT here, since nothing else should be depending
5145-
* on these objects.
5169+
* first, since some of them might depend on the indexes. In fact, we
5170+
* have to delete FOREIGN KEY constraints before UNIQUE constraints,
5171+
* but we already ordered the constraint list to ensure that would happen.
5172+
* It should be okay to use DROP_RESTRICT here, since nothing else should
5173+
* be depending on these objects.
51465174
*/
51475175
foreach(l,tab->changedConstraintOids)
51485176
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp