aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-06-04 16:20:03 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2017-06-04 16:20:03 -0400
commite7941a976688f0f5d13a5227ed4f3efe0718db9d (patch)
tree70ed212430cbfe514222fb70d8b8115fd695b316 /src
parent9db7d47f909482ac2b76c28f5e9a2ef48fb19b9d (diff)
downloadpostgresql-e7941a976688f0f5d13a5227ed4f3efe0718db9d.tar.gz
postgresql-e7941a976688f0f5d13a5227ed4f3efe0718db9d.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/aclchk.c4
-rw-r--r--src/backend/catalog/objectaddress.c2
-rw-r--r--src/backend/catalog/partition.c3
-rw-r--r--src/backend/commands/extension.c9
-rw-r--r--src/backend/utils/adt/ruleutils.c2
5 files changed, 11 insertions, 9 deletions
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index 387a3be701a..304e3c4bc3d 100644
--- a/src/backend/catalog/aclchk.c
+++ b/src/backend/catalog/aclchk.c
@@ -2738,7 +2738,7 @@ ExecGrant_Largeobject(InternalGrant *istmt)
tuple = systable_getnext(scan);
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);
@@ -5503,7 +5503,7 @@ recordExtObjInitPriv(Oid objoid, Oid classoid)
tuple = systable_getnext(scan);
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,
Anum_pg_largeobject_metadata_lomacl,
diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index 6bc05cab3a2..be16cf66f48 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -3345,7 +3345,7 @@ getObjectDescription(const ObjectAddress *object)
tuple = systable_getnext(sscan);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "cache lookup failed for policy %u",
+ elog(ERROR, "could not find tuple for policy %u",
object->objectId);
form_policy = (Form_pg_policy) GETSTRUCT(tuple);
diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c
index 37fa1458bef..5c5a9e11ab1 100644
--- a/src/backend/catalog/partition.c
+++ b/src/backend/catalog/partition.c
@@ -874,7 +874,8 @@ get_partition_parent(Oid relid)
NULL, 2, key);
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);
result = form->inhparent;
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
index c3718b08c17..e8126a38a9d 100644
--- a/src/backend/commands/extension.c
+++ b/src/backend/commands/extension.c
@@ -2387,7 +2387,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
extTup = systable_getnext(extScan);
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);
memset(repl_val, 0, sizeof(repl_val));
@@ -2535,7 +2535,7 @@ extension_config_remove(Oid extensionoid, Oid tableoid)
extTup = systable_getnext(extScan);
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);
/* Search extconfig for the tableoid */
@@ -2736,7 +2736,8 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
extTup = systable_getnext(extScan);
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 */
extTup = heap_copytuple(extTup);
@@ -3057,7 +3058,7 @@ ApplyExtensionUpdates(Oid extensionOid,
extTup = systable_getnext(extScan);
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);
extForm = (Form_pg_extension) GETSTRUCT(extTup);
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 824d7572faf..6a0d273bd26 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1851,7 +1851,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
heap_close(relation, AccessShareLock);
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);