pingcap/tidb

TiDB's warning logs for "Data Truncated" Error are not friendly.

Open

#5,777 建立於 2018年2月2日

在 GitHub 查看
 (5 留言) (0 反應) (0 負責人)Go (40,090 star) (6,186 fork)batch import
component/expressiongood first issuehelp wantedseverity/minortype/bug

描述

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?

I encountered the same error as https://github.com/pingcap/tidb/issues/5532, but my concern is that the server side warning logs for "Data Truncated" error are not friendly, which caused a lot of trouble in locating the root reason.

mysql> desc test;
+-------+-------------+------+------+---------+-------+
| Field | Type        | Null | Key  | Default | Extra |
+-------+-------------+------+------+---------+-------+
| id    | int(11)     | NO   |      | NULL    |       |
| total | decimal(20) | NO   |      | NULL    |       |
+-------+-------------+------+------+---------+-------+
2 rows in set (0.01 sec)

Java Code snippet:

String DB_URL = "jdbc:mysql://172.20.51.61:4000/test";
Properties info = new Properties();
info.setProperty("user", "root");
info.setProperty("password", "");
info.setProperty("useServerPrepStmts", "true");

Connection conn = DriverManager.getConnection(DB_URL, info);

String sql = "update test set total = total + ? where id = ?";
PreparedStatement preparedStatement = conn.prepareStatement(sql);
preparedStatement.setDouble(1, 1.16);
preparedStatement.setInt(2, 1);
preparedStatement.executeUpdate();

Note: set useServerPrepStmts=true , using Server Prepared Statements

MySQL Connector/J version:

<dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
     <version>6.0.6</version>
</dependency>
  1. What did you expect to see?

I expected TiDB's server side warning logs to point out the SQL statement which caused the error.

  1. What did you see instead?
2018/02/02 10:47:55.454 conn.go:472: [warning] [33] dispatch error:
id:33, addr:172.20.225.11:64749 status:2, collation:utf8_general_ci, user:root
"\x01\x00\x00\x00\x00\x01\x00\x00\x00\x00\x01\x05\x00\x03\x00\x8f\xc2\xf5(\\\x8f\xf2?\x01\x00\x00\x00"
[types:1265]Data Truncated
/home/jenkins/workspace/build_tidb_master/go/src/github.com/pingcap/tidb/types/datum.go:1105: 
/home/jenkins/workspace/build_tidb_master/go/src/github.com/pingcap/tidb/expression/builtin_cast.go:672: 
/home/jenkins/workspace/build_tidb_master/go/src/github.com/pingcap/tidb/expression/scalar_function.go:212: 
/home/jenkins/workspace/build_tidb_master/go/src/github.com/pingcap/tidb/executor/write.go:1883: 
/home/jenkins/workspace/build_tidb_master/go/src/github.com/pingcap/tidb/executor/write.go:1869: 
/home/jenkins/workspace/build_tidb_master/go/src/github.com/pingcap/tidb/executor/write.go:1821: 
/home/jenkins/workspace/build_tidb_master/go/src/github.com/pingcap/tidb/executor/adapter.go:284: 
/home/jenkins/workspace/build_tidb_master/go/src/github.com/pingcap/tidb/tidb.go:199: 
/home/jenkins/workspace/build_tidb_master/go/src/github.com/pingcap/tidb/session.go:910: 
/home/jenkins/workspace/build_tidb_master/go/src/github.com/pingcap/tidb/server/driver_tidb.go:70: 
/home/jenkins/workspace/build_tidb_master/go/src/github.com/pingcap/tidb/server/conn_stmt.go:168: 
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
mysql> select tidb_version();
+-------------------------------------------------------------------------
| tidb_version()                
+-------------------------------------------------------------------------
| Release Version: v1.1.0-alpha.1-53-g1f1e5f5
Git Commit Hash: 1f1e5f53eb66acb9ef534d87f4e8daeae2552f73
Git Branch: master
UTC Build Time: 2018-02-01 03:33:14 |
+-------------------------------------------------------------------------
1 row in set (0.02 sec)

貢獻者指南

TiDB's warning logs for "Data Truncated" Error are not friendly. · pingcap/tidb#5777 | Good First Issue