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 1jxa3W-00030U-O7 for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Jul 2020 17:58:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jxa3V-00008V-DG for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Jul 2020 17:58:25 +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 1jxa3V-00008O-7H for pgsql-bugs@lists.postgresql.org; Mon, 20 Jul 2020 17:58:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jxa3S-0005WW-W2 for pgsql-bugs@lists.postgresql.org; Mon, 20 Jul 2020 17:58:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 06KHwJp8578635; Mon, 20 Jul 2020 13:58:20 -0400 From: Tom Lane To: =?utf-8?Q?Tobias_V=C3=B6lk?= cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: Improvement for query planner? (no, not about count(*) again ;-)) In-reply-to: <1jxEsu-0bGx160@fwd35.t-online.de> References: <1jxEsu-0bGx160@fwd35.t-online.de> Comments: In-reply-to =?utf-8?Q?Tobias_V=C3=B6lk?= message dated "Sun, 19 Jul 2020 21:22:03 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <578633.1595267899.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 20 Jul 2020 13:58:19 -0400 Message-ID: <578634.1595267899@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?utf-8?Q?Tobias_V=3DC3=3DB6lk?=3D writes: > I=E2=80=99ve asked postgres to make an unlogged newtable(name text prima= ry key) consisting of the unqiue names and executed: > Insert into newtable(name) select name1 from games on conflict do nothin= g; ON CONFLICT is a really, really expensive way to eliminate duplicates. It's meant to handle situations where two or more sessions might concurrently insert duplicate keys, which means that (a) there's not really any way to detect the situation in advance or optimize it, and (b) we don't expect it to happen that much anyhow. You'd be better off with something like insert into newtable(name) select distinct name1 from games; or insert into newtable(name) select name1 from games group by name1; regards, tom lane