diff --git a/src/chunk.c b/src/chunk.c index c129256a4ea..0c4fa0646b9 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -3960,6 +3960,7 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3 DEBUG_WAITPOINT("drop_chunks_chunks_found"); + int32 osm_chunk_id = ts_chunk_get_osm_chunk_id(ht->fd.id); if (has_continuous_aggs) { /* Exclusively lock all chunks, and invalidate the continuous @@ -3989,6 +3990,11 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3 * therefore be able to refresh accordingly.*/ for (uint64 i = 0; i < num_chunks; i++) { + if (osm_chunk_id == chunks[i].fd.id) + { + // we do not rebuild continuous aggs if tiered data is dropped */ + continue; + } int64 start = ts_chunk_primary_dimension_start(&chunks[i]); int64 end = ts_chunk_primary_dimension_end(&chunks[i]); @@ -4008,8 +4014,11 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3 /* frozen chunks are skipped. Not dropped. */ if (!ts_chunk_validate_chunk_status_for_operation(&chunks[i], CHUNK_DROP, - false /*throw_error */)) + false /*throw_error */) || + osm_chunk_id == chunks[i].fd.id) + { continue; + } /* store chunk name for output */ schema_name = quote_identifier(chunks[i].fd.schema_name.data); @@ -4032,7 +4041,6 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3 } // if we have tiered chunks cascade drop to tiering layer as well #if PG14_GE - int32 osm_chunk_id = ts_chunk_get_osm_chunk_id(ht->fd.id); if (osm_chunk_id != INVALID_CHUNK_ID) { diff --git a/tsl/test/expected/chunk_utils_internal.out b/tsl/test/expected/chunk_utils_internal.out index 4fe4c5c7e18..e1fcc22062c 100644 --- a/tsl/test/expected/chunk_utils_internal.out +++ b/tsl/test/expected/chunk_utils_internal.out @@ -921,23 +921,34 @@ SELECT ts_setup_osm_hook(); (1 row) +BEGIN; SELECT drop_chunks('hyper_constr', 10::int); -NOTICE: hypertable_drop_chunks_hook (-9223372036854775808 10) - drop_chunks -------------- -(0 rows) +NOTICE: hypertable_drop_chunks_hook + drop_chunks +----------------------------- + _timescaledb_internal.dummy +(1 row) + +SELECT id, table_name FROM _timescaledb_catalog.chunk +where hypertable_id = (Select id from _timescaledb_catalog.hypertable where table_name = 'hyper_constr'); + id | table_name +----+-------------------- + 13 | _hyper_7_13_chunk + 14 | child_hyper_constr +(2 rows) +ROLLBACK; CALL run_job(:deljob_id); -NOTICE: hypertable_drop_chunks_hook (-9223372036854775808 400) +NOTICE: hypertable_drop_chunks_hook CALL run_job(:deljob_id); -NOTICE: hypertable_drop_chunks_hook (-9223372036854775808 400) +NOTICE: hypertable_drop_chunks_hook SELECT chunk_name, range_start, range_end FROM chunk_view WHERE hypertable_name = 'hyper_constr' ORDER BY chunk_name; - chunk_name | range_start | range_end ---------------------+---------------------------------------+----------- - child_hyper_constr | Sat Jan 09 20:00:54.775806 294247 PST | infinity + chunk_name | range_start | range_end +--------------------+-----------------------------------+------------------------------------ + child_hyper_constr | Wed Dec 31 16:00:00.0001 1969 PST | Wed Dec 31 16:00:00.00011 1969 PST (1 row) SELECT ts_undo_osm_hook(); @@ -1049,26 +1060,6 @@ SELECT indexname, tablename FROM pg_indexes WHERE indexname = 'hyper_constr_mid_ (1 row) DROP INDEX hyper_constr_mid_idx; ---TEST policy is applied on OSM chunk --- XXX this is to be updated once the hook for dropping chunks is added -CREATE OR REPLACE FUNCTION dummy_now_smallint() RETURNS BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 500::bigint' ; -SELECT set_integer_now_func('hyper_constr', 'dummy_now_smallint'); - set_integer_now_func ----------------------- - -(1 row) - -SELECT add_retention_policy('hyper_constr', 100::int) AS deljob_id \gset -CALL run_job(:deljob_id); -CALL run_job(:deljob_id); -SELECT chunk_name, range_start, range_end -FROM chunk_view -WHERE hypertable_name = 'hyper_constr' -ORDER BY chunk_name; - chunk_name | range_start | range_end -------------+-------------+----------- -(0 rows) - -- test range of dimension slice for osm chunk for different datatypes CREATE TABLE osm_int2(time int2 NOT NULL); CREATE TABLE osm_int4(time int4 NOT NULL); diff --git a/tsl/test/sql/chunk_utils_internal.sql b/tsl/test/sql/chunk_utils_internal.sql index ea8953ec194..59f3c02ce05 100644 --- a/tsl/test/sql/chunk_utils_internal.sql +++ b/tsl/test/sql/chunk_utils_internal.sql @@ -516,7 +516,11 @@ SELECT add_retention_policy('hyper_constr', 100::int) AS deljob_id \gset --add hooks for osm callbacks that are triggered when drop_chunks is invoked--- SELECT ts_setup_osm_hook(); +BEGIN; SELECT drop_chunks('hyper_constr', 10::int); +SELECT id, table_name FROM _timescaledb_catalog.chunk +where hypertable_id = (Select id from _timescaledb_catalog.hypertable where table_name = 'hyper_constr'); +ROLLBACK; CALL run_job(:deljob_id); CALL run_job(:deljob_id); SELECT chunk_name, range_start, range_end @@ -602,20 +606,6 @@ CREATE INDEX hyper_constr_mid_idx ON hyper_constr(mid, time) WITH (timescaledb.t SELECT indexname, tablename FROM pg_indexes WHERE indexname = 'hyper_constr_mid_idx'; DROP INDEX hyper_constr_mid_idx; ---TEST policy is applied on OSM chunk --- XXX this is to be updated once the hook for dropping chunks is added -CREATE OR REPLACE FUNCTION dummy_now_smallint() RETURNS BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 500::bigint' ; - -SELECT set_integer_now_func('hyper_constr', 'dummy_now_smallint'); -SELECT add_retention_policy('hyper_constr', 100::int) AS deljob_id \gset - -CALL run_job(:deljob_id); -CALL run_job(:deljob_id); -SELECT chunk_name, range_start, range_end -FROM chunk_view -WHERE hypertable_name = 'hyper_constr' -ORDER BY chunk_name; - -- test range of dimension slice for osm chunk for different datatypes CREATE TABLE osm_int2(time int2 NOT NULL); CREATE TABLE osm_int4(time int4 NOT NULL);