Re: pg_collation_actual_version() ERROR: cache lookup failed for collation 123
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Justin Pryzby <pryzby@telsasoft.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2021-02-17T07:04:01Z
Lists: pgsql-hackers
On Wed, Feb 17, 2021 at 03:08:36PM +1300, Thomas Munro wrote:
> tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(oid));
> if (!HeapTupleIsValid(tp))
> + {
> + if (found)
> + {
> + *found = false;
> + return NULL;
> + }
> elog(ERROR, "cache lookup failed for collation %u", oid);
> + }
> collform = (Form_pg_collation) GETSTRUCT(tp);
> version = get_collation_actual_version(collform->collprovider,
> NameStr(collform->collcollate));
> + if (found)
> + *found = true;
> }
FWIW, we usually prefer using NULL instead of an error for the result
of a system function if an object cannot be found because it allows
users to not get failures in a middle of a full table scan if things
like an InvalidOid is mixed in the data set. For example, we do that
in the partition functions, for objectaddress functions, etc. That
would make this patch set simpler, switching
get_collation_version_for_oid() to just use a missing_ok argument.
And that would be more consistent with the other syscache lookup
functions we have here and there in the tree.
--
Michael
Commits
-
Tab-complete CREATE COLLATION.
- 5bc09a74719d 14.0 landed
-
Refactor get_collation_current_version().
- beb4480c853a 14.0 landed
-
pg_collation_actual_version() -> pg_collation_current_version().
- 9cf184cc0599 14.0 landed
-
Hide internal error for pg_collation_actual_version(<bad OID>).
- 0fb0a0503bfc 14.0 landed