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: Sun, 30 Oct 2011 10:58:53 -0400
Message-ID: <21986.1319986733@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+TgmoZbXGOCYCBrb1T6w8sVDxOA4yP-B8CPtXv4FxxDwRWwtA@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>
<29562.1319920566@sss.pgh.pa.us>
<CA+TgmoZbXGOCYCBrb1T6w8sVDxOA4yP-B8CPtXv4FxxDwRWwtA@mail.gmail.com>
Robert Haas <robertmhaas@gmail.com> writes:
> On Sat, Oct 29, 2011 at 4:36 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> 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.
> On this point I believe you are still confused. The old code tried
> one character per position, and the new code tries one character per
> position. Nothing has been lobotomized in any way.
No, on this point you are flat out wrong. Try something like
select ... where f1 like 'p%';
in tt_RU locale, wherein 'q' sorts between 'k' and 'l'. The old code
correctly found that 'r' works as a string greater than 'p'. The new
code fails to find a greater string, because it only tries 'q' and then
gives up. This results in a selectivity estimate much poorer than
necessary.
Since the stated purpose of this patch is to fix some corner cases
where the code fails to find a greater string, I fail to see why it's
acceptable to introduce some other corner cases that weren't there
before.
> The difference is
> that the old code used a "guess and check" approach to generate the
> character, so there was an inner loop that was trying to generate a
> character (possibly generating various garbage strings that did not
> represent a character along the way) and then, upon success, checked
> the sort order of that single string before truncating and retrying.
You are misreading the old code. The inner loop increments the last
byte, checks for success, and if it hasn't produced a greater string
then it loops around to increment again.
> The fact that we haven't gotten any complaints before suggests that this
> actually works decently well as it stands.
Well, that's true of the old algorithm ;-)
I had likewise thought of the idea of trying some fixed number of
character values at each position, but it's unclear to me why that's
better than allowing an encoding-specific behavior. I don't believe
that we could get away with trying less than a few dozen values, though.
For example, in a situation where case sensitivity is relevant, you
might need to increment past all the upper-case letters to get to a
suitable lower-case letter. I also think that it's probably useful to
try incrementing higher-order bytes of a multibyte character before
giving up --- we just can't afford to do an exhaustive search.
Thus my proposal to let the low-order bytes max out but not cycle.
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: <21986.1319986733@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> <CA+TgmoZbXGOCYCBrb1T6w8sVDxOA4yP-B8CPtXv4FxxDwRWwtA@mail.gmail.com> <21986.1319986733@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