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 1w9tfz-001rv8-28 for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 23:48:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9tfx-00CnTw-0I for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 23:48:13 +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 1w9tfw-00CnTn-2B for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2026 23:48:13 +0000 Received: from mail-dy1-x1336.google.com ([2607:f8b0:4864:20::1336]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w9tfu-00000000w7p-2iPn for pgsql-hackers@postgresql.org; Mon, 06 Apr 2026 23:48:11 +0000 Received: by mail-dy1-x1336.google.com with SMTP id 5a478bee46e88-2c56aa62931so9479777eec.0 for ; Mon, 06 Apr 2026 16:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775519290; x=1776124090; darn=postgresql.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/cWCX7FWLIqzpoxUsSStmh3nEouHnJbNTPY7SWZ96Qg=; b=oM1lKELkbsfbIHda2707IzMOI+8UocCyYTicNaBGuNopBXeU4q/VdBctqzRYnsYIdN m0m2sllrDEyMLofSr6dhJCNBtbxgg83O3GQkaMRMh5SXNq5lhO6O5aPd2xprl7Xva109 Aim7l1HTT9NmOqdguc7UKxSOhg8H6I/gQDR1S9FWYy4fzPUX0+w4tgJlWWrhaXUaWptt u04Lzc48IqNN97ZvrjHfxNi6LGpjJ7/8X8L9arn6nbKp0p9/WFsuKtQSgtllGhw3ehck Rnf3BSkfdPAIpS5+uPXccn8o4gp32TkEzSPpD8w07DeRYPS4NFUmeoZvziNviGB9zsn9 Jvag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775519290; x=1776124090; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/cWCX7FWLIqzpoxUsSStmh3nEouHnJbNTPY7SWZ96Qg=; b=YRPmOn+8GKEOzltRUfybPUEeQlqMhNGhqXgiol847+DkIo87o1isJGPF+bYSaLCo59 XptkoOCJYrzRtIAfuzotVuQbVsCkEfhtBu+DaoJAF8eeWy73dNnOIkAPhCOKjYEZLwwU exTVeglpzONW7iL+X0OFuGXrWhpX46fZb+sG4382QnrBCt/j0lh4eGDaABX3DrheOd0R MzqqJKSWD/lp8btAFdexd40+5Rji4zLtOwfAnDuIHr9S7r8dLkPJw3nb0grb78VVQ8ha mpDLMyaVKT/HQlZlM8ZnlOWfUD9wIhdbJzLq9A3oXE40Ia8SGPCuAKSyonF9io5BXwvJ BN4Q== X-Forwarded-Encrypted: i=1; AJvYcCXtbLCpx9IXOhCMXfngvEjUJYBh55AssAJ1doGVgHxT1xsjdA6RLVo/UjPG5eD1F0YXHc3uiAdVQ51rUi6a@postgresql.org X-Gm-Message-State: AOJu0YzM3Lryy3S6RejFXIY/not8ln3mNLjSxjp6f1gg/UY2Vqd9QMjq vmeXZuTHQ09IxHAxPb4PTNdL6kIH7RKWX5POrvyBvsJ0LmnmMCy+MZ6H X-Gm-Gg: AeBDieu6tDpfCWBzusHrbQ7N+eUnLVf85Efes7wYGlmnHPqANnbtsBbBk3NnfGnRCOo Gfjt69c28JmnFZ+vx6XHxIPUJb3OF9El6945ibjedrqitjoaA9ajt47clPxOKuDyBwrOwPuhlHR V+mbtz0XBv3wMiKBGOs8LBBZBif7SucvhoQbqLHh39N2IeNfjeClGBmdcIsilZ1iwBagmctCect UTcCl1ogy2j+DM/9YvxQ8M8YBuNz+hw86UR+2oBwAI73ROuFEifziRjO3FEYQXFMabcGKonFK7u HbhoxzcwRtneVFaMsSAxsSrU6G0Pu5M0KlfEhkPOn5RK3zuWj9Koe7KbePisbxZnrxxGhWXUs6D WFuRxZRQVwt+Ezx2K40gbPCvOY5NjWfgZXav73XYcgnnf9vccqRL42y8Q3RgjKp3tPTtjhQ8eMj tZAmC+lBsem48dWW5mxN+AcIQk301lPbl32aBAWhYmr3tKjQ== X-Received: by 2002:a05:7300:3242:b0:2c1:27c:75bd with SMTP id 5a478bee46e88-2cbf6a8d94dmr7229315eec.0.1775519289719; Mon, 06 Apr 2026 16:48:09 -0700 (PDT) Received: from localhost ([2804:14d:328a:a59c:2593:23d3:4374:36cc]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca7c3010e9sm18730293eec.14.2026.04.06.16.48.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Apr 2026 16:48:09 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 06 Apr 2026 20:48:05 -0300 Message-Id: Cc: "Alexander Pyhalov" , "Pgsql Hackers" Subject: Re: Asynchronous MergeAppend From: "Matheus Alcantara" To: "Alexander Korotkov" X-Mailer: aerc 0.21.0 References: <59be194c5a409fb9fc9f2031581b8a44@postgrespro.ru> <2fb1d9923b6995492e7b163e6cb95402@postgrespro.ru> <782a968c8e01ec6db3b2da2120adf73b@postgrespro.ru> <554a73f7ffea8b22b3f81a4804b5fc34@postgrespro.ru> <42a9a941-e768-4fd8-8067-12958c5a1d70@gmail.com> In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat Apr 4, 2026 at 11:24 PM -03, Alexander Korotkov wrote: > I made more work on the patchset. > > Patch #1 now considers IncrementalSort as exclusion alongside with > Sort. Exclusion check is now on the top of the switch(). > Patch #2 is split into 3 patches: common structures, common sync > append logic, and common async append logic. > New structs are now named AppendBase/AppendBaseState, corresponding > fields are "ab" and "as". > > Most importantly I noted that this patchset actually only makes > initial heap filling asynchronous. The steady work after that is > still syncnronous. Even that it used async infrastructure, it fetched > tuples from children subplans one-by-one: effectively synchronous but > paying for asynchronous infrastructure. I think even with this > limitation, this patchset is valuable: the startup cost for children > foreignscans can be high. But this understanding allowed me to > significantly simplify the main patch including: > 1) After initial heap filling, use ExecProcNode() to fetch from children = plans. > 2) Remove ms_has_asyncresults entirely. Async responses store directly > into ms_slots[] (the existing heap slot array), which serves as both > the merge state and the "result arrived" indicator via TupIsNull(). > 3) Removed needrequest usage from MergeAppend. Since MergeAppend only > fires initial requests (via ExecAppendBaseAsyncBegin()) and never > sends follow-up requests, needrequest tracking is unnecessary. > ExecMergeAppendAsyncRequest() was eliminated entirely. > 4) ExecMergeAppendAsyncGetNext() reduced to a simple wait loop: > 5) asyncresults allocation reduced back to nasyncplans. MergeAppend > doesn't use it (stores in ms_slots), and Append only needs nasyncplans > entries for its stack. > > Additionally, I made the following changes. > 1) WAIT_EVENT_MERGE_APPEND_READY wait event instead of extending > WAIT_EVENT_APPEND_READY. That should be less confusing for monitoring > purposes. > 2) More tests: error handling with broken partition, plan-time > partition pruning, and run-time partition pruning tests for async > MergeAppend. > Thanks for v17, the split of 0002 into multiple patches seems much better. Overall I agree with the changes on v17 compared with v16, the removal of ms_has_asyncresults makes the code better to read and follow. The separate WAIT_EVENT_MERGE_APPEND_READY for better monitoring is also good, I've tested some long running queries and I've find the event on pg_stat_activity. The steady work changes also looks good. One minor issue on 0002: + bool valid_subplans_identified; /* is valid_asyncplans valid? */ + Bitmapset *valid_subplans; + Bitmapset *valid_asyncplans; /* valid asynchronous plans indexes */ Should be /* is valid_subplans valid? */ ----- Minor comment on 0005: +static void +ExecMergeAppendAsyncGetNext(MergeAppendState *node, int mplan) +{ + /* + * All initial async requests were fired by ExecAppendBaseAsyncBegin. Wondering if we should reference ExecMergeAppendAsyncBegin() instead of ExecAppendBaseAsyncBegin() since this is on nodeMergeAppend, what do you think? -- Matheus Alcantara EDB: https://www.enterprisedb.com