From a1c01cde78894fa9395b7bc6084a11385c29df79 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Fri, 13 Oct 2023 13:52:11 +0530 Subject: [PATCH] wip --- .../planbuilder/operators/query_planning.go | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/go/vt/vtgate/planbuilder/operators/query_planning.go b/go/vt/vtgate/planbuilder/operators/query_planning.go index c06a10098ca..dfa35cf7c49 100644 --- a/go/vt/vtgate/planbuilder/operators/query_planning.go +++ b/go/vt/vtgate/planbuilder/operators/query_planning.go @@ -22,6 +22,7 @@ import ( "math/rand" "time" "unsafe" + "vitess.io/vitess/go/test/dbg" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vtgate/planbuilder/operators/ops" @@ -427,21 +428,21 @@ func exposeColumnsThroughDerivedTable(ctx *plancontext.PlanningContext, p *Proje return } + // If we didn't find it, and we are dealing with a ColName, we have to add it to the derived table + colExpr, ok := this.(*sqlparser.ColName) + if !ok { + return + } + // First we check if this expression is already being returned for _, column := range cols { - if ctx.SemTable.EqualsExprWithDeps(column.Expr, this) { - col := sqlparser.NewColName(column.As.String()) + if ctx.SemTable.EqualsExprWithDeps(column.Expr, colExpr) { + col := sqlparser.NewColName(column.ColumnName()) cursor.Replace(col) return } } - // If we didn't find it, and we are dealing with a ColName, we have to add it to the derived table - colExpr, ok := this.(*sqlparser.ColName) - if !ok { - return - } - colAlias := fmt.Sprintf("%s_vt_%s_%s", p.DT.Alias, sqlparser.String(colExpr), RandString(2)) newCol := sqlparser.NewColName(colAlias) @@ -463,20 +464,21 @@ func exposeColumnsThroughDerivedTable(ctx *plancontext.PlanningContext, p *Proje return e, nil } - for i, pred := range src.JoinPredicates { - x, err := pred.Map(f) + //for i, pred := range src.JoinPredicates { + // x, err := pred.Map(f) + // if err != nil { + // return err + // } + // src.JoinPredicates[i] = x + //} + + for i, col := range src.JoinColumns { + var err error + src.JoinColumns[i], err = col.Map(f) if err != nil { return err } - src.JoinPredicates[i] = x } - - // for i, col := range src.JoinColumns { - // src.JoinColumns[i], err = col.Map(f) - // if err != nil { - // return err - // } - // } return nil }