greenlion / warp

WarpSQL Server, an open source OLAP focused distribution of the world's most popular open source database bundled with OLAP performance related plugins such as the WARP storage engine..
http://warpsql.blog
Other
41 stars 2 forks source link

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

Open greenlion opened 3 years ago

greenlion commented 3 years ago
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)