Skip to content

Commit 73e7361

Browse files
committed
Restore comments in ChangeVarNodesExtended()
This commit restores comments in ChangeVarNodesExtended(), which were accidentally removed by fc069a3. Reported-by: Richard Guo <[email protected]> Discussion: https://postgr.es/m/CAMbWs49PE3CvnV8vrQ0Dr%3DHqgZZmX0tdNbzVNJxqc8yg-8kDQQ%40mail.gmail.com
1 parent aaf9e95 commit 73e7361

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/backend/rewrite/rewriteManip.c

+14
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,23 @@ ChangeVarNodesExtended(Node *node, int rt_index, int new_index,
758758
context.sublevels_up = sublevels_up;
759759
context.change_RangeTblRef = change_RangeTblRef;
760760

761+
/*
762+
* Must be prepared to start with a Query or a bare expression tree; if
763+
* it's a Query, go straight to query_tree_walker to make sure that
764+
* sublevels_up doesn't get incremented prematurely.
765+
*/
761766
if (node && IsA(node, Query))
762767
{
763768
Query *qry = (Query *) node;
764769

770+
/*
771+
* If we are starting at a Query, and sublevels_up is zero, then we
772+
* must also fix rangetable indexes in the Query itself --- namely
773+
* resultRelation, mergeTargetRelation, exclRelIndex and rowMarks
774+
* entries. sublevels_up cannot be zero when recursing into a
775+
* subquery, so there's no need to have the same logic inside
776+
* ChangeVarNodes_walker.
777+
*/
765778
if (sublevels_up == 0)
766779
{
767780
ListCell *l;
@@ -772,6 +785,7 @@ ChangeVarNodesExtended(Node *node, int rt_index, int new_index,
772785
if (qry->mergeTargetRelation == rt_index)
773786
qry->mergeTargetRelation = new_index;
774787

788+
/* this is unlikely to ever be used, but ... */
775789
if (qry->onConflict && qry->onConflict->exclRelIndex == rt_index)
776790
qry->onConflict->exclRelIndex = new_index;
777791

0 commit comments

Comments
 (0)