diff --git a/tsl/src/continuous_aggs/materialize.c b/tsl/src/continuous_aggs/materialize.c index 3fe6e0434bd..40ed1524201 100644 --- a/tsl/src/continuous_aggs/materialize.c +++ b/tsl/src/continuous_aggs/materialize.c @@ -3,7 +3,6 @@ * Please see the included NOTICE for copyright information and * LICENSE-TIMESCALE for a copy of the license. */ -#include #include #include #include @@ -20,6 +19,7 @@ #include #include +#include "compat/compat.h" #include "debug_assert.h" #include "guc.h" #include "materialize.h" @@ -770,11 +770,15 @@ execute_materializations(MaterializationContext *context) rows_processed += execute_materialization_plan(context, PLAN_TYPE_DELETE); rows_processed += execute_materialization_plan(context, PLAN_TYPE_INSERT); } + + /* Free all cached plans */ + free_materialization_plans(context); } - PG_FINALLY(); + PG_CATCH(); { /* Make sure all cached plans in the session be released before rethrowing the error */ free_materialization_plans(context); + PG_RE_THROW(); } PG_END_TRY();