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

unexpect data truncate error when prepare plan cache enabled #8644

Closed
lysu opened this issue Dec 11, 2018 · 4 comments
Closed

unexpect data truncate error when prepare plan cache enabled #8644

lysu opened this issue Dec 11, 2018 · 4 comments
Labels
type/bug The issue is confirmed as a bug.

Comments

@lysu
Copy link
Contributor

lysu commented Dec 11, 2018

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.

enable prepare plan cache

mysql> create table t(data mediumblob);
Query OK, 0 rows affected (0.01 sec)

mysql> prepare stmt1 from 'insert t (data) values (?)';
Query OK, 0 rows affected (0.00 sec)

mysql> set @a = 'a';
Query OK, 0 rows affected (0.00 sec)

mysql> execute stmt1 using @a;
Query OK, 1 row affected (0.01 sec)

mysql> set @b = 'aaaaaaaaaaaaaaaaaa';
Query OK, 0 rows affected (0.00 sec)

mysql> execute stmt1 using @b;

  1. What did you expect to see?
2 insert ok
  1. What did you see instead?
ERROR 1406 (22001): Data too long for column 'data' at row 1
mysql> 
github.com/pingcap/errors.AddStack
	/home/robi/Code/go/pkg/mod/github.com/pingcap/errors@v0.11.0/errors.go:174
github.com/pingcap/parser/terror.(*Error).GenWithStack
	/home/robi/Code/go/pkg/mod/github.com/cloud-pi/parser@v0.0.0-20181211095502-1e4340922693/terror/terror.go:224
github.com/pingcap/tidb/types.ProduceStrWithSpecifiedTp
	/home/robi/Code/go/src/github.com/pingcap/tidb/types/datum.go:839
github.com/pingcap/tidb/types.(*Datum).convertToString
	/home/robi/Code/go/src/github.com/pingcap/tidb/types/datum.go:807
github.com/pingcap/tidb/types.(*Datum).ConvertTo
	/home/robi/Code/go/src/github.com/pingcap/tidb/types/datum.go:686
github.com/pingcap/tidb/expression.(*Constant).Eval
	/home/robi/Code/go/src/github.com/pingcap/tidb/expression/constant.go:102
github.com/pingcap/tidb/executor.(*InsertValues).evalRow
	/home/robi/Code/go/src/github.com/pingcap/tidb/executor/insert_common.go:247
github.com/pingcap/tidb/executor.(*InsertValues).insertRows
	/home/robi/Code/go/src/github.com/pingcap/tidb/executor/insert_common.go:189
github.com/pingcap/tidb/executor.(*InsertExec).Next
	/home/robi/Code/go/src/github.com/pingcap/tidb/executor/insert.go:142
github.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelayExecutor
	/home/robi/Code/go/src/github.com/pingcap/tidb/executor/adapter.go:288


[types:1406]Data too long for column 'data' at row 1
github.com/pingcap/errors.AddStack
	/home/robi/Code/go/pkg/mod/github.com/pingcap/errors@v0.11.0/errors.go:174
github.com/pingcap/parser/terror.(*Error).GenWithStack
	/home/robi/Code/go/pkg/mod/github.com/cloud-pi/parser@v0.0.0-20181211095502-1e4340922693/terror/terror.go:224
github.com/pingcap/tidb/executor.resetErrDataTooLong
	/home/robi/Code/go/src/github.com/pingcap/tidb/executor/write.go:171
github.com/pingcap/tidb/executor.(*InsertValues).handleErr
	/home/robi/Code/go/src/github.com/pingcap/tidb/executor/insert_common.go:215
github.com/pingcap/tidb/executor.(*InsertValues).evalRow
	/home/robi/Code/go/src/github.com/pingcap/tidb/executor/insert_common.go:248
github.com/pingcap/tidb/executor.(*InsertValues).insertRows
	/home/robi/Code/go/src/github.com/pingcap/tidb/executor/insert_common.go:189
github.com/pingcap/tidb/executor.(*InsertExec).Next
	/home/robi/Code/go/src/github.com/pingcap/tidb/executor/insert.go:142
github.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelayExecutor
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
Release Version: None
Git Commit Hash: None
Git Branch: None
UTC Build Time: None
GoVersion: None
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false 
@lysu lysu added the type/bug The issue is confirmed as a bug. label Dec 11, 2018
@lysu
Copy link
Contributor Author

lysu commented Dec 11, 2018

The question is:

In first execution, we rewrite ParamMarkerExpr to Constant with DeferredExpr, using current data length, "a" ---> 1 as tp.Flen

tp.Flen = len(x)

then next execution,

val, err := dt.ConvertTo(sf.GetCtx().GetSessionVars().StmtCtx, c.RetType)
, will check last Flen=1 instead of real mediumtext len.

@lysu
Copy link
Contributor Author

lysu commented Dec 11, 2018

@dbjoa how do you think about this ? 😆

@dbjoa
Copy link
Contributor

dbjoa commented Dec 11, 2018

@lysu I'm going to handle the issue.

@shenli
Copy link
Member

shenli commented Dec 12, 2018

@dbjoa Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

3 participants