diff options
author | Jeff Davis <jdavis@postgresql.org> | 2024-07-28 12:39:57 -0700 |
---|---|---|
committer | Jeff Davis <jdavis@postgresql.org> | 2024-07-28 12:39:57 -0700 |
commit | 005c6b833f7866b71b50a5382e30d6c3f695306e (patch) | |
tree | 14ce9db119aab73c97d308e4b33a39427f916faf /src/backend/utils/adt/pg_locale.c | |
parent | cdd6ab9d1f5396ec1097d51c21a224aa41118c9c (diff) | |
download | postgresql-005c6b833f7866b71b50a5382e30d6c3f695306e.tar.gz postgresql-005c6b833f7866b71b50a5382e30d6c3f695306e.zip |
Change collation cache to use simplehash.h.
Speeds up text comparison expressions when using a collation other
than the database default collation. Does not affect larger operations
such as ORDER BY, because the lookup is only done once.
Discussion: https://postgr.es/m/7bb9f018d20a7b30b9a7f6231efab1b5e50c7720.camel@j-davis.com
Reviewed-by: John Naylor, Andreas Karlsson
Diffstat (limited to 'src/backend/utils/adt/pg_locale.c')
-rw-r--r-- | src/backend/utils/adt/pg_locale.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 38c40a40489..f386945ee0c 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -56,12 +56,12 @@ #include "access/htup_details.h" #include "catalog/pg_collation.h" +#include "common/hashfn.h" #include "mb/pg_wchar.h" #include "miscadmin.h" #include "utils/builtins.h" #include "utils/formatting.h" #include "utils/guc_hooks.h" -#include "utils/hsearch.h" #include "utils/lsyscache.h" #include "utils/memutils.h" #include "utils/pg_locale.h" @@ -129,10 +129,27 @@ typedef struct bool ctype_is_c; /* is collation's LC_CTYPE C? */ bool flags_valid; /* true if above flags are valid */ pg_locale_t locale; /* locale_t struct, or 0 if not valid */ -} collation_cache_entry; -static HTAB *collation_cache = NULL; + /* needed for simplehash */ + uint32 hash; + char status; +} collation_cache_entry; +#define SH_PREFIX collation_cache +#define SH_ELEMENT_TYPE collation_cache_entry +#define SH_KEY_TYPE Oid +#define SH_KEY collid +#define SH_HASH_KEY(tb, key) murmurhash32((uint32) key) +#define SH_EQUAL(tb, a, b) (a == b) +#define SH_GET_HASH(tb, a) a->hash +#define SH_SCOPE static inline +#define SH_STORE_HASH +#define SH_DECLARE +#define SH_DEFINE +#include "lib/simplehash.h" + +static MemoryContext CollationCacheContext = NULL; +static collation_cache_hash *CollationCache = NULL; #if defined(WIN32) && defined(LC_MESSAGES) static char *IsoLocaleName(const char *); @@ -1235,18 +1252,16 @@ lookup_collation_cache(Oid collation, bool set_flags) Assert(OidIsValid(collation)); Assert(collation != DEFAULT_COLLATION_OID); - if (collation_cache == NULL) + if (CollationCache == NULL) { - /* First time through, initialize the hash table */ - HASHCTL ctl; - - ctl.keysize = sizeof(Oid); - ctl.entrysize = sizeof(collation_cache_entry); - collation_cache = hash_create("Collation cache", 100, &ctl, - HASH_ELEM | HASH_BLOBS); + CollationCacheContext = AllocSetContextCreate(TopMemoryContext, + "collation cache", + ALLOCSET_DEFAULT_SIZES); + CollationCache = collation_cache_create( + CollationCacheContext, 16, NULL); } - cache_entry = hash_search(collation_cache, &collation, HASH_ENTER, &found); + cache_entry = collation_cache_insert(CollationCache, collation, &found); if (!found) { /* |