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

incompatible query result with MySQL #14399

Open
eurekaka opened this issue Jan 8, 2020 · 3 comments
Open

incompatible query result with MySQL #14399

eurekaka opened this issue Jan 8, 2020 · 3 comments
Labels
component/expression severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@eurekaka
Copy link
Contributor

eurekaka commented Jan 8, 2020

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
mysql> create table t(col_double double);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values(1);
Query OK, 1 row affected (0.00 sec)

mysql> set session tidb_enable_vectorized_expression = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into mysql.expr_pushdown_blacklist values('cast');
Query OK, 1 row affected (0.00 sec)

mysql> admin reload expr_pushdown_blacklist;
Query OK, 0 rows affected (0.00 sec)

mysql> prepare stmt from "SELECT * FROM (SELECT col_double AS c0 FROM t) t WHERE (ABS((REPEAT(?, ?) OR 5617780767323292672)) < LN(EXP(c0)) + (? ^ ?))";
Query OK, 0 rows affected (0.01 sec)

mysql> set @a1 = "JuvkBX7ykVux20zQlkwDK2DFelgn7";
Query OK, 0 rows affected (0.00 sec)

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

mysql> set @a3 = -112990.35179796701;
Query OK, 0 rows affected (0.00 sec)

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

mysql> execute stmt using @a1, @a2, @a3, @a4;
+------+
| c0   |
+------+
|    1 |
+------+
1 row in set, 3 warnings (0.00 sec)
  1. What did you expect to see?

In MySQL:

mysql> create table t(col_double double);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into t values(1.0);
Query OK, 1 row affected (0.01 sec)

mysql> prepare stmt from "SELECT * FROM (SELECT col_double AS c0 FROM t) t WHERE (ABS((REPEAT(?, ?) OR 5617780767323292672)) < LN(EXP(c0)) + (? ^ ?))";
Query OK, 0 rows affected (0.00 sec)
Statement prepared

mysql> set @a1 = "JuvkBX7ykVux20zQlkwDK2DFelgn7";
Query OK, 0 rows affected (0.01 sec)

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

mysql> set @a3 = -112990.35179796701;
Query OK, 0 rows affected (0.00 sec)

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

mysql> execute stmt using @a1, @a2, @a3, @a4;
Empty set (0.00 sec)
  1. What did you see instead?

Different result for execute.

  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
57bb931a273d37a1d59e3f7b6a09dd94ff8e2326
@eurekaka eurekaka added type/bug The issue is confirmed as a bug. component/expression labels Jan 8, 2020
@eurekaka
Copy link
Contributor Author

eurekaka commented Jan 8, 2020

@qw4990 Should this issue be assigned to expression SIG?

@ghost
Copy link

ghost commented Jul 16, 2020

This behaves different in MySQL 5.7 / MySQL 8.0 / TiDB. I am not smart enough to figure out which one is most correct :(

Testcase:

drop table if exists t;
create table t(col_double double);
insert into t values(1);
prepare stmt from "SELECT * FROM (SELECT col_double AS c0 FROM t) t WHERE (ABS((REPEAT(?, ?) OR 5617780767323292672)) < LN(EXP(c0)) + (? ^ ?))";
SET @a1 = "JuvkBX7ykVux20zQlkwDK2DFelgn7", @a2 = 1, @a3 = -112990.35179796701, @a4 = 87997.92704840179;
execute stmt using @a1, @a2, @a3, @a4;

MySQL 5.7:

mysql [localhost:5731] {msandbox} (test) > execute stmt using @a1, @a2, @a3, @a4;
Empty set (0.00 sec)

MySQL 8.0:

mysql [localhost:8021] {msandbox} (test) > execute stmt using @a1, @a2, @a3, @a4;
+------+
| c0   |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

TiDB (master):

mysql> execute stmt using @a1, @a2, @a3, @a4;
+------+
| c0   |
+------+
|    1 |
+------+
1 row in set, 23 warnings (0.01 sec)

@guo-shaoge
Copy link
Collaborator

Simplified testcase:

drop table t;
create table t(col_double double);
insert into t values(1);
select * from t where  0 < (col_double + (-1 ^ 8));
select 0 < (col_double + (-1 ^ 8)) from t; 

MySQL 5.6 result:

Server version: 5.6.51 Source distribution
mysql> select * from t where  0 < (col_double + (-1 ^ 8));
Empty set (0.00 sec)

mysql> select 0 < (col_double + (-1 ^ 8)) from t;
+-----------------------------+
| 0 < (col_double + (-1 ^ 8)) |
+-----------------------------+
|                           1 |
+-----------------------------+
1 row in set (0.00 sec)

MySQL 8.0 result:

Server version: 8.0.23 MySQL Community Server - GPL
mysql> select * from t where  0 < (col_double + (-1 ^ 8));
+------------+
| col_double |
+------------+
|          1 |
+------------+
1 row in set (0.00 sec)

mysql> select 0 < (col_double + (-1 ^ 8)) from t;
+-----------------------------+
| 0 < (col_double + (-1 ^ 8)) |
+-----------------------------+
|                           1 |
+-----------------------------+
1 row in set (0.00 sec)

"0 < (col_double + (-1 ^ 8))": result of this expression should be true. TiDB's result is OK.

Implementation of MySQL 5.6 got bug, because it didn't convert the result of "-1 ^ 8" to unsigned longlong(see Item_cache_int::val_real(), it shoud check Item::unsigned_flag, then convert value to unsigned, just like Item_int_func::val_real() does.)

Maybe we can close this issue?

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

No branches or pull requests

4 participants