Commit 1cda2aa1 authored by Dmitry Shulga's avatar Dmitry Shulga Committed by Sergei Golubchik

MDEV-5816: Stored programs: validation of stored program statements

Fix of existing mtr tests.
parent 0b0188c5
...@@ -1544,9 +1544,9 @@ f ...@@ -1544,9 +1544,9 @@ f
DROP TABLE t; DROP TABLE t;
CREATE TABLE t (i INT); CREATE TABLE t (i INT);
CALL p; CALL p;
ERROR 42S22: Unknown column 't1.f' in 'field list' ERROR 42S22: Unknown column 'f' in 'from clause'
CALL p; CALL p;
ERROR 42S22: Unknown column 't1.f' in 'field list' ERROR 42S22: Unknown column 'f' in 'from clause'
DROP PROCEDURE p; DROP PROCEDURE p;
DROP TABLE t; DROP TABLE t;
CREATE TABLE t1 (a INT, b INT); CREATE TABLE t1 (a INT, b INT);
......
...@@ -320,8 +320,8 @@ create table t3 (a int unique); ...@@ -320,8 +320,8 @@ create table t3 (a int unique);
create view v1 as select a from t2; create view v1 as select a from t2;
create trigger t1_ai after insert on t1 for each row create trigger t1_ai after insert on t1 for each row
insert into v1 (a) values (new.a); insert into v1 (a) values (new.a);
# Demonstrate that the same bug is present # Demonstrate that this bug is fixed by MDEV-5816
# without prepared statements # both for regular and prepared statements
insert into t1 (a) values (5); insert into t1 (a) values (5);
select * from t2; select * from t2;
a a
...@@ -331,15 +331,15 @@ a ...@@ -331,15 +331,15 @@ a
drop view v1; drop view v1;
create view v1 as select a from t3; create view v1 as select a from t3;
insert into t1 (a) values (6); insert into t1 (a) values (6);
ERROR 42S02: Table 'test.t2' doesn't exist
flush table t1; flush table t1;
insert into t1 (a) values (6); insert into t1 (a) values (60);
select * from t2; select * from t2;
a a
5 5
select * from t3; select * from t3;
a a
6 6
60
prepare stmt from "insert into t1 (a) values (?)"; prepare stmt from "insert into t1 (a) values (?)";
set @var=7; set @var=7;
execute stmt using @var; execute stmt using @var;
...@@ -350,6 +350,7 @@ select * from t3; ...@@ -350,6 +350,7 @@ select * from t3;
a a
6 6
7 7
60
select * from t2; select * from t2;
a a
5 5
...@@ -364,23 +365,26 @@ set @var=8; ...@@ -364,23 +365,26 @@ set @var=8;
# but repreparation of the main statement doesn't cause repreparation # but repreparation of the main statement doesn't cause repreparation
# of trigger statements. # of trigger statements.
# #
# The following EXECUTE results in ER_NO_SUCH_TABLE (t3) error, because # Prior MDEV-5816, the following EXECUTE resulted in
# pre-locking list of the prepared statement has been changed # ER_NO_SUCH_TABLE (t3) error, because pre-locking list of the prepared
# statement has been changed
# (the prepared statement has noticed the meta-data change), # (the prepared statement has noticed the meta-data change),
# but the trigger still tries to deal with 't3', which is not opened. # but the trigger still tries to deal with 't3', which is not opened.
# That's why '8' is not inserted neither into 't2', nor into 't3'. # That's why '8' is not inserted neither into 't2', nor into 't3'.
# After the task MDEV-5816 be implemented this issue does't exist.
execute stmt using @var; execute stmt using @var;
ERROR 42S02: Table 'test.t3' doesn't exist
call p_verify_reprepare_count(1); call p_verify_reprepare_count(1);
SUCCESS SUCCESS
select * from t2; select * from t2;
a a
5 5
8
select * from t3; select * from t3;
a a
6 6
7 7
60
flush table t1; flush table t1;
set @var=9; set @var=9;
execute stmt using @var; execute stmt using @var;
...@@ -390,11 +394,13 @@ SUCCESS ...@@ -390,11 +394,13 @@ SUCCESS
select * from t2; select * from t2;
a a
5 5
8
9 9
select * from t3; select * from t3;
a a
6 6
7 7
60
drop view v1; drop view v1;
drop table t1,t2,t3; drop table t1,t2,t3;
# Test 7-d: dependent TABLE has changed # Test 7-d: dependent TABLE has changed
......
...@@ -334,17 +334,18 @@ create view v1 as select a from t2; ...@@ -334,17 +334,18 @@ create view v1 as select a from t2;
create trigger t1_ai after insert on t1 for each row create trigger t1_ai after insert on t1 for each row
insert into v1 (a) values (new.a); insert into v1 (a) values (new.a);
--echo # Demonstrate that the same bug is present --echo # Demonstrate that this bug is fixed by MDEV-5816
--echo # without prepared statements --echo # both for regular and prepared statements
insert into t1 (a) values (5); insert into t1 (a) values (5);
select * from t2; select * from t2;
select * from t3; select * from t3;
drop view v1; drop view v1;
create view v1 as select a from t3; create view v1 as select a from t3;
--error ER_NO_SUCH_TABLE # Before MDEV-5816 the following statement would fail
# with the error ER_NO_SUCH_TABLE
insert into t1 (a) values (6); insert into t1 (a) values (6);
flush table t1; flush table t1;
insert into t1 (a) values (6); insert into t1 (a) values (60);
select * from t2; select * from t2;
select * from t3; select * from t3;
...@@ -365,12 +366,13 @@ set @var=8; ...@@ -365,12 +366,13 @@ set @var=8;
--echo # but repreparation of the main statement doesn't cause repreparation --echo # but repreparation of the main statement doesn't cause repreparation
--echo # of trigger statements. --echo # of trigger statements.
--echo # --echo #
--echo # The following EXECUTE results in ER_NO_SUCH_TABLE (t3) error, because --echo # Prior MDEV-5816, the following EXECUTE resulted in
--echo # pre-locking list of the prepared statement has been changed --echo # ER_NO_SUCH_TABLE (t3) error, because pre-locking list of the prepared
--echo # statement has been changed
--echo # (the prepared statement has noticed the meta-data change), --echo # (the prepared statement has noticed the meta-data change),
--echo # but the trigger still tries to deal with 't3', which is not opened. --echo # but the trigger still tries to deal with 't3', which is not opened.
--echo # That's why '8' is not inserted neither into 't2', nor into 't3'. --echo # That's why '8' is not inserted neither into 't2', nor into 't3'.
--error ER_NO_SUCH_TABLE --echo # After the task MDEV-5816 be implemented this issue does't exist.
execute stmt using @var; execute stmt using @var;
call p_verify_reprepare_count(1); call p_verify_reprepare_count(1);
select * from t2; select * from t2;
......
...@@ -6775,7 +6775,7 @@ call p1$ ...@@ -6775,7 +6775,7 @@ call p1$
a a
alter table t1 add b integer$ alter table t1 add b integer$
call p1$ call p1$
a a b
drop table t1; drop table t1;
drop procedure p1; drop procedure p1;
# ------------------------------------------------------------------ # ------------------------------------------------------------------
...@@ -7240,12 +7240,12 @@ create table t1 (a int); ...@@ -7240,12 +7240,12 @@ create table t1 (a int);
insert into t1 (a) values (1), (2), (3), (4), (5); insert into t1 (a) values (1), (2), (3), (4), (5);
# #
# Do we correctly resolve identifiers in LIMIT? # Do we correctly resolve identifiers in LIMIT?
# Since DROP and CREATE did not invalidate # DROP and CREATE results in SP statement recompilation
# the SP cache, we can't test until # so second execution of the procedure p1() doesn't lead
# we drop and re-create the procedure. # to issuing an error
# #
call p1(); call p1();
ERROR 42S22: Unknown column 'test.t1.c1' in 'field list' a
# #
# Drop and recreate the procedure, then repeat # Drop and recreate the procedure, then repeat
# #
......
...@@ -8700,11 +8700,10 @@ create table t1 (a int); ...@@ -8700,11 +8700,10 @@ create table t1 (a int);
insert into t1 (a) values (1), (2), (3), (4), (5); insert into t1 (a) values (1), (2), (3), (4), (5);
--echo # --echo #
--echo # Do we correctly resolve identifiers in LIMIT? --echo # Do we correctly resolve identifiers in LIMIT?
--echo # Since DROP and CREATE did not invalidate --echo # DROP and CREATE results in SP statement recompilation
--echo # the SP cache, we can't test until --echo # so second execution of the procedure p1() doesn't lead
--echo # we drop and re-create the procedure. --echo # to issuing an error
--echo # --echo #
--error ER_BAD_FIELD_ERROR
call p1(); call p1();
--echo # --echo #
--echo # Drop and recreate the procedure, then repeat --echo # Drop and recreate the procedure, then repeat
......
...@@ -1221,7 +1221,6 @@ CREATE PROCEDURE p1 () BEGIN SELECT f1 FROM t1 WHERE f1 IN (SELECT f1 FROM t2); ...@@ -1221,7 +1221,6 @@ CREATE PROCEDURE p1 () BEGIN SELECT f1 FROM t1 WHERE f1 IN (SELECT f1 FROM t2);
delimiter ;| delimiter ;|
CALL p1; CALL p1;
ALTER TABLE t2 CHANGE COLUMN f1 my_column INT; ALTER TABLE t2 CHANGE COLUMN f1 my_column INT;
--error ER_BAD_FIELD_ERROR
CALL p1; CALL p1;
DROP PROCEDURE p1; DROP PROCEDURE p1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
......
...@@ -1472,7 +1472,7 @@ CALL p1; ...@@ -1472,7 +1472,7 @@ CALL p1;
f1 f1
ALTER TABLE t2 CHANGE COLUMN f1 my_column INT; ALTER TABLE t2 CHANGE COLUMN f1 my_column INT;
CALL p1; CALL p1;
ERROR 42S22: Unknown column 'f1' in 'where clause' f1
DROP PROCEDURE p1; DROP PROCEDURE p1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
# #
......
...@@ -1475,7 +1475,7 @@ CALL p1; ...@@ -1475,7 +1475,7 @@ CALL p1;
f1 f1
ALTER TABLE t2 CHANGE COLUMN f1 my_column INT; ALTER TABLE t2 CHANGE COLUMN f1 my_column INT;
CALL p1; CALL p1;
ERROR 42S22: Unknown column 'f1' in 'where clause' f1
DROP PROCEDURE p1; DROP PROCEDURE p1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
# #
......
...@@ -41,8 +41,7 @@ end | ...@@ -41,8 +41,7 @@ end |
call pr(1); call pr(1);
b b
call pr(2); call pr(2);
ERROR 42S22: Unknown column 'test.t1.b' in 'field list' a
drop table t1;
set global stored_program_cache=0; set global stored_program_cache=0;
call pr(1); call pr(1);
b b
......
...@@ -33,9 +33,11 @@ create procedure pr(i int) begin ...@@ -33,9 +33,11 @@ create procedure pr(i int) begin
end | end |
--delimiter ; --delimiter ;
call pr(1); call pr(1);
--error ER_BAD_FIELD_ERROR #--error ER_BAD_FIELD_ERROR
# MDEV-5816 added support for recompilation of statements
# inside a stored routine so the error ER_BAD_FIELD_ERROR is
# no more expcted
call pr(2); call pr(2);
drop table t1;
set global stored_program_cache=0; set global stored_program_cache=0;
call pr(1); call pr(1);
......
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