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

executor: fix update float panic (#8045) #8170

Merged
merged 4 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 24 additions & 4 deletions executor/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ func (e *UpdateExec) Next(ctx context.Context, chk *chunk.Chunk) error {

func (e *UpdateExec) fetchChunkRows(ctx context.Context) error {
fields := e.children[0].retTypes()
schema := e.children[0].Schema()
colsInfo := make([]*table.Column, len(fields))
for id, cols := range schema.TblID2Handle {
tbl := e.tblID2table[id]
for _, col := range cols {
offset := getTableOffset(schema, col)
for i, c := range tbl.WritableCols() {
colsInfo[offset+i] = c
}
}
}
globalRowIdx := 0
chk := e.children[0].newFirstChunk()
e.evalBuffer = chunk.MutRowFromTypes(fields)
Expand All @@ -156,7 +167,7 @@ func (e *UpdateExec) fetchChunkRows(ctx context.Context) error {
for rowIdx := 0; rowIdx < chk.NumRows(); rowIdx++ {
chunkRow := chk.GetRow(rowIdx)
datumRow := chunkRow.GetDatumRow(fields)
newRow, err1 := e.composeNewRow(globalRowIdx, datumRow)
newRow, err1 := e.composeNewRow(globalRowIdx, datumRow, colsInfo)
if err1 != nil {
return errors.Trace(err1)
}
Expand All @@ -181,7 +192,7 @@ func (e *UpdateExec) handleErr(colName model.CIStr, rowIdx int, err error) error
return errors.Trace(err)
}

func (e *UpdateExec) composeNewRow(rowIdx int, oldRow []types.Datum) ([]types.Datum, error) {
func (e *UpdateExec) composeNewRow(rowIdx int, oldRow []types.Datum, cols []*table.Column) ([]types.Datum, error) {
newRowData := types.CopyRow(oldRow)
e.evalBuffer.SetDatums(newRowData...)
for _, assign := range e.OrderedList {
Expand All @@ -190,10 +201,19 @@ func (e *UpdateExec) composeNewRow(rowIdx int, oldRow []types.Datum) ([]types.Da
continue
}
val, err := assign.Expr.Eval(e.evalBuffer.ToRow())
if err = e.handleErr(assign.Col.ColName, rowIdx, err); err != nil {
return nil, err
}

if err1 := e.handleErr(assign.Col.ColName, rowIdx, err); err1 != nil {
return nil, err1
// info of `_tidb_rowid` column is nil.
// No need to cast `_tidb_rowid` column value.
if cols[assign.Col.Index] != nil {
val, err = table.CastValue(e.ctx, val, cols[assign.Col.Index].ColumnInfo)
if err = e.handleErr(assign.Col.ColName, rowIdx, err); err != nil {
return nil, errors.Trace(err)
}
}

newRowData[assign.Col.Index] = *val.Copy()
e.evalBuffer.SetDatum(assign.Col.Index, val)
}
Expand Down
6 changes: 6 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,12 @@ func (s *testSuite) TestUpdate(c *C) {
_, err = tk.Exec("update t, (select * from t) as b set b.k = t.k")
c.Assert(err.Error(), Equals, "[planner:1288]The target table b of the UPDATE is not updatable")
tk.MustExec("update t, (select * from t) as b set t.k = b.k")

// issue 8045
tk.MustExec("drop table if exists t1")
tk.MustExec(`CREATE TABLE t1 (c1 float)`)
tk.MustExec("INSERT INTO t1 SET c1 = 1")
tk.MustExec("UPDATE t1 SET c1 = 1.2 WHERE c1=1;")
}

func (s *testSuite) TestPartitionedTableUpdate(c *C) {
Expand Down