From 50cc8e3f3b325e5e2d25f9432dede7af79c22995 Mon Sep 17 00:00:00 2001 From: Nikhil Sontakke Date: Mon, 18 Mar 2024 20:04:13 +0530 Subject: [PATCH] Don't show osm chunk via show_chunks Fix show_chunks to not to show the OSM chunk. In passing, also fix a compilation error on macOS. --- src/chunk.c | 27 ++++++++++++++++++--- tsl/src/continuous_aggs/utils.c | 2 +- tsl/test/expected/chunk_utils_internal.out | 7 ++++++ tsl/test/expected/compression_errors-13.out | 12 ++++++++- tsl/test/expected/compression_errors-14.out | 12 ++++++++- tsl/test/expected/compression_errors-15.out | 12 ++++++++- tsl/test/expected/compression_errors-16.out | 12 ++++++++- tsl/test/sql/chunk_utils_internal.sql | 2 ++ tsl/test/sql/compression_errors.sql.in | 9 ++++++- 9 files changed, 85 insertions(+), 10 deletions(-) diff --git a/src/chunk.c b/src/chunk.c index 79ea1e557..d9b4fbfbe 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -129,7 +129,7 @@ static void chunk_scan_ctx_destroy(ChunkScanCtx *ctx); static void chunk_collision_scan(ChunkScanCtx *scanctx, const Hypercube *cube); static int chunk_scan_ctx_foreach_chunk_stub(ChunkScanCtx *ctx, on_chunk_stub_func on_chunk, uint16 limit); -static Datum chunks_return_srf(FunctionCallInfo fcinfo); +static Datum show_chunks_return_srf(FunctionCallInfo fcinfo); static int chunk_cmp(const void *ch1, const void *ch2); static int chunk_point_find_chunk_id(const Hypertable *ht, const Point *p); static void init_scan_by_qualified_table_name(ScanIterator *iterator, const char *schema_name, @@ -2034,7 +2034,7 @@ Datum ts_chunk_show_chunks(PG_FUNCTION_ARGS) { /* - * chunks_return_srf is called even when it is not the first call but only + * show_chunks_return_srf is called even when it is not the first call but only * after doing some computation first */ if (SRF_IS_FIRSTCALL()) @@ -2173,7 +2173,7 @@ ts_chunk_show_chunks(PG_FUNCTION_ARGS) ts_cache_release(hcache); } - return chunks_return_srf(fcinfo); + return show_chunks_return_srf(fcinfo); } static Chunk * @@ -3720,12 +3720,13 @@ chunk_cmp(const void *ch1, const void *ch2) * to work. */ static Datum -chunks_return_srf(FunctionCallInfo fcinfo) +show_chunks_return_srf(FunctionCallInfo fcinfo) { FuncCallContext *funcctx; uint64 call_cntr; TupleDesc tupdesc; Chunk *result_set; + Chunk *curr_chunk; /* stuff done only on the first call of the function */ if (SRF_IS_FIRSTCALL()) @@ -3745,6 +3746,24 @@ chunks_return_srf(FunctionCallInfo fcinfo) call_cntr = funcctx->call_cntr; result_set = (Chunk *) funcctx->user_fctx; + /* + * skip if it's an OSM chunk. Ideally this check could be done deep down in + * functions like "chunk_scan_context_add_chunk", "chunk_tuple_dropped_filter" + * etc. but they are used by other APIs like drop_chunks, chunk_scan_find, etc + * which need access to the OSM chunk. Trying to unify scan functions across + * all such usages seems to be too much of an overhaul as compared to this. + * + * Check the index appropriately first. + */ + if (call_cntr < funcctx->max_calls) + { + curr_chunk = &result_set[call_cntr]; + if (IS_OSM_CHUNK(curr_chunk)) + { + call_cntr = ++funcctx->call_cntr; + } + } + /* do when there is more left to send */ if (call_cntr < funcctx->max_calls) SRF_RETURN_NEXT(funcctx, result_set[call_cntr].table_id); diff --git a/tsl/src/continuous_aggs/utils.c b/tsl/src/continuous_aggs/utils.c index 8e19f5d39..a687cafa7 100644 --- a/tsl/src/continuous_aggs/utils.c +++ b/tsl/src/continuous_aggs/utils.c @@ -23,7 +23,7 @@ static Datum create_cagg_validate_query_datum(TupleDesc tupdesc, const bool is_valid_query, const ErrorData *edata) { - NullableDatum datums[Natts_cagg_validate_query] = { 0 }; + NullableDatum datums[Natts_cagg_validate_query] = { { 0 } }; HeapTuple tuple; tupdesc = BlessTupleDesc(tupdesc); diff --git a/tsl/test/expected/chunk_utils_internal.out b/tsl/test/expected/chunk_utils_internal.out index f741753ad..8985a690f 100644 --- a/tsl/test/expected/chunk_utils_internal.out +++ b/tsl/test/expected/chunk_utils_internal.out @@ -946,6 +946,13 @@ ORDER BY id; 16 | child_hyper_constr (2 rows) +-- show_chunks will not show the OSM chunk which is visible via the above query +SELECT show_chunks('hyper_constr'); + show_chunks +----------------------------------------- + _timescaledb_internal._hyper_7_15_chunk +(1 row) + ROLLBACK; CALL run_job(:deljob_id); NOTICE: hypertable_drop_chunks_hook diff --git a/tsl/test/expected/compression_errors-13.out b/tsl/test/expected/compression_errors-13.out index ca90ec06d..847891257 100644 --- a/tsl/test/expected/compression_errors-13.out +++ b/tsl/test/expected/compression_errors-13.out @@ -878,6 +878,16 @@ WARNING: there was some uncertainty picking the default segment by for the hype NOTICE: default segment by for hypertable "osm_table" is set to "" NOTICE: default order by for hypertable "osm_table" is set to ""time" DESC" INSERT INTO osm_table VALUES ('2022-11-11 11:11:11', 'foo', 1.0); +SELECT format('%I.%I',chunk_schema,chunk_name) AS "CHUNK_NAME" +FROM timescaledb_information.chunks +WHERE hypertable_name = 'osm_table' +ORDER BY chunk_name LIMIT 1 \gset UPDATE _timescaledb_catalog.chunk ch SET osm_chunk = true FROM _timescaledb_catalog.hypertable ht WHERE ch.hypertable_id = ht.id AND ht.table_name='osm_table'; -SELECT compress_chunk(show_chunks('osm_table')); +-- show_chunks should not show any OSM chunks +SELECT show_chunks('osm_table'); + show_chunks +------------- +(0 rows) + +SELECT compress_chunk(:'CHUNK_NAME'); ERROR: compress_chunk not permitted on tiered chunk "_hyper_43_31_chunk" diff --git a/tsl/test/expected/compression_errors-14.out b/tsl/test/expected/compression_errors-14.out index ca90ec06d..847891257 100644 --- a/tsl/test/expected/compression_errors-14.out +++ b/tsl/test/expected/compression_errors-14.out @@ -878,6 +878,16 @@ WARNING: there was some uncertainty picking the default segment by for the hype NOTICE: default segment by for hypertable "osm_table" is set to "" NOTICE: default order by for hypertable "osm_table" is set to ""time" DESC" INSERT INTO osm_table VALUES ('2022-11-11 11:11:11', 'foo', 1.0); +SELECT format('%I.%I',chunk_schema,chunk_name) AS "CHUNK_NAME" +FROM timescaledb_information.chunks +WHERE hypertable_name = 'osm_table' +ORDER BY chunk_name LIMIT 1 \gset UPDATE _timescaledb_catalog.chunk ch SET osm_chunk = true FROM _timescaledb_catalog.hypertable ht WHERE ch.hypertable_id = ht.id AND ht.table_name='osm_table'; -SELECT compress_chunk(show_chunks('osm_table')); +-- show_chunks should not show any OSM chunks +SELECT show_chunks('osm_table'); + show_chunks +------------- +(0 rows) + +SELECT compress_chunk(:'CHUNK_NAME'); ERROR: compress_chunk not permitted on tiered chunk "_hyper_43_31_chunk" diff --git a/tsl/test/expected/compression_errors-15.out b/tsl/test/expected/compression_errors-15.out index ca90ec06d..847891257 100644 --- a/tsl/test/expected/compression_errors-15.out +++ b/tsl/test/expected/compression_errors-15.out @@ -878,6 +878,16 @@ WARNING: there was some uncertainty picking the default segment by for the hype NOTICE: default segment by for hypertable "osm_table" is set to "" NOTICE: default order by for hypertable "osm_table" is set to ""time" DESC" INSERT INTO osm_table VALUES ('2022-11-11 11:11:11', 'foo', 1.0); +SELECT format('%I.%I',chunk_schema,chunk_name) AS "CHUNK_NAME" +FROM timescaledb_information.chunks +WHERE hypertable_name = 'osm_table' +ORDER BY chunk_name LIMIT 1 \gset UPDATE _timescaledb_catalog.chunk ch SET osm_chunk = true FROM _timescaledb_catalog.hypertable ht WHERE ch.hypertable_id = ht.id AND ht.table_name='osm_table'; -SELECT compress_chunk(show_chunks('osm_table')); +-- show_chunks should not show any OSM chunks +SELECT show_chunks('osm_table'); + show_chunks +------------- +(0 rows) + +SELECT compress_chunk(:'CHUNK_NAME'); ERROR: compress_chunk not permitted on tiered chunk "_hyper_43_31_chunk" diff --git a/tsl/test/expected/compression_errors-16.out b/tsl/test/expected/compression_errors-16.out index e4ea1ae37..9ad6955df 100644 --- a/tsl/test/expected/compression_errors-16.out +++ b/tsl/test/expected/compression_errors-16.out @@ -878,6 +878,16 @@ WARNING: there was some uncertainty picking the default segment by for the hype NOTICE: default segment by for hypertable "osm_table" is set to "" NOTICE: default order by for hypertable "osm_table" is set to ""time" DESC" INSERT INTO osm_table VALUES ('2022-11-11 11:11:11', 'foo', 1.0); +SELECT format('%I.%I',chunk_schema,chunk_name) AS "CHUNK_NAME" +FROM timescaledb_information.chunks +WHERE hypertable_name = 'osm_table' +ORDER BY chunk_name LIMIT 1 \gset UPDATE _timescaledb_catalog.chunk ch SET osm_chunk = true FROM _timescaledb_catalog.hypertable ht WHERE ch.hypertable_id = ht.id AND ht.table_name='osm_table'; -SELECT compress_chunk(show_chunks('osm_table')); +-- show_chunks should not show any OSM chunks +SELECT show_chunks('osm_table'); + show_chunks +------------- +(0 rows) + +SELECT compress_chunk(:'CHUNK_NAME'); ERROR: compress_chunk not permitted on tiered chunk "_hyper_43_31_chunk" diff --git a/tsl/test/sql/chunk_utils_internal.sql b/tsl/test/sql/chunk_utils_internal.sql index 9c2dde243..70f72b231 100644 --- a/tsl/test/sql/chunk_utils_internal.sql +++ b/tsl/test/sql/chunk_utils_internal.sql @@ -515,6 +515,8 @@ 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') ORDER BY id; +-- show_chunks will not show the OSM chunk which is visible via the above query +SELECT show_chunks('hyper_constr'); ROLLBACK; CALL run_job(:deljob_id); CALL run_job(:deljob_id); diff --git a/tsl/test/sql/compression_errors.sql.in b/tsl/test/sql/compression_errors.sql.in index 8266395a6..2d3a52094 100644 --- a/tsl/test/sql/compression_errors.sql.in +++ b/tsl/test/sql/compression_errors.sql.in @@ -511,7 +511,14 @@ ALTER TABLE osm_table SET (timescaledb.compress); INSERT INTO osm_table VALUES ('2022-11-11 11:11:11', 'foo', 1.0); +SELECT format('%I.%I',chunk_schema,chunk_name) AS "CHUNK_NAME" +FROM timescaledb_information.chunks +WHERE hypertable_name = 'osm_table' +ORDER BY chunk_name LIMIT 1 \gset + UPDATE _timescaledb_catalog.chunk ch SET osm_chunk = true FROM _timescaledb_catalog.hypertable ht WHERE ch.hypertable_id = ht.id AND ht.table_name='osm_table'; -SELECT compress_chunk(show_chunks('osm_table')); +-- show_chunks should not show any OSM chunks +SELECT show_chunks('osm_table'); +SELECT compress_chunk(:'CHUNK_NAME');