Re: [PATCH] heap_insert() and heap_update() optimization

From: Andres Freund <andres(at)anarazel(dot)de>
To: Andrey Klychkov <aaklychkov(at)mail(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] heap_insert() and heap_update() optimization
Date: 2018-10-16 19:57:25
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 2018-10-16 11:28:17 +0300, Andrey Klychkov wrote:
> I suggest the small attached patch that gives a bit of heap_insert() and heap_update() optimization
> by reducing calls of BufferGetPage(buffer) into them.
> I measured call time of these:
> heap_insert(): avg origin 13394 ns, avg patched 12685 ns; perf increases +5.59%
> heap_update(): avg origin 15728 ns, avg patched 13936 ns; perf increases +11.39%
> This can be notable when there are handling many rows.

Interesting. That's with an optimized build, or an assertion build?

Wonder what precisely prevents the optimizer to recognize
BufferGetPage() with a constant argument will always be the same
result. I assume it's that it doesn't recognize that BufferBlocks can't
change across other function calls? Might also be the pointer math, or
the if block...

Wonder if we could force the compiler's hand by making BufferGetPage an
inline function and decorating it with __attribute__((pure)) or such.

I see little reason to not apply what you have here, but there's a lot
of other places that access buffers...


Andres Freund

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2018-10-16 20:11:45 Re: Large writable variables
Previous Message Tom Lane 2018-10-16 19:48:59 Re: pg_dump multi VALUES INSERT