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 1xQiUd-00000000K4K-2atD for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Nov 2026 09:50:19 +0000 Received: from localhost ([127.0.0.1]:54270 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xQiUc-00000004oAu-12gr for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Nov 2026 09:50:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:53658) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xQPEH-00000001B1Y-1p60 for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 13:16:10 +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 1xQPEE-000000002MP-2oaO for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 13:16:09 +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=9YNiNJ999m/9qrfjpXbbaP1jKHvLWlfyFofk0PYCW0E=; b=NUfmap4MT7Uq1Y1bcZmCV1zera YiXXxXVnKuaQK5HS6goQSdQc5enX0ZEzJ4SSWTifL56l7d9mHfJ0Ark3Rs8Z7XjQGFFKYzZXzXL9s dIC4q3s+M7Ns0G7vomq+pfJJYaZD7ArdBdEgnNnC3+pz/E9RxO/wMfcsmQwLKOuLshplvgLeo5b1w AJ76V6M1dI6fU8lXkL7uXB0VoRHqTCWmrAT/Gs2cS79Um9HrmzyUPUl0kBW/GL9qgZXe9K4jHpaem 8FdIdwhY0lVa01yCa8rsb9g5JhUdUJVTq/6rJ3btFzvWJqjco+aZHrBRbV4+zMbXxrl5qdJeL3g/1 M7LzJlWg==; 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 1xQPEC-000000004xS-2xPU for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 13:16:05 +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 1xQPEB-00000000J6k-2omA for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 13:16:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19857: Stats restore rejects empty arrays, losing range and array stats To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 125atishprak@gmail.com Reply-To: 125atishprak@gmail.com, pgsql-bugs@lists.postgresql.org Date: Mon, 09 Nov 2026 13:15:35 +0000 Message-ID: <19857-6e808a09ff4b75d2@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: 19857 Logged by: Atish Prakash Email address: 125atishprak@gmail.com PostgreSQL version: 18.6 Operating system: Linux x86_64 Description: =20 If a range column has fewer than two non-empty values, ANALYZE stores an empty range length histogram. Restoring those statistics fails with a WARNING, so range_empty_frac is lost too, and estimates change a lot. CREATE TABLE r(a int4range); INSERT INTO r SELECT 'empty' FROM generate_series(1, 10000); ANALYZE r; Then dump with "pg_dump --statistics" and restore into an empty database: master: WARNING: "range_length_histogram" must be a one-dimensional array 18.6: WARNING: argument "range_length_histogram" must be specified when argument "range_empty_frac" is specified (message shortened) Estimates on master, with autovacuum disabled on the table so that a later ANALYZE does not replace the statistics: query actual before after SELECT * FROM r WHERE a <@ '[1,2)' 10000 10000 89 SELECT * FROM r WHERE a && '[1,2)' 0 1 178 A table with one non-empty value and 9,999 empty ones is affected the same way (estimate 9999 before, 87 after, for the first form of query, with actual 10000). Multirange columns also produce the warning. pg_upgrade loses them too: after an upgrade from 18.6 to 19rc1, range_empty_frac for table r went from 1 to NULL, and the first query above was estimated at 50 rows. On 19rc1 and master the same check rejects most_common_elems when it is empty, which commit 261f89a976 makes common. An ordinary array column with all-distinct elements is enough, and tsvector columns are affected too: CREATE TABLE tags(id int, a int[]); INSERT INTO tags SELECT i, ARRAY[i, i + 1000000] FROM generate_series(1, 50000) i; ANALYZE tags; WARNING: "most_common_elems" must be a one-dimensional array query actual before after SELECT * FROM tags WHERE a @> '{5}' 1 3 ~270 SELECT * FROM tags WHERE a && '{5,6}' 2 7 ~530 Extended statistics are hit harder on master. An empty array in one expression's statistics rejects the statistics for every expression in that object, including unrelated ones: WARNING: could not parse "exprs": invalid element in expression -1 Expected: the statistics restore as they were, without a warning. Cause: on master, pg_stats shows range_length_histogram as '{}' and pg_dump emits that. statatt_build_stavalues() requires a one-dimensional array, and an empty array has zero dimensions. On 18.6, pg_stats shows it as NULL, so pg_dump omits it while still emitting range_empty_frac, and the restore function rejects that pair. I have not written a patch. Found with dump and restore differential tests. I reproduced and checked the result myself.