diff options
Diffstat (limited to 'mysql-test/t')
-rw-r--r-- | mysql-test/t/lock.test | 2 | ||||
-rw-r--r-- | mysql-test/t/mysqldump.test | 1 | ||||
-rw-r--r-- | mysql-test/t/sp.test | 329 |
3 files changed, 263 insertions, 69 deletions
diff --git a/mysql-test/t/lock.test b/mysql-test/t/lock.test index 80da2cad192..faa1fa3ac25 100644 --- a/mysql-test/t/lock.test +++ b/mysql-test/t/lock.test @@ -53,7 +53,7 @@ check table t1; # Check error message lock tables t1 write; check table t2; ---error 1143 +--error 1100 insert into t1 select index1,nr from t1; unlock tables; lock tables t1 write, t1 as t1_alias read; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 3f19c7f0c52..429812eb74b 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -1,6 +1,7 @@ --disable_warnings DROP TABLE IF EXISTS t1, `"t"1`, t1aa,t2aa; drop database if exists mysqldump_test_db; +drop view if exists v1; --enable_warnings # XML output diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index d474fb1c84e..4587d4b6990 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -339,16 +339,15 @@ drop procedure if exists sub1| create procedure sub1(id char(16), x int) insert into test.t1 values (id, x)| -# QQ This doesn't work yet -#--disable_warnings -#drop procedure if exists sub2| -#--enable_warnings -#create procedure sub2(id char(16)) -#begin -# declare x int; -# set x = (select sum(t.x) from test.t2 t); -# insert into test.t1 values (id, x); -#end| +--disable_warnings +drop procedure if exists sub2| +--enable_warnings +create procedure sub2(id char(16)) +begin + declare x int; + set x = (select sum(t.i) from test.t2 t); + insert into test.t1 values (id, x); +end| --disable_warnings drop procedure if exists sub3| @@ -360,11 +359,11 @@ call sub1("sub1a", (select 7))| call sub1("sub1b", (select max(i) from t2))| call sub1("sub1c", (select i,d from t2 limit 1))| call sub1("sub1d", (select 1 from (select 1) a))| -#call sub2("sub2"); +call sub2("sub2"); select * from t1| select sub3((select max(i) from t2))| drop procedure sub1| -#drop procedure sub2| +drop procedure sub2| drop function sub3| delete from t2| @@ -1279,6 +1278,202 @@ drop procedure rc| # +# Let us test how well new locking scheme works. +# + +# Let us prepare playground +--disable_warnings +drop function if exists f0| +drop function if exists f1| +drop function if exists f2| +drop function if exists f3| +drop function if exists f4| +drop function if exists f5| +drop function if exists f6| +drop function if exists f7| +drop function if exists f8| +drop view if exists v0| +drop view if exists v1| +drop view if exists v2| +--enable_warnings +delete from t1| +delete from t2| +insert into t1 values ("a", 1), ("b", 2) | +insert into t2 values ("a", 1, 1.0), ("b", 2, 2.0), ("c", 3, 3.0) | + +# Test the simplest function using tables +create function f1() returns int + return (select sum(data) from t1)| +select f1()| +# This should work too (and give 2 rows as result) +select id, f1() from t1| + +# Function which uses two instances of table simultaneously +create function f2() returns int + return (select data from t1 where data <= (select sum(data) from t1) limit 1)| +select f2()| +select id, f2() from t1| + +# Function which uses the same table twice in different queries +create function f3() returns int +begin + declare n int; + declare m int; + set n:= (select min(data) from t1); + set m:= (select max(data) from t1); + return n < m; +end| +select f3()| +select id, f3() from t1| + +# Calling two functions using same table +select f1(), f3()| +select id, f1(), f3() from t1| + +# Function which uses two different tables +create function f4() returns double + return (select d from t1, t2 where t1.data = t2.i and t1.id= "b")| +select f4()| +select s, f4() from t2| + +# Recursive functions which due to this recursion require simultaneous +# access to several instance of the same table won't work +create function f5(i int) returns int +begin + if i <= 0 then + return 0; + elseif i = 1 then + return (select count(*) from t1 where data = i); + else + return (select count(*) + f5( i - 1) from t1 where data = i); + end if; +end| +select f5(1)| +# This should generate an error about insuficient number of tables locked +--error 1100 +select f5(2)| +# But now it simply miserably fails because we are trying to use the same +# lex on the next iteration :/ It should generate some error too... +# select f5(3)| + +# OTOH this should work +create function f6() returns int +begin + declare n int; + set n:= f1(); + return (select count(*) from t1 where data <= f7() and data <= n); +end| +create function f7() returns int + return (select sum(data) from t1 where data <= f1())| +select f6()| +select id, f6() from t1| + +# TODO Test temporary table handling + +# +# Let us test how new locking work with views +# +# The most trivial view +create view v1 (a) as select f1()| +select * from v1| +select id, a from t1, v1| +select * from v1, v1 as v| +# A bit more complex construction +create view v2 (a) as select a*10 from v1| +select * from v2| +select id, a from t1, v2| +select * from v1, v2| + +# Nice example where the same view is used on +# on different expression levels +create function f8 () returns int + return (select count(*) from v2)| + +select *, f8() from v1| + +# Let us test what will happen if function is missing +drop function f1| +--error 1356 +select * from v1| + +# And what will happen if we have recursion which involves +# views and functions ? +create function f1() returns int + return (select sum(data) from t1) + (select sum(data) from v1)| +# FIXME All these just exceed file limit for me :) +#select f1()| +#select * from v1| +#select * from v2| +# Back to the normal cases +drop function f1| +create function f1() returns int + return (select sum(data) from t1)| + +# Let us also test some weird cases where no real tables is used +create function f0() returns int + return (select * from (select 100) as r)| +select f0()| +select *, f0() from (select 1) as t| +create view v0 as select f0()| +select * from v0| +select *, f0() from v0| + +# +# Let us test how well prelocking works with explicit LOCK TABLES. +# +# Nowdays we have to lock mysql.proc to be able to read SP definitions. +# But Monty was going to fix this. +lock tables t1 read, t1 as t11 read, mysql.proc read| +# These should work well +select f3()| +select id, f3() from t1 as t11| +# Degenerate cases work too :) +select f0()| +select * from v0| +select *, f0() from v0, (select 123) as d1| +# But these should not ! +--error 1100 +select id, f3() from t1| +--error 1100 +select f4()| +unlock tables| + +# Let us test how LOCK TABLES which implicitly depends on functions +# works +lock tables v2 read, mysql.proc read| +select * from v2| +select * from v1| +# These should not work as we have too little instances of tables locked +--error 1100 +select * from v1, v2| +--error 1100 +select f4()| +unlock tables| + + +# TODO We also should test integration with triggers + + +# Cleanup +drop function f0| +drop function f1| +drop function f2| +drop function f3| +drop function f4| +drop function f5| +drop function f6| +drop function f7| +drop function f8| +drop view v0| +drop view v1| +drop view v2| +delete from t1 | +delete from t2 | + +# End of non-bug tests + + +# # Test cases for old bugs # @@ -1453,49 +1648,56 @@ drop procedure bug2260| # # BUG#2267 # ---disable_warnings -drop procedure if exists bug2267_1| ---enable_warnings -create procedure bug2267_1() -begin - show procedure status; -end| - ---disable_warnings -drop procedure if exists bug2267_2| ---enable_warnings -create procedure bug2267_2() -begin - show function status; -end| - ---disable_warnings -drop procedure if exists bug2267_3| ---enable_warnings -create procedure bug2267_3() -begin - show create procedure bug2267_1; -end| - ---disable_warnings -drop procedure if exists bug2267_4| ---enable_warnings -create procedure bug2267_4() -begin - show create function fac; -end| - ---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' -call bug2267_1()| ---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' -call bug2267_2()| -call bug2267_3()| -call bug2267_4()| - -drop procedure bug2267_1| -drop procedure bug2267_2| -drop procedure bug2267_3| -drop procedure bug2267_4| +# NOTE: This test case will be fixed as soon as Monty +# will allow to open mysql.proc table under LOCK TABLES +# without mentioning in lock list. +# +# FIXME: Other solution would be to use preopened proc table +# instead of opening it anew. +# +#--disable_warnings +#drop procedure if exists bug2267_1| +#--enable_warnings +#create procedure bug2267_1() +#begin +# show procedure status; +#end| +# +#--disable_warnings +#drop procedure if exists bug2267_2| +#--enable_warnings +#create procedure bug2267_2() +#begin +# show function status; +#end| +# +#--disable_warnings +#drop procedure if exists bug2267_3| +#--enable_warnings +#create procedure bug2267_3() +#begin +# show create procedure bug2267_1; +#end| +# +#--disable_warnings +#drop procedure if exists bug2267_4| +#--enable_warnings +#create procedure bug2267_4() +#begin +# show create function fac; +#end| +# +#--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +#call bug2267_1()| +#--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +#call bug2267_2()| +#call bug2267_3()| +#call bug2267_4()| +# +#drop procedure bug2267_1| +#drop procedure bug2267_2| +#drop procedure bug2267_3| +#drop procedure bug2267_4| # # BUG#2227 @@ -1529,7 +1731,7 @@ drop procedure bug2227| #--enable_warnings #create procedure bug2614() #begin -# drop table if exists t3; +# drop temporary table if exists t3; # create temporary table t3 (id int default '0' not null); # insert into t3 select 12; # insert into t3 select * from t3; @@ -1539,7 +1741,7 @@ drop procedure bug2227| #call bug2614()| #--enable_warnings #call bug2614()| -#drop table t3| +#drop temporary table t3| #drop procedure bug2614| # @@ -1680,7 +1882,7 @@ begin declare rc int default 0; declare continue handler for 1065 set rc = 1; - drop table if exists temp_t1; + drop temporary table if exists temp_t1; create temporary table temp_t1 ( f1 int auto_increment, f2 varchar(20), primary key (f1) ); @@ -1702,6 +1904,7 @@ call bug1863(10)| select * from t4| drop procedure bug1863| +drop temporary table temp_t1; drop table t3, t4| # @@ -2800,15 +3003,6 @@ drop table t3| drop function getcount| # -# Former BUG#1654 -# QQ Currently crashes -# -#create function bug1654() returns int -# return (select sum(t1.data) from test.t1 t)| -# -#select bug1654()| - -# # BUG#5240: Stored procedure crash if function has cursor declaration # --disable_warnings @@ -2827,7 +3021,6 @@ end| delete from t1| insert into t1 values ("answer", 42)| -# QQ BUG: This returns the wrong result, id=42 instead of "answer". select id, bug5240() from t1| drop function bug5240| |