Re: B-Tree support function number 3 (strxfrm() optimization)

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Peter Geoghegan <pg(at)heroku(dot)com>
Cc: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>, Noah Misch <noah(at)leadboat(dot)com>, Marti Raudsepp <marti(at)juffo(dot)org>, Stephen Frost <sfrost(at)snowman(dot)net>, Greg Stark <stark(at)mit(dot)edu>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Thom Brown <thom(at)linux(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: B-Tree support function number 3 (strxfrm() optimization)
Date: 2014-09-19 21:35:50
Message-ID: CA+TgmoYVmkfxRuAczSf9o_sutM3LK0ecHM0GrSy4N=QajJsS8g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Sep 11, 2014 at 8:34 PM, Peter Geoghegan <pg(at)heroku(dot)com> wrote:
> On Tue, Sep 9, 2014 at 2:25 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>>> I like that I don't have to care about every combination, and can
>>> treat abbreviation abortion as the special case with the extra step,
>>> in line with how I think of the optimization conceptually. Does that
>>> make sense?
>>
>> No. comparetup_heap() is hip-deep in this optimization as it stands,
>> and what I proposed - if done correctly - isn't going to make that
>> significantly worse. In fact, it really ought to make things better:
>> you should be able to set things up so that ssup->comparator is always
>> the test that should be applied first, regardless of whether we're
>> aborted or not-aborted or not doing this in the first place; and then
>> ssup->tiebreak_comparator, if not NULL, can be applied after that.
>
> I'm not following here. Isn't that at least equally true of what I've
> proposed? Sure, I'm checking "if (!state->abbrevAborted)" first, but
> that's irrelevant to the non-abbreviated case. It has nothing to
> abort. Also, AFAICT we cannot abort and still call ssup->comparator()
> indifferently, since sorttuple.datum1 fields are perhaps abbreviated
> keys in half of all cases (i.e. pre-abort tuples), and uninitialized
> garbage the other half of the time (i.e. post-abort tuples).

You can if you engineer ssup->comparator() to contain the right
pointer at the right time. Also, shouldn't you go back and fix up
those abbreviated keys to point to datum1 again if you abort?

> Where is the heap_getattr() stuff supposed to happen for the first
> attribute to get an authoritative comparison in the event of aborting
> (if we're calling ssup->comparator() on datum1 indifferently)? We
> decide that we're going to use abbreviated keys within datum1 fields
> up-front. When we abort, we cannot use datum1 fields at all (which
> doesn't appear to matter for text -- the datum1 optimization has
> historically only benefited pass-by-value types).

You always pass datum1 to a function. The code doesn't need to care
about whether that function is expecting abbreviated or
non-abbreviated datums unless that function returns equality. Then it
needs to think about calling a backup comparator if there is one.

> Is doing all this worth the small saving in memory? Personally, I
> don't think that it is, but I defer to you.

I don't care about the memory; I care about the code complexity and
the ease of understanding that code. I am confident that it can be
done better than the patch does it today.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-09-19 21:42:08 Re: Turning off HOT/Cleanup sometimes
Previous Message Robert Haas 2014-09-19 21:29:08 Re: Turning off HOT/Cleanup sometimes