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 1ermjC-0001NC-Mp for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Mar 2018 15:36:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ermjB-0000bV-K9 for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Mar 2018 15:36:09 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ermjB-0000Xg-93 for pgsql-hackers@lists.postgresql.org; Fri, 02 Mar 2018 15:36:09 +0000 Received: from mail-qk0-x233.google.com ([2607:f8b0:400d:c09::233]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ermj7-0004FV-Gj for pgsql-hackers@postgresql.org; Fri, 02 Mar 2018 15:36:07 +0000 Received: by mail-qk0-x233.google.com with SMTP id g2so12359327qkd.12 for ; Fri, 02 Mar 2018 07:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=RrX4f4dpW+iQd0rdoakEHxIKD/HDuua8+e3wK1x/mh4=; b=PbQGkJZOETGrbJ6E1SzTPwAcDHYI+hbQyMGX1AxFk/TCHIhKHcAA4ogM9E+29TVQHH 9rHMIDDMqcfsF7AxiyRUfGiHcl20O9aT2K3xXsS4Nd/0/gfRSZ1Db4InkZ9fw9bzHqr4 R0vhYD/hFsytfXbkwT67kBw+9nlF8fGybVslNtVCL6n2mx4tIWPD1aTAubQJZ03tskO/ Vxj582Jy3Ud9jizimApbrA1RPd98Msi7f+EUUDwy46Aoy1yK8KQXHo1+rKvY8jDmNCiq QQSSM+SoQXMq7yU77h5CSZQP8WleovjPJWcF1mby7U4l77dSoqQ6lCS5yW5W6hMywiYw DAHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=RrX4f4dpW+iQd0rdoakEHxIKD/HDuua8+e3wK1x/mh4=; b=Ui0hqkG1720PUTaYViwAcgwu1LQqbYq0i7ShYbJGNr0n6bLh0NgwZyvAmdsY3nGl1V 4k2p6zba3YmAuSnqNgV2EBZE6+jgeV4TzN4AVG8aKDOVixWYoxPFNdgCuzINI+BhFAEK 68r0FRgkwjxaX0uF+n7Gtid9CXcAF48gCNF7YIwrmTrsfFRSRowhq4oeJslo9gCx1Flw WSPh1Bz6KWe+lQW3gvgmY8309CY457ouZUIwuMn6SulbkHDtPphhVX47eoL65gjysgs2 cAOO+Lla7X8XhMnrrotxjrMW/tihc72vnTL2gfOBa0WPyHvl/oy2e9AI49fshKODPgig biHg== X-Gm-Message-State: AElRT7GDE+h2Uak5RKTzQ/OS5kMxBL21S8aLW7fo2F7CmRgwNk0eKD9T V5tY0TnAdCYkXP4dLn3ohjg0MawL X-Google-Smtp-Source: AG47ELscbwqvje6wgoIz8oAEJOW3QxxR+UfV/hg2ISzWm4iHOt3RXpIF5cf4naedd4q/KqwQWHTOIA== X-Received: by 10.55.6.10 with SMTP id 10mr8906482qkg.191.1520004963964; Fri, 02 Mar 2018 07:36:03 -0800 (PST) Received: from alvin.alvh.no-ip.org ([179.57.113.18]) by smtp.gmail.com with ESMTPSA id j10sm4658570qtb.50.2018.03.02.07.36.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 02 Mar 2018 07:36:03 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id E9747751; Fri, 2 Mar 2018 12:35:58 -0300 (-03) Date: Fri, 2 Mar 2018 12:35:58 -0300 From: Alvaro Herrera To: Amit Langote Cc: Pg Hackers Subject: Re: ON CONFLICT DO UPDATE for partitioned tables Message-ID: <20180302153558.czbufv6ojwdfk4lp@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3c3bbb2c-c28f-5b09-c124-b99e2231fe9b@lab.ntt.co.jp> User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Amit Langote wrote: > Actually, after your comment on my original patch [1], I did make it work > for multiple levels by teaching the partition initialization code to find > a given partition's indexes that are inherited from the root table (that > is the table mentioned in command). So, after a tuple is routed to a > partition, we switch from the original arbiterIndexes list to the one we > created for the partition, which must contain OIDs corresponding to those > in the original list. After all, for each of the parent's indexes that > the planner put into the original arbiterIndexes list, there must exist an > index in each of the leaf partitions. Oh, your solution for this seems simple enough. Silly me, I was trying to implement it in a quite roundabout way. Thanks. (I do wonder if we should save the "root" reloid in the relcache). > I had also observed when working on the patch that various TupleTableSlots > used by the ON CONFLICT DO UPDATE code must be based on TupleDesc of the > inheritance-translated target list (DO UPDATE SET target list). In fact, > that has to take into account also the dropped columns; we may have > dropped columns either in parent or in a partition or in both at same or > different attnum positions. That means, simple map_partition_varattnos() > translation doesn't help in this case. Yeah, I was aware these corner cases could become a problem though I hadn't gotten around to testing them yet. Thanks for all your work on this. The usage of the few optimizer/prep/ functions that are currently static doesn't fill me with joy. These functions have weird APIs because they're static so we don't rally care, but once we export them we should strive to be more careful. I'd rather stay away from just exporting them all, so I chose to encapsulate those calls in a single function and export only expand_targetlist from preptlist.c, keeping the others static in prepunion.c. In the attached patch set, I put an API change (work on tupdescs rather than full-blown relations) for a couple of those functions as 0001, then your patch as 0002, then a few fixups of my own. (0002 is not bit-by-bit identical to yours; I think I had to fix some merge conflict with 0001, but should be pretty much the same). But looking further, I think there is much cruft that has accumulated in those functions (because they've gotten simplified over time), and we could do some additional cleanup surgery. For example, there is no reason to pass a list pointer to make_inh_translation_list(); we could just return it. And then we don't have to cons up a fake AppendRelInfo with all dummy values that adjust_inherited_tlist doesn't even care about. I think there was a point for all these contortions back at some point (visible by checking git history of this code), but it all seems useless now. Re. the "ugly hack" comments in adjust_inherited_tlist(), I'm confused: expand_targetlist() runs *after*, not before, so how could it have affected the result? I'm obviously confused about what expand_targetlist call this comment is talking about. Anyway I wanted to make it use resjunk entries instead, but that broke some other case that I didn't have time to research yesterday. I'll get back to this soon, but in the meantime, here's what I have. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services