Skip to content

Commit 06421b0

Browse files
committed
Remove lc_collate_is_c().
Instead just look up the collation and check collate_is_c field. Author: Andreas Karlsson Discussion: https://postgr.es/m/60929555-4709-40a7-b136-bcb44cff5a3c@proxel.se
1 parent 83eb481 commit 06421b0

File tree

8 files changed

+35
-73
lines changed

8 files changed

+35
-73
lines changed

src/backend/access/spgist/spgtextproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ spg_text_inner_consistent(PG_FUNCTION_ARGS)
427427
{
428428
spgInnerConsistentIn *in = (spgInnerConsistentIn *) PG_GETARG_POINTER(0);
429429
spgInnerConsistentOut *out = (spgInnerConsistentOut *) PG_GETARG_POINTER(1);
430-
bool collate_is_c = lc_collate_is_c(PG_GET_COLLATION());
430+
bool collate_is_c = pg_newlocale_from_collation(PG_GET_COLLATION())->collate_is_c;
431431
text *reconstructedValue;
432432
text *reconstrText;
433433
int maxReconstrLen;

src/backend/commands/collationcmds.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,9 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
377377
if (!OidIsValid(newoid))
378378
return InvalidObjectAddress;
379379

380-
/*
381-
* Check that the locales can be loaded. NB: pg_newlocale_from_collation
382-
* is only supposed to be called on non-C-equivalent locales.
383-
*/
380+
/* Check that the locales can be loaded. */
384381
CommandCounterIncrement();
385-
if (!lc_collate_is_c(newoid) || !lc_ctype_is_c(newoid))
386-
(void) pg_newlocale_from_collation(newoid);
382+
(void) pg_newlocale_from_collation(newoid);
387383

388384
ObjectAddressSet(address, CollationRelationId, newoid);
389385

src/backend/utils/adt/like_support.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ match_pattern_prefix(Node *leftop,
433433
* collation.
434434
*/
435435
if (collation_aware &&
436-
!lc_collate_is_c(indexcollation))
436+
!pg_newlocale_from_collation(indexcollation)->collate_is_c)
437437
return NIL;
438438

439439
/*
@@ -1603,7 +1603,7 @@ make_greater_string(const Const *str_const, FmgrInfo *ltproc, Oid collation)
16031603
else
16041604
workstr = TextDatumGetCString(str_const->constvalue);
16051605
len = strlen(workstr);
1606-
if (lc_collate_is_c(collation) || len == 0)
1606+
if (len == 0 || pg_newlocale_from_collation(collation)->collate_is_c)
16071607
cmpstr = str_const->constvalue;
16081608
else
16091609
{

src/backend/utils/adt/pg_locale.c

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,33 +1266,6 @@ lookup_collation_cache(Oid collation)
12661266
return cache_entry;
12671267
}
12681268

1269-
1270-
/*
1271-
* Detect whether collation's LC_COLLATE property is C
1272-
*/
1273-
bool
1274-
lc_collate_is_c(Oid collation)
1275-
{
1276-
/*
1277-
* If we're asked about "collation 0", return false, so that the code will
1278-
* go into the non-C path and report that the collation is bogus.
1279-
*/
1280-
if (!OidIsValid(collation))
1281-
return false;
1282-
1283-
/*
1284-
* If we're asked about the built-in C/POSIX collations, we know that.
1285-
*/
1286-
if (collation == C_COLLATION_OID ||
1287-
collation == POSIX_COLLATION_OID)
1288-
return true;
1289-
1290-
/*
1291-
* Otherwise, we have to consult pg_collation, but we cache that.
1292-
*/
1293-
return pg_newlocale_from_collation(collation)->collate_is_c;
1294-
}
1295-
12961269
/*
12971270
* Detect whether collation's LC_CTYPE property is C
12981271
*/
@@ -1571,12 +1544,12 @@ pg_newlocale_from_collation(Oid collid)
15711544
{
15721545
collation_cache_entry *cache_entry;
15731546

1574-
/* Callers must pass a valid OID */
1575-
Assert(OidIsValid(collid));
1576-
15771547
if (collid == DEFAULT_COLLATION_OID)
15781548
return &default_locale;
15791549

1550+
if (!OidIsValid(collid))
1551+
elog(ERROR, "cache lookup failed for collation %u", collid);
1552+
15801553
if (last_collation_cache_oid == collid)
15811554
return last_collation_cache_locale;
15821555

src/backend/utils/adt/selfuncs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4646,6 +4646,7 @@ static char *
46464646
convert_string_datum(Datum value, Oid typid, Oid collid, bool *failure)
46474647
{
46484648
char *val;
4649+
pg_locale_t mylocale;
46494650

46504651
switch (typid)
46514652
{
@@ -4671,9 +4672,10 @@ convert_string_datum(Datum value, Oid typid, Oid collid, bool *failure)
46714672
return NULL;
46724673
}
46734674

4674-
if (!lc_collate_is_c(collid))
4675+
mylocale = pg_newlocale_from_collation(collid);
4676+
4677+
if (!mylocale->collate_is_c)
46754678
{
4676-
pg_locale_t mylocale = pg_newlocale_from_collation(collid);
46774679
char *xfrmstr;
46784680
size_t xfrmlen;
46794681
size_t xfrmlen2 PG_USED_FOR_ASSERTS_ONLY;

src/backend/utils/adt/varchar.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -748,20 +748,16 @@ bpchareq(PG_FUNCTION_ARGS)
748748
len2;
749749
bool result;
750750
Oid collid = PG_GET_COLLATION();
751-
bool locale_is_c = false;
752-
pg_locale_t mylocale = 0;
751+
pg_locale_t mylocale;
753752

754753
check_collation_set(collid);
755754

756755
len1 = bcTruelen(arg1);
757756
len2 = bcTruelen(arg2);
758757

759-
if (lc_collate_is_c(collid))
760-
locale_is_c = true;
761-
else
762-
mylocale = pg_newlocale_from_collation(collid);
758+
mylocale = pg_newlocale_from_collation(collid);
763759

764-
if (locale_is_c || pg_locale_deterministic(mylocale))
760+
if (mylocale->collate_is_c || pg_locale_deterministic(mylocale))
765761
{
766762
/*
767763
* Since we only care about equality or not-equality, we can avoid all
@@ -793,20 +789,16 @@ bpcharne(PG_FUNCTION_ARGS)
793789
len2;
794790
bool result;
795791
Oid collid = PG_GET_COLLATION();
796-
bool locale_is_c = false;
797-
pg_locale_t mylocale = 0;
792+
pg_locale_t mylocale;
798793

799794
check_collation_set(collid);
800795

801796
len1 = bcTruelen(arg1);
802797
len2 = bcTruelen(arg2);
803798

804-
if (lc_collate_is_c(collid))
805-
locale_is_c = true;
806-
else
807-
mylocale = pg_newlocale_from_collation(collid);
799+
mylocale = pg_newlocale_from_collation(collid);
808800

809-
if (locale_is_c || pg_locale_deterministic(mylocale))
801+
if (mylocale->collate_is_c || pg_locale_deterministic(mylocale))
810802
{
811803
/*
812804
* Since we only care about equality or not-equality, we can avoid all

src/backend/utils/adt/varlena.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,21 +1538,20 @@ int
15381538
varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
15391539
{
15401540
int result;
1541+
pg_locale_t mylocale;
15411542

15421543
check_collation_set(collid);
15431544

1544-
if (lc_collate_is_c(collid))
1545+
mylocale = pg_newlocale_from_collation(collid);
1546+
1547+
if (mylocale->collate_is_c)
15451548
{
15461549
result = memcmp(arg1, arg2, Min(len1, len2));
15471550
if ((result == 0) && (len1 != len2))
15481551
result = (len1 < len2) ? -1 : 1;
15491552
}
15501553
else
15511554
{
1552-
pg_locale_t mylocale;
1553-
1554-
mylocale = pg_newlocale_from_collation(collid);
1555-
15561555
/*
15571556
* memcmp() can't tell us which of two unequal strings sorts first,
15581557
* but it's a cheap way to tell if they're equal. Testing shows that
@@ -1859,10 +1858,12 @@ varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)
18591858
bool abbreviate = ssup->abbreviate;
18601859
bool collate_c = false;
18611860
VarStringSortSupport *sss;
1862-
pg_locale_t locale = 0;
1861+
pg_locale_t locale;
18631862

18641863
check_collation_set(collid);
18651864

1865+
locale = pg_newlocale_from_collation(collid);
1866+
18661867
/*
18671868
* If possible, set ssup->comparator to a function which can be used to
18681869
* directly compare two datums. If we can do this, we'll avoid the
@@ -1876,7 +1877,7 @@ varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)
18761877
* varstrfastcmp_c, bpcharfastcmp_c, or namefastcmp_c, all of which use
18771878
* memcmp() rather than strcoll().
18781879
*/
1879-
if (lc_collate_is_c(collid))
1880+
if (locale->collate_is_c)
18801881
{
18811882
if (typid == BPCHAROID)
18821883
ssup->comparator = bpcharfastcmp_c;
@@ -1893,13 +1894,6 @@ varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)
18931894
}
18941895
else
18951896
{
1896-
/*
1897-
* We need a collation-sensitive comparison. To make things faster,
1898-
* we'll figure out the collation based on the locale id and cache the
1899-
* result.
1900-
*/
1901-
locale = pg_newlocale_from_collation(collid);
1902-
19031897
/*
19041898
* We use varlenafastcmp_locale except for type NAME.
19051899
*/
@@ -1950,7 +1944,10 @@ varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)
19501944
sss->last_len2 = -1;
19511945
/* Initialize */
19521946
sss->last_returned = 0;
1953-
sss->locale = locale;
1947+
if (collate_c)
1948+
sss->locale = NULL;
1949+
else
1950+
sss->locale = locale;
19541951

19551952
/*
19561953
* To avoid somehow confusing a strxfrm() blob and an original string,
@@ -2536,12 +2533,15 @@ btvarstrequalimage(PG_FUNCTION_ARGS)
25362533
{
25372534
/* Oid opcintype = PG_GETARG_OID(0); */
25382535
Oid collid = PG_GET_COLLATION();
2536+
pg_locale_t locale;
25392537

25402538
check_collation_set(collid);
25412539

2542-
if (lc_collate_is_c(collid) ||
2540+
locale = pg_newlocale_from_collation(collid);
2541+
2542+
if (locale->collate_is_c ||
25432543
collid == DEFAULT_COLLATION_OID ||
2544-
get_collation_isdeterministic(collid))
2544+
pg_locale_deterministic(locale))
25452545
PG_RETURN_BOOL(true);
25462546
else
25472547
PG_RETURN_BOOL(false);

src/include/utils/pg_locale.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ extern PGDLLIMPORT bool database_ctype_is_c;
5454
extern bool check_locale(int category, const char *locale, char **canonname);
5555
extern char *pg_perm_setlocale(int category, const char *locale);
5656

57-
extern bool lc_collate_is_c(Oid collation);
5857
extern bool lc_ctype_is_c(Oid collation);
5958

6059
/*

0 commit comments

Comments
 (0)