Re: Batching in executor

From: Daniil Davydov <3danissimo(at)gmail(dot)com>
To: cca5507 <2624345507(at)qq(dot)com>
Cc: Amit Langote <amitlangote09(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Tomas Vondra <tomas(at)vondra(dot)me>
Subject: Re: Batching in executor
Date: 2026-01-26 09:34:44
Message-ID: CAJDiXggP41+-HrRzT+BmtgmS8wkoZM7b4skkQA5NAe+NFEMPSQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Mon, Dec 22, 2025 at 6:46 PM cca5507 <2624345507(at)qq(dot)com> wrote:
>
> Some comments for v4:
>

Agree with your (1)-(4) comments.

> 5) heapgettup_pagemode_batch()
> If the scan key filters out all tuples on a page, we may return 0 before reaching the end of scan, right?
>

Yes. I think that we should advance to the next page if "nout == 0"
at the end of walking through the rs_vistuples.

> 6) heap_begin_batch()
> ```
> hb = palloc(sizeof(HeapBatch));
> hb->tupdata = palloc(sizeof(HeapTupleData) * maxitems);
> ```
> Can we just use one palloc() for cache-friendly?
>

Actually, we are using memory context when calling the palloc function.
I.e. in the general case it will not cause memory allocation. But of course
there is no guarantee for it. I saw a lot of places in the code where we
are calling the palloc function several times in a row, so I guess that
this is OK.

If you will decide to leave these palloc calls, I suggest using the
palloc_object/palloc_array functions.

A few other comments on 0001 patch:

1)
+ void *(*scan_begin_batch)(TableScanDesc sscan, int maxitems);
Is it syntactically correct?

2)
/* Initialize static fields of HeapTupleData. Row bodies remain on page. */
relid = RelationGetRelid(sscan->rs_rd);
for (int i = 0; i < maxitems; i++)
hb->tupdata[i].t_tableOid = relid;

Is it really necessary? I see that we are setting this field inside the
heapgettup_pagemode_batch function.

A few comment on 0002 patch:

1)
I guess that you should rebase your patches on the current master, because
the second patch doesn't apply.

2)
Maybe we can use tuplestore for tuples stored in TupleBatch? It is just a
proposal - I didn't check this idea carefully.

--
Best regards,
Daniil Davydov

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-01-26 09:35:59 Re: Newly created replication slot may be invalidated by checkpoint
Previous Message Peter Eisentraut 2026-01-26 09:34:10 Re: alignas (C11)