aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-07-16 18:17:47 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2019-07-16 18:17:47 -0400
commitf9208f2469635c372bf3c2ccfc9835dc11bd8c1c (patch)
tree9bfa38f8d1f6262ad1ffdf46057da057f1ee1ecc
parent1944a253b3aeaaeb204cbaa66f84237a81f87151 (diff)
downloadpostgresql-f9208f2469635c372bf3c2ccfc9835dc11bd8c1c.tar.gz
postgresql-f9208f2469635c372bf3c2ccfc9835dc11bd8c1c.zip
Fix thinko in construction of old_conpfeqop list.
This should lappend the OIDs, not lcons them; the existing code produced a list in reversed order. This is harmless for single-key FKs or FKs where all the key columns are of the same type, which probably explains how it went unnoticed. But if those conditions are not met, ATAddForeignKeyConstraint would make the wrong decision about whether an existing FK needs to be revalidated. I think it would almost always err in the safe direction by revalidating a constraint that didn't need it. You could imagine scenarios where the pfeqop check was fooled by swapping the types of two FK columns in one ALTER TABLE, but that case would probably be rejected by other tests, so it might be impossible to get to the worst-case scenario where an FK should be revalidated and isn't. (And even then, it's likely to be fine, unless there are weird inconsistencies in the equality behavior of the replacement types.) However, this is a performance bug at least. Noted while poking around to see whether lcons calls could be converted to lappend. This bug is old, dating to commit cb3a7c2b9, so back-patch to all supported branches.
-rw-r--r--src/backend/commands/tablecmds.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 5b487b82556..8a8095c8a00 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -6570,7 +6570,6 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel,
new_castfunc == old_castfunc &&
(!IsPolymorphicType(pfeqop_right) ||
new_fktype == old_fktype));
-
}
pfeqoperators[i] = pfeqop;
@@ -9058,7 +9057,7 @@ TryReuseForeignKey(Oid oldId, Constraint *con)
/* stash a List of the operator Oids in our Constraint node */
for (i = 0; i < numkeys; i++)
- con->old_conpfeqop = lcons_oid(rawarr[i], con->old_conpfeqop);
+ con->old_conpfeqop = lappend_oid(con->old_conpfeqop, rawarr[i]);
ReleaseSysCache(tup);
}