Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9b95f2f

Browse files
committed
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.
1 parent 5459cfd commit 9b95f2f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/backend/catalog/partition.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,12 @@ get_qual_from_partbound(Relation rel, Relation parent, Node *bound)
921921
* map_partition_varattnos - maps varattno of any Vars in expr from the
922922
* parent attno to partition attno.
923923
*
924-
* We must allow for a case where physical attnos of a partition can be
924+
* We must allow for cases where physical attnos of a partition can be
925925
* different from the parent's.
926+
*
927+
* Note: this will work on any node tree, so really the argument and result
928+
* should be declared "Node *". But a substantial majority of the callers
929+
* are working on Lists, so it's less messy to do the casts internally.
926930
*/
927931
List *
928932
map_partition_varattnos(List *expr, int target_varno,

src/backend/commands/tablecmds.c

+10-12
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ typedef struct AlteredTableInfo
167167
Oid newTableSpace; /* new tablespace; 0 means no change */
168168
bool chgPersistence; /* T if SET LOGGED/UNLOGGED is used */
169169
char newrelpersistence; /* if above is true */
170-
List *partition_constraint; /* for attach partition validation */
170+
Expr *partition_constraint; /* for attach partition validation */
171171
/* Objects to rebuild after completing ALTER TYPE operations */
172172
List *changedConstraintOids; /* OIDs of constraints to rebuild */
173173
List *changedConstraintDefs; /* string definitions of same */
@@ -3740,7 +3740,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode)
37403740
*/
37413741
if (((tab->relkind == RELKIND_RELATION ||
37423742
tab->relkind == RELKIND_PARTITIONED_TABLE) &&
3743-
tab->partition_constraint == NIL) ||
3743+
tab->partition_constraint == NULL) ||
37443744
tab->relkind == RELKIND_MATVIEW)
37453745
AlterTableCreateToastTable(tab->relid, (Datum) 0, lockmode);
37463746
}
@@ -4182,7 +4182,7 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode)
41824182
* generated by ALTER TABLE commands, but don't rebuild data.
41834183
*/
41844184
if (tab->constraints != NIL || tab->new_notnull ||
4185-
tab->partition_constraint != NIL)
4185+
tab->partition_constraint != NULL)
41864186
ATRewriteTable(tab, InvalidOid, lockmode);
41874187

41884188
/*
@@ -4330,7 +4330,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
43304330
if (tab->partition_constraint)
43314331
{
43324332
needscan = true;
4333-
partqualstate = ExecPrepareCheck(tab->partition_constraint, estate);
4333+
partqualstate = ExecPrepareExpr(tab->partition_constraint, estate);
43344334
}
43354335

43364336
foreach(l, tab->newvals)
@@ -13354,9 +13354,9 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1335413354
RelationGetRelationName(attachRel))));
1335513355

1335613356
/*
13357-
* Set up to have the table to be scanned to validate the partition
13357+
* Set up to have the table be scanned to validate the partition
1335813358
* constraint (see partConstraint above). If it's a partitioned table, we
13359-
* instead schdule its leaf partitions to be scanned instead.
13359+
* instead schedule its leaf partitions to be scanned.
1336013360
*/
1336113361
if (!skip_validate)
1336213362
{
@@ -13376,7 +13376,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1337613376
Oid part_relid = lfirst_oid(lc);
1337713377
Relation part_rel;
1337813378
Expr *constr;
13379-
List *my_constr;
1338013379

1338113380
/* Lock already taken */
1338213381
if (part_relid != RelationGetRelid(attachRel))
@@ -13398,12 +13397,11 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1339813397
/* Grab a work queue entry */
1339913398
tab = ATGetQueueEntry(wqueue, part_rel);
1340013399

13400+
/* Adjust constraint to match this partition */
1340113401
constr = linitial(partConstraint);
13402-
my_constr = make_ands_implicit((Expr *) constr);
13403-
tab->partition_constraint = map_partition_varattnos(my_constr,
13404-
1,
13405-
part_rel,
13406-
rel);
13402+
tab->partition_constraint = (Expr *)
13403+
map_partition_varattnos((List *) constr, 1,
13404+
part_rel, rel);
1340713405
/* keep our lock until commit */
1340813406
if (part_rel != attachRel)
1340913407
heap_close(part_rel, NoLock);

0 commit comments

Comments
 (0)