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 1pCSJB-00020Z-Oz for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Jan 2023 21:25:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pCSJA-0007NI-IF for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Jan 2023 21:25:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pCSJA-0007N9-99 for pgsql-hackers@lists.postgresql.org; Mon, 02 Jan 2023 21:25:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pCSJ8-0002l6-8m for pgsql-hackers@postgresql.org; Mon, 02 Jan 2023 21:25:23 +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 302LPJnC1650236; Mon, 2 Jan 2023 16:25:19 -0500 From: Tom Lane To: Richard Guo cc: PostgreSQL-development , David Rowley Subject: Re: An oversight in ExecInitAgg for grouping sets In-reply-to: References: Comments: In-reply-to Richard Guo message dated "Tue, 27 Dec 2022 15:12:17 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1650234.1672694719.1@sss.pgh.pa.us> Date: Mon, 02 Jan 2023 16:25:19 -0500 Message-ID: <1650235.1672694719@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > On Thu, Dec 22, 2022 at 2:02 PM Richard Guo wrote: >> If it is an empty grouping set, its length will be zero, and accessing >> phasedata->eqfunctions[length - 1] is not right. > Attached is a trivial patch for the fix. Agreed, that's a latent bug. It's only latent because the word just before a palloc chunk will never be zero, either in our historical palloc code or in v16's shiny new implementation. Nonetheless it is a horrible idea for ExecInitAgg to depend on that fact, so I pushed your fix. The thing that I find really distressing here is that it's been like this for years and none of our automated testing caught it. You'd have expected valgrind testing to do so ... but it does not, because we've never marked that word NOACCESS. Maybe we should rethink that? It'd require making mcxt.c do some valgrind flag manipulations so it could access the hdrmask when appropriate. regards, tom lane