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 1smgzf-007cqR-Sz for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Sep 2024 21:59:52 +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 1smgzd-004lHN-VM for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Sep 2024 21:59:50 +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 1smgzd-004lE8-9A for pgsql-hackers@lists.postgresql.org; Fri, 06 Sep 2024 21:59:49 +0000 Received: from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1smgzW-000V83-MS for pgsql-hackers@lists.postgresql.org; Fri, 06 Sep 2024 21:59:48 +0000 Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-5df9a9f7fe2so1709271eaf.2 for ; Fri, 06 Sep 2024 14:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1725659981; x=1726264781; darn=lists.postgresql.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8JVlg5Hpk411ndUjMPU2Qw5NmTv1XoaGt47cqtYZ9bw=; b=P97YwV2wgDDh7Qnzw1UXDQRyUhrO09VyY7c1JV0QMvuIO83dHM4UMgPrI7HaO5VKjl C1KdJL7JXcgLhQBymUhbo+NRbKo0mEOFe/Ux9aKiZVSmhIZT0gWH5rDvCRFGzkqghSrE HkxtQlYjqHkxhx36M8XiS/pjIzM/qoUov/gK0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725659981; x=1726264781; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8JVlg5Hpk411ndUjMPU2Qw5NmTv1XoaGt47cqtYZ9bw=; b=ZF4jAYVik4Vc6EL4kTtXNts3g5r9Yvzqw9DVqkabnd9eCsYSXEV0xKw757DuFOBSkY Bnj/rQGe2dmorA/EEHuPVGhLtugIQ2fInTTA6yJGjEFSpd9+xuX2Ys+nwUpX+ESe2E42 41aHSg7/dXp2lI3aDE4YjBI+uE4kjmLChyuyo9Vzt51SDG7/zpnuY7yeu4rnRuyrg1ZD Y7SfswGa9AKvLYrhKmrpmNApnAp8zpa/4G/tcMCeOQwnrV+CbPrY6vVW9zCSPrCXI2U5 VOyilo9BzeQTGdw9fduDJadajkWPK0Uyj3ldUm7QTUSEr3oMB1ZTq4vMyQZY3KwmQa7t IIPw== X-Forwarded-Encrypted: i=1; AJvYcCXorzx8Pf2Khawe+xL4CSfr3j/piNiBdmlnqYcmeEyANF3iJLPEEY6ZkFOGmkpGyRy0RyJ9m48rYL90224m@lists.postgresql.org X-Gm-Message-State: AOJu0Ywga9NRN2YrofBAmgvoPJiuSTtGejxZC+GlX1YNUAn2b9bIWdLt DmXh8gJfmR9U4iR+syyKPha5+WExO3due5S5ZpZ/FgQP8eDufK9DfFSFfdtaRg== X-Google-Smtp-Source: AGHT+IG4Mniu171buhqMY1bWsDEvo/H4IbtYtrEftO8I91W94R+8LBCpGENAIszeMZsx9r4UU9WbAA== X-Received: by 2002:a05:6820:504:b0:5ce:f75b:1755 with SMTP id 006d021491bc7-5e1a9cefa0cmr4853102eaf.4.1725659981024; Fri, 06 Sep 2024 14:59:41 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-710d9db35a5sm4693a34.59.2024.09.06.14.59.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Sep 2024 14:59:40 -0700 (PDT) Date: Fri, 6 Sep 2024 14:59:37 -0700 From: Noah Misch To: Masahiko Sawada Cc: Joe Conway , Peter Eisentraut , Tom Lane , 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 Message-ID: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Sep 06, 2024 at 02:07:10PM -0700, Masahiko Sawada wrote: > On Fri, Aug 30, 2024 at 8:10 PM Noah Misch wrote: > > On Thu, Aug 29, 2024 at 03:48:53PM -0500, Masahiko Sawada wrote: > > > On Sun, May 19, 2024 at 6:46 AM Noah Misch wrote: > > > > If I were standardizing pg_trgm on one or the other notion of "char", I would > > > > choose signed char, since I think it's still the majority. More broadly, I > > > > see these options to fix pg_trgm: > > > > > > > > 1. Change to signed char. Every arm64 system needs to scan pg_trgm indexes. > > > > 2. Change to unsigned char. Every x86 system needs to scan pg_trgm indexes. > > > > > > Even though it's true that signed char systems are the majority, it > > > would not be acceptable to force the need to scan pg_trgm indexes on > > > unsigned char systems. > > > > > > > 3. Offer both, as an upgrade path. For example, pg_trgm could have separate > > > > operator classes gin_trgm_ops and gin_trgm_ops_unsigned. Running > > > > pg_upgrade on an unsigned-char system would automatically map v17 > > > > gin_trgm_ops to v18 gin_trgm_ops_unsigned. This avoids penalizing any > > > > architecture with upgrade-time scans. > > > > > > Very interesting idea. How can new v18 users use the correct operator > > > class? I don't want to require users to specify the correct signed or > > > unsigned operator classes when creating a GIN index. Maybe we need to > > > > In brief, it wouldn't matter which operator class new v18 indexes use. The > > documentation would focus on gin_trgm_ops and also say something like: > > > > There's an additional operator class, gin_trgm_ops_unsigned. It behaves > > exactly like gin_trgm_ops, but it uses a deprecated on-disk representation. > > Use gin_trgm_ops in new indexes, but there's no disadvantage from continuing > > to use gin_trgm_ops_unsigned. Before PostgreSQL 18, gin_trgm_ops used a > > platform-dependent representation. pg_upgrade automatically uses > > gin_trgm_ops_unsigned when upgrading from source data that used the > > deprecated representation. > > > > What concerns might users have, then? (Neither operator class would use plain > > "char" in a context that affects on-disk state. They'll use "signed char" and > > "unsigned char".) > > I think I understand your idea now. Since gin_trgm_ops will use > "signed char", there is no impact for v18 users -- they can continue > using gin_trgm_ops. Right. > But how does pg_upgrade use gin_trgm_ops_unsigned? This opclass will > be created by executing the pg_trgm script for v18, but it isn't > executed during pg_upgrade. Another way would be to do these opclass > replacement when executing the pg_trgm's update script (i.e., 1.6 to > 1.7). 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 "unsigned 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_unsigned, 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 first. (In back branches, the C code behind gin_trgm_ops_unsigned could just raise an error if called.) What other options exist? I bet there are more.