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

Where clauses wtih string constant comparisons to integers on left hand side return wrong results #52

Open
greenlion opened this issue Aug 14, 2020 · 0 comments
Labels
BETA3 Target for beta #3 bug Something isn't working

Comments

@greenlion
Copy link
Owner

mysql> show create table t1\G
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `c1` int DEFAULT NULL,
  `c2` int DEFAULT NULL
) ENGINE=WARP DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
1 row in set (0.01 sec)

mysql> select c1, count(*) From t1 group by c1;
+------+----------+
| c1   | count(*) |
+------+----------+
|    1 |   524288 |
+------+----------+
1 row in set (0.20 sec)

-- left hand side on int compare to int works
mysql> select count(*) from t1 where 0 = c1;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.03 sec)

-- left hand side on int compare to int works
mysql> select count(*) from t1 where 1 = c1;
+----------+
| count(*) |
+----------+
|   524288 |
+----------+
1 row in set (0.12 sec)

-- left hand side on string compare to int does not work
-- wrong result!
mysql> select count(*) from t1 where '0' = c1;
+----------+
| count(*) |
+----------+
|   524288 |
+----------+
1 row in set (0.13 sec)

Right hand side to string comparisons work properly:

mysql> select count(*) from t1 where c1 = '0';
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.02 sec)

mysql> select count(*) from t1 where c1 = '1';
+----------+
| count(*) |
+----------+
|   524288 |
+----------+
1 row in set (0.12 sec)

mysql> select count(*) from t1 where c1 > '1';
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.02 sec)

mysql> select count(*) from t1 where c1 > '0';
+----------+
| count(*) |
+----------+
|   524288 |
+----------+
1 row in set (0.12 sec)

@greenlion greenlion added bug Something isn't working BETA3 Target for beta #3 labels Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BETA3 Target for beta #3 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant