Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0fb0a05

Browse filesBrowse files
committed
Hide internal error for pg_collation_actual_version(<bad OID>).
Instead of an unsightly internal "cache lookup failed" message, just return NULL for bad OIDs, as is the convention for other similar things. Reported-by: Justin Pryzby <pryzby@telsasoft.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/20210117215940.GE8560%40telsasoft.com
1 parent f05ed5a commit 0fb0a05
Copy full SHA for 0fb0a05

File tree

Expand file treeCollapse file tree

7 files changed

+33
-7
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+33
-7
lines changed

‎src/backend/catalog/index.c

Copy file name to clipboardExpand all lines: src/backend/catalog/index.c
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,8 @@ do_collation_version_check(const ObjectAddress *otherObject,
12901290
return false;
12911291

12921292
/* Ask the provider for the current version. Give up if unsupported. */
1293-
current_version = get_collation_version_for_oid(otherObject->objectId);
1293+
current_version = get_collation_version_for_oid(otherObject->objectId,
1294+
false);
12941295
if (!current_version)
12951296
return false;
12961297

@@ -1369,7 +1370,7 @@ do_collation_version_update(const ObjectAddress *otherObject,
13691370
if (OidIsValid(*coll) && otherObject->objectId != *coll)
13701371
return false;
13711372

1372-
*new_version = get_collation_version_for_oid(otherObject->objectId);
1373+
*new_version = get_collation_version_for_oid(otherObject->objectId, false);
13731374

13741375
return true;
13751376
}

‎src/backend/catalog/pg_depend.c

Copy file name to clipboardExpand all lines: src/backend/catalog/pg_depend.c
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ recordMultipleDependencies(const ObjectAddress *depender,
116116
referenced->objectId == POSIX_COLLATION_OID)
117117
continue;
118118

119-
version = get_collation_version_for_oid(referenced->objectId);
119+
version = get_collation_version_for_oid(referenced->objectId,
120+
false);
120121

121122
/*
122123
* Default collation is pinned, so we need to force recording

‎src/backend/commands/collationcmds.c

Copy file name to clipboardExpand all lines: src/backend/commands/collationcmds.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ pg_collation_actual_version(PG_FUNCTION_ARGS)
273273
Oid collid = PG_GETARG_OID(0);
274274
char *version;
275275

276-
version = get_collation_version_for_oid(collid);
276+
version = get_collation_version_for_oid(collid, true);
277277

278278
if (version)
279279
PG_RETURN_TEXT_P(cstring_to_text(version));

‎src/backend/utils/adt/pg_locale.c

Copy file name to clipboardExpand all lines: src/backend/utils/adt/pg_locale.c
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,10 +1726,11 @@ get_collation_actual_version(char collprovider, const char *collcollate)
17261726
/*
17271727
* Get provider-specific collation version string for a given collation OID.
17281728
* Return NULL if the provider doesn't support versions, or the collation is
1729-
* unversioned (for example "C").
1729+
* unversioned (for example "C"). Unknown OIDs result in NULL if missing_ok is
1730+
* true.
17301731
*/
17311732
char *
1732-
get_collation_version_for_oid(Oid oid)
1733+
get_collation_version_for_oid(Oid oid, bool missing_ok)
17331734
{
17341735
HeapTuple tp;
17351736
char *version;
@@ -1751,7 +1752,11 @@ get_collation_version_for_oid(Oid oid)
17511752

17521753
tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(oid));
17531754
if (!HeapTupleIsValid(tp))
1755+
{
1756+
if (missing_ok)
1757+
return NULL;
17541758
elog(ERROR, "cache lookup failed for collation %u", oid);
1759+
}
17551760
collform = (Form_pg_collation) GETSTRUCT(tp);
17561761
version = get_collation_actual_version(collform->collprovider,
17571762
NameStr(collform->collcollate));

‎src/include/utils/pg_locale.h

Copy file name to clipboardExpand all lines: src/include/utils/pg_locale.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ typedef struct pg_locale_struct *pg_locale_t;
103103

104104
extern pg_locale_t pg_newlocale_from_collation(Oid collid);
105105

106-
extern char *get_collation_version_for_oid(Oid collid);
106+
extern char *get_collation_version_for_oid(Oid collid, bool missing_ok);
107107

108108
#ifdef USE_ICU
109109
extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes);

‎src/test/regress/expected/collate.icu.utf8.out

Copy file name to clipboardExpand all lines: src/test/regress/expected/collate.icu.utf8.out
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,3 +2155,17 @@ DROP SCHEMA collate_tests CASCADE;
21552155
RESET client_min_messages;
21562156
-- leave a collation for pg_upgrade test
21572157
CREATE COLLATION coll_icu_upgrade FROM "und-x-icu";
2158+
-- Test user-visible function for inspecting versions
2159+
SELECT pg_collation_actual_version('"en-x-icu"'::regcollation) is not null;
2160+
?column?
2161+
----------
2162+
t
2163+
(1 row)
2164+
2165+
-- Invalid OIDs are silently ignored
2166+
SELECT pg_collation_actual_version(0) is null;
2167+
?column?
2168+
----------
2169+
t
2170+
(1 row)
2171+

‎src/test/regress/sql/collate.icu.utf8.sql

Copy file name to clipboardExpand all lines: src/test/regress/sql/collate.icu.utf8.sql
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,3 +883,8 @@ RESET client_min_messages;
883883

884884
-- leave a collation for pg_upgrade test
885885
CREATE COLLATION coll_icu_upgrade FROM "und-x-icu";
886+
887+
-- Test user-visible function for inspecting versions
888+
SELECT pg_collation_actual_version('"en-x-icu"'::regcollation) is not null;
889+
-- Invalid OIDs are silently ignored
890+
SELECT pg_collation_actual_version(0) is null;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.