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 1xMgsi-000000029Tv-1mgt for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 07:18:32 +0000 Received: from localhost ([127.0.0.1]:51196 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xMgsf-00000008qJy-2Zo4 for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 07:18:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:36290) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMgZu-00000008JnH-0C05 for pgsql-bugs@lists.postgresql.org; Fri, 30 Oct 2026 06:59: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 1xMgZs-00000001ekd-1ukR for pgsql-bugs@lists.postgresql.org; Fri, 30 Oct 2026 06:59: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=cQEyFtssMAxg8WCYDui/BG+CVzmWQ5mAYgkRzP/P6lE=; b=1sag++p/ZxxbPSiSMsj6v32lad SK4nOdQ4kMi/P+O47Rkwwm0QXle141TzYNniqmW28zGCEyXnhzQN/Dzd4ucygQc0y1Ic35zvue/sL wKvVkxWfUtNCwv3OL30SmPlskBRTAyKX7rJEYInXDQpXE8yMuesYQ8ChqLa7tRK82y761pUj43Lwq 25UUId/jo3TI2hFyBn9zGdr2l7KuDkePZeJUE4cAoJ3HFm0YH7vYoqueS++rIRR3r0wX9StSOIXXw wRgXVOSq5717QxY0mtjtt8jRrHAWyf3EtczAc1ZiH4ypfWGiadPn7b8D7XUSrCUe2H6cOclquNYQT kd7Vu7sA==; 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 1xMgZs-00000004m6U-1FEB for pgsql-bugs@lists.postgresql.org; Fri, 30 Oct 2026 06:59: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 1xMgZq-000000076zX-1MJl for pgsql-bugs@lists.postgresql.org; Fri, 30 Oct 2026 06:59:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19820: ANALYZE can store empty (0-dimensional) stavalues that the statistics import functions refuse to res 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: Fri, 30 Oct 2026 06:58:56 +0000 Message-ID: <19820-5ee0f95d22b7366a@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: 19820 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: Unsupported/Unknown Operating system: Linux (TencentOS 4.4, x86_64) Description: =20 Hello, On current 20devel, ANALYZE deliberately stores an empty (zero-dimensional) array -- not NULL -- in stavalues whenever a statistics slot has no content to record (get_attstatsslot() raises an internal error on NULL stavalues, so NULL was never an option). Three producers do this: - compute_range_stats(): range_length_histogram, when fewer than two sampled ranges are non-empty (one-row table, mostly-empty ranges, or a mostly-NULL range column); - compute_tsvector_stats(): most_common_elems, when every sampled tsvector has no lexemes (all ''::tsvector); - compute_array_stats(): most_common_elems, when every sampled array is the empty array '{}' . The import side, however, requires a one-dimensional array: statatt_build_stavalues() (src/backend/statistics/stat_utils.c:620-630) rejects ARR_NDIM !=3D 1. So the statistics that ANALYZE just wrote cannot = be restored by the import functions, and the roundtrip silently drops them. Reproducer (self-contained; attribute path): CREATE TABLE e1 (tv tsvector, ia int[]) WITH (autovacuum_enabled =3D false); INSERT INTO e1 SELECT ''::tsvector, '{}'::int[] FROM generate_series(1, 50) g; ANALYZE e1; -- what ANALYZE stored (pg_stats exposes it just fine): -- most_common_elems =3D {} (zero-dimensional) -- most_common_elem_freqs =3D {0.02,0.02,0} -- feeding those exact values back is rejected: SELECT pg_restore_attribute_stats('schemaname', 'public', 'relname', 'e1', 'attname', 'tv', 'inherited', false, 'most_common_elems', '{}', 'most_common_elem_freqs', '{0.02,0.02,0}'); -- WARNING: "most_common_elems" must be a one-dimensional array -- (returns false; the slot is dropped, together with range_empty_frac -- when the range producer is involved) The extended-statistics path fails the same way and even less gracefully: pg_restore_extended_stats() reports WARNING: could not parse "exprs": invalid element in expression -N HINT: range_length_histogram/range_empty_frac/range_bounds_histogram must be all either strings or all nulls and drops the whole expression's statistics (including null_frac and avg_width), not just the offending slot. Expected: what ANALYZE writes, the import functions should accept back -- a zero-dimensional array is representable in the function's input syntax, and it is what ANALYZE itself produces. Alternatively, if 0-dim input is to stay unsupported, ANALYZE should not write it in the first place; the current combination means every statistics roundtrip (any consumer that encodes statistics as pg_restore_*() calls, e.g. pg_dump's statistics export or pg_upgrade) silently loses these slots. For reference, on 18.6 the same ANALYZE does not produce these slots at all for the tsvector/array producers (older behavior), so the asymmetry between producer and consumer is new with the 20devel behavior. Reproduced on: - PostgreSQL 20devel (snapshot of 2026-10-27, x86_64-pc-linux-gnu); attribute and extended paths, re-runs after DROP and from fresh sessions give identical results. A draft fix location would be statatt_build_stavalues() (src/backend/statistics/stat_utils.c): accept ARR_NDIM =3D=3D 0 for the element-array slots, mirroring what the producers write. Regards, Chunling Qin