@@ -988,27 +988,27 @@ read_opexpr_const(const OpExpr *opexpr,
988
988
/*
989
989
* Validate hash constraint. It MUST have this exact format:
990
990
*
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
992
992
*
993
- * Writes 'part_hash ' hash value for this partition on success.
993
+ * Writes 'part_idx ' hash value for this partition on success.
994
994
*/
995
995
bool
996
996
validate_hash_constraint (const Expr * expr ,
997
997
const PartRelationInfo * prel ,
998
998
const AttrNumber part_attno ,
999
- uint32 * part_hash )
999
+ uint32 * part_idx )
1000
1000
{
1001
1001
const TypeCacheEntry * tce ;
1002
1002
const OpExpr * eq_expr ;
1003
1003
const FuncExpr * get_hash_expr ,
1004
1004
* type_hash_proc_expr ;
1005
- const Var * var ; /* partitioned column */
1006
1005
1007
1006
if (!expr )
1008
1007
return false;
1009
1008
1010
1009
if (!IsA (expr , OpExpr ))
1011
1010
return false;
1011
+
1012
1012
eq_expr = (const OpExpr * ) expr ;
1013
1013
1014
1014
/* Check that left expression is a function call */
@@ -1027,31 +1027,51 @@ validate_hash_constraint(const Expr *expr,
1027
1027
{
1028
1028
Node * first = linitial (get_hash_expr -> args ); /* arg #1: TYPE_HASH_PROC(VALUE) */
1029
1029
Node * 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 ;
1031
1032
1032
1033
if (!IsA (first , FuncExpr ) || !IsA (second , Const ))
1033
1034
return false;
1034
1035
1035
1036
type_hash_proc_expr = (FuncExpr * ) first ;
1036
1037
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 )
1042
1040
return false;
1043
- }
1044
1041
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 )
1053
1044
return false;
1054
1045
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
+
1055
1075
/* Check that PARTITIONS_COUNT is equal to total amount of partitions */
1056
1076
if (DatumGetUInt32 (((Const * ) second )-> constvalue ) != PrelChildrenCount (prel ))
1057
1077
return false;
@@ -1060,22 +1080,22 @@ validate_hash_constraint(const Expr *expr,
1060
1080
if (!IsA (lsecond (eq_expr -> args ), Const ))
1061
1081
return false;
1062
1082
1063
- cur_partition_hash = lsecond (eq_expr -> args );
1083
+ /* Fetch CUR_PARTITION_IDX */
1084
+ cur_partition_idx = lsecond (eq_expr -> args );
1064
1085
1065
1086
/* Check that CUR_PARTITION_HASH is NOT NULL */
1066
- if (cur_partition_hash -> constisnull )
1087
+ if (cur_partition_idx -> constisnull )
1067
1088
return false;
1068
1089
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 ))
1071
1092
return false;
1072
1093
1073
1094
return true; /* everything seems to be ok */
1074
1095
}
1075
1096
1076
1097
return false;
1077
1098
}
1078
-
1079
1099
/* needed for find_inheritance_children_array() function */
1080
1100
static int
1081
1101
oid_cmp (const void * p1 , const void * p2 )
0 commit comments