|
8 | 8 | * ------------------------------------------------------------------------
|
9 | 9 | */
|
10 | 10 |
|
| 11 | +#include "compat/expand_rte_hook.h" |
11 | 12 | #include "compat/relation_tags.h"
|
12 | 13 | #include "compat/rowmarks_fix.h"
|
13 | 14 |
|
@@ -180,19 +181,31 @@ pathman_transform_query_walker(Node *node, void *context)
|
180 | 181 | static void
|
181 | 182 | disable_standard_inheritance(Query *parse)
|
182 | 183 | {
|
183 |
| - ListCell *lc; |
| 184 | + ListCell *lc; |
| 185 | + Index current_rti; /* current range table entry index */ |
184 | 186 |
|
185 |
| - /* Exit if it's not a SELECT query */ |
| 187 | +/* |
| 188 | + * We can't handle non-SELECT queries unless |
| 189 | + * there's a pathman_expand_inherited_rtentry_hook() |
| 190 | + */ |
| 191 | +#ifndef NATIVE_EXPAND_RTE_HOOK |
186 | 192 | if (parse->commandType != CMD_SELECT)
|
187 | 193 | return;
|
| 194 | +#endif |
188 | 195 |
|
189 | 196 | /* Walk through RangeTblEntries list */
|
| 197 | + current_rti = 0; |
190 | 198 | foreach (lc, parse->rtable)
|
191 | 199 | {
|
192 | 200 | RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
|
193 | 201 |
|
194 |
| - /* Operate only on simple (non-join etc) relations */ |
195 |
| - if (rte->rtekind != RTE_RELATION || rte->relkind != RELKIND_RELATION) |
| 202 | + current_rti++; /* increment RTE index */ |
| 203 | + Assert(current_rti != 0); |
| 204 | + |
| 205 | + /* Process only non-result base relations */ |
| 206 | + if (rte->rtekind != RTE_RELATION || |
| 207 | + rte->relkind != RELKIND_RELATION || |
| 208 | + parse->resultRelation == current_rti) /* is it a result relation? */ |
196 | 209 | continue;
|
197 | 210 |
|
198 | 211 | /* Table may be partitioned */
|
|
0 commit comments