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

From Tom Lane
Subject Re: Improvement for query planner? (no, not about count(*) again ;-))
Date
Msg-id 578634.1595267899@sss.pgh.pa.us
Whole thread Raw
In response to Improvement for query planner? (no, not about count(*) again ;-))  (Tobias Völk <tobias.voelk@t-online.de>)
Responses Re: Improvement for query planner? (no, not about count(*) again ;-))
List pgsql-bugs
=?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



pgsql-bugs by date:

Previous
From: Jehan-Guillaume de Rorthais
Date:
Subject: Re: Buffers from parallel workers not accumulated to upper nodes with gather merge
Next
From: Andres Freund
Date:
Subject: Re: Improvement for query planner? (no, not about count(*) again ;-))