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

execuor, plan: check b.err in buildUpdate after doOptimize #7204

Merged
merged 3 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,11 @@ func (s *testSuite) TestUpdate(c *C) {
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1265 Data Truncated"))
r = tk.MustQuery("select * from decimals")
r.Check(testkit.Rows("202"))

tk.MustExec("drop table t")
tk.MustExec("CREATE TABLE `t` ( `c1` year DEFAULT NULL, `c2` year DEFAULT NULL, `c3` date DEFAULT NULL, `c4` datetime DEFAULT NULL, KEY `idx` (`c1`,`c2`))")
_, err = tk.Exec("UPDATE t SET c2=16777215 WHERE c1>= -8388608 AND c1 < -9 ORDER BY c1 LIMIT 2")
c.Assert(err.Error(), Equals, "cannot convert datum from bigint to type year.")
}

// TestUpdateCastOnlyModifiedValues for issue #4514.
Expand Down
28 changes: 28 additions & 0 deletions plan/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (b *planBuilder) buildResultSetNode(node ast.ResultSetNode) LogicalPlan {
b.err = ErrUnsupportedType.GenByArgs(v)
}
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
if v, ok := p.(*DataSource); ok {
Expand Down Expand Up @@ -266,11 +267,13 @@ func (b *planBuilder) buildJoin(joinNode *ast.Join) LogicalPlan {

leftPlan := b.buildResultSetNode(joinNode.Left)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}

rightPlan := b.buildResultSetNode(joinNode.Right)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
joinPlan := LogicalJoin{StraightJoin: joinNode.StraightJoin || b.inStraightJoin}.init(b.ctx)
Expand Down Expand Up @@ -1622,16 +1625,19 @@ func (b *planBuilder) buildSelect(sel *ast.SelectStmt) LogicalPlan {
p = b.buildTableDual()
}
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
originalFields := sel.Fields.Fields
sel.Fields.Fields = b.unfoldWildStar(p, sel.Fields.Fields)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
if sel.GroupBy != nil {
p, gbyCols = b.resolveGbyExprs(p, sel.GroupBy, sel.Fields.Fields)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
Expand All @@ -1646,6 +1652,7 @@ func (b *planBuilder) buildSelect(sel *ast.SelectStmt) LogicalPlan {
if sel.Where != nil {
p = b.buildSelection(p, sel.Where, nil)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
Expand All @@ -1656,6 +1663,7 @@ func (b *planBuilder) buildSelect(sel *ast.SelectStmt) LogicalPlan {
if hasAgg {
aggFuncs, totalMap = b.extractAggFuncs(sel.Fields.Fields)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
var aggIndexMap map[int]int
Expand All @@ -1664,36 +1672,42 @@ func (b *planBuilder) buildSelect(sel *ast.SelectStmt) LogicalPlan {
totalMap[k] = aggIndexMap[v]
}
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
var oldLen int
p, oldLen = b.buildProjection(p, sel.Fields.Fields, totalMap)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
if sel.Having != nil {
b.curClause = havingClause
p = b.buildSelection(p, sel.Having.Expr, havingMap)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
if sel.Distinct {
p = b.buildDistinct(p, oldLen)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
if sel.OrderBy != nil {
p = b.buildSort(p, sel.OrderBy.Items, orderMap)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
if sel.Limit != nil {
p = b.buildLimit(p, sel.Limit)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
Expand Down Expand Up @@ -2024,6 +2038,7 @@ func (b *planBuilder) buildUpdate(update *ast.UpdateStmt) Plan {
sel := &ast.SelectStmt{Fields: &ast.FieldList{}, From: update.TableRefs, Where: update.Where, OrderBy: update.Order, Limit: update.Limit}
p := b.buildResultSetNode(sel.From.TableRefs)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}

Expand All @@ -2040,23 +2055,27 @@ func (b *planBuilder) buildUpdate(update *ast.UpdateStmt) Plan {
if sel.Where != nil {
p = b.buildSelection(p, sel.Where, nil)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
if sel.OrderBy != nil {
p = b.buildSort(p, sel.OrderBy.Items, nil)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
if sel.Limit != nil {
p = b.buildLimit(p, sel.Limit)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
orderedList, np := b.buildUpdateLists(tableList, update.List, p)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
p = np
Expand All @@ -2066,6 +2085,10 @@ func (b *planBuilder) buildUpdate(update *ast.UpdateStmt) Plan {
}.init(b.ctx)
updt.SetSchema(p.Schema())
updt.SelectPlan, b.err = doOptimize(b.optFlag, p)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
updt.ResolveIndices()
return updt
}
Expand Down Expand Up @@ -2197,24 +2220,28 @@ func (b *planBuilder) buildDelete(delete *ast.DeleteStmt) Plan {
}
p := b.buildResultSetNode(sel.From.TableRefs)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}

if sel.Where != nil {
p = b.buildSelection(p, sel.Where, nil)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
if sel.OrderBy != nil {
p = b.buildSort(p, sel.OrderBy.Items, nil)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
if sel.Limit != nil {
p = b.buildLimit(p, sel.Limit)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
}
Expand All @@ -2230,6 +2257,7 @@ func (b *planBuilder) buildDelete(delete *ast.DeleteStmt) Plan {
}.init(b.ctx)
del.SelectPlan, b.err = doOptimize(b.optFlag, p)
if b.err != nil {
b.err = errors.Trace(b.err)
return nil
}
del.SetSchema(expression.NewSchema())
Expand Down