Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit005c6b8

Browse files
committed
Change collation cache to use simplehash.h.
Speeds up text comparison expressions when using a collation otherthan the database default collation. Does not affect larger operationssuch as ORDER BY, because the lookup is only done once.Discussion:https://postgr.es/m/7bb9f018d20a7b30b9a7f6231efab1b5e50c7720.camel@j-davis.comReviewed-by: John Naylor, Andreas Karlsson
1 parentcdd6ab9 commit005c6b8

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

‎src/backend/utils/adt/pg_locale.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@
5656

5757
#include"access/htup_details.h"
5858
#include"catalog/pg_collation.h"
59+
#include"common/hashfn.h"
5960
#include"mb/pg_wchar.h"
6061
#include"miscadmin.h"
6162
#include"utils/builtins.h"
6263
#include"utils/formatting.h"
6364
#include"utils/guc_hooks.h"
64-
#include"utils/hsearch.h"
6565
#include"utils/lsyscache.h"
6666
#include"utils/memutils.h"
6767
#include"utils/pg_locale.h"
@@ -129,10 +129,27 @@ typedef struct
129129
boolctype_is_c;/* is collation's LC_CTYPE C? */
130130
boolflags_valid;/* true if above flags are valid */
131131
pg_locale_tlocale;/* locale_t struct, or 0 if not valid */
132-
}collation_cache_entry;
133132

134-
staticHTAB*collation_cache=NULL;
133+
/* needed for simplehash */
134+
uint32hash;
135+
charstatus;
136+
}collation_cache_entry;
135137

138+
#defineSH_PREFIXcollation_cache
139+
#defineSH_ELEMENT_TYPEcollation_cache_entry
140+
#defineSH_KEY_TYPEOid
141+
#defineSH_KEYcollid
142+
#defineSH_HASH_KEY(tb,key) murmurhash32((uint32) key)
143+
#defineSH_EQUAL(tb,a,b)(a == b)
144+
#defineSH_GET_HASH(tb,a)a->hash
145+
#defineSH_SCOPEstatic inline
146+
#defineSH_STORE_HASH
147+
#defineSH_DECLARE
148+
#defineSH_DEFINE
149+
#include"lib/simplehash.h"
150+
151+
staticMemoryContextCollationCacheContext=NULL;
152+
staticcollation_cache_hash*CollationCache=NULL;
136153

137154
#if defined(WIN32)&& defined(LC_MESSAGES)
138155
staticchar*IsoLocaleName(constchar*);
@@ -1235,18 +1252,16 @@ lookup_collation_cache(Oid collation, bool set_flags)
12351252
Assert(OidIsValid(collation));
12361253
Assert(collation!=DEFAULT_COLLATION_OID);
12371254

1238-
if (collation_cache==NULL)
1255+
if (CollationCache==NULL)
12391256
{
1240-
/* First time through, initialize the hash table */
1241-
HASHCTLctl;
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);
12471262
}
12481263

1249-
cache_entry=hash_search(collation_cache,&collation,HASH_ENTER,&found);
1264+
cache_entry=collation_cache_insert(CollationCache,collation,&found);
12501265
if (!found)
12511266
{
12521267
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp