Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1layau-0006A3-Iv for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Apr 2021 10:36:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1layas-0008Da-WA for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Apr 2021 10:35:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1layas-0008DT-Mq for pgsql-hackers@lists.postgresql.org; Mon, 26 Apr 2021 10:35:58 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1layaq-0004rj-8b for pgsql-hackers@lists.postgresql.org; Mon, 26 Apr 2021 10:35:58 +0000 Received: from [192.168.129.197] (unknown [94.25.177.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 5B05121C60E4; Mon, 26 Apr 2021 13:35:54 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1619433354; bh=3IeG4aZg2KMCoBKR5iM2GU2aKpolZMrovjn2dv8PEVo=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=LTE2qqD3Ft7PFhTOinSIMwQ5WVXRGAz+b08beTnEOkbPf5jFt/d6SbWAcrY/BF9C4 nnq6rS1lEYgeu9/9IBIcIt8DUkEbN3MWoKQor5P0ra9xXv3/WBTVR8Hd3wWFZsCMEl 26lJzGgQR9/lMaoY7FBZrlsxOmExRb0fYqka5WhI= Subject: Re: Asynchronous Append on postgres_fdw nodes. To: Etsuro Fujita , Kyotaro Horiguchi Cc: Justin Pryzby , PostgreSQL Hackers References: <20210331.101137.148208859959175708.horikyota.ntt@gmail.com> From: "Andrey V. Lepikhov" Organization: Postgres Professional Message-ID: <2eb662bb-105d-fc20-7412-2f027cc3ca72@postgrespro.ru> Date: Mon, 26 Apr 2021 15:35:53 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------D2469C3CB6912FB21B6CFB8A" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------D2469C3CB6912FB21B6CFB8A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 4/23/21 8:12 AM, Etsuro Fujita wrote: > I have committed the patch. Small mistake i found. If no tuple was received from a foreign partition, explain shows that we never executed node. For example, if we have 0 tuples in f1 and 100 tuples in f2: Query: EXPLAIN (ANALYZE, VERBOSE, TIMING OFF, COSTS OFF) SELECT * FROM (SELECT * FROM f1 UNION ALL SELECT * FROM f2) AS q1 LIMIT 101; Explain: Limit (actual rows=100 loops=1) Output: f1.a -> Append (actual rows=100 loops=1) -> Async Foreign Scan on public.f1 (never executed) Output: f1.a Remote SQL: SELECT a FROM public.l1 -> Async Foreign Scan on public.f2 (actual rows=100 loops=1) Output: f2.a Remote SQL: SELECT a FROM public.l2 The patch in the attachment fixes this. -- regards, Andrey Lepikhov Postgres Professional --------------D2469C3CB6912FB21B6CFB8A Content-Type: text/x-patch; charset=UTF-8; name="never_executed_fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="never_executed_fix.patch" diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index e201b5404e..a960ada441 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -6857,8 +6857,13 @@ produce_tuple_asynchronously(AsyncRequest *areq, bool fetch) } else { - /* There's nothing more to do; just return a NULL pointer */ - result = NULL; + /* + * There's nothing more to do; just check it and get an empty slot + * from the child node. + */ + result = ExecProcNode((PlanState *) node); + Assert(TupIsNull(result)); + /* Mark the request as complete */ ExecAsyncRequestDone(areq, result); } --------------D2469C3CB6912FB21B6CFB8A--