Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit69028ca

Browse files
committed
small changes in validate_hash_constraint()
1 parentd33f4e3 commit69028ca

File tree

4 files changed

+48
-28
lines changed

4 files changed

+48
-28
lines changed

‎src/include/init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ bool validate_range_constraint(const Expr *expr,
218218
boolvalidate_hash_constraint(constExpr*expr,
219219
constPartRelationInfo*prel,
220220
constAttrNumberpart_attno,
221-
uint32*part_hash);
221+
uint32*part_idx);
222222

223223

224224
#endif/* PATHMAN_INIT_H */

‎src/include/relation_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ typedef struct
176176
boolbyval;
177177

178178
/* For HASH partitions */
179-
uint32hash;
179+
uint32part_idx;
180180
}PartBoundInfo;
181181

182182
/*

‎src/init.c

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
995995
bool
996996
validate_hash_constraint(constExpr*expr,
997997
constPartRelationInfo*prel,
998998
constAttrNumberpart_attno,
999-
uint32*part_hash)
999+
uint32*part_idx)
10001000
{
10011001
constTypeCacheEntry*tce;
10021002
constOpExpr*eq_expr;
10031003
constFuncExpr*get_hash_expr,
10041004
*type_hash_proc_expr;
1005-
constVar*var;/* partitioned column */
10061005

10071006
if (!expr)
10081007
return false;
10091008

10101009
if (!IsA(expr,OpExpr))
10111010
return false;
1011+
10121012
eq_expr= (constOpExpr*)expr;
10131013

10141014
/* Check that left expression is a function call */
@@ -1027,31 +1027,51 @@ validate_hash_constraint(const Expr *expr,
10271027
{
10281028
Node*first=linitial(get_hash_expr->args);/* arg #1: TYPE_HASH_PROC(VALUE) */
10291029
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;
10311032

10321033
if (!IsA(first,FuncExpr)|| !IsA(second,Const))
10331034
return false;
10341035

10351036
type_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)
10421040
return 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)
10531044
return 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+
caseT_RelabelType:
1053+
{
1054+
hash_arg= (Node*) ((RelabelType*)hash_arg)->arg;
1055+
}
1056+
/* FALL THROUGH (no break) */
1057+
1058+
caseT_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 */
10561076
if (DatumGetUInt32(((Const*)second)->constvalue)!=PrelChildrenCount(prel))
10571077
return false;
@@ -1060,22 +1080,22 @@ validate_hash_constraint(const Expr *expr,
10601080
if (!IsA(lsecond(eq_expr->args),Const))
10611081
return 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)
10671088
return 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))
10711092
return false;
10721093

10731094
return true;/* everything seems to be ok */
10741095
}
10751096

10761097
return false;
10771098
}
1078-
10791099
/* needed for find_inheritance_children_array() function */
10801100
staticint
10811101
oid_cmp(constvoid*p1,constvoid*p2)

‎src/relation_info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ fill_prel_with_partitions(PartRelationInfo *prel,
479479
switch (prel->parttype)
480480
{
481481
casePT_HASH:
482-
prel->children[bound_info->hash]=bound_info->child_rel;
482+
prel->children[bound_info->part_idx]=bound_info->child_rel;
483483
break;
484484

485485
casePT_RANGE:
@@ -1047,7 +1047,7 @@ fill_pbin_with_bounds(PartBoundInfo *pbin,
10471047
{
10481048
if (!validate_hash_constraint(constraint_expr,
10491049
prel,part_attno,
1050-
&pbin->hash))
1050+
&pbin->part_idx))
10511051
{
10521052
DisablePathman();/* disable pg_pathman since config is broken */
10531053
ereport(ERROR,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp