1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-09 02:08:45 +03:00

Control collation behavior with a method table.

Previously, behavior branched based on the provider. A method table is
less error-prone and more flexible.

The ctype behavior will be addressed in an upcoming commit.

Reviewed-by: Andreas Karlsson
Discussion: https://postgr.es/m/2830211e1b6e6a2e26d845780b03e125281ea17b.camel%40j-davis.com
This commit is contained in:
Jeff Davis
2025-01-08 14:26:33 -08:00
parent 4f5cef2607
commit a2f17f004d
4 changed files with 180 additions and 176 deletions

View File

@@ -47,6 +47,36 @@ extern struct lconv *PGLC_localeconv(void);
extern void cache_locale_time(void);
struct pg_locale_struct;
typedef struct pg_locale_struct *pg_locale_t;
/* methods that define collation behavior */
struct collate_methods
{
/* required */
int (*strncoll) (const char *arg1, ssize_t len1,
const char *arg2, ssize_t len2,
pg_locale_t locale);
/* required */
size_t (*strnxfrm) (char *dest, size_t destsize,
const char *src, ssize_t srclen,
pg_locale_t locale);
/* optional */
size_t (*strnxfrm_prefix) (char *dest, size_t destsize,
const char *src, ssize_t srclen,
pg_locale_t locale);
/*
* If the strnxfrm method is not trusted to return the correct results,
* set strxfrm_is_safe to false. It set to false, the method will not be
* used in most cases, but the planner still expects it to be there for
* estimation purposes (where incorrect results are acceptable).
*/
bool strxfrm_is_safe;
};
/*
* 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.
@@ -70,6 +100,9 @@ struct pg_locale_struct
bool collate_is_c;
bool ctype_is_c;
bool is_default;
const struct collate_methods *collate; /* NULL if collate_is_c */
union
{
struct