@@ -988,27 +988,27 @@ read_opexpr_const(const OpExpr *opexpr,
988988/*
989989 * Validate hash constraint. It MUST have this exact format:
990990 *
991- *get_hash_part_idx(TYPE_HASH_PROC(VALUE), PARTITIONS_COUNT) =CUR_PARTITION_HASH
991+ *get_hash_part_idx(TYPE_HASH_PROC(VALUE), PARTITIONS_COUNT) =CUR_PARTITION_IDX
992992 *
993- * Writes 'part_hash ' hash value for this partition on success.
993+ * Writes 'part_idx ' hash value for this partition on success.
994994 */
995995bool
996996validate_hash_constraint (const Expr * expr ,
997997const PartRelationInfo * prel ,
998998const AttrNumber part_attno ,
999- uint32 * part_hash )
999+ uint32 * part_idx )
10001000{
10011001const TypeCacheEntry * tce ;
10021002const OpExpr * eq_expr ;
10031003const FuncExpr * get_hash_expr ,
10041004* type_hash_proc_expr ;
1005- const Var * var ;/* partitioned column */
10061005
10071006if (!expr )
10081007return false;
10091008
10101009if (!IsA (expr ,OpExpr ))
10111010return false;
1011+
10121012eq_expr = (const OpExpr * )expr ;
10131013
10141014/* Check that left expression is a function call */
@@ -1027,31 +1027,51 @@ validate_hash_constraint(const Expr *expr,
10271027{
10281028Node * first = linitial (get_hash_expr -> args );/* arg #1: TYPE_HASH_PROC(VALUE) */
10291029Node * second = lsecond (get_hash_expr -> args );/* arg #2: PARTITIONS_COUNT */
1030- Const * cur_partition_hash ;/* hash value for this partition */
1030+ Const * cur_partition_idx ;/* hash value for this partition */
1031+ Node * hash_arg ;
10311032
10321033if (!IsA (first ,FuncExpr )|| !IsA (second ,Const ))
10331034return false;
10341035
10351036type_hash_proc_expr = (FuncExpr * )first ;
10361037
1037- /* Check that function is indeed TYPE_HASH_PROC */
1038- if (type_hash_proc_expr -> funcid != prel -> hash_proc ||
1039- !(IsA (linitial (type_hash_proc_expr -> args ),Var )||
1040- IsA (linitial (type_hash_proc_expr -> args ),RelabelType )))
1041- {
1038+ /* Check that function is indeed TYPE_HASH_PROC() */
1039+ if (type_hash_proc_expr -> funcid != prel -> hash_proc )
10421040return false;
1043- }
10441041
1045- /* Extract argument into 'var' */
1046- if (IsA (linitial (type_hash_proc_expr -> args ),RelabelType ))
1047- var = (Var * ) ((RelabelType * )linitial (type_hash_proc_expr -> args ))-> arg ;
1048- else
1049- var = (Var * )linitial (type_hash_proc_expr -> args );
1050-
1051- /* Check that 'var' is the partitioning key attribute */
1052- if (var -> varoattno != part_attno )
1042+ /* There should be exactly 1 argument */
1043+ if (list_length (type_hash_proc_expr -> args )!= 1 )
10531044return false;
10541045
1046+ /* Extract arg of TYPE_HASH_PROC() */
1047+ hash_arg = (Node * )linitial (type_hash_proc_expr -> args );
1048+
1049+ /* Check arg of TYPE_HASH_PROC() */
1050+ switch (nodeTag (hash_arg ))
1051+ {
1052+ case T_RelabelType :
1053+ {
1054+ hash_arg = (Node * ) ((RelabelType * )hash_arg )-> arg ;
1055+ }
1056+ /* FALL THROUGH (no break) */
1057+
1058+ case T_Var :
1059+ {
1060+ Var * var = (Var * )hash_arg ;
1061+
1062+ if (!IsA (var ,Var ))
1063+ return false;
1064+
1065+ /* Check that 'var' is the partitioning key attribute */
1066+ if (var -> varoattno != part_attno )
1067+ return false;
1068+ }
1069+ break ;
1070+
1071+ default :
1072+ return false;
1073+ }
1074+
10551075/* Check that PARTITIONS_COUNT is equal to total amount of partitions */
10561076if (DatumGetUInt32 (((Const * )second )-> constvalue )!= PrelChildrenCount (prel ))
10571077return false;
@@ -1060,22 +1080,22 @@ validate_hash_constraint(const Expr *expr,
10601080if (!IsA (lsecond (eq_expr -> args ),Const ))
10611081return false;
10621082
1063- cur_partition_hash = lsecond (eq_expr -> args );
1083+ /* Fetch CUR_PARTITION_IDX */
1084+ cur_partition_idx = lsecond (eq_expr -> args );
10641085
10651086/* Check that CUR_PARTITION_HASH is NOT NULL */
1066- if (cur_partition_hash -> constisnull )
1087+ if (cur_partition_idx -> constisnull )
10671088return false;
10681089
1069- * part_hash = DatumGetUInt32 (cur_partition_hash -> constvalue );
1070- if (* part_hash >=PrelChildrenCount (prel ))
1090+ * part_idx = DatumGetUInt32 (cur_partition_idx -> constvalue );
1091+ if (* part_idx >=PrelChildrenCount (prel ))
10711092return false;
10721093
10731094return true;/* everything seems to be ok */
10741095}
10751096
10761097return false;
10771098}
1078-
10791099/* needed for find_inheritance_children_array() function */
10801100static int
10811101oid_cmp (const void * p1 ,const void * p2 )