Skip to content

Navigation Menu

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 6974a8f

Browse filesBrowse files
committed
Refactor to introduce pg_locale_deterministic().
Avoids the need of callers to test for NULL, and also avoids the need to access the pg_locale_t structure directly. Reviewed-by: Peter Eisentraut, Peter Geoghegan Discussion: https://postgr.es/m/a581136455c940d7bd0ff482d3a2bd51af25a94f.camel%40j-davis.com
1 parent d87d548 commit 6974a8f
Copy full SHA for 6974a8f

File tree

7 files changed

+25
-17
lines changed
Filter options

7 files changed

+25
-17
lines changed

‎src/backend/access/hash/hashfunc.c

Copy file name to clipboardExpand all lines: src/backend/access/hash/hashfunc.c
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ hashtext(PG_FUNCTION_ARGS)
282282
if (!lc_collate_is_c(collid))
283283
mylocale = pg_newlocale_from_collation(collid);
284284

285-
if (!mylocale || mylocale->deterministic)
285+
if (pg_locale_deterministic(mylocale))
286286
{
287287
result = hash_any((unsigned char *) VARDATA_ANY(key),
288288
VARSIZE_ANY_EXHDR(key));
@@ -342,7 +342,7 @@ hashtextextended(PG_FUNCTION_ARGS)
342342
if (!lc_collate_is_c(collid))
343343
mylocale = pg_newlocale_from_collation(collid);
344344

345-
if (!mylocale || mylocale->deterministic)
345+
if (pg_locale_deterministic(mylocale))
346346
{
347347
result = hash_any_extended((unsigned char *) VARDATA_ANY(key),
348348
VARSIZE_ANY_EXHDR(key),

‎src/backend/regex/regc_pg_locale.c

Copy file name to clipboardExpand all lines: src/backend/regex/regc_pg_locale.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ pg_set_regex_collation(Oid collation)
259259
*/
260260
pg_regex_locale = pg_newlocale_from_collation(collation);
261261

262-
if (pg_regex_locale && !pg_regex_locale->deterministic)
262+
if (!pg_locale_deterministic(pg_regex_locale))
263263
ereport(ERROR,
264264
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
265265
errmsg("nondeterministic collations are not supported for regular expressions")));

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

Copy file name to clipboardExpand all lines: src/backend/utils/adt/like.c
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ GenericMatchText(const char *s, int slen, const char *p, int plen, Oid collation
155155
{
156156
pg_locale_t locale = pg_newlocale_from_collation(collation);
157157

158-
if (locale && !locale->deterministic)
158+
if (!pg_locale_deterministic(locale))
159159
ereport(ERROR,
160160
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
161161
errmsg("nondeterministic collations are not supported for LIKE")));
@@ -196,7 +196,7 @@ Generic_Text_IC_like(text *str, text *pat, Oid collation)
196196
else
197197
locale = pg_newlocale_from_collation(collation);
198198

199-
if (locale && !locale->deterministic)
199+
if (!pg_locale_deterministic(locale))
200200
ereport(ERROR,
201201
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
202202
errmsg("nondeterministic collations are not supported for ILIKE")));

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

Copy file name to clipboardExpand all lines: src/backend/utils/adt/pg_locale.c
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,15 @@ report_newlocale_failure(const char *localename)
14811481
}
14821482
#endif /* HAVE_LOCALE_T */
14831483

1484+
bool
1485+
pg_locale_deterministic(pg_locale_t locale)
1486+
{
1487+
/* default locale must always be deterministic */
1488+
if (locale == NULL)
1489+
return true;
1490+
else
1491+
return locale->deterministic;
1492+
}
14841493

14851494
/*
14861495
* Create a locale_t from a collation OID. Results are cached for the

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

Copy file name to clipboardExpand all lines: src/backend/utils/adt/varchar.c
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ bpchareq(PG_FUNCTION_ARGS)
762762
else
763763
mylocale = pg_newlocale_from_collation(collid);
764764

765-
if (locale_is_c || !mylocale || mylocale->deterministic)
765+
if (locale_is_c || pg_locale_deterministic(mylocale))
766766
{
767767
/*
768768
* Since we only care about equality or not-equality, we can avoid all
@@ -807,7 +807,7 @@ bpcharne(PG_FUNCTION_ARGS)
807807
else
808808
mylocale = pg_newlocale_from_collation(collid);
809809

810-
if (locale_is_c || !mylocale || mylocale->deterministic)
810+
if (locale_is_c || pg_locale_deterministic(mylocale))
811811
{
812812
/*
813813
* Since we only care about equality or not-equality, we can avoid all
@@ -1015,7 +1015,7 @@ hashbpchar(PG_FUNCTION_ARGS)
10151015
if (!lc_collate_is_c(collid))
10161016
mylocale = pg_newlocale_from_collation(collid);
10171017

1018-
if (!mylocale || mylocale->deterministic)
1018+
if (pg_locale_deterministic(mylocale))
10191019
{
10201020
result = hash_any((unsigned char *) keydata, keylen);
10211021
}
@@ -1077,7 +1077,7 @@ hashbpcharextended(PG_FUNCTION_ARGS)
10771077
if (!lc_collate_is_c(collid))
10781078
mylocale = pg_newlocale_from_collation(collid);
10791079

1080-
if (!mylocale || mylocale->deterministic)
1080+
if (pg_locale_deterministic(mylocale))
10811081
{
10821082
result = hash_any_extended((unsigned char *) keydata, keylen,
10831083
PG_GETARG_INT64(1));

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

Copy file name to clipboardExpand all lines: src/backend/utils/adt/varlena.c
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ text_position_setup(text *t1, text *t2, Oid collid, TextPositionState *state)
12211221
if (!lc_collate_is_c(collid))
12221222
mylocale = pg_newlocale_from_collation(collid);
12231223

1224-
if (mylocale && !mylocale->deterministic)
1224+
if (!pg_locale_deterministic(mylocale))
12251225
ereport(ERROR,
12261226
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12271227
errmsg("nondeterministic collations are not supported for substring searches")));
@@ -1572,8 +1572,7 @@ varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
15721572
result = pg_strncoll(arg1, len1, arg2, len2, mylocale);
15731573

15741574
/* Break tie if necessary. */
1575-
if (result == 0 &&
1576-
(!mylocale || mylocale->deterministic))
1575+
if (result == 0 && pg_locale_deterministic(mylocale))
15771576
{
15781577
result = memcmp(arg1, arg2, Min(len1, len2));
15791578
if ((result == 0) && (len1 != len2))
@@ -1628,7 +1627,7 @@ texteq(PG_FUNCTION_ARGS)
16281627
else
16291628
mylocale = pg_newlocale_from_collation(collid);
16301629

1631-
if (locale_is_c || !mylocale || mylocale->deterministic)
1630+
if (locale_is_c || pg_locale_deterministic(mylocale))
16321631
{
16331632
Datum arg1 = PG_GETARG_DATUM(0);
16341633
Datum arg2 = PG_GETARG_DATUM(1);
@@ -1687,7 +1686,7 @@ textne(PG_FUNCTION_ARGS)
16871686
else
16881687
mylocale = pg_newlocale_from_collation(collid);
16891688

1690-
if (locale_is_c || !mylocale || mylocale->deterministic)
1689+
if (locale_is_c || pg_locale_deterministic(mylocale))
16911690
{
16921691
Datum arg1 = PG_GETARG_DATUM(0);
16931692
Datum arg2 = PG_GETARG_DATUM(1);
@@ -1801,7 +1800,7 @@ text_starts_with(PG_FUNCTION_ARGS)
18011800
if (!lc_collate_is_c(collid))
18021801
mylocale = pg_newlocale_from_collation(collid);
18031802

1804-
if (mylocale && !mylocale->deterministic)
1803+
if (!pg_locale_deterministic(mylocale))
18051804
ereport(ERROR,
18061805
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18071806
errmsg("nondeterministic collations are not supported for substring searches")));
@@ -2217,8 +2216,7 @@ varstrfastcmp_locale(char *a1p, int len1, char *a2p, int len2, SortSupport ssup)
22172216
result = pg_strcoll(sss->buf1, sss->buf2, sss->locale);
22182217

22192218
/* Break tie if necessary. */
2220-
if (result == 0 &&
2221-
(!sss->locale || sss->locale->deterministic))
2219+
if (result == 0 && pg_locale_deterministic(sss->locale))
22222220
result = strcmp(sss->buf1, sss->buf2);
22232221

22242222
/* Cache result, perhaps saving an expensive strcoll() call next time */

‎src/include/utils/pg_locale.h

Copy file name to clipboardExpand all lines: src/include/utils/pg_locale.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ extern PGDLLIMPORT struct pg_locale_struct default_locale;
9797
extern void make_icu_collator(const char *iculocstr,
9898
struct pg_locale_struct *resultp);
9999

100+
extern bool pg_locale_deterministic(pg_locale_t locale);
100101
extern pg_locale_t pg_newlocale_from_collation(Oid collid);
101102

102103
extern char *get_collation_actual_version(char collprovider, const char *collcollate);

0 commit comments

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