@@ -468,10 +468,11 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
468468
469469PlannedStmt * result ;
470470uint32 query_id = parse -> queryId ;
471+ bool pathman_ready = IsPathmanReady ();/* in case it changes */
471472
472473PG_TRY ();
473474{
474- if (IsPathmanReady () )
475+ if (pathman_ready )
475476{
476477/* Increment parenthood_statuses refcount */
477478incr_refcount_parenthood_statuses ();
@@ -486,7 +487,7 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
486487else
487488result = standard_planner (parse ,cursorOptions ,boundParams );
488489
489- if (IsPathmanReady () )
490+ if (pathman_ready )
490491{
491492/* Give rowmark-related attributes correct names */
492493ExecuteForPlanTree (result ,postprocess_lock_rows );
@@ -504,9 +505,13 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
504505/* We must decrease parenthood statuses refcount on ERROR */
505506PG_CATCH ();
506507{
507- /* Caught an ERROR, decrease refcount */
508- decr_refcount_parenthood_statuses ();
508+ if (pathman_ready )
509+ {
510+ /* Caught an ERROR, decrease refcount */
511+ decr_refcount_parenthood_statuses ();
512+ }
509513
514+ /* Rethrow ERROR further */
510515PG_RE_THROW ();
511516}
512517PG_END_TRY ();