Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict creation of partial cagg #6056

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .unreleased/PR_6056
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implements: #6056 Restrict creation of partial cagg
12 changes: 12 additions & 0 deletions src/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ bool ts_guc_enable_async_append = true;
TSDLLEXPORT bool ts_guc_enable_compression_indexscan = true;
TSDLLEXPORT bool ts_guc_enable_bulk_decompression = true;
TSDLLEXPORT bool ts_guc_enable_skip_scan = true;
TSDLLEXPORT bool ts_guc_block_old_format_cagg = true;
/* default value of ts_guc_max_open_chunks_per_insert and ts_guc_max_cached_chunks_per_hypertable
* will be set as their respective boot-value when the GUC mechanism starts up */
int ts_guc_max_open_chunks_per_insert;
Expand Down Expand Up @@ -476,6 +477,17 @@ _guc_init(void)
NULL,
NULL);

DefineCustomBoolVariable("timescaledb.block_old_format_cagg",
"Block creation of old format continuous aggregate",
"Disable creation of continuous aggregate with partials",
&ts_guc_block_old_format_cagg,
true,
PGC_USERSET,
0,
NULL,
NULL,
NULL);

DefineCustomIntVariable("timescaledb.max_insert_batch_size",
"The max number of tuples to batch before sending to a data node",
"When acting as a access node, TimescaleDB splits batches of "
Expand Down
1 change: 1 addition & 0 deletions src/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern TSDLLEXPORT bool ts_guc_enable_per_data_node_queries;
extern TSDLLEXPORT bool ts_guc_enable_parameterized_data_node_scan;
extern TSDLLEXPORT bool ts_guc_enable_async_append;
extern TSDLLEXPORT bool ts_guc_enable_skip_scan;
extern TSDLLEXPORT bool ts_guc_block_old_format_cagg;
extern bool ts_guc_restoring;
extern int ts_guc_max_open_chunks_per_insert;
extern int ts_guc_max_cached_chunks_per_hypertable;
Expand Down
3 changes: 3 additions & 0 deletions test/sql/updates/setup.continuous_aggs.v2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ SELECT generate_series('2018-11-01 00:00'::timestamp, '2018-12-31 00:00'::timest
INSERT INTO conditions_before
SELECT generate_series('2018-11-01 00:00'::timestamp, '2018-12-15 00:00'::timestamp, '1 day'), 'LA', 73, 55, NULL, 28, NULL, NULL, 8, true;

-- Aggregates with partials are supported under a custom boolean flag
SET timescaledb.block_old_format_cagg TO OFF;

\if :has_refresh_mat_view
CREATE VIEW rename_cols
WITH (timescaledb.continuous, timescaledb.materialized_only = false, timescaledb.refresh_lag='14 days') AS
Expand Down
15 changes: 5 additions & 10 deletions tsl/src/continuous_aggs/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "common.h"
#include "guc.h"

static Const *check_time_bucket_argument(Node *arg, char *position);
static void caggtimebucketinfo_init(CAggTimebucketInfo *src, int32 hypertable_id,
Expand Down Expand Up @@ -419,14 +420,10 @@ cagg_agg_validate(Node *node, void *context)
static bool
cagg_query_supported(const Query *query, StringInfo hint, StringInfo detail, const bool finalized)
{
/*
* For now deprecate partial aggregates on release builds only.
* Once migration tests are made compatible with PG15 enable deprecation
* on debug builds as well.
*/
#ifndef DEBUG
#if PG15_GE
if (!finalized)
/*
* Deprecate partial aggregates to support only finalized aggregates.
*/
if (!finalized && ts_guc_block_old_format_cagg)
{
/* continuous aggregates with old format will not be allowed */
appendStringInfoString(detail,
Expand All @@ -436,8 +433,6 @@ cagg_query_supported(const Query *query, StringInfo hint, StringInfo detail, con
"to true.");
return false;
}
#endif
#endif
if (!query->jointree->fromlist)
{
appendStringInfoString(hint, "FROM clause missing in the query");
Expand Down
10 changes: 9 additions & 1 deletion tsl/src/continuous_aggs/repair.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ cagg_rebuild_view_definition(ContinuousAgg *agg, Hypertable *mat_ht, bool force_
int sec_ctx;
Oid uid, saved_uid;

bool finalized = ContinuousAggIsFinalized(agg);
if (!finalized)
{
ereport(WARNING,
(errmsg("Continuous Aggregates with partials is not supported anymore."),
errdetail("Migrate Continuous Aggregate to finalized form")));
return;
}

/* Cagg view created by the user. */
Oid user_view_oid = relation_oid(&agg->data.user_view_schema, &agg->data.user_view_name);
Relation user_view_rel = relation_open(user_view_oid, AccessShareLock);
Query *user_query = get_view_query(user_view_rel);

bool finalized = ContinuousAggIsFinalized(agg);
bool rebuild_cagg_with_joins = false;

/* Extract final query from user view query. */
Expand Down
2 changes: 2 additions & 0 deletions tsl/test/expected/cagg_errors_deprecated.out
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ select table_name from create_hypertable( 'conditions', 'timec');
conditions
(1 row)

-- Continuous aggregates with partials are supported under a custom boolean flag.
SET timescaledb.block_old_format_cagg TO OFF;
CREATE MATERIALIZED VIEW mat_m1 WITH (timescaledb.continuous, timescaledb.finalized = false, timescaledb.myfill = 1)
as
select location , min(temperature)
Expand Down
2 changes: 2 additions & 0 deletions tsl/test/expected/cagg_joins.out
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,8 @@ ERROR: invalid continuous aggregate view
DETAIL: Unsupported expression in join clause.
HINT: Only equality conditions are supported in continuous aggregates.
--With old format cagg definition
-- Continuous aggregates with partials are supported under a custom boolean flag.
SET timescaledb.block_old_format_cagg TO OFF;
CREATE MATERIALIZED VIEW cagg_cagg_old
WITH (timescaledb.continuous, timescaledb.materialized_only = TRUE, timescaledb.finalized = FALSE) AS
SELECT time_bucket(INTERVAL '1 day', day) AS bucket,
Expand Down
Loading
Loading