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 1xNm0H-00000002jqU-203O for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Nov 2026 06:58:50 +0000 Received: from localhost ([127.0.0.1]:53490 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xNm0G-00000001pBG-3vZo for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Nov 2026 06:58:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:43826) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xNm0G-00000001pAr-1QrM for pgsql-hackers@lists.postgresql.org; Mon, 02 Nov 2026 06:58:48 +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 1xNm0C-000000027bu-44v2 for pgsql-hackers@postgresql.org; Mon, 02 Nov 2026 06:58:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1793602721; bh=MofHqvCydUi8njgTMzheaCCAu614cZfkR1DTEp55PM4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID:From; b=erRZUAB22RSgm3PmKUFlZCuB9AWUqdhcg5vmkaTaodOZh0ZJF7yQm9V2mmWOoO4PG jX1Rgi6qXMrhroEe4enL+ufyQM6M4cQ5oVb1vrrjyMjhiaoukCgJZySIASqgMXWdhE MyaXeXPrHPTAbLPkQWYjFnzom+QCBKPMytuYUsV9ENJa7Wk+GdgTsg8HuICTfYEw8Y /51FGLEN75U058alcmHtYnIOOoyMT/kx22IT1xCfNJrkYIvnsIYKIAZqW5lIQcpSm8 95XzXInaLv+ZmoOMv2SizQGdpqwEGUGUR+UJOuM47G4hyQYuXu8Pk2svBXINAuqRWP 2TyxQxLyRYX3g== 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 0D10960541; Mon, 02 Nov 2026 09:58:41 +0300 (MSK) MIME-Version: 1.0 Date: Mon, 02 Nov 2026 09:58:40 +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: <0bf760a18b139ece9f447c2082499e6d@postgrespro.ru> 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/11/02 05:10:00 #28779465 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-11-01 20:44: > Hi Alexander, Hi. > > On Wed, Oct 28, 2026 at 8:37 PM Alexander Pyhalov > wrote: >> 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 > > [snip] > >> s/csse/case/ > > Fixed. I also tweaked the comments a bit further. > /* * This is the case when an asynchronous request made by the - * requestor for another subplan is currently in-progress. Skip the - * configuration even in the case where the requestor is MergeAppend; - * in which csse we just defer the configuration until the preceding - * request(s) are processed by ExecMergeAppendAsyncDrain. + * requestor for a preceding subplan is currently in-progress. Skip + * the configuration even in the MergeAppend case; in that case just + * difer the configuration until the caller processes the request(s) + * for the preceding subplan(s). */ s/difer/defer/ >> 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? > > Agreed. I updated fdwhandler.sgml to incorporate that perspective. I > updated postgres-fdw.sgml and src/backend/executor/README as well. > Looks good to me. > I also adjusted regression test cases and their comments. While doing > that, I noticed these test cases: > > +-- Test async Merge Append rescan when a LIMIT stops the scan before > every > +-- async subplan's request has completed, so on the next rescan (for > the > +-- next outer row) some subplan's request is still in flight. > +EXPLAIN (VERBOSE, COSTS OFF) > +SELECT g.i, s.b FROM generate_series(1, 3) g(i), > + LATERAL (SELECT b FROM async_pt WHERE a > g.i ORDER BY b LIMIT 1) s; > > +-- Test async Merge Append rescan when a LIMIT stops the scan before > an > +-- async subplan's already-delivered result was ever consumed (because > it > +-- didn't win the race to the heap top). The next rescan (for the > next > +-- outer row) must not mistake that leftover result for a fresh one; > the > +-- expected result increases each row, so a stale reused value would > show > +-- up as the first row's value repeating instead. > +EXPLAIN (VERBOSE, COSTS OFF) > +SELECT g.i, s.b FROM generate_series(1, 3) g(i), > + LATERAL (SELECT b FROM async_pt WHERE a > g.i AND b > g.i * 100 > ORDER BY b LIMIT 1) s; > > These are testing the old implementation? There are two more test > cases for testing the rescan, which seems to me good enough, so I just > removed them (and adjusted the comments for the remaining test cases). > Maybe I'm missing something, though. > Firstly I've confused these tests with another one: +-- Test ExecMergeAppendAsyncReset code path that asserts async requests +-- made for subplans aren't pending anymore at ReScan +-- SubPlan case +EXPLAIN (VERBOSE, COSTS OFF) +SELECT + ARRAY(SELECT f.i FROM (SELECT b + g.i FROM async_pt WHERE a > g.i ORDER BY b) f(i) ORDER BY f.i LIMIT 10) +FROM generate_series(1, 3) g(i); The reason is obvious - comment is misleading. In the previous version of the patch it was -- Test async Merge Append rescan Now it states -- Test ExecMergeAppendAsyncReset code path that asserts async requests -- made for subplans aren't pending anymore at ReScan -- SubPlan case The original intention was not this, it was to show that valid async subplans are recalculated after rescan (and identification of new valid asyncplans). Likely, the comment has to be fixed. And yes, as now we wait for all async requests to deliver results, it seems we can't have "old" results from previous runs while looking at node->ms_slots, corresponding to async plans. So, I suppose that tests that you removed, can be safely removed. -- Best regards, Alexander Pyhalov, Postgres Professional