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 1xQHw1-00000001IEW-3dkI for pgsql-bugs@arkaria.postgresql.org; Mon, 09 Nov 2026 05:28:51 +0000 Received: from localhost ([127.0.0.1]:53010 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xQHw2-000000089VL-0l2s for pgsql-bugs@arkaria.postgresql.org; Mon, 09 Nov 2026 05:28:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:36142) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xQHw1-000000089VC-0mib for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 05:28:49 +0000 Received: from fhigh-b5-smtp.messagingengine.com ([202.12.124.156]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xQHvx-000000019mr-1L9Z for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 05:28:48 +0000 Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailfhigh.stl.internal (Postfix) with ESMTP id 106717A011C for ; Mon, 9 Nov 2026 00:28:42 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 09 Nov 2026 00:28:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1794202121; x=1794288521; bh=kRpDdY1skg pt2z2MAvsK6FfguDqmFNyGxDLq2yugXLU=; b=MqQp+1TZZoaT8qBH02id017fW4 MjQbcF6JiKEuj10uezj+UndC+hGrI35zZD2CtmqXc1PiDHHeyTRUKhSeOFm9dNLB zhqPipJpR2UJAgrPyBxHUkjgqvadLGmamST1CsTFMTDRoB5ubIQunV6a/qFBvoIi ujOGsyBwrKEKH9R0sIEg5OYs0H21NU4Q3ZqVwmWRj0k96tbqsvEZXAIq965R26cW JS1Fce+7Ii9Ky6rNPmJWOlWtZbFzFO41HJ2jeUXGgoP+GyhsvH5F+1/GWHCJ/Hgn 5069Udzz3i4Zq67MDtXAUg/1G5zYlfHZVavFgoL/aX1xG7ChRHG9WIW1Ovyw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1794202121; x=1794288521; bh=kRpDdY1skgpt2z2MAvsK6FfguDqmFNyGxDL q2yugXLU=; b=gfW/MYArjLmQ3vKLwiX1+xatTe0pc2KET7NFy0zqwCaSESuLm7e Ky2w3xFV3RVnkU81JQt3GBhuwiBjd1mo6LiOsGf03F3QqMA8mjRoVbSUSt/1x00K kZozd+yQoNcxWFNkyGi/goG7xlrp6T9DVOvxMS5zys0EGq+7d7fNgwqpxbpKOE1j fs3JY0qQKCijQt+htI68i/Go5OeD/QzMytfmKXng2izDNaBhagTdmdQYsDjEYvCD IstgNgtnGfsHdgz5sPKCL/yEWuq2vCWX54H8Nys5rPo/tKWixpsfMsiRDLL/+dFf dI5JYLFqGDXEXZ/789Ri1i21OyS7u/yw1QQ== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=paquier.xyz a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1794202121; d=paquier.xyz; mf=PG1pY2hhZWxAcGFxdWllci54eXo+; rt=PHBnc3FsLWJ1Z3NAbGlzdHMucG9zdGdyZXNxbC5vcmc+; s=fm3:rsa-sha256:Rvxtfl7kc/vLsoWfaIPO/RFEjejeDIJ7X3Wtiwvm/iVjyrd wT7D9ujbmYncLIbYkSNL9HIwWW0B7OffBFCS3D1B2sOlvYZCNb4fLcanbgJ5Fa5S XnhpNBOUOPKa4jKlhA944BEVLCwnCzBsieXb2lLY8/kwp13jI6Sz0yS6ntAQNiwl Cx8J+WQE/eeNe6JquvRsDN2riA4jzyktKq5WIqmRCKbDNebcszESwhGzm2GsiLxU shsFteivEfpQo7x163i1LBw1OEWnkPL/t624MvEfIPY8SFUboqBFLSTvtYcB62Wz 1olzqHl80bnAj0RnMwHSeGuLHJ2j8w2xoGgM59g==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-disposition,content-type,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:IPjdra6J01xkNoJgQ1S5rgx/Pr7SXxj7LAxbH9zpsz0=:q+mVEAS/jfmtk3OlbulHjckKq3SJ8zV1TQuU9c/MIrs=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFex9Qz/j9PXRQ9eea0yR20Y0t8bIVQtIXmDklCgdwnJnYobHume+yy0PUTGkYi27 4Vg0GkSo2ctPiOB+J1aIx+eevH9xkuISBbuMkVJxOyiiFxwYAeiZOeiGRdV2Ba+MAmgM4F S0S3Tzhm22kEyBlsg0VZQ1zBBlucLw04LOc6sYvRWRXGtXBSl+VlxbgkyVbyi4qq0DC1Vj uCIfuVUgG5g//dEvw/fm2fq9cLNRrMIrqh51Ma7gXDGbU7jpTYzhfs/nza8swpQu9VBUD8 2/4FBIFP46k5klXd26vK5QnQSrQQhBUji6Obl4HEGdKrIFoorH1xcKRqDgGk8iwZJvYlrA 2A0cOjTPTzS2+85Uo2SFEZj8kgnMfsukEBOIZ9/rUt+bsBIzq58F3qZ6Ms2aO3MSnph8hN 9aBJ8UQb/R/3oy/WTAR0Xwa/mkitf8Z8AREgMbLZ6yOYeMTpWVjaugSnQXuQc4mN0FMn05 t+w1/HN5li0ERJWOEKbcHt0yJFqEdgA6Yye/MpgRMvN+Sfn7W0UaAFDjjOQTcQ5GNf6rky DILna3xIQ5uO75u2eeQIDCwxOCJ9zBhKYcnXY53ITiEN4tPYqY7nvJedoD9UZCgh7uRrYW qkIV20U7kMhwoW9DkBhXQmwiHUCtQZIgg/0+d4zRIMR/K+cV03aNK4G0fAEw X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 9 Nov 2026 00:28:39 -0500 (EST) Date: Mon, 9 Nov 2026 14:28:37 +0900 From: Michael Paquier To: 303677365@qq.com, pgsql-bugs@lists.postgresql.org Cc: Corey Huinker Subject: Re: BUG #19842: pg_restore_extended_stats() rejects a faithful pg_dump of ANALYZE-produced range expression statisti Message-ID: References: <19842-ca042326dd2430a4@postgresql.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="gyR6XT+l5PmNnWG7" Content-Disposition: inline In-Reply-To: <19842-ca042326dd2430a4@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --gyR6XT+l5PmNnWG7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Nov 07, 2026 at 04:22:06AM +0000, PG Bug reporting form wrote: > When an extended-statistics object has an expression of a range/multirange > type, and fewer than 2 non-empty range values are sampled by ANALYZE (a > 2-row table, or a column where most ranges are empty), > `compute_range_stats()` still produces a statistics slot whose only range > field is `range_empty_frac`. This is legal and intentional: > `pg_stats_ext_exprs` exposes it, and `pg_dump --statistics-only` therefore > emits a `pg_restore_extended_stats()` call whose `exprs` JSON contains on= ly > `range_empty_frac` (no `range_length_histogram`, no > `range_bounds_histogram`). >=20 > The restore side rejects exactly this input with a WARNING (and returns > false), so on restore/pg_upgrade the expression statistics are silently > lost. The planner then has no `range_empty_frac` and wrongfully assumes "= no > empty ranges", producing wrong selectivity/row estimates. You are not mentioning the attribute case, that exists down to v18: CREATE TABLE promo (id int, valid int4range); INSERT INTO promo SELECT i, CASE WHEN i =3D 1 THEN int4range(1, 100) ELSE 'empty' END FROM generate_series(1, 10000) i; ANALYZE promo; SELECT range_length_histogram, range_empty_frac, range_bounds_histogram FROM pg_stats WHERE tablename =3D 'promo' AND attname =3D 'valid'; This generates the following dump data: SELECT * FROM pg_catalog.pg_restore_attribute_stats( 'version', '200000'::integer, 'schemaname', 'public', 'relname', 'promo', 'attname', 'valid', 'inherited', 'f'::boolean, 'null_frac', '0'::real, 'avg_width', '6'::integer, 'n_distinct', '-1'::real, 'range_length_histogram', '{}'::text, 'range_empty_frac', '0.9999'::real); And once a restore is attempted: WARNING: 22023: "range_length_histogram" must be a one-dimensional array LOCATION: statatt_build_stavalues, stat_utils.c:627 pg_restore_attribute_stats ---------------------------- f (1 row) Hence the extstats case has just been copy-pasting the same rule as previously, because we have the same 1-dimensional array requirement. In order to do something about that, we would need to allow a case in the restore paths where empty arrays are OK on an option-basis. That means touching array_in_safe() and statatt_build_stavalues(), or change their interfaces. Invasive, but after seeing 261f89a976bf I am afraid that we have to fix that especially for the MCEs. range_bounds_histogram should be mostly esoteric in this case, no? Still it seems good to make consistent choices across the board, especially as the range bound histograms require the same fixes. Corey, what's your take? -- Michael --gyR6XT+l5PmNnWG7 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmrxWgUACgkQnvQgOdby QH2Mgg/5AXfu9yuDfHsfGQMcfoIVJEhYD0JwN7IF3ps+BaqfhFQPIj/58ftEcS6V D6wKgTM8pBTBkBH36CjBZVpInShoBqyjIYEp2zj5bZof/d1lYMoG/2muiShmai4d fP6n0JkKvQO7WdqPCkSkLcD5gOrggi7AijkdLTxjogZlKDOh0GNNlFl3R0OMI4e/ YFR9xJvK4h783Sy8PkMBBqWvjENQ8ySx5vlw0zizZsldIo41bpD0h8CtBZdF5ENp RLU7eQ95QzbuDWBwp4brns70gZLM+YJcvcpnzlGqabaP3kCt9sja7gI5Itb/qLbD fNr781WvFT1HcS09UhtGxTIeG4ySsq2dwDVoF6/Gv2VqdCI5LlSRbHYjhoL3ERDo h7m67bmSAU1/8YR2Nebz+359cMVN25nkzzdkg2AxghWddv4ybG5OVxJbmszJy1Z4 8UAgHDJLAlI3zAK2nPLaiPZdfjbToLo0MsJ+nK6Wm85TVNaJJXQhYAxCMX2nwr1E Y5e0DJuuQIKBd5brxzKkUYPqmcDtQ8xyaRCQlKKIKzdBe/6u08bTkqdmyo1k+DSp 3B0nmFjXBjrE4HpFb6J6TG3At9kN6BDtNMc0ix7XulzW8fv5yrSf1fHzXHmYT28Q l+q2NxuPUC/RqzSPW2w9FkrAx7rntUs0Pjv5Wg9vs5ub404i1HU= =oj7M -----END PGP SIGNATURE----- --gyR6XT+l5PmNnWG7--