fix shared dependencies that are not resident in a database (#4992)

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.
pull/4997/head
Nils Dijk 2021-05-20 17:55:02 +02:00 committed by GitHub
parent b25d3e83ef
commit d7dd247fb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -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,