1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-29 16:21:20 +03:00

Restore comments in ChangeVarNodesExtended()

This commit restores comments in ChangeVarNodesExtended(), which were
accidentally removed by fc069a3a6319.

Reported-by: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49PE3CvnV8vrQ0Dr%3DHqgZZmX0tdNbzVNJxqc8yg-8kDQQ%40mail.gmail.com
This commit is contained in:
Alexander Korotkov 2025-04-28 11:20:22 +03:00
parent aaf9e95e87
commit 73e7361376

View File

@ -758,10 +758,23 @@ ChangeVarNodesExtended(Node *node, int rt_index, int new_index,
context.sublevels_up = sublevels_up;
context.change_RangeTblRef = change_RangeTblRef;
/*
* Must be prepared to start with a Query or a bare expression tree; if
* it's a Query, go straight to query_tree_walker to make sure that
* sublevels_up doesn't get incremented prematurely.
*/
if (node && IsA(node, Query))
{
Query *qry = (Query *) node;
/*
* If we are starting at a Query, and sublevels_up is zero, then we
* must also fix rangetable indexes in the Query itself --- namely
* resultRelation, mergeTargetRelation, exclRelIndex and rowMarks
* entries. sublevels_up cannot be zero when recursing into a
* subquery, so there's no need to have the same logic inside
* ChangeVarNodes_walker.
*/
if (sublevels_up == 0)
{
ListCell *l;
@ -772,6 +785,7 @@ ChangeVarNodesExtended(Node *node, int rt_index, int new_index,
if (qry->mergeTargetRelation == rt_index)
qry->mergeTargetRelation = new_index;
/* this is unlikely to ever be used, but ... */
if (qry->onConflict && qry->onConflict->exclRelIndex == rt_index)
qry->onConflict->exclRelIndex = new_index;