Re: When Update balloons memory

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Klaudie Willis <Klaudie(dot)Willis(at)protonmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: When Update balloons memory
Date: 2021-12-14 19:21:54
Message-ID: CAH2-Wzm54LA8EeOf6-cFZCHwigZ0YgQVgcmuyFr=b8w2pzQgzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general

On Tue, Dec 14, 2021 at 7:58 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> ITYM "((actiondate::date))", but yeah, this leaks memory like there's
> no tomorrow. I traced it to 9dc718bdf (Pass down "logically unchanged
> index" hint), which has added a function index_unchanged_by_update()
> that (a) looks fairly expensive, (b) leaks a copy of every expression
> tree it examines, and (c) is invoked over again for each row, even
> though AFAICS the answer shouldn't change across rows. This seems very
> poorly thought through. Peter?

Ugh, what a howler. Clearly I am at fault here. Apologies.

Are you sure that it would really be worth the trouble of caching our
answer? It's not clear that that has only minimal maintenance burden.
I have always suspected that index_unchanged_by_update() was at least
slightly over-engineered.

The fact is that most individual aminsert() calls that get the hint
will never actually apply it in any way. In practice the hint is only
relevant when there isn't enough space on an nbtree leaf page to fit
the incoming item. Even then, it won't be used when there are LP_DEAD
bits set on the leaf page -- we prefer to perform a conventional index
deletion over a bottom-up index deletion. And so there is a fair
practical argument to be made in favor of assuming that we should give
the hint in cases where we can't rule it out inexpensively. Of course
that assumes that there will be no other use for the hint in the
future. I'm not making this argument myself, but it does seem like a
factor worth considering.

--
Peter Geoghegan

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2021-12-14 19:33:47 Re: When Update balloons memory
Previous Message Vincent Veyron 2021-12-14 18:41:45 Re: When Update balloons memory

Browse pgsql-general by date

  From Date Subject
Next Message Marc Millas 2021-12-14 19:22:41 Re: locks within select
Previous Message Vincent Veyron 2021-12-14 18:41:45 Re: When Update balloons memory