@@ -81,6 +81,8 @@ static int append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
8181RangeTblEntry * rte ,int index ,Oid childOID ,List * wrappers );
8282static Node * wrapper_make_expression (WrapperNode * wrap ,int index ,bool * alwaysTrue );
8383static void disable_inheritance (Query * parse );
84+ static void disable_inheritance_cte (Query * parse );
85+ static void disable_inheritance_subselect (Query * parse );
8486bool inheritance_disabled ;
8587
8688/* Expression tree handlers */
@@ -254,7 +256,6 @@ PlannedStmt *
254256pathman_planner_hook (Query * parse ,int cursorOptions ,ParamListInfo boundParams )
255257{
256258PlannedStmt * result ;
257- ListCell * lc ;
258259
259260if (pg_pathman_enable )
260261{
@@ -266,20 +267,13 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
266267break ;
267268case CMD_UPDATE :
268269case CMD_DELETE :
270+ disable_inheritance_cte (parse );
271+ disable_inheritance_subselect (parse );
269272handle_modification_query (parse );
270273break ;
271274default :
272275break ;
273276}
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- }
283277}
284278
285279/* Invoke original hook */
@@ -298,10 +292,16 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
298292static void
299293disable_inheritance (Query * parse )
300294{
301- RangeTblEntry * rte ;
302- ListCell * lc ;
295+ ListCell * lc ;
296+ RangeTblEntry * rte ;
303297PartRelationInfo * 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 );
305305
306306foreach (lc ,parse -> rtable )
307307{
@@ -336,6 +336,35 @@ disable_inheritance(Query *parse)
336336}
337337}
338338
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+
339368/*
340369 * Checks if query is affects only one partition. If true then substitute
341370 */