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

refine data truncate error msg #7401

Merged
merged 6 commits into from
Aug 15, 2018
Merged

Conversation

crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented Aug 15, 2018

What problem does this PR solve?

fix #7390
In TiDB now:

mysql root@127.0.0.1:test> create table t(a bigint);
Query OK, 0 rows affected
Time: 0.008s
mysql root@127.0.0.1:test> insert into t values("asfasdfsajhlkhlksdaf");
(1366, "Incorrect bigint value: 'asfasdfsajhlkhlksdaf' for column 'a' at row 1")
mysql root@127.0.0.1:test> insert into t values("12asdf");
(1366, "Incorrect bigint value: '12asdf' for column 'a' at row 1")

In Mysql

mysql root@127.0.0.1:test> create table t (a bigint)
Query OK, 0 rows affected
Time: 0.018s
mysql root@127.0.0.1:test> insert into t values("asfasdfsajhlkhlksdaf");
(1366, "Incorrect integer value: 'asfasdfsajhlkhlksdaf' for column 'a' at row 1")
mysql root@127.0.0.1:test> insert into t values("12asdf");
(1265, "Data truncated for column 'a' at row 1")

As you can see, The return error of insert into t values("12asdf"); in TiDB is still different from MySQL.

What is changed and how it works?

Check List

Tests

@winkyao
Copy link
Contributor

winkyao commented Aug 15, 2018

@crazycs520 Please read the https://github.com/pingcap/tidb/blob/master/CONTRIBUTING.md, and the proper commit message is :

<subsystem>: <what changed>
<BLANK LINE>
<why this change was made>
<BLANK LINE>
<footer>(optional)

Please follow this style.

Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reset LGTM

@@ -77,6 +77,8 @@ var (
ErrInvalidRecordKey = terror.ClassTable.New(codeInvalidRecordKey, "invalid record key")
// ErrTruncateWrongValue returns for truncate wrong value for field.
ErrTruncateWrongValue = terror.ClassTable.New(codeTruncateWrongValue, "incorrect value")
// ErrTruncatedWrongValueForField returns for truncate wrong value for field.
ErrTruncatedWrongValueForField = terror.ClassTable.New(codeTruncateWrongValue, mysql.MySQLErrName[mysql.ErrTruncatedWrongValueForField])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add code map in line 213, in tableMySQLErrCodes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codeTruncateWrongValue already in code map.

_, err = tk.Exec("insert into t values ('abc')")
c.Assert(terror.ErrorEqual(err, types.ErrTruncated), IsTrue)
c.Assert(terror.ErrorEqual(err, table.ErrTruncatedWrongValueForField), IsTrue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure the error code is 1366

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error code of table.ErrTruncatedWrongValueForField is 1366.

@crazycs520 crazycs520 added the type/enhancement The issue or PR belongs to an enhancement. label Aug 15, 2018
Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -198,11 +201,12 @@ func (e *InsertValues) getRow(cols []*table.Column, list []expression.Expression

for i, expr := range list {
val, err := expr.Eval(chunk.MutRowFromDatums(row).ToRow())
if err = e.handleErr(cols[i], rowIdx, err); err != nil {
valStr, _ := val.ToString()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move the ToString() operation into the handErr() function? We could use a lazy way to call the ToString function. Or you will call ToString for all the data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@crazycs520
Copy link
Contributor Author

crazycs520 commented Aug 15, 2018

@shenli here is a benchmark about datum and *datum:

func foo1 (d Datum){
        _ = d.Kind()
}

func foo2 (d *Datum){
        _ = d.Kind()
}

func AllDatumSlice() []Datum {
        ds := make([]Datum,0,8)
        ds = append(ds,NewIntDatum(1))
        ds = append(ds,NewUintDatum(1))
        ds = append(ds,NewFloat64Datum(28.0))
        ds = append(ds,NewDecimalDatum(NewDecFromStringForTest("72.5")))
        ds = append(ds,NewMysqlBitDatum([]byte{1,2,3,4,5,6,7,8,9}))
        ds = append(ds,NewTimeDatum(Time{Time: FromGoTime(time.Now()), Fsp: 6, Type: mysql.TypeTimestamp}))
        ds = append(ds,NewStringDatum("abcdefghijklmnopqrstuvwxyz"))
        ds = append(ds,NewBytesDatum([]byte("abcdefghijklmnopqrstuvwxyz")))
        return ds
}

func BenchmarkDatum(b *testing.B){
        ds := AllDatumSlice()
        for i:=0;i<b.N;i++ {
                foo1(ds[i%len(ds)])
        }
}

func BenchmarkDatumPoint(b *testing.B){
        ds := AllDatumSlice()
        for i:=0;i<b.N;i++ {
                foo2(&ds[i%len(ds)])
        }
}

result is:

~/code/goread/src/test2 ᐅ go version
go version go1.10.3 darwin/amd64
~/code/goread/src/test2 ᐅ go test -bench=. -v test_test.go
goarch: amd64
pkg: github.com/pingcap/tidb/types
BenchmarkDatum-8                100000000               10.6 ns/op
BenchmarkDatumPoint-8           200000000                7.91 ns/op
PASS
ok      github.com/pingcap/tidb/types   3.495s

Copy link
Member

@shenli shenli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Good job!

@shenli shenli added the status/LGT2 Indicates that a PR has LGTM 2. label Aug 15, 2018
@crazycs520
Copy link
Contributor Author

@zz-jason PTAL

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crazycs520 crazycs520 merged commit 1f87107 into pingcap:master Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

provide more info in error "Data Truncated"
4 participants