Skip to content
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

Merged
merged 12 commits into from Dec 26, 2018

Conversation

@AndrewDi
Copy link
Contributor

AndrewDi commented Dec 19, 2018

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

  • Unit test

This change is Reviewable

@AndrewDi AndrewDi referenced this pull request Dec 20, 2018

Open

Tracking view feature implement #8520

15 of 19 tasks complete

@AndrewDi AndrewDi force-pushed the AndrewDi:view/implement_select_view branch from 81179a1 to 49c1183 Dec 20, 2018

@AndrewDi

This comment has been minimized.

Copy link
Contributor Author

AndrewDi commented Dec 20, 2018

/rebuild

Show resolved Hide resolved planner/core/logical_plan_builder.go Outdated
Show resolved Hide resolved planner/core/logical_plan_builder.go Outdated
Show resolved Hide resolved planner/core/logical_plan_builder.go Outdated
@XuHuaiyu

This comment has been minimized.

Copy link
Contributor

XuHuaiyu commented Dec 20, 2018

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;
@AndrewDi

This comment has been minimized.

Copy link
Contributor Author

AndrewDi commented Dec 20, 2018

@XuHuaiyu PTAL

if col == nil {
return nil, ErrViewInvalid.GenWithStackByArgs(dbName.L, tableInfo.Name.L)
}
col.ColName = tableInfo.Cols()[i].Name

This comment has been minimized.

Copy link
@XuHuaiyu

XuHuaiyu Dec 20, 2018

Contributor

line2018 and line2019 is useless.

Show resolved Hide resolved planner/core/logical_plan_builder.go Outdated
Show resolved Hide resolved 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...))

This comment has been minimized.

Copy link
@XuHuaiyu

XuHuaiyu Dec 20, 2018

Contributor

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(),
	}

This comment has been minimized.

Copy link
@XuHuaiyu

XuHuaiyu Dec 20, 2018

Contributor

We should not use the column in the child schema as the parent schema

This comment has been minimized.

Copy link
@AndrewDi

AndrewDi Dec 20, 2018

Author Contributor

Understand, PTAL again

Show resolved Hide resolved executor/executor_test.go Outdated
@winoros
Copy link
Member

winoros left a comment

Please also add tests in planner package.

Show resolved Hide resolved planner/core/logical_plan_builder.go Outdated

@AndrewDi AndrewDi force-pushed the AndrewDi:view/implement_select_view branch from bf8d417 to b60541c Dec 22, 2018

AndrewDi added some commits Dec 24, 2018

@AndrewDi AndrewDi force-pushed the AndrewDi:view/implement_select_view branch from 0a7c265 to c855ba4 Dec 24, 2018

@XuHuaiyu
Copy link
Contributor

XuHuaiyu left a comment

LGTM

AndrewDi added some commits Dec 24, 2018

@winoros
Copy link
Member

winoros left a comment

LGTM

@XuHuaiyu

This comment has been minimized.

Copy link
Contributor

XuHuaiyu commented Dec 25, 2018

/run-all-tests

@XuHuaiyu XuHuaiyu added this to Reviewer approved in Support View Dec 25, 2018

@XuHuaiyu

This comment has been minimized.

Copy link
Contributor

XuHuaiyu commented Dec 25, 2018

/rebuild

@@ -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 (

This comment has been minimized.

Copy link
@zz-jason

zz-jason Dec 25, 2018

Member

These variable declaration looks ugly. We can avoid this by using the := operator in golang.

Show resolved Hide resolved planner/core/logical_plan_builder.go Outdated
Show resolved Hide resolved planner/core/logical_plan_builder.go Outdated
@zz-jason

This comment has been minimized.

Copy link
Member

zz-jason commented Dec 25, 2018

/run-all-tests

Support View automation moved this from Reviewer approved to Needs review Dec 26, 2018

@AndrewDi

This comment has been minimized.

Copy link
Contributor Author

AndrewDi commented Dec 26, 2018

@zz-jason PTAL

Support View automation moved this from Needs review to Reviewer approved Dec 26, 2018

@zz-jason
Copy link
Member

zz-jason left a comment

LGTM

@zz-jason zz-jason changed the title planner,executor: basic support for SELECT_VIEW planner: support building data source from View Dec 26, 2018

@XuHuaiyu XuHuaiyu merged commit 123aba2 into pingcap:master Dec 26, 2018

4 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
idc-jenkins-ci-tidb/build Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details

Support View automation moved this from Reviewer approved to Done Dec 26, 2018

@AndrewDi AndrewDi deleted the AndrewDi:view/implement_select_view branch Dec 26, 2018

yu34po added a commit to yu34po/tidb that referenced this pull request Jan 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.