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

Make compression metadata column names reusable #5607

Merged
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
30 changes: 20 additions & 10 deletions tsl/src/compression/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,14 @@ get_default_algorithm_id(Oid typeoid)
}

static char *
compression_column_segment_metadata_name(const FormData_hypertable_compression *fd,
const char *type)
compression_column_segment_metadata_name(int16 column_index, const char *type)
{
char *buf = palloc(sizeof(char) * NAMEDATALEN);
int ret;

Assert(fd->orderby_column_index > 0);
ret = snprintf(buf,
NAMEDATALEN,
COMPRESSION_COLUMN_METADATA_PREFIX "%s_%d",
type,
fd->orderby_column_index);
Assert(column_index > 0);
ret =
snprintf(buf, NAMEDATALEN, COMPRESSION_COLUMN_METADATA_PREFIX "%s_%d", type, column_index);
if (ret < 0 || ret > NAMEDATALEN)
{
ereport(ERROR,
Expand All @@ -126,16 +122,30 @@ compression_column_segment_metadata_name(const FormData_hypertable_compression *
return buf;
}

char *
column_segment_min_name(int16 column_index)
{
return compression_column_segment_metadata_name(column_index,
COMPRESSION_COLUMN_METADATA_MIN_COLUMN_NAME);
}

char *
column_segment_max_name(int16 column_index)
{
return compression_column_segment_metadata_name(column_index,
COMPRESSION_COLUMN_METADATA_MAX_COLUMN_NAME);
}

char *
compression_column_segment_min_name(const FormData_hypertable_compression *fd)
{
return compression_column_segment_metadata_name(fd, "min");
return column_segment_min_name(fd->orderby_column_index);
}

char *
compression_column_segment_max_name(const FormData_hypertable_compression *fd)
{
return compression_column_segment_metadata_name(fd, "max");
return column_segment_max_name(fd->orderby_column_index);
}

static void
Expand Down
5 changes: 5 additions & 0 deletions tsl/src/compression/create.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#define COMPRESSION_COLUMN_METADATA_COUNT_NAME COMPRESSION_COLUMN_METADATA_PREFIX "count"
#define COMPRESSION_COLUMN_METADATA_SEQUENCE_NUM_NAME \
COMPRESSION_COLUMN_METADATA_PREFIX "sequence_num"
#define COMPRESSION_COLUMN_METADATA_MIN_COLUMN_NAME "min"
#define COMPRESSION_COLUMN_METADATA_MAX_COLUMN_NAME "max"

bool tsl_process_compress_table(AlterTableCmd *cmd, Hypertable *ht,
WithClauseResult *with_clause_options);
Expand All @@ -26,4 +28,7 @@ Chunk *create_compress_chunk(Hypertable *compress_ht, Chunk *src_chunk, Oid tabl
char *compression_column_segment_min_name(const FormData_hypertable_compression *fd);
char *compression_column_segment_max_name(const FormData_hypertable_compression *fd);

char *column_segment_min_name(int16 column_index);
char *column_segment_max_name(int16 column_index);

#endif /* TIMESCALEDB_TSL_COMPRESSION_CREATE_H */