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.96) (envelope-from ) id 1vrLtA-00GZUr-0R for pgsql-bugs@arkaria.postgresql.org; Sat, 14 Feb 2026 20:05:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vrLt7-000Bf9-1S for pgsql-bugs@arkaria.postgresql.org; Sat, 14 Feb 2026 20:05:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vrLt7-000Bf1-0T for pgsql-bugs@lists.postgresql.org; Sat, 14 Feb 2026 20:05:09 +0000 Received: from mail-dy1-x132b.google.com ([2607:f8b0:4864:20::132b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vrLt4-00000000ggi-15Fl for pgsql-bugs@lists.postgresql.org; Sat, 14 Feb 2026 20:05:08 +0000 Received: by mail-dy1-x132b.google.com with SMTP id 5a478bee46e88-2b8095668ebso163137eec.2 for ; Sat, 14 Feb 2026 12:05:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771099504; cv=none; d=google.com; s=arc-20240605; b=erYxzDbnTlUpS5Xz4LLacluEWTs/AmQrZLZBjS+0/TTV6bek7i+WDJm+gd6cDk2FkP WBq/6uowFX2ob5zoyE15nOmjo+dm4cGO26W5fNvoERA5Pz32P9sz9Q+YlGpRWEFGSpFd f6o3xxolozq9h8lWdeopkza5oI6F8wUXzp776yimyDJI/2BbKsGZvW05LRNyTgKsSdyV TvZVd0Q1ejmkyZ/Z2copIf7MIy4U276l3Za/teh2v/aN4/cpsAGLR6woyoTQWxHbozk2 EQygAot6qNLAzxEVKohTX4c7a3jJNwi3PzLtACD/Gram1AqFTgQNU/VUxn+avqKHli3o pCdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Bvj5+uZYmjch+2TBkB2xjpJtrgL9prbC4p28EjBQbww=; fh=D2PfL8PDkMXctQhRm7EMDu150qGOwVbUU7pkdgSkpMM=; b=CFz+RpWVZYhb17POLgXxqCRbreaO0SJ2mM0ollfV07PHn8yeo9coB1rJsFdtZRnhu6 GUa/f2ZjHEggVEwtHsHEzTdsh09Bpcyy+w9KCPUkufuiTbKdGDz0JXfkDAuUWMI8earl RhtZAv9X8tCu1u9yyTrFLnO5B89oeUU42YJs0imNgwzxBhrAGMQdoBdo134yA0xLyEry u7eu+UXB0SXgu590iqD7KQZTVCUEzXZuCsmyqCJ+EghJLm8Loucv3DPKGLHmZCQ1tryr DaE8GVK8gYFpmaMvC6hzX3WzVhSEV45aBrgPvo/tTln895fv58kE+VPQBMCXQ4TIS/4F R0Uw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771099504; x=1771704304; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Bvj5+uZYmjch+2TBkB2xjpJtrgL9prbC4p28EjBQbww=; b=I9SEaQrXuJ6wjG7eAZ20W4TTQYlV2mtQ46TEmjps9ng+OzlFIE6iU9rkvLkuDhwhng DWB5fM/tp4mD+ZWnKs/pMhpP4CyKVDhq59z08dRdqNpEnI9mrQu3JMHfl1mEoi2uqOvs F6QmkcbntnwmmZO2qsTa2zR2DuwqsYMFuPGaWR8oxtuaa6E7X13XDaKFbaNNzK8660DX R1Y6n24Z8R5hA045JYr1rhiV086UJaF2B0db9na6Q9X1alpTtuZaDxUxe22vNtSFaIu0 GmokjLEf9lDul+YaTUlET8XLILxEWByXhZwwV4Og4Z1Pzfaqi1MSsQlCtfGSPWWbtutB 7igA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771099504; x=1771704304; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Bvj5+uZYmjch+2TBkB2xjpJtrgL9prbC4p28EjBQbww=; b=WVIftELQVr413VBWnEvx5ZUT+ez9B0VwipKY0XVKEaz3z12wfg9UbdH5da/HxHCGMb CNIeuHBhHwBs+Ea20w8GL+T/tICPeLxJ4HmxvHb/OczS00lW9CNi8i0xJfKRxzVM2lwi yPc9QJw4vhKdTkrXgrwxVjL7IBK3To+HmU7+sivNIErDfHaVzwZHr2VNinnOebBb4hWy tFLhKpuwf2bJwovOWkqbmbkvnodRRm9YIca8T0NvWtoFrDRDnQRaFwV142te/2WpG/KR d9cUeMESLoxF/p3/W8eXTDibxgqCRhiqUHdSIFX3/vhwPh68c0A4tp6wObplsKQhi8bw pcOQ== X-Forwarded-Encrypted: i=1; AJvYcCUkio1NMNQrKYgY8pgqgMUPVdP9HSQE8/flwfnxRZJQKKe57vnf2rjbkQRaN8MC9lnGyllfg3ewWnad@lists.postgresql.org X-Gm-Message-State: AOJu0Yyikvgd3vfzEtTxuW1kOoikHYR6hw4x9/jof/Y2cq7YKCXSoUH5 UYE/ycOLTOgvgzxgImMuvWWZtIjoYW75Y8xS9r1DzN9lKfMTIJTkKTTZ16tGhztO4vVIlP+qRK+ J1T02WL0ko25M9je+dyPfxSbN/LhvpEc= X-Gm-Gg: AZuq6aKoUHwEZiK1Or6VudU9PLEWo/Zk5RbwyJprAFtiJMKYvpInR0rgCADdAqhYl5q s+qjz70x9fBEJZnhheIG0bzGRlaiAb/DuPKeMUD0CvNEgCJWnhk5ucIkst6C+IgfkuFuLHDGT2Z wgMeBqZtvSyOfN/lqLQ4RpxR8eDvBJQ95uyrJNqBA+px6S7z+LRPZqVMMbLDR14faLAxj19DGqN 16NSBzlyW3Oqxje69u6R3l52HJKtwz1NpmxWwdwcJ8oehaHlNBh+Sgo+F2lAYXO0gpp5C788+8Y sWggyNYiCOz9kKkLtjp7+g33gJ1uzex6Ws3zrIrS3tMam+H3olJryZNZhTafhGGz8Q== X-Received: by 2002:a05:7301:3f0a:b0:2b7:1008:9f2e with SMTP id 5a478bee46e88-2baba0b549emr1448940eec.7.1771099503552; Sat, 14 Feb 2026 12:05:03 -0800 (PST) MIME-Version: 1.0 References: <19406-9867fddddd724fca@postgresql.org> <20260213172702.71@rfd.leadboat.com> <20260213224804.2c@rfd.leadboat.com> <20260214002113.1f.noahmisch@microsoft.com> <20260214053821.fa.noahmisch@microsoft.com> <20260214193344.48@rfd.leadboat.com> In-Reply-To: <20260214193344.48@rfd.leadboat.com> From: Thomas Munro Date: Sun, 15 Feb 2026 09:10:00 +1300 X-Gm-Features: AaiRm52XpKPS3WhLEg41FCMiGpBKb_ooHu0rtDFPE814SM7PDYlE2_0AqfIyDkg Message-ID: Subject: Re: BUG #19406: substring(text) fails on valid UTF-8 toasted value in PostgreSQL 15.16 To: Noah Misch Cc: ranvis@gmail.com, pgsql-bugs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Feb 15, 2026 at 8:33=E2=80=AFAM Noah Misch wrot= e: > - slice_len is the amount *returned* from the toaster. It's nonnegative. Ah, right, that makes more sense. > > The outline I had come up with before seeing your patch was: let's > > just delete it. The position search can check bounds incrementally, > > following our general approach. This avoids the reported problem by > > ditching the pre-flight scan through the slice (up to 4x more > > pg_mblen_XXX calls and memory access than we strictly need), and also > > the special cases for empty strings since they already fall out of the > > general behaviour (am I missing something?), not leaving much code > > behind. > > Like you, I made a note that it's wasteful to make two mblen passes over = the > string. I'm only seeing a 50% reduction in mblen calls, not an 80% reduc= tion, > but I didn't look too closely. I guessed such a change would be less cle= arly > correct, so I figured it would be less suitable for back branches. Hence= , I > didn't draft it. I was comparing to unpatched master, but yeah of course your patch already gets part of the way there. > My first impression, hurried due to the commit ETA in 30 minutes, is that= this > is less conservative and should hold for master-only. Got it. Will add it to the pile of master-only fallout from this area.