diff --git a/tsl/src/continuous_aggs/common.c b/tsl/src/continuous_aggs/common.c index 4efe494a078..bda7ad1bc57 100644 --- a/tsl/src/continuous_aggs/common.c +++ b/tsl/src/continuous_aggs/common.c @@ -256,20 +256,31 @@ caggtimebucket_validate(CAggTimebucketInfo *tbinfo, List *groupClause, List *tar continue; } - /* Do we have a bucketing function that is not allowed in the CAgg definition */ + /* Do we have a bucketing function that is not allowed in the CAgg definition? + * + * This is only validated upon creation. If an older TSDB version has allowed us to use + * the function and it's now removed from the list of allowed functions, we should not + * error out (e.g., materialized_only setting is changed on a CAgg that uses the + * deprecated time_bucket_ng function). */ if (!function_allowed_in_cagg_definition(fe->funcid)) { if (IS_DEPRECATED_BUCKET_FUNC(finfo)) { - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("experimental bucket functions are not supported inside a CAgg " - "definition"), - errhint("Use a function from the %s schema instead.", - FUNCTIONS_SCHEMA_NAME))); + if (is_cagg_create) + { + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("experimental bucket functions are not supported inside a " + "CAgg " + "definition"), + errhint("Use a function from the %s schema instead.", + FUNCTIONS_SCHEMA_NAME))); + } + } + else + { + continue; } - - continue; } if (found) diff --git a/tsl/src/continuous_aggs/create.c b/tsl/src/continuous_aggs/create.c index a7e2183fe0b..0b36fbdd7d0 100644 --- a/tsl/src/continuous_aggs/create.c +++ b/tsl/src/continuous_aggs/create.c @@ -1026,7 +1026,7 @@ cagg_flip_realtime_view_definition(ContinuousAgg *agg, Hypertable *mat_ht) agg->data.finalized, NameStr(agg->data.user_view_schema), NameStr(agg->data.user_view_name), - true); + false); /* Flip */ agg->data.materialized_only = !agg->data.materialized_only; diff --git a/tsl/src/continuous_aggs/repair.c b/tsl/src/continuous_aggs/repair.c index 0c355e9379f..400bdb979c0 100644 --- a/tsl/src/continuous_aggs/repair.c +++ b/tsl/src/continuous_aggs/repair.c @@ -130,7 +130,7 @@ cagg_rebuild_view_definition(ContinuousAgg *agg, Hypertable *mat_ht, bool force_ finalized, NameStr(agg->data.user_view_schema), NameStr(agg->data.user_view_name), - true); + false); mattablecolumninfo_init(&mattblinfo, copyObject(direct_query->groupClause)); fqi.finalized = finalized; diff --git a/tsl/test/expected/exp_cagg_next_gen.out b/tsl/test/expected/exp_cagg_next_gen.out index ff758c51af7..32dc2be3487 100644 --- a/tsl/test/expected/exp_cagg_next_gen.out +++ b/tsl/test/expected/exp_cagg_next_gen.out @@ -196,5 +196,8 @@ FROM _timescaledb_catalog.continuous_aggs_bucket_function ORDER BY 1; timescaledb_experimental.time_bucket_ng(interval,timestamp without time zone) | @ 1 mon | | | f (2 rows) +-- Try to toggle realtime feature on existing CAgg using timescaledb_experimental.time_bucket_ng +ALTER MATERIALIZED VIEW conditions_summary_monthly SET (timescaledb.materialized_only=false); +ALTER MATERIALIZED VIEW conditions_summary_monthly SET (timescaledb.materialized_only=true); \c :TEST_DBNAME :ROLE_SUPERUSER DROP DATABASE test WITH (FORCE); diff --git a/tsl/test/sql/exp_cagg_next_gen.sql b/tsl/test/sql/exp_cagg_next_gen.sql index bf4396b7c91..769e9729dda 100644 --- a/tsl/test/sql/exp_cagg_next_gen.sql +++ b/tsl/test/sql/exp_cagg_next_gen.sql @@ -163,5 +163,9 @@ WITH NO DATA; SELECT bucket_func, bucket_width, bucket_origin, bucket_timezone, bucket_fixed_width FROM _timescaledb_catalog.continuous_aggs_bucket_function ORDER BY 1; +-- Try to toggle realtime feature on existing CAgg using timescaledb_experimental.time_bucket_ng +ALTER MATERIALIZED VIEW conditions_summary_monthly SET (timescaledb.materialized_only=false); +ALTER MATERIALIZED VIEW conditions_summary_monthly SET (timescaledb.materialized_only=true); + \c :TEST_DBNAME :ROLE_SUPERUSER DROP DATABASE test WITH (FORCE);