Re: partition routing layering in nodeModifyTable.c
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Amit Langote <amitlangote09@gmail.com>
Cc: Daniel Gustafsson <daniel@yesql.se>,
Etsuro Fujita <etsuro.fujita@gmail.com>, Andres Freund <andres@anarazel.de>,
PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2020-10-12T16:57:38Z
Lists: pgsql-hackers
Attachments
On 12/10/2020 16:47, Amit Langote wrote: > On Mon, Oct 12, 2020 at 8:12 PM Heikki Linnakangas <hlinnaka@iki.fi> wrote: >> 1. We have many different cleanup/close routines now: >> ExecCloseResultRelations, ExecCloseRangeTableRelations, and >> ExecCleanUpTriggerState. Do we need them all? It seems to me that we >> could merge ExecCloseRangeTableRelations() and >> ExecCleanUpTriggerState(), they seem to do roughly the same thing: close >> relations that were opened for ResultRelInfos. They are always called >> together, except in afterTriggerInvokeEvents(). And in >> afterTriggerInvokeEvents() too, there would be no harm in doing both, >> even though we know there aren't any entries in the es_result_relations >> array at that point. > > Hmm, I find trigger result relations to behave differently enough to > deserve a separate function. For example, unlike plan-specified > result relations, they don't point to range table relations and don't > open indices. Maybe the name could be revisited, say, > ExecCloseTriggerResultRelations(). Matter of perception I guess. I still prefer to club them together into one Close call. It's true that they're slightly different, but they're also pretty similar. And IMHO they're more similar than different. > Also, maybe call the other functions: > > ExecInitPlanResultRelationsArray() > ExecInitPlanResultRelation() > ExecClosePlanResultRelations() > > Thoughts? Hmm. How about initializing the array lazily, on the first ExecInitPlanResultRelation() call? It's not performance critical, and that way there's one fewer initialization function that you need to remember to call. 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. > 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. - Heikki
Commits
-
Fix initialization of es_result_relations in EvalPlanQualStart().
- 22b73d3cb0b5 14.0 landed
-
Remove PartitionRoutingInfo struct.
- fb5883da8615 14.0 landed
-
Revise child-to-root tuple conversion map management.
- 6973533650c0 14.0 landed
-
Clean up code to resolve the "root target relation" in nodeModifyTable.c
- f49b85d783f6 14.0 landed
-
Refactor code for cross-partition updates to a separate function.
- c5b097f8fa69 14.0 landed
-
Remove es_result_relation_info from EState.
- a04daa97a433 14.0 landed
-
Include result relation info in direct modify ForeignScan nodes.
- 178f2d560dde 14.0 landed
-
Create ResultRelInfos later in InitPlan, index them by RT index.
- 1375422c7826 14.0 landed