Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wvANk-0017QW-0l for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Aug 2026 09:08:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wvANg-003je3-2Z for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Aug 2026 09:08:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wvANg-003jdu-1F for pgsql-hackers@lists.postgresql.org; Sat, 15 Aug 2026 09:08:45 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wvANe-00000000rRo-0yvi for pgsql-hackers@postgresql.org; Sat, 15 Aug 2026 09:08:44 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-5aeb8c19017so2306378e87.0 for ; Sat, 15 Aug 2026 02:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786784920; x=1787389720; darn=postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:content-type :message-id:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=KOCljsv4JoLiZQa/4bUpA1sH4+UdCw6Nejw4OMx2iOA=; b=SiP9vT0DG1z82OnOTztkCBVnMJBtE4JgnKZ/dUULuXqUkXctyf0IEb75PIas7FawM3 O9/A94vN7hQXQ5rQrW2zYeK3f7HlwD4G8Ofl7hQmiiPWInHf27Z2ei2qry6OIxfaja4n sYySP9OcZEpufMocjZUBlqrKRv3QLjYgMoNaoNsisYHe4KCsB46oUeuX16x3mTcOSvZa Wfh+b5BZjUpoG6rbC6eA2pdH1SjGNLus+U0gNsJkJf+71d/8lFNt+Mva777NOYOKiKzq Rqv8D5zb3bgMgPArBLzgKMCri8fx3AmsrB2Nt/+SKPyl+rr7/geEMbuQf/FInINYC+Zu Pn2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786784920; x=1787389720; h=references:to:cc:in-reply-to:date:subject:mime-version:content-type :message-id:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=KOCljsv4JoLiZQa/4bUpA1sH4+UdCw6Nejw4OMx2iOA=; b=BwSUG5xmgd7hTeg5tJInMTfXgfYU/SFsYQjuTLvOgFFymCtDxC1uPS6AWyXKK5jswp Hrfb5eJ+tPoOKDH1fbprgwimBd5xb3+HuHeqyoEkPeYq4jdrlXkYbc6JqTbI+DItSql0 mkGWp4MSH2KsszXXAz0LpYNK8xNq7RkkJywE+eySKq36vO4jgZRi9X1ZnWldlDTz3Fl2 28WdZytUd5Z38BLLaxSxHZKUK24y7y8o4GRYlfH0cPR2mS7J8W21yQ6h6pItDdyi7sbO Rim630IEVFaUeKVNd2vX0uTwuXy65mzFmqCjKp0ceHRPiW1potUAntLjW5ch0gTZ8IHI dm1g== X-Forwarded-Encrypted: i=1; AHgh+Roite4kxrKuTVVdR+yKO9xwxzVszKKXI8/I9xzFHjsk/CdaBnU+a+0c67guAxrsZNgMpFMwSqV1akuuWYhw@postgresql.org X-Gm-Message-State: AOJu0Yz1FZKX6F2OEtqorKqF2mkdLrY2tfVttnRLVnnzAsqF2q3b8tQQ sz/zooCPwUCMFk6/GDqg2I3OhM6GO1l8vpcTWX/Cek6X4niGDE5akuR4 X-Gm-Gg: AR+sD12RQhsVUjoHnBMXuvA2X36+yp4PEvhbnutumKGH1T71ZyivzsrGYA5EwG10b1b zzaHHk8BvjvuDmOIBco8K+3opgUuEAGCizNp0PE7nx5bNIVBScGurxx5wYN1l/0GJFVTKLg4a2I A9id2NjArqHKtWuHFt8QkRf6tOPEN+W8kdREQTCZz8TVQGLftYqmjRZwNHEkcpnvZWuYGXB1oGV G+VILrsCLa7KasHYKdTQNgv/D2zWpG5SDH3T6ju6Ew22NPa9x9h8BDDDYy22ikzprXpyFvkns7p 8DOQPSqMg/QMnRU66wBbTNb6gLRz0Z8JNZjrUu7TqLE+qtuSiCuuKiEtVA51US9pyhnyoy59fmu 1lNsGM3x5eaR6GcSc9IUAiBIZj1ofKjFkR3E4msicg074zL5M4xZtw6/tKCw6aiQzvPn/nR//Df LBByM8kNibfc7Y8mXyeP9muv5zAgmRlUnaAd0RoVQHUSQSUxaUi6Sla4HWMTEAU8L059FVGe3AJ BuyshvTGik46rFYQgRBu9jcvzphHNiXrP1/UbBfnc3fMvfQTm6IQbDw X-Received: by 2002:a05:6512:66da:b0:5b2:e82b:37f5 with SMTP id 2adb3069b0e04-5b45910ae50mr1208896e87.2.1786784919400; Sat, 15 Aug 2026 02:08:39 -0700 (PDT) Received: from smtpclient.apple (mx-ll-171.5.28-175.dynamic.3bb.co.th. [171.5.28.175]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b45d41314csm716015e87.42.2026.08.15.02.08.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Aug 2026 02:08:38 -0700 (PDT) From: Denis Smirnov Message-Id: <85371DE4-6957-4408-9FAA-A4871B501AB6@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_2B6D1D6D-AD73-4E42-8C55-8D214CF02B5C" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: Batching in executor Date: Sat, 15 Aug 2026 16:08:18 +0700 In-Reply-To: Cc: Amit Langote , Antonin Houska , Junwang Zhao , cca5507 , Daniil Davydov <3danissimo@gmail.com>, PostgreSQL-development , Tomas Vondra , Mats Kindahl To: =?utf-8?Q?Erik_Nordstr=C3=B6m?= References: <68f3771f-91f5-4cb7-b1de-74d9abbf0b96@vondra.me> <3D8D1BA5-B8A6-400A-B605-42EEE37890B4@gmail.com> <30925.1784290324@localhost> X-Mailer: Apple Mail (2.3864.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_2B6D1D6D-AD73-4E42-8C55-8D214CF02B5C Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii 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 --Apple-Mail=_2B6D1D6D-AD73-4E42-8C55-8D214CF02B5C Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
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

= --Apple-Mail=_2B6D1D6D-AD73-4E42-8C55-8D214CF02B5C--