10000 Update some comments that should've covered MERGE · postgrespro/postgres@3b2db22 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b2db22

Browse files
committed
Update some comments that should've covered MERGE
Oversight in 7103ebb. Backpatch to 15. Author: Richard Guo <guofenglinux@gmail.com> Discussion: https://postgr.es/m/CAMbWs48gnDjZXq3-b56dVpQCNUJ5hD9kdtWN4QFwKCEapspNsA@mail.gmail.com
1 parent 8328a15 commit 3b2db22

File tree

14 files changed

+42
-34
lines changed

14 files changed

+42
-34
lines changed

src/backend/optimizer/path/indxpath.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,12 +3393,13 @@ check_index_predicates(PlannerInfo *root, RelOptInfo *rel)
33933393
* Normally we remove quals that are implied by a partial index's
33943394
* predicate from indrestrictinfo, indicating that they need not be
33953395
* checked explicitly by an indexscan plan using this index. However, if
3396-
* the rel is a target relation of UPDATE/DELETE/SELECT FOR UPDATE, we
3397-
* cannot remove such quals from the plan, because they need to be in the
3398-
* plan so that they will be properly rechecked by EvalPlanQual testing.
3399-
* Some day we might want to remove such quals from the main plan anyway
3400-
* and pass them through to EvalPlanQual via a side channel; but for now,
3401-
* we just don't remove implied quals at all for target relations.
3396+
* the rel is a target relation of UPDATE/DELETE/MERGE/SELECT FOR UPDATE,
3397+
* we cannot remove such quals from the plan, because they need to be in
3398+
* the plan so that they will be properly rechecked by EvalPlanQual
3399+
* testing. Some day we might want to remove such quals from the main
3400+
* plan anyway and pass them through to EvalPlanQual via a side channel;
3401+
* but for now, we just don't remove implied quals at all for target
3402+
* relations.
34023403
*/
34033404
is_target_rel = (bms_is_member(rel->relid, root->all_result_relids) ||
34043405
get_plan_rowmark(root->rowMarks, rel->relid) != NULL);

src/backend/optimizer/plan/planmain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ query_planner(PlannerInfo *root,
266266
add_other_rels_to_query(root);
267267

268268
/*
269-
* Distribute any UPDATE/DELETE row identity variables to the target
269+
* Distribute any UPDATE/DELETE/MERGE row identity variables to the target
270270
* relations. This can't be done till we've finished expansion of
271271
* appendrels.
272272
*/

src/backend/optimizer/plan/planner.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,7 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
17491749

17501750
if (bms_membership(root->all_result_relids) == BMS_MULTIPLE)
17511751
{
1752-
/* Inherited UPDATE/DELETE */
1752+
/* Inherited UPDATE/DELETE/MERGE */
17531753
RelOptInfo *top_result_rel = find_base_rel(root,
17541754
parse->resultRelation);
17551755
int resultRelation = -1;
@@ -1876,7 +1876,7 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
18761876
}
18771877
else
18781878
{
1879-
/* Single-relation INSERT/UPDATE/DELETE. */
1879+
/* Single-relation INSERT/UPDATE/DELETE/MERGE. */
18801880
resultRelations = list_make1_int(parse->resultRelation);
18811881
if (parse->commandType == CMD_UPDATE)
18821882
updateColnosLists = list_make1(root->update_colnos);

src/backend/optimizer/util/appendinfo.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
730730

731731
/*
732732
* add_row_identity_var
733-
* Register a row-identity column to be used in UPDATE/DELETE.
733+
* Register a row-identity column to be used in UPDATE/DELETE/MERGE.
734734
*
735735
* The Var must be equal(), aside from varno, to any other row-identity
736736
* column with the same rowid_name. Thus, for example, "wholerow"
@@ -909,8 +909,8 @@ add_row_identity_columns(PlannerInfo *root, Index rtindex,
909909
* distribute_row_identity_vars
910910
*
911911
* After we have finished identifying all the row identity columns
912-
* needed by an inherited UPDATE/DELETE query, make sure that these
913-
* columns will be generated by all the target relations.
912+
* needed by an inherited UPDATE/DELETE/MERGE query, make sure that
913+
* these columns will be generated by all the target relations.
914914
*
915915
* This is more or less like what build_base_rel_tlists() does,
916916
* except that it would not understand what to do with ROWID_VAR Vars.

src/backend/optimizer/util/inherit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ expand_single_inheritance_child(PlannerInfo *root, RangeTblEntry *parentrte,
609609

610610
/*
611611
* If we are creating a child of the query target relation (only possible
612-
* in UPDATE/DELETE), add it to all_result_relids, as well as
612+
* in UPDATE/DELETE/MERGE), add it to all_result_relids, as well as
613613
* leaf_result_relids if appropriate, and make sure that we generate
614614
* required row-identity data.
615615
*/

src/backend/optimizer/util/pathnode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3630,7 +3630,8 @@ create_lockrows_path(PlannerInfo *root, RelOptInfo *rel,
36303630

36313631
/*
36323632
* create_modifytable_path
3633-
* Creates a pathnode that represents performing INSERT/UPDATE/DELETE mods
< F438 /code>3633+
* Creates a pathnode that represents performing INSERT/UPDATE/DELETE/MERGE
3634+
* mods
36343635
*
36353636
* 'rel' is the parent relation associated with the result
36363637
* 'subpath' is a Path producing source data

src/backend/optimizer/util/relnode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel,
10131013

10141014
if (var->varno == ROWID_VAR)
10151015
{
1016-
/* UPDATE/DELETE row identity vars are always needed */
1016+
/* UPDATE/DELETE/MERGE row identity vars are always needed */
10171017
RowIdentityVarInfo *ridinfo = (RowIdentityVarInfo *)
10181018
list_nth(root->row_identity_vars, var->varattno - 1);
10191019

src/backend/parser/parse_clause.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ transformFromClause(ParseState *pstate, List *frmList)
153153

154154
/*
155155
* setTargetTable
156-
* Add the target relation of INSERT/UPDATE/DELETE to the range table,
156+
* Add the target relation of INSERT/UPDATE/DELETE/MERGE to the range table,
157157
* and make the special links to it in the ParseState.
158158
*
159159
* We also open the target relation and acquire a write lock on it.
@@ -163,7 +163,9 @@ transformFromClause(ParseState *pstate, List *frmList)
163163
*
164164
* If alsoSource is true, add the target to the query's joinlist and
165165
* namespace. For INSERT, we don't want the target to be joined to;
166-
* it's a destination of tuples, not a source. For UPDATE/DELETE,
166+
* it's a destination of tuples, not a source. MERGE is actually
167+
* both, but we'll add it separately to joinlist and namespace, so
168+
* doing nothing (like INSERT) is correct here. For UPDATE/DELETE,
167169
* we do need to scan or join the target. (NOTE: we do not bother
168170
* to check for namespace conflict; we assume that the namespace was
169171
* initially empty in these cases.)

src/backend/parser/parse_expr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,8 +1679,8 @@ transformSubLink(ParseState *pstate, SubLink *sublink)
16791679

16801680
/*
16811681
* Check to see if the sublink is in an invalid place within the query. We
1682-
* allow sublinks everywhere in SELECT/INSERT/UPDATE/DELETE, but generally
1683-
* not in utility statements.
1682+
* allow sublinks everywhere in SELECT/INSERT/UPDATE/DELETE/MERGE, but
1683+
* generally not in utility statements.
16841684
*/
16851685
err = NULL;
16861686
switch (pstate->p_expr_kind)

src/backend/parser/parse_merge.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ transformMergeStmt(ParseState *pstate, MergeStmt *stmt)
163163
errmsg("unreachable WHEN clause specified after unconditional WHEN clause")));
164164
}
165165

166-
/* Set up the MERGE target table. */
166+
/*
167+
* Set up the MERGE target table. The target table is added to the
168+
* namespace below and to joinlist in transform_MERGE_to_join, so don't
169+
* do it here.
170+
*/
167171
qry->resultRelation = setTargetTable(pstate, stmt->relation,
168172
stmt->relation->inh,
169173
false, targetPerms);

0 commit comments

Comments
 (0)
0