Grouping Sets: Fix unrecognized node type bug

From: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Postgres-Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Grouping Sets: Fix unrecognized node type bug
Date: 2015-07-15 13:40:45
Message-ID: CAM2+6=V5YvuxB+EyN4iH=GbD-XTA435TCNvnDFSD--YvXs+pww@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Hi,

It looks like we do support nested GROUPING SETS, I mean Sets withing
Sets, not other types. However this nesting is broken.

Here is the simple example where I would expect three rows in the
result. But unfortunately it is giving "unrecognized node type"
error. Which is something weird and need a fix.

postgres=# create table gstest2 (a integer, b integer, c integer);
postgres=# insert into gstest2 values (1,1,1), (1,1,1), (1,1,1),
(1,1,1), (1,1,1), (1,1,1), (1,1,2), (1,2,2), (2,2,2);
postgres=# select sum(c) from gstest2
group by grouping sets((), grouping sets((), grouping sets(())))
order by 1 desc;
ERROR: unrecognized node type: 926

I spend much time to understand the cause and was looking into
transformGroupingSet() and transformGroupClauseList() function.
I have tried fixing "unrecognized node type: 926" error there,
but later it is failing with "unrecognized node type: 656".

Later I have realized that we have actually have an issue while
flattening grouping sets. If we have nested grouping sets like
above, then we are getting GroupingSet node inside the list and
transformGroupClauseList() does not expect that and end up with
this error.

I have tried fixing this issue in flatten_grouping_sets(), after
flattening grouping sets node, we need to concat the result with
the existing list and should not append. This alone does not
solve the issue as we need a list when we have ROW expression.
Thus there, if not top level, I am creating a list now.

Attached patch with few testcases too.

Please have a look.

Thanks

--
Jeevan B Chalke
Principal Software Engineer, Product Development
EnterpriseDB Corporation
The Enterprise PostgreSQL Company

Attachment Content-Type Size
gsets_fix_unrecognized_error_bug.patch text/x-diff 4.6 KB

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2015-07-15 15:28:20 Re: BUG #13501: Bug with subqueries in WHERE clause
Previous Message me 2015-07-15 11:12:47 BUG #13501: Bug with subqueries in WHERE clause

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhaomo Yang 2015-07-15 13:53:30 Re: Implementation of global temporary tables?
Previous Message Pavel Stehule 2015-07-15 13:30:06 Re: Implementation of global temporary tables?