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 1hMYM0-0000SL-Vp for pgsql-general@arkaria.postgresql.org; Fri, 03 May 2019 13:35:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hMYLz-0008H9-PI for pgsql-general@arkaria.postgresql.org; Fri, 03 May 2019 13:35:55 +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 1hMYLz-0008Gy-Fh for pgsql-general@lists.postgresql.org; Fri, 03 May 2019 13:35:55 +0000 Received: from mail.verite.pro ([185.16.44.216]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMYLw-0003r9-3T for pgsql-general@postgresql.org; Fri, 03 May 2019 13:35:55 +0000 Received: from genius-map.net (verite.pro [195.154.189.246]) by mail.verite.pro (Postfix) with ESMTP id 46EEF8C00F6; Fri, 3 May 2019 15:30:18 +0200 (CEST) Received: by genius-map.net (Postfix, from userid 1001) id 8014C38A0B0A; Fri, 3 May 2019 15:35:49 +0200 (CEST) Content-Type: text/plain; charset="iso-8859-15" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: Upgrading locale issues From: "Daniel Verite" To: "rihad" Cc: "Peter Geoghegan" ,"pgsql-general General" In-Reply-To: <352ac37a-39e6-5afe-d822-b4e031b9b314@mail.ru> Date: Fri, 03 May 2019 15:35:47 +0200 Message-Id: X-Mailer: Manitou v1.7.3 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk rihad wrote: > Thanks, I'm a bit confused here. AFAIK indexes are used for at least two= =20 > things: for speed and for skipping the ORDER BY step (since btree=20 > indexes are already sorted). Will such an "upgrade-immune" C.UTF-8 index= =20 > 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: =3D# select upper('=E9t=E9' collate "C"), upper('=E9t=E9' collate "C.UTF-8"= ); upper | upper=20 -------+------- =E9T=E9 | =C9T=C9 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=20 > isn't set explicitly for any of our string columns. I assume there's=20 > some "catch-all" ordering taking place even for the C locale, so there=20 > won't be any bizarre things like b coming before a, or generally for any= =20 > 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, --=20 Daniel V=E9rit=E9 PostgreSQL-powered mailer: http://www.manitou-mail.org Twitter: @DanielVerite