Commit e7941a97 authored by Tom Lane's avatar Tom Lane

Replace over-optimistic Assert in partitioning code with a runtime test.

get_partition_parent felt that it could simply Assert that systable_getnext
found a tuple.  This is unlike any other caller of that function, and it's
unsafe IMO --- in fact, the reason I noticed it was that the Assert failed.
(OK, I was working with known-inconsistent catalog contents, but I wasn't
expecting the DB to fall over quite that violently.  The behavior in a
non-assert-enabled build wouldn't be very nice, either.)  Fix it to do what
other callers do, namely an actual runtime-test-and-elog.

Also, standardize the wording of elog messages that are complaining about
unexpected failure of systable_getnext.  90% of them say "could not find
tuple for <object>", so make the remainder do likewise.  Many of the
holdouts were using the phrasing "cache lookup failed", which is outright
misleading since no catcache search is involved.
parent 9db7d47f
...@@ -88,7 +88,7 @@ sepgsql_database_post_create(Oid databaseId, const char *dtemplate) ...@@ -88,7 +88,7 @@ sepgsql_database_post_create(Oid databaseId, const char *dtemplate)
SnapshotSelf, 1, &skey); SnapshotSelf, 1, &skey);
tuple = systable_getnext(sscan); tuple = systable_getnext(sscan);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "catalog lookup failed for database %u", databaseId); elog(ERROR, "could not find tuple for database %u", databaseId);
datForm = (Form_pg_database) GETSTRUCT(tuple); datForm = (Form_pg_database) GETSTRUCT(tuple);
......
...@@ -68,7 +68,7 @@ sepgsql_proc_post_create(Oid functionId) ...@@ -68,7 +68,7 @@ sepgsql_proc_post_create(Oid functionId)
tuple = systable_getnext(sscan); tuple = systable_getnext(sscan);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "catalog lookup failed for proc %u", functionId); elog(ERROR, "could not find tuple for function %u", functionId);
proForm = (Form_pg_proc) GETSTRUCT(tuple); proForm = (Form_pg_proc) GETSTRUCT(tuple);
...@@ -261,7 +261,7 @@ sepgsql_proc_setattr(Oid functionId) ...@@ -261,7 +261,7 @@ sepgsql_proc_setattr(Oid functionId)
SnapshotSelf, 1, &skey); SnapshotSelf, 1, &skey);
newtup = systable_getnext(sscan); newtup = systable_getnext(sscan);
if (!HeapTupleIsValid(newtup)) if (!HeapTupleIsValid(newtup))
elog(ERROR, "catalog lookup failed for function %u", functionId); elog(ERROR, "could not find tuple for function %u", functionId);
newform = (Form_pg_proc) GETSTRUCT(newtup); newform = (Form_pg_proc) GETSTRUCT(newtup);
/* /*
......
...@@ -83,7 +83,7 @@ sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum) ...@@ -83,7 +83,7 @@ sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum)
tuple = systable_getnext(sscan); tuple = systable_getnext(sscan);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "catalog lookup failed for column %d of relation %u", elog(ERROR, "could not find tuple for column %d of relation %u",
attnum, relOid); attnum, relOid);
attForm = (Form_pg_attribute) GETSTRUCT(tuple); attForm = (Form_pg_attribute) GETSTRUCT(tuple);
...@@ -271,7 +271,7 @@ sepgsql_relation_post_create(Oid relOid) ...@@ -271,7 +271,7 @@ sepgsql_relation_post_create(Oid relOid)
tuple = systable_getnext(sscan); tuple = systable_getnext(sscan);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "catalog lookup failed for relation %u", relOid); elog(ERROR, "could not find tuple for relation %u", relOid);
classForm = (Form_pg_class) GETSTRUCT(tuple); classForm = (Form_pg_class) GETSTRUCT(tuple);
...@@ -623,7 +623,7 @@ sepgsql_relation_setattr(Oid relOid) ...@@ -623,7 +623,7 @@ sepgsql_relation_setattr(Oid relOid)
newtup = systable_getnext(sscan); newtup = systable_getnext(sscan);
if (!HeapTupleIsValid(newtup)) if (!HeapTupleIsValid(newtup))
elog(ERROR, "catalog lookup failed for relation %u", relOid); elog(ERROR, "could not find tuple for relation %u", relOid);
newform = (Form_pg_class) GETSTRUCT(newtup); newform = (Form_pg_class) GETSTRUCT(newtup);
/* /*
...@@ -700,7 +700,7 @@ sepgsql_relation_setattr_extra(Relation catalog, ...@@ -700,7 +700,7 @@ sepgsql_relation_setattr_extra(Relation catalog,
SnapshotSelf, 1, &skey); SnapshotSelf, 1, &skey);
tuple = systable_getnext(sscan); tuple = systable_getnext(sscan);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "catalog lookup failed for object %u in catalog \"%s\"", elog(ERROR, "could not find tuple for object %u in catalog \"%s\"",
extra_oid, RelationGetRelationName(catalog)); extra_oid, RelationGetRelationName(catalog));
datum = heap_getattr(tuple, anum_relation_id, datum = heap_getattr(tuple, anum_relation_id,
......
...@@ -67,7 +67,7 @@ sepgsql_schema_post_create(Oid namespaceId) ...@@ -67,7 +67,7 @@ sepgsql_schema_post_create(Oid namespaceId)
SnapshotSelf, 1, &skey); SnapshotSelf, 1, &skey);
tuple = systable_getnext(sscan); tuple = systable_getnext(sscan);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "catalog lookup failed for namespace %u", namespaceId); elog(ERROR, "could not find tuple for namespace %u", namespaceId);
nspForm = (Form_pg_namespace) GETSTRUCT(tuple); nspForm = (Form_pg_namespace) GETSTRUCT(tuple);
nsp_name = NameStr(nspForm->nspname); nsp_name = NameStr(nspForm->nspname);
......
...@@ -2738,7 +2738,7 @@ ExecGrant_Largeobject(InternalGrant *istmt) ...@@ -2738,7 +2738,7 @@ ExecGrant_Largeobject(InternalGrant *istmt)
tuple = systable_getnext(scan); tuple = systable_getnext(scan);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for large object %u", loid); elog(ERROR, "could not find tuple for large object %u", loid);
form_lo_meta = (Form_pg_largeobject_metadata) GETSTRUCT(tuple); form_lo_meta = (Form_pg_largeobject_metadata) GETSTRUCT(tuple);
...@@ -5503,7 +5503,7 @@ recordExtObjInitPriv(Oid objoid, Oid classoid) ...@@ -5503,7 +5503,7 @@ recordExtObjInitPriv(Oid objoid, Oid classoid)
tuple = systable_getnext(scan); tuple = systable_getnext(scan);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for large object %u", objoid); elog(ERROR, "could not find tuple for large object %u", objoid);
aclDatum = heap_getattr(tuple, aclDatum = heap_getattr(tuple,
Anum_pg_largeobject_metadata_lomacl, Anum_pg_largeobject_metadata_lomacl,
......
...@@ -3345,7 +3345,7 @@ getObjectDescription(const ObjectAddress *object) ...@@ -3345,7 +3345,7 @@ getObjectDescription(const ObjectAddress *object)
tuple = systable_getnext(sscan); tuple = systable_getnext(sscan);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for policy %u", elog(ERROR, "could not find tuple for policy %u",
object->objectId); object->objectId);
form_policy = (Form_pg_policy) GETSTRUCT(tuple); form_policy = (Form_pg_policy) GETSTRUCT(tuple);
......
...@@ -874,7 +874,8 @@ get_partition_parent(Oid relid) ...@@ -874,7 +874,8 @@ get_partition_parent(Oid relid)
NULL, 2, key); NULL, 2, key);
tuple = systable_getnext(scan); tuple = systable_getnext(scan);
Assert(HeapTupleIsValid(tuple)); if (!HeapTupleIsValid(tuple))
elog(ERROR, "could not find tuple for parent of relation %u", relid);
form = (Form_pg_inherits) GETSTRUCT(tuple); form = (Form_pg_inherits) GETSTRUCT(tuple);
result = form->inhparent; result = form->inhparent;
......
...@@ -2387,7 +2387,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS) ...@@ -2387,7 +2387,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
extTup = systable_getnext(extScan); extTup = systable_getnext(extScan);
if (!HeapTupleIsValid(extTup)) /* should not happen */ if (!HeapTupleIsValid(extTup)) /* should not happen */
elog(ERROR, "extension with oid %u does not exist", elog(ERROR, "could not find tuple for extension %u",
CurrentExtensionObject); CurrentExtensionObject);
memset(repl_val, 0, sizeof(repl_val)); memset(repl_val, 0, sizeof(repl_val));
...@@ -2535,7 +2535,7 @@ extension_config_remove(Oid extensionoid, Oid tableoid) ...@@ -2535,7 +2535,7 @@ extension_config_remove(Oid extensionoid, Oid tableoid)
extTup = systable_getnext(extScan); extTup = systable_getnext(extScan);
if (!HeapTupleIsValid(extTup)) /* should not happen */ if (!HeapTupleIsValid(extTup)) /* should not happen */
elog(ERROR, "extension with oid %u does not exist", elog(ERROR, "could not find tuple for extension %u",
extensionoid); extensionoid);
/* Search extconfig for the tableoid */ /* Search extconfig for the tableoid */
...@@ -2736,7 +2736,8 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o ...@@ -2736,7 +2736,8 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
extTup = systable_getnext(extScan); extTup = systable_getnext(extScan);
if (!HeapTupleIsValid(extTup)) /* should not happen */ if (!HeapTupleIsValid(extTup)) /* should not happen */
elog(ERROR, "extension with oid %u does not exist", extensionOid); elog(ERROR, "could not find tuple for extension %u",
extensionOid);
/* Copy tuple so we can modify it below */ /* Copy tuple so we can modify it below */
extTup = heap_copytuple(extTup); extTup = heap_copytuple(extTup);
...@@ -3057,7 +3058,7 @@ ApplyExtensionUpdates(Oid extensionOid, ...@@ -3057,7 +3058,7 @@ ApplyExtensionUpdates(Oid extensionOid,
extTup = systable_getnext(extScan); extTup = systable_getnext(extScan);
if (!HeapTupleIsValid(extTup)) /* should not happen */ if (!HeapTupleIsValid(extTup)) /* should not happen */
elog(ERROR, "extension with oid %u does not exist", elog(ERROR, "could not find tuple for extension %u",
extensionOid); extensionOid);
extForm = (Form_pg_extension) GETSTRUCT(extTup); extForm = (Form_pg_extension) GETSTRUCT(extTup);
......
...@@ -1851,7 +1851,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, ...@@ -1851,7 +1851,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
heap_close(relation, AccessShareLock); heap_close(relation, AccessShareLock);
return NULL; return NULL;
} }
elog(ERROR, "cache lookup failed for constraint %u", constraintId); elog(ERROR, "could not find tuple for constraint %u", constraintId);
} }
conForm = (Form_pg_constraint) GETSTRUCT(tup); conForm = (Form_pg_constraint) GETSTRUCT(tup);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment