From 8f5bb5300a725931d98b4ade6a25f7e02b093f41 Mon Sep 17 00:00:00 2001 From: Colin Zhao Date: Fri, 1 Mar 2024 13:13:38 +0800 Subject: [PATCH] Check if PgIvmImmvRelationId is invalid before open it (#78) When pg_ivm is installed shared_preload_libraries without executing CREATE EXTENSION command, the hook function is set while the catalog table pg_ivm_immv is not created. In this case, the hook function failed to open the catalog table and an error was raised. Although this way of installing pg_ivm was not considered, it would be nice to reduce any possible troubles on users. Therefore, to prevent this error, check if PgIvmImmvRelationId is invalid before open it. When this is invalid, pg_ivm_immv relation is not created yet, so there are not any IMMVs, so we don't have to do anything in this hook function. Review and commit message by Yugo Nagata --- pg_ivm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pg_ivm.c b/pg_ivm.c index 33b99c6..ba14888 100644 --- a/pg_ivm.c +++ b/pg_ivm.c @@ -385,11 +385,16 @@ PgIvmObjectAccessHook(ObjectAccessType access, Oid classId, if (access == OAT_DROP && classId == RelationRelationId && !OidIsValid(subId)) { - Relation pgIvmImmv = table_open(PgIvmImmvRelationId(), AccessShareLock); + Relation pgIvmImmv; SysScanDesc scan; ScanKeyData key; HeapTuple tup; - + Oid pgIvmImmvOid = PgIvmImmvRelationId(); + + if (pgIvmImmvOid == InvalidOid) + return; + + pgIvmImmv = table_open(pgIvmImmvOid, AccessShareLock); ScanKeyInit(&key, Anum_pg_ivm_immv_immvrelid, BTEqualStrategyNumber, F_OIDEQ,