Skip to content

Commit

Permalink
Fix option "timescaledb.create_group_indexes"
Browse files Browse the repository at this point in the history
Previously this option was ignored when creating a
continuous aggregate, even when explicitly set to true.

Fixes #4249
  • Loading branch information
konskov committed Apr 20, 2022
1 parent fca865c commit 6ba70c8
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ accidentally triggering the load of a previous DB version.**
**Bugfixes**
* #4225 Fix TRUNCATE error as non-owner on hypertable
* #3899 Fix segfault in Continuous Aggregates
* #4255 Fix option "timescaledb.create_group_indexes"

## 2.6.1 (2022-04-11)
This release is patch release. We recommend that you upgrade at the next available opportunity.
Expand Down
3 changes: 2 additions & 1 deletion tsl/src/continuous_aggs/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -2128,7 +2128,8 @@ cagg_create(const CreateTableAsStmt *create_stmt, ViewStmt *stmt, Query *panquer
ts_catalog_restore_user(&sec_ctx);
PRINT_MATINTERNAL_NAME(relnamebuf, "_materialized_hypertable_%d", materialize_hypertable_id);
mat_rel = makeRangeVar(pstrdup(INTERNAL_SCHEMA_NAME), pstrdup(relnamebuf), -1);
is_create_mattbl_index = with_clause_options[ContinuousViewOptionCreateGroupIndex].is_default;
is_create_mattbl_index =
DatumGetBool(with_clause_options[ContinuousViewOptionCreateGroupIndex].parsed);
mattablecolumninfo_create_materialization_table(&mattblinfo,
materialize_hypertable_id,
mat_rel,
Expand Down
104 changes: 104 additions & 0 deletions tsl/test/expected/continuous_aggs.out
Original file line number Diff line number Diff line change
Expand Up @@ -1738,3 +1738,107 @@ SELECT
--
(0 rows)

-- test that option create_group_indexes is taken into account
SET client_min_messages = ERROR;
CREATE TABLE test_group_idx (
time timestamptz,
symbol int,
value numeric
);
select create_hypertable('test_group_idx', 'time');
create_hypertable
------------------------------
(48,public,test_group_idx,t)
(1 row)

insert into test_group_idx
(select generate_series(
'2020-01-01',
'2020-02-25', INTERVAL '30 sec'
),
round(random()*10),
random()*5);
create materialized view cagg_index_true
with (timescaledb.continuous, timescaledb.create_group_indexes = true) as
select
time_bucket('1 day', "time") as bucket,
sum(value),
symbol
from test_group_idx
group by bucket, symbol;
create materialized view cagg_index_false
with (timescaledb.continuous, timescaledb.create_group_indexes = false) as
select
time_bucket('1 day', "time") as bucket,
sum(value),
symbol
from test_group_idx
group by bucket, symbol;
create materialized view cagg_index_default
with (timescaledb.continuous) as
select
time_bucket('1 day', "time") as bucket,
sum(value),
symbol
from test_group_idx
group by bucket, symbol;
-- make sure a group index has been created when explicitly asked for
SELECT format('%I.%I', materialization_hypertable_schema,
materialization_hypertable_name) AS mat_hyper_cagg_index_true
FROM timescaledb_information.continuous_aggregates where view_name like 'cagg_index_true'
\gset
\d+ :mat_hyper_cagg_index_true
Table "_timescaledb_internal._materialized_hypertable_49"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+--------------------------+-----------+----------+---------+----------+--------------+-------------
bucket | timestamp with time zone | | not null | | plain | |
agg_2_2 | bytea | | | | extended | |
symbol | integer | | | | plain | |
chunk_id | integer | | | | plain | |
Indexes:
"_materialized_hypertable_49_bucket_idx" btree (bucket DESC)
"_materialized_hypertable_49_symbol_bucket_idx" btree (symbol, bucket DESC)
Triggers:
ts_insert_blocker BEFORE INSERT ON _timescaledb_internal._materialized_hypertable_49 FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker()
Child tables: _timescaledb_internal._hyper_49_106_chunk,
_timescaledb_internal._hyper_49_107_chunk

SELECT format('%I.%I', materialization_hypertable_schema,
materialization_hypertable_name) AS mat_hyper_cagg_index_false
FROM timescaledb_information.continuous_aggregates where view_name like 'cagg_index_false'
\gset
\d+ :mat_hyper_cagg_index_false
Table "_timescaledb_internal._materialized_hypertable_50"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+--------------------------+-----------+----------+---------+----------+--------------+-------------
bucket | timestamp with time zone | | not null | | plain | |
agg_2_2 | bytea | | | | extended | |
symbol | integer | | | | plain | |
chunk_id | integer | | | | plain | |
Indexes:
"_materialized_hypertable_50_bucket_idx" btree (bucket DESC)
Triggers:
ts_insert_blocker BEFORE INSERT ON _timescaledb_internal._materialized_hypertable_50 FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker()
Child tables: _timescaledb_internal._hyper_50_108_chunk,
_timescaledb_internal._hyper_50_109_chunk

SELECT format('%I.%I', materialization_hypertable_schema,
materialization_hypertable_name) AS mat_hyper_cagg_index_default
FROM timescaledb_information.continuous_aggregates where view_name like 'cagg_index_default'
\gset
\d+ :mat_hyper_cagg_index_default
Table "_timescaledb_internal._materialized_hypertable_51"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+--------------------------+-----------+----------+---------+----------+--------------+-------------
bucket | timestamp with time zone | | not null | | plain | |
agg_2_2 | bytea | | | | extended | |
symbol | integer | | | | plain | |
chunk_id | integer | | | | plain | |
Indexes:
"_materialized_hypertable_51_bucket_idx" btree (bucket DESC)
"_materialized_hypertable_51_symbol_bucket_idx" btree (symbol, bucket DESC)
Triggers:
ts_insert_blocker BEFORE INSERT ON _timescaledb_internal._materialized_hypertable_51 FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker()
Child tables: _timescaledb_internal._hyper_51_110_chunk,
_timescaledb_internal._hyper_51_111_chunk

68 changes: 68 additions & 0 deletions tsl/test/sql/continuous_aggs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1226,3 +1226,71 @@ FROM issue3248 GROUP BY 1,2;
SELECT
FROM issue3248 AS m,
LATERAL(SELECT m FROM issue3248_cagg WHERE avg IS NULL LIMIT 1) AS lat;

-- test that option create_group_indexes is taken into account
SET client_min_messages = ERROR;

CREATE TABLE test_group_idx (
time timestamptz,
symbol int,
value numeric
);

select create_hypertable('test_group_idx', 'time');

insert into test_group_idx
(select generate_series(
'2020-01-01',
'2020-02-25', INTERVAL '30 sec'
),
round(random()*10),
random()*5);

create materialized view cagg_index_true
with (timescaledb.continuous, timescaledb.create_group_indexes = true) as
select
time_bucket('1 day', "time") as bucket,
sum(value),
symbol
from test_group_idx
group by bucket, symbol;

create materialized view cagg_index_false
with (timescaledb.continuous, timescaledb.create_group_indexes = false) as
select
time_bucket('1 day', "time") as bucket,
sum(value),
symbol
from test_group_idx
group by bucket, symbol;

create materialized view cagg_index_default
with (timescaledb.continuous) as
select
time_bucket('1 day', "time") as bucket,
sum(value),
symbol
from test_group_idx
group by bucket, symbol;

-- make sure a group index has been created when explicitly asked for
SELECT format('%I.%I', materialization_hypertable_schema,
materialization_hypertable_name) AS mat_hyper_cagg_index_true
FROM timescaledb_information.continuous_aggregates where view_name like 'cagg_index_true'
\gset

\d+ :mat_hyper_cagg_index_true

SELECT format('%I.%I', materialization_hypertable_schema,
materialization_hypertable_name) AS mat_hyper_cagg_index_false
FROM timescaledb_information.continuous_aggregates where view_name like 'cagg_index_false'
\gset

\d+ :mat_hyper_cagg_index_false

SELECT format('%I.%I', materialization_hypertable_schema,
materialization_hypertable_name) AS mat_hyper_cagg_index_default
FROM timescaledb_information.continuous_aggregates where view_name like 'cagg_index_default'
\gset

\d+ :mat_hyper_cagg_index_default

0 comments on commit 6ba70c8

Please sign in to comment.