Michael Paquier <mich...@paquier.xyz> writes: > On Tue, May 18, 2021 at 07:42:08PM -0400, Tom Lane wrote: >> This might go away if worker.c weren't so creatively different >> from the other code paths concerned with executor shutdown.
> The tuple routing has made the whole worker logic messier by a larger > degree compared to when this stuff was only able to apply DMLs changes > on the partition leaves. I know that it is not that great to be more > creative here, but we need to make sure that AfterTriggerEndQuery() is > moved before ExecCleanupTupleRouting(). We could either keep the > ExecCleanupTupleRouting() calls as they are now, and call > AfterTriggerEndQuery() in more code paths. Or we could have one > PartitionTupleRouting and one ModifyTableState created beforehand > in create_estate_for_relation() if applying the change on a > partitioned table but that means manipulating more structures across > more layers of this code. Something like the attached fixes the > problem for me, but honestly it does not help in clarifying this code > more. I was wondering if we could move the ExecCleanupTupleRouting call into finish_estate. copyfrom.c, for example, does that during its shutdown function. Compare also the worker.c changes proposed in https://www.postgresql.org/message-id/3362608.1621367104%40sss.pgh.pa.us which are because I discovered it's unsafe to pop the snapshot before running AfterTriggerEndQuery. regards, tom lane