Commit 9b95f2fa authored by Tom Lane's avatar Tom Lane

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.
parent 5459cfd3
...@@ -921,8 +921,12 @@ get_qual_from_partbound(Relation rel, Relation parent, Node *bound) ...@@ -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 * map_partition_varattnos - maps varattno of any Vars in expr from the
* parent attno to partition attno. * 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. * 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 * List *
map_partition_varattnos(List *expr, int target_varno, map_partition_varattnos(List *expr, int target_varno,
......
...@@ -167,7 +167,7 @@ typedef struct AlteredTableInfo ...@@ -167,7 +167,7 @@ typedef struct AlteredTableInfo
Oid newTableSpace; /* new tablespace; 0 means no change */ Oid newTableSpace; /* new tablespace; 0 means no change */
bool chgPersistence; /* T if SET LOGGED/UNLOGGED is used */ bool chgPersistence; /* T if SET LOGGED/UNLOGGED is used */
char newrelpersistence; /* if above is true */ 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 */ /* Objects to rebuild after completing ALTER TYPE operations */
List *changedConstraintOids; /* OIDs of constraints to rebuild */ List *changedConstraintOids; /* OIDs of constraints to rebuild */
List *changedConstraintDefs; /* string definitions of same */ List *changedConstraintDefs; /* string definitions of same */
...@@ -3740,7 +3740,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode) ...@@ -3740,7 +3740,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode)
*/ */
if (((tab->relkind == RELKIND_RELATION || if (((tab->relkind == RELKIND_RELATION ||
tab->relkind == RELKIND_PARTITIONED_TABLE) && tab->relkind == RELKIND_PARTITIONED_TABLE) &&
tab->partition_constraint == NIL) || tab->partition_constraint == NULL) ||
tab->relkind == RELKIND_MATVIEW) tab->relkind == RELKIND_MATVIEW)
AlterTableCreateToastTable(tab->relid, (Datum) 0, lockmode); AlterTableCreateToastTable(tab->relid, (Datum) 0, lockmode);
} }
...@@ -4182,7 +4182,7 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode) ...@@ -4182,7 +4182,7 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode)
* generated by ALTER TABLE commands, but don't rebuild data. * generated by ALTER TABLE commands, but don't rebuild data.
*/ */
if (tab->constraints != NIL || tab->new_notnull || if (tab->constraints != NIL || tab->new_notnull ||
tab->partition_constraint != NIL) tab->partition_constraint != NULL)
ATRewriteTable(tab, InvalidOid, lockmode); ATRewriteTable(tab, InvalidOid, lockmode);
/* /*
...@@ -4330,7 +4330,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode) ...@@ -4330,7 +4330,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
if (tab->partition_constraint) if (tab->partition_constraint)
{ {
needscan = true; needscan = true;
partqualstate = ExecPrepareCheck(tab->partition_constraint, estate); partqualstate = ExecPrepareExpr(tab->partition_constraint, estate);
} }
foreach(l, tab->newvals) foreach(l, tab->newvals)
...@@ -13354,9 +13354,9 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) ...@@ -13354,9 +13354,9 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
RelationGetRelationName(attachRel)))); 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 * 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) if (!skip_validate)
{ {
...@@ -13376,7 +13376,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) ...@@ -13376,7 +13376,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
Oid part_relid = lfirst_oid(lc); Oid part_relid = lfirst_oid(lc);
Relation part_rel; Relation part_rel;
Expr *constr; Expr *constr;
List *my_constr;
/* Lock already taken */ /* Lock already taken */
if (part_relid != RelationGetRelid(attachRel)) if (part_relid != RelationGetRelid(attachRel))
...@@ -13398,12 +13397,11 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) ...@@ -13398,12 +13397,11 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
/* Grab a work queue entry */ /* Grab a work queue entry */
tab = ATGetQueueEntry(wqueue, part_rel); tab = ATGetQueueEntry(wqueue, part_rel);
/* Adjust constraint to match this partition */
constr = linitial(partConstraint); constr = linitial(partConstraint);
my_constr = make_ands_implicit((Expr *) constr); tab->partition_constraint = (Expr *)
tab->partition_constraint = map_partition_varattnos(my_constr, map_partition_varattnos((List *) constr, 1,
1, part_rel, rel);
part_rel,
rel);
/* keep our lock until commit */ /* keep our lock until commit */
if (part_rel != attachRel) if (part_rel != attachRel)
heap_close(part_rel, NoLock); heap_close(part_rel, NoLock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment