Not read heaptuple after closing pg_rewrite (#5255)

(cherry picked from commit cc49e63222)
pull/5978/head
Onur Tirtir 2021-09-08 14:03:17 +03:00
parent 5f5e5ef471
commit 30b46975b8
1 changed files with 18 additions and 5 deletions

View File

@ -1204,18 +1204,31 @@ GetDependingView(Form_pg_depend pg_depend)
true, NULL, 1, rkey);
HeapTuple rewriteTup = systable_getnext(rscan);
if (!HeapTupleIsValid(rewriteTup))
{
/*
* This function already verified that objid's classid is
* RewriteRelationId, so it should exists. But be on the
* safe side.
*/
ereport(ERROR, (errmsg("catalog lookup failed for view %u",
pg_depend->objid)));
}
Form_pg_rewrite pg_rewrite = (Form_pg_rewrite) GETSTRUCT(rewriteTup);
bool isView = get_rel_relkind(pg_rewrite->ev_class) == RELKIND_VIEW;
bool isMatView = get_rel_relkind(pg_rewrite->ev_class) == RELKIND_MATVIEW;
bool isDifferentThanRef = pg_rewrite->ev_class != pg_depend->refobjid;
Oid dependingView = InvalidOid;
if ((isView || isMatView) && isDifferentThanRef)
{
dependingView = pg_rewrite->ev_class;
}
systable_endscan(rscan);
relation_close(rewriteRel, AccessShareLock);
if ((isView || isMatView) && isDifferentThanRef)
{
return pg_rewrite->ev_class;
}
return InvalidOid;
return dependingView;
}