Re: btree: downlink right separator/HIKEY optimization - Mailing list pgsql-hackers

From vignesh C
Subject Re: btree: downlink right separator/HIKEY optimization
Date
Msg-id CALDaNm00LKEnFHUoRs5c1GVT6N1jL5x6LdKzvRQwC0368+wx=A@mail.gmail.com
Whole thread Raw
In response to btree: downlink right separator/HIKEY optimization  (Matthias van de Meent <boekewurm+postgres@gmail.com>)
Responses Re: btree: downlink right separator/HIKEY optimization
List pgsql-hackers
On Wed, 1 Nov 2023 at 03:38, Matthias van de Meent
<boekewurm+postgres@gmail.com> wrote:
>
> (now really to -hackers)
> Hi,
>
> Over at [0] I'd implemented an optimization that allows us to skip
> calling _bt_compare in _bt_moveright in many common cases. This patch,
> when stacked on top of the prefix truncation patch, improves INSERT
> performance by an additional 2-9%pt, with an extreme case of 45% in
> the worscase index tests at [0].
>
> The optimization is that we now recognze that our page split algorithm
> all but guarantees that the HIKEY matches this page's downlink's right
> separator key bytewise, excluding the data stored in the
> IndexTupleData struct.
>
> By caching the right separator index tuple in _bt_search, we can
> compare the downlink's right separator and the HIKEY, and when they
> are equal (memcmp() == 0) we don't have to call _bt_compare - the
> HIKEY is known to be larger than the scan key, because our key is
> smaller than the right separator, and thus transitively also smaller
> than the HIKEY because it contains the same data. As _bt_compare can
> call expensive user-provided functions, this can be a large
> performance boon, especially when there are only a small number of
> column getting compared on each page (e.g. index tuples of many 100s
> of bytes, or dynamic prefix truncation is enabled).
>
> By adding this, the number of _bt_compare calls per _bt_search is
> often reduced by one per btree level.

CFBot shows the following compilation error at [1]:
[16:56:22.153] FAILED:
src/backend/postgres_lib.a.p/access_nbtree_nbtsearch.c.obj
[16:56:22.153] "cl" "-Isrc\backend\postgres_lib.a.p" "-Isrc\include"
"-I..\src\include" "-Ic:\openssl\1.1\include"
"-I..\src\include\port\win32" "-I..\src\include\port\win32_msvc"
"/MDd" "/FIpostgres_pch.h" "/Yupostgres_pch.h"
"/Fpsrc\backend\postgres_lib.a.p\postgres_pch.pch" "/nologo"
"/showIncludes" "/utf-8" "/W2" "/Od" "/Zi" "/DWIN32" "/DWINDOWS"
"/D__WINDOWS__" "/D__WIN32__" "/D_CRT_SECURE_NO_DEPRECATE"
"/D_CRT_NONSTDC_NO_DEPRECATE" "/wd4018" "/wd4244" "/wd4273" "/wd4101"
"/wd4102" "/wd4090" "/wd4267" "-DBUILDING_DLL" "/FS"
"/FdC:\cirrus\build\src\backend\postgres_lib.pdb"
/Fosrc/backend/postgres_lib.a.p/access_nbtree_nbtsearch.c.obj "/c"
../src/backend/access/nbtree/nbtsearch.c
[16:56:22.153] ../src/backend/access/nbtree/nbtsearch.c(112): error
C2143: syntax error: missing ';' before 'type'
[16:56:22.280] ../src/backend/access/nbtree/nbtsearch.c(112): warning
C4091: ' ': ignored on left of 'int' when no variable is declared

[1] - https://cirrus-ci.com/task/4634619035779072

Regards,
Vignesh



pgsql-hackers by date:

Previous
From: Geoff Winkless
Date:
Subject: Re: weird GROUPING SETS and ORDER BY behaviour
Next
From: vignesh C
Date:
Subject: Re: Bytea PL/Perl transform