Hi

Build on v2 by adding checks in the recursive calls to find_relation_rte() to 
ensure that 
the relevant Var properties match, as shown below:
               /*
                 * We can only recurse through a simple Var of the subquery's 
query
                 * level, and only if its varattno, vartype, vartypmod, 
varcollid, and
                 * varreturningtype properties match those of the upper Var.
                 */
                if (tmpvar && IsA((tmpvar), Var) &&
                        tmpvar->varlevelsup == 0)
                {
                        if (tmpvar->varattno <= 0 ||
                                tmpvar->vartype != (*var)->vartype ||
                                tmpvar->vartypmod != (*var)->vartypmod ||
                                tmpvar->varcollid != (*var)->varcollid ||
                                tmpvar->varreturningtype != 
(*var)->varreturningtype)
                                goto fail;

                        /* OK, recurse into the subquery. */
                        *var = tmpvar;
                        return find_relation_rte(subroot, var);
                }

Also, revise the comments in find_relation_rte() and simplify its 
implementation, using examine_simple_variable() as a reference.

regards,
--
ZizhuanLiu (X-MAN) 
[email protected]

Attachment: v3-0001-Optimize-mergejoinscansel-by-avoiding-redundant-c.patch
Description: Binary data

Reply via email to