aboutsummaryrefslogtreecommitdiff
path: root/src/include/utils
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2024-07-30 00:58:06 -0700
committerJeff Davis <jdavis@postgresql.org>2024-07-30 00:58:06 -0700
commit72fe6d24a38c88e112d5e63a8e907c3e96ae46ad (patch)
tree73bff00c25ec951c6fcd7781b17e1590511c895a /src/include/utils
parent9b282a9359a12831c087eba7f0f5f0b1dba7b7eb (diff)
downloadpostgresql-72fe6d24a38c88e112d5e63a8e907c3e96ae46ad.tar.gz
postgresql-72fe6d24a38c88e112d5e63a8e907c3e96ae46ad.zip
Make collation not depend on setlocale().
Now that the result of pg_newlocale_from_collation() is always non-NULL, then we can move the collate_is_c and ctype_is_c flags into pg_locale_t. That simplifies the logic in lc_collate_is_c() and lc_ctype_is_c(), removing the dependence on setlocale(). This commit also eliminates the multi-stage initialization of the collation cache. As long as we have catalog access, then it's now safe to call pg_newlocale_from_collation() without checking lc_collate_is_c() first. Discussion: https://postgr.es/m/cfd9eb85-c52a-4ec9-a90e-a5e4de56e57d@eisentraut.org Reviewed-by: Peter Eisentraut, Andreas Karlsson
Diffstat (limited to 'src/include/utils')
-rw-r--r--src/include/utils/pg_locale.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h
index 3e14a261b16..f41d33975be 100644
--- a/src/include/utils/pg_locale.h
+++ b/src/include/utils/pg_locale.h
@@ -69,11 +69,25 @@ extern void cache_locale_time(void);
/*
* We use a discriminated union to hold either a locale_t or an ICU collator.
* pg_locale_t is occasionally checked for truth, so make it a pointer.
+ *
+ * Also, hold two flags: whether the collation's LC_COLLATE or LC_CTYPE is C
+ * (or POSIX), so we can optimize a few code paths in various places. For the
+ * built-in C and POSIX collations, we can know that without even doing a
+ * cache lookup, but we want to support aliases for C/POSIX too. For the
+ * "default" collation, there are separate static cache variables, since
+ * consulting the pg_collation catalog doesn't tell us what we need.
+ *
+ * Note that some code relies on the flags not reporting false negatives
+ * (that is, saying it's not C when it is). For example, char2wchar()
+ * could fail if the locale is C, so str_tolower() shouldn't call it
+ * in that case.
*/
struct pg_locale_struct
{
char provider;
bool deterministic;
+ bool collate_is_c;
+ bool ctype_is_c;
union
{
struct