Skip to content

Commit 5a5a47c

Browse files
committed
build proj
1 parent 996dbb7 commit 5a5a47c

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

executor/executor_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3448,6 +3448,6 @@ func (s *testSuite) TestSelectView(c *C) {
34483448
tk.MustQuery("select * from view1;").Check(testkit.Rows("1 2"))
34493449
tk.MustQuery("select * from view2;").Check(testkit.Rows("1 2"))
34503450
tk.MustQuery("select * from view3;").Check(testkit.Rows("1 2"))
3451-
defer tk.MustExec("drop table view_t;")
3452-
defer tk.MustExec("drop view view1,view2,view3;")
3451+
tk.MustExec("drop table view_t;")
3452+
tk.MustExec("drop view view1,view2,view3;")
34533453
}

planner/core/logical_plan_builder.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -2009,19 +2009,25 @@ func (b *PlanBuilder) buildDataSourceFromView(dbName model.CIStr, tableInfo *mod
20092009
if err != nil {
20102010
return nil, err
20112011
}
2012-
var viewCols []*expression.Column
2012+
var projExprs []*expression.Column
20132013
for i := range tableInfo.View.Cols {
20142014
col := selectLogicalPlan.Schema().FindColumnByName(tableInfo.View.Cols[i].L)
20152015
if col == nil {
2016-
return nil, ErrViewInvalid.GenWithStackByArgs(dbName.L, tableInfo.Name.L)
2017-
}
2018-
col.ColName = tableInfo.Cols()[i].Name
2019-
col.OrigColName = tableInfo.View.Cols[i]
2020-
viewCols = append(viewCols, col)
2016+
return nil, ErrViewInvalid.GenWithStackByArgs(dbName.O, tableInfo.Name.O)
2017+
}
2018+
projExprs = append(projExprs, &expression.Column{
2019+
UniqueID: b.ctx.GetSessionVars().AllocPlanColumnID(),
2020+
TblName: col.TblName,
2021+
OrigTblName: col.OrigTblName,
2022+
ColName: tableInfo.Cols()[i].Name,
2023+
OrigColName: tableInfo.View.Cols[i],
2024+
DBName: dbName,
2025+
RetType: col.GetType(),
2026+
})
20212027
}
2022-
projUponView := LogicalProjection{Exprs: expression.Column2Exprs(viewCols)}.Init(b.ctx)
2028+
projUponView := LogicalProjection{Exprs: expression.Column2Exprs(projExprs)}.Init(b.ctx)
20232029
projUponView.SetChildren(selectLogicalPlan.(LogicalPlan))
2024-
projUponView.SetSchema(expression.NewSchema(viewCols...))
2030+
projUponView.SetSchema(expression.NewSchema(projExprs...))
20252031
return projUponView, nil
20262032
}
20272033

0 commit comments

Comments
 (0)