Commit 15a76619 authored by kostja@bodhi.local's avatar kostja@bodhi.local

Post-merge fixes for Bug#19399 "Stored Procedures 'Lost Connection'

when dropping/creating tables"
parent e4598dae
...@@ -485,11 +485,6 @@ execute stmt; ...@@ -485,11 +485,6 @@ execute stmt;
pnum pnum
deallocate prepare stmt; deallocate prepare stmt;
drop table t1, t2; drop table t1, t2;
create table t1 (a varchar(20));
insert into t1 values ('foo');
prepare stmt FROM 'SELECT char_length (a) FROM t1';
ERROR 42000: FUNCTION test.char_length does not exist
drop table t1;
prepare stmt from "SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0"; prepare stmt from "SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0";
execute stmt; execute stmt;
foo foo
...@@ -502,77 +497,6 @@ SELECT FOUND_ROWS(); ...@@ -502,77 +497,6 @@ SELECT FOUND_ROWS();
FOUND_ROWS() FOUND_ROWS()
2 2
deallocate prepare stmt; deallocate prepare stmt;
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;
prepare 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;
a
execute stmt;
a
execute stmt;
a
prepare 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;
a b c a b c
execute stmt using @a, @b, @c;
a b c a b c
execute stmt using @a, @b, @c;
a b c a b c
deallocate prepare stmt;
drop table t1,t2;
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'";
prepare my_stmt from @aux;
execute my_stmt;
COUNT(*)
37
execute my_stmt;
COUNT(*)
37
execute my_stmt;
COUNT(*)
37
deallocate prepare my_stmt;
drop procedure if exists p1|
drop table if exists t1|
create 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|
id
1
7
-1
1
7
-1
-5
deallocate prepare stmt|
drop procedure p1|
drop table t1|
drop table if exists t1; drop table if exists t1;
Warnings: Warnings:
Note 1051 Unknown table 't1' Note 1051 Unknown table 't1'
...@@ -636,47 +560,6 @@ id ...@@ -636,47 +560,6 @@ id
3 3
deallocate prepare stmt; deallocate prepare stmt;
drop table t1, t2; drop table t1, t2;
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;
a
1
select * from t1 limit 0, 1;
a
1
set @offset=3, @limit=2;
execute stmt using @offset, @limit;
a
4
5
select * from t1 limit 3, 2;
a
4
5
prepare stmt from "select * from t1 limit ?";
execute stmt using @limit;
a
1
2
prepare stmt from "select * from t1 where a in (select a from t1 limit ?)";
ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
prepare stmt from "select * from t1 union all select * from t1 limit ?, ?";
set @offset=9;
set @limit=2;
execute stmt using @offset, @limit;
a
10
1
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;
a
10
10
drop table t1;
deallocate prepare stmt;
create table t1 (id int); create table t1 (id int);
prepare stmt from "insert into t1 (id) select id from t1 union select id from t1"; prepare stmt from "insert into t1 (id) select id from t1 union select id from t1";
execute stmt; execute stmt;
...@@ -777,15 +660,6 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp ...@@ -777,15 +660,6 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
select ? from t1; select ? from t1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? from t1' at line 1 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? from t1' at line 1
drop table t1; drop table t1;
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;
1
DROP VIEW b12651_V1;
DROP TABLE b12651_T1, b12651_T2;
DEALLOCATE PREPARE b12651;
prepare stmt from "select @@time_zone"; prepare stmt from "select @@time_zone";
execute stmt; execute stmt;
@@time_zone @@time_zone
...@@ -1002,6 +876,147 @@ select @@max_prepared_stmt_count, @@prepared_stmt_count; ...@@ -1002,6 +876,147 @@ select @@max_prepared_stmt_count, @@prepared_stmt_count;
@@max_prepared_stmt_count @@prepared_stmt_count @@max_prepared_stmt_count @@prepared_stmt_count
3 0 3 0
set global max_prepared_stmt_count= @old_max_prepared_stmt_count; set global max_prepared_stmt_count= @old_max_prepared_stmt_count;
drop table if exists t1;
create temporary table if not exists t1 (a1 int);
prepare 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);
execute stmt;
drop temporary table t1;
create temporary table if not exists t1 (a1 int);
execute stmt;
drop temporary table t1;
create temporary table if not exists t1 (a1 int);
execute stmt;
drop temporary table t1;
deallocate prepare stmt;
End of 4.1 tests
create table t1 (a varchar(20));
insert into t1 values ('foo');
prepare stmt FROM 'SELECT char_length (a) FROM t1';
ERROR 42000: FUNCTION test.char_length does not exist
drop table t1;
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;
prepare 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;
a
execute stmt;
a
execute stmt;
a
prepare 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;
a b c a b c
execute stmt using @a, @b, @c;
a b c a b c
execute stmt using @a, @b, @c;
a b c a b c
deallocate prepare stmt;
drop table t1,t2;
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'";
prepare my_stmt from @aux;
execute my_stmt;
COUNT(*)
37
execute my_stmt;
COUNT(*)
37
execute my_stmt;
COUNT(*)
37
deallocate prepare my_stmt;
drop procedure if exists p1|
drop table if exists t1|
create 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|
id
1
7
-1
1
7
-1
-5
deallocate prepare stmt|
drop procedure p1|
drop table t1|
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;
a
1
select * from t1 limit 0, 1;
a
1
set @offset=3, @limit=2;
execute stmt using @offset, @limit;
a
4
5
select * from t1 limit 3, 2;
a
4
5
prepare stmt from "select * from t1 limit ?";
execute stmt using @limit;
a
1
2
prepare stmt from "select * from t1 where a in (select a from t1 limit ?)";
ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
prepare stmt from "select * from t1 union all select * from t1 limit ?, ?";
set @offset=9;
set @limit=2;
execute stmt using @offset, @limit;
a
10
1
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;
a
10
10
drop table t1;
deallocate prepare stmt;
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;
1
DROP VIEW b12651_V1;
DROP TABLE b12651_T1, b12651_T2;
DEALLOCATE PREPARE b12651;
create table t1 (id int); create table t1 (id int);
prepare ins_call from "insert into t1 (id) values (1)"; prepare ins_call from "insert into t1 (id) values (1)";
execute ins_call; execute ins_call;
......
...@@ -527,6 +527,7 @@ set @a=200887, @b=860; ...@@ -527,6 +527,7 @@ set @a=200887, @b=860;
# this query did not return all matching rows # this query did not return all matching rows
execute stmt using @a, @b; execute stmt using @a, @b;
deallocate prepare stmt; deallocate prepare stmt;
drop table t1; drop table t1;
# #
...@@ -586,7 +587,6 @@ execute stmt; ...@@ -586,7 +587,6 @@ execute stmt;
execute stmt; execute stmt;
deallocate prepare stmt; deallocate prepare stmt;
drop table t1; drop table t1;
# #
# Bug#11458 "Prepared statement with subselects return random data": # Bug#11458 "Prepared statement with subselects return random data":
# drop PARAM_TABLE_BIT from the list of tables used by a subquery # drop PARAM_TABLE_BIT from the list of tables used by a subquery
...@@ -655,7 +655,6 @@ execute stmt using @user_id, @id; ...@@ -655,7 +655,6 @@ execute stmt using @user_id, @id;
execute stmt using @user_id, @id; execute stmt using @user_id, @id;
deallocate prepare stmt; deallocate prepare stmt;
drop table t1, t2, t3, t4; drop table t1, t2, t3, t4;
# #
# Bug#9379: make sure that Item::collation is reset when one sets # Bug#9379: make sure that Item::collation is reset when one sets
# a parameter marker from a string variable. # a parameter marker from a string variable.
...@@ -770,7 +769,6 @@ execute stmt using @like; ...@@ -770,7 +769,6 @@ execute stmt using @like;
deallocate prepare stmt; deallocate prepare stmt;
drop table t1; drop table t1;
# #
# Bug#13134 "Length of VARCHAR() utf8 column is increasing when table is # Bug#13134 "Length of VARCHAR() utf8 column is increasing when table is
# recreated with PS/SP" # recreated with PS/SP"
...@@ -841,17 +839,17 @@ set global max_prepared_stmt_count=10000000000000000; ...@@ -841,17 +839,17 @@ set global max_prepared_stmt_count=10000000000000000;
select @@max_prepared_stmt_count; select @@max_prepared_stmt_count;
set global max_prepared_stmt_count=default; set global max_prepared_stmt_count=default;
select @@max_prepared_stmt_count; select @@max_prepared_stmt_count;
--error 1229 # ER_GLOBAL_VARIABLE --error ER_GLOBAL_VARIABLE
set @@max_prepared_stmt_count=1; set @@max_prepared_stmt_count=1;
--error 1229 # ER_GLOBAL_VARIABLE --error ER_GLOBAL_VARIABLE
set max_prepared_stmt_count=1; set max_prepared_stmt_count=1;
--error 1229 # ER_GLOBAL_VARIABLE --error ER_GLOBAL_VARIABLE
set local max_prepared_stmt_count=1; set local max_prepared_stmt_count=1;
--error 1229 # ER_GLOBAL_VARIABLE --error ER_INCORRECT_GLOBAL_LOCAL_VAR
set local prepared_stmt_count=0; set local prepared_stmt_count=0;
--error 1229 # ER_GLOBAL_VARIABLE --error ER_INCORRECT_GLOBAL_LOCAL_VAR
set @@prepared_stmt_count=0; set @@prepared_stmt_count=0;
--error 1232 # ER_WRONG_TYPE_FOR_VAR --error ER_INCORRECT_GLOBAL_LOCAL_VAR
set global prepared_stmt_count=1; set global prepared_stmt_count=1;
# set to a reasonable limit works # set to a reasonable limit works
set global max_prepared_stmt_count=1; set global max_prepared_stmt_count=1;
...@@ -861,13 +859,13 @@ select @@max_prepared_stmt_count; ...@@ -861,13 +859,13 @@ select @@max_prepared_stmt_count;
# #
set global max_prepared_stmt_count=0; set global max_prepared_stmt_count=0;
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_prepared_stmt_count, @@prepared_stmt_count;
--error 1105 # ER_UNKNOWN_ERROR --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt from "select 1"; prepare stmt from "select 1";
select @@prepared_stmt_count; select @@prepared_stmt_count;
set global max_prepared_stmt_count=1; set global max_prepared_stmt_count=1;
prepare stmt from "select 1"; prepare stmt from "select 1";
select @@prepared_stmt_count; select @@prepared_stmt_count;
--error 1105 # ER_UNKNOWN_ERROR --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt1 from "select 1"; prepare stmt1 from "select 1";
select @@prepared_stmt_count; select @@prepared_stmt_count;
deallocate prepare stmt; deallocate prepare stmt;
...@@ -886,13 +884,13 @@ select @@prepared_stmt_count; ...@@ -886,13 +884,13 @@ select @@prepared_stmt_count;
# #
select @@prepared_stmt_count, @@max_prepared_stmt_count; select @@prepared_stmt_count, @@max_prepared_stmt_count;
set global max_prepared_stmt_count=0; set global max_prepared_stmt_count=0;
--error 1105 # ER_UNKNOWN_ERROR --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt from "select 1"; prepare stmt from "select 1";
# Result: the old statement is deallocated, the new is not created. # Result: the old statement is deallocated, the new is not created.
--error 1243 # ER_UNKNOWN_STMT_HANDLER --error 1243 # ER_UNKNOWN_STMT_HANDLER
execute stmt; execute stmt;
select @@prepared_stmt_count; select @@prepared_stmt_count;
--error 1105 # ER_UNKNOWN_ERROR --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt from "select 1"; prepare stmt from "select 1";
select @@prepared_stmt_count; select @@prepared_stmt_count;
# #
...@@ -906,10 +904,10 @@ connect (con1,localhost,root,,); ...@@ -906,10 +904,10 @@ connect (con1,localhost,root,,);
connection con1; connection con1;
prepare stmt from "select 2"; prepare stmt from "select 2";
prepare stmt1 from "select 3"; prepare stmt1 from "select 3";
--error 1105 # ER_UNKNOWN_ERROR --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt2 from "select 4"; prepare stmt2 from "select 4";
connection default; connection default;
--error 1105 # ER_UNKNOWN_ERROR --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt2 from "select 4"; prepare stmt2 from "select 4";
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_prepared_stmt_count, @@prepared_stmt_count;
disconnect con1; disconnect con1;
......
...@@ -126,7 +126,7 @@ void lex_start(THD *thd, uchar *buf,uint length) ...@@ -126,7 +126,7 @@ void lex_start(THD *thd, uchar *buf,uint length)
lex->param_list.empty(); lex->param_list.empty();
lex->view_list.empty(); lex->view_list.empty();
lex->prepared_stmt_params.empty(); lex->prepared_stmt_params.empty();
lex->auxilliary_table_list.empty(); lex->auxiliary_table_list.empty();
lex->unit.next= lex->unit.master= lex->unit.next= lex->unit.master=
lex->unit.link_next= lex->unit.return_to= 0; lex->unit.link_next= lex->unit.return_to= 0;
lex->unit.prev= lex->unit.link_prev= 0; lex->unit.prev= lex->unit.link_prev= 0;
......
...@@ -2138,9 +2138,9 @@ void reinit_stmt_before_use(THD *thd, LEX *lex) ...@@ -2138,9 +2138,9 @@ void reinit_stmt_before_use(THD *thd, LEX *lex)
(multi-delete). We do a full clean up, although at the moment all we (multi-delete). We do a full clean up, although at the moment all we
need to clean in the tables of MULTI-DELETE list is 'table' member. need to clean in the tables of MULTI-DELETE list is 'table' member.
*/ */
for (TABLE_LIST *tables= (TABLE_LIST*) lex->auxilliary_table_list.first; for (TABLE_LIST *tables= (TABLE_LIST*) lex->auxiliary_table_list.first;
tables; tables;
tables= tables->next) tables= tables->next_global)
{ {
tables->reinit_before_use(thd); tables->reinit_before_use(thd);
} }
......
...@@ -2992,14 +2992,27 @@ Field_iterator_table_ref::get_natural_column_ref() ...@@ -2992,14 +2992,27 @@ Field_iterator_table_ref::get_natural_column_ref()
st_table_list::reinit_before_use() st_table_list::reinit_before_use()
*/ */
void st_table_list::reinit_before_use(THD * /* thd */) void st_table_list::reinit_before_use(THD *thd)
{ {
/* /*
Reset old pointers to TABLEs: they are not valid since the tables Reset old pointers to TABLEs: they are not valid since the tables
were closed in the end of previous prepare or execute call. were closed in the end of previous prepare or execute call.
*/ */
table= 0; table= 0;
table_list= 0; /* Reset is_schema_table_processed value(needed for I_S tables */
is_schema_table_processed= FALSE;
TABLE_LIST *embedded; /* The table at the current level of nesting. */
TABLE_LIST *embedding= this; /* The parent nested table reference. */
do
{
embedded= embedding;
if (embedded->prep_on_expr)
embedded->on_expr= embedded->prep_on_expr->copy_andor_structure(thd);
embedding= embedded->embedding;
}
while (embedding &&
embedding->nested_join->join_list.head() == embedded);
} }
......
...@@ -668,6 +668,7 @@ typedef struct st_table_list ...@@ -668,6 +668,7 @@ typedef struct st_table_list
Security_context *find_view_security_context(THD *thd); Security_context *find_view_security_context(THD *thd);
bool prepare_view_securety_context(THD *thd); bool prepare_view_securety_context(THD *thd);
#endif #endif
void reinit_before_use(THD *thd);
private: private:
bool prep_check_option(THD *thd, uint8 check_opt_type); bool prep_check_option(THD *thd, uint8 check_opt_type);
...@@ -676,7 +677,6 @@ private: ...@@ -676,7 +677,6 @@ private:
Cleanup for re-execution in a prepared statement or a stored Cleanup for re-execution in a prepared statement or a stored
procedure. procedure.
*/ */
void reinit_before_use(THD *thd);
} TABLE_LIST; } TABLE_LIST;
class Item; class Item;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment