Re: Making all nbtree entries unique by having heap TIDs participate in comparisons

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Peter Geoghegan <pg(at)bowt(dot)ie>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Claudio Freire <klaussfreire(at)gmail(dot)com>, Anastasia Lubennikova <a(dot)lubennikova(at)postgrespro(dot)ru>, "Andrey V(dot) Lepikhov" <a(dot)lepikhov(at)postgrespro(dot)ru>
Subject: Re: Making all nbtree entries unique by having heap TIDs participate in comparisons
Date: 2018-12-28 23:20:42
Message-ID: 30dd5ef9-77f5-7f6a-f95a-e2045f3acad2@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 29/12/2018 01:04, Peter Geoghegan wrote:
>> However, naively computing the penalty upfront for every offset would be
>> a bit wasteful. Instead, start from the middle of the page, and walk
>> "outwards" towards both ends, until you find a "good enough" penalty.
>
> You can't start at the middle of the page, though.
>
> You have to start at the left (though you could probably start at the
> right instead). This is because of page fragmentation -- it's not
> correct to assume that the line pointer offset into tuple space on the
> page (firstright linw pointer lp_off for candidate split point) tells
> you anything about what the space delta will be after the split. You
> have to exhaustively add up the free space before the line pointer
> (the free space for all earlier line pointers) before seeing if the
> line pointer works as a split point, since each previous line
> pointer's tuple could be located anywhere in the original page's tuple
> space (anywhere to the left or to the right of where it would be in
> the simple/unfragmented case).

Right. You'll need to do the free space computations from left to right,
but once you have done that, you can compute the penalties in any order.

I'm envisioning that you have an array, with one element for each item
on the page (including the tuple we're inserting, which isn't really on
the page yet). In the first pass, you count up from left to right,
filling the array. Next, you compute the complete penalties, starting
from the middle, walking outwards.

That's not so different from what you're doing now, but I find it more
natural to explain the algorithm that way.

- Heikki

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2018-12-28 23:26:35 Re: Offline enabling/disabling of data checksums
Previous Message Tom Lane 2018-12-28 23:15:05 Re: random() (was Re: New GUC to sample log queries)