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 1m6tK8-0007QK-1r for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Jul 2021 11:26:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m6tK6-0003wb-U9 for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Jul 2021 11:26:34 +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 1m6tK6-0003wT-Ku for pgsql-bugs@lists.postgresql.org; Fri, 23 Jul 2021 11:26:34 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m6tK4-0001dy-KI for pgsql-bugs@lists.postgresql.org; Fri, 23 Jul 2021 11:26:34 +0000 Received: from [192.168.129.197] (unknown [94.25.177.92]) (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 BA72A21CD084; Fri, 23 Jul 2021 14:26:30 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1627039590; bh=+K/AjqsiGwvIKjJYXDLfLetdaojiOnchOZ6PvX59odc=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=MJd3uPVnXxEeFQOW0lBy9gZeV5EQ64cfT5mOZ6zoSTLbgTkFutoyrhPUcnSfU53JW DftJDLh77IwkTPntoJCwAWFM+G2ebpM5uVwUOKOKff4nmD5QNuntnLtsfiGMRF8pnD n/Os1iWk9xtzKGHKfqyvdwL/WXEQ/eDauFxVrEHQ= Subject: Re: The case when AsyncAppend exists also in the qual of Async ForeignScan To: Etsuro Fujita Cc: pgsql-bugs@lists.postgresql.org References: From: "Andrey V. Lepikhov" Organization: Postgres Professional Message-ID: Date: Fri, 23 Jul 2021 16:26:29 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/22/21 4:14 PM, Etsuro Fujita wrote: > On Fri, Jul 2, 2021 at 10:24 PM Andrey Lepikhov > @@ -7015,6 +7015,21 @@ process_pending_request(AsyncRequest *areq) > > fetch_more_data(node); > > + /* > + * If the request are made by another append we will only prepare connection > + * for the next query and don't take a tuple immediately. It is needed to > + * prevent possible recursion into a qual subplan. > + */ > + if (!fetch) > + { > + AppendState *node = (AppendState *) areq->requestor; > + > + ExecAsyncRequestDone(areq, NULL); > + node->as_needrequest = bms_add_member(node->as_needrequest, > + areq->request_index); > + return; > + } > > I don’t think this is a good idea, because it is pretty inconsistent, > as doing ExecAsyncRequestDone(areq, NULL) means that there are no more > tuples while changing as_needrequest like that means that there is at > least one tuple to return. This would happen to work, but for > example, if we add to the core more sanity checks on AsyncRequests, > this would not work well anymore. I tried to devise a consistent > solution for this issue, but I couldn’t. So I feel inclined to > disable async execution in cases where async-capable nodes access to > subplans (or initplans), for now. That do you think, if (in addition to the patch) we will give ExecAsyncAppendResponse a chance to fill the result slot? Code: --- a/src/backend/executor/nodeAppend.c +++ b/src/backend/executor/nodeAppend.c @@ -1108,6 +1108,9 @@ ExecAsyncAppendResponse(AsyncRequest *areq) return; } + if (areq->result == NULL) + areq->result = areq->requestee->ExecProcNodeReal(areq->requestee); + /* If the result is NULL or an empty slot, there's nothing more to do. */ if (TupIsNull(slot)) { -- regards, Andrey Lepikhov Postgres Professional