📄 ps.test
字号:
prepare stmt1 from "select 1";show status like 'prepared_stmt_count';deallocate prepare stmt;show status like 'prepared_stmt_count';## E. Check that we can prepare a statement with the same name # successfully, without hitting the limit.#prepare stmt from "select 1";show status like 'prepared_stmt_count';prepare stmt from "select 2";show status like 'prepared_stmt_count';## F. We can set the max below the current count. In this case no new # statements should be allowed to prepare.#show status like 'prepared_stmt_count';select @@max_prepared_stmt_count;set global max_prepared_stmt_count=0;--error ER_MAX_PREPARED_STMT_COUNT_REACHEDprepare stmt from "select 1";# Result: the old statement is deallocated, the new is not created.--error ER_UNKNOWN_STMT_HANDLERexecute stmt;show status like 'prepared_stmt_count';--error ER_MAX_PREPARED_STMT_COUNT_REACHEDprepare stmt from "select 1";show status like 'prepared_stmt_count';## G. Show that the variables are up to date even after a connection with all# statements in it was terminated.#set global max_prepared_stmt_count=3;select @@max_prepared_stmt_count;show status like 'prepared_stmt_count';prepare stmt from "select 1";connect (con1,localhost,root,,);connection con1;prepare stmt from "select 2";prepare stmt1 from "select 3";--error ER_MAX_PREPARED_STMT_COUNT_REACHEDprepare stmt2 from "select 4";connection default;--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt2 from "select 4";select @@max_prepared_stmt_count;show status like 'prepared_stmt_count';disconnect con1;connection default;deallocate prepare stmt;## Restore the old value.#set global max_prepared_stmt_count= @old_max_prepared_stmt_count;--enable_ps_protocol## Bug#19399 "Stored Procedures 'Lost Connection' when dropping/creating# tables"# Check that multi-delete tables are also cleaned up before re-execution.# --disable_warningsdrop table if exists t1;create temporary table if not exists t1 (a1 int);--enable_warnings# exact delete syntax is essentialprepare stmt from "delete t1 from t1 where (cast(a1/3 as unsigned) * 3) = a1";drop temporary table t1;create temporary table if not exists t1 (a1 int);# the server crashed on the next statement without the fixexecute stmt;drop temporary table t1;create temporary table if not exists t1 (a1 int);# the problem was in memory corruption: repeat the test just in caseexecute stmt;drop temporary table t1;create temporary table if not exists t1 (a1 int);execute stmt;drop temporary table t1;deallocate prepare stmt;## BUG#22085: Crash on the execution of a prepared statement that# uses an IN subquery with aggregate functions in HAVING #CREATE TABLE t1( ID int(10) unsigned NOT NULL auto_increment, Member_ID varchar(15) NOT NULL default '', Action varchar(12) NOT NULL, Action_Date datetime NOT NULL, Track varchar(15) default NULL, User varchar(12) default NULL, Date_Updated timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (ID), KEY Action (Action), KEY Action_Date (Action_Date));INSERT INTO t1(Member_ID, Action, Action_Date, Track) VALUES ('111111', 'Disenrolled', '2006-03-01', 'CAD' ), ('111111', 'Enrolled', '2006-03-01', 'CAD' ), ('111111', 'Disenrolled', '2006-07-03', 'CAD' ), ('222222', 'Enrolled', '2006-03-07', 'CAD' ), ('222222', 'Enrolled', '2006-03-07', 'CHF' ), ('222222', 'Disenrolled', '2006-08-02', 'CHF' ), ('333333', 'Enrolled', '2006-03-01', 'CAD' ), ('333333', 'Disenrolled', '2006-03-01', 'CAD' ), ('444444', 'Enrolled', '2006-03-01', 'CAD' ), ('555555', 'Disenrolled', '2006-03-01', 'CAD' ), ('555555', 'Enrolled', '2006-07-21', 'CAD' ), ('555555', 'Disenrolled', '2006-03-01', 'CHF' ), ('666666', 'Enrolled', '2006-02-09', 'CAD' ), ('666666', 'Enrolled', '2006-05-12', 'CHF' ), ('666666', 'Disenrolled', '2006-06-01', 'CAD' );PREPARE STMT FROM"SELECT GROUP_CONCAT(Track SEPARATOR ', ') FROM t1 WHERE Member_ID=? AND Action='Enrolled' AND (Track,Action_Date) IN (SELECT Track, MAX(Action_Date) FROM t1 WHERE Member_ID=? GROUP BY Track HAVING Track>='CAD' AND MAX(Action_Date)>'2006-03-01')";SET @id='111111';EXECUTE STMT USING @id,@id;SET @id='222222';EXECUTE STMT USING @id,@id;DEALLOCATE PREPARE STMT;DROP TABLE t1;## BUG#21354: (COUNT(*) = 1) not working in SELECT inside prepared# statement #--disable_warningsDROP TABLE IF EXISTS t1;--enable_warningsCREATE TABLE t1 (i INT, INDEX(i));INSERT INTO t1 VALUES (1);PREPARE stmt FROM "SELECT (COUNT(i) = 1), COUNT(i) FROM t1 WHERE i = ?";SET @a = 0;EXECUTE stmt USING @a;SET @a = 1;EXECUTE stmt USING @a;SET @a = 0;EXECUTE stmt USING @a;PREPARE stmt FROM "SELECT (AVG(i) = 1), AVG(i) FROM t1 WHERE i = ?";SET @a = 0;EXECUTE stmt USING @a;SET @a = 1;EXECUTE stmt USING @a;SET @a = 0;EXECUTE stmt USING @a;PREPARE stmt FROM "SELECT (VARIANCE(i) = 1), VARIANCE(i) FROM t1 WHERE i = ?";SET @a = 0;EXECUTE stmt USING @a;SET @a = 1;EXECUTE stmt USING @a;SET @a = 0;EXECUTE stmt USING @a;PREPARE stmt FROM "SELECT (STDDEV(i) = 1), STDDEV(i) FROM t1 WHERE i = ?";SET @a = 0;EXECUTE stmt USING @a;SET @a = 1;EXECUTE stmt USING @a;SET @a = 0;EXECUTE stmt USING @a;PREPARE stmt FROM "SELECT (BIT_OR(i) = 1), BIT_OR(i) FROM t1 WHERE i = ?";SET @a = 0;EXECUTE stmt USING @a;SET @a = 1;EXECUTE stmt USING @a;SET @a = 0;EXECUTE stmt USING @a;PREPARE stmt FROM "SELECT (BIT_AND(i) = 1), BIT_AND(i) FROM t1 WHERE i = ?";SET @a = 0;EXECUTE stmt USING @a;SET @a = 1;EXECUTE stmt USING @a;SET @a = 0;EXECUTE stmt USING @a;PREPARE stmt FROM "SELECT (BIT_XOR(i) = 1), BIT_XOR(i) FROM t1 WHERE i = ?";SET @a = 0;EXECUTE stmt USING @a;SET @a = 1;EXECUTE stmt USING @a;SET @a = 0;EXECUTE stmt USING @a;DEALLOCATE PREPARE stmt;DROP TABLE t1;## Bug#19182: CREATE TABLE bar (m INT) SELECT n FROM foo; doesn't work# from stored procedure.## The cause of a bug was that cached LEX::create_list was modified,# and then together with LEX::key_list was reset.#--disable_warningsDROP TABLE IF EXISTS t1, t2;--enable_warningsCREATE TABLE t1 (i INT);PREPARE st_19182FROM "CREATE TABLE t2 (i INT, j INT, KEY (i), KEY(j)) SELECT i FROM t1";EXECUTE st_19182;DESC t2;DROP TABLE t2;# Check that on second execution we don't loose 'j' column and the keys# on 'i' and 'j' columns.EXECUTE st_19182;DESC t2;DEALLOCATE PREPARE st_19182;DROP TABLE t2, t1;## Bug #22060 "ALTER TABLE x AUTO_INCREMENT=y in SP crashes server"## Code which implemented CREATE/ALTER TABLE and CREATE DATABASE# statement modified HA_CREATE_INFO structure in LEX, making these# statements PS/SP-unsafe (their re-execution might have resulted# in incorrect results).#--disable_warningsdrop database if exists mysqltest;drop table if exists t1, t2;--enable_warnings# CREATE TABLE and CREATE TABLE ... SELECTcreate database mysqltest character set utf8;prepare stmt1 from "create table mysqltest.t1 (c char(10))";prepare stmt2 from "create table mysqltest.t2 select 'test'";execute stmt1;execute stmt2;show create table mysqltest.t1;show create table mysqltest.t2;drop table mysqltest.t1;drop table mysqltest.t2;alter database mysqltest character set latin1;execute stmt1;execute stmt2;show create table mysqltest.t1;show create table mysqltest.t2;drop database mysqltest;deallocate prepare stmt1;deallocate prepare stmt2;## CREATE TABLE with DATA DIRECTORY option#--disable_warnings--disable_query_logeval prepare stmt from "create table t1 (c char(10)) data directory='$MYSQLTEST_VARDIR/tmp'";--enable_query_logexecute stmt;## DATA DIRECTORY option does not always work: if the operating# system does not support symlinks, have_symlinks option is automatically# disabled.# In this case DATA DIRECTORY is silently ignored when# creating a table, and is not output by SHOW CREATE TABLE.#--disable_result_logshow create table t1;--enable_result_logdrop table t1;execute stmt;--disable_result_logshow create table t1;--enable_result_log--enable_warningsdrop table t1;deallocate prepare stmt;### Bug #27937: crash on the second execution for prepared statement # from UNION with ORDER BY an expression containing RAND()#CREATE TABLE t1(a int);INSERT INTO t1 VALUES (2), (3), (1);PREPARE st1 FROM '(SELECT a FROM t1) UNION (SELECT a+10 FROM t1) ORDER BY RAND()*0+a';EXECUTE st1;EXECUTE st1;DEALLOCATE PREPARE st1;DROP TABLE t1;--echo End of 4.1 tests.############################# 5.0 tests start ################################### Bug#6102 "Server crash with prepared statement and blank after# function name"# ensure that stored functions are cached when preparing a statement# before we open tables#create table t1 (a varchar(20)); insert into t1 values ('foo'); --error 1305prepare stmt FROM 'SELECT char_length (a) FROM t1'; drop table t1;## Bug#8115: equality propagation and prepared statements#create table t1 (a char(3) not null, b char(3) not null, c char(3) not null, primary key (a, b, c));create table t2 like t1;# reduced queryprepare stmt from "select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b) where t1.a=1";execute stmt;execute stmt;execute stmt;# original queryprepare stmt from"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from(t1 left outer join t2 on t2.a=? and t1.b=t2.b)left outer join t2 t3 on t3.a=? where t1.a=?";set @a:=1, @b:=1, @c:=1;execute stmt using @a, @b, @c;execute stmt using @a, @b, @c;execute stmt using @a, @b, @c;deallocate prepare stmt;drop table t1,t2;## Bug#9383: INFORMATION_SCHEMA.COLUMNS, JOIN, Crash, prepared statement#eval SET @aux= "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS A, INFORMATION_SCHEMA.COLUMNS B WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA AND A.TABLE_NAME = B.TABLE_NAME AND A.COLUMN_NAME = B.COLUMN_NAME AND A.TABLE_NAME = 'user'";let $exec_loop_count= 3;eval prepare my_stmt from @aux;while ($exec_loop_count){ eval execute my_stmt; dec $exec_loop_count;}deallocate prepare my_stmt;# Test CALL in prepared modedelimiter |;--disable_warningsdrop procedure if exists p1|drop table if exists t1|--enable_warningscreate table t1 (id int)|insert into t1 values(1)|create procedure p1(a int, b int)begin declare c int; select max(id)+1 into c from t1; insert into t1 select a+b; insert into t1 select a-b; insert into t1 select a-c;end|set @a= 3, @b= 4|prepare stmt from "call p1(?, ?)"|execute stmt using @a, @b|execute stmt using @a, @b|select * from t1|deallocate prepare stmt|drop procedure p1|drop table t1|delimiter ;|## Bug#7306 LIMIT ?, ? and also WL#1785 " Prepared statements: implement# support for placeholders in LIMIT clause."# Add basic test coverage for the feature.# create table t1 (a int);insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);prepare stmt from "select * from t1 limit ?, ?";set @offset=0, @limit=1;execute stmt using @offset, @limit;select * from t1 limit 0, 1;set @offset=3, @limit=2;execute stmt using @offset, @limit;select * from t1 limit 3, 2;prepare stmt from "select * from t1 limit ?";execute stmt using @limit;--error 1235prepare stmt from "select * from t1 where a in (select a from t1 limit ?)";prepare stmt from "select * from t1 union all select * from t1 limit ?, ?";set @offset=9;set @limit=2;execute stmt using @offset, @limit;prepare stmt from "(select * from t1 limit ?, ?) union all (select * from t1 limit ?, ?) order by a limit ?";execute stmt using @offset, @limit, @offset, @limit, @limit;drop table t1;deallocate prepare stmt;## Bug#12651# (Crash on a PS including a subquery which is a select from a simple view)#CREATE TABLE b12651_T1(a int) ENGINE=MYISAM;CREATE TABLE b12651_T2(b int) ENGINE=MYISAM;CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2;PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)';EXECUTE b12651;DROP VIEW b12651_V1;DROP TABLE b12651_T1, b12651_T2;DEALLOCATE PREPARE b12651;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -