pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Cc: mertkul669@gmail.com, 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 16:10:39 -0400
Message-ID: <2533535.1791490239@sss.pgh.pa.us> (raw)
In-Reply-To: <CAB8bMiuw5ytFDC9eXANQBCybdUWVX5vWYZ6hVHUZbcqo4kHsuw@mail.gmail.com>
References: <19752-928339cd23b58a33@postgresql.org>
	<2530849.1791487908@sss.pgh.pa.us>
	<CAB8bMiuw5ytFDC9eXANQBCybdUWVX5vWYZ6hVHUZbcqo4kHsuw@mail.gmail.com>

Andrey Rachitskiy <pl0h0yp1@gmail.com> writes:
> пт, 9 окт. 2026 г. в 00:32, Tom Lane <tgl@sss.pgh.pa.us>:
>> 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?

> We should still replace the grouped constant itself.  Bisect puts the
> crash at f5050f795ae ("Mark expressions nullable by grouping sets"),
> whose parent 247dea89f76 does not crash.  247dea89f76 returns on Const
> before equal().  f5050f795ae moves that return to after equal(), and
> the comment says why.  A GROUP BY constant is no longer constant after
> the grouping step.  The regress query added in that commit is

>     select 1 as one group by rollup(one) order by one nulls first;

I think that's different: the "group by one" should identify the
first TLE and nothing else.  Otherwise we have insanities like

      select 1 as one, 1+2 as three group by rollup(one)

affecting both columns.  (I see that it does not, right now,
but it's hard to argue why not if you think replacing constants
is okay.)

> Skipping every GROUP BY item that contains no level-zero Var is too
> broad.  The item in that query is a Const, so it contains no Var, and
> the commit exists to keep it a candidate.  The constants that must not
> be replaced are the other Const nodes that happen to compare equal.

We might need to special-case TLEs that are identified this way.
The basic problem is how do you tell which Consts are okay to replace,
and what I'm saying is "none of them, except the identified TLE".

			regards, tom lane






view thread (11+ messages)  latest in thread

Message-ID: <2533535.1791490239@sss.pgh.pa.us>
Permalink:  ../2533535.1791490239@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2533535.1791490239@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, pl0h0yp1@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: <2533535.1791490239@sss.pgh.pa.us>
  References: <19752-928339cd23b58a33@postgresql.org> <2530849.1791487908@sss.pgh.pa.us> <CAB8bMiuw5ytFDC9eXANQBCybdUWVX5vWYZ6hVHUZbcqo4kHsuw@mail.gmail.com> <2533535.1791490239@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