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 1kT4iv-0004DQ-FQ for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Oct 2020 14:59:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kT4iu-0001Jl-95 for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Oct 2020 14:59:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kT4it-0001Jd-Ul for pgsql-hackers@lists.postgresql.org; Thu, 15 Oct 2020 14:59:20 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kT4ir-0004oH-Cy for pgsql-hackers@postgresql.org; Thu, 15 Oct 2020 14:59:19 +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 C8AC11B001F0; Thu, 15 Oct 2020 17:59:13 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1602773953; 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=S0vzBxk4nPyUiLogLtkN3qYCsAM3EBsN2g+nlK4wBXE=; b=tOxG6p04w8qK3bg/aJky2VzqmYbM/Xj6GJXBTPxG4qZjbjcGJ4oPBp9PsLfOBQWUX6qD9a iBA5fTcbscnyI6QqkrB3ZtHLuTNdRr/j0Rhfhm/VWSPIpqpo5IolhzFKEVem5ZGjsz6KEk Ue/CY0nkoKNBLhO+tOxVZvEhzKxzZbe6T/8aZOr4EWsWTwZ694y64SCzMDQlJCAxe02UBZ um/sE7vrU5C5kCJPqngwERxiQ0PQxHRTmSmvLbOj+QNzVHk2mxibDXlNuD9zwZH/tlnJ2t QVB6fEIRCcpwii/swkc0QhE92MJv1HR9m1UzlwvWwGgTYyzGyqGVAs0Kkd5IvA== 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> <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> <902a656d-e4f2-70bf-f30f-1796d65791fe@iki.fi> From: Heikki Linnakangas Message-ID: Date: Thu, 15 Oct 2020 17:59:13 +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=1602773953; 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=S0vzBxk4nPyUiLogLtkN3qYCsAM3EBsN2g+nlK4wBXE=; b=vJtnvxqt/YAbSYAi54N/nrgR6zr/o82Av871UunNtql4TFgQC6eglx4/ung/zw+ScCc4/t u/xOWZvD5XMzpVfyV0w6qW4/2YnzGLOU2fbriF8iRHbQV7pynU3hCrZdhasLi4s5kZPsB3 74luYX9Pwf+mQ4x7c4f1RHNshKOvzFrsZF49GP/+GsFTwpKYRDW1Varr3XSwj0Cfod4REL 0lA3jd6nOAuuG2OoKAH/Cl2GVVcuVEL6HH8SHdG9DYTVpp+jBZ+x5whPoh5z9e96+RQIC2 cK2HY2e1R2/26rmMnjOhtc+eXM4Jthl4baNubo1N59OH4ZsRU8yeBy/UaKbXpQ== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1602773953; a=rsa-sha256; cv=none; b=qBsw9Q9IwQuviJwlg1qu4gHy+UEqyp1uolEufxHkfva8T1UHLck1N6ZtxmtSFtHdwCyLR3 ydADKUN5xMJdPVwKBYNSih8Qb+5RMbbq/kpDQNeqbL3mFOhLeqtSZy+Q4R/xHEmyduHGEP xP6gUgGbi8QLCBcUAevhJlFc5a503p8WZuA1GugJlVn+yrEXbfLfgjLPupjA/YT7umdwKT 9aHZmH6i0b7jWcPvT4n/BJH7IxFxHOzd4FufbDoWLzlShEzX04kMEcznTK7AQqeHg0QENN U6G6BCfg+VlqtIWtL6RQAUgM3tfo0sRzv8CWI9wzztuf8AGBySIHyJelDUqNPg== 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 Wed, Oct 14, 2020 at 6:04 PM Heikki Linnakangas wrote: > I'll continue with the last couple of patches in this thread. I committed the move of the cross-partition logic to new ExecCrossPartitionUpdate() function, with just minor comment editing and pgindent. I left out the refactoring around the calls to AFTER ROW INSERT/DELETE triggers. I stared at the change for a while, and wasn't sure if I liked the patched or the unpatched new version better, so I left it alone. Looking at the last patch, "Revise child-to-root tuple conversion map management", that's certainly an improvement. However, I find it confusing that sometimes the mapping from child to root is in relinfo->ri_ChildToRootMap, and sometimes in relinfo->ri_PartitionInfo->pi_PartitionToRootMap. When is each of those filled in? If both are set, is it well defined which one is initialized first? In general, I'm pretty confused by the initialization of ri_PartitionInfo. Where is initialized, and when? In execnodes.h, the definition of ResultRelInfo says: > /* info for partition tuple routing (NULL if not set up yet) */ > struct PartitionRoutingInfo *ri_PartitionInfo; That implies that the field is initialized lazily. But in ExecFindPartition, we have this: > if (partidx == partdesc->boundinfo->default_index) > { > PartitionRoutingInfo *partrouteinfo = rri->ri_PartitionInfo; > > /* > * The tuple must match the partition's layout for the constraint > * expression to be evaluated successfully. If the partition is > * sub-partitioned, that would already be the case due to the code > * above, but for a leaf partition the tuple still matches the > * parent's layout. > * > * Note that we have a map to convert from root to current > * partition, but not from immediate parent to current partition. > * So if we have to convert, do it from the root slot; if not, use > * the root slot as-is. > */ > if (partrouteinfo) > { > TupleConversionMap *map = partrouteinfo->pi_RootToPartitionMap; > > if (map) > slot = execute_attr_map_slot(map->attrMap, rootslot, > partrouteinfo->pi_PartitionTupleSlot); > else > slot = rootslot; > } > > ExecPartitionCheck(rri, slot, estate, true); > } That check implies that it's not just lazily initialized, the code will work differently if ri_PartitionInfo is set or not. I think all this would be more clear if ri_PartitionInfo and ri_ChildToRootMap were both truly lazily initialized, the first time they're needed. And if we removed ri_PartitionInfo->pi_PartitionToRootMap, and always used ri_ChildToRootMap for it. Maybe remove PartitionRoutingInfo struct altogether, and just move its fields directly to ResultRelInfo. - Heikki