public inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH v6 3/3] Optimize hash function
5+ messages / 3 participants
[nested] [flat]

* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06  Heikki Linnakangas <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Heikki Linnakangas @ 2021-01-20 22:06 UTC (permalink / raw)

---
 src/backend/utils/resowner/resowner.c | 24 ++++++++++++++++++------
 src/include/common/hashfn.h           | 15 +++++++++++++++
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/src/backend/utils/resowner/resowner.c b/src/backend/utils/resowner/resowner.c
index 1db1e7cf14b..72e4d8a784c 100644
--- a/src/backend/utils/resowner/resowner.c
+++ b/src/backend/utils/resowner/resowner.c
@@ -163,15 +163,27 @@ static void ReleaseAuxProcessResourcesCallback(int code, Datum arg);
  *	  INTERNAL ROUTINES														 *
  *****************************************************************************/
 
+/*
+ * Hash function for value+kind combination.
+ */
 static inline uint32
 hash_resource_elem(Datum value, ResourceOwnerFuncs *kind)
 {
-	Datum		data[2];
-
-	data[0] = value;
-	data[1] = PointerGetDatum(kind);
-
-	return hash_bytes((unsigned char *) &data, 2 * SIZEOF_DATUM);
+	/*
+	 * Most resources types store a pointer in 'value', and pointers are
+	 * unique all on their own. But some resources store plain integers (Files
+	 * and Buffers as of this writing), so we want to incorporate the 'kind'
+	 * in the hash too, otherwise those resources will collide a lot. But
+	 * because there are only a few resource kinds like that - and only a few
+	 * resource kinds to begin with - we don't need to work too hard to mix
+	 * 'kind' into the hash. Just add it with hash_combine(), it perturbs the
+	 * result enough for our purposes.
+	 */
+#if SIZEOF_DATUM == 8
+	return hash_combine64(murmurhash64((uint64) value), (uint64) kind);
+#else
+	return hash_combine(murmurhash32((uint32) value), (uint32) kind);
+#endif
 }
 
 static void
diff --git a/src/include/common/hashfn.h b/src/include/common/hashfn.h
index c634cc067a1..009ffbbdd38 100644
--- a/src/include/common/hashfn.h
+++ b/src/include/common/hashfn.h
@@ -101,4 +101,19 @@ murmurhash32(uint32 data)
 	return h;
 }
 
+/* 64-bit variant */
+static inline uint64
+murmurhash64(uint64 data)
+{
+	uint64		h = data;
+
+	h ^= h >> 33;
+	h *= 0xff51afd7ed558ccd;
+	h ^= h >> 33;
+	h *= 0xc4ceb9fe1a85ec53;
+	h ^= h >> 33;
+
+	return h;
+}
+
 #endif							/* HASHFN_H */
-- 
2.29.2


--------------F30A5443A5D524A5CBC51AE7
Content-Type: text/x-patch; charset=UTF-8;
 name="v2-0001-resownerbench.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="v2-0001-resownerbench.patch"



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* How to add a new pg oid?
@ 2023-09-05 14:29  jacktby jacktby <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: jacktby jacktby @ 2023-09-05 14:29 UTC (permalink / raw)
  To: [email protected]







^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to add a new pg oid?
@ 2023-09-05 17:47  David G. Johnston <[email protected]>
  parent: jacktby jacktby <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: David G. Johnston @ 2023-09-05 17:47 UTC (permalink / raw)
  To: jacktby jacktby <[email protected]>; +Cc: [email protected]

OIDs don't exist independently of the data they are associated with.  Give
more context if you want a better answer.  Or just go look at the source
code commits for when the last time something needing an OID got added to
the core catalog.

David J.


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to add a new pg oid?
@ 2023-09-06 10:19  jacktby jacktby <[email protected]>
  parent: David G. Johnston <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: jacktby jacktby @ 2023-09-06 10:19 UTC (permalink / raw)
  To: [email protected]; +Cc: David G. Johnston <[email protected]>



> 2023年9月6日 01:47,David G. Johnston <[email protected]> 写道:
> 
> OIDs don't exist independently of the data they are associated with.  Give more context if you want a better answer.  Or just go look at the source code commits for when the last time something needing an OID got added to the core catalog.
> 
> David J.
>  

{ oid => '111', array_type_oid => '6099', descr => 'similarity columns',
  typname => 'similarity_columns', typlen => '-1', typlen => '-1', typbyval => 'f', typcategory => 'U',
  typinput => 'byteain', typoutput => 'byteaout', typreceive => 'bytearecv',
  typsend => 'byteasend', typalign => 'i', typstorage => 'x' },

I add above into pg_type.dat. And then I add execute “make install” and restart pg. And Then do below:
postgres=# SELECT typname from pg_type where typname like '%similarity%';
 typname 
---------
(0 rows)

I can’t get the type I added. What else I need to do?

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to add a new pg oid?
@ 2023-09-06 10:50  jacktby jacktby <[email protected]>
  parent: jacktby jacktby <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: jacktby jacktby @ 2023-09-06 10:50 UTC (permalink / raw)
  To: [email protected]



> 2023年9月6日 18:19,jacktby jacktby <[email protected]> 写道:
> 
> 
> 
>> 2023年9月6日 01:47,David G. Johnston <[email protected]> 写道:
>> 
>> OIDs don't exist independently of the data they are associated with.  Give more context if you want a better answer.  Or just go look at the source code commits for when the last time something needing an OID got added to the core catalog.
>> 
>> David J.
>>  
> 
> { oid => '111', array_type_oid => '6099', descr => 'similarity columns',
>   typname => 'similarity_columns', typlen => '-1', typlen => '-1', typbyval => 'f', typcategory => 'U',
>   typinput => 'byteain', typoutput => 'byteaout', typreceive => 'bytearecv',
>   typsend => 'byteasend', typalign => 'i', typstorage => 'x' },
> 
> I add above into pg_type.dat. And then I add execute “make install” and restart pg. And Then do below:
> postgres=# SELECT typname from pg_type where typname like '%similarity%';
>  typname 
> ---------
> (0 rows)
> 
> I can’t get the type I added. What else I need to do?
I add below in bootstrap.c:
static const struct typinfo TypInfo[] = {
	{"similarity_columns", SimilarityColumns, 0, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
	 F_BYTEAIN, F_BYTEAOUT},
….
}
And then “make install” and restart pg.but still:
postgres=# SELECT typname from pg_type where typname like '%similarity%';
 typname 
---------
(0 rows)

Please give me help.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2023-09-06 10:50 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2023-09-05 14:29 How to add a new pg oid? jacktby jacktby <[email protected]>
2023-09-05 17:47 ` Re: How to add a new pg oid? David G. Johnston <[email protected]>
2023-09-06 10:19   ` Re: How to add a new pg oid? jacktby jacktby <[email protected]>
2023-09-06 10:50     ` Re: How to add a new pg oid? jacktby jacktby <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox