@@ -51,6 +51,9 @@ typedef struct
5151Oid new_varno ;
5252}change_varno_context ;
5353
54+ bool pg_pathman_enable ;
55+ PathmanState * pmstate ;
56+
5457/* Original hooks */
5558static set_rel_pathlist_hook_type set_rel_pathlist_hook_original = NULL ;
5659static shmem_startup_hook_type shmem_startup_hook_original = NULL ;
@@ -170,6 +173,17 @@ _PG_init(void)
170173pickyappend_exec_methods .RestrPosCustomScan = NULL ;
171174pickyappend_exec_methods .ExplainCustomScan = pickyppend_explain ;
172175
176+ DefineCustomBoolVariable ("pg_pathman.enable" ,
177+ "Enables pg_pathman's optimizations during the planner stage" ,
178+ NULL ,
179+ & pg_pathman_enable ,
180+ true,
181+ PGC_USERSET ,
182+ 0 ,
183+ NULL ,
184+ NULL ,
185+ NULL );
186+
173187DefineCustomBoolVariable ("pg_pathman.enable_pickyappend" ,
174188"Enables the planner's use of PickyAppend custom node." ,
175189NULL ,
@@ -255,27 +269,30 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
255269PlannedStmt * result ;
256270ListCell * lc ;
257271
258- inheritance_disabled = false;
259- switch (parse -> commandType )
272+ if (pg_pathman_enable )
260273{
261- case CMD_SELECT :
262- disable_inheritance (parse );
263- break ;
264- case CMD_UPDATE :
265- case CMD_DELETE :
266- handle_modification_query (parse );
267- break ;
268- default :
269- break ;
270- }
274+ inheritance_disabled = false;
275+ switch (parse -> commandType )
276+ {
277+ case CMD_SELECT :
278+ disable_inheritance (parse );
279+ break ;
280+ case CMD_UPDATE :
281+ case CMD_DELETE :
282+ handle_modification_query (parse );
283+ break ;
284+ default :
285+ break ;
286+ }
271287
272- /* If query contains CTE (WITH statement) then handle subqueries too */
273- foreach (lc ,parse -> cteList )
274- {
275- CommonTableExpr * cte = (CommonTableExpr * )lfirst (lc );
288+ /* If query contains CTE (WITH statement) then handle subqueries too */
289+ foreach (lc ,parse -> cteList )
290+ {
291+ CommonTableExpr * cte = (CommonTableExpr * )lfirst (lc );
276292
277- if (IsA (cte -> ctequery ,Query ))
278- disable_inheritance ((Query * )cte -> ctequery );
293+ if (IsA (cte -> ctequery ,Query ))
294+ disable_inheritance ((Query * )cte -> ctequery );
295+ }
279296}
280297
281298/* Invoke original hook */
@@ -411,6 +428,9 @@ pathman_set_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, Ran
411428bool found ;
412429int first_child_relid = 0 ;
413430
431+ if (!pg_pathman_enable )
432+ return ;
433+
414434/* This works only for SELECT queries */
415435if (root -> parse -> commandType != CMD_SELECT || !inheritance_disabled )
416436return ;