Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
jnidzwetzki committed May 22, 2023
1 parent a1a17ef commit 8487617
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions tsl/src/nodes/decompress_chunk/decompress_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,27 +561,41 @@ can_sorted_merge_append(PlannerInfo *root, CompressionInfo *info, Chunk *chunk)
}

/*
* The logic in make_partition_pruneinfo() contains an assert that checks
* that relids are unique in a query plan.
* Clone the info->chunk_rel ReloptInfo and set the relid to the relid of info->compressed_rel.
*
* When we access a partially compressed chunk, we create an append path that combines the data
* from the compressed part with the uncompressed part. The logic in make_partition_pruneinfo()
* contains a check to ensure that relids are unique in an append path.
*
* To create the path that reads the uncompressed chunk data, the planner calls
* decompress_chunk_path_create() again. Therefore, we end up with a second path with the same
* RelOptInfo data structure as the real compressed path. So, we need to adjust the relid in one of
* these data structures if we want to use both paths in an append path.
*
*/
static void
adjust_compressed_relid(PlannerInfo *root, CompressionInfo *info, Path *path)
adjust_compressed_relid_in_path(PlannerInfo *root, CompressionInfo *info, Path *compressed_path,
Path *uncompressed_path)
{
/* The compressed path and the uncompressed path share the same RelOptInfo */
Assert(compressed_path->parent == uncompressed_path->parent);

Oid compressed_relid = info->compressed_rel->relid;
Oid uncompressed_relid = info->chunk_rel->relid;

/* Ensure the relid of the uncompressed and the compressed part of the chunk are different */
Assert(compressed_relid != uncompressed_relid);

/* Make sure the planner can find the append rel data structures for the compressed relid */
root->append_rel_array[compressed_relid] =
root->append_rel_array[uncompressed_relid];

/* Clone the existing chunk_rel and adjust the relid */
/* Clone the chunk_rel RelOptInfo and adjust the relid */
RelOptInfo *newrel_opt_info = palloc(sizeof(RelOptInfo));
memcpy(newrel_opt_info, info->chunk_rel, sizeof(RelOptInfo));
newrel_opt_info->relid = compressed_relid;

path->parent = newrel_opt_info;
/* Assign the new RelOptInfo structure to the compressed_path */
compressed_path->parent = newrel_opt_info;

/* Make sure the planner can find the append rel data structures for the compressed relid */
root->append_rel_array[compressed_relid] = root->append_rel_array[uncompressed_relid];
}

void
Expand Down Expand Up @@ -825,9 +839,9 @@ ts_decompress_chunk_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, Hyp
continue;
}

adjust_compressed_relid(root, info, path);

adjust_compressed_relid_in_path(root, info, path, uncompressed_path);
Assert(path->parent->relid != uncompressed_path->parent->relid);

path = (Path *) create_append_path_compat(root,
chunk_rel,
list_make2(path, uncompressed_path),
Expand Down Expand Up @@ -900,7 +914,8 @@ ts_decompress_chunk_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, Hyp
continue;
}

adjust_compressed_relid(root, info, path);
adjust_compressed_relid_in_path(root, info, path, uncompressed_path);
Assert(path->parent->relid != uncompressed_path->parent->relid);

path = (Path *) create_append_path_compat(root,
chunk_rel,
Expand Down

0 comments on commit 8487617

Please sign in to comment.