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 1tg8IG-007ykR-6l for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Feb 2025 20:16:12 +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 1tg8IE-00BNbG-4A for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Feb 2025 20:16:10 +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 1tg8ID-00BNWT-QW for pgsql-hackers@lists.postgresql.org; Thu, 06 Feb 2025 20:16:09 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tg8I8-003biq-38 for pgsql-hackers@postgresql.org; Thu, 06 Feb 2025 20:16:08 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-54021daa6cbso1455760e87.0 for ; Thu, 06 Feb 2025 12:16:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738872963; x=1739477763; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=IuPff4TRPTYCXRY3Iu0lUM4iiIeGGX4ioaeTTFFSXq8=; b=N9JV5gRleAvGWxlerZzicpOLuW+FcKkcfDKRKGeygImLlFrdLYPSLB834A3Cq7RqV7 QJURHf7EoHshF8ZESK7lpOlfBqwm9NbipruVe69rR6nFSaByDAwZJ0FLOUXi2xzYFdQg s6owmxQvbDH5mygUuPwl4VKo71X43f3BogEqfFzS3xjb0oOTGY/htsEykcZd60kj193S NuLOrd9PPRDh9yiN8CfeRiginLNA5yUGjFJQ/10jnpzYHJXPdMxwt5V/9fbDqQnrJPEh yefhdkisv+jBlMiNK9BVKBy5jQ6eKTwlaeVm2bw6ijb2RC4CKy8u4g1LBiBxQMmRu/Dt Rs1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738872963; x=1739477763; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IuPff4TRPTYCXRY3Iu0lUM4iiIeGGX4ioaeTTFFSXq8=; b=gj7RnDs+R7Wuo/jGvlA/f8dAQa9I4TeHtCmmVxYxbnVyy/HcrkgePfeZf0T3BCxd8n v8wPs856879Oq6p06wq8Yyy3+w3loSWagT12rr1AOyWdrK7aieeHVUsjfLMGNasNR4i4 CtbjkMzEcE4SN4f1sBwuwecRGTjbfpWlt+oyqU+YiN/5jFAketbHMjt5d2aiccdoAKhN HYpQ5LOYjMG3XB/ftvXwWgseRFrTwo3nxc8ITc1TmP21ZCaLhC6Cg0ePTb5nDfl1Une4 IVP0hdBwsLZ+2SdvjdumhQ0VfHOYrlt+gTBQDmK9asSVtHIEqbXHteM3SFUM5gYF3c8g OMzg== X-Forwarded-Encrypted: i=1; AJvYcCUWus6z4bZLAlhoxDy4wEKwxNFhqsFCLSexVbMOuljteoIQsiwOV4uZWx7HVZU1x/SHQe7ZC+q9fE+WAEEE@postgresql.org X-Gm-Message-State: AOJu0Yxmjvn+X0e8+W4dNJWG3igCqaxS4oY8NwCJcexJyLQ37JeYGqwA cZaxOd8cOi+UStQ6OdpNXFZiI+pNFl68qhS1+vhfwN8nwPGYSmwX/Ldpcg== X-Gm-Gg: ASbGncvChwxB5w5TV+sGe8iz5uh1DWMnhHAuHlqpQz2g5R/r2vRRrCe9fdefnPzla9P N8tYdY77eVWTny58qbXFLWeMUoyp6do7ubjHk/VEeW+OAHn/W+Ji4ZoP2PD6ArnFwi95NJMCDch OX1cdBwWErj7jHef8rCrVkL56NP1fdruiehYRbK90hxXqG9KSmsHqdtPmO4pTX0hjUEk/e9BfhH tLvuYxhrTVfNPDQpMwLbF4T9jHyESwE09LsyAFvpskwE8RG4ox/XarN/WeuHErH7sGdcVGXyDCQ FqKdZsf9koA+WkqaF1gnPYZH8+ERV+TqqusejXWpL39D4PMZPUDZT8YlkHRdyL5vuZnqBioGdA= = X-Google-Smtp-Source: AGHT+IGIPsWDEHpQjhPkWyKFypt45Uw6kpON3l0RmTOhh2b4YlevMtckkCiqz8aiMkQfZvMSPi7dvw== X-Received: by 2002:a05:6512:3fc:b0:53e:fa8b:822e with SMTP id 2adb3069b0e04-54414ae0c54mr60070e87.37.1738872962406; Thu, 06 Feb 2025 12:16:02 -0800 (PST) Received: from [192.168.50.231] (broadband-188-255-2-52.ip.moscow.rt.ru. [188.255.2.52]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-544105f31efsm220519e87.181.2025.02.06.12.16.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Feb 2025 12:16:02 -0800 (PST) Message-ID: <65fc398c-864a-47f7-88d1-d8be2219d14a@gmail.com> Date: Thu, 6 Feb 2025 23:16:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Optimization for lower(), upper(), casefold() functions. To: Jeff Davis , Heikki Linnakangas , pgsql-hackers@postgresql.org References: <7cac7e66-9a3b-4e3f-a997-42aa0c401f80@gmail.com> <2a1b632e-4531-43cf-a6d9-51cc1a271dc1@gmail.com> <7ab9d255-d7c0-4841-96c3-ed3ce9aa4abd@iki.fi> <12956299-1496-4455-b3ab-299cc0a87d7c@gmail.com> <340f2451-cd76-487b-a1e4-0f0a2fe91fba@gmail.com> <3ffb8b75b26e76624668c0883cac7886468c5d07.camel@j-davis.com> <5cf176fa-44b9-4019-b9b7-ee902352a844@gmail.com> <3080de9bcce916cf8720ac197f634e381c4de564.camel@j-davis.com> Content-Language: ru From: Alexander Borisov In-Reply-To: <3080de9bcce916cf8720ac197f634e381c4de564.camel@j-davis.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 06.02.2025 22:08, Jeff Davis пишет: > On Thu, 2025-02-06 at 18:39 +0300, Alexander Borisov wrote: >> Since I started to improve Unicode Case, I used the same approach, >> essentially a binary search, only not by individual values, but by >> ranges. > > I considered it a 4th approach because of the generated branches in > case_index(). Case_index() is essentially a part of the data structure > -- you can't navigate the table without it. > > By the way, could we just represent those ranges as another tiny table > instead of representing them as branches? > > In other words, a table something like: > > {{.start=0x0000, .end=0x0588, .offset=0}, > {.start=0x10A0, .end=0x1100, .offset=0x10A0 - 0x0588}, > ... > {.start=0x1E900, .end=0x1E944, .offset=0x1E900 - 0x11D3}} > > How would that perform? I'll try this approach, but it seems like the only hope here is compiler optimizations. >> I plan to use the same approach for Unicode Normalization. Acting >> sequentially and suggesting improvements. >> Unfortunately I'm new here and I can't say why one place uses one >> approach and another another - I just don't know. > > We have 3 or 4 different solutions (naive binary search, range binary > search, perfect hashing, and radix tree) to 3 or 4 similar problems > (normalization, character properties, case mapping, and encoding > conversion). We should consolidate these approaches somehow. > > IIUC, out of the solutions, it seems that either your modified binary > search or the radix tree are best because they are both fast and both > allow compact tables. > > My questions are: is there a clear winner between radix tree and the > range binary search for all four problems? If not, what are the trade- > offs? I think it is already clear that there is only one thing left - to test radix tree and range binary in how they will behave in Encoding and Unicode Case. That is, implement both approaches in both cases. I'm thinking of taking big5 (big table there) to utf-8 for testing. The main thing is to understand how to test it correctly (pgbench). Okay, I'll do that. But it's worth remembering that there is no such thing as a silver bullet. -- Alexander Borisov