@@ -158,7 +158,15 @@ func applyTriggers(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope,
158
158
db = n .Database ().Name ()
159
159
}
160
160
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
+ }
162
170
triggerEvent = plan .UpdateTrigger
163
171
if n .Database () != "" {
164
172
db = n .Database ()
@@ -355,7 +363,15 @@ func applyTrigger(ctx *sql.Context, a *Analyzer, originalNode, n sql.Node, scope
355
363
}
356
364
}
357
365
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 ) {
359
375
// Don't double-apply trigger executors to the bodies of triggers. To avoid this, don't apply the trigger if the
360
376
// parent is a trigger body.
361
377
// TODO: this won't work for BEGIN END blocks, stored procedures, etc. For those, we need to examine all ancestors,
0 commit comments