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 1lehY5-00047m-OZ for pgsql-hackers@arkaria.postgresql.org; Thu, 06 May 2021 17:12:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lehY4-00036k-MP for pgsql-hackers@arkaria.postgresql.org; Thu, 06 May 2021 17:12:28 +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 1lehY4-00036a-ED for pgsql-hackers@lists.postgresql.org; Thu, 06 May 2021 17:12:28 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lehY1-0005Vh-UF for pgsql-hackers@lists.postgresql.org; Thu, 06 May 2021 17:12:27 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 3A72A5F799; Thu, 6 May 2021 13:12:24 -0400 (EDT) Date: Thu, 6 May 2021 13:12:24 -0400 From: Stephen Frost To: Etsuro Fujita Cc: Kyotaro Horiguchi , Justin Pryzby , Andrey Lepikhov , PostgreSQL Hackers Subject: Re: Asynchronous Append on postgres_fdw nodes. Message-ID: <20210506171224.GV20766@tamriel.snowman.net> References: <20210218.151557.1106337659785292399.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="sm6iOyB4RRMQYNyk" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --sm6iOyB4RRMQYNyk Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Etsuro Fujita (etsuro.fujita@gmail.com) wrote: > On Thu, Mar 4, 2021 at 1:00 PM Etsuro Fujita wr= ote: > > Another thing I'm concerned about in the postgres_fdw part is the case > > where all/many postgres_fdw ForeignScans of an Append use the same > > connection, because in that case those ForeignScans are executed one > > by one, not in parallel, and hence the overhead of async execution > > (i.e., doing ExecAppendAsyncEventWait()) would merely cause a > > performance degradation. Here is such an example: > > > > postgres=3D# create server loopback foreign data wrapper postgres_fdw > > options (dbname 'postgres'); > > postgres=3D# create user mapping for current_user server loopback; > > postgres=3D# create table pt (a int, b int, c text) partition by range = (a); > > postgres=3D# create table loct1 (a int, b int, c text); > > postgres=3D# create table loct2 (a int, b int, c text); > > postgres=3D# create table loct3 (a int, b int, c text); > > postgres=3D# create foreign table p1 partition of pt for values from > > (10) to (20) server loopback options (table_name 'loct1'); > > postgres=3D# create foreign table p2 partition of pt for values from > > (20) to (30) server loopback options (table_name 'loct2'); > > postgres=3D# create foreign table p3 partition of pt for values from > > (30) to (40) server loopback options (table_name 'loct3'); > > postgres=3D# insert into p1 select 10 + i % 10, i, to_char(i, 'FM00000') > > from generate_series(0, 99999) i; > > postgres=3D# insert into p2 select 20 + i % 10, i, to_char(i, 'FM00000') > > from generate_series(0, 99999) i; > > postgres=3D# insert into p3 select 30 + i % 10, i, to_char(i, 'FM00000') > > from generate_series(0, 99999) i; > > postgres=3D# analyze pt; > > > > postgres=3D# set enable_async_append to off; > > postgres=3D# select count(*) from pt; > > count > > -------- > > 300000 > > (1 row) > > > > Time: 366.905 ms > > > > postgres=3D# set enable_async_append to on; > > postgres=3D# select count(*) from pt; > > count > > -------- > > 300000 > > (1 row) > > > > Time: 385.431 ms >=20 > I think the user should be careful about this. How about adding a > note about it to the =E2=80=9CAsynchronous Execution Options=E2=80=9D sec= tion in > postgres-fdw.sgml, like the attached? I'd suggest the language point out that it's not actually possible to do otherwise, since they all need to be part of the same transaction. Without that, it looks like we're just missing a trick somewhere and someone might think that they could improve PG to open multiple connections to the same remote server to execute them in parallel. Maybe: In order to ensure that the data being returned from a foreign server is consistent, postgres_fdw will only open one connection for a given foreign server and will run all queries against that server sequentially even if there are multiple foreign tables involved. In such a case, it may be more performant to disable this option to eliminate the overhead associated with running queries asynchronously. =2E.. then again, it'd really be better if we could figure out a way to just do the right thing here. I haven't looked at this in depth but I would think that the overhead of async would be well worth it just about any time there's more than one foreign server involved. Is it not reasonable to have a heuristic where we disable async in the cases where there's only one foreign server, but have it enabled all the other time? While continuing to allow users to manage it explicitly if they want. Thanks, Stephen --sm6iOyB4RRMQYNyk Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJglCN3AAoJEO1sijiDR2RVdsoP/2PPPrl8eZ++PnwgQPqKiGSD Pti8PDIiUqjAqCzFhuhzSUEc4bAXFfF4U0oIw3HW84A80yuR3jDnUoEeQGP0ZAoQ IJNao1oU5ab7OgUr0PzsSJgzNt+kF8sE0jVyNGuqQqYmbFiscQwCJqXFy11PqnW6 Qqe6AAUtyJsqfmjNMQMR/MJ6VTeSSlsA6ZnbTvmwJFQDC4NcEzrf9BBRmNb8gP2m YgKC+Pzw5uN+CqteY2U+V29C3oxYh55FAoJF7/clj48DCtiXiyGh0ez7HZYXfvjL /QDxaZR5hrIHIP2+rLTC3ot2RL68y019q0tyJZ27JozmNmNGsUVhHV6i7DjMSvnA Nc+jWsUg4WdraT+NzBzi6WcXf2ZnBImohGfXW1s04gXoHpQucXy8hjM+YMVOhNZj ui7DfH0i4DJXyvcSoT6MP59WW8cLqsPAVCF7Th2eavPf9po+hX8zPxivQn/Oh/6O LGyzNDUeoFXSJAORFjFFFhZurJt3rBHXg12xaTLptqOxUec2wnxvN9BbR4qMEJf0 AhGB+wFZjrFHbkV8TXQb0UfufUrN3EzlEKrvNnuWUfOmrLLdIAn3lsQlQwBVW7Zz EAeH/uq0zV+N/PNlBp+bBHVdTJOVqk7syWdqOqX/bssUrb2JO9LiTcH5Zwz3Uge5 C/oszdf3dECpU1LMmoza =DIVK -----END PGP SIGNATURE----- --sm6iOyB4RRMQYNyk--