@@ -70,6 +70,8 @@ static PlannedStmt * pathman_planner_hook(Query *parse, int cursorOptions, Param
70
70
static void handle_modification_query (Query * parse );
71
71
static Node * wrapper_make_expression (WrapperNode * wrap ,int index ,bool * alwaysTrue );
72
72
static void disable_inheritance (Query * parse );
73
+ static void disable_inheritance_cte (Query * parse );
74
+ static void disable_inheritance_subselect (Query * parse );
73
75
74
76
/* Expression tree handlers */
75
77
static int make_hash (const PartRelationInfo * prel ,int value );
@@ -252,7 +254,6 @@ PlannedStmt *
252
254
pathman_planner_hook (Query * parse ,int cursorOptions ,ParamListInfo boundParams )
253
255
{
254
256
PlannedStmt * result ;
255
- ListCell * lc ;
256
257
257
258
if (pg_pathman_enable )
258
259
{
@@ -264,20 +265,13 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
264
265
break ;
265
266
case CMD_UPDATE :
266
267
case CMD_DELETE :
268
+ disable_inheritance_cte (parse );
269
+ disable_inheritance_subselect (parse );
267
270
handle_modification_query (parse );
268
271
break ;
269
272
default :
270
273
break ;
271
274
}
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
- }
281
275
}
282
276
283
277
/* Invoke original hook */
@@ -296,10 +290,16 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
296
290
static void
297
291
disable_inheritance (Query * parse )
298
292
{
299
- RangeTblEntry * rte ;
300
- ListCell * lc ;
293
+ ListCell * lc ;
294
+ RangeTblEntry * rte ;
301
295
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 );
303
303
304
304
foreach (lc ,parse -> rtable )
305
305
{
@@ -334,6 +334,38 @@ disable_inheritance(Query *parse)
334
334
}
335
335
}
336
336
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
+
337
369
/*
338
370
* Checks if query is affects only one partition. If true then substitute
339
371
*/