Skip to content

Commit f6f991f

Browse files
committed
Merge master (resolve conflicts)
2 parents 98d44c0 + bb30bce commit f6f991f

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

pg_pathman.c

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ static PlannedStmt * pathman_planner_hook(Query *parse, int cursorOptions, Param
7070
static void handle_modification_query(Query *parse);
7171
static Node *wrapper_make_expression(WrapperNode *wrap, int index, bool *alwaysTrue);
7272
static void disable_inheritance(Query *parse);
73+
static void disable_inheritance_cte(Query *parse);
74+
static void disable_inheritance_subselect(Query *parse);
7375

7476
/* Expression tree handlers */
7577
static int make_hash(const PartRelationInfo *prel, int value);
@@ -252,7 +254,6 @@ PlannedStmt *
252254
pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
253255
{
254256
PlannedStmt *result;
255-
ListCell *lc;
256257

257258
if (pg_pathman_enable)
258259
{
@@ -264,20 +265,13 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
264265
break;
265266
case CMD_UPDATE:
266267
case CMD_DELETE:
268+
disable_inheritance_cte(parse);
269+
disable_inheritance_subselect(parse);
267270
handle_modification_query(parse);
268271
break;
269272
default:
270273
break;
271274
}
272-
273-
/* If query contains CTE (WITH statement) then handle subqueries too */
274-
foreach(lc, parse->cteList)
275-
{
276-
CommonTableExpr *cte = (CommonTableExpr*) lfirst(lc);
277-
278-
if (IsA(cte->ctequery, Query))
279-
disable_inheritance((Query *)cte->ctequery);
280-
}
281275
}
282276

283277
/* Invoke original hook */
@@ -296,10 +290,16 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
296290
static void
297291
disable_inheritance(Query *parse)
298292
{
299-
RangeTblEntry *rte;
300-
ListCell *lc;
293+
ListCell *lc;
294+
RangeTblEntry *rte;
301295
PartRelationInfo *prel;
302-
bool found;
296+
bool found;
297+
298+
/* If query contains CTE (WITH statement) then handle subqueries too */
299+
disable_inheritance_cte(parse);
300+
301+
/* If query contains subselects */
302+
disable_inheritance_subselect(parse);
303303

304304
foreach(lc, parse->rtable)
305305
{
@@ -334,6 +334,38 @@ disable_inheritance(Query *parse)
334334
}
335335
}
336336

337+
static void
338+
disable_inheritance_cte(Query *parse)
339+
{
340+
ListCell *lc;
341+
342+
foreach(lc, parse->cteList)
343+
{
344+
CommonTableExpr *cte = (CommonTableExpr*) lfirst(lc);
345+
346+
if (IsA(cte->ctequery, Query))
347+
disable_inheritance((Query *) cte->ctequery);
348+
}
349+
}
350+
351+
static void
352+
disable_inheritance_subselect(Query *parse)
353+
{
354+
Node *quals;
355+
356+
if (!parse->jointree || !parse->jointree->quals)
357+
return;
358+
359+
quals = parse->jointree->quals;
360+
if (!IsA(quals, SubLink))
361+
return;
362+
363+
if (!IsA(((SubLink *) quals)->subselect, Query))
364+
return;
365+
366+
disable_inheritance((Query *) (((SubLink *) quals)->subselect));
367+
}
368+
337369
/*
338370
* Checks if query is affects only one partition. If true then substitute
339371
*/

0 commit comments

Comments
 (0)