Re: [v9.2] make_greater_string() does not return a string in some cases - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [v9.2] make_greater_string() does not return a string in some cases
Date
Msg-id 7465.1317052336@sss.pgh.pa.us
Whole thread Raw
In response to Re: [v9.2] make_greater_string() does not return a string in some cases  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-hackers
Peter Eisentraut <peter_e@gmx.net> writes:
> On mån, 2011-09-26 at 10:08 -0400, Tom Lane wrote:
>> 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 <FFFF> <FFFF> <FFFF> <FFFF>.  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 the problem is not "make a string greater than this given one".
It is "make a string greater than any string that begins with this
given one".  As an example, suppose we are given "xyz" where "z" is
the last letter in the collation.  We can probably find characters
such as "~" that are greater than "z", but no string x-y-nonletter
is going to be considered greater than x-y-z-z by a dictionary
sorting method.  This is why make_greater_string has to be prepared
to give up and go increment some character before the last one:
the only way to succeed for this input is to construct "xz".
        regards, tom lane


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: random isolation test failures
Next
From: "Kevin Grittner"
Date:
Subject: Re: random isolation test failures