Re: [HACKERS] Surjective functional indexes

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Konstantin Knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Christoph Berg <myon(at)debian(dot)org>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Surjective functional indexes
Date: 2018-05-11 04:48:44
Message-ID: CAKFQuwYXEZhvN5HyNpM8PsRY5gJTOXU9DJ-U2FKsBU9y-=+TsA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thursday, February 1, 2018, Konstantin Knizhnik <
k(dot)knizhnik(at)postgrespro(dot)ru> wrote:

>
> Old + New for check = 2
>> plus calculate again in index = 3
>>
>
> Yes, we have to calculate the value of index expression for original and
> updated version of the record. If them are equal, then it is all we have to
> do with this index: hot update is applicable.
> In this case we calculate index expression twice.
> But if them are not equal, then hot update is not applicable and we have
> to update index. In this case expression will be calculated one more time.
> So totally three times.
> This is why, if calculation of index expression is very expensive, then
> effect of this optimization may be negative even if value of index
> expression is not changed.
>

For the old/new comparison and the re-calculate if changed dynamics - is
this a side effect of separation of concerns only or is there some other
reason the old computed value already stored in the index isn't compared to
the one and only function result of the new tuple which, if found to be
different, is then stored. One function invocation, which has to happen
anyway, and one extra equality check. Seems like this could be used for
non-functional indexes too, so that mere presence in the update listing
doesn't negate HOT if the column didn't actually change (if I'm not
mis-remembering something here anyway...)

Also, create index page doc typo from site: "with an total" s/b "with a
total" (expression cost less than 1000) - maybe add a comma for 1,000

David J.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2018-05-11 05:37:31 Re: Should we add GUCs to allow partition pruning to be disabled?
Previous Message Amit Langote 2018-05-11 03:59:27 Re: Should we add GUCs to allow partition pruning to be disabled?