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 1hq2Ax-0005gj-Ew for pgsql-general@arkaria.postgresql.org; Tue, 23 Jul 2019 21:18:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hq2Av-0000yI-NW for pgsql-general@arkaria.postgresql.org; Tue, 23 Jul 2019 21:18:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hq2Av-0000xS-DJ for pgsql-general@lists.postgresql.org; Tue, 23 Jul 2019 21:18:21 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hq2Ao-0000xh-5m for pgsql-general@lists.postgresql.org; Tue, 23 Jul 2019 21:18:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x6NLIAoW029966; Tue, 23 Jul 2019 17:18:10 -0400 From: Tom Lane To: Alexander Voytsekhovskyy cc: pgsql-general@lists.postgresql.org Subject: Re: Query plan: SELECT vs INSERT from same select In-reply-to: References: Comments: In-reply-to Alexander Voytsekhovskyy message dated "Tue, 23 Jul 2019 23:29:27 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29964.1563916690.1@sss.pgh.pa.us> Date: Tue, 23 Jul 2019 17:18:10 -0400 Message-ID: <29965.1563916690@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alexander Voytsekhovskyy writes: > You can see explain analyze verbose here: > https://explain.depesz.com/s/AEWj > The problem is, when i wrap it to > A) > INSERT INTO norepl_1542_result (axis_x1, axis_y1, v_1) > SELECT .... SAME QUERY > OR even > B) > WITH rows AS ( > ... SAME SELECT QUERY ... > ) > INSERT INTO norepl_1542_result (axis_x1, axis_y1, v_1) > SELECT * FROM rows > The query time dramatically drops to 500+ seconds. > You can see explain analyze verbose here > https://explain.depesz.com/s/AEWj That's the same link. > As you can see, 100% of time goes to same SELECT query, there is no issues > with INSERT-part We can't see any such thing from what you posted. regards, tom lane