pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: 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:50:41 -0700
Message-ID: <20200720205041.32grdowjochgagpq@alap3.anarazel.de> (raw)
In-Reply-To: <578634.1595267899@sss.pgh.pa.us>
References: <1jxEsu-0bGx160@fwd35.t-online.de>
	<578634.1595267899@sss.pgh.pa.us>

Hi,

On 2020-07-20 13:58:19 -0400, Tom Lane wrote:
> =?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.

And it's explicitly not about handling conflicts between rows inserted
in the same statement. In fact, one gets an error when using ON
CONFLICT .. DO UPDATE affects a row modified in the same statement:

CREATE TABLE conflict(key text primary key, data text not null);
INSERT INTO conflict VALUES ('a', 'a1'),('a', 'a2'),('b', 'b2') ON CONFLICT (key) DO UPDATE set data = excluded.data;
ERROR:  21000: ON CONFLICT DO UPDATE command cannot affect row a second time
HINT:  Ensure that no rows proposed for insertion within the same command have duplicate constrained values.
LOCATION:  ExecOnConflictUpdate, nodeModifyTable.c:1590
Time: 1.174 ms

Greetings,

Andres Freund





view thread (5+ messages)

Message-ID: <20200720205041.32grdowjochgagpq@alap3.anarazel.de>
Permalink:  ../20200720205041.32grdowjochgagpq@alap3.anarazel.de/
Also on:    postgresql.org/message-id/20200720205041.32grdowjochgagpq@alap3.anarazel.de

 · 

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: andres@anarazel.de, 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: <20200720205041.32grdowjochgagpq@alap3.anarazel.de>
  References: <1jxEsu-0bGx160@fwd35.t-online.de> <578634.1595267899@sss.pgh.pa.us> <20200720205041.32grdowjochgagpq@alap3.anarazel.de>

* 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