Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 7CFC0B5DDE8 for ; Mon, 26 Sep 2011 11:42:24 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 17145-02-7 for ; Mon, 26 Sep 2011 14:42:18 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.23]) by mail.postgresql.org (Postfix) with SMTP id CBC4DB5DEB0 for ; Mon, 26 Sep 2011 11:30:35 -0300 (ADT) Received: (qmail invoked by alias); 26 Sep 2011 14:30:34 -0000 Received: from fsgw.f-secure.com (EHLO [10.128.133.18]) [193.110.108.33] by mail.gmx.net (mp065) with SMTP; 26 Sep 2011 16:30:34 +0200 X-Authenticated: #495269 X-Provags-ID: V01U2FsdGVkX19+0qlEcd1+Lr2YgD7TpJl/S7lj2DGViNahqyB6OP b4snH/ctS4q00F Subject: Re: [v9.2] make_greater_string() does not return a string in some cases From: Peter Eisentraut To: Tom Lane Cc: Marcin =?UTF-8?Q?Ma=C5=84k?= , Robert Haas , Kyotaro HORIGUCHI , "pgsql-hackers@postgresql.org" In-Reply-To: <5358.1317046134@sss.pgh.pa.us> References: <20110711.155531.15100243.horiguchi.kyotaro@oss.ntt.co.jp> <20110712.161231.138791411.horiguchi.kyotaro@oss.ntt.co.jp> <20110914.111320.18404009.horiguchi.kyotaro@oss.ntt.co.jp> <6425.1316656167@sss.pgh.pa.us> <8755.1316665444@sss.pgh.pa.us> <18434.1316702188@sss.pgh.pa.us> <24673.1316782288@sss.pgh.pa.us> <624360DC-C26A-4FA6-8C6A-26D28EA79422@gmail.com> <1317034343.1759.13.camel@fsopti579.F-Secure.com> <5358.1317046134@sss.pgh.pa.us> Content-Type: text/plain; charset="UTF-8" Date: Mon, 26 Sep 2011 17:30:32 +0300 Message-ID: <1317047432.1759.27.camel@fsopti579.F-Secure.com> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 8bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.403 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/1376 X-Sequence-Number: 195565 On mån, 2011-09-26 at 10:08 -0400, Tom Lane wrote: > Peter Eisentraut writes: > > On fre, 2011-09-23 at 20:35 +0300, Marcin Mańk wrote: > >> One idea: > >> col like 'foo%' could be translated to col >= 'foo' and col <= foo || 'zzz' , where 'z' is the largest possible character. This should be good enough for calculating stats. > >> How to find such a character, i do not know. > > > That's what makes this so difficult. > > > If we knew the largest character, we could probably also find the > > largest-1, largest-2, etc. characters and determine the total order of > > everything. > > No, it's a hundred times worse than that, because in collations other > than C there typically *is* no total order. The collation behavior of > many characters is context-sensitive, thanks to the multi-pass behavior > of typical "dictionary" algorithms. Well, there is a total order of all strings, but it's not consistent under string concatenation. But there is a "largest character". If the collation implementation uses four weights (the typical case), the largest character is the one that maps to . If you appended that character to a string, you would get a larger string. (Unless there are French backwards levels or other funny things in place, perhaps.) But we don't know which character that is, and likely there isn't one, so we'd need to largest character that maps to an actually assigned weight, and that's not possible without exhaustive search of all collating elements. We could possibly try to make this whole thing work differently by storing the strxfrm results in the histograms.