-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
planner: support building data source from View #8757
planner: support building data source from View #8757
Conversation
81179a1
to
49c1183
Compare
/rebuild |
Add a test case for changing column order of the underlying table. create table t(a int, b int);
create view v as select * from t;
alter table t drop column a;
alter table t add column a int after b;
select * from v; |
@XuHuaiyu PTAL |
planner/core/logical_plan_builder.go
Outdated
if col == nil { | ||
return nil, ErrViewInvalid.GenWithStackByArgs(dbName.L, tableInfo.Name.L) | ||
} | ||
col.ColName = tableInfo.Cols()[i].Name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line2018 and line2019 is useless.
planner/core/logical_plan_builder.go
Outdated
} | ||
projUponView := LogicalProjection{Exprs: expression.Column2Exprs(viewCols)}.Init(b.ctx) | ||
projUponView.SetChildren(selectLogicalPlan.(LogicalPlan)) | ||
projUponView.SetSchema(expression.NewSchema(viewCols...)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should build schema.Columns instead of using the selectLogicalPlan.Schema.Columns
&expression.Column{
UniqueID: b.ctx.GetSessionVars().AllocPlanColumnID(),
TblName: viewname,
OrigTblName: tableInfo.Cols[i].Name,
ColName: colName,
OrigColName: tableInfo.View.Cols[i].Name,
DBName: dbName,
RetType: expr.GetType(),
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not use the column in the child schema as the parent schema
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understand, PTAL again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add tests in planner package.
bf8d417
to
b60541c
Compare
0a7c265
to
c855ba4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
/rebuild |
planner/core/logical_plan_builder.go
Outdated
@@ -1994,6 +1998,46 @@ func (b *PlanBuilder) buildDataSource(tn *ast.TableName) (LogicalPlan, error) { | |||
return result, nil | |||
} | |||
|
|||
func (b *PlanBuilder) buildDataSourceFromView(dbName model.CIStr, tableInfo *model.TableInfo) (LogicalPlan, error) { | |||
var ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These variable declaration looks ugly. We can avoid this by using the :=
operator in golang.
/run-all-tests |
…wDi/tidb into view/implement_select_view
@zz-jason PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What problem does this PR solve?
Implement basic select view feature
What is changed and how it works?
ref proposal Proposal: Implement View Feature
Check List
Tests
This change is