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

Wrong behavior about max prepared stmt #39969

Open
xuyifangreeneyes opened this issue Dec 15, 2022 · 1 comment
Open

Wrong behavior about max prepared stmt #39969

xuyifangreeneyes opened this issue Dec 15, 2022 · 1 comment
Assignees
Labels
epic/plan-cache severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@xuyifangreeneyes
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

ref #39736

create table t1
(
  a int primary key,
  b char(10)
);

prepare stmt4 from 'update t1 set a=? where b=?';
set @arg1=55, @arg2='five';
execute stmt4 using @arg1, @arg2;

prepare stmt4 from 'create table t2 (a int)';
execute stmt4;
deallocate prepare stmt4;

set global max_prepared_stmt_count=1;
prepare stmt from "select 1";

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

mysql> create table t1
    -> (
    ->   a int primary key,
    ->   b char(10)
    -> );
Query OK, 0 rows affected (0.16 sec)

mysql> prepare stmt4 from 'update t1 set a=? where b=?';
Query OK, 0 rows affected (0.01 sec)
Statement prepared

mysql> set @arg1=55, @arg2='five';
Query OK, 0 rows affected (0.01 sec)

mysql> execute stmt4 using @arg1, @arg2;
Query OK, 0 rows affected (0.01 sec)
Rows matched: 0  Changed: 0  Warnings: 0

mysql> prepare stmt4 from 'create table t2 (a int)';
Query OK, 0 rows affected (0.01 sec)
Statement prepared

mysql> execute stmt4;
Query OK, 0 rows affected (0.02 sec)

mysql> deallocate prepare stmt4;
Query OK, 0 rows affected (0.00 sec)

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

mysql> prepare stmt from "select 1";
Query OK, 0 rows affected (0.00 sec)
Statement prepared

3. What did you see instead (Required)

mysql> create table t1
    -> (
    ->   a int primary key,
    ->   b char(10)
    -> );
Query OK, 0 rows affected (0.07 sec)

mysql> prepare stmt4 from 'update t1 set a=? where b=?';
Query OK, 0 rows affected (0.00 sec)

mysql> set @arg1=55, @arg2='five';
Query OK, 0 rows affected (0.00 sec)

mysql> execute stmt4 using @arg1, @arg2;
Query OK, 0 rows affected (0.02 sec)
Rows matched: 0  Changed: 0  Warnings: 0

mysql> prepare stmt4 from 'create table t2 (a int)';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> execute stmt4;
Query OK, 0 rows affected (0.02 sec)

mysql> deallocate prepare stmt4;
Query OK, 0 rows affected (0.00 sec)

mysql> set global max_prepared_stmt_count=1;
Query OK, 0 rows affected (0.01 sec)

mysql> prepare stmt from "select 1";
ERROR 1461 (42000): Can't create more than maxPreparedStmtCount statements (current value: 1)

4. What is your TiDB version? (Required)

#39736

@qw4990
Copy link
Contributor

qw4990 commented Apr 14, 2023

In the internal of TiDB, each prepared statement has a unique ID, and TiDB uses these ID to count how many statements there.
So if we run 2 prepare statements with the same statement name twice, TiDB will create 2 different prepared statements internally, and the count becomes to 2.

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

No branches or pull requests

2 participants