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 1xIqHG-00000003va6-32so for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Oct 2026 16:31:58 +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 1xIqHF-000000087aZ-0poO for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Oct 2026 16:31:57 +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 1xIaDa-00000004VFv-21DN for pgsql-bugs@lists.postgresql.org; Sun, 18 Oct 2026 23:23:06 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xIaDY-00000002i86-35lI for pgsql-bugs@lists.postgresql.org; Sun, 18 Oct 2026 23:23:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=xB1PZp9cbn/4l07C06k3OS1XrA1T6sor/krlgNYmgWU=; b=3khjUGi8/OvX/KL9e5eP+SOOkN ZCqxOTrzUCBnoXZo5aOdResuxS6DY1IRiO7v2OJhUFhXZQJa5aaWbrX8rDk4s9Yk3vIkpXVIL5fTj JI9wtN8+achV3MEWG3GN5IJuLVWkctwz6pSMsCAxTW7XT5k9mYqIptfecOFWJrWGJPRjYKacbnej7 b1yJj9LDvO0VFUp//DU9DXyDDMwZJ9q/h7FN2EyMy3pU6D2PkyMtm6w3W+cUrME3tOCjQp2Q6TkPk qgU41vxWdYlU4T73mJJrnbUqSvDUftxPvZZYZoTcmD7glxnlXsDFeNlnB/inqrkl/eqhOYfpudKqs z3yxkuwQ==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xIaDY-00000007tIa-1RJ0 for pgsql-bugs@lists.postgresql.org; Sun, 18 Oct 2026 23:23:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xIaDW-00000006BoQ-47k8 for pgsql-bugs@lists.postgresql.org; Sun, 18 Oct 2026 23:23:02 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19772: ERROR: corrupt MVNDistinct entry for GROUP BY c0, ROLLUP (abs(c0)) with ndistinct statistics To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: alpkeles99@gmail.com Reply-To: alpkeles99@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sun, 18 Oct 2026 23:22:05 +0000 Message-ID: <19772-d8c886b4db230132@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19772 Logged by: Alperen Keles Email address: alpkeles99@gmail.com PostgreSQL version: 18.6 Operating system: Ubuntu 24.04 x86_64 (also macOS arm64) Description: =20 Hello, With an ndistinct extended statistics object on a table, a GROUP BY that has a plain column in every grouping set and an expression of the same column in only some of them fails at plan time: CREATE TABLE t0 (c0 int8, c1 int8); INSERT INTO t0 VALUES (NULL, NULL); CREATE STATISTICS t0_s ON c0, c1 FROM t0; ANALYZE t0; SELECT c0 FROM t0 GROUP BY c0, ROLLUP (abs(c0)); ERROR: XX000: corrupt MVNDistinct entry LOCATION: estimate_multivariate_ndistinct, selfuncs.c:4485 (18.6) CREATE STATISTICS makes ANALYZE store, among other things, the number of distinct values of each combination of two or more of the listed columns, and the planner uses those to estimate how many groups a GROUP BY yields. ROLLUP (abs(c0)) means the grouping sets (c0, abs(c0)) and (c0), so the planner estimates the group count of each set separately. The NULL row is not needed: any non-empty table that is analyzed after the statistics object is created fails the same way (for example 1000 rows of (i % 10, i % 7)), and so does EXPLAIN. The same error comes from CUBE (abs(c0)), GROUPING SETS ((c0, abs(c0)), (c0)), GROUP BY abs(c0), ROLLUP (c0), from c0 + 1, c0::text and c0::numeric instead of abs(c0), from statistics with only the ndistinct kind, on three columns, or ON c0, abs(c0), and from a view over the query. It does not happen with a plain GROUP BY c0, abs(c0), with ROLLUP (c0, abs(c0)), with GROUP BY c0, c1, ROLLUP (abs(c0)), with an expression over a different column (abs(c1), c0 + c1), with only the dependencies or mcv kinds, or before the table is analyzed. It is an ordinary ERROR; the cassert builds do not hit an assertion. Reproduced on 18.6 (REL_18_STABLE dfbc1507cdb), 19rc1 (REL_19_STABLE 1212d5d33b1) and master a261fc2b722, Ubuntu 24.04 x86_64, --enable-cassert; also on 18.6 and master on macOS arm64. 14.24 (REL_14_STABLE 14904052e65) runs all of these queries without error. Found with a query fuzzer. Regards, Alperen Keles