Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3b2db22

Browse filesBrowse 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
Copy full SHA for 3b2db22

File tree

Expand file treeCollapse file tree

14 files changed

+42
-34
lines changed
Filter options
Expand file treeCollapse file tree

14 files changed

+42
-34
lines changed

‎src/backend/optimizer/path/indxpath.c

Copy file name to clipboardExpand all lines: src/backend/optimizer/path/indxpath.c
+7-6Lines 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

Copy file name to clipboardExpand all lines: src/backend/optimizer/plan/planmain.c
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/backend/optimizer/plan/planner.c
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/backend/optimizer/util/appendinfo.c
+3-3Lines 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

Copy file name to clipboardExpand all lines: src/backend/optimizer/util/inherit.c
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/backend/optimizer/util/pathnode.c
+2-1Lines 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
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

Copy file name to clipboardExpand all lines: src/backend/optimizer/util/relnode.c
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/backend/parser/parse_clause.c
+4-2Lines 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

Copy file name to clipboardExpand all lines: src/backend/parser/parse_expr.c
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/backend/parser/parse_merge.c
+5-1Lines 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

Copy file name to clipboardExpand all lines: src/include/nodes/parsenodes.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,8 +1043,8 @@ typedef struct RangeTblEntry
10431043
*
10441044
* rellockmode is really LOCKMODE, but it's declared int to avoid having
10451045
* to include lock-related headers here. It must be RowExclusiveLock if
1046-
* the RTE is an INSERT/UPDATE/DELETE target, else RowShareLock if the RTE
1047-
* is a SELECT FOR UPDATE/FOR SHARE target, else AccessShareLock.
1046+
* the RTE is an INSERT/UPDATE/DELETE/MERGE target, else RowShareLock if
1047+
* the RTE is a SELECT FOR UPDATE/FOR SHARE target, else AccessShareLock.
10481048
*
10491049
* Note: in some cases, rule expansion may result in RTEs that are marked
10501050
* with RowExclusiveLock even though they are not the target of the

‎src/include/nodes/pathnodes.h

Copy file name to clipboardExpand all lines: src/include/nodes/pathnodes.h
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ struct PlannerInfo
328328

329329
/*
330330
* all_result_relids is empty for SELECT, otherwise it contains at least
331-
* parse->resultRelation. For UPDATE/DELETE across an inheritance or
332-
* partitioning tree, the result rel's child relids are added. When using
333-
* multi-level partitioning, intermediate partitioned rels are included.
334-
* leaf_result_relids is similar except that only actual result tables,
335-
* not partitioned tables, are included in it.
331+
* parse->resultRelation. For UPDATE/DELETE/MERGE across an inheritance
332+
* or partitioning tree, the result rel's child relids are added. When
333+
* using multi-level partitioning, intermediate partitioned rels are
334+
* included. leaf_result_relids is similar except that only actual result
335+
* tables, not partitioned tables, are included in it.
336336
*/
337337
/* set of all result relids */
338338
Relids all_result_relids;
@@ -2792,10 +2792,10 @@ typedef struct AppendRelInfo
27922792
} AppendRelInfo;
27932793

27942794
/*
2795-
* Information about a row-identity "resjunk" column in UPDATE/DELETE.
2795+
* Information about a row-identity "resjunk" column in UPDATE/DELETE/MERGE.
27962796
*
2797-
* In partitioned UPDATE/DELETE it's important for child partitions to share
2798-
* row-identity columns whenever possible, so as not to chew up too many
2797+
* In partitioned UPDATE/DELETE/MERGE it's important for child partitions to
2798+
* share row-identity columns whenever possible, so as not to chew up too many
27992799
* targetlist columns. We use these structs to track which identity columns
28002800
* have been requested. In the finished plan, each of these will give rise
28012801
* to one resjunk entry in the targetlist of the ModifyTable's subplan node.

‎src/include/nodes/plannodes.h

Copy file name to clipboardExpand all lines: src/include/nodes/plannodes.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ typedef struct PlannedStmt
7272

7373
List *rtable; /* list of RangeTblEntry nodes */
7474

75-
/* rtable indexes of target relations for INSERT/UPDATE/DELETE */
75+
/* rtable indexes of target relations for INSERT/UPDATE/DELETE/MERGE */
7676
List *resultRelations; /* integer list of RT indexes, or NIL */
7777

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

‎src/include/nodes/primnodes.h

Copy file name to clipboardExpand all lines: src/include/nodes/primnodes.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ typedef struct Expr
177177
* is abused to signify references to columns of a custom scan tuple type.)
178178
*
179179
* ROWID_VAR is used in the planner to identify nonce variables that carry
180-
* row identity information during UPDATE/DELETE. This value should never
181-
* be seen outside the planner.
180+
* row identity information during UPDATE/DELETE/MERGE. This value should
181+
* never be seen outside the planner.
182182
*
183183
* In the parser, varnosyn and varattnosyn are either identical to
184184
* varno/varattno, or they specify the column's position in an aliased JOIN

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.