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 1uSfLJ-00BNx3-6o for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Jun 2025 17:15:57 +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 1uSfLH-003A8e-6C for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Jun 2025 17:15:55 +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.94.2) (envelope-from ) id 1uSfLG-003A8W-NU for pgsql-hackers@lists.postgresql.org; Fri, 20 Jun 2025 17:15:55 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uSfLE-003ALv-1i for pgsql-hackers@postgresql.org; Fri, 20 Jun 2025 17:15:54 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-234fcadde3eso28626095ad.0 for ; Fri, 20 Jun 2025 10:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1750439749; x=1751044549; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=rrzDEIzGRLssxIjFCjosG7ZoTuisBsm7h/CF2z1lOg8=; b=yn8MUpUGyPNou4EZAYpUA2FrFtJ2DyhA3t/UrhzVfyOXSTsEDR2D7LKnxhD9hZMBEG RoFdUF/KX546mFCr226CbPfHX4HVxqof/q4LwdhCGGeaf9Vbt8hw4K6lnl8x4GdnMhqr FUsKa2cVF8Rjdj2kDocxppO2bAUl5ulvK/iqcRc0TR3KIun4mzgWfSh2EqW4kFHDExuD krUr+DkfYr8TmGbK6UiifwEs/b2HFOT4cKORrZbWOF0yYY/BUHiRp+RKnyIFX27bbj83 ufaaebwOryoX5TrcARkVgVXh/bwoNsEHKdVshY2yYkR+oCnq3btPFwJcZ0MuK4WITPuW GaKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750439749; x=1751044549; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rrzDEIzGRLssxIjFCjosG7ZoTuisBsm7h/CF2z1lOg8=; b=S5QrgQ1Vcqfxw/HG+HrJq1MxqvdndD11v4Cwp+TbFRF/0JV2nztdK48f8gc+wW2mJ2 Ig2r/vEsXhvdBQZqrwGt44SqmAOWcY0DVX0i7UoWt3F32PCyyU7HCaxckegWSyorvlL+ Rr7q04lNf09J4VZMy00HpqRZWdQMhfrX8Sk/2TfpU/WaQBg4MWxp09PLNSbEr/6dGDM7 Qv9nU2e2Y7g9dxpsQ9XKoIOdJP/3iLs85igWNd/jzD417HkdjIf14npUfZSRU6EiUllZ 7e+e5eTJ3uF2xRJBHf3hQa1CFOTrnztu7TDZEt4vbnFt9AnSREVfARuPkZArWEvcMch8 Aj/A== X-Forwarded-Encrypted: i=1; AJvYcCWRML+K828ebwa9Re6VPvNZAflXHlxnIx45dqf0xj+51RD/T+u+qYIq76ofZ4qoTtvcTiqrfdWOSmvsg4mA@postgresql.org X-Gm-Message-State: AOJu0YzDY7l/pJMgVij3jiioccnAMBOtUrZ+TtoPi5GODZQaoh46cq0D keNjdyML5nno6kAsIuMtI9vZiYfzztpStUy929DPwaKZUx+UfL9AX2+kBfVSVsZL1w== X-Gm-Gg: ASbGncu4KOzgvSIqkq736PPYpXktJqwRYpWYO7Sbp27fHfdUbDRCmhbYOZ34VlQ0Enj rq38OG0vQw5vp7S5ptmuioASHTj6oGxjvFFZBlNZ9O8K5ANNiFEIw3DD3iHhfQRbqhCs3HyzhNF G+8TmaHADsOSkg1HbjF9TXZpcC/e/Wyx42We0e3m9LgYHO5YVwextEryteX1B25kjL2kjhpCxl7 HzZwvu0xsvO2wL1mzNoa7gGI1F9eENqriPU/fNkgH6XxN3OmcpjTasclfbt2WMIkLN0x6gVyQ13 fzXFNHktx4U/1uqQExhz5Kr1dHYIKKsTPyWA4p2w4FQtdYkm+tYsYTp+KSLovFFFVQpAf8BAwx9 /CqCWZS+F3oAS3bu10JdosP8KG2pVzv87 X-Google-Smtp-Source: AGHT+IGaHDQboL5WaFC5AmphHm3hwVKIm7w06aZXHB5gWtLtS3+Amg1G13exnOsPGdrLAxo3jTha8g== X-Received: by 2002:a17:902:ce8c:b0:235:ea0d:ae10 with SMTP id d9443c01a7336-237d97ce44cmr62323835ad.12.1750439748897; Fri, 20 Jun 2025 10:15:48 -0700 (PDT) Received: from jeff-ws-bridge.lan (c-76-102-242-158.hsd1.ca.comcast.net. [76.102.242.158]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-237d8393470sm22735165ad.37.2025.06.20.10.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jun 2025 10:15:48 -0700 (PDT) Message-ID: <792ee592556431aaa2ad1570a978574f53e5be7a.camel@j-davis.com> Subject: Re: Improve the performance of Unicode Normalization Forms. From: Jeff Davis To: Nico Williams Cc: Alexander Borisov , PostgreSQL Hackers Date: Fri, 20 Jun 2025 10:15:47 -0700 In-Reply-To: References: <844d3dd7-2955-4794-95d1-7f4c13cb89fc@gmail.com> <4211ffd7fe154c4af693b98d78f4a3689ce8cc30.camel@j-davis.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.3-0ubuntu1 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2025-06-20 at 11:31 -0500, Nico Williams wrote: > In the slow path you only > normalize the _current character_, so you only need enough buffer > space > for that. That's a clear win for UTF8 data. Also, if there are no changes, then you can just return the input buffer and not bother allocating an output buffer. > The really nice thing about form-insensitive/form-preserving > functionality is that it is form-preserving rather than normalizing > on > create and lookup, and that makes the fast-path described above > feasible.=C2=A0 Whereas if you normalize on create and lookup you have to > heap allocate enough space for each string normalized. Non-deterministic ICU collations are already insensitive to most normalization differences. Some differences are not handled when it involves too many combining marks, but you can use the "full normalization" option to address that. See: https://www.postgresql.org/docs/current/collation.html#ICU-COLLATION-SETTIN= GS-TABLE > =C2=A0 The other nice > thing is that f-i/f-p behavior is a lot less surprising to users -- > the > input methods they use don't matter. Postgres is already form-preserving; it does not auto-normalize. (I have suggested that we might want to offer something like that, but that would be a user choice.) Currently, the non-deterministic collations (which offer form- insensitivity) are not available at the database level, so you have to explicitly specify the COLLATE clause on a column or query. In other words, Postgres is not form-insensitive by default, though there is work to make that possible. > What motivated this f-i/f-p behavior was that HFS+ used NFD (well, > something very close to NFD) but input methods (even on OS X) > invariably > produce NFC (well, something close to it), at least for Latin > scripts. > This means that on OS X if you use filenames from directory listings > those will be NFD while user inputs will be NFC, and so you can't > just > memcmp()/strcmp() those -- you have to normalize _or_ use form- > insensitive string comparison, but nothing did that 20 years ago.=C2=A0 > Thus > doing the form-insensitivity in the filesystem seemed best, and if > you > do that you can be form-preserving to enable the optimization > described > above. Databases have similar concerns as a filesystem in this respect. Regards, Jeff Davis