Fix segfault creating cagg with NULL bucket width

When creating a Continuous Aggregate using a NULL `bucket_width` in the
`time_bucket` function it lead to a segfault, for example:

CREATE MATERIALIZED VIEW cagg WITH (timescaledb.continuous) AS
SELECT time_bucket(NULL, time), count(*)
FROM metrics
GROUP BY 1;

Fixed it by raising an ERROR if a NULL `bucked_width` is used during the
Continuous Aggregate query validation.
This commit is contained in:
Fabrízio de Royes Mello 2023-11-08 17:30:09 -03:00
parent b423d14ef5
commit d0021d5f38
4 changed files with 22 additions and 0 deletions

1
.unreleased/pr_6297 Normal file
View File

@ -0,0 +1 @@
Fixes: #6297 Fix segfault when creating a cagg using a NULL width in time bucket function

View File

@ -319,6 +319,11 @@ caggtimebucket_validate(CAggTimebucketInfo *tbinfo, List *groupClause, List *tar
Const *width = castNode(Const, width_arg);
tbinfo->bucket_width_type = width->consttype;
if (width->constisnull)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid bucket width for time bucket function")));
if (width->consttype == INTERVALOID)
{
tbinfo->interval = DatumGetIntervalP(width->constvalue);

View File

@ -256,6 +256,14 @@ SELECT time_bucket('1 week', timec)
GROUP BY time_bucket('1 week', timec);
ERROR: cannot create continuous aggregate with CREATE VIEW
HINT: Use CREATE MATERIALIZED VIEW to create a continuous aggregate.
-- invalid `bucket_width` for `time_bucket` function
CREATE MATERIALIZED VIEW mat_m1 WITH (timescaledb.continuous, timescaledb.materialized_only=false)
AS
SELECT time_bucket(NULL, timec), sum(temperature), min(location)
FROM conditions
GROUP BY 1
WITH NO DATA;
ERROR: invalid bucket width for time bucket function
-- row security on table
create table rowsec_tab( a bigint, b integer, c integer);
select table_name from create_hypertable( 'rowsec_tab', 'a', chunk_time_interval=>10);

View File

@ -236,6 +236,14 @@ SELECT time_bucket('1 week', timec)
FROM conditions
GROUP BY time_bucket('1 week', timec);
-- invalid `bucket_width` for `time_bucket` function
CREATE MATERIALIZED VIEW mat_m1 WITH (timescaledb.continuous, timescaledb.materialized_only=false)
AS
SELECT time_bucket(NULL, timec), sum(temperature), min(location)
FROM conditions
GROUP BY 1
WITH NO DATA;
-- row security on table
create table rowsec_tab( a bigint, b integer, c integer);
select table_name from create_hypertable( 'rowsec_tab', 'a', chunk_time_interval=>10);