Skip to content

Commit b31d607

Browse files
committed
Fix rescan_append_common
1 parent c7d8fd4 commit b31d607

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/nodes_common.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,27 @@ end_append_common(CustomScanState *node)
612612
hash_destroy(scan_state->children_table);
613613
}
614614

615+
/*
616+
* This function is similar to ChangeVarNodes, but changes only
617+
* varno attributes, but doesn't change varnoold attribute
618+
*/
619+
static bool
620+
change_only_varnos(Node *node, const int *idx)
621+
{
622+
if (node == NULL)
623+
return false;
624+
625+
if (IsA(node, Var))
626+
{
627+
Var *var = (Var *) node;
628+
Assert(var->varno == 1);
629+
var->varno = *idx;
630+
return false;
631+
}
632+
633+
return expression_tree_walker(node, change_only_varnos, (void *) idx);
634+
}
635+
615636
void
616637
rescan_append_common(CustomScanState *node)
617638
{
@@ -625,16 +646,14 @@ rescan_append_common(CustomScanState *node)
625646
int nparts;
626647
Node *prel_expr;
627648

649+
const int index_var = INDEX_VAR;
650+
628651
prel = get_pathman_relation_info(scan_state->relid);
629652
Assert(prel);
630653

631654
/* Prepare expression */
632-
prel_expr = prel->expr;
633-
if (INDEX_VAR != 1)
634-
{
635-
prel_expr = copyObject(prel_expr);
636-
ChangeVarNodes(prel_expr, 1, INDEX_VAR, 0);
637-
}
655+
prel_expr = copyObject(prel->expr);
656+
change_only_varnos(prel_expr, &index_var);
638657

639658
/* First we select all available partitions... */
640659
ranges = list_make1_irange(make_irange(0, PrelLastChild(prel), IR_COMPLETE));

0 commit comments

Comments
 (0)