diff options
author | Jeff Davis <jdavis@postgresql.org> | 2024-09-03 16:05:58 -0700 |
---|---|---|
committer | Jeff Davis <jdavis@postgresql.org> | 2024-09-03 16:30:03 -0700 |
commit | 12d3345c0d2842a36d0ee2bce06cfe7d3cac84da (patch) | |
tree | b86e0e74b12648d653dd10add8cd46ceecef62b3 /src/backend/utils/adt/pg_locale.c | |
parent | 516ff05539bb70cc378e21e5e67588ec9c959cf7 (diff) | |
download | postgresql-12d3345c0d2842a36d0ee2bce06cfe7d3cac84da.tar.gz postgresql-12d3345c0d2842a36d0ee2bce06cfe7d3cac84da.zip |
Remember last collation to speed up collation cache.
This optimization is to avoid a performance regression in an upcoming
patch that will remove lc_collate_is_c().
Discussion: https://postgr.es/m/96a559be83329bc66074a3925ebcfa8ceb16dfc5.camel@j-davis.com
Discussion: https://postgr.es/m/646f662e145ab38cff1c04d475f4448f53fc5042.camel@j-davis.com
Discussion: https://postgr.es/m/54565933-d82f-4d7c-8f47-288b1b570fd8@eisentraut.org
Diffstat (limited to 'src/backend/utils/adt/pg_locale.c')
-rw-r--r-- | src/backend/utils/adt/pg_locale.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 643cca05d38..d82e816230f 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -151,6 +151,13 @@ typedef struct static MemoryContext CollationCacheContext = NULL; static collation_cache_hash *CollationCache = NULL; +/* + * The collation cache is often accessed repeatedly for the same collation, so + * remember the last one used. + */ +static Oid last_collation_cache_oid = InvalidOid; +static pg_locale_t last_collation_cache_locale = NULL; + #if defined(WIN32) && defined(LC_MESSAGES) static char *IsoLocaleName(const char *); #endif @@ -1570,6 +1577,9 @@ pg_newlocale_from_collation(Oid collid) if (collid == DEFAULT_COLLATION_OID) return &default_locale; + if (last_collation_cache_oid == collid) + return last_collation_cache_locale; + cache_entry = lookup_collation_cache(collid); if (cache_entry->locale == 0) @@ -1695,6 +1705,9 @@ pg_newlocale_from_collation(Oid collid) cache_entry->locale = resultp; } + last_collation_cache_oid = collid; + last_collation_cache_locale = cache_entry->locale; + return cache_entry->locale; } |