|
56 | 56 |
|
57 | 57 | #include "access/htup_details.h"
|
58 | 58 | #include "catalog/pg_collation.h"
|
| 59 | +#include "common/hashfn.h" |
59 | 60 | #include "mb/pg_wchar.h"
|
60 | 61 | #include "miscadmin.h"
|
61 | 62 | #include "utils/builtins.h"
|
62 | 63 | #include "utils/formatting.h"
|
63 | 64 | #include "utils/guc_hooks.h"
|
64 |
| -#include "utils/hsearch.h" |
65 | 65 | #include "utils/lsyscache.h"
|
66 | 66 | #include "utils/memutils.h"
|
67 | 67 | #include "utils/pg_locale.h"
|
@@ -129,10 +129,27 @@ typedef struct
|
129 | 129 | bool ctype_is_c; /* is collation's LC_CTYPE C? */
|
130 | 130 | bool flags_valid; /* true if above flags are valid */
|
131 | 131 | pg_locale_t locale; /* locale_t struct, or 0 if not valid */
|
132 |
| -} collation_cache_entry; |
133 | 132 |
|
134 |
| -static HTAB *collation_cache = NULL; |
| 133 | + /* needed for simplehash */ |
| 134 | + uint32 hash; |
| 135 | + char status; |
| 136 | +} collation_cache_entry; |
135 | 137 |
|
| 138 | +#define SH_PREFIX collation_cache |
| 139 | +#define SH_ELEMENT_TYPE collation_cache_entry |
| 140 | +#define SH_KEY_TYPE Oid |
| 141 | +#define SH_KEY collid |
| 142 | +#define SH_HASH_KEY(tb, key) murmurhash32((uint32) key) |
| 143 | +#define SH_EQUAL(tb, a, b) (a == b) |
| 144 | +#define SH_GET_HASH(tb, a) a->hash |
| 145 | +#define SH_SCOPE static inline |
| 146 | +#define SH_STORE_HASH |
| 147 | +#define SH_DECLARE |
| 148 | +#define SH_DEFINE |
| 149 | +#include "lib/simplehash.h" |
| 150 | + |
| 151 | +static MemoryContext CollationCacheContext = NULL; |
| 152 | +static collation_cache_hash *CollationCache = NULL; |
136 | 153 |
|
137 | 154 | #if defined(WIN32) && defined(LC_MESSAGES)
|
138 | 155 | static char *IsoLocaleName(const char *);
|
@@ -1235,18 +1252,16 @@ lookup_collation_cache(Oid collation, bool set_flags)
|
1235 | 1252 | Assert(OidIsValid(collation));
|
1236 | 1253 | Assert(collation != DEFAULT_COLLATION_OID);
|
1237 | 1254 |
|
1238 |
| - if (collation_cache == NULL) |
| 1255 | + if (CollationCache == NULL) |
1239 | 1256 | {
|
1240 |
| - /* First time through, initialize the hash table */ |
1241 |
| - HASHCTL ctl; |
1242 |
| - |
1243 |
| - ctl.keysize = sizeof(Oid); |
1244 |
| - ctl.entrysize = sizeof(collation_cache_entry); |
1245 |
| - collation_cache = hash_create("Collation cache", 100, &ctl, |
1246 |
| - HASH_ELEM | HASH_BLOBS); |
| 1257 | + CollationCacheContext = AllocSetContextCreate(TopMemoryContext, |
| 1258 | + "collation cache", |
| 1259 | + ALLOCSET_DEFAULT_SIZES); |
| 1260 | + CollationCache = collation_cache_create( |
| 1261 | + CollationCacheContext, 16, NULL); |
1247 | 1262 | }
|
1248 | 1263 |
|
1249 |
| - cache_entry = hash_search(collation_cache, &collation, HASH_ENTER, &found); |
| 1264 | + cache_entry = collation_cache_insert(CollationCache, collation, &found); |
1250 | 1265 | if (!found)
|
1251 | 1266 | {
|
1252 | 1267 | /*
|
|
0 commit comments