@@ -32,7 +32,7 @@ func assignExecIndexes(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Sc
3232 if ! scope .IsEmpty () {
3333 // triggers
3434 s .triggerScope = true
35- s .insertSourceScope = scope .InInsertSource
35+ s .insertSourceScope = scope .InInsertSource ()
3636 s .addSchema (scope .Schema ())
3737 s = s .push ()
3838 }
@@ -300,9 +300,6 @@ func (s *idxScope) copy() *idxScope {
300300 parentScopes : parentCopy ,
301301 columns : varsCopy ,
302302 ids : idsCopy ,
303-
304- triggerScope : s .triggerScope ,
305- insertSourceScope : s .insertSourceScope ,
306303 }
307304}
308305
@@ -369,42 +366,10 @@ func (s *idxScope) visitChildren(n sql.Node) error {
369366 // keep only the first union scope to avoid double counting
370367 s .childScopes = append (s .childScopes , keepScope )
371368 case * plan.InsertInto :
372- // TODO: special case into sources when in triggers with groupby/window functions
373- var newSrc sql.Node
374- var err error
375-
376- // TODO: do something cleaner
377- //var isInTrigger bool
378- //for _, ps := range s.parentScopes {
379- // if ps.triggerScope {
380- // isInTrigger = true
381- // break
382- // }
383- //}
384- //if isInTrigger {
385- // if proj, isProj := n.Source.(*plan.Project); isProj {
386- // switch proj.Child.(type) {
387- // case *plan.GroupBy, *plan.Window:
388- // subScope := s.copy()
389- // subScope.parentScopes = subScope.parentScopes[:0]
390- // newSrc, _, err = assignIndexesHelper(proj, subScope)
391- // default:
392- // newSrc, _, err = assignIndexesHelper(n.Source, s)
393- // }
394- // } else {
395- // newSrc, _, err = assignIndexesHelper(n.Source, s)
396- // }
397- //} else {
398- // newSrc, _, err = assignIndexesHelper(n.Source, s)
399- //}
400-
401- s .insertSourceScope = true
402- newSrc , _ , err = assignIndexesHelper (n .Source , s )
369+ newSrc , _ , err := assignIndexesHelper (n .Source , s )
403370 if err != nil {
404371 return err
405372 }
406- s .insertSourceScope = false
407-
408373 newDst , dScope , err := assignIndexesHelper (n .Destination , s )
409374 if err != nil {
410375 return err
@@ -426,9 +391,6 @@ func (s *idxScope) visitChildren(n sql.Node) error {
426391 }
427392 default :
428393 for _ , c := range n .Children () {
429- if _ , ok := c .(* plan.GroupBy ); ok {
430- print ()
431- }
432394 newC , cScope , err := assignIndexesHelper (c , s )
433395 if err != nil {
434396 return err
@@ -600,7 +562,9 @@ func (s *idxScope) visitSelf(n sql.Node) error {
600562 n .DestSch [colIdx ].Default = newDef .(* sql.ColumnDefaultValue )
601563 }
602564 default :
603- // TODO: this very specific pattern
565+ // Group By and Window functions already account for the new/old columns present from triggers
566+ // This means that when indexing the Projections, we should not include the trigger scope(s), which are
567+ // within s.parentScopes.
604568 if proj , isProj := n .(* plan.Project ); isProj {
605569 switch proj .Child .(type ) {
606570 case * plan.GroupBy , * plan.Window :
@@ -771,9 +735,6 @@ func fixExprToScope(e sql.Expression, scopes ...*idxScope) sql.Expression {
771735 // don't have the destination schema, and column references in default values are determined in the build phase)
772736
773737 idx , _ := newScope .getIdxId (e .Id (), e .String ())
774- if e .String () == "modeldisambig.id_modelinfo" && e .Index () == 1 {
775- print ()
776- }
777738 if idx >= 0 {
778739 return e .WithIndex (idx ), transform .NewTree , nil
779740 }
0 commit comments