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 1kSHIr-0000IP-HE for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Oct 2020 10:13:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSHIq-0003Kc-El for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Oct 2020 10:13:08 +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 1kSHIq-0003I6-3c for pgsql-hackers@lists.postgresql.org; Tue, 13 Oct 2020 10:13:08 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSHIn-0001t9-Bq for pgsql-hackers@postgresql.org; Tue, 13 Oct 2020 10:13:07 +0000 Received: from [192.168.1.113] (dsl-hkibng22-54faa4-119.dhcp.inet.fi [84.250.164.119]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id C87621B002EC; Tue, 13 Oct 2020 13:12:59 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1602583979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GpYfHec8ubH2MMj2jVOPiuq6qVqmK+UjGT32BKg/Hes=; b=XbKy9Hw5VgrXNFmhkBsGKTkkfzOwBz+bPvqGlzr3zgqjSIc0L4uMQPEXNnoceYXxnMHZ5D 3KaxFbstILdUWO5j84//UbnPK8qOCOukZQ3onnLzMRLeFL8NUKqkLsZr+McXs5FDiUxW17 x+RQS2h2x6NR+Gl4S5aqNVRBrPMWWcUOmvnyf1H3NoVpZpHypSCSJB4JIE0vqqLhC2Nxex 2rBKD/XdzmTy2U0dNuuTQK0ZNh2dvlDcmZw90Utdzd/iYU5K+i0oy5Ny+MFitNGHUB2C31 n9rX8B+BghhUZO7DQkYwyy7hG4VLsqqnz3sWGMTWSMraR3oeQuQI0xjVlfT5Aw== Subject: Re: partition routing layering in nodeModifyTable.c To: Amit Langote Cc: Daniel Gustafsson , Etsuro Fujita , Andres Freund , PostgreSQL-development References: <20190718010911.l6xcdv6birtxiei4@alap3.anarazel.de> <30269.1583091776@sss.pgh.pa.us> <424F4298-7826-40DC-B12B-37EFE60EE243@yesql.se> <73fe6ce6-d2a1-bd4b-17cf-9deba4e91467@iki.fi> <19c23dd9-89ce-75a3-9105-5fc05a46f94a@iki.fi> <9bfb949e-21b6-e0f7-c9c9-58710d11e7b1@iki.fi> <3603af69-eb52-4891-5d50-669cb03090a6@iki.fi> From: Heikki Linnakangas Message-ID: Date: Tue, 13 Oct 2020 13:12:59 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1602583979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GpYfHec8ubH2MMj2jVOPiuq6qVqmK+UjGT32BKg/Hes=; b=aBPVJtKyOE756IpQP4EaNFCkK+uU+1DLLDf5eo2qDNQj9U0hAI5NgrPXEQA7mzT43Lqveh MI+8mR/80nHhiAhIMPvpRb4Wp0l4edNhmrpl+pI1Yva6ONYJfx4Nk8dYE15hD8ngqW/KDK LZq7Bbrjdi1uX3g0OkJObuZLYJ/9Uf0neGjKK3Yg3BozY3DdZTMhIj76OuycFaNjutrMYI VTh4ZaP0OO1Mxa0ZLyA6ljHciwun6xGSdm7SEemmf1ay3d2jAVrXVLDy4bOp5DdF3Ww9+S bnx1bc3nz5M2y0rSsndHCr607txmKCeLKD3jzOR2Z/nBqlrMdfUgJvenHK7sGw== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1602583979; a=rsa-sha256; cv=none; b=V4Drgc+JXB6vPzt2dSq2uOcYdheBQSCLsQlfO/+gWpseQzgvYIDfqeUv8wmUiAnI3Ph5vw W60CbSR2vde4eTKBzEkg7R4zdTP7OeVNFGsmUd7IWOs9yXUCMKCk+ttRLmEUApfDrE56oN sWu4CJ/Dy6h1zAg9+LcmVPNtJkH7I+5vwiFry62GPywHdQpKv0TVEJ6iArJL6r5tDblq4O jBUJYSR4wF8tX8Qi3uHI8RkjXJ3bRDgcevOTqGu2BEwQzRq4HBA5CTjA6iDpEOomxFkVc4 F4SzsklXMc6KhGLX8lqfWgVIJPwqt4h0mjxv52vS4uyWBal5HHdG8h5sJrfk6A== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 13/10/2020 07:32, Amit Langote wrote: > On Tue, Oct 13, 2020 at 1:57 AM Heikki Linnakangas wrote: >> It occurred to me that if we do that (initialize the array lazily), >> there's very little need for the PlannedStmt->resultRelations list >> anymore. It's only used in ExecRelationIsTargetRelation(), but if we >> assume that ExecRelationIsTargetRelation() is only called after InitPlan >> has initialized the result relation for the relation, it can easily >> check es_result_relations instead. I think that's a safe assumption. >> ExecRelationIsTargetRelation() is only used in FDWs, and I believe the >> FDWs initialization routine can only be called after ExecInitModifyTable >> has been called on the relation. >> >> The PlannedStmt->rootResultRelations field is even more useless. > > I am very much tempted to remove those fields from PlannedStmt, > although I am concerned that the following now assumes that *all* > result relations are initialized in the executor initialization phase: > > bool > ExecRelationIsTargetRelation(EState *estate, Index scanrelid) > { > if (!estate->es_result_relations) > return false; > > return estate->es_result_relations[scanrelid - 1] != NULL; > } > > In the other thread [1], I am proposing that we initialize result > relations lazily, but the above will be a blocker to that. Ok, I'll leave it alone then. But I'll still merge resultRelations and rootResultRelations into one list. I don't see any point in keeping them separate. I'm tempted to remove ExecRelationIsTargetRelation() altogether, but keeping the resultRelations list isn't really a big deal, so I'll leave that for another discussion. >>> Actually, maybe we don't need to be so paranoid about setting up >>> es_result_relations in worker.c, because none of the downstream >>> functionality invoked seems to rely on it, that is, no need to call >>> ExecInitResultRelationsArray() and ExecInitResultRelation(). >>> ExecSimpleRelation* and downstream functionality assume a >>> single-relation operation and the ResultRelInfo is explicitly passed. >> >> Hmm, yeah, I like that. Similarly in ExecuteTruncateGuts(), there isn't >> actually any need to put the ResultRelInfos in the es_result_relations >> array. >> >> Putting all this together, I ended up with the attached. It doesn't >> include the subsequent commits in this patch set yet, for removal of >> es_result_relation_info et al. > > Thanks. > > + * We put the ResultRelInfos in the es_opened_result_relations list, even > + * though we don't have a range table and don't populate the > + * es_result_relations array. That's a big bogus, but it's enough to make > + * ExecGetTriggerResultRel() find them. > */ > estate = CreateExecutorState(); > resultRelInfos = (ResultRelInfo *) > palloc(list_length(rels) * sizeof(ResultRelInfo)); > resultRelInfo = resultRelInfos; > + estate->es_result_relations = (ResultRelInfo **) > + palloc(list_length(rels) * sizeof(ResultRelInfo *)); > > Maybe don't allocate es_result_relations here? Fixed. > Anyway, other than my concern about ExecRelationIsTargetRelation() > mentioned above, I think the patch looks good. Ok, committed. I'll continue to look at the rest of the patches in this patch series now. - Heikki