Simplify checks for deterministic collations.
authorJeff Davis <[email protected]>
Thu, 12 Sep 2024 20:35:56 +0000 (13:35 -0700)
committerJeff Davis <[email protected]>
Thu, 12 Sep 2024 20:35:56 +0000 (13:35 -0700)
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

src/backend/access/hash/hashfunc.c
src/backend/regex/regc_pg_locale.c
src/backend/utils/adt/like.c
src/backend/utils/adt/pg_locale.c
src/backend/utils/adt/varchar.c
src/backend/utils/adt/varlena.c
src/include/utils/pg_locale.h

index 2e3e5b06a61cfb54e7c398078bfaa223c0286bae..eacc146bae30dd5be70e8f723e0e1973715c9e5e 100644 (file)
@@ -279,7 +279,7 @@ hashtext(PG_FUNCTION_ARGS)
 
    mylocale = pg_newlocale_from_collation(collid);
 
-   if (pg_locale_deterministic(mylocale))
+   if (mylocale->deterministic)
    {
        result = hash_any((unsigned char *) VARDATA_ANY(key),
                          VARSIZE_ANY_EXHDR(key));
@@ -334,7 +334,7 @@ hashtextextended(PG_FUNCTION_ARGS)
 
    mylocale = pg_newlocale_from_collation(collid);
 
-   if (pg_locale_deterministic(mylocale))
+   if (mylocale->deterministic)
    {
        result = hash_any_extended((unsigned char *) VARDATA_ANY(key),
                                   VARSIZE_ANY_EXHDR(key),
index 8f34948ad37cbce3c0f27254992dced7ed132fed..b75784b6ce5aa794a3e33de6e1a043588a2f2a6d 100644 (file)
@@ -260,7 +260,7 @@ pg_set_regex_collation(Oid collation)
    {
        locale = pg_newlocale_from_collation(collation);
 
-       if (!pg_locale_deterministic(locale))
+       if (!locale->deterministic)
            ereport(ERROR,
                    (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                     errmsg("nondeterministic collations are not supported for regular expressions")));
index f87675d7557460c6ac2e86b1aab40e105823260f..286b737fd713630c2a898ff21a46b2d4292a8d5d 100644 (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);
 
-       if (!pg_locale_deterministic(locale))
+       if (!locale->deterministic)
            ereport(ERROR,
                    (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                     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);
 
-   if (!pg_locale_deterministic(locale))
+   if (!locale->deterministic)
        ereport(ERROR,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                 errmsg("nondeterministic collations are not supported for ILIKE")));
index a738da5674fe81d283c7e2683b2465a3f2689b2e..5bef1b113a8b8a4b5b0d87ec671862a89fe3efee 100644 (file)
@@ -1415,13 +1415,6 @@ make_icu_collator(const char *iculocstr,
 #endif                         /* not USE_ICU */
 }
 
-
-bool
-pg_locale_deterministic(pg_locale_t locale)
-{
-   return locale->deterministic;
-}
-
 /*
  * Initialize default_locale with database locale settings.
  */
index d2d1c5709d3e0972831e0e69331452c7772e922b..8f86aca2973f1b8a8d942d56034c42cc4f4c9ebb 100644 (file)
@@ -757,7 +757,7 @@ bpchareq(PG_FUNCTION_ARGS)
 
    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
@@ -798,7 +798,7 @@ bpcharne(PG_FUNCTION_ARGS)
 
    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
@@ -1005,7 +1005,7 @@ hashbpchar(PG_FUNCTION_ARGS)
 
    mylocale = pg_newlocale_from_collation(collid);
 
-   if (pg_locale_deterministic(mylocale))
+   if (mylocale->deterministic)
    {
        result = hash_any((unsigned char *) keydata, keylen);
    }
@@ -1061,7 +1061,7 @@ hashbpcharextended(PG_FUNCTION_ARGS)
 
    mylocale = pg_newlocale_from_collation(collid);
 
-   if (pg_locale_deterministic(mylocale))
+   if (mylocale->deterministic)
    {
        result = hash_any_extended((unsigned char *) keydata, keylen,
                                   PG_GETARG_INT64(1));
index 3658d0047b0bdcc1178b7a465ce9457dfec56581..d46ed3ccf9f1053bf44e480738446efdc12c5d3d 100644 (file)
@@ -1223,7 +1223,7 @@ text_position_setup(text *t1, text *t2, Oid collid, TextPositionState *state)
 
    mylocale = pg_newlocale_from_collation(collid);
 
-   if (!pg_locale_deterministic(mylocale))
+   if (!mylocale->deterministic)
        ereport(ERROR,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                 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);
 
        /* Break tie if necessary. */
-       if (result == 0 && pg_locale_deterministic(mylocale))
+       if (result == 0 && mylocale->deterministic)
        {
            result = memcmp(arg1, arg2, Min(len1, len2));
            if ((result == 0) && (len1 != len2))
@@ -1618,7 +1618,7 @@ texteq(PG_FUNCTION_ARGS)
 
    mylocale = pg_newlocale_from_collation(collid);
 
-   if (pg_locale_deterministic(mylocale))
+   if (mylocale->deterministic)
    {
        Datum       arg1 = PG_GETARG_DATUM(0);
        Datum       arg2 = PG_GETARG_DATUM(1);
@@ -1673,7 +1673,7 @@ textne(PG_FUNCTION_ARGS)
 
    mylocale = pg_newlocale_from_collation(collid);
 
-   if (pg_locale_deterministic(mylocale))
+   if (mylocale->deterministic)
    {
        Datum       arg1 = PG_GETARG_DATUM(0);
        Datum       arg2 = PG_GETARG_DATUM(1);
@@ -1786,7 +1786,7 @@ text_starts_with(PG_FUNCTION_ARGS)
 
    mylocale = pg_newlocale_from_collation(collid);
 
-   if (!pg_locale_deterministic(mylocale))
+   if (!mylocale->deterministic)
        ereport(ERROR,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                 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);
 
    /* Break tie if necessary. */
-   if (result == 0 && pg_locale_deterministic(sss->locale))
+   if (result == 0 && sss->locale->deterministic)
        result = strcmp(sss->buf1, sss->buf2);
 
    /* Cache result, perhaps saving an expensive strcoll() call next time */
@@ -2539,11 +2539,7 @@ btvarstrequalimage(PG_FUNCTION_ARGS)
 
    locale = pg_newlocale_from_collation(collid);
 
-   if (locale->collate_is_c ||
-       pg_locale_deterministic(locale))
-       PG_RETURN_BOOL(true);
-   else
-       PG_RETURN_BOOL(false);
+   PG_RETURN_BOOL(locale->deterministic);
 }
 
 Datum
index ab1c37a44b31b46a7fa4876826b6a86672667c71..faae868bfccff7b24518d646748b593dfbbcb462 100644 (file)
@@ -108,7 +108,6 @@ extern void make_icu_collator(const char *iculocstr,
                              const char *icurules,
                              struct pg_locale_struct *resultp);
 
-extern bool pg_locale_deterministic(pg_locale_t locale);
 extern void init_database_collation(void);
 extern pg_locale_t pg_newlocale_from_collation(Oid collid);