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

Commita7b9ea3

Browse files
committed
make check constraint machinery aware of different TupleDescs (part_attno)
1 parent39a2274 commita7b9ea3

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

‎src/init.c

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,18 @@ static int cmp_range_entries(const void *p1, const void *p2, void *arg);
7777

7878
staticboolvalidate_range_constraint(constExpr*expr,
7979
constPartRelationInfo*prel,
80+
constAttrNumberpart_attno,
8081
Datum*min,
8182
Datum*max);
8283

8384
staticboolvalidate_hash_constraint(constExpr*expr,
8485
constPartRelationInfo*prel,
86+
constAttrNumberpart_attno,
8587
uint32*part_hash);
8688

8789
staticboolread_opexpr_const(constOpExpr*opexpr,
8890
constPartRelationInfo*prel,
91+
constAttrNumberpart_attno,
8992
Datum*val);
9093

9194
staticintoid_cmp(constvoid*p1,constvoid*p2);
@@ -347,6 +350,7 @@ init_shmem_config(void)
347350
void
348351
fill_prel_with_partitions(constOid*partitions,
349352
constuint32parts_count,
353+
constchar*part_column_name,
350354
PartRelationInfo*prel)
351355
{
352356
uint32i;
@@ -361,7 +365,18 @@ fill_prel_with_partitions(const Oid *partitions,
361365

362366
for (i=0;i<PrelChildrenCount(prel);i++)
363367
{
364-
con_expr=get_partition_constraint_expr(partitions[i],prel->attnum);
368+
AttrNumberpart_attno;
369+
370+
/* NOTE: Partitions may have different TupleDescs */
371+
part_attno=get_attnum(partitions[i],part_column_name);
372+
373+
/* Raise ERROR if there's no such column */
374+
if (part_attno==InvalidAttrNumber)
375+
elog(ERROR,"partition \"%s\" has no column \"%s\"",
376+
get_rel_name_or_relid(partitions[i]),
377+
part_column_name);
378+
379+
con_expr=get_partition_constraint_expr(partitions[i],part_attno);
365380

366381
/* Perform a partitioning_type-dependent task */
367382
switch (prel->parttype)
@@ -370,13 +385,13 @@ fill_prel_with_partitions(const Oid *partitions,
370385
{
371386
uint32hash;/* hash value < parts_count */
372387

373-
if (validate_hash_constraint(con_expr,prel,&hash))
388+
if (validate_hash_constraint(con_expr,prel,part_attno,&hash))
374389
prel->children[hash]=partitions[i];
375390
else
376391
{
377392
DisablePathman();/* disable pg_pathman since config is broken */
378393
ereport(ERROR,
379-
(errmsg("Wrong constraint format for HASH partition \"%s\"",
394+
(errmsg("wrong constraint format for HASH partition \"%s\"",
380395
get_rel_name_or_relid(partitions[i])),
381396
errhint(INIT_ERROR_HINT)));
382397
}
@@ -387,7 +402,7 @@ fill_prel_with_partitions(const Oid *partitions,
387402
{
388403
Datumrange_min,range_max;
389404

390-
if (validate_range_constraint(con_expr,prel,
405+
if (validate_range_constraint(con_expr,prel,part_attno,
391406
&range_min,&range_max))
392407
{
393408
prel->ranges[i].child_oid=partitions[i];
@@ -398,7 +413,7 @@ fill_prel_with_partitions(const Oid *partitions,
398413
{
399414
DisablePathman();/* disable pg_pathman since config is broken */
400415
ereport(ERROR,
401-
(errmsg("Wrong constraint format for RANGE partition \"%s\"",
416+
(errmsg("wrong constraint format for RANGE partition \"%s\"",
402417
get_rel_name_or_relid(partitions[i])),
403418
errhint(INIT_ERROR_HINT)));
404419
}
@@ -905,6 +920,7 @@ cmp_range_entries(const void *p1, const void *p2, void *arg)
905920
staticbool
906921
validate_range_constraint(constExpr*expr,
907922
constPartRelationInfo*prel,
923+
constAttrNumberpart_attno,
908924
Datum*min,
909925
Datum*max)
910926
{
@@ -928,23 +944,21 @@ validate_range_constraint(const Expr *expr,
928944

929945
if (strategy==BTGreaterEqualStrategyNumber)
930946
{
931-
if (!read_opexpr_const(opexpr,prel,min))
947+
if (!read_opexpr_const(opexpr,prel,part_attno,min))
932948
return false;
933949
}
934-
else
935-
return false;
950+
elsereturn false;
936951

937952
/* check that right operand is < operator */
938953
opexpr= (OpExpr*)lsecond(boolexpr->args);
939954
strategy=get_op_opfamily_strategy(opexpr->opno,tce->btree_opf);
940955

941956
if (strategy==BTLessStrategyNumber)
942957
{
943-
if (!read_opexpr_const(opexpr,prel,max))
958+
if (!read_opexpr_const(opexpr,prel,part_attno,max))
944959
return false;
945960
}
946-
else
947-
return false;
961+
elsereturn false;
948962

949963
return true;
950964
}
@@ -957,6 +971,7 @@ validate_range_constraint(const Expr *expr,
957971
staticbool
958972
read_opexpr_const(constOpExpr*opexpr,
959973
constPartRelationInfo*prel,
974+
constAttrNumberpart_attno,
960975
Datum*val)
961976
{
962977
constNode*left;
@@ -990,7 +1005,7 @@ read_opexpr_const(const OpExpr *opexpr,
9901005
elsereturn false;
9911006

9921007
/* VAR.attno == partitioned attribute number */
993-
if (part_attr->varoattno!=prel->attnum)
1008+
if (part_attr->varoattno!=part_attno)
9941009
return false;
9951010

9961011
/* CONST is NOT NULL */
@@ -1026,6 +1041,7 @@ read_opexpr_const(const OpExpr *opexpr,
10261041
staticbool
10271042
validate_hash_constraint(constExpr*expr,
10281043
constPartRelationInfo*prel,
1044+
constAttrNumberpart_attno,
10291045
uint32*part_hash)
10301046
{
10311047
constTypeCacheEntry*tce;
@@ -1079,7 +1095,7 @@ validate_hash_constraint(const Expr *expr,
10791095
var= (Var*)linitial(type_hash_proc_expr->args);
10801096

10811097
/* Check that 'var' is the partitioning key attribute */
1082-
if (var->varoattno!=prel->attnum)
1098+
if (var->varoattno!=part_attno)
10831099
return false;
10841100

10851101
/* Check that PARTITIONS_COUNT is equal to total amount of partitions */

‎src/init.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ void unload_config(void);
122122

123123
voidfill_prel_with_partitions(constOid*partitions,
124124
constuint32parts_count,
125+
constchar*part_column_name,
125126
PartRelationInfo*prel);
126127

127128
/* Result of find_inheritance_children_array() */

‎src/relation_info.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ refresh_pathman_relation_info(Oid relid,
197197
* will try to refresh it again (and again), until the error is fixed
198198
* by user manually (i.e. invalid check constraints etc).
199199
*/
200-
fill_prel_with_partitions(prel_children,prel_children_count,prel);
200+
fill_prel_with_partitions(prel_children,
201+
prel_children_count,
202+
part_column_name,prel);
201203

202204
/* Peform some actions for each child */
203205
for (i=0;i<prel_children_count;i++)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp