summaryrefslogtreecommitdiff
path: root/src/backend/access/common
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2017-08-22 16:05:48 -0700
committerAndres Freund <andres@anarazel.de>2017-08-22 16:11:54 -0700
commit35ea75632a56ca8ef22aa8fed03b9dabb9c8c575 (patch)
tree630833921351b6f89f7be11372a2ac8bcba332a8 /src/backend/access/common
parent0052a0243d9c979a06ef273af965508103c456e0 (diff)
Refactor typcache.c's record typmod hash table.
Previously, tuple descriptors were stored in chains keyed by a fixed size array of OIDs. That meant there were effectively two levels of collision chain -- one inside and one outside the hash table. Instead, let dynahash.c look after conflicts for us by supplying a proper hash and equal function pair. This is a nice cleanup on its own, but also simplifies followup changes allowing blessed TupleDescs to be shared between backends participating in parallel query. Author: Thomas Munro Reviewed-By: Andres Freund Discussion: https://postgr.es/m/CAEepm%3D34GVhOL%2BarUx56yx7OPk7%3DqpGsv3CpO54feqjAwQKm5g%40mail.gmail.com
Diffstat (limited to 'src/backend/access/common')
-rw-r--r--src/backend/access/common/tupdesc.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 75b191ba2aa..4436c863617 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -19,6 +19,7 @@
#include "postgres.h"
+#include "access/hash.h"
#include "access/htup_details.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
@@ -26,6 +27,7 @@
#include "parser/parse_type.h"
#include "utils/acl.h"
#include "utils/builtins.h"
+#include "utils/hashutils.h"
#include "utils/resowner_private.h"
#include "utils/syscache.h"
@@ -444,6 +446,31 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
}
/*
+ * hashTupleDesc
+ * Compute a hash value for a tuple descriptor.
+ *
+ * If two tuple descriptors would be considered equal by equalTupleDescs()
+ * then their hash value will be equal according to this function.
+ *
+ * Note that currently contents of constraint are not hashed - it'd be a bit
+ * painful to do so, and conflicts just due to constraints are unlikely.
+ */
+uint32
+hashTupleDesc(TupleDesc desc)
+{
+ uint32 s;
+ int i;
+
+ s = hash_combine(0, hash_uint32(desc->natts));
+ s = hash_combine(s, hash_uint32(desc->tdtypeid));
+ s = hash_combine(s, hash_uint32(desc->tdhasoid));
+ for (i = 0; i < desc->natts; ++i)
+ s = hash_combine(s, hash_uint32(TupleDescAttr(desc, i)->atttypid));
+
+ return s;
+}
+
+/*
* TupleDescInitEntry
* This function initializes a single attribute structure in
* a previously allocated tuple descriptor.