Skip to content

Commit

Permalink
executor, plan: fix a bug occurred in `set @varname = (select a from …
Browse files Browse the repository at this point in the history
…t limit 1)` (pingcap#4326)

* fix infoschema not support unsigned

* change the comment of FieldType's InfoSchemaStr for specification

* fix issue pingcap#4302

* use mockPlan instend of process subquery directly

* add test case for issue pingcap#4302
  • Loading branch information
CodeRushing authored and hanfei1991 committed Aug 26, 2017
1 parent 6c44eb6 commit 45a9515
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ func (s *testSuite) TestSetVar(c *C) {
tk.MustExec(testSQL)
tk.MustQuery(`select @issue998b, @@global.autocommit;`).Check(testkit.Rows("6 1"))

// For issue 4302
testSQL = "use test;drop table if exists x;create table x(a int);insert into x value(1);"
tk.MustExec(testSQL)
testSQL = "SET @issue4302=(select a from x limit 1);"
tk.MustExec(testSQL)
tk.MustQuery(`select @issue4302;`).Check(testkit.Rows("1"))

// Set default
// {ScopeGlobal | ScopeSession, "low_priority_updates", "OFF"},
// For global var
Expand Down
4 changes: 3 additions & 1 deletion plan/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ func (b *planBuilder) buildSet(v *ast.SetStmt) Plan {
IsSystem: vars.IsSystem,
}
if _, ok := vars.Value.(*ast.DefaultExpr); !ok {
assign.Expr, _, b.err = b.rewrite(vars.Value, nil, nil, true)
mockTablePlan := TableDual{}.init(b.allocator, b.ctx)
mockTablePlan.SetSchema(expression.NewSchema())
assign.Expr, _, b.err = b.rewrite(vars.Value, mockTablePlan, nil, true)
if b.err != nil {
return nil
}
Expand Down

0 comments on commit 45a9515

Please sign in to comment.