Simplify checks for deterministic collations.

Remove redundant checks for locale->collate_is_c now that we always
have a valid pg_locale_t.

Also, remove pg_locale_deterministic() wrapper, which is no longer
useful after commit e9931bfb75. Just check the field directly,
consistent with other fields in pg_locale_t.

Author: Andreas Karlsson
Discussion: https://postgr.es/m/60929555-4709-40a7-b136-bcb44cff5a3c@proxel.se
This commit is contained in:
Jeff Davis 2024-09-12 13:35:56 -07:00
parent 6a9fc11033
commit b0c30612c5
7 changed files with 16 additions and 28 deletions

View File

@ -279,7 +279,7 @@ hashtext(PG_FUNCTION_ARGS)
mylocale = pg_newlocale_from_collation(collid); mylocale = pg_newlocale_from_collation(collid);
if (pg_locale_deterministic(mylocale)) if (mylocale->deterministic)
{ {
result = hash_any((unsigned char *) VARDATA_ANY(key), result = hash_any((unsigned char *) VARDATA_ANY(key),
VARSIZE_ANY_EXHDR(key)); VARSIZE_ANY_EXHDR(key));
@ -334,7 +334,7 @@ hashtextextended(PG_FUNCTION_ARGS)
mylocale = pg_newlocale_from_collation(collid); mylocale = pg_newlocale_from_collation(collid);
if (pg_locale_deterministic(mylocale)) if (mylocale->deterministic)
{ {
result = hash_any_extended((unsigned char *) VARDATA_ANY(key), result = hash_any_extended((unsigned char *) VARDATA_ANY(key),
VARSIZE_ANY_EXHDR(key), VARSIZE_ANY_EXHDR(key),

View File

@ -260,7 +260,7 @@ pg_set_regex_collation(Oid collation)
{ {
locale = pg_newlocale_from_collation(collation); locale = pg_newlocale_from_collation(collation);
if (!pg_locale_deterministic(locale)) if (!locale->deterministic)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("nondeterministic collations are not supported for regular expressions"))); errmsg("nondeterministic collations are not supported for regular expressions")));

View File

@ -151,7 +151,7 @@ GenericMatchText(const char *s, int slen, const char *p, int plen, Oid collation
{ {
pg_locale_t locale = pg_newlocale_from_collation(collation); pg_locale_t locale = pg_newlocale_from_collation(collation);
if (!pg_locale_deterministic(locale)) if (!locale->deterministic)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("nondeterministic collations are not supported for LIKE"))); errmsg("nondeterministic collations are not supported for LIKE")));
@ -188,7 +188,7 @@ Generic_Text_IC_like(text *str, text *pat, Oid collation)
locale = pg_newlocale_from_collation(collation); locale = pg_newlocale_from_collation(collation);
if (!pg_locale_deterministic(locale)) if (!locale->deterministic)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("nondeterministic collations are not supported for ILIKE"))); errmsg("nondeterministic collations are not supported for ILIKE")));

View File

@ -1415,13 +1415,6 @@ make_icu_collator(const char *iculocstr,
#endif /* not USE_ICU */ #endif /* not USE_ICU */
} }
bool
pg_locale_deterministic(pg_locale_t locale)
{
return locale->deterministic;
}
/* /*
* Initialize default_locale with database locale settings. * Initialize default_locale with database locale settings.
*/ */

View File

@ -757,7 +757,7 @@ bpchareq(PG_FUNCTION_ARGS)
mylocale = pg_newlocale_from_collation(collid); mylocale = pg_newlocale_from_collation(collid);
if (mylocale->collate_is_c || pg_locale_deterministic(mylocale)) if (mylocale->deterministic)
{ {
/* /*
* Since we only care about equality or not-equality, we can avoid all * Since we only care about equality or not-equality, we can avoid all
@ -798,7 +798,7 @@ bpcharne(PG_FUNCTION_ARGS)
mylocale = pg_newlocale_from_collation(collid); mylocale = pg_newlocale_from_collation(collid);
if (mylocale->collate_is_c || pg_locale_deterministic(mylocale)) if (mylocale->deterministic)
{ {
/* /*
* Since we only care about equality or not-equality, we can avoid all * Since we only care about equality or not-equality, we can avoid all
@ -1005,7 +1005,7 @@ hashbpchar(PG_FUNCTION_ARGS)
mylocale = pg_newlocale_from_collation(collid); mylocale = pg_newlocale_from_collation(collid);
if (pg_locale_deterministic(mylocale)) if (mylocale->deterministic)
{ {
result = hash_any((unsigned char *) keydata, keylen); result = hash_any((unsigned char *) keydata, keylen);
} }
@ -1061,7 +1061,7 @@ hashbpcharextended(PG_FUNCTION_ARGS)
mylocale = pg_newlocale_from_collation(collid); mylocale = pg_newlocale_from_collation(collid);
if (pg_locale_deterministic(mylocale)) if (mylocale->deterministic)
{ {
result = hash_any_extended((unsigned char *) keydata, keylen, result = hash_any_extended((unsigned char *) keydata, keylen,
PG_GETARG_INT64(1)); PG_GETARG_INT64(1));

View File

@ -1223,7 +1223,7 @@ text_position_setup(text *t1, text *t2, Oid collid, TextPositionState *state)
mylocale = pg_newlocale_from_collation(collid); mylocale = pg_newlocale_from_collation(collid);
if (!pg_locale_deterministic(mylocale)) if (!mylocale->deterministic)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("nondeterministic collations are not supported for substring searches"))); errmsg("nondeterministic collations are not supported for substring searches")));
@ -1567,7 +1567,7 @@ varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
result = pg_strncoll(arg1, len1, arg2, len2, mylocale); result = pg_strncoll(arg1, len1, arg2, len2, mylocale);
/* Break tie if necessary. */ /* Break tie if necessary. */
if (result == 0 && pg_locale_deterministic(mylocale)) if (result == 0 && mylocale->deterministic)
{ {
result = memcmp(arg1, arg2, Min(len1, len2)); result = memcmp(arg1, arg2, Min(len1, len2));
if ((result == 0) && (len1 != len2)) if ((result == 0) && (len1 != len2))
@ -1618,7 +1618,7 @@ texteq(PG_FUNCTION_ARGS)
mylocale = pg_newlocale_from_collation(collid); mylocale = pg_newlocale_from_collation(collid);
if (pg_locale_deterministic(mylocale)) if (mylocale->deterministic)
{ {
Datum arg1 = PG_GETARG_DATUM(0); Datum arg1 = PG_GETARG_DATUM(0);
Datum arg2 = PG_GETARG_DATUM(1); Datum arg2 = PG_GETARG_DATUM(1);
@ -1673,7 +1673,7 @@ textne(PG_FUNCTION_ARGS)
mylocale = pg_newlocale_from_collation(collid); mylocale = pg_newlocale_from_collation(collid);
if (pg_locale_deterministic(mylocale)) if (mylocale->deterministic)
{ {
Datum arg1 = PG_GETARG_DATUM(0); Datum arg1 = PG_GETARG_DATUM(0);
Datum arg2 = PG_GETARG_DATUM(1); Datum arg2 = PG_GETARG_DATUM(1);
@ -1786,7 +1786,7 @@ text_starts_with(PG_FUNCTION_ARGS)
mylocale = pg_newlocale_from_collation(collid); mylocale = pg_newlocale_from_collation(collid);
if (!pg_locale_deterministic(mylocale)) if (!mylocale->deterministic)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("nondeterministic collations are not supported for substring searches"))); errmsg("nondeterministic collations are not supported for substring searches")));
@ -2200,7 +2200,7 @@ varstrfastcmp_locale(char *a1p, int len1, char *a2p, int len2, SortSupport ssup)
result = pg_strcoll(sss->buf1, sss->buf2, sss->locale); result = pg_strcoll(sss->buf1, sss->buf2, sss->locale);
/* Break tie if necessary. */ /* Break tie if necessary. */
if (result == 0 && pg_locale_deterministic(sss->locale)) if (result == 0 && sss->locale->deterministic)
result = strcmp(sss->buf1, sss->buf2); result = strcmp(sss->buf1, sss->buf2);
/* Cache result, perhaps saving an expensive strcoll() call next time */ /* Cache result, perhaps saving an expensive strcoll() call next time */
@ -2539,11 +2539,7 @@ btvarstrequalimage(PG_FUNCTION_ARGS)
locale = pg_newlocale_from_collation(collid); locale = pg_newlocale_from_collation(collid);
if (locale->collate_is_c || PG_RETURN_BOOL(locale->deterministic);
pg_locale_deterministic(locale))
PG_RETURN_BOOL(true);
else
PG_RETURN_BOOL(false);
} }
Datum Datum

View File

@ -108,7 +108,6 @@ extern void make_icu_collator(const char *iculocstr,
const char *icurules, const char *icurules,
struct pg_locale_struct *resultp); struct pg_locale_struct *resultp);
extern bool pg_locale_deterministic(pg_locale_t locale);
extern void init_database_collation(void); extern void init_database_collation(void);
extern pg_locale_t pg_newlocale_from_collation(Oid collid); extern pg_locale_t pg_newlocale_from_collation(Oid collid);