pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: mertkul669@gmail.com
Cc: pgsql-bugs@lists.postgresql.org, Richard Guo <guofenglinux@gmail.com>
Subject: Re: BUG #19752: GROUP BY on a constant and a cast to a length-limited array type crashes the server while planning
Date: Thu, 08 Oct 2026 15:31:48 -0400
Message-ID: <2530849.1791487908@sss.pgh.pa.us> (raw)
In-Reply-To: <19752-928339cd23b58a33@postgresql.org>
References: <19752-928339cd23b58a33@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> I found a planner crash (SIGSEGV) in PostgreSQL 18 with the following
> query:

> SELECT ARRAY[]::varchar(500)[]
> GROUP BY CAST('true' AS boolean);

> Cause
> For ARRAY[]::varchar(500)[], the parser builds an ArrayCoerceExpr whose
> elemexpr is a per-element template:
> varchar(CaseTestExpr, 500, true)
> where the final "true" is the internal isExplicit flag.
> substitute_grouped_columns_mutator() in parse_agg.c replaces any
> subexpression that equal()s a GROUP BY expression with a Var referencing
> the RTE_GROUP RTE. It also descends into elemexpr. The GROUP BY
> expression is Const(bool, true), and the internal isExplicit flag is also
> Const(bool, true), so the flag is wrongly replaced by a Var. (Dumping
> elemexpr at the point of failure on 18.4 shows the third argument is a
> VAR rather than a CONST.)

Yeah, that's nasty, and what's nastier is that even non-crash cases
might result in seriously wrong answers.  We shouldn't be replacing
constant subexpressions by group Vars ever.  I'm inclined to think
that GROUP BY items should not be candidates for this
search-and-replace unless they contain at least one level-zero Var.
But maybe that's too simplistic?

			regards, tom lane






view thread (11+ messages)  latest in thread

Message-ID: <2530849.1791487908@sss.pgh.pa.us>
Permalink:  ../2530849.1791487908@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2530849.1791487908@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, mertkul669@gmail.com, guofenglinux@gmail.com
  Subject: Re: BUG #19752: GROUP BY on a constant and a cast to a length-limited array type crashes the server while planning
  In-Reply-To: <2530849.1791487908@sss.pgh.pa.us>
  References: <19752-928339cd23b58a33@postgresql.org> <2530849.1791487908@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox