From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: horiguchi.kyotaro@oss.ntt.co.jp
Cc: pgsql-hackers@postgresql.org
Subject: Re: [v9.2] make_greater_string() does not return a string in some cases
Date: Sat, 29 Oct 2011 16:36:06 -0400
Message-ID: <29562.1319920566@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+Tgmobs+-oxMrps_rfOFwx_7FknFd2qwnwvGTSiv1tS=CXUrQ@mail.gmail.com>
References: <CA+Tgmobhk5mWdoSjZFZ+qU_Z5tN2Gd8EVCBoraYydwXd3PtLpw@mail.gmail.com>
<20111030.021603.01379645.horiguchi.kyotaro@horiguti.oss.ntt.co.jp>
<CA+TgmobMOox8xVcJ62OoqfH5CQyBEm-2z4SFywwC-VgAtZDE_A@mail.gmail.com>
<28652.1319916927@sss.pgh.pa.us>
<CA+Tgmobs+-oxMrps_rfOFwx_7FknFd2qwnwvGTSiv1tS=CXUrQ@mail.gmail.com>
Robert Haas <robertmhaas@gmail.com> writes:
> On Sat, Oct 29, 2011 at 3:35 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Ummm ... why do the incrementer functions think they need to restore the
>> previous value on failure? AFAICS that's a waste of code and cycles,
>> since there is only one caller and it doesn't care in the least.
> Well, it might not be strictly necessary for pg_utf8_increment() and
> pg_eucjp_increment(), but it's clearly necessary for the generic
> incrementer function for exactly the same reason it was needed in the
> old coding. I suppose we could weaken the rule to "you must leave a
> valid character behind rather than a bunch of bytes that doesn't
> encode to a character", but the cycle savings are negligible and the
> current rule seems both simpler and more bullet-proof.
No, it's *not* necessary any more, AFAICS. make_greater_string discards
the data and overwrites it with a null instantly upon getting a failure
return from the incrementer. The reason we used to need it was that we
did pg_mbcliplen after failing to increment, but now we do that before
we ever increment anything, so we already know the length of the last
character. It doesn't matter whether those bytes are still valid or
contain garbage.
>> I'm also quite distressed that you ignored my advice to limit the number
>> of combinations tried. This patch could be horribly slow when dealing
>> with wide characters, eg think what will happen when starting from
>> U+10000.
> Uh, I think it will try at most one character in that position and
> then truncate away that character entirely, per my last email on this
> topic (to which you never responded):
> http://archives.postgresql.org/pgsql-hackers/2011-09/msg01195.php
Oh! You are right, I was expecting it to try multiple characters at the
same position before truncating the string. This change seems to have
lobotomized things rather thoroughly. What is the rationale for that?
As an example, when dealing with a single-character string, it will fail
altogether if the next code value sorts out-of-order, so this seems to
me to be a rather large step backwards.
I think we ought to go back to the previous design of incrementing till
failure and then truncating, which puts the onus on the incrementer to
make a reasonable tradeoff of how many combinations to try per character
position. There's a simple tweak we could make to the patch to limit
that: once we've maxed out a lower-order byte of a multibyte char,
*don't reset it to minimum*, just move on to incrementing the next
higher byte. This preserves the old property that the maximum number of
combinations tried is bounded by 256 * string's length in bytes.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, robertmhaas@gmail.com, horiguchi.kyotaro@oss.ntt.co.jp, pgsql-hackers@postgresql.org
Subject: Re: [v9.2] make_greater_string() does not return a string in some cases
In-Reply-To: <29562.1319920566@sss.pgh.pa.us>
References: <CA+Tgmobhk5mWdoSjZFZ+qU_Z5tN2Gd8EVCBoraYydwXd3PtLpw@mail.gmail.com> <20111030.021603.01379645.horiguchi.kyotaro@horiguti.oss.ntt.co.jp> <CA+TgmobMOox8xVcJ62OoqfH5CQyBEm-2z4SFywwC-VgAtZDE_A@mail.gmail.com> <28652.1319916927@sss.pgh.pa.us> <CA+Tgmobs+-oxMrps_rfOFwx_7FknFd2qwnwvGTSiv1tS=CXUrQ@mail.gmail.com> <29562.1319920566@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox