Re: BUG #17480: Assertion failure in parse_relation.c

Alvaro Herrera <alvherre@alvh.no-ip.org>

From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: krking@zju.edu.cn, pgsql-bugs@lists.postgresql.org
Date: 2022-05-15T10:42:10Z
Lists: pgsql-bugs

Attachments

On 2022-May-10, Tom Lane wrote:

> Looking at the other addRangeTableEntry* functions, 
> addRangeTableEntryForJoin seems to similarly lack a defense
> against too many aliases.  Testing shows that the case is covered
> elsewhere:
> 
> regression=# select * from (int8_tbl i cross join int4_tbl j) ss(a,b,c,d) limit 2;
> ERROR:  column alias list for "ss" has too many entries
> regression=# \errverbose 
> ERROR:  42601: column alias list for "ss" has too many entries
> LOCATION:  transformFromClauseItem, parse_clause.c:1458
> 
> but this is randomly different both in the message wording and in the
> choice of ERRCODE.  I wonder if we shouldn't harmonize that, and maybe
> move detection of the case to addRangeTableEntryForJoin for consistency
> with the other cases.

That makes sense; I ended up with the attached patch, in which I also
attempt to add regression test cases to cover all the cases.

I find that the check in addRangeTableEntryForValues is dead code,
because both callers pass a NULL Alias.  I find no way to give VALUES an
alias directly.  This has annoyed me in the past (not a big deal tbh),
but that makes me refrain from suggesting to removing the code.

We do get the correct error with this query,
  select * from (values (1)) as f (a, b);
but that is coming from addRangeTableEntryForSubquery.

This is backpatchable (sans the JSON_TABLE bits).  I'll attempt to get
it pushed later today.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
"People get annoyed when you try to debug them."  (Larry Wall)

Commits

  1. Check column list length in XMLTABLE/JSON_TABLE alias