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 1wgkX5-006NAS-1l for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 14:42:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wgkX3-001CqQ-0Z for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 14:42:49 +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 1wgkX2-001CqI-2R for pgsql-hackers@lists.postgresql.org; Mon, 06 Jul 2026 14:42: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 1wgkX0-00000001rRI-1By1 for pgsql-hackers@postgresql.org; Mon, 06 Jul 2026 14:42:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1783348962; bh=oL4UFoDBkUdw9BWFe1WkFm6WEGUAMXTy7XjZofCNI/8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID:From; b=fzTGKLX9aWJjffGkOB1gF9ZdGtAJKNHNuEiF1IPV183d8/VTyFMNczxZCQkT3gsHA 64kVz6sddAgrXF3FF7lqHVmEhkCVtWoMN4Gm9C0FbKcDtGpKrMjRuXgWSAdDVn6Qww iQg+qVHmXS56eG2Aausacp8Rv6OP6PaaZTS4hfYFSh7PPfUKLd1A13n+ndB/innAoD UCUPAU7xIl+TsWsYmjltjXIpwjjUURj0nougPYKhhrvkl16JejHkTNSFPMQ1ARjkH0 w0cXhsysKOTnN4BC9kmr9KHVon82enRGn1K27ddytfAHkJl/YLN/ka+EnNWGCndhSn 8ZzK79Ls/gwvQ== 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 360BB5FE21; Mon, 6 Jul 2026 17:42:42 +0300 (MSK) MIME-Version: 1.0 Date: Mon, 06 Jul 2026 17:42:42 +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/07/06 13:00:00 #28400771 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 Hi. 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. > 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). > * 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. -- Best regards, Alexander Pyhalov, Postgres Professional