Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper function to get all chunks of a hypertable #6506

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3160,6 +3160,41 @@ ts_chunk_get_chunk_ids_by_hypertable_id(int32 hypertable_id)
return chunkids;
}

/* Return list of chunks that belong to the given hypertable.
*
* The returned chunk objects will not have any constraints or dimension
* information filled in.
*/
List *
ts_chunk_get_by_hypertable_id(int32 hypertable_id)
{
List *chunks = NIL;
Oid hypertable_relid = ts_hypertable_id_to_relid(hypertable_id, false);

ScanIterator iterator = ts_scan_iterator_create(CHUNK, RowExclusiveLock, CurrentMemoryContext);

init_scan_by_hypertable_id(&iterator, hypertable_id);
ts_scanner_foreach(&iterator)
{
TupleInfo *ti = ts_scan_iterator_tuple_info(&iterator);
Chunk *chunk = palloc0(sizeof(Chunk));
ts_chunk_formdata_fill(&chunk->fd, ti);

chunk->hypertable_relid = hypertable_relid;

if (!chunk->fd.dropped)
{
chunk->table_id = ts_get_relation_relid(NameStr(chunk->fd.schema_name),
NameStr(chunk->fd.table_name),
false);
}

chunks = lappend(chunks, chunk);
}

return chunks;
}

static ChunkResult
chunk_recreate_constraint(ChunkScanCtx *ctx, ChunkStub *stub)
{
Expand Down
1 change: 1 addition & 0 deletions src/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ extern TSDLLEXPORT bool ts_chunk_contains_compressed_data(const Chunk *chunk);
extern TSDLLEXPORT ChunkCompressionStatus ts_chunk_get_compression_status(int32 chunk_id);
extern TSDLLEXPORT Datum ts_chunk_id_from_relid(PG_FUNCTION_ARGS);
extern TSDLLEXPORT List *ts_chunk_get_chunk_ids_by_hypertable_id(int32 hypertable_id);
extern TSDLLEXPORT List *ts_chunk_get_by_hypertable_id(int32 hypertable_id);

extern TSDLLEXPORT Chunk *ts_chunk_create_only_table(Hypertable *ht, Hypercube *cube,
const char *schema_name,
Expand Down
8 changes: 4 additions & 4 deletions src/ts_catalog/compression_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ ts_compression_settings_rename_column_hypertable(Hypertable *ht, char *old, char
if (ht->fd.compressed_hypertable_id)
{
ListCell *lc;
List *chunk_ids = ts_chunk_get_chunk_ids_by_hypertable_id(ht->fd.compressed_hypertable_id);
foreach (lc, chunk_ids)
List *chunks = ts_chunk_get_by_hypertable_id(ht->fd.compressed_hypertable_id);
foreach (lc, chunks)
{
Oid relid = ts_chunk_get_relid(lfirst_int(lc), false);
ts_compression_settings_rename_column(relid, old, new);
Chunk *chunk = lfirst(lc);
ts_compression_settings_rename_column(chunk->table_id, old, new);
}
}
}
Expand Down