Re: partition routing layering in nodeModifyTable.c
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Etsuro Fujita <etsuro.fujita@gmail.com>
Cc: Amit Langote <amitlangote09@gmail.com>, Thomas Munro <thomas.munro@gmail.com>, David Rowley <david.rowley@2ndquadrant.com>, Robert Haas <robertmhaas@gmail.com>, Alvaro Herrera <alvherre@2ndquadrant.com>, Etsuro Fujita <fujita.etsuro@lab.ntt.co.jp>, PostgreSQL-development <pgsql-hackers@postgresql.org>, amitdkhan.pg@gmail.com
Date: 2019-08-02T21:01:52Z
Lists: pgsql-hackers
Hi, On 2019-08-01 18:38:09 +0900, Etsuro Fujita wrote: > On Thu, Aug 1, 2019 at 10:33 AM Amit Langote <amitlangote09@gmail.com> wrote: > > If it's the approach of adding a resultRelation Index field to > > ForeignScan node, I tried and had to give up, realizing that we don't > > maintain ResultRelInfos in an array that is indexable by RT indexes. > > It would've worked if es_result_relations had mirrored es_range_table, > > although that probably complicates how the individual ModifyTable > > nodes attach to that array. We know at plan time what the the resultRelation offset for a ModifyTable node is. We just need to transport that to the respective foreign scan node, and update it properly in setrefs? Then we can index es_result_relations without any additional mapping? Maybe I'm missing something? I think all we need to do is to have setrefs.c:set_plan_refs() iterate over ->fdwDirectModifyPlans or such, and set the respective node's result_relation_offset or whatever we're naming it to splan->resultRelIndex + offset from fdwDirectModifyPlans? > > In any case, given this discussion, further hacking on a global > > variable like es_result_relations may be a course we might not want > > to pursue. I don't think es_result_relations really is problem - it doesn't have to change while processing individual subplans / partitions / whatnot. If we needed a mapping between rtis and result indexes, I'd not see a problem. Doubtful it's needed though. There's a fundamental difference between EState->es_result_relations and EState->es_result_relation_info. The former stays static during the whole query once initialized, whereas es_result_relation_info changes depending on which relation we're processing. The latter is what makes the code more complicated, because we cannot ever return early etc. Similarly, ModifyTableState->mt_per_subplan_tupconv_maps is not a problem, it stays static, but e.g. mtstate->mt_transition_capture is a problem, because we have to change for each subplan / routing / partition movement. Greetings, Andres Freund
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