* map_partition_varattnos - maps varattno of any Vars in expr from the
* parent attno to partition attno.
*
- * We must allow for a case where physical attnos of a partition can be
+ * We must allow for cases where physical attnos of a partition can be
* different from the parent's.
+ *
+ * Note: this will work on any node tree, so really the argument and result
+ * should be declared "Node *". But a substantial majority of the callers
+ * are working on Lists, so it's less messy to do the casts internally.
*/
List *
map_partition_varattnos(List *expr, int target_varno,
Oid newTableSpace; /* new tablespace; 0 means no change */
bool chgPersistence; /* T if SET LOGGED/UNLOGGED is used */
char newrelpersistence; /* if above is true */
- List *partition_constraint; /* for attach partition validation */
+ Expr *partition_constraint; /* for attach partition validation */
/* Objects to rebuild after completing ALTER TYPE operations */
List *changedConstraintOids; /* OIDs of constraints to rebuild */
List *changedConstraintDefs; /* string definitions of same */
*/
if (((tab->relkind == RELKIND_RELATION ||
tab->relkind == RELKIND_PARTITIONED_TABLE) &&
- tab->partition_constraint == NIL) ||
+ tab->partition_constraint == NULL) ||
tab->relkind == RELKIND_MATVIEW)
AlterTableCreateToastTable(tab->relid, (Datum) 0, lockmode);
}
* generated by ALTER TABLE commands, but don't rebuild data.
*/
if (tab->constraints != NIL || tab->new_notnull ||
- tab->partition_constraint != NIL)
+ tab->partition_constraint != NULL)
ATRewriteTable(tab, InvalidOid, lockmode);
/*
if (tab->partition_constraint)
{
needscan = true;
- partqualstate = ExecPrepareCheck(tab->partition_constraint, estate);
+ partqualstate = ExecPrepareExpr(tab->partition_constraint, estate);
}
foreach(l, tab->newvals)
RelationGetRelationName(attachRel))));
/*
- * Set up to have the table to be scanned to validate the partition
+ * Set up to have the table be scanned to validate the partition
* constraint (see partConstraint above). If it's a partitioned table, we
- * instead schdule its leaf partitions to be scanned instead.
+ * instead schedule its leaf partitions to be scanned.
*/
if (!skip_validate)
{
Oid part_relid = lfirst_oid(lc);
Relation part_rel;
Expr *constr;
- List *my_constr;
/* Lock already taken */
if (part_relid != RelationGetRelid(attachRel))
/* Grab a work queue entry */
tab = ATGetQueueEntry(wqueue, part_rel);
+ /* Adjust constraint to match this partition */
constr = linitial(partConstraint);
- my_constr = make_ands_implicit((Expr *) constr);
- tab->partition_constraint = map_partition_varattnos(my_constr,
- 1,
- part_rel,
- rel);
+ tab->partition_constraint = (Expr *)
+ map_partition_varattnos((List *) constr, 1,
+ part_rel, rel);
/* keep our lock until commit */
if (part_rel != attachRel)
heap_close(part_rel, NoLock);