pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Antonin Houska <ah@cybertec.at>
To: Amit Langote <amitlangote09@gmail.com>
Cc: Junwang Zhao <zhjwpku@gmail.com>
Cc: cca5507 <cca5507@qq.com>
Cc: Daniil Davydov <3danissimo@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: Tomas Vondra <tomas@vondra.me>
Subject: Re: Batching in executor
Date: Fri, 17 Jul 2026 13:22:37 +0200
Message-ID: <29988.1784287357@localhost> (raw)
In-Reply-To: <CA+HiwqHv1CggSbpn=n+GU=Cp1AqDD25=hzx_PTYyqjMyZO2+mA@mail.gmail.com>
References: <CA+HiwqFfAY_ZFqN8wcAEMw71T9hM_kA8UtyHaZZEZtuT3UyogA@mail.gmail.com>
	<68f3771f-91f5-4cb7-b1de-74d9abbf0b96@vondra.me>
	<CA+HiwqGqeS_94wxiYa8VpymiR_OtFPKDSpX+Me=MYWO45f5yig@mail.gmail.com>
	<dbce8def-e817-4e70-a9cb-e62574724d95@vondra.me>
	<CA+HiwqGM0ZTeVHicSkGnCp-2U-jvU-KBQCkPJ0N7nAj_c2LjZg@mail.gmail.com>
	<CA+HiwqHyE7-oOvtZ+OC-4N7DvKSr8Jbu75erMLQ7O4d6gfkBhg@mail.gmail.com>
	<CA+HiwqEPMwhg6pUE4XML2rG4fRqKMpeGTtMwRPGes90f9iOqtg@mail.gmail.com>
	<CA+HiwqEZja5rJ78p3FBDZNvynWsHwanxyt6h0YaK_r84NemXng@mail.gmail.com>
	<tencent_B45268659AF0400F68EC1643950ABB6A1B09@qq.com>
	<CAJDiXggP41+-HrRzT+BmtgmS8wkoZM7b4skkQA5NAe+NFEMPSQ@mail.gmail.com>
	<CA+HiwqGufj46_4kT6z5nQrCOxp3rcMDR8fn_t33n2pDKokNRQg@mail.gmail.com>
	<CA+HiwqH-2GmTKLW9kHdnqV4KdFiPfuAdVK2TgqOM2JaaeUYXnw@mail.gmail.com>
	<CAEG8a3JKNRGwBb-C_YV6Px4aFHwd_G=AsB5AbfyU4-8YZT54AQ@mail.gmail.com>
	<tencent_164C2A5EDF8189DD70287661406D688A8506@qq.com>
	<CAEG8a3K22s9LmDZa486suFu3AV=yRuTf09j+Ww+djG63y=R8hg@mail.gmail.com>
	<CA+HiwqGkway9dcpTVmRs0Q=ZsQQ8Nx0MRjy9jfDmR8QFLnd-Mg@mail.gmail.com>
	<CA+HiwqHLjBegqeUw-babABj_icAiBTq5gh48-D3BEodVZkm8Ug@mail.gmail.com>
	<CA+HiwqEnHfjCVEo9PcTCNTCQVDBSRVeu=rPLqAc1tTafu7zowg@mail.gmail.com>
	<CA+HiwqHv1CggSbpn=n+GU=Cp1AqDD25=hzx_PTYyqjMyZO2+mA@mail.gmail.com>

Amit Langote <amitlangote09@gmail.com> wrote:

> The last version on this thread (v7, the "Rebased" post) used the
> RowBatch design: the AM handed the executor a RowBatch carrying a
> slice of tuples, a single scan slot was re-pointed at the current
> tuple through a repoint_slot AM callback, and an executor_batch_rows
> GUC controlled the batch size.  As I described in my pgconf.dev talk,
> I have regrouped around a smaller, incremental foundation and dropped
> that design. This series is the result; it supersedes v7 rather than
> extending it.

Interesting project! I've spent some time looking at the code:

0001:

* Since the BatchMVCCState structure ends up with a single field, the comment
  about not increasing the number of arguments is no longer valid. (I'm not
  sure though if the structer should be removed now.)

@@ -498,14 +500,13 @@ extern bool HeapTupleIsSurelyDead(HeapTuple htup,
  */
 typedef struct BatchMVCCState
 {
-	HeapTupleData tuples[MaxHeapTuplesPerPage];
 	bool		visible[MaxHeapTuplesPerPage];
 } BatchMVCCState;


0003:

* I'm not sure the batch-specific callbacks should be mandatory

inline patch 1: src/backend/access/table/tableamapi.c (+2/-0 lines) download inline-1.patchdiff --git a/src/backend/access/table/tableamapi.c b/src/backend/access/table/tableamapi.c index 5450a27faeb..9ef6b5cca65 100644 --- a/src/backend/access/table/tableamapi.c +++ b/src/backend/access/table/tableamapi.c @@ -45,6 +45,8 @@ GetTableAmRoutine(Oid amhandler) Assert(routine->scan_end != NULL); Assert(routine->scan_rescan != NULL); Assert(routine->scan_getnextslot != NULL); + Assert(routine->scan_getnextbatch != NULL); + Assert(routine->batch_slot_callbacks != NULL);
* I think it's clearer to retur NULL here. (The current coding works because TupIsNull() is called upper in the stack.)
inline patch 2: src/backend/executor/nodeSeqscan.c (+0/-0 lines) download inline-2.patchdiff --git a/src/backend/executor/nodeSeqscan.c b/src/backend/executor/nodeSeqscan.c index 5bcb0a861d7..943944ededa 100644 --- a/src/backend/executor/nodeSeqscan.c +++ b/src/backend/executor/nodeSeqscan.c @@ -85,11 +85,22 @@ SeqNext(SeqScanState *node) }
... + ExecClearTuple(slot); + + if (!table_scan_getnextbatch(scandesc, direction, slot)) + return slot; ... * I suggest that ExecStoreBatchBufferHeapTuples() checks the kind of slot, so it cannot be called on batch-unaware slots. Likewise, the existing ExecStore...Tuple() functions (plus ExecForceStoreHeapTuple()) should not accept the batch-aware slot. Maybe you need a separate macro for this (e.g. TTS_IS_BATCHBUFFERTUPLE). * I wonder if the 'tuples', 'ntuples' and 'cindex' fields should be wrapped in a structure, as in the future we'll need to add them to other slot types, when implementing their batch-aware variants. (The 'tuples' member of such a structure can point to an array of heap tuples now, but would need to be more generic in the future, to handle other kinds of tuples, e.g. "minimal tuple".) @@ -309,6 +311,34 @@ typedef struct BufferHeapTupleTableSlot Buffer buffer; /* tuple's buffer, or InvalidBuffer */ } BufferHeapTupleTableSlot; ... +typedef struct BatchBufferHeapTupleTableSlot +{ + BufferHeapTupleTableSlot base; + + HeapTupleData *tuples; /* points into HeapScanDesc->rs_vistuples[] */ + int ntuples; /* number of tuples in this batch */ + int cindex; /* index of last-returned tuple, or -1 if + * none returned from this batch yet */ +} BatchBufferHeapTupleTableSlot; * In the commit message you say "materialize copies the current tuple and retains the buffer pin, since the remaining batch entries still reference the page". Shouldn't it release the pin if after having materialized the _last_ tuple of the batch? -- Antonin Houska Web: https://www.cybertec-postgresql.com Patches: download all (2 files, .tar.gz)

view thread (49+ messages)  latest in thread

Message-ID: <29988.1784287357@localhost>
Permalink:  ../29988.1784287357@localhost/
Also on:    postgresql.org/message-id/29988.1784287357@localhost

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: ah@cybertec.at, amitlangote09@gmail.com, zhjwpku@gmail.com, cca5507@qq.com, 3danissimo@gmail.com, tomas@vondra.me
  Subject: Re: Batching in executor
  In-Reply-To: <29988.1784287357@localhost>
  References: <CA+HiwqFfAY_ZFqN8wcAEMw71T9hM_kA8UtyHaZZEZtuT3UyogA@mail.gmail.com> <CA+HiwqEPMwhg6pUE4XML2rG4fRqKMpeGTtMwRPGes90f9iOqtg@mail.gmail.com> <CA+HiwqEZja5rJ78p3FBDZNvynWsHwanxyt6h0YaK_r84NemXng@mail.gmail.com> <tencent_B45268659AF0400F68EC1643950ABB6A1B09@qq.com> <CAJDiXggP41+-HrRzT+BmtgmS8wkoZM7b4skkQA5NAe+NFEMPSQ@mail.gmail.com> <CA+HiwqGufj46_4kT6z5nQrCOxp3rcMDR8fn_t33n2pDKokNRQg@mail.gmail.com> <CA+HiwqH-2GmTKLW9kHdnqV4KdFiPfuAdVK2TgqOM2JaaeUYXnw@mail.gmail.com> <CAEG8a3JKNRGwBb-C_YV6Px4aFHwd_G=AsB5AbfyU4-8YZT54AQ@mail.gmail.com> <tencent_164C2A5EDF8189DD70287661406D688A8506@qq.com> <CAEG8a3K22s9LmDZa486suFu3AV=yRuTf09j+Ww+djG63y=R8hg@mail.gmail.com> <CA+HiwqGkway9dcpTVmRs0Q=ZsQQ8Nx0MRjy9jfDmR8QFLnd-Mg@mail.gmail.com> <CA+HiwqHLjBegqeUw-babABj_icAiBTq5gh48-D3BEodVZkm8Ug@mail.gmail.com> <CA+HiwqEnHfjCVEo9PcTCNTCQVDBSRVeu=rPLqAc1tTafu7zowg@mail.gmail.com> <CA+HiwqHv1CggSbpn=n+GU=Cp1AqDD25=hzx_PTYyqjMyZO2+mA@mail.gmail.com> <29988.1784287357@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox