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 1wqmMo-002P1z-0R for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Aug 2026 06:41:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wqmMn-004RHW-0G for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Aug 2026 06:41:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wqmMm-004RHN-21 for pgsql-hackers@lists.postgresql.org; Mon, 03 Aug 2026 06:41:40 +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 1wqmMj-00000001evh-2TjA for pgsql-hackers@postgresql.org; Mon, 03 Aug 2026 06:41:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1785739293; bh=wzCx4omEpnB5DUyD7/dyBGmdzoZhSBmGpHe1RsLLZDo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID:From; b=zwc8GzydaIigE4nJ8vEYozGmhiZm2VHM7n8f4RTQe07PU7I+oKt6Ser9n9Ro+6yvW fu4EOQ/V2BBM3jrZ8dqmQKiQE31n4iTjeCrHJQKqGSfKXQFylYVdS2u8MV5dO8oTEc 2S7BQ84geiSc4cNRmg/nhBOeI7CXKi432+G688/gHOYod4/MSijiFZ5u5tto3sAlz/ ZPRT3wm0FQeqzvaDcdWOXrJL8lnrfjDn7xQcBgL4jORJPls6xlRYf81fH6swIqjaS2 1pn8eCKI49XTyoRp5Q/JWRUPgd/HVCIOxSITTuWJpGki2ooVKZn8bg9G70qi+ZKGrW lSI06aYgDDZdA== 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 BA83160CB3; Mon, 03 Aug 2026 09:41:33 +0300 (MSK) MIME-Version: 1.0 Date: Mon, 03 Aug 2026 09:41:33 +0300 From: Alexander Pyhalov To: Alexander Korotkov Cc: 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/08/03 06:26:00 #28628949 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 Alexander Korotkov писал(а) 2026-08-01 00:03: > Hi! > > On Mon, Jul 6, 2026 at 4:42 PM Alexander Pyhalov > wrote: >> Alexander Korotkov писал(а) 2026-07-04 02:05: >> >> > While discovering a correctness of callback_pending flag reset in >> > async MergeAppend, I found bug in async plain Append [1]. I've >> > included the fix as 0001 in the current patchset. Other changes to >> > patchset includes. >> > >> >> I expect that this issue can affect both MergeAppend and Append, but >> current test cases don't confirm this. >> If we revert to the old behavior (setting areq->callback_pending to >> false), the tests results of Merge Append tests >> are not changed. > > Did you try the test case showed by Gleb [1]. Yet I think it's safe > to follow the fix by Etsuro. In the revised patchset I put this into > ExecAppendBaseAsyncProcessPending() and use for both async append and > async merge append. Yes, he found this case when we tested your original fix for ExecReScanAppend() behavior. I'm fine with following Etsuro's fix. > >> > 0003 contains some cleanups >> > * Unify set_append_references and set_mergeappend_references >> > (setrefs.c) >> > * Merge duplicate Append/MergeAppend cases in explain.c >> > * Merge duplicate Append/MergeAppend cases in >> > planstate_tree_walker_impl (nodeFuncs.c) >> >> This looks good. >> >> > 0006 includes following optimizations and fixes >> > * Fix assertion failure on MergeAppend rescan with an in-flight async >> > request (same as 0001 but for MergeAppend) >> >> >> > * Don't use ExecProcNode() for async subplans. Despite its >> > effectiveness, it doesn't works correctly. When postgres_fdw subplan >> > is executed by ExecProcNode() it interprets the end of async batch as >> > end of the whole data. That effectively leads to skipping the >> > remaining dataset after first batch (100 rows). The test is added. >> >> Ouch. Luckily we've catched this. postgresIterateForeignScan() doesn't >> fetch tuples for async scan states... >> >> > * Make ExecReScanMergeAppend() clear ms_slots. Otherwise subsequent >> > scans can use leftover tuples. The test is also added. >> >> This seems to happen only in updated version of the patch, where >> ExecMergeAppendAsyncGetNext() relies on the fact that >> async requests have been already sent (previously this function >> firstly >> set slot to NULL prior to sending requests and processing them). > > Yes, thank you for clarification. Are you good with this approach? Yes, I'm fine with this. > >> > * Document that the needrequest fast-skip is a no-op for MergeAppend >> > (postgres_fdw.c) >> > * Document why create_merge_append_plan discards >> > mark_async_capable_plan's result (createplan.c) >> > >> Looks good. >> >> ExecMergeAppendGetNextSlot() - I'd sligtly prefer to check if mplan is >> member of as_asyncplans and assert that it's a member of >> node->as.valid_asyncplans >> in this case, but I think it doesn't matter much. > > OK, I changed to this way. It seems you've missed the attachment. -- Best regards, Alexander Pyhalov, Postgres Professional