Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hoa9x-0006xH-NR for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jul 2019 21:11:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hoa9w-0004SK-KG for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jul 2019 21:11:20 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hoa9w-0004SD-7N for pgsql-hackers@lists.postgresql.org; Fri, 19 Jul 2019 21:11:20 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hoa9s-0007ES-Um for pgsql-hackers@postgresql.org; Fri, 19 Jul 2019 21:11:19 +0000 Received: by mail-qk1-x742.google.com with SMTP id t8so24315216qkt.1 for ; Fri, 19 Jul 2019 14:11:16 -0700 (PDT) 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=uDW7slnTvUrfROP1ub/MQKyaXufYUSYBd4sMvADFOFo=; b=KN3qKthvktVAYDpf5yUvt7dUSGNla/6ga7e5AYWNxXhipPLW/mG7/1FiiHERmdTjGZ c5Hwe3YPeoz3+9h8bHAa7cMleUEyKm05lP19GDtMutPdTpGItLkvl1jAU5cQfu2d6FPQ qwEybo7BXJGueP4vP83ntQilBoh698HtB4h3eO+8ZGYpSUcnr7AVuUu9BudQcZbL6JhU SOYxUifMJHMSKGnFYaio070g0oeGfVwVmA0xcnsEXCCa5AY7IjOhBLJS45OUAZDF/4k1 oOsFasgg1vVrAcWeRDkZW1AyEU8grmP4nqZk3P4rl6Z28mOjmB+wOpBGTSpcjAFQMpAo PVYw== 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=uDW7slnTvUrfROP1ub/MQKyaXufYUSYBd4sMvADFOFo=; b=RjHLiB4V/XoH9IdTuFltjULubjqd7GvNJo2zyuKCfhWzeuhlGDMSJArKgQbm3vNd40 t4YBY7334Nzk+QGcsyusC5sX/HKytU8QKv3sK0fhHbyC3YWtlPobkVD7HeKOWdfQqEZq dSnZgPUAeAnT+xTxUW3Qd1CjRvVif48jyCSS0mPcEgTIm2F4n6WRfT9SydzJ99EZ1EI6 q323k27Xb4NXzjM1f2LP0R+o02tLHqaCqfcZGxjQK29kfXh3iQ+Z4vsxVRgbczMUV48C Awqfi2TbRQ3K0SlHOK7RIZ1ksjhnWyphrKekk9udb6UbTG4KVSBQHr9n8KkDQ7BEmkPy LyvQ== X-Gm-Message-State: APjAAAXAYBPL7e3OzfSeOmKUZwILhj/pshECj8iS6dtnRn5rkBad1H/p o518yMuV7+Zys5m9Mmf+Clhv2w== X-Google-Smtp-Source: APXvYqxmEq6on7FnTm+K61vM4QBRdjEzqxXBqSSOT79z58Pdm2CBh8MQOPiMZGJYy7Ns1ksvz/XuZg== X-Received: by 2002:a05:620a:1f5:: with SMTP id x21mr27247569qkn.338.1563570674047; Fri, 19 Jul 2019 14:11:14 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([177.154.145.102]) by smtp.gmail.com with ESMTPSA id l80sm14730994qke.24.2019.07.19.14.11.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 19 Jul 2019 14:11:13 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 5F45B1249C7; Fri, 19 Jul 2019 17:11:10 -0400 (-04) Date: Fri, 19 Jul 2019 17:11:10 -0400 From: Alvaro Herrera To: Andres Freund Cc: Amit Langote , Thomas Munro , David Rowley , Robert Haas , Etsuro Fujita , PostgreSQL-development , amitdkhan.pg@gmail.com Subject: Re: partition routing layering in nodeModifyTable.c Message-ID: <20190719211110.GA19074@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190719165241.nblajgpf5ys2q5sh@alap3.anarazel.de> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Jul-19, Andres Freund wrote: > On 2019-07-19 17:52:20 +0900, Amit Langote wrote: > > The first one (0001) deals with reducing the core executor's reliance > > on es_result_relation_info to access the currently active result > > relation, in favor of receiving it from the caller as a function > > argument. So no piece of core code relies on it being correctly set > > anymore. It still needs to be set correctly for the third-party code > > such as FDWs. > > I'm inclined to just remove it. There's not much code out there relying > on it, as far as I can tell. Most FDWs don't support the direct modify > API, and that's afaict the case where we one needs to use > es_result_relation_info? Yeah, I too agree with removing it; since our code doesn't use it, it seems very likely that it will become slightly out of sync with reality and we'd not notice until some FDW misbehaves weirdly. > > - slot = ExecDelete(node, tupleid, oldtuple, planSlot, > > - &node->mt_epqstate, estate, > > + slot = ExecDelete(node, resultRelInfo, tupleid, oldtuple, > > + planSlot, &node->mt_epqstate, estate, > > true, node->canSetTag, > > false /* changingPart */ , NULL, NULL); > > break; > > This reminds me of another complaint: ExecDelete and ExecInsert() have > gotten more boolean parameters for partition moving, but only one of > them is explained with a comment (/* changingPart */) - think we should > do that for all. Maybe change the API to use a flags bitmask? (IMO the placement of the comment inside the function call, making the comma appear preceded with a space, looks ugly. If we want to add comments, let's put each param on its own line with the comment beyond the comma. That's what we do in other places where this pattern is used.) > > /* Initialize the executor state. */ > > - estate = create_estate_for_relation(rel); > > + estate = create_estate_for_relation(rel, &resultRelInfo); > > Hm. It kinda seems cleaner if we were to instead return the relevant > index, rather than the entire ResultRelInfo, as an output from > create_estate_for_relation(). Makes it clearer that it's still in the > EState. Yeah. > Or perhaps we ought to compute it in a separate step? Then that'd be > more amenable to support replcating into partition roots. I'm not quite seeing the shape that you're imagining this would take. I vote not to mess with that for this patch; I bet that we'll have to change a few other things in this code when we add better support for partitioning in logical replication. > > +/* > > + * ExecMove > > + * Move an updated tuple from the input result relation to the > > + * new partition of its root parent table > > + * > > + * This works by first deleting the tuple from the input result relation > > + * followed by inserting it into the root parent table, that is, > > + * mtstate->rootResultRelInfo. > > + * > > + * Returns true if it's detected that the tuple we're trying to move has > > + * been concurrently updated. > > + */ > > +static bool > > +ExecMove(ModifyTableState *mtstate, ResultRelInfo *resultRelInfo, > > + ItemPointer tupleid, HeapTuple oldtuple, TupleTableSlot *planSlot, > > + EPQState *epqstate, bool canSetTag, TupleTableSlot **slot, > > + TupleTableSlot **inserted_tuple) > > +{ > > I know that it was one of the names I proposed, but now that I'm > thinking about it again, it sounds too generic. Perhaps > ExecCrossPartitionUpdate() wouldn't be a quite so generic name? Since > there's only one reference the longer name wouldn't be painful. That name sounds good. Isn't the return convention backwards? Sounds like "true" should mean that it succeeded. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services