From bea51df2e00b2bbcc2934af4ab6f05f7fabcb07e Mon Sep 17 00:00:00 2001 From: shhnwz Date: Sun, 26 Feb 2023 22:18:02 +0530 Subject: [PATCH] Fix for inconsistent num_chunks Different num_chunks values reported by timescaledb_information.hypertables and timescaledb_information.chunks. View definition of hypertables was not filtering dropped and osm_chunks. Fixes #5338 (cherry picked from commit e6f6eb3ab8c95b2531401324b97d345ec6fb8ff2) --- CHANGELOG.md | 10 +++ sql/views.sql | 2 +- .../expected/information_view_chunk_count.out | 68 +++++++++++++++++++ tsl/test/sql/CMakeLists.txt | 1 + tsl/test/sql/information_view_chunk_count.sql | 46 +++++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 tsl/test/expected/information_view_chunk_count.out create mode 100644 tsl/test/sql/information_view_chunk_count.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f66e2caa1e..3a4d0bc9b08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ `psql` with the `-X` flag to prevent any `.psqlrc` commands from accidentally triggering the load of a previous DB version.** +## Unreleased + +**Bugfixes** +* #5364 Fix num_chunks inconsistency in hypertables view +* #5336 Use NameData and namestrcpy for names +* #5317 Fix some incorrect memory handling + +**Thanks** +* @Medvecrab for discovering an issue with copying NameData when forming heap tuples. + ## 2.10.0 (2023-02-21) This release contains new features and bug fixes since the 2.9.3 release. diff --git a/sql/views.sql b/sql/views.sql index 7ff2468f153..3142cecac0c 100644 --- a/sql/views.sql +++ b/sql/views.sql @@ -11,7 +11,7 @@ SELECT ht.schema_name AS hypertable_schema, ( SELECT count(1) FROM _timescaledb_catalog.chunk ch - WHERE ch.hypertable_id = ht.id) AS num_chunks, + WHERE ch.hypertable_id = ht.id AND ch.dropped IS FALSE AND ch.osm_chunk IS FALSE) AS num_chunks, ( CASE WHEN compression_state = 1 THEN TRUE diff --git a/tsl/test/expected/information_view_chunk_count.out b/tsl/test/expected/information_view_chunk_count.out new file mode 100644 index 00000000000..25a52ed6534 --- /dev/null +++ b/tsl/test/expected/information_view_chunk_count.out @@ -0,0 +1,68 @@ +-- This file and its contents are licensed under the Timescale License. +-- Please see the included NOTICE for copyright information and +-- LICENSE-TIMESCALE for a copy of the license. +CREATE TABLE sensor_data( +time timestamptz not null, +sensor_id integer not null, +cpu double precision null, +temperature double precision null); +SELECT from create_hypertable('sensor_data','time'); +-- +(1 row) + +INSERT INTO sensor_data +SELECT time + (INTERVAL '1 minute' * random()) AS time, + sensor_id, + random() AS cpu, + random() * 100 AS temperature +FROM + generate_series('2018-03-02 1:00'::TIMESTAMPTZ, '2018-03-28 1:00', '1 hour') AS g1(time), + generate_series(1, 100, 1 ) AS g2(sensor_id) +ORDER BY time; +CREATE materialized VIEW sensor_data_v WITH(timescaledb.continuous) AS +SELECT sensor_id, time_bucket(INTERVAL '1 day', time) AS bucket, +AVG(temperature) FROM sensor_data +GROUP BY sensor_id, bucket; +NOTICE: refreshing continuous aggregate "sensor_data_v" +INSERT INTO sensor_data +SELECT time + (INTERVAL '1 minute' * random()) AS time, + sensor_id, random() AS cpu, random()* 100 AS temperature +FROM + generate_series('2018-03-03 1:00'::TIMESTAMPTZ, '2018-03-31 1:00', '1 hour') AS g1(time), + generate_series(1, 100, 1 ) AS g2(sensor_id) +ORDER BY time; +SELECT count(*) AS num_chunks FROM show_chunks('sensor_data'); + num_chunks +------------ + 5 +(1 row) + +SELECT drop_chunks('sensor_data','2018-03-28'::timestamp); + drop_chunks +---------------------------------------- + _timescaledb_internal._hyper_1_1_chunk + _timescaledb_internal._hyper_1_2_chunk + _timescaledb_internal._hyper_1_3_chunk +(3 rows) + +SELECT count(*) AS num_chunks from timescaledb_information.chunks where hypertable_name = 'sensor_data'; + num_chunks +------------ + 2 +(1 row) + +SELECT num_chunks from timescaledb_information.hypertables where hypertable_name = 'sensor_data'; + num_chunks +------------ + 2 +(1 row) + +SELECT count(*) AS num_chunks FROM show_chunks('sensor_data'); + num_chunks +------------ + 2 +(1 row) + +DROP TABLE sensor_data CASCADE; +NOTICE: drop cascades to 3 other objects +NOTICE: drop cascades to table _timescaledb_internal._hyper_2_5_chunk diff --git a/tsl/test/sql/CMakeLists.txt b/tsl/test/sql/CMakeLists.txt index 63ac4970be7..74c1ec9a286 100644 --- a/tsl/test/sql/CMakeLists.txt +++ b/tsl/test/sql/CMakeLists.txt @@ -86,6 +86,7 @@ if(CMAKE_BUILD_TYPE MATCHES Debug) dist_triggers.sql dist_backup.sql insert_memory_usage.sql + information_view_chunk_count.sql read_only.sql remote_connection_cache.sql remote_connection.sql diff --git a/tsl/test/sql/information_view_chunk_count.sql b/tsl/test/sql/information_view_chunk_count.sql new file mode 100644 index 00000000000..592f31391d7 --- /dev/null +++ b/tsl/test/sql/information_view_chunk_count.sql @@ -0,0 +1,46 @@ +-- This file and its contents are licensed under the Timescale License. +-- Please see the included NOTICE for copyright information and +-- LICENSE-TIMESCALE for a copy of the license. + +CREATE TABLE sensor_data( +time timestamptz not null, +sensor_id integer not null, +cpu double precision null, +temperature double precision null); + +SELECT from create_hypertable('sensor_data','time'); + +INSERT INTO sensor_data +SELECT time + (INTERVAL '1 minute' * random()) AS time, + sensor_id, + random() AS cpu, + random() * 100 AS temperature +FROM + generate_series('2018-03-02 1:00'::TIMESTAMPTZ, '2018-03-28 1:00', '1 hour') AS g1(time), + generate_series(1, 100, 1 ) AS g2(sensor_id) +ORDER BY time; + +CREATE materialized VIEW sensor_data_v WITH(timescaledb.continuous) AS +SELECT sensor_id, time_bucket(INTERVAL '1 day', time) AS bucket, +AVG(temperature) FROM sensor_data +GROUP BY sensor_id, bucket; + +INSERT INTO sensor_data +SELECT time + (INTERVAL '1 minute' * random()) AS time, + sensor_id, random() AS cpu, random()* 100 AS temperature +FROM + generate_series('2018-03-03 1:00'::TIMESTAMPTZ, '2018-03-31 1:00', '1 hour') AS g1(time), + generate_series(1, 100, 1 ) AS g2(sensor_id) +ORDER BY time; + +SELECT count(*) AS num_chunks FROM show_chunks('sensor_data'); + +SELECT drop_chunks('sensor_data','2018-03-28'::timestamp); + +SELECT count(*) AS num_chunks from timescaledb_information.chunks where hypertable_name = 'sensor_data'; + +SELECT num_chunks from timescaledb_information.hypertables where hypertable_name = 'sensor_data'; + +SELECT count(*) AS num_chunks FROM show_chunks('sensor_data'); + +DROP TABLE sensor_data CASCADE;