allow frontend use of the backend's core hashing functions
Late last year, I did some work to make it possible to use simplehash
in frontend code.[1]/messages/by-id/CA+Tgmob8oyh02NrZW=xCScB+5GyJ-jVowE3+TWTUmPF=FsGWTA@mail.gmail.com However, a hash table is not much good unless one
also has some hash functions that one can use to hash the keys that
need to be inserted into that hash table. I initially thought that
solving this problem was going to be pretty annoying, but when I
looked at it again today I found what I think is a pretty simple way
to adapt things so that the hashing routines we use in the backend are
easily available to frontend code.
Here are some patches for that. It may make sense to combine some of
these in terms of actually getting this committed, but I have
separated them here so that it is, hopefully, easy to see what I did
and why I did it. There are three basic problems which are solved by
the three preparatory patches:
0001 - hashfn.c has a couple of routines that depend on bitmapsets,
and bitmapset.c is currently backend-only. Fix by moving this code
near related code in bitmapset.c.
0002 - some of the prototypes for functions in hashfn.c are in
hsearch.h, mixed with the dynahash stuff, and others are in
hashutils.c. Fix by making hashutils.h the one true header for
hashfn.c.
0003 - Some of hashfn.c's routines return Datum, but that's
backend-only. Fix by renaming the functions and changing the return
types to uint32 and uint64, and add static inline wrappers with the
old names that convert to Datum. Just changing the return types of the
existing functions seemed like it would've required a lot more code
churn, and also seems like it could cause silent breakage in the
future.
Thanks,
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
[1]: /messages/by-id/CA+Tgmob8oyh02NrZW=xCScB+5GyJ-jVowE3+TWTUmPF=FsGWTA@mail.gmail.com
Attachments:
0001-Move-bitmap_hash-and-bitmap_match-to-bitmapset.c.patchapplication/octet-stream; name=0001-Move-bitmap_hash-and-bitmap_match-to-bitmapset.c.patchDownload
From bc970297d1894b95bcd79283762800e7bfc8e9f8 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 7 Feb 2020 11:25:46 -0500
Subject: [PATCH 1/4] Move bitmap_hash and bitmap_match to bitmapset.c.
The closely-related function bms_hash_value is already defined in that
file, and this change means that hashfn.c no longer needs to depend on
nodes/bitmapset.h.
---
src/backend/nodes/bitmapset.c | 23 +++++++++++++++++++++++
src/backend/utils/hash/hashfn.c | 24 ------------------------
src/include/nodes/bitmapset.h | 2 ++
src/include/utils/hsearch.h | 2 --
4 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/src/backend/nodes/bitmapset.c b/src/backend/nodes/bitmapset.c
index 648cc1a7eb..f711e6c699 100644
--- a/src/backend/nodes/bitmapset.c
+++ b/src/backend/nodes/bitmapset.c
@@ -1167,3 +1167,26 @@ bms_hash_value(const Bitmapset *a)
return DatumGetUInt32(hash_any((const unsigned char *) a->words,
(lastword + 1) * sizeof(bitmapword)));
}
+
+/*
+ * bitmap_hash - hash function for keys that are (pointers to) Bitmapsets
+ *
+ * Note: don't forget to specify bitmap_match as the match function!
+ */
+uint32
+bitmap_hash(const void *key, Size keysize)
+{
+ Assert(keysize == sizeof(Bitmapset *));
+ return bms_hash_value(*((const Bitmapset *const *) key));
+}
+
+/*
+ * bitmap_match - match function to use with bitmap_hash
+ */
+int
+bitmap_match(const void *key1, const void *key2, Size keysize)
+{
+ Assert(keysize == sizeof(Bitmapset *));
+ return !bms_equal(*((const Bitmapset *const *) key1),
+ *((const Bitmapset *const *) key2));
+}
diff --git a/src/backend/utils/hash/hashfn.c b/src/backend/utils/hash/hashfn.c
index dc3cbac7ef..fa46c59d25 100644
--- a/src/backend/utils/hash/hashfn.c
+++ b/src/backend/utils/hash/hashfn.c
@@ -23,7 +23,6 @@
#include "postgres.h"
#include "fmgr.h"
-#include "nodes/bitmapset.h"
#include "utils/hashutils.h"
#include "utils/hsearch.h"
@@ -695,26 +694,3 @@ uint32_hash(const void *key, Size keysize)
Assert(keysize == sizeof(uint32));
return DatumGetUInt32(hash_uint32(*((const uint32 *) key)));
}
-
-/*
- * bitmap_hash: hash function for keys that are (pointers to) Bitmapsets
- *
- * Note: don't forget to specify bitmap_match as the match function!
- */
-uint32
-bitmap_hash(const void *key, Size keysize)
-{
- Assert(keysize == sizeof(Bitmapset *));
- return bms_hash_value(*((const Bitmapset *const *) key));
-}
-
-/*
- * bitmap_match: match function to use with bitmap_hash
- */
-int
-bitmap_match(const void *key1, const void *key2, Size keysize)
-{
- Assert(keysize == sizeof(Bitmapset *));
- return !bms_equal(*((const Bitmapset *const *) key1),
- *((const Bitmapset *const *) key2));
-}
diff --git a/src/include/nodes/bitmapset.h b/src/include/nodes/bitmapset.h
index b7b18a0b68..d113c271ee 100644
--- a/src/include/nodes/bitmapset.h
+++ b/src/include/nodes/bitmapset.h
@@ -116,5 +116,7 @@ extern int bms_prev_member(const Bitmapset *a, int prevbit);
/* support for hashtables using Bitmapsets as keys: */
extern uint32 bms_hash_value(const Bitmapset *a);
+extern uint32 bitmap_hash(const void *key, Size keysize);
+extern int bitmap_match(const void *key1, const void *key2, Size keysize);
#endif /* BITMAPSET_H */
diff --git a/src/include/utils/hsearch.h b/src/include/utils/hsearch.h
index b0077b7827..934c4a399e 100644
--- a/src/include/utils/hsearch.h
+++ b/src/include/utils/hsearch.h
@@ -152,8 +152,6 @@ extern void AtEOSubXact_HashTables(bool isCommit, int nestDepth);
extern uint32 string_hash(const void *key, Size keysize);
extern uint32 tag_hash(const void *key, Size keysize);
extern uint32 uint32_hash(const void *key, Size keysize);
-extern uint32 bitmap_hash(const void *key, Size keysize);
-extern int bitmap_match(const void *key1, const void *key2, Size keysize);
#define oid_hash uint32_hash /* Remove me eventually */
--
2.17.2 (Apple Git-113)
0004-Move-src-backend-utils-hash-hashfn.c-to-src-common.patchapplication/octet-stream; name=0004-Move-src-backend-utils-hash-hashfn.c-to-src-common.patchDownload
From ed56aa0d9efb48a4fb5701d18105e956008031e7 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 7 Feb 2020 12:18:03 -0500
Subject: [PATCH 4/4] Move src/backend/utils/hash/hashfn.c to src/common
This also involves renaming src/include/utils/hashutils.h, which
becomes src/include/common/hashfn.h. Perhaps an argument can be
made for keeping the hashutils.h name, but it seemed more
consistent to make it match the name of the file, and also more
descriptive of what is actually going on here.
---
contrib/citext/citext.c | 2 +-
contrib/hstore/hstore_op.c | 2 +-
contrib/pg_stat_statements/pg_stat_statements.c | 2 +-
contrib/sepgsql/uavc.c | 2 +-
src/backend/access/common/tupdesc.c | 2 +-
src/backend/access/hash/hashfunc.c | 2 +-
src/backend/access/tablesample/bernoulli.c | 2 +-
src/backend/access/tablesample/system.c | 2 +-
src/backend/commands/async.c | 2 +-
src/backend/executor/execGrouping.c | 2 +-
src/backend/lib/bloomfilter.c | 2 +-
src/backend/lib/dshash.c | 2 +-
src/backend/nodes/bitmapset.c | 2 +-
src/backend/nodes/tidbitmap.c | 2 +-
src/backend/partitioning/partbounds.c | 2 +-
src/backend/storage/file/sharedfileset.c | 2 +-
src/backend/tsearch/ts_typanalyze.c | 2 +-
src/backend/utils/adt/acl.c | 2 +-
src/backend/utils/adt/date.c | 2 +-
src/backend/utils/adt/jsonb_gin.c | 2 +-
src/backend/utils/adt/jsonb_util.c | 2 +-
src/backend/utils/adt/mac.c | 2 +-
src/backend/utils/adt/mac8.c | 2 +-
src/backend/utils/adt/network.c | 2 +-
src/backend/utils/adt/numeric.c | 2 +-
src/backend/utils/adt/rangetypes.c | 2 +-
src/backend/utils/adt/tid.c | 2 +-
src/backend/utils/adt/uuid.c | 2 +-
src/backend/utils/adt/varchar.c | 2 +-
src/backend/utils/adt/varlena.c | 2 +-
src/backend/utils/cache/catcache.c | 2 +-
src/backend/utils/hash/Makefile | 1 -
src/backend/utils/hash/dynahash.c | 2 +-
src/backend/utils/resowner/resowner.c | 2 +-
src/common/Makefile | 1 +
src/{backend/utils/hash => common}/hashfn.c | 4 ++--
src/include/access/hash.h | 2 +-
src/include/{utils/hashutils.h => common/hashfn.h} | 6 +++---
38 files changed, 40 insertions(+), 40 deletions(-)
rename src/{backend/utils/hash => common}/hashfn.c (99%)
rename src/include/{utils/hashutils.h => common/hashfn.h} (97%)
diff --git a/contrib/citext/citext.c b/contrib/citext/citext.c
index a4adafe895..df139462a6 100644
--- a/contrib/citext/citext.c
+++ b/contrib/citext/citext.c
@@ -4,9 +4,9 @@
#include "postgres.h"
#include "catalog/pg_collation.h"
+#include "common/hashfn.h"
#include "utils/builtins.h"
#include "utils/formatting.h"
-#include "utils/hashutils.h"
#include "utils/varlena.h"
PG_MODULE_MAGIC;
diff --git a/contrib/hstore/hstore_op.c b/contrib/hstore/hstore_op.c
index 01e59beaa3..fb1bb0681c 100644
--- a/contrib/hstore/hstore_op.c
+++ b/contrib/hstore/hstore_op.c
@@ -5,10 +5,10 @@
#include "access/htup_details.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "funcapi.h"
#include "hstore.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
/* old names for C functions */
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 6f82a671ee..1f3c443d3f 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -62,6 +62,7 @@
#include <unistd.h>
#include "catalog/pg_authid.h"
+#include "common/hashfn.h"
#include "executor/instrument.h"
#include "funcapi.h"
#include "mb/pg_wchar.h"
@@ -77,7 +78,6 @@
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
PG_MODULE_MAGIC;
diff --git a/contrib/sepgsql/uavc.c b/contrib/sepgsql/uavc.c
index d3723768a6..639a52c556 100644
--- a/contrib/sepgsql/uavc.c
+++ b/contrib/sepgsql/uavc.c
@@ -14,10 +14,10 @@
#include "catalog/pg_proc.h"
#include "commands/seclabel.h"
+#include "common/hashfn.h"
#include "sepgsql.h"
#include "storage/ipc.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
/*
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 00bb4cb53d..28835512f0 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -23,12 +23,12 @@
#include "access/tupdesc_details.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#include "parser/parse_type.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/datum.h"
-#include "utils/hashutils.h"
#include "utils/resowner_private.h"
#include "utils/syscache.h"
diff --git a/src/backend/access/hash/hashfunc.c b/src/backend/access/hash/hashfunc.c
index 5b517106ff..a8498226e3 100644
--- a/src/backend/access/hash/hashfunc.c
+++ b/src/backend/access/hash/hashfunc.c
@@ -28,8 +28,8 @@
#include "access/hash.h"
#include "catalog/pg_collation.h"
+#include "common/hashfn.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/pg_locale.h"
/*
diff --git a/src/backend/access/tablesample/bernoulli.c b/src/backend/access/tablesample/bernoulli.c
index 46016fb5de..606730d6cb 100644
--- a/src/backend/access/tablesample/bernoulli.c
+++ b/src/backend/access/tablesample/bernoulli.c
@@ -28,9 +28,9 @@
#include "access/tsmapi.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "optimizer/optimizer.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
/* Private state */
diff --git a/src/backend/access/tablesample/system.c b/src/backend/access/tablesample/system.c
index 8a5f03bfd3..29b7c0d3c2 100644
--- a/src/backend/access/tablesample/system.c
+++ b/src/backend/access/tablesample/system.c
@@ -29,9 +29,9 @@
#include "access/relscan.h"
#include "access/tsmapi.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "optimizer/optimizer.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
/* Private state */
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c
index 9aa2b61600..dae939a4ab 100644
--- a/src/backend/commands/async.c
+++ b/src/backend/commands/async.c
@@ -126,6 +126,7 @@
#include "access/xact.h"
#include "catalog/pg_database.h"
#include "commands/async.h"
+#include "common/hashfn.h"
#include "funcapi.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
@@ -138,7 +139,6 @@
#include "storage/sinval.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "utils/snapmgr.h"
diff --git a/src/backend/executor/execGrouping.c b/src/backend/executor/execGrouping.c
index f0737fecca..5040e50c21 100644
--- a/src/backend/executor/execGrouping.c
+++ b/src/backend/executor/execGrouping.c
@@ -19,9 +19,9 @@
#include "postgres.h"
#include "access/parallel.h"
+#include "common/hashfn.h"
#include "executor/executor.h"
#include "miscadmin.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
diff --git a/src/backend/lib/bloomfilter.c b/src/backend/lib/bloomfilter.c
index 29b62e70e4..f040e83c01 100644
--- a/src/backend/lib/bloomfilter.c
+++ b/src/backend/lib/bloomfilter.c
@@ -35,9 +35,9 @@
#include <math.h>
+#include "common/hashfn.h"
#include "lib/bloomfilter.h"
#include "port/pg_bitutils.h"
-#include "utils/hashutils.h"
#define MAX_HASH_FUNCS 10
diff --git a/src/backend/lib/dshash.c b/src/backend/lib/dshash.c
index 5e0167d9b0..78ccf03217 100644
--- a/src/backend/lib/dshash.c
+++ b/src/backend/lib/dshash.c
@@ -31,11 +31,11 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "lib/dshash.h"
#include "storage/ipc.h"
#include "storage/lwlock.h"
#include "utils/dsa.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
/*
diff --git a/src/backend/nodes/bitmapset.c b/src/backend/nodes/bitmapset.c
index f711e6c699..2719ea45a3 100644
--- a/src/backend/nodes/bitmapset.c
+++ b/src/backend/nodes/bitmapset.c
@@ -20,10 +20,10 @@
*/
#include "postgres.h"
+#include "common/hashfn.h"
#include "nodes/bitmapset.h"
#include "nodes/pg_list.h"
#include "port/pg_bitutils.h"
-#include "utils/hashutils.h"
#define WORDNUM(x) ((x) / BITS_PER_BITMAPWORD)
diff --git a/src/backend/nodes/tidbitmap.c b/src/backend/nodes/tidbitmap.c
index e102589e74..ad4e071ca3 100644
--- a/src/backend/nodes/tidbitmap.c
+++ b/src/backend/nodes/tidbitmap.c
@@ -41,11 +41,11 @@
#include <limits.h>
#include "access/htup_details.h"
+#include "common/hashfn.h"
#include "nodes/bitmapset.h"
#include "nodes/tidbitmap.h"
#include "storage/lwlock.h"
#include "utils/dsa.h"
-#include "utils/hashutils.h"
/*
* The maximum number of tuples per page is not large (typically 256 with
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 95af37b9c7..dfc2dc03cf 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -21,6 +21,7 @@
#include "catalog/pg_inherits.h"
#include "catalog/pg_type.h"
#include "commands/tablecmds.h"
+#include "common/hashfn.h"
#include "executor/executor.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
@@ -32,7 +33,6 @@
#include "utils/builtins.h"
#include "utils/datum.h"
#include "utils/fmgroids.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/partcache.h"
#include "utils/ruleutils.h"
diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c
index 6666a25521..f7206c9175 100644
--- a/src/backend/storage/file/sharedfileset.c
+++ b/src/backend/storage/file/sharedfileset.c
@@ -22,11 +22,11 @@
#include "catalog/pg_tablespace.h"
#include "commands/tablespace.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#include "storage/dsm.h"
#include "storage/sharedfileset.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
static void SharedFileSetOnDetach(dsm_segment *segment, Datum datum);
static void SharedFileSetPath(char *path, SharedFileSet *fileset, Oid tablespace);
diff --git a/src/backend/tsearch/ts_typanalyze.c b/src/backend/tsearch/ts_typanalyze.c
index 24c6479f61..2eed0cd137 100644
--- a/src/backend/tsearch/ts_typanalyze.c
+++ b/src/backend/tsearch/ts_typanalyze.c
@@ -16,9 +16,9 @@
#include "catalog/pg_collation.h"
#include "catalog/pg_operator.h"
#include "commands/vacuum.h"
+#include "common/hashfn.h"
#include "tsearch/ts_type.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
/* A hash key for lexemes */
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index cc4170efbf..bce1f1e0b1 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -26,6 +26,7 @@
#include "commands/dbcommands.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
+#include "common/hashfn.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "lib/qunique.h"
@@ -34,7 +35,6 @@
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/catcache.h"
-#include "utils/hashutils.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 393ee991b0..0c55b68fbf 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -21,6 +21,7 @@
#include <time.h>
#include "access/xact.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "nodes/supportnodes.h"
@@ -29,7 +30,6 @@
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/datetime.h"
-#include "utils/hashutils.h"
#include "utils/sortsupport.h"
/*
diff --git a/src/backend/utils/adt/jsonb_gin.c b/src/backend/utils/adt/jsonb_gin.c
index 72a88121d5..63122edf2e 100644
--- a/src/backend/utils/adt/jsonb_gin.c
+++ b/src/backend/utils/adt/jsonb_gin.c
@@ -63,9 +63,9 @@
#include "access/stratnum.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/jsonb.h"
#include "utils/jsonpath.h"
#include "utils/varlena.h"
diff --git a/src/backend/utils/adt/jsonb_util.c b/src/backend/utils/adt/jsonb_util.c
index edec657cd3..04b70c805b 100644
--- a/src/backend/utils/adt/jsonb_util.c
+++ b/src/backend/utils/adt/jsonb_util.c
@@ -15,11 +15,11 @@
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/jsonapi.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/datetime.h"
-#include "utils/hashutils.h"
#include "utils/json.h"
#include "utils/jsonb.h"
#include "utils/memutils.h"
diff --git a/src/backend/utils/adt/mac.c b/src/backend/utils/adt/mac.c
index f9eb0b57d8..8aeddc6863 100644
--- a/src/backend/utils/adt/mac.c
+++ b/src/backend/utils/adt/mac.c
@@ -13,12 +13,12 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "lib/hyperloglog.h"
#include "libpq/pqformat.h"
#include "port/pg_bswap.h"
#include "utils/builtins.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/inet.h"
#include "utils/sortsupport.h"
diff --git a/src/backend/utils/adt/mac8.c b/src/backend/utils/adt/mac8.c
index 571eee920f..b7b2968b92 100644
--- a/src/backend/utils/adt/mac8.c
+++ b/src/backend/utils/adt/mac8.c
@@ -21,9 +21,9 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/inet.h"
/*
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index a6dd8b75aa..0ab54316f8 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -15,6 +15,7 @@
#include "access/stratnum.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/ip.h"
#include "lib/hyperloglog.h"
#include "libpq/libpq-be.h"
@@ -26,7 +27,6 @@
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/inet.h"
#include "utils/lsyscache.h"
#include "utils/sortsupport.h"
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index c92ad5a4fe..bd00f23b94 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -27,6 +27,7 @@
#include <math.h>
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/int.h"
#include "funcapi.h"
#include "lib/hyperloglog.h"
@@ -38,7 +39,6 @@
#include "utils/builtins.h"
#include "utils/float.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/int8.h"
#include "utils/numeric.h"
#include "utils/sortsupport.h"
diff --git a/src/backend/utils/adt/rangetypes.c b/src/backend/utils/adt/rangetypes.c
index 639e1dad6c..b95132b714 100644
--- a/src/backend/utils/adt/rangetypes.c
+++ b/src/backend/utils/adt/rangetypes.c
@@ -31,12 +31,12 @@
#include "postgres.h"
#include "access/tupmacs.h"
+#include "common/hashfn.h"
#include "lib/stringinfo.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/date.h"
-#include "utils/hashutils.h"
#include "utils/int8.h"
#include "utils/lsyscache.h"
#include "utils/rangetypes.h"
diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c
index fad2057754..4ce8375eab 100644
--- a/src/backend/utils/adt/tid.c
+++ b/src/backend/utils/adt/tid.c
@@ -25,12 +25,12 @@
#include "access/tableam.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "parser/parsetree.h"
#include "utils/acl.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/varlena.h"
diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c
index 4abd861dd7..c906ee789d 100644
--- a/src/backend/utils/adt/uuid.c
+++ b/src/backend/utils/adt/uuid.c
@@ -13,12 +13,12 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "lib/hyperloglog.h"
#include "libpq/pqformat.h"
#include "port/pg_bswap.h"
#include "utils/builtins.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/sortsupport.h"
#include "utils/uuid.h"
diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c
index 1e1239a1ba..39acfdff6c 100644
--- a/src/backend/utils/adt/varchar.c
+++ b/src/backend/utils/adt/varchar.c
@@ -17,13 +17,13 @@
#include "access/detoast.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "nodes/nodeFuncs.h"
#include "nodes/supportnodes.h"
#include "utils/array.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/pg_locale.h"
#include "utils/varlena.h"
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 1b351cbc68..0d7baacca1 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -20,6 +20,7 @@
#include "access/detoast.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/int.h"
#include "lib/hyperloglog.h"
#include "libpq/pqformat.h"
@@ -29,7 +30,6 @@
#include "regex/regex.h"
#include "utils/builtins.h"
#include "utils/bytea.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/pg_locale.h"
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 64776e3209..3613ae5f44 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -24,6 +24,7 @@
#include "catalog/pg_collation.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#ifdef CATCACHE_STATS
#include "storage/ipc.h" /* for on_proc_exit */
@@ -32,7 +33,6 @@
#include "utils/builtins.h"
#include "utils/datum.h"
#include "utils/fmgroids.h"
-#include "utils/hashutils.h"
#include "utils/inval.h"
#include "utils/memutils.h"
#include "utils/rel.h"
diff --git a/src/backend/utils/hash/Makefile b/src/backend/utils/hash/Makefile
index fc7b165f7f..d4c1210e36 100644
--- a/src/backend/utils/hash/Makefile
+++ b/src/backend/utils/hash/Makefile
@@ -14,7 +14,6 @@ include $(top_builddir)/src/Makefile.global
OBJS = \
dynahash.o \
- hashfn.o \
pg_crc.o
include $(top_srcdir)/src/backend/common.mk
diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index d245e1aa12..b5381958e7 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -86,10 +86,10 @@
#include <limits.h>
#include "access/xact.h"
+#include "common/hashfn.h"
#include "storage/shmem.h"
#include "storage/spin.h"
#include "utils/dynahash.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
diff --git a/src/backend/utils/resowner/resowner.c b/src/backend/utils/resowner/resowner.c
index ac6f226f59..3c39e48825 100644
--- a/src/backend/utils/resowner/resowner.c
+++ b/src/backend/utils/resowner/resowner.c
@@ -20,12 +20,12 @@
*/
#include "postgres.h"
+#include "common/hashfn.h"
#include "jit/jit.h"
#include "storage/bufmgr.h"
#include "storage/ipc.h"
#include "storage/predicate.h"
#include "storage/proc.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/resowner_private.h"
diff --git a/src/common/Makefile b/src/common/Makefile
index e757fb7399..b78898462e 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -55,6 +55,7 @@ OBJS_COMMON = \
exec.o \
f2s.o \
file_perm.o \
+ hashfn.o \
ip.o \
jsonapi.o \
keywords.o \
diff --git a/src/backend/utils/hash/hashfn.c b/src/common/hashfn.c
similarity index 99%
rename from src/backend/utils/hash/hashfn.c
rename to src/common/hashfn.c
index f34dd08811..6a01ddb423 100644
--- a/src/backend/utils/hash/hashfn.c
+++ b/src/common/hashfn.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * src/backend/utils/hash/hashfn.c
+ * src/common/hashfn.c
*
* NOTES
* It is expected that every bit of a hash function's 32-bit result is
@@ -23,7 +23,7 @@
*/
#include "postgres.h"
-#include "utils/hashutils.h"
+#include "common/hashfn.h"
/*
diff --git a/src/include/access/hash.h b/src/include/access/hash.h
index 9fc0696096..2707e1924b 100644
--- a/src/include/access/hash.h
+++ b/src/include/access/hash.h
@@ -21,10 +21,10 @@
#include "access/itup.h"
#include "access/sdir.h"
#include "catalog/pg_am_d.h"
+#include "common/hashfn.h"
#include "lib/stringinfo.h"
#include "storage/bufmgr.h"
#include "storage/lockdefs.h"
-#include "utils/hashutils.h"
#include "utils/hsearch.h"
#include "utils/relcache.h"
diff --git a/src/include/utils/hashutils.h b/src/include/common/hashfn.h
similarity index 97%
rename from src/include/utils/hashutils.h
rename to src/include/common/hashfn.h
index de79fcc699..40bf239007 100644
--- a/src/include/utils/hashutils.h
+++ b/src/include/common/hashfn.h
@@ -4,8 +4,8 @@
* Portions Copyright (c) 2017-2020, PostgreSQL Global Development Group
*/
-#ifndef HASHUTILS_H
-#define HASHUTILS_H
+#ifndef HASHFN_H
+#define HASHFN_H
/*
@@ -107,4 +107,4 @@ murmurhash32(uint32 data)
return h;
}
-#endif /* HASHUTILS_H */
+#endif /* HASHFN_H */
--
2.17.2 (Apple Git-113)
0003-Adapt-hashfn.c-and-hashutils.h-for-frontend-use.patchapplication/octet-stream; name=0003-Adapt-hashfn.c-and-hashutils.h-for-frontend-use.patchDownload
From 8e281e906d6f16c9d6168d2ee561bb42ca54a1e6 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 7 Feb 2020 10:42:47 -0500
Subject: [PATCH 3/4] Adapt hashfn.c and hashutils.h for frontend use.
hash_any() and its various variants are defiend to return Datum,
which is a backend-only concept, but the underlying functions
actually want to return uint32 and uint64, and only return Datum
because it's convenient for callers who are using them to
implement a hash function for some SQL datatype.
However, changing these functions to return uint32 and uint64
seems like it might lead to programming errors or back-patching
difficulties, both because they are widely used and because
failure to use UInt{32,64}GetDatum() might not provoke a
compilation error. Instead, rename the existing functions as
well as changing the return type, and add static inline wrappers
for those callers that need the previous behavior.
Although this commit adapts hashutils.h and hashfn.c so that they
can be compiled as frontend code, it does not actually do
anything that would cause them to be so compiled. That is left
for another commit.
---
src/backend/utils/hash/hashfn.c | 52 +++++++++++++++------------------
src/include/utils/hashutils.h | 42 ++++++++++++++++++++++----
2 files changed, 61 insertions(+), 33 deletions(-)
diff --git a/src/backend/utils/hash/hashfn.c b/src/backend/utils/hash/hashfn.c
index fa46c59d25..f34dd08811 100644
--- a/src/backend/utils/hash/hashfn.c
+++ b/src/backend/utils/hash/hashfn.c
@@ -16,15 +16,14 @@
* It is expected that every bit of a hash function's 32-bit result is
* as random as every other; failure to ensure this is likely to lead
* to poor performance of hash tables. In most cases a hash
- * function should use hash_any() or its variant hash_uint32().
+ * function should use hash_bytes() or its variant hash_bytes_uint32(),
+ * or the wrappers hash_any() and hash_any_uint32 defined in hashfn.h.
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-#include "fmgr.h"
#include "utils/hashutils.h"
-#include "utils/hsearch.h"
/*
@@ -126,7 +125,7 @@
}
/*
- * hash_any() -- hash a variable-length key into a 32-bit value
+ * hash_bytes() -- hash a variable-length key into a 32-bit value
* k : the key (the unaligned variable-length array of bytes)
* len : the length of the key, counting by bytes
*
@@ -143,8 +142,8 @@
* by using the final values of both b and c. b is perhaps a little less
* well mixed than c, however.
*/
-Datum
-hash_any(const unsigned char *k, int keylen)
+uint32
+hash_bytes(const unsigned char *k, int keylen)
{
uint32 a,
b,
@@ -358,20 +357,19 @@ hash_any(const unsigned char *k, int keylen)
final(a, b, c);
/* report the result */
- return UInt32GetDatum(c);
+ return c;
}
/*
- * hash_any_extended() -- hash into a 64-bit value, using an optional seed
+ * hash_bytes_extended() -- hash into a 64-bit value, using an optional seed
* k : the key (the unaligned variable-length array of bytes)
* len : the length of the key, counting by bytes
* seed : a 64-bit seed (0 means no seed)
*
- * Returns a uint64 value. Otherwise similar to hash_any.
+ * Returns a uint64 value. Otherwise similar to hash_bytes.
*/
-Datum
-hash_any_extended(const unsigned char *k, int keylen,
- uint64 seed)
+uint64
+hash_bytes_extended(const unsigned char *k, int keylen, uint64 seed)
{
uint32 a,
b,
@@ -598,18 +596,18 @@ hash_any_extended(const unsigned char *k, int keylen,
final(a, b, c);
/* report the result */
- PG_RETURN_UINT64(((uint64) b << 32) | c);
+ return ((uint64) b << 32) | c;
}
/*
- * hash_uint32() -- hash a 32-bit value to a 32-bit value
+ * hash_bytes_uint32() -- hash a 32-bit value to a 32-bit value
*
* This has the same result as
- * hash_any(&k, sizeof(uint32))
+ * hash_bytes(&k, sizeof(uint32))
* but is faster and doesn't force the caller to store k into memory.
*/
-Datum
-hash_uint32(uint32 k)
+uint32
+hash_bytes_uint32(uint32 k)
{
uint32 a,
b,
@@ -621,16 +619,16 @@ hash_uint32(uint32 k)
final(a, b, c);
/* report the result */
- return UInt32GetDatum(c);
+ return c;
}
/*
- * hash_uint32_extended() -- hash a 32-bit value to a 64-bit value, with a seed
+ * hash_bytes_uint32_extended() -- hash 32-bit value to 64-bit value, with seed
*
- * Like hash_uint32, this is a convenience function.
+ * Like hash_bytes_uint32, this is a convenience function.
*/
-Datum
-hash_uint32_extended(uint32 k, uint64 seed)
+uint64
+hash_bytes_uint32_extended(uint32 k, uint64 seed)
{
uint32 a,
b,
@@ -650,7 +648,7 @@ hash_uint32_extended(uint32 k, uint64 seed)
final(a, b, c);
/* report the result */
- PG_RETURN_UINT64(((uint64) b << 32) | c);
+ return ((uint64) b << 32) | c;
}
/*
@@ -669,8 +667,7 @@ string_hash(const void *key, Size keysize)
Size s_len = strlen((const char *) key);
s_len = Min(s_len, keysize - 1);
- return DatumGetUInt32(hash_any((const unsigned char *) key,
- (int) s_len));
+ return hash_bytes((const unsigned char *) key, (int) s_len);
}
/*
@@ -679,8 +676,7 @@ string_hash(const void *key, Size keysize)
uint32
tag_hash(const void *key, Size keysize)
{
- return DatumGetUInt32(hash_any((const unsigned char *) key,
- (int) keysize));
+ return hash_bytes((const unsigned char *) key, (int) keysize);
}
/*
@@ -692,5 +688,5 @@ uint32
uint32_hash(const void *key, Size keysize)
{
Assert(keysize == sizeof(uint32));
- return DatumGetUInt32(hash_uint32(*((const uint32 *) key)));
+ return hash_bytes_uint32(*((const uint32 *) key));
}
diff --git a/src/include/utils/hashutils.h b/src/include/utils/hashutils.h
index f2ae55194a..de79fcc699 100644
--- a/src/include/utils/hashutils.h
+++ b/src/include/utils/hashutils.h
@@ -20,11 +20,43 @@
(((v) >> 31) & UINT64CONST(0x100000001)))
-extern Datum hash_any(const unsigned char *k, int keylen);
-extern Datum hash_any_extended(const unsigned char *k,
- int keylen, uint64 seed);
-extern Datum hash_uint32(uint32 k);
-extern Datum hash_uint32_extended(uint32 k, uint64 seed);
+extern uint32 hash_bytes(const unsigned char *k, int keylen);
+extern uint64 hash_bytes_extended(const unsigned char *k,
+ int keylen, uint64 seed);
+extern uint32 hash_bytes_uint32(uint32 k);
+extern uint64 hash_bytes_uint32_extended(uint32 k, uint64 seed);
+
+#ifndef FRONTEND
+static inline Datum
+hash_any(const unsigned char *k, int keylen)
+{
+ return UInt32GetDatum(hash_bytes(k, keylen));
+}
+
+static inline Datum
+hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
+{
+ return UInt64GetDatum(hash_bytes_extended(k, keylen, seed));
+}
+
+static inline Datum
+hash_uint32(uint32 k)
+{
+ return UInt32GetDatum(hash_bytes_uint32(k));
+}
+
+static inline Datum
+hash_uint32_extended(uint32 k, uint64 seed)
+{
+ return UInt64GetDatum(hash_bytes_uint32_extended(k, seed));
+}
+#endif
+
+extern uint32 hash_bytes(const unsigned char *k, int keylen);
+extern uint64 hash_bytes_extended(const unsigned char *k,
+ int keylen, uint64 seed);
+extern uint32 hash_bytes_uint32(uint32 k);
+extern uint64 hash_bytes_uint32_extended(uint32 k, uint64 seed);
extern uint32 string_hash(const void *key, Size keysize);
extern uint32 tag_hash(const void *key, Size keysize);
--
2.17.2 (Apple Git-113)
0002-Put-all-the-prototypes-for-hashfn.c-into-the-same-he.patchapplication/octet-stream; name=0002-Put-all-the-prototypes-for-hashfn.c-into-the-same-he.patchDownload
From dce13da2e1d8b6a7a76f6a33fc2a433200edd4db Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 7 Feb 2020 11:04:30 -0500
Subject: [PATCH 2/4] Put all the prototypes for hashfn.c into the same header
file.
Previously, some of the prototypes for functions in hashfn.c were
in utils/hashutils.h and others were in utils/hsearch.h, but that
is confusing and has no particular benefit.
---
src/backend/lib/dshash.c | 2 +-
src/backend/utils/hash/dynahash.c | 1 +
src/include/utils/hashutils.h | 6 ++++++
src/include/utils/hsearch.h | 17 ++++-------------
4 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/src/backend/lib/dshash.c b/src/backend/lib/dshash.c
index fbdd941325..5e0167d9b0 100644
--- a/src/backend/lib/dshash.c
+++ b/src/backend/lib/dshash.c
@@ -35,7 +35,7 @@
#include "storage/ipc.h"
#include "storage/lwlock.h"
#include "utils/dsa.h"
-#include "utils/hsearch.h"
+#include "utils/hashutils.h"
#include "utils/memutils.h"
/*
diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index c9026f0e1a..d245e1aa12 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -89,6 +89,7 @@
#include "storage/shmem.h"
#include "storage/spin.h"
#include "utils/dynahash.h"
+#include "utils/hashutils.h"
#include "utils/memutils.h"
diff --git a/src/include/utils/hashutils.h b/src/include/utils/hashutils.h
index 9a2e13f536..f2ae55194a 100644
--- a/src/include/utils/hashutils.h
+++ b/src/include/utils/hashutils.h
@@ -26,6 +26,12 @@ extern Datum hash_any_extended(const unsigned char *k,
extern Datum hash_uint32(uint32 k);
extern Datum hash_uint32_extended(uint32 k, uint64 seed);
+extern uint32 string_hash(const void *key, Size keysize);
+extern uint32 tag_hash(const void *key, Size keysize);
+extern uint32 uint32_hash(const void *key, Size keysize);
+
+#define oid_hash uint32_hash /* Remove me eventually */
+
/*
* Combine two 32-bit hash values, resulting in another hash value, with
* decent bit mixing.
diff --git a/src/include/utils/hsearch.h b/src/include/utils/hsearch.h
index 934c4a399e..f1deb9beab 100644
--- a/src/include/utils/hsearch.h
+++ b/src/include/utils/hsearch.h
@@ -118,6 +118,10 @@ typedef struct
/*
* prototypes for functions in dynahash.c
+ *
+ * Note: It is deprecated for callers of hash_create to explicitly specify
+ * string_hash, tag_hash, uint32_hash, or oid_hash. Just set HASH_BLOBS or
+ * not. Use HASH_FUNCTION only when you want something other than those.
*/
extern HTAB *hash_create(const char *tabname, long nelem,
HASHCTL *info, int flags);
@@ -142,17 +146,4 @@ extern Size hash_get_shared_size(HASHCTL *info, int flags);
extern void AtEOXact_HashTables(bool isCommit);
extern void AtEOSubXact_HashTables(bool isCommit, int nestDepth);
-/*
- * prototypes for functions in hashfn.c
- *
- * Note: It is deprecated for callers of hash_create to explicitly specify
- * string_hash, tag_hash, uint32_hash, or oid_hash. Just set HASH_BLOBS or
- * not. Use HASH_FUNCTION only when you want something other than those.
- */
-extern uint32 string_hash(const void *key, Size keysize);
-extern uint32 tag_hash(const void *key, Size keysize);
-extern uint32 uint32_hash(const void *key, Size keysize);
-
-#define oid_hash uint32_hash /* Remove me eventually */
-
#endif /* HSEARCH_H */
--
2.17.2 (Apple Git-113)
Hi,
I have spent some time reviewing the patches and overall it looks good to
me.
However, I have few cosmetic review comments for 0003 patch as below;
1:
+++ b/src/backend/utils/hash/hashfn.c
@@ -16,15 +16,14 @@
* It is expected that every bit of a hash function's 32-bit result is
* as random as every other; failure to ensure this is likely to lead
* to poor performance of hash tables. In most cases a hash
- * function should use hash_any() or its variant hash_uint32().
+ * function should use hash_bytes() or its variant hash_bytes_uint32(),
+ * or the wrappers hash_any() and *hash_any_uint32* defined in hashfn.h.
Here, indicated function name should be *hash_uint32*.
2: I can see renamed functions are declared twice in hashutils.c. I think
duplicate declarations after #endif can be removed,
+extern uint32 hash_bytes(const unsigned char *k, int keylen);
+extern uint64 hash_bytes_extended(const unsigned char *k,
+ int keylen, uint64 seed);
+extern uint32 hash_bytes_uint32(uint32 k);
+extern uint64 hash_bytes_uint32_extended(uint32 k, uint64 seed);
+
+#ifndef FRONTEND
..
Wrapper functions
..
+#endif
+
+extern uint32 hash_bytes(const unsigned char *k, int keylen);
+extern uint64 hash_bytes_extended(const unsigned char *k,
+ int keylen, uint64 seed);
+extern uint32 hash_bytes_uint32(uint32 k);
+extern uint64 hash_bytes_uint32_extended(uint32 k, uint64 seed);
3: The first line of the commit message has one typo.
defiend => defined.
On Fri, Feb 7, 2020 at 11:00 PM Robert Haas <robertmhaas@gmail.com> wrote:
Late last year, I did some work to make it possible to use simplehash
in frontend code.[1] However, a hash table is not much good unless one
also has some hash functions that one can use to hash the keys that
need to be inserted into that hash table. I initially thought that
solving this problem was going to be pretty annoying, but when I
looked at it again today I found what I think is a pretty simple way
to adapt things so that the hashing routines we use in the backend are
easily available to frontend code.Here are some patches for that. It may make sense to combine some of
these in terms of actually getting this committed, but I have
separated them here so that it is, hopefully, easy to see what I did
and why I did it. There are three basic problems which are solved by
the three preparatory patches:0001 - hashfn.c has a couple of routines that depend on bitmapsets,
and bitmapset.c is currently backend-only. Fix by moving this code
near related code in bitmapset.c.0002 - some of the prototypes for functions in hashfn.c are in
hsearch.h, mixed with the dynahash stuff, and others are in
hashutils.c. Fix by making hashutils.h the one true header for
hashfn.c.0003 - Some of hashfn.c's routines return Datum, but that's
backend-only. Fix by renaming the functions and changing the return
types to uint32 and uint64, and add static inline wrappers with the
old names that convert to Datum. Just changing the return types of the
existing functions seemed like it would've required a lot more code
churn, and also seems like it could cause silent breakage in the
future.Thanks,
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company[1]
/messages/by-id/CA+Tgmob8oyh02NrZW=xCScB+5GyJ-jVowE3+TWTUmPF=FsGWTA@mail.gmail.com
--
--
Thanks & Regards,
Suraj kharage,
EnterpriseDB Corporation,
The Postgres Database Company.
On Feb 13, 2020, at 3:44 AM, Suraj Kharage <suraj.kharage@enterprisedb.com> wrote:
Hi,
I have spent some time reviewing the patches and overall it looks good to me.
However, I have few cosmetic review comments for 0003 patch as below;
1: +++ b/src/backend/utils/hash/hashfn.c @@ -16,15 +16,14 @@ * It is expected that every bit of a hash function's 32-bit result is * as random as every other; failure to ensure this is likely to lead * to poor performance of hash tables. In most cases a hash - * function should use hash_any() or its variant hash_uint32(). + * function should use hash_bytes() or its variant hash_bytes_uint32(), + * or the wrappers hash_any() and hash_any_uint32 defined in hashfn.h.Here, indicated function name should be hash_uint32.
+1
2: I can see renamed functions are declared twice in hashutils.c. I think duplicate declarations after #endif can be removed,
+extern uint32 hash_bytes(const unsigned char *k, int keylen); +extern uint64 hash_bytes_extended(const unsigned char *k, + int keylen, uint64 seed); +extern uint32 hash_bytes_uint32(uint32 k); +extern uint64 hash_bytes_uint32_extended(uint32 k, uint64 seed); + +#ifndef FRONTEND .. Wrapper functions .. +#endif + +extern uint32 hash_bytes(const unsigned char *k, int keylen); +extern uint64 hash_bytes_extended(const unsigned char *k, + int keylen, uint64 seed); +extern uint32 hash_bytes_uint32(uint32 k); +extern uint64 hash_bytes_uint32_extended(uint32 k, uint64 seed);
+1
3: The first line of the commit message has one typo.
defiend => defined.
+1
I have made these changes and rebased Robert’s patches but otherwise changed nothing. Here they are:
Attachments:
v2-0001-Move-bitmap_hash-and-bitmap_match-to-bitmapset.c.patchapplication/octet-stream; name=v2-0001-Move-bitmap_hash-and-bitmap_match-to-bitmapset.c.patch; x-unix-mode=0644Download
From 78db14088784a9b1f234cbe28bbab49fe2c64a5d Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 7 Feb 2020 11:25:46 -0500
Subject: [PATCH v2 1/4] Move bitmap_hash and bitmap_match to bitmapset.c.
The closely-related function bms_hash_value is already defined in that
file, and this change means that hashfn.c no longer needs to depend on
nodes/bitmapset.h.
---
src/backend/nodes/bitmapset.c | 23 +++++++++++++++++++++++
src/backend/utils/hash/hashfn.c | 24 ------------------------
src/include/nodes/bitmapset.h | 2 ++
src/include/utils/hsearch.h | 2 --
4 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/src/backend/nodes/bitmapset.c b/src/backend/nodes/bitmapset.c
index 648cc1a7eb..f711e6c699 100644
--- a/src/backend/nodes/bitmapset.c
+++ b/src/backend/nodes/bitmapset.c
@@ -1167,3 +1167,26 @@ bms_hash_value(const Bitmapset *a)
return DatumGetUInt32(hash_any((const unsigned char *) a->words,
(lastword + 1) * sizeof(bitmapword)));
}
+
+/*
+ * bitmap_hash - hash function for keys that are (pointers to) Bitmapsets
+ *
+ * Note: don't forget to specify bitmap_match as the match function!
+ */
+uint32
+bitmap_hash(const void *key, Size keysize)
+{
+ Assert(keysize == sizeof(Bitmapset *));
+ return bms_hash_value(*((const Bitmapset *const *) key));
+}
+
+/*
+ * bitmap_match - match function to use with bitmap_hash
+ */
+int
+bitmap_match(const void *key1, const void *key2, Size keysize)
+{
+ Assert(keysize == sizeof(Bitmapset *));
+ return !bms_equal(*((const Bitmapset *const *) key1),
+ *((const Bitmapset *const *) key2));
+}
diff --git a/src/backend/utils/hash/hashfn.c b/src/backend/utils/hash/hashfn.c
index dc3cbac7ef..fa46c59d25 100644
--- a/src/backend/utils/hash/hashfn.c
+++ b/src/backend/utils/hash/hashfn.c
@@ -23,7 +23,6 @@
#include "postgres.h"
#include "fmgr.h"
-#include "nodes/bitmapset.h"
#include "utils/hashutils.h"
#include "utils/hsearch.h"
@@ -695,26 +694,3 @@ uint32_hash(const void *key, Size keysize)
Assert(keysize == sizeof(uint32));
return DatumGetUInt32(hash_uint32(*((const uint32 *) key)));
}
-
-/*
- * bitmap_hash: hash function for keys that are (pointers to) Bitmapsets
- *
- * Note: don't forget to specify bitmap_match as the match function!
- */
-uint32
-bitmap_hash(const void *key, Size keysize)
-{
- Assert(keysize == sizeof(Bitmapset *));
- return bms_hash_value(*((const Bitmapset *const *) key));
-}
-
-/*
- * bitmap_match: match function to use with bitmap_hash
- */
-int
-bitmap_match(const void *key1, const void *key2, Size keysize)
-{
- Assert(keysize == sizeof(Bitmapset *));
- return !bms_equal(*((const Bitmapset *const *) key1),
- *((const Bitmapset *const *) key2));
-}
diff --git a/src/include/nodes/bitmapset.h b/src/include/nodes/bitmapset.h
index b7b18a0b68..d113c271ee 100644
--- a/src/include/nodes/bitmapset.h
+++ b/src/include/nodes/bitmapset.h
@@ -116,5 +116,7 @@ extern int bms_prev_member(const Bitmapset *a, int prevbit);
/* support for hashtables using Bitmapsets as keys: */
extern uint32 bms_hash_value(const Bitmapset *a);
+extern uint32 bitmap_hash(const void *key, Size keysize);
+extern int bitmap_match(const void *key1, const void *key2, Size keysize);
#endif /* BITMAPSET_H */
diff --git a/src/include/utils/hsearch.h b/src/include/utils/hsearch.h
index b0077b7827..934c4a399e 100644
--- a/src/include/utils/hsearch.h
+++ b/src/include/utils/hsearch.h
@@ -152,8 +152,6 @@ extern void AtEOSubXact_HashTables(bool isCommit, int nestDepth);
extern uint32 string_hash(const void *key, Size keysize);
extern uint32 tag_hash(const void *key, Size keysize);
extern uint32 uint32_hash(const void *key, Size keysize);
-extern uint32 bitmap_hash(const void *key, Size keysize);
-extern int bitmap_match(const void *key1, const void *key2, Size keysize);
#define oid_hash uint32_hash /* Remove me eventually */
--
2.21.1 (Apple Git-122.3)
v2-0002-Put-all-the-prototypes-for-hashfn.c-into-the-same.patchapplication/octet-stream; name=v2-0002-Put-all-the-prototypes-for-hashfn.c-into-the-same.patch; x-unix-mode=0644Download
From 7f1c70b5c9cb2cbb4a52f8b87d3ddf6300d1d08a Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 7 Feb 2020 11:04:30 -0500
Subject: [PATCH v2 2/4] Put all the prototypes for hashfn.c into the same
header file.
Previously, some of the prototypes for functions in hashfn.c were
in utils/hashutils.h and others were in utils/hsearch.h, but that
is confusing and has no particular benefit.
---
src/backend/lib/dshash.c | 2 +-
src/backend/utils/hash/dynahash.c | 1 +
src/include/utils/hashutils.h | 6 ++++++
src/include/utils/hsearch.h | 17 ++++-------------
4 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/src/backend/lib/dshash.c b/src/backend/lib/dshash.c
index fbdd941325..5e0167d9b0 100644
--- a/src/backend/lib/dshash.c
+++ b/src/backend/lib/dshash.c
@@ -35,7 +35,7 @@
#include "storage/ipc.h"
#include "storage/lwlock.h"
#include "utils/dsa.h"
-#include "utils/hsearch.h"
+#include "utils/hashutils.h"
#include "utils/memutils.h"
/*
diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index c9026f0e1a..d245e1aa12 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -89,6 +89,7 @@
#include "storage/shmem.h"
#include "storage/spin.h"
#include "utils/dynahash.h"
+#include "utils/hashutils.h"
#include "utils/memutils.h"
diff --git a/src/include/utils/hashutils.h b/src/include/utils/hashutils.h
index 9a2e13f536..f2ae55194a 100644
--- a/src/include/utils/hashutils.h
+++ b/src/include/utils/hashutils.h
@@ -26,6 +26,12 @@ extern Datum hash_any_extended(const unsigned char *k,
extern Datum hash_uint32(uint32 k);
extern Datum hash_uint32_extended(uint32 k, uint64 seed);
+extern uint32 string_hash(const void *key, Size keysize);
+extern uint32 tag_hash(const void *key, Size keysize);
+extern uint32 uint32_hash(const void *key, Size keysize);
+
+#define oid_hash uint32_hash /* Remove me eventually */
+
/*
* Combine two 32-bit hash values, resulting in another hash value, with
* decent bit mixing.
diff --git a/src/include/utils/hsearch.h b/src/include/utils/hsearch.h
index 934c4a399e..f1deb9beab 100644
--- a/src/include/utils/hsearch.h
+++ b/src/include/utils/hsearch.h
@@ -118,6 +118,10 @@ typedef struct
/*
* prototypes for functions in dynahash.c
+ *
+ * Note: It is deprecated for callers of hash_create to explicitly specify
+ * string_hash, tag_hash, uint32_hash, or oid_hash. Just set HASH_BLOBS or
+ * not. Use HASH_FUNCTION only when you want something other than those.
*/
extern HTAB *hash_create(const char *tabname, long nelem,
HASHCTL *info, int flags);
@@ -142,17 +146,4 @@ extern Size hash_get_shared_size(HASHCTL *info, int flags);
extern void AtEOXact_HashTables(bool isCommit);
extern void AtEOSubXact_HashTables(bool isCommit, int nestDepth);
-/*
- * prototypes for functions in hashfn.c
- *
- * Note: It is deprecated for callers of hash_create to explicitly specify
- * string_hash, tag_hash, uint32_hash, or oid_hash. Just set HASH_BLOBS or
- * not. Use HASH_FUNCTION only when you want something other than those.
- */
-extern uint32 string_hash(const void *key, Size keysize);
-extern uint32 tag_hash(const void *key, Size keysize);
-extern uint32 uint32_hash(const void *key, Size keysize);
-
-#define oid_hash uint32_hash /* Remove me eventually */
-
#endif /* HSEARCH_H */
--
2.21.1 (Apple Git-122.3)
v2-0003-Adapt-hashfn.c-and-hashutils.h-for-frontend-use.patchapplication/octet-stream; name=v2-0003-Adapt-hashfn.c-and-hashutils.h-for-frontend-use.patch; x-unix-mode=0644Download
From 39bbefb8c273b6d7785c95276954f1fda1e9b076 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 7 Feb 2020 10:42:47 -0500
Subject: [PATCH v2 3/4] Adapt hashfn.c and hashutils.h for frontend use.
hash_any() and its various variants are defined to return Datum,
which is a backend-only concept, but the underlying functions
actually want to return uint32 and uint64, and only return Datum
because it's convenient for callers who are using them to
implement a hash function for some SQL datatype.
However, changing these functions to return uint32 and uint64
seems like it might lead to programming errors or back-patching
difficulties, both because they are widely used and because
failure to use UInt{32,64}GetDatum() might not provoke a
compilation error. Instead, rename the existing functions as
well as changing the return type, and add static inline wrappers
for those callers that need the previous behavior.
Although this commit adapts hashutils.h and hashfn.c so that they
can be compiled as frontend code, it does not actually do
anything that would cause them to be so compiled. That is left
for another commit.
---
src/backend/utils/hash/hashfn.c | 52 +++++++++++++++------------------
src/include/utils/hashutils.h | 36 +++++++++++++++++++----
2 files changed, 55 insertions(+), 33 deletions(-)
diff --git a/src/backend/utils/hash/hashfn.c b/src/backend/utils/hash/hashfn.c
index fa46c59d25..ecc52014af 100644
--- a/src/backend/utils/hash/hashfn.c
+++ b/src/backend/utils/hash/hashfn.c
@@ -16,15 +16,14 @@
* It is expected that every bit of a hash function's 32-bit result is
* as random as every other; failure to ensure this is likely to lead
* to poor performance of hash tables. In most cases a hash
- * function should use hash_any() or its variant hash_uint32().
+ * function should use hash_bytes() or its variant hash_bytes_uint32(),
+ * or the wrappers hash_any() and hash_uint32 defined in hashfn.h.
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-#include "fmgr.h"
#include "utils/hashutils.h"
-#include "utils/hsearch.h"
/*
@@ -126,7 +125,7 @@
}
/*
- * hash_any() -- hash a variable-length key into a 32-bit value
+ * hash_bytes() -- hash a variable-length key into a 32-bit value
* k : the key (the unaligned variable-length array of bytes)
* len : the length of the key, counting by bytes
*
@@ -143,8 +142,8 @@
* by using the final values of both b and c. b is perhaps a little less
* well mixed than c, however.
*/
-Datum
-hash_any(const unsigned char *k, int keylen)
+uint32
+hash_bytes(const unsigned char *k, int keylen)
{
uint32 a,
b,
@@ -358,20 +357,19 @@ hash_any(const unsigned char *k, int keylen)
final(a, b, c);
/* report the result */
- return UInt32GetDatum(c);
+ return c;
}
/*
- * hash_any_extended() -- hash into a 64-bit value, using an optional seed
+ * hash_bytes_extended() -- hash into a 64-bit value, using an optional seed
* k : the key (the unaligned variable-length array of bytes)
* len : the length of the key, counting by bytes
* seed : a 64-bit seed (0 means no seed)
*
- * Returns a uint64 value. Otherwise similar to hash_any.
+ * Returns a uint64 value. Otherwise similar to hash_bytes.
*/
-Datum
-hash_any_extended(const unsigned char *k, int keylen,
- uint64 seed)
+uint64
+hash_bytes_extended(const unsigned char *k, int keylen, uint64 seed)
{
uint32 a,
b,
@@ -598,18 +596,18 @@ hash_any_extended(const unsigned char *k, int keylen,
final(a, b, c);
/* report the result */
- PG_RETURN_UINT64(((uint64) b << 32) | c);
+ return ((uint64) b << 32) | c;
}
/*
- * hash_uint32() -- hash a 32-bit value to a 32-bit value
+ * hash_bytes_uint32() -- hash a 32-bit value to a 32-bit value
*
* This has the same result as
- * hash_any(&k, sizeof(uint32))
+ * hash_bytes(&k, sizeof(uint32))
* but is faster and doesn't force the caller to store k into memory.
*/
-Datum
-hash_uint32(uint32 k)
+uint32
+hash_bytes_uint32(uint32 k)
{
uint32 a,
b,
@@ -621,16 +619,16 @@ hash_uint32(uint32 k)
final(a, b, c);
/* report the result */
- return UInt32GetDatum(c);
+ return c;
}
/*
- * hash_uint32_extended() -- hash a 32-bit value to a 64-bit value, with a seed
+ * hash_bytes_uint32_extended() -- hash 32-bit value to 64-bit value, with seed
*
- * Like hash_uint32, this is a convenience function.
+ * Like hash_bytes_uint32, this is a convenience function.
*/
-Datum
-hash_uint32_extended(uint32 k, uint64 seed)
+uint64
+hash_bytes_uint32_extended(uint32 k, uint64 seed)
{
uint32 a,
b,
@@ -650,7 +648,7 @@ hash_uint32_extended(uint32 k, uint64 seed)
final(a, b, c);
/* report the result */
- PG_RETURN_UINT64(((uint64) b << 32) | c);
+ return ((uint64) b << 32) | c;
}
/*
@@ -669,8 +667,7 @@ string_hash(const void *key, Size keysize)
Size s_len = strlen((const char *) key);
s_len = Min(s_len, keysize - 1);
- return DatumGetUInt32(hash_any((const unsigned char *) key,
- (int) s_len));
+ return hash_bytes((const unsigned char *) key, (int) s_len);
}
/*
@@ -679,8 +676,7 @@ string_hash(const void *key, Size keysize)
uint32
tag_hash(const void *key, Size keysize)
{
- return DatumGetUInt32(hash_any((const unsigned char *) key,
- (int) keysize));
+ return hash_bytes((const unsigned char *) key, (int) keysize);
}
/*
@@ -692,5 +688,5 @@ uint32
uint32_hash(const void *key, Size keysize)
{
Assert(keysize == sizeof(uint32));
- return DatumGetUInt32(hash_uint32(*((const uint32 *) key)));
+ return hash_bytes_uint32(*((const uint32 *) key));
}
diff --git a/src/include/utils/hashutils.h b/src/include/utils/hashutils.h
index f2ae55194a..ba3ecb7592 100644
--- a/src/include/utils/hashutils.h
+++ b/src/include/utils/hashutils.h
@@ -20,11 +20,37 @@
(((v) >> 31) & UINT64CONST(0x100000001)))
-extern Datum hash_any(const unsigned char *k, int keylen);
-extern Datum hash_any_extended(const unsigned char *k,
- int keylen, uint64 seed);
-extern Datum hash_uint32(uint32 k);
-extern Datum hash_uint32_extended(uint32 k, uint64 seed);
+extern uint32 hash_bytes(const unsigned char *k, int keylen);
+extern uint64 hash_bytes_extended(const unsigned char *k,
+ int keylen, uint64 seed);
+extern uint32 hash_bytes_uint32(uint32 k);
+extern uint64 hash_bytes_uint32_extended(uint32 k, uint64 seed);
+
+#ifndef FRONTEND
+static inline Datum
+hash_any(const unsigned char *k, int keylen)
+{
+ return UInt32GetDatum(hash_bytes(k, keylen));
+}
+
+static inline Datum
+hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
+{
+ return UInt64GetDatum(hash_bytes_extended(k, keylen, seed));
+}
+
+static inline Datum
+hash_uint32(uint32 k)
+{
+ return UInt32GetDatum(hash_bytes_uint32(k));
+}
+
+static inline Datum
+hash_uint32_extended(uint32 k, uint64 seed)
+{
+ return UInt64GetDatum(hash_bytes_uint32_extended(k, seed));
+}
+#endif
extern uint32 string_hash(const void *key, Size keysize);
extern uint32 tag_hash(const void *key, Size keysize);
--
2.21.1 (Apple Git-122.3)
v2-0004-Move-src-backend-utils-hash-hashfn.c-to-src-commo.patchapplication/octet-stream; name=v2-0004-Move-src-backend-utils-hash-hashfn.c-to-src-commo.patch; x-unix-mode=0644Download
From 9172342412e585232d299450270526e2a2dae4ed Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 7 Feb 2020 12:18:03 -0500
Subject: [PATCH v2 4/4] Move src/backend/utils/hash/hashfn.c to src/common
This also involves renaming src/include/utils/hashutils.h, which
becomes src/include/common/hashfn.h. Perhaps an argument can be
made for keeping the hashutils.h name, but it seemed more
consistent to make it match the name of the file, and also more
descriptive of what is actually going on here.
---
contrib/citext/citext.c | 2 +-
contrib/hstore/hstore_op.c | 2 +-
contrib/pg_stat_statements/pg_stat_statements.c | 2 +-
contrib/sepgsql/uavc.c | 2 +-
src/backend/access/common/tupdesc.c | 2 +-
src/backend/access/hash/hashfunc.c | 2 +-
src/backend/access/tablesample/bernoulli.c | 2 +-
src/backend/access/tablesample/system.c | 2 +-
src/backend/commands/async.c | 2 +-
src/backend/executor/execGrouping.c | 2 +-
src/backend/lib/bloomfilter.c | 2 +-
src/backend/lib/dshash.c | 2 +-
src/backend/nodes/bitmapset.c | 2 +-
src/backend/nodes/tidbitmap.c | 2 +-
src/backend/partitioning/partbounds.c | 2 +-
src/backend/storage/file/sharedfileset.c | 2 +-
src/backend/tsearch/ts_typanalyze.c | 2 +-
src/backend/utils/adt/acl.c | 2 +-
src/backend/utils/adt/date.c | 2 +-
src/backend/utils/adt/jsonb_gin.c | 2 +-
src/backend/utils/adt/jsonb_util.c | 2 +-
src/backend/utils/adt/mac.c | 2 +-
src/backend/utils/adt/mac8.c | 2 +-
src/backend/utils/adt/network.c | 2 +-
src/backend/utils/adt/numeric.c | 2 +-
src/backend/utils/adt/rangetypes.c | 2 +-
src/backend/utils/adt/tid.c | 2 +-
src/backend/utils/adt/uuid.c | 2 +-
src/backend/utils/adt/varchar.c | 2 +-
src/backend/utils/adt/varlena.c | 2 +-
src/backend/utils/cache/catcache.c | 2 +-
src/backend/utils/hash/Makefile | 1 -
src/backend/utils/hash/dynahash.c | 2 +-
src/backend/utils/resowner/resowner.c | 2 +-
src/common/Makefile | 1 +
src/{backend/utils/hash => common}/hashfn.c | 4 ++--
src/include/access/hash.h | 2 +-
src/include/{utils/hashutils.h => common/hashfn.h} | 6 +++---
38 files changed, 40 insertions(+), 40 deletions(-)
rename src/{backend/utils/hash => common}/hashfn.c (99%)
rename src/include/{utils/hashutils.h => common/hashfn.h} (97%)
diff --git a/contrib/citext/citext.c b/contrib/citext/citext.c
index a4adafe895..df139462a6 100644
--- a/contrib/citext/citext.c
+++ b/contrib/citext/citext.c
@@ -4,9 +4,9 @@
#include "postgres.h"
#include "catalog/pg_collation.h"
+#include "common/hashfn.h"
#include "utils/builtins.h"
#include "utils/formatting.h"
-#include "utils/hashutils.h"
#include "utils/varlena.h"
PG_MODULE_MAGIC;
diff --git a/contrib/hstore/hstore_op.c b/contrib/hstore/hstore_op.c
index 01e59beaa3..fb1bb0681c 100644
--- a/contrib/hstore/hstore_op.c
+++ b/contrib/hstore/hstore_op.c
@@ -5,10 +5,10 @@
#include "access/htup_details.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "funcapi.h"
#include "hstore.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
/* old names for C functions */
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index e0dbeebde3..e4fda4b404 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -62,6 +62,7 @@
#include <unistd.h>
#include "catalog/pg_authid.h"
+#include "common/hashfn.h"
#include "executor/instrument.h"
#include "funcapi.h"
#include "mb/pg_wchar.h"
@@ -77,7 +78,6 @@
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
PG_MODULE_MAGIC;
diff --git a/contrib/sepgsql/uavc.c b/contrib/sepgsql/uavc.c
index d3723768a6..639a52c556 100644
--- a/contrib/sepgsql/uavc.c
+++ b/contrib/sepgsql/uavc.c
@@ -14,10 +14,10 @@
#include "catalog/pg_proc.h"
#include "commands/seclabel.h"
+#include "common/hashfn.h"
#include "sepgsql.h"
#include "storage/ipc.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
/*
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 00bb4cb53d..28835512f0 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -23,12 +23,12 @@
#include "access/tupdesc_details.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#include "parser/parse_type.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/datum.h"
-#include "utils/hashutils.h"
#include "utils/resowner_private.h"
#include "utils/syscache.h"
diff --git a/src/backend/access/hash/hashfunc.c b/src/backend/access/hash/hashfunc.c
index 5b517106ff..a8498226e3 100644
--- a/src/backend/access/hash/hashfunc.c
+++ b/src/backend/access/hash/hashfunc.c
@@ -28,8 +28,8 @@
#include "access/hash.h"
#include "catalog/pg_collation.h"
+#include "common/hashfn.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/pg_locale.h"
/*
diff --git a/src/backend/access/tablesample/bernoulli.c b/src/backend/access/tablesample/bernoulli.c
index 46016fb5de..606730d6cb 100644
--- a/src/backend/access/tablesample/bernoulli.c
+++ b/src/backend/access/tablesample/bernoulli.c
@@ -28,9 +28,9 @@
#include "access/tsmapi.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "optimizer/optimizer.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
/* Private state */
diff --git a/src/backend/access/tablesample/system.c b/src/backend/access/tablesample/system.c
index 8a5f03bfd3..29b7c0d3c2 100644
--- a/src/backend/access/tablesample/system.c
+++ b/src/backend/access/tablesample/system.c
@@ -29,9 +29,9 @@
#include "access/relscan.h"
#include "access/tsmapi.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "optimizer/optimizer.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
/* Private state */
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c
index 9aa2b61600..dae939a4ab 100644
--- a/src/backend/commands/async.c
+++ b/src/backend/commands/async.c
@@ -126,6 +126,7 @@
#include "access/xact.h"
#include "catalog/pg_database.h"
#include "commands/async.h"
+#include "common/hashfn.h"
#include "funcapi.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
@@ -138,7 +139,6 @@
#include "storage/sinval.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "utils/snapmgr.h"
diff --git a/src/backend/executor/execGrouping.c b/src/backend/executor/execGrouping.c
index de0205f4fc..f6c3e4cbde 100644
--- a/src/backend/executor/execGrouping.c
+++ b/src/backend/executor/execGrouping.c
@@ -19,9 +19,9 @@
#include "postgres.h"
#include "access/parallel.h"
+#include "common/hashfn.h"
#include "executor/executor.h"
#include "miscadmin.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
diff --git a/src/backend/lib/bloomfilter.c b/src/backend/lib/bloomfilter.c
index 29b62e70e4..f040e83c01 100644
--- a/src/backend/lib/bloomfilter.c
+++ b/src/backend/lib/bloomfilter.c
@@ -35,9 +35,9 @@
#include <math.h>
+#include "common/hashfn.h"
#include "lib/bloomfilter.h"
#include "port/pg_bitutils.h"
-#include "utils/hashutils.h"
#define MAX_HASH_FUNCS 10
diff --git a/src/backend/lib/dshash.c b/src/backend/lib/dshash.c
index 5e0167d9b0..78ccf03217 100644
--- a/src/backend/lib/dshash.c
+++ b/src/backend/lib/dshash.c
@@ -31,11 +31,11 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "lib/dshash.h"
#include "storage/ipc.h"
#include "storage/lwlock.h"
#include "utils/dsa.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
/*
diff --git a/src/backend/nodes/bitmapset.c b/src/backend/nodes/bitmapset.c
index f711e6c699..2719ea45a3 100644
--- a/src/backend/nodes/bitmapset.c
+++ b/src/backend/nodes/bitmapset.c
@@ -20,10 +20,10 @@
*/
#include "postgres.h"
+#include "common/hashfn.h"
#include "nodes/bitmapset.h"
#include "nodes/pg_list.h"
#include "port/pg_bitutils.h"
-#include "utils/hashutils.h"
#define WORDNUM(x) ((x) / BITS_PER_BITMAPWORD)
diff --git a/src/backend/nodes/tidbitmap.c b/src/backend/nodes/tidbitmap.c
index e102589e74..ad4e071ca3 100644
--- a/src/backend/nodes/tidbitmap.c
+++ b/src/backend/nodes/tidbitmap.c
@@ -41,11 +41,11 @@
#include <limits.h>
#include "access/htup_details.h"
+#include "common/hashfn.h"
#include "nodes/bitmapset.h"
#include "nodes/tidbitmap.h"
#include "storage/lwlock.h"
#include "utils/dsa.h"
-#include "utils/hashutils.h"
/*
* The maximum number of tuples per page is not large (typically 256 with
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 95af37b9c7..dfc2dc03cf 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -21,6 +21,7 @@
#include "catalog/pg_inherits.h"
#include "catalog/pg_type.h"
#include "commands/tablecmds.h"
+#include "common/hashfn.h"
#include "executor/executor.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
@@ -32,7 +33,6 @@
#include "utils/builtins.h"
#include "utils/datum.h"
#include "utils/fmgroids.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/partcache.h"
#include "utils/ruleutils.h"
diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c
index 6666a25521..f7206c9175 100644
--- a/src/backend/storage/file/sharedfileset.c
+++ b/src/backend/storage/file/sharedfileset.c
@@ -22,11 +22,11 @@
#include "catalog/pg_tablespace.h"
#include "commands/tablespace.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#include "storage/dsm.h"
#include "storage/sharedfileset.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
static void SharedFileSetOnDetach(dsm_segment *segment, Datum datum);
static void SharedFileSetPath(char *path, SharedFileSet *fileset, Oid tablespace);
diff --git a/src/backend/tsearch/ts_typanalyze.c b/src/backend/tsearch/ts_typanalyze.c
index 24c6479f61..2eed0cd137 100644
--- a/src/backend/tsearch/ts_typanalyze.c
+++ b/src/backend/tsearch/ts_typanalyze.c
@@ -16,9 +16,9 @@
#include "catalog/pg_collation.h"
#include "catalog/pg_operator.h"
#include "commands/vacuum.h"
+#include "common/hashfn.h"
#include "tsearch/ts_type.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
/* A hash key for lexemes */
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index cc4170efbf..bce1f1e0b1 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -26,6 +26,7 @@
#include "commands/dbcommands.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
+#include "common/hashfn.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "lib/qunique.h"
@@ -34,7 +35,6 @@
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/catcache.h"
-#include "utils/hashutils.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 393ee991b0..0c55b68fbf 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -21,6 +21,7 @@
#include <time.h>
#include "access/xact.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "nodes/supportnodes.h"
@@ -29,7 +30,6 @@
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/datetime.h"
-#include "utils/hashutils.h"
#include "utils/sortsupport.h"
/*
diff --git a/src/backend/utils/adt/jsonb_gin.c b/src/backend/utils/adt/jsonb_gin.c
index 72a88121d5..63122edf2e 100644
--- a/src/backend/utils/adt/jsonb_gin.c
+++ b/src/backend/utils/adt/jsonb_gin.c
@@ -63,9 +63,9 @@
#include "access/stratnum.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/jsonb.h"
#include "utils/jsonpath.h"
#include "utils/varlena.h"
diff --git a/src/backend/utils/adt/jsonb_util.c b/src/backend/utils/adt/jsonb_util.c
index edec657cd3..04b70c805b 100644
--- a/src/backend/utils/adt/jsonb_util.c
+++ b/src/backend/utils/adt/jsonb_util.c
@@ -15,11 +15,11 @@
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/jsonapi.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/datetime.h"
-#include "utils/hashutils.h"
#include "utils/json.h"
#include "utils/jsonb.h"
#include "utils/memutils.h"
diff --git a/src/backend/utils/adt/mac.c b/src/backend/utils/adt/mac.c
index f9eb0b57d8..8aeddc6863 100644
--- a/src/backend/utils/adt/mac.c
+++ b/src/backend/utils/adt/mac.c
@@ -13,12 +13,12 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "lib/hyperloglog.h"
#include "libpq/pqformat.h"
#include "port/pg_bswap.h"
#include "utils/builtins.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/inet.h"
#include "utils/sortsupport.h"
diff --git a/src/backend/utils/adt/mac8.c b/src/backend/utils/adt/mac8.c
index 571eee920f..b7b2968b92 100644
--- a/src/backend/utils/adt/mac8.c
+++ b/src/backend/utils/adt/mac8.c
@@ -21,9 +21,9 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/inet.h"
/*
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index a6dd8b75aa..0ab54316f8 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -15,6 +15,7 @@
#include "access/stratnum.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/ip.h"
#include "lib/hyperloglog.h"
#include "libpq/libpq-be.h"
@@ -26,7 +27,6 @@
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/inet.h"
#include "utils/lsyscache.h"
#include "utils/sortsupport.h"
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index c92ad5a4fe..bd00f23b94 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -27,6 +27,7 @@
#include <math.h>
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/int.h"
#include "funcapi.h"
#include "lib/hyperloglog.h"
@@ -38,7 +39,6 @@
#include "utils/builtins.h"
#include "utils/float.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/int8.h"
#include "utils/numeric.h"
#include "utils/sortsupport.h"
diff --git a/src/backend/utils/adt/rangetypes.c b/src/backend/utils/adt/rangetypes.c
index 639e1dad6c..b95132b714 100644
--- a/src/backend/utils/adt/rangetypes.c
+++ b/src/backend/utils/adt/rangetypes.c
@@ -31,12 +31,12 @@
#include "postgres.h"
#include "access/tupmacs.h"
+#include "common/hashfn.h"
#include "lib/stringinfo.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/date.h"
-#include "utils/hashutils.h"
#include "utils/int8.h"
#include "utils/lsyscache.h"
#include "utils/rangetypes.h"
diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c
index fad2057754..4ce8375eab 100644
--- a/src/backend/utils/adt/tid.c
+++ b/src/backend/utils/adt/tid.c
@@ -25,12 +25,12 @@
#include "access/tableam.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "parser/parsetree.h"
#include "utils/acl.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/varlena.h"
diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c
index 4abd861dd7..c906ee789d 100644
--- a/src/backend/utils/adt/uuid.c
+++ b/src/backend/utils/adt/uuid.c
@@ -13,12 +13,12 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "lib/hyperloglog.h"
#include "libpq/pqformat.h"
#include "port/pg_bswap.h"
#include "utils/builtins.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/sortsupport.h"
#include "utils/uuid.h"
diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c
index 1e1239a1ba..39acfdff6c 100644
--- a/src/backend/utils/adt/varchar.c
+++ b/src/backend/utils/adt/varchar.c
@@ -17,13 +17,13 @@
#include "access/detoast.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "nodes/nodeFuncs.h"
#include "nodes/supportnodes.h"
#include "utils/array.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/pg_locale.h"
#include "utils/varlena.h"
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 1b351cbc68..0d7baacca1 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -20,6 +20,7 @@
#include "access/detoast.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/int.h"
#include "lib/hyperloglog.h"
#include "libpq/pqformat.h"
@@ -29,7 +30,6 @@
#include "regex/regex.h"
#include "utils/builtins.h"
#include "utils/bytea.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/pg_locale.h"
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 64776e3209..3613ae5f44 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -24,6 +24,7 @@
#include "catalog/pg_collation.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#ifdef CATCACHE_STATS
#include "storage/ipc.h" /* for on_proc_exit */
@@ -32,7 +33,6 @@
#include "utils/builtins.h"
#include "utils/datum.h"
#include "utils/fmgroids.h"
-#include "utils/hashutils.h"
#include "utils/inval.h"
#include "utils/memutils.h"
#include "utils/rel.h"
diff --git a/src/backend/utils/hash/Makefile b/src/backend/utils/hash/Makefile
index fc7b165f7f..d4c1210e36 100644
--- a/src/backend/utils/hash/Makefile
+++ b/src/backend/utils/hash/Makefile
@@ -14,7 +14,6 @@ include $(top_builddir)/src/Makefile.global
OBJS = \
dynahash.o \
- hashfn.o \
pg_crc.o
include $(top_srcdir)/src/backend/common.mk
diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index d245e1aa12..b5381958e7 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -86,10 +86,10 @@
#include <limits.h>
#include "access/xact.h"
+#include "common/hashfn.h"
#include "storage/shmem.h"
#include "storage/spin.h"
#include "utils/dynahash.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
diff --git a/src/backend/utils/resowner/resowner.c b/src/backend/utils/resowner/resowner.c
index ac6f226f59..3c39e48825 100644
--- a/src/backend/utils/resowner/resowner.c
+++ b/src/backend/utils/resowner/resowner.c
@@ -20,12 +20,12 @@
*/
#include "postgres.h"
+#include "common/hashfn.h"
#include "jit/jit.h"
#include "storage/bufmgr.h"
#include "storage/ipc.h"
#include "storage/predicate.h"
#include "storage/proc.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/resowner_private.h"
diff --git a/src/common/Makefile b/src/common/Makefile
index ab98f4faaf..ce01df68b9 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -54,6 +54,7 @@ OBJS_COMMON = \
exec.o \
f2s.o \
file_perm.o \
+ hashfn.o \
ip.o \
jsonapi.o \
keywords.o \
diff --git a/src/backend/utils/hash/hashfn.c b/src/common/hashfn.c
similarity index 99%
rename from src/backend/utils/hash/hashfn.c
rename to src/common/hashfn.c
index ecc52014af..990f18e610 100644
--- a/src/backend/utils/hash/hashfn.c
+++ b/src/common/hashfn.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * src/backend/utils/hash/hashfn.c
+ * src/common/hashfn.c
*
* NOTES
* It is expected that every bit of a hash function's 32-bit result is
@@ -23,7 +23,7 @@
*/
#include "postgres.h"
-#include "utils/hashutils.h"
+#include "common/hashfn.h"
/*
diff --git a/src/include/access/hash.h b/src/include/access/hash.h
index 9fc0696096..2707e1924b 100644
--- a/src/include/access/hash.h
+++ b/src/include/access/hash.h
@@ -21,10 +21,10 @@
#include "access/itup.h"
#include "access/sdir.h"
#include "catalog/pg_am_d.h"
+#include "common/hashfn.h"
#include "lib/stringinfo.h"
#include "storage/bufmgr.h"
#include "storage/lockdefs.h"
-#include "utils/hashutils.h"
#include "utils/hsearch.h"
#include "utils/relcache.h"
diff --git a/src/include/utils/hashutils.h b/src/include/common/hashfn.h
similarity index 97%
rename from src/include/utils/hashutils.h
rename to src/include/common/hashfn.h
index ba3ecb7592..6ecc864f84 100644
--- a/src/include/utils/hashutils.h
+++ b/src/include/common/hashfn.h
@@ -4,8 +4,8 @@
* Portions Copyright (c) 2017-2020, PostgreSQL Global Development Group
*/
-#ifndef HASHUTILS_H
-#define HASHUTILS_H
+#ifndef HASHFN_H
+#define HASHFN_H
/*
@@ -101,4 +101,4 @@ murmurhash32(uint32 data)
return h;
}
-#endif /* HASHUTILS_H */
+#endif /* HASHFN_H */
--
2.21.1 (Apple Git-122.3)
On Thu, Feb 13, 2020 at 11:26 AM Mark Dilger
<mark.dilger@enterprisedb.com> wrote:
I have made these changes and rebased Robert’s patches but otherwise changed nothing. Here they are:
Thanks. Anyone else have comments? I think this is pretty
straightforward and unobjectionable work so I'm inclined to press
forward with committing it fairly soon, but if someone feels
otherwise, please speak up.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Fri, Feb 14, 2020 at 10:33:04AM -0500, Robert Haas wrote:
On Thu, Feb 13, 2020 at 11:26 AM Mark Dilger
<mark.dilger@enterprisedb.com> wrote:I have made these changes and rebased Robert’s patches but
otherwise changed nothing. Here they are:Thanks. Anyone else have comments? I think this is pretty
straightforward and unobjectionable work so I'm inclined to press
forward with committing it fairly soon, but if someone feels
otherwise, please speak up.
One question. It might be possible to make these functions faster
using compiler intrinsics. Would those still be available to front-end
code?
Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
On Feb 14, 2020, at 8:15 AM, David Fetter <david@fetter.org> wrote:
On Fri, Feb 14, 2020 at 10:33:04AM -0500, Robert Haas wrote:
On Thu, Feb 13, 2020 at 11:26 AM Mark Dilger
<mark.dilger@enterprisedb.com> wrote:I have made these changes and rebased Robert’s patches but
otherwise changed nothing. Here they are:Thanks. Anyone else have comments? I think this is pretty
straightforward and unobjectionable work so I'm inclined to press
forward with committing it fairly soon, but if someone feels
otherwise, please speak up.One question. It might be possible to make these functions faster
using compiler intrinsics. Would those still be available to front-end
code?
Do you have a specific proposal that would preserve on-disk compatibility?
—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Fri, Feb 14, 2020 at 11:15 AM David Fetter <david@fetter.org> wrote:
One question. It might be possible to make these functions faster
using compiler intrinsics. Would those still be available to front-end
code?
Why not? We use the same compiler for frontend code as we do for
backend code. Possibly you might need some more header-file
rejiggering someplace, but I don't know of anything specific or see
any reason why it would be particularly painful if we had to do
something.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Fri, Feb 14, 2020 at 08:16:47AM -0800, Mark Dilger wrote:
On Feb 14, 2020, at 8:15 AM, David Fetter <david@fetter.org> wrote:
On Fri, Feb 14, 2020 at 10:33:04AM -0500, Robert Haas wrote:
On Thu, Feb 13, 2020 at 11:26 AM Mark Dilger
<mark.dilger@enterprisedb.com> wrote:I have made these changes and rebased Robert’s patches but
otherwise changed nothing. Here they are:Thanks. Anyone else have comments? I think this is pretty
straightforward and unobjectionable work so I'm inclined to press
forward with committing it fairly soon, but if someone feels
otherwise, please speak up.One question. It might be possible to make these functions faster
using compiler intrinsics. Would those still be available to front-end
code?Do you have a specific proposal that would preserve on-disk compatibility?
I hadn't planned on changing the representation, just cutting
instructions out of the calculation of same.
Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
On Feb 14, 2020, at 8:29 AM, David Fetter <david@fetter.org> wrote:
On Fri, Feb 14, 2020 at 08:16:47AM -0800, Mark Dilger wrote:
On Feb 14, 2020, at 8:15 AM, David Fetter <david@fetter.org> wrote:
On Fri, Feb 14, 2020 at 10:33:04AM -0500, Robert Haas wrote:
On Thu, Feb 13, 2020 at 11:26 AM Mark Dilger
<mark.dilger@enterprisedb.com> wrote:I have made these changes and rebased Robert’s patches but
otherwise changed nothing. Here they are:Thanks. Anyone else have comments? I think this is pretty
straightforward and unobjectionable work so I'm inclined to press
forward with committing it fairly soon, but if someone feels
otherwise, please speak up.One question. It might be possible to make these functions faster
using compiler intrinsics. Would those still be available to front-end
code?Do you have a specific proposal that would preserve on-disk compatibility?
I hadn't planned on changing the representation, just cutting
instructions out of the calculation of same.
Ok, I misunderstood.
I thought the question was about using compiler intrinsics to implement an alltogether different hashing algorithm than the one currently in use and whether exposing the hash function to frontend code would lock down the algorithm in a way that would make it harder to change in the future. That lead me to the question of whether we had sufficient flexibility to entertain changing the hashing algorithm anyway.
—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Fri, Feb 14, 2020 at 9:03 PM Robert Haas <robertmhaas@gmail.com> wrote:
On Thu, Feb 13, 2020 at 11:26 AM Mark Dilger
<mark.dilger@enterprisedb.com> wrote:I have made these changes and rebased Robert’s patches but otherwise changed nothing. Here they are:
Thanks. Anyone else have comments? I think this is pretty
straightforward and unobjectionable work so I'm inclined to press
forward with committing it fairly soon, but if someone feels
otherwise, please speak up.
I've committed 0001 through 0003 as revised by Mark in accordance with
the comments from Suraj. Here's the last patch again with a tweak to
try not to break the Windows build, per some off-list advice I
received on how not to break the Windows build. Barring complaints
from the buildfarm or otherwise, I'll commit this one too.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachments:
v3-0001-Move-src-backend-utils-hash-hashfn.c-to-src-commo.patchapplication/octet-stream; name=v3-0001-Move-src-backend-utils-hash-hashfn.c-to-src-commo.patchDownload
From d50392c6a6c424e2e20fcf679df297b1330a6b24 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Mon, 24 Feb 2020 17:30:49 +0530
Subject: [PATCH v3] Move src/backend/utils/hash/hashfn.c to src/common
This also involves renaming src/include/utils/hashutils.h, which
becomes src/include/common/hashfn.h. Perhaps an argument can be
made for keeping the hashutils.h name, but it seemed more
consistent to make it match the name of the file, and also more
descriptive of what is actually going on here.
Patch by me, reviewed by Suraj Kharage and Mark Dilger. Off-list
advice on how not to break the Windows build from Davinder Singh
and Amit Kapila.
Discussion: http://postgr.es/m/CA+TgmoaRiG4TXND8QuM6JXFRkM_1wL2ZNhzaUKsuec9-4yrkgw@mail.gmail.com
---
contrib/citext/citext.c | 2 +-
contrib/hstore/hstore_op.c | 2 +-
contrib/pg_stat_statements/pg_stat_statements.c | 2 +-
contrib/sepgsql/uavc.c | 2 +-
src/backend/access/common/tupdesc.c | 2 +-
src/backend/access/hash/hashfunc.c | 2 +-
src/backend/access/tablesample/bernoulli.c | 2 +-
src/backend/access/tablesample/system.c | 2 +-
src/backend/commands/async.c | 2 +-
src/backend/executor/execGrouping.c | 2 +-
src/backend/lib/bloomfilter.c | 2 +-
src/backend/lib/dshash.c | 2 +-
src/backend/nodes/bitmapset.c | 2 +-
src/backend/nodes/tidbitmap.c | 2 +-
src/backend/partitioning/partbounds.c | 2 +-
src/backend/storage/file/sharedfileset.c | 2 +-
src/backend/tsearch/ts_typanalyze.c | 2 +-
src/backend/utils/adt/acl.c | 2 +-
src/backend/utils/adt/date.c | 2 +-
src/backend/utils/adt/jsonb_gin.c | 2 +-
src/backend/utils/adt/jsonb_util.c | 2 +-
src/backend/utils/adt/mac.c | 2 +-
src/backend/utils/adt/mac8.c | 2 +-
src/backend/utils/adt/network.c | 2 +-
src/backend/utils/adt/numeric.c | 2 +-
src/backend/utils/adt/rangetypes.c | 2 +-
src/backend/utils/adt/tid.c | 2 +-
src/backend/utils/adt/uuid.c | 2 +-
src/backend/utils/adt/varchar.c | 2 +-
src/backend/utils/adt/varlena.c | 2 +-
src/backend/utils/cache/catcache.c | 2 +-
src/backend/utils/hash/Makefile | 1 -
src/backend/utils/hash/dynahash.c | 2 +-
src/backend/utils/resowner/resowner.c | 2 +-
src/common/Makefile | 1 +
src/{backend/utils/hash => common}/hashfn.c | 4 ++--
src/include/access/hash.h | 2 +-
src/include/{utils/hashutils.h => common/hashfn.h} | 6 +++---
src/tools/msvc/Mkvcbuild.pm | 2 +-
39 files changed, 41 insertions(+), 41 deletions(-)
rename src/{backend/utils/hash => common}/hashfn.c (99%)
rename src/include/{utils/hashutils.h => common/hashfn.h} (97%)
diff --git a/contrib/citext/citext.c b/contrib/citext/citext.c
index a4adafe895..df139462a6 100644
--- a/contrib/citext/citext.c
+++ b/contrib/citext/citext.c
@@ -4,9 +4,9 @@
#include "postgres.h"
#include "catalog/pg_collation.h"
+#include "common/hashfn.h"
#include "utils/builtins.h"
#include "utils/formatting.h"
-#include "utils/hashutils.h"
#include "utils/varlena.h"
PG_MODULE_MAGIC;
diff --git a/contrib/hstore/hstore_op.c b/contrib/hstore/hstore_op.c
index 01e59beaa3..fb1bb0681c 100644
--- a/contrib/hstore/hstore_op.c
+++ b/contrib/hstore/hstore_op.c
@@ -5,10 +5,10 @@
#include "access/htup_details.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "funcapi.h"
#include "hstore.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
/* old names for C functions */
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index e0dbeebde3..e4fda4b404 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -62,6 +62,7 @@
#include <unistd.h>
#include "catalog/pg_authid.h"
+#include "common/hashfn.h"
#include "executor/instrument.h"
#include "funcapi.h"
#include "mb/pg_wchar.h"
@@ -77,7 +78,6 @@
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
PG_MODULE_MAGIC;
diff --git a/contrib/sepgsql/uavc.c b/contrib/sepgsql/uavc.c
index d3723768a6..639a52c556 100644
--- a/contrib/sepgsql/uavc.c
+++ b/contrib/sepgsql/uavc.c
@@ -14,10 +14,10 @@
#include "catalog/pg_proc.h"
#include "commands/seclabel.h"
+#include "common/hashfn.h"
#include "sepgsql.h"
#include "storage/ipc.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
/*
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 00bb4cb53d..28835512f0 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -23,12 +23,12 @@
#include "access/tupdesc_details.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#include "parser/parse_type.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/datum.h"
-#include "utils/hashutils.h"
#include "utils/resowner_private.h"
#include "utils/syscache.h"
diff --git a/src/backend/access/hash/hashfunc.c b/src/backend/access/hash/hashfunc.c
index 5b517106ff..a8498226e3 100644
--- a/src/backend/access/hash/hashfunc.c
+++ b/src/backend/access/hash/hashfunc.c
@@ -28,8 +28,8 @@
#include "access/hash.h"
#include "catalog/pg_collation.h"
+#include "common/hashfn.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/pg_locale.h"
/*
diff --git a/src/backend/access/tablesample/bernoulli.c b/src/backend/access/tablesample/bernoulli.c
index 46016fb5de..606730d6cb 100644
--- a/src/backend/access/tablesample/bernoulli.c
+++ b/src/backend/access/tablesample/bernoulli.c
@@ -28,9 +28,9 @@
#include "access/tsmapi.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "optimizer/optimizer.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
/* Private state */
diff --git a/src/backend/access/tablesample/system.c b/src/backend/access/tablesample/system.c
index 8a5f03bfd3..29b7c0d3c2 100644
--- a/src/backend/access/tablesample/system.c
+++ b/src/backend/access/tablesample/system.c
@@ -29,9 +29,9 @@
#include "access/relscan.h"
#include "access/tsmapi.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "optimizer/optimizer.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
/* Private state */
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c
index 9aa2b61600..dae939a4ab 100644
--- a/src/backend/commands/async.c
+++ b/src/backend/commands/async.c
@@ -126,6 +126,7 @@
#include "access/xact.h"
#include "catalog/pg_database.h"
#include "commands/async.h"
+#include "common/hashfn.h"
#include "funcapi.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
@@ -138,7 +139,6 @@
#include "storage/sinval.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "utils/snapmgr.h"
diff --git a/src/backend/executor/execGrouping.c b/src/backend/executor/execGrouping.c
index de0205f4fc..f6c3e4cbde 100644
--- a/src/backend/executor/execGrouping.c
+++ b/src/backend/executor/execGrouping.c
@@ -19,9 +19,9 @@
#include "postgres.h"
#include "access/parallel.h"
+#include "common/hashfn.h"
#include "executor/executor.h"
#include "miscadmin.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
diff --git a/src/backend/lib/bloomfilter.c b/src/backend/lib/bloomfilter.c
index 29b62e70e4..f040e83c01 100644
--- a/src/backend/lib/bloomfilter.c
+++ b/src/backend/lib/bloomfilter.c
@@ -35,9 +35,9 @@
#include <math.h>
+#include "common/hashfn.h"
#include "lib/bloomfilter.h"
#include "port/pg_bitutils.h"
-#include "utils/hashutils.h"
#define MAX_HASH_FUNCS 10
diff --git a/src/backend/lib/dshash.c b/src/backend/lib/dshash.c
index 5e0167d9b0..78ccf03217 100644
--- a/src/backend/lib/dshash.c
+++ b/src/backend/lib/dshash.c
@@ -31,11 +31,11 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "lib/dshash.h"
#include "storage/ipc.h"
#include "storage/lwlock.h"
#include "utils/dsa.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
/*
diff --git a/src/backend/nodes/bitmapset.c b/src/backend/nodes/bitmapset.c
index f711e6c699..2719ea45a3 100644
--- a/src/backend/nodes/bitmapset.c
+++ b/src/backend/nodes/bitmapset.c
@@ -20,10 +20,10 @@
*/
#include "postgres.h"
+#include "common/hashfn.h"
#include "nodes/bitmapset.h"
#include "nodes/pg_list.h"
#include "port/pg_bitutils.h"
-#include "utils/hashutils.h"
#define WORDNUM(x) ((x) / BITS_PER_BITMAPWORD)
diff --git a/src/backend/nodes/tidbitmap.c b/src/backend/nodes/tidbitmap.c
index e102589e74..ad4e071ca3 100644
--- a/src/backend/nodes/tidbitmap.c
+++ b/src/backend/nodes/tidbitmap.c
@@ -41,11 +41,11 @@
#include <limits.h>
#include "access/htup_details.h"
+#include "common/hashfn.h"
#include "nodes/bitmapset.h"
#include "nodes/tidbitmap.h"
#include "storage/lwlock.h"
#include "utils/dsa.h"
-#include "utils/hashutils.h"
/*
* The maximum number of tuples per page is not large (typically 256 with
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 54eb83a0d1..35953f23fa 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -21,6 +21,7 @@
#include "catalog/pg_inherits.h"
#include "catalog/pg_type.h"
#include "commands/tablecmds.h"
+#include "common/hashfn.h"
#include "executor/executor.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
@@ -32,7 +33,6 @@
#include "utils/builtins.h"
#include "utils/datum.h"
#include "utils/fmgroids.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/partcache.h"
#include "utils/ruleutils.h"
diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c
index 6666a25521..f7206c9175 100644
--- a/src/backend/storage/file/sharedfileset.c
+++ b/src/backend/storage/file/sharedfileset.c
@@ -22,11 +22,11 @@
#include "catalog/pg_tablespace.h"
#include "commands/tablespace.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#include "storage/dsm.h"
#include "storage/sharedfileset.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
static void SharedFileSetOnDetach(dsm_segment *segment, Datum datum);
static void SharedFileSetPath(char *path, SharedFileSet *fileset, Oid tablespace);
diff --git a/src/backend/tsearch/ts_typanalyze.c b/src/backend/tsearch/ts_typanalyze.c
index 24c6479f61..2eed0cd137 100644
--- a/src/backend/tsearch/ts_typanalyze.c
+++ b/src/backend/tsearch/ts_typanalyze.c
@@ -16,9 +16,9 @@
#include "catalog/pg_collation.h"
#include "catalog/pg_operator.h"
#include "commands/vacuum.h"
+#include "common/hashfn.h"
#include "tsearch/ts_type.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
/* A hash key for lexemes */
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index cc4170efbf..bce1f1e0b1 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -26,6 +26,7 @@
#include "commands/dbcommands.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
+#include "common/hashfn.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "lib/qunique.h"
@@ -34,7 +35,6 @@
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/catcache.h"
-#include "utils/hashutils.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 393ee991b0..0c55b68fbf 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -21,6 +21,7 @@
#include <time.h>
#include "access/xact.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "nodes/supportnodes.h"
@@ -29,7 +30,6 @@
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/datetime.h"
-#include "utils/hashutils.h"
#include "utils/sortsupport.h"
/*
diff --git a/src/backend/utils/adt/jsonb_gin.c b/src/backend/utils/adt/jsonb_gin.c
index 72a88121d5..63122edf2e 100644
--- a/src/backend/utils/adt/jsonb_gin.c
+++ b/src/backend/utils/adt/jsonb_gin.c
@@ -63,9 +63,9 @@
#include "access/stratnum.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/jsonb.h"
#include "utils/jsonpath.h"
#include "utils/varlena.h"
diff --git a/src/backend/utils/adt/jsonb_util.c b/src/backend/utils/adt/jsonb_util.c
index edec657cd3..04b70c805b 100644
--- a/src/backend/utils/adt/jsonb_util.c
+++ b/src/backend/utils/adt/jsonb_util.c
@@ -15,11 +15,11 @@
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/jsonapi.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/datetime.h"
-#include "utils/hashutils.h"
#include "utils/json.h"
#include "utils/jsonb.h"
#include "utils/memutils.h"
diff --git a/src/backend/utils/adt/mac.c b/src/backend/utils/adt/mac.c
index f9eb0b57d8..8aeddc6863 100644
--- a/src/backend/utils/adt/mac.c
+++ b/src/backend/utils/adt/mac.c
@@ -13,12 +13,12 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "lib/hyperloglog.h"
#include "libpq/pqformat.h"
#include "port/pg_bswap.h"
#include "utils/builtins.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/inet.h"
#include "utils/sortsupport.h"
diff --git a/src/backend/utils/adt/mac8.c b/src/backend/utils/adt/mac8.c
index 571eee920f..b7b2968b92 100644
--- a/src/backend/utils/adt/mac8.c
+++ b/src/backend/utils/adt/mac8.c
@@ -21,9 +21,9 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/inet.h"
/*
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index a6dd8b75aa..0ab54316f8 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -15,6 +15,7 @@
#include "access/stratnum.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/ip.h"
#include "lib/hyperloglog.h"
#include "libpq/libpq-be.h"
@@ -26,7 +27,6 @@
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/inet.h"
#include "utils/lsyscache.h"
#include "utils/sortsupport.h"
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index c92ad5a4fe..bd00f23b94 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -27,6 +27,7 @@
#include <math.h>
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/int.h"
#include "funcapi.h"
#include "lib/hyperloglog.h"
@@ -38,7 +39,6 @@
#include "utils/builtins.h"
#include "utils/float.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/int8.h"
#include "utils/numeric.h"
#include "utils/sortsupport.h"
diff --git a/src/backend/utils/adt/rangetypes.c b/src/backend/utils/adt/rangetypes.c
index 639e1dad6c..b95132b714 100644
--- a/src/backend/utils/adt/rangetypes.c
+++ b/src/backend/utils/adt/rangetypes.c
@@ -31,12 +31,12 @@
#include "postgres.h"
#include "access/tupmacs.h"
+#include "common/hashfn.h"
#include "lib/stringinfo.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/date.h"
-#include "utils/hashutils.h"
#include "utils/int8.h"
#include "utils/lsyscache.h"
#include "utils/rangetypes.h"
diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c
index fad2057754..4ce8375eab 100644
--- a/src/backend/utils/adt/tid.c
+++ b/src/backend/utils/adt/tid.c
@@ -25,12 +25,12 @@
#include "access/tableam.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "parser/parsetree.h"
#include "utils/acl.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/varlena.h"
diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c
index 4abd861dd7..c906ee789d 100644
--- a/src/backend/utils/adt/uuid.c
+++ b/src/backend/utils/adt/uuid.c
@@ -13,12 +13,12 @@
#include "postgres.h"
+#include "common/hashfn.h"
#include "lib/hyperloglog.h"
#include "libpq/pqformat.h"
#include "port/pg_bswap.h"
#include "utils/builtins.h"
#include "utils/guc.h"
-#include "utils/hashutils.h"
#include "utils/sortsupport.h"
#include "utils/uuid.h"
diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c
index 1e1239a1ba..39acfdff6c 100644
--- a/src/backend/utils/adt/varchar.c
+++ b/src/backend/utils/adt/varchar.c
@@ -17,13 +17,13 @@
#include "access/detoast.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "nodes/nodeFuncs.h"
#include "nodes/supportnodes.h"
#include "utils/array.h"
#include "utils/builtins.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/pg_locale.h"
#include "utils/varlena.h"
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 1b351cbc68..0d7baacca1 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -20,6 +20,7 @@
#include "access/detoast.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "common/int.h"
#include "lib/hyperloglog.h"
#include "libpq/pqformat.h"
@@ -29,7 +30,6 @@
#include "regex/regex.h"
#include "utils/builtins.h"
#include "utils/bytea.h"
-#include "utils/hashutils.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/pg_locale.h"
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 64776e3209..3613ae5f44 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -24,6 +24,7 @@
#include "catalog/pg_collation.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "miscadmin.h"
#ifdef CATCACHE_STATS
#include "storage/ipc.h" /* for on_proc_exit */
@@ -32,7 +33,6 @@
#include "utils/builtins.h"
#include "utils/datum.h"
#include "utils/fmgroids.h"
-#include "utils/hashutils.h"
#include "utils/inval.h"
#include "utils/memutils.h"
#include "utils/rel.h"
diff --git a/src/backend/utils/hash/Makefile b/src/backend/utils/hash/Makefile
index fc7b165f7f..d4c1210e36 100644
--- a/src/backend/utils/hash/Makefile
+++ b/src/backend/utils/hash/Makefile
@@ -14,7 +14,6 @@ include $(top_builddir)/src/Makefile.global
OBJS = \
dynahash.o \
- hashfn.o \
pg_crc.o
include $(top_srcdir)/src/backend/common.mk
diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index d245e1aa12..b5381958e7 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -86,10 +86,10 @@
#include <limits.h>
#include "access/xact.h"
+#include "common/hashfn.h"
#include "storage/shmem.h"
#include "storage/spin.h"
#include "utils/dynahash.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
diff --git a/src/backend/utils/resowner/resowner.c b/src/backend/utils/resowner/resowner.c
index ac6f226f59..3c39e48825 100644
--- a/src/backend/utils/resowner/resowner.c
+++ b/src/backend/utils/resowner/resowner.c
@@ -20,12 +20,12 @@
*/
#include "postgres.h"
+#include "common/hashfn.h"
#include "jit/jit.h"
#include "storage/bufmgr.h"
#include "storage/ipc.h"
#include "storage/predicate.h"
#include "storage/proc.h"
-#include "utils/hashutils.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/resowner_private.h"
diff --git a/src/common/Makefile b/src/common/Makefile
index ab98f4faaf..ce01df68b9 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -54,6 +54,7 @@ OBJS_COMMON = \
exec.o \
f2s.o \
file_perm.o \
+ hashfn.o \
ip.o \
jsonapi.o \
keywords.o \
diff --git a/src/backend/utils/hash/hashfn.c b/src/common/hashfn.c
similarity index 99%
rename from src/backend/utils/hash/hashfn.c
rename to src/common/hashfn.c
index ecc52014af..990f18e610 100644
--- a/src/backend/utils/hash/hashfn.c
+++ b/src/common/hashfn.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * src/backend/utils/hash/hashfn.c
+ * src/common/hashfn.c
*
* NOTES
* It is expected that every bit of a hash function's 32-bit result is
@@ -23,7 +23,7 @@
*/
#include "postgres.h"
-#include "utils/hashutils.h"
+#include "common/hashfn.h"
/*
diff --git a/src/include/access/hash.h b/src/include/access/hash.h
index 9fc0696096..2707e1924b 100644
--- a/src/include/access/hash.h
+++ b/src/include/access/hash.h
@@ -21,10 +21,10 @@
#include "access/itup.h"
#include "access/sdir.h"
#include "catalog/pg_am_d.h"
+#include "common/hashfn.h"
#include "lib/stringinfo.h"
#include "storage/bufmgr.h"
#include "storage/lockdefs.h"
-#include "utils/hashutils.h"
#include "utils/hsearch.h"
#include "utils/relcache.h"
diff --git a/src/include/utils/hashutils.h b/src/include/common/hashfn.h
similarity index 97%
rename from src/include/utils/hashutils.h
rename to src/include/common/hashfn.h
index ba3ecb7592..6ecc864f84 100644
--- a/src/include/utils/hashutils.h
+++ b/src/include/common/hashfn.h
@@ -4,8 +4,8 @@
* Portions Copyright (c) 2017-2020, PostgreSQL Global Development Group
*/
-#ifndef HASHUTILS_H
-#define HASHUTILS_H
+#ifndef HASHFN_H
+#define HASHFN_H
/*
@@ -101,4 +101,4 @@ murmurhash32(uint32 data)
return h;
}
-#endif /* HASHUTILS_H */
+#endif /* HASHFN_H */
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index 727a8fdec9..834c2c39d1 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -120,7 +120,7 @@ sub mkvcbuild
our @pgcommonallfiles = qw(
base64.c config_info.c controldata_utils.c d2s.c encnames.c exec.c
- f2s.c file_perm.c ip.c jsonapi.c
+ f2s.c file_perm.c hashfn.c ip.c jsonapi.c
keywords.c kwlookup.c link-canary.c md5.c
pg_lzcompress.c pgfnames.c psprintf.c relpath.c rmtree.c
saslprep.c scram-common.c string.c stringinfo.c unicode_norm.c username.c
--
2.17.2 (Apple Git-113)
On Mon, Feb 24, 2020 at 5:32 PM Robert Haas <robertmhaas@gmail.com> wrote:
I've committed 0001 through 0003 as revised by Mark in accordance with
the comments from Suraj. Here's the last patch again with a tweak to
try not to break the Windows build, per some off-list advice I
received on how not to break the Windows build. Barring complaints
from the buildfarm or otherwise, I'll commit this one too.
Done.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company