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.94.2) (envelope-from ) id 1smhZk-007gf0-W6 for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Sep 2024 22:37:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1smhZj-005IwM-DQ for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Sep 2024 22:37:07 +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.94.2) (envelope-from ) id 1smhZi-005Ivp-V5 for pgsql-hackers@lists.postgresql.org; Fri, 06 Sep 2024 22:37:07 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1smhZg-000VUa-PI for pgsql-hackers@lists.postgresql.org; Fri, 06 Sep 2024 22:37:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 486MarVT2385727; Fri, 6 Sep 2024 18:36:53 -0400 From: Tom Lane To: Noah Misch cc: Masahiko Sawada , Joe Conway , Peter Eisentraut , Alexander Korotkov , "Guo, Adam" , "pgsql-hackers@lists.postgresql.org" , Nathan Bossart , Jim Mlodgenski Subject: Re: pg_trgm comparison bug on cross-architecture replication due to different char implementation In-reply-to: <20240906215937.f7.nmisch@google.com> References: <1696557.1714498172@sss.pgh.pa.us> <2652929.1714745623@sss.pgh.pa.us> <3846ef0f-5273-41aa-a77e-f92841e0515f@eisentraut.org> <362570f3-1031-4f8e-a077-81c103200b64@joeconway.com> <20240518214546.e8@rfd.leadboat.com> <20240831031038.31.nmisch@google.com> <20240906215937.f7.nmisch@google.com> Comments: In-reply-to Noah Misch message dated "Fri, 06 Sep 2024 14:59:37 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2385725.1725662213.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 06 Sep 2024 18:36:53 -0400 Message-ID: <2385726.1725662213@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Noah Misch writes: > Yes, that's one way to make it work. If we do it that way, it would be > critical to make the ALTER EXTENSION UPDATE run before anything uses the > index. Otherwise, we'll run new v18 "signed char" code on a v17 "unsign= ed > char" data file. Running ALTER EXTENSION UPDATE early enough should be > feasible, so that's fine. Some other options: > - If v18 "pg_dump -b" decides to emit CREATE INDEX ... gin_trgm_ops_unsi= gned, > then make it also emit the statements to create the opclass. > - Ship pg_trgm--1.6--1.7.sql in back branches. If the upgrade wants to = use > gin_trgm_ops_unsigned, require the user to ALTER EXTENSION UPDATE firs= t. > (In back branches, the C code behind gin_trgm_ops_unsigned could just = raise > an error if called.) I feel like all of these are leaning heavily on users to get it right, and therefore have a significant chance of breaking use-cases that were perfectly fine before. Remind me of why we can't do something like this: * Add APIs that allow opclasses to read/write some space in the GIN metapage. (We could get ambitious and add such APIs for other AMs too, but doing it just for GIN is probably a prudent start.) Ensure that this space is initially zeroed. * In gin_trgm_ops, read a byte of this space and interpret it as 0 =3D unset 1 =3D signed chars 2 =3D unsigned chars If the value is zero, set the byte on the basis of the native char-signedness of the current platform. (Obviously, a secondary server couldn't write the byte, and would have to wait for the primary to update the value. In the meantime, it's no more broken than today.) * Subsequently, use either signed or unsigned comparisons based on that value. This would automatically do the right thing in all cases that work today, and it'd provide the ability for cross-platform replication to work in future. You can envision cases where transferring a pre-existing index to a platform of the other stripe would misbehave, but they're the same cases that fail today, and the fix remains the same: reindex. regards, tom lane