@@ -158,7 +158,15 @@ func applyTriggers(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope,
158158 db = n .Database ().Name ()
159159 }
160160 case * plan.Update :
161- affectedTables = append (affectedTables , getTableName (n ))
161+ if n .IsJoin {
162+ uj := n .Child .(* plan.UpdateJoin )
163+ updateTargets := uj .UpdateTargets
164+ for _ , updateTarget := range updateTargets {
165+ affectedTables = append (affectedTables , getTableName (updateTarget ))
166+ }
167+ } else {
168+ affectedTables = append (affectedTables , getTableName (n ))
169+ }
162170 triggerEvent = plan .UpdateTrigger
163171 if n .Database () != "" {
164172 db = n .Database ()
@@ -355,7 +363,15 @@ func applyTrigger(ctx *sql.Context, a *Analyzer, originalNode, n sql.Node, scope
355363 }
356364 }
357365
358- return transform .NodeWithCtx (n , nil , func (c transform.Context ) (sql.Node , transform.TreeIdentity , error ) {
366+ canApplyTriggerExecutor := func (c transform.Context ) bool {
367+ if _ , ok := c .Parent .(* plan.TriggerExecutor ); ok {
368+ if c .ChildNum == 1 {
369+ return false
370+ }
371+ }
372+ return true
373+ }
374+ return transform .NodeWithCtx (n , canApplyTriggerExecutor , func (c transform.Context ) (sql.Node , transform.TreeIdentity , error ) {
359375 // Don't double-apply trigger executors to the bodies of triggers. To avoid this, don't apply the trigger if the
360376 // parent is a trigger body.
361377 // TODO: this won't work for BEGIN END blocks, stored procedures, etc. For those, we need to examine all ancestors,
0 commit comments