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.94.2) (envelope-from ) id 1t1Ep0-00FJC3-35 for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Oct 2024 00:56:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t1Eoy-00DV4o-BL for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Oct 2024 00:56:56 +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.94.2) (envelope-from ) id 1t1Eoy-00DV3m-30 for pgsql-bugs@lists.postgresql.org; Thu, 17 Oct 2024 00:56:56 +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.94.2) (envelope-from ) id 1t1Eow-001H44-0Z for pgsql-bugs@lists.postgresql.org; Thu, 17 Oct 2024 00:56:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 49H0uqjV508108; Wed, 16 Oct 2024 20:56:52 -0400 From: Tom Lane To: Amit Langote cc: Tender Wang , Michael Paquier , exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18657: Using JSON_OBJECTAGG with volatile function leads to segfault In-reply-to: References: <18657-1b90ccce2b16bdb8@postgresql.org> <71060.1729088799@sss.pgh.pa.us> Comments: In-reply-to Amit Langote message dated "Thu, 17 Oct 2024 09:38:04 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <508106.1729126612.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Wed, 16 Oct 2024 20:56:52 -0400 Message-ID: <508107.1729126612@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Amit Langote writes: > On Wed, Oct 16, 2024 at 11:26 PM Tom Lane wrote: >> Would it be better for parse analysis to explicitly NULL out this >> field once it's done looking at it? Carrying unmaintained pieces >> of an expression tree around seems both inefficient and prone to >> future failures of this same ilk. The further the raw_expr gets >> out of step with current reality, the worse the hazards. > It seems we can't do that in this case, because get_rule_expr() wants > to read it. I think you just increased my level of concern. Aren't you saying that get_rule_expr is likely to deliver utter garbage, because it will be working from an expression that has not tracked transformations made to other parts of the tree? Also, I see that ruleutils is applying get_rule_expr to raw_expr, which AFAICT means it's *not* raw-parser output, else that wouldn't work at all. Which means the field is badly named and incorrectly documented. But in particular it means you cannot just make the tree-walking routines ignore it --- you *must* update it during transformations such as subquery pullup, or you will have garbage that will cause EXPLAIN to crash or at least produce wrong results. In other words, the proposed patch is dangerously wrong. I suspect at this point that the true bug might be the opposite: somebody feeling that they could dispense with updating raw_expr when they shouldn't. In particular, I think "... is not evaluated by eval_const_expressions_mutator()" is already a huge red flag. There are transformations that eval_const_expressions does that are not optional. regards, tom lane