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 1vIvUC-0034Vd-2x for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Nov 2025 21:01:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vIvUA-007ruA-1j for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Nov 2025 21:01:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vIvUA-007ru1-0n for pgsql-hackers@lists.postgresql.org; Tue, 11 Nov 2025 21:01:06 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vIvU5-007Dc3-2o for pgsql-hackers@postgresql.org; Tue, 11 Nov 2025 21:01:05 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-7b6dd81e2d4so139123b3a.0 for ; Tue, 11 Nov 2025 13:01:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762894859; x=1763499659; 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=4zhbCF6fZXXXdBReJl6z/HyC8zEbq93pUhe/eeNJSHo=; b=PEdfCNkB0la739rZEilQoUtg9rtKqXqvSMDHc7Xjr82UIuEmbc9nUdXhWUDNk7kkQQ 0S1y3A7Xo+PtuGw9O1FUcFPNJYfeHm4mzN9/2y/loGKGZOv20tkvEyuoOR229fCf9rVG kHimL6WvBT+O4XdZaSkY8j5WqORqHlcVSgNVfTbRxdHHeXPbycqGVSW7+KiI2jJSELBl lnLX2SkwNZ1uDNAid8SO06oOGlw79PGau06nYF0Wm6b/ftLydPODkBHRaGmh/snolhPp MVxwEnzhtLfiWOs4TVS1AzAarcCs8gkJgOxjDTkCycHiUWTQ2lp+bs5jB+tvP+tzzbFC c1jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762894859; x=1763499659; 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=4zhbCF6fZXXXdBReJl6z/HyC8zEbq93pUhe/eeNJSHo=; b=Sj3XjRap0ZjdmxbXlIzRKx2rVIeJeh+PWDNCy+wBJvKlfbnZRWhmgwvgGIweHvT0Uj EJxAkG5YmuKXXdKY5DvM09jAwr2iZ6QafDy6sW+l0NljMdhJAkpZ00zlsKu74v81fhSS ISH71xsg3FqsBmhqM11TbH41CISPHNTOcG4gccQeiPATIDUTat0FjrRPygJguLHviC7s qsZXJ7FjxahZWuXKvVGgEfpq2+VQYvMUH7ocJn/Vyxl7ZLzCSq/fajLLrxIguNdJI+UN mF4IofCJpDuX9RCXK+tJrSItWPbSo6uYCdIr1Npxf9STA6sMYY2bUBTxVpNDNRvFKgr6 RZaw== X-Forwarded-Encrypted: i=1; AJvYcCXz7ksBfcOqVJx7cFejYPp7P24iePJG+3QYunmeArYcxxfDYS9CiGZNfhTQtJ3A3BhjoZvFcXs5QbrivKNe@postgresql.org X-Gm-Message-State: AOJu0Yyl2f15CAb4J1ucRy41iuJ22zN1QBJhlkRNzagMMwLL+v/OVvxQ 9Yet6ji529DaToz+vv7kDBK+VYVvm87ojVwI0tlMZOXcxI+8lez/tPpc X-Gm-Gg: ASbGncvyvN+oaR1asxhJYaAUTRzzCPUrynLMmdc4vQ2EjhByrmBZ/kzSxQoZYpRQGrJ bVXFxo5LLtZHfLpv5TSRjtZf8fI96Ae2h0xMWJS2BVvvYJ71cuzQxTimkeAG9qKHK/ko86F56xu dKOhCdWKmFCtqV+u2KhkLRI6QwhFY0nrpH3zLzfjYu/c1ebDPNm21FKwW41hjW78pGGfHHBfwG0 8Wrp9Qu+4kyX60FxPwNrZ9+bcgD71ouG8j09QUJ8F9Kg3VU3Me8FqTVGnFHILJ0IgpcDZLzyMim au6M9NwXHdRcWOgEJxOwKi4A0RaF8KHyQ3R0Q3wCM1twRR804E2QY9SuCkn4LRhsjLo1BQQAr2E 6e3lBcyr6wLBAQCRRbfk//fyT7S1vnj2uvnPe7lDRvsS18AWHQ926ps/vK7lYuk+MZAACw2po3g pv9O1OA88f4E/R3kxTojhTcJ9aNy3O5E2wrg== X-Google-Smtp-Source: AGHT+IG46C8t6Du6ujv/uJOjG3HFPccSe1Kw2A5njyVKJOqyOppw0l5WEdkuU/T15662IoT35APdXA== X-Received: by 2002:a05:6a20:4305:b0:341:1dc6:aea with SMTP id adf61e73a8af0-3590619f39emr677388637.0.1762894858647; Tue, 11 Nov 2025 13:00:58 -0800 (PST) Received: from localhost ([2804:14d:328a:a59c:959a:5672:ad37:7990]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b0c9cff5f6sm16163475b3a.24.2025.11.11.13.00.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Nov 2025 13:00:58 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 11 Nov 2025 18:00:53 -0300 Message-Id: Cc: "Alena Rybakina" , "Pgsql Hackers" Subject: Re: Asynchronous MergeAppend From: "Matheus Alcantara" To: "Alexander Pyhalov" , "Matheus Alcantara" X-Mailer: aerc 0.21.0 References: <59be194c5a409fb9fc9f2031581b8a44@postgrespro.ru> <764dd8b8-6374-4f5a-aac7-d8e3f6ebe5fd@postgrespro.ru> <159b591411bb2c81332018927acbd509@postgrespro.ru> <2fb1d9923b6995492e7b163e6cb95402@postgrespro.ru> In-Reply-To: <2fb1d9923b6995492e7b163e6cb95402@postgrespro.ru> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed Nov 5, 2025 at 3:30 AM -03, Alexander Pyhalov wrote: >> So I'm +1 for the idea. I know it's been while since the last patch, >> and unfortunully it hasn't received reviews since then. Do you still >> plan to work on it? I still need to take a look on the code to see if >> I can help with some comments. > > I'm still interested in working on this patch, but it didn't get any=20 > review (besides internal one). I suppose, Append and MergeAppend nodes=20 > need some unification, for example, ExecAppendAsyncEventWait and=20 > ExecMergeAppendAsyncEventWait looks the same, both=20 > classify_matching_subplans() versions are suspiciously similar. But=20 > honestly, patch needs thorough review. > Here are some comments on my first look at the patches. I still don't have too much experience with the executor code but I hope that I can help with something. v5-0001-mark_async_capable-subpath-should-match-subplan.patch I don't have to much comments on this, perhaps we could have a commit message explaining the reason behind the change.=20 ---- v5-0002-MergeAppend-should-support-Async-Foreign-Scan-sub.patch The AppendState struct has the "as_syncdone", this field is not needed on MergeAppendState? ---- Regarding the duplicated code on classify_matching_subplans I think that we can have a more generic function that operates over function parameters, something like this: /* * Classify valid subplans into sync and async groups. * * It calculates the intersection of *valid_subplans and *asyncplans, * stores the result in *valid_asyncplans, and removes those members * from *valid_subplans (leaving only sync plans). * * Returns true if valid async plans were found, false otherwise. */ static bool classify_subplans_internal(Bitmapset **valid_subplans, Bitmapset *asyncplans, Bitmapset **valid_asyncplans); ---- The GetValidAsyncplans() is not being used ---- We have some reduction of code coverage on nodeMergeAppend.c. The significant blocks are on ExecMergeAppendAsyncBegin(): + /* If we've yet to determine the valid subplans then do so now. */ + if (!node->ms_valid_subplans_identified) + { + node->ms_valid_subplans =3D + ExecFindMatchingSubPlans(node->ms_prune_state, false, NULL); + node->ms_valid_subplans_identified =3D true; + + classify_matching_subplans(node); + } And there are some blocks on ExecReScanMergeAppend(). It's worth adding a test case for then? I'm not sure how hard would be to write a regression test that cover these blocks. ---- I agree that duplicated code is not good but it seems to me that we already have some code on nodeMergeAppend.c borrowed from nodeAppend.c even without you patch, for example the ExecInitMergeAppend(), ExecReScanMergeAppend() and partially ExecMergeAppend(). Although nodeMergeAppend.c and nodeAppend.c have similar functions , some difference exists and I'm wondering if we should wait for the rule of three [1] to refactor these duplicated code? [1] https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming) -- Matheus Alcantara EDB: http://www.enterprisedb.com