Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 12d3345

Browse files
committed
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
1 parent 516ff05 commit 12d3345

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/backend/utils/adt/pg_locale.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ typedef struct
151151
static MemoryContext CollationCacheContext = NULL;
152152
static collation_cache_hash *CollationCache = NULL;
153153

154+
/*
155+
* The collation cache is often accessed repeatedly for the same collation, so
156+
* remember the last one used.
157+
*/
158+
static Oid last_collation_cache_oid = InvalidOid;
159+
static pg_locale_t last_collation_cache_locale = NULL;
160+
154161
#if defined(WIN32) && defined(LC_MESSAGES)
155162
static char *IsoLocaleName(const char *);
156163
#endif
@@ -1570,6 +1577,9 @@ pg_newlocale_from_collation(Oid collid)
15701577
if (collid == DEFAULT_COLLATION_OID)
15711578
return &default_locale;
15721579

1580+
if (last_collation_cache_oid == collid)
1581+
return last_collation_cache_locale;
1582+
15731583
cache_entry = lookup_collation_cache(collid);
15741584

15751585
if (cache_entry->locale == 0)
@@ -1695,6 +1705,9 @@ pg_newlocale_from_collation(Oid collid)
16951705
cache_entry->locale = resultp;
16961706
}
16971707

1708+
last_collation_cache_oid = collid;
1709+
last_collation_cache_locale = cache_entry->locale;
1710+
16981711
return cache_entry->locale;
16991712
}
17001713

0 commit comments

Comments
 (0)