summaryrefslogtreecommitdiff
path: root/src/backend/rewrite/rewriteHandler.c
diff options
context:
space:
mode:
authorTom Lane2023-06-13 19:58:37 +0000
committerTom Lane2023-06-13 19:58:43 +0000
commit792213f2e9f6d321d5a463f4a0fc263c2b770ac3 (patch)
tree1cc1aa601e1dd8124fef8cca561bc144e0780adc /src/backend/rewrite/rewriteHandler.c
parentb93c63d1972a28ffa3e16c2bc71fd60d82a57f73 (diff)
Correctly update hasSubLinks while mutating a rule action.
rewriteRuleAction neglected to check for SubLink nodes in the securityQuals of range table entries. This could lead to failing to convert such a SubLink to a SubPlan, resulting in assertion crashes or weird errors later in planning. In passing, fix some poor coding in rewriteTargetView: we should not pass the source parsetree's hasSubLinks field to ReplaceVarsFromTargetList's outer_hasSubLinks. ReplaceVarsFromTargetList knows enough to ignore that when a Query node is passed, but it's still confusing and bad precedent: if we did try to update that flag we'd be updating a stale copy of the parsetree. Per bug #17972 from Alexander Lakhin. This has been broken since we added RangeTblEntry.securityQuals (although the presented test case only fails back to 215b43cdc), so back-patch all the way. Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/backend/rewrite/rewriteHandler.c')
-rw-r--r--src/backend/rewrite/rewriteHandler.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c
index 0e4f76efa82..6e724010c04 100644
--- a/src/backend/rewrite/rewriteHandler.c
+++ b/src/backend/rewrite/rewriteHandler.c
@@ -484,6 +484,8 @@ rewriteRuleAction(Query *parsetree,
/* other RTE types don't contain bare expressions */
break;
}
+ sub_action->hasSubLinks |=
+ checkExprHasSubLink((Node *) rte->securityQuals);
if (sub_action->hasSubLinks)
break; /* no need to keep scanning rtable */
}
@@ -3341,7 +3343,7 @@ rewriteTargetView(Query *parsetree, Relation view)
view_targetlist,
REPLACEVARS_REPORT_ERROR,
0,
- &parsetree->hasSubLinks);
+ NULL);
/*
* Update all other RTI references in the query that point to the view