Skip to content

Commit

Permalink
Filter materialized hypertables in view
Browse files Browse the repository at this point in the history
This change filters materialized hypertables from the hypertables
view, similar to how internal compression hypertables are
filtered.

Materialized hypertables are internal objects created as a side effect
of creating a continuous aggregate, and these internal hypertables are
still listed in the continuous_aggregates view.

Fixes timescale#2382
  • Loading branch information
erimatnor committed Sep 14, 2020
1 parent 0d8fc61 commit dcee9ff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sql/views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ CREATE OR REPLACE VIEW timescaledb_information.hypertables AS
INNER JOIN pg_tables t
ON ht.table_name=t.tablename
AND ht.schema_name=t.schemaname
LEFT OUTER JOIN _timescaledb_catalog.continuous_agg ca
ON ca.mat_hypertable_id=ht.id
LEFT OUTER JOIN (
SELECT hypertable_id,
array_agg(tablespace_name ORDER BY id) as tablespace_list
Expand All @@ -38,7 +40,7 @@ CREATE OR REPLACE VIEW timescaledb_information.hypertables AS
GROUP BY hypertable_id) dn
ON ht.id = dn.hypertable_id
WHERE ht.compressed is false --> no internal compression tables
;
AND ca.mat_hypertable_id IS NULL;

CREATE OR REPLACE VIEW timescaledb_information.license AS
SELECT _timescaledb_internal.license_edition() as edition,
Expand Down
10 changes: 10 additions & 0 deletions tsl/test/expected/continuous_aggs.out
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ FROM _timescaledb_catalog.continuous_agg ca
INNER JOIN _timescaledb_catalog.hypertable h ON(h.id = ca.mat_hypertable_id)
WHERE user_view_name = 'mat_m1'
\gset
-- Materialized hypertable for mat_m1 should not be visible in the
-- hypertables view:
SELECT table_schema, table_name
FROM timescaledb_information.hypertables;
table_schema | table_name
--------------+------------
public | foo
public | conditions
(2 rows)

SET ROLE :ROLE_SUPERUSER;
insert into :"MAT_SCHEMA_NAME".:"MAT_TABLE_NAME"
select
Expand Down
5 changes: 5 additions & 0 deletions tsl/test/sql/continuous_aggs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ INNER JOIN _timescaledb_catalog.hypertable h ON(h.id = ca.mat_hypertable_id)
WHERE user_view_name = 'mat_m1'
\gset

-- Materialized hypertable for mat_m1 should not be visible in the
-- hypertables view:
SELECT table_schema, table_name
FROM timescaledb_information.hypertables;

SET ROLE :ROLE_SUPERUSER;
insert into :"MAT_SCHEMA_NAME".:"MAT_TABLE_NAME"
select
Expand Down

0 comments on commit dcee9ff

Please sign in to comment.