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 1m6oPu-0006gB-Jd for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Jul 2021 06:12:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m6oPt-00033d-L7 for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Jul 2021 06:12:13 +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 1m6oNQ-0007Rb-Md for pgsql-bugs@lists.postgresql.org; Fri, 23 Jul 2021 06:09:40 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m6oNO-0007ZO-1y for pgsql-bugs@lists.postgresql.org; Fri, 23 Jul 2021 06:09:40 +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 ABB8321CCE40; Fri, 23 Jul 2021 09:09:36 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1627020576; bh=02tIgqpUzGaNpObGsiDz2vLyOkZNyCEG6nEsVCeD9TA=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=p0CBelxw8ocrBQhFIk9/NDzi/I7nAtLd6GH/Op2dds8XC2b5cxD2i6wOQ2LFC46cx m05LOHQ9DvqZ+ABhyHWuQFl+GLe/AZ+GnOX0M/RZYD0F/W2h6hikdHP5Qu/duwEOV0 Ku1IXSWJZYRmsFtvV2HTMAonvOsfZaMU7f0PHzCU= 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 11:09:35 +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 agree. > 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. I think it can be done, but only as a temporary solution. InitPlan is a common planning utility. Maybe we can split async logic into: - receiving stage, when we only fetch and store tuples, - evaluating stage, when we form resulting tuple and return by a scan node. I will think about such solution more. Also, may be you tell your opinion about an additional optimization of Async Append [1]? [1] https://www.postgresql.org/message-id/edb1331c-e861-0c53-9fdb-f7ca7dfd884d%40postgrespro.ru -- regards, Andrey Lepikhov Postgres Professional