I suggested that we should push the actual execution (not just queuing)
of non-deferred AFTER triggers into the new ModifyTable plan node.
The attached patch does that, and seems like a nice improvement since it
removes knowledge of trigger handling from a number of other places.
However the original objective was to allow EXPLAIN to associate trigger
runtimes with ModifyTable nodes, and I realized that this patch doesn't
accomplish that --- the trigger stats are still accumulated in the
executor-wide EState, not in the ModifyTable node. Right at the moment
we could cheat and have EXPLAIN print the trigger stats under
ModifyTable anyway, because there can be only one ModifyTable in any
plan tree. But that will fall down as soon as we try to let INSERT
RETURNING and friends execute within WITH clauses.
After poking around a bit I think it should be possible to keep the
trigger instrumentation data in the ModifyTable node instead of in
EState, and thereby allow EXPLAIN to know which node to blame the
trigger time on. This will require passing an extra parameter down
from nodeModifyTable into the trigger code, but none of those call paths
are very long. Still, it'll be a significantly more invasive patch by
the time it's done than what you see here.
So, before I go off and do that work: anybody have an objection to this
line of development? The main implication of changing to this approach
is that we'll be nailing down the assumption that each WITH (command
RETURNING) clause acts very much like a separate statement for
trigger purposes: it will fire BEFORE STATEMENT triggers at start,
and AFTER STATEMENT triggers at end, and actually execute all
non-deferred AFTER triggers, before we move on to executing the next
WITH clause or the main query.
regards, tom lane
pgsql-hackers by date
|Next:||From: Marko Tiikkaja||Date: 2009-10-29 00:21:09|
|Subject: Re: WIP: push AFTER-trigger execution into ModifyTable
|Previous:||From: Guillaume Lelarge||Date: 2009-10-28 22:35:45|
|Subject: Re: Show schema size with \dn+|