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 1jxckL-00012b-Si for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Jul 2020 20:50:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jxckJ-0006Go-Nx for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Jul 2020 20:50:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jxckJ-0006Gg-HR for pgsql-bugs@lists.postgresql.org; Mon, 20 Jul 2020 20:50:47 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jxckH-0004In-Ev for pgsql-bugs@lists.postgresql.org; Mon, 20 Jul 2020 20:50:46 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id C6214A72; Mon, 20 Jul 2020 16:50:43 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 20 Jul 2020 16:50:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:content-transfer-encoding:in-reply-to; s=fm2; bh=z eZOIukc1EqnK53Vz78beIodyZGTxZ5yOUQyHAyEKIo=; b=W6UbL2St99slKaAub rjFDaxixAy1wSeJ6s38UrvGD8b/rgv8oOIoCxFeACUrxxVMIoYP0+Vkv+CNnn1dj EuEd7ABOW8gTCa13c9NYAWRlUPUAWBhDyi+HkO+0fJaqdeca04D4AR0r0BDN8Di0 kEFpad0sHoWtObsMupT6oAb7HuZSLlhiU3MlBSFL8zCfashsYhuIc3HmHHWIKd+2 mW/VIw2SivpS3WTtdJjI2sJ08KVj16Yjzt15u9Mq2QNbJ74yIWG2SI5EbvAFH59C UUPuMRqKE52xroGrCVs3gBC2YjnecZqWOcksIO2sJEmBq4MTJFWmUXOrvm7tqiVF 1Vb/A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=zeZOIukc1EqnK53Vz78beIodyZGTxZ5yOUQyHAyEK Io=; b=Al4u1PvXprR37x6eeV6DYx2bTU9rzF7/EhYJiTkQ9ijlyaJ03JxyRJY9E sM4JzFXaCXFoFLyziZwZ0O9bfnHI9WgC/8a3LAswoTeSDzOl+KVbNHl/9gZ3x5Bu pjrXkCNbm2+5kU+f+G590N5JagPkmXMNuZi01CqILmSsXhkXpHkDvdR6mScbZn5t E33tR6tPOjW0sHk7+aJlfznybUFBze3xJSR8KdgHgjyO+UWVgJycC/uE2kbzQXfM y0jsIHWxbgfXhq7ERBmdb/kFbyUslZnjrw+/A7gDogfZLyaK3LdjYqTta+DWeGSX V7RAi/a1fsNO3amiRVrGM1qEMQlGg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrgeeggddufeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggugfgjsehtke ertddttdejnecuhfhrohhmpeetnhgurhgvshcuhfhrvghunhguuceorghnughrvghssegr nhgrrhgriigvlhdruggvqeenucggtffrrghtthgvrhhnpeeiudeujefhueefffffffekie dthfelueffueelhfekheeujefffefghfffffetffenucfkphepieejrdduiedtrddvudej rddvhedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Received: from intern.anarazel.de (c-67-160-217-250.hsd1.ca.comcast.net [67.160.217.250]) by mail.messagingengine.com (Postfix) with ESMTPA id 65F0F3060067; Mon, 20 Jul 2020 16:50:42 -0400 (EDT) Date: Mon, 20 Jul 2020 13:50:41 -0700 From: Andres Freund To: Tom Lane Cc: Tobias =?utf-8?B?VsO2bGs=?= , "pgsql-bugs@lists.postgresql.org" Subject: Re: Improvement for query planner? (no, not about count(*) again ;-)) Message-ID: <20200720205041.32grdowjochgagpq@alap3.anarazel.de> References: <1jxEsu-0bGx160@fwd35.t-online.de> <578634.1595267899@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <578634.1595267899@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2020-07-20 13:58:19 -0400, Tom Lane wrote: > =?utf-8?Q?Tobias_V=C3=B6lk?= 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