@@ -581,18 +581,15 @@ func (s *idxScope) visitSelf(n sql.Node) error {
581581 // default nodes can't see lateral join nodes, unless we're in lateral
582582 // join and lateral scopes are promoted to parent status
583583 for _ , e := range ne .Expressions () {
584- // OrderedAggregations are special as they append results to the outer scope row
584+ // OrderedAggregations are special as they append a new field to the outer scope row
585585 // We need to account for this extra column in the rows when assigning indexes
586586 // Example: gms/expression/function/aggregation/group_concat.go:groupConcatBuffer.Update()
587- if ordAgg , isOrdAgg := e .(sql.OrderedAggregation ); isOrdAgg {
588- selExprs := ordAgg .OutputExpressions ()
587+ if _ , isOrdAgg := e .(sql.OrderedAggregation ); isOrdAgg {
589588 selScope := & idxScope {}
590- for _ , expr := range selExprs {
591- selScope .columns = append (selScope .columns , expr .String ())
592- if gf , isGf := expr .(* expression.GetField ); isGf {
593- selScope .ids = append (selScope .ids , gf .Id ())
594- }
589+ if idExpr , isIdExpr := e .(sql.IdExpression ); isIdExpr {
590+ selScope .ids = append (selScope .ids , idExpr .Id ())
595591 }
592+ selScope .columns = append (selScope .columns , e .String ())
596593 scope = append (scope , selScope )
597594 }
598595 s .expressions = append (s .expressions , fixExprToScope (e , scope ... ))
@@ -620,7 +617,6 @@ func (s *idxScope) finalizeSelf(n sql.Node) (sql.Node, error) {
620617 }
621618
622619 s .ids = columnIdsForNode (n )
623-
624620 s .addSchema (n .Schema ())
625621 var err error
626622 if s .children != nil {
0 commit comments