From 62f8c4dbd5216501ca2762bac9104d19bfec6465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Nordstr=C3=B6m?= Date: Mon, 14 Sep 2020 10:13:29 +0200 Subject: [PATCH] Filter materialized hypertables in view 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 #2383 --- sql/views.sql | 4 +++- tsl/test/expected/continuous_aggs.out | 10 ++++++++++ tsl/test/sql/continuous_aggs.sql | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/sql/views.sql b/sql/views.sql index b4d6187643d..a3c73cc1100 100644 --- a/sql/views.sql +++ b/sql/views.sql @@ -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 @@ -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, diff --git a/tsl/test/expected/continuous_aggs.out b/tsl/test/expected/continuous_aggs.out index bb798ed4204..b51b5f5147b 100644 --- a/tsl/test/expected/continuous_aggs.out +++ b/tsl/test/expected/continuous_aggs.out @@ -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 diff --git a/tsl/test/sql/continuous_aggs.sql b/tsl/test/sql/continuous_aggs.sql index b8c93ec369c..f2fd29542f3 100644 --- a/tsl/test/sql/continuous_aggs.sql +++ b/tsl/test/sql/continuous_aggs.sql @@ -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