diff options
Diffstat (limited to 'src/backend/partitioning/partbounds.c')
-rw-r--r-- | src/backend/partitioning/partbounds.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c index 99d26de7e64..f3c9236ad56 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -1237,6 +1237,13 @@ check_default_partition_contents(Relation parent, Relation default_rel, : get_qual_for_range(parent, new_spec, false); def_part_constraints = get_proposed_default_constraint(new_part_constraints); + /* + * Map the Vars in the constraint expression from parent's attnos to + * default_rel's. + */ + def_part_constraints = + map_partition_varattnos(def_part_constraints, 1, default_rel, + parent, NULL); /* * If the existing constraints on the default partition imply that it will @@ -1265,7 +1272,6 @@ check_default_partition_contents(Relation parent, Relation default_rel, { Oid part_relid = lfirst_oid(lc); Relation part_rel; - Expr *constr; Expr *partition_constraint; EState *estate; ExprState *partqualstate = NULL; @@ -1281,6 +1287,15 @@ check_default_partition_contents(Relation parent, Relation default_rel, part_rel = table_open(part_relid, NoLock); /* + * Map the Vars in the constraint expression from default_rel's + * the sub-partition's. + */ + partition_constraint = make_ands_explicit(def_part_constraints); + partition_constraint = (Expr *) + map_partition_varattnos((List *) partition_constraint, 1, + part_rel, default_rel, NULL); + + /* * If the partition constraints on default partition child imply * that it will not contain any row that would belong to the new * partition, we can avoid scanning the child table. @@ -1297,7 +1312,10 @@ check_default_partition_contents(Relation parent, Relation default_rel, } } else + { part_rel = default_rel; + partition_constraint = make_ands_explicit(def_part_constraints); + } /* * Only RELKIND_RELATION relations (i.e. leaf partitions) need to be @@ -1318,10 +1336,6 @@ check_default_partition_contents(Relation parent, Relation default_rel, continue; } - constr = linitial(def_part_constraints); - partition_constraint = (Expr *) - map_partition_varattnos((List *) constr, - 1, part_rel, parent, NULL); estate = CreateExecutorState(); /* Build expression execution states for partition check quals */ |