Use ExecPrepareExpr in place of ExecPrepareCheck where appropriate.
Change one more place where ExecInitCheck/ExecPrepareCheck's insistence on getting implicit-AND-format quals wasn't really helpful, because the caller had to do make_ands_implicit() for no reason that it cared about. Using ExecPrepareExpr directly simplifies the code and saves cycles. The only remaining use of these functions is to process resultRelInfo->ri_PartitionCheck quals. However, implicit-AND format does seem to be what we want for that, so leave it alone.
This commit is contained in:
parent
5459cfd3ad
commit
9b95f2fa1e
|
@ -921,8 +921,12 @@ get_qual_from_partbound(Relation rel, Relation parent, Node *bound)
|
|||
* 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,
|
||||
|
|
|
@ -167,7 +167,7 @@ typedef struct AlteredTableInfo
|
|||
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 */
|
||||
|
@ -3740,7 +3740,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode)
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
@ -4182,7 +4182,7 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE 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);
|
||||
|
||||
/*
|
||||
|
@ -4330,7 +4330,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
|
|||
if (tab->partition_constraint)
|
||||
{
|
||||
needscan = true;
|
||||
partqualstate = ExecPrepareCheck(tab->partition_constraint, estate);
|
||||
partqualstate = ExecPrepareExpr(tab->partition_constraint, estate);
|
||||
}
|
||||
|
||||
foreach(l, tab->newvals)
|
||||
|
@ -13354,9 +13354,9 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
|
|||
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)
|
||||
{
|
||||
|
@ -13376,7 +13376,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
|
|||
Oid part_relid = lfirst_oid(lc);
|
||||
Relation part_rel;
|
||||
Expr *constr;
|
||||
List *my_constr;
|
||||
|
||||
/* Lock already taken */
|
||||
if (part_relid != RelationGetRelid(attachRel))
|
||||
|
@ -13398,12 +13397,11 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
|
|||
/* 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);
|
||||
|
|
Loading…
Reference in New Issue