Skip to content

Commit

Permalink
bugfix: lookup_input_varnode_defitem() should not use equal() to comp…
Browse files Browse the repository at this point in the history
…are Var-nodes

Var-nodes in the reltarget of input-paths are not normalized
to this level of GpuJoin, so it may have different varnullingrels
even if they are identical Var-nodes. So, we should not use equal()
here to compare Var-nodes.

issue related to #673
  • Loading branch information
kaigai committed May 1, 2024
1 parent 349debf commit 2943488
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,34 @@ __assign_codegen_kvar_defitem_subfields(codegen_kvar_defitem *kvdef)
}
}

/*
* equalVar - compares two Var nodes except for varnullingrels
*
* NOTE: Var-nodes in the reltarget of input-paths are not normalized
* to this level of GpuJoin, so it may have different varnullingrels
* even if they are identical Var-nodes. So, we should not use equal()
* here to compare Var-nodes.
*/
static inline bool
equalVar(const void *__a, const void *__b)
{
if (IsA(__a, Var) && IsA(__b, Var))
{
const Var *a = __a;
const Var *b = __b;

if (a->varno == b->varno &&
a->varattno == b->varattno)
{
Assert(a->vartype == b->vartype &&
a->vartypmod == b->vartypmod &&
a->varcollid == b->varcollid);
return true;
}
}
return false;
}

/*
* lookup_input_varnode_defitem
*/
Expand Down Expand Up @@ -1464,7 +1492,7 @@ lookup_input_varnode_defitem(codegen_context *context,
resno = 1;
foreach (lc, target->exprs)
{
if (equal(var, lfirst(lc)))
if (equalVar(var, lfirst(lc)))
goto found;
resno++;
}
Expand All @@ -1478,7 +1506,7 @@ lookup_input_varnode_defitem(codegen_context *context,
if (kvdef->kv_depth == depth &&
kvdef->kv_resno == resno)
{
Assert(equal(var, kvdef->kv_expr));
Assert(equalVar(var, kvdef->kv_expr));
kvdef->kv_maxref = Max(kvdef->kv_maxref, curr_depth);
return kvdef;
}
Expand Down

0 comments on commit 2943488

Please sign in to comment.