@@ -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 */
@@ -240,7 +242,6 @@ PlannedStmt *
240
242
pathman_planner_hook (Query * parse ,int cursorOptions ,ParamListInfo boundParams )
241
243
{
242
244
PlannedStmt * result ;
243
- ListCell * lc ;
244
245
245
246
if (pg_pathman_enable )
246
247
{
@@ -252,20 +253,13 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
252
253
break ;
253
254
case CMD_UPDATE :
254
255
case CMD_DELETE :
256
+ disable_inheritance_cte (parse );
257
+ disable_inheritance_subselect (parse );
255
258
handle_modification_query (parse );
256
259
break ;
257
260
default :
258
261
break ;
259
262
}
260
-
261
- /* If query contains CTE (WITH statement) then handle subqueries too */
262
- foreach (lc ,parse -> cteList )
263
- {
264
- CommonTableExpr * cte = (CommonTableExpr * )lfirst (lc );
265
-
266
- if (IsA (cte -> ctequery ,Query ))
267
- disable_inheritance ((Query * )cte -> ctequery );
268
- }
269
263
}
270
264
271
265
/* Invoke original hook */
@@ -284,10 +278,16 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
284
278
static void
285
279
disable_inheritance (Query * parse )
286
280
{
287
- RangeTblEntry * rte ;
288
- ListCell * lc ;
281
+ ListCell * lc ;
282
+ RangeTblEntry * rte ;
289
283
PartRelationInfo * prel ;
290
- bool found ;
284
+ bool found ;
285
+
286
+ /* If query contains CTE (WITH statement) then handle subqueries too */
287
+ disable_inheritance_cte (parse );
288
+
289
+ /* If query contains subselects */
290
+ disable_inheritance_subselect (parse );
291
291
292
292
foreach (lc ,parse -> rtable )
293
293
{
@@ -322,6 +322,35 @@ disable_inheritance(Query *parse)
322
322
}
323
323
}
324
324
325
+ static void
326
+ disable_inheritance_cte (Query * parse )
327
+ {
328
+ ListCell * lc ;
329
+
330
+ foreach (lc ,parse -> cteList )
331
+ {
332
+ CommonTableExpr * cte = (CommonTableExpr * )lfirst (lc );
333
+
334
+ if (IsA (cte -> ctequery ,Query ))
335
+ disable_inheritance ((Query * )cte -> ctequery );
336
+ }
337
+ }
338
+
339
+ static void
340
+ disable_inheritance_subselect (Query * parse )
341
+ {
342
+ SubLink * sublink ;
343
+
344
+ if (!parse -> jointree || !parse -> jointree -> quals )
345
+ return ;
346
+
347
+ sublink = (SubLink * )parse -> jointree -> quals ;
348
+ if (!IsA (sublink -> subselect ,Query ))
349
+ return ;
350
+
351
+ disable_inheritance ((Query * )sublink -> subselect );
352
+ }
353
+
325
354
/*
326
355
* Checks if query is affects only one partition. If true then substitute
327
356
*/