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 1xDhA5-00000000efH-1FS8 for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Oct 2026 11:47:17 +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 1xDhA4-00000009uDp-1OjY for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Oct 2026 11:47:16 +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 1xDEdq-000000043CH-1JP7 for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:20: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 1xDEdo-00000000GSr-3SmX for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:20: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=z39ZhHWcSeyrP012Q3eJ+4K7x7rXgP9xEWHw8z5Ghh0=; b=Rj5Hm8zXZwkD/oF/vKVZP8WulP DWMoISzZzNo8QoXR8ebN1Sf1nHA4GlOOSkrigZle5Xknl9H0zxV/sHUYnvMlcbw7Lejv7BjkNOF2j cfMM0y3/jiwshFKh1YBl1eZpjQmKXL4Hdozr38IaTg3JmbZ/2QkNKF4wHx2L5XCtSM/ys7v/zpYEh 5b0FYe1odJ9o76HF0KjfbFahs/fcJYJuNOM3cYuG9i7SAaTKz6Ga4Vo4DcLqt+YfOPtWY15gVNM3R d7XZwWUWj76LIgxa48zvh6kdfKz5i70UJD6VHwfQpkkDIhv99lEH/LGnA/R1U9PfeA5aow0tMU1jb FrV/fJEQ==; 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 1xDEdo-00000000uk3-1p3h for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:20: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 1xDEdn-00000002SDP-1LA1 for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:20:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19749: bpchar_ops declares equalimage although bpchar equality ignores trailing spaces To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: kehan5800@gmail.com Reply-To: kehan5800@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sun, 04 Oct 2026 05:20:01 +0000 Message-ID: <19749-d46adf7c7d910b07@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: 19749 Logged by: Ke Email address: kehan5800@gmail.com PostgreSQL version: 18.6 Operating system: Ubuntu 22.04.2 x86_64 Description: =20 bpchar_ops registers btvarstrequalimage as btree support function 4 (src/include/catalog/pg_amproc.dat:33-35). btvarstrequalimage (src/backend/utils/adt/varlena.c:2311) returns true for any deterministic collation. But bpchar equality ignores trailing spaces, so for bpchar "equal" does not imply "identical image". A bpchar column without typmod (CREATE TABLE t (c bpchar)) stores values at their own length, so such pairs can coexist in one index: SELECT 'a'::bpchar =3D 'a '::bpchar, -- t octet_length('a'::bpchar), octet_length('a '::bpchar); -- 1, 3 On an assert-enabled build, a plain CREATE INDEX hits the check in _bt_keep_natts() (src/backend/access/nbtree/nbtutils.c:882-883): CREATE TABLE t (c bpchar); INSERT INTO t SELECT x FROM generate_series(1, 500), (VALUES ('a'::bpchar), ('a '::bpchar)) v(x); CREATE INDEX ti ON t (c); TRAP: failed Assert("!itup_key->allequalimage || keepnatts =3D=3D _bt_keep_natts_fast(rel, lastleft, firstright)"), File: "nbtutils.c", Line: 882 LOG: client backend (PID ...) was terminated by signal 6: Aborted The assertion is only reached on a leaf page split, so small tables do not show it: 365 rows (730 index tuples) build fine, 370 rows abort. This is the same assertion that interval_ops tripped in 2023 (https://www.postgresql.org/message-id/20231011013317.22.nmisch@google.com), fixed by removing interval_ops' equalimage support function. In that message's audit, bpchar_ops is listed under btvarstrequalimage and was judged okay. Of the opclasses using btvarstrequalimage (bpchar_ops, text_ops for text and name, varchar_ops via text), only bpchar has an equality that ignores part of the value. Impact on a non-assert build (checked on an 18.6 build without assertions): I could not demonstrate wrong results. amcheck bt_index_parent_check(heapallindexed, rootdescend) passes, index and sequential scans agree, index-only scans return the heap's bytes, and deduplication does not merge 'a' and 'a ' (_bt_dedup_pass compares images, which differ). The demonstrated problem is a reachable Assert (developer and buildfarm builds) plus an optimisation whose stated precondition (equal implies image-equal) does not hold for this opclass. Expected: bpchar_ops does not claim equalimage, or CREATE INDEX on bpchar does not violate the nbtree invariant. Actual: allequalimage is set for bpchar indexes, and an assert-enabled server aborts on CREATE INDEX with equal-but-differently-padded values. Suggested fix (the same as for interval_ops): drop the amprocnum 4 entry for btree/bpchar_ops from pg_amproc.dat (catversion bump). As with interval_ops, existing indexes keep the allequalimage flag in their metapage, so a REINDEX note would be needed if back-patched. A typmod-dependent answer is not possible, since equalimage is called per opclass and collation, not per column.