diff options
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 35bda67b1f1..0508d16902b 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -916,6 +916,12 @@ inheritance_planner(PlannerInfo *root) subplan = grouping_planner(&subroot, 0.0 /* retrieve all tuples */ ); /* + * Planning may have modified the query result relation (if there + * were security barrier quals on the result RTE). + */ + appinfo->child_relid = subroot.parse->resultRelation; + + /* * If this child rel was excluded by constraint exclusion, exclude it * from the result plan. */ @@ -932,9 +938,40 @@ inheritance_planner(PlannerInfo *root) if (final_rtable == NIL) final_rtable = subroot.parse->rtable; else - final_rtable = list_concat(final_rtable, + { + List *tmp_rtable = NIL; + ListCell *cell1, *cell2; + + /* + * Check to see if any of the original RTEs were turned into + * subqueries during planning. Currently, this should only ever + * happen due to securityQuals being involved which push a + * relation down under a subquery, to ensure that the security + * barrier quals are evaluated first. + * + * When this happens, we want to use the new subqueries in the + * final rtable. + */ + forboth(cell1, final_rtable, cell2, subroot.parse->rtable) + { + RangeTblEntry *rte1 = (RangeTblEntry *) lfirst(cell1); + RangeTblEntry *rte2 = (RangeTblEntry *) lfirst(cell2); + + if (rte1->rtekind == RTE_RELATION && + rte2->rtekind == RTE_SUBQUERY) + { + /* Should only be when there are securityQuals today */ + Assert(rte1->securityQuals != NIL); + tmp_rtable = lappend(tmp_rtable, rte2); + } + else + tmp_rtable = lappend(tmp_rtable, rte1); + } + + final_rtable = list_concat(tmp_rtable, list_copy_tail(subroot.parse->rtable, list_length(final_rtable))); + } /* * We need to collect all the RelOptInfos from all child plans into @@ -1163,6 +1200,12 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) tlist = preprocess_targetlist(root, tlist); /* + * Expand any rangetable entries that have security barrier quals. + * This may add new security barrier subquery RTEs to the rangetable. + */ + expand_security_quals(root, tlist); + + /* * Locate any window functions in the tlist. (We don't need to look * anywhere else, since expressions used in ORDER BY will be in there * too.) Note that they could all have been eliminated by constant |