pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Denis Smirnov <darthunix@gmail.com>
To: Erik Nordström <erik@tigerdata.com>
Cc: Amit Langote <amitlangote09@gmail.com>
Cc: Antonin Houska <ah@cybertec.at>
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>
Cc: Mats Kindahl <mats.kindahl@gmail.com>
Subject: Re: Batching in executor
Date: Sat, 15 Aug 2026 16:08:18 +0700
Message-ID: <85371DE4-6957-4408-9FAA-A4871B501AB6@gmail.com> (raw)
In-Reply-To: <CACAa4VKb75kUpptWAg5r9tXmu0=bBkWyLtFLXTR2SJ_nZEcYqA@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>
	<3D8D1BA5-B8A6-400A-B605-42EEE37890B4@gmail.com>
	<30925.1784290324@localhost>
	<CA+HiwqGQPDwxK7QQNUWhqhAEwaH4Z+YQhHG5jNPYHGNzDMfsXw@mail.gmail.com>
	<CACAa4VKb75kUpptWAg5r9tXmu0=bBkWyLtFLXTR2SJ_nZEcYqA@mail.gmail.com>

Hi Erik,

Thank you. Your slot-based design is very close to the direction I think we
should take.

The idea is to generalize tts_batch for both heap and columnar storage. We
do not want to add a new table AM callback. A batch should keep its native
data for as long as possible. For heap, this would be an array of Datum
values for each column, built from a pinned buffer page. A columnar slot
could keep Arrow arrays, compressed columns, dictionaries, or any other
extension-specific data. Conversion to Datum would happen only when a
regular PostgreSQL node asks for rows.

The structures could look roughly like this:

typedef struct TupleBatchRequest
{
    Bitmapset *filter_attrs;
    Bitmapset *output_attrs;
} TupleBatchRequest;

typedef struct TupleTableSlotBatch
{
    const TupleTableSlotBatchOps *ops;
    void       *private_data;
    const TupleBatchRequest *request;

    /*
      * One bit per row. A set bit means that the row passed the filters.
      * NULL means that all rows passed.
      */
    const uint64 *selection;

    uint64      generation;
    int         ntuples;
    int         current;
} TupleTableSlotBatch;

TupleBatchRequest would be set in the scan slot during initialization. The
separate attribute sets allow the slot to prepare filter columns first.
After filtering, it can prepare output columns only if some rows passed.

The ops identify the native batch layout. They also provide a way to convert
the needed data to Datum and a way to mark the batch as consumed.

ExecProcNode() would remain the only interface between plan nodes. Existing
nodes would ignore tts_batch and continue to read the current row through
the normal slot API.

A batch-aware node would call ExecProcNode() in the same way, then inspect
slot->tts_batch. If it understands the batch ops, it can process all
remaining selected rows at once. Otherwise, it uses the normal row path.

A simple projection could keep the batch and only remap column numbers. A
complex projection would switch to the normal Datum row path.

A batch-aware Agg could read the selection bitmap and native columns
directly. It could add an aggregate FILTER mask and process the whole batch.
Unsupported aggregates or batch layouts would use the existing row path.
The final aggregate values would still be returned as normal Datum values.

After processing a batch, the parent must mark it as consumed. The next
ExecProcNode() call would then read the next batch. This step must also
update executor statistics. The scan node counts rows rejected by filters,
and a helper such as

    ExecConsumeSlotBatch(child, slot, nconsumed)

could account for all rows processed by one ExecProcNode() call.

This also seems to fit current TimescaleDB well. DecompressBatchState could
be stored in private_data. total_batch_rows, next_batch_row, and
vector_qual_result map directly to the common batch fields.
CompressedColumnValues can stay in the native TimescaleDB format.
compressed_batch_discard_tuples() already works like the consume operation.

ColumnarScan could return this slot through its normal ExecProcNode().
VectorAgg could detect the batch and process it directly, without bypassing
ColumnarScan and reading its child.

Does this match what you would want ColumnarScan to expose?


Best regards,
Denis Smirnov

view thread (49+ messages)  latest in thread

Message-ID: <85371DE4-6957-4408-9FAA-A4871B501AB6@gmail.com>
Permalink:  ../85371DE4-6957-4408-9FAA-A4871B501AB6@gmail.com/
Also on:    postgresql.org/message-id/85371DE4-6957-4408-9FAA-A4871B501AB6@gmail.com

 · 

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: darthunix@gmail.com, erik@tigerdata.com, amitlangote09@gmail.com, ah@cybertec.at, zhjwpku@gmail.com, cca5507@qq.com, 3danissimo@gmail.com, tomas@vondra.me, mats.kindahl@gmail.com
  Subject: Re: Batching in executor
  In-Reply-To: <85371DE4-6957-4408-9FAA-A4871B501AB6@gmail.com>
  References: <CA+HiwqFfAY_ZFqN8wcAEMw71T9hM_kA8UtyHaZZEZtuT3UyogA@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> <3D8D1BA5-B8A6-400A-B605-42EEE37890B4@gmail.com> <30925.1784290324@localhost> <CA+HiwqGQPDwxK7QQNUWhqhAEwaH4Z+YQhHG5jNPYHGNzDMfsXw@mail.gmail.com> <CACAa4VKb75kUpptWAg5r9tXmu0=bBkWyLtFLXTR2SJ_nZEcYqA@mail.gmail.com> <85371DE4-6957-4408-9FAA-A4871B501AB6@gmail.com>

* 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