Skip to content

Commit

Permalink
Add function to drop the osm chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
konskov committed Apr 3, 2024
1 parent a9a0334 commit ff2896d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions sql/chunk.sql
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ CREATE OR REPLACE FUNCTION _timescaledb_functions.attach_osm_table_chunk(
hypertable REGCLASS,
chunk REGCLASS)
RETURNS BOOL AS '@MODULE_PATHNAME@', 'ts_chunk_attach_osm_table_chunk' LANGUAGE C VOLATILE;

-- internal API used by OSM extension to drop an OSM chunk table from the hypertable
CREATE OR REPLACE FUNCTION _timescaledb_functions.drop_osm_table_chunk(
hypertable REGCLASS,
chunk REGCLASS)
RETURNS BOOL AS '@MODULE_PATHNAME@', 'ts_chunk_drop_osm_table_chunk' LANGUAGE C VOLATILE;
5 changes: 5 additions & 0 deletions sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,8 @@ ANALYZE _timescaledb_catalog.continuous_agg;
--
-- END Rebuild the catalog table `_timescaledb_catalog.continuous_agg`
--

CREATE FUNCTION _timescaledb_functions.drop_osm_table_chunk(
hypertable REGCLASS,
chunk REGCLASS)
RETURNS BOOL AS '@MODULE_PATHNAME@', 'ts_chunk_drop_osm_table_chunk' LANGUAGE C VOLATILE;
2 changes: 1 addition & 1 deletion sql/updates/reverse-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,4 @@ CREATE FUNCTION _timescaledb_functions.get_chunk_colstats(relid REGCLASS)
RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, att_num INTEGER, nullfrac REAL, width INTEGER, distinctval REAL, slotkind INTEGER[], slotopstrings CSTRING[], slotcollations OID[], slot1numbers FLOAT4[], slot2numbers FLOAT4[], slot3numbers FLOAT4[], slot4numbers FLOAT4[], slot5numbers FLOAT4[], slotvaluetypetrings CSTRING[], slot1values CSTRING[], slot2values CSTRING[], slot3values CSTRING[], slot4values CSTRING[], slot5values CSTRING[])
AS $$BEGIN END$$ LANGUAGE plpgsql SET search_path = pg_catalog, pg_temp;


DROP FUNCTION IF EXISTS _timescaledb_functions.drop_osm_table_chunk(REGCLASS, REGCLASS);
28 changes: 28 additions & 0 deletions src/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ TS_FUNCTION_INFO_V1(ts_chunk_id_from_relid);
TS_FUNCTION_INFO_V1(ts_chunk_show);
TS_FUNCTION_INFO_V1(ts_chunk_create);
TS_FUNCTION_INFO_V1(ts_chunk_status);
TS_FUNCTION_INFO_V1(ts_chunk_drop_osm_table_chunk);

static bool ts_chunk_add_status(Chunk *chunk, int32 status);

Expand Down Expand Up @@ -5189,3 +5190,30 @@ get_chunks_in_creation_time_range(Hypertable *ht, int64 older_than, int64 newer_

return chunks;
}


Datum
ts_chunk_drop_osm_table_chunk(PG_FUNCTION_ARGS)

Check warning on line 5196 in src/chunk.c

View check run for this annotation

Codecov / codecov/patch

src/chunk.c#L5196

Added line #L5196 was not covered by tests
{
Oid hypertable_relid = PG_ARGISNULL(0) ? InvalidOid : PG_GETARG_OID(0);
Cache *hcache = ts_hypertable_cache_pin();
Hypertable *ht = ts_resolve_hypertable_from_table_or_cagg(hcache, hypertable_relid, true);

Check warning on line 5200 in src/chunk.c

View check run for this annotation

Codecov / codecov/patch

src/chunk.c#L5199-L5200

Added lines #L5199 - L5200 were not covered by tests

Oid chunk_relid = PG_ARGISNULL(1) ? InvalidOid : PG_GETARG_OID(1);
char *chunk_table_name = get_rel_name(chunk_relid);
char *chunk_schema_name = get_namespace_name(get_rel_namespace(chunk_relid));

Check warning on line 5204 in src/chunk.c

View check run for this annotation

Codecov / codecov/patch

src/chunk.c#L5203-L5204

Added lines #L5203 - L5204 were not covered by tests

const Chunk *ch = ts_chunk_get_by_name_with_memory_context(chunk_schema_name,

Check warning on line 5206 in src/chunk.c

View check run for this annotation

Codecov / codecov/patch

src/chunk.c#L5206

Added line #L5206 was not covered by tests
chunk_table_name,
CurrentMemoryContext,
true);
Assert(ch != NULL);
ts_chunk_validate_chunk_status_for_operation(ch, CHUNK_DROP, true /*throw_error */);

Check warning on line 5211 in src/chunk.c

View check run for this annotation

Codecov / codecov/patch

src/chunk.c#L5211

Added line #L5211 was not covered by tests
/* do not drop any chunk dependencies */
ts_chunk_drop(ch, DROP_RESTRICT, LOG);

Check warning on line 5213 in src/chunk.c

View check run for this annotation

Codecov / codecov/patch

src/chunk.c#L5213

Added line #L5213 was not covered by tests
/* reset hypertable OSM status */
ht->fd.status = HYPERTABLE_STATUS_DEFAULT;
ts_hypertable_update(ht);
ts_cache_release(hcache);
PG_RETURN_BOOL(true);

Check warning on line 5218 in src/chunk.c

View check run for this annotation

Codecov / codecov/patch

src/chunk.c#L5215-L5218

Added lines #L5215 - L5218 were not covered by tests
}
1 change: 1 addition & 0 deletions tsl/test/shared/expected/extension.out
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ ORDER BY pronamespace::regnamespace::text COLLATE "C", p.oid::regprocedure::text
_timescaledb_functions.dimension_info_in(cstring)
_timescaledb_functions.dimension_info_out(_timescaledb_internal.dimension_info)
_timescaledb_functions.drop_chunk(regclass)
_timescaledb_functions.drop_osm_table_chunk(regclass,regclass)
_timescaledb_functions.finalize_agg(text,name,name,name[],bytea,anyelement)
_timescaledb_functions.finalize_agg_ffunc(internal,text,name,name,name[],bytea,anyelement)
_timescaledb_functions.finalize_agg_sfunc(internal,text,name,name,name[],bytea,anyelement)
Expand Down

0 comments on commit ff2896d

Please sign in to comment.