Skip to content

Commit e7941a9

Browse files
committed
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.
1 parent 9db7d47 commit e7941a9

File tree

9 files changed

+19
-17
lines changed

9 files changed

+19
-17
lines changed

contrib/sepgsql/database.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ sepgsql_database_post_create(Oid databaseId, const char *dtemplate)
8888
SnapshotSelf, 1, &skey);
8989
tuple = systable_getnext(sscan);
9090
if (!HeapTupleIsValid(tuple))
91-
elog(ERROR, "catalog lookup failed for database %u", databaseId);
91+
elog(ERROR, "could not find tuple for database %u", databaseId);
9292

9393
datForm = (Form_pg_database) GETSTRUCT(tuple);
9494

contrib/sepgsql/proc.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ sepgsql_proc_post_create(Oid functionId)
6868

6969
tuple = systable_getnext(sscan);
7070
if (!HeapTupleIsValid(tuple))
71-
elog(ERROR, "catalog lookup failed for proc %u", functionId);
71+
elog(ERROR, "could not find tuple for function %u", functionId);
7272

7373
proForm = (Form_pg_proc) GETSTRUCT(tuple);
7474

@@ -261,7 +261,7 @@ sepgsql_proc_setattr(Oid functionId)
261261
SnapshotSelf, 1, &skey);
262262
newtup = systable_getnext(sscan);
263263
if (!HeapTupleIsValid(newtup))
264-
elog(ERROR, "catalog lookup failed for function %u", functionId);
264+
elog(ERROR, "could not find tuple for function %u", functionId);
265265
newform = (Form_pg_proc) GETSTRUCT(newtup);
266266

267267
/*

contrib/sepgsql/relation.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum)
8383

8484
tuple = systable_getnext(sscan);
8585
if (!HeapTupleIsValid(tuple))
86-
elog(ERROR, "catalog lookup failed for column %d of relation %u",
86+
elog(ERROR, "could not find tuple for column %d of relation %u",
8787
attnum, relOid);
8888

8989
attForm = (Form_pg_attribute) GETSTRUCT(tuple);
@@ -271,7 +271,7 @@ sepgsql_relation_post_create(Oid relOid)
271271

272272
tuple = systable_getnext(sscan);
273273
if (!HeapTupleIsValid(tuple))
274-
elog(ERROR, "catalog lookup failed for relation %u", relOid);
274+
elog(ERROR, "could not find tuple for relation %u", relOid);
275275

276276
classForm = (Form_pg_class) GETSTRUCT(tuple);
277277

@@ -623,7 +623,7 @@ sepgsql_relation_setattr(Oid relOid)
623623

624624
newtup = systable_getnext(sscan);
625625
if (!HeapTupleIsValid(newtup))
626-
elog(ERROR, "catalog lookup failed for relation %u", relOid);
626+
elog(ERROR, "could not find tuple for relation %u", relOid);
627627
newform = (Form_pg_class) GETSTRUCT(newtup);
628628

629629
/*
@@ -700,7 +700,7 @@ sepgsql_relation_setattr_extra(Relation catalog,
700700
SnapshotSelf, 1, &skey);
701701
tuple = systable_getnext(sscan);
702702
if (!HeapTupleIsValid(tuple))
703-
elog(ERROR, "catalog lookup failed for object %u in catalog \"%s\"",
703+
elog(ERROR, "could not find tuple for object %u in catalog \"%s\"",
704704
extra_oid, RelationGetRelationName(catalog));
705705

706706
datum = heap_getattr(tuple, anum_relation_id,

contrib/sepgsql/schema.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ sepgsql_schema_post_create(Oid namespaceId)
6767
SnapshotSelf, 1, &skey);
6868
tuple = systable_getnext(sscan);
6969
if (!HeapTupleIsValid(tuple))
70-
elog(ERROR, "catalog lookup failed for namespace %u", namespaceId);
70+
elog(ERROR, "could not find tuple for namespace %u", namespaceId);
7171

7272
nspForm = (Form_pg_namespace) GETSTRUCT(tuple);
7373
nsp_name = NameStr(nspForm->nspname);

src/backend/catalog/aclchk.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,7 @@ ExecGrant_Largeobject(InternalGrant *istmt)
27382738

27392739
tuple = systable_getnext(scan);
27402740
if (!HeapTupleIsValid(tuple))
2741-
elog(ERROR, "cache lookup failed for large object %u", loid);
2741+
elog(ERROR, "could not find tuple for large object %u", loid);
27422742

27432743
form_lo_meta = (Form_pg_largeobject_metadata) GETSTRUCT(tuple);
27442744

@@ -5503,7 +5503,7 @@ recordExtObjInitPriv(Oid objoid, Oid classoid)
55035503

55045504
tuple = systable_getnext(scan);
55055505
if (!HeapTupleIsValid(tuple))
5506-
elog(ERROR, "cache lookup failed for large object %u", objoid);
5506+
elog(ERROR, "could not find tuple for large object %u", objoid);
55075507

55085508
aclDatum = heap_getattr(tuple,
55095509
Anum_pg_largeobject_metadata_lomacl,

src/backend/catalog/objectaddress.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3345,7 +3345,7 @@ getObjectDescription(const ObjectAddress *object)
33453345
tuple = systable_getnext(sscan);
33463346

33473347
if (!HeapTupleIsValid(tuple))
3348-
elog(ERROR, "cache lookup failed for policy %u",
3348+
elog(ERROR, "could not find tuple for policy %u",
33493349
object->objectId);
33503350

33513351
form_policy = (Form_pg_policy) GETSTRUCT(tuple);

src/backend/catalog/partition.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,8 @@ get_partition_parent(Oid relid)
874874
NULL, 2, key);
875875

876876
tuple = systable_getnext(scan);
877-
Assert(HeapTupleIsValid(tuple));
877+
if (!HeapTupleIsValid(tuple))
878+
elog(ERROR, "could not find tuple for parent of relation %u", relid);
878879

879880
form = (Form_pg_inherits) GETSTRUCT(tuple);
880881
result = form->inhparent;

src/backend/commands/extension.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
23872387
extTup = systable_getnext(extScan);
23882388

23892389
if (!HeapTupleIsValid(extTup)) /* should not happen */
2390-
elog(ERROR, "extension with oid %u does not exist",
2390+
elog(ERROR, "could not find tuple for extension %u",
23912391
CurrentExtensionObject);
23922392

23932393
memset(repl_val, 0, sizeof(repl_val));
@@ -2535,7 +2535,7 @@ extension_config_remove(Oid extensionoid, Oid tableoid)
25352535
extTup = systable_getnext(extScan);
25362536

25372537
if (!HeapTupleIsValid(extTup)) /* should not happen */
2538-
elog(ERROR, "extension with oid %u does not exist",
2538+
elog(ERROR, "could not find tuple for extension %u",
25392539
extensionoid);
25402540

25412541
/* Search extconfig for the tableoid */
@@ -2736,7 +2736,8 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
27362736
extTup = systable_getnext(extScan);
27372737

27382738
if (!HeapTupleIsValid(extTup)) /* should not happen */
2739-
elog(ERROR, "extension with oid %u does not exist", extensionOid);
2739+
elog(ERROR, "could not find tuple for extension %u",
2740+
extensionOid);
27402741

27412742
/* Copy tuple so we can modify it below */
27422743
extTup = heap_copytuple(extTup);
@@ -3057,7 +3058,7 @@ ApplyExtensionUpdates(Oid extensionOid,
30573058
extTup = systable_getnext(extScan);
30583059

30593060
if (!HeapTupleIsValid(extTup)) /* should not happen */
3060-
elog(ERROR, "extension with oid %u does not exist",
3061+
elog(ERROR, "could not find tuple for extension %u",
30613062
extensionOid);
30623063

30633064
extForm = (Form_pg_extension) GETSTRUCT(extTup);

src/backend/utils/adt/ruleutils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
18511851
heap_close(relation, AccessShareLock);
18521852
return NULL;
18531853
}
1854-
elog(ERROR, "cache lookup failed for constraint %u", constraintId);
1854+
elog(ERROR, "could not find tuple for constraint %u", constraintId);
18551855
}
18561856

18571857
conForm = (Form_pg_constraint) GETSTRUCT(tup);

0 commit comments

Comments
 (0)