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

Commit fb2a83b

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 4a6de74 commit fb2a83b

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
@@ -3378,12 +3378,13 @@ check_index_predicates(PlannerInfo *root, RelOptInfo *rel)
33783378
* Normally we remove quals that are implied by a partial index's
33793379
* predicate from indrestrictinfo, indicating that they need not be
33803380
* checked explicitly by an indexscan plan using this index. However, if
3381-
* the rel is a target relation of UPDATE/DELETE/SELECT FOR UPDATE, we
3382-
* cannot remove such quals from the plan, because they need to be in the
3383-
* plan so that they will be properly rechecked by EvalPlanQual testing.
3384-
* Some day we might want to remove such quals from the main plan anyway
3385-
* and pass them through to EvalPlanQual via a side channel; but for now,
3386-
* we just don't remove implied quals at all for target relations.
3381+
* the rel is a target relation of UPDATE/DELETE/MERGE/SELECT FOR UPDATE,
3382+
* we cannot remove such quals from the plan, because they need to be in
3383+
* the plan so that they will be properly rechecked by EvalPlanQual
3384+
* testing. Some day we might want to remove such quals from the main
3385+
* plan anyway and pass them through to EvalPlanQual via a side channel;
3386+
* but for now, we just don't remove implied quals at all for target
3387+
* relations.
33873388
*/
33883389
is_target_rel = (bms_is_member(rel->relid, root->all_result_relids) ||
33893390
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
@@ -264,7 +264,7 @@ query_planner(PlannerInfo *root,
264264
add_other_rels_to_query(root);
265265

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

src/backend/optimizer/plan/planner.c

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

17481748
if (bms_membership(root->all_result_relids) == BMS_MULTIPLE)
17491749
{
1750-
/* Inherited UPDATE/DELETE */
1750+
/* Inherited UPDATE/DELETE/MERGE */
17511751
RelOptInfo *top_result_rel = find_base_rel(root,
17521752
parse->resultRelation);
17531753
int resultRelation = -1;
@@ -1874,7 +1874,7 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
18741874
}
18751875
else
18761876
{
1877-
/* Single-relation INSERT/UPDATE/DELETE. */
1877+
/* Single-relation INSERT/UPDATE/DELETE/MERGE. */
18781878
resultRelations = list_make1_int(parse->resultRelation);
18791879
if (parse->commandType == CMD_UPDATE)
18801880
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
@@ -748,7 +748,7 @@ find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
748748

749749
/*
750750
* add_row_identity_var
751-
* Register a row-identity column to be used in UPDATE/DELETE.
751+
* Register a row-identity column to be used in UPDATE/DELETE/MERGE.
752752
*
753753
* The Var must be equal(), aside from varno, to any other row-identity
754754
* column with the same rowid_name. Thus, for example, "wholerow"
@@ -927,8 +927,8 @@ add_row_identity_columns(PlannerInfo *root, Index rtindex,
927927
* distribute_row_identity_vars
928928
*
929929
* After we have finished identifying all the row identity columns
930-
* needed by an inherited UPDATE/DELETE query, make sure that these
931-
* columns will be generated by all the target relations.
930+
* needed by an inherited UPDATE/DELETE/MERGE query, make sure that
931+
* these columns will be generated by all the target relations.
932932
*
933933
* This is more or less like what build_base_rel_tlists() does,
934934
* 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
@@ -3613,7 +3613,8 @@ create_lockrows_path(PlannerInfo *root, RelOptInfo *rel,
36133613

36143614
/*
36153615
* create_modifytable_path
3616-
* Creates a pathnode that represents performing INSERT/UPDATE/DELETE mods
3616+
* Creates a pathnode that represents performing INSERT/UPDATE/DELETE/MERGE
3617+
* mods
36173618
*
36183619
* 'rel' is the parent relation associated with the result
36193620
* '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
@@ -999,7 +999,7 @@ build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel,
999999

10001000
if (var->varno == ROWID_VAR)
10011001
{
1002-
/* UPDATE/DELETE row identity vars are always needed */
1002+
/* UPDATE/DELETE/MERGE row identity vars are always needed */
10031003
RowIdentityVarInfo *ridinfo = (RowIdentityVarInfo *)
10041004
list_nth(root->row_identity_vars, var->varattno - 1);
10051005

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
@@ -1689,8 +1689,8 @@ transformSubLink(ParseState *pstate, SubLink *sublink)
16891689

16901690
/*
16911691
* Check to see if the sublink is in an invalid place within the query. We
1692-
* allow sublinks everywhere in SELECT/INSERT/UPDATE/DELETE, but generally
1693-
* not in utility statements.
1692+
* allow sublinks everywhere in SELECT/INSERT/UPDATE/DELETE/MERGE, but
1693+
* generally not in utility statements.
16941694
*/
16951695
err = NULL;
16961696
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);

src/include/nodes/parsenodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,8 @@ typedef struct RangeTblEntry
10311031
*
10321032
* rellockmode is really LOCKMODE, but it's declared int to avoid having
10331033
* to include lock-related headers here. It must be RowExclusiveLock if
1034-
* the RTE is an INSERT/UPDATE/DELETE target, else RowShareLock if the RTE
1035-
* is a SELECT FOR UPDATE/FOR SHARE target, else AccessShareLock.
1034+
* the RTE is an INSERT/UPDATE/DELETE/MERGE target, else RowShareLock if
1035+
* the RTE is a SELECT FOR UPDATE/FOR SHARE target, else AccessShareLock.
10361036
*
10371037
* Note: in some cases, rule expansion may result in RTEs that are marked
10381038
* with RowExclusiveLock even though they are not the target of the

src/include/nodes/pathnodes.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,11 @@ struct PlannerInfo
268268

269269
/*
270270
* all_result_relids is empty for SELECT, otherwise it contains at least
271-
* parse->resultRelation. For UPDATE/DELETE across an inheritance or
272-
* partitioning tree, the result rel's child relids are added. When using
273-
* multi-level partitioning, intermediate partitioned rels are included.
274-
* leaf_result_relids is similar except that only actual result tables,
275-
* not partitioned tables, are included in it.
271+
* parse->resultRelation. For UPDATE/DELETE/MERGE across an inheritance
272+
* or partitioning tree, the result rel's child relids are added. When
273+
* using multi-level partitioning, intermediate partitioned rels are
274+
* included. leaf_result_relids is similar except that only actual result
275+
* tables, not partitioned tables, are included in it.
276276
*/
277277
Relids all_result_relids; /* set of all result relids */
278278
Relids leaf_result_relids; /* set of all leaf relids */
@@ -2361,10 +2361,10 @@ typedef struct AppendRelInfo
23612361
} AppendRelInfo;
23622362

23632363
/*
2364-
* Information about a row-identity "resjunk" column in UPDATE/DELETE.
2364+
* Information about a row-identity "resjunk" column in UPDATE/DELETE/MERGE.
23652365
*
2366-
* In partitioned UPDATE/DELETE it's important for child partitions to share
2367-
* row-identity columns whenever possible, so as not to chew up too many
2366+
* In partitioned UPDATE/DELETE/MERGE it's important for child partitions to
2367+
* share row-identity columns whenever possible, so as not to chew up too many
23682368
* targetlist columns. We use these structs to track which identity columns
23692369
* have been requested. In the finished plan, each of these will give rise
23702370
* to one resjunk entry in the targetlist of the ModifyTable's subplan node.

src/include/nodes/plannodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef struct PlannedStmt
6666

6767
List *rtable; /* list of RangeTblEntry nodes */
6868

69-
/* rtable indexes of target relations for INSERT/UPDATE/DELETE */
69+
/* rtable indexes of target relations for INSERT/UPDATE/DELETE/MERGE */
7070
List *resultRelations; /* integer list of RT indexes, or NIL */
7171

7272
List *appendRelations; /* list of AppendRelInfo nodes */
@@ -209,7 +209,7 @@ typedef struct ProjectSet
209209
* nominalRelation and rootRelation contain the RT index of the partition
210210
* root, which is not otherwise mentioned in the plan. Otherwise rootRelation
211211
* is zero. However, nominalRelation will always be set, as it's the rel that
212-
* EXPLAIN should claim is the INSERT/UPDATE/DELETE target.
212+
* EXPLAIN should claim is the INSERT/UPDATE/DELETE/MERGE target.
213213
*
214214
* Note that rowMarks and epqParam are presumed to be valid for all the
215215
* table(s); they can't contain any info that varies across tables.

src/include/nodes/primnodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ typedef struct Expr
159159
* is abused to signify references to columns of a custom scan tuple type.)
160160
*
161161
* ROWID_VAR is used in the planner to identify nonce variables that carry
162-
* row identity information during UPDATE/DELETE. This value should never
163-
* be seen outside the planner.
162+
* row identity information during UPDATE/DELETE/MERGE. This value should
163+
* never be seen outside the planner.
164164
*
165165
* In the parser, varnosyn and varattnosyn are either identical to
166166
* varno/varattno, or they specify the column's position in an aliased JOIN

0 commit comments

Comments
 (0)