From 7454af4cfd36b876a0faa8bcd6273b46da803462 Mon Sep 17 00:00:00 2001 From: Jan Nidzwetzki Date: Mon, 22 May 2023 08:54:28 +0200 Subject: [PATCH] Init child nodes / clean up code --- .../nodes/decompress_chunk/decompress_chunk.c | 39 ++++++++++++------- tsl/src/nodes/decompress_chunk_vector/exec.c | 13 +++++-- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/tsl/src/nodes/decompress_chunk/decompress_chunk.c b/tsl/src/nodes/decompress_chunk/decompress_chunk.c index 49c3de6677f..8df971260e9 100644 --- a/tsl/src/nodes/decompress_chunk/decompress_chunk.c +++ b/tsl/src/nodes/decompress_chunk/decompress_chunk.c @@ -560,6 +560,30 @@ can_sorted_merge_append(PlannerInfo *root, CompressionInfo *info, Chunk *chunk) return merge_result; } +/* + * The logic in make_partition_pruneinfo() contains an assert that checks + * that relids are unique in a query plan. + */ +static void +adjust_compressed_relid(PlannerInfo *root, CompressionInfo *info, Path *path) +{ + Oid compressed_relid = info->compressed_rel->relid; + Oid uncompressed_relid = info->chunk_rel->relid; + + 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 */ + 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; +} + void ts_decompress_chunk_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, Hypertable *ht, Chunk *chunk) @@ -801,14 +825,7 @@ ts_decompress_chunk_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, Hyp continue; } - // make make_partition_pruneinfo() happy - root->append_rel_array[info->compressed_rel->relid] = - root->append_rel_array[info->chunk_rel->relid]; - - RelOptInfo *newrel = palloc(sizeof(RelOptInfo)); - memcpy(newrel, info->chunk_rel, sizeof(RelOptInfo)); - newrel->relid = info->compressed_rel->relid; - path->parent = newrel; + adjust_compressed_relid(root, info, path); Assert(path->parent->relid != uncompressed_path->parent->relid); path = (Path *) create_append_path_compat(root, @@ -883,11 +900,7 @@ ts_decompress_chunk_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, Hyp continue; } - // Fix relid - RelOptInfo *newrel = palloc(sizeof(RelOptInfo)); - memcpy(newrel, info->chunk_rel, sizeof(RelOptInfo)); - newrel->relid = info->compressed_rel->relid; - path->parent = newrel; + adjust_compressed_relid(root, info, path); path = (Path *) create_append_path_compat(root, chunk_rel, diff --git a/tsl/src/nodes/decompress_chunk_vector/exec.c b/tsl/src/nodes/decompress_chunk_vector/exec.c index daf92acb723..73f7c52e38f 100644 --- a/tsl/src/nodes/decompress_chunk_vector/exec.c +++ b/tsl/src/nodes/decompress_chunk_vector/exec.c @@ -48,11 +48,18 @@ decompress_chunk_vector_exec(CustomScanState *node) static void decompress_chunk_vector_begin(CustomScanState *node, EState *estate, int eflags) { + // DecompressChunkVectorState *chunk_state = (DecompressChunkVectorState *) node; + CustomScan *vector_scan_plan = castNode(CustomScan, node->ss.ps.plan); + + Plan *compressed_scan = (Plan *) linitial(vector_scan_plan->custom_plans); + PlanState *compressed_state = (PlanState *) ExecInitNode(compressed_scan, estate, eflags); + node->custom_ps = lappend(node->custom_ps, compressed_state); } static void decompress_chunk_vector_end(CustomScanState *node) { + ExecEndNode(linitial(node->custom_ps)); } static void @@ -68,9 +75,9 @@ decompress_chunk_vector_explain(CustomScanState *node, List *ancestors, ExplainS Node * decompress_chunk_vector_state_create(CustomScan *cscan) { - DecompressChunkVectorState *chunk_state; - chunk_state = (DecompressChunkVectorState *) newNode(sizeof(DecompressChunkVectorState), - T_CustomScanState); + DecompressChunkVectorState *chunk_state = + (DecompressChunkVectorState *) newNode(sizeof(DecompressChunkVectorState), + T_CustomScanState); chunk_state->csstate.methods = &decompress_chunk_vector_state_methods; return (Node *) chunk_state; }