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 1jiaR7-00068e-RJ for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jun 2020 09:20:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jiaR5-0006eL-U9 for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jun 2020 09:20:47 +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 1jiaR5-0006eE-H6 for pgsql-hackers@lists.postgresql.org; Tue, 09 Jun 2020 09:20:47 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jiaR2-0001IU-LM for pgsql-hackers@lists.postgresql.org; Tue, 09 Jun 2020 09:20:47 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 899D821C6CD5; Tue, 9 Jun 2020 12:20:43 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.129.197] (unknown [94.25.177.230]) (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 0C9D721C6AB3; Tue, 9 Jun 2020 12:20:42 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1591694443; bh=oKse5MCV2DxhrpRPU01ZekbXvqRV5ZBl5Q9rX/rrIVQ=; h=From:Subject:To:Cc:References:Date:In-Reply-To; b=Tk2stvM/LSvuHI2pV8kdWbTNBb1Ar6iKcs+gdPqr/HhtAKemv9WQsFs0yL1mQXLkC 3Zra+XSCqi1JPKvpF3/khlECpSybCwtJuP5UOg0O5Idfstzm71LBhpaOianPyq4yO7 a7mWPfXYYO9RohUPTzhFuhkxoVR8FWe9FNEMCqpQ= From: Andrey Lepikhov Subject: Re: Asynchronous Append on postgres_fdw nodes. To: Kyotaro Horiguchi Cc: etsuro.fujita@gmail.com, movead.li@highgo.ca, pgsql-hackers@lists.postgresql.org References: <158389119893.14910.7314550871261530973.pgcf@coridan.postgresql.org> <20200604.150015.2305436578805492574.horikyota.ntt@gmail.com> Message-ID: <90cced83-9061-0cac-0012-84e5faac8c78@postgrespro.ru> Date: Tue, 9 Jun 2020 14:20:42 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200604.150015.2305436578805492574.horikyota.ntt@gmail.com> Content-Type: multipart/mixed; boundary="------------E640AA771C6E46CE20E146CB" 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. --------------E640AA771C6E46CE20E146CB Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit On 6/4/20 11:00 AM, Kyotaro Horiguchi wrote: > Removed a useless variable PgFdwScanState.result_ready. > Removed duplicate code from remove_async_node() by using move_to_next_waiter(). > Done some minor cleanups. > I am reviewing your code. A couple of variables are no longer needed (see changes.patch in attachment. Something about the cost of an asynchronous plan: At the simple query plan (see below) I see: 1. Startup cost of local SeqScan is equal 0, ForeignScan - 100. But startup cost of Append is 0. 2. Total cost of an Append node is a sum of the subplans. Maybe in the case of asynchronous append we need to use some reduce factor? explain select * from parts; With Async Append: ===================== Append (cost=0.00..2510.30 rows=106780 width=8) Async subplans: 3 -> Async Foreign Scan on part_1 parts_2 (cost=100.00..177.80 rows=2260 width=8) -> Async Foreign Scan on part_2 parts_3 (cost=100.00..177.80 rows=2260 width=8) -> Async Foreign Scan on part_3 parts_4 (cost=100.00..177.80 rows=2260 width=8) -> Seq Scan on part_0 parts_1 (cost=0.00..1443.00 rows=100000 width=8) Without Async Append: ===================== Append (cost=0.00..2510.30 rows=106780 width=8) -> Seq Scan on part_0 parts_1 (cost=0.00..1443.00 rows=100000 width=8) -> Foreign Scan on part_1 parts_2 (cost=100.00..177.80 rows=2260 width=8) -> Foreign Scan on part_2 parts_3 (cost=100.00..177.80 rows=2260 width=8) -> Foreign Scan on part_3 parts_4 (cost=100.00..177.80 rows=2260 width=8) -- Andrey Lepikhov Postgres Professional https://postgrespro.com The Russian Postgres Company --------------E640AA771C6E46CE20E146CB Content-Type: text/x-patch; charset=UTF-8; name="changes.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="changes.patch" diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index b04b6a0e54..4406a9c3b3 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -1632,9 +1632,6 @@ remove_async_node(ForeignScanState *node) if (leader == node) { - /* It's the leader */ - ForeignScanState *next_leader; - if (leader_state->s.commonstate->busy) { /* @@ -1769,7 +1766,7 @@ postgresIterateForeignScan(ForeignScanState *node) node->ss.ps.asyncstate = AS_AVAILABLE; else node->ss.ps.asyncstate = AS_WAITING; - +elog(WARNING, "No tuple result %d", fsstate->cursor_number); return ExecClearTuple(slot); } @@ -3703,7 +3700,7 @@ request_more_data(ForeignScanState *node) snprintf(sql, sizeof(sql), "FETCH %d FROM c%u", fsstate->fetch_size, fsstate->cursor_number); - +elog(WARNING, "FETCH: %s", sql); if (!PQsendQuery(conn, sql)) pgfdw_report_error(ERROR, NULL, conn, false, sql); @@ -3769,7 +3766,6 @@ fetch_received_data(ForeignScanState *node) PG_TRY(); { PGconn *conn = fsstate->s.conn; - char sql[64]; int addrows; size_t newsize; int i; @@ -3798,7 +3794,7 @@ fetch_received_data(ForeignScanState *node) node, fsstate->temp_cxt); } - +elog(WARNING, "fetch cursor: %d (%d %d)", fsstate->cursor_number, fsstate->num_tuples, addrows); /* Update fetch_ct_2 */ if (fsstate->fetch_ct_2 < 2 && fsstate->next_tuple == 0) fsstate->fetch_ct_2++; --------------E640AA771C6E46CE20E146CB--