Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZRku-0002HW-QM for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Dec 2018 02:38:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gZRks-0000LK-8t for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Dec 2018 02:38:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZRkq-0000A3-I9 for pgsql-bugs@lists.postgresql.org; Wed, 19 Dec 2018 02:38:38 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZRki-0005ZU-Pd for pgsql-bugs@lists.postgresql.org; Wed, 19 Dec 2018 02:38:35 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id EDC2F22131; Tue, 18 Dec 2018 21:38:27 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 18 Dec 2018 21:38:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=A+WFhxAzOEn3AYGvkAIlWEoHkF8 JCljsbYBP8da0iAg=; b=KwiNUEiM3HHjeJBKfDB6YL1jBq1aR5cip/JPmxQ23AP 5zKQQcrAMr4Z0r9JF9HWPqWpkZ3kphs0+AYTW9BywA5qb2pa5dI7wKL0wO4FVnbJ 0XJDYloM1naKGZCgpDfJR59faIeR6tJOSlPpDRK+hdF//aelcVpdkP7kyBDKSHqB zmvAJU84QhJQjK9QylMy7QTj43jm1QySj4pqrdaj0zVlaIYUI7KUvXYdHlfc9Obo t5mCwM08AJEj/gUEnJ1Ijpm+AixITQcyLy+7Gk0P7B36JmWEr2rQLWuALOaCflyZ 5McX6JIcZ4B8nh+BTEsCvwY9+UwoGVbKh74cdcBpfeQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=A+WFhx AzOEn3AYGvkAIlWEoHkF8JCljsbYBP8da0iAg=; b=mRMmNW8fZ/MYtu7o9DU3Fz 7ap5jeO5O4ME3hInQCHM4bIw/aOr2nzMOYzaZ0cZG8Ui1CE8JhOfTNqDVE1wU4Hz +a9YBQdeLR9EcRxRLUjObjdJw/f8Oz8zoip0IppVILpPO5jKjvf/0KLPi6AncAxY /AWzPYUzuuoNX1dkNC1FOeU5P2YqpAm1S1qulX7K5yDAq8ObSiZ/5hA59CcqJ3Q8 JRUf679WCG23RRx9Ml4tCyksio2O4jc+D2GglIH5CXFq1UfRqL3z1U/Yd+ws1RV9 dnMU4e3maCjgP5LpHMY0LuuAJzfW6xiC2ZoSX6ul4V9sBsDs4A0Q30ajRf8Bvb2w == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtkedrudeiledgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhhtnecuuegrihhlohhuthemucef tddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdejtd dmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgt hhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqne cukfhppeeiuddrvdduhedrudefjedrudeivdenucfrrghrrghmpehmrghilhhfrhhomhep mhhitghhrggvlhesphgrqhhuihgvrhdrgiihiienucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id F2A5B10085; Tue, 18 Dec 2018 21:38:20 -0500 (EST) Date: Wed, 19 Dec 2018 11:38:14 +0900 From: Michael Paquier To: Amit Langote Cc: Luis Carril , Etsuro Fujita , "pgsql-bugs@lists.postgresql.org" , PG Bug reporting form , Michael Paquier Subject: Re: BUG #15552: Unexpected error in COPY to a foreign table in a transaction Message-ID: <20181219023814.GA6577@paquier.xyz> References: <15552-c64aa14c5c22f63c@postgresql.org> <8e82d10d-cc16-eed4-7634-3654f59d8053@lab.ntt.co.jp> <30718b48-8020-329a-c6f0-74e1222e5283@lab.ntt.co.jp> <5C18ECBB.2000507@lab.ntt.co.jp> <3539e73a-313a-5406-27c7-850affb47921@lab.ntt.co.jp> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ftEhullJWpWg/VHq" Content-Disposition: inline In-Reply-To: <3539e73a-313a-5406-27c7-850affb47921@lab.ntt.co.jp> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --ftEhullJWpWg/VHq Content-Type: multipart/mixed; boundary="KsGdsel6WgEHnImy" Content-Disposition: inline --KsGdsel6WgEHnImy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Dec 19, 2018 at 10:19:58AM +0900, Amit Langote wrote: > Not sure that's a good name to give to the test file, although since I'm > not greatly enthusiastic about adding a TAP test for this, I don't have a > good suggestion. Maybe, choose a more generic name? Michael, any > suggestions? I have looked at the proposal seriously myself, and adding a TAP test for that edge case is overdoing it. So why not just adding a test to postgres_fdw.sql? The failure can be triggered with installcheck and wal_level =3D minimal. Not everybody tests with non-default options, but some of us do. > @@ -2401,6 +2401,7 @@ CopyFrom(CopyState cstate) > ^I */ > ^I/* createSubid is creation check, newRelfilenodeSubid is truncation > check */ > ^Iif (cstate->rel->rd_rel->relkind !=3D RELKIND_PARTITIONED_TABLE && > +^I cstate->rel->rd_rel->relkind !=3D RELKIND_FOREIGN_TABLE && > ^I^I(cstate->rel->rd_createSubid !=3D InvalidSubTransactionId || > ^I^I cstate->rel->rd_newRelfilenodeSubid !=3D InvalidSubTransactionId)) > ^I{ >=20 > It seems you've used spaces to indent the newly added line. Please, > change that to a tab like neighboring lines. Indeed. Attached is a more simple, updated, patch which adds a new test and a comment. I would rather not play with the semantics of heap_sync() on the back branches as well as on a thread dealing with a bug about COPY with foreign tables. Such discussions deserve a larger audience on -hackers. it is a bit funny to see COPY FREEZE working for foreign tables actually, but perhaps this has some use-cases for some FDWs, so I'd rather not touch it. -- Michael --KsGdsel6WgEHnImy Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="no_heap_opt_fdw_copy-v4.patch" Content-Transfer-Encoding: quoted-printable diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postg= res_fdw/expected/postgres_fdw.out index 666548ba69..bb92d9d37a 100644 --- a/contrib/postgres_fdw/expected/postgres_fdw.out +++ b/contrib/postgres_fdw/expected/postgres_fdw.out @@ -7981,6 +7981,22 @@ drop trigger rem2_trig_row_before on rem2; drop trigger rem2_trig_row_after on rem2; drop trigger loc2_trig_row_before_insert on loc2; delete from rem2; +-- test COPY FROM with foreign table created in the same transaction +create table loc3 (f1 int, f2 text); +begin; +create foreign table rem3 (f1 int, f2 text) + server loopback options(table_name 'loc3'); +copy rem3 from stdin; +commit; +select * from rem3; + f1 | f2 =20 +----+----- + 1 | foo + 2 | bar +(2 rows) + +drop foreign table rem3; +drop table loc3; -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -- test IMPORT FOREIGN SCHEMA -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_f= dw/sql/postgres_fdw.sql index f963e99ab6..f438165650 100644 --- a/contrib/postgres_fdw/sql/postgres_fdw.sql +++ b/contrib/postgres_fdw/sql/postgres_fdw.sql @@ -2124,6 +2124,20 @@ drop trigger loc2_trig_row_before_insert on loc2; =20 delete from rem2; =20 +-- test COPY FROM with foreign table created in the same transaction +create table loc3 (f1 int, f2 text); +begin; +create foreign table rem3 (f1 int, f2 text) + server loopback options(table_name 'loc3'); +copy rem3 from stdin; +1 foo +2 bar +\. +commit; +select * from rem3; +drop foreign table rem3; +drop table loc3; + -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -- test IMPORT FOREIGN SCHEMA -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 4311e16007..4d39509c61 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -2397,10 +2397,14 @@ CopyFrom(CopyState cstate) * possible to improve on this, but it does mean maintaining heap insert * option flags per partition and setting them when we first open the * partition. + * + * This optimization is not supported for foreign tables as they have no + * physical storage. *---------- */ /* createSubid is creation check, newRelfilenodeSubid is truncation check= */ if (cstate->rel->rd_rel->relkind !=3D RELKIND_PARTITIONED_TABLE && + cstate->rel->rd_rel->relkind !=3D RELKIND_FOREIGN_TABLE && (cstate->rel->rd_createSubid !=3D InvalidSubTransactionId || cstate->rel->rd_newRelfilenodeSubid !=3D InvalidSubTransactionId)) { --KsGdsel6WgEHnImy-- --ftEhullJWpWg/VHq Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlwZrxYACgkQnvQgOdby QH28Rg//e3Vl1BCBfwzIe06+lZuU73U8jdGr8fP6AjcT1Z+tSkjq2vogINZzRC1G uDULj6L4KXRK93f28CsfJNPpoxB8HzFVhgI5vsbXg5WR+4XIHWP7ahKyECXwU9kU oJY9INF+3hb1bK31z+lI2JR1IscEF32b1OxrUF8IJzzDjAECc5LZwCXZRac7iVI6 ie8LW5TZDPFigDoQdDAK+qFj2a5Pngh9DrUGZWdFN5oy0NyjIlWb5ITxfYQ8TvNL nuZ8pg9A0aW86uHEMEvScJI1LMxNifU7dynfVEchzRUo4qGSilXpL3cl0ovYVF+F kwiTWsmJwCN1UbuwSDmUGImBu2EHivfdo9gfdONqA0XUgHJ4QtHkMZi9/9lobSjN xUHlPtdlLrHRTGhjFGJaygqi61ac7SwhB0QnokfTKvwwVRZullWKAZk6o/iiJSMB nD3hM3VLDnYrTLiqVFmKQWHrfi2KFtIqiI0Ga8uOnqfvMj2HC3loCii0/DhZDxEA AyuNBtyWkt7QJKf41C5NAO1JLnHGhzsL6Y2bBcNZqq9o/SGOOEDatk1A5Y3CJ7xT DUibORoruHC7CFbw46XSrd1onjwnomMiodeJcligHAk8Fva8vXjyloXkn/yol1o5 j6kfjTO1cGJku91ISYrW7+Qg2vDnRvs3smX/vDra78u75qKad2g= =4nqC -----END PGP SIGNATURE----- --ftEhullJWpWg/VHq--