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 1qnoOP-00C5Ow-Gd for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Oct 2023 23:01:29 +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 1qnoON-009u4Z-UH for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Oct 2023 23:01:28 +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 1qnoON-009u4R-8a for pgsql-hackers@lists.postgresql.org; Tue, 03 Oct 2023 23:01:27 +0000 Received: from bumble.maple.relay.mailchannels.net ([23.83.214.25]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnoOJ-008vk2-V2 for pgsql-hackers@postgresql.org; Tue, 03 Oct 2023 23:01:26 +0000 X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 9594F6C14A0; Tue, 3 Oct 2023 23:01:20 +0000 (UTC) Received: from pdx1-sub0-mail-a301.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 645446C0CB4; Tue, 3 Oct 2023 23:01:19 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1696374079; a=rsa-sha256; cv=none; b=74mVz30sZuMgGbc9ENlDoA87k2yug9NgIjYsyjM5n/8Bai5d3CFee4oDuSTIEugQmtVLCe B7KbKPakVRovxWu+NkWPWiXFi3yvwnvkQNa3Yw5OJnzb+6i3P7K92WRIbwcrLY+gc/bJ40 FjE1AaJXhWS8E2ScTY1cqYBPW3DMSZC1tMLNl3pXngzzaw35IVnJJtBl90J7uVR3nZftg2 cWGvLF4HHNRSYR5QaTUnzdcqRV3zCsWhF2Hs6oe/ETXgCXxqPb9eHcR5GD1obUO5sawjOi 9NYf9WswQ962kWXd/Qt/5mL2L6IgcCSJdpw3AYYVuIYPpaWlLjzpe0RNu08dlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1696374079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DfQSXhN2QJxl2/3idHKGpdbr4XYjg6qDb1J8PLGON4Y=; b=x/1FPhW/4Q4oCw8hPMFTH6Zxz0u0e3dKxdp1h/HliY2jm9PUSxPZwpV6RTbYht1a9+gmCW m5isxEcVN803WMXCLhrSnJRXNAx2KJUrVL/z0Ixty1L9zs98EhYgqvr6g3P0ePD4SaUgAz a03/uxbbi8HKyZ/ciXr6Mx+dDL48gUteHUYHozK2/me3C2NQpCbYro33HKu8fzUnxsjbP1 6DMkEslZvJ4Vc3JDSrP/UAN4EiNeUGwF1cQUhnT031qPGGjq/9krjkj9NHcPd01o6+tP6h kEWzCpCOUxLp0PcF/AnLnlNExvO89eSQMgoDERGU0JNT3K91RhJ79a96xjMifQ== ARC-Authentication-Results: i=1; rspamd-7d5dc8fd68-r8pvp; auth=pass smtp.auth=dreamhost smtp.mailfrom=nico@cryptonector.com X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|nico@cryptonector.com X-MailChannels-Auth-Id: dreamhost X-Unite-Lonely: 4401d4c67a72eeb0_1696374080339_3316155106 X-MC-Loop-Signature: 1696374080339:163669477 X-MC-Ingress-Time: 1696374080339 Received: from pdx1-sub0-mail-a301.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.110.212 (trex/6.9.1); Tue, 03 Oct 2023 23:01:20 +0000 Received: from ubby21 (075-081-095-064.res.spectrum.com [75.81.95.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nico@cryptonector.com) by pdx1-sub0-mail-a301.dreamhost.com (Postfix) with ESMTPSA id 4S0YGQ6Yzqz7y; Tue, 3 Oct 2023 16:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cryptonector.com; s=dreamhost; t=1696374079; bh=DfQSXhN2QJxl2/3idHKGpdbr4XYjg6qDb1J8PLGON4Y=; h=Date:From:To:Cc:Subject:Content-Type:Content-Transfer-Encoding; b=p3eodq+ogEvrrpRMQaG/FmTgNBOwcxWJ3DvPgLrcnsQsq3u5iPk27EOtxzj/zQ3Yf +Qz4T/8SRirQUSi1b7wDwdKrkTW26hA9NHW1vD8YJWY4/ep97fRaF0YUzzQsUjIOh/ Fyk1YWrnJpg1liY6jhi5NzoRzNs1vIKM/UzBF4hqJtBp4ss58v4j0uHBBQLgn6CYxB irk7ujVf89qq2//H2S5sU+UhBhXXNFtTEflI7+/KPuLKs+7o/doynsxJe8gvHvnttf 2L0VvCR0fADUKddo+2CKoY3huvbnIFKYMMitGswDLT7qRfdDtcAiod7molKvxm6XPm U5j3EwgMPfexw== Date: Tue, 3 Oct 2023 18:01:16 -0500 From: Nico Williams To: Jeff Davis Cc: pgsql-hackers@postgresql.org Subject: Re: Pre-proposal: unicode normalized text Message-ID: References: <23edd434b490f74a82b564b8027b6a52059f8de7.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Oct 03, 2023 at 03:34:44PM -0700, Jeff Davis wrote: > On Tue, 2023-10-03 at 15:15 -0500, Nico Williams wrote: > > Ugh, My client is not displying 'a' correctly > > Ugh. Is that an argument in favor of normalization or against? Heheh, well, it's an argument in favor of more software getting this right (darn it). It's also an argument for building a time machine so HFS+ can just always have used NFC. But the existence of UTF-16 is proof that time machines don't exist (or that only bad actors have them). > I've also noticed that some fonts render the same character a bit > differently depending on the constituent code points. For instance, if > the accent is its own code point, it seems to be more prominent than if > a single code point represents both the base character and the accent. > That seems to be a violation, but I can understand why that might be > useful. Yes, that happens. Did you know that the ASCII character set was designed with overstrike in mind for typing of accented Latin characters? Unicode combining sequences are kinda like that, but more complex. Yes, the idea really was that you could write a' (or 'a) to get á. That's how people did it with typewriters anyways. > > Almost every Latin input mode out there produces precomposed > > characters and so they effectively produce NFC. > > The problem is not the normal case, the problem will be things like > obscure input methods, some kind of software that's being too clever, > or some kind of malicious user trying to confuse the database. _HFS+ enters the chat_ > > That means that indices > > need to normalize strings, but tables need to store unnormalized > > strings. > > That's an interesting idea. Would the equality operator normalize > first, or are you saying that the index would need to recheck the > results? You can optimize this to avoid having to normalize first. Most strings are not equal, and they tend to differ early. And most strings will likely be ASCII-mostly or in the same form anyways. So you can just walk a cursor down each string looking at two bytes, and if they are both ASCII then you move each cursor forward by one byte, and if then are not both ASCII then you take a slow path where you normalize one grapheme cluster at each cursor (if necessary) and compare that. (ZFS does this.) You can also assume ASCII-mostly, load as many bits of each string (padding as needed) as will fit in SIMD registers, compare and check that they're all ASCII, and if not then jump to the slow path. You can also normalize one grapheme cluster at a time when hashing (e.g., for hash indices), thus avoiding a large allocation if the string is large. Nico --