1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Add missing index_insert_cleanup calls

The optimization for inserts into BRIN indexes added by c1ec02be1d
relies on a cache that needs to be explicitly released after calling
index_insert(). The commit however failed to invoke the cleanup in
validate_index(), which calls index_insert() indirectly through
table_index_validate_scan().

After inspecting index_insert() callers, it seems unique_key_recheck()
is missing the call too.

Fixed by adding the two missing index_insert_cleanup() calls.

The commit does two additional improvements. The aminsertcleanup()
signature is modified to have the index as the first argument, to make
it more like the other AM callbacks. And the aminsertcleanup() callback
is invoked even if the ii_AmCache is NULL, so that it can decide if the
cleanup is necessary.

Author: Alvaro Herrera, Tomas Vondra
Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/202401091043.e3nrqiad6gb7@alvherre.pgsql
This commit is contained in:
Tomas Vondra
2024-04-19 15:47:48 +02:00
parent 95d14b7ae2
commit 41d2c6f952
9 changed files with 26 additions and 16 deletions

View File

@ -367,21 +367,21 @@ aminsert (Relation indexRelation,
within an SQL statement, it can allocate space
in <literal>indexInfo-&gt;ii_Context</literal> and store a pointer to the
data in <literal>indexInfo-&gt;ii_AmCache</literal> (which will be NULL
initially). After the index insertions complete, the memory will be freed
automatically. If additional cleanup is required (e.g. if the cache contains
buffers and tuple descriptors), the AM may define an optional function
<literal>aminsertcleanup</literal>, called before the memory is released.
initially). If resources other than memory have to be released after
index insertions, <function>aminsertcleanup</function> may be provided,
which will be called before the memory is released.
</para>
<para>
<programlisting>
void
aminsertcleanup (IndexInfo *indexInfo);
aminsertcleanup (Relation indexRelation,
IndexInfo *indexInfo);
</programlisting>
Clean up state that was maintained across successive inserts in
<literal>indexInfo-&gt;ii_AmCache</literal>. This is useful if the data
requires additional cleanup steps, and simply releasing the memory is not
sufficient.
requires additional cleanup steps (e.g., releasing pinned buffers), and
simply releasing the memory is not sufficient.
</para>
<para>