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 1lgIbF-0003NE-K7 for pgsql-hackers@arkaria.postgresql.org; Tue, 11 May 2021 02:58:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lgIbD-0007vA-9L for pgsql-hackers@arkaria.postgresql.org; Tue, 11 May 2021 02:58:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lgIbC-0007v1-Vd for pgsql-hackers@lists.postgresql.org; Tue, 11 May 2021 02:58:19 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lgIb8-0005gO-A1 for pgsql-hackers@lists.postgresql.org; Tue, 11 May 2021 02:58:17 +0000 Received: from ip-192-168-0-192.is74.loc (pool-77-222-105-30.is74.ru [77.222.105.30]) (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 6598F21C7E6A; Tue, 11 May 2021 05:58:11 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1620701891; bh=vJcAFNjBeS6VvkOoeHFlkqNTIFy7P6GAYWySkYHldMI=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=aZD55Jxd7iI8xi1Ico1ijZ5jIuNf9jW1RaAHfEPWXV0wK1WG5ncHa8rFL3TlJsa0x ijYiPFC/YmWMx4IZ6mXCWQO8KPHLbsf2jk7hCKrptAT9vvkLEaQYD5rDjJg+sjgNZw r3s/zMttI3hn4rCYaFpmjgawe9Bbxye8xs7IkDb8= Subject: Re: Asynchronous Append on postgres_fdw nodes. To: Etsuro Fujita Cc: Kyotaro Horiguchi , Justin Pryzby , PostgreSQL Hackers References: <20210331.101137.148208859959175708.horikyota.ntt@gmail.com> <2eb662bb-105d-fc20-7412-2f027cc3ca72@postgrespro.ru> From: Andrey Lepikhov Organization: Postgres Professional Message-ID: <2080193d-da8d-4132-f48c-8e29be8fcffc@postgrespro.ru> Date: Tue, 11 May 2021 07:58:10 +0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/5/21 08:03, Etsuro Fujita wrote: > On Fri, May 7, 2021 at 7:32 PM Andrey Lepikhov > I think a simple fix for this would be just remove the check whether > the instr->running flag is set or not in InstrUpdateTupleCount(). > Attached is an updated patch, in which I also updated a comment in > execnodes.h and docs in fdwhandler.sgml to match the code in > nodeAppend.c, and fixed typos in comments in nodeAppend.c. Your patch fixes the problem. But I found two more problems: EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT * FROM ( (SELECT * FROM f1) UNION ALL (SELECT * FROM f2) UNION ALL (SELECT * FROM l3) ) q1 LIMIT 6709; QUERY PLAN -------------------------------------------------------------- Limit (actual rows=6709 loops=1) -> Append (actual rows=6709 loops=1) -> Async Foreign Scan on f1 (actual rows=1 loops=1) -> Async Foreign Scan on f2 (actual rows=1 loops=1) -> Seq Scan on l3 (actual rows=6708 loops=1) Here we scan 6710 tuples at low level but appended only 6709. Where did we lose one tuple? 2. SELECT * FROM ( (SELECT * FROM f1) UNION ALL (SELECT * FROM f2) UNION ALL (SELECT * FROM f3 WHERE a > 0) ) q1 LIMIT 3000; QUERY PLAN -------------------------------------------------------------- Limit (actual rows=3000 loops=1) -> Append (actual rows=3000 loops=1) -> Async Foreign Scan on f1 (actual rows=0 loops=1) -> Async Foreign Scan on f2 (actual rows=0 loops=1) -> Foreign Scan on f3 (actual rows=3000 loops=1) Here we give preference to the synchronous scan. Why? -- regards, Andrey Lepikhov Postgres Professional