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

*: fix panic for create view using prepare #10651

Merged
merged 5 commits into from Jun 4, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

*: fix panic for create view using prepare

  • Loading branch information...
lamxTyler committed May 30, 2019
commit 081feb537c2c65632676aae13dce62740501a0e2
@@ -1400,19 +1400,12 @@ func (d *ddl) CreateView(ctx sessionctx.Context, s *ast.CreateViewStmt) (err err

func buildViewInfoWithTableColumns(ctx sessionctx.Context, s *ast.CreateViewStmt) (*model.ViewInfo, []*table.Column) {
viewInfo := &model.ViewInfo{Definer: s.Definer, Algorithm: s.Algorithm,
Security: s.Security, SelectStmt: s.Select.Text(), CheckOption: s.CheckOption}

var schemaCols = s.Select.(*ast.SelectStmt).Fields.Fields
viewInfo.Cols = make([]model.CIStr, len(schemaCols))
for i, v := range schemaCols {
viewInfo.Cols[i] = v.AsName
}

var tableColumns = make([]*table.Column, len(schemaCols))
Security: s.Security, SelectStmt: s.Select.Text(), CheckOption: s.CheckOption, Cols: s.SelectSchema}
var tableColumns = make([]*table.Column, len(s.SelectSchema))
if s.Cols == nil {
for i, v := range schemaCols {
for i, v := range s.SelectSchema {
tableColumns[i] = table.ToColumn(&model.ColumnInfo{
Name: v.AsName,
Name: v,
ID: int64(i),
Offset: i,
State: model.StatePublic,
@@ -187,6 +187,9 @@ func (s *testSuite3) TestCreateView(c *C) {
tk.MustExec("create table if not exists t1 (a int ,b int)")
_, err = tk.Exec("create or replace view t1 as select * from t1")
c.Assert(err.Error(), Equals, ddl.ErrWrongObject.GenWithStackByArgs("test", "t1", "VIEW").Error())
// create view using prepare
tk.MustExec(`prepare stmt from "create view v10 (x) as select 1";`)
tk.MustExec("execute stmt")
}

func (s *testSuite3) TestCreateDropDatabase(c *C) {
2 go.mod
@@ -73,3 +73,5 @@ require (
sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67
)

replace github.com/pingcap/parser => github.com/lamxTyler/parser v0.0.0-20190530064012-d6487877ce9b
4 go.sum
@@ -111,6 +111,8 @@ github.com/kr/pty v1.0.0/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lamxTyler/parser v0.0.0-20190530064012-d6487877ce9b h1:eNIbPGvrrPY9ZTFDbkt//p+zQeeGOXWZ6r2AK137kGs=
github.com/lamxTyler/parser v0.0.0-20190530064012-d6487877ce9b/go.mod h1:6c1rwSy9dUuNebYdr1IMI4+/sT3/Q65MXP2UCg7/vJI=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
@@ -160,8 +162,6 @@ github.com/pingcap/kvproto v0.0.0-20190528074401-b942b3f4108f/go.mod h1:QMdbTAXC
github.com/pingcap/log v0.0.0-20190214045112-b37da76f67a7/go.mod h1:xsfkWVaFVV5B8e1K9seWfyJWFrIhbtUTAD8NV1Pq3+w=
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 h1:t2OQTpPJnrPDGlvA+3FwJptMTt6MEPdzK1Wt99oaefQ=
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw=
github.com/pingcap/parser v0.0.0-20190523113241-89ae120307cc h1:FLouvtxa2Xn82ggR43M0HQ/0aZV2rSZDn5qEmAl5HhI=
github.com/pingcap/parser v0.0.0-20190523113241-89ae120307cc/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/pd v0.0.0-20190424024702-bd1e2496a669 h1:ZoKjndm/Ig7Ru/wojrQkc/YLUttUdQXoH77gtuWCvL4=
github.com/pingcap/pd v0.0.0-20190424024702-bd1e2496a669/go.mod h1:MUCxRzOkYiWZtlyi4MhxjCIj9PgQQ/j+BLNGm7aUsnM=
github.com/pingcap/tidb-tools v2.1.3-0.20190321065848-1e8b48f5c168+incompatible h1:MkWCxgZpJBgY2f4HtwWMMFzSBb3+JPzeJgF3VrXE/bU=
@@ -1750,12 +1750,10 @@ func (b *PlanBuilder) buildDDL(node ast.DDLNode) (Plan, error) {
if v.Cols != nil && len(v.Cols) != schema.Len() {
return nil, ddl.ErrViewWrongList
}
// we use fieldList to store schema.Columns temporary
var fieldList = make([]*ast.SelectField, schema.Len())
v.SelectSchema = make([]model.CIStr, schema.Len())
for i, col := range schema.Columns {
fieldList[i] = &ast.SelectField{AsName: col.ColName}
v.SelectSchema[i] = col.ColName
}
v.Select.(*ast.SelectStmt).Fields.Fields = fieldList
if _, ok := plan.(LogicalPlan); ok {
if b.ctx.GetSessionVars().User != nil {
authErr = ErrTableaccessDenied.GenWithStackByArgs("CREATE VIEW", b.ctx.GetSessionVars().User.Hostname,
@@ -1764,7 +1762,7 @@ func (b *PlanBuilder) buildDDL(node ast.DDLNode) (Plan, error) {
b.visitInfo = appendVisitInfo(b.visitInfo, mysql.CreateViewPriv, v.ViewName.Schema.L,
v.ViewName.Name.L, "", authErr)
}
if v.Definer.CurrentUser {
if v.Definer.CurrentUser && b.ctx.GetSessionVars().User != nil {
v.Definer = b.ctx.GetSessionVars().User
}
if b.ctx.GetSessionVars().User != nil && v.Definer.String() != b.ctx.GetSessionVars().User.String() {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.