Skip to content

Commit

Permalink
Init child nodes / clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
jnidzwetzki committed May 22, 2023
1 parent 045355a commit 7454af4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
39 changes: 26 additions & 13 deletions tsl/src/nodes/decompress_chunk/decompress_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions tsl/src/nodes/decompress_chunk_vector/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

0 comments on commit 7454af4

Please sign in to comment.