Re: [HACKERS] Grouping Sets: Fix unrecognized node type bug

From: Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>
To: jeevan(dot)chalke(at)enterprisedb(dot)com
Cc: andrew(at)tao11(dot)riddles(dot)org(dot)uk, atri(dot)jiit(at)gmail(dot)com, pgsql-hackers(at)postgresql(dot)org, pgsql-bugs(at)postgresql(dot)org
Subject: Re: [HACKERS] Grouping Sets: Fix unrecognized node type bug
Date: 2015-07-17 08:13:09
Message-ID: 20150717.171309.187064257.horiguchi.kyotaro@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Hello, this looks to be a kind of thinko. The attached patch
fixes it.

===
According to the comment of transformGroupingSet, it assumes that
the given GROUPING SETS node is already flatted out and
flatten_grouping_sets() does that. The details of the
transformation is described in the comment for the function.

The problmen is what does the function for nested grouping sets.

> Node *n2 = flatten_grouping_sets(lfirst(l2), false, NULL);
> result_set = lappend(result_set, n2);

This does not flattens the list as required. n2 should be
concatenated if it is a list. The attached small patch fixes it
and the problematic query returns sane (perhaps) result.

# Though I don't know the exact definition of the syntax..

=# select sum(c) from gstest2 group by grouping sets ((), grouping sets ((), grouping sets (())));
sum
-----
12
12
12
(3 rows)

=# select sum(c) from gstest2 group by grouping sets ((a), grouping sets ((b), grouping sets ((c))));
sum
-----
10
2
6
6
8
4
(6 rows)

regards,

At Fri, 17 Jul 2015 11:37:26 +0530, Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com> wrote in <CAM2+6=XPRgumbqWTsczbECC3xjv4zH1ryQ3fwds5uajON1iq2A(at)mail(dot)gmail(dot)com>
> > Jeevan> It looks like we do support nested GROUPING SETS, I mean Sets
> > Jeevan> withing Sets, not other types. However this nesting is broken.
> >
> > Good catch, but I'm not yet sure your fix is correct; I'll need to look
> > into that.
> >
>
> Sure. Thanks.
>
> However I wonder why we are supporting GROUPING SETS inside GROUPING SETS.
> On Oracle, it is throwing an error.
> We are not trying to be Oracle compatible, but just curious to know.
>
> I have tried restricting it in attached patch.
>
> But it may require few comment adjustment.

--
Kyotaro Horiguchi
NTT Open Source Software Center

Attachment Content-Type Size
fix_flatten_nested_grupingsets.patch text/x-patch 596 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message priyanka 2015-07-17 10:45:07 BUG #13505: Create Extension
Previous Message Jeevan Chalke 2015-07-17 06:07:26 Re: [HACKERS] Grouping Sets: Fix unrecognized node type bug

Browse pgsql-hackers by date

  From Date Subject
Next Message Florent Guiliani 2015-07-17 08:16:09 Re: Retrieve the snapshot's LSN
Previous Message Haribabu Kommi 2015-07-17 07:52:58 Re: Parallel Seq Scan