pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tobias Völk <tobias.voelk@t-online.de>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: Improvement for query planner? (no, not about count(*) again ;-))
Date: Mon, 20 Jul 2020 13:58:19 -0400
Message-ID: <578634.1595267899@sss.pgh.pa.us> (raw)
In-Reply-To: <1jxEsu-0bGx160@fwd35.t-online.de>
References: <1jxEsu-0bGx160@fwd35.t-online.de>

=?utf-8?Q?Tobias_V=C3=B6lk?= <tobias.voelk@t-online.de> writes:
> I’ve asked postgres to make an unlogged newtable(name text primary key) consisting of the unqiue names and executed:

> Insert into newtable(name) select name1 from games on conflict do nothing;

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





view thread (5+ messages)  latest in thread

Message-ID: <578634.1595267899@sss.pgh.pa.us>
Permalink:  ../578634.1595267899@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/578634.1595267899@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, tobias.voelk@t-online.de, pgsql-bugs@lists.postgresql.org
  Subject: Re: Improvement for query planner? (no, not about count(*) again ;-))
  In-Reply-To: <578634.1595267899@sss.pgh.pa.us>
  References: <1jxEsu-0bGx160@fwd35.t-online.de> <578634.1595267899@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox