public inbox for [email protected]
help / color / mirror / Atom feed[PATCH v7 3/3] Optimize hash function
51+ messages / 4 participants
[nested] [flat]
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v8 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.2
--------------846F221A8A016B7AA8E567B3--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v7 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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 d62b1495dd3..6189d051072 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.30.1
--------------C6A03312D0F99F9183A0DF46--
^ permalink raw reply [nested|flat] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v6 3/3] Optimize hash function
@ 2021-01-20 22:06 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ 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] 51+ messages in thread
* [PATCH v10 3/3] Optimize hash function
@ 2021-10-18 10:59 Heikki Linnakangas <[email protected]>
0 siblings, 0 replies; 51+ messages in thread
From: Heikki Linnakangas @ 2021-10-18 10:59 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 35e824d4534..118bd2b34c9 100644
--- a/src/backend/utils/resowner/resowner.c
+++ b/src/backend/utils/resowner/resowner.c
@@ -169,15 +169,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
}
/*
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.30.2
--------------AF226508B1039DE40796DE51--
^ permalink raw reply [nested|flat] 51+ messages in thread
* Fix incorrect column name in error message for range partition bound check
@ 2026-01-07 05:44 myzhen <[email protected]>
2026-01-07 05:55 ` Re: Fix incorrect column name in error message for range partition bound check zhibin wang <[email protected]>
2026-01-12 02:45 ` Re: Fix incorrect column name in error message for range partition bound check David Rowley <[email protected]>
0 siblings, 2 replies; 51+ messages in thread
From: myzhen @ 2026-01-07 05:44 UTC (permalink / raw)
To: [email protected]
Hi all,
Recently, while working with partitioned tables, I identified an issue where the error message references an incorrect column name when a range-partitioned table’s boundary values include MINVALUE or MAXVALUE.
For example:
postgres=# CREATE TABLE pt_test_colname(a int, b int, c int) PARTITION BY RANGE(a, b);
-- right case
postgres=# CREATE TABLE pt_test_colname_p1 PARTITION OF pt_test_colname FOR VALUES FROM (10, now()) TO (100, 100);
ERROR: specified value cannot be cast to type integer for column "b"
LINE 1: ...PARTITION OF pt_test_colname FOR VALUES FROM (10, now()) TO ...
^
-- wrong case
postgres=# CREATE TABLE pt_test_colname_p1 PARTITION OF pt_test_colname FOR VALUES FROM (minvalue, now()) TO (100, 100);
ERROR: specified value cannot be cast to type integer for column "a"
LINE 1: ...ION OF pt_test_colname FOR VALUES FROM (minvalue, now()) TO ...
^
The datetime value returned by now() cannot be cast to the partition key b (integer type), yet the error message incorrectly attributes this casting failure to column a when the preceding boundary value is the special MINVALUE or MAXVALUE.
Attachments:
[application/octet-stream] v1-0001-Fix-incorrect-column-name-in-error-message-for-range.patch (1.1K, ../../[email protected]/3-v1-0001-Fix-incorrect-column-name-in-error-message-for-range.patch)
download | inline diff:
From 11f9f048a40d15ad563e4ca405c7e27ca2ae6e36 Mon Sep 17 00:00:00 2001
From: myzhen <[email protected]>
Date: Tue, 6 Jan 2026 18:42:28 +0800
Subject: [PATCH] Fix incorrect column name in error message for range
partition bound check.
When range partition boundary value lists contain MINVALUE or MAXVALUE, and subsequent
boundary values cannot be implicitly cast to the corresponding partition key data type,
the error message references an incorrect column name.
---
src/backend/parser/parse_utilcmd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 3f4393b52ea..d739ca96813 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -4841,10 +4841,10 @@ transformPartitionRangeBounds(ParseState *pstate, List *blist,
prd = makeNode(PartitionRangeDatum);
prd->kind = PARTITION_RANGE_DATUM_VALUE;
prd->value = (Node *) value;
- ++i;
}
prd->location = exprLocation(expr);
+ ++i;
result = lappend(result, prd);
}
--
2.28.0.windows.1
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Fix incorrect column name in error message for range partition bound check
2026-01-07 05:44 Fix incorrect column name in error message for range partition bound check myzhen <[email protected]>
@ 2026-01-07 05:55 ` zhibin wang <[email protected]>
2026-01-07 09:50 ` Re:Re: Fix incorrect column name in error message for range partition bound check myzhen <[email protected]>
1 sibling, 1 reply; 51+ messages in thread
From: zhibin wang @ 2026-01-07 05:55 UTC (permalink / raw)
To: myzhen <[email protected]>; +Cc: [email protected]
Hi myzhen,
On Wed, Jan 7, 2026 at 1:48 PM myzhen <[email protected]> wrote:
>
> postgres=# CREATE TABLE pt_test_colname_p1 PARTITION OF pt_test_colname
> FOR VALUES FROM (minvalue, now()) TO (100, 100);
> ERROR: specified value cannot be cast to type integer for column "a"
> LINE 1: ...ION OF pt_test_colname FOR VALUES FROM (minvalue, now()) TO ...
> ^
> The datetime value returned by now() cannot be cast to the partition key b
> (integer type), yet the error message incorrectly attributes this casting
> failure to column a when the preceding boundary value is the special
> MINVALUE or MAXVALUE.
>
Yes, I think you are correct. It seems that this is an error prompt caused
by the infinite boundary values MINVALUE and MAXVALUE.
By the way, based on the context, once a column is set to MINVALUE or
MAXVALUE, the values of the remaining columns must be the same. However, I
noticed that 'validateInfiniteBounds' is only invoked after all boundary
value transformations are completed. Perhaps we can perform the validity
check for infinite boundary values earlier. In this way, we can not only
avoid this error but also achieve timely "short-circuit" — because any
non-MINVALUE transformation performed after MINVALUE is essentially
meaningless overhead. ideas?
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re:Re: Fix incorrect column name in error message for range partition bound check
2026-01-07 05:44 Fix incorrect column name in error message for range partition bound check myzhen <[email protected]>
2026-01-07 05:55 ` Re: Fix incorrect column name in error message for range partition bound check zhibin wang <[email protected]>
@ 2026-01-07 09:50 ` myzhen <[email protected]>
0 siblings, 0 replies; 51+ messages in thread
From: myzhen @ 2026-01-07 09:50 UTC (permalink / raw)
To: zhibin wang <[email protected]>; +Cc: [email protected]
Hi zhibin,
By the way, based on the context, once a column is set to MINVALUE or MAXVALUE, the values of the remaining columns must be the same. However, I noticed that 'validateInfiniteBounds' is only invoked after all boundary value transformations are completed. Perhaps we can perform the validity check for infinite boundary values earlier. In this way, we can not only avoid this error but also achieve timely "short-circuit" — because any non-MINVALUE transformation performed after MINVALUE is essentially meaningless overhead. ideas?
Thanks, I think it makes some sense, so I tried to make the second version.
Attachments:
[application/octet-stream] v2-Fix-incorrect-column-name-in-error-message-for-range.patch (4.3K, ../../[email protected]/3-v2-Fix-incorrect-column-name-in-error-message-for-range.patch)
download | inline diff:
From f8a18a1d8e129156123e1fc4b990d52a6f9c8539 Mon Sep 17 00:00:00 2001
From: myzhen <[email protected]>
Date: Tue, 6 Jan 2026 18:42:28 +0800
Subject: [PATCH] Fix incorrect column name in error message for range
partition bound check.
When range partition boundary value lists contain MINVALUE or MAXVALUE, and subsequent
boundary values cannot be implicitly cast to the corresponding partition key data type,
the error message references an incorrect column name.
---
src/backend/parser/parse_utilcmd.c | 85 ++++++++++++------------------
1 file changed, 35 insertions(+), 50 deletions(-)
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 3f4393b52ea..6d909d407a7 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -140,7 +140,6 @@ static void setSchemaName(const char *context_schema, char **stmt_schema_name);
static void transformPartitionCmd(CreateStmtContext *cxt, PartitionBoundSpec *bound);
static List *transformPartitionRangeBounds(ParseState *pstate, List *blist,
Relation parent);
-static void validateInfiniteBounds(ParseState *pstate, List *blist);
static Const *transformPartitionBoundValue(ParseState *pstate, Node *val,
const char *colName, Oid colType, int32 colTypmod,
Oid partCollation);
@@ -4755,6 +4754,7 @@ transformPartitionRangeBounds(ParseState *pstate, List *blist,
PartitionKey key = RelationGetPartitionKey(parent);
List *partexprs = get_partition_exprs(key);
ListCell *lc;
+ PartitionRangeDatumKind kind = PARTITION_RANGE_DATUM_VALUE;
int i,
j;
@@ -4804,6 +4804,39 @@ transformPartitionRangeBounds(ParseState *pstate, List *blist,
}
}
+ /*
+ * Once we see MINVALUE or MAXVALUE for one column, the remaining columns
+ * must be the same.
+ */
+ if (kind == PARTITION_RANGE_DATUM_VALUE && prd)
+ kind = prd->kind;
+
+ if (kind != PARTITION_RANGE_DATUM_VALUE &&
+ (prd == NULL ||
+ kind != prd->kind))
+ {
+ switch (kind)
+ {
+ case PARTITION_RANGE_DATUM_VALUE:
+ /* shouldn't happen, but keep compiler quiet */
+ break;
+
+ case PARTITION_RANGE_DATUM_MAXVALUE:
+ ereport(ERROR,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ errmsg("every bound following MAXVALUE must also be MAXVALUE"),
+ parser_errposition(pstate, exprLocation(expr))));
+ break;
+
+ case PARTITION_RANGE_DATUM_MINVALUE:
+ ereport(ERROR,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ errmsg("every bound following MINVALUE must also be MINVALUE"),
+ parser_errposition(pstate, exprLocation(expr))));
+ break;
+ }
+ }
+
if (prd == NULL)
{
char *colname;
@@ -4841,65 +4874,17 @@ transformPartitionRangeBounds(ParseState *pstate, List *blist,
prd = makeNode(PartitionRangeDatum);
prd->kind = PARTITION_RANGE_DATUM_VALUE;
prd->value = (Node *) value;
- ++i;
}
prd->location = exprLocation(expr);
+ ++i;
result = lappend(result, prd);
}
- /*
- * Once we see MINVALUE or MAXVALUE for one column, the remaining columns
- * must be the same.
- */
- validateInfiniteBounds(pstate, result);
-
return result;
}
-/*
- * validateInfiniteBounds
- *
- * Check that a MAXVALUE or MINVALUE specification in a partition bound is
- * followed only by more of the same.
- */
-static void
-validateInfiniteBounds(ParseState *pstate, List *blist)
-{
- ListCell *lc;
- PartitionRangeDatumKind kind = PARTITION_RANGE_DATUM_VALUE;
-
- foreach(lc, blist)
- {
- PartitionRangeDatum *prd = lfirst_node(PartitionRangeDatum, lc);
-
- if (kind == prd->kind)
- continue;
-
- switch (kind)
- {
- case PARTITION_RANGE_DATUM_VALUE:
- kind = prd->kind;
- break;
-
- case PARTITION_RANGE_DATUM_MAXVALUE:
- ereport(ERROR,
- (errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("every bound following MAXVALUE must also be MAXVALUE"),
- parser_errposition(pstate, exprLocation((Node *) prd))));
- break;
-
- case PARTITION_RANGE_DATUM_MINVALUE:
- ereport(ERROR,
- (errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("every bound following MINVALUE must also be MINVALUE"),
- parser_errposition(pstate, exprLocation((Node *) prd))));
- break;
- }
- }
-}
-
/*
* Transform one entry in a partition bound spec, producing a constant.
*/
--
2.28.0.windows.1
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Fix incorrect column name in error message for range partition bound check
2026-01-07 05:44 Fix incorrect column name in error message for range partition bound check myzhen <[email protected]>
@ 2026-01-12 02:45 ` David Rowley <[email protected]>
1 sibling, 0 replies; 51+ messages in thread
From: David Rowley @ 2026-01-12 02:45 UTC (permalink / raw)
To: myzhen <[email protected]>; +Cc: [email protected]
On Wed, 7 Jan 2026 at 18:45, myzhen <[email protected]> wrote:
> postgres=# CREATE TABLE pt_test_colname(a int, b int, c int) PARTITION BY RANGE(a, b);
> -- wrong case
> postgres=# CREATE TABLE pt_test_colname_p1 PARTITION OF pt_test_colname FOR VALUES FROM (minvalue, now()) TO (100, 100);
> ERROR: specified value cannot be cast to type integer for column "a"
> LINE 1: ...ION OF pt_test_colname FOR VALUES FROM (minvalue, now()) TO ...
(I thought I'd sent this email last week, but I don't see it in the
archives or my sent items)
I've pushed a fix similar to your v1 patch for this. I used
foreach_current_index rather than what you did in your v1. That seems
less prone to get broken again in the future if someone were to add
additional logic within the loop body.
I didn't see any need to do any more than that, so I didn't consider
anything your v2 patch did.
Thanks for the patch.
David
^ permalink raw reply [nested|flat] 51+ messages in thread
end of thread, other threads:[~2026-01-12 02:45 UTC | newest]
Thread overview: 51+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v8 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v7 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-01-20 22:06 [PATCH v6 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2021-10-18 10:59 [PATCH v10 3/3] Optimize hash function Heikki Linnakangas <[email protected]>
2026-01-07 05:44 Fix incorrect column name in error message for range partition bound check myzhen <[email protected]>
2026-01-07 05:55 ` Re: Fix incorrect column name in error message for range partition bound check zhibin wang <[email protected]>
2026-01-07 09:50 ` Re:Re: Fix incorrect column name in error message for range partition bound check myzhen <[email protected]>
2026-01-12 02:45 ` Re: Fix incorrect column name in error message for range partition bound check David Rowley <[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