Skip to content

Commit

Permalink
Reset compressor between recompression runs
Browse files Browse the repository at this point in the history
If we reuse the compressor to recompress multiple sets
of tuples, internal state gets left behind from the previous
run which can contain invalid data. Resetting the compressor
first iteration field between runs fixes this.
  • Loading branch information
antekresic authored and jnidzwetzki committed Nov 28, 2023
1 parent 60e2d88 commit b2cd1ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tsl/src/compression/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,7 @@ tsl_recompress_chunk_segmentwise(PG_FUNCTION_ARGS)

tuplesort_performsort(segment_tuplesortstate);

row_compressor_reset(&row_compressor);
recompress_segment(segment_tuplesortstate, uncompressed_chunk_rel, &row_compressor);

/* now any pointers returned will be garbage */
Expand Down Expand Up @@ -1556,6 +1557,7 @@ tsl_recompress_chunk_segmentwise(PG_FUNCTION_ARGS)
uncompressed_chunk_rel,
current_segment);
tuplesort_performsort(segment_tuplesortstate);
row_compressor_reset(&row_compressor);
recompress_segment(segment_tuplesortstate, uncompressed_chunk_rel, &row_compressor);
tuplesort_end(segment_tuplesortstate);

Expand All @@ -1582,6 +1584,7 @@ tsl_recompress_chunk_segmentwise(PG_FUNCTION_ARGS)
if (unmatched_rows_exist)
{
tuplesort_performsort(segment_tuplesortstate);
row_compressor_reset(&row_compressor);
row_compressor_append_sorted_rows(&row_compressor,
segment_tuplesortstate,
RelationGetDescr(uncompressed_chunk_rel));
Expand Down
6 changes: 6 additions & 0 deletions tsl/src/compression/compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,12 @@ row_compressor_flush(RowCompressor *row_compressor, CommandId mycid, bool change
MemoryContextReset(row_compressor->per_row_ctx);
}

void
row_compressor_reset(RowCompressor *row_compressor)
{
row_compressor->first_iteration = true;
}

void
row_compressor_finish(RowCompressor *row_compressor)
{
Expand Down
1 change: 1 addition & 0 deletions tsl/src/compression/compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ extern void row_compressor_init(RowCompressor *row_compressor, TupleDesc uncompr
const ColumnCompressionInfo **column_compression_info,
int16 *column_offsets, int16 num_columns_in_compressed_table,
bool need_bistate, bool reset_sequence, int insert_options);
extern void row_compressor_reset(RowCompressor *row_compressor);
extern void row_compressor_finish(RowCompressor *row_compressor);
extern void row_compressor_append_sorted_rows(RowCompressor *row_compressor,
Tuplesortstate *sorted_rel, TupleDesc sorted_desc);
Expand Down

0 comments on commit b2cd1ec

Please sign in to comment.