Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMZIz-0003Ut-U0 for pgsql-general@arkaria.postgresql.org; Fri, 03 May 2019 14:36:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hMZIy-0006Du-Gc for pgsql-general@arkaria.postgresql.org; Fri, 03 May 2019 14:36:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMZIy-0006AQ-1k for pgsql-general@lists.postgresql.org; Fri, 03 May 2019 14:36:52 +0000 Received: from smtp55.i.mail.ru ([217.69.128.35]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMZIu-0005Ib-UO for pgsql-general@postgresql.org; Fri, 03 May 2019 14:36:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject; bh=lfK3G9uNqvNn/WeSBSajEUGIqgjV3+0hIq097GJEw30=; b=B3BM58L50Q7w5h9dN5Uq/8ijMHJdzPAixAgzf7nkJtO6uNqv1aIU0uaCj11KQsYJVGuzAO7KJWRV90xhjMWjhvmZ4cpUmExUClmjMeUddkfZM9AV3KHbtRoxKtZI7uKgFfdlBEEwh/AEXA5xX6n+JwRQ+PaQTRX5P/Qcj/KlTGo=; Received: by smtp55.i.mail.ru with esmtpa (envelope-from ) id 1hMZIs-0007Hh-VL; Fri, 03 May 2019 17:36:47 +0300 Subject: Re: Upgrading locale issues To: Daniel Verite Cc: Peter Geoghegan , pgsql-general General References: From: rihad Message-ID: <7833dd2f-633f-d41d-0a93-26155979f584@mail.ru> Date: Fri, 3 May 2019 18:36:44 +0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Authentication-Results: smtp55.i.mail.ru; auth=pass smtp.auth=rihad@mail.ru smtp.mailfrom=rihad@mail.ru X-77F55803: 689590B63E0A4B015A78504BD2AC29419190768C267DA4DC1A219F6C620988744EE812AAF3235A7DD83F1230EAF91384 X-7FA49CB5: 0D63561A33F958A53BFF116C7B4FF38DB7F5149641FF54EA0E4FE003F744AF918941B15DA834481FA18204E546F3947CEDCF5861DED71B2F389733CBF5DBD5E9C8A9BA7A39EFB7666BA297DBC24807EA117882F44604297287769387670735209ECD01F8117BC8BEA471835C12D1D977C4224003CC8364767815B9869FA544D8D32BA5DBAC0009BE9E8FC8737B5C2249CF022B9B1C4215823AA81AA40904B5D9CF19DD082D7633A093541453170D46FCD81D268191BDAD3D78DA827A17800CE7542AF255F21831B5CD04E86FAF290E2DBBC930A3941E20C675ECD9A6C639B01B78DA827A17800CE7FED7F7793140C1ABB0AED21466FA0A5F75ECD9A6C639B01B4E70A05D1297E1BBC6867C52282FAC8519DC0BE04022C72727F269C8F02392CD5571747095F342E88FB05168BE4CE3AF X-Mailru-Sender: B19AB4DAF1EA2FB57B1A52EF3A1F0324A99F0C34D223D833AF4E173BF89FAB66695E860E62102A0A108F17C94788D7333DDE9B364B0DF2891F953FB4A677E77772D6B4FCE48DF648AE208404248635DF X-Mras: OK List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 05/03/2019 05:35 PM, Daniel Verite wrote: > rihad wrote: > >> Thanks, I'm a bit confused here. AFAIK indexes are used for at least two >> things: for speed and for skipping the ORDER BY step (since btree >> indexes are already sorted). Will such an "upgrade-immune" C.UTF-8 index >> still work correctly for table lookups? > If the lookup is based on a equality test or a pattern match with LIKE > or a regexp, it makes no difference. But the locale makes a > difference with inequality tests, such as < > or BETWEEN. > > Around version 9.1 and in the pre-ICU days, Robert Haas wrote > this post that explained it pretty well, I think: > http://rhaas.blogspot.com/2012/03/perils-of-collation-aware-comparisons.html > > Quote: > > If you happen to need the particular sorting behavior that > collation-aware sorting and comparisons provide, then you may find > this price worth paying, but I suspect there are a lot of people out > there who are paying it more or less accidentally and don't really > care very much about the underlying sorting behavior. If, for > example, all of your queries are based on equality, and you don't > use greater-than or less-than tests, then it doesn't matter what > collation is in use. You might as well use "C" instead of whatever > your local default may be, because it's faster. > > For non-English text, I would recommend C.UTF-8 over "C" because of > its better handling of Unicode characters. For instance: > > =# select upper('été' collate "C"), upper('été' collate "C.UTF-8"); > upper | upper > -------+------- > éTé | ÉTÉ > > The "price" of linguistic comparisons that Robert mentioned was about > performance, but the troubles we have with the lack of long-term > immutability of these locales are worth being added to that. > >> And can the existing en_US.UTF-8 fields' definition be altered in >> place, without a dump+restore? > Changing the COLLATE clause of a column with ALTER TABLE does > implicitly rebuild an index on this column if there is one, > A dump+restore is not needed, nor an explicit REINDEX. > > The dump+restore is needed in another scenario, where you would > decide to change the LC_COLLATE and LC_CTYPE of the database, > instead of doing it only for some columns. > This scenario makes perfect sense if the locale of the database > has been set implicitly and it uses linguistic sorts without > really needing them ("accidentally" as said in the post). > > >> en_US.UTF-8 is the default encoding+locale+collation, it >> isn't set explicitly for any of our string columns. I assume there's >> some "catch-all" ordering taking place even for the C locale, so there >> won't be any bizarre things like b coming before a, or generally for any >> language, the second letter of its alphabet coming before the first? > 'b' < 'a' is never true for any locale AFAIK, it is 'B' < 'a' that is > true for some locales such as C or C.UTF-8. > > > Best regards, Thanks a lot for sharing your insights!