Re: Improvement for query planner? (no, not about count(*) again ;-))

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tobias Völk <tobias(dot)voelk(at)t-online(dot)de>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: Improvement for query planner? (no, not about count(*) again ;-))
Date: 2020-07-20 17:58:19
Message-ID: 578634.1595267899@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general

=?utf-8?Q?Tobias_V=C3=B6lk?= <tobias(dot)voelk(at)t-online(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andres Freund 2020-07-20 20:50:41 Re: Improvement for query planner? (no, not about count(*) again ;-))
Previous Message Francisco Olarte 2020-07-20 14:44:16 Re: Improvement for query planner? (no, not about count(*) again ;-))

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2020-07-20 18:04:45 Re: Logical replication from 11.x to 12.x and "unique key violations"
Previous Message Adrian Klaver 2020-07-20 17:56:59 Re: Logical replication from 11.x to 12.x and "unique key violations"