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 1wkgeS-000opw-2h for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Jul 2026 11:22:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wkgeR-00HE5i-25 for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Jul 2026 11:22:43 +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 1wkgeR-00HE5a-0y for pgsql-hackers@lists.postgresql.org; Fri, 17 Jul 2026 11:22:43 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wkgeP-00000000kpf-0PvJ for pgsql-hackers@postgresql.org; Fri, 17 Jul 2026 11:22:43 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-472326ca506so6138711f8f.2 for ; Fri, 17 Jul 2026 04:22:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1784287359; x=1784892159; darn=postgresql.org; h=message-id:date:content-transfer-encoding:content-id:content-type :mime-version:comments:references:in-reply-to:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to:content-type; bh=CwxDmT4W1RPhl9hPfnpEaaHHzDANMrbMcsEXm4P9iyI=; b=bHtl+Bgmq3TPQxFybEluZWZ8y9rSfOruMT51SoE6J2i2FEqdwcyfAvSa35ce6nndRH HfndY8I+s11YI9HLc8+qD9iMf5EYCu3OLDq5bOUTy+gDh6I9Eb2TNaqVMabNir+rOdGm rjVFr4/eMRiWNDviLARMFhODtMhk+5s4BYYjILnYwcQDoOSu4Bx32HwcbErtF8cOCe3H 2QtaHMFkGTt141rUmhnrxIHFRv8vzPWFMljm7h3GD2yCy7H5Yigfq+3JdfAuiD6HP4qS ITGQ5VfEtxqjq4pCADHOqo8oiedqomZxex/wRt8sbxi1QHT/v/0USBZhkTO+kJ5o8ZW8 wfow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784287359; x=1784892159; h=message-id:date:content-transfer-encoding:content-id:content-type :mime-version:comments:references:in-reply-to:subject:cc:to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=CwxDmT4W1RPhl9hPfnpEaaHHzDANMrbMcsEXm4P9iyI=; b=rxFFXsf16pbymwb3/OJBlIJoGFv+7rL7WUY4awvgV53msVKbpKmqSrl5mXVjwPqDso 4QCUZdkveDN+E67d/jGdrxswM/+8buuvXYOJPLywPVwaYXpGpDDmwRBjIUHpiSYy8VdR OFlTzATOqHlrAZb3nMiQMfA7ONDYtyr36oLZ9clGKurHkUFgJNKIvhlHnQQJm7Yp7bbb yQHTlvq+FXTSFtVaKAA19fTZYz0LOsfhVD1yBAhDz+WBYyQENTGZBYVnuTwW4vLprjMf cO/tey3cR+c/k1kVjQtfY4W0cMJA0b1eKrtEHcVwWTkfyYSvcGhxkHEe6D/afMX3h+Zi B+RA== X-Forwarded-Encrypted: i=1; AHgh+RrA7J2c3NVoxPFC79qm7HFB2DwwnmoSzgyMbgmJxImSjZWUgIH92QFN8Fx+ZxjKcKSH20/deRQ6BlAsI10v@postgresql.org X-Gm-Message-State: AOJu0YxE/2bZGO6o3dGRuvp6G5cyFZd1DrGNIoROklXfa9EIdhJeLkVM f3XxmMpfGHFDgGMTdr3EnGa/O62Vbow/+QLMgufup509PO37lu+mPpLthTADQEkFsa0= X-Gm-Gg: AfdE7clcwTwn8zbq+y8E5QaN9tdNlXUPvWvUjLr9EiQLJBGGSm7MAQCdAQdI6Tp9kxu N3kjHVplNlPxaezcli4IRYl8o8JYBDNhFJOPaSmRijnMwso9614xK14tUvIcUMFhcX1Eal66Ynz gYvY0Nqf8SV0X0Xy6O5pHjGHL6z0zIO5+MjzC7xawb4bq3YtqeeF7VXmwPYWfAzRap+G4Yflg9t pzACu3OkQxwHacTN0bYepiAfv4wIrhIAxyYtNwOkdirXpvbaLJOgLFs4kLsJH39Di+g8rWO+0i4 IZcHzqrvJlglICEzsIgW9ylBWwFwfHjRxQn/UbfL/8EPE0bWgXOrTsiPP6sn6MURcgyWIeVeU4D R5JUeXd7/iN4yuihILNt6Una3SjkigDZMiqB4AHUOtZjwPt1Q8fvSHeH12SgyI7JixA2dI4jbFm Lm0Jj8qIp++kdWhvFCNJPgFcdQBQ== X-Received: by 2002:a05:600c:1554:b0:493:c10c:22f0 with SMTP id 5b1f17b1804b1-4954a50d963mr28389835e9.20.1784287358658; Fri, 17 Jul 2026 04:22:38 -0700 (PDT) Received: from localhost (109-81-170-190.rct.o2.cz. [109.81.170.190]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49549c9c940sm45628565e9.13.2026.07.17.04.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 04:22:38 -0700 (PDT) From: Antonin Houska To: Amit Langote cc: Junwang Zhao , cca5507 , Daniil Davydov <3danissimo@gmail.com>, PostgreSQL-development , Tomas Vondra Subject: Re: Batching in executor In-reply-to: References: <68f3771f-91f5-4cb7-b1de-74d9abbf0b96@vondra.me> Comments: In-reply-to Amit Langote message dated "Fri, 03 Jul 2026 14:19:46 +0900." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29987.1784287357.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Fri, 17 Jul 2026 13:22:37 +0200 Message-ID: <29988.1784287357@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Amit Langote 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 comm= ent about not increasing the number of arguments is no longer valid. (I'm no= t 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 diff --git a/src/backend/access/table/tableamapi.c b/src/backend/access/ta= ble/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 !=3D NULL); Assert(routine->scan_rescan !=3D NULL); Assert(routine->scan_getnextslot !=3D NULL); + Assert(routine->scan_getnextbatch !=3D NULL); + Assert(routine->batch_slot_callbacks !=3D NULL); * I think it's clearer to retur NULL here. (The current coding works becau= se TupIsNull() is called upper in the stack.) diff --git a/src/backend/executor/nodeSeqscan.c b/src/backend/executor/nod= eSeqscan.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 no= t 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 wrappe= d 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 su= ch 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. "minim= al 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