Skip to content

Commit 1a97b11

Browse files
committed
fix tlist rebuild logic in function create_append_plan_common()
1 parent c8851e7 commit 1a97b11

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/nodes_common.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,24 +396,31 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
396396

397397
cscan = makeNode(CustomScan);
398398
cscan->custom_scan_tlist = NIL; /* initial value (empty list) */
399-
cscan->scan.plan.targetlist = NIL;
400399

401400
if (custom_plans)
402401
{
403402
ListCell *lc1,
404403
*lc2;
404+
bool processed_rel_tlist = false;
405+
406+
Assert(list_length(rpath->cpath.custom_paths) == list_length(custom_plans));
405407

406408
forboth (lc1, rpath->cpath.custom_paths, lc2, custom_plans)
407409
{
408410
Plan *child_plan = (Plan *) lfirst(lc2);
409411
RelOptInfo *child_rel = ((Path *) lfirst(lc1))->parent;
410412

411-
/* Replace rel's tlist with a matching one */
412-
if (!cscan->scan.plan.targetlist)
413+
/* Replace rel's tlist with a matching one (for ExecQual()) */
414+
if (!processed_rel_tlist)
415+
{
413416
tlist = replace_tlist_varnos(child_plan->targetlist,
414417
child_rel->relid,
415418
rel->relid);
416419

420+
/* Done, new target list has been built */
421+
processed_rel_tlist = true;
422+
}
423+
417424
/* Add partition attribute if necessary (for ExecQual()) */
418425
child_plan->targetlist = append_part_attr_to_tlist(child_plan->targetlist,
419426
child_rel->relid,

0 commit comments

Comments
 (0)