summaryrefslogtreecommitdiff
path: root/src/include/utils
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-10-30 21:55:20 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2010-10-30 21:56:11 -0400
commit186cbbda8f8dc5e42f68fc7892f206a76d56a20f (patch)
tree2c909d8365726683a61515b639c02a9ac00682f4 /src/include/utils
parentbd1ff9713369c2f54391112b92e0c22ab5c99180 (diff)
downloadpostgresql-186cbbda8f8dc5e42f68fc7892f206a76d56a20f.tar.gz
Provide hashing support for arrays.
The core of this patch is hash_array() and associated typcache infrastructure, which works just about exactly like the existing support for array comparison. In addition I did some work to ensure that the planner won't think that an array type is hashable unless its element type is hashable, and similarly for sorting. This includes adding a datatype parameter to op_hashjoinable and op_mergejoinable, and adding an explicit "hashable" flag to SortGroupClause. The lack of a cross-check on the element type was a pre-existing bug in mergejoin support --- but it didn't matter so much before, because if you couldn't sort the element type there wasn't any good alternative to failing anyhow. Now that we have the alternative of hashing the array type, there are cases where we can avoid a failure by being picky at the planner stage, so it's time to be picky. The issue of exactly how to combine the per-element hash values to produce an array hash is still open for discussion, but the rest of this is pretty solid, so I'll commit it as-is.
Diffstat (limited to 'src/include/utils')
-rw-r--r--src/include/utils/array.h1
-rw-r--r--src/include/utils/lsyscache.h4
-rw-r--r--src/include/utils/typcache.h23
3 files changed, 17 insertions, 11 deletions
diff --git a/src/include/utils/array.h b/src/include/utils/array.h
index bce28bb26d..dba9c3d741 100644
--- a/src/include/utils/array.h
+++ b/src/include/utils/array.h
@@ -192,6 +192,7 @@ extern Datum array_gt(PG_FUNCTION_ARGS);
extern Datum array_le(PG_FUNCTION_ARGS);
extern Datum array_ge(PG_FUNCTION_ARGS);
extern Datum btarraycmp(PG_FUNCTION_ARGS);
+extern Datum hash_array(PG_FUNCTION_ARGS);
extern Datum arrayoverlap(PG_FUNCTION_ARGS);
extern Datum arraycontains(PG_FUNCTION_ARGS);
extern Datum arraycontained(PG_FUNCTION_ARGS);
diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h
index 02c0219fa0..b6104d7dec 100644
--- a/src/include/utils/lsyscache.h
+++ b/src/include/utils/lsyscache.h
@@ -67,8 +67,8 @@ extern Oid get_opclass_input_type(Oid opclass);
extern RegProcedure get_opcode(Oid opno);
extern char *get_opname(Oid opno);
extern void op_input_types(Oid opno, Oid *lefttype, Oid *righttype);
-extern bool op_mergejoinable(Oid opno);
-extern bool op_hashjoinable(Oid opno);
+extern bool op_mergejoinable(Oid opno, Oid inputtype);
+extern bool op_hashjoinable(Oid opno, Oid inputtype);
extern bool op_strict(Oid opno);
extern char op_volatile(Oid opno);
extern Oid get_commutator(Oid opno);
diff --git a/src/include/utils/typcache.h b/src/include/utils/typcache.h
index 28b66718b3..313f781591 100644
--- a/src/include/utils/typcache.h
+++ b/src/include/utils/typcache.h
@@ -49,16 +49,18 @@ typedef struct TypeCacheEntry
Oid lt_opr; /* the less-than operator */
Oid gt_opr; /* the greater-than operator */
Oid cmp_proc; /* the btree comparison function */
+ Oid hash_proc; /* the hash calculation function */
/*
- * Pre-set-up fmgr call info for the equality operator and the btree
- * comparison function. These are kept in the type cache to avoid
- * problems with memory leaks in repeated calls to array_eq and array_cmp.
- * There is not currently a need to maintain call info for the lt_opr or
- * gt_opr.
+ * Pre-set-up fmgr call info for the equality operator, the btree
+ * comparison function, and the hash calculation function. These are kept
+ * in the type cache to avoid problems with memory leaks in repeated calls
+ * to array_eq, array_cmp, hash_array. There is not currently a need to
+ * maintain call info for the lt_opr or gt_opr.
*/
FmgrInfo eq_opr_finfo;
FmgrInfo cmp_proc_finfo;
+ FmgrInfo hash_proc_finfo;
/*
* Tuple descriptor if it's a composite type (row type). NULL if not
@@ -79,10 +81,13 @@ typedef struct TypeCacheEntry
#define TYPECACHE_LT_OPR 0x0002
#define TYPECACHE_GT_OPR 0x0004
#define TYPECACHE_CMP_PROC 0x0008
-#define TYPECACHE_EQ_OPR_FINFO 0x0010
-#define TYPECACHE_CMP_PROC_FINFO 0x0020
-#define TYPECACHE_TUPDESC 0x0040
-#define TYPECACHE_BTREE_OPFAMILY 0x0080
+#define TYPECACHE_HASH_PROC 0x0010
+#define TYPECACHE_EQ_OPR_FINFO 0x0020
+#define TYPECACHE_CMP_PROC_FINFO 0x0040
+#define TYPECACHE_HASH_PROC_FINFO 0x0080
+#define TYPECACHE_TUPDESC 0x0100
+#define TYPECACHE_BTREE_OPFAMILY 0x0200
+#define TYPECACHE_HASH_OPFAMILY 0x0400
extern TypeCacheEntry *lookup_type_cache(Oid type_id, int flags);