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

incorect batch point get plan when prepare plan cache enabled #14852

Closed
zz-jason opened this issue Feb 19, 2020 · 1 comment · Fixed by #14855
Closed

incorect batch point get plan when prepare plan cache enabled #14852

zz-jason opened this issue Feb 19, 2020 · 1 comment · Fixed by #14855
Assignees
Labels
severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@zz-jason
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. What did you do?

CREATE TABLE `bmsql_item` (
  `i_id` int(11) NOT NULL,
  `i_name` varchar(24) DEFAULT NULL,
  `i_price` decimal(5,2) DEFAULT NULL,
  `i_data` varchar(50) DEFAULT NULL,
  `i_im_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`i_id`)
)

enable prepare plan cache, then execute a prepared statement in the following steps:

TiDB(root@127.0.0.1:test) > prepare stmt from 'select i_id, i_price, i_name, i_data from bmsql_item where i_id in (?, ?)';
Query OK, 0 rows affected (0.00 sec)

execute it in the first time:

TiDB(root@127.0.0.1:test) > set @a = "123", @b = "456";
Query OK, 0 rows affected (0.00 sec)

TiDB(root@127.0.0.1:test) > execute stmt using @a, @b;
Empty set (0.00 sec)

TiDB(root@127.0.0.1:test) > explain for connection 1;
+-------------------------+-------+------+-----------------------------------------+
| id                      | count | task | operator info                           |
+-------------------------+-------+------+-----------------------------------------+
| _0                      | N/A   | root | N/A                                     |
| └─Batch_Point_Get_1     | 2.00  | root | table:bmsql_item, handles: %#v[123 456] |
+-------------------------+-------+------+-----------------------------------------+
2 rows in set (0.00 sec)

execute it in the second time:

TiDB(root@127.0.0.1:test) > set @a = "123", @b = "45612";
Query OK, 0 rows affected (0.00 sec)

TiDB(root@127.0.0.1:test) > execute stmt using @a, @b;
Empty set (0.00 sec)

TiDB(root@127.0.0.1:test) > explain for connection 1;
+-------------------------+-------+------+-----------------------------------------+
| id                      | count | task | operator info                           |
+-------------------------+-------+------+-----------------------------------------+
| _0                      | N/A   | root | N/A                                     |
| └─Batch_Point_Get_1     | 2.00  | root | table:bmsql_item, handles: %#v[123 456] |
+-------------------------+-------+------+-----------------------------------------+
2 rows in set (0.00 sec)

2. What did you expect to see?

handles should be reset

3. What did you see instead?

got incorrect plan

4. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?

TiDB(root@127.0.0.1:test) > select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta-51-gc46044f02-dirty
Git Commit Hash: c46044f02651fa18b0d4654c22ae69e715a5fdd0
Git Branch: master
UTC Build Time: 2020-02-19 12:19:34
GoVersion: go1.13.5
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)
@zz-jason zz-jason added the type/bug The issue is confirmed as a bug. label Feb 19, 2020
@eurekaka eurekaka self-assigned this Feb 19, 2020
@zz-jason zz-jason added the sig/planner SIG: Planner label Feb 19, 2020
@eurekaka
Copy link
Contributor

Simplified reproduction:

mysql> create table t(a int primary key, b int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t values(1,1),(2,2),(3,3),(4,4);
Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> explain select * from t where a in (1,2);
+-------------------+-------+------+---------------+
| id                | count | task | operator info |
+-------------------+-------+------+---------------+
| Batch_Point_Get_1 | 2.00  | root | table:t       |
+-------------------+-------+------+---------------+
1 row in set (0.00 sec)

mysql> prepare stmt from "select * from t where a in (?,?)";
Query OK, 0 rows affected (0.00 sec)

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

mysql> execute stmt using @p1, @p2;
+---+------+
| a | b    |
+---+------+
| 1 |    1 |
| 2 |    2 |
+---+------+
2 rows in set (0.01 sec)

mysql> set @p1 = 3, @p2 = 4;
Query OK, 0 rows affected (0.00 sec)

mysql> execute stmt using @p1, @p2;
+---+------+
| a | b    |
+---+------+
| 3 |    3 |
| 2 |    2 |
+---+------+
2 rows in set (0.00 sec)

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

Successfully merging a pull request may close this issue.

3 participants