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 291efba
Show file tree
Hide file tree
Showing 4 changed files with 40 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 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;
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)
{
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);

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));

const Chunk *ch = ts_chunk_get_by_name_with_memory_context(chunk_schema_name,
chunk_table_name,
CurrentMemoryContext,
true);
Assert(ch != NULL);
ts_chunk_validate_chunk_status_for_operation(ch, CHUNK_DROP, true /*throw_error */);
/* do not drop any chunk dependencies */
ts_chunk_drop(ch, DROP_RESTRICT, LOG);
/* reset hypertable OSM status */
ht->fd.status = HYPERTABLE_STATUS_DEFAULT;
ts_hypertable_update(ht);
ts_cache_release(hcache);
PG_RETURN_BOOL(true);
}

0 comments on commit 291efba

Please sign in to comment.