Skip to content

Commit

Permalink
Simplify is_compressed_column in DecompressChunk
Browse files Browse the repository at this point in the history
Change the is_compressed_column implementation to determine whether
a column is compressed based on datatype. Any column with type
_timescaledb_internal.compressed_data is considered compressed.
The new implementation should return exactly the same result as the old
one.
  • Loading branch information
svenklemm committed Dec 5, 2023
1 parent c81ae6f commit ad9ab6c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 7 additions & 8 deletions tsl/src/nodes/decompress_chunk/decompress_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <planner.h>

#include "compat/compat.h"
#include "custom_type_cache.h"
#include "debug_assert.h"
#include "ts_catalog/hypertable_compression.h"
#include "import/planner.h"
Expand Down Expand Up @@ -82,13 +83,9 @@ static SortInfo build_sortinfo(Chunk *chunk, RelOptInfo *chunk_rel, CompressionI
List *pathkeys);

static bool
is_compressed_column(CompressionInfo *info, AttrNumber attno)
is_compressed_column(CompressionInfo *info, Oid type)
{
char *column_name = get_attname(info->compressed_rte->relid, attno, false);
FormData_hypertable_compression *column_info =
get_column_compressioninfo(info->hypertable_compression_info, column_name);

return column_info->algo_id != 0;
return type == info->compresseddata_oid;
}

static EquivalenceClass *
Expand Down Expand Up @@ -283,6 +280,8 @@ build_compressioninfo(PlannerInfo *root, Hypertable *ht, RelOptInfo *chunk_rel)
AppendRelInfo *appinfo;
CompressionInfo *info = palloc0(sizeof(CompressionInfo));

info->compresseddata_oid = ts_custom_type_cache_get(CUSTOM_TYPE_COMPRESSED_DATA)->type_oid;

info->chunk_rel = chunk_rel;
info->chunk_rte = planner_rt_fetch(chunk_rel->relid, root);

Expand Down Expand Up @@ -732,7 +731,7 @@ ts_decompress_chunk_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, Hyp
info->compressed_rel->relid)
{
Var *var = castNode(Var, ri->right_em->em_expr);
if (is_compressed_column(info, var->varattno))
if (is_compressed_column(info, var->vartype))
{
references_compressed = true;
break;
Expand All @@ -743,7 +742,7 @@ ts_decompress_chunk_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, Hyp
info->compressed_rel->relid)
{
Var *var = castNode(Var, ri->left_em->em_expr);
if (is_compressed_column(info, var->varattno))
if (is_compressed_column(info, var->vartype))
{
references_compressed = true;
break;
Expand Down
2 changes: 2 additions & 0 deletions tsl/src/nodes/decompress_chunk/decompress_chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ typedef struct CompressionInfo
RangeTblEntry *compressed_rte;
RangeTblEntry *ht_rte;

Oid compresseddata_oid;

int hypertable_id;
List *hypertable_compression_info;

Expand Down

0 comments on commit ad9ab6c

Please sign in to comment.