@@ -468,10 +468,11 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
468
468
469
469
PlannedStmt * result ;
470
470
uint32 query_id = parse -> queryId ;
471
+ bool pathman_ready = IsPathmanReady ();/* in case it changes */
471
472
472
473
PG_TRY ();
473
474
{
474
- if (IsPathmanReady () )
475
+ if (pathman_ready )
475
476
{
476
477
/* Increment parenthood_statuses refcount */
477
478
incr_refcount_parenthood_statuses ();
@@ -486,7 +487,7 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
486
487
else
487
488
result = standard_planner (parse ,cursorOptions ,boundParams );
488
489
489
- if (IsPathmanReady () )
490
+ if (pathman_ready )
490
491
{
491
492
/* Give rowmark-related attributes correct names */
492
493
ExecuteForPlanTree (result ,postprocess_lock_rows );
@@ -504,9 +505,13 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
504
505
/* We must decrease parenthood statuses refcount on ERROR */
505
506
PG_CATCH ();
506
507
{
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
+ }
509
513
514
+ /* Rethrow ERROR further */
510
515
PG_RE_THROW ();
511
516
}
512
517
PG_END_TRY ();