Re: Identity projection

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Amit Kapila <amit(dot)kapila(at)huawei(dot)com>
Cc: 'Tom Lane' <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 'Kyotaro HORIGUCHI' <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Identity projection
Date: 2013-03-08 17:51:42
Message-ID: 513A252E.2070907@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 12.02.2013 11:03, Amit Kapila wrote:
> + /*
> + * equivalent_tlists
> + * returns whether two traget lists are equivalent
> + *
> + * We consider two target lists equivalent if both have
> + * only Var entries and resjunk of each target entry is same.
> + *
> + * This function is used to decide whether to create a result node.
> + * We need to ensure that each entry is Var as below node will not be
> + * projection capable, so it will not be able to compute expressions.
> + */
> + bool
> + equivalent_tlists(List *tlist1, List *tlist2)
> + {
> + ListCell *lp,
> + *lc;
> +
> + if (list_length(tlist1) != list_length(tlist2))
> + return false; /* tlists not same length */
> +
> + forboth(lp, tlist1, lc, tlist2)
> + {
> + TargetEntry *tle1 = (TargetEntry *) lfirst(lp);
> + TargetEntry *tle2 = (TargetEntry *) lfirst(lc);
> +
> + if (tle1->resjunk != tle1->resjunk)
> + return false; /* tlist doesn't match junk status */
> +
> + if (tle1->expr && IsA(tle1->expr, Var) &&
> + tle2->expr && IsA(tle2->expr, Var))
> + {
> + Var *var1 = (Var *) tle1->expr;
> + Var *var2 = (Var *) tle2->expr;
> +
> + if (var1->varattno != var2->varattno)
> + return false; /* different order */
> + }
> + else
> + return false;
> + }
> + return true;
> + }

Hmm, shouldn't that also check Var.varno and Var.varlevelsup? I tried
really hard to come up with a query that would fail because of that, but
I wasn't able to find one. Nevertheless, seems like those fields should
be checked.

On a more trivial note, equivalent_tlists() seems too generic for this.
I'd expect two tlists that contain e.g an identical Const node to be
"equivalent", but this returns false for it. I'd suggest calling it
something like "tlist_needs_projection()" instead. Also, it probably
belongs in tlist.c.

- Heikki

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2013-03-08 17:59:58 Re: [HACKERS] REFRESH MATERIALIZED VIEW locklevel
Previous Message Josh Berkus 2013-03-08 17:46:25 Re: Enabling Checksums