@@ -81,6 +81,8 @@ static int append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
81
81
RangeTblEntry * rte ,int index ,Oid childOID ,List * wrappers );
82
82
static Node * wrapper_make_expression (WrapperNode * wrap ,int index ,bool * alwaysTrue );
83
83
static void disable_inheritance (Query * parse );
84
+ static void disable_inheritance_cte (Query * parse );
85
+ static void disable_inheritance_subselect (Query * parse );
84
86
bool inheritance_disabled ;
85
87
86
88
/* Expression tree handlers */
@@ -254,7 +256,6 @@ PlannedStmt *
254
256
pathman_planner_hook (Query * parse ,int cursorOptions ,ParamListInfo boundParams )
255
257
{
256
258
PlannedStmt * result ;
257
- ListCell * lc ;
258
259
259
260
if (pg_pathman_enable )
260
261
{
@@ -266,20 +267,13 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
266
267
break ;
267
268
case CMD_UPDATE :
268
269
case CMD_DELETE :
270
+ disable_inheritance_cte (parse );
271
+ disable_inheritance_subselect (parse );
269
272
handle_modification_query (parse );
270
273
break ;
271
274
default :
272
275
break ;
273
276
}
274
-
275
- /* If query contains CTE (WITH statement) then handle subqueries too */
276
- foreach (lc ,parse -> cteList )
277
- {
278
- CommonTableExpr * cte = (CommonTableExpr * )lfirst (lc );
279
-
280
- if (IsA (cte -> ctequery ,Query ))
281
- disable_inheritance ((Query * )cte -> ctequery );
282
- }
283
277
}
284
278
285
279
/* Invoke original hook */
@@ -298,10 +292,16 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
298
292
static void
299
293
disable_inheritance (Query * parse )
300
294
{
301
- RangeTblEntry * rte ;
302
- ListCell * lc ;
295
+ ListCell * lc ;
296
+ RangeTblEntry * rte ;
303
297
PartRelationInfo * prel ;
304
- bool found ;
298
+ bool found ;
299
+
300
+ /* If query contains CTE (WITH statement) then handle subqueries too */
301
+ disable_inheritance_cte (parse );
302
+
303
+ /* If query contains subselects */
304
+ disable_inheritance_subselect (parse );
305
305
306
306
foreach (lc ,parse -> rtable )
307
307
{
@@ -336,6 +336,35 @@ disable_inheritance(Query *parse)
336
336
}
337
337
}
338
338
339
+ static void
340
+ disable_inheritance_cte (Query * parse )
341
+ {
342
+ ListCell * lc ;
343
+
344
+ foreach (lc ,parse -> cteList )
345
+ {
346
+ CommonTableExpr * cte = (CommonTableExpr * )lfirst (lc );
347
+
348
+ if (IsA (cte -> ctequery ,Query ))
349
+ disable_inheritance ((Query * )cte -> ctequery );
350
+ }
351
+ }
352
+
353
+ static void
354
+ disable_inheritance_subselect (Query * parse )
355
+ {
356
+ SubLink * sublink ;
357
+
358
+ if (!parse -> jointree || !parse -> jointree -> quals )
359
+ return ;
360
+
361
+ sublink = (SubLink * )parse -> jointree -> quals ;
362
+ if (!IsA (sublink -> subselect ,Query ))
363
+ return ;
364
+
365
+ disable_inheritance ((Query * )sublink -> subselect );
366
+ }
367
+
339
368
/*
340
369
* Checks if query is affects only one partition. If true then substitute
341
370
*/