Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xEuRx-00000001Ksq-0fEV for pgsql-bugs@arkaria.postgresql.org; Thu, 08 Oct 2026 20:10:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xEuRv-0000000E1Tt-3nCK for pgsql-bugs@arkaria.postgresql.org; Thu, 08 Oct 2026 20:10:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xEuRv-0000000E1Tb-2gGo for pgsql-bugs@lists.postgresql.org; Thu, 08 Oct 2026 20:10:43 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xEuRt-000000012iK-0obK for pgsql-bugs@lists.postgresql.org; Thu, 08 Oct 2026 20:10:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 698KAdRL2533536; Thu, 8 Oct 2026 16:10:39 -0400 From: Tom Lane To: Andrey Rachitskiy cc: mertkul669@gmail.com, pgsql-bugs@lists.postgresql.org, Richard Guo 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: References: <19752-928339cd23b58a33@postgresql.org> <2530849.1791487908@sss.pgh.pa.us> Comments: In-reply-to Andrey Rachitskiy message dated "Fri, 09 Oct 2026 00:48:05 +0500" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2533534.1791490239.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 08 Oct 2026 16:10:39 -0400 Message-ID: <2533535.1791490239@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrey Rachitskiy writes: > пт, 9 окт. 2026 г. в 00:32, Tom Lane : >> 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