make tsearch use the database default locale
Jeff Davis <pgsql@j-davis.com>
From: Jeff Davis <pgsql@j-davis.com>
To: pgsql-hackers@postgresql.org
Date: 2025-10-07T22:49:55Z
Lists: pgsql-hackers
Attachments
- v1-0001-Rename-static-functions-pg_wc_xyz-to-regc_wc_xyz.patch (text/x-patch) patch v1-0001
- v1-0002-Add-pg_wc_xyz-exported-functions.patch (text/x-patch) patch v1-0002
- v1-0003-Add-pg_wc_isxdigit-useful-for-tsearch.patch (text/x-patch) patch v1-0003
- v1-0004-Add-pg_database_locale-to-retrieve-database-defau.patch (text/x-patch) patch v1-0004
- v1-0005-tsearch-use-database-default-collation-for-parsin.patch (text/x-patch) patch v1-0005
- v1-0006-Remove-obsolete-global-database_ctype_is_c.patch (text/x-patch) patch v1-0006
tsvector and tsquery are not collatable types, but they do need locale information to parse the original text. It would not do any good to make it a collatable type, because a COLLATE clause would typically be applied after the parsing is done. Previously, tsearch used the database CTYPE for parsing, but that's not good because it creates an unnecessary dependency on libc even when the user has requested another provider. This patch series allows tsearch to use the database default locale for parsing. If the database collation is libc, there's no change. Motivation: (a) it reduces the dependence on setlocale(), which is not thread- safe; (b) if a user is using the builtin or ICU providers, understanding the effects of LC_CTYPE can be very confusing; (c) it would allow us to test more of the tsearch parsing behavior. Notes: * Should have the the exact same behavior as before if the database locale provider is libc. If the database locale provider is builtin or ICU, then there will be some differences in tsearch parsing behavior. * Most of the patches are straightforward, but v1-0005 might need extra attention. There are quite a few cases there with subtle distinctions, and I might have missed something. For example, in the "C" locale, tsearch treats non-ascii characters as alpha, even though the libc functions do not do so (I preserved this behavior). * This introduces redundancy between the character isxyz() functions in recg_pg_locale.c and similar functions in pg_locale.c. It would be easy enough to refactor to eliminate the redundancy, but that might have performance implications, so I didn't do it yet. Regards, Jeff Davis
Commits
-
Make char2wchar() static.
- ff53907c3571 19 (unreleased) landed
-
Remove obsolete global database_ctype_is_c.
- 844385d12e75 19 (unreleased) landed
-
tsearch: use database default collation for parsing.
- e113f9c102b7 19 (unreleased) landed
-
Add pg_database_locale() to retrieve database default locale.
- e533524b23b8 19 (unreleased) landed
-
Add pg_iswxdigit(), useful for tsearch.
- 67a8b49e96ca 19 (unreleased) landed
-
Add pg_iswalpha() and related functions.
- af164f31b9f5 19 (unreleased) landed
-
pg_regc_locale.c: rename some static functions.
- 8efe982fe2c5 19 (unreleased) landed