Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f0T1b-0005TS-4M for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Mar 2018 14:23:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f0T1a-0000U8-7h for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Mar 2018 14:23:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f0Sz9-0005Ev-Gd for pgsql-hackers@lists.postgresql.org; Mon, 26 Mar 2018 14:20:31 +0000 Received: from new1-smtp.messagingengine.com ([66.111.4.221]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f0Sz0-0007At-N1 for pgsql-hackers@postgresql.org; Mon, 26 Mar 2018 14:20:30 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 9A0811218; Mon, 26 Mar 2018 10:20:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 26 Mar 2018 10:20:20 -0400 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:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=BdHViJ6a1aoBxVp3n 9IKxCBc5uaAFhMK/bs5UaFPXec=; b=ki1iLfBgqymHCOBmSBJpMasT+AaypejpB AHet/86MnMWCa3wf8MzlAoXfL9GbC1QH6EWnYbSD4BkdA2MIbFtx6b7m60NRf3sM w+2dSpoeORnUiEljtRUjKOqDy9tuTAsKLvrPcFR08Wj00WkQF9JEMPfUdYmGdwf9 XEjUbrf9LGascX32z5UZV4x64W7M/FEZRCAAH37d8AvxneSGpEDAo1UL6WPtgxmO 4/Vc0xd4MiQuqumO/kh+t22X+gR+P1LV0Ox+2Ja9+7bpW3UVuuYDvRqOxu2dD9VM Iqqb1uTJZoHG1pv16CLQtph2C3++v4L99J1iY1zDEBx5fcgmI6ppQ== X-ME-Sender: Received: from alvin.alvh.no-ip.org (unknown [179.56.51.182]) by mail.messagingengine.com (Postfix) with ESMTPA id 7B2FCE5084; Mon, 26 Mar 2018 10:20:19 -0400 (EDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 2BA385A7; Mon, 26 Mar 2018 11:20:16 -0300 (-03) Date: Mon, 26 Mar 2018 11:20:16 -0300 From: Alvaro Herrera To: Amit Langote Cc: Pavan Deolasee , Etsuro Fujita , Andres Freund , Pg Hackers , Peter Geoghegan Subject: Re: ON CONFLICT DO UPDATE for partitioned tables Message-ID: <20180326142016.m4st5e34chrzrknk@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Pushed now. Amit Langote wrote: > On 2018/03/24 9:23, Alvaro Herrera wrote: > > To fix this, I had to completely rework the "get partition parent root" > > stuff into "get list of ancestors of this partition". > > I wondered if a is_partition_ancestor(partrelid, ancestorid) isn't enough > instead of creating a list of ancestors and then looping over it as you've > done, but maybe what you have here is fine. Yeah, I wondered about doing it that way too (since you can stop looking early), but decided that I didn't like repeatedly opening pg_inherits for each level. Anyway the most common case is a single level, and in rare cases two levels ... I don't think we're going to see much more than that. So it doesn't matter too much. We can refine later anyway, if this becomes a hot spot (I doubt it TBH). > > * General code style improvements, comment rewording, etc. > > There was one comment in Fujita-san's review he posted on Friday [1] that > doesn't seem to be addressed in v10, which I think we probably should. It > was this comment: > > "ExecBuildProjectionInfo is called without setting the tuple descriptor of > mtstate->mt_conflproj to tupDesc. That might work at least for now, but I > think it's a good thing to set it appropriately to make that future proof." > > All of his other comments seem to have been taken care of in v10. I have > fixed the above one in the attached updated version. I was of two minds about this item myself; we don't use the tupdesc for anything at that point and I expect more things would break if we required that. But I don't think it hurts, so I kept it. The one thing I wasn't terribly in love with is the four calls to map_partition_varattnos(), creating the attribute map four times ... but we already have it in the TupleConversionMap, no? Looks like we could save a bunch of work there. And a final item is: can we have a whole-row expression in the clauses? We currently don't handle those either, not even to throw an error. [figures a test case] ... and now that I test it, it does crash! create table part (a int primary key, b text) partition by range (a); create table part1 (b text, a int not null); alter table part attach partition part1 for values from (1) to (1000); insert into part values (1, 'two') on conflict (a) do update set b = format('%s (was %s)', excluded.b, part.b) where part.* *<> (1, text 'two'); I think this means we should definitely handle found_whole_row. (If you create part1 in the normal way, it works as you'd expect.) I'm going to close a few other things first, then come back to this. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services