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.98.2) (envelope-from ) id 1xM1yR-00000001onR-0wj7 for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Oct 2026 11:37:44 +0000 Received: from localhost ([127.0.0.1]:48938 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xM1yQ-0000000G0ZU-355s for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Oct 2026 11:37:42 +0000 Received: from makus.postgresql.org ([72.32.157.229]:37704) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xM1yQ-0000000G0ZG-0ZfY for pgsql-hackers@lists.postgresql.org; Wed, 28 Oct 2026 11:37:42 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xM1yN-00000001LyV-0Cpa for pgsql-hackers@postgresql.org; Wed, 28 Oct 2026 11:37:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1793187455; bh=OdNR6AUwaRE8tnTDSwGWl+LbUp5djAtf8vryaqhwxcw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID:From; b=2lSOk4h4ZGrOS1YLe2cpbtPeFNrflEV4mf3XbScJdHmZ76WKE4UMSt5B6VFJgniN0 5I22n6S1rxGMUHEjF5LR4tBDWd0prkzktKPlQGY1Wt+5b/Ka5nTtnLHn3w4xqoHqbp c+S+GWBhzNIIlJRY+6RMV4x5mbHuk92HbNJiLSnYVE4DzHiFmbIWY9784by6YQbbFp 95TBLeKP8dZDMn5E1MkSPgGC/MEvOiJPphTIArnFHeFAFyd0CfJO694UW7m5hKMyiK sIKS1raE1hdih79oOjU0r7d3QnwGtfwoiHWHs8oe+gGWqZSwqnnY/uLFzWQqSK0L0a IUD8h0Vm01htQ== Received: from mail.l.postgrespro.ru (webmail-master-mstn.l.postgrespro.ru [192.168.2.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.pyhalov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 33D8A605BA; Wed, 28 Oct 2026 14:37:35 +0300 (MSK) MIME-Version: 1.0 Date: Wed, 28 Oct 2026 14:37:35 +0300 From: Alexander Pyhalov To: Etsuro Fujita Cc: Alexander Korotkov , Matheus Alcantara , Pgsql Hackers Subject: Re: Asynchronous MergeAppend In-Reply-To: References: <59be194c5a409fb9fc9f2031581b8a44@postgrespro.ru> <2fb1d9923b6995492e7b163e6cb95402@postgrespro.ru> <782a968c8e01ec6db3b2da2120adf73b@postgrespro.ru> <554a73f7ffea8b22b3f81a4804b5fc34@postgrespro.ru> <42a9a941-e768-4fd8-8067-12958c5a1d70@gmail.com> <10c97af0ce34ebdb81708b1c49ed6038@postgrespro.ru> Message-ID: X-Sender: a.pyhalov@postgrespro.ru Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 3.0.0.9059, bases: 2026/10/28 10:04:00 #28752886 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Etsuro Fujita писал(а) 2026-10-27 14:34: > On Thu, Oct 15, 2026 at 8:34 PM Etsuro Fujita > wrote: >> I've already started reworking on Alexander >> Pyhalov's original patch for that. I will post a reworked version as >> soon as possible. > > Here is an updated version of the patch, which I created with AI > assistance. In the patch I removed the changes made to both the > MergeAppendState struct and nodeMergeAppend.c so that async execution > of MergeAppend works (almost) the same as that of Append, and then > modified them in a more optimized way, which makes the patch pretty > small/simple. Hi. I've looked through the updated patch. It looks good, but I've found some misprints in comments: 1) postgres_fdw.c - you have a typo here 8708 /* 8709 * Otheewise, process the in-progress request, begin an asynchronous 8710 * data fetch for the given request, and configure the file descriptor 8711 * event below. 8712 */ 8713 process_pending_request(pendingAreq); 8714 fetch_more_data_begin(areq); .... 8718 /* 8719 * This is the case when an asynchronous request made by the 8720 * requestor for another subplan is currently in-progress. Skip the 8721 * configuration even in the case where the requestor is MergeAppend; 8722 * in which csse we just defer the configuration until the preceding 8723 * request(s) are processed by ExecMergeAppendAsyncDrain. 8724 */ 8725 return; s/csse/case/ 2) nodeMergeAppend.c: 199 if (mergestate->ms_nasyncplans > 0) 200 { 201 mergestate->ms_asyncrequests = (AsyncRequest **) 202 palloc0(nplans * sizeof(AsyncRequest *)); 203 We could use palloc0_array as in surrounding code. 3) One more issue is that we change current semantics of ForeignAsyncConfigureWait - out-of-tree FDWs now should handle MergeAppendState in addition to AppendState as requestor. Should we at least document it? > > Some notes about the patch: > > * As for the struct, I removed from it ms_asyncresults, > ms_has_asyncresults, ms_asyncremian, ms_needrequest, > ms_valid_subplans_identified and ms_valid_asyncplans; and instead > added to it new member ms_asyncpending, which doesn't exist in > AppendState. As for the source file, I modified it based on the new > data struct, reusing some of the code in the original version. > * I adjusted the change made to create_merge_append_plan(), which > makes the original 0001 patch useless, so I removed it from the patch. > * I deduplicated the code in ExecAppendAsyncEventWait() and > ExecMergeAppendAsyncEventWait() as mentioned upthread. I didn't do so > for other functions/parts, though, because I don't strongly feel the > need for that. (I didn't include any of the proposed refactoring, > either, for the reason I mentioned upthread.) > * I modified postgresForeignAsyncConfigureWait() a bit further to work > better with async MergeAppend, and rewrote comments there. > * I did some editorialization as well, including renaming/relocating > functions like GetAppendEventSet() in the original version to match > other functions. > * I used the regression tests in the v22 patch as-proposed. I think > some comments should be updated, but I haven't done that yet. > > What do you think about that? Maybe I'm missing something, though. > -- Best regards, Alexander Pyhalov, Postgres Professional