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 1vkZJj-00H3xQ-03 for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Jan 2026 03:00:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vkZJi-00BhSe-0V for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Jan 2026 03:00:34 +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 1vkZJh-00BhSV-2h for pgsql-hackers@lists.postgresql.org; Tue, 27 Jan 2026 03:00:34 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vkZJf-00000000dlW-4ByD for pgsql-hackers@postgresql.org; Tue, 27 Jan 2026 03:00:33 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-34ccbf37205so2530123a91.2 for ; Mon, 26 Jan 2026 19:00:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769482830; cv=none; d=google.com; s=arc-20240605; b=HfIZkitOHW5KIBegDZvZ2u5ag1w5kS9rnLnsj3/VqmpEy3610anPnTsAzhbuX/btKE uJsQ5f2U8uoMga46EXhKu0PM/Y6ttDchDJg2qV905uzV/dMduYAV57EnwRKZ3WAGNLVv 9O+aBEzKK4YCRne61aivC91ZyjU5ydqQ7qHDoKZIMsB76Ue40puHmo4NYpBf57ed+8eQ D/28xjBqwmEijsa9THfsP8HvWMt2rmNyo7AJp9a4cxGLsx4bce7Vm6lVgAR7LA1BTb9o tTXbsyeMnfg7gsoim9vEXRnSAe9tPzhEV7T6AYAiz7UKC/ZzYcy/Gu7B6Ifl9kIzW5C4 w+ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=JGb7aD5BdfbhCdeOJXkxLaKCUepiYAxpbA9maA2sBHw=; fh=OtUAHjschS6K5Ds5s+1mf1el455HsU0NnAwG77t2d2U=; b=LXWplSbBNNh5CXLumum4dDSIpRcGnyg+LSy5wlA/QQSh078CaUomu0GS6zZkSP+V0W FoNlgjiqHfmVGDSRZgvedWwCvMxufcPlig4F/5/R8zzS3G51AfePzOcErPrhNaIhWVCi Od2ooee5FZvgOF9MBf/DQqa7oA47AbFrqX1av2RCIf6VWZ9ufk+EguobplX9OF1STCtW +zagxrCDS2dDBhuG2ipfoebpn0zKpc3/bFe8VtPiilBYywCGNqjos2GtMnHLqU3d0pEV QE5N2mkq90W6b8Lja5b7GB6SlYXS4djX14rJowHXocx40nysL3zl+fmnt+bZ/wOtu5N+ PHmQ==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769482830; x=1770087630; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JGb7aD5BdfbhCdeOJXkxLaKCUepiYAxpbA9maA2sBHw=; b=KSKHFXPjAMJ3hhjQOoRM+TCZ95OXvfbsOlOi6vPl1dpWBoAJE85YZJf5sv11Hh4K9d yoIZmgmSRv2q97upgXenAc4B418uOf9zT1SFAC28hRphu6mgZrzRidxKSgkcD0+O3snt YTGxsKOHn68TwXBHCKYekH9vrGmfXCL06568Xd9ST9S+9cXIMJLoIGWG26jhn+mPatJz A9JJX1qzD+XKSKWSMIST7Zsmm/vD2LFv4T9WQRV65YaFJkOVsGnYsFVDIvO8T5pvVdl8 yxSJui2pKcOijQ8yHVln0D+wATQtB66ug82dwDCiMYo70j08jkJd/DFMmm+fUVAr1z+3 XKtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769482830; x=1770087630; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=JGb7aD5BdfbhCdeOJXkxLaKCUepiYAxpbA9maA2sBHw=; b=PjJ1Swd5VdZUj/3nFouraPhfpdbvJ7el6Qywbu56QQox/RhMdFMaEV//T9WB+EePzN RJUIVE5biL+H5eCx79saHz0ypnkovmrM+txHn13NKuHaAPh/wuQk5kQM/+HIUPYigz32 ihBEZcLzoKlkRLMUD3F2ZyRWHPNL9ycBjUxs1FhQTlYrBUsPkqfvzzhZGFeixcvJ3wQK 3PyhVc2KL/TmgPC91H1jXGaykeyXXZIAxVMCtefwCqxLQfRDmsjfNY23/O/zHubwoykC E148pNX/gIBg8BqQYyURX5IbAJNtmi00g/oY6O0xBxbX1xAHbAY1l/I83IKf6jR4hBJ9 TCpA== X-Forwarded-Encrypted: i=1; AJvYcCU5ndH8ZKSfDWnktVJy3cjGjnhiFFLPjmIADblxfR7AWlotAtx0gt2i4vTdnCfPButghHuR2v1y4hi7Hdqv@postgresql.org X-Gm-Message-State: AOJu0Yze1VGZzHAuaWDWIVL5vE6HgLYwkwuFrvsbXrE+p0VIBaA7GSNU EOdsv5/VDhhFMDlScDDkLDSODmKfpQ983gNeKm5gV4onOK/bNrQ9qLmOXgqeheg6ib0x0Dapr+x w384ilso5S+1pzxB0ug/+TjNls87V/E8= X-Gm-Gg: AZuq6aK2NoKTJXbvPIzJyYDlFJCbPySlqLx1HrHBkBP++T9hrKCCn1bJahRf4fTs6B2 G1/pZbzvcJnK004fclZXfF4U4okpJ2S5MCLqJ8V7UHlfjuQRgn0foX8ibwxXKZuZCUfrWFjHVWv dIyl1gAlyyZQaZ8Uqv5fRm8vQ67p85bC6+2FIkRu9y/8tMYD62gBDs705zMEuWM5Fp7OE7NdUpq R9A8AScxNZSucvbrdZhtA7Nxyc2mtUL1d8awsnewZEaYrhallD2gsu88RRGLc+D8tajkQYF X-Received: by 2002:a17:90b:1b51:b0:340:25f0:a9b with SMTP id 98e67ed59e1d1-353feda1830mr365631a91.33.1769482829965; Mon, 26 Jan 2026 19:00:29 -0800 (PST) MIME-Version: 1.0 References: <68f3771f-91f5-4cb7-b1de-74d9abbf0b96@vondra.me> In-Reply-To: From: Amit Langote Date: Tue, 27 Jan 2026 12:00:13 +0900 X-Gm-Features: AZwV_Qj4XGE93dQCg_KHwPMEASDdVHV-XQdtjINlYdcqe3GmD9U09DxS6xbSd9A Message-ID: Subject: Re: Batching in executor To: Daniil Davydov <3danissimo@gmail.com> Cc: cca5507 <2624345507@qq.com>, PostgreSQL-development , Tomas Vondra Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Mon, Jan 26, 2026 at 6:34=E2=80=AFPM Daniil Davydov <3danissimo@gmail.co= m> wrote: > > Hi, > > On Mon, Dec 22, 2025 at 6:46=E2=80=AFPM cca5507 <2624345507@qq.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 befor= e reaching the end of scan, right? > > > > Yes. I think that we should advance to the next page if "nout =3D=3D 0" > at the end of walking through the rs_vistuples. Next version (v5) does it like that. > > 6) heap_begin_batch() > > ``` > > hb =3D palloc(sizeof(HeapBatch)); > > hb->tupdata =3D 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 cour= se > 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. I think combining those individual pallocs into one is a good idea, so v5 does it like that. > A few other comments on 0001 patch: > > 1) > + void *(*scan_begin_batch)(TableScanDesc sscan, int maxitems); > Is it syntactically correct? Yes, it compiles fine. Though I'm considering changing the return type to a struct with common fields (like nitems) so callers can access them directly without callback indirection. Maybe call it TAMBatch or something. > 2) > /* Initialize static fields of HeapTupleData. Row bodies remain on pa= ge. */ > relid =3D RelationGetRelid(sscan->rs_rd); > for (int i =3D 0; i < maxitems; i++) > hb->tupdata[i].t_tableOid =3D relid; > > Is it really necessary? I see that we are setting this field inside the > heapgettup_pagemode_batch function. It's intentional -- by initializing t_tableOid once in heap_begin_batch, we can avoid setting it repeatedly for every tuple in heapgettup_pagemode_batch(). Though you are correct to point out the redundant assignment in heapgettup_pagemode_batch(); I'll change it to an Assert instead. The relid doesn't change during the scan. > A few comment on 0002 patch: > > 1) > I guess that you should rebase your patches on the current master, becaus= e > the second patch doesn't apply. Yep, will do. > 2) > Maybe we can use tuplestore for tuples stored in TupleBatch? It is just a > proposal - I didn't check this idea carefully. TupleBatch is designed to be lightweight -- it holds an array of TupleTableSlot pointers, not the tuple data itself. The slots reference tuples that remain in the AM's buffer (no copy). Using tuplestore would require materializing tuples, adding overhead we're trying to avoid. --=20 Thanks, Amit Langote