Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o5Rxz-00075r-C0 for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Jun 2022 13:06:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o5Rxx-0007K4-T8 for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Jun 2022 13:06:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o5Rxx-0007Jv-KB for pgsql-hackers@lists.postgresql.org; Sun, 26 Jun 2022 13:06:17 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o5Rxt-0001pR-S7 for pgsql-hackers@lists.postgresql.org; Sun, 26 Jun 2022 13:06:16 +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 25QD6BQE1349485; Sun, 26 Jun 2022 09:06:11 -0400 From: Tom Lane To: Dean Rasheed cc: PostgreSQL Hackers Subject: Re: Core dump in range_table_mutator() In-reply-to: References: <545569.1656107045@sss.pgh.pa.us> <631351.1656128349@sss.pgh.pa.us> Comments: In-reply-to Dean Rasheed message dated "Sat, 25 Jun 2022 11:20:09 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1349483.1656248771.1@sss.pgh.pa.us> Date: Sun, 26 Jun 2022 09:06:11 -0400 Message-ID: <1349484.1656248771@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dean Rasheed writes: > On Sat, 25 Jun 2022 at 04:39, Tom Lane wrote: >> Well, if we want to clean this up a bit rather than just doing the >> minimum safe fix ... I spent some time why we were bothering with the >> FLATCOPY step at all, rather than just mutating the Query* pointer. >> I think the reason is to not fail if the QTW_DONT_COPY_QUERY flag is >> set, but maybe we should clear that flag when recursing? > Hmm, interesting, but we don't actually pass on that flag when > recursing anyway. Since it is the mutator routine's responsibility to > make a possibly-modified copy of its input node, if it wants to > recurse into the subquery, it should always call query_tree_mutator() > with QTW_DONT_COPY_QUERY unset, and range_table_mutator() should never > need to FLATCOPY() the subquery. Actually, QTW_DONT_COPY_QUERY is dead code AFAICS: we don't use it anywhere, and Debian Code Search doesn't know of any outside users either. Removing it might be something to do in v16. (I think it's a bit late for unnecessary API changes in v15.) > But then, in the interests of further tidying up, why does > range_table_mutator() call copyObject() on the subquery if > QTW_IGNORE_RT_SUBQUERIES is set? I thought about that for a bit, but all of the QTW_IGNORE flags work like that, and I'm hesitant to change it. There may be code that assumes it can modify those trees in-place afterwards. Committed with just the change to use straight MUTATE, making this case exactly like the other places with QTW_IGNORE options. Thanks for the discussion! regards, tom lane