Skip to content

Commit b6cb118

Browse files
committed
ts_chunk_exists_with_compression
1 parent 7252ed7 commit b6cb118

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

src/chunk.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,10 +3130,11 @@ ts_chunk_exists_with_compression(int32 hypertable_id)
31303130
init_scan_by_hypertable_id(&iterator, hypertable_id);
31313131
ts_scanner_foreach(&iterator)
31323132
{
3133-
bool isnull_chunk_id =
3134-
slot_attisnull(ts_scan_iterator_slot(&iterator), Anum_chunk_compressed_chunk_id);
3133+
bool status_isnull;
3134+
Datum status =
3135+
slot_getattr(ts_scan_iterator_slot(&iterator), Anum_chunk_status, &status_isnull);
31353136

3136-
if (!isnull_chunk_id)
3137+
if (!status_isnull && ts_flags_are_set_32(DatumGetInt32(status), CHUNK_STATUS_COMPRESSED))
31373138
{
31383139
found = true;
31393140
break;

tsl/src/chunk_merge.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ merge_relinfos(RelationMergeInfo *relinfos, int nrelids, int mergeindex, LOCKMOD
715715
}
716716

717717
stats->relid = result_minfo->relid;
718-
stats->chunk_id = result_minfo->chunk->fd.id;
718+
/* Compressed relinfos carry no Chunk */
719+
stats->chunk_id = result_minfo->chunk ? result_minfo->chunk->fd.id : INVALID_CHUNK_ID;
719720

720721
Oid tablespace = result_rel->rd_rel->reltablespace;
721722
struct VacuumCutoffs *merged_cutoffs = &result_minfo->cutoffs;
@@ -1358,16 +1359,9 @@ chunk_merge_chunks(PG_FUNCTION_ARGS)
13581359
if (ts_chunk_is_compressed(chunk))
13591360
{
13601361
RelationMergeInfo *crelinfo = &crelinfos[i];
1361-
Chunk *cchunk = ts_chunk_get_by_id(chunk->fd.compressed_chunk_id, true);
1362-
/*
1363-
* Allocate on merge_cxt to survive transaction end in
1364-
* concurrent mode.
1365-
*/
1366-
MemoryContext old_mcxt = MemoryContextSwitchTo(merge_cxt);
1367-
crelinfo->chunk = ts_chunk_copy(cchunk);
1368-
MemoryContextSwitchTo(old_mcxt);
1369-
1370-
crelinfo->relid = crelinfo->chunk->table_id;
1362+
/* Merging the compressed relation only needs its relid, not a full Chunk. */
1363+
crelinfo->chunk = NULL;
1364+
crelinfo->relid = ts_relation_get_compressed_relid(chunk->table_id);
13711365
crelinfo->rel = table_open(crelinfo->relid, lockmode);
13721366
crelinfo->isresult = relinfos[i].isresult;
13731367
crelinfo->iscompressed_rel = true;

0 commit comments

Comments
 (0)