From b17812c4da47032344d12a8d72bd5e40ee4df9d8 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 31 Aug 2004 23:16:36 +0000 Subject: [PATCH] Repair 'expected both swapped tables to have TOAST tables' bug in 7.4 branch. I wasn't excited about doing this when the first report came in, but now that we have two of 'em, I suppose it had better get fixed. --- src/backend/commands/cluster.c | 53 +++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 10e82354fc..dd5d0c4c95 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -787,9 +787,8 @@ swap_relfilenodes(Oid r1, Oid r2) * their new owning relations. Otherwise the wrong one will get * dropped ... * - * NOTE: for now, we can assume the new table will have a TOAST table if - * and only if the old one does. This logic might need work if we get - * smarter about dropped columns. + * NOTE: it is possible that only one table has a toast table; this can + * happen in CLUSTER if there were dropped columns in the old table. * * NOTE: at present, a TOAST table's only dependency is the one on its * owning table. If more are ever created, we'd need to use something @@ -802,35 +801,43 @@ swap_relfilenodes(Oid r1, Oid r2) toastobject; long count; - if (!(relform1->reltoastrelid && relform2->reltoastrelid)) - elog(ERROR, "expected both swapped tables to have TOAST tables"); - /* Delete old dependencies */ - count = deleteDependencyRecordsFor(RelOid_pg_class, - relform1->reltoastrelid); - if (count != 1) - elog(ERROR, "expected one dependency record for TOAST table, found %ld", - count); - count = deleteDependencyRecordsFor(RelOid_pg_class, - relform2->reltoastrelid); - if (count != 1) - elog(ERROR, "expected one dependency record for TOAST table, found %ld", - count); + if (relform1->reltoastrelid) + { + count = deleteDependencyRecordsFor(RelOid_pg_class, + relform1->reltoastrelid); + if (count != 1) + elog(ERROR, "expected one dependency record for TOAST table, found %ld", + count); + } + if (relform2->reltoastrelid) + { + count = deleteDependencyRecordsFor(RelOid_pg_class, + relform2->reltoastrelid); + if (count != 1) + elog(ERROR, "expected one dependency record for TOAST table, found %ld", + count); + } /* Register new dependencies */ baseobject.classId = RelOid_pg_class; - baseobject.objectId = r1; baseobject.objectSubId = 0; toastobject.classId = RelOid_pg_class; - toastobject.objectId = relform1->reltoastrelid; toastobject.objectSubId = 0; - recordDependencyOn(&toastobject, &baseobject, DEPENDENCY_INTERNAL); - - baseobject.objectId = r2; - toastobject.objectId = relform2->reltoastrelid; + if (relform1->reltoastrelid) + { + baseobject.objectId = r1; + toastobject.objectId = relform1->reltoastrelid; + recordDependencyOn(&toastobject, &baseobject, DEPENDENCY_INTERNAL); + } - recordDependencyOn(&toastobject, &baseobject, DEPENDENCY_INTERNAL); + if (relform2->reltoastrelid) + { + baseobject.objectId = r2; + toastobject.objectId = relform2->reltoastrelid; + recordDependencyOn(&toastobject, &baseobject, DEPENDENCY_INTERNAL); + } } /* -- 2.39.5