{
        spgInnerConsistentIn *in = (spgInnerConsistentIn *) PG_GETARG_POINTER(0);
        spgInnerConsistentOut *out = (spgInnerConsistentOut *) PG_GETARG_POINTER(1);
-       bool            collate_is_c = lc_collate_is_c(PG_GET_COLLATION());
+       bool            collate_is_c = pg_newlocale_from_collation(PG_GET_COLLATION())->collate_is_c;
        text       *reconstructedValue;
        text       *reconstrText;
        int                     maxReconstrLen;
 
        if (!OidIsValid(newoid))
                return InvalidObjectAddress;
 
-       /*
-        * Check that the locales can be loaded.  NB: pg_newlocale_from_collation
-        * is only supposed to be called on non-C-equivalent locales.
-        */
+       /* Check that the locales can be loaded. */
        CommandCounterIncrement();
-       if (!lc_collate_is_c(newoid) || !lc_ctype_is_c(newoid))
-               (void) pg_newlocale_from_collation(newoid);
+       (void) pg_newlocale_from_collation(newoid);
 
        ObjectAddressSet(address, CollationRelationId, newoid);
 
 
         * collation.
         */
        if (collation_aware &&
-               !lc_collate_is_c(indexcollation))
+               !pg_newlocale_from_collation(indexcollation)->collate_is_c)
                return NIL;
 
        /*
                else
                        workstr = TextDatumGetCString(str_const->constvalue);
                len = strlen(workstr);
-               if (lc_collate_is_c(collation) || len == 0)
+               if (len == 0 || pg_newlocale_from_collation(collation)->collate_is_c)
                        cmpstr = str_const->constvalue;
                else
                {
 
        return cache_entry;
 }
 
-
-/*
- * Detect whether collation's LC_COLLATE property is C
- */
-bool
-lc_collate_is_c(Oid collation)
-{
-       /*
-        * If we're asked about "collation 0", return false, so that the code will
-        * go into the non-C path and report that the collation is bogus.
-        */
-       if (!OidIsValid(collation))
-               return false;
-
-       /*
-        * If we're asked about the built-in C/POSIX collations, we know that.
-        */
-       if (collation == C_COLLATION_OID ||
-               collation == POSIX_COLLATION_OID)
-               return true;
-
-       /*
-        * Otherwise, we have to consult pg_collation, but we cache that.
-        */
-       return pg_newlocale_from_collation(collation)->collate_is_c;
-}
-
 /*
  * Detect whether collation's LC_CTYPE property is C
  */
 {
        collation_cache_entry *cache_entry;
 
-       /* Callers must pass a valid OID */
-       Assert(OidIsValid(collid));
-
        if (collid == DEFAULT_COLLATION_OID)
                return &default_locale;
 
+       if (!OidIsValid(collid))
+               elog(ERROR, "cache lookup failed for collation %u", collid);
+
        if (last_collation_cache_oid == collid)
                return last_collation_cache_locale;
 
 
 convert_string_datum(Datum value, Oid typid, Oid collid, bool *failure)
 {
        char       *val;
+       pg_locale_t mylocale;
 
        switch (typid)
        {
                        return NULL;
        }
 
-       if (!lc_collate_is_c(collid))
+       mylocale = pg_newlocale_from_collation(collid);
+
+       if (!mylocale->collate_is_c)
        {
-               pg_locale_t mylocale = pg_newlocale_from_collation(collid);
                char       *xfrmstr;
                size_t          xfrmlen;
                size_t          xfrmlen2 PG_USED_FOR_ASSERTS_ONLY;
 
                                len2;
        bool            result;
        Oid                     collid = PG_GET_COLLATION();
-       bool            locale_is_c = false;
-       pg_locale_t mylocale = 0;
+       pg_locale_t mylocale;
 
        check_collation_set(collid);
 
        len1 = bcTruelen(arg1);
        len2 = bcTruelen(arg2);
 
-       if (lc_collate_is_c(collid))
-               locale_is_c = true;
-       else
-               mylocale = pg_newlocale_from_collation(collid);
+       mylocale = pg_newlocale_from_collation(collid);
 
-       if (locale_is_c || pg_locale_deterministic(mylocale))
+       if (mylocale->collate_is_c || pg_locale_deterministic(mylocale))
        {
                /*
                 * Since we only care about equality or not-equality, we can avoid all
                                len2;
        bool            result;
        Oid                     collid = PG_GET_COLLATION();
-       bool            locale_is_c = false;
-       pg_locale_t mylocale = 0;
+       pg_locale_t mylocale;
 
        check_collation_set(collid);
 
        len1 = bcTruelen(arg1);
        len2 = bcTruelen(arg2);
 
-       if (lc_collate_is_c(collid))
-               locale_is_c = true;
-       else
-               mylocale = pg_newlocale_from_collation(collid);
+       mylocale = pg_newlocale_from_collation(collid);
 
-       if (locale_is_c || pg_locale_deterministic(mylocale))
+       if (mylocale->collate_is_c || pg_locale_deterministic(mylocale))
        {
                /*
                 * Since we only care about equality or not-equality, we can avoid all
 
 varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
 {
        int                     result;
+       pg_locale_t mylocale;
 
        check_collation_set(collid);
 
-       if (lc_collate_is_c(collid))
+       mylocale = pg_newlocale_from_collation(collid);
+
+       if (mylocale->collate_is_c)
        {
                result = memcmp(arg1, arg2, Min(len1, len2));
                if ((result == 0) && (len1 != len2))
        }
        else
        {
-               pg_locale_t mylocale;
-
-               mylocale = pg_newlocale_from_collation(collid);
-
                /*
                 * memcmp() can't tell us which of two unequal strings sorts first,
                 * but it's a cheap way to tell if they're equal.  Testing shows that
        bool            abbreviate = ssup->abbreviate;
        bool            collate_c = false;
        VarStringSortSupport *sss;
-       pg_locale_t locale = 0;
+       pg_locale_t locale;
 
        check_collation_set(collid);
 
+       locale = pg_newlocale_from_collation(collid);
+
        /*
         * If possible, set ssup->comparator to a function which can be used to
         * directly compare two datums.  If we can do this, we'll avoid the
         * varstrfastcmp_c, bpcharfastcmp_c, or namefastcmp_c, all of which use
         * memcmp() rather than strcoll().
         */
-       if (lc_collate_is_c(collid))
+       if (locale->collate_is_c)
        {
                if (typid == BPCHAROID)
                        ssup->comparator = bpcharfastcmp_c;
        }
        else
        {
-               /*
-                * We need a collation-sensitive comparison.  To make things faster,
-                * we'll figure out the collation based on the locale id and cache the
-                * result.
-                */
-               locale = pg_newlocale_from_collation(collid);
-
                /*
                 * We use varlenafastcmp_locale except for type NAME.
                 */
                sss->last_len2 = -1;
                /* Initialize */
                sss->last_returned = 0;
-               sss->locale = locale;
+               if (collate_c)
+                       sss->locale = NULL;
+               else
+                       sss->locale = locale;
 
                /*
                 * To avoid somehow confusing a strxfrm() blob and an original string,
 {
        /* Oid          opcintype = PG_GETARG_OID(0); */
        Oid                     collid = PG_GET_COLLATION();
+       pg_locale_t locale;
 
        check_collation_set(collid);
 
-       if (lc_collate_is_c(collid) ||
+       locale = pg_newlocale_from_collation(collid);
+
+       if (locale->collate_is_c ||
                collid == DEFAULT_COLLATION_OID ||
-               get_collation_isdeterministic(collid))
+               pg_locale_deterministic(locale))
                PG_RETURN_BOOL(true);
        else
                PG_RETURN_BOOL(false);
 
 extern bool check_locale(int category, const char *locale, char **canonname);
 extern char *pg_perm_setlocale(int category, const char *locale);
 
-extern bool lc_collate_is_c(Oid collation);
 extern bool lc_ctype_is_c(Oid collation);
 
 /*