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 1kKiWo-000227-J2 for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Sep 2020 13:40:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kKiWm-0007HL-Q8 for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Sep 2020 13:40:16 +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 1kKiWm-0007HE-IA for pgsql-hackers@lists.postgresql.org; Tue, 22 Sep 2020 13:40:16 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kKiWj-0001nl-El for pgsql-hackers@lists.postgresql.org; Tue, 22 Sep 2020 13:40:16 +0000 Received: from [192.168.27.200] (unknown [93.174.131.141]) (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 D5D6A21C1CEB; Tue, 22 Sep 2020 16:40:11 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1600782011; bh=XPxVenzfSqw5mFHiUW6n4iYzglhpyIWHtV8KvYHCuZ4=; h=Subject:From:To:Cc:References:Date:In-Reply-To; b=XmdVNTPbE0cKcdmxRkBUQchNPPR+bHEsbHIxKRbtRnO7w8pJqqfxa9AJy3Z7jXFH2 NOB97c+6zF5S3Nba+W7V0X3SFS/2jcT6HmPuUS/7ZKYMscaQ7mdHMyaqQU4Sl9fpVy kSvZJDlOtaXLlW+91aDZh8iiNHJCEuN229UXAFGQ= Subject: Re: Asynchronous Append on postgres_fdw nodes. From: Konstantin Knizhnik To: Kyotaro Horiguchi , pryzby@telsasoft.com Cc: a.lepikhov@postgrespro.ru, etsuro.fujita@gmail.com, movead.li@highgo.ca, pgsql-hackers@lists.postgresql.org References: <20200610.120510.2075667454883130505.horikyota.ntt@gmail.com> <20200702.111448.2019475770338322857.horikyota.ntt@gmail.com> <20200820042536.GB2886@telsasoft.com> <20200820.163608.1893015081639298019.horikyota.ntt@gmail.com> <84ea4412-5c0e-9a9c-df04-79033fc066da@postgrespro.ru> Message-ID: Date: Tue, 22 Sep 2020 16:40:11 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <84ea4412-5c0e-9a9c-df04-79033fc066da@postgrespro.ru> Content-Type: multipart/mixed; boundary="------------26304BCBEC93A687CA7F435B" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------26304BCBEC93A687CA7F435B Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit On 22.09.2020 15:52, Konstantin Knizhnik wrote: > > > On 20.08.2020 10:36, Kyotaro Horiguchi wrote: >> At Wed, 19 Aug 2020 23:25:36 -0500, Justin Pryzby >> wrote in >>> On Thu, Jul 02, 2020 at 11:14:48AM +0900, Kyotaro Horiguchi wrote: >>>> As the result of a discussion with Fujita-san off-list, I'm going to >>>> hold off development until he decides whether mine or Thomas' is >>>> better. >>> The latest patch doesn't apply so I set as WoA. >>> https://commitfest.postgresql.org/29/2491/ >> Thanks. This is rebased version. >> >> At Fri, 14 Aug 2020 13:29:16 +1200, Thomas Munro >> wrote in >>> Either way, we definitely need patch 0001.  One comment: >>> >>> -CreateWaitEventSet(MemoryContext context, int nevents) >>> +CreateWaitEventSet(MemoryContext context, ResourceOwner res, int >>> nevents) >>> >>> I wonder if it's better to have it receive ResourceOwner like that, or >>> to have it capture CurrentResourceOwner.  I think the latter is more >>> common in existing code. >> There's no existing WaitEventSets belonging to a resowner. So >> unconditionally capturing CurrentResourceOwner doesn't work well. I >> could pass a bool instead but that make things more complex. >> >> Come to think of "complex", ExecAsync stuff in this patch might be >> too-much for a short-term solution until executor overhaul, if it >> comes shortly. (the patch of mine here as a whole is like that, >> though..). The queueing stuff in postgres_fdw is, too. >> >> regards. >> > > > Hi, > Looks like current implementation of asynchronous append incorrectly > handle LIMIT clause: > > psql:append.sql:10: ERROR:  another command is already in progress > CONTEXT:  remote SQL command: CLOSE c1 > > > Just FYI: the following patch fixes the problem: --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -1667,6 +1667,11 @@ remove_async_node(ForeignScanState *node)          if (cur == node)          { +            PGconn *conn = curstate->s.conn; + +            while(PQisBusy(conn)) +                PQclear(PQgetResult(conn)); +              prev_state->waiter = curstate->waiter;              /* relink to the previous node if the last node was removed */ -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company --------------26304BCBEC93A687CA7F435B Content-Type: text/x-patch; name="async_append_limit.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="async_append_limit.patch" diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index 1482436..9fe16cf 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -1667,6 +1667,11 @@ remove_async_node(ForeignScanState *node) if (cur == node) { + PGconn *conn = curstate->s.conn; + + while(PQisBusy(conn)) + PQclear(PQgetResult(conn)); + prev_state->waiter = curstate->waiter; /* relink to the previous node if the last node was removed */ --------------26304BCBEC93A687CA7F435B--