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 1xMgsh-000000029Tu-3qGx for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 07:18:32 +0000 Received: from localhost ([127.0.0.1]:51180 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xMgsf-00000008qJl-26rB for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 07:18:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:47312) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMK8Q-000000035KE-1pJc for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 07:01:14 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMK8O-00000001Y4W-0IgG for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 07:01:14 +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=WeneNoAI3YJPkK8jOy5MtXyMyANTbFu1Dhc5aBcUkuA=; b=xPLGzKV59KyZZly7uVVghZMfRh 1oaVZVFiOZCavSejA/LYkl/WpdH4502TyR7t0IqugspD4sZyHdVNCnrfKtv/Vj2z9uf4W+5KOxv6p 5jyi8W6Je7UVmCgEgL9o+d6Pv7OVm1ArOovYlgEzTHgm71kU9HF3VpDZqc6WVX01k+tlKt/+SDFPR J05kDmT9fUA5fJhBJTpJeLM3zDLerwIMWFx4enDj6vTH8ikwbmIdVKPPiBcKurjCKPLHgol9Ooetj ySH28Bya43swgDgJIerzKP1FwbiKrjn+5Jj7l/772Sjwb73+u2xl2bpt0AXJ1DNPgYt/gQegTOZd9 8kxLi9sQ==; 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 1xMK8L-00000004ICU-2H0w for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 07:01:10 +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 1xMK8E-00000005dId-1qLF for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 07:01:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19814: pg_restore_attribute_stats: MCV accepted without eq operator; ANALYZE range slot rejected To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 303677365@qq.com Reply-To: 303677365@qq.com, pgsql-bugs@lists.postgresql.org Date: Thu, 29 Oct 2026 07:00:28 +0000 Message-ID: <19814-5005fc464c4ef1ea@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: 19814 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: 18.6 Operating system: Linux x86_64 Description: =20 Two defects in pg_restore_attribute_stats(), in opposite directions: one check is missing (invalid statistics are accepted), one check is too strict (statistics that ANALYZE itself produces are rejected). Both reproduce on the official postgres:latest docker image (18.6). 1. MCV statistics are accepted for types with no default equality operator CREATE TABLE jt (j json, p point) WITH (autovacuum_enabled =3D false); INSERT INTO jt SELECT ('{"k":'||(g%5)||'}')::json, point(g%5,g%5) FROM generate_series(1,300) g; ANALYZE jt; ANALYZE produces no statistics slot for these columns (stakind1 =3D 0 - no default btree/hash opclass). Restoring MCV values is nevertheless accepted: SELECT pg_restore_attribute_stats( 'schemaname', current_schema()::text, 'relname', 'jt', 'attname', 'j', 'inherited', false, 'most_common_vals', '{"1","2"}'::text, 'most_common_freqs', '{0.4,0.4}'::real[]); -> true (no warning) The result is a STATISTIC_KIND_MCV slot (stakind1 =3D 1) with staop1 =3D 0 (InvalidOid) - a state ANALYZE can never produce - and pg_stats now reports most_common_vals for the column. The sibling checks in the same function behave correctly on the same column: histogram_bounds -> WARNING: could not determine less-than operator ... -> false most_common_elems -> WARNING: could not determine element type ... -> false Only the MCV path lacks the equality-operator (eq_opr) guard. 2. The range_empty_frac-only slot that ANALYZE produces cannot be restored CREATE TABLE w1 (r int4range) WITH (autovacuum_enabled =3D false); INSERT INTO w1 SELECT 'empty'::int4range FROM generate_series(1,20000) g; ANALYZE w1; ANALYZE produces a STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM slot with stavalues1 =3D NULL (no length histogram; the sample has fewer than two non-empty ranges) and stanumbers1 =3D {1} (the empty fraction): SELECT stakind1, stavalues1 IS NULL AS vals_null, stanumbers1 FROM pg_statistic WHERE starelid =3D 'w1'::regclass; -> stakind1 =3D 6, vals_null =3D t, stanumbers1 =3D {1} pg_restore_attribute_stats() requires range_length_histogram to be specified whenever range_empty_frac is, so restoring exactly the values ANALYZE produced fails: SELECT pg_restore_attribute_stats( 'schemaname', current_schema()::text, 'relname', 'w1', 'attname', 'r', 'inherited', false, 'null_frac', , 'avg_width', <...>, 'n_distinct', <...>, 'range_empty_frac', ); WARNING: argument "range_length_histogram" must be specified when argument "range_empty_frac" is specified -> false and the statistics row ends up empty - the slot is lost. Restoring the same row without the range arguments succeeds (returns true), confirming that the range pairing rule is what rejects it. The export/restore round trip therefore loses statistics that ANALYZE itself computed - for example in the pre-ANALYZE step of an upgrade, where the target has no statistics row yet. Note: when passing these arguments, use values that are already of type real (e.g. carried through a table or a subquery); untyped numeric literals raise unrelated "has type numeric, expected type real" warnings.