Re: Removing Functionally Dependent GROUP BY Columns

From: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Marko Tiikkaja <marko(at)joh(dot)to>, Julien Rouhaud <julien(dot)rouhaud(at)dalibo(dot)com>
Subject: Re: Removing Functionally Dependent GROUP BY Columns
Date: 2016-02-14 21:16:35
Message-ID: CAKJS1f9eGXkv0UnriEP3uaQED6U+x_b41LVeuBnt9MZZXmh3Jg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 14/02/2016 5:11 pm, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> David Rowley <david(dot)rowley(at)2ndquadrant(dot)com> writes:
> > On 12/02/2016 12:01 am, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > I can't quite understand what you're seeing here.
>
> The second loop is iterating through the original GROUP BY list, so it
> will see again any outer Vars that were excluded by the first loop.
> It needs to exclude them exactly the same, because they are outside
> the scope of its data structures. Consider something like (admittedly
> pretty silly, but legal SQL)
>
> create table up (u1 int, u2 int, u3 int);
> create table down (f1 int primary key, f2 int);
>
> select * from othertable, up
> where u1 in (select f2 from down group by f1, f2, up.u3);
>
> up.u3 would have varlevelsup = 1, varno = 2, varattno = 3.
> If you don't skip it then the surplusvars[var->varno] access
> will be trying to fetch off the end of the surplusvars[] array,
> because there is only one RTE in the subquery's rangetable
> though there are two in the outer query's rangetable.

Thanks for explaining this. Clearly I missed the case of the varno pointing
off the end of the array. Thanks for noticing and fixing.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-02-14 22:05:04 Re: Re: [COMMITTERS] pgsql: Introduce group locking to prevent parallel processes from deadl
Previous Message Magnus Hagander 2016-02-14 20:48:07 Refectoring of receivelog.c