diff options
author | Andres Freund <andres@anarazel.de> | 2015-05-13 00:13:22 +0200 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2015-05-13 00:13:22 +0200 |
commit | 4af6e61a363246cf7fff3368a76603b0ce9945dd (patch) | |
tree | 95812a969e049a62dedc89eb60c96304b81f5a5a /src/backend/rewrite/rewriteManip.c | |
parent | 5c7df74204e2fb9440b576518d40fcf3ac65c8ac (diff) | |
download | postgresql-4af6e61a363246cf7fff3368a76603b0ce9945dd.tar.gz postgresql-4af6e61a363246cf7fff3368a76603b0ce9945dd.zip |
Fix ON CONFLICT bugs that manifest when used in rules.
Specifically the tlist and rti of the pseudo "excluded" relation weren't
properly treated by expression_tree_walker, which lead to errors when
excluded was referenced inside a rule because the varnos where not
properly adjusted. Similar omissions in OffsetVarNodes and
expression_tree_mutator had less impact, but should obviously be fixed
nonetheless.
A couple tests of for ON CONFLICT UPDATE into INSERT rule bearing
relations have been added.
In passing I updated a couple comments.
Diffstat (limited to 'src/backend/rewrite/rewriteManip.c')
-rw-r--r-- | src/backend/rewrite/rewriteManip.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/backend/rewrite/rewriteManip.c b/src/backend/rewrite/rewriteManip.c index df457080fea..a9c6e626ba7 100644 --- a/src/backend/rewrite/rewriteManip.c +++ b/src/backend/rewrite/rewriteManip.c @@ -426,9 +426,9 @@ OffsetVarNodes(Node *node, int offset, int sublevels_up) /* * 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 and rowMarks entries. sublevels_up cannot be zero - * when recursing into a subquery, so there's no need to have the same - * logic inside OffsetVarNodes_walker. + * resultRelation, 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 OffsetVarNodes_walker. */ if (sublevels_up == 0) { @@ -436,6 +436,10 @@ OffsetVarNodes(Node *node, int offset, int sublevels_up) if (qry->resultRelation) qry->resultRelation += offset; + + if (qry->onConflict && qry->onConflict->exclRelIndex) + qry->onConflict->exclRelIndex += offset; + foreach(l, qry->rowMarks) { RowMarkClause *rc = (RowMarkClause *) lfirst(l); @@ -617,6 +621,11 @@ ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up) if (qry->resultRelation == rt_index) qry->resultRelation = new_index; + + /* this is unlikely to ever be used, but ... */ + if (qry->onConflict && qry->onConflict->exclRelIndex == rt_index) + qry->onConflict->exclRelIndex = new_index; + foreach(l, qry->rowMarks) { RowMarkClause *rc = (RowMarkClause *) lfirst(l); |