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

Commit954e435

Browse files
committed
Use a faster hash function in resource owners.
This buys back some of the performance loss that we otherwise saw from theprevious commit.Reviewed-by: Aleksander Alekseev, Michael Paquier, Julien RouhaudReviewed-by: Kyotaro Horiguchi, Hayato Kuroda, Álvaro Herrera, Zhihong YuReviewed-by: Peter Eisentraut, Andres FreundDiscussion:https://www.postgresql.org/message-id/d746cead-a1ef-7efe-fb47-933311e876a3%40iki.fi
1 parentb8bff07 commit954e435

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

‎src/backend/utils/resowner/resowner.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,27 @@ static void ReleaseAuxProcessResourcesCallback(int code, Datum arg);
206206
* INTERNAL ROUTINES *
207207
*****************************************************************************/
208208

209+
/*
210+
* Hash function for value+kind combination.
211+
*/
209212
staticinlineuint32
210213
hash_resource_elem(Datumvalue,constResourceOwnerDesc*kind)
211214
{
212-
Datumdata[2];
213-
214-
data[0]=value;
215-
data[1]=PointerGetDatum(kind);
216-
217-
returnhash_bytes((unsignedchar*)&data,2*SIZEOF_DATUM);
215+
/*
216+
* Most resource kinds store a pointer in 'value', and pointers are unique
217+
* all on their own. But some resources store plain integers (Files and
218+
* Buffers as of this writing), so we want to incorporate the 'kind' in
219+
* the hash too, otherwise those resources will collide a lot. But
220+
* because there are only a few resource kinds like that - and only a few
221+
* resource kinds to begin with - we don't need to work too hard to mix
222+
* 'kind' into the hash. Just add it with hash_combine(), it perturbs the
223+
* result enough for our purposes.
224+
*/
225+
#ifSIZEOF_DATUM==8
226+
returnhash_combine64(murmurhash64((uint64)value), (uint64)kind);
227+
#else
228+
returnhash_combine(murmurhash32((uint32)value), (uint32)kind);
229+
#endif
218230
}
219231

220232
/*

‎src/include/common/hashfn.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,19 @@ murmurhash32(uint32 data)
101101
returnh;
102102
}
103103

104+
/* 64-bit variant */
105+
staticinlineuint64
106+
murmurhash64(uint64data)
107+
{
108+
uint64h=data;
109+
110+
h ^=h >>33;
111+
h *=0xff51afd7ed558ccd;
112+
h ^=h >>33;
113+
h *=0xc4ceb9fe1a85ec53;
114+
h ^=h >>33;
115+
116+
returnh;
117+
}
118+
104119
#endif/* HASHFN_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp