diff --git a/src/codegen.c b/src/codegen.c index 96b51840..8fbb40c0 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -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 */ @@ -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++; } @@ -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; }