* fireRIRrules - * Apply all RIR rules on each rangetable entry in the given query * * activeRIRs is a list of the OIDs of views we're already processing RIR * rules for, used to detect/reject recursion. */
| 2048 | * rules for, used to detect/reject recursion. |
| 2049 | */ |
| 2050 | static Query * |
| 2051 | fireRIRrules(Query *parsetree, List *activeRIRs) |
| 2052 | { |
| 2053 | int origResultRelation = parsetree->resultRelation; |
| 2054 | int rt_index; |
| 2055 | ListCell *lc; |
| 2056 | |
| 2057 | /* |
| 2058 | * Expand SEARCH and CYCLE clauses in CTEs. |
| 2059 | * |
| 2060 | * This is just a convenient place to do this, since we are already |
| 2061 | * looking at each Query. |
| 2062 | */ |
| 2063 | foreach(lc, parsetree->cteList) |
| 2064 | { |
| 2065 | CommonTableExpr *cte = lfirst_node(CommonTableExpr, lc); |
| 2066 | |
| 2067 | if (cte->search_clause || cte->cycle_clause) |
| 2068 | { |
| 2069 | cte = rewriteSearchAndCycle(cte); |
| 2070 | lfirst(lc) = cte; |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | /* |
| 2075 | * don't try to convert this into a foreach loop, because rtable list can |
| 2076 | * get changed each time through... |
| 2077 | */ |
| 2078 | rt_index = 0; |
| 2079 | while (rt_index < list_length(parsetree->rtable)) |
| 2080 | { |
| 2081 | RangeTblEntry *rte; |
| 2082 | Relation rel; |
| 2083 | List *locks; |
| 2084 | RuleLock *rules; |
| 2085 | RewriteRule *rule; |
| 2086 | int i; |
| 2087 | |
| 2088 | ++rt_index; |
| 2089 | |
| 2090 | rte = rt_fetch(rt_index, parsetree->rtable); |
| 2091 | |
| 2092 | /* |
| 2093 | * A subquery RTE can't have associated rules, so there's nothing to |
| 2094 | * do to this level of the query, but we must recurse into the |
| 2095 | * subquery to expand any rule references in it. |
| 2096 | */ |
| 2097 | if (rte->rtekind == RTE_SUBQUERY || rte->rtekind == RTE_TABLEFUNCTION) |
| 2098 | { |
| 2099 | rte->subquery = fireRIRrules(rte->subquery, activeRIRs); |
| 2100 | continue; |
| 2101 | } |
| 2102 | |
| 2103 | /* |
| 2104 | * Joins and other non-relation RTEs can be ignored completely. |
| 2105 | */ |
| 2106 | if (rte->rtekind != RTE_RELATION) |
| 2107 | continue; |
no test coverage detected