From d7dd247fb5ae9c3cdcf12b343b111d702d9a5bf8 Mon Sep 17 00:00:00 2001 From: Nils Dijk Date: Thu, 20 May 2021 17:55:02 +0200 Subject: [PATCH] fix shared dependencies that are not resident in a database (#4992) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DESCRIPTION: fix shared dependencies that are not resident in a database eg. databases depend on users (their owners) that both don’t have a database they reside in. These dependencies are recorded in pg_shdepend with a `dbid` of `InvalidOid` When we fetch our shared dependencies we don’t take these links in account. With this patch we use logic inspired by `classIdGetDbId` to decide when to use `MyDatabaseId` vs `InvalidOid` to correctly resolve dependencies between shared objects. --- src/backend/distributed/metadata/dependency.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/metadata/dependency.c b/src/backend/distributed/metadata/dependency.c index e57dae987..6dfa6afce 100644 --- a/src/backend/distributed/metadata/dependency.c +++ b/src/backend/distributed/metadata/dependency.c @@ -17,6 +17,7 @@ #include "access/htup_details.h" #include "access/skey.h" #include "access/sysattr.h" +#include "catalog/catalog.h" #include "catalog/dependency.h" #include "catalog/indexing.h" #include "catalog/pg_class.h" @@ -379,9 +380,19 @@ DependencyDefinitionFromPgShDepend(ObjectAddress target) /* * Scan pg_shdepend for dbid = $1 AND classid = $2 AND objid = $3 using * pg_shdepend_depender_index + * + * where $1 is decided as follows: + * - shared dependencies $1 = InvalidOid + * - other dependencies $1 = MyDatabaseId + * This is consistent with postgres' static classIdGetDbId function */ + Oid dbid = InvalidOid; + if (!IsSharedRelation(target.classId)) + { + dbid = MyDatabaseId; + } ScanKeyInit(&key[0], Anum_pg_shdepend_dbid, BTEqualStrategyNumber, F_OIDEQ, - MyDatabaseId); + ObjectIdGetDatum(dbid)); ScanKeyInit(&key[1], Anum_pg_shdepend_classid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(target.classId)); ScanKeyInit(&key[2], Anum_pg_shdepend_objid, BTEqualStrategyNumber, F_OIDEQ,