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

Query with CONV expression gives incorrect result if using plan cache #53505

Closed
YangKeao opened this issue May 23, 2024 · 0 comments · Fixed by #53681
Closed

Query with CONV expression gives incorrect result if using plan cache #53505

YangKeao opened this issue May 23, 2024 · 0 comments · Fixed by #53681

Comments

@YangKeao
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

It actually has two issues:

  1. The result is not consistent with / without plan cache.
  2. The result is always not compatible with MySQL.

1. Minimal reproduce step (Required)

create table t (v varchar(16));
insert into t values ('156');
prepare stmt7 from 'select * from t where v = conv(?, 16, 8)';
set @arg=0x6E;
execute stmt7 using @arg;
execute stmt7 using @arg;
set @arg=0x70;
execute stmt7 using @arg;

2. What did you expect to see? (Required)

The result from MySQL is:

mysql> use test;
Database changed
mysql> create table t (v varchar(16));
Query OK, 0 rows affected (0.01 sec)

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

mysql> prepare stmt7 from 'select * from t where v = conv(?, 16, 8)';
Query OK, 0 rows affected (0.00 sec)
Statement prepared

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

mysql> execute stmt7 using @arg;
Empty set, 1 warning (0.00 sec)

mysql> execute stmt7 using @arg;
Empty set, 1 warning (0.00 sec)

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

mysql> execute stmt7 using @arg;
Empty set, 1 warning (0.00 sec)

3. What did you see instead (Required)

The result from TiDB is:

mysql> create table t (v varchar(16));
Query OK, 0 rows affected (0.12 sec)

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

mysql> prepare stmt7 from 'select * from t where v = conv(?, 16, 8)';
Query OK, 0 rows affected (0.00 sec)

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

mysql> execute stmt7 using @arg;
+------+
| v    |
+------+
| 156  |
+------+
1 row in set (0.00 sec)

mysql> execute stmt7 using @arg;
+------+
| v    |
+------+
| 156  |
+------+
1 row in set (0.00 sec)

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

mysql> execute stmt7 using @arg;
+------+
| v    |
+------+
| 156  |
+------+
1 row in set (0.00 sec)

If you execute the second statement without using plan cache, it'll give nothing:

mysql> create table t (v varchar(16));
Query OK, 0 rows affected (0.11 sec)

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

mysql> prepare stmt7 from 'select * from t where v = conv(?, 16, 8)';
Query OK, 0 rows affected (0.00 sec)

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

mysql> execute stmt7 using @arg;
Empty set (0.01 sec)

4. What is your TiDB version? (Required)

@YangKeao YangKeao added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner component/expression severity/major labels May 23, 2024
@qw4990 qw4990 self-assigned this May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants