diff options
Diffstat (limited to 'mysql-test/t')
383 files changed, 49477 insertions, 1541 deletions
diff --git a/mysql-test/t/alias.test b/mysql-test/t/alias.test index 941bc8091fc..6546581eef2 100644 --- a/mysql-test/t/alias.test +++ b/mysql-test/t/alias.test @@ -30,7 +30,7 @@ CREATE TABLE t1 ( prov_hdl_nr int(11) NOT NULL default '0', auto_wirknetz varchar(50) default NULL, auto_billing varchar(50) default NULL, - touch timestamp(14) NOT NULL, + touch timestamp NOT NULL, kategorie varchar(50) default NULL, kundentyp varchar(20) NOT NULL default '', sammel_rech_msisdn varchar(30) NOT NULL default '', @@ -61,7 +61,6 @@ INSERT INTO t1 VALUES (3359361,406,3359361,'Mustermann Musterfrau',7001,'2000-05 INSERT INTO t1 VALUES (3359362,406,3359362,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1509984,2145874,'+','','P',1909154,'MobilComSuper92000D1(Akquise)',NULL,NULL,'MS9ND1',327,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); # This died because we used the field Kundentyp twice - SELECT ELT(FIELD(kundentyp,'PP','PPA','PG','PGA','FK','FKA','FP','FPA','K','KA','V','VA',''), 'Privat (Private Nutzung)','Privat (Private Nutzung) Sitz im Ausland','Privat (geschaeftliche Nutzung)','Privat (geschaeftliche Nutzung) Sitz im Ausland','Firma (Kapitalgesellschaft)','Firma (Kapitalgesellschaft) Sitz im Ausland','Firma (Personengesellschaft)','Firma (Personengesellschaft) Sitz im Ausland','oeff. rechtl. Koerperschaft','oeff. rechtl. Koerperschaft Sitz im Ausland','Eingetragener Verein','Eingetragener Verein Sitz im Ausland','Typ unbekannt') AS Kundentyp ,kategorie FROM t1 WHERE hdl_nr < 2000000 AND kategorie IN ('Prepaid','Mobilfunk') AND st_klasse = 'Workflow' GROUP BY kundentyp ORDER BY kategorie; drop table t1; diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index 9bd34c2a610..cfa6182543b 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -278,7 +278,7 @@ insert into t1 values ('ÔÅÓÔ'); select a,hex(a) from t1; alter table t1 change a a char(10) character set cp1251; select a,hex(a) from t1; -alter table t1 change a a binary(10); +alter table t1 change a a binary(4); select a,hex(a) from t1; alter table t1 change a a char(10) character set cp1251; select a,hex(a) from t1; @@ -338,6 +338,16 @@ alter table t1 drop key a; drop table t1; # +# BUG 12207 alter table ... discard table space on MyISAM table causes ERROR 2013 (HY000) +# +# Some platforms (Mac OS X, Windows) will send the error message using small letters. +CREATE TABLE T12207(a int) ENGINE=MYISAM; +--replace_result t12207 T12207 +--error 1031 +ALTER TABLE T12207 DISCARD TABLESPACE; +DROP TABLE T12207; + +# # Bug #6479 ALTER TABLE ... changing charset fails for TEXT columns # # The column's character set was changed but the actual data was not @@ -365,24 +375,24 @@ drop table t1; # Bug#11493 - Alter table rename to default database does not work without # db name qualifying # -create database mysqltest1; +create database mysqltest; create table t1 (c1 int); # Move table to other database. -alter table t1 rename mysqltest1.t1; +alter table t1 rename mysqltest.t1; # Assure that it has moved. --error 1051 drop table t1; # Move table back. -alter table mysqltest1.t1 rename t1; +alter table mysqltest.t1 rename t1; # Assure that it is back. drop table t1; # Now test for correct message if no database is selected. # Create t1 in 'test'. create table t1 (c1 int); # Change to other db. -use mysqltest1; +use mysqltest; # Drop the current db. This de-selects any db. -drop database mysqltest1; +drop database mysqltest; # Now test for correct message. --error 1046 alter table test.t1 rename t1; @@ -393,3 +403,22 @@ use test; drop table t1; # End of 4.1 tests + +# +# Bug #14693 (ALTER SET DEFAULT doesn't work) +# + +create table t1 (mycol int(10) not null); +alter table t1 alter column mycol set default 0; +desc t1; +drop table t1; + +# +# Bug#6073 "ALTER table minor glich": ALTER TABLE complains that an index +# without # prefix is not allowed for TEXT columns, while index +# is defined with prefix. +# +create table t1 (t varchar(255) default null, key t (t(80))) +engine=myisam default charset=latin1; +alter table t1 change t t text; +drop table t1; diff --git a/mysql-test/t/analyse.test b/mysql-test/t/analyse.test index 88fe8dc55e7..efcf5f6421c 100644 --- a/mysql-test/t/analyse.test +++ b/mysql-test/t/analyse.test @@ -48,6 +48,14 @@ insert into t1 values ('abc'),('abc\'def\\hij\"klm\0opq'),('\''),('\"'),('\\'),( select * from t1 procedure analyse(); drop table t1; +#decimal-related test + +create table t1 (df decimal(5,1)); +insert into t1 values(1.1); +insert into t1 values(2.2); +select * from t1 procedure analyse(); +drop table t1; + # # Bug#10716 - Procedure Analyse results in wrong values for optimal field type # diff --git a/mysql-test/t/analyze.test b/mysql-test/t/analyze.test index a4694c32d3c..7c9830bb468 100644 --- a/mysql-test/t/analyze.test +++ b/mysql-test/t/analyze.test @@ -39,6 +39,20 @@ check table t1; drop table t1; +# Bug #14902 ANALYZE TABLE fails to recognize up-to-date tables +# minimal test case to get an error. +# The problem is happening when analysing table with FT index that +# contains stopwords only. The first execution of analyze table should +# mark index statistics as up to date so that next execution of this +# statement will end up with Table is up to date status. +create table t1 (a mediumtext, fulltext key key1(a)) charset utf8 collate utf8_general_ci engine myisam; +insert into t1 values ('hello'); + +analyze table t1; +analyze table t1; + +drop table t1; + # # procedure in PS BUG#13673 # @@ -47,6 +61,7 @@ prepare stmt1 from "SELECT * FROM t1 PROCEDURE ANALYSE()"; execute stmt1; execute stmt1; deallocate prepare stmt1; +drop table t1; # # bug#15225 (ANALYZE temporary has no effect) diff --git a/mysql-test/t/archive.test b/mysql-test/t/archive.test index 7b3ee45de5f..f712a770712 100644 --- a/mysql-test/t/archive.test +++ b/mysql-test/t/archive.test @@ -1289,16 +1289,6 @@ select fld3 from t2 where (fld3 like "C%" and fld3 = "Chantilly"); select fld1,fld3 from t2 where fld1 like "25050%"; select fld1,fld3 from t2 where fld1 like "25050_"; -# -# Test for insert after select -# -INSERT INTO t2 VALUES (1,000001,00,'Omaha','teethe','neat',''); -INSERT INTO t2 VALUES (2,011401,37,'breaking','dreaded','Steinberg','W'); -INSERT INTO t2 VALUES (3,011402,37,'Romans','scholastics','jarring',''); -INSERT INTO t2 VALUES (4,011403,37,'intercepted','audiology','tinily',''); -SELECT * FROM t2; -OPTIMIZE TABLE t2; -SELECT * FROM t2; # # Test rename of table @@ -1306,14 +1296,38 @@ SELECT * FROM t2; create table t3 engine=archive select * from t2; select * from t3 where fld3='bonfire'; select count(*) from t3; +# Clean up path in error message +--replace_result $MYSQL_TEST_DIR . /var/master-data/ / rename table t3 to t4; select * from t4 where fld3='bonfire'; select count(*) from t4; - # End of 4.1 tests # +# Test for insert after select +# +INSERT INTO t2 VALUES (1,000001,00,'Omaha','teethe','neat',''); +INSERT INTO t2 VALUES (2,011401,37,'breaking','dreaded','Steinberg','W'); +INSERT INTO t2 VALUES (3,011402,37,'Romans','scholastics','jarring',''); +INSERT INTO t2 VALUES (4,011403,37,'intercepted','audiology','tinily',''); +SELECT * FROM t2; +OPTIMIZE TABLE t2; +SELECT * FROM t2; +INSERT INTO t2 VALUES (2,011401,37,'breaking','dreaded','Steinberg','W'); +INSERT INTO t2 VALUES (3,011402,37,'Romans','scholastics','jarring',''); +INSERT INTO t2 VALUES (4,011403,37,'intercepted','audiology','tinily',''); +OPTIMIZE TABLE t2 EXTENDED; +SELECT * FROM t2; +REPAIR TABLE t2; +SELECT * FROM t2; + +# +# Test bulk inserts +INSERT INTO t2 VALUES (1,000001,00,'Omaha','teethe','neat','') , (2,011401,37,'breaking','dreaded','Steinberg','W') , (3,011402,37,'Romans','scholastics','jarring','') , (4,011403,37,'intercepted','audiology','tinily',''); +SELECT * FROM t2; + +# # For bug #12836 # Delete was allowing all rows to be removed --error 1031 @@ -1327,4 +1341,22 @@ SELECT * FROM t2; TRUNCATE TABLE t2; SELECT * FROM t2; +# Adding support for CHECK table +CHECK TABLE t2; +SELECT * FROM t2; + + +# Just test syntax, we will never know if the output is right or wrong +# Must be the last test +INSERT DELAYED INTO t2 VALUES (4,011403,37,'intercepted','audiology','tinily',''); + +# Adding test for alter table +ALTER TABLE t2 DROP COLUMN fld6; +SHOW CREATE TABLE t2; +SELECT * from t2; +# +# Cleanup, test is over +# + + drop table t1, t2, t4; diff --git a/mysql-test/t/archive_gis.test b/mysql-test/t/archive_gis.test new file mode 100644 index 00000000000..ffbad923173 --- /dev/null +++ b/mysql-test/t/archive_gis.test @@ -0,0 +1,3 @@ +--source include/have_archive.inc +SET storage_engine=archive; +--source include/gis_generic.inc diff --git a/mysql-test/t/auto_increment.test b/mysql-test/t/auto_increment.test index 37b92b32bfb..5d22bdd46a0 100644 --- a/mysql-test/t/auto_increment.test +++ b/mysql-test/t/auto_increment.test @@ -256,3 +256,39 @@ select * from t2; drop table t1, t2; --echo End of 4.1 tests + +# +# Bug #11080 & #11005 Multi-row REPLACE fails on a duplicate key error +# + +CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)); +insert into t1 (b) values (1); +replace into t1 (b) values (2), (1), (3); +select * from t1; +truncate table t1; +insert into t1 (b) values (1); +replace into t1 (b) values (2); +replace into t1 (b) values (1); +replace into t1 (b) values (3); +select * from t1; +drop table t1; + +create table t1 (rowid int not null auto_increment, val int not null,primary +key (rowid), unique(val)); +replace into t1 (val) values ('1'),('2'); +replace into t1 (val) values ('1'),('2'); +--error 1062 +insert into t1 (val) values ('1'),('2'); +select * from t1; +drop table t1; + +# +# Test that update changes internal auto-increment value +# + +create table t1 (a int not null auto_increment primary key, val int); +insert into t1 (val) values (1); +update t1 set a=2 where a=1; +insert into t1 (val) values (1); +select * from t1; +drop table t1; diff --git a/mysql-test/t/backup-master.sh b/mysql-test/t/backup-master.sh index 99da5857afe..c099064f6b7 100755 --- a/mysql-test/t/backup-master.sh +++ b/mysql-test/t/backup-master.sh @@ -1,5 +1,5 @@ #!/bin/sh if [ "$MYSQL_TEST_DIR" ] then - rm -f $MYSQL_TEST_DIR/var/tmp/*.frm $MYSQL_TEST_DIR/var/tmp/*.MY? + rm -f $MYSQLTEST_VARDIR/tmp/*.frm $MYSQLTEST_VARDIR/tmp/*.MY? fi diff --git a/mysql-test/t/backup.test b/mysql-test/t/backup.test index b6b3ef1c060..053e83528e0 100644 --- a/mysql-test/t/backup.test +++ b/mysql-test/t/backup.test @@ -1,3 +1,6 @@ +# This test should work in embedded server after we fix mysqltest +-- source include/not_embedded.inc + # # This test is a bit tricky as we can't use backup table to overwrite an old # table @@ -10,10 +13,10 @@ set SQL_LOG_BIN=0; drop table if exists t1, t2, t3; --enable_warnings create table t4(n int); ---replace_result "errno: 1" "errno: X" "errno: 2" "errno: X" "errno: 22" "errno: X" "errno: 23" "errno: X" +--replace_result ": 1" ": X" ": 2" ": X" ": 22" ": X" ": 23" ": X" $MYSQLTEST_VARDIR MYSQLTEST_VARDIR backup table t4 to '../bogus'; backup table t4 to '../tmp'; ---replace_result "errno: 7" "errno: X" "errno: 17" "errno: X" +--replace_result ": 7" ": X" ": 17" ": X" $MYSQLTEST_VARDIR MYSQLTEST_VARDIR backup table t4 to '../tmp'; drop table t4; restore table t4 from '../tmp'; @@ -23,6 +26,7 @@ create table t1(n int); insert into t1 values (23),(45),(67); backup table t1 to '../tmp'; drop table t1; +--replace_result ": 1" ": X" ": 2" ": X" ": 22" ": X" ": 23" ": X" $MYSQLTEST_VARDIR MYSQLTEST_VARDIR restore table t1 from '../bogus'; restore table t1 from '../tmp'; select n from t1; @@ -51,5 +55,6 @@ unlock tables; connection con1; reap; drop table t5; +--system rm $MYSQLTEST_VARDIR/tmp/t?.* # End of 4.1 tests diff --git a/mysql-test/t/bdb.test b/mysql-test/t/bdb.test index de9709b97ad..ec05eeb3c34 100644 --- a/mysql-test/t/bdb.test +++ b/mysql-test/t/bdb.test @@ -42,8 +42,13 @@ update ignore t1 set id=id+1; # This will change all rows select * from t1; update ignore t1 set id=1023 where id=1010; select * from t1 where parent_id=102 order by parent_id,id; +# Here and below the differences in result are caused by difference in +# floating point calculations performed in BDB handler. +--replace_result 5 X 6 X explain select level from t1 where level=1; +--replace_result 5 X 6 X explain select level,id from t1 where level=1; +--replace_result 5 X 6 X explain select level,id,parent_id from t1 where level=1; select level,id from t1 where level=1; select level,id,parent_id from t1 where level=1; @@ -349,6 +354,7 @@ update ignore t1 set id=id+1; # This will change all rows select * from t1; update ignore t1 set id=1023 where id=1010; select * from t1 where parent_id=102; +--replace_result 5 X 6 X explain select level from t1 where level=1; select level,id from t1 where level=1; select level,id,parent_id from t1 where level=1; @@ -395,6 +401,7 @@ set @a:=now(); CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=bdb; insert into t1 (a) values(1),(2),(3); select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a; +select a from t1 natural join t1 as t2 where b >= @a order by a; update t1 set a=5 where a=1; select a from t1; drop table t1; @@ -824,7 +831,7 @@ select a from t1; drop table t1; # -# bug#2686 - index_merge select on BerkeleyDB table with varchar PK causes mysqld to crash +# bug#2686 - index_merge select on BerkeleyDB table with varchar PK crashes # create table t1( @@ -842,7 +849,8 @@ select substring(pk1, 1, 4), substring(pk1, 4001), drop table t1; # -# bug#2688 - Wrong index_merge query results for BDB table with variable length primary key +# bug#2688 - Wrong index_merge query results for BDB table with +# variable length primary key # create table t1 ( @@ -949,3 +957,101 @@ select count(*) from t1; drop table t1, t2; --echo End of 4.1 tests + +# +# alter temp table +# +create temporary table t1 (a int, primary key(a)) engine=bdb; +select * from t1; +alter table t1 add b int; +select * from t1; +drop table t1; + + +# +# Test varchar +# + +let $default=`select @@storage_engine`; +set storage_engine=bdb; +source include/varchar.inc; + +# +# Some errors/warnings on create +# + +--replace_result 1024 MAX_KEY_LENGTH 3072 MAX_KEY_LENGTH +create table t1 (v varchar(65530), key(v)); +drop table if exists t1; +create table t1 (v varchar(65536)); +show create table t1; +drop table t1; +create table t1 (v varchar(65530) character set utf8); +show create table t1; +drop table t1; + +# End varchar test +eval set storage_engine=$default; + +# +# Test that we can create a large key +# +create table t1 (a varchar(255) character set utf8, + b varchar(255) character set utf8, + c varchar(255) character set utf8, + d varchar(255) character set utf8, + key (a,b,c,d)) engine=bdb; +drop table t1; +--error ER_TOO_LONG_KEY +create table t1 (a varchar(255) character set utf8, + b varchar(255) character set utf8, + c varchar(255) character set utf8, + d varchar(255) character set utf8, + e varchar(255) character set utf8, + key (a,b,c,d,e)) engine=bdb; + +# +# Bug #14212: Server crash after COMMIT + ALTER TABLE +# +set autocommit=0; +create table t1 (a int) engine=bdb; +commit; +alter table t1 add primary key(a); +drop table t1; + + +# +# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode +# +set autocommit=1; + +let $VERSION=`select version()`; + +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +set autocommit=0; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/bdb_gis.test b/mysql-test/t/bdb_gis.test new file mode 100644 index 00000000000..88dcbb7cbe9 --- /dev/null +++ b/mysql-test/t/bdb_gis.test @@ -0,0 +1,3 @@ +-- source include/have_bdb.inc +SET storage_engine=bdb; +--source include/gis_generic.inc diff --git a/mysql-test/t/bigint.test b/mysql-test/t/bigint.test index 8a238d33e08..35cda11646a 100644 --- a/mysql-test/t/bigint.test +++ b/mysql-test/t/bigint.test @@ -2,7 +2,7 @@ # Initialize --disable_warnings -drop table if exists t1; +drop table if exists t1, t2; --enable_warnings # @@ -35,21 +35,27 @@ drop table t1; create table t1 ( a int not null default 1, big bigint ); insert into t1 (big) values (-1),(12345678901234567),(9223372036854775807),(18446744073709551615); +select * from t1; select min(big),max(big),max(big)-1 from t1; select min(big),max(big),max(big)-1 from t1 group by a; alter table t1 modify big bigint unsigned not null; select min(big),max(big),max(big)-1 from t1; select min(big),max(big),max(big)-1 from t1 group by a; +insert into t1 (big) values (18446744073709551615); +select * from t1; +select min(big),max(big),max(big)-1 from t1; +select min(big),max(big),max(big)-1 from t1 group by a; alter table t1 add key (big); select min(big),max(big),max(big)-1 from t1; select min(big),max(big),max(big)-1 from t1 group by a; alter table t1 modify big bigint not null; +select * from t1; select min(big),max(big),max(big)-1 from t1; select min(big),max(big),max(big)-1 from t1 group by a; drop table t1; # -# Test problem with big values fir auto_increment +# Test problem with big values for auto_increment # create table t1 (id bigint auto_increment primary key, a int) auto_increment=9999999999; @@ -108,3 +114,168 @@ t2.value64=t1.value64; drop table t1, t2; # End of 4.1 tests + +# +# Test of CREATE ... SELECT and unsigned integers +# + +create table t1 select 1 as 'a'; +show create table t1; +drop table t1; +create table t1 select 9223372036854775809 as 'a'; +show create table t1; +select * from t1; +drop table t1; +DROP DATABASE IF EXISTS `scott`; + + +# +# Check various conversions from/to unsigned bigint. +# + +create table t1 (a char(100), b varchar(100), c text, d blob); +insert into t1 values( + 18446744073709551615,18446744073709551615, + 18446744073709551615, 18446744073709551615 +); + +insert into t1 values (-1 | 0,-1 | 0,-1 | 0 ,-1 | 0); +select * from t1; +drop table t1; + +create table t1 ( quantity decimal(2) unsigned); +insert into t1 values (500), (-500), (~0), (-1); +select * from t1; +drop table t1; + +# +# Test of storing decimal values in BIGINT range +# (Bug #12750: Incorrect storage of 9999999999999999999 in DECIMAL(19, 0)) +# + +CREATE TABLE t1 ( + `col1` INT(1) NULL, + `col2` INT(2) NULL, + `col3` INT(3) NULL, + `col4` INT(4) NULL, + `col5` INT(5) NULL, + `col6` INT(6) NULL, + `col7` INT(7) NULL, + `col8` INT(8) NULL, + `col9` INT(9) NULL, + `col10` BIGINT(10) NULL, + `col11` BIGINT(11) NULL, + `col12` BIGINT(12) NULL, + `col13` BIGINT(13) NULL, + `col14` BIGINT(14) NULL, + `col15` BIGINT(15) NULL, + `col16` BIGINT(16) NULL, + `col17` BIGINT(17) NULL, + `col18` BIGINT(18) NULL, + `col19` DECIMAL(19, 0) NULL, + `col20` DECIMAL(20, 0) NULL, + `col21` DECIMAL(21, 0) NULL, + `col22` DECIMAL(22, 0) NULL, + `col23` DECIMAL(23, 0) NULL, + `col24` DECIMAL(24, 0) NULL, + `col25` DECIMAL(25, 0) NULL, + `col26` DECIMAL(26, 0) NULL, + `col27` DECIMAL(27, 0) NULL, + `col28` DECIMAL(28, 0) NULL, + `col29` DECIMAL(29, 0) NULL, + `col30` DECIMAL(30, 0) NULL, + `col31` DECIMAL(31, 0) NULL, + `col32` DECIMAL(32, 0) NULL, + `col33` DECIMAL(33, 0) NULL, + `col34` DECIMAL(34, 0) NULL, + `col35` DECIMAL(35, 0) NULL, + `col36` DECIMAL(36, 0) NULL, + `col37` DECIMAL(37, 0) NULL, + `col38` DECIMAL(38, 0) NULL, + `fix1` DECIMAL(38, 1) NULL, + `fix2` DECIMAL(38, 2) NULL, + `fix3` DECIMAL(38, 3) NULL, + `fix4` DECIMAL(38, 4) NULL, + `fix5` DECIMAL(38, 5) NULL, + `fix6` DECIMAL(38, 6) NULL, + `fix7` DECIMAL(38, 7) NULL, + `fix8` DECIMAL(38, 8) NULL, + `fix9` DECIMAL(38, 9) NULL, + `fix10` DECIMAL(38, 10) NULL, + `fix11` DECIMAL(38, 11) NULL, + `fix12` DECIMAL(38, 12) NULL, + `fix13` DECIMAL(38, 13) NULL, + `fix14` DECIMAL(38, 14) NULL, + `fix15` DECIMAL(38, 15) NULL, + `fix16` DECIMAL(38, 16) NULL, + `fix17` DECIMAL(38, 17) NULL, + `fix18` DECIMAL(38, 18) NULL, + `fix19` DECIMAL(38, 19) NULL, + `fix20` DECIMAL(38, 20) NULL, + `fix21` DECIMAL(38, 21) NULL, + `fix22` DECIMAL(38, 22) NULL, + `fix23` DECIMAL(38, 23) NULL, + `fix24` DECIMAL(38, 24) NULL, + `fix25` DECIMAL(38, 25) NULL, + `fix26` DECIMAL(38, 26) NULL, + `fix27` DECIMAL(38, 27) NULL, + `fix28` DECIMAL(38, 28) NULL, + `fix29` DECIMAL(38, 29) NULL, + `fix30` DECIMAL(38, 30) NULL +); + +INSERT INTO t1(`col1`, `col2`, `col3`, `col4`, `col5`, `col6`, `col7`, `col8`, `col9`, `col10`, `col11`, `col12`, `col13`, `col14`, `col15`, `col16`, `col17`, `col18`, `col19`, `col20`, `col21`, `col22`, `col23`, `col24`, `col25`, `col26`, `col27`, `col28`, `col29`, `col30`, `col31`, `col32`, `col33`, `col34`, `col35`, `col36`, `col37`, `col38`, `fix1`, `fix2`, `fix3`, `fix4`, `fix5`, `fix6`, `fix7`, `fix8`, `fix9`, `fix10`, `fix11`, `fix12`, `fix13`, `fix14`, `fix15`, `fix16`, `fix17`, `fix18`, `fix19`, `fix20`, `fix21`, `fix22`, `fix23`, `fix24`, `fix25`, `fix26`, `fix27`, `fix28`, `fix29`, `fix30`) +VALUES (9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, +9999999999, 99999999999, 999999999999, 9999999999999, 99999999999999, +999999999999999, 9999999999999999, 99999999999999999, 999999999999999999, +9999999999999999999, 99999999999999999999, 999999999999999999999, +9999999999999999999999, 99999999999999999999999, 999999999999999999999999, +9999999999999999999999999, 99999999999999999999999999, +999999999999999999999999999, 9999999999999999999999999999, +99999999999999999999999999999, 999999999999999999999999999999, +9999999999999999999999999999999, 99999999999999999999999999999999, +999999999999999999999999999999999, 9999999999999999999999999999999999, +99999999999999999999999999999999999, 999999999999999999999999999999999999, +9999999999999999999999999999999999999, 99999999999999999999999999999999999999, +9999999999999999999999999999999999999.9, +999999999999999999999999999999999999.99, +99999999999999999999999999999999999.999, +9999999999999999999999999999999999.9999, +999999999999999999999999999999999.99999, +99999999999999999999999999999999.999999, +9999999999999999999999999999999.9999999, +999999999999999999999999999999.99999999, +99999999999999999999999999999.999999999, +9999999999999999999999999999.9999999999, +999999999999999999999999999.99999999999, +99999999999999999999999999.999999999999, +9999999999999999999999999.9999999999999, +999999999999999999999999.99999999999999, +99999999999999999999999.999999999999999, +9999999999999999999999.9999999999999999, +999999999999999999999.99999999999999999, +99999999999999999999.999999999999999999, +9999999999999999999.9999999999999999999, +999999999999999999.99999999999999999999, +99999999999999999.999999999999999999999, +9999999999999999.9999999999999999999999, +999999999999999.99999999999999999999999, +99999999999999.999999999999999999999999, +9999999999999.9999999999999999999999999, +999999999999.99999999999999999999999999, +99999999999.999999999999999999999999999, +9999999999.9999999999999999999999999999, +999999999.99999999999999999999999999999, +99999999.999999999999999999999999999999); + +SELECT * FROM t1; +DROP TABLE t1; + +#bug #9088 BIGINT WHERE CLAUSE +create table t1 (bigint_col bigint unsigned); +insert into t1 values (17666000000000000000); +select * from t1 where bigint_col=17666000000000000000; +select * from t1 where bigint_col='17666000000000000000'; +drop table t1; + + diff --git a/mysql-test/t/binary.test b/mysql-test/t/binary.test index 02773b32302..4ab6ee9eaf1 100644 --- a/mysql-test/t/binary.test +++ b/mysql-test/t/binary.test @@ -56,7 +56,7 @@ drop table t1; # # Test of binary and upper/lower # -create table t1 (a char(15) binary, b binary(15)); +create table t1 (a char(3) binary, b binary(3)); insert into t1 values ('aaa','bbb'),('AAA','BBB'); select upper(a),upper(b) from t1; select lower(a),lower(b) from t1; @@ -89,3 +89,15 @@ show create table t1; drop table t1; # End of 4.1 tests + +# +# Bug#16857 +# +create table t1 (col1 binary(4)); +insert into t1 values ('a'),('a '); +select hex(col1) from t1; +alter table t1 modify col1 binary(10); +select hex(col1) from t1; +insert into t1 values ('b'),('b '); +select hex(col1) from t1; +drop table t1; diff --git a/mysql-test/t/binlog-master.opt b/mysql-test/t/binlog-master.opt new file mode 100644 index 00000000000..ad2c6a647b5 --- /dev/null +++ b/mysql-test/t/binlog-master.opt @@ -0,0 +1 @@ +-O max_binlog_size=4096 diff --git a/mysql-test/t/binlog.test b/mysql-test/t/binlog.test new file mode 100644 index 00000000000..1063940d378 --- /dev/null +++ b/mysql-test/t/binlog.test @@ -0,0 +1,49 @@ +# +# misc binlogging tests that do not require a slave running +# +-- source include/not_embedded.inc +-- source include/have_bdb.inc +-- source include/have_innodb.inc + +--disable_warnings +drop table if exists t1, t2; +--enable_warnings +reset master; + +create table t1 (a int) engine=bdb; +create table t2 (a int) engine=innodb; +begin; +insert t1 values (5); +commit; +begin; +insert t2 values (5); +commit; +# first COMMIT must be Query_log_event, second - Xid_log_event +--replace_result "xid=21" "xid=12" +--replace_column 2 # 5 # +show binlog events from 98; +drop table t1,t2; + +# +# binlog rotation after one big transaction +# +reset master; +let $1=100; + +create table t1 (n int) engine=innodb; +begin; +--disable_query_log +while ($1) +{ + eval insert into t1 values($1 + 4); + dec $1; +} +--enable_query_log +commit; +drop table t1; +--replace_result "xid=32" "xid=19" +--replace_column 2 # 5 # +show binlog events in 'master-bin.000001' from 98; +--replace_column 2 # 5 # +show binlog events in 'master-bin.000002' from 98; + diff --git a/mysql-test/t/blackhole.test b/mysql-test/t/blackhole.test index 257770d311c..e40b84eb5cd 100644 --- a/mysql-test/t/blackhole.test +++ b/mysql-test/t/blackhole.test @@ -2,6 +2,7 @@ # Simple test for blackhole example # Taken from the select test # +-- source include/not_embedded.inc -- source include/have_blackhole.inc --disable_warnings @@ -108,7 +109,7 @@ insert into t1 values(1); insert ignore into t1 values(1); replace into t1 values(100); create table t2 (a varchar(200)) engine=blackhole; -load data infile '../../std_data/words.dat' into table t2; +load data infile '../std_data_ln/words.dat' into table t2; alter table t1 add b int; alter table t1 drop b; create table t3 like t1; diff --git a/mysql-test/t/bool.test b/mysql-test/t/bool.test index 67b9eeaeb94..34c51c648d3 100644 --- a/mysql-test/t/bool.test +++ b/mysql-test/t/bool.test @@ -20,6 +20,16 @@ SELECT * FROM t1 where (1 AND a)=0; SELECT * FROM t1 where (1 AND a)=1; SELECT * FROM t1 where (1 AND a) IS NULL; +# WL#638 - Behaviour of NOT does not follow SQL specification +set sql_mode='high_not_precedence'; +select * from t1 where not a between 2 and 3; +set sql_mode=default; +select * from t1 where not a between 2 and 3; + +# SQL boolean tests +select a, a is false, a is true, a is unknown from t1; +select a, a is not false, a is not true, a is not unknown from t1; + # Verify that NULL optimisation works in AND clause: SET @a=0, @b=0; SELECT * FROM t1 WHERE NULL AND (@a:=@a+1); diff --git a/mysql-test/t/case.test b/mysql-test/t/case.test index fd1b6e5247f..0e9e141f6d8 100644 --- a/mysql-test/t/case.test +++ b/mysql-test/t/case.test @@ -58,7 +58,10 @@ CREATE TABLE t1 SELECT CASE WHEN 1 THEN 1.0 ELSE 'a' END AS c6, CASE WHEN 1 THEN 1 ELSE 1.0 END AS c7, CASE WHEN 1 THEN 1.0 ELSE 1 END AS c8, - CASE WHEN 1 THEN 1.0 END AS c9 + CASE WHEN 1 THEN 1.0 END AS c9, + CASE WHEN 1 THEN 0.1e1 else 0.1 END AS c10, + CASE WHEN 1 THEN 0.1e1 else 1 END AS c11, + CASE WHEN 1 THEN 0.1e1 else '1' END AS c12 ; SHOW CREATE TABLE t1; DROP TABLE t1; @@ -130,4 +133,23 @@ select min(a), min(case when 1=1 then a else NULL end), from t1 where b=3 group by b; drop table t1; + +# +# Tests for bug #9939: conversion of the arguments for COALESCE and IFNULL +# + +CREATE TABLE t1 (EMPNUM INT); +INSERT INTO t1 VALUES (0), (2); +CREATE TABLE t2 (EMPNUM DECIMAL (4, 2)); +INSERT INTO t2 VALUES (0.0), (9.0); + +SELECT COALESCE(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM, + t1.EMPNUM AS EMPMUM1, t2.EMPNUM AS EMPNUM2 + FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM; + +SELECT IFNULL(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM, + t1.EMPNUM AS EMPMUM1, t2.EMPNUM AS EMPNUM2 + FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM; + +DROP TABLE t1,t2; # End of 4.1 tests diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index b214cef10fa..ecc92ed01d1 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -4,6 +4,7 @@ select CAST(1-2 AS UNSIGNED); select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER); +select CAST('10 ' as unsigned integer); select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1; select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1; select ~5, cast(~5 as signed); @@ -15,6 +16,12 @@ select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A"; select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME); select cast("1:2:3" as TIME); select CONVERT("2004-01-22 21:45:33",DATE); +select 10+'10'; +select 10.0+'10'; +select 10E+0+'10'; + +# The following cast creates warnings + select CONVERT(DATE "2004-01-22 21:45:33" USING latin1); select CONVERT(DATE "2004-01-22 21:45:33",CHAR); select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4)); @@ -24,6 +31,11 @@ select CAST(0xb3 as signed); select CAST(0x8fffffffffffffff as signed); select CAST(0xffffffffffffffff as unsigned); select CAST(0xfffffffffffffffe as signed); +select cast('-10a' as signed integer); +select cast('a10' as unsigned integer); +select 10+'a'; +select 10.0+cast('a' as decimal); +select 10E+0+'a'; # out-of-range cases select cast('18446744073709551616' as unsigned); @@ -52,7 +64,8 @@ select cast(_latin1'a ' AS char) as c2, cast(_latin1'abc' AS char(2)) as c3, cast(_latin1'a ' AS char(2)) as c4, - cast(_latin1'a' AS char(2)) as c5; + hex(cast(_latin1'a' AS char(2))) as c5; +select cast(1000 as CHAR(3)); create table t1 select cast(_latin1'ab' AS char) as c1, @@ -60,7 +73,7 @@ create table t1 select cast(_latin1'abc' AS char(2)) as c3, cast(_latin1'a ' AS char(2)) as c4, cast(_latin1'a' AS char(2)) as c5; -select * from t1; +select c1,c2,c3,c4,hex(c5) from t1; show create table t1; drop table t1; @@ -88,7 +101,7 @@ drop table t1; # Bug 2202 # CAST from BINARY to non-BINARY and from non-BINARY to BINARY # -create table t1 (a binary(10), b char(10) character set koi8r); +create table t1 (a binary(4), b char(4) character set koi8r); insert into t1 values (_binary'ÔÅÓÔ',_binary'ÔÅÓÔ'); select a,b,cast(a as char character set cp1251),cast(b as binary) from t1; set names koi8r; @@ -148,12 +161,6 @@ select cast(repeat('1',20) as unsigned); select cast(repeat('1',20) as signed); # -# Bug#8663 cant use bgint unsigned as input to cast -# -select cast(19999999999999999999 as unsigned); - - -# # Bug #13344: cast of large decimal to signed int not handled correctly # select cast(1.0e+300 as signed int); @@ -164,7 +171,52 @@ select cast(1.0e+300 as signed int); CREATE TABLE t1 (f1 double); INSERT INTO t1 SET f1 = -1.0e+30 ; INSERT INTO t1 SET f1 = +1.0e+30 ; +# Expected result is +-1e+30, but Windows returns +-1e+030. +--replace_result 1e+030 1e+30 SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1; DROP TABLE t1; # End of 4.1 tests + + +#decimal-related additions +select cast('1.2' as decimal(3,2)); +select 1e18 * cast('1.2' as decimal(3,2)); +select cast(cast('1.2' as decimal(3,2)) as signed); +set @v1=1e18; +select cast(@v1 as decimal(22, 2)); +select cast(-1e18 as decimal(22,2)); + +create table t1(s1 time); +insert into t1 values ('11:11:11'); +select cast(s1 as decimal(7,2)) from t1; +drop table t1; + +# +# Test for bug #11283: field conversion from varchar, and text types to decimal +# + +CREATE TABLE t1 (v varchar(10), tt tinytext, t text, + mt mediumtext, lt longtext); +INSERT INTO t1 VALUES ('1.01', '2.02', '3.03', '4.04', '5.05'); + +SELECT CAST(v AS DECIMAL), CAST(tt AS DECIMAL), CAST(t AS DECIMAL), + CAST(mt AS DECIMAL), CAST(lt AS DECIMAL) from t1; + +DROP TABLE t1; + +# +# Bug #10237 (CAST(NULL DECIMAL) crashes server) +# +select cast(NULL as decimal(6)) as t1; + + +# +# Bug #17903: cast to char results in binary +# +set names latin1; +select hex(cast('a' as char(2) binary)); +select hex(cast('a' as binary(2))); +select hex(cast('a' as char(2) binary)); + +--echo End of 5.0 tests diff --git a/mysql-test/t/check.test b/mysql-test/t/check.test index 4ce2cb04a3b..8d9d70bd29a 100644 --- a/mysql-test/t/check.test +++ b/mysql-test/t/check.test @@ -23,3 +23,16 @@ reap; drop table t1; # End of 4.1 tests + +# +# Bug #9897 Views: 'Check Table' crashes MySQL, with a view and a table +# in the statement +# + +connection default; +Create table t1(f1 int); +Create table t2(f1 int); +Create view v1 as Select * from t1; +Check Table v1,t2; +drop view v1; +drop table t1, t2; diff --git a/mysql-test/t/client_xml.test b/mysql-test/t/client_xml.test new file mode 100644 index 00000000000..017b7a1569a --- /dev/null +++ b/mysql-test/t/client_xml.test @@ -0,0 +1,21 @@ +# Can't run with embedded server +-- source include/not_embedded.inc + +# Test of the xml output of the 'mysql' and 'mysqldump' clients -- makes +# sure that basic encoding issues are handled properly +create table t1 ( + `a&b` int, + `a<b` int, + `a>b` text +); +insert into t1 values (1, 2, 'a&b a<b a>b'); +--exec $MYSQL --xml test -e "select * from t1" +--exec $MYSQL_DUMP --xml --skip-create test + +--exec $MYSQL --xml test -e "select count(*) from t1" +--exec $MYSQL --xml test -e "select 1 < 2 from dual" +--exec $MYSQL --xml test -e "select 1 > 2 from dual" +--exec $MYSQL --xml test -e "select 1 & 3 from dual" +--exec $MYSQL --xml test -e "select null from dual" + +drop table t1; diff --git a/mysql-test/t/compare.test b/mysql-test/t/compare.test index a42ba5ac88a..337035a8095 100644 --- a/mysql-test/t/compare.test +++ b/mysql-test/t/compare.test @@ -37,3 +37,12 @@ SELECT CHAR(31) = '', '' = CHAR(31); SELECT CHAR(30) = '', '' = CHAR(30); # End of 4.1 tests + +# +#Bug #21159: Optimizer: wrong result after AND with different data types +# +create table t1 (a tinyint(1),b binary(1)); +insert into t1 values (0x01,0x01); +select * from t1 where a=b; +select * from t1 where a=b and b=0x01; +drop table if exists t1; diff --git a/mysql-test/t/compress.test b/mysql-test/t/compress.test new file mode 100644 index 00000000000..3f1892b5dec --- /dev/null +++ b/mysql-test/t/compress.test @@ -0,0 +1,18 @@ +# Turn on compression between the client and server +# and run a number of tests + +# Can't test with embedded server +-- source include/not_embedded.inc + +-- source include/have_compress.inc + +connect (comp_con,localhost,root,,,,,COMPRESS); + +# Check compression turned on +SHOW STATUS LIKE 'Compression'; + +# Source select test case +-- source include/common-tests.inc + +# Check compression turned on +SHOW STATUS LIKE 'Compression'; diff --git a/mysql-test/t/connect.test b/mysql-test/t/connect.test index 89e34f0c8e0..2147d5b71af 100644 --- a/mysql-test/t/connect.test +++ b/mysql-test/t/connect.test @@ -57,7 +57,7 @@ connect (con10,localhost,test,gambling2,); connect (con5,localhost,test,gambling2,mysql); connection con5; set password=""; ---error 1105 +--error 1372 set password='gambling3'; set password=old_password('gambling3'); show tables; diff --git a/mysql-test/t/count_distinct.test b/mysql-test/t/count_distinct.test index 8e3ca7025b4..e63bdabdb95 100644 --- a/mysql-test/t/count_distinct.test +++ b/mysql-test/t/count_distinct.test @@ -56,3 +56,24 @@ select count(distinct f) from t1; drop table t1; # End of 4.1 tests + +# +# Bug #6515 +# + +create table t1 (a char(3), b char(20), primary key (a, b)); +insert into t1 values ('ABW', 'Dutch'), ('ABW', 'English'); +select count(distinct a) from t1 group by b; +drop table t1; + +# +# Bug #9593 "The combination of COUNT, DISTINCT and CONCAT +# seems to lock the server" +# Bug appears only on Windows system +# + +create table t1 (f1 int, f2 int); +insert into t1 values (0,1),(1,2); +select count(distinct if(f1,3,f2)) from t1; +drop table t1; + diff --git a/mysql-test/t/count_distinct2.test b/mysql-test/t/count_distinct2.test index dd43fe6f7ba..8dcb2a70065 100644 --- a/mysql-test/t/count_distinct2.test +++ b/mysql-test/t/count_distinct2.test @@ -64,7 +64,7 @@ select count(distinct n) from t1; show status like 'Created_tmp_disk_tables'; drop table t1; -#test conversion from heap to MyISAM +# Test use of MyISAM tmp tables create table t1 (s text); let $1=5000; disable_query_log; diff --git a/mysql-test/t/count_distinct3.test b/mysql-test/t/count_distinct3.test index 9c3e7f439c2..f817b2c635d 100644 --- a/mysql-test/t/count_distinct3.test +++ b/mysql-test/t/count_distinct3.test @@ -9,7 +9,6 @@ DROP TABLE IF EXISTS t1, t2; CREATE TABLE t1 (id INTEGER, grp TINYINT, id_rev INTEGER); ---disable_warnings --disable_query_log SET @rnd_max= 2147483647; let $1 = 1000; @@ -18,7 +17,7 @@ while ($1) SET @rnd= RAND(); SET @id = CAST(@rnd * @rnd_max AS UNSIGNED); SET @id_rev= @rnd_max - @id; - SET @grp= CAST(128.0 * @rnd AS UNSIGNED); + SET @grp= CAST(127.0 * @rnd AS UNSIGNED); INSERT INTO t1 (id, grp, id_rev) VALUES (@id, @grp, @id_rev); dec $1; } @@ -44,7 +43,6 @@ INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2; INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1; DROP TABLE t2; --enable_query_log ---enable_warnings SELECT COUNT(*) FROM t1; diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 57b16a13c01..91c22001b6c 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -49,14 +49,25 @@ create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int); # -# Some wrong defaults, so these creates should fail too +# Some wrong defaults, so these creates should fail too (Bug #5902) # --error 1067 -create table test (a datetime default now()); +create table t1 (a datetime default now()); --error 1294 -create table test (a datetime on update now()); +create table t1 (a datetime on update now()); --error 1067 -create table test (a int default 100 auto_increment); +create table t1 (a int default 100 auto_increment); +--error 1067 +create table t1 (a tinyint default 1000); +--error 1067 +create table t1 (a varchar(5) default 'abcdef'); + +create table t1 (a varchar(5) default 'abcde'); +insert into t1 values(); +select * from t1; +--error 1067 +alter table t1 alter column a set default 'abcdef'; +drop table t1; # # test of dummy table names @@ -266,8 +277,8 @@ create table t3 like t1; show create table t3; select * from t3; # Disable PS becasue of @@warning_count ---disable_ps_protocol create table if not exists t3 like t1; +--disable_ps_protocol select @@warning_count; --enable_ps_protocol create temporary table t3 like t2; @@ -489,8 +500,7 @@ drop table t1,t2; # Bug #12537: UNION produces longtext instead of varchar # CREATE TABLE t1 (f1 VARCHAR(255) CHARACTER SET utf8); -CREATE TABLE t2 AS SELECT LEFT(f1,86) AS f2 FROM t1 UNION SELECT LEFT(f1,86) -AS f2 FROM t1; +CREATE TABLE t2 AS SELECT LEFT(f1,171) AS f2 FROM t1 UNION SELECT LEFT(f1,171) AS f2 FROM t1; DESC t2; DROP TABLE t1,t2; @@ -507,13 +517,22 @@ DROP TABLE t12913; create database mysqltest; use mysqltest; drop database mysqltest; ---error 1102 +--error ER_NO_DB_ERROR create table test.t1 like x; --disable_warnings drop table if exists test.t1; --enable_warnings # +# Bug #6859: Bogus error message on attempt to CREATE TABLE t LIKE view +# +create database mysqltest; +use mysqltest; +create view v1 as select 'foo' from dual; +--error 1347 +create table t1 like v1; +drop view v1; +drop database mysqltest; # Bug #6008 MySQL does not create warnings when # creating database and using IF NOT EXISTS # @@ -531,6 +550,7 @@ create table t1 ( a varchar(112) charset utf8 collate utf8_bin not null, primary key (a) ) select 'test' as a ; +--warning 1364 show create table t1; drop table t1; @@ -543,6 +563,7 @@ CREATE TABLE t2 ( ); insert into t2 values(111); +--warning 1364 create table t1 ( a varchar(12) charset utf8 collate utf8_bin not null, b int not null, primary key (a) @@ -550,6 +571,23 @@ create table t1 ( show create table t1; drop table t1; +--warning 1364 +create table t1 ( + a varchar(12) charset utf8 collate utf8_bin not null, + b int not null, primary key (a) +) select a, 1 as c from t2 ; +show create table t1; +drop table t1; + +--warning 1364 +create table t1 ( + a varchar(12) charset utf8 collate utf8_bin not null, + b int null, primary key (a) +) select a, 1 as c from t2 ; +show create table t1; +drop table t1; + +--warning 1364 create table t1 ( a varchar(12) charset utf8 collate utf8_bin not null, b int not null, primary key (a) @@ -557,6 +595,7 @@ create table t1 ( show create table t1; drop table t1; +--warning 1364 create table t1 ( a varchar(12) charset utf8 collate utf8_bin, b int not null, primary key (a) @@ -570,6 +609,7 @@ create table t1 ( ); insert into t1 values (1,1,1, 1,1,1, 1,1,1); +--warning 1364 create table t2 ( a1 varchar(12) charset utf8 collate utf8_bin not null, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, @@ -577,17 +617,20 @@ create table t2 ( ) select a1,a2,a3,a4,a5,a6,a7,a8,a9 from t1 ; drop table t2; +--warning 1364 create table t2 ( a1 varchar(12) charset utf8 collate utf8_bin, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int ) select a1,a2,a3,a4,a5,a6,a7,a8,a9 from t1; drop table t1, t2; +--warning 1364 create table t1 ( a1 int, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int ); insert into t1 values (1,1,1, 1,1,1, 1,1,1); +--warning 1364 create table t2 ( a1 varchar(12) charset utf8 collate utf8_bin not null, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, @@ -606,7 +649,27 @@ drop table t1, t2; # # Bug #15316 SET value having comma not correctly handled # ---error 1105 +--error 1367 create table t1(a set("a,b","c,d") not null); # End of 4.1 tests + +# +# Bug #14155: Maximum value of MAX_ROWS handled incorrectly on 64-bit +# platforms +# +create table t1 (i int) engine=myisam max_rows=100000000000; +show create table t1; +alter table t1 max_rows=100; +show create table t1; +alter table t1 max_rows=100000000000; +show create table t1; +drop table t1; + +# +# Bug#21772: can not name a column 'upgrade' when create a table +# +create table t1 (upgrade int); +drop table t1; + +# End of 5.0 tests diff --git a/mysql-test/t/create_not_windows.test b/mysql-test/t/create_not_windows.test new file mode 100644 index 00000000000..71ad9ccd7fe --- /dev/null +++ b/mysql-test/t/create_not_windows.test @@ -0,0 +1,20 @@ +# Non-windows specific create tests. + +--source include/not_windows.inc + +# +# Bug#19479:mysqldump creates invalid dump +# +--disable_warnings +drop table if exists `about:text`; +--enable_warnings +create table `about:text` ( +_id int not null auto_increment, +`about:text` varchar(255) not null default '', +primary key (_id) +); + +show create table `about:text`; +drop table `about:text`; + +# End of 5.0 tests diff --git a/mysql-test/t/create_select_tmp.test b/mysql-test/t/create_select_tmp.test index 1661a115f72..c527548e282 100644 --- a/mysql-test/t/create_select_tmp.test +++ b/mysql-test/t/create_select_tmp.test @@ -27,5 +27,6 @@ select * from t2; CREATE TEMPORARY TABLE t2 ( PRIMARY KEY (a) ) ENGINE=MYISAM SELECT a FROM t1; --error 1146 select * from t2; +drop table t1; # End of 4.1 tests diff --git a/mysql-test/t/csv.test b/mysql-test/t/csv.test index e78c2ccc578..65173cbf355 100644 --- a/mysql-test/t/csv.test +++ b/mysql-test/t/csv.test @@ -1352,3 +1352,59 @@ SELECT * FROM bug14672; DROP TABLE bug14672; # End of 4.1 tests + +# +# BUG#13406 - incorrect amount of "records deleted" +# + +create table t1 (a int) engine=csv; +insert t1 values (1); +--enable_info +delete from t1; -- delete_row +delete from t1; -- delete_all_rows +--disable_info +insert t1 values (1),(2); +--enable_info +delete from t1; -- delete_all_rows +--disable_info +insert t1 values (1),(2),(3); +flush tables; +--enable_info +delete from t1; -- delete_row +--disable_info +insert t1 values (1),(2),(3),(4); +flush tables; +select count(*) from t1; +--enable_info +delete from t1; -- delete_all_rows +--disable_info +insert t1 values (1),(2),(3),(4),(5); +--enable_info +truncate table t1; -- truncate +--disable_info +drop table t1; + +# +# Bug #15205 Select from CSV table without the datafile causes crash +# +# NOTE: the bug is not deterministic + +# The crash happens because the necessary cleanup after an error wasn't +# performed. Namely, the table share, inserted in the hash during table +# open, was not deleted from hash. At the same time the share was freed +# when an error was encountered. Thus, subsequent access to the hash +# resulted in scanning through deleted memory and we were geting a crash. +# that's why we need two tables in the bugtest + +create table bug15205 (val int(11) default null) engine=csv; +create table bug15205_2 (val int(11) default null) engine=csv; +--exec rm $MYSQLTEST_VARDIR/master-data/test/bug15205.CSV +# system error (can't open the datafile) +--error ER_GET_ERRNO +select * from bug15205; +select * from bug15205_2; +--exec touch $MYSQLTEST_VARDIR/master-data/test/bug15205.CSV +select * from bug15205; +drop table bug15205; +drop table bug15205_2; + diff --git a/mysql-test/t/ctype_cp1251.test b/mysql-test/t/ctype_cp1251.test index 1aafe7b7266..463a9cea4bc 100644 --- a/mysql-test/t/ctype_cp1251.test +++ b/mysql-test/t/ctype_cp1251.test @@ -21,7 +21,7 @@ drop table t1; # # Test of binary and upper/lower # -create table t1 (a char(15) binary, b binary(15)) character set cp1251; +create table t1 (a char(3) binary, b binary(3)) character set cp1251; insert into t1 values ('aaa','bbb'),('AAA','BBB'); select upper(a),upper(b) from t1; select lower(a),lower(b) from t1; diff --git a/mysql-test/t/ctype_cp932.test b/mysql-test/t/ctype_cp932.test index 3ea8be211df..688d06c4dde 100644 --- a/mysql-test/t/ctype_cp932.test +++ b/mysql-test/t/ctype_cp932.test @@ -379,35 +379,37 @@ INSERT INTO t1 VALUES (0xF9F8),(0xF9F9),(0xF9FA),(0xF9FB),(0xF9FC); #Test that all the characters are stored correctly -SELECT HEX(c1) FROM t1 ORDER BY BINARY c1; +SELECT HEX(c1) FROM t1; #Test conversion to ucs2 -CREATE TABLE t2 SELECT CONVERT(c1 USING ucs2) AS c1 FROM t1 ORDER BY BINARY c1; -SELECT HEX(c1) FROM t2 ORDER BY BINARY c1; +CREATE TABLE t2 SELECT CONVERT(c1 USING ucs2) AS c1 FROM t1; +SELECT HEX(c1) FROM t2; #Test round trip conversion -CREATE TABLE t3 SELECT CONVERT(c1 USING cp932) AS c1 FROM t2 ORDER BY BINARY c1; -SELECT HEX(c1) FROM t3 ORDER BY BINARY c1; +CREATE TABLE t3 SELECT CONVERT(c1 USING cp932) AS c1 FROM t2; +SELECT HEX(c1) FROM t3; -#eucjpms is only available from version 5.0 -#skip this test in version 4.1 -# #Test conversion to eucjpms -#CREATE TABLE t4 SELECT CONVERT(c1 USING eucjpms) AS c1 FROM t1 ORDER BY BINARY c1; -#SELECT HEX(c1) FROM t4 ORDER BY BINARY c1; +CREATE TABLE t4 SELECT CONVERT(c1 USING eucjpms) AS c1 FROM t1; +SELECT HEX(c1) FROM t4; DROP TABLE t1; DROP TABLE t2; DROP TABLE t3; -#DROP TABLE t4; +DROP TABLE t4; SET collation_connection='cp932_japanese_ci'; -- source include/ctype_filesort.inc --- source include/ctype_innodb_like.inc --- source include/ctype_like_escape.inc SET collation_connection='cp932_bin'; -- source include/ctype_filesort.inc --- source include/ctype_innodb_like.inc --- source include/ctype_like_escape.inc -# End of 4.1 tests +# +# Bug#12547: Inserting long string into varchar causes table crash in cp932 +# +create table t1 (col1 varchar(1)) character set cp932; +insert into t1 values ('a'); +insert into t1 values ('ab'); +select * from t1; +insert into t1 values ('abc'); +select * from t1; +drop table t1; diff --git a/mysql-test/t/ctype_cp932_binlog.test b/mysql-test/t/ctype_cp932_binlog.test index e8ec0d46caf..3bbbe94f0e3 100644 --- a/mysql-test/t/ctype_cp932_binlog.test +++ b/mysql-test/t/ctype_cp932_binlog.test @@ -26,10 +26,32 @@ SET @var1= x'8300'; # code (and I have used it to test the fix) until there is some way to # exercise this code from mysql-test-run. EXECUTE stmt1 USING @var1; ---replace_column 2 # 5 # -SHOW BINLOG EVENTS FROM 79; +SHOW BINLOG EVENTS FROM 98; SELECT HEX(f1) FROM t1; DROP table t1; # end test for bug#11338 # End of 4.1 tests + +# +# Bug#18293: Values in stored procedure written to binlog unescaped +# + +delimiter |; +CREATE TABLE t4 (s1 CHAR(50) CHARACTER SET latin1, + s2 CHAR(50) CHARACTER SET cp932, + d DECIMAL(10,2))| +CREATE PROCEDURE bug18293 (IN ins1 CHAR(50), + IN ins2 CHAR(50) CHARACTER SET cp932, + IN ind DECIMAL(10,2)) + BEGIN + INSERT INTO t4 VALUES (ins1, ins2, ind); + END| +CALL bug18293("Foo's a Bar", _cp932 0xED40ED41ED42, 47.93)| +SELECT HEX(s1),HEX(s2),d FROM t4| +DROP PROCEDURE bug18293| +DROP TABLE t4| +SHOW BINLOG EVENTS FROM 393| +delimiter ;| + +# End of 5.0 tests diff --git a/mysql-test/t/ctype_cp932_notembedded.test b/mysql-test/t/ctype_cp932_notembedded.test new file mode 100644 index 00000000000..52e7acc3f01 --- /dev/null +++ b/mysql-test/t/ctype_cp932_notembedded.test @@ -0,0 +1,32 @@ +-- source include/not_embedded.inc +-- source include/have_cp932.inc + +--character_set cp932 +--disable_warnings +drop table if exists t1; +--enable_warnings + +set names cp932; +set character_set_database = cp932; + +# Test prepared statement with 0x8300 sequence in parameter while +# running with cp932 client character set. +RESET MASTER; +CREATE TABLE t1(f1 blob); +PREPARE stmt1 FROM 'INSERT INTO t1 VALUES(?)'; +SET @var1= x'8300'; +# TODO: Note that this doesn't actually test the code which was added for +# bug#11338 because this syntax for prepared statements causes the PS to +# be replicated differently than if we executed the PS from C or Java. +# Using this syntax, variable names are inserted into the binlog instead +# of values. The real goal of this test is to check the code that was +# added to Item_param::query_val_str() in order to do hex encoding of +# PS parameters when the client character set is cp932; +# Bug#11338 has an example java program which can be used to verify this +# code (and I have used it to test the fix) until there is some way to +# exercise this code from mysql-test-run. +EXECUTE stmt1 USING @var1; +SHOW BINLOG EVENTS FROM 98; +SELECT HEX(f1) FROM t1; +DROP table t1; +# end test for bug#11338 diff --git a/mysql-test/t/ctype_eucjpms.test b/mysql-test/t/ctype_eucjpms.test new file mode 100644 index 00000000000..8f813fbd82b --- /dev/null +++ b/mysql-test/t/ctype_eucjpms.test @@ -0,0 +1,382 @@ +-- source include/have_eucjpms.inc + + +--disable_warnings +drop table if exists t1; +drop table if exists t2; +drop table if exists t3; +drop table if exists t4; +--enable_warnings + +set names eucjpms; +set character_set_database = eucjpms; + +CREATE TABLE t1(c1 CHAR(1)) DEFAULT CHARACTER SET = eucjpms; + +#Characters which are converted to Unicode ambiguously +INSERT INTO t1 VALUES +(0x5C),(0x7E),(0xA1B1),(0xA1BD),(0xA1C0),(0xA1C1),(0xA1C2),(0xA1DD),(0xA1F1),(0xA1F2),(0xA1EF),(0xA2CC),(0x8FA2B7),(0x8FA2C3); + +#NEC ROW 13 characters (0x8740 - 0x879C of cp932) +INSERT INTO t1 VALUES +(0xADA1),(0xADA2),(0xADA3),(0xADA4),(0xADA5),(0xADA6),(0xADA7),(0xADA8), +(0xADA9),(0xADAA),(0xADAB),(0xADAC),(0xADAD),(0xADAE),(0xADAF),(0xADB0), +(0xADB1),(0xADB2),(0xADB3),(0xADB4),(0xADB5),(0xADB6),(0xADB7),(0xADB8), +(0xADB9),(0xADBA),(0xADBB),(0xADBC),(0xADBD),(0xADBE),(0xADC0),(0xADC1), +(0xADC2),(0xADC3),(0xADC4),(0xADC5),(0xADC6),(0xADC7),(0xADC8),(0xADC9), +(0xADCA),(0xADCB),(0xADCC),(0xADCD),(0xADCE),(0xADCF),(0xADD0),(0xADD1), +(0xADD2),(0xADD3),(0xADD4),(0xADD5),(0xADD6),(0xADDF),(0xADE0),(0xADE1), +(0xADE2),(0xADE3),(0xADE4),(0xADE5),(0xADE6),(0xADE7),(0xADE8),(0xADE9), +(0xADEA),(0xADEB),(0xADEC),(0xADED),(0xADEE),(0xADEF),(0xADF0),(0xADF1), +(0xADF2),(0xADF3),(0xADF4),(0xADF5),(0xADF6),(0xADF7),(0xADF8),(0xADF9), +(0xADFA),(0xADFB),(0xADFC); + +#IBM Selected Kanji and Non-Kanji (0xFA40 - 0xFC4B of cp932) +INSERT INTO t1 VALUES +(0x8FF3F3),(0x8FF3F4),(0x8FF3F5),(0x8FF3F6),(0x8FF3F7),(0x8FF3F8),(0x8FF3F9),(0x8FF3FA), +(0x8FF3FB),(0x8FF3FC),(0x8FF3FD),(0x8FF3FE),(0x8FF4A1),(0x8FF4A2),(0x8FF4A3),(0x8FF4A4), +(0x8FF4A5),(0x8FF4A6),(0x8FF4A7),(0x8FF4A8),(0xA2CC),(0x8FA2C3),(0x8FF4A9),(0x8FF4AA), +(0x8FF4AB),(0x8FF4AC),(0x8FF4AD),(0xA2E8),(0x8FD4E3),(0x8FDCDF),(0x8FE4E9),(0x8FE3F8), +(0x8FD9A1),(0x8FB1BB),(0x8FF4AE),(0x8FC2AD),(0x8FC3FC),(0x8FE4D0),(0x8FC2BF),(0x8FBCF4), +(0x8FB0A9),(0x8FB0C8),(0x8FF4AF),(0x8FB0D2),(0x8FB0D4),(0x8FB0E3),(0x8FB0EE),(0x8FB1A7), +(0x8FB1A3),(0x8FB1AC),(0x8FB1A9),(0x8FB1BE),(0x8FB1DF),(0x8FB1D8),(0x8FB1C8),(0x8FB1D7), +(0x8FB1E3),(0x8FB1F4),(0x8FB1E1),(0x8FB2A3),(0x8FF4B0),(0x8FB2BB),(0x8FB2E6),(0x8FB2ED), +(0x8FB2F5),(0x8FB2FC),(0x8FF4B1),(0x8FB3B5),(0x8FB3D8),(0x8FB3DB),(0x8FB3E5),(0x8FB3EE), +(0x8FB3FB),(0x8FF4B2),(0x8FF4B3),(0x8FB4C0),(0x8FB4C7),(0x8FB4D0),(0x8FB4DE),(0x8FF4B4), +(0x8FB5AA),(0x8FF4B5),(0x8FB5AF),(0x8FB5C4),(0x8FB5E8),(0x8FF4B6),(0x8FB7C2),(0x8FB7E4), +(0x8FB7E8),(0x8FB7E7),(0x8FF4B7),(0x8FF4B8),(0x8FF4B9),(0x8FB8CE),(0x8FB8E1),(0x8FB8F5), +(0x8FB8F7),(0x8FB8F8),(0x8FB8FC),(0x8FB9AF),(0x8FB9B7),(0x8FBABE),(0x8FBADB),(0x8FCDAA), +(0x8FBAE1),(0x8FF4BA),(0x8FBAEB),(0x8FBBB3),(0x8FBBB8),(0x8FF4BB),(0x8FBBCA),(0x8FF4BC), +(0x8FF4BD),(0x8FBBD0),(0x8FBBDE),(0x8FBBF4),(0x8FBBF5),(0x8FBBF9),(0x8FBCE4),(0x8FBCED), +(0x8FBCFE),(0x8FF4BE),(0x8FBDC2),(0x8FBDE7),(0x8FF4BF),(0x8FBDF0),(0x8FBEB0),(0x8FBEAC), +(0x8FF4C0),(0x8FBEB3),(0x8FBEBD),(0x8FBECD),(0x8FBEC9),(0x8FBEE4),(0x8FBFA8),(0x8FBFC9), +(0x8FC0C4),(0x8FC0E4),(0x8FC0F4),(0x8FC1A6),(0x8FF4C1),(0x8FC1F5),(0x8FC1FC),(0x8FF4C2), +(0x8FC1F8),(0x8FC2AB),(0x8FC2A1),(0x8FC2A5),(0x8FF4C3),(0x8FC2B8),(0x8FC2BA),(0x8FF4C4), +(0x8FC2C4),(0x8FC2D2),(0x8FC2D7),(0x8FC2DB),(0x8FC2DE),(0x8FC2ED),(0x8FC2F0),(0x8FF4C5), +(0x8FC3A1),(0x8FC3B5),(0x8FC3C9),(0x8FC3B9),(0x8FF4C6),(0x8FC3D8),(0x8FC3FE),(0x8FF4C7), +(0x8FC4CC),(0x8FF4C8),(0x8FC4D9),(0x8FC4EA),(0x8FC4FD),(0x8FF4C9),(0x8FC5A7),(0x8FC5B5), +(0x8FC5B6),(0x8FF4CA),(0x8FC5D5),(0x8FC6B8),(0x8FC6D7),(0x8FC6E0),(0x8FC6EA),(0x8FC6E3), +(0x8FC7A1),(0x8FC7AB),(0x8FC7C7),(0x8FC7C3),(0x8FC7CB),(0x8FC7CF),(0x8FC7D9),(0x8FF4CB), +(0x8FF4CC),(0x8FC7E6),(0x8FC7EE),(0x8FC7FC),(0x8FC7EB),(0x8FC7F0),(0x8FC8B1),(0x8FC8E5), +(0x8FC8F8),(0x8FC9A6),(0x8FC9AB),(0x8FC9AD),(0x8FF4CD),(0x8FC9CA),(0x8FC9D3),(0x8FC9E9), +(0x8FC9E3),(0x8FC9FC),(0x8FC9F4),(0x8FC9F5),(0x8FF4CE),(0x8FCAB3),(0x8FCABD),(0x8FCAEF), +(0x8FCAF1),(0x8FCBAE),(0x8FF4CF),(0x8FCBCA),(0x8FCBE6),(0x8FCBEA),(0x8FCBF0),(0x8FCBF4), +(0x8FCBEE),(0x8FCCA5),(0x8FCBF9),(0x8FCCAB),(0x8FCCAE),(0x8FCCAD),(0x8FCCB2),(0x8FCCC2), +(0x8FCCD0),(0x8FCCD9),(0x8FF4D0),(0x8FCDBB),(0x8FF4D1),(0x8FCEBB),(0x8FF4D2),(0x8FCEBA), +(0x8FCEC3),(0x8FF4D3),(0x8FCEF2),(0x8FB3DD),(0x8FCFD5),(0x8FCFE2),(0x8FCFE9),(0x8FCFED), +(0x8FF4D4),(0x8FF4D5),(0x8FF4D6),(0x8FF4D7),(0x8FD0E5),(0x8FF4D8),(0x8FD0E9),(0x8FD1E8), +(0x8FF4D9),(0x8FF4DA),(0x8FD1EC),(0x8FD2BB),(0x8FF4DB),(0x8FD3E1),(0x8FD3E8),(0x8FD4A7), +(0x8FF4DC),(0x8FF4DD),(0x8FD4D4),(0x8FD4F2),(0x8FD5AE),(0x8FF4DE),(0x8FD7DE),(0x8FF4DF), +(0x8FD8A2),(0x8FD8B7),(0x8FD8C1),(0x8FD8D1),(0x8FD8F4),(0x8FD9C6),(0x8FD9C8),(0x8FD9D1), +(0x8FF4E0),(0x8FF4E1),(0x8FF4E2),(0x8FF4E3),(0x8FF4E4),(0x8FDCD3),(0x8FDDC8),(0x8FDDD4), +(0x8FDDEA),(0x8FDDFA),(0x8FDEA4),(0x8FDEB0),(0x8FF4E5),(0x8FDEB5),(0x8FDECB),(0x8FF4E6), +(0x8FDFB9),(0x8FF4E7),(0x8FDFC3),(0x8FF4E8),(0x8FF4E9),(0x8FE0D9),(0x8FF4EA),(0x8FF4EB), +(0x8FE1E2),(0x8FF4EC),(0x8FF4ED),(0x8FF4EE),(0x8FE2C7),(0x8FE3A8),(0x8FE3A6),(0x8FE3A9), +(0x8FE3AF),(0x8FE3B0),(0x8FE3AA),(0x8FE3AB),(0x8FE3BC),(0x8FE3C1),(0x8FE3BF),(0x8FE3D5), +(0x8FE3D8),(0x8FE3D6),(0x8FE3DF),(0x8FE3E3),(0x8FE3E1),(0x8FE3D4),(0x8FE3E9),(0x8FE4A6), +(0x8FE3F1),(0x8FE3F2),(0x8FE4CB),(0x8FE4C1),(0x8FE4C3),(0x8FE4BE),(0x8FF4EF),(0x8FE4C0), +(0x8FE4C7),(0x8FE4BF),(0x8FE4E0),(0x8FE4DE),(0x8FE4D1),(0x8FF4F0),(0x8FE4DC),(0x8FE4D2), +(0x8FE4DB),(0x8FE4D4),(0x8FE4FA),(0x8FE4EF),(0x8FE5B3),(0x8FE5BF),(0x8FE5C9),(0x8FE5D0), +(0x8FE5E2),(0x8FE5EA),(0x8FE5EB),(0x8FF4F1),(0x8FF4F2),(0x8FF4F3),(0x8FE6E8),(0x8FE6EF), +(0x8FE7AC),(0x8FF4F4),(0x8FE7AE),(0x8FF4F5),(0x8FE7B1),(0x8FF4F6),(0x8FE7B2),(0x8FE8B1), +(0x8FE8B6),(0x8FF4F7),(0x8FF4F8),(0x8FE8DD),(0x8FF4F9),(0x8FF4FA),(0x8FE9D1),(0x8FF4FB), +(0x8FE9ED),(0x8FEACD),(0x8FF4FC),(0x8FEADB),(0x8FEAE6),(0x8FEAEA),(0x8FEBA5),(0x8FEBFB), +(0x8FEBFA),(0x8FF4FD),(0x8FECD6),(0x8FF4FE); + +#User defined characters (0xF040-F9FC of cp932) +INSERT INTO t1 VALUES +(0xF5A1),(0xF5A2),(0xF5A3),(0xF5A4),(0xF5A5),(0xF5A6),(0xF5A7),(0xF5A8), +(0xF5A9),(0xF5AA),(0xF5AB),(0xF5AC),(0xF5AD),(0xF5AE),(0xF5AF),(0xF5B0), +(0xF5B1),(0xF5B2),(0xF5B3),(0xF5B4),(0xF5B5),(0xF5B6),(0xF5B7),(0xF5B8), +(0xF5B9),(0xF5BA),(0xF5BB),(0xF5BC),(0xF5BD),(0xF5BE),(0xF5BF),(0xF5C0), +(0xF5C1),(0xF5C2),(0xF5C3),(0xF5C4),(0xF5C5),(0xF5C6),(0xF5C7),(0xF5C8), +(0xF5C9),(0xF5CA),(0xF5CB),(0xF5CC),(0xF5CD),(0xF5CE),(0xF5CF),(0xF5D0), +(0xF5D1),(0xF5D2),(0xF5D3),(0xF5D4),(0xF5D5),(0xF5D6),(0xF5D7),(0xF5D8), +(0xF5D9),(0xF5DA),(0xF5DB),(0xF5DC),(0xF5DD),(0xF5DE),(0xF5DF),(0xF5E0), +(0xF5E1),(0xF5E2),(0xF5E3),(0xF5E4),(0xF5E5),(0xF5E6),(0xF5E7),(0xF5E8), +(0xF5E9),(0xF5EA),(0xF5EB),(0xF5EC),(0xF5ED),(0xF5EE),(0xF5EF),(0xF5F0), +(0xF5F1),(0xF5F2),(0xF5F3),(0xF5F4),(0xF5F5),(0xF5F6),(0xF5F7),(0xF5F8), +(0xF5F9),(0xF5FA),(0xF5FB),(0xF5FC),(0xF5FD),(0xF5FE), +(0xF6A1),(0xF6A2),(0xF6A3),(0xF6A4),(0xF6A5),(0xF6A6),(0xF6A7),(0xF6A8), +(0xF6A9),(0xF6AA),(0xF6AB),(0xF6AC),(0xF6AD),(0xF6AE),(0xF6AF),(0xF6B0), +(0xF6B1),(0xF6B2),(0xF6B3),(0xF6B4),(0xF6B5),(0xF6B6),(0xF6B7),(0xF6B8), +(0xF6B9),(0xF6BA),(0xF6BB),(0xF6BC),(0xF6BD),(0xF6BE),(0xF6BF),(0xF6C0), +(0xF6C1),(0xF6C2),(0xF6C3),(0xF6C4),(0xF6C5),(0xF6C6),(0xF6C7),(0xF6C8), +(0xF6C9),(0xF6CA),(0xF6CB),(0xF6CC),(0xF6CD),(0xF6CE),(0xF6CF),(0xF6D0), +(0xF6D1),(0xF6D2),(0xF6D3),(0xF6D4),(0xF6D5),(0xF6D6),(0xF6D7),(0xF6D8), +(0xF6D9),(0xF6DA),(0xF6DB),(0xF6DC),(0xF6DD),(0xF6DE),(0xF6DF),(0xF6E0), +(0xF6E1),(0xF6E2),(0xF6E3),(0xF6E4),(0xF6E5),(0xF6E6),(0xF6E7),(0xF6E8), +(0xF6E9),(0xF6EA),(0xF6EB),(0xF6EC),(0xF6ED),(0xF6EE),(0xF6EF),(0xF6F0), +(0xF6F1),(0xF6F2),(0xF6F3),(0xF6F4),(0xF6F5),(0xF6F6),(0xF6F7),(0xF6F8), +(0xF6F9),(0xF6FA),(0xF6FB),(0xF6FC),(0xF6FD),(0xF6FE), +(0xF7A1),(0xF7A2),(0xF7A3),(0xF7A4),(0xF7A5),(0xF7A6),(0xF7A7),(0xF7A8), +(0xF7A9),(0xF7AA),(0xF7AB),(0xF7AC),(0xF7AD),(0xF7AE),(0xF7AF),(0xF7B0), +(0xF7B1),(0xF7B2),(0xF7B3),(0xF7B4),(0xF7B5),(0xF7B6),(0xF7B7),(0xF7B8), +(0xF7B9),(0xF7BA),(0xF7BB),(0xF7BC),(0xF7BD),(0xF7BE),(0xF7BF),(0xF7C0), +(0xF7C1),(0xF7C2),(0xF7C3),(0xF7C4),(0xF7C5),(0xF7C6),(0xF7C7),(0xF7C8), +(0xF7C9),(0xF7CA),(0xF7CB),(0xF7CC),(0xF7CD),(0xF7CE),(0xF7CF),(0xF7D0), +(0xF7D1),(0xF7D2),(0xF7D3),(0xF7D4),(0xF7D5),(0xF7D6),(0xF7D7),(0xF7D8), +(0xF7D9),(0xF7DA),(0xF7DB),(0xF7DC),(0xF7DD),(0xF7DE),(0xF7DF),(0xF7E0), +(0xF7E1),(0xF7E2),(0xF7E3),(0xF7E4),(0xF7E5),(0xF7E6),(0xF7E7),(0xF7E8), +(0xF7E9),(0xF7EA),(0xF7EB),(0xF7EC),(0xF7ED),(0xF7EE),(0xF7EF),(0xF7F0), +(0xF7F1),(0xF7F2),(0xF7F3),(0xF7F4),(0xF7F5),(0xF7F6),(0xF7F7),(0xF7F8), +(0xF7F9),(0xF7FA),(0xF7FB),(0xF7FC),(0xF7FD),(0xF7FE), +(0xF8A1),(0xF8A2),(0xF8A3),(0xF8A4),(0xF8A5),(0xF8A6),(0xF8A7),(0xF8A8), +(0xF8A9),(0xF8AA),(0xF8AB),(0xF8AC),(0xF8AD),(0xF8AE),(0xF8AF),(0xF8B0), +(0xF8B1),(0xF8B2),(0xF8B3),(0xF8B4),(0xF8B5),(0xF8B6),(0xF8B7),(0xF8B8), +(0xF8B9),(0xF8BA),(0xF8BB),(0xF8BC),(0xF8BD),(0xF8BE),(0xF8BF),(0xF8C0), +(0xF8C1),(0xF8C2),(0xF8C3),(0xF8C4),(0xF8C5),(0xF8C6),(0xF8C7),(0xF8C8), +(0xF8C9),(0xF8CA),(0xF8CB),(0xF8CC),(0xF8CD),(0xF8CE),(0xF8CF),(0xF8D0), +(0xF8D1),(0xF8D2),(0xF8D3),(0xF8D4),(0xF8D5),(0xF8D6),(0xF8D7),(0xF8D8), +(0xF8D9),(0xF8DA),(0xF8DB),(0xF8DC),(0xF8DD),(0xF8DE),(0xF8DF),(0xF8E0), +(0xF8E1),(0xF8E2),(0xF8E3),(0xF8E4),(0xF8E5),(0xF8E6),(0xF8E7),(0xF8E8), +(0xF8E9),(0xF8EA),(0xF8EB),(0xF8EC),(0xF8ED),(0xF8EE),(0xF8EF),(0xF8F0), +(0xF8F1),(0xF8F2),(0xF8F3),(0xF8F4),(0xF8F5),(0xF8F6),(0xF8F7),(0xF8F8), +(0xF8F9),(0xF8FA),(0xF8FB),(0xF8FC),(0xF8FD),(0xF8FE), +(0xF9A1),(0xF9A2),(0xF9A3),(0xF9A4),(0xF9A5),(0xF9A6),(0xF9A7),(0xF9A8), +(0xF9A9),(0xF9AA),(0xF9AB),(0xF9AC),(0xF9AD),(0xF9AE),(0xF9AF),(0xF9B0), +(0xF9B1),(0xF9B2),(0xF9B3),(0xF9B4),(0xF9B5),(0xF9B6),(0xF9B7),(0xF9B8), +(0xF9B9),(0xF9BA),(0xF9BB),(0xF9BC),(0xF9BD),(0xF9BE),(0xF9BF),(0xF9C0), +(0xF9C1),(0xF9C2),(0xF9C3),(0xF9C4),(0xF9C5),(0xF9C6),(0xF9C7),(0xF9C8), +(0xF9C9),(0xF9CA),(0xF9CB),(0xF9CC),(0xF9CD),(0xF9CE),(0xF9CF),(0xF9D0), +(0xF9D1),(0xF9D2),(0xF9D3),(0xF9D4),(0xF9D5),(0xF9D6),(0xF9D7),(0xF9D8), +(0xF9D9),(0xF9DA),(0xF9DB),(0xF9DC),(0xF9DD),(0xF9DE),(0xF9DF),(0xF9E0), +(0xF9E1),(0xF9E2),(0xF9E3),(0xF9E4),(0xF9E5),(0xF9E6),(0xF9E7),(0xF9E8), +(0xF9E9),(0xF9EA),(0xF9EB),(0xF9EC),(0xF9ED),(0xF9EE),(0xF9EF),(0xF9F0), +(0xF9F1),(0xF9F2),(0xF9F3),(0xF9F4),(0xF9F5),(0xF9F6),(0xF9F7),(0xF9F8), +(0xF9F9),(0xF9FA),(0xF9FB),(0xF9FC),(0xF9FD),(0xF9FE), +(0xFAA1),(0xFAA2),(0xFAA3),(0xFAA4),(0xFAA5),(0xFAA6),(0xFAA7),(0xFAA8), +(0xFAA9),(0xFAAA),(0xFAAB),(0xFAAC),(0xFAAD),(0xFAAE),(0xFAAF),(0xFAB0), +(0xFAB1),(0xFAB2),(0xFAB3),(0xFAB4),(0xFAB5),(0xFAB6),(0xFAB7),(0xFAB8), +(0xFAB9),(0xFABA),(0xFABB),(0xFABC),(0xFABD),(0xFABE),(0xFABF),(0xFAC0), +(0xFAC1),(0xFAC2),(0xFAC3),(0xFAC4),(0xFAC5),(0xFAC6),(0xFAC7),(0xFAC8), +(0xFAC9),(0xFACA),(0xFACB),(0xFACC),(0xFACD),(0xFACE),(0xFACF),(0xFAD0), +(0xFAD1),(0xFAD2),(0xFAD3),(0xFAD4),(0xFAD5),(0xFAD6),(0xFAD7),(0xFAD8), +(0xFAD9),(0xFADA),(0xFADB),(0xFADC),(0xFADD),(0xFADE),(0xFADF),(0xFAE0), +(0xFAE1),(0xFAE2),(0xFAE3),(0xFAE4),(0xFAE5),(0xFAE6),(0xFAE7),(0xFAE8), +(0xFAE9),(0xFAEA),(0xFAEB),(0xFAEC),(0xFAED),(0xFAEE),(0xFAEF),(0xFAF0), +(0xFAF1),(0xFAF2),(0xFAF3),(0xFAF4),(0xFAF5),(0xFAF6),(0xFAF7),(0xFAF8), +(0xFAF9),(0xFAFA),(0xFAFB),(0xFAFC),(0xFAFD),(0xFAFE), +(0xFBA1),(0xFBA2),(0xFBA3),(0xFBA4),(0xFBA5),(0xFBA6),(0xFBA7),(0xFBA8), +(0xFBA9),(0xFBAA),(0xFBAB),(0xFBAC),(0xFBAD),(0xFBAE),(0xFBAF),(0xFBB0), +(0xFBB1),(0xFBB2),(0xFBB3),(0xFBB4),(0xFBB5),(0xFBB6),(0xFBB7),(0xFBB8), +(0xFBB9),(0xFBBA),(0xFBBB),(0xFBBC),(0xFBBD),(0xFBBE),(0xFBBF),(0xFBC0), +(0xFBC1),(0xFBC2),(0xFBC3),(0xFBC4),(0xFBC5),(0xFBC6),(0xFBC7),(0xFBC8), +(0xFBC9),(0xFBCA),(0xFBCB),(0xFBCC),(0xFBCD),(0xFBCE),(0xFBCF),(0xFBD0), +(0xFBD1),(0xFBD2),(0xFBD3),(0xFBD4),(0xFBD5),(0xFBD6),(0xFBD7),(0xFBD8), +(0xFBD9),(0xFBDA),(0xFBDB),(0xFBDC),(0xFBDD),(0xFBDE),(0xFBDF),(0xFBE0), +(0xFBE1),(0xFBE2),(0xFBE3),(0xFBE4),(0xFBE5),(0xFBE6),(0xFBE7),(0xFBE8), +(0xFBE9),(0xFBEA),(0xFBEB),(0xFBEC),(0xFBED),(0xFBEE),(0xFBEF),(0xFBF0), +(0xFBF1),(0xFBF2),(0xFBF3),(0xFBF4),(0xFBF5),(0xFBF6),(0xFBF7),(0xFBF8), +(0xFBF9),(0xFBFA),(0xFBFB),(0xFBFC),(0xFBFD),(0xFBFE), +(0xFCA1),(0xFCA2),(0xFCA3),(0xFCA4),(0xFCA5),(0xFCA6),(0xFCA7),(0xFCA8), +(0xFCA9),(0xFCAA),(0xFCAB),(0xFCAC),(0xFCAD),(0xFCAE),(0xFCAF),(0xFCB0), +(0xFCB1),(0xFCB2),(0xFCB3),(0xFCB4),(0xFCB5),(0xFCB6),(0xFCB7),(0xFCB8), +(0xFCB9),(0xFCBA),(0xFCBB),(0xFCBC),(0xFCBD),(0xFCBE),(0xFCBF),(0xFCC0), +(0xFCC1),(0xFCC2),(0xFCC3),(0xFCC4),(0xFCC5),(0xFCC6),(0xFCC7),(0xFCC8), +(0xFCC9),(0xFCCA),(0xFCCB),(0xFCCC),(0xFCCD),(0xFCCE),(0xFCCF),(0xFCD0), +(0xFCD1),(0xFCD2),(0xFCD3),(0xFCD4),(0xFCD5),(0xFCD6),(0xFCD7),(0xFCD8), +(0xFCD9),(0xFCDA),(0xFCDB),(0xFCDC),(0xFCDD),(0xFCDE),(0xFCDF),(0xFCE0), +(0xFCE1),(0xFCE2),(0xFCE3),(0xFCE4),(0xFCE5),(0xFCE6),(0xFCE7),(0xFCE8), +(0xFCE9),(0xFCEA),(0xFCEB),(0xFCEC),(0xFCED),(0xFCEE),(0xFCEF),(0xFCF0), +(0xFCF1),(0xFCF2),(0xFCF3),(0xFCF4),(0xFCF5),(0xFCF6),(0xFCF7),(0xFCF8), +(0xFCF9),(0xFCFA),(0xFCFB),(0xFCFC),(0xFCFD),(0xFCFE), +(0xFDA1),(0xFDA2),(0xFDA3),(0xFDA4),(0xFDA5),(0xFDA6),(0xFDA7),(0xFDA8), +(0xFDA9),(0xFDAA),(0xFDAB),(0xFDAC),(0xFDAD),(0xFDAE),(0xFDAF),(0xFDB0), +(0xFDB1),(0xFDB2),(0xFDB3),(0xFDB4),(0xFDB5),(0xFDB6),(0xFDB7),(0xFDB8), +(0xFDB9),(0xFDBA),(0xFDBB),(0xFDBC),(0xFDBD),(0xFDBE),(0xFDBF),(0xFDC0), +(0xFDC1),(0xFDC2),(0xFDC3),(0xFDC4),(0xFDC5),(0xFDC6),(0xFDC7),(0xFDC8), +(0xFDC9),(0xFDCA),(0xFDCB),(0xFDCC),(0xFDCD),(0xFDCE),(0xFDCF),(0xFDD0), +(0xFDD1),(0xFDD2),(0xFDD3),(0xFDD4),(0xFDD5),(0xFDD6),(0xFDD7),(0xFDD8), +(0xFDD9),(0xFDDA),(0xFDDB),(0xFDDC),(0xFDDD),(0xFDDE),(0xFDDF),(0xFDE0), +(0xFDE1),(0xFDE2),(0xFDE3),(0xFDE4),(0xFDE5),(0xFDE6),(0xFDE7),(0xFDE8), +(0xFDE9),(0xFDEA),(0xFDEB),(0xFDEC),(0xFDED),(0xFDEE),(0xFDEF),(0xFDF0), +(0xFDF1),(0xFDF2),(0xFDF3),(0xFDF4),(0xFDF5),(0xFDF6),(0xFDF7),(0xFDF8), +(0xFDF9),(0xFDFA),(0xFDFB),(0xFDFC),(0xFDFD),(0xFDFE), +(0xFEA1),(0xFEA2),(0xFEA3),(0xFEA4),(0xFEA5),(0xFEA6),(0xFEA7),(0xFEA8), +(0xFEA9),(0xFEAA),(0xFEAB),(0xFEAC),(0xFEAD),(0xFEAE),(0xFEAF),(0xFEB0), +(0xFEB1),(0xFEB2),(0xFEB3),(0xFEB4),(0xFEB5),(0xFEB6),(0xFEB7),(0xFEB8), +(0xFEB9),(0xFEBA),(0xFEBB),(0xFEBC),(0xFEBD),(0xFEBE),(0xFEBF),(0xFEC0), +(0xFEC1),(0xFEC2),(0xFEC3),(0xFEC4),(0xFEC5),(0xFEC6),(0xFEC7),(0xFEC8), +(0xFEC9),(0xFECA),(0xFECB),(0xFECC),(0xFECD),(0xFECE),(0xFECF),(0xFED0), +(0xFED1),(0xFED2),(0xFED3),(0xFED4),(0xFED5),(0xFED6),(0xFED7),(0xFED8), +(0xFED9),(0xFEDA),(0xFEDB),(0xFEDC),(0xFEDD),(0xFEDE),(0xFEDF),(0xFEE0), +(0xFEE1),(0xFEE2),(0xFEE3),(0xFEE4),(0xFEE5),(0xFEE6),(0xFEE7),(0xFEE8), +(0xFEE9),(0xFEEA),(0xFEEB),(0xFEEC),(0xFEED),(0xFEEE),(0xFEEF),(0xFEF0), +(0xFEF1),(0xFEF2),(0xFEF3),(0xFEF4),(0xFEF5),(0xFEF6),(0xFEF7),(0xFEF8), +(0xFEF9),(0xFEFA),(0xFEFB),(0xFEFC),(0xFEFD),(0xFEFE), +(0x8FF5A1),(0x8FF5A2),(0x8FF5A3),(0x8FF5A4),(0x8FF5A5),(0x8FF5A6),(0x8FF5A7),(0x8FF5A8), +(0x8FF5A9),(0x8FF5AA),(0x8FF5AB),(0x8FF5AC),(0x8FF5AD),(0x8FF5AE),(0x8FF5AF),(0x8FF5B0), +(0x8FF5B1),(0x8FF5B2),(0x8FF5B3),(0x8FF5B4),(0x8FF5B5),(0x8FF5B6),(0x8FF5B7),(0x8FF5B8), +(0x8FF5B9),(0x8FF5BA),(0x8FF5BB),(0x8FF5BC),(0x8FF5BD),(0x8FF5BE),(0x8FF5BF),(0x8FF5C0), +(0x8FF5C1),(0x8FF5C2),(0x8FF5C3),(0x8FF5C4),(0x8FF5C5),(0x8FF5C6),(0x8FF5C7),(0x8FF5C8), +(0x8FF5C9),(0x8FF5CA),(0x8FF5CB),(0x8FF5CC),(0x8FF5CD),(0x8FF5CE),(0x8FF5CF),(0x8FF5D0), +(0x8FF5D1),(0x8FF5D2),(0x8FF5D3),(0x8FF5D4),(0x8FF5D5),(0x8FF5D6),(0x8FF5D7),(0x8FF5D8), +(0x8FF5D9),(0x8FF5DA),(0x8FF5DB),(0x8FF5DC),(0x8FF5DD),(0x8FF5DE),(0x8FF5DF),(0x8FF5E0), +(0x8FF5E1),(0x8FF5E2),(0x8FF5E3),(0x8FF5E4),(0x8FF5E5),(0x8FF5E6),(0x8FF5E7),(0x8FF5E8), +(0x8FF5E9),(0x8FF5EA),(0x8FF5EB),(0x8FF5EC),(0x8FF5ED),(0x8FF5EE),(0x8FF5EF),(0x8FF5F0), +(0x8FF5F1),(0x8FF5F2),(0x8FF5F3),(0x8FF5F4),(0x8FF5F5),(0x8FF5F6),(0x8FF5F7),(0x8FF5F8), +(0x8FF5F9),(0x8FF5FA),(0x8FF5FB),(0x8FF5FC),(0x8FF5FD),(0x8FF5FE), +(0x8FF6A1),(0x8FF6A2),(0x8FF6A3),(0x8FF6A4),(0x8FF6A5),(0x8FF6A6),(0x8FF6A7),(0x8FF6A8), +(0x8FF6A9),(0x8FF6AA),(0x8FF6AB),(0x8FF6AC),(0x8FF6AD),(0x8FF6AE),(0x8FF6AF),(0x8FF6B0), +(0x8FF6B1),(0x8FF6B2),(0x8FF6B3),(0x8FF6B4),(0x8FF6B5),(0x8FF6B6),(0x8FF6B7),(0x8FF6B8), +(0x8FF6B9),(0x8FF6BA),(0x8FF6BB),(0x8FF6BC),(0x8FF6BD),(0x8FF6BE),(0x8FF6BF),(0x8FF6C0), +(0x8FF6C1),(0x8FF6C2),(0x8FF6C3),(0x8FF6C4),(0x8FF6C5),(0x8FF6C6),(0x8FF6C7),(0x8FF6C8), +(0x8FF6C9),(0x8FF6CA),(0x8FF6CB),(0x8FF6CC),(0x8FF6CD),(0x8FF6CE),(0x8FF6CF),(0x8FF6D0), +(0x8FF6D1),(0x8FF6D2),(0x8FF6D3),(0x8FF6D4),(0x8FF6D5),(0x8FF6D6),(0x8FF6D7),(0x8FF6D8), +(0x8FF6D9),(0x8FF6DA),(0x8FF6DB),(0x8FF6DC),(0x8FF6DD),(0x8FF6DE),(0x8FF6DF),(0x8FF6E0), +(0x8FF6E1),(0x8FF6E2),(0x8FF6E3),(0x8FF6E4),(0x8FF6E5),(0x8FF6E6),(0x8FF6E7),(0x8FF6E8), +(0x8FF6E9),(0x8FF6EA),(0x8FF6EB),(0x8FF6EC),(0x8FF6ED),(0x8FF6EE),(0x8FF6EF),(0x8FF6F0), +(0x8FF6F1),(0x8FF6F2),(0x8FF6F3),(0x8FF6F4),(0x8FF6F5),(0x8FF6F6),(0x8FF6F7),(0x8FF6F8), +(0x8FF6F9),(0x8FF6FA),(0x8FF6FB),(0x8FF6FC),(0x8FF6FD),(0x8FF6FE), +(0x8FF7A1),(0x8FF7A2),(0x8FF7A3),(0x8FF7A4),(0x8FF7A5),(0x8FF7A6),(0x8FF7A7),(0x8FF7A8), +(0x8FF7A9),(0x8FF7AA),(0x8FF7AB),(0x8FF7AC),(0x8FF7AD),(0x8FF7AE),(0x8FF7AF),(0x8FF7B0), +(0x8FF7B1),(0x8FF7B2),(0x8FF7B3),(0x8FF7B4),(0x8FF7B5),(0x8FF7B6),(0x8FF7B7),(0x8FF7B8), +(0x8FF7B9),(0x8FF7BA),(0x8FF7BB),(0x8FF7BC),(0x8FF7BD),(0x8FF7BE),(0x8FF7BF),(0x8FF7C0), +(0x8FF7C1),(0x8FF7C2),(0x8FF7C3),(0x8FF7C4),(0x8FF7C5),(0x8FF7C6),(0x8FF7C7),(0x8FF7C8), +(0x8FF7C9),(0x8FF7CA),(0x8FF7CB),(0x8FF7CC),(0x8FF7CD),(0x8FF7CE),(0x8FF7CF),(0x8FF7D0), +(0x8FF7D1),(0x8FF7D2),(0x8FF7D3),(0x8FF7D4),(0x8FF7D5),(0x8FF7D6),(0x8FF7D7),(0x8FF7D8), +(0x8FF7D9),(0x8FF7DA),(0x8FF7DB),(0x8FF7DC),(0x8FF7DD),(0x8FF7DE),(0x8FF7DF),(0x8FF7E0), +(0x8FF7E1),(0x8FF7E2),(0x8FF7E3),(0x8FF7E4),(0x8FF7E5),(0x8FF7E6),(0x8FF7E7),(0x8FF7E8), +(0x8FF7E9),(0x8FF7EA),(0x8FF7EB),(0x8FF7EC),(0x8FF7ED),(0x8FF7EE),(0x8FF7EF),(0x8FF7F0), +(0x8FF7F1),(0x8FF7F2),(0x8FF7F3),(0x8FF7F4),(0x8FF7F5),(0x8FF7F6),(0x8FF7F7),(0x8FF7F8), +(0x8FF7F9),(0x8FF7FA),(0x8FF7FB),(0x8FF7FC),(0x8FF7FD),(0x8FF7FE), +(0x8FF8A1),(0x8FF8A2),(0x8FF8A3),(0x8FF8A4),(0x8FF8A5),(0x8FF8A6),(0x8FF8A7),(0x8FF8A8), +(0x8FF8A9),(0x8FF8AA),(0x8FF8AB),(0x8FF8AC),(0x8FF8AD),(0x8FF8AE),(0x8FF8AF),(0x8FF8B0), +(0x8FF8B1),(0x8FF8B2),(0x8FF8B3),(0x8FF8B4),(0x8FF8B5),(0x8FF8B6),(0x8FF8B7),(0x8FF8B8), +(0x8FF8B9),(0x8FF8BA),(0x8FF8BB),(0x8FF8BC),(0x8FF8BD),(0x8FF8BE),(0x8FF8BF),(0x8FF8C0), +(0x8FF8C1),(0x8FF8C2),(0x8FF8C3),(0x8FF8C4),(0x8FF8C5),(0x8FF8C6),(0x8FF8C7),(0x8FF8C8), +(0x8FF8C9),(0x8FF8CA),(0x8FF8CB),(0x8FF8CC),(0x8FF8CD),(0x8FF8CE),(0x8FF8CF),(0x8FF8D0), +(0x8FF8D1),(0x8FF8D2),(0x8FF8D3),(0x8FF8D4),(0x8FF8D5),(0x8FF8D6),(0x8FF8D7),(0x8FF8D8), +(0x8FF8D9),(0x8FF8DA),(0x8FF8DB),(0x8FF8DC),(0x8FF8DD),(0x8FF8DE),(0x8FF8DF),(0x8FF8E0), +(0x8FF8E1),(0x8FF8E2),(0x8FF8E3),(0x8FF8E4),(0x8FF8E5),(0x8FF8E6),(0x8FF8E7),(0x8FF8E8), +(0x8FF8E9),(0x8FF8EA),(0x8FF8EB),(0x8FF8EC),(0x8FF8ED),(0x8FF8EE),(0x8FF8EF),(0x8FF8F0), +(0x8FF8F1),(0x8FF8F2),(0x8FF8F3),(0x8FF8F4),(0x8FF8F5),(0x8FF8F6),(0x8FF8F7),(0x8FF8F8), +(0x8FF8F9),(0x8FF8FA),(0x8FF8FB),(0x8FF8FC),(0x8FF8FD),(0x8FF8FE), +(0x8FF9A1),(0x8FF9A2),(0x8FF9A3),(0x8FF9A4),(0x8FF9A5),(0x8FF9A6),(0x8FF9A7),(0x8FF9A8), +(0x8FF9A9),(0x8FF9AA),(0x8FF9AB),(0x8FF9AC),(0x8FF9AD),(0x8FF9AE),(0x8FF9AF),(0x8FF9B0), +(0x8FF9B1),(0x8FF9B2),(0x8FF9B3),(0x8FF9B4),(0x8FF9B5),(0x8FF9B6),(0x8FF9B7),(0x8FF9B8), +(0x8FF9B9),(0x8FF9BA),(0x8FF9BB),(0x8FF9BC),(0x8FF9BD),(0x8FF9BE),(0x8FF9BF),(0x8FF9C0), +(0x8FF9C1),(0x8FF9C2),(0x8FF9C3),(0x8FF9C4),(0x8FF9C5),(0x8FF9C6),(0x8FF9C7),(0x8FF9C8), +(0x8FF9C9),(0x8FF9CA),(0x8FF9CB),(0x8FF9CC),(0x8FF9CD),(0x8FF9CE),(0x8FF9CF),(0x8FF9D0), +(0x8FF9D1),(0x8FF9D2),(0x8FF9D3),(0x8FF9D4),(0x8FF9D5),(0x8FF9D6),(0x8FF9D7),(0x8FF9D8), +(0x8FF9D9),(0x8FF9DA),(0x8FF9DB),(0x8FF9DC),(0x8FF9DD),(0x8FF9DE),(0x8FF9DF),(0x8FF9E0), +(0x8FF9E1),(0x8FF9E2),(0x8FF9E3),(0x8FF9E4),(0x8FF9E5),(0x8FF9E6),(0x8FF9E7),(0x8FF9E8), +(0x8FF9E9),(0x8FF9EA),(0x8FF9EB),(0x8FF9EC),(0x8FF9ED),(0x8FF9EE),(0x8FF9EF),(0x8FF9F0), +(0x8FF9F1),(0x8FF9F2),(0x8FF9F3),(0x8FF9F4),(0x8FF9F5),(0x8FF9F6),(0x8FF9F7),(0x8FF9F8), +(0x8FF9F9),(0x8FF9FA),(0x8FF9FB),(0x8FF9FC),(0x8FF9FD),(0x8FF9FE), +(0x8FFAA1),(0x8FFAA2),(0x8FFAA3),(0x8FFAA4),(0x8FFAA5),(0x8FFAA6),(0x8FFAA7),(0x8FFAA8), +(0x8FFAA9),(0x8FFAAA),(0x8FFAAB),(0x8FFAAC),(0x8FFAAD),(0x8FFAAE),(0x8FFAAF),(0x8FFAB0), +(0x8FFAB1),(0x8FFAB2),(0x8FFAB3),(0x8FFAB4),(0x8FFAB5),(0x8FFAB6),(0x8FFAB7),(0x8FFAB8), +(0x8FFAB9),(0x8FFABA),(0x8FFABB),(0x8FFABC),(0x8FFABD),(0x8FFABE),(0x8FFABF),(0x8FFAC0), +(0x8FFAC1),(0x8FFAC2),(0x8FFAC3),(0x8FFAC4),(0x8FFAC5),(0x8FFAC6),(0x8FFAC7),(0x8FFAC8), +(0x8FFAC9),(0x8FFACA),(0x8FFACB),(0x8FFACC),(0x8FFACD),(0x8FFACE),(0x8FFACF),(0x8FFAD0), +(0x8FFAD1),(0x8FFAD2),(0x8FFAD3),(0x8FFAD4),(0x8FFAD5),(0x8FFAD6),(0x8FFAD7),(0x8FFAD8), +(0x8FFAD9),(0x8FFADA),(0x8FFADB),(0x8FFADC),(0x8FFADD),(0x8FFADE),(0x8FFADF),(0x8FFAE0), +(0x8FFAE1),(0x8FFAE2),(0x8FFAE3),(0x8FFAE4),(0x8FFAE5),(0x8FFAE6),(0x8FFAE7),(0x8FFAE8), +(0x8FFAE9),(0x8FFAEA),(0x8FFAEB),(0x8FFAEC),(0x8FFAED),(0x8FFAEE),(0x8FFAEF),(0x8FFAF0), +(0x8FFAF1),(0x8FFAF2),(0x8FFAF3),(0x8FFAF4),(0x8FFAF5),(0x8FFAF6),(0x8FFAF7),(0x8FFAF8), +(0x8FFAF9),(0x8FFAFA),(0x8FFAFB),(0x8FFAFC),(0x8FFAFD),(0x8FFAFE), +(0x8FFBA1),(0x8FFBA2),(0x8FFBA3),(0x8FFBA4),(0x8FFBA5),(0x8FFBA6),(0x8FFBA7),(0x8FFBA8), +(0x8FFBA9),(0x8FFBAA),(0x8FFBAB),(0x8FFBAC),(0x8FFBAD),(0x8FFBAE),(0x8FFBAF),(0x8FFBB0), +(0x8FFBB1),(0x8FFBB2),(0x8FFBB3),(0x8FFBB4),(0x8FFBB5),(0x8FFBB6),(0x8FFBB7),(0x8FFBB8), +(0x8FFBB9),(0x8FFBBA),(0x8FFBBB),(0x8FFBBC),(0x8FFBBD),(0x8FFBBE),(0x8FFBBF),(0x8FFBC0), +(0x8FFBC1),(0x8FFBC2),(0x8FFBC3),(0x8FFBC4),(0x8FFBC5),(0x8FFBC6),(0x8FFBC7),(0x8FFBC8), +(0x8FFBC9),(0x8FFBCA),(0x8FFBCB),(0x8FFBCC),(0x8FFBCD),(0x8FFBCE),(0x8FFBCF),(0x8FFBD0), +(0x8FFBD1),(0x8FFBD2),(0x8FFBD3),(0x8FFBD4),(0x8FFBD5),(0x8FFBD6),(0x8FFBD7),(0x8FFBD8), +(0x8FFBD9),(0x8FFBDA),(0x8FFBDB),(0x8FFBDC),(0x8FFBDD),(0x8FFBDE),(0x8FFBDF),(0x8FFBE0), +(0x8FFBE1),(0x8FFBE2),(0x8FFBE3),(0x8FFBE4),(0x8FFBE5),(0x8FFBE6),(0x8FFBE7),(0x8FFBE8), +(0x8FFBE9),(0x8FFBEA),(0x8FFBEB),(0x8FFBEC),(0x8FFBED),(0x8FFBEE),(0x8FFBEF),(0x8FFBF0), +(0x8FFBF1),(0x8FFBF2),(0x8FFBF3),(0x8FFBF4),(0x8FFBF5),(0x8FFBF6),(0x8FFBF7),(0x8FFBF8), +(0x8FFBF9),(0x8FFBFA),(0x8FFBFB),(0x8FFBFC),(0x8FFBFD),(0x8FFBFE), +(0x8FFCA1),(0x8FFCA2),(0x8FFCA3),(0x8FFCA4),(0x8FFCA5),(0x8FFCA6),(0x8FFCA7),(0x8FFCA8), +(0x8FFCA9),(0x8FFCAA),(0x8FFCAB),(0x8FFCAC),(0x8FFCAD),(0x8FFCAE),(0x8FFCAF),(0x8FFCB0), +(0x8FFCB1),(0x8FFCB2),(0x8FFCB3),(0x8FFCB4),(0x8FFCB5),(0x8FFCB6),(0x8FFCB7),(0x8FFCB8), +(0x8FFCB9),(0x8FFCBA),(0x8FFCBB),(0x8FFCBC),(0x8FFCBD),(0x8FFCBE),(0x8FFCBF),(0x8FFCC0), +(0x8FFCC1),(0x8FFCC2),(0x8FFCC3),(0x8FFCC4),(0x8FFCC5),(0x8FFCC6),(0x8FFCC7),(0x8FFCC8), +(0x8FFCC9),(0x8FFCCA),(0x8FFCCB),(0x8FFCCC),(0x8FFCCD),(0x8FFCCE),(0x8FFCCF),(0x8FFCD0), +(0x8FFCD1),(0x8FFCD2),(0x8FFCD3),(0x8FFCD4),(0x8FFCD5),(0x8FFCD6),(0x8FFCD7),(0x8FFCD8), +(0x8FFCD9),(0x8FFCDA),(0x8FFCDB),(0x8FFCDC),(0x8FFCDD),(0x8FFCDE),(0x8FFCDF),(0x8FFCE0), +(0x8FFCE1),(0x8FFCE2),(0x8FFCE3),(0x8FFCE4),(0x8FFCE5),(0x8FFCE6),(0x8FFCE7),(0x8FFCE8), +(0x8FFCE9),(0x8FFCEA),(0x8FFCEB),(0x8FFCEC),(0x8FFCED),(0x8FFCEE),(0x8FFCEF),(0x8FFCF0), +(0x8FFCF1),(0x8FFCF2),(0x8FFCF3),(0x8FFCF4),(0x8FFCF5),(0x8FFCF6),(0x8FFCF7),(0x8FFCF8), +(0x8FFCF9),(0x8FFCFA),(0x8FFCFB),(0x8FFCFC),(0x8FFCFD),(0x8FFCFE), +(0x8FFDA1),(0x8FFDA2),(0x8FFDA3),(0x8FFDA4),(0x8FFDA5),(0x8FFDA6),(0x8FFDA7),(0x8FFDA8), +(0x8FFDA9),(0x8FFDAA),(0x8FFDAB),(0x8FFDAC),(0x8FFDAD),(0x8FFDAE),(0x8FFDAF),(0x8FFDB0), +(0x8FFDB1),(0x8FFDB2),(0x8FFDB3),(0x8FFDB4),(0x8FFDB5),(0x8FFDB6),(0x8FFDB7),(0x8FFDB8), +(0x8FFDB9),(0x8FFDBA),(0x8FFDBB),(0x8FFDBC),(0x8FFDBD),(0x8FFDBE),(0x8FFDBF),(0x8FFDC0), +(0x8FFDC1),(0x8FFDC2),(0x8FFDC3),(0x8FFDC4),(0x8FFDC5),(0x8FFDC6),(0x8FFDC7),(0x8FFDC8), +(0x8FFDC9),(0x8FFDCA),(0x8FFDCB),(0x8FFDCC),(0x8FFDCD),(0x8FFDCE),(0x8FFDCF),(0x8FFDD0), +(0x8FFDD1),(0x8FFDD2),(0x8FFDD3),(0x8FFDD4),(0x8FFDD5),(0x8FFDD6),(0x8FFDD7),(0x8FFDD8), +(0x8FFDD9),(0x8FFDDA),(0x8FFDDB),(0x8FFDDC),(0x8FFDDD),(0x8FFDDE),(0x8FFDDF),(0x8FFDE0), +(0x8FFDE1),(0x8FFDE2),(0x8FFDE3),(0x8FFDE4),(0x8FFDE5),(0x8FFDE6),(0x8FFDE7),(0x8FFDE8), +(0x8FFDE9),(0x8FFDEA),(0x8FFDEB),(0x8FFDEC),(0x8FFDED),(0x8FFDEE),(0x8FFDEF),(0x8FFDF0), +(0x8FFDF1),(0x8FFDF2),(0x8FFDF3),(0x8FFDF4),(0x8FFDF5),(0x8FFDF6),(0x8FFDF7),(0x8FFDF8), +(0x8FFDF9),(0x8FFDFA),(0x8FFDFB),(0x8FFDFC),(0x8FFDFD),(0x8FFDFE), +(0x8FFEA1),(0x8FFEA2),(0x8FFEA3),(0x8FFEA4),(0x8FFEA5),(0x8FFEA6),(0x8FFEA7),(0x8FFEA8), +(0x8FFEA9),(0x8FFEAA),(0x8FFEAB),(0x8FFEAC),(0x8FFEAD),(0x8FFEAE),(0x8FFEAF),(0x8FFEB0), +(0x8FFEB1),(0x8FFEB2),(0x8FFEB3),(0x8FFEB4),(0x8FFEB5),(0x8FFEB6),(0x8FFEB7),(0x8FFEB8), +(0x8FFEB9),(0x8FFEBA),(0x8FFEBB),(0x8FFEBC),(0x8FFEBD),(0x8FFEBE),(0x8FFEBF),(0x8FFEC0), +(0x8FFEC1),(0x8FFEC2),(0x8FFEC3),(0x8FFEC4),(0x8FFEC5),(0x8FFEC6),(0x8FFEC7),(0x8FFEC8), +(0x8FFEC9),(0x8FFECA),(0x8FFECB),(0x8FFECC),(0x8FFECD),(0x8FFECE),(0x8FFECF),(0x8FFED0), +(0x8FFED1),(0x8FFED2),(0x8FFED3),(0x8FFED4),(0x8FFED5),(0x8FFED6),(0x8FFED7),(0x8FFED8), +(0x8FFED9),(0x8FFEDA),(0x8FFEDB),(0x8FFEDC),(0x8FFEDD),(0x8FFEDE),(0x8FFEDF),(0x8FFEE0), +(0x8FFEE1),(0x8FFEE2),(0x8FFEE3),(0x8FFEE4),(0x8FFEE5),(0x8FFEE6),(0x8FFEE7),(0x8FFEE8), +(0x8FFEE9),(0x8FFEEA),(0x8FFEEB),(0x8FFEEC),(0x8FFEED),(0x8FFEEE),(0x8FFEEF),(0x8FFEF0), +(0x8FFEF1),(0x8FFEF2),(0x8FFEF3),(0x8FFEF4),(0x8FFEF5),(0x8FFEF6),(0x8FFEF7),(0x8FFEF8), +(0x8FFEF9),(0x8FFEFA),(0x8FFEFB),(0x8FFEFC),(0x8FFEFD),(0x8FFEFE); + +#Test that all the characters are stored correctly +SELECT HEX(c1) FROM t1; + +#Test conversion to ucs2 +CREATE TABLE t2 SELECT CONVERT(c1 USING ucs2) AS c1 FROM t1; +SELECT HEX(c1) FROM t2; + +#Test round trip conversion +CREATE TABLE t3 SELECT CONVERT(c1 USING eucjpms) AS c1 FROM t2; +SELECT HEX(c1) FROM t3; + +#Test conversion to cp932 +CREATE TABLE t4 SELECT CONVERT(c1 USING cp932) AS c1 FROM t1; +SELECT HEX(c1) FROM t4; + +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t3; +DROP TABLE t4; + +#Test bug#11717 +CREATE TABLE t1(c1 varchar(10)) default character set = eucjpms; + +insert into t1 values(_ucs2 0x00F7); +insert into t1 values(_eucjpms 0xA1E0); +insert into t1 values(_ujis 0xA1E0); +insert into t1 values(_sjis 0x8180); +insert into t1 values(_cp932 0x8180); + +SELECT HEX(c1) FROM t1; + +DROP TABLE t1; + +SET collation_connection='eucjpms_japanese_ci'; +-- source include/ctype_filesort.inc +SET collation_connection='eucjpms_bin'; +-- source include/ctype_filesort.inc + + +# +# Bugs#15375: Unassigned multibyte codes are broken +# into parts when converting to Unicode. +# This query should return 0x003F0041. I.e. it should +# scan unassigned double-byte character 0xA5FE, convert +# it as QUESTION MARK 0x003F and then scan the next +# character, which is a single byte character 0x41. +# +select hex(convert(_eucjpms 0xA5FE41 using ucs2)); +# This one should return 0x003F0041: +# scan unassigned three-byte character 0x8FABF8, +# convert it as QUESTION MARK 0x003F and then scan +# the next character, which is a single byte character 0x41. +select hex(convert(_eucjpms 0x8FABF841 using ucs2)); + diff --git a/mysql-test/t/ctype_gbk.test b/mysql-test/t/ctype_gbk.test index 7aec48586d8..5ff138fa97b 100644 --- a/mysql-test/t/ctype_gbk.test +++ b/mysql-test/t/ctype_gbk.test @@ -42,3 +42,13 @@ DROP TABLE t1; select hex(convert(_gbk 0xA14041 using ucs2)); # End of 4.1 tests + +# +# Bug#21620 ALTER TABLE affects other columns +# +create table t1 (c1 text not null, c2 text not null) character set gbk; +alter table t1 change c1 c1 mediumtext character set gbk not null; +show create table t1; +drop table t1; + +--echo End of 5.0 tests diff --git a/mysql-test/t/ctype_latin1_de.test b/mysql-test/t/ctype_latin1_de.test index 58153913648..d6a11a22857 100644 --- a/mysql-test/t/ctype_latin1_de.test +++ b/mysql-test/t/ctype_latin1_de.test @@ -66,7 +66,7 @@ drop table t1; # # The below checks both binary and character comparisons. # -create table t1 (word varchar(255) not null, word2 varchar(255) not null, index(word)); +create table t1 (word varchar(255) not null, word2 varchar(255) not null default '', index(word)); show create table t1; insert into t1 (word) values ('ss'),(0xDF),(0xE4),('ae'); update t1 set word2=word; @@ -134,3 +134,11 @@ SELECT * FROM t1 WHERE col1='ß' ORDER BY col1, BINARY col1; DROP TABLE t1; # End of 4.1 tests + +# +# Bug#9509 +# +create table t1 (s1 char(5) character set latin1 collate latin1_german2_ci); +insert into t1 values (0xf6) /* this is o-umlaut */; +select * from t1 where length(s1)=1 and s1='oe'; +drop table t1; diff --git a/mysql-test/t/ctype_latin2_ch.test b/mysql-test/t/ctype_latin2_ch.test index 626d83fa17d..3925d02659d 100644 --- a/mysql-test/t/ctype_latin2_ch.test +++ b/mysql-test/t/ctype_latin2_ch.test @@ -28,3 +28,5 @@ select * from t1 ignore index (primary) where tt like 'AA%'; select * from t1 where tt like '%AA%'; # End of 4.1 tests + +drop table t1; diff --git a/mysql-test/t/ctype_many.test b/mysql-test/t/ctype_many.test index 26dc6282e1e..0903c3dd7fa 100644 --- a/mysql-test/t/ctype_many.test +++ b/mysql-test/t/ctype_many.test @@ -8,7 +8,7 @@ SET CHARACTER SET latin1; CREATE TABLE t1 ( comment CHAR(32) ASCII NOT NULL, - koi8_ru_f CHAR(32) CHARACTER SET koi8r NOT NULL + koi8_ru_f CHAR(32) CHARACTER SET koi8r NOT NULL default '' ) CHARSET=latin5; SHOW CREATE TABLE t1; @@ -142,13 +142,13 @@ INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'ñ','CYR CAPIT YA'); SET CHARACTER SET utf8; SELECT koi8_ru_f,MIN(comment),COUNT(*) FROM t1 GROUP BY 1; -ALTER TABLE t1 ADD utf8_f CHAR(32) CHARACTER SET utf8 NOT NULL; +ALTER TABLE t1 ADD utf8_f CHAR(32) CHARACTER SET utf8 NOT NULL default ''; UPDATE t1 SET utf8_f=CONVERT(koi8_ru_f USING utf8); SET CHARACTER SET koi8r; SELECT * FROM t1; -ALTER TABLE t1 ADD bin_f CHAR(32) BYTE NOT NULL; +ALTER TABLE t1 ADD bin_f CHAR(1) BYTE NOT NULL default ''; UPDATE t1 SET bin_f=koi8_ru_f; SELECT COUNT(DISTINCT bin_f),COUNT(DISTINCT koi8_ru_f),COUNT(DISTINCT utf8_f) FROM t1; @@ -204,7 +204,7 @@ UPDATE t1 SET greek_f=CONVERT(ucs2_f USING greek) WHERE comment LIKE _latin2'GRE UPDATE t1 SET armscii8_f=CONVERT(ucs2_f USING armscii8) WHERE comment LIKE _latin2'ARM%'; UPDATE t1 SET utf8_f=CONVERT(ucs2_f USING utf8) WHERE utf8_f=_utf8''; UPDATE t1 SET ucs2_f=CONVERT(utf8_f USING ucs2) WHERE ucs2_f=_ucs2''; -SELECT * FROM t1; +SELECT comment, koi8_ru_f, utf8_f, hex(bin_f), ucs2_f, armscii8_f, greek_f FROM t1; SET CHARACTER SET 'binary'; SELECT * FROM t1; SELECT min(comment),count(*) FROM t1 GROUP BY ucs2_f; diff --git a/mysql-test/t/ctype_recoding.test b/mysql-test/t/ctype_recoding.test index ddaaa7b9e4f..c18c46b6b08 100644 --- a/mysql-test/t/ctype_recoding.test +++ b/mysql-test/t/ctype_recoding.test @@ -187,7 +187,7 @@ select rpad(c1,3,'ö'), rpad('ö',3,c1) from t1; #select case c1 when 'ß' then 'ß' when 'ö' then 'ö' else 'c' end from t1; #select export_set(5,c1,'ö'), export_set(5,'ö',c1) from t1; drop table t1; - + # # Bug 20695: problem with field default value's character set # @@ -199,4 +199,4 @@ drop table t1; --error 1067 create table t1(a char character set latin1 default _cp1251 0xFF); -# End of 4.1 tests +--echo End of 4.1 tests diff --git a/mysql-test/t/ctype_uca.test b/mysql-test/t/ctype_uca.test index 2300abca69d..3e49b9de883 100644 --- a/mysql-test/t/ctype_uca.test +++ b/mysql-test/t/ctype_uca.test @@ -211,6 +211,8 @@ select group_concat(c1 order by c1) from t1 group by c1 collate utf8_lithuanian_ select group_concat(c1 order by c1) from t1 group by c1 collate utf8_slovak_ci; select group_concat(c1 order by c1) from t1 group by c1 collate utf8_spanish2_ci; select group_concat(c1 order by c1) from t1 group by c1 collate utf8_roman_ci; +select group_concat(c1 order by c1) from t1 group by c1 collate utf8_esperanto_ci; +select group_concat(c1 order by c1) from t1 group by c1 collate utf8_hungarian_ci; drop table t1; @@ -458,3 +460,18 @@ SET collation_connection='utf8_unicode_ci'; -- source include/ctype_like_escape.inc # End of 4.1 tests + +# +# Check UPPER/LOWER changeing length +# +# Result shorter than argument +CREATE TABLE t1 (id int, a varchar(30) character set utf8); +INSERT INTO t1 VALUES (1, _ucs2 0x01310069), (2, _ucs2 0x01310131); +INSERT INTO t1 VALUES (3, _ucs2 0x00690069), (4, _ucs2 0x01300049); +INSERT INTO t1 VALUES (5, _ucs2 0x01300130), (6, _ucs2 0x00490049); +SELECT a, length(a) la, @l:=lower(a) l, length(@l) ll, @u:=upper(a) u, length(@u) lu +FROM t1 ORDER BY id; +ALTER TABLE t1 MODIFY a VARCHAR(30) character set utf8 collate utf8_turkish_ci; +SELECT a, length(a) la, @l:=lower(a) l, length(@l) ll, @u:=upper(a) u, length(@u) lu +FROM t1 ORDER BY id; +DROP TABLE t1; diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test index 641080f48ab..6c814368c88 100644 --- a/mysql-test/t/ctype_ucs.test +++ b/mysql-test/t/ctype_ucs.test @@ -20,17 +20,19 @@ SET CHARACTER SET koi8r; # which contains 0x20 in the high byte. # -CREATE TABLE t1 (word VARCHAR(64) CHARACTER SET ucs2); -INSERT INTO t1 VALUES (_koi8r'ò'), (X'2004'); +CREATE TABLE t1 (word VARCHAR(64) CHARACTER SET ucs2, word2 CHAR(64) CHARACTER SET ucs2); +INSERT INTO t1 VALUES (_koi8r'ò',_koi8r'ò'), (X'2004',X'2004'); SELECT hex(word) FROM t1 ORDER BY word; +SELECT hex(word2) FROM t1 ORDER BY word2; DELETE FROM t1; # # Check that real spaces are correctly trimmed. # -INSERT INTO t1 VALUES (X'042000200020'), (X'200400200020'); +INSERT INTO t1 VALUES (X'042000200020',X'042000200020'), (X'200400200020', X'200400200020'); SELECT hex(word) FROM t1 ORDER BY word; +SELECT hex(word2) FROM t1 ORDER BY word2; DROP TABLE t1; # @@ -52,7 +54,6 @@ RPAD(_ucs2 X'0420',10,_ucs2 X'0421') r; SHOW CREATE TABLE t1; DROP TABLE t1; - # # BUG3946 # @@ -61,6 +62,7 @@ create table t2(f1 Char(30)); insert into t2 values ("103000"), ("22720000"), ("3401200"), ("78000"); select lpad(f1, 12, "-o-/") from t2; drop table t2; + ###################################################### # # Test of like @@ -510,6 +512,17 @@ DROP TABLE t1,t2; select password(name) from bug20536; select old_password(name) from bug20536; +# Disable test case as encrypt relies on 'crypt' function. +# "decrypt" is noramlly tested in func_crypt.test which have a +# "have_crypt.inc" test +--disable_parsing +# ENCRYPT relies on OS function crypt() which takes a NUL-terminated string; it +# doesn't return good results for strings with embedded 0 bytes. It won't be +# fixed unless we choose to re-implement the crypt() function ourselves to take +# an extra size_t string_length argument. +select encrypt(name, 'SALT') from bug20536; +--enable_parsing + # QUOTE doesn't work with UCS2 data. It would require a total rewrite # of Item_func_quote::val_str(), which isn't worthwhile until UCS2 is # supported fully as a client character set. @@ -518,3 +531,36 @@ select quote(name) from bug20536; drop table bug20536; --echo End of 4.1 tests + +# +# Conversion from an UCS2 string to a decimal column +# +CREATE TABLE t1 (a varchar(64) character set ucs2, b decimal(10,3)); +INSERT INTO t1 VALUES ("1.1", 0), ("2.1", 0); +update t1 set b=a; +SELECT * FROM t1; +DROP TABLE t1; + +# +# Bug#9442 Set parameter make query fail if column character set is UCS2 +# +create table t1 (utext varchar(20) character set ucs2); +insert into t1 values ("lily"); +insert into t1 values ("river"); +prepare stmt from 'select utext from t1 where utext like ?'; +set @param1='%%'; +execute stmt using @param1; +execute stmt using @param1; +select utext from t1 where utext like '%%'; +drop table t1; +deallocate prepare stmt; + +# +# Bug #14290: character_maximum_length for text fields +# +create table t1(a blob, b text charset utf8, c text charset ucs2); +select data_type, character_octet_length, character_maximum_length + from information_schema.columns where table_name='t1'; +drop table t1; + +--echo End of 5.0 tests diff --git a/mysql-test/t/ctype_ucs_binlog.test b/mysql-test/t/ctype_ucs_binlog.test index 7faefde7d1a..2467d34386c 100644 --- a/mysql-test/t/ctype_ucs_binlog.test +++ b/mysql-test/t/ctype_ucs_binlog.test @@ -9,12 +9,12 @@ create table t2 (c char(30)) charset=ucs2; set @v=convert('abc' using ucs2); reset master; insert into t2 values (@v); -show binlog events from 79; +show binlog events from 98; # more important than SHOW BINLOG EVENTS, mysqlbinlog (where we # absolutely need variables names to be quoted and strings to be # escaped). --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.000001 +--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001 drop table t2; # End of 4.1 tests diff --git a/mysql-test/t/ctype_ujis.test b/mysql-test/t/ctype_ujis.test index 12d05f44a94..14b37569b11 100644 --- a/mysql-test/t/ctype_ujis.test +++ b/mysql-test/t/ctype_ujis.test @@ -1168,3 +1168,45 @@ select hex(convert(_ujis 0xA5FE41 using ucs2)); select hex(convert(_ujis 0x8FABF841 using ucs2)); # End of 4.1 tests +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +DROP PROCEDURE IF EXISTS sp1; +--enable_warnings + +set names ujis; +set character_set_database = ujis; +set character_set_server = ujis; + +CREATE TABLE t1(c1 char(2)) default charset = ujis; +CREATE TABLE t2(c2 char(2)) default charset = ujis; + +INSERT INTO t1 VALUES(_ujis 0xA4A2); + +DELIMITER |; +CREATE PROCEDURE sp1() +BEGIN + DECLARE a CHAR(2) CHARSET ujis; + DECLARE cur1 CURSOR FOR SELECT c1 FROM t1; + OPEN cur1; + FETCH cur1 INTO a; + INSERT INTO t2 VALUES (a); + CLOSE cur1; +END| +DELIMITER ;| +CALL sp1(); + +#The data in t1 and t2 should be the same but different +SELECT c1,c2 FROM t1,t2; + +#Since the result of hex(convert(_latin1 0xA4A2 using ujis)) +#equals to hex(c2), it seems that the value which was inserted +#by using cursor is interpreted as latin1 character set +SELECT hex(convert(_latin1 0xA4A2 using ujis)),hex(c2) FROM t1,t2; + +DROP PROCEDURE sp1; +DROP TABLE t1; +DROP TABLE t2; + +set names default; +set character_set_database=default; +set character_set_server=default; diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index af40121852f..812965d648a 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -858,20 +858,6 @@ drop table t1; # -# Bug #12371 executing prepared statement fails (illegal mix of collations) -# -set names utf8; -create table t1 (a char(3), b varchar(10)); -insert into t1 values ('bar','kostja'); -prepare my_stmt from "select * from t1 where a=?"; -set @a:='bar'; -execute my_stmt using @a; -set @a:=NULL; -execute my_stmt using @a; -drop table t1; - - -# # Bug#9557 MyISAM utf8 table crash # CREATE TABLE t1 ( @@ -911,6 +897,17 @@ DROP TABLE t2; DROP TABLE t1; # +# Bug#17313: N'xxx' and _utf8'xxx' are not equivalent +# +CREATE TABLE t1 (item varchar(255)) default character set utf8; +INSERT INTO t1 VALUES (N'\\'); +INSERT INTO t1 VALUES (_utf8'\\'); +INSERT INTO t1 VALUES (N'Cote d\'Ivoire'); +INSERT INTO t1 VALUES (_utf8'Cote d\'Ivoire'); +SELECT item FROM t1 ORDER BY item; +DROP TABLE t1; + +# # Bug#17705: Corruption of compressed index when index length changes between # 254 and 256 # @@ -1142,7 +1139,6 @@ explain select a from t1 group by a; select a from t1 group by a; drop table t1; - # # Bug #20204: "order by" changes the results returned # @@ -1154,3 +1150,104 @@ explain select substr(Z.a,-1), Z.a from t1 as Y join t1 as Z on Y.a=Z.a order by 1; drop table t1; # End of 4.1 tests + +# +# Test for bug #11484: wrong results for a DISTINCT varchar column in uft8. +# + +CREATE TABLE t1(id varchar(20) NOT NULL) DEFAULT CHARSET=utf8; +INSERT INTO t1 VALUES ('xxx'), ('aa'), ('yyy'), ('aa'); + +SELECT id FROM t1; +SELECT DISTINCT id FROM t1; +SELECT DISTINCT id FROM t1 ORDER BY id; + +DROP TABLE t1; + +# +# Bug#10504: Character set does not support traditional mode +# Bug#14146: CHAR(...USING ...) and CONVERT(CHAR(...) USING...) +# produce different results +# +set names utf8; +# correct value +select hex(char(1 using utf8)); +select char(0xd1,0x8f using utf8); +select char(0xd18f using utf8); +select char(53647 using utf8); +# incorrect value: return with warning +select char(0xff,0x8f using utf8); +select convert(char(0xff,0x8f) using utf8); +# incorrect value in strict mode: return NULL with "Error" level warning +set sql_mode=traditional; +select char(0xff,0x8f using utf8); +select char(195 using utf8); +select char(196 using utf8); +select char(2557 using utf8); +select convert(char(0xff,0x8f) using utf8); + +# +# Check convert + char + using +# +select hex(convert(char(2557 using latin1) using utf8)); + +# +# char() without USING returns "binary" by default, any argument is ok +# +select hex(char(195)); +select hex(char(196)); +select hex(char(2557)); + + + +# +# Bug#12891: UNION doesn't return DISTINCT result for multi-byte characters +# +set names utf8; +create table t1 (a char(1)) default character set utf8; +create table t2 (a char(1)) default character set utf8; +insert into t1 values('a'),('a'),(0xE38182),(0xE38182); +insert into t1 values('i'),('i'),(0xE38184),(0xE38184); +select * from t1 union distinct select * from t2; +drop table t1,t2; + + +# +# Bug#12371: executing prepared statement fails (illegal mix of collations) +# +set names utf8; +create table t1 (a char(10), b varchar(10)); +insert into t1 values ('bar','kostja'); +insert into t1 values ('kostja','bar'); +prepare my_stmt from "select * from t1 where a=?"; +set @a:='bar'; +execute my_stmt using @a; +set @a:='kostja'; +execute my_stmt using @a; +set @a:=null; +execute my_stmt using @a; +drop table if exists t1; + +# +# Bug#19960: Inconsistent results when joining +# InnoDB tables using partial UTF8 indexes +# +--disable_warnings +CREATE TABLE t1 ( + colA int(11) NOT NULL, + colB varchar(255) character set utf8 NOT NULL, + PRIMARY KEY (colA) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +--enable_warnings +INSERT INTO t1 (colA, colB) VALUES (1, 'foo'), (2, 'foo bar'); +--disable_warnings +CREATE TABLE t2 ( + colA int(11) NOT NULL, + colB varchar(255) character set utf8 NOT NULL, + KEY bad (colA,colB(3)) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +--enable_warnings +INSERT INTO t2 (colA, colB) VALUES (1, 'foo'),(2, 'foo bar'); +SELECT * FROM t1 JOIN t2 ON t1.colA=t2.colA AND t1.colB=t2.colB +WHERE t1.colA < 3; +DROP TABLE t1, t2; diff --git a/mysql-test/t/date_formats.test b/mysql-test/t/date_formats.test index 922d047eac8..a81487d273d 100644 --- a/mysql-test/t/date_formats.test +++ b/mysql-test/t/date_formats.test @@ -122,6 +122,7 @@ SET datetime_format=default; --disable_ps_protocol select str_to_date(concat('15-01-2001',' 2:59:58.999'), concat('%d-%m-%Y',' ','%H:%i:%s.%f')); +select STR_TO_DATE('2004.12.12 22.30.61','%Y.%m.%d %T'); --enable_ps_protocol create table t1 (date char(30), format char(30) not null); @@ -292,6 +293,10 @@ select str_to_date( 1, IF(1=1,NULL,NULL) ); # # Bug#11326 +# TIME_FORMAT using "%r" returns wrong hour using 24:00:00 in TIME column +# +# This tests that 24:00:00 does not return PM, when it should be AM. +# Some other values are being tested same time. # SELECT TIME_FORMAT("24:00:00", '%r'); @@ -303,6 +308,10 @@ SELECT TIME_FORMAT("25:00:00", '%r'); # # Bug#11324 +# TIME_FORMAT using "%l:%i" returns 36:00 with 24:00:00 in TIME column +# +# This tests that 24:00:00 does not change to "36:00 AM". Testing +# some other values same time. # SELECT TIME_FORMAT("00:00:00", '%l %p'); diff --git a/mysql-test/t/default.test b/mysql-test/t/default.test new file mode 100644 index 00000000000..b5522394d2d --- /dev/null +++ b/mysql-test/t/default.test @@ -0,0 +1,84 @@ +# +# test of already fixed bugs +# +--disable_warnings +drop table if exists t1,t2,t3,t4,t5,t6; +drop database if exists mysqltest; + +# +# Bug 10838 +# Insert causes warnings for no default values and corrupts tables +# +CREATE TABLE t1 (a varchar(30) binary NOT NULL DEFAULT ' ', + b varchar(1) binary NOT NULL DEFAULT ' ', + c varchar(4) binary NOT NULL DEFAULT '0000', + d tinyblob NULL, + e tinyblob NULL, + f tinyblob NULL, + g tinyblob NULL, + h tinyblob NULL, + i tinyblob NULL, + j tinyblob NULL, + k tinyblob NULL, + l tinyblob NULL, + m tinyblob NULL, + n tinyblob NULL, + o tinyblob NULL, + p tinyblob NULL, + q varchar(30) binary NOT NULL DEFAULT ' ', + r varchar(30) binary NOT NULL DEFAULT ' ', + s tinyblob NULL, + t varchar(4) binary NOT NULL DEFAULT ' ', + u varchar(1) binary NOT NULL DEFAULT ' ', + v varchar(30) binary NOT NULL DEFAULT ' ', + w varchar(30) binary NOT NULL DEFAULT ' ', + x tinyblob NULL, + y varchar(5) binary NOT NULL DEFAULT ' ', + z varchar(20) binary NOT NULL DEFAULT ' ', + a1 varchar(30) binary NOT NULL DEFAULT ' ', + b1 tinyblob NULL) +ENGINE=InnoDB DEFAULT CHARACTER SET = latin1 COLLATE latin1_bin; +--enable_warnings + +INSERT into t1 (b) values ('1'); +SHOW WARNINGS; +SELECT * from t1; + +CREATE TABLE t2 (a varchar(30) binary NOT NULL DEFAULT ' ', + b varchar(1) binary NOT NULL DEFAULT ' ', + c varchar(4) binary NOT NULL DEFAULT '0000', + d tinyblob NULL, + e tinyblob NULL, + f tinyblob NULL, + g tinyblob NULL, + h tinyblob NULL, + i tinyblob NULL, + j tinyblob NULL, + k tinyblob NULL, + l tinyblob NULL, + m tinyblob NULL, + n tinyblob NULL, + o tinyblob NULL, + p tinyblob NULL, + q varchar(30) binary NOT NULL DEFAULT ' ', + r varchar(30) binary NOT NULL DEFAULT ' ', + s tinyblob NULL, + t varchar(4) binary NOT NULL DEFAULT ' ', + u varchar(1) binary NOT NULL DEFAULT ' ', + v varchar(30) binary NOT NULL DEFAULT ' ', + w varchar(30) binary NOT NULL DEFAULT ' ', + x tinyblob NULL, + y varchar(5) binary NOT NULL DEFAULT ' ', + z varchar(20) binary NOT NULL DEFAULT ' ', + a1 varchar(30) binary NOT NULL DEFAULT ' ', + b1 tinyblob NULL) +ENGINE=MyISAM DEFAULT CHARACTER SET = latin1 COLLATE latin1_bin; + +SHOW CREATE TABLE t2; +INSERT into t2 (b) values ('1'); +SHOW WARNINGS; +SELECT * from t2; + +drop table t1; +drop table t2; + diff --git a/mysql-test/t/delayed.test b/mysql-test/t/delayed.test index a32eec536ea..03d8e20dd8f 100644 --- a/mysql-test/t/delayed.test +++ b/mysql-test/t/delayed.test @@ -3,6 +3,9 @@ # (Can't be tested with purify :( ) # +# This tests not performed with embedded server +-- source include/not_embedded.inc + --disable_warnings drop table if exists t1; --enable_warnings @@ -14,7 +17,8 @@ insert delayed into t1 set a = 4; insert delayed into t1 set a = 5, tmsp = 19711006010203; insert delayed into t1 (a, tmsp) values (6, 19711006010203); insert delayed into t1 (a, tmsp) values (7, NULL); ---sleep 2 +# Wait until the rows are flushed to the table files. +FLUSH TABLE t1; insert into t1 set a = 8,tmsp=19711006010203; select * from t1 where tmsp=0; select * from t1 where tmsp=19711006010203; @@ -31,8 +35,203 @@ insert delayed into t1 values (null,"c"); insert delayed into t1 values (3,"d"),(null,"e"); --error 1136 insert delayed into t1 values (3,"this will give an","error"); ---sleep 2 +# Wait until the rows are flushed to the table files. +FLUSH TABLE t1; +show status like 'not_flushed_delayed_rows'; select * from t1; drop table t1; # End of 4.1 tests + +# +# Bug #12226: Crash when a delayed insert fails due to a duplicate key +# +create table t1 (a int not null primary key); +insert into t1 values (1); +insert delayed into t1 values (1); +select * from t1; +drop table t1; + +# +# Bug #20195: INSERT DELAYED with auto_increment is assigned wrong values +# +CREATE TABLE t1 ( a int(10) NOT NULL auto_increment, PRIMARY KEY (a)); + +# Make one delayed insert to start the separate thread +insert delayed into t1 values(null); + +# Do some normal inserts +insert into t1 values(null); +insert into t1 values(null); + +# Discarded, since the delayed-counter is 2, which is already used +insert delayed into t1 values(null); + +# Discarded, since the delayed-counter is 3, which is already used +insert delayed into t1 values(null); + +# Works, since the delayed-counter is 4, which is unused +insert delayed into t1 values(null); + +# Do some more inserts +insert into t1 values(null); +insert into t1 values(null); +insert into t1 values(null); + +# Delete one of the above to make a hole +delete from t1 where a=6; + +# Discarded, since the delayed-counter is 5, which is already used +insert delayed into t1 values(null); + +# Works, since the delayed-counter is 6, which is unused (the row we deleted) +insert delayed into t1 values(null); + +# Discarded, since the delayed-counter is 7, which is already used +insert delayed into t1 values(null); + +# Works, since the delayed-counter is 8, which is unused +insert delayed into t1 values(null); + +# Wait until the rows are flushed to the table files. +FLUSH TABLE t1; +# Check what we have now +select * from t1 order by a; + +DROP TABLE t1; + +# +# Bug#20627 - INSERT DELAYED does not honour auto_increment_* variables +# +SET @bug20627_old_auto_increment_offset= + @@auto_increment_offset= 2; +SET @bug20627_old_auto_increment_increment= + @@auto_increment_increment= 3; +SET @bug20627_old_session_auto_increment_offset= + @@session.auto_increment_offset= 4; +SET @bug20627_old_session_auto_increment_increment= + @@session.auto_increment_increment= 5; +SET @@auto_increment_offset= 2; +SET @@auto_increment_increment= 3; +SET @@session.auto_increment_offset= 4; +SET @@session.auto_increment_increment= 5; +# +# Normal insert as reference. +CREATE TABLE t1 ( + c1 INT NOT NULL AUTO_INCREMENT, + PRIMARY KEY (c1) + ); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL); +# Check what we have now +SELECT * FROM t1; +DROP TABLE t1; +# +# Delayed insert. +CREATE TABLE t1 ( + c1 INT NOT NULL AUTO_INCREMENT, + PRIMARY KEY (c1) + ); +INSERT DELAYED INTO t1 VALUES (NULL),(NULL),(NULL); +# Wait until the rows are flushed to the table files. +FLUSH TABLE t1; +# Check what we have now +SELECT * FROM t1; +DROP TABLE t1; +# +# Cleanup +SET @@auto_increment_offset= + @bug20627_old_auto_increment_offset; +SET @@auto_increment_increment= + @bug20627_old_auto_increment_increment; +SET @@session.auto_increment_offset= + @bug20627_old_session_auto_increment_offset; +SET @@session.auto_increment_increment= + @bug20627_old_session_auto_increment_increment; + +# +# Bug#20830 - INSERT DELAYED does not honour SET INSERT_ID +# +SET @bug20830_old_auto_increment_offset= + @@auto_increment_offset= 2; +SET @bug20830_old_auto_increment_increment= + @@auto_increment_increment= 3; +SET @bug20830_old_session_auto_increment_offset= + @@session.auto_increment_offset= 4; +SET @bug20830_old_session_auto_increment_increment= + @@session.auto_increment_increment= 5; +SET @@auto_increment_offset= 2; +SET @@auto_increment_increment= 3; +SET @@session.auto_increment_offset= 4; +SET @@session.auto_increment_increment= 5; +# +# Normal insert as reference. +CREATE TABLE t1 ( + c1 INT(11) NOT NULL AUTO_INCREMENT, + c2 INT(11) DEFAULT NULL, + PRIMARY KEY (c1) + ); +SET insert_id= 14; +INSERT INTO t1 VALUES(NULL, 11), (NULL, 12), (NULL, 13); +INSERT INTO t1 VALUES(NULL, 21), (NULL, 22), (NULL, 23); +# Restart sequence at a different value. +INSERT INTO t1 VALUES( 69, 31), (NULL, 32), (NULL, 33); +INSERT INTO t1 VALUES(NULL, 41), (NULL, 42), (NULL, 43); +# Restart sequence at a different value. +SET insert_id= 114; +INSERT INTO t1 VALUES(NULL, 51), (NULL, 52), (NULL, 53); +INSERT INTO t1 VALUES(NULL, 61), (NULL, 62), (NULL, 63); +# Set one value below the maximum value. +INSERT INTO t1 VALUES( 49, 71), (NULL, 72), (NULL, 73); +INSERT INTO t1 VALUES(NULL, 81), (NULL, 82), (NULL, 83); +# Create a duplicate value. +SET insert_id= 114; +--error 1062 +INSERT INTO t1 VALUES(NULL, 91); +INSERT INTO t1 VALUES (NULL, 92), (NULL, 93); +# Check what we have now +SELECT * FROM t1; +SELECT COUNT(*) FROM t1; +SELECT SUM(c1) FROM t1; +DROP TABLE t1; +# +# Delayed insert. +CREATE TABLE t1 ( + c1 INT(11) NOT NULL AUTO_INCREMENT, + c2 INT(11) DEFAULT NULL, + PRIMARY KEY (c1) + ); +SET insert_id= 14; +INSERT DELAYED INTO t1 VALUES(NULL, 11), (NULL, 12), (NULL, 13); +INSERT DELAYED INTO t1 VALUES(NULL, 21), (NULL, 22), (NULL, 23); +# Restart sequence at a different value. +INSERT DELAYED INTO t1 VALUES( 69, 31), (NULL, 32), (NULL, 33); +INSERT DELAYED INTO t1 VALUES(NULL, 41), (NULL, 42), (NULL, 43); +# Restart sequence at a different value. +SET insert_id= 114; +INSERT DELAYED INTO t1 VALUES(NULL, 51), (NULL, 52), (NULL, 53); +INSERT DELAYED INTO t1 VALUES(NULL, 61), (NULL, 62), (NULL, 63); +# Set one value below the maximum value. +INSERT DELAYED INTO t1 VALUES( 49, 71), (NULL, 72), (NULL, 73); +INSERT DELAYED INTO t1 VALUES(NULL, 81), (NULL, 82), (NULL, 83); +# Create a duplicate value. +SET insert_id= 114; +INSERT DELAYED INTO t1 VALUES(NULL, 91); +INSERT DELAYED INTO t1 VALUES (NULL, 92), (NULL, 93); +# Wait until the rows are flushed to the table files. +FLUSH TABLE t1; +# Check what we have now +SELECT * FROM t1; +SELECT COUNT(*) FROM t1; +SELECT SUM(c1) FROM t1; +DROP TABLE t1; +# +# Cleanup +SET @@auto_increment_offset= + @bug20830_old_auto_increment_offset; +SET @@auto_increment_increment= + @bug20830_old_auto_increment_increment; +SET @@session.auto_increment_offset= + @bug20830_old_session_auto_increment_offset; +SET @@session.auto_increment_increment= + @bug20830_old_session_auto_increment_increment; + diff --git a/mysql-test/t/delete.test b/mysql-test/t/delete.test index 2036b59d810..865e1746fd3 100644 --- a/mysql-test/t/delete.test +++ b/mysql-test/t/delete.test @@ -3,7 +3,7 @@ # --disable_warnings -drop table if exists t1,t11,t12,t2; +drop table if exists t1,t2,t3,t11,t12; --enable_warnings CREATE TABLE t1 (a tinyint(3), b tinyint(5)); INSERT INTO t1 VALUES (1,1); @@ -163,15 +163,32 @@ delete `4.t1` from t1 as `4.t1` where `4.t1`.a = 5; delete FROM `4.t1` USING t1 as `4.t1` where `4.t1`.a = 5; drop table t1; +# End of 4.1 tests + # -# Bug #8143: deleting '0000-00-00' values using IS NULL +# Test of multi-delete where we are not scanning the first table # -create table t1(a date not null); -insert into t1 values (0); -select * from t1 where a is null; -delete from t1 where a is null; -select count(*) from t1; -drop table t1; +CREATE TABLE t1 (a int not null,b int not null); +CREATE TABLE t2 (a int not null, b int not null, primary key (a,b)); +CREATE TABLE t3 (a int not null, b int not null, primary key (a,b)); +insert into t1 values (1,1),(2,1),(1,3); +insert into t2 values (1,1),(2,2),(3,3); +insert into t3 values (1,1),(2,1),(1,3); +select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b; +explain select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b; +delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b; +# This should be empty +select * from t3; +drop table t1,t2,t3; + +# +# Bug #8143: deleting '0000-00-00' values using IS NULL +# ---echo End of 4.1 tests +create table t1(a date not null); +insert into t1 values (0); +select * from t1 where a is null; +delete from t1 where a is null; +select count(*) from t1; +drop table t1; diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test index 91fa3238e69..3ad33dddcbe 100644 --- a/mysql-test/t/derived.test +++ b/mysql-test/t/derived.test @@ -42,7 +42,7 @@ CREATE TABLE t2 (a int not null); insert into t2 values(1); select * from (select * from t1 where t1.a=(select a from t2 where t2.a=t1.a)) a; select * from (select * from t1 where t1.a=(select t2.a from t2 where t2.a=t1.a) union select t1.a, t1.b from t1) a; -explain select * from (select * from t1,t2 where t1.a=t2.a) t1; +explain select * from (select t1.*, t2.a as t2a from t1,t2 where t1.a=t2.a) t1; drop table t1, t2; create table t1(a int not null, t char(8), index(a)); disable_query_log; @@ -140,7 +140,6 @@ select * from ( select * from t1 union select * from t1) a,(select * from t1 uni explain select * from ( select * from t1 union select * from t1) a,(select * from t1 union select * from t1) b; drop table t1; - # # multi-update & multi-delete with derived tables # @@ -158,7 +157,7 @@ UPDATE `t1` AS P1 INNER JOIN (SELECT aaaa FROM `t1` GROUP BY N HAVING Count(M) > delete P1.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N; select * from t1; --replace_result P2 p2 ---error 1288 +--error ER_UNKNOWN_TABLE delete P1.*,P2.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N; -- error 1054 delete P1.* from `t1` AS P1 INNER JOIN (SELECT aaa FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N; @@ -224,6 +223,19 @@ select distinct sum(b) from t1 group by a; select distinct sum(b) from (select a,b from t1) y group by a; drop table t1; + +# +# Test for bug #7413 "Subquery with non-scalar results participating in +# select list of derived table crashes server" aka "VIEW with sub query can +# cause the MySQL server to crash". If we have encountered problem during +# filling of derived table we should report error and perform cleanup +# properly. +# +CREATE TABLE t1 (a char(10), b char(10)); +INSERT INTO t1 VALUES ('root','localhost'), ('root','%'); +--error 1242 +SELECT * FROM (SELECT (SELECT a.a FROM t1 AS a WHERE a.a = b.a) FROM t1 AS b) AS c; +DROP TABLE t1; # # test of union subquery in the FROM clause with complex distinct/all (BUG#6565) # @@ -237,4 +249,26 @@ select * from t1 union distinct select * from t2 union all select * from t3; select * from (select * from t1 union distinct select * from t2 union all select * from t3) X; drop table t1, t2, t3; +# +# Bug #11864 non unique names are allowed in subquery +# +create table t1 (a int); +create table t2 (a int); +--error 1060 +select * from (select * from t1,t2) foo; +drop table t1,t2; + +# +# Bug#10586 - query works with 4.1.8, but not with 4.1.11 +# +create table t1 (ID int unsigned not null auto_increment, + DATA varchar(5) not null, primary key (ID)); +create table t2 (ID int unsigned not null auto_increment, + DATA varchar(5) not null, FID int unsigned not null, + primary key (ID)); +select A.* from (t1 inner join (select * from t2) as A on t1.ID = A.FID); +select t2.* from ((select * from t1) as A inner join t2 on A.ID = t2.FID); +select t2.* from (select * from t1) as A inner join t2 on A.ID = t2.FID; +drop table t1, t2; + # End of 4.1 tests diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def index 9bfe9567d83..eaea7c710b0 100644 --- a/mysql-test/t/disabled.def +++ b/mysql-test/t/disabled.def @@ -10,3 +10,6 @@ # ############################################################################## +ndb_load : Bug#17233 +user_limits : Bug#23921 random failure of user_limits.test + diff --git a/mysql-test/t/distinct.test b/mysql-test/t/distinct.test index a057eee8e37..b671d7b06cd 100644 --- a/mysql-test/t/distinct.test +++ b/mysql-test/t/distinct.test @@ -326,11 +326,11 @@ drop table t1,t2; CREATE TABLE t1 ( html varchar(5) default NULL, rin int(11) default '0', - out int(11) default '0' + rout int(11) default '0' ) ENGINE=MyISAM; INSERT INTO t1 VALUES ('1',1,0); -SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin; +SELECT DISTINCT html,SUM(rout)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin; drop table t1; # @@ -378,6 +378,13 @@ EXPLAIN SELECT DISTINCT a,b,d FROM t2 GROUP BY c,b,d; DROP TABLE t1,t2; +# Bug 9784 DISTINCT IFNULL truncates data +# +create table t1 (id int, dsc varchar(50)); +insert into t1 values (1, "line number one"), (2, "line number two"), (3, "line number three"); +select distinct id, IFNULL(dsc, '-') from t1; +drop table t1; + # # Bug 21456: SELECT DISTINCT(x) produces incorrect results when using order by # @@ -389,6 +396,47 @@ explain SELECT DISTINCT a, b FROM t1 ORDER BY b; SELECT DISTINCT a, b FROM t1 ORDER BY b; DROP TABLE t1; +# End of 4.1 tests + + +# +# Bug #15745 ( COUNT(DISTINCT CONCAT(x,y)) returns wrong result) +# +CREATE TABLE t1 ( + ID int(11) NOT NULL auto_increment, + x varchar(20) default NULL, + y decimal(10,0) default NULL, + PRIMARY KEY (ID), + KEY (y) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +INSERT INTO t1 VALUES +(1,'ba','-1'), +(2,'ba','1150'), +(306,'ba','-1'), +(307,'ba','1150'), +(611,'ba','-1'), +(612,'ba','1150'); + +select count(distinct x,y) from t1; +select count(distinct concat(x,y)) from t1; +drop table t1; + +# +# Bug #18068: SELECT DISTINCT +# +CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a,b)); + +INSERT INTO t1 VALUES (1, 101); +INSERT INTO t1 SELECT a + 1, a + 101 FROM t1; +INSERT INTO t1 SELECT a + 2, a + 102 FROM t1; +INSERT INTO t1 SELECT a + 4, a + 104 FROM t1; +INSERT INTO t1 SELECT a + 8, a + 108 FROM t1; + +EXPLAIN SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a; +SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a; + +DROP TABLE t1; # #Bug #20836: Selecting into variables results in wrong results being returned # @@ -454,4 +502,3 @@ SELECT * FROM t2; DROP TABLE t1; DROP TABLE t2; -# End of 4.1 tests diff --git a/mysql-test/t/drop.test b/mysql-test/t/drop.test index 7cd943d46da..a1451773e90 100644 --- a/mysql-test/t/drop.test +++ b/mysql-test/t/drop.test @@ -81,3 +81,44 @@ show tables; drop table t1; # End of 4.1 tests + + +# +# Test for bug#21216 "Simultaneous DROP TABLE and SHOW OPEN TABLES causes +# server to crash". Crash (caused by failed assertion in 5.0 or by null +# pointer dereference in 5.1) happened when one ran SHOW OPEN TABLES +# while concurrently doing DROP TABLE (or RENAME TABLE, CREATE TABLE LIKE +# or any other command that takes name-lock) in other connection. +# +# Also includes test for similar bug#12212 "Crash that happens during +# removing of database name from cache" reappeared in 5.1 as bug#19403 +# In its case crash happened when one concurrently executed DROP DATABASE +# and one of name-locking command. +# +--disable_warnings +drop database if exists mysqltest; +drop table if exists t1; +--enable_warnings +create table t1 (i int); +lock tables t1 read; +create database mysqltest; +connect (addconroot1, localhost, root,,); +--send drop table t1 +connect (addconroot2, localhost, root,,); +# Server should not crash in any of the following statements +--disable_result_log +show open tables; +--enable_result_log +--send drop database mysqltest +connection default; +select 1; +unlock tables; +connection addconroot1; +--reap +connection addconroot2; +--reap +disconnect addconroot1; +disconnect addconroot2; +connection default; + +--echo End of 5.0 tests diff --git a/mysql-test/t/drop_temp_table.test b/mysql-test/t/drop_temp_table.test index 38c13e3e5e4..bc06de4096c 100644 --- a/mysql-test/t/drop_temp_table.test +++ b/mysql-test/t/drop_temp_table.test @@ -1,6 +1,10 @@ # Embedded server doesn't support binlog -- source include/not_embedded.inc +--disable_warnings +drop database if exists `drop-temp+table-test`; +--enable_warnings + connect (con1,localhost,root,,); connect (con2,localhost,root,,); connection con1; diff --git a/mysql-test/t/endspace.test b/mysql-test/t/endspace.test index 28b288e34a3..c4d53450910 100644 --- a/mysql-test/t/endspace.test +++ b/mysql-test/t/endspace.test @@ -41,16 +41,16 @@ alter table t1 modify text1 text not null, pack_keys=1; select concat('|', text1, '|') from t1 where text1='teststring'; select concat('|', text1, '|') from t1 where text1='teststring '; explain select concat('|', text1, '|') from t1 where text1='teststring '; -select * from t1 where text1 like 'teststring_%'; -select * from t1 where text1='teststring' or text1 like 'teststring_%'; +select concat('|', text1, '|') from t1 where text1 like 'teststring_%'; +select concat('|', text1, '|') from t1 where text1='teststring' or text1 like 'teststring_%'; select concat('|', text1, '|') from t1 where text1='teststring' or text1 > 'teststring\t'; select concat('|', text1, '|') from t1 order by text1; drop table t1; create table t1 (text1 varchar(32) not NULL, KEY key1 (text1)) pack_keys=0; insert into t1 values ('teststring'), ('nothing'), ('teststring\t'); -select * from t1 where text1='teststring' or text1 like 'teststring_%'; -select * from t1 where text1='teststring' or text1 >= 'teststring\t'; +select concat('|', text1, '|') from t1 where text1='teststring' or text1 like 'teststring_%'; +select concat('|', text1, '|') from t1 where text1='teststring' or text1 >= 'teststring\t'; drop table t1; # Test HEAP tables (with BTREE keys) diff --git a/mysql-test/t/errors.test b/mysql-test/t/errors.test index 93668ffdd3d..f5647a293e8 100644 --- a/mysql-test/t/errors.test +++ b/mysql-test/t/errors.test @@ -14,9 +14,9 @@ update t1 set a=1; create table t1 (a int); --error 1054 select count(test.t1.b) from t1; ---error 1109 +--error 1054 select count(not_existing_database.t1) from t1; ---error 1109 +--error 1054 select count(not_existing_database.t1.a) from t1; --error 1044,1146 select count(not_existing_database.t1.a) from not_existing_database.t1; @@ -31,3 +31,14 @@ select count(*),b from t1; drop table t1; # End of 4.1 tests + +# +# Bug #6080: Error message for a field with a display width that is too long +# +--error 1439 +create table t1 (a int(256)); +set sql_mode='traditional'; +--error 1074 +create table t1 (a varchar(66000)); + +# End of 5.0 tests diff --git a/mysql-test/t/execution_constants.test b/mysql-test/t/execution_constants.test new file mode 100644 index 00000000000..00967b2eeba --- /dev/null +++ b/mysql-test/t/execution_constants.test @@ -0,0 +1,74 @@ +# +# Bug#21476: Lost Database Connection During Query +# +# When the amount of stack space we think we need to report an error is +# actually too small, then we can get SEGVs. But, we don't want to reserve +# space that we could use to get real work done. So, we want the reserved +# space small, and this test verifies that the reservation is not too small. + +CREATE TABLE `t_bug21476` ( + `ID_BOARD` smallint(5) unsigned NOT NULL default '0', + `ID_MEMBER` mediumint(8) unsigned NOT NULL default '0', + `logTime` int(10) unsigned NOT NULL default '0', + `ID_MSG` mediumint(8) unsigned NOT NULL default '0', + PRIMARY KEY (`ID_MEMBER`,`ID_BOARD`), + KEY `logTime` (`logTime`) +) ENGINE=MyISAM DEFAULT CHARSET=cp1251 COLLATE=cp1251_bulgarian_ci; + +INSERT INTO `t_bug21476` VALUES (2,2,1154870939,0),(1,2,1154870957,0),(2,183,1154941362,0),(2,84,1154904301,0),(1,84,1154905867,0),(2,13,1154947484,10271),(3,84,1154880549,0),(1,6,1154892183,0),(2,25,1154947581,10271),(3,25,1154904760,0),(1,25,1154947373,10271),(1,179,1154899992,0),(2,179,1154899410,0),(5,25,1154901666,0),(2,329,1154902026,0),(3,329,1154902040,0),(1,329,1154902058,0),(1,13,1154930841,0),(3,85,1154904987,0),(1,183,1154929665,0),(3,13,1154931268,0),(1,85,1154936888,0),(1,169,1154937959,0),(2,169,1154941717,0),(3,183,1154939810,0),(3,169,1154941734,0); + +delimiter //; +let $query_head=UPDATE t_bug21476 SET ID_MSG = IF(logTime BETWEEN 1 AND 1101770053, 2, // +let $query_tail =) WHERE logTime BETWEEN 1 AND 1104091539 AND ID_MSG = 0// + +# Scan over the possible stack heights, trying to recurse to exactly that +# depth. Eventually, we will reach our imposed limit on height and try to +# raise an error. If the remaining stack space is enough to raise that error, +# we will get an error-number of 1436 and quit the loop. If it's not enough +# space, we should get a SEGV + +# Well more than enough recursions to find the end of our stack. +let $i = 100000// +disable_query_log// +disable_result_log// +while ($i) +{ + # If we SEGV because the min stack size is exceeded, this would return error + # 2013 . + error 0,1436 // + eval $query_head 0 $query_tail// + + if ($mysql_errno != 1436) + { + # We reached the place where we reported an error about the stack limit, + # and we successfully returned the error. That means that at the stack + # limit, we still have enough space reserved to report an error. + let $i = 1// + } + + # Multiplying by three stack frames should be fine enough resolution. + # Trading exactness for speed. + + # go one more level deep + let $query_head = $query_head IF(logTime <= 1104091$i, $i, // + let $query_tail =) $query_tail// + + # go one more level deep + let $query_head = $query_head IF(logTime <= 1105091$i, $i, // + let $query_tail =) $query_tail// + + # go one more level deep + let $query_head = $query_head IF(logTime <= 1106091$i, $i, // + let $query_tail =) $query_tail// + + dec $i// +} +enable_result_log// +enable_query_log// + +echo Assertion: mysql_errno 1436 == $mysql_errno// + +delimiter ;// +DROP TABLE `t_bug21476`; + +--echo End of 5.0 tests. diff --git a/mysql-test/t/explain.test b/mysql-test/t/explain.test index 5bfae0a96bb..efce0cdf3b5 100644 --- a/mysql-test/t/explain.test +++ b/mysql-test/t/explain.test @@ -43,3 +43,12 @@ drop table ÔÁÂ; set names latin1; # End of 4.1 tests + + +# +# Bug#15463: EXPLAIN SELECT..INTO hangs the client (QB, command line) +# +select 3 into @v1; +explain select 3 into @v1; + +# End of 5.0 tests. diff --git a/mysql-test/t/federated.test b/mysql-test/t/federated.test new file mode 100644 index 00000000000..c2218b3451b --- /dev/null +++ b/mysql-test/t/federated.test @@ -0,0 +1,1547 @@ +source include/federated.inc; + +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL, + `name` varchar(32) NOT NULL default '' + ) + DEFAULT CHARSET=latin1; + +connection master; +DROP TABLE IF EXISTS federated.t1; +# test too many items (malformed) in the comment string url +--error 1432 +CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL, + `name` varchar(32) NOT NULL default '' + ) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:@/too/many/items/federated/t1'; + +# test not enough items (malformed) in the comment string url +--error 1432 +CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL, + `name` varchar(32) NOT NULL default '' + ) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1'; + +# test non-existant table +--replace_result $SLAVE_MYPORT SLAVE_PORT +--error 1434 +eval CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL, + `name` varchar(32) NOT NULL default '' + ) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t3'; + +# test bad user/password +--replace_result $SLAVE_MYPORT SLAVE_PORT +--error 1429 +eval CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL, + `name` varchar(32) NOT NULL default '' + ) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://user:pass@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +DROP TABLE IF EXISTS federated.t1; +# # correct connection, same named tables +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL, + `name` varchar(32) NOT NULL default '' + ) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 (id, name) VALUES (1, 'foo'); +INSERT INTO federated.t1 (id, name) VALUES (2, 'fee'); + +SELECT * FROM federated.t1; +DELETE FROM federated.t1; +DROP TABLE federated.t1; + +# correct connection, differently named tables +DROP TABLE IF EXISTS federated.t2; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t2 ( + `id` int(20) NOT NULL, + `name` varchar(32) NOT NULL default '' + ) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval SHOW CREATE TABLE federated.t2; + +INSERT INTO federated.t2 (id, name) VALUES (1, 'foo'); +INSERT INTO federated.t2 (id, name) VALUES (2, 'fee'); + +SELECT * FROM federated.t2; +DROP TABLE federated.t2; + +connection slave; +DROP TABLE IF EXISTS federated.t1; + +DROP TABLE IF EXISTS federated.`t1%`; +CREATE TABLE federated.`t1%` ( + `id` int(20) NOT NULL, + `name` varchar(32) NOT NULL default '' + ) + DEFAULT CHARSET=latin1; + +connection master; +DROP TABLE IF EXISTS federated.t1; + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL, + `name` varchar(32) NOT NULL default '' + ) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1%'; + +INSERT INTO federated.t1 (id, name) VALUES (1, 'foo'); +INSERT INTO federated.t1 (id, name) VALUES (2, 'fee'); + +SELECT * FROM federated.t1; +DELETE FROM federated.t1; +DROP TABLE IF EXISTS federated.t1; + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.`t1%` ( + `id` int(20) NOT NULL, + `name` varchar(32) NOT NULL default '' + ) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1%'; + +INSERT INTO federated.`t1%` (id, name) VALUES (1, 'foo'); +INSERT INTO federated.`t1%` (id, name) VALUES (2, 'fee'); + +SELECT * FROM federated.`t1%`; +DELETE FROM federated.`t1%`; +DROP TABLE IF EXISTS federated.`t1%`; + +connection slave; +DROP TABLE IF EXISTS federated.`t1%`; + +# I wanted to use timestamp, but results will fail if so!!! +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + `name` varchar(32) NOT NULL default '', + `other` int(20) NOT NULL default '0', + `created` datetime default '2004-04-04 04:04:04', + PRIMARY KEY (`id`)) + DEFAULT CHARSET=latin1; + +connection master; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + `name` varchar(32) NOT NULL default '', + `other` int(20) NOT NULL default '0', + `created` datetime default '2004-04-04 04:04:04', + PRIMARY KEY (`id`)) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 (name, other) VALUES ('First Name', 11111); +INSERT INTO federated.t1 (name, other) VALUES ('Second Name', 22222); +INSERT INTO federated.t1 (name, other) VALUES ('Third Name', 33333); +INSERT INTO federated.t1 (name, other) VALUES ('Fourth Name', 44444); +INSERT INTO federated.t1 (name, other) VALUES ('Fifth Name', 55555); +INSERT INTO federated.t1 (name, other) VALUES ('Sixth Name', 66666); +INSERT INTO federated.t1 (name, other) VALUES ('Seventh Name', 77777); +INSERT INTO federated.t1 (name, other) VALUES ('Eigth Name', 88888); +INSERT INTO federated.t1 (name, other) VALUES ('Ninth Name', 99999); +INSERT INTO federated.t1 (name, other) VALUES ('Tenth Name', 101010); + +# basic select +SELECT * FROM federated.t1; +# with PRIMARY KEY index_read_idx +SELECT * FROM federated.t1 WHERE id = 5; +SELECT * FROM federated.t1 WHERE name = 'Sixth Name'; +SELECT * FROM federated.t1 WHERE id = 6 and name = 'Sixth Name'; +SELECT * FROM federated.t1 WHERE name = 'Sixth Name' AND other = 44444; +SELECT * FROM federated.t1 WHERE name like '%th%'; +UPDATE federated.t1 SET name = '3rd name' WHERE id = 3; +SELECT * FROM federated.t1 WHERE name = '3rd name'; +UPDATE federated.t1 SET name = 'Third name' WHERE name = '3rd name'; +SELECT * FROM federated.t1 WHERE name = 'Third name'; +# rnd_post, ::position +SELECT * FROM federated.t1 ORDER BY id DESC; +SELECT * FROM federated.t1 ORDER BY name; +SELECT * FROM federated.t1 ORDER BY name DESC; +SELECT * FROM federated.t1 ORDER BY name ASC; +SELECT * FROM federated.t1 GROUP BY other; + +# ::delete_row +DELETE FROM federated.t1 WHERE id = 5; +SELECT * FROM federated.t1 WHERE id = 5; + +# ::delete_all_rows +DELETE FROM federated.t1; +SELECT * FROM federated.t1 WHERE id = 5; + +# previous test, but this time with indexes +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + `name` varchar(32) NOT NULL default '', + `other` int(20) NOT NULL default '0', + `created` datetime NOT NULL, + PRIMARY KEY (`id`), + key name(`name`), + key other(`other`), + key created(`created`)) + DEFAULT CHARSET=latin1; + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + `name` varchar(32) NOT NULL default '', + `other` int(20) NOT NULL default '0', + `created` datetime NOT NULL, + PRIMARY KEY (`id`), + key name(`name`), + key other(`other`), + key created(`created`)) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 (name, other, created) + VALUES ('First Name', 11111, '2004-01-01 01:01:01'); +INSERT INTO federated.t1 (name, other, created) + VALUES ('Second Name', 22222, '2004-01-23 02:43:00'); +INSERT INTO federated.t1 (name, other, created) + VALUES ('Third Name', 33333, '2004-02-14 02:14:00'); +INSERT INTO federated.t1 (name, other, created) + VALUES ('Fourth Name', 44444, '2003-04-05 00:00:00'); +INSERT INTO federated.t1 (name, other, created) + VALUES ('Fifth Name', 55555, '2001-02-02 02:02:02'); +INSERT INTO federated.t1 (name, other, created) + VALUES ('Sixth Name', 66666, '2005-06-06 15:30:00'); +INSERT INTO federated.t1 (name, other, created) + VALUES ('Seventh Name', 77777, '2003-12-12 18:32:00'); +INSERT INTO federated.t1 (name, other, created) + VALUES ('Eigth Name', 88888, '2005-03-12 11:00:00'); +INSERT INTO federated.t1 (name, other, created) + VALUES ('Ninth Name', 99999, '2005-03-12 11:00:01'); +INSERT INTO federated.t1 (name, other, created) + VALUES ('Tenth Name', 101010, '2005-03-12 12:00:01'); + +# basic select +SELECT * FROM federated.t1; +# with PRIMARY KEY index_read_idx +SELECT * FROM federated.t1 WHERE id = 5; +# with regular key index_read -> index_read_idx +# regular and PRIMARY KEY index_read_idx +SELECT * FROM federated.t1 WHERE id = 6 and name = 'Sixth Name'; +# with regular key index_read -> index_read_idx +SELECT * FROM federated.t1 WHERE other = 44444; +SELECT * FROM federated.t1 WHERE name like '%th%'; +# update - update_row, index_read_idx +UPDATE federated.t1 SET name = '3rd name' WHERE id = 3; +SELECT * FROM federated.t1 WHERE name = '3rd name'; +# update - update_row, index_read -> index_read_idx +UPDATE federated.t1 SET name = 'Third name' WHERE name = '3rd name'; +SELECT * FROM federated.t1 WHERE name = 'Third name'; +# rnd_post, ::position +SELECT * FROM federated.t1 ORDER BY id DESC; +SELECT * FROM federated.t1 ORDER BY name; +SELECT * FROM federated.t1 ORDER BY name DESC; +SELECT * FROM federated.t1 ORDER BY name ASC; +SELECT * FROM federated.t1 GROUP BY other; + +# ::delete_row +DELETE FROM federated.t1 WHERE id = 5; +SELECT * FROM federated.t1 WHERE id = 5; + +# ::delete_all_rows +DELETE FROM federated.t1; +SELECT * FROM federated.t1 WHERE id = 5; +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + `name` varchar(32), + `other` varchar(20), + PRIMARY KEY (`id`) ); + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + `name` varchar(32), + `other` varchar(20), + PRIMARY KEY (`id`) ) + ENGINE="FEDERATED" + DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 (name, other) VALUES ('First Name', 11111); +INSERT INTO federated.t1 (name, other) VALUES ('Second Name', NULL); +INSERT INTO federated.t1 (name, other) VALUES ('Third Name', 33333); +INSERT INTO federated.t1 (name, other) VALUES (NULL, NULL); +INSERT INTO federated.t1 (name, other) VALUES ('Fifth Name', 55555); +INSERT INTO federated.t1 (name, other) VALUES ('Sixth Name', 66666); +INSERT INTO federated.t1 (name) VALUES ('Seventh Name'); +INSERT INTO federated.t1 (name, other) VALUES ('Eigth Name', 88888); +INSERT INTO federated.t1 (name, other) VALUES ('Ninth Name', 99999); +INSERT INTO federated.t1 (other) VALUES ('fee fie foe fum'); + +SELECT * FROM federated.t1 WHERE other IS NULL; +SELECT * FROM federated.t1 WHERE name IS NULL; +SELECT * FROM federated.t1 WHERE name IS NULL and other IS NULL; +SELECT * FROM federated.t1 WHERE name IS NULL or other IS NULL; + +UPDATE federated.t1 +SET name = 'Fourth Name', other = 'four four four' +WHERE name IS NULL AND other IS NULL; + +UPDATE federated.t1 SET other = 'two two two two' WHERE name = 'Second Name'; +UPDATE federated.t1 SET other = 'seven seven' WHERE name like 'Sev%'; +UPDATE federated.t1 SET name = 'Tenth Name' WHERE other like 'fee fie%'; +SELECT * FROM federated.t1 WHERE name IS NULL OR other IS NULL ; +SELECT * FROM federated.t1; + +# test multi-keys +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + `name` varchar(32) NOT NULL DEFAULT '', + `other` varchar(20) NOT NULL DEFAULT '', + PRIMARY KEY (`id`), + KEY nameoth (name, other) ); + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + `name` varchar(32) NOT NULL DEFAULT '', + `other` varchar(20) NOT NULL DEFAULT '', + PRIMARY KEY (`id`), + KEY nameoth (name, other)) + ENGINE="FEDERATED" DEFAULT + CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 (name, other) VALUES ('First Name', '1111'); +INSERT INTO federated.t1 (name, other) VALUES ('Second Name', '2222'); +INSERT INTO federated.t1 (name, other) VALUES ('Third Name', '3333'); +SELECT * FROM federated.t1 WHERE name = 'Second Name'; +SELECT * FROM federated.t1 WHERE other = '2222'; +SELECT * FROM federated.t1 WHERE name = 'Third Name'; +SELECT * FROM federated.t1 WHERE name = 'Third Name' AND other = '3333'; + +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `id` int NOT NULL auto_increment, + `name` char(32) NOT NULL DEFAULT '', + `bincol` binary(1) NOT NULL, + `floatval` decimal(5,2) NOT NULL DEFAULT 0.0, + `other` int NOT NULL DEFAULT 0, + PRIMARY KEY (id), + KEY nameoth(name, other), + KEY bincol(bincol), + KEY floatval(floatval)); + +# test other types of indexes +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int NOT NULL auto_increment, + `name` char(32) NOT NULL DEFAULT '', + `bincol` binary(1) NOT NULL, + `floatval` decimal(5,2) NOT NULL DEFAULT 0.0, + `other` int NOT NULL DEFAULT 0, + PRIMARY KEY (id), + KEY nameoth(name,other), + KEY bincol(bincol), + KEY floatval(floatval)) + ENGINE="FEDERATED" + DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 (name, bincol, floatval, other) + VALUES ('first', 0x65, 11.11, 1111); +INSERT INTO federated.t1 (name, bincol, floatval, other) + VALUES ('second', 0x66, 22.22, 2222); +INSERT INTO federated.t1 (name, bincol, floatval, other) + VALUES ('third', 'g', 22.22, 2222); +SELECT * FROM federated.t1; +SELECT * FROM federated.t1 WHERE name = 'second'; +SELECT * FROM federated.t1 WHERE bincol= 'f'; +SELECT * FROM federated.t1 WHERE bincol= 0x66; +SELECT * FROM federated.t1 WHERE bincol= 0x67; +SELECT * FROM federated.t1 WHERE bincol= 'g'; +SELECT * FROM federated.t1 WHERE floatval=11.11; +SELECT * FROM federated.t1 WHERE name='third'; +SELECT * FROM federated.t1 WHERE other=2222; +SELECT * FROM federated.t1 WHERE name='third' and other=2222; + +# more multi-column indexes, in the primary key +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `id` int NOT NULL auto_increment, + `col1` int(10) NOT NULL DEFAULT 0, + `col2` varchar(64) NOT NULL DEFAULT '', + `col3` int(20) NOT NULL, + `col4` int(40) NOT NULL, + primary key (`id`, `col1`, `col2`, `col3`, `col4`), + key col1(col1), + key col2(col2), + key col3(col3), + key col4(col4)); + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int NOT NULL auto_increment, + `col1` int(10) NOT NULL DEFAULT 0, + `col2` varchar(64) NOT NULL DEFAULT '', + `col3` int(20) NOT NULL, + `col4` int(40) NOT NULL, + primary key (`id`, `col1`, `col2`, `col3`, `col4`), + key col1(col1), + key col2(col2), + key col3(col3), + key col4(col4)) + ENGINE="FEDERATED" + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES (1, 'one One', 11, 1111); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES (2, 'Two two', 22, 2222); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES (3, 'three Three', 33, 33333); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES (4, 'fourfourfour', 444, 4444444); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES (5, 'five 5 five five 5', 5, 55555); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES (6, 'six six Sixsix', 6666, 6); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES (7, 'seven Sevenseven', 77777, 7777); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES (8, 'eight eight eight', 88888, 88); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES (9, 'nine Nine', 999999, 999999); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES (10, 'Tenth ten TEN', 1010101, 1010); + +SELECT * FROM federated.t1 WHERE col2 = 'two two'; +SELECT * FROM federated.t1 WHERE col2 = 'two Two'; +SELECT * FROM federated.t1 WHERE id = 3; +SELECT * FROM federated.t1 WHERE id = 3 AND col1 = 3; +SELECT * FROM federated.t1 WHERE id = 4 AND col1 = 4 AND col2 = 'Two two'; +SELECT * FROM federated.t1 WHERE id = 4 AND col1 = 4 AND col2 = 'fourfourfour'; +SELECT * FROM federated.t1 WHERE id = 5 AND col2 = 'five 5 five five 5' + AND col3 = 5; +SELECT * FROM federated.t1 WHERE id = 5 AND col2 = 'five 5 five five 5' + AND col3 = 5 + AND col4 = 55555; +SELECT * FROM federated.t1 WHERE id = 5 + AND col2 = 'Two two' AND col3 = 22 + AND col4 = 33; +SELECT * FROM federated.t1 WHERE id = 5 + AND col2 = 'five 5 five five 5' AND col3 = 5 + AND col4 = 55555; +SELECT * FROM federated.t1 WHERE (id = 5 AND col2 = 'five 5 five five 5') + OR (col2 = 'three Three' AND col3 = 33); +SELECT * FROM federated.t1 WHERE (id = 5 AND col2 = 'Two two') + OR (col2 = 444 AND col3 = 4444444); +SELECT * FROM federated.t1 WHERE id = 1 + OR col1 = 10 + OR col2 = 'Two two' + OR col3 = 33 + OR col4 = 4444444; +SELECT * FROM federated.t1 WHERE id > 5; +SELECT * FROM federated.t1 WHERE id >= 5; +SELECT * FROM federated.t1 WHERE id < 5; +SELECT * FROM federated.t1 WHERE id <= 5; +SELECT * FROM federated.t1 WHERE id != 5; +SELECT * FROM federated.t1 WHERE id > 3 AND id < 7; +SELECT * FROM federated.t1 WHERE id > 3 AND id <= 7; +SELECT * FROM federated.t1 WHERE id >= 3 AND id <= 7; +SELECT * FROM federated.t1 WHERE id < 3 AND id <= 7; +SELECT * FROM federated.t1 WHERE id < 3 AND id > 7; +SELECT * FROM federated.t1 WHERE id < 3 OR id > 7; +SELECT * FROM federated.t1 WHERE col2 = 'three Three'; +SELECT * FROM federated.t1 WHERE col2 > 'one'; +SELECT * FROM federated.t1 WHERE col2 LIKE 's%'; +SELECT * FROM federated.t1 WHERE col2 LIKE 'si%'; +SELECT * FROM federated.t1 WHERE col2 LIKE 'se%'; +SELECT * FROM federated.t1 WHERE col2 NOT LIKE 'e%'; +SELECT * FROM federated.t1 WHERE col2 <> 'one One'; + +# more multi-column indexes, in the primary key +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `col1` varchar(8) NOT NULL DEFAULT '', + `col2` varchar(128) NOT NULL DEFAULT '', + `col3` varchar(20) NOT NULL DEFAULT '', + `col4` varchar(40) NOT NULL DEFAULT '', + primary key (`col1`, `col2`, `col3`, `col4`), + key 3key(`col2`,`col3`,`col4`), + key 2key (`col3`,`col4`), + key col4(col4)); + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `col1` varchar(8) NOT NULL DEFAULT '', + `col2` varchar(128) NOT NULL DEFAULT '', + `col3` varchar(20) NOT NULL DEFAULT '', + `col4` varchar(40) NOT NULL DEFAULT '', + primary key (`col1`, `col2`, `col3`, `col4`), + key 3key(`col2`,`col3`,`col4`), + key 2key (`col3`,`col4`), + key col4(col4)) + ENGINE="FEDERATED" + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES ('aaaa', 'aaaaaaaaaaaaaaaaaaa', 'ababababab', 'acacacacacacacac'); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES ('bbbb', 'bbbbbbbbbbbbbbbbbbb', 'bababababa', 'bcbcbcbcbcbcbcbc'); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES ('cccc', 'ccccccccccccccccccc', 'cacacacaca', 'cbcbcbcbcbcbcbcb'); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES ('dddd', 'ddddddddddddddddddd', 'dadadadada', 'dcdcdcdcdcdcdcdc'); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES ('eeee', 'eeeeeeeeeeeeeeeeeee', 'eaeaeaeaea', 'ecececececececec'); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES ('ffff', 'fffffffffffffffffff', 'fafafafafa', 'fcfcfcfcfcfcfcfc'); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES ('gggg', 'ggggggggggggggggggg', 'gagagagaga', 'gcgcgcgcgcgcgcgc'); +INSERT INTO federated.t1 (col1, col2, col3, col4) + VALUES ('hhhh', 'hhhhhhhhhhhhhhhhhhh', 'hahahahaha', 'hchchchchchchchc'); + +SELECT * FROM federated.t1 WHERE col1 = 'cccc'; +SELECT * FROM federated.t1 WHERE col2 = 'eeeeeeeeeeeeeeeeeee'; +SELECT * FROM federated.t1 WHERE col3 = 'bababababa'; +SELECT * FROM federated.t1 WHERE col1 = 'gggg' AND col2 = 'ggggggggggggggggggg'; +SELECT * FROM federated.t1 WHERE col1 = 'gggg' AND col3 = 'gagagagaga'; +SELECT * FROM federated.t1 WHERE col1 = 'ffff' AND col4 = 'fcfcfcfcfcfcfcfc'; +SELECT * FROM federated.t1 WHERE col1 > 'bbbb'; +SELECT * FROM federated.t1 WHERE col1 >= 'bbbb'; +SELECT * FROM federated.t1 WHERE col1 < 'bbbb'; +SELECT * FROM federated.t1 WHERE col1 <= 'bbbb'; +SELECT * FROM federated.t1 WHERE col1 <> 'bbbb'; +SELECT * FROM federated.t1 WHERE col1 LIKE 'b%'; +SELECT * FROM federated.t1 WHERE col4 LIKE '%b%'; +SELECT * FROM federated.t1 WHERE col1 NOT LIKE 'c%'; +SELECT * FROM federated.t1 WHERE col4 NOT LIKE '%c%'; +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `col1` varchar(8) NOT NULL DEFAULT '', + `col2` int(8) NOT NULL DEFAULT 0, + `col3` varchar(8) NOT NULL DEFAULT '', + primary key (`col1`, `col2`, `col3`)); + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `col1` varchar(8) NOT NULL DEFAULT '', + `col2` varchar(8) NOT NULL DEFAULT '', + `col3` varchar(8) NOT NULL DEFAULT '', + primary key (`col1`, `col2`, `col3`)) + ENGINE="FEDERATED" + DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 VALUES ('a00', '110', 'cc0'); +INSERT INTO federated.t1 VALUES ('aaa', '111', 'ccc'); +INSERT INTO federated.t1 VALUES ('bbb', '222', 'yyy'); +INSERT INTO federated.t1 VALUES ('ccc', '111', 'zzz'); +INSERT INTO federated.t1 VALUES ('ccd', '112', 'zzzz'); + +# let's see what the foreign database says +connection slave; +SELECT col3 FROM federated.t1 WHERE ( +(col1 = 'aaa' AND col2 >= '111') OR col1 > 'aaa') AND +(col1 < 'ccc' OR ( col1 = 'ccc' AND col2 <= '111')); + +connection master; +SELECT col3 FROM federated.t1 WHERE ( +(col1 = 'aaa' AND col2 >= '111') OR col1 > 'aaa') AND +(col1 < 'ccc' OR ( col1 = 'ccc' AND col2 <= '111')); + +# test NULLs +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `id` int, + `name` varchar(32), + `floatval` float, + `other` int) +DEFAULT CHARSET=latin1; + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int, + `name` varchar(32), + `floatval` float, + `other` int) +ENGINE="FEDERATED" +DEFAULT CHARSET=latin1 +CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +# these both should be the same +INSERT INTO federated.t1 values (NULL, NULL, NULL, NULL); +INSERT INTO federated.t1 values (); +INSERT INTO federated.t1 (id) VALUES (1); +INSERT INTO federated.t1 (name, floatval, other) + VALUES ('foo', 33.33333332, NULL); +INSERT INTO federated.t1 (name, floatval, other) + VALUES (0, 00.3333, NULL); +SELECT * FROM federated.t1; +SELECT count(*) FROM federated.t1 +WHERE id IS NULL +AND name IS NULL +AND floatval IS NULL +AND other IS NULL; + +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `blurb_id` int NOT NULL DEFAULT 0, + `blurb` text default '', + PRIMARY KEY (blurb_id)) + DEFAULT CHARSET=latin1; + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `blurb_id` int NOT NULL DEFAULT 0, + `blurb` text default '', + PRIMARY KEY (blurb_id)) + ENGINE="FEDERATED" + DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 VALUES (1, " MySQL supports a number of column types in several categories: numeric types, date and time types, and string (character) types. This chapter first gives an overview of these column types, and then provides a more detailed description of the properties of the types in each category, and a summary of the column type storage requirements. The overview is intentionally brief. The more detailed descriptions should be consulted for additional information about particular column types, such as the allowable formats in which you can specify values."); +INSERT INTO federated.t1 VALUES (2, "All arithmetic is done using signed BIGINT or DOUBLE values, so you should not use unsigned big integers larger than 9223372036854775807 (63 bits) except with bit functions! If you do that, some of the last digits in the result may be wrong because of rounding errors when converting a BIGINT value to a DOUBLE."); +INSERT INTO federated.t1 VALUES (3, " A floating-point number. p represents the precision. It can be from 0 to 24 for a single-precision floating-point number and from 25 to 53 for a double-precision floating-point number. These types are like the FLOAT and DOUBLE types described immediately following. FLOAT(p) has the same range as the corresponding FLOAT and DOUBLE types, but the display size and number of decimals are undefined. "); +INSERT INTO federated.t1 VALUES(4, "Die Übersetzung einer so umfangreichen technischen Dokumentation wie des MySQL-Referenzhandbuchs ist schon eine besondere Herausforderung. Zumindest für jemanden, der seine Zielsprache ernst nimmt:"); +SELECT * FROM federated.t1; + +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `a` int NOT NULL, + `b` int NOT NULL, + `c` int NOT NULL, + PRIMARY KEY (a),key(b)); + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `a` int NOT NULL, + `b` int NOT NULL, + `c` int NOT NULL, + PRIMARY KEY (a), + KEY (b)) + ENGINE="FEDERATED" + DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 VALUES (3,3,3),(1,1,1),(2,2,2),(4,4,4); + +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 (i1 int, i2 int, i3 int, i4 int, i5 int, i6 int, i7 int, i8 +int, i9 int, i10 int, i11 int, i12 int, i13 int, i14 int, i15 int, i16 int, i17 +int, i18 int, i19 int, i20 int, i21 int, i22 int, i23 int, i24 int, i25 int, +i26 int, i27 int, i28 int, i29 int, i30 int, i31 int, i32 int, i33 int, i34 +int, i35 int, i36 int, i37 int, i38 int, i39 int, i40 int, i41 int, i42 int, +i43 int, i44 int, i45 int, i46 int, i47 int, i48 int, i49 int, i50 int, i51 +int, i52 int, i53 int, i54 int, i55 int, i56 int, i57 int, i58 int, i59 int, +i60 int, i61 int, i62 int, i63 int, i64 int, i65 int, i66 int, i67 int, i68 +int, i69 int, i70 int, i71 int, i72 int, i73 int, i74 int, i75 int, i76 int, +i77 int, i78 int, i79 int, i80 int, i81 int, i82 int, i83 int, i84 int, i85 +int, i86 int, i87 int, i88 int, i89 int, i90 int, i91 int, i92 int, i93 int, +i94 int, i95 int, i96 int, i97 int, i98 int, i99 int, i100 int, i101 int, i102 +int, i103 int, i104 int, i105 int, i106 int, i107 int, i108 int, i109 int, i110 +int, i111 int, i112 int, i113 int, i114 int, i115 int, i116 int, i117 int, i118 +int, i119 int, i120 int, i121 int, i122 int, i123 int, i124 int, i125 int, i126 +int, i127 int, i128 int, i129 int, i130 int, i131 int, i132 int, i133 int, i134 +int, i135 int, i136 int, i137 int, i138 int, i139 int, i140 int, i141 int, i142 +int, i143 int, i144 int, i145 int, i146 int, i147 int, i148 int, i149 int, i150 +int, i151 int, i152 int, i153 int, i154 int, i155 int, i156 int, i157 int, i158 +int, i159 int, i160 int, i161 int, i162 int, i163 int, i164 int, i165 int, i166 +int, i167 int, i168 int, i169 int, i170 int, i171 int, i172 int, i173 int, i174 +int, i175 int, i176 int, i177 int, i178 int, i179 int, i180 int, i181 int, i182 +int, i183 int, i184 int, i185 int, i186 int, i187 int, i188 int, i189 int, i190 +int, i191 int, i192 int, i193 int, i194 int, i195 int, i196 int, i197 int, i198 +int, i199 int, i200 int, i201 int, i202 int, i203 int, i204 int, i205 int, i206 +int, i207 int, i208 int, i209 int, i210 int, i211 int, i212 int, i213 int, i214 +int, i215 int, i216 int, i217 int, i218 int, i219 int, i220 int, i221 int, i222 +int, i223 int, i224 int, i225 int, i226 int, i227 int, i228 int, i229 int, i230 +int, i231 int, i232 int, i233 int, i234 int, i235 int, i236 int, i237 int, i238 +int, i239 int, i240 int, i241 int, i242 int, i243 int, i244 int, i245 int, i246 +int, i247 int, i248 int, i249 int, i250 int, i251 int, i252 int, i253 int, i254 +int, i255 int, i256 int, i257 int, i258 int, i259 int, i260 int, i261 int, i262 +int, i263 int, i264 int, i265 int, i266 int, i267 int, i268 int, i269 int, i270 +int, i271 int, i272 int, i273 int, i274 int, i275 int, i276 int, i277 int, i278 +int, i279 int, i280 int, i281 int, i282 int, i283 int, i284 int, i285 int, i286 +int, i287 int, i288 int, i289 int, i290 int, i291 int, i292 int, i293 int, i294 +int, i295 int, i296 int, i297 int, i298 int, i299 int, i300 int, i301 int, i302 +int, i303 int, i304 int, i305 int, i306 int, i307 int, i308 int, i309 int, i310 +int, i311 int, i312 int, i313 int, i314 int, i315 int, i316 int, i317 int, i318 +int, i319 int, i320 int, i321 int, i322 int, i323 int, i324 int, i325 int, i326 +int, i327 int, i328 int, i329 int, i330 int, i331 int, i332 int, i333 int, i334 +int, i335 int, i336 int, i337 int, i338 int, i339 int, i340 int, i341 int, i342 +int, i343 int, i344 int, i345 int, i346 int, i347 int, i348 int, i349 int, i350 +int, i351 int, i352 int, i353 int, i354 int, i355 int, i356 int, i357 int, i358 +int, i359 int, i360 int, i361 int, i362 int, i363 int, i364 int, i365 int, i366 +int, i367 int, i368 int, i369 int, i370 int, i371 int, i372 int, i373 int, i374 +int, i375 int, i376 int, i377 int, i378 int, i379 int, i380 int, i381 int, i382 +int, i383 int, i384 int, i385 int, i386 int, i387 int, i388 int, i389 int, i390 +int, i391 int, i392 int, i393 int, i394 int, i395 int, i396 int, i397 int, i398 +int, i399 int, i400 int, i401 int, i402 int, i403 int, i404 int, i405 int, i406 +int, i407 int, i408 int, i409 int, i410 int, i411 int, i412 int, i413 int, i414 +int, i415 int, i416 int, i417 int, i418 int, i419 int, i420 int, i421 int, i422 +int, i423 int, i424 int, i425 int, i426 int, i427 int, i428 int, i429 int, i430 +int, i431 int, i432 int, i433 int, i434 int, i435 int, i436 int, i437 int, i438 +int, i439 int, i440 int, i441 int, i442 int, i443 int, i444 int, i445 int, i446 +int, i447 int, i448 int, i449 int, i450 int, i451 int, i452 int, i453 int, i454 +int, i455 int, i456 int, i457 int, i458 int, i459 int, i460 int, i461 int, i462 +int, i463 int, i464 int, i465 int, i466 int, i467 int, i468 int, i469 int, i470 +int, i471 int, i472 int, i473 int, i474 int, i475 int, i476 int, i477 int, i478 +int, i479 int, i480 int, i481 int, i482 int, i483 int, i484 int, i485 int, i486 +int, i487 int, i488 int, i489 int, i490 int, i491 int, i492 int, i493 int, i494 +int, i495 int, i496 int, i497 int, i498 int, i499 int, i500 int, i501 int, i502 +int, i503 int, i504 int, i505 int, i506 int, i507 int, i508 int, i509 int, i510 +int, i511 int, i512 int, i513 int, i514 int, i515 int, i516 int, i517 int, i518 +int, i519 int, i520 int, i521 int, i522 int, i523 int, i524 int, i525 int, i526 +int, i527 int, i528 int, i529 int, i530 int, i531 int, i532 int, i533 int, i534 +int, i535 int, i536 int, i537 int, i538 int, i539 int, i540 int, i541 int, i542 +int, i543 int, i544 int, i545 int, i546 int, i547 int, i548 int, i549 int, i550 +int, i551 int, i552 int, i553 int, i554 int, i555 int, i556 int, i557 int, i558 +int, i559 int, i560 int, i561 int, i562 int, i563 int, i564 int, i565 int, i566 +int, i567 int, i568 int, i569 int, i570 int, i571 int, i572 int, i573 int, i574 +int, i575 int, i576 int, i577 int, i578 int, i579 int, i580 int, i581 int, i582 +int, i583 int, i584 int, i585 int, i586 int, i587 int, i588 int, i589 int, i590 +int, i591 int, i592 int, i593 int, i594 int, i595 int, i596 int, i597 int, i598 +int, i599 int, i600 int, i601 int, i602 int, i603 int, i604 int, i605 int, i606 +int, i607 int, i608 int, i609 int, i610 int, i611 int, i612 int, i613 int, i614 +int, i615 int, i616 int, i617 int, i618 int, i619 int, i620 int, i621 int, i622 +int, i623 int, i624 int, i625 int, i626 int, i627 int, i628 int, i629 int, i630 +int, i631 int, i632 int, i633 int, i634 int, i635 int, i636 int, i637 int, i638 +int, i639 int, i640 int, i641 int, i642 int, i643 int, i644 int, i645 int, i646 +int, i647 int, i648 int, i649 int, i650 int, i651 int, i652 int, i653 int, i654 +int, i655 int, i656 int, i657 int, i658 int, i659 int, i660 int, i661 int, i662 +int, i663 int, i664 int, i665 int, i666 int, i667 int, i668 int, i669 int, i670 +int, i671 int, i672 int, i673 int, i674 int, i675 int, i676 int, i677 int, i678 +int, i679 int, i680 int, i681 int, i682 int, i683 int, i684 int, i685 int, i686 +int, i687 int, i688 int, i689 int, i690 int, i691 int, i692 int, i693 int, i694 +int, i695 int, i696 int, i697 int, i698 int, i699 int, i700 int, i701 int, i702 +int, i703 int, i704 int, i705 int, i706 int, i707 int, i708 int, i709 int, i710 +int, i711 int, i712 int, i713 int, i714 int, i715 int, i716 int, i717 int, i718 +int, i719 int, i720 int, i721 int, i722 int, i723 int, i724 int, i725 int, i726 +int, i727 int, i728 int, i729 int, i730 int, i731 int, i732 int, i733 int, i734 +int, i735 int, i736 int, i737 int, i738 int, i739 int, i740 int, i741 int, i742 +int, i743 int, i744 int, i745 int, i746 int, i747 int, i748 int, i749 int, i750 +int, i751 int, i752 int, i753 int, i754 int, i755 int, i756 int, i757 int, i758 +int, i759 int, i760 int, i761 int, i762 int, i763 int, i764 int, i765 int, i766 +int, i767 int, i768 int, i769 int, i770 int, i771 int, i772 int, i773 int, i774 +int, i775 int, i776 int, i777 int, i778 int, i779 int, i780 int, i781 int, i782 +int, i783 int, i784 int, i785 int, i786 int, i787 int, i788 int, i789 int, i790 +int, i791 int, i792 int, i793 int, i794 int, i795 int, i796 int, i797 int, i798 +int, i799 int, i800 int, i801 int, i802 int, i803 int, i804 int, i805 int, i806 +int, i807 int, i808 int, i809 int, i810 int, i811 int, i812 int, i813 int, i814 +int, i815 int, i816 int, i817 int, i818 int, i819 int, i820 int, i821 int, i822 +int, i823 int, i824 int, i825 int, i826 int, i827 int, i828 int, i829 int, i830 +int, i831 int, i832 int, i833 int, i834 int, i835 int, i836 int, i837 int, i838 +int, i839 int, i840 int, i841 int, i842 int, i843 int, i844 int, i845 int, i846 +int, i847 int, i848 int, i849 int, i850 int, i851 int, i852 int, i853 int, i854 +int, i855 int, i856 int, i857 int, i858 int, i859 int, i860 int, i861 int, i862 +int, i863 int, i864 int, i865 int, i866 int, i867 int, i868 int, i869 int, i870 +int, i871 int, i872 int, i873 int, i874 int, i875 int, i876 int, i877 int, i878 +int, i879 int, i880 int, i881 int, i882 int, i883 int, i884 int, i885 int, i886 +int, i887 int, i888 int, i889 int, i890 int, i891 int, i892 int, i893 int, i894 +int, i895 int, i896 int, i897 int, i898 int, i899 int, i900 int, i901 int, i902 +int, i903 int, i904 int, i905 int, i906 int, i907 int, i908 int, i909 int, i910 +int, i911 int, i912 int, i913 int, i914 int, i915 int, i916 int, i917 int, i918 +int, i919 int, i920 int, i921 int, i922 int, i923 int, i924 int, i925 int, i926 +int, i927 int, i928 int, i929 int, i930 int, i931 int, i932 int, i933 int, i934 +int, i935 int, i936 int, i937 int, i938 int, i939 int, i940 int, i941 int, i942 +int, i943 int, i944 int, i945 int, i946 int, i947 int, i948 int, i949 int, i950 +int, i951 int, i952 int, i953 int, i954 int, i955 int, i956 int, i957 int, i958 +int, i959 int, i960 int, i961 int, i962 int, i963 int, i964 int, i965 int, i966 +int, i967 int, i968 int, i969 int, i970 int, i971 int, i972 int, i973 int, i974 +int, i975 int, i976 int, i977 int, i978 int, i979 int, i980 int, i981 int, i982 +int, i983 int, i984 int, i985 int, i986 int, i987 int, i988 int, i989 int, i990 +int, i991 int, i992 int, i993 int, i994 int, i995 int, i996 int, i997 int, i998 +int, i999 int, i1000 int, b varchar(256)) row_format=dynamic; + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 +(i1 int, i2 int, i3 int, i4 int, i5 int, i6 int, i7 int, i8 +int, i9 int, i10 int, i11 int, i12 int, i13 int, i14 int, i15 int, i16 int, +i17 int, i18 int, i19 int, i20 int, i21 int, i22 int, i23 int, i24 int, i25 int, +i26 int, i27 int, i28 int, i29 int, i30 int, i31 int, i32 int, i33 int, i34 +int, i35 int, i36 int, i37 int, i38 int, i39 int, i40 int, i41 int, i42 int, +i43 int, i44 int, i45 int, i46 int, i47 int, i48 int, i49 int, i50 int, i51 +int, i52 int, i53 int, i54 int, i55 int, i56 int, i57 int, i58 int, i59 int, +i60 int, i61 int, i62 int, i63 int, i64 int, i65 int, i66 int, i67 int, i68 +int, i69 int, i70 int, i71 int, i72 int, i73 int, i74 int, i75 int, i76 int, +i77 int, i78 int, i79 int, i80 int, i81 int, i82 int, i83 int, i84 int, i85 +int, i86 int, i87 int, i88 int, i89 int, i90 int, i91 int, i92 int, i93 int, +i94 int, i95 int, i96 int, i97 int, i98 int, i99 int, i100 int, i101 int, i102 +int, i103 int, i104 int, i105 int, i106 int, i107 int, i108 int, i109 int, i110 +int, i111 int, i112 int, i113 int, i114 int, i115 int, i116 int, i117 int, i118 +int, i119 int, i120 int, i121 int, i122 int, i123 int, i124 int, i125 int, i126 +int, i127 int, i128 int, i129 int, i130 int, i131 int, i132 int, i133 int, i134 +int, i135 int, i136 int, i137 int, i138 int, i139 int, i140 int, i141 int, i142 +int, i143 int, i144 int, i145 int, i146 int, i147 int, i148 int, i149 int, i150 +int, i151 int, i152 int, i153 int, i154 int, i155 int, i156 int, i157 int, i158 +int, i159 int, i160 int, i161 int, i162 int, i163 int, i164 int, i165 int, i166 +int, i167 int, i168 int, i169 int, i170 int, i171 int, i172 int, i173 int, i174 +int, i175 int, i176 int, i177 int, i178 int, i179 int, i180 int, i181 int, i182 +int, i183 int, i184 int, i185 int, i186 int, i187 int, i188 int, i189 int, i190 +int, i191 int, i192 int, i193 int, i194 int, i195 int, i196 int, i197 int, i198 +int, i199 int, i200 int, i201 int, i202 int, i203 int, i204 int, i205 int, i206 +int, i207 int, i208 int, i209 int, i210 int, i211 int, i212 int, i213 int, i214 +int, i215 int, i216 int, i217 int, i218 int, i219 int, i220 int, i221 int, i222 +int, i223 int, i224 int, i225 int, i226 int, i227 int, i228 int, i229 int, i230 +int, i231 int, i232 int, i233 int, i234 int, i235 int, i236 int, i237 int, i238 +int, i239 int, i240 int, i241 int, i242 int, i243 int, i244 int, i245 int, i246 +int, i247 int, i248 int, i249 int, i250 int, i251 int, i252 int, i253 int, i254 +int, i255 int, i256 int, i257 int, i258 int, i259 int, i260 int, i261 int, i262 +int, i263 int, i264 int, i265 int, i266 int, i267 int, i268 int, i269 int, i270 +int, i271 int, i272 int, i273 int, i274 int, i275 int, i276 int, i277 int, i278 +int, i279 int, i280 int, i281 int, i282 int, i283 int, i284 int, i285 int, i286 +int, i287 int, i288 int, i289 int, i290 int, i291 int, i292 int, i293 int, i294 +int, i295 int, i296 int, i297 int, i298 int, i299 int, i300 int, i301 int, i302 +int, i303 int, i304 int, i305 int, i306 int, i307 int, i308 int, i309 int, i310 +int, i311 int, i312 int, i313 int, i314 int, i315 int, i316 int, i317 int, i318 +int, i319 int, i320 int, i321 int, i322 int, i323 int, i324 int, i325 int, i326 +int, i327 int, i328 int, i329 int, i330 int, i331 int, i332 int, i333 int, i334 +int, i335 int, i336 int, i337 int, i338 int, i339 int, i340 int, i341 int, i342 +int, i343 int, i344 int, i345 int, i346 int, i347 int, i348 int, i349 int, i350 +int, i351 int, i352 int, i353 int, i354 int, i355 int, i356 int, i357 int, i358 +int, i359 int, i360 int, i361 int, i362 int, i363 int, i364 int, i365 int, i366 +int, i367 int, i368 int, i369 int, i370 int, i371 int, i372 int, i373 int, i374 +int, i375 int, i376 int, i377 int, i378 int, i379 int, i380 int, i381 int, i382 +int, i383 int, i384 int, i385 int, i386 int, i387 int, i388 int, i389 int, i390 +int, i391 int, i392 int, i393 int, i394 int, i395 int, i396 int, i397 int, i398 +int, i399 int, i400 int, i401 int, i402 int, i403 int, i404 int, i405 int, i406 +int, i407 int, i408 int, i409 int, i410 int, i411 int, i412 int, i413 int, i414 +int, i415 int, i416 int, i417 int, i418 int, i419 int, i420 int, i421 int, i422 +int, i423 int, i424 int, i425 int, i426 int, i427 int, i428 int, i429 int, i430 +int, i431 int, i432 int, i433 int, i434 int, i435 int, i436 int, i437 int, i438 +int, i439 int, i440 int, i441 int, i442 int, i443 int, i444 int, i445 int, i446 +int, i447 int, i448 int, i449 int, i450 int, i451 int, i452 int, i453 int, i454 +int, i455 int, i456 int, i457 int, i458 int, i459 int, i460 int, i461 int, i462 +int, i463 int, i464 int, i465 int, i466 int, i467 int, i468 int, i469 int, i470 +int, i471 int, i472 int, i473 int, i474 int, i475 int, i476 int, i477 int, i478 +int, i479 int, i480 int, i481 int, i482 int, i483 int, i484 int, i485 int, i486 +int, i487 int, i488 int, i489 int, i490 int, i491 int, i492 int, i493 int, i494 +int, i495 int, i496 int, i497 int, i498 int, i499 int, i500 int, i501 int, i502 +int, i503 int, i504 int, i505 int, i506 int, i507 int, i508 int, i509 int, i510 +int, i511 int, i512 int, i513 int, i514 int, i515 int, i516 int, i517 int, i518 +int, i519 int, i520 int, i521 int, i522 int, i523 int, i524 int, i525 int, i526 +int, i527 int, i528 int, i529 int, i530 int, i531 int, i532 int, i533 int, i534 +int, i535 int, i536 int, i537 int, i538 int, i539 int, i540 int, i541 int, i542 +int, i543 int, i544 int, i545 int, i546 int, i547 int, i548 int, i549 int, i550 +int, i551 int, i552 int, i553 int, i554 int, i555 int, i556 int, i557 int, i558 +int, i559 int, i560 int, i561 int, i562 int, i563 int, i564 int, i565 int, i566 +int, i567 int, i568 int, i569 int, i570 int, i571 int, i572 int, i573 int, i574 +int, i575 int, i576 int, i577 int, i578 int, i579 int, i580 int, i581 int, i582 +int, i583 int, i584 int, i585 int, i586 int, i587 int, i588 int, i589 int, i590 +int, i591 int, i592 int, i593 int, i594 int, i595 int, i596 int, i597 int, i598 +int, i599 int, i600 int, i601 int, i602 int, i603 int, i604 int, i605 int, i606 +int, i607 int, i608 int, i609 int, i610 int, i611 int, i612 int, i613 int, i614 +int, i615 int, i616 int, i617 int, i618 int, i619 int, i620 int, i621 int, i622 +int, i623 int, i624 int, i625 int, i626 int, i627 int, i628 int, i629 int, i630 +int, i631 int, i632 int, i633 int, i634 int, i635 int, i636 int, i637 int, i638 +int, i639 int, i640 int, i641 int, i642 int, i643 int, i644 int, i645 int, i646 +int, i647 int, i648 int, i649 int, i650 int, i651 int, i652 int, i653 int, i654 +int, i655 int, i656 int, i657 int, i658 int, i659 int, i660 int, i661 int, i662 +int, i663 int, i664 int, i665 int, i666 int, i667 int, i668 int, i669 int, i670 +int, i671 int, i672 int, i673 int, i674 int, i675 int, i676 int, i677 int, i678 +int, i679 int, i680 int, i681 int, i682 int, i683 int, i684 int, i685 int, i686 +int, i687 int, i688 int, i689 int, i690 int, i691 int, i692 int, i693 int, i694 +int, i695 int, i696 int, i697 int, i698 int, i699 int, i700 int, i701 int, i702 +int, i703 int, i704 int, i705 int, i706 int, i707 int, i708 int, i709 int, i710 +int, i711 int, i712 int, i713 int, i714 int, i715 int, i716 int, i717 int, i718 +int, i719 int, i720 int, i721 int, i722 int, i723 int, i724 int, i725 int, i726 +int, i727 int, i728 int, i729 int, i730 int, i731 int, i732 int, i733 int, i734 +int, i735 int, i736 int, i737 int, i738 int, i739 int, i740 int, i741 int, i742 +int, i743 int, i744 int, i745 int, i746 int, i747 int, i748 int, i749 int, i750 +int, i751 int, i752 int, i753 int, i754 int, i755 int, i756 int, i757 int, i758 +int, i759 int, i760 int, i761 int, i762 int, i763 int, i764 int, i765 int, i766 +int, i767 int, i768 int, i769 int, i770 int, i771 int, i772 int, i773 int, i774 +int, i775 int, i776 int, i777 int, i778 int, i779 int, i780 int, i781 int, i782 +int, i783 int, i784 int, i785 int, i786 int, i787 int, i788 int, i789 int, i790 +int, i791 int, i792 int, i793 int, i794 int, i795 int, i796 int, i797 int, i798 +int, i799 int, i800 int, i801 int, i802 int, i803 int, i804 int, i805 int, i806 +int, i807 int, i808 int, i809 int, i810 int, i811 int, i812 int, i813 int, i814 +int, i815 int, i816 int, i817 int, i818 int, i819 int, i820 int, i821 int, i822 +int, i823 int, i824 int, i825 int, i826 int, i827 int, i828 int, i829 int, i830 +int, i831 int, i832 int, i833 int, i834 int, i835 int, i836 int, i837 int, i838 +int, i839 int, i840 int, i841 int, i842 int, i843 int, i844 int, i845 int, i846 +int, i847 int, i848 int, i849 int, i850 int, i851 int, i852 int, i853 int, i854 +int, i855 int, i856 int, i857 int, i858 int, i859 int, i860 int, i861 int, i862 +int, i863 int, i864 int, i865 int, i866 int, i867 int, i868 int, i869 int, i870 +int, i871 int, i872 int, i873 int, i874 int, i875 int, i876 int, i877 int, i878 +int, i879 int, i880 int, i881 int, i882 int, i883 int, i884 int, i885 int, i886 +int, i887 int, i888 int, i889 int, i890 int, i891 int, i892 int, i893 int, i894 +int, i895 int, i896 int, i897 int, i898 int, i899 int, i900 int, i901 int, i902 +int, i903 int, i904 int, i905 int, i906 int, i907 int, i908 int, i909 int, i910 +int, i911 int, i912 int, i913 int, i914 int, i915 int, i916 int, i917 int, i918 +int, i919 int, i920 int, i921 int, i922 int, i923 int, i924 int, i925 int, i926 +int, i927 int, i928 int, i929 int, i930 int, i931 int, i932 int, i933 int, i934 +int, i935 int, i936 int, i937 int, i938 int, i939 int, i940 int, i941 int, i942 +int, i943 int, i944 int, i945 int, i946 int, i947 int, i948 int, i949 int, i950 +int, i951 int, i952 int, i953 int, i954 int, i955 int, i956 int, i957 int, i958 +int, i959 int, i960 int, i961 int, i962 int, i963 int, i964 int, i965 int, i966 +int, i967 int, i968 int, i969 int, i970 int, i971 int, i972 int, i973 int, i974 +int, i975 int, i976 int, i977 int, i978 int, i979 int, i980 int, i981 int, i982 +int, i983 int, i984 int, i985 int, i986 int, i987 int, i988 int, i989 int, i990 +int, i991 int, i992 int, i993 int, i994 int, i995 int, i996 int, i997 int, i998 +int, i999 int, i1000 int, b varchar(256)) +row_format=dynamic +ENGINE="FEDERATED" +DEFAULT CHARSET=latin1 +CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 +values (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, "PatrickG"); +UPDATE federated.t1 SET b=repeat('a',256); +UPDATE federated.t1 SET i1=0, i2=0, i3=0, i4=0, i5=0, i6=0, i7=0, i8=0, i9=0, i10=0; +SELECT * FROM federated.t1 WHERE i9=0 and i10=0; +UPDATE federated.t1 SET i50=20; +SELECT * FROM federated.t1; +DELETE FROM federated.t1 WHERE i51=20; +SELECT * FROM federated.t1; +DELETE FROM federated.t1 WHERE i50=20; +SELECT * FROM federated.t1; + +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 (id int NOT NULL auto_increment, code char(20) NOT NULL, fileguts blob NOT NULL, creation_date datetime, entered_time datetime default '2004-04-04 04:04:04', PRIMARY KEY(id), index(code), index(fileguts(10))) DEFAULT CHARSET=latin1; + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + id int NOT NULL auto_increment, + code char(20) NOT NULL, + fileguts blob NOT NULL, + creation_date datetime, + entered_time datetime default '2004-04-04 04:04:04', + PRIMARY KEY(id), + index(code), + index(fileguts(10))) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; +INSERT INTO federated.t1 (code, fileguts, creation_date) VALUES ('ASDFWERQWETWETAWETA', '*()w*09*$()*#)(*09*^90*d)(*s()d8g)(s*ned)(*)(s*d)(*hn(d*)(*sbn)D((#$*(#*%%&#&^$#&#&#&#&^&#*&*#$*&^*(&#(&Q*&&(*!&!(*&*(#&*(%&#<S-F8>*<S-F8><S-F8><S-F8>#<S-F8>#<S-F8>#<S-F8>[[', '2003-03-03 03:03:03'); +INSERT INTO federated.t1 (code, fileguts, creation_date) VALUES ('DEUEUEUEUEUEUEUEUEU', '*()w*09*$()*#)(*09*^90*d)(*s()d8g)(s*ned)(*)(s*d)(*hn(d*)(*sbn)D((#$*(#*%%&#&^$#&#&#&#&^&#*&*#$*&^*(&#(&Q*&&(*!&!(*&*(#&*(%&#<S-F8>*<S-F8><S-F8><S-F8>#<S-F8>#<S-F8>#<S-F8>[[', '2004-04-04 04:04:04'); +INSERT INTO federated.t1 (code, fileguts, creation_date) VALUES ('DEUEUEUEUEUEUEUEUEU', 'jimbob', '2004-04-04 04:04:04'); +SELECT * FROM federated.t1; +# test blob indexes +SELECT * FROM federated.t1 WHERE fileguts = 'jimbob'; + +# test blob with binary +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 (`a` BLOB); + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `a` BLOB) +ENGINE="FEDERATED" +CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 VALUES (0x00); +INSERT INTO federated.t1 VALUES (0x0001); +INSERT INTO federated.t1 VALUES (0x0100); +SELECT HEX(a) FROM federated.t1; + +# # simple tests for cyrillic, given to me by +# DROP TABLE IF EXISTS federated.t1; +# --replace_result $SLAVE_MYPORT SLAVE_PORT +# eval CREATE TABLE federated.t1 +# (a char(20)) charset=cp1251 +# ENGINE="FEDERATED" CONNECTION="mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1"; +# # +# connection slave; +# DROP TABLE IF EXISTS federated.t1; +# CREATE TABLE federated.t1 (a char(20)) charset=cp1251; +# # +# connection master; +# INSERT INTO federated.t1 values (_cp1251'À-ÁÂÃ-1'); +# INSERT INTO federated.t1 values (_cp1251'Á-ÂÃÄ-2'); +# SELECT * FROM federated.t1; +# SET names cp1251; +# INSERT INTO federated.t1 values ('Â-ÃÄÅ-3'); +# INSERT INTO federated.t1 values ('Ã-ŨÆ-4'); +# SELECT * FROM federated.t1; +# SELECT hex(a) from federated.t1; +# SELECT hex(a) from federated.t1 ORDER BY a desc; +# UPDATE federated.t1 SET a='À-ÁÂÃ-1íîâûé' WHERE a='À-ÁÂÃ-1'; +# SELECT * FROM federated.t1; +# DELETE FROM federated.t1 WHERE a='Ã-ŨÆ-4'; +# SELECT * FROM federated.t1; +# DELETE FROM federated.t1 WHERE a>'Â-'; +# SELECT * FROM federated.t1; +# SET names default; +# DROP TABLE IF EXISTS federated.t1; + +# +# DROP TABLE IF EXISTS federated.t1; +# + +# test joins with non-federated table +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + `country_id` int(20) NOT NULL DEFAULT 0, + `name` varchar(32), + `other` varchar(20), + PRIMARY KEY (`id`), + key (country_id)); + +connection master; +DROP TABLE IF EXISTS federated.countries; +CREATE TABLE federated.countries ( + `id` int(20) NOT NULL auto_increment, + `country` varchar(32), + PRIMARY KEY (id)); +INSERT INTO federated.countries (country) VALUES ('India'); +INSERT INTO federated.countries (country) VALUES ('Germany'); +INSERT INTO federated.countries (country) VALUES ('Italy'); +INSERT INTO federated.countries (country) VALUES ('Finland'); +INSERT INTO federated.countries (country) VALUES ('Ukraine'); + +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + `country_id` int(20) NOT NULL DEFAULT 0, + `name` varchar(32), + `other` varchar(20), + PRIMARY KEY (`id`), + KEY (country_id) ) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 (name, country_id, other) VALUES ('Kumar', 1, 11111); +INSERT INTO federated.t1 (name, country_id, other) VALUES ('Lenz', 2, 22222); +INSERT INTO federated.t1 (name, country_id, other) VALUES ('Marizio', 3, 33333); +INSERT INTO federated.t1 (name, country_id, other) VALUES ('Monty', 4, 33333); +INSERT INTO federated.t1 (name, country_id, other) VALUES ('Sanja', 5, 33333); + +#inner join +SELECT federated.t1.name AS name, federated.t1.country_id AS country_id, +federated.t1.other AS other, federated.countries.country AS country +FROM federated.t1, federated.countries WHERE +federated.t1.country_id = federated.countries.id; + +SELECT federated.t1.name AS name, federated.t1.country_id AS country_id, +federated.t1.other AS other, federated.countries.country AS country +FROM federated.t1 INNER JOIN federated.countries ON +federated.t1.country_id = federated.countries.id; + +SELECT federated.t1.name AS name, federated.t1.country_id AS country_id, +federated.t1.other AS other, federated.countries.country AS country +FROM federated.t1 INNER JOIN federated.countries ON +federated.t1.country_id = federated.countries.id +WHERE federated.t1.name = 'Monty'; + +#left join +SELECT federated.t1.*, federated.countries.country +FROM federated.t1 LEFT JOIN federated.countries +ON federated.t1.country_id = federated.countries.id +ORDER BY federated.countries.id; + +SELECT federated.t1.*, federated.countries.country +FROM federated.t1 LEFT JOIN federated.countries +ON federated.t1.country_id = federated.countries.id +ORDER BY federated.countries.country; + +#right join +SELECT federated.t1.*, federated.countries.country +FROM federated.t1 RIGHT JOIN federated.countries +ON federated.t1.country_id = federated.countries.id +ORDER BY federated.t1.country_id; + +DROP TABLE federated.countries; + +#BEGIN optimize and repair tests +OPTIMIZE TABLE federated.t1; +REPAIR TABLE federated.t1; +REPAIR TABLE federated.t1 QUICK; +REPAIR TABLE federated.t1 EXTENDED; +REPAIR TABLE federated.t1 USE_FRM; +#END optimize and repair tests + + +# BEGIN ALTER TEST +connection slave; +--disable_warnings +DROP TABLE IF EXISTS federated.normal_table; +--enable_warnings + +CREATE TABLE federated.normal_table ( + `id` int(4) NOT NULL, + `name` varchar(10) default NULL + ) DEFAULT CHARSET=latin1; + +connection master; +--disable_warnings +DROP TABLE IF EXISTS federated.alter_me; +--enable_warnings + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.alter_me ( + `id` int(4) NOT NULL, + `name` varchar(10) default NULL, + PRIMARY KEY (`id`) + ) ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/normal_table'; + +INSERT INTO federated.alter_me (id, name) VALUES (1, 'Monty'); +INSERT INTO federated.alter_me (id, name) VALUES (2, 'David'); + +SELECT * FROM federated.alter_me; + +--error 1031 +ALTER TABLE federated.alter_me MODIFY COLUMN id int(16) NOT NULL; + +SELECT * FROM federated.alter_me; + +DROP TABLE federated.alter_me; +connection slave; +DROP TABLE federated.normal_table; +# END ALTER TEST + +# +# Test BUG #14532 - bit columns broken in federated +# storage engine +# +--disable_warnings +DROP TABLE IF EXISTS federated.t1; +--enable_warnings +CREATE TABLE federated.t1 ( + `bitty` bit(3) +) DEFAULT CHARSET=latin1; + +connection master; + +--disable_warnings +DROP TABLE IF EXISTS federated.t1; +--enable_warnings + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `bitty` bit(3) +) ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 VALUES (b'001'); +INSERT INTO federated.t1 VALUES (b'010'); +INSERT INTO federated.t1 VALUES (b'011'); +INSERT INTO federated.t1 VALUES (b'100'); +INSERT INTO federated.t1 VALUES (b'101'); +INSERT INTO federated.t1 VALUES (b'110'); +INSERT INTO federated.t1 VALUES (b'111'); +select * FROM federated.t1; +drop table federated.t1; + +connection slave; +drop table federated.t1; + +# +# BUG# 14768 test auto_increment last_insert_id() +# +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + PRIMARY KEY (`id`)); + +connection master; +DROP TABLE IF EXISTS federated.t1; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int(20) NOT NULL auto_increment, + PRIMARY KEY (`id`) + ) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +INSERT INTO federated.t1 VALUES (); +SELECT LAST_INSERT_ID(); +INSERT INTO federated.t1 VALUES (); +SELECT LAST_INSERT_ID(); +INSERT INTO federated.t1 VALUES (); +SELECT LAST_INSERT_ID(); +INSERT INTO federated.t1 VALUES (); +SELECT LAST_INSERT_ID(); +INSERT INTO federated.t1 VALUES (); +SELECT LAST_INSERT_ID(); +SELECT * FROM federated.t1; +DROP TABLE federated.t1; + +connection slave; +DROP TABLE federated.t1; + +# +# Bug#17377 Federated Engine returns wrong Data, always the rows +# with the highest ID +# + +connection slave; + +--disable_warnings +DROP TABLE IF EXISTS federated.bug_17377_table; +--enable_warnings + +CREATE TABLE federated.bug_17377_table ( +`fld_cid` bigint(20) NOT NULL auto_increment, +`fld_name` varchar(255) NOT NULL default '', +`fld_parentid` bigint(20) NOT NULL default '0', +`fld_delt` int(1) NOT NULL default '0', +PRIMARY KEY (`fld_cid`), +KEY `fld_parentid` (`fld_parentid`), +KEY `fld_delt` (`fld_delt`), +KEY `fld_cid` (`fld_cid`) +) ENGINE=MyISAM; + +# Insert some test-data +insert into federated.bug_17377_table( fld_name ) +values +("Mats"), ("Sivert"), ("Sigvard"), ("Torgny"), ("Torkel"); + +connection master; +--disable_warnings +DROP TABLE IF EXISTS federated.t1; +--enable_warnings + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( +`fld_cid` bigint(20) NOT NULL auto_increment, +`fld_name` varchar(255) NOT NULL default '', +`fld_parentid` bigint(20) NOT NULL default '0', +`fld_delt` int(1) NOT NULL default '0', +PRIMARY KEY (`fld_cid`), +KEY `fld_parentid` (`fld_parentid`), +KEY `fld_delt` (`fld_delt`), +KEY `fld_cid` (`fld_cid`) +) ENGINE=FEDERATED +CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/bug_17377_table'; + +select * from federated.t1 where fld_parentid=0 and fld_delt=0 +order by fld_name; + +select * from federated.t1 where fld_parentid=0 and fld_delt=0; + +DROP TABLE federated.t1; +connection slave; +DROP TABLE federated.bug_17377_table; + +# +# BUG 19773 Crash when using multi-table updates, deletes +# with federated tables +# +connection slave; +create table federated.t1 (i1 int, i2 int, i3 int); +create table federated.t2 (id int, c1 varchar(20), c2 varchar(20)); + +connection master; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval create table federated.t1 (i1 int, i2 int, i3 int) ENGINE=FEDERATED CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval create table federated.t2 (id int, c1 varchar(20), c2 varchar(20)) ENGINE=FEDERATED CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t2'; +insert into federated.t1 values (1,5,10),(3,7,12),(4,5,2),(9,10,15),(2,2,2); +insert into federated.t2 values (9,"abc","def"),(5,"opq","lmn"),(2,"test t","t test"); +select * from federated.t1 order by i1; +select * from federated.t2; +update federated.t1,federated.t2 set t1.i2=15, t2.c2="ppc" where t1.i1=t2.id; +select * from federated.t1 order by i1; +select * from federated.t2 order by id; +delete federated.t1.*,federated.t2.* from federated.t1,federated.t2 where t1.i2=t2.id; +select * from federated.t1 order by i1; +select * from federated.t2 order by id; +drop table federated.t1, federated.t2; +connection slave; +drop table federated.t1, federated.t2; + +# Test multi updates and deletes with keys +connection slave; +create table federated.t1 (i1 int, i2 int, i3 int, primary key (i1)); +create table federated.t2 (id int, c1 varchar(20), c2 varchar(20), primary key (id)); + +connection master; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval create table federated.t1 (i1 int auto_increment not null, i2 int, i3 int, primary key (i1)) ENGINE=FEDERATED CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval create table federated.t2 (id int auto_increment not null, c1 varchar(20), c2 varchar(20), primary key(id)) ENGINE=FEDERATED CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t2'; +insert into federated.t1 values (1,5,10),(3,7,12),(4,5,2),(9,10,15),(2,2,2); +insert into federated.t2 values (9,"abc","def"),(5,"opq","lmn"),(2,"test t","t test"); +select * from federated.t1 order by i1; +select * from federated.t2 order by id; +update federated.t1,federated.t2 set t1.i2=15, t2.c2="ppc" where t1.i1=t2.id; +select * from federated.t1 order by i1; +select * from federated.t2 order by id; +delete federated.t1.*,federated.t2.* from federated.t1,federated.t2 where t1.i2=t2.id; +select * from federated.t1 order by i1; +select * from federated.t2 order by id; +drop table federated.t1, federated.t2; + +connection slave; +drop table federated.t1, federated.t2; + +# +# BUG #18764: Delete conditions causing inconsistencies in Federated tables +# +connection slave; +--disable_warnings +DROP TABLE IF EXISTS federated.test; +--enable_warnings +CREATE TABLE federated.test ( + `id` int(11) NOT NULL, + `val1` varchar(255) NOT NULL, + `val2` varchar(255) NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +connection master; +--disable_warnings +DROP TABLE IF EXISTS federated.test_local; +DROP TABLE IF EXISTS federated.test_remote; +--enable_warnings +CREATE TABLE federated.test_local ( + `id` int(11) NOT NULL, + `val1` varchar(255) NOT NULL, + `val2` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +INSERT INTO federated.test_local VALUES (1, 'foo', 'bar'), +(2, 'bar', 'foo'); + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.test_remote ( + `id` int(11) NOT NULL, + `val1` varchar(255) NOT NULL, + `val2` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=FEDERATED DEFAULT CHARSET=latin1 +CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/test'; + +insert into federated.test_remote select * from federated.test_local; + +select * from federated.test_remote; + +delete from federated.test_remote where id in (1,2); + +insert into federated.test_remote select * from federated.test_local; + +select * from federated.test_remote; +--disable_warnings +DROP TABLE federated.test_local; +DROP TABLE federated.test_remote; +--enable_warnings +connection slave; +--disable_warnings +DROP TABLE federated.test; +--enable_warnings + +# +# Additional test for bug#18437 "Wrong values inserted with a before +# update trigger on NDB table". SQL-layer didn't properly inform +# handler about fields which were read and set in triggers. In some +# cases this resulted in incorrect (garbage) values of OLD variables +# and lost changes to NEW variables. +# Since for federated engine only operation which is affected by wrong +# fields mark-up is handler::write_row() this file constains coverage +# for ON INSERT triggers only. Tests for other types of triggers reside +# in ndb_trigger.test. +# +--disable_warnings +drop table if exists federated.t1; +--enable_warnings +create table federated.t1 (a int, b int, c int); +connection master; +--disable_warnings +drop table if exists federated.t1; +drop table if exists federated.t2; +--enable_warnings +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval create table federated.t1 (a int, b int, c int) engine=federated connection='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; +create trigger federated.t1_bi before insert on federated.t1 for each row set new.c= new.a * new.b; +create table federated.t2 (a int, b int); +insert into federated.t2 values (13, 17), (19, 23); +# Each of three statements should correctly set values for all three fields +# insert +insert into federated.t1 (a, b) values (1, 2), (3, 5), (7, 11); +select * from federated.t1; +delete from federated.t1; +# insert ... select +insert into federated.t1 (a, b) select * from federated.t2; +select * from federated.t1; +delete from federated.t1; +# load +load data infile '../std_data_ln/loaddata5.dat' into table federated.t1 fields terminated by '' enclosed by '' ignore 1 lines (a, b); +select * from federated.t1; +drop tables federated.t1, federated.t2; + +connection slave; +drop table federated.t1; +# +# Bug #16494: Updates that set a column to NULL fail sometimes +# +connection slave; +create table t1 (id int not null auto_increment primary key, val int); +connection master; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval create table t1 + (id int not null auto_increment primary key, val int) engine=federated + connection='mysql://root@127.0.0.1:$SLAVE_MYPORT/test/t1'; +insert into t1 values (1,0),(2,0); +update t1 set val = NULL where id = 1; +select * from t1; +connection slave; +select * from t1; +drop table t1; +connection master; +drop table t1; + +# +# Bug #17608: String literals lost during INSERT query on FEDERATED table +# +connection slave; +create table t1 (a longblob not null); +connection master; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval create table t1 + (a longblob not null) engine=federated + connection='mysql://root@127.0.0.1:$SLAVE_MYPORT/test/t1'; +insert into t1 values (repeat('a',5000)); +select length(a) from t1; +connection slave; +select length(a) from t1; +drop table t1; +connection master; +drop table t1; + +# +# BUG #15133: unique index with nullable value not accepted in federated table +# + +connection slave; +--disable_warnings +DROP TABLE IF EXISTS federated.test; +CREATE TABLE federated.test ( + `i` int(11) NOT NULL, + `j` int(11) NOT NULL, + `c` varchar(30) default NULL, + PRIMARY KEY (`i`,`j`), + UNIQUE KEY `i` (`i`,`c`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +--enable_warnings + +connection master; +--disable_warnings +DROP TABLE IF EXISTS federated.test1; +DROP TABLE IF EXISTS federated.test2; +--enable_warnings + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval create table federated.test1 ( + i int not null, + j int not null, + c varchar(30), + primary key (i,j), + unique key (i, c)) +engine = federated +connection='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/test'; + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval create table federated.test2 ( + i int default null, + j int not null, + c varchar(30), + key (i)) +engine = federated +connection='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/test'; +drop table federated.test1, federated.test2; + +connection slave; +drop table federated.test; + +source include/federated_cleanup.inc; diff --git a/mysql-test/t/federated_archive.test b/mysql-test/t/federated_archive.test new file mode 100644 index 00000000000..6d80664fef7 --- /dev/null +++ b/mysql-test/t/federated_archive.test @@ -0,0 +1,58 @@ +source include/have_archive.inc; +source include/federated.inc; + + +connection slave; +--disable_warnings +DROP TABLE IF EXISTS federated.archive_table; +--enable_warnings + +CREATE TABLE federated.archive_table ( + `id` int(4) NOT NULL, + `name` varchar(54) default NULL + ) ENGINE=ARCHIVE DEFAULT CHARSET=latin1; + + +connection master; +--disable_warnings +DROP TABLE IF EXISTS federated.t1; +--enable_warnings + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `id` int(4) NOT NULL, + `name` varchar(54) default NULL, + PRIMARY KEY (`id`) + ) + ENGINE="FEDERATED" DEFAULT CHARSET=latin1 + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/archive_table'; + +INSERT INTO federated.t1 (id, name) VALUES (1, 'foo'); +INSERT INTO federated.t1 (id, name) VALUES (2, 'bar'); + +SELECT * FROM federated.t1; + +--error 1296 +DELETE FROM federated.t1 WHERE id = 1; + +SELECT * FROM federated.t1; + + +--error 1296 +UPDATE federated.t1 SET name='baz' WHERE id = 1; + +SELECT * FROM federated.t1; + + +# --error 1296 +# TRUNCATE federated.t1; +# +# SELECT * from federated.t1; + +DROP TABLE federated.t1; +connection slave; +DROP TABLE federated.archive_table; + + +source include/federated_cleanup.inc; + diff --git a/mysql-test/t/federated_bug_13118.test b/mysql-test/t/federated_bug_13118.test new file mode 100644 index 00000000000..deec79becd2 --- /dev/null +++ b/mysql-test/t/federated_bug_13118.test @@ -0,0 +1,42 @@ +source include/federated.inc; + + +connection slave; +--disable_warnings +DROP TABLE IF EXISTS federated.bug_13118_table; +--enable_warnings + +CREATE TABLE federated.bug_13118_table ( + `foo` integer, + `bar` integer + ); + + +connection master; +--disable_warnings +DROP TABLE IF EXISTS federated.t1; +--enable_warnings + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE federated.t1 ( + `foo` integer, + `bar` integer + ) ENGINE="FEDERATED" + CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/bug_13118_table'; + +SELECT * from federated.t1; + +INSERT INTO federated.t1 VALUES (1,1); +SELECT * FROM federated.t1; + +INSERT INTO federated.t1 VALUES (1,1); +SELECT * FROM federated.t1; + + +DROP TABLE federated.t1; +connection slave; +DROP TABLE federated.bug_13118_table; + + +source include/federated_cleanup.inc; + diff --git a/mysql-test/t/flush.test b/mysql-test/t/flush.test index aedf8e85b65..95ba633fefd 100644 --- a/mysql-test/t/flush.test +++ b/mysql-test/t/flush.test @@ -37,7 +37,7 @@ connection con1; select * from t1; connection con2; flush tables with read lock; ---error 1099 +--error 1223 drop table t2; connection con1; send drop table t2; @@ -102,3 +102,43 @@ unlock tables; drop table t1, t2, t3; # End of 4.1 tests + +# +# Test of deadlock problem when doing FLUSH TABLE with read lock +# (Bug was in NTPL threads in Linux when using different mutex while +# waiting for a condtion variable) + +create table t1 (c1 int); +create table t2 (c1 int); + +connect (con1,localhost,root,,); +connect (con3,localhost,root,,); + +connection con1; +lock table t1 write; + +connection con2; +send flush tables with read lock; +--sleep 1 + +connection con3; +send insert into t2 values(1); +--sleep 1 + +connection con1; +unlock tables; +disconnect con1; + +connection con2; +reap; +disconnect con2; + +connection con3; +# It hangs here (insert into t2 does not end). +reap; +disconnect con3; + +connection default; +drop table t1, t2; + +# End of 5.0 tests diff --git a/mysql-test/t/flush_block_commit.test b/mysql-test/t/flush_block_commit.test index 1e7ecd2548c..ebb48242a4d 100644 --- a/mysql-test/t/flush_block_commit.test +++ b/mysql-test/t/flush_block_commit.test @@ -78,3 +78,24 @@ show create database test; drop table t1; # End of 4.1 tests + +# FLUSH TABLES WITH READ LOCK should block writes to binlog too +connection con1; +create table t1 (a int) engine=innodb; +reset master; +set autocommit=0; +insert t1 values (1); +connection con2; +flush tables with read lock; +show master status; +connection con1; +send commit; +connection con2; +sleep 1; +show master status; +unlock tables; +connection con1; +reap; +drop table t1; +set autocommit=1; + diff --git a/mysql-test/t/flush_read_lock_kill-master.opt b/mysql-test/t/flush_read_lock_kill-master.opt new file mode 100644 index 00000000000..2b2b5eb5ebf --- /dev/null +++ b/mysql-test/t/flush_read_lock_kill-master.opt @@ -0,0 +1 @@ +--loose-debug=d,make_global_read_lock_block_commit_loop diff --git a/mysql-test/t/flush_read_lock_kill.test b/mysql-test/t/flush_read_lock_kill.test new file mode 100644 index 00000000000..19a47b2893a --- /dev/null +++ b/mysql-test/t/flush_read_lock_kill.test @@ -0,0 +1,49 @@ +# Let's see if FLUSH TABLES WITH READ LOCK can be killed when waiting +# for running commits to finish (in the past it could not) +# This will not be a meaningful test on non-debug servers so will be +# skipped. +# If running mysql-test-run --debug, the --debug added by +# mysql-test-run to the mysqld command line will override the one of +# -master.opt. But this test is designed to still pass then (though it +# won't test anything interesting). + +# This also won't work with the embedded server test +-- source include/not_embedded.inc + +-- source include/have_debug.inc + +connect (con1,localhost,root,,); +connect (con2,localhost,root,,); +connection con1; + +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1 (kill_id int); +insert into t1 values(connection_id()); + +# Thanks to the parameter we passed to --debug, this FLUSH will +# block on a debug build running with our --debug=make_global... It +# will block until killed. In other cases (non-debug build or other +# --debug) it will succeed immediately + +connection con1; +send flush tables with read lock; + +# kill con1 +connection con2; +select ((@id := kill_id) - kill_id) from t1; + +--sleep 2 # leave time for FLUSH to block +kill connection @id; + +connection con1; +# On debug builds it will be error 1053 (killed); on non-debug, or +# debug build running without our --debug=make_global..., will be +# error 0 (no error). The only important thing to test is that on +# debug builds with our --debug=make_global... we don't hang forever. +--error 0,1053,2013 +reap; + +connection con2; +drop table t1; diff --git a/mysql-test/t/flush_table.test b/mysql-test/t/flush_table.test index 0330582bc34..e46b67ad3d0 100644 --- a/mysql-test/t/flush_table.test +++ b/mysql-test/t/flush_table.test @@ -73,4 +73,11 @@ handler t1 read next limit 1; handler t1 close; drop table t1; +# +# Bug #11934 Two sequential FLUSH TABLES WITH READ LOCK hangs client +# +FLUSH TABLES WITH READ LOCK ; +FLUSH TABLES WITH READ LOCK ; +UNLOCK TABLES; + # End of 4.1 tests diff --git a/mysql-test/t/fulltext.test b/mysql-test/t/fulltext.test index d5ce6241490..0f7835e9e7e 100644 --- a/mysql-test/t/fulltext.test +++ b/mysql-test/t/fulltext.test @@ -59,6 +59,7 @@ select * from t1 where MATCH a,b AGAINST ("+call* +coll*" IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('"support now"' IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('"Now sUPPort"' IN BOOLEAN MODE); +select * from t1 where MATCH a,b AGAINST ('"now support"' IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('"text search" "now support"' IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('"text search" -"now support"' IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('"text search" +"now support"' IN BOOLEAN MODE); @@ -68,7 +69,6 @@ select * from t1 where MATCH a,b AGAINST ('"xt indexes"' IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('+(support collections) +foobar*' IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('+(+(support collections)) +foobar*' IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('+collections -supp* -foobar*' IN BOOLEAN MODE); -select * from t1 where MATCH a,b AGAINST ('"xt indexes"' IN BOOLEAN MODE); # bug#2708, bug#3870 crash @@ -128,14 +128,14 @@ WHERE ticket2.id = ttxt.ticket AND t1.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar'); # In the following query MySQL didn't use the fulltext index -select t1.id FROM t2 as ttxt,t1 INNER JOIN t1 as ticket2 ON -ticket2.id = ttxt.ticket -WHERE t1.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar'); +select ticket2.id FROM t2 as ttxt,t2 INNER JOIN t1 as ticket2 ON +ticket2.id = t2.ticket +WHERE ticket2.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar'); INSERT INTO t1 VALUES (3,3); -select t1.id FROM t2 as ttxt,t1 -INNER JOIN t1 as ticket2 ON ticket2.id = ttxt.ticket -WHERE t1.id = ticket2.ticket and +select ticket2.id FROM t2 as ttxt,t2 +INNER JOIN t1 as ticket2 ON ticket2.id = t2.ticket +WHERE ticket2.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar'); # Check that we get 'fulltext' index in SHOW CREATE @@ -358,12 +358,20 @@ SELECT a FROM t1 WHERE MATCH a AGAINST('testword\'\'' IN BOOLEAN MODE); DROP TABLE t1; # +# BUG#13835: max key length is 1000 bytes when trying to create +# a fulltext index +# +CREATE TABLE t1 (a VARCHAR(10000), FULLTEXT(a)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +# # BUG#14496: Crash or strange results with prepared statement, # MATCH and FULLTEXT # CREATE TABLE t1 (a TEXT, FULLTEXT KEY(a)); INSERT INTO t1 VALUES('test'),('test1'),('test'); -PREPARE stmt from "SELECT a, MATCH(a) AGAINST('test1 test') FROM t1 WHERE MATCH(a) AGAINST('test1 test')"; +PREPARE stmt from "SELECT a, FORMAT(MATCH(a) AGAINST('test1 test'),6) FROM t1 WHERE MATCH(a) AGAINST('test1 test')"; EXECUTE stmt; EXECUTE stmt; DEALLOCATE PREPARE stmt; diff --git a/mysql-test/t/fulltext_left_join.test b/mysql-test/t/fulltext_left_join.test index 3bb1f0b7309..7c22f49ed8c 100644 --- a/mysql-test/t/fulltext_left_join.test +++ b/mysql-test/t/fulltext_left_join.test @@ -32,7 +32,7 @@ select match(t1.texte,t1.sujet,t1.motsclefs) against('droit' IN BOOLEAN MODE) drop table t1, t2; # -# Bug #484, reported by Stephen Brandon <stephen@brandonitconsulting.co.uk> +# BUG#484, reported by Stephen Brandon <stephen@brandonitconsulting.co.uk> # create table t1 (venue_id int(11) default null, venue_text varchar(255) default null, dt datetime default null) engine=myisam; @@ -45,4 +45,17 @@ select * from t1 left join t2 on (venue_id = entity_id and match(name) against(' select * from t1 left join t2 on (venue_id = entity_id and match(name) against('aberdeen')) where dt = '2003-05-23 19:30:00'; drop table t1,t2; +# +# BUG#14708 +# Inconsistent treatment of NULLs in LEFT JOINed FULLTEXT matching without index +# + +create table t1 (id int not null primary key, d char(200) not null, e char(200)); +insert into t1 values (1, 'aword', null), (2, 'aword', 'bword'), (3, 'bword', null), (4, 'bword', 'aword'), (5, 'aword and bword', null); +select * from t1 where match(d, e) against ('+aword +bword' in boolean mode); +create table t2 (m_id int not null, f char(200), key (m_id)); +insert into t2 values (1, 'bword'), (3, 'aword'), (5, ''); +select * from t1 left join t2 on m_id = id where match(d, e, f) against ('+aword +bword' in boolean mode); +drop table t1,t2; + # End of 4.1 tests diff --git a/mysql-test/t/fulltext_order_by.test b/mysql-test/t/fulltext_order_by.test index da05fd494c4..074aefbf943 100644 --- a/mysql-test/t/fulltext_order_by.test +++ b/mysql-test/t/fulltext_order_by.test @@ -1,5 +1,5 @@ --disable_warnings -DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t1,t2,t3; --enable_warnings CREATE TABLE t1 ( @@ -80,7 +80,7 @@ CREATE TABLE t3 ( FULLTEXT KEY betreff (betreff) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=996 ; ---error 1109 +--error 1054 select a.text, b.id, b.betreff from t2 a inner join t3 b on a.id = b.forum inner join @@ -100,7 +100,7 @@ group by order by match(b.betreff) against ('+abc' in boolean mode) desc; ---error 1109 +--error 1054 select a.text, b.id, b.betreff from t2 a inner join t3 b on a.id = b.forum inner join diff --git a/mysql-test/t/fulltext_var.test b/mysql-test/t/fulltext_var.test index 6b0b8aa463b..a048dab7f40 100644 --- a/mysql-test/t/fulltext_var.test +++ b/mysql-test/t/fulltext_var.test @@ -5,6 +5,9 @@ drop table if exists t1; --enable_warnings +# Save ft_boolean_syntax variable +let $saved_ft_boolean_syntax=`select @@global.ft_boolean_syntax`; + show variables like "ft\_%"; create table t1 (b text not null); @@ -25,4 +28,9 @@ set global ft_boolean_syntax='@ -><()~*:""@|'; set global ft_boolean_syntax='+ -><()~*:""@!|'; drop table t1; +# Restore ft_boolean_syntax variable +--disable_query_log +eval set global ft_boolean_syntax='$saved_ft_boolean_syntax'; +--enable_query_log + # End of 4.1 tests diff --git a/mysql-test/t/func_compress.test b/mysql-test/t/func_compress.test index 223a5540f38..68f07f258bf 100644 --- a/mysql-test/t/func_compress.test +++ b/mysql-test/t/func_compress.test @@ -2,6 +2,8 @@ # # Test for compress and uncompress functions: # +# Note that this test gives error in the gzip library when running under +# valgrind, but these warnings can be ignored select @test_compress_string:='string for test compress function aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa '; select length(@test_compress_string); @@ -67,3 +69,17 @@ select compress(a) is null from t1; drop table t1; --echo End of 4.1 tests + +# +# Bug #18539: uncompress(d) is null: impossible? +# +create table t1 (a varchar(32) not null); +insert into t1 values ('foo'); +explain select * from t1 where uncompress(a) is null; +select * from t1 where uncompress(a) is null; +explain select *, uncompress(a) from t1; +select *, uncompress(a) from t1; +select *, uncompress(a), uncompress(a) is null from t1; +drop table t1; + +--echo End of 5.0 tests diff --git a/mysql-test/t/func_concat.test b/mysql-test/t/func_concat.test index f546a25f647..5487ad9c56b 100644 --- a/mysql-test/t/func_concat.test +++ b/mysql-test/t/func_concat.test @@ -46,10 +46,12 @@ select 'a' union select concat('a', -'3'); select 'a' union select concat('a', -concat('3',4)); select 'a' union select concat('a', -0); - ---replace_result 'a-0.0' good 'a0.0' good +--replace_result a-0.0 a0.0 select 'a' union select concat('a', -0.0); +--replace_result a-0.0000 a0.0000 +select 'a' union select concat('a', -0.0000); + # # Bug#16716: subselect in concat() may lead to a wrong result # @@ -58,3 +60,11 @@ select concat((select x from (select 'a' as x) as t1 ), as t3; # End of 4.1 tests + +# +# Bug#15962: CONCAT() in UNION may lead to a data trucation. +# +create table t1(f1 varchar(6)) charset=utf8; +insert into t1 values ("123456"); +select concat(f1, 2) a from t1 union select 'x' a from t1; +drop table t1; diff --git a/mysql-test/t/func_date_add.test b/mysql-test/t/func_date_add.test index 5213395c35d..b575eeececa 100644 --- a/mysql-test/t/func_date_add.test +++ b/mysql-test/t/func_date_add.test @@ -11,7 +11,7 @@ CREATE TABLE t1 ( group_id int(10) unsigned DEFAULT '0' NOT NULL, hits int(10) unsigned DEFAULT '0' NOT NULL, sessions int(10) unsigned DEFAULT '0' NOT NULL, - ts timestamp(14), + ts timestamp, PRIMARY KEY (visitor_id,group_id) )/*! engine=MyISAM */; INSERT INTO t1 VALUES (465931136,7,2,2,20000318160952); @@ -41,4 +41,40 @@ select visitor_id,max(ts) as mts from t1 group by visitor_id having DATE_ADD(mts,INTERVAL 3 MONTH) < NOW(); drop table t1; -# End of 4.1 tests +# +# Bug #10627: Invalid date turned to NULL from date_sub/date_add in +# traditional mode +# +set sql_mode='traditional'; +create table t1 (d date); +--error S22008 +insert into t1 (d) select date_sub('2000-01-01', INTERVAL 2001 YEAR); +--error S22008 +insert into t1 (d) select date_add('2000-01-01',interval 8000 year); +# No warnings/errors from the next two +insert into t1 values (date_add(NULL, INTERVAL 1 DAY)); +insert into t1 values (date_add('2000-01-04', INTERVAL NULL DAY)); +set sql_mode=''; +# These will all work now, and we'll end up with some NULL entries in the +# table and some warnings. +insert into t1 (d) select date_sub('2000-01-01', INTERVAL 2001 YEAR); +insert into t1 (d) select date_add('2000-01-01',interval 8000 year); +insert into t1 values (date_add(NULL, INTERVAL 1 DAY)); +insert into t1 values (date_add('2000-01-04', INTERVAL NULL DAY)); +select * from t1; +drop table t1; + +--echo End of 4.1 tests + +# +# Bug#21811 +# +# Make sure we end up with an appropriate +# date format (DATE) after addition operation +# +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 DAY; +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 MONTH; +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 YEAR; +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 WEEK; + +--echo End of 5.0 tests diff --git a/mysql-test/t/func_default.test b/mysql-test/t/func_default.test index 836511cc07a..7bebd4b4b72 100644 --- a/mysql-test/t/func_default.test +++ b/mysql-test/t/func_default.test @@ -19,3 +19,13 @@ explain select * from t1 where str <> default(str); drop table t1; # End of 4.1 tests + +# +# Bug #11314 (HAVING DEFAULT() hangs) +# +CREATE TABLE t1 (id int(11), s varchar(20)); +INSERT INTO t1 VALUES (1, 'one'), (2, 'two'), (3, 'three'); +--error 1364 +SELECT s, 32 AS mi FROM t1 GROUP BY s HAVING DEFAULT(mi) IS NULL; +DROP TABLE t1; + diff --git a/mysql-test/t/func_equal.test b/mysql-test/t/func_equal.test index 18d34e3ba16..1c219af0254 100644 --- a/mysql-test/t/func_equal.test +++ b/mysql-test/t/func_equal.test @@ -11,10 +11,12 @@ drop table if exists t1,t2; # First some simple tests # -select 0<=>0,0.0<=>0.0,"A"<=>"A",NULL<=>NULL; +select 0<=>0,0.0<=>0.0,0E0=0E0,"A"<=>"A",NULL<=>NULL; select 1<=>0,0<=>NULL,NULL<=>0; select 1.0<=>0.0,0.0<=>NULL,NULL<=>0.0; select "A"<=>"B","A"<=>NULL,NULL<=>"A"; +select 0<=>0.0, 0.0<=>0E0, 0E0<=>"0", 10.0<=>1E1, 10<=>10.0, 10<=>1E1; +select 1.0<=>0E1,10<=>NULL,NULL<=>0.0, NULL<=>0E0; # # Test with tables @@ -32,4 +34,13 @@ select * from t1 where value <=> value; select * from t1 where id <=> value or value<=>id; drop table t1,t2; +# +# Bug #12612: quoted bigint unsigned value and the use of "in" in where clause +# +create table t1 (a bigint unsigned); +insert into t1 values (4828532208463511553); +select * from t1 where a = '4828532208463511553'; +select * from t1 where a in ('4828532208463511553'); +drop table t1; + # End of 4.1 tests diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test index 40179ae7f38..769f10277d4 100644 --- a/mysql-test/t/func_gconcat.test +++ b/mysql-test/t/func_gconcat.test @@ -68,7 +68,7 @@ set group_concat_max_len = 1024; # Test errors --error 1111 -select group_concat(sum(a)) from t1 group by grp; +select group_concat(sum(c)) from t1 group by grp; --error 1054 select grp,group_concat(c order by 2) from t1 group by grp; @@ -320,6 +320,13 @@ select a, group_concat(distinct b order by b) from t1 group by a with rollup; drop table t1; # +# Bug #6475 +# +create table t1 (a char(3), b char(20), primary key (a, b)); +insert into t1 values ('ABW', 'Dutch'), ('ABW', 'English'); +select group_concat(a) from t1 group by b; +drop table t1; +# # Bug #12095: GROUP_CONCAT for one row table # @@ -401,3 +408,56 @@ select f2,group_concat(f1) from t1 group by f2; drop table t1; # End of 4.1 tests + +# +# Bug#8568 "GROUP_CONCAT returns string, unless in a UNION in which case +# returns BLOB": add a test case, the bug can not be repeated any more. +# + +set names latin1; +create table t1 (a char, b char); +insert into t1 values ('a', 'a'), ('a', 'b'), ('b', 'a'), ('b', 'b'); +create table t2 select group_concat(b) as a from t1 where a = 'a'; +create table t3 (select group_concat(a) as a from t1 where a = 'a') union + (select group_concat(b) as a from t1 where a = 'b'); +select charset(a) from t2; +select charset(a) from t3; +drop table t1, t2, t3; +set names default; + +# +# Bug#18281 group_concat changes charset to binary +# +create table t1 (c1 varchar(10), c2 int); +select charset(group_concat(c1 order by c2)) from t1; +drop table t1; + +# +# Bug #16712: group_concat returns odd string instead of intended result +# +CREATE TABLE t1 (a INT(10), b LONGTEXT, PRIMARY KEY (a)); + +SET GROUP_CONCAT_MAX_LEN = 20000000; + +INSERT INTO t1 VALUES (1,REPEAT(CONCAT('A',CAST(CHAR(0) AS BINARY),'B'), 40000)); +INSERT INTO t1 SELECT a + 1, b FROM t1; + +SELECT a, CHAR_LENGTH(b) FROM t1; +SELECT CHAR_LENGTH( GROUP_CONCAT(b) ) FROM t1; +SET GROUP_CONCAT_MAX_LEN = 1024; +DROP TABLE t1; + +# +# Bug #22015: crash with GROUP_CONCAT over a derived table that +# returns the results of aggregation by GROUP_CONCAT +# + +CREATE TABLE t1 (a int, b int); + +INSERT INTO t1 VALUES (2,1), (1,2), (2,2), (1,3); + +SELECT GROUP_CONCAT(a), x + FROM (SELECT a, GROUP_CONCAT(b) x FROM t1 GROUP BY a) AS s + GROUP BY x; + +DROP TABLE t1; diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index 18cb5d0a430..079d107fad8 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -2,12 +2,13 @@ # simple test of all group functions # ---source include/have_innodb.inc - --disable_warnings drop table if exists t1,t2; --enable_warnings +set @sav_dpi= @@div_precision_increment; +set div_precision_increment= 5; +show variables like 'div_precision_increment'; create table t1 (grp int, a bigint unsigned, c char(10) not null); insert into t1 values (1,1,"a"); insert into t1 values (2,2,"b"); @@ -34,9 +35,7 @@ create table t2 (grp int, a bigint unsigned, c char(10)); insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp; # REPLACE ... SELECT doesn't yet work with PS ---disable_ps_protocol replace into t2 select grp, a, c from t1 limit 2,1; ---enable_ps_protocol select * from t2; drop table t1,t2; @@ -62,6 +61,11 @@ create table t2 (id int not null,rating int null); insert into t1 values(1),(2),(3); insert into t2 values(1, 3),(2, NULL),(2, NULL),(3, 2),(3, NULL); select t1.id, avg(rating) from t1 left join t2 on ( t1.id = t2.id ) group by t1.id; +# Test different types with avg() +select sql_small_result t2.id, avg(rating) from t2 group by t2.id; +select sql_big_result t2.id, avg(rating) from t2 group by t2.id; +select sql_small_result t2.id, avg(rating+0.0e0) from t2 group by t2.id; +select sql_big_result t2.id, avg(rating+0.0e0) from t2 group by t2.id; drop table t1,t2; # @@ -218,6 +222,7 @@ insert into t1 values('GTM',3,'DAL',0.070,date'1977-09-23'); insert into t1 values('SSJ',null,'CHI',null,date'1974-03-19'); insert into t1 values('KKK',3,'ATL',null,null); insert into t1 values('XXX',null,'MIN',null,null); +insert into t1 values('WWW',1,'LED',null,null); # Populate table t2 insert into t2 values('TKF','Seattle','WA','AME'); @@ -226,6 +231,7 @@ insert into t2 values('DEN','Denver','CO','BDL'); insert into t2 values('SDC','San Diego','CA','TWU'); insert into t2 values('NOL','New Orleans','LA','GTM'); insert into t2 values('LAK','Los Angeles','CA','TWU'); +insert into t2 values('AAA','AAA','AA','AME'); # Show the table contents select * from t1; @@ -392,8 +398,12 @@ create table t1 (a char character set latin2); insert into t1 values ('a'),('b'); select charset(max(a)), coercibility(max(a)), charset(min(a)), coercibility(min(a)) from t1; +show create table t1; create table t2 select max(a),min(a) from t1; show create table t2; +drop table t2; +create table t2 select concat(a) from t1; +show create table t2; drop table t2,t1; # @@ -530,75 +540,6 @@ SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6; DROP TABLE t1; # -# Bug #12882 min/max inconsistent on empty table -# - -create table t1m (a int) engine=myisam; -create table t1i (a int) engine=innodb; -create table t2m (a int) engine=myisam; -create table t2i (a int) engine=innodb; -insert into t2m values (5); -insert into t2i values (5); - -# test with MyISAM -select min(a) from t1m; -select min(7) from t1m; -select min(7) from DUAL; -explain select min(7) from t2m join t1m; -select min(7) from t2m join t1m; - -select max(a) from t1m; -select max(7) from t1m; -select max(7) from DUAL; -explain select max(7) from t2m join t1m; -select max(7) from t2m join t1m; - -select 1, min(a) from t1m where a=99; -select 1, min(a) from t1m where 1=99; -select 1, min(1) from t1m where a=99; -select 1, min(1) from t1m where 1=99; - -select 1, max(a) from t1m where a=99; -select 1, max(a) from t1m where 1=99; -select 1, max(1) from t1m where a=99; -select 1, max(1) from t1m where 1=99; - -# test with InnoDB -select min(a) from t1i; -select min(7) from t1i; -select min(7) from DUAL; -explain select min(7) from t2i join t1i; -select min(7) from t2i join t1i; - -select max(a) from t1i; -select max(7) from t1i; -select max(7) from DUAL; -explain select max(7) from t2i join t1i; -select max(7) from t2i join t1i; - -select 1, min(a) from t1i where a=99; -select 1, min(a) from t1i where 1=99; -select 1, min(1) from t1i where a=99; -select 1, min(1) from t1i where 1=99; - -select 1, max(a) from t1i where a=99; -select 1, max(a) from t1i where 1=99; -select 1, max(1) from t1i where a=99; -select 1, max(1) from t1i where 1=99; - -# mixed MyISAM/InnoDB test -explain select count(*), min(7), max(7) from t1m, t1i; -select count(*), min(7), max(7) from t1m, t1i; - -explain select count(*), min(7), max(7) from t1m, t2i; -select count(*), min(7), max(7) from t1m, t2i; - -explain select count(*), min(7), max(7) from t2m, t1i; -select count(*), min(7), max(7) from t2m, t1i; - -drop table t1m, t1i, t2m, t2i; - -# # Bug #18206: min/max optimization cannot be applied to partial index # @@ -617,6 +558,14 @@ SELECT MAX(b) FROM t1; EXPLAIN SELECT MAX(b) FROM t1; DROP TABLE t1; +CREATE TABLE t1 (id int , b varchar(512), INDEX(b(250))) COLLATE latin1_bin; +INSERT INTO t1 VALUES + (1,CONCAT(REPEAT('_', 250), "qq")), (1,CONCAT(REPEAT('_', 250), "zz")), + (1,CONCAT(REPEAT('_', 250), "aa")), (1,CONCAT(REPEAT('_', 250), "ff")); + +SELECT MAX(b) FROM t1; +EXPLAIN SELECT MAX(b) FROM t1; +DROP TABLE t1; # # Bug #16792 query with subselect, join, and group not returning proper values # @@ -632,3 +581,122 @@ SELECT AVG(2), BIT_AND(2), BIT_OR(2), BIT_XOR(2), COUNT(*), COUNT(12), DROP TABLE t1; # End of 4.1 tests + +# +# decimal-related tests +# +create table t2 (ff double); +insert into t2 values (2.2); +select cast(sum(distinct ff) as decimal(5,2)) from t2; +select cast(sum(distinct ff) as signed) from t2; +select cast(variance(ff) as decimal(10,3)) from t2; +select cast(min(ff) as decimal(5,2)) from t2; + +create table t1 (df decimal(5,1)); +insert into t1 values(1.1); +insert into t1 values(2.2); +select cast(sum(distinct df) as signed) from t1; +select cast(min(df) as signed) from t1; +select 1e8 * sum(distinct df) from t1; +select 1e8 * min(df) from t1; + +create table t3 (ifl int); +insert into t3 values(1), (2); +select cast(min(ifl) as decimal(5,2)) from t3; + +drop table t1, t2, t3; + + +# +# BUG#3190, WL#1639: Standard Deviation STDDEV - 2 different calculations +# + +CREATE TABLE t1 (id int(11),value1 float(10,2)); +INSERT INTO t1 VALUES (1,0.00),(1,1.00), (1,2.00), (2,10.00), (2,11.00), (2,12.00), (2,13.00); +select id, stddev_pop(value1), var_pop(value1), stddev_samp(value1), var_samp(value1) from t1 group by id; +DROP TABLE t1; + +# +# BUG#8464 decimal AVG returns incorrect result +# + +CREATE TABLE t1 (col1 decimal(16,12)); +INSERT INTO t1 VALUES (-5.00000000001),(-5.00000000002),(-5.00000000003),(-5.00000000000),(-5.00000000001),(-5.00000000002); +insert into t1 select * from t1; +select col1,count(col1),sum(col1),avg(col1) from t1 group by col1; +DROP TABLE t1; + +# +# BUG#8465 decimal MIN and MAX return incorrect result +# + +create table t1 (col1 decimal(16,12)); +insert into t1 values (-5.00000000001); +insert into t1 values (-5.00000000001); +select col1,sum(col1),max(col1),min(col1) from t1 group by col1; +delete from t1; +insert into t1 values (5.00000000001); +insert into t1 values (5.00000000001); +select col1,sum(col1),max(col1),min(col1) from t1 group by col1; +DROP TABLE t1; + +# +# Test that new VARCHAR correctly works with COUNT(DISTINCT) +# + +CREATE TABLE t1 (a VARCHAR(400)); +INSERT INTO t1 (a) VALUES ("A"), ("a"), ("a "), ("a "), + ("B"), ("b"), ("b "), ("b "); +SELECT COUNT(DISTINCT a) FROM t1; +DROP TABLE t1; + +# +# Test for buf #9210: GROUP BY with expression if a decimal type +# + +CREATE TABLE t1 (a int, b int, c int); +INSERT INTO t1 (a, b, c) VALUES + (1,1,1), (1,1,2), (1,1,3), + (1,2,1), (1,2,2), (1,2,3), + (1,3,1), (1,3,2), (1,3,3), + (2,1,1), (2,1,2), (2,1,3), + (2,2,1), (2,2,2), (2,2,3), + (2,3,1), (2,3,2), (2,3,3), + (3,1,1), (3,1,2), (3,1,3), + (3,2,1), (3,2,2), (3,2,3), + (3,3,1), (3,3,2), (3,3,3); + +SELECT b/c as v, a FROM t1 ORDER BY v; +SELECT b/c as v, SUM(a) FROM t1 GROUP BY v; +SELECT SUM(a) FROM t1 GROUP BY b/c; + +DROP TABLE t1; +set div_precision_increment= @sav_dpi; + +# +# Bug #20868: Client connection is broken on SQL query error +# +CREATE TABLE t1 (a INT PRIMARY KEY, b INT); +INSERT INTO t1 VALUES (1,1), (2,2); + +CREATE TABLE t2 (a INT PRIMARY KEY, b INT); +INSERT INTO t2 VALUES (1,1), (3,3); + +SELECT SQL_NO_CACHE + (SELECT SUM(c.a) FROM t1 ttt, t2 ccc + WHERE ttt.a = ccc.b AND ttt.a = t.a GROUP BY ttt.a) AS minid +FROM t1 t, t2 c WHERE t.a = c.b; + +DROP TABLE t1,t2; + +# +# Bug #10966: Variance functions return wrong data type +# + +create table t1 select variance(0); +show create table t1; +drop table t1; +create table t1 select stddev(0); +show create table t1; +drop table t1; + diff --git a/mysql-test/t/func_if.test b/mysql-test/t/func_if.test index 5756793c673..beaa371f847 100644 --- a/mysql-test/t/func_if.test +++ b/mysql-test/t/func_if.test @@ -25,9 +25,10 @@ explain extended select if(u=1,st,binary st) s from t1 where st like "%a%" order # # NULLIF test # -select nullif(u=0, 'test') from t1; -explain extended select nullif(u=0, 'test') from t1; +select nullif(u, 1) from t1; +explain extended select nullif(u, 1) from t1; drop table t1; +select nullif(1,'test'); # # Bug 2629 @@ -62,6 +63,20 @@ drop table t1; SELECT NULLIF(5,5) IS NULL, NULLIF(5,5) IS NOT NULL; # +# Bug #9669 Ordering on IF function with FROM_UNIXTIME function fails +# +CREATE TABLE `t1` ( + `id` int(11) NOT NULL , + `date` int(10) default NULL, + `text` varchar(32) NOT NULL +); +INSERT INTO t1 VALUES (1,1110000000,'Day 1'),(2,1111000000,'Day 2'),(3,1112000000,'Day 3'); +SELECT id, IF(date IS NULL, '-', FROM_UNIXTIME(date, '%d-%m-%Y')) AS date_ord, text FROM t1 ORDER BY date_ord ASC; +SELECT id, IF(date IS NULL, '-', FROM_UNIXTIME(date, '%d-%m-%Y')) AS date_ord, text FROM t1 ORDER BY date_ord DESC; +DROP TABLE t1; + + +# # Test for bug #11142: evaluation of NULLIF when the first argument is NULL # @@ -74,3 +89,11 @@ SELECT a, NULLIF(a,'') FROM t1 WHERE NULLIF(a,'') IS NULL; DROP TABLE t1; # End of 4.1 tests + +# +# Bug #16272 IF function with decimal args can produce wrong result +# +create table t1 (f1 int, f2 int); +insert into t1 values(1,1),(0,0); +select f1, f2, if(f1, 40.0, 5.00) from t1 group by f1 order by f2; +drop table t1; diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test index 2ffe5a2d5f7..8ddf1fbe314 100644 --- a/mysql-test/t/func_in.test +++ b/mysql-test/t/func_in.test @@ -1,6 +1,6 @@ # Initialise --disable_warnings -drop table if exists t1; +drop table if exists t1, t2; --enable_warnings # # test of IN (NULL) @@ -97,7 +97,7 @@ select 1 in ('1.1',2.0); # Test case for bug #6365 -create table t1 (a char(20) character set binary); +create table t1 (a char(2) character set binary); insert into t1 values ('aa'), ('bb'); select * from t1 where a in (NULL, 'aa'); drop table t1; @@ -110,3 +110,125 @@ select count(*) from t1 where id not in (1,2); drop table t1; # End of 4.1 tests + +# +# Bug #11885: WHERE condition with NOT IN (one element) +# + +CREATE TABLE t1 (a int PRIMARY KEY); +INSERT INTO t1 VALUES (44), (45), (46); + +SELECT * FROM t1 WHERE a IN (45); +SELECT * FROM t1 WHERE a NOT IN (0, 45); +SELECT * FROM t1 WHERE a NOT IN (45); + +CREATE VIEW v1 AS SELECT * FROM t1 WHERE a NOT IN (45); +SHOW CREATE VIEW v1; +SELECT * FROM v1; + +DROP VIEW v1; +DROP TABLE t1; + +# BUG#15872: Excessive memory consumption of range analysis of NOT IN +create table t1 (a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t2 (a int, filler char(200), key(a)); + +insert into t2 select C.a*2, 'no' from t1 A, t1 B, t1 C; +insert into t2 select C.a*2+1, 'yes' from t1 C; + +explain +select * from t2 where a NOT IN (0, 2,4,6,8,10,12,14,16,18); +select * from t2 where a NOT IN (0, 2,4,6,8,10,12,14,16,18); + +explain select * from t2 force index(a) where a NOT IN (2,2,2,2,2,2); +explain select * from t2 force index(a) where a <> 2; + +drop table t2; + +# +# Repeat the test for DATETIME +# +create table t2 (a datetime, filler char(200), key(a)); + +insert into t2 select '2006-04-25 10:00:00' + interval C.a minute, + 'no' from t1 A, t1 B, t1 C where C.a % 2 = 0; + +insert into t2 select '2006-04-25 10:00:00' + interval C.a*2+1 minute, + 'yes' from t1 C; + +explain +select * from t2 where a NOT IN ( + '2006-04-25 10:00:00','2006-04-25 10:02:00','2006-04-25 10:04:00', + '2006-04-25 10:06:00', '2006-04-25 10:08:00'); +select * from t2 where a NOT IN ( + '2006-04-25 10:00:00','2006-04-25 10:02:00','2006-04-25 10:04:00', + '2006-04-25 10:06:00', '2006-04-25 10:08:00'); +drop table t2; + +# +# Repeat the test for CHAR(N) +# +create table t2 (a varchar(10), filler char(200), key(a)); + +insert into t2 select 'foo', 'no' from t1 A, t1 B; +insert into t2 select 'barbar', 'no' from t1 A, t1 B; +insert into t2 select 'bazbazbaz', 'no' from t1 A, t1 B; + +insert into t2 values ('fon', '1'), ('fop','1'), ('barbaq','1'), + ('barbas','1'), ('bazbazbay', '1'),('zz','1'); + +explain select * from t2 where a not in('foo','barbar', 'bazbazbaz'); + +drop table t2; + +# +# Repeat for DECIMAL +# +create table t2 (a decimal(10,5), filler char(200), key(a)); + +insert into t2 select 345.67890, 'no' from t1 A, t1 B; +insert into t2 select 43245.34, 'no' from t1 A, t1 B; +insert into t2 select 64224.56344, 'no' from t1 A, t1 B; + +insert into t2 values (0, '1'), (22334.123,'1'), (33333,'1'), + (55555,'1'), (77777, '1'); + +explain +select * from t2 where a not in (345.67890, 43245.34, 64224.56344); +select * from t2 where a not in (345.67890, 43245.34, 64224.56344); + +drop table t2; + +# Try a very big IN-list +create table t2 (a int, key(a), b int); +insert into t2 values (1,1),(2,2); + +set @cnt= 1; +set @str="update t2 set b=1 where a not in ("; +select count(*) from ( + select @str:=concat(@str, @cnt:=@cnt+1, ",") + from t1 A, t1 B, t1 C, t1 D) Z; + +set @str:=concat(@str, "10000)"); +select substr(@str, 1, 50); +prepare s from @str; +execute s; +deallocate prepare s; +set @str=NULL; + +drop table t2; +drop table t1; + +# BUG#19618: Crash in range optimizer for +# "unsigned_keypart NOT IN(negative_number,...)" +# (introduced in fix BUG#15872) +create table t1 ( + some_id smallint(5) unsigned, + key (some_id) +); +insert into t1 values (1),(2); +select some_id from t1 where some_id not in(2,-1); +select some_id from t1 where some_id not in(-4,-1,-4); +select some_id from t1 where some_id not in(-4,-1,3423534,2342342); +drop table t1; diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index c22c09ab62b..4041c267134 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -54,6 +54,11 @@ SELECT ASIN(1.2-0.2); #select floor(log(8)/log(2)); #select floor(log(16)/log(2)); +# +# Bug #9060 (format returns incorrect result) +# +select format(4.55, 1), format(4.551, 1); + explain extended select degrees(pi()),radians(360); # @@ -63,6 +68,31 @@ explain extended select degrees(pi()),radians(360); --error 1054 select rand(rand); +# End of 4.1 tests + +# +# Bug #8459 (FORMAT returns incorrect result) +# +create table t1 (col1 int, col2 decimal(60,30)); +insert into t1 values(1,1234567890.12345); +select format(col2,7) from t1; +select format(col2,8) from t1; +insert into t1 values(7,1234567890123456.12345); +select format(col2,6) from t1 where col1=7; +drop table t1; + + +# +# Bug #10083 (round doesn't increase decimals) +# +select round(150, 2); + +# +# Bug @10632 (Ceiling function returns wrong answer) +# +select ceil(0.09); +select ceil(0.000000000000000009); + # # Bug #9837: problem with round() # @@ -99,3 +129,51 @@ select a from t1 where a='http://www.foo.com/' order by abs(timediff(ts, 0)); drop table t1; # End of 4.1 tests + +# +# Bug #13820 (No warning on log(negative) +# +set sql_mode='traditional'; +select ln(-1); +select log10(-1); +select log2(-1); +select log(2,-1); +select log(-2,1); +set sql_mode=''; + +# +# Bug #8461 truncate() and round() return false results 2nd argument negative. +# +# round(a,-b) log_10(b) > a +select round(111,-10); +# round on bigint +select round(-5000111000111000155,-1); +# round on unsigned bigint +select round(15000111000111000155,-1); +# truncate on bigint +select truncate(-5000111000111000155,-1); +# truncate on unsigned bigint +select truncate(15000111000111000155,-1); + +# +# Bug#16678 FORMAT gives wrong result if client run with default-character-set=utf8 +# +set names utf8; +create table t1 +(f1 varchar(32) not null, + f2 smallint(5) unsigned not null, + f3 int(10) unsigned not null default '0') +engine=myisam default charset=utf8; +insert into t1 values ('zombie',0,0),('gold',1,10000),('silver',2,10000); + +create table t2 +(f1 int(10) unsigned not null, + f2 int(10) unsigned not null, + f3 smallint(5) unsigned not null) +engine=myisam default charset=utf8; +insert into t2 values (16777216,16787215,1),(33554432,33564431,2); + +select format(t2.f2-t2.f1+1,0) from t1,t2 +where t1.f2 = t2.f3 order by t1.f1; +drop table t1, t2; +set names default; diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test index a7dc9e7c966..52a5512d070 100644 --- a/mysql-test/t/func_misc.test +++ b/mysql-test/t/func_misc.test @@ -38,11 +38,6 @@ select a from t1 where mid(a+0,6,3) = ( mid(20040106123400,6,3) ); drop table t1; -# Test for BUG#9535 -create table t1 as select uuid(), length(uuid()); -show create table t1; -drop table t1; - # # Bug#16501: IS_USED_LOCK does not appear to work @@ -89,3 +84,45 @@ DROP TABLE t1; select export_set(3, _latin1'foo', _utf8'bar', ',', 4); --echo End of 4.1 tests + + +# +# Test for BUG#9535 +# +create table t1 as select uuid(), length(uuid()); +show create table t1; +drop table t1; + +# +# Bug #6760: Add SLEEP() function +# +create table t1 (a timestamp default '2005-05-05 01:01:01', + b timestamp default '2005-05-05 01:01:01'); +insert into t1 set a = now(); +select sleep(3); +update t1 set b = now(); +select timediff(b, a) >= '00:00:03' from t1; +drop table t1; + +# +# Bug #12689: SLEEP() gets incorrectly cached/optimized-away +# +set global query_cache_size=1355776; +create table t1 (a int); +insert into t1 values (1),(1),(1); +create table t2 (a datetime default null, b datetime default null); +insert into t2 set a = now(); +select a from t1 where sleep(1); +update t2 set b = now() where b is null; +insert into t2 set a = now(); +select a from t1 where sleep(a); +update t2 set b = now() where b is null; +insert into t2 set a = now(); +select a from t1 where sleep(1); +update t2 set b = now() where b is null; +select timediff(b, a) >= '00:00:03' from t2; +drop table t2; +drop table t1; +set global query_cache_size=default; + +--echo End of 5.0 tests diff --git a/mysql-test/t/func_sapdb.test b/mysql-test/t/func_sapdb.test index 930ad37c60c..97101fba615 100644 --- a/mysql-test/t/func_sapdb.test +++ b/mysql-test/t/func_sapdb.test @@ -30,10 +30,16 @@ select adddate("1997-12-31 23:59:59.000001", 10); select subdate("1997-12-31 23:59:59.000001", 10); select datediff("1997-12-31 23:59:59.000001","1997-12-30"); +select datediff("1997-11-30 23:59:59.000001","1997-12-31"); +SET @@SQL_MODE="ALLOW_INVALID_DATES"; select datediff("1997-11-31 23:59:59.000001","1997-12-31"); -select datediff("1997-11-31 23:59:59.000001",null); +SET @@SQL_MODE=""; -select weekofyear("1997-11-31 23:59:59.000001"); +-- This will give a warning +select datediff("1997-11-31 23:59:59.000001","1997-12-31"); +select datediff("1997-11-30 23:59:59.000001",null); + +select weekofyear("1997-11-30 23:59:59.000001"); select makedate(1997,1); select makedate(1997,0); @@ -110,7 +116,8 @@ insert into test values SELECT ADDTIME(t1,t2) As ttt, ADDTIME(t2, t3) As qqq from test; # PS doesn't support fractional seconds --disable_ps_protocol -SELECT TIMEDIFF(t1,t4) As ttt, TIMEDIFF(t2, t3) As qqq from test; +SELECT TIMEDIFF(t1, t4) As ttt, TIMEDIFF(t2, t3) As qqq, + TIMEDIFF(t3, t2) As eee, TIMEDIFF(t2, t4) As rrr from test; --enable_ps_protocol drop table t1, test; diff --git a/mysql-test/t/func_set.test b/mysql-test/t/func_set.test index c003826ff5a..710b9b90a05 100644 --- a/mysql-test/t/func_set.test +++ b/mysql-test/t/func_set.test @@ -18,6 +18,8 @@ select export_set(9,"Y","N","-",5),export_set(9,"Y","N"),export_set(9,"Y","N","" # Wrong usage of functions # select elt(2,1),field(NULL,"a","b","c"); +select field("b","a",NULL),field(1,0,NULL)+0,field(1.0,0.0,NULL)+0.0,field(1.0e1,0.0e1,NULL)+0.0e1; +select field(NULL,"a",NULL),field(NULL,0,NULL)+0,field(NULL,0.0,NULL)+0.0,field(NULL,0.0e1,NULL)+0.0e1; select find_in_set("","a,b,c"),find_in_set("","a,b,c,"),find_in_set("",",a,b,c"); select find_in_set("abc","abc"),find_in_set("ab","abc"),find_in_set("abcd","abc"); select interval(null, 1, 10, 100); diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 3c855a32eed..9622de96143 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -3,7 +3,7 @@ # Testing string functions --disable_warnings -drop table if exists t1; +drop table if exists t1,t2; --enable_warnings set names latin1; @@ -15,9 +15,15 @@ select bit_length('\n\t\r\b\0\_\%\\'); select char_length('\n\t\r\b\0\_\%\\'); select length(_latin1'\n\t\n\b\0\\_\\%\\'); select concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h'); +select hex(char(256)); select locate('he','hello'),locate('he','hello',2),locate('lo','hello',2) ; select instr('hello','HE'), instr('hello',binary 'HE'), instr(binary 'hello','HE'); select position(binary 'll' in 'hello'),position('a' in binary 'hello'); +# +# Bug#11728 string function LEFT, +# strange undocumented behaviour, strict mode +# +select left('hello',null), right('hello',null); select left('hello',2),right('hello',2),substring('hello',2,2),mid('hello',1,5) ; select concat('',left(right(concat('what ',concat('is ','happening')),9),4),'',substring('monty',5,1)) ; select substring_index('www.tcx.se','.',-2),substring_index('www.tcx.se','.',1); @@ -64,6 +70,7 @@ select substring_index('the king of the the hill','the',2); select substring_index('the king of the the hill','the',3); select concat(':',ltrim(' left '),':',rtrim(' right '),':'); +select concat(':',trim(leading from ' left '),':',trim(trailing from ' right '),':'); select concat(':',trim(LEADING FROM ' left'),':',trim(TRAILING FROM ' right '),':'); select concat(':',trim(' m '),':',trim(BOTH FROM ' y '),':',trim('*' FROM '*s*'),':'); select concat(':',trim(BOTH 'ab' FROM 'ababmyabab'),':',trim(BOTH '*' FROM '***sql'),':'); @@ -166,7 +173,7 @@ CREATE TABLE t1 ( program int(10) unsigned default NULL, bugdesc text, created datetime default NULL, - modified timestamp(14) NOT NULL, + modified timestamp NOT NULL, bugstatus int(10) unsigned default NULL, submitter int(10) unsigned default NULL ) ENGINE=MyISAM; @@ -282,7 +289,7 @@ select FIELD('b','A' COLLATE latin1_bin,'B'); select FIELD(_latin2'b','A','B'); --error 1270 select FIELD('b',_latin2'A','B'); -select FIELD('b',_latin2'A','B',1); +select FIELD('1',_latin2'3','2',1); select POSITION(_latin1'B' IN _latin1'abcd'); select POSITION(_latin1'B' IN _latin1'abcd' COLLATE latin1_bin); @@ -466,6 +473,7 @@ SELECT lpad(12345, 5, "#"); # SELECT conv(71, 10, 36), conv('1Z', 36, 10); +SELECT conv(71, 10, 37), conv('1Z', 37, 10), conv(0,1,10),conv(0,0,10), conv(0,-1,10); # # Bug in SUBSTRING when mixed with CONCAT and ORDER BY (Bug #3089) @@ -511,6 +519,8 @@ drop table t1; # select trim(null from 'kate') as "must_be_null"; select trim('xyz' from null) as "must_be_null"; +select trim(leading NULL from 'kate') as "must_be_null"; +select trim(trailing NULL from 'xyz') as "must_be_null"; # # Bug #7751 - conversion for a bigint unsigned constant @@ -560,7 +570,6 @@ SELECT t1.id, aes_decrypt(str, 'bar') FROM t1, t2 WHERE t1.id = t2.id DROP TABLE t1, t2; - # # Bug #10944: Mishandling of NULL arguments in FIELD() # @@ -714,3 +723,250 @@ EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(BOTH 'y' FROM s) > 'ab'; DROP TABLE t1; --echo End of 4.1 tests + +# +# Bug #13361: SELECT FORMAT(<decimal field with null>, 2) crashes +# +create table t1 (d decimal default null); +insert into t1 values (null); +select format(d, 2) from t1; +drop table t1; + +# +# Bug #14676: substring_index() returns incorrect results +# +create table t1 (c varchar(40)); +insert into t1 values ('y,abc'),('y,abc'); +select c, substring_index(lcase(c), @q:=',', -1) as res from t1; +drop table t1; + +# +# Bug #17043: Casting trimmed string to decimal loses precision +# +select cast(rtrim(' 20.06 ') as decimal(19,2)); +select cast(ltrim(' 20.06 ') as decimal(19,2)); +select cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2)); + +# +# Bug #13975: "same string" + 0 has 2 different results +# +select conv("18383815659218730760",10,10) + 0; +select "18383815659218730760" + 0; + +# +# Bug #21698: substitution of a string field for a constant under a function +# + +CREATE TABLE t1 (code varchar(10)); +INSERT INTO t1 VALUES ('a12'), ('A12'), ('a13'); + +SELECT ASCII(code), code FROM t1 WHERE code='A12'; +SELECT ASCII(code), code FROM t1 WHERE code='A12' AND ASCII(code)=65; + +INSERT INTO t1 VALUES ('a12 '), ('A12 '); + +SELECT LENGTH(code), code FROM t1 WHERE code='A12'; +SELECT LENGTH(code), code FROM t1 WHERE code='A12' AND LENGTH(code)=5; + +ALTER TABLE t1 ADD INDEX (code); +CREATE TABLE t2 (id varchar(10) PRIMARY KEY); +INSERT INTO t2 VALUES ('a11'), ('a12'), ('a13'), ('a14'); + +SELECT * FROM t1 INNER JOIN t2 ON t1.code=t2.id + WHERE t2.id='a12' AND (LENGTH(code)=5 OR code < 'a00'); +EXPLAIN EXTENDED +SELECT * FROM t1 INNER JOIN t2 ON code=id + WHERE id='a12' AND (LENGTH(code)=5 OR code < 'a00'); + +DROP TABLE t1,t2; + +# +# Bug #10963 +# 4294967296 18446744073709551616 + +select locate('he','hello',-2); +select locate('lo','hello',-4294967295); +select locate('lo','hello',4294967295); +select locate('lo','hello',-4294967296); +select locate('lo','hello',4294967296); +select locate('lo','hello',-4294967297); +select locate('lo','hello',4294967297); +select locate('lo','hello',-18446744073709551615); +select locate('lo','hello',18446744073709551615); +select locate('lo','hello',-18446744073709551616); +select locate('lo','hello',18446744073709551616); +select locate('lo','hello',-18446744073709551617); +select locate('lo','hello',18446744073709551617); + +select left('hello', 10); +select left('hello', 0); +select left('hello', -1); +select left('hello', -4294967295); +select left('hello', 4294967295); +select left('hello', -4294967296); +select left('hello', 4294967296); +select left('hello', -4294967297); +select left('hello', 4294967297); +select left('hello', -18446744073709551615); +select left('hello', 18446744073709551615); +select left('hello', -18446744073709551616); +select left('hello', 18446744073709551616); +select left('hello', -18446744073709551617); +select left('hello', 18446744073709551617); + +select right('hello', 10); +select right('hello', 0); +select right('hello', -1); +select right('hello', -4294967295); +select right('hello', 4294967295); +select right('hello', -4294967296); +select right('hello', 4294967296); +select right('hello', -4294967297); +select right('hello', 4294967297); +select right('hello', -18446744073709551615); +select right('hello', 18446744073709551615); +select right('hello', -18446744073709551616); +select right('hello', 18446744073709551616); +select right('hello', -18446744073709551617); +select right('hello', 18446744073709551617); + +select substring('hello', 2, -1); + +select substring('hello', -1, 1); +select substring('hello', -2, 1); +select substring('hello', -4294967295, 1); +select substring('hello', 4294967295, 1); +select substring('hello', -4294967296, 1); +select substring('hello', 4294967296, 1); +select substring('hello', -4294967297, 1); +select substring('hello', 4294967297, 1); +select substring('hello', -18446744073709551615, 1); +select substring('hello', 18446744073709551615, 1); +select substring('hello', -18446744073709551616, 1); +select substring('hello', 18446744073709551616, 1); +select substring('hello', -18446744073709551617, 1); +select substring('hello', 18446744073709551617, 1); +select substring('hello', 1, -1); +select substring('hello', 1, -4294967295); +select substring('hello', 1, 4294967295); +select substring('hello', 1, -4294967296); +select substring('hello', 1, 4294967296); +select substring('hello', 1, -4294967297); +select substring('hello', 1, 4294967297); +select substring('hello', 1, -18446744073709551615); +select substring('hello', 1, 18446744073709551615); +select substring('hello', 1, -18446744073709551616); +select substring('hello', 1, 18446744073709551616); +select substring('hello', 1, -18446744073709551617); +select substring('hello', 1, 18446744073709551617); +select substring('hello', -1, -1); +select substring('hello', -4294967295, -4294967295); +select substring('hello', 4294967295, 4294967295); +select substring('hello', -4294967296, -4294967296); +select substring('hello', 4294967296, 4294967296); +select substring('hello', -4294967297, -4294967297); +select substring('hello', 4294967297, 4294967297); +select substring('hello', -18446744073709551615, -18446744073709551615); +select substring('hello', 18446744073709551615, 18446744073709551615); +select substring('hello', -18446744073709551616, -18446744073709551616); +select substring('hello', 18446744073709551616, 18446744073709551616); +select substring('hello', -18446744073709551617, -18446744073709551617); +select substring('hello', 18446744073709551617, 18446744073709551617); + +select insert('hello', -1, 1, 'hi'); +select insert('hello', -4294967295, 1, 'hi'); +select insert('hello', 4294967295, 1, 'hi'); +select insert('hello', -4294967296, 1, 'hi'); +select insert('hello', 4294967296, 1, 'hi'); +select insert('hello', -4294967297, 1, 'hi'); +select insert('hello', 4294967297, 1, 'hi'); +select insert('hello', -18446744073709551615, 1, 'hi'); +select insert('hello', 18446744073709551615, 1, 'hi'); +select insert('hello', -18446744073709551616, 1, 'hi'); +select insert('hello', 18446744073709551616, 1, 'hi'); +select insert('hello', -18446744073709551617, 1, 'hi'); +select insert('hello', 18446744073709551617, 1, 'hi'); +select insert('hello', 1, -1, 'hi'); +select insert('hello', 1, -4294967295, 'hi'); +select insert('hello', 1, 4294967295, 'hi'); +select insert('hello', 1, -4294967296, 'hi'); +select insert('hello', 1, 4294967296, 'hi'); +select insert('hello', 1, -4294967297, 'hi'); +select insert('hello', 1, 4294967297, 'hi'); +select insert('hello', 1, -18446744073709551615, 'hi'); +select insert('hello', 1, 18446744073709551615, 'hi'); +select insert('hello', 1, -18446744073709551616, 'hi'); +select insert('hello', 1, 18446744073709551616, 'hi'); +select insert('hello', 1, -18446744073709551617, 'hi'); +select insert('hello', 1, 18446744073709551617, 'hi'); +select insert('hello', -1, -1, 'hi'); +select insert('hello', -4294967295, -4294967295, 'hi'); +select insert('hello', 4294967295, 4294967295, 'hi'); +select insert('hello', -4294967296, -4294967296, 'hi'); +select insert('hello', 4294967296, 4294967296, 'hi'); +select insert('hello', -4294967297, -4294967297, 'hi'); +select insert('hello', 4294967297, 4294967297, 'hi'); +select insert('hello', -18446744073709551615, -18446744073709551615, 'hi'); +select insert('hello', 18446744073709551615, 18446744073709551615, 'hi'); +select insert('hello', -18446744073709551616, -18446744073709551616, 'hi'); +select insert('hello', 18446744073709551616, 18446744073709551616, 'hi'); +select insert('hello', -18446744073709551617, -18446744073709551617, 'hi'); +select insert('hello', 18446744073709551617, 18446744073709551617, 'hi'); + +select repeat('hello', -1); +select repeat('hello', -4294967295); +select repeat('hello', 4294967295); +select repeat('hello', -4294967296); +select repeat('hello', 4294967296); +select repeat('hello', -4294967297); +select repeat('hello', 4294967297); +select repeat('hello', -18446744073709551615); +select repeat('hello', 18446744073709551615); +select repeat('hello', -18446744073709551616); +select repeat('hello', 18446744073709551616); +select repeat('hello', -18446744073709551617); +select repeat('hello', 18446744073709551617); + +select space(-1); +select space(-4294967295); +select space(4294967295); +select space(-4294967296); +select space(4294967296); +select space(-4294967297); +select space(4294967297); +select space(-18446744073709551615); +select space(18446744073709551615); +select space(-18446744073709551616); +select space(18446744073709551616); +select space(-18446744073709551617); +select space(18446744073709551617); + +select rpad('hello', -1, '1'); +select rpad('hello', -4294967295, '1'); +select rpad('hello', 4294967295, '1'); +select rpad('hello', -4294967296, '1'); +select rpad('hello', 4294967296, '1'); +select rpad('hello', -4294967297, '1'); +select rpad('hello', 4294967297, '1'); +select rpad('hello', -18446744073709551615, '1'); +select rpad('hello', 18446744073709551615, '1'); +select rpad('hello', -18446744073709551616, '1'); +select rpad('hello', 18446744073709551616, '1'); +select rpad('hello', -18446744073709551617, '1'); +select rpad('hello', 18446744073709551617, '1'); + +select lpad('hello', -1, '1'); +select lpad('hello', -4294967295, '1'); +select lpad('hello', 4294967295, '1'); +select lpad('hello', -4294967296, '1'); +select lpad('hello', 4294967296, '1'); +select lpad('hello', -4294967297, '1'); +select lpad('hello', 4294967297, '1'); +select lpad('hello', -18446744073709551615, '1'); +select lpad('hello', 18446744073709551615, '1'); +select lpad('hello', -18446744073709551616, '1'); +select lpad('hello', 18446744073709551616, '1'); +select lpad('hello', -18446744073709551617, '1'); +select lpad('hello', 18446744073709551617, '1'); + +--echo End of 5.0 tests diff --git a/mysql-test/t/func_test.test b/mysql-test/t/func_test.test index 99519b54ca6..77bf3be5e72 100644 --- a/mysql-test/t/func_test.test +++ b/mysql-test/t/func_test.test @@ -140,4 +140,23 @@ select mod(12.0, NULL) as 'NULL'; select mod(NULL, 2) as 'NULL'; select mod(NULL, 2.0) as 'NULL'; + +# +# Bug#6726: NOT BETWEEN parse failure +# +create table t1 (a int, b int); +insert into t1 values (1,2), (2,3), (3,4), (4,5); +select * from t1 where a not between 1 and 2; +select * from t1 where a not between 1 and 2 and b not between 3 and 4; +drop table t1; + +# +# Test for bug #12791: one of the arguments of LEAST/GREATEST is NULL +# + +SELECT GREATEST(1,NULL) FROM DUAL; +SELECT LEAST('xxx','aaa',NULL,'yyy') FROM DUAL; +SELECT LEAST(1.1,1.2,NULL,1.0) FROM DUAL; +SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL; + # End of 4.1 tests diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 066a059483c..a3985998b13 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -5,6 +5,9 @@ drop table if exists t1,t2,t3; --enable_warnings +# Set timezone to GMT-3, to make it possible to use "interval 3 hour" +set time_zone="+03:00"; + select from_days(to_days("960101")),to_days(960201)-to_days("19960101"),to_days(date_add(curdate(), interval 1 day))-to_days(curdate()),weekday("1997-11-29"); select period_add("9602",-12),period_diff(199505,"9404") ; @@ -140,6 +143,22 @@ select extract(SECOND FROM "1999-01-02 10:11:12"); select extract(MONTH FROM "2001-02-00"); # +# test EXTRACT QUARTER (Bug #18100) +# + +SELECT EXTRACT(QUARTER FROM '2004-01-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-02-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-03-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-04-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-05-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-06-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-07-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-08-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-09-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-10-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-11-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-12-15') AS quarter; +# # MySQL Bugs: #12356: DATE_SUB or DATE_ADD incorrectly returns null # SELECT DATE_SUB(str_to_date('9999-12-31 00:01:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE); @@ -217,7 +236,7 @@ drop table t1; CREATE TABLE t1 ( start datetime default NULL); INSERT INTO t1 VALUES ('2002-10-21 00:00:00'),('2002-10-28 00:00:00'),('2002-11-04 00:00:00'); -CREATE TABLE t2 ( ctime1 timestamp(14) NOT NULL, ctime2 timestamp(14) NOT NULL); +CREATE TABLE t2 ( ctime1 timestamp NOT NULL, ctime2 timestamp NOT NULL); INSERT INTO t2 VALUES (20021029165106,20021105164731); CREATE TABLE t3 (ctime1 char(19) NOT NULL, ctime2 char(19) NOT NULL); INSERT INTO t3 VALUES ("2002-10-29 16:51:06","2002-11-05 16:47:31"); @@ -236,17 +255,57 @@ select unix_timestamp(@a); select unix_timestamp('1969-12-01 19:00:01'); # -# Test for bug #6439 "unix_timestamp() function returns wrong datetime -# values for too big argument" and bug #7515 "from_unixtime(0) now -# returns NULL instead of the epoch". unix_timestamp() should return error -# for too big or negative argument. It should return Epoch value for zero -# argument since it seems that many user's rely on this fact. +# Tests for bug #6439 "unix_timestamp() function returns wrong datetime +# values for too big argument", bug #7515 "from_unixtime(0) now +# returns NULL instead of the epoch" and bug #9191 +# "TIMESTAMP/from_unixtime() no longer accepts 2^31-1." +# unix_timestamp() should return error for too big or negative argument. +# It should return Epoch value for zero argument since it seems that many +# users rely on this fact, from_unixtime() should work with values +# up to INT_MAX32 because of the same reason. # select from_unixtime(-1); -select from_unixtime(2145916800); +# check for from_unixtime(2^31-1) and from_unixtime(2^31) +select from_unixtime(2147483647); +select from_unixtime(2147483648); select from_unixtime(0); # +# Some more tests for bug #9191 "TIMESTAMP/from_unixtime() no +# longer accepts 2^31-1". Here we test that from_unixtime and +# unix_timestamp are consistent, when working with boundary dates. +# +select unix_timestamp(from_unixtime(2147483647)); +select unix_timestamp(from_unixtime(2147483648)); + +# check for invalid dates + +# bad year +select unix_timestamp('2039-01-20 01:00:00'); +select unix_timestamp('1968-01-20 01:00:00'); +# bad month +select unix_timestamp('2038-02-10 01:00:00'); +select unix_timestamp('1969-11-20 01:00:00'); +# bad day +select unix_timestamp('2038-01-20 01:00:00'); +select unix_timestamp('1969-12-30 01:00:00'); + +# +# Check negative shift (we subtract several days for boundary dates during +# conversion). +select unix_timestamp('2038-01-17 12:00:00'); + +# +# Check positive shift. (it happens only on +# platfroms with unsigned time_t, such as QNX) +# +select unix_timestamp('1970-01-01 03:00:01'); + +# check bad date, close to the boundary (we cut them off in the very end) +select unix_timestamp('2038-01-19 07:14:07'); + + +# # Test types from + INTERVAL # @@ -272,6 +331,64 @@ select date_add(date,INTERVAL "1 1" YEAR_MONTH) from t1; select date_add(date,INTERVAL "1:1:1" HOUR_SECOND) from t1; select date_add(date,INTERVAL "1 1:1" DAY_MINUTE) from t1; select date_add(date,INTERVAL "1 1:1:1" DAY_SECOND) from t1; +select date_add(date,INTERVAL "1" WEEK) from t1; +select date_add(date,INTERVAL "1" QUARTER) from t1; +select timestampadd(MINUTE, 1, date) from t1; +select timestampadd(WEEK, 1, date) from t1; +select timestampadd(SQL_TSI_SECOND, 1, date) from t1; +# Prepared statements doesn't support FRAC_SECOND yet +--disable_ps_protocol +select timestampadd(SQL_TSI_FRAC_SECOND, 1, date) from t1; +--enable_ps_protocol + +select timestampdiff(MONTH, '2001-02-01', '2001-05-01') as a; +select timestampdiff(YEAR, '2002-05-01', '2001-01-01') as a; +select timestampdiff(QUARTER, '2002-05-01', '2001-01-01') as a; +select timestampdiff(MONTH, '2000-03-28', '2000-02-29') as a; +select timestampdiff(MONTH, '1991-03-28', '2000-02-29') as a; +select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a; +select timestampdiff(SQL_TSI_HOUR, '2001-02-01', '2001-05-01') as a; +select timestampdiff(SQL_TSI_DAY, '2001-02-01', '2001-05-01') as a; +select timestampdiff(SQL_TSI_MINUTE, '2001-02-01 12:59:59', '2001-05-01 12:58:59') as a; +select timestampdiff(SQL_TSI_SECOND, '2001-02-01 12:59:59', '2001-05-01 12:58:58') as a; +select timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a; + +select timestampdiff(SQL_TSI_DAY, '1986-02-01', '1986-03-01') as a1, + timestampdiff(SQL_TSI_DAY, '1900-02-01', '1900-03-01') as a2, + timestampdiff(SQL_TSI_DAY, '1996-02-01', '1996-03-01') as a3, + timestampdiff(SQL_TSI_DAY, '2000-02-01', '2000-03-01') as a4; + +# bug 16226 +SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:27'); +SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:28'); +SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:29'); +SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:27'); +SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:28'); +SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:29'); + +SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:27'); +SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:28'); +SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:29'); +SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:27'); +SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:28'); +SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:29'); + +SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:27'); +SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:28'); +SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:29'); +SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:27'); +SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:28'); +SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:29'); + +SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:27'); +SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:28'); +SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:29'); +SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:27'); +SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:28'); +SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:29'); + +# end of bug + select date_add(time,INTERVAL 1 SECOND) from t1; drop table t1; @@ -296,6 +413,7 @@ select last_day("1997-12-1")+0.0; # Test SAPDB UTC_% functions. This part is TZ dependant (It is supposed that # TZ variable set to GMT-3 + select strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0; select strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%T"), utc_time())=0; select strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%Y-%m-%d"), utc_date())=0; @@ -354,7 +472,7 @@ select f3 from t1 where f3 between cast("2006-1-1 12:1:1" as datetime) and cast( select f3 from t1 where timestamp(f3) between cast("2006-1-1 12:1:1" as datetime) and cast("2006-1-1 12:1:2" as datetime); select f1 from t1 where cast("2006-1-1" as date) between f1 and f3; select f1 from t1 where cast("2006-1-1" as date) between date(f1) and date(f3); -select f1 from t1 where cast("2006-1-1" as date) between f1 and 'zzz'; +select f1 from t1 where cast("2006-1-1" as date) between f1 and cast('zzz' as date); select f1 from t1 where makedate(2006,1) between date(f1) and date(f3); select f1 from t1 where makedate(2006,2) between date(f1) and date(f3); drop table t1; @@ -447,3 +565,139 @@ union (select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%k') As H); --echo End of 4.1 tests + +explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1, + timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2; + +# +# Bug #10568 +# + +select last_day('2005-00-00'); +select last_day('2005-00-01'); +select last_day('2005-01-00'); + +# +# Bug #10590: %h, %I, and %l format specifies should all return results in +# the 0-11 range +# +select time_format('100:00:00', '%H %k %h %I %l'); + +# +# Bug #12562: Make SYSDATE behave like it does in Oracle: always the current +# time, regardless of magic to make NOW() always the same for the +# entirety of a statement. +create table t1 (a timestamp default '2005-05-05 01:01:01', + b timestamp default '2005-05-05 01:01:01'); +delimiter //; +create function t_slow_sysdate() returns timestamp +begin + do sleep(2); + return sysdate(); +end; +// + +insert into t1 set a = sysdate(), b = t_slow_sysdate();// + +create trigger t_before before insert on t1 +for each row begin + set new.b = t_slow_sysdate(); +end +// + +delimiter ;// + +insert into t1 set a = sysdate(); + +select a != b from t1; + +drop trigger t_before; +drop function t_slow_sysdate; +drop table t1; + +create table t1 (a datetime, i int, b datetime); +insert into t1 select sysdate(), sleep(1), sysdate() from dual; +select a != b from t1; +drop table t1; + +delimiter //; +create procedure t_sysdate() +begin + select sysdate() into @a; + do sleep(2); + select sysdate() into @b; + select @a != @b; +end; +// +delimiter ;// +call t_sysdate(); +drop procedure t_sysdate; + +# +# Bug #13534: timestampdiff() returned incorrect results across leap years +# +select timestampdiff(month,'2004-09-11','2004-09-11'); +select timestampdiff(month,'2004-09-11','2005-09-11'); +select timestampdiff(month,'2004-09-11','2006-09-11'); +select timestampdiff(month,'2004-09-11','2007-09-11'); +select timestampdiff(month,'2005-09-11','2004-09-11'); +select timestampdiff(month,'2005-09-11','2003-09-11'); + +select timestampdiff(month,'2004-02-28','2005-02-28'); +select timestampdiff(month,'2004-02-29','2005-02-28'); +select timestampdiff(month,'2004-02-28','2005-02-28'); +select timestampdiff(month,'2004-03-29','2005-03-28'); +select timestampdiff(month,'2003-02-28','2004-02-29'); +select timestampdiff(month,'2003-02-28','2005-02-28'); + +select timestampdiff(month,'1999-09-11','2001-10-10'); +select timestampdiff(month,'1999-09-11','2001-9-11'); + +select timestampdiff(year,'1999-09-11','2001-9-11'); +select timestampdiff(year,'2004-02-28','2005-02-28'); +select timestampdiff(year,'2004-02-29','2005-02-28'); + +# +# Bug #18618: BETWEEN for dates with the second argument being a constant +# expression and the first and the third arguments being fields +# + +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, day date); +CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, day date); + +INSERT INTO t1 VALUES + (1, '2005-06-01'), (2, '2005-02-01'), (3, '2005-07-01'); +INSERT INTO t2 VALUES + (1, '2005-08-01'), (2, '2005-06-15'), (3, '2005-07-15'); + +SELECT * FROM t1, t2 + WHERE t1.day BETWEEN + '2005.09.01' - INTERVAL 6 MONTH AND t2.day; +SELECT * FROM t1, t2 + WHERE CAST(t1.day AS DATE) BETWEEN + '2005.09.01' - INTERVAL 6 MONTH AND t2.day; + +DROP TABLE t1,t2; + +# End of 5.0 tests + +# Restore timezone to default +set time_zone= @@global.time_zone; + +# +# 21913: DATE_FORMAT() Crashes mysql server if I use it through +# mysql-connector-j driver. +# + +SET NAMES latin1; +SET character_set_results = NULL; +SHOW VARIABLES LIKE 'character_set_results'; + +CREATE TABLE testBug8868 (field1 DATE, field2 VARCHAR(32) CHARACTER SET BINARY); +INSERT INTO testBug8868 VALUES ('2006-09-04', 'abcd'); + +SELECT DATE_FORMAT(field1,'%b-%e %l:%i%p') as fmtddate, field2 FROM testBug8868; + +DROP TABLE testBug8868; + +SET NAMES DEFAULT; diff --git a/mysql-test/t/func_timestamp.test b/mysql-test/t/func_timestamp.test index e1bb7e878ee..05a91b06d28 100644 --- a/mysql-test/t/func_timestamp.test +++ b/mysql-test/t/func_timestamp.test @@ -6,6 +6,9 @@ drop table if exists t1; --enable_warnings +# Set timezone to GMT-3, to make it possible to use "interval 3 hour" +set time_zone="+03:00"; + create table t1 (Zeit time, Tag tinyint not null, Monat tinyint not null, Jahr smallint not null, index(Tag), index(Monat), index(Jahr) ); insert into t1 values ("09:26:00",16,9,1998),("09:26:00",16,9,1998); @@ -15,3 +18,6 @@ FROM t1; drop table t1; # End of 4.1 tests + +# Restore timezone to default +set time_zone= @@global.time_zone; diff --git a/mysql-test/t/gis-rtree.test b/mysql-test/t/gis-rtree.test index cdd8d1f3f0f..09cdcb2435e 100644 --- a/mysql-test/t/gis-rtree.test +++ b/mysql-test/t/gis-rtree.test @@ -120,7 +120,6 @@ INSERT INTO t1 (g) VALUES (GeomFromText('LineString(1 2, 2 3)')),(GeomFromText(' drop table t1; CREATE TABLE t1 ( - geoobjid INT NOT NULL, line LINESTRING NOT NULL, kind ENUM('po', 'pp', 'rr', 'dr', 'rd', 'ts', 'cl') NOT NULL DEFAULT 'po', name VARCHAR(32), @@ -169,7 +168,7 @@ drop table t1; CREATE TABLE t1 (st varchar(100)); INSERT INTO t1 VALUES ("Fake string"); CREATE TABLE t2 (geom GEOMETRY NOT NULL, SPATIAL KEY gk(geom)); ---error 1105 +--error 1416 INSERT INTO t2 SELECT GeomFromText(st) FROM t1; drop table t1, t2; diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test index b66b97c2c41..7bba34be3ff 100644 --- a/mysql-test/t/gis.test +++ b/mysql-test/t/gis.test @@ -165,9 +165,9 @@ explain extended select issimple(MultiPoint(Point(3, 6), Point(4, 10))), issimpl create table t1 (a geometry not null); insert into t1 values (GeomFromText('Point(1 2)')); --- error 1105 +-- error 1416 insert into t1 values ('Garbage'); --- error 1105 +-- error 1416 insert IGNORE into t1 values ('Garbage'); alter table t1 add spatial index(a); @@ -281,7 +281,7 @@ INSERT INTO t1 VALUES(GeomFromText('POINT(580848489 219587743)')); INSERT INTO t1 VALUES(GeomFromText('POINT(11247614 782797569)')); drop table t1; -create table t1 select POINT(1,3); +create table t1 select GeomFromWKB(POINT(1,3)); show create table t1; drop table t1; @@ -360,14 +360,65 @@ t1 where object_id=85984; drop table t1; +create table t1 (fl geometry); +--error 1416 +insert into t1 values (1); +--error 1416 +insert into t1 values (1.11); +--error 1416 +insert into t1 values ("qwerty"); +--error 1416 +insert into t1 values (pointfromtext('point(1,1)')); + +drop table t1; + select (asWKT(geomfromwkb((0x000000000140240000000000004024000000000000)))); select (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440)))); # End of 4.1 tests +# +# Bug #12281 (Geometry: crash in trigger) +# + +create table t1 (s1 geometry not null,s2 char(100)); +create trigger t1_bu before update on t1 for each row set new.s1 = null; +--error 1048 +insert into t1 values (null,null); +drop table t1; + +# +# Bug #10499 (function creation with GEOMETRY datatype) +# +--disable_warnings +drop procedure if exists fn3; +--enable_warnings +create function fn3 () returns point return GeomFromText("point(1 1)"); +show create function fn3; +select astext(fn3()); +drop function fn3; + +# +# Bug #12267 (primary key over GIS) +# +create table t1(pt POINT); +alter table t1 add primary key pti(pt); +drop table t1; +create table t1(pt GEOMETRY); +--error 1170 +alter table t1 add primary key pti(pt); +alter table t1 add primary key pti(pt(20)); +drop table t1; + --enable_metadata create table t1 (g GEOMETRY); select * from t1; select asbinary(g) from t1; --disable_metadata drop table t1; + + +create table t1 select GeomFromText('point(1 1)'); +desc t1; +drop table t1; + diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test index 3365145650a..d3781d58780 100644 --- a/mysql-test/t/grant.test +++ b/mysql-test/t/grant.test @@ -6,6 +6,7 @@ # Cleanup --disable_warnings drop table if exists t1; +drop database if exists mysqltest; --enable_warnings connect (master,localhost,root,,); @@ -184,16 +185,18 @@ grant select(a) on test.t1 to drop_user1@localhost; grant select on test.t1 to drop_user2@localhost; grant select on test.* to drop_user3@localhost; grant select on *.* to drop_user4@localhost; ---error 1268 +# Drop user now implicitly revokes all privileges. drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost, drop_user4@localhost; +--error 1269 revoke all privileges, grant option from drop_user1@localhost, drop_user2@localhost, drop_user3@localhost, drop_user4@localhost; +--error 1396 drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost, drop_user4@localhost; drop table t1; grant usage on *.* to mysqltest_1@localhost identified by "password"; -grant select, update, insert on test.* to mysqltest@localhost; +grant select, update, insert on test.* to mysqltest_1@localhost; show grants for mysqltest_1@localhost; drop user mysqltest_1@localhost; @@ -217,6 +220,9 @@ GRANT SELECT (ËÏÌ) ON ÂÄ.ÔÁ TO ÀÚÅÒ@localhost; SHOW GRANTS FOR ÀÚÅÒ@localhost; REVOKE SELECT (ËÏÌ) ON ÂÄ.ÔÁ FROM ÀÚÅÒ@localhost; +# Revoke does not drop user. Leave a clean user table for the next tests. +DROP USER ÀÚÅÒ@localhost; + DROP DATABASE ÂÄ; SET NAMES latin1; @@ -296,7 +302,7 @@ DROP DATABASE testdb10; create table t1(a int, b int, c int, d int); grant insert(b), insert(c), insert(d), insert(a) on t1 to grant_user@localhost; show grants for grant_user@localhost; -select Host,Db,User,Table_name,Column_name,Column_priv from mysql.columns_priv; +select Host,Db,User,Table_name,Column_name,Column_priv from mysql.columns_priv order by Column_name; revoke ALL PRIVILEGES on t1 from grant_user@localhost; show grants for grant_user@localhost; select Host,Db,User,Table_name,Column_name,Column_priv from mysql.columns_priv; @@ -320,12 +326,25 @@ grant select (c) on mysqltest_2.t1 to mysqltest_3@localhost; grant update (d) on mysqltest_2.t2 to mysqltest_3@localhost; connect (conn1,localhost,mysqltest_3,,); connection conn1; -show grants for mysqltest_3@localhost; +SELECT * FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES + WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_NAME,COLUMN_NAME,PRIVILEGE_TYPE; +SELECT * FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES + WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_NAME,PRIVILEGE_TYPE; +SELECT * from INFORMATION_SCHEMA.SCHEMA_PRIVILEGES + WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_SCHEMA,PRIVILEGE_TYPE; +SELECT * from INFORMATION_SCHEMA.USER_PRIVILEGES + WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_CATALOG,PRIVILEGE_TYPE; --error 1143 update mysqltest_1.t1, mysqltest_1.t2 set q=10 where b=1; +--error 1143 +update mysqltest_1.t2, mysqltest_2.t2 set d=20 where d=1; --error 1142 update mysqltest_1.t1, mysqltest_2.t2 set d=20 where d=1; ---error 1143 +--error 1142 update mysqltest_2.t1, mysqltest_1.t2 set c=20 where b=1; --error 1143 update mysqltest_2.t1, mysqltest_2.t2 set d=10 where s=2; @@ -352,7 +371,7 @@ connection conn2; use mysqltest_1; update mysqltest_2.t1, mysqltest_2.t2 set c=500,d=600; # the following failed before, should fail now. ---error 1143 +--error 1142 update mysqltest_1.t1, mysqltest_1.t2 set a=100,b=200; use mysqltest_2; #the following used to succeed, it must fail now. @@ -376,6 +395,11 @@ drop database mysqltest_1; drop database mysqltest_2; # +# just SHOW PRIVILEGES test +# +SHOW PRIVILEGES; + +# # Rights for renaming test (Bug #3270) # connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); @@ -395,6 +419,71 @@ delete from mysql.user where user=_binary'mysqltest_1'; drop database mysqltest; # +# check all new table priveleges +# +CREATE USER dummy@localhost; +CREATE DATABASE mysqltest; +CREATE TABLE mysqltest.dummytable (dummyfield INT); +CREATE VIEW mysqltest.dummyview AS SELECT dummyfield FROM mysqltest.dummytable; +GRANT ALL PRIVILEGES ON mysqltest.dummytable TO dummy@localhost; +GRANT ALL PRIVILEGES ON mysqltest.dummyview TO dummy@localhost; +SHOW GRANTS FOR dummy@localhost; +use INFORMATION_SCHEMA; +SELECT TABLE_SCHEMA, TABLE_NAME, GROUP_CONCAT(PRIVILEGE_TYPE ORDER BY +PRIVILEGE_TYPE SEPARATOR ', ') AS PRIVILEGES FROM TABLE_PRIVILEGES WHERE GRANTEE += '\'dummy\'@\'localhost\'' GROUP BY TABLE_SCHEMA, TABLE_NAME; +FLUSH PRIVILEGES; +SHOW GRANTS FOR dummy@localhost; +SELECT TABLE_SCHEMA, TABLE_NAME, GROUP_CONCAT(PRIVILEGE_TYPE ORDER BY +PRIVILEGE_TYPE SEPARATOR ', ') AS PRIVILEGES FROM TABLE_PRIVILEGES WHERE GRANTEE += '\'dummy\'@\'localhost\'' GROUP BY TABLE_SCHEMA, TABLE_NAME; +SHOW FIELDS FROM mysql.tables_priv; +use test; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM dummy@localhost; +DROP USER dummy@localhost; +DROP DATABASE mysqltest; +# check view only privileges +CREATE USER dummy@localhost; +CREATE DATABASE mysqltest; +CREATE TABLE mysqltest.dummytable (dummyfield INT); +CREATE VIEW mysqltest.dummyview AS SELECT dummyfield FROM mysqltest.dummytable; +GRANT CREATE VIEW ON mysqltest.dummytable TO dummy@localhost; +GRANT CREATE VIEW ON mysqltest.dummyview TO dummy@localhost; +SHOW GRANTS FOR dummy@localhost; +use INFORMATION_SCHEMA; +SELECT TABLE_SCHEMA, TABLE_NAME, GROUP_CONCAT(PRIVILEGE_TYPE ORDER BY +PRIVILEGE_TYPE SEPARATOR ', ') AS PRIVILEGES FROM TABLE_PRIVILEGES WHERE GRANTEE += '\'dummy\'@\'localhost\'' GROUP BY TABLE_SCHEMA, TABLE_NAME; +FLUSH PRIVILEGES; +SHOW GRANTS FOR dummy@localhost; +SELECT TABLE_SCHEMA, TABLE_NAME, GROUP_CONCAT(PRIVILEGE_TYPE ORDER BY +PRIVILEGE_TYPE SEPARATOR ', ') AS PRIVILEGES FROM TABLE_PRIVILEGES WHERE GRANTEE += '\'dummy\'@\'localhost\'' GROUP BY TABLE_SCHEMA, TABLE_NAME; +use test; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM dummy@localhost; +DROP USER dummy@localhost; +DROP DATABASE mysqltest; +CREATE USER dummy@localhost; +CREATE DATABASE mysqltest; +CREATE TABLE mysqltest.dummytable (dummyfield INT); +CREATE VIEW mysqltest.dummyview AS SELECT dummyfield FROM mysqltest.dummytable; +GRANT SHOW VIEW ON mysqltest.dummytable TO dummy@localhost; +GRANT SHOW VIEW ON mysqltest.dummyview TO dummy@localhost; +SHOW GRANTS FOR dummy@localhost; +use INFORMATION_SCHEMA; +SELECT TABLE_SCHEMA, TABLE_NAME, GROUP_CONCAT(PRIVILEGE_TYPE ORDER BY +PRIVILEGE_TYPE SEPARATOR ', ') AS PRIVILEGES FROM TABLE_PRIVILEGES WHERE GRANTEE += '\'dummy\'@\'localhost\'' GROUP BY TABLE_SCHEMA, TABLE_NAME; +FLUSH PRIVILEGES; +SHOW GRANTS FOR dummy@localhost; +SELECT TABLE_SCHEMA, TABLE_NAME, GROUP_CONCAT(PRIVILEGE_TYPE ORDER BY +PRIVILEGE_TYPE SEPARATOR ', ') AS PRIVILEGES FROM TABLE_PRIVILEGES WHERE GRANTEE += '\'dummy\'@\'localhost\'' GROUP BY TABLE_SCHEMA, TABLE_NAME; +use test; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM dummy@localhost; +DROP USER dummy@localhost; +DROP DATABASE mysqltest; +# # Bug #11330: Entry in tables_priv with host = '' causes crash # connection default; @@ -403,6 +492,7 @@ insert into tables_priv values ('','test_db','mysqltest_1','test_table','test_gr flush privileges; delete from tables_priv where host = '' and user = 'mysqltest_1'; flush privileges; +use test; # # Bug #10892 user variables not auto cast for comparisons @@ -427,8 +517,7 @@ set names latin1; # Bug #15598 Server crashes in specific case during setting new password # - Caused by a user with host '' # -insert into mysql.user (host, user) values ('', 'mysqltest_7'); -flush privileges; +create user mysqltest_7@; set password for mysqltest_7@ = password('systpass'); show grants for mysqltest_7@; drop user mysqltest_7@; @@ -452,3 +541,326 @@ flush privileges; drop database mysqltest; # End of 4.1 tests + +# +# Bug #16297 In memory grant tables not flushed when users's hostname is "" +# +use test; +create table t1 (a int); + +# Backup anonymous users and remove them. (They get in the way of +# the one we test with here otherwise.) +create table t2 as select * from mysql.user where user=''; +delete from mysql.user where user=''; +flush privileges; + +# Create some users with different hostnames +create user mysqltest_8@''; +create user mysqltest_8; +create user mysqltest_8@host8; + +# Try to create them again +--error 1396 +create user mysqltest_8@''; +--error 1396 +create user mysqltest_8; +--error 1396 +create user mysqltest_8@host8; + +select user, QUOTE(host) from mysql.user where user="mysqltest_8"; + +--echo Schema privileges +grant select on mysqltest.* to mysqltest_8@''; +show grants for mysqltest_8@''; +grant select on mysqltest.* to mysqltest_8@; +show grants for mysqltest_8@; +grant select on mysqltest.* to mysqltest_8; +show grants for mysqltest_8; +select * from information_schema.schema_privileges +where grantee like "'mysqltest_8'%"; +connect (conn3,localhost,mysqltest_8,,); +select * from t1; +disconnect conn3; +connection master; +revoke select on mysqltest.* from mysqltest_8@''; +revoke select on mysqltest.* from mysqltest_8; +show grants for mysqltest_8@''; +show grants for mysqltest_8; +select * from information_schema.schema_privileges +where grantee like "'mysqltest_8'%"; +flush privileges; +show grants for mysqltest_8@''; +show grants for mysqltest_8@; +grant select on mysqltest.* to mysqltest_8@''; +flush privileges; +show grants for mysqltest_8@; +revoke select on mysqltest.* from mysqltest_8@''; +flush privileges; + +--echo Column privileges +grant update (a) on t1 to mysqltest_8@''; +grant update (a) on t1 to mysqltest_8; +show grants for mysqltest_8@''; +show grants for mysqltest_8; +flush privileges; +show grants for mysqltest_8@''; +show grants for mysqltest_8; +select * from information_schema.column_privileges; +connect (conn4,localhost,mysqltest_8,,); +select * from t1; +disconnect conn4; +connection master; +revoke update (a) on t1 from mysqltest_8@''; +revoke update (a) on t1 from mysqltest_8; +show grants for mysqltest_8@''; +show grants for mysqltest_8; +select * from information_schema.column_privileges; +flush privileges; +show grants for mysqltest_8@''; +show grants for mysqltest_8; + +--echo Table privileges +grant update on t1 to mysqltest_8@''; +grant update on t1 to mysqltest_8; +show grants for mysqltest_8@''; +show grants for mysqltest_8; +flush privileges; +show grants for mysqltest_8@''; +show grants for mysqltest_8; +select * from information_schema.table_privileges; +connect (conn5,localhost,mysqltest_8,,); +select * from t1; +disconnect conn5; +connection master; +revoke update on t1 from mysqltest_8@''; +revoke update on t1 from mysqltest_8; +show grants for mysqltest_8@''; +show grants for mysqltest_8; +select * from information_schema.table_privileges; +flush privileges; +show grants for mysqltest_8@''; +show grants for mysqltest_8; + +--echo "DROP USER" should clear privileges +grant all privileges on mysqltest.* to mysqltest_8@''; +grant select on mysqltest.* to mysqltest_8@''; +grant update on t1 to mysqltest_8@''; +grant update (a) on t1 to mysqltest_8@''; +grant all privileges on mysqltest.* to mysqltest_8; +show grants for mysqltest_8@''; +show grants for mysqltest_8; +select * from information_schema.user_privileges +where grantee like "'mysqltest_8'%"; +connect (conn5,localhost,mysqltest_8,,); +select * from t1; +disconnect conn5; +connection master; +flush privileges; +show grants for mysqltest_8@''; +show grants for mysqltest_8; +drop user mysqltest_8@''; +--error 1141 +show grants for mysqltest_8@''; +show grants for mysqltest_8; +select * from information_schema.user_privileges +where grantee like "'mysqltest_8'%"; +drop user mysqltest_8; +--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT +--error 1045 +connect (conn6,localhost,mysqltest_8,,); +connection master; +--error 1141 +show grants for mysqltest_8; +drop user mysqltest_8@host8; +--error 1141 +show grants for mysqltest_8@host8; + +# Restore the anonymous users. +insert into mysql.user select * from t2; +flush privileges; +drop table t2; + +drop table t1; + +# +# Bug#20214: Incorrect error when user calls SHOW CREATE VIEW on non +# privileged view +# + +connection master; + +CREATE DATABASE mysqltest3; +use mysqltest3; + +CREATE TABLE t_nn (c1 INT); +CREATE VIEW v_nn AS SELECT * FROM t_nn; + +CREATE DATABASE mysqltest2; +use mysqltest2; + +CREATE TABLE t_nn (c1 INT); +CREATE VIEW v_nn AS SELECT * FROM t_nn; +CREATE VIEW v_yn AS SELECT * FROM t_nn; +CREATE VIEW v_gy AS SELECT * FROM t_nn; +CREATE VIEW v_ny AS SELECT * FROM t_nn; +CREATE VIEW v_yy AS SELECT * FROM t_nn WHERE c1=55; + +GRANT SHOW VIEW ON mysqltest2.v_ny TO 'mysqltest_1'@'localhost' IDENTIFIED BY 'mysqltest_1'; +GRANT SELECT ON mysqltest2.v_yn TO 'mysqltest_1'@'localhost' IDENTIFIED BY 'mysqltest_1'; +GRANT SELECT ON mysqltest2.* TO 'mysqltest_1'@'localhost' IDENTIFIED BY 'mysqltest_1'; +GRANT SHOW VIEW,SELECT ON mysqltest2.v_yy TO 'mysqltest_1'@'localhost' IDENTIFIED BY 'mysqltest_1'; + +connect (mysqltest_1, localhost, mysqltest_1, mysqltest_1,); + +# fail because of missing SHOW VIEW (have generic SELECT) +--error ER_TABLEACCESS_DENIED_ERROR +SHOW CREATE VIEW mysqltest2.v_nn; +--error ER_TABLEACCESS_DENIED_ERROR +SHOW CREATE TABLE mysqltest2.v_nn; + + + +# fail because of missing SHOW VIEW +--error ER_TABLEACCESS_DENIED_ERROR +SHOW CREATE VIEW mysqltest2.v_yn; +--error ER_TABLEACCESS_DENIED_ERROR +SHOW CREATE TABLE mysqltest2.v_yn; + + + +# succeed (despite of missing SELECT, having SHOW VIEW bails us out) +SHOW CREATE TABLE mysqltest2.v_ny; + +# succeed (despite of missing SELECT, having SHOW VIEW bails us out) +SHOW CREATE VIEW mysqltest2.v_ny; + + + +# fail because of missing (specific or generic) SELECT +--error ER_TABLEACCESS_DENIED_ERROR +SHOW CREATE TABLE mysqltest3.t_nn; + +# fail because of missing (specific or generic) SELECT (not because it's not a view!) +--error ER_TABLEACCESS_DENIED_ERROR +SHOW CREATE VIEW mysqltest3.t_nn; + + + +# fail because of missing missing (specific or generic) SELECT (and SHOW VIEW) +--error ER_TABLEACCESS_DENIED_ERROR +SHOW CREATE VIEW mysqltest3.v_nn; +--error ER_TABLEACCESS_DENIED_ERROR +SHOW CREATE TABLE mysqltest3.v_nn; + + + +# succeed thanks to generic SELECT +SHOW CREATE TABLE mysqltest2.t_nn; + +# fail because it's not a view! (have generic SELECT though) +--error ER_WRONG_OBJECT +SHOW CREATE VIEW mysqltest2.t_nn; + + + +# succeed, have SELECT and SHOW VIEW +SHOW CREATE VIEW mysqltest2.v_yy; + +# succeed, have SELECT and SHOW VIEW +SHOW CREATE TABLE mysqltest2.v_yy; + + + +#clean-up +connection master; + +# succeed, we're root +SHOW CREATE TABLE mysqltest2.v_nn; +SHOW CREATE VIEW mysqltest2.v_nn; + +SHOW CREATE TABLE mysqltest2.t_nn; + +# fail because it's not a view! +--error ER_WRONG_OBJECT +SHOW CREATE VIEW mysqltest2.t_nn; + + + +DROP VIEW mysqltest2.v_nn; +DROP VIEW mysqltest2.v_yn; +DROP VIEW mysqltest2.v_ny; +DROP VIEW mysqltest2.v_yy; + +DROP TABLE mysqltest2.t_nn; + +DROP DATABASE mysqltest2; + + + +DROP VIEW mysqltest3.v_nn; +DROP TABLE mysqltest3.t_nn; + +DROP DATABASE mysqltest3; + +REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'mysqltest_1'@'localhost'; +DROP USER 'mysqltest_1'@'localhost'; + +# restore the original database +use test; + +# +# Bug #10668: CREATE USER does not enforce username length limit +# +--error ER_WRONG_STRING_LENGTH +create user mysqltest1_thisisreallytoolong; + +# +# Test for BUG#16899: Possible buffer overflow in handling of DEFINER-clause. +# +# These checks are intended to ensure that appropriate errors are risen when +# illegal user name or hostname is specified in user-clause of GRANT/REVOKE +# statements. +# + +# Working with database-level privileges. + +--error ER_WRONG_STRING_LENGTH +GRANT CREATE ON mysqltest.* TO 1234567890abcdefGHIKL@localhost; + +--error ER_WRONG_STRING_LENGTH +GRANT CREATE ON mysqltest.* TO some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; + +--error ER_WRONG_STRING_LENGTH +REVOKE CREATE ON mysqltest.* FROM 1234567890abcdefGHIKL@localhost; + +--error ER_WRONG_STRING_LENGTH +REVOKE CREATE ON mysqltest.* FROM some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; + +# Working with table-level privileges. + +--error ER_WRONG_STRING_LENGTH +GRANT CREATE ON t1 TO 1234567890abcdefGHIKL@localhost; + +--error ER_WRONG_STRING_LENGTH +GRANT CREATE ON t1 TO some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; + +--error ER_WRONG_STRING_LENGTH +REVOKE CREATE ON t1 FROM 1234567890abcdefGHIKL@localhost; + +--error ER_WRONG_STRING_LENGTH +REVOKE CREATE ON t1 FROM some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; + +# Working with routine-level privileges. + +--error ER_WRONG_STRING_LENGTH +GRANT EXECUTE ON PROCEDURE p1 TO 1234567890abcdefGHIKL@localhost; + +--error ER_WRONG_STRING_LENGTH +GRANT EXECUTE ON PROCEDURE p1 TO some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; + +--error ER_WRONG_STRING_LENGTH +REVOKE EXECUTE ON PROCEDURE p1 FROM 1234567890abcdefGHIKL@localhost; + +--error ER_WRONG_STRING_LENGTH +REVOKE EXECUTE ON PROCEDURE t1 FROM some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; +--echo End of 5.0 tests diff --git a/mysql-test/t/grant2.test b/mysql-test/t/grant2.test index 9da95cd42da..66128e56515 100644 --- a/mysql-test/t/grant2.test +++ b/mysql-test/t/grant2.test @@ -21,17 +21,61 @@ delete from mysql.columns_priv where user like 'mysqltest\_%'; flush privileges; +grant all privileges on `my\_1`.* to mysqltest_1@localhost with grant option; +grant create user on *.* to mysqltest_1@localhost; +create user mysqltest_2@localhost; +connect (user_a,localhost,mysqltest_1,,); +connection user_a; +grant select on `my\_1`.* to mysqltest_2@localhost; +--error 1132 +grant select on `my\_1`.* to mysqltest_2@localhost identified by 'pass'; +disconnect user_a; +connection default; +grant update on mysql.* to mysqltest_1@localhost; +connect (user_b,localhost,mysqltest_1,,); +connection user_b; +grant select on `my\_1`.* to mysqltest_2@localhost identified by 'pass'; +grant select on `my\_1`.* to mysqltest_3@localhost; +disconnect user_b; +connection default; +grant insert on mysql.* to mysqltest_1@localhost; +connect (user_c,localhost,mysqltest_1,,); +connection user_c; +grant select on `my\_1`.* to mysqltest_3@localhost; +grant select on `my\_1`.* to mysqltest_4@localhost identified by 'pass'; +disconnect user_c; +connection default; +delete from mysql.user where user like 'mysqltest\_%'; +delete from mysql.db where user like 'mysqltest\_%'; +delete from mysql.tables_priv where user like 'mysqltest\_%'; +delete from mysql.columns_priv where user like 'mysqltest\_%'; +flush privileges; + # # wild_compare fun # grant all privileges on `my\_%`.* to mysqltest_1@localhost with grant option; +grant create user on *.* to mysqltest_1@localhost; connect (user1,localhost,mysqltest_1,,); connection user1; select current_user(); grant all privileges on `my\_1`.* to mysqltest_2@localhost with grant option; --error 1044 grant all privileges on `my_%`.* to mysqltest_3@localhost with grant option; + +# +# NO_AUTO_CREATE_USER mode +# +set @@sql_mode='NO_AUTO_CREATE_USER'; +select @@sql_mode; +# +# GRANT without IDENTIFIED BY does not create new users +# +--error 1133 +grant select on `my\_1`.* to mysqltest_4@localhost with grant option; +grant select on `my\_1`.* to mysqltest_4@localhost identified by 'mypass' +with grant option; disconnect user1; connection default; show grants for mysqltest_1@localhost; @@ -75,10 +119,10 @@ connect (mrbad, localhost, mysqltest_1,,mysqltest); connection mrbad; show grants for current_user(); insert into t1 values (1, 'I can''t change it!'); ---error 1044 +--error 1142 update t1 set data='I can change it!' where id = 1; # This should not be allowed since it too require UPDATE privilege. ---error 1044 +--error 1142 insert into t1 values (1, 'XXX') on duplicate key update data= 'I can change it!'; select * from t1; disconnect mrbad; @@ -88,7 +132,8 @@ drop table t1; delete from mysql.user where user like 'mysqltest\_%'; delete from mysql.db where user like 'mysqltest\_%'; flush privileges; - +# +# create table t1 (a int, b int); grant select (a) on t1 to mysqltest_1@localhost with grant option; connect (mrugly, localhost, mysqltest_1,,mysqltest); @@ -110,7 +155,202 @@ flush privileges; drop database mysqltest; use test; + +# +# Bug #15775: "drop user" command does not refresh acl_check_hosts +# + +# Create some test users +create user mysqltest_1@host1; +create user mysqltest_2@host2; +create user mysqltest_3@host3; +create user mysqltest_4@host4; +create user mysqltest_5@host5; +create user mysqltest_6@host6; +create user mysqltest_7@host7; +flush privileges; + +# Drop one user +drop user mysqltest_3@host3; + +# This connect failed before fix since the acl_check_hosts list was corrupted by the "drop user" +connect (con8,127.0.0.1,root,,test,$MASTER_MYPORT,); +disconnect con8; +connection default; + +# Clean up - Drop all of the remaining users at once +drop user mysqltest_1@host1, mysqltest_2@host2, mysqltest_4@host4, + mysqltest_5@host5, mysqltest_6@host6, mysqltest_7@host7; + +# Check that it's still possible to connect +connect (con9,127.0.0.1,root,,test,$MASTER_MYPORT,); +disconnect con9; +connection default; + +# +# Bug# 16180 - Setting SQL_LOG_OFF without SUPER privilege is silently ignored +# +create database mysqltest_1; +grant select, insert, update on `mysqltest\_1`.* to mysqltest_1@localhost; +connect (con10,localhost,mysqltest_1,,); +connection con10; +--error 1227 +set sql_log_off = 1; +--error 1227 +set sql_log_bin = 0; +disconnect con10; +connection default; +delete from mysql.user where user like 'mysqltest\_1'; +delete from mysql.db where user like 'mysqltest\_1'; +drop database mysqltest_1; +flush privileges; + +# End of 4.1 tests +# Create and drop user +# +set sql_mode='maxdb'; +--disable_warnings +drop table if exists t1, t2; +--enable_warnings +create table t1(c1 int); +create table t2(c1 int, c2 int); +# +# Three forms of CREATE USER +create user 'mysqltest_1'; +--error 1396 +create user 'mysqltest_1'; +create user 'mysqltest_2' identified by 'Mysqltest-2'; +create user 'mysqltest_3' identified by password 'fffffffffffffffffffffffffffffffffffffffff'; +grant select on *.* to 'mysqltest_2'; +grant insert on test.* to 'mysqltest_2'; +grant update on test.t1 to 'mysqltest_2'; +grant update (c2) on test.t2 to 'mysqltest_2'; +select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password; +select host,db,user from mysql.db where user like 'mysqltest_%' order by host,db,user; +select host,db,user,table_name from mysql.tables_priv where user like 'mysqltest_%' order by host,db,user,table_name; +select host,db,user,table_name,column_name from mysql.columns_priv where user like 'mysqltest_%' order by host,db,user,table_name,column_name; +show grants for 'mysqltest_1'; +show grants for 'mysqltest_2'; +# +# Drop +drop user 'mysqltest_1'; +select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password; +select host,db,user from mysql.db where user like 'mysqltest_%' order by host,db,user; +select host,db,user,table_name from mysql.tables_priv where user like 'mysqltest_%' order by host,db,user,table_name; +select host,db,user,table_name,column_name from mysql.columns_priv where user like 'mysqltest_%' order by host,db,user,table_name,column_name; +--error 1141 +show grants for 'mysqltest_1'; +# +# Rename +rename user 'mysqltest_2' to 'mysqltest_1'; +select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password; +select host,db,user from mysql.db where user like 'mysqltest_%' order by host,db,user; +select host,db,user,table_name from mysql.tables_priv where user like 'mysqltest_%' order by host,db,user,table_name; +select host,db,user,table_name,column_name from mysql.columns_priv where user like 'mysqltest_%' order by host,db,user,table_name,column_name; +show grants for 'mysqltest_1'; +drop user 'mysqltest_1', 'mysqltest_3'; +--error 1396 +drop user 'mysqltest_1'; +# +# Cleanup +drop table t1, t2; +# +# Add a stray record +insert into mysql.db set user='mysqltest_1', db='%', host='%'; +flush privileges; +--error 1141 +show grants for 'mysqltest_1'; +--error 1269 +revoke all privileges, grant option from 'mysqltest_1'; +drop user 'mysqltest_1'; +select host,db,user from mysql.db where user = 'mysqltest_1' order by host,db,user; +# +# Add a stray record +insert into mysql.tables_priv set host='%', db='test', user='mysqltest_1', table_name='t1'; +flush privileges; +--error 1141 +show grants for 'mysqltest_1'; +drop user 'mysqltest_1'; +select host,db,user,table_name from mysql.tables_priv where user = 'mysqltest_1' order by host,db,user,table_name; +# +# Add a stray record +insert into mysql.columns_priv set host='%', db='test', user='mysqltest_1', table_name='t1', column_name='c1'; +flush privileges; +--error 1141 +show grants for 'mysqltest_1'; +drop user 'mysqltest_1'; +select host,db,user,table_name,column_name from mysql.columns_priv where user = 'mysqltest_1' order by host,db,user,table_name,column_name; +# +# Handle multi user lists +create user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3'; +drop user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3'; +create user 'mysqltest_1', 'mysqltest_2' identified by 'Mysqltest-2', 'mysqltest_3' identified by password 'fffffffffffffffffffffffffffffffffffffffff'; +rename user 'mysqltest_1' to 'mysqltest_1a', 'mysqltest_2' TO 'mysqltest_2a', 'mysqltest_3' TO 'mysqltest_3a'; +--error 1396 +drop user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3'; +drop user 'mysqltest_1a', 'mysqltest_2a', 'mysqltest_3a'; +# +# Let one of multiple users fail +create user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3'; +--error 1396 +create user 'mysqltest_1a', 'mysqltest_2', 'mysqltest_3a'; +--error 1396 +rename user 'mysqltest_1a' to 'mysqltest_1b', 'mysqltest_2a' TO 'mysqltest_2b', 'mysqltest_3a' TO 'mysqltest_3b'; +drop user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3'; +--error 1396 +drop user 'mysqltest_1b', 'mysqltest_2b', 'mysqltest_3b'; +# +# Obsolete syntax has been dropped +create user 'mysqltest_2' identified by 'Mysqltest-2'; +--error 1064 +drop user 'mysqltest_2' identified by 'Mysqltest-2'; +drop user 'mysqltest_2'; +# +# Strange user names +create user '%@b'@'b'; +show grants for '%@b'@'b'; +grant select on mysql.* to '%@b'@'b'; +show grants for '%@b'@'b'; +rename user '%@b'@'b' to '%@a'@'a'; +--error 1141 +show grants for '%@b'@'b'; +show grants for '%@a'@'a'; +drop user '%@a'@'a'; +# +# CREATE USER privilege is enough +# +create user mysqltest_2@localhost; +grant create user on *.* to mysqltest_2@localhost; +connect (user3,localhost,mysqltest_2,,); +connection user3; +--error 1142 +select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password; +create user mysqltest_A@'%'; +rename user mysqltest_A@'%' to mysqltest_B@'%'; +drop user mysqltest_B@'%'; +disconnect user3; +connection default; +drop user mysqltest_2@localhost; +# +# INSERT/UPDATE/DELETE is ok too +create user mysqltest_3@localhost; +grant INSERT,DELETE,UPDATE on mysql.* to mysqltest_3@localhost; +connect (user4,localhost,mysqltest_3,,); +connection user4; +show grants; +--error 1142 +select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password; +insert into mysql.user set host='%', user='mysqltest_B'; +create user mysqltest_A@'%'; +rename user mysqltest_B@'%' to mysqltest_C@'%'; +drop user mysqltest_C@'%'; +drop user mysqltest_A@'%'; +disconnect user4; +connection default; +drop user mysqltest_3@localhost; +# # Bug #3309: Test IP addresses with netmask +set @@sql_mode=''; create database mysqltest_1; create table mysqltest_1.t1 (i int); insert into mysqltest_1.t1 values (1),(2),(3); @@ -206,54 +446,66 @@ drop user 'mysqltest_1'@'localhost'; disconnect con2root; disconnect con3root; +# End of 4.1 tests + # -# Bug #15775: "drop user" command does not refresh acl_check_hosts +# Bug#17279 user with no global privs and with create +# priv in db can create databases # -# Create some test users -insert into mysql.user (user, host) values - ('mysqltest_1', 'host1'), - ('mysqltest_2', 'host2'), - ('mysqltest_3', 'host3'), - ('mysqltest_4', 'host4'), - ('mysqltest_5', 'host5'), - ('mysqltest_6', 'host6'), - ('mysqltest_7', 'host7'); -flush privileges; - -# Drop one user -drop user mysqltest_3@host3; +create database TESTDB; +create table t2(a int); +create temporary table t1 as select * from mysql.user; +delete from mysql.user where host='localhost'; +INSERT INTO mysql.user VALUES +('%','mysqltest_1',password('password'),'N','N','N','N','N','N', +'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N', +'','','','',0,0,0,0); +INSERT INTO mysql.db VALUES +('%','TESTDB','mysqltest_1','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','N','Y','Y','Y',' +Y','N'); +FLUSH PRIVILEGES; -# This connect failed before fix since the acl_check_hosts list was corrupted by the "drop user" -connect (con8,127.0.0.1,root,,test,$MASTER_MYPORT,); -disconnect con8; -connection default; +connect (con1,localhost,mysqltest_1,password,TESTDB); -# Clean up - Drop all of the remaining users at once -drop user mysqltest_1@host1, mysqltest_2@host2, mysqltest_4@host4, - mysqltest_5@host5, mysqltest_6@host6, mysqltest_7@host7; +# The user mysqltest_1 should only be allowed access to +# database TESTDB, not TEStdb +# On system with "lowercase names" we get error "1007: Can't create db..." +--error 1044, 1007 +create database TEStdb; -# Check that it's still possible to connect -connect (con9,127.0.0.1,root,,test,$MASTER_MYPORT,); -disconnect con9; +# Clean-up connection default; +delete from mysql.user; +delete from mysql.db where host='%' and user='mysqltest_1' and db='TESTDB'; +insert into mysql.user select * from t1; +drop table t1, t2; +drop database TESTDB; +flush privileges; # -# Bug# 16180 - Setting SQL_LOG_OFF without SUPER privilege is silently ignored +# BUG#13310 incorrect user parsing by SP # -create database mysqltest_1; -grant select, insert, update on `mysqltest\_1`.* to mysqltest_1@localhost; -connect (con10,localhost,mysqltest_1,,); -connection con10; ---error 1227 -set sql_log_off = 1; ---error 1227 -set sql_log_bin = 0; -disconnect con10; -connection default; -delete from mysql.user where user like 'mysqltest\_1'; -delete from mysql.db where user like 'mysqltest\_1'; -drop database mysqltest_1; -flush privileges; -# End of 4.1 tests +grant all privileges on test.* to `a@`@localhost; +grant execute on * to `a@`@localhost; +connect (bug13310,localhost,'a@',,test); +connection bug13310; +create table t2 (s1 int); +insert into t2 values (1); +--disable_warnings +drop function if exists f2; +--enable_warnings +delimiter //; +create function f2 () returns int begin declare v int; select s1 from t2 +into v; return v; end// +delimiter ;// +select f2(); + +drop function f2; +drop table t2; +disconnect bug13310; + +connection default; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM `a@`@localhost; +drop user `a@`@localhost; diff --git a/mysql-test/t/grant3-master.opt b/mysql-test/t/grant3-master.opt new file mode 100644 index 00000000000..4b11f5902c1 --- /dev/null +++ b/mysql-test/t/grant3-master.opt @@ -0,0 +1 @@ +--safe-user-create diff --git a/mysql-test/t/grant3.test b/mysql-test/t/grant3.test new file mode 100644 index 00000000000..115586e807d --- /dev/null +++ b/mysql-test/t/grant3.test @@ -0,0 +1,36 @@ +# Can't run with embedded server +-- source include/not_embedded.inc + +# Test of GRANT commands + +SET NAMES binary; +connect (master,localhost,root,,); +connection master; + +# Cleanup +--disable_warnings +drop table if exists t1; +--enable_warnings + +delete from mysql.user where user like 'mysqltest\_%'; +delete from mysql.db where user like 'mysqltest\_%'; +delete from mysql.tables_priv where user like 'mysqltest\_%'; +delete from mysql.columns_priv where user like 'mysqltest\_%'; +flush privileges; + +create user mysqltest_1@localhost; +grant create user on *.* to mysqltest_1@localhost; +grant select on `my\_1`.* to mysqltest_1@localhost with grant option; +connect (user_a,localhost,mysqltest_1,,); +connection user_a; +--error 1410 +grant select on `my\_1`.* to mysqltest_2@localhost; +create user mysqltest_2@localhost; +disconnect user_a; +connection default; + +delete from mysql.user where user like 'mysqltest\_%'; +delete from mysql.db where user like 'mysqltest\_%'; +delete from mysql.tables_priv where user like 'mysqltest\_%'; +delete from mysql.columns_priv where user like 'mysqltest\_%'; +flush privileges; diff --git a/mysql-test/t/grant_cache.test b/mysql-test/t/grant_cache.test index 703ad5d8004..7e17a03ec21 100644 --- a/mysql-test/t/grant_cache.test +++ b/mysql-test/t/grant_cache.test @@ -14,7 +14,7 @@ set GLOBAL query_cache_size=1355776; reset query cache; flush status; -connect (root,localhost,root,,test,$MASTER_MYPORT,master.sock); +connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); connection root; show grants for current_user; show grants; @@ -29,7 +29,7 @@ insert into mysqltest.t2 values (3,3,3); create table test.t1 (a char (10)); insert into test.t1 values ("test.t1"); select * from t1; -connect (root2,localhost,root,,mysqltest,$MASTER_MYPORT,master.sock); +connect (root2,localhost,root,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK); connection root2; # put queries in cache select * from t1; @@ -47,7 +47,7 @@ grant SELECT on test.t1 to mysqltest_2@localhost; grant SELECT(a) on mysqltest.t1 to mysqltest_3@localhost; # The following queries should be fetched from cache -connect (user1,localhost,mysqltest_1,,mysqltest,$MASTER_MYPORT,master.sock); +connect (user1,localhost,mysqltest_1,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK); connection user1; show grants for current_user(); show status like "Qcache_queries_in_cache"; @@ -72,12 +72,12 @@ show status like "Qcache_hits"; show status like "Qcache_not_cached"; # Don't use '' as user because it will pick Unix login -connect (unkuser,localhost,unkuser,,,$MASTER_MYPORT,master.sock); +connect (unkuser,localhost,unkuser,,,$MASTER_MYPORT,$MASTER_MYSOCK); connection unkuser; show grants for current_user(); # The following queries should be fetched from cache -connect (user2,localhost,mysqltest_2,,mysqltest,$MASTER_MYPORT,master.sock); +connect (user2,localhost,mysqltest_2,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK); connection user2; select "user2"; select * from t1; @@ -92,7 +92,7 @@ show status like "Qcache_hits"; show status like "Qcache_not_cached"; # The following queries should not be fetched from cache -connect (user3,localhost,mysqltest_3,,mysqltest,$MASTER_MYPORT,master.sock); +connect (user3,localhost,mysqltest_3,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK); connection user3; select "user3"; --replace_result 127.0.0.1 localhost @@ -113,7 +113,7 @@ show status like "Qcache_hits"; show status like "Qcache_not_cached"; # Connect without a database -connect (user4,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,master.sock); +connect (user4,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,$MASTER_MYSOCK); connection user4; select "user4"; show grants; diff --git a/mysql-test/t/greedy_optimizer.test b/mysql-test/t/greedy_optimizer.test new file mode 100644 index 00000000000..e547d85b7f3 --- /dev/null +++ b/mysql-test/t/greedy_optimizer.test @@ -0,0 +1,313 @@ +# +# A simple test of the greedy query optimization algorithm and the switches that +# control the optimizationprocess. +# + +# +# Schema +# +--disable_warnings +drop table if exists t1,t2,t3,t4,t5,t6,t7; +--enable_warnings + +create table t1 ( + c11 integer,c12 integer,c13 integer,c14 integer,c15 integer,c16 integer, + primary key (c11) +); +create table t2 ( + c21 integer,c22 integer,c23 integer,c24 integer,c25 integer,c26 integer +); +create table t3 ( + c31 integer,c32 integer,c33 integer,c34 integer,c35 integer,c36 integer, + primary key (c31) +); +create table t4 ( + c41 integer,c42 integer,c43 integer,c44 integer,c45 integer,c46 integer +); +create table t5 ( + c51 integer,c52 integer,c53 integer,c54 integer,c55 integer,c56 integer, + primary key (c51) +); +create table t6 ( + c61 integer,c62 integer,c63 integer,c64 integer,c65 integer,c66 integer +); +create table t7 ( + c71 integer,c72 integer,c73 integer,c74 integer,c75 integer,c76 integer, + primary key (c71) +); + +# +# Data +# cardinality(Ti) = cardinality(T(i-1)) + 3 +# +insert into t1 values (1,2,3,4,5,6); +insert into t1 values (2,2,3,4,5,6); +insert into t1 values (3,2,3,4,5,6); + +insert into t2 values (1,2,3,4,5,6); +insert into t2 values (2,2,3,4,5,6); +insert into t2 values (3,2,3,4,5,6); +insert into t2 values (4,2,3,4,5,6); +insert into t2 values (5,2,3,4,5,6); +insert into t2 values (6,2,3,4,5,6); + +insert into t3 values (1,2,3,4,5,6); +insert into t3 values (2,2,3,4,5,6); +insert into t3 values (3,2,3,4,5,6); +insert into t3 values (4,2,3,4,5,6); +insert into t3 values (5,2,3,4,5,6); +insert into t3 values (6,2,3,4,5,6); +insert into t3 values (7,2,3,4,5,6); +insert into t3 values (8,2,3,4,5,6); +insert into t3 values (9,2,3,4,5,6); + +insert into t4 values (1,2,3,4,5,6); +insert into t4 values (2,2,3,4,5,6); +insert into t4 values (3,2,3,4,5,6); +insert into t4 values (4,2,3,4,5,6); +insert into t4 values (5,2,3,4,5,6); +insert into t4 values (6,2,3,4,5,6); +insert into t4 values (7,2,3,4,5,6); +insert into t4 values (8,2,3,4,5,6); +insert into t4 values (9,2,3,4,5,6); +insert into t4 values (10,2,3,4,5,6); +insert into t4 values (11,2,3,4,5,6); +insert into t4 values (12,2,3,4,5,6); + +insert into t5 values (1,2,3,4,5,6); +insert into t5 values (2,2,3,4,5,6); +insert into t5 values (3,2,3,4,5,6); +insert into t5 values (4,2,3,4,5,6); +insert into t5 values (5,2,3,4,5,6); +insert into t5 values (6,2,3,4,5,6); +insert into t5 values (7,2,3,4,5,6); +insert into t5 values (8,2,3,4,5,6); +insert into t5 values (9,2,3,4,5,6); +insert into t5 values (10,2,3,4,5,6); +insert into t5 values (11,2,3,4,5,6); +insert into t5 values (12,2,3,4,5,6); +insert into t5 values (13,2,3,4,5,6); +insert into t5 values (14,2,3,4,5,6); +insert into t5 values (15,2,3,4,5,6); + +insert into t6 values (1,2,3,4,5,6); +insert into t6 values (2,2,3,4,5,6); +insert into t6 values (3,2,3,4,5,6); +insert into t6 values (4,2,3,4,5,6); +insert into t6 values (5,2,3,4,5,6); +insert into t6 values (6,2,3,4,5,6); +insert into t6 values (7,2,3,4,5,6); +insert into t6 values (8,2,3,4,5,6); +insert into t6 values (9,2,3,4,5,6); +insert into t6 values (10,2,3,4,5,6); +insert into t6 values (11,2,3,4,5,6); +insert into t6 values (12,2,3,4,5,6); +insert into t6 values (13,2,3,4,5,6); +insert into t6 values (14,2,3,4,5,6); +insert into t6 values (15,2,3,4,5,6); +insert into t6 values (16,2,3,4,5,6); +insert into t6 values (17,2,3,4,5,6); +insert into t6 values (18,2,3,4,5,6); + +insert into t7 values (1,2,3,4,5,6); +insert into t7 values (2,2,3,4,5,6); +insert into t7 values (3,2,3,4,5,6); +insert into t7 values (4,2,3,4,5,6); +insert into t7 values (5,2,3,4,5,6); +insert into t7 values (6,2,3,4,5,6); +insert into t7 values (7,2,3,4,5,6); +insert into t7 values (8,2,3,4,5,6); +insert into t7 values (9,2,3,4,5,6); +insert into t7 values (10,2,3,4,5,6); +insert into t7 values (11,2,3,4,5,6); +insert into t7 values (12,2,3,4,5,6); +insert into t7 values (13,2,3,4,5,6); +insert into t7 values (14,2,3,4,5,6); +insert into t7 values (15,2,3,4,5,6); +insert into t7 values (16,2,3,4,5,6); +insert into t7 values (17,2,3,4,5,6); +insert into t7 values (18,2,3,4,5,6); +insert into t7 values (19,2,3,4,5,6); +insert into t7 values (20,2,3,4,5,6); +insert into t7 values (21,2,3,4,5,6); + +# +# The actual test begins here +# + +# Check the default values for the optimizer paramters + +select @@optimizer_search_depth; +select @@optimizer_prune_level; + +-- This value swithes back to the old implementation of 'find_best()' +-- set optimizer_search_depth=63; - old (independent of the optimizer_prune_level) +-- +-- These are the values for the parameters that control the greedy optimizer +-- (total 6 combinations - 3 for optimizer_search_depth, 2 for optimizer_prune_level): +-- +-- set optimizer_search_depth=0; - automatic +-- set optimizer_search_depth=1; - min +-- set optimizer_search_depth=62; - max (default) +-- +-- set optimizer_prune_level=0 - exhaustive; +-- set optimizer_prune_level=1 - heuristic; -- default + + +# +# Compile several queries with all combinations of the query +# optimizer parameters. Each test query has two variants, where +# in the second variant the tables in the FROM clause are in +# inverse order to the tables in the first variant. +# Due to pre-sorting of tables before compilation, there should +# be no difference in the plans for each two such query variants. +# + +# First, for reference compile the test queries with the 'old' optimization +# procedure 'find_best'. Notice that 'find_best' does not depend on the +# choice of heuristic. + +set optimizer_search_depth=63; +select @@optimizer_search_depth; + +-- 6-table join, chain +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, star +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, clique +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; + + +# Test the new optimization procedures + +set optimizer_prune_level=0; +select @@optimizer_prune_level; + +set optimizer_search_depth=0; +select @@optimizer_search_depth; + +-- 6-table join, chain +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, star +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, clique +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; + +set optimizer_search_depth=1; +select @@optimizer_search_depth; + +-- 6-table join, chain +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, star +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, clique +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; + +set optimizer_search_depth=62; +select @@optimizer_search_depth; + +-- 6-table join, chain +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, star +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, clique +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; + + +set optimizer_prune_level=1; +select @@optimizer_prune_level; + +set optimizer_search_depth=0; +select @@optimizer_search_depth; + +-- 6-table join, chain +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, star +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, clique +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; + +set optimizer_search_depth=1; +select @@optimizer_search_depth; + +-- 6-table join, chain +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, star +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, clique +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; + +set optimizer_search_depth=62; +select @@optimizer_search_depth; + +-- 6-table join, chain +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, star +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; +show status like 'Last_query_cost'; +-- 6-table join, clique +explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; +explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; +show status like 'Last_query_cost'; + +drop table t1,t2,t3,t4,t5,t6,t7; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 064d46aa0c0..3e926fba0c6 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -135,7 +135,7 @@ CREATE TABLE t1 ( bug_severity enum('blocker','critical','major','normal','minor','trivial','enhancement') DEFAULT 'blocker' NOT NULL, bug_status enum('','NEW','ASSIGNED','REOPENED','RESOLVED','VERIFIED','CLOSED') DEFAULT 'NEW' NOT NULL, creation_ts datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, - delta_ts timestamp(14), + delta_ts timestamp, short_desc mediumtext, long_desc mediumtext, op_sys enum('All','Windows 3.1','Windows 95','Windows 98','Windows NT','Windows 2000','Linux','other') DEFAULT 'All' NOT NULL, @@ -575,22 +575,12 @@ CREATE TABLE t1 (id varchar(20) NOT NULL); INSERT INTO t1 VALUES ('trans1'), ('trans2'); CREATE TABLE t2 (id varchar(20) NOT NULL, err_comment blob NOT NULL); INSERT INTO t2 VALUES ('trans1', 'a problem'); - -SELECT COUNT(DISTINCT(t1.id)), LEFT(err_comment, 256) AS err_comment - FROM t1 LEFT JOIN t2 ON t1.id=t2.id GROUP BY err_comment; +SELECT COUNT(DISTINCT(t1.id)), LEFT(err_comment, 256) AS comment + FROM t1 LEFT JOIN t2 ON t1.id=t2.id GROUP BY comment; DROP TABLE t1, t2; # -# Test for bug #11414: crash on Windows for a simple GROUP BY query -# - -CREATE TABLE t1 (n int); -INSERT INTO t1 VALUES (1); -SELECT n+1 AS n FROM t1 GROUP BY n; -DROP TABLE t1; - -# # Bug #12266 GROUP BY expression on DATE column produces result with # reduced length # @@ -601,6 +591,15 @@ select date(left(f1+0,8)) from t1 group by 1; drop table t1; # +# Test for bug #11414: crash on Windows for a simple GROUP BY query +# + +CREATE TABLE t1 (n int); +INSERT INTO t1 VALUES (1); +SELECT n+1 AS n FROM t1 GROUP BY n; +DROP TABLE t1; + +# # BUG#12695: Item_func_isnull::update_used_tables # did not update const_item_cache # @@ -633,4 +632,72 @@ SELECT a FROM t1 ORDER BY 'a' DESC; SELECT a FROM t1 ORDER BY "a" DESC; SELECT a FROM t1 ORDER BY `a` DESC; DROP TABLE t1; + # End of 4.1 tests + +# +# Bug#11211: Ambiguous column reference in GROUP BY. +# + +create table t1 (c1 char(3), c2 char(3)); +create table t2 (c3 char(3), c4 char(3)); +insert into t1 values ('aaa', 'bb1'), ('aaa', 'bb2'); +insert into t2 values ('aaa', 'bb1'), ('aaa', 'bb2'); + +# query with ambiguous column reference 'c2' +select t1.c1 as c2 from t1, t2 where t1.c2 = t2.c4 +group by c2; +show warnings; + +# this query has no ambiguity +select t1.c1 as c2 from t1, t2 where t1.c2 = t2.c4 +group by t1.c1; + +show warnings; +drop table t1, t2; + +# +# Bug #20466: a view is mixing data when there's a trigger on the table +# +CREATE TABLE t1 (a tinyint(3), b varchar(255), PRIMARY KEY (a)); + +INSERT INTO t1 VALUES (1,'-----'), (6,'Allemagne'), (17,'Autriche'), + (25,'Belgique'), (54,'Danemark'), (62,'Espagne'), (68,'France'); + +CREATE TABLE t2 (a tinyint(3), b tinyint(3), PRIMARY KEY (a), KEY b (b)); + +INSERT INTO t2 VALUES (1,1), (2,1), (6,6), (18,17), (15,25), (16,25), + (17,25), (10,54), (5,62),(3,68); + +CREATE VIEW v1 AS select t1.a, concat(t1.b,'') AS b, t1.b as real_b from t1; + +explain +SELECT straight_join sql_no_cache v1.a, v1.b, v1.real_b from t2, v1 +where t2.b=v1.a GROUP BY t2.b; +SELECT straight_join sql_no_cache v1.a, v1.b, v1.real_b from t2, v1 +where t2.b=v1.a GROUP BY t2.b; + +DROP VIEW v1; +DROP TABLE t1,t2; + +# +# Bug#22781: SQL_BIG_RESULT fails to influence sort plan +# +CREATE TABLE t1 (a INT PRIMARY KEY, b INT, key (b)); + +INSERT INTO t1 VALUES (1, 1); +INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20) FROM t1; +INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20) FROM t1; +INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20) FROM t1; +INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20) FROM t1; +INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20) FROM t1; +INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20) FROM t1; +INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20) FROM t1; + +SELECT MIN(b), MAX(b) from t1; + +EXPLAIN SELECT b, sum(1) FROM t1 GROUP BY b; +EXPLAIN SELECT SQL_BIG_RESULT b, sum(1) FROM t1 GROUP BY b; +SELECT b, sum(1) FROM t1 GROUP BY b; +SELECT SQL_BIG_RESULT b, sum(1) FROM t1 GROUP BY b; +DROP TABLE t1; diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test new file mode 100644 index 00000000000..08f0f54df60 --- /dev/null +++ b/mysql-test/t/group_min_max.test @@ -0,0 +1,812 @@ +# +# Test file for WL#1724 (Min/Max Optimization for Queries with Group By Clause). +# The queries in this file test query execution via QUICK_GROUP_MIN_MAX_SELECT. +# + +# +# TODO: +# Add queries with: +# - C != const +# - C IS NOT NULL +# - HAVING clause + +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1 ( + a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' ' +); + +insert into t1 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'), +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'); + +create index idx_t1_0 on t1 (a1); +create index idx_t1_1 on t1 (a1,a2,b,c); +create index idx_t1_2 on t1 (a1,a2,b); +analyze table t1; + +-- t2 is the same as t1, but with some NULLs in the MIN/MAX column, and one more +-- nullable attribute + +--disable_warnings +drop table if exists t2; +--enable_warnings + +create table t2 ( + a1 char(64), a2 char(64) not null, b char(16), c char(16), d char(16), dummy char(64) default ' ' +); +insert into t2 select * from t1; +-- add few rows with NULL's in the MIN/MAX column +insert into t2 (a1, a2, b, c, d) values +('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'), +('a','a','a',NULL,'xyz'), +('a','a','b',NULL,'xyz'), +('a','b','a',NULL,'xyz'), +('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'), +('d','b','b',NULL,'xyz'), +('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'), +('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'), +('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'), +('a','a','a',NULL,'xyz'), +('a','a','b',NULL,'xyz'), +('a','b','a',NULL,'xyz'), +('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'), +('d','b','b',NULL,'xyz'), +('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'), +('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'); + +create index idx_t2_0 on t2 (a1); +create index idx_t2_1 on t2 (a1,a2,b,c); +create index idx_t2_2 on t2 (a1,a2,b); +analyze table t2; + +-- Table t3 is the same as t1, but with smaller column lenghts. +-- This allows to test different branches of the cost computation procedure +-- when the number of keys per block are less than the number of keys in the +-- sub-groups formed by predicates over non-group attributes. + +--disable_warnings +drop table if exists t3; +--enable_warnings + +create table t3 ( + a1 char(1), a2 char(1), b char(1), c char(4) not null, d char(3), dummy char(1) default ' ' +); + +insert into t3 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'); +insert into t3 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'); +insert into t3 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'); +insert into t3 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'); + +create index idx_t3_0 on t3 (a1); +create index idx_t3_1 on t3 (a1,a2,b,c); +create index idx_t3_2 on t3 (a1,a2,b); +analyze table t3; + + +-- +-- Queries without a WHERE clause. These queries do not use ranges. +-- + +-- plans +explain select a1, min(a2) from t1 group by a1; +explain select a1, max(a2) from t1 group by a1; +explain select a1, min(a2), max(a2) from t1 group by a1; +explain select a1, a2, b, min(c), max(c) from t1 group by a1,a2,b; +explain select a1,a2,b,max(c),min(c) from t1 group by a1,a2,b; +--replace_column 7 # 9 # +explain select a1,a2,b,max(c),min(c) from t2 group by a1,a2,b; +-- Select fields in different order +explain select min(a2), a1, max(a2), min(a2), a1 from t1 group by a1; +explain select a1, b, min(c), a1, max(c), b, a2, max(c), max(c) from t1 group by a1, a2, b; +explain select min(a2) from t1 group by a1; +explain select a2, min(c), max(c) from t1 group by a1,a2,b; + +-- queries +select a1, min(a2) from t1 group by a1; +select a1, max(a2) from t1 group by a1; +select a1, min(a2), max(a2) from t1 group by a1; +select a1, a2, b, min(c), max(c) from t1 group by a1,a2,b; +select a1,a2,b,max(c),min(c) from t1 group by a1,a2,b; +select a1,a2,b,max(c),min(c) from t2 group by a1,a2,b; +-- Select fields in different order +select min(a2), a1, max(a2), min(a2), a1 from t1 group by a1; +select a1, b, min(c), a1, max(c), b, a2, max(c), max(c) from t1 group by a1, a2, b; +select min(a2) from t1 group by a1; +select a2, min(c), max(c) from t1 group by a1,a2,b; + +-- +-- Queries with a where clause +-- + +-- A) Preds only over the group 'A' attributes +-- plans +explain select a1,a2,b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where a1 >= 'b' group by a1,a2,b; +explain select a1,a2,b, max(c) from t1 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; +explain select a1, max(c) from t1 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where a1 >= 'c' or a2 < 'b' group by a1,a2,b; +explain select a1,a2,b, max(c) from t1 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; +explain select a1,a2,b, max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; +explain select a1,min(c),max(c) from t1 where a1 >= 'b' group by a1,a2,b; +explain select a1, max(c) from t1 where a1 in ('a','b','d') group by a1,a2,b; + +--replace_column 9 # +explain select a1,a2,b, max(c) from t2 where a1 < 'd' group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where a1 < 'd' group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where a1 >= 'b' group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b, max(c) from t2 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; +--replace_column 9 # +explain select a1, max(c) from t2 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where a1 >= 'c' or a2 < 'b' group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b, max(c) from t2 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b, max(c) from t2 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; +--replace_column 9 # +explain select a1,min(c),max(c) from t2 where a1 >= 'b' group by a1,a2,b; +--replace_column 9 # +explain select a1, max(c) from t2 where a1 in ('a','b','d') group by a1,a2,b; + +-- queries +select a1,a2,b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where a1 >= 'b' group by a1,a2,b; +select a1,a2,b, max(c) from t1 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; +select a1, max(c) from t1 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where a1 >= 'c' or a2 < 'b' group by a1,a2,b; +select a1,a2,b, max(c) from t1 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; +select a1,a2,b, max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; +select a1,min(c),max(c) from t1 where a1 >= 'b' group by a1,a2,b; +select a1, max(c) from t1 where a1 in ('a','b','d') group by a1,a2,b; + +select a1,a2,b, max(c) from t2 where a1 < 'd' group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where a1 < 'd' group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where a1 >= 'b' group by a1,a2,b; +select a1,a2,b, max(c) from t2 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; +select a1, max(c) from t2 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where a1 >= 'c' or a2 < 'b' group by a1,a2,b; +select a1,a2,b, max(c) from t2 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; +select a1,a2,b, max(c) from t2 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; +select a1,min(c),max(c) from t2 where a1 >= 'b' group by a1,a2,b; +select a1, max(c) from t2 where a1 in ('a','b','d') group by a1,a2,b; + +-- B) Equalities only over the non-group 'B' attributes +-- plans +explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; +explain select a1,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; +explain select a1,a2,b, max(c) from t1 where (b = 'b') group by a1,a2; +explain select a1,a2,b,min(c),max(c) from t1 where (b = 'b') group by a1,a2; +explain select a1,a2, max(c) from t1 where (b = 'b') group by a1,a2; + +explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') group by a1; +explain select a1,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') group by a1; +explain select a1,a2,b, max(c) from t2 where (b = 'b') group by a1,a2; +explain select a1,a2,b,min(c),max(c) from t2 where (b = 'b') group by a1,a2; +explain select a1,a2, max(c) from t2 where (b = 'b') group by a1,a2; + +-- these queries test case 2) in TRP_GROUP_MIN_MAX::update_cost() +explain select a1,a2,b,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b') group by a1; +explain select a1,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b') group by a1; + +-- queries +select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; +select a1,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; +select a1,a2,b, max(c) from t1 where (b = 'b') group by a1,a2; +select a1,a2,b,min(c),max(c) from t1 where (b = 'b') group by a1,a2; +select a1,a2, max(c) from t1 where (b = 'b') group by a1,a2; + +select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') group by a1; +select a1,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') group by a1; +select a1,a2,b, max(c) from t2 where (b = 'b') group by a1,a2; +select a1,a2,b,min(c),max(c) from t2 where (b = 'b') group by a1,a2; +select a1,a2, max(c) from t2 where (b = 'b') group by a1,a2; + +-- these queries test case 2) in TRP_GROUP_MIN_MAX::update_cost() +select a1,a2,b,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b') group by a1; +select a1,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b') group by a1; + + +-- IS NULL (makes sense for t2 only) +-- plans +explain select a1,a2,b,min(c) from t2 where (a2 = 'a') and b is NULL group by a1; +explain select a1,a2,b,max(c) from t2 where (a2 = 'a') and b is NULL group by a1; +explain select a1,a2,b,min(c) from t2 where b is NULL group by a1,a2; +explain select a1,a2,b,max(c) from t2 where b is NULL group by a1,a2; +explain select a1,a2,b,min(c),max(c) from t2 where b is NULL group by a1,a2; +explain select a1,a2,b,min(c),max(c) from t2 where b is NULL group by a1,a2; +-- queries +select a1,a2,b,min(c) from t2 where (a2 = 'a') and b is NULL group by a1; +select a1,a2,b,max(c) from t2 where (a2 = 'a') and b is NULL group by a1; +select a1,a2,b,min(c) from t2 where b is NULL group by a1,a2; +select a1,a2,b,max(c) from t2 where b is NULL group by a1,a2; +select a1,a2,b,min(c),max(c) from t2 where b is NULL group by a1,a2; +select a1,a2,b,min(c),max(c) from t2 where b is NULL group by a1,a2; + +-- C) Range predicates for the MIN/MAX attribute +-- plans +--replace_column 9 # +explain select a1,a2,b, max(c) from t1 where (c > 'b1') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') group by a1,a2,b; +explain select a1,a2,b, max(c) from t1 where (c > 'f123') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (c > 'f123') group by a1,a2,b; +explain select a1,a2,b, max(c) from t1 where (c < 'a0') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') group by a1,a2,b; +explain select a1,a2,b, max(c) from t1 where (c < 'k321') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (c < 'k321') group by a1,a2,b; +explain select a1,a2,b, max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b; +explain select a1,a2,b, max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b111') and (c <= 'g112') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (c < 'c5') or (c = 'g412') or (c = 'k421') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where ((c > 'b111') and (c <= 'g112')) or ((c > 'd000') and (c <= 'i110')) group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (c between 'b111' and 'g112') or (c between 'd000' and 'i110') group by a1,a2,b; + +--replace_column 9 # +explain select a1,a2,b, max(c) from t2 where (c > 'b1') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (c > 'b1') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b, max(c) from t2 where (c > 'f123') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (c > 'f123') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b, max(c) from t2 where (c < 'a0') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (c < 'a0') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b, max(c) from t2 where (c < 'k321') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (c < 'k321') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b, max(c) from t2 where (c < 'a0') or (c > 'b1') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (c < 'a0') or (c > 'b1') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b, max(c) from t2 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (c > 'b111') and (c <= 'g112') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (c < 'c5') or (c = 'g412') or (c = 'k421') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where ((c > 'b111') and (c <= 'g112')) or ((c > 'd000') and (c <= 'i110')) group by a1,a2,b; + +-- queries +select a1,a2,b, max(c) from t1 where (c > 'b1') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') group by a1,a2,b; +select a1,a2,b, max(c) from t1 where (c > 'f123') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (c > 'f123') group by a1,a2,b; +select a1,a2,b, max(c) from t1 where (c < 'a0') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') group by a1,a2,b; +select a1,a2,b, max(c) from t1 where (c < 'k321') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (c < 'k321') group by a1,a2,b; +select a1,a2,b, max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b; +select a1,a2,b, max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (c > 'b111') and (c <= 'g112') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (c < 'c5') or (c = 'g412') or (c = 'k421') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where ((c > 'b111') and (c <= 'g112')) or ((c > 'd000') and (c <= 'i110')) group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (c between 'b111' and 'g112') or (c between 'd000' and 'i110') group by a1,a2,b; + +select a1,a2,b, max(c) from t2 where (c > 'b1') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where (c > 'b1') group by a1,a2,b; +select a1,a2,b, max(c) from t2 where (c > 'f123') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where (c > 'f123') group by a1,a2,b; +select a1,a2,b, max(c) from t2 where (c < 'a0') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where (c < 'a0') group by a1,a2,b; +select a1,a2,b, max(c) from t2 where (c < 'k321') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where (c < 'k321') group by a1,a2,b; +select a1,a2,b, max(c) from t2 where (c < 'a0') or (c > 'b1') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where (c < 'a0') or (c > 'b1') group by a1,a2,b; +select a1,a2,b, max(c) from t2 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where (c > 'b111') and (c <= 'g112') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where (c < 'c5') or (c = 'g412') or (c = 'k421') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where ((c > 'b111') and (c <= 'g112')) or ((c > 'd000') and (c <= 'i110')) group by a1,a2,b; + +-- analyze the sub-select +explain select a1,a2,b,min(c),max(c) from t1 +where exists ( select * from t2 where t2.c = t1.c ) +group by a1,a2,b; + +-- the sub-select is unrelated to MIN/MAX +explain select a1,a2,b,min(c),max(c) from t1 +where exists ( select * from t2 where t2.c > 'b1' ) +group by a1,a2,b; + + +-- A,B,C) Predicates referencing mixed classes of attributes +-- plans +explain select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (c > 'b111') group by a1,a2,b; +explain select a1,a2,b,min(c),max(c) from t1 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b; +explain select a1,a2,b,min(c) from t1 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c < 'h112') or (c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122')) group by a1,a2,b; +explain select a1,a2,b,min(c) from t1 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122') or (c < 'h112') or (c = 'c111')) group by a1,a2,b; +explain select a1,a2,b,min(c) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; +explain select a1,a2,b,min(c) from t1 where (ord(a1) > 97) and (ord(a2) + ord(a1) > 194) and (b = 'c') group by a1,a2,b; + +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (a1 >= 'c' or a2 < 'b') and (c > 'b111') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c),max(c) from t2 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c) from t2 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c < 'h112') or (c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122')) group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c) from t2 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122') or (c < 'h112') or (c = 'c111')) group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,min(c) from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; + +-- queries +select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (c > 'b111') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t1 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b; +select a1,a2,b,min(c) from t1 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c < 'h112') or (c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122')) group by a1,a2,b; +select a1,a2,b,min(c) from t1 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122') or (c < 'h112') or (c = 'c111')) group by a1,a2,b; +select a1,a2,b,min(c) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; +select a1,a2,b,min(c) from t1 where (ord(a1) > 97) and (ord(a2) + ord(a1) > 194) and (b = 'c') group by a1,a2,b; + +select a1,a2,b,min(c),max(c) from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where (a1 >= 'c' or a2 < 'b') and (c > 'b111') group by a1,a2,b; +select a1,a2,b,min(c),max(c) from t2 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b; +select a1,a2,b,min(c) from t2 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c < 'h112') or (c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122')) group by a1,a2,b; +select a1,a2,b,min(c) from t2 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122') or (c < 'h112') or (c = 'c111')) group by a1,a2,b; +select a1,a2,b,min(c) from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; + + +-- +-- GROUP BY queries without MIN/MAX +-- + +-- plans +explain select a1,a2,b from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; +explain select a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; +explain select a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; +explain select a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; + +--replace_column 9 # +explain select a1,a2,b from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; +--replace_column 9 # +explain select a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; + +-- queries +select a1,a2,b from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; +select a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; +select a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; +select a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; + +select a1,a2,b from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; +select a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; +select a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; +select a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; + +-- +-- DISTINCT queries +-- + +-- plans +explain select distinct a1,a2,b from t1; +explain select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a'); +explain select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); +explain select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); +explain select distinct b from t1 where (a2 >= 'b') and (b = 'a'); + +--replace_column 9 # +explain select distinct a1,a2,b from t2; +--replace_column 9 # +explain select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a'); +explain select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); +--replace_column 9 # +explain select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); +explain select distinct b from t2 where (a2 >= 'b') and (b = 'a'); + +-- queries +select distinct a1,a2,b from t1; +select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a'); +select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); +select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); +select distinct b from t1 where (a2 >= 'b') and (b = 'a'); + +select distinct a1,a2,b from t2; +select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a'); +select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); +select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); +select distinct b from t2 where (a2 >= 'b') and (b = 'a'); + +-- BUG #6303 +select distinct t_00.a1 +from t1 t_00 +where exists ( select * from t2 where a1 = t_00.a1 ); + +-- BUG #8532 - SELECT DISTINCT a, a causes server to crash +select distinct a1,a1 from t1; +select distinct a2,a1,a2,a1 from t1; +select distinct t1.a1,t2.a1 from t1,t2; + + +-- +-- DISTINCT queries with GROUP-BY +-- + +-- plans +explain select distinct a1,a2,b from t1; +explain select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; +explain select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; +explain select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; +explain select distinct b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; + +--replace_column 9 # +explain select distinct a1,a2,b from t2; +--replace_column 9 # +explain select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; +--replace_column 9 # +explain select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; +--replace_column 9 # +explain select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; +--replace_column 9 # +explain select distinct b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; + +-- queries +select distinct a1,a2,b from t1; +select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; +select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; +select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; +select distinct b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; + +select distinct a1,a2,b from t2; +select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; +select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; +select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; +select distinct b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; + + +-- +-- COUNT (DISTINCT cols) queries +-- + +explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); +explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); +explain select count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); +explain select count(distinct b) from t1 where (a2 >= 'b') and (b = 'a'); +explain select ord(a1) + count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a'); + +select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); +select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); +select count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); +select count(distinct b) from t1 where (a2 >= 'b') and (b = 'a'); +select ord(a1) + count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a'); + +-- +-- Queries with expressions in the select clause +-- + +explain select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b; +explain select concat(a1,min(c)),b from t1 where a1 < 'd' group by a1,a2,b; +explain select concat(a1,min(c)),b,max(c) from t1 where a1 < 'd' group by a1,a2,b; +explain select concat(a1,a2),b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b; +explain select concat(ord(min(b)),ord(max(b))),min(b),max(b) from t1 group by a1,a2; + +select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b; +select concat(a1,min(c)),b from t1 where a1 < 'd' group by a1,a2,b; +select concat(a1,min(c)),b,max(c) from t1 where a1 < 'd' group by a1,a2,b; +select concat(a1,a2),b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b; +select concat(ord(min(b)),ord(max(b))),min(b),max(b) from t1 group by a1,a2; + + +-- +-- Negative examples: queries that should NOT be treated as optimizable by +-- QUICK_GROUP_MIN_MAX_SELECT +-- + +-- select a non-indexed attribute +explain select a1,a2,b,d,min(c),max(c) from t1 group by a1,a2,b; + +explain select a1,a2,b,d from t1 group by a1,a2,b; + +-- predicate that references an attribute that is after the MIN/MAX argument +-- in the index +explain select a1,a2,min(b),max(b) from t1 +where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2; + +-- predicate that references a non-indexed attribute +explain select a1,a2,b,min(c),max(c) from t1 +where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b; + +explain select a1,a2,b,c from t1 +where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b,c; + +-- non-equality predicate for a non-group select attribute +explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') or (b < 'b') group by a1; +explain select a1,a2,b from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2,b; + +-- non-group field with an equality predicate that references a keypart after the +-- MIN/MAX argument +explain select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1; +select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1; + +-- disjunction for a non-group select attribute +explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') or (b = 'a') group by a1; + +-- non-range predicate for the MIN/MAX attribute +explain select a1,a2,b,min(c),max(c) from t2 +where (c > 'a000') and (c <= 'd999') and (c like '_8__') group by a1,a2,b; + +-- not all attributes are indexed by one index +explain select a1, a2, b, c, min(d), max(d) from t1 group by a1,a2,b,c; + +-- other aggregate functions than MIN/MAX +explain select a1,a2,count(a2) from t1 group by a1,a2,b; +explain select a1,a2,count(a2) from t1 where (a1 > 'a') group by a1,a2,b; +explain select sum(ord(a1)) from t1 where (a1 > 'a') group by a1,a2,b; + + +# +# Bug #16710: select distinct doesn't return all it should +# + +explain select distinct(a1) from t1 where ord(a2) = 98; +select distinct(a1) from t1 where ord(a2) = 98; + +# +# BUG#11044: DISTINCT or GROUP BY queries with equality predicates instead of MIN/MAX. +# + +explain select a1 from t1 where a2 = 'b' group by a1; +select a1 from t1 where a2 = 'b' group by a1; + +explain select distinct a1 from t1 where a2 = 'b'; +select distinct a1 from t1 where a2 = 'b'; + +drop table t1,t2,t3; +# +# Bug #14920 Ordering aggregated result sets with composite primary keys +# corrupts resultset +# +create table t1 (c1 int not null,c2 int not null, primary key(c1,c2)); +insert into t1 (c1,c2) values +(10,1),(10,2),(10,3),(20,4),(20,5),(20,6),(30,7),(30,8),(30,9); +select distinct c1, c2 from t1 order by c2; +select c1,min(c2) as c2 from t1 group by c1 order by c2; +select c1,c2 from t1 group by c1,c2 order by c2; +drop table t1; + +# +# Bug #16203: Analysis for possible min/max optimization erroneously +# returns impossible range +# + +CREATE TABLE t1 (a varchar(5), b int(11), PRIMARY KEY (a,b)); +INSERT INTO t1 VALUES ('AA',1), ('AA',2), ('AA',3), ('BB',1), ('AA',4); +OPTIMIZE TABLE t1; + +SELECT a FROM t1 WHERE a='AA' GROUP BY a; +SELECT a FROM t1 WHERE a='BB' GROUP BY a; + +EXPLAIN SELECT a FROM t1 WHERE a='AA' GROUP BY a; +EXPLAIN SELECT a FROM t1 WHERE a='BB' GROUP BY a; + +SELECT DISTINCT a FROM t1 WHERE a='BB'; +SELECT DISTINCT a FROM t1 WHERE a LIKE 'B%'; +SELECT a FROM t1 WHERE a LIKE 'B%' GROUP BY a; + +DROP TABLE t1; + + +# +# Bug #15102: select distinct returns empty result, select count +# distinct > 0 (correct) +# + +CREATE TABLE t1 ( + a int(11) NOT NULL DEFAULT '0', + b varchar(16) COLLATE latin1_general_ci NOT NULL DEFAULT '', + PRIMARY KEY (a,b) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; + +delimiter |; + +CREATE PROCEDURE a(x INT) +BEGIN + DECLARE rnd INT; + DECLARE cnt INT; + + WHILE x > 0 DO + SET rnd= x % 100; + SET cnt = (SELECT COUNT(*) FROM t1 WHERE a = rnd); + INSERT INTO t1(a,b) VALUES (rnd, CAST(cnt AS CHAR)); + SET x= x - 1; + END WHILE; +END| + +DELIMITER ;| + +CALL a(1000); + +SELECT a FROM t1 WHERE a=0; +SELECT DISTINCT a FROM t1 WHERE a=0; +SELECT COUNT(DISTINCT a) FROM t1 WHERE a=0; + +DROP TABLE t1; +DROP PROCEDURE a; + +# +# Bug #18068: SELECT DISTINCT +# + +CREATE TABLE t1 (a varchar(64) NOT NULL default '', PRIMARY KEY(a)); + +INSERT INTO t1 (a) VALUES + (''), ('CENTRAL'), ('EASTERN'), ('GREATER LONDON'), + ('NORTH CENTRAL'), ('NORTH EAST'), ('NORTH WEST'), ('SCOTLAND'), + ('SOUTH EAST'), ('SOUTH WEST'), ('WESTERN'); + +EXPLAIN SELECT DISTINCT a,a FROM t1 ORDER BY a; +SELECT DISTINCT a,a FROM t1 ORDER BY a; + +DROP TABLE t1; + +# +# Bug #21007: NATURAL JOIN (any JOIN (2 x NATURAL JOIN)) crashes the server +# + +CREATE TABLE t1 (id1 INT, id2 INT); +CREATE TABLE t2 (id2 INT, id3 INT, id5 INT); +CREATE TABLE t3 (id3 INT, id4 INT); +CREATE TABLE t4 (id4 INT); +CREATE TABLE t5 (id5 INT, id6 INT); +CREATE TABLE t6 (id6 INT); + +INSERT INTO t1 VALUES(1,1); +INSERT INTO t2 VALUES(1,1,1); +INSERT INTO t3 VALUES(1,1); +INSERT INTO t4 VALUES(1); +INSERT INTO t5 VALUES(1,1); +INSERT INTO t6 VALUES(1); + +-- original bug query +SELECT * FROM +t1 + NATURAL JOIN +(t2 JOIN (t3 NATURAL JOIN t4, t5 NATURAL JOIN t6) + ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5)); + +-- inner join swapped +SELECT * FROM +t1 + NATURAL JOIN +(((t3 NATURAL JOIN t4) join (t5 NATURAL JOIN t6) on t3.id4 = t5.id5) JOIN t2 + ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5)); + +-- one join less, no ON cond +SELECT * FROM t1 NATURAL JOIN ((t3 join (t5 NATURAL JOIN t6)) JOIN t2); + +-- wrong error message: 'id2' - ambiguous column +SELECT * FROM +(t2 JOIN (t3 NATURAL JOIN t4, t5 NATURAL JOIN t6) + ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5)) + NATURAL JOIN +t1; +SELECT * FROM +(t2 JOIN ((t3 NATURAL JOIN t4) join (t5 NATURAL JOIN t6))) + NATURAL JOIN +t1; + +DROP TABLE t1,t2,t3,t4,t5,t6; + +# +# Bug#22342: No results returned for query using max and group by +# +CREATE TABLE t1 (a int, b int, PRIMARY KEY (a,b), KEY b (b)); +INSERT INTO t1 VALUES (1,1),(1,2),(1,0),(1,3); + +explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; +SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; +SELECT MIN(b), a FROM t1 WHERE b > 1 AND a = 1 GROUP BY a; +CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a,b,c)); +INSERT INTO t2 SELECT a,b,b FROM t1; +explain SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a; +SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a; + +DROP TABLE t1,t2; diff --git a/mysql-test/t/handler.test b/mysql-test/t/handler.test index 55936e44b32..bf18b8da941 100644 --- a/mysql-test/t/handler.test +++ b/mysql-test/t/handler.test @@ -3,8 +3,11 @@ # test of HANDLER ... # +# should work in embedded server after mysqltest is fixed +-- source include/not_embedded.inc + --disable_warnings -drop table if exists t1; +drop table if exists t1,t3,t4,t5; --enable_warnings create table t1 (a int, b char(10), key a(a), key b(a,b)); @@ -377,3 +380,50 @@ connection default; drop table t1; # End of 4.1 tests + +# +# Addendum to Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash +# Show that DROP TABLE can no longer deadlock against +# FLUSH TABLES WITH READ LOCK. This is a 5.0 issue. +# +create table t1 (c1 int); +insert into t1 values (14397); +flush tables with read lock; +# The thread with the global read lock cannot drop the table itself: +--error 1223 +drop table t1; +# +# client 2 +# We need a second connection to try the drop. +# The drop waits for the global read lock to go away. +# Without the addendum fix it locked LOCK_open before entering the wait loop. +connection con2; +--exec echo send the below to another connection, do not wait for the result +send drop table t1; +--sleep 1 +# +# client 1 +# Now we need something that wants LOCK_open. A simple table access which +# opens the table does the trick. +--exec echo proceed with the normal connection +connection default; +# This would hang on LOCK_open without the 5.0 addendum fix. +select * from t1; +# Release the read lock. This should make the DROP go through. +unlock tables; +# +# client 2 +# Read the result of the drop command. +connection con2; +--exec echo read the result from the other connection +reap; +# +# client 1 +# Now back to normal operation. The table should not exist any more. +--exec echo proceed with the normal connection +connection default; +--error 1146 +select * from t1; +# Just to be sure and not confuse the next test case writer. +drop table if exists t1; + diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test index 8b39e3bd454..9bea78a7bca 100644 --- a/mysql-test/t/having.test +++ b/mysql-test/t/having.test @@ -2,7 +2,7 @@ # --disable_warnings -drop table if exists t1,t2; +drop table if exists t1,t2,t3; --enable_warnings create table t1 (a int); @@ -152,3 +152,257 @@ EXPLAIN SELECT 0 AS x, a FROM t1 GROUP BY x,a HAVING x=1 AND a > 1; DROP table t1; # End of 4.1 tests + +# +# Tests for WL#1972 CORRECT EVALUATION OF COLUMN REFERENCES IN THE HAVING CLAUSE +# Per the SAP VERI tests and WL#1972, MySQL must ensure that HAVING can +# correctly evaluate column references from the GROUP BY clause, even if the +# same references are not also found in the select list. +# + +# set global sql_mode='ansi'; +# set session sql_mode='ansi'; + +create table t1 (col1 int, col2 varchar(5), col_t1 int); +create table t2 (col1 int, col2 varchar(5), col_t2 int); +create table t3 (col1 int, col2 varchar(5), col_t3 int); + +insert into t1 values(10,'hello',10); +insert into t1 values(20,'hello',20); +insert into t1 values(30,'hello',30); +insert into t1 values(10,'bye',10); +insert into t1 values(10,'sam',10); +insert into t1 values(10,'bob',10); + +insert into t2 select * from t1; +insert into t3 select * from t1; + +select count(*) from t1 group by col1 having col1 = 10; +select count(*) as count_col1 from t1 group by col1 having col1 = 10; +select count(*) as count_col1 from t1 as tmp1 group by col1 having col1 = 10; +select count(*) from t1 group by col2 having col2 = 'hello'; +--error 1054 +select count(*) from t1 group by col2 having col1 = 10; +select col1 as count_col1 from t1 as tmp1 group by col1 having col1 = 10; +select col1 as count_col1 from t1 as tmp1 group by col1 having count_col1 = 10; +select col1 as count_col1 from t1 as tmp1 group by count_col1 having col1 = 10; +# ANSI: should return SQLSTATE 42000 Syntax error or access violation +# MySQL: returns 10 - because of GROUP BY name resolution +select col1 as count_col1 from t1 as tmp1 group by count_col1 having count_col1 = 10; +# ANSI: should return SQLSTATE 42000 Syntax error or access violation +# MySQL: returns 10 - because of GROUP BY name resolution +select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having col1 = 10; +select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having count_col1 = 10; +select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having col2 = 'hello'; +select col1 as count_col1,col2 as group_col2 from t1 as tmp1 group by col1,col2 having group_col2 = 'hello'; +--error 1064 +select sum(col1) as co12 from t1 group by col2 having col2 10; +select sum(col1) as co2, count(col2) as cc from t1 group by col1 having col1 =10; +--error 1054 +select t2.col2 from t2 group by t2.col1, t2.col2 having t1.col1 <= 10; + + +# +# queries with nested sub-queries +# + +# the having column is resolved in the same query +select t1.col1 from t1 +where t1.col2 in + (select t2.col2 from t2 + group by t2.col1, t2.col2 having t2.col1 <= 10); + +select t1.col1 from t1 +where t1.col2 in + (select t2.col2 from t2 + group by t2.col1, t2.col2 + having t2.col1 <= + (select min(t3.col1) from t3)); + +# the having column is resolved in the SELECT clause of the outer query - +# works in ANSI +select t1.col1 from t1 +where t1.col2 in + (select t2.col2 from t2 + group by t2.col1, t2.col2 having t1.col1 <= 10); + +# the having column is resolved in the SELECT clause of the outer query - +# error in ANSI, works with MySQL extension +select t1.col1 as tmp_col from t1 +where t1.col2 in + (select t2.col2 from t2 + group by t2.col1, t2.col2 having tmp_col <= 10); + +# the having column is resolved in the FROM clause of the outer query - +# works in ANSI +select t1.col1 from t1 +where t1.col2 in + (select t2.col2 from t2 + group by t2.col1, t2.col2 having col_t1 <= 10); + +# Item_field must be resolved in the same way as Item_ref +select sum(col1) from t1 +group by col_t1 +having (select col_t1 from t2 where col_t1 = col_t2 order by col_t2 limit 1); + +# nested queries with HAVING, inner having column resolved in outer FROM clause +# the outer having column is not referenced in GROUP BY which results in an error +--error 1054 +select t1.col1 from t1 +where t1.col2 in + (select t2.col2 from t2 + group by t2.col1, t2.col2 having col_t1 <= 10) +having col_t1 <= 20; + +# both having columns are resolved in the GROUP clause of the outer query +select t1.col1 from t1 +where t1.col2 in + (select t2.col2 from t2 + group by t2.col1, t2.col2 having col_t1 <= 10) +group by col_t1 +having col_t1 <= 20; + +# +# nested HAVING clauses +# + +# non-correlated subqueries +select col_t1, sum(col1) from t1 +group by col_t1 +having col_t1 > 10 and + exists (select sum(t2.col1) from t2 + group by t2.col2 having t2.col2 > 'b'); + +# correlated subqueries - inner having column 't1.col2' resolves to +# the outer FROM clause, which cannot be used because the outer query +# is grouped +--error 1054 +select sum(col1) from t1 +group by col_t1 +having col_t1 in (select sum(t2.col1) from t2 + group by t2.col2, t2.col1 having t2.col1 = t1.col1); + +# correlated subqueries - inner having column 'col_t1' resolves to +# the outer GROUP clause +select sum(col1) from t1 +group by col_t1 +having col_t1 in (select sum(t2.col1) from t2 + group by t2.col2, t2.col1 having t2.col1 = col_t1); + +# +# queries with joins and ambiguous column names +# +--error 1052 +select t1.col1, t2.col1 from t1, t2 where t1.col1 = t2.col1 +group by t1.col1, t2.col1 having col1 = 2; + +--error 1052 +select t1.col1*10+t2.col1 from t1,t2 where t1.col1=t2.col1 +group by t1.col1, t2.col1 having col1 = 2; + +drop table t1, t2, t3; + +# More queries to test ANSI compatibility +create table t1 (s1 int); +insert into t1 values (1),(2),(3); + +select count(*) from t1 group by s1 having s1 is null; + +# prepared statements prints warnings too early +--disable_ps_protocol +select s1*0 as s1 from t1 group by s1 having s1 <> 0; +--enable_ps_protocol + +# ANSI requires: 3 rows +# MySQL returns: 0 rows - because of GROUP BY name resolution + +select s1*0 from t1 group by s1 having s1 = 0; + +select s1 from t1 group by 1 having 1 = 0; + +select count(s1) from t1 group by s1 having count(1+1)=2; +# ANSI requires: 3 rows +# MySQL returns: 0 rows - because of GROUP BY name resolution + +select count(s1) from t1 group by s1 having s1*0=0; + +-- error 1052 +select * from t1 a, t1 b group by a.s1 having s1 is null; +# ANSI requires: 0 rows +# MySQL returns: +# "ERROR 1052 (23000): Column 's1' in having clause is ambiguous" +# I think the column is ambiguous in ANSI too. +# It is the same as: +# select a.s1, b.s1 from t1 a, t1 b group by a.s1 having s1 is null; +# currently we first check SELECT, thus s1 is ambiguous. + +drop table t1; + +create table t1 (s1 char character set latin1 collate latin1_german1_ci); +insert into t1 values ('ü'),('y'); + +select s1,count(s1) from t1 +group by s1 collate latin1_swedish_ci having s1 = 'y'; +# ANSI requires: 1 row, with count(s1) = 2 +# MySQL returns: 1 row, with count(s1) = 1 + +drop table t1; + + +# +# Bug #15917: unexpected complain for a name in having clause +# when the server is run on Windows or with --lower-case-table-names=1 +# + +--disable_warnings +DROP SCHEMA IF EXISTS HU; +--enable_warnings +CREATE SCHEMA HU ; +USE HU ; + +CREATE TABLE STAFF + (EMPNUM CHAR(3) NOT NULL UNIQUE, + EMPNAME CHAR(20), + GRADE DECIMAL(4), + CITY CHAR(15)); + +CREATE TABLE PROJ + (PNUM CHAR(3) NOT NULL UNIQUE, + PNAME CHAR(20), + PTYPE CHAR(6), + BUDGET DECIMAL(9), + CITY CHAR(15)); + +INSERT INTO STAFF VALUES ('E1','Alice',12,'Deale'); +INSERT INTO STAFF VALUES ('E2','Betty',10,'Vienna'); +INSERT INTO STAFF VALUES ('E3','Carmen',13,'Vienna'); +INSERT INTO STAFF VALUES ('E4','Don',12,'Deale'); +INSERT INTO STAFF VALUES ('E5','Ed',13,'Akron'); + +INSERT INTO PROJ VALUES ('P1','MXSS','Design',10000,'Deale'); +INSERT INTO PROJ VALUES ('P2','CALM','Code',30000,'Vienna'); +INSERT INTO PROJ VALUES ('P3','SDP','Test',30000,'Tampa'); +INSERT INTO PROJ VALUES ('P4','SDP','Design',20000,'Deale'); +INSERT INTO PROJ VALUES ('P5','IRM','Test',10000,'Vienna'); +INSERT INTO PROJ VALUES ('P6','PAYR','Design',50000,'Deale'); + +SELECT EMPNUM, GRADE*1000 + FROM HU.STAFF WHERE GRADE * 1000 > + ANY (SELECT SUM(BUDGET) FROM HU.PROJ + GROUP BY CITY, PTYPE + HAVING HU.PROJ.CITY = HU.STAFF.CITY); + +DROP SCHEMA HU; +USE test; +# +# Bug#18739: non-standard HAVING extension was allowed in strict ANSI sql mode. +# +create table t1(f1 int); +select f1 from t1 having max(f1)=f1; +select f1 from t1 group by f1 having max(f1)=f1; +set session sql_mode='ONLY_FULL_GROUP_BY'; +--error 1463 +select f1 from t1 having max(f1)=f1; +select f1 from t1 group by f1 having max(f1)=f1; +set session sql_mode=''; +drop table t1; diff --git a/mysql-test/t/heap.test b/mysql-test/t/heap.test index 50147b4182d..e501fce1eeb 100644 --- a/mysql-test/t/heap.test +++ b/mysql-test/t/heap.test @@ -3,7 +3,7 @@ # --disable_warnings -drop table if exists t1; +drop table if exists t1,t2,t3; --enable_warnings create table t1 (a int not null,b int not null, primary key (a)) engine=heap comment="testing heaps" avg_row_length=100 min_rows=1 max_rows=100; @@ -34,7 +34,7 @@ select * from t1; drop table t1; create table t1 (a int not null) engine=heap; -insert into t1 values (869751),(736494),(226312),(802616); +insert into t1 values (869751),(736494),(226312),(802616),(728912); select * from t1 where a > 736494; alter table t1 add unique uniq_id(a); select * from t1 where a > 736494; @@ -197,34 +197,236 @@ select * from t1; drop table t1; # +# Test varchar +# We can't use varchar.inc becasue heap doesn't support blob's +# + +let $default=`select @@storage_engine`; +set storage_engine=HEAP; + +# +# Simple basic test that endspace is saved +# + +create table t1 (v varchar(10), c char(10), t varchar(50)); +insert into t1 values('+ ', '+ ', '+ '); +set @a=repeat(' ',20); +insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a)); +select concat('*',v,'*',c,'*',t,'*') from t1; + +# Check how columns are copied +show create table t1; +create table t2 like t1; +show create table t2; +create table t3 select * from t1; +show create table t3; +alter table t1 modify c varchar(10); +show create table t1; +alter table t1 modify v char(10); +show create table t1; +alter table t1 modify t varchar(10); +show create table t1; +select concat('*',v,'*',c,'*',t,'*') from t1; +drop table t1,t2,t3; + +# +# Testing of keys +# +create table t1 (v varchar(10), c char(10), t varchar(50), key(v), key(c), key(t(10))); +show create table t1; +disable_query_log; +let $1=10; +while ($1) +{ + let $2=27; + eval set @space=repeat(' ',10-$1); + while ($2) + { + eval set @char=char(ascii('a')+$2-1); + insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space)); + dec $2; + } + dec $1; +} +enable_query_log; +select count(*) from t1; +insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1))); +select count(*) from t1 where v='a'; +select count(*) from t1 where c='a'; +select count(*) from t1 where t='a'; +select count(*) from t1 where v='a '; +select count(*) from t1 where c='a '; +select count(*) from t1 where t='a '; +select count(*) from t1 where v between 'a' and 'a '; +select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; +select count(*) from t1 where v like 'a%'; +select count(*) from t1 where c like 'a%'; +select count(*) from t1 where t like 'a%'; +select count(*) from t1 where v like 'a %'; +explain select count(*) from t1 where v='a '; +explain select count(*) from t1 where c='a '; +explain select count(*) from t1 where t='a '; +explain select count(*) from t1 where v like 'a%'; +explain select count(*) from t1 where v between 'a' and 'a '; +explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; + +--error 1062 +alter table t1 add unique(v); +select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*')); +explain select * from t1 where v='a'; + +# GROUP BY + +select v,count(*) from t1 group by v limit 10; +select v,count(t) from t1 group by v limit 10; +select v,count(c) from t1 group by v limit 10; +select sql_big_result trim(v),count(t) from t1 group by v limit 10; +select sql_big_result trim(v),count(c) from t1 group by v limit 10; +select c,count(*) from t1 group by c limit 10; +select c,count(t) from t1 group by c limit 10; +select sql_big_result c,count(t) from t1 group by c limit 10; +select t,count(*) from t1 group by t limit 10; +select t,count(t) from t1 group by t limit 10; +select sql_big_result trim(t),count(t) from t1 group by t limit 10; +drop table t1; + +# +# Test unique keys +# + +create table t1 (a char(10), unique (a)); +insert into t1 values ('a'); +--error 1062 +insert into t1 values ('a '); + +alter table t1 modify a varchar(10); +--error 1062 +insert into t1 values ('a '),('a '),('a '),('a '); +--error 1062 +insert into t1 values ('a '); +--error 1062 +insert into t1 values ('a '); +--error 1062 +insert into t1 values ('a '); +update t1 set a='a ' where a like 'a '; +update t1 set a='a ' where a like 'a '; +drop table t1; + +# +# Testing of btree keys +# + +create table t1 (v varchar(10), c char(10), t varchar(50), key using btree (v), key using btree (c), key using btree (t(10))); +show create table t1; +disable_query_log; +let $1=10; +while ($1) +{ + let $2=27; + eval set @space=repeat(' ',10-$1); + while ($2) + { + eval set @char=char(ascii('a')+$2-1); + insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space)); + dec $2; + } + dec $1; +} +enable_query_log; +select count(*) from t1; +insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1))); +select count(*) from t1 where v='a'; +select count(*) from t1 where c='a'; +select count(*) from t1 where t='a'; +select count(*) from t1 where v='a '; +select count(*) from t1 where c='a '; +select count(*) from t1 where t='a '; +select count(*) from t1 where v between 'a' and 'a '; +--replace_column 9 # +select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; +--replace_column 9 # +explain select count(*) from t1 where v='a '; +--replace_column 9 # +explain select count(*) from t1 where c='a '; +--replace_column 9 # +explain select count(*) from t1 where t='a '; +--replace_column 9 # +explain select count(*) from t1 where v like 'a%'; +--replace_column 9 # +explain select count(*) from t1 where v between 'a' and 'a '; +--replace_column 9 # +explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; + +--error 1062 +alter table t1 add unique(v); +select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*')); +# Number of rows is not constant for b-trees keys +--replace_column 9 # +explain select * from t1 where v='a'; + +drop table t1; + +# +# Test unique btree keys +# + +create table t1 (a char(10), unique using btree (a)) engine=heap; +insert into t1 values ('a'); +--error 1062 +insert into t1 values ('a '); + +alter table t1 modify a varchar(10); +--error 1062 +insert into t1 values ('a '),('a '),('a '),('a '); +--error 1062 +insert into t1 values ('a '); +--error 1062 +insert into t1 values ('a '); +--error 1062 +insert into t1 values ('a '); +update t1 set a='a ' where a like 'a '; +update t1 set a='a ' where a like 'a '; +drop table t1; + +# +# test show create table +# + +create table t1 (v varchar(10), c char(10), t varchar(50), key(v(5)), key(c(5)), key(t(5))); +show create table t1; +drop table t1; + +create table t1 (v varchar(65530), key(v(10))); +show create table t1; +insert into t1 values(repeat('a',65530)); +select length(v) from t1 where v=repeat('a',65530); +drop table t1; + +# +# Reset varchar test +# +eval set storage_engine=$default; + +# # Bug #8489: Strange auto_increment behaviour # create table t1 (a bigint unsigned auto_increment primary key, b int, key (b, a)) engine=heap; -insert t1 (b) values (1); -insert t1 (b) values (1); -insert t1 (b) values (1); -insert t1 (b) values (1); -insert t1 (b) values (1); -insert t1 (b) values (1); -insert t1 (b) values (1); -insert t1 (b) values (1); -select * from t1; +insert t1 (b) values (1),(1),(1),(1),(1),(1),(1),(1); +select * from t1; drop table t1; + create table t1 (a int not null, b int not null auto_increment, primary key(a, b), key(b)) engine=heap; -insert t1 (a) values (1); -insert t1 (a) values (1); -insert t1 (a) values (1); -insert t1 (a) values (1); -insert t1 (a) values (1); -insert t1 (a) values (1); -insert t1 (a) values (1); -insert t1 (a) values (1); -select * from t1; +insert t1 (a) values (1),(1),(1),(1),(1),(1),(1),(1); +select * from t1; drop table t1; +--error 1075 +create table t1 (a int not null, b int not null auto_increment, + primary key(a, b)) engine=heap; + # # Bug #10566: Verify that we can create a prefixed key with length > 255 # @@ -246,3 +448,26 @@ select * from t1 where a = 0; drop table t1; # End of 4.1 tests + +# +# Bug #3094: Row format of memory tables should always be reported as Fixed +# +create table t1 (c char(10)) engine=memory; +create table t2 (c varchar(10)) engine=memory; +--replace_column 8 # +show table status like 't_'; +drop table t1, t2; + +# +# BUG#18233 - Memory tables INDEX USING HASH (a,b) returns 1 row on +# SELECT WHERE a= AND b= +# +CREATE TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256), + KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY; +INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256)); +SELECT COUNT(*) FROM t1 WHERE a='a'; +SELECT COUNT(*) FROM t1 WHERE b='aa'; +SELECT COUNT(*) FROM t1 WHERE c=REPEAT('a',256); +DROP TABLE t1; + +# End of 5.0 tests diff --git a/mysql-test/t/heap_btree.test b/mysql-test/t/heap_btree.test index 9aa820becd9..03ba8661a3c 100644 --- a/mysql-test/t/heap_btree.test +++ b/mysql-test/t/heap_btree.test @@ -34,7 +34,7 @@ select * from t1; drop table t1; create table t1 (a int not null) engine=heap; -insert into t1 values (869751),(736494),(226312),(802616); +insert into t1 values (869751),(736494),(226312),(802616),(728912); select * from t1 where a > 736494; alter table t1 add unique uniq_id using BTREE (a); select * from t1 where a > 736494; @@ -170,16 +170,38 @@ DROP TABLE t1; create table t1(a int not null, key using btree(a)) engine=heap; insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3); -select a from t1 where a > 2; +select a from t1 where a > 2 order by a; delete from t1 where a < 4; select a from t1 order by a; insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3); -select a from t1 where a > 4; +select a from t1 where a > 4 order by a; delete from t1 where a > 4; select a from t1 order by a; -select a from t1 where a > 3; +select a from t1 where a > 3 order by a; delete from t1 where a >= 2; select a from t1 order by a; drop table t1; --echo End of 4.1 tests + +# +# BUG#18160 - Memory-/HEAP Table endless growing indexes +# +CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory; +INSERT INTO t1 VALUES(0); +--replace_result 37 21 +SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1'; +UPDATE t1 SET val=1; +--replace_result 37 21 +SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1'; +DROP TABLE t1; + +# +# BUG#12873 - BTREE index on MEMORY table with multiple NULL values doesn't +# work properly +# +CREATE TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY; +INSERT INTO t1 VALUES(NULL),(NULL); +DROP TABLE t1; + +--echo End of 5.0 tests diff --git a/mysql-test/t/heap_hash.test b/mysql-test/t/heap_hash.test index 2cdec652688..28a75a5ee11 100644 --- a/mysql-test/t/heap_hash.test +++ b/mysql-test/t/heap_hash.test @@ -34,7 +34,7 @@ select * from t1; drop table t1; create table t1 (a int not null) engine=heap; -insert into t1 values (869751),(736494),(226312),(802616); +insert into t1 values (869751),(736494),(226312),(802616),(728912); select * from t1 where a > 736494; alter table t1 add unique uniq_id using HASH (a); select * from t1 where a > 736494; diff --git a/mysql-test/t/im_daemon_life_cycle-im.opt b/mysql-test/t/im_daemon_life_cycle-im.opt new file mode 100644 index 00000000000..3a45c7a41f7 --- /dev/null +++ b/mysql-test/t/im_daemon_life_cycle-im.opt @@ -0,0 +1,3 @@ +--run-as-service +--log=$MYSQLTEST_VARDIR/log/im.log +--monitoring-interval=1 diff --git a/mysql-test/t/im_daemon_life_cycle.imtest b/mysql-test/t/im_daemon_life_cycle.imtest new file mode 100644 index 00000000000..65db9dee93f --- /dev/null +++ b/mysql-test/t/im_daemon_life_cycle.imtest @@ -0,0 +1,72 @@ +########################################################################### +# +# This file contains test for (1.2) test suite. +# +# Consult WL#2789 for more information. +# +########################################################################### + +--source include/im_check_env.inc + +# Turn on reconnect, not on by default anymore +--enable_reconnect + +########################################################################### + +# Kill the IM main process and check that the IM Angel will restart the main +# process. + +--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted 30 + +########################################################################### + +# Wait for IM to start accepting connections. + +--exec $MYSQL_TEST_DIR/t/wait_for_socket.sh $EXE_MYSQL $IM_PATH_SOCK $IM_USERNAME $IM_PASSWORD '' 30 + +########################################################################### + +# +# BUG#12751: Instance Manager: client hangs +# + +--echo +--echo -------------------------------------------------------------------- +--echo -- Test for BUG#12751 +--echo -------------------------------------------------------------------- + +# Give some time to begin accepting connections after restart. +# FIXME: race condition here. + +--sleep 3 + +# 1. Start mysqld; + +START INSTANCE mysqld2; +# FIXME: START INSTANCE should be synchronous. +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started + +# 2. Restart IM-main: kill it and IM-angel will restart it; wait for IM to +# start accepting connections again. + +--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted 30 + +--exec $MYSQL_TEST_DIR/t/wait_for_socket.sh $EXE_MYSQL $IM_PATH_SOCK $IM_USERNAME $IM_PASSWORD '' 30 + +# 3. Issue some statement -- connection should be re-established. + +# Give some time to begin accepting connections after restart. +# FIXME: race condition here. + +--sleep 3 + +--replace_column 3 VERSION +SHOW INSTANCE STATUS mysqld1; + +# 4. Stop mysqld2, because it will not be stopped by IM, as it is nonguarded. +# So, if it we do not stop it, it will be stopped by mysql-test-run.pl with +# warning. + +STOP INSTANCE mysqld2; +# FIXME: STOP INSTANCE should be synchronous. +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped diff --git a/mysql-test/t/im_life_cycle-im.opt b/mysql-test/t/im_life_cycle-im.opt new file mode 100644 index 00000000000..34b74ce0c95 --- /dev/null +++ b/mysql-test/t/im_life_cycle-im.opt @@ -0,0 +1 @@ +--monitoring-interval=1 diff --git a/mysql-test/t/im_life_cycle.imtest b/mysql-test/t/im_life_cycle.imtest new file mode 100644 index 00000000000..ddfb62d312e --- /dev/null +++ b/mysql-test/t/im_life_cycle.imtest @@ -0,0 +1,203 @@ +########################################################################### +# +# This file contains test for (1.1) test suite. +# +# Consult WL#2789 for more information. +# +########################################################################### + +--source include/im_check_env.inc + +########################################################################### +# +# 1.1.2. Check 'START INSTANCE' command: +# - start the second instance; +# - check that it is reported as online; +# - execute some SQL-statement on mysqld2 to ensure that it is really up and +# running; +# +########################################################################### + +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.2. +--echo -------------------------------------------------------------------- + +START INSTANCE mysqld2; +# FIXME: START INSTANCE should be synchronous. +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started + +# FIXME: Result of SHOW INSTANCES here is not deterministic unless START +# INSTANCE is synchronous. Even waiting for mysqld to start by looking at +# its pid file is not enough, because it is unknown when IM detects that +# mysqld has started. +# SHOW INSTANCES; + +--connect (mysql_con,localhost,root,,mysql,$IM_MYSQLD2_PORT,$IM_MYSQLD2_SOCK) +--connection mysql_con + +--replace_result $IM_MYSQLD2_PORT IM_MYSQLD2_PORT +SHOW VARIABLES LIKE 'port'; + +--connection default +--disconnect mysql_con + +########################################################################### +# +# 1.1.3. Check 'STOP INSTANCE' command: +# - stop the second instance; +# - check that it is reported as offline; +# - TODO: try to execute some SQL-statement to ensure that it is really down; +# +########################################################################### + +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.3. +--echo -------------------------------------------------------------------- + +STOP INSTANCE mysqld2; +# FIXME: STOP INSTANCE should be synchronous. +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped + +# FIXME: Result of SHOW INSTANCES here is not deterministic unless START +# INSTANCE is synchronous. Even waiting for mysqld to start by looking at +# its pid file is not enough, because it is unknown when IM detects that +# mysqld has started. +# SHOW INSTANCES; + +########################################################################### +# +# 1.1.4. Check that Instance Manager reports correct errors for 'START +# INSTANCE' command: +# - if the client tries to start unregistered instance; +# - if the client tries to start already started instance; +# - if the client submits invalid arguments; +# +########################################################################### + +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.4. +--echo -------------------------------------------------------------------- + +--error 3000 # ER_BAD_INSTANCE_NAME +START INSTANCE mysqld3; + +--error 3002 # ER_INSTANCE_ALREADY_STARTED +START INSTANCE mysqld1; + +########################################################################### +# +# 1.1.5. Check that Instance Manager reports correct errors for +# 'STOP INSTANCE' command: +# - if the client tries to start unregistered instance; +# - if the client tries to start already stopped instance; +# - if the client submits invalid arguments; +# +########################################################################### + +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.5. +--echo -------------------------------------------------------------------- + +--error 3000 # ER_BAD_INSTANCE_NAME +STOP INSTANCE mysqld3; + +# TODO: IM should be fixed. +# BUG#12673: Instance Manager allows to stop the instance many times +# --error 3002 # ER_INSTANCE_ALREADY_STARTED +# STOP INSTANCE mysqld2; + +########################################################################### +# +# 1.1.6. Check that Instance Manager is able to restart guarded instances. +# +########################################################################### + +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.6. +--echo -------------------------------------------------------------------- + +--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted 30 + +# Give some time to IM to detect that mysqld was restarted. It should be +# longer than monitoring interval. + +--sleep 3 + +SHOW INSTANCES; + +########################################################################### +# +# 1.1.7. Check that Instance Manager does not restart non-guarded instance. +# +########################################################################### + +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.7. +--echo -------------------------------------------------------------------- + +START INSTANCE mysqld2; +# FIXME: START INSTANCE should be synchronous. +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started + +# FIXME: Result of SHOW INSTANCES here is not deterministic unless START +# INSTANCE is synchronous. Even waiting for mysqld to start by looking at +# its pid file is not enough, because it is unknown when IM detects that +# mysqld has started. +# SHOW INSTANCES; + +--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed 10 + +# FIXME: Result of SHOW INSTANCES here is not deterministic unless START +# INSTANCE is synchronous. Even waiting for mysqld to start by looking at +# its pid file is not enough, because it is unknown when IM detects that +# mysqld has started. +# SHOW INSTANCES; + +########################################################################### +# +# 1.1.8. Check that Instance Manager returns an error on +# incomplete SHOW INSTANCE STATUS command. +# +########################################################################### + +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.8. +--echo -------------------------------------------------------------------- + +--error ER_SYNTAX_ERROR +SHOW INSTANCE STATUS; + +# +# Tests for bug fixes +# + +# +# Bug #12813 Instance Manager: START/STOP INSTANCE commands accept +# a list as argument. +# + +--echo +--echo -------------------------------------------------------------------- +--echo -- BUG#12813 +--echo -------------------------------------------------------------------- + +--error ER_SYNTAX_ERROR +START INSTANCE mysqld1,mysqld2,mysqld3; + +--error ER_SYNTAX_ERROR +STOP INSTANCE mysqld1,mysqld2,mysqld3; + +# +# Bug #12673: Instance Manager: allows to stop the instance many times +# +--error 3001 +STOP INSTANCE mysqld2; + +--echo End of 5.0 tests diff --git a/mysql-test/t/im_options_set.imtest b/mysql-test/t/im_options_set.imtest new file mode 100644 index 00000000000..6a70c31c0a4 --- /dev/null +++ b/mysql-test/t/im_options_set.imtest @@ -0,0 +1,116 @@ +########################################################################### +# +# This file contains test for (3) test suite. +# +# Consult WL#2789 for more information. +# +########################################################################### + +# +# Check the options-management commands: +# - SET; +# - FLUSH INSTANCES; +# +# Let's test the commands on the option 'server_id'. It's expected that +# originally the instances have the following server ids: +# - mysqld1: 1 +# - mysqld2: 2 +# +# 1. SET <instance_id>.server_id= SERVER_ID); where SERVER_ID is 11 or 12. +# 1.1. check that the configuration file has been updated (i.e. contains +# server_id=SERVER_ID for the instance); +# 1.2. (for mysqld1) check that the running instance has not been affected: +# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' +# returns zero; +# 1.3. check that internal cache of Instance Manager has not been affected +# (i.e. SHOW INSTANCE OPTIONS <instance> does not contain updated value). +# +# 2. FLUSH INSTANCES; +# 2.1. check that the configuration file has not been updated; +# 2.2. (for mysqld1) check that the running instance has not been affected: +# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' +# returns zero value; +# 2.3. check that internal cache of Instance Manager has been updated (i.e. +# SHOW INSTANCE OPTIONS <instance> contains 'server_id=SERVER_ID' line). +# +# 3. Restore options. +# + +########################################################################### + +--source include/im_check_env.inc + +########################################################################### +# +# 1. SET <instance_id>.server_id= SERVER_ID); where SERVER_ID is 11 or 12. +# +########################################################################### + +# * mysqld1 + +SET mysqld1.server_id = 11; + +# - check that the configuration file has been updated (i.e. contains +# server_id=SERVER_ID for the instance); + +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; + +# - (for mysqld1) check that the running instance has not been affected: +# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' +# returns zero; + +--connection mysql1_con + +SHOW VARIABLES LIKE 'server_id'; + +--connection default + +# - check that internal cache of Instance Manager has not been affected +# (i.e. SHOW INSTANCE OPTIONS <instance> does not contain updated value). +# TODO: we should check only server_id option here. + +# SHOW INSTANCE OPTIONS mysqld1; + +# * mysqld2 + +SET mysqld2.server_id = 12; + +# - check that the configuration file has been updated (i.e. contains +# server_id=SERVER_ID for the instance); + +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; + +# - check that internal cache of Instance Manager has not been affected +# (i.e. SHOW INSTANCE OPTIONS <instance> does not contain updated value). +# TODO: we should check only server_id option here. + +# SHOW INSTANCE OPTIONS mysqld2; + +########################################################################### +# +# 2. FLUSH INSTANCES; +# +########################################################################### + +FLUSH INSTANCES; + +# - check that the configuration file has not been updated; + +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; + +# - (for mysqld1) check that the running instance has not been affected: +# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' +# returns zero value; + +--connection mysql1_con + +SHOW VARIABLES LIKE 'server_id'; + +--connection default + +# - check that internal cache of Instance Manager has been updated (i.e. +# SHOW INSTANCE OPTIONS <instance> contains 'server_id=' line). +# TODO: we should check only server_id option here. + +# SHOW INSTANCE OPTIONS mysqld1; +# SHOW INSTANCE OPTIONS mysqld2; diff --git a/mysql-test/t/im_options_unset.imtest b/mysql-test/t/im_options_unset.imtest new file mode 100644 index 00000000000..074c9a3b869 --- /dev/null +++ b/mysql-test/t/im_options_unset.imtest @@ -0,0 +1,124 @@ +########################################################################### +# +# This file contains test for (3) test suite. +# +# Consult WL#2789 for more information. +# +########################################################################### + +# +# Check the options-management commands: +# - UNSET; +# - FLUSH INSTANCES; +# +# Let's test the commands on the option 'server_id'. It's expected that +# originally the instances have the following server ids: +# - mysqld1: 1 +# - mysqld2: 2 +# +# The test case: +# +# 1. UNSET <instance_id>.server_id; +# +# Do the step for both instances. +# +# 1.1. check that the configuration file has been updated (i.e. does not +# contain 'server_id=' line for the instance); +# 1.2. (for mysqld1) check that the running instance has not been affected: +# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' +# returns non-zero value; +# 1.3. check that internal cache of Instance Manager is not affected (i.e. +# SHOW INSTANCE OPTIONS <instance> contains non-zero value for server_id); +# +# 2. FLUSH INSTANCES; +# +# Do the step for both instances. +# +# 2.1. check that the configuration file has not been updated (i.e. does not +# contain 'server_id=' for the instance); +# 2.2. (for mysqld1) check that the running instance has not been affected: +# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' +# returns non-zero value; +# 2.3. check that internal cache of Instance Manager has been updated (i.e. +# SHOW INSTANCE OPTIONS <instance> does not contain 'server_id=' line). +# + +########################################################################### + +--source include/im_check_env.inc + +########################################################################### +# +# 1. UNSET <instance_id>.server_id; +# +########################################################################### + +# * mysqld1 + +UNSET mysqld1.server_id; + +# - check that the configuration file has been updated (i.e. does not +# contain 'server_id=' line for the instance); + +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; + +# - check that the running instance has not been affected: connect to the +# instance and check that 'SHOW VARIABLES LIKE 'server_id'' returns non-zero +# value; + +--connection mysql1_con + +SHOW VARIABLES LIKE 'server_id'; + +--connection default + +# - check that internal cache of Instance Manager is not affected (i.e. SHOW +# INSTANCE OPTIONS <instance> contains non-zero value for server_id); +# TODO: we should check only server_id option here. + +# SHOW INSTANCE OPTIONS mysqld1; + +# * mysqld2 + +UNSET mysqld2.server_id; + +# - check that the configuration file has been updated (i.e. does not +# contain 'server_id=' line for the instance); + +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf || true; + +# - check that internal cache of Instance Manager is not affected (i.e. SHOW +# INSTANCE OPTIONS <instance> contains non-zero value for server_id); +# TODO: we should check only server_id option here. + +# SHOW INSTANCE OPTIONS mysqld2; + +########################################################################### +# +# 2. FLUSH INSTANCES; +# +########################################################################### + +FLUSH INSTANCES; + +# - check that the configuration file has not been updated (i.e. does not +# contain 'server_id=' for the instance); + +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf || true; + +# - (for mysqld1) check that the running instance has not been affected: +# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' +# returns non-zero value; + +--connection mysql1_con + +SHOW VARIABLES LIKE 'server_id'; + +--connection default + +# - check that internal cache of Instance Manager has been updated (i.e. +# SHOW INSTANCE OPTIONS <instance> does not contain 'server_id=' line). +# TODO: we should check only server_id option here. + +# SHOW INSTANCE OPTIONS mysqld1; +# SHOW INSTANCE OPTIONS mysqld2; diff --git a/mysql-test/t/im_utils-im.opt b/mysql-test/t/im_utils-im.opt new file mode 100644 index 00000000000..34b74ce0c95 --- /dev/null +++ b/mysql-test/t/im_utils-im.opt @@ -0,0 +1 @@ +--monitoring-interval=1 diff --git a/mysql-test/t/im_utils.imtest b/mysql-test/t/im_utils.imtest new file mode 100644 index 00000000000..52878f6c2b5 --- /dev/null +++ b/mysql-test/t/im_utils.imtest @@ -0,0 +1,105 @@ +########################################################################### +# +# This file contains test for (2) test suite. +# +# Consult WL#2789 for more information. +# +########################################################################### + +--source include/im_check_env.inc + +########################################################################### + +# +# Check 'SHOW INSTANCE OPTIONS' command. +# +# Since configuration of an mysqld-instance contains directories, we should +# completely ignore the second column (values) in order to make the test +# case produce the same results on different installations; +# TODO: ignore values of only directory-specific options. +# + +--replace_column 2 VALUE +SHOW INSTANCE OPTIONS mysqld1; + +--replace_column 2 VALUE +SHOW INSTANCE OPTIONS mysqld2; + +# +# Before checking log files, we should start the second instance (mysqld2) to +# give it a chance to create log files. +# + +START INSTANCE mysqld2; +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started + +STOP INSTANCE mysqld2; +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped + +# +# Check 'SHOW LOG FILES' command: +# - check that log files of both offline and online instances are accessible; +# - since placement of the log files is installation-specific, we should +# ignore it in comparisson; +# - also, we should ignore log file size, since it may depend on the version +# being tested; +# + +--replace_column 2 PATH 3 FILE_SIZE +SHOW mysqld1 LOG FILES; + +--replace_column 2 PATH 3 FILE_SIZE +SHOW mysqld2 LOG FILES; + +# +# Check 'SHOW LOG' command: +# - check that all three kinds of logs are available for both offline and +# online instances; +# - we should ignore the value, because it is very specific and depends on +# many factors; we only check that Instance Manager is able to provide log +# files. +# + +# mysqld1 (online) w/o the optional argument. + +--replace_column 1 LOG_DATA +SHOW mysqld1 LOG ERROR 10; + +--replace_column 1 LOG_DATA +SHOW mysqld1 LOG SLOW 10; + +--replace_column 1 LOG_DATA +SHOW mysqld1 LOG GENERAL 10; + +# mysqld1 (online) with the optional argument. + +--replace_column 1 LOG_DATA +SHOW mysqld1 LOG ERROR 10, 2; + +--replace_column 1 LOG_DATA +SHOW mysqld1 LOG SLOW 10, 2; + +--replace_column 1 LOG_DATA +SHOW mysqld1 LOG GENERAL 10, 2; + +# mysqld2 (offline) w/o the optional argument. + +--replace_column 1 LOG_DATA +SHOW mysqld2 LOG ERROR 10; + +--replace_column 1 LOG_DATA +SHOW mysqld2 LOG SLOW 10; + +--replace_column 1 LOG_DATA +SHOW mysqld2 LOG GENERAL 10; + +# mysqld2 (offline) with the optional argument. + +--replace_column 1 LOG_DATA +SHOW mysqld2 LOG ERROR 10, 2; + +--replace_column 1 LOG_DATA +SHOW mysqld2 LOG SLOW 10, 2; + +--replace_column 1 LOG_DATA +SHOW mysqld2 LOG GENERAL 10, 2; diff --git a/mysql-test/t/index_merge.test b/mysql-test/t/index_merge.test new file mode 100644 index 00000000000..30eb0b40fca --- /dev/null +++ b/mysql-test/t/index_merge.test @@ -0,0 +1,417 @@ +# +# Index merge tests +# +--disable_warnings +drop table if exists t0, t1, t2, t3, t4; +--enable_warnings + +# Create and fill a table with simple keys +create table t0 +( + key1 int not null, + INDEX i1(key1) +); + +--disable_query_log +insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8); + +let $1=7; +set @d=8; +while ($1) +{ + eval insert into t0 select key1+@d from t0; + eval set @d=@d*2; + dec $1; +} +--enable_query_log + +alter table t0 add key2 int not null, add index i2(key2); +alter table t0 add key3 int not null, add index i3(key3); +alter table t0 add key4 int not null, add index i4(key4); +alter table t0 add key5 int not null, add index i5(key5); +alter table t0 add key6 int not null, add index i6(key6); +alter table t0 add key7 int not null, add index i7(key7); +alter table t0 add key8 int not null, add index i8(key8); + +update t0 set key2=key1,key3=key1,key4=key1,key5=key1,key6=key1,key7=key1,key8=1024-key1; +analyze table t0; + +# 1. One index +explain select * from t0 where key1 < 3 or key1 > 1020; + +# 2. Simple cases +explain +select * from t0 where key1 < 3 or key2 > 1020; +select * from t0 where key1 < 3 or key2 > 1020; + +explain select * from t0 where key1 < 3 or key2 <4; + +explain +select * from t0 where (key1 > 30 and key1<35) or (key2 >32 and key2 < 40); +select * from t0 where (key1 > 30 and key1<35) or (key2 >32 and key2 < 40); + +# 3. Check that index_merge doesn't break "ignore/force/use index" +explain select * from t0 ignore index (i2) where key1 < 3 or key2 <4; +explain select * from t0 where (key1 < 3 or key2 <4) and key3 = 50; +explain select * from t0 use index (i1,i2) where (key1 < 3 or key2 <4) and key3 = 50; + +explain select * from t0 where (key1 > 1 or key2 > 2); +explain select * from t0 force index (i1,i2) where (key1 > 1 or key2 > 2); + + +# 4. Check if conjuncts are grouped by keyuse +explain + select * from t0 where key1<3 or key2<3 or (key1>5 and key1<8) or + (key1>10 and key1<12) or (key2>100 and key2<110); + +# 5. Check index_merge with conjuncts that are always true/false +# verify fallback to "range" if there is only one non-confluent condition +explain select * from t0 where key2 = 45 or key1 <=> null; + +explain select * from t0 where key2 = 45 or key1 is not null; +explain select * from t0 where key2 = 45 or key1 is null; + +# the last conj. is always false and will be discarded +explain select * from t0 where key2=10 or key3=3 or key4 <=> null; + +# the last conj. is always true and will cause 'all' scan +explain select * from t0 where key2=10 or key3=3 or key4 is null; + +# some more complicated cases +explain select key1 from t0 where (key1 <=> null) or (key2 < 5) or + (key3=10) or (key4 <=> null); +explain select key1 from t0 where (key1 <=> null) or (key1 < 5) or + (key3=10) or (key4 <=> null); + +# 6.Several ways to do index_merge, (ignored) index_merge vs. range +explain select * from t0 where + (key1 < 3 or key2 < 3) and (key3 < 4 or key4 < 4) and (key5 < 5 or key6 < 5); + +explain +select * from t0 where (key1 < 3 or key2 < 6) and (key1 < 7 or key3 < 4); + +select * from t0 where (key1 < 3 or key2 < 6) and (key1 < 7 or key3 < 4); + + +explain select * from t0 where + (key1 < 3 or key2 < 3) and (key3 < 4 or key4 < 4) and (key5 < 2 or key6 < 2); + +# now index_merge is not used at all when "range" is possible +explain select * from t0 where + (key1 < 3 or key2 < 3) and (key3 < 100); + +# this even can cause "all" scan: +explain select * from t0 where + (key1 < 3 or key2 < 3) and (key3 < 1000); + + +# 7. Complex cases +# tree_or(List<SEL_IMERGE>, range SEL_TREE). +explain select * from t0 where + ((key1 < 4 or key2 < 4) and (key2 <5 or key3 < 4)) + or + key2 > 5; + +explain select * from t0 where + ((key1 < 4 or key2 < 4) and (key2 <5 or key3 < 4)) + or + key1 < 7; + +select * from t0 where + ((key1 < 4 or key2 < 4) and (key2 <5 or key3 < 4)) + or + key1 < 7; + +# tree_or(List<SEL_IMERGE>, List<SEL_IMERGE>). +explain select * from t0 where + ((key1 < 4 or key2 < 4) and (key3 <5 or key5 < 4)) + or + ((key5 < 5 or key6 < 6) and (key7 <7 or key8 < 4)); + +explain select * from t0 where + ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4)) + or + ((key7 <7 or key8 < 4) and (key5 < 5 or key6 < 6)); + +explain select * from t0 where + ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4)) + or + ((key3 <7 or key5 < 2) and (key5 < 5 or key6 < 6)); + +explain select * from t0 where + ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4)) + or + (((key3 <7 and key7 < 6) or key5 < 2) and (key5 < 5 or key6 < 6)); + +explain select * from t0 where + ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4)) + or + ((key3 >=5 or key5 < 2) and (key5 < 5 or key6 < 6)); + +explain select * from t0 force index(i1, i2, i3, i4, i5, i6 ) where + ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4)) + or + ((key3 >=5 or key5 < 2) and (key5 < 5 or key6 < 6)); + +# 8. Verify that "order by" after index merge uses filesort +select * from t0 where key1 < 5 or key8 < 4 order by key1; + +explain +select * from t0 where key1 < 5 or key8 < 4 order by key1; + +# 9. Check that index_merge cost is compared to 'index' where possible +create table t2 like t0; +insert into t2 select * from t0; + +alter table t2 add index i1_3(key1, key3); +alter table t2 add index i2_3(key2, key3); +alter table t2 drop index i1; +alter table t2 drop index i2; +alter table t2 add index i321(key3, key2, key1); + +# index_merge vs 'index', index_merge is better. +explain select key3 from t2 where key1 = 100 or key2 = 100; + +# index_merge vs 'index', 'index' is better. +explain select key3 from t2 where key1 <100 or key2 < 100; + +# index_merge vs 'all', index_merge is better. +explain select key7 from t2 where key1 <100 or key2 < 100; + +# 10. Multipart keys. +create table t4 ( + key1a int not null, + key1b int not null, + key2 int not null, + key2_1 int not null, + key2_2 int not null, + key3 int not null, + + index i1a (key1a, key1b), + index i1b (key1b, key1a), + + index i2_1(key2, key2_1), + index i2_2(key2, key2_1) +); + +insert into t4 select key1,key1,key1 div 10, key1 % 10, key1 % 10, key1 from t0; + +# the following will be handled by index_merge: +select * from t4 where key1a = 3 or key1b = 4; +explain select * from t4 where key1a = 3 or key1b = 4; + +# and the following will not +explain select * from t4 where key2 = 1 and (key2_1 = 1 or key3 = 5); + +explain select * from t4 where key2 = 1 and (key2_1 = 1 or key2_2 = 5); + +explain select * from t4 where key2_1 = 1 or key2_2 = 5; + + +# 11. Multitable selects +create table t1 like t0; +insert into t1 select * from t0; + +# index_merge on first table in join +explain select * from t0 left join t1 on (t0.key1=t1.key1) + where t0.key1=3 or t0.key2=4; + +select * from t0 left join t1 on (t0.key1=t1.key1) + where t0.key1=3 or t0.key2=4; + +explain +select * from t0,t1 where (t0.key1=t1.key1) and ( t0.key1=3 or t0.key2=4); + +# index_merge vs. ref +explain +select * from t0,t1 where (t0.key1=t1.key1) and + (t0.key1=3 or t0.key2=4) and t1.key1<200; + +# index_merge vs. ref +explain +select * from t0,t1 where (t0.key1=t1.key1) and + (t0.key1=3 or t0.key2<4) and t1.key1=2; + +# index_merge on second table in join +explain select * from t0,t1 where t0.key1 = 5 and + (t1.key1 = t0.key1 or t1.key8 = t0.key1); + +# Fix for bug#1974 +explain select * from t0,t1 where t0.key1 < 3 and + (t1.key1 = t0.key1 or t1.key8 = t0.key1); + +# index_merge inside union +explain select * from t1 where key1=3 or key2=4 + union select * from t1 where key1<4 or key3=5; + +# index merge in subselect +explain select * from (select * from t1 where key1 = 3 or key2 =3) as Z where key8 >5; + +# 12. check for long index_merges. +create table t3 like t0; +insert into t3 select * from t0; +alter table t3 add key9 int not null, add index i9(key9); +alter table t3 add keyA int not null, add index iA(keyA); +alter table t3 add keyB int not null, add index iB(keyB); +alter table t3 add keyC int not null, add index iC(keyC); +update t3 set key9=key1,keyA=key1,keyB=key1,keyC=key1; + +explain select * from t3 where + key1=1 or key2=2 or key3=3 or key4=4 or + key5=5 or key6=6 or key7=7 or key8=8 or + key9=9 or keyA=10 or keyB=11 or keyC=12; + +select * from t3 where + key1=1 or key2=2 or key3=3 or key4=4 or + key5=5 or key6=6 or key7=7 or key8=8 or + key9=9 or keyA=10 or keyB=11 or keyC=12; + +# Test for Bug#3183 +explain select * from t0 where key1 < 3 or key2 < 4; +select * from t0 where key1 < 3 or key2 < 4; + +update t0 set key8=123 where key1 < 3 or key2 < 4; +select * from t0 where key1 < 3 or key2 < 4; + +delete from t0 where key1 < 3 or key2 < 4; +select * from t0 where key1 < 3 or key2 < 4; +select count(*) from t0; + +# Test for BUG#4177 +drop table t4; +create table t4 (a int); +insert into t4 values (1),(4),(3); +set @save_join_buffer_size=@@join_buffer_size; +set join_buffer_size= 4000; +explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) + from t0 as A force index(i1,i2), t0 as B force index (i1,i2) + where (A.key1 < 500000 or A.key2 < 3) + and (B.key1 < 500000 or B.key2 < 3); + +select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) + from t0 as A force index(i1,i2), t0 as B force index (i1,i2) + where (A.key1 < 500000 or A.key2 < 3) + and (B.key1 < 500000 or B.key2 < 3); + +update t0 set key1=1; +explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) + from t0 as A force index(i1,i2), t0 as B force index (i1,i2) + where (A.key1 = 1 or A.key2 = 1) + and (B.key1 = 1 or B.key2 = 1); + +select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) + from t0 as A force index(i1,i2), t0 as B force index (i1,i2) + where (A.key1 = 1 or A.key2 = 1) + and (B.key1 = 1 or B.key2 = 1); + +alter table t0 add filler1 char(200), add filler2 char(200), add filler3 char(200); +update t0 set key2=1, key3=1, key4=1, key5=1,key6=1,key7=1 where key7 < 500; + +# The next query will not use index i7 in intersection if the OS doesn't +# support file sizes > 2GB. (ha_myisam::ref_length depends on this and index +# scan cost estimates depend on ha_myisam::ref_length) +--replace_column 9 # +--replace_result "4,4,4,4,4,4,4" X "4,4,4,4,4,4" X "i6,i7" "i6,i7?" "i6" "i6,i7?" +explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) + from t0 as A, t0 as B + where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1) + and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1); + +select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) + from t0 as A, t0 as B + where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1) + and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1); + +set join_buffer_size= @save_join_buffer_size; +# Test for BUG#4177 ends + +drop table t0, t1, t2, t3, t4; + +# BUG#16166 +CREATE TABLE t1 ( + cola char(3) not null, colb char(3) not null, filler char(200), + key(cola), key(colb) +); +INSERT INTO t1 VALUES ('foo','bar', 'ZZ'),('fuz','baz', 'ZZ'); + +--disable_query_log +let $1=9; +while ($1) +{ + eval INSERT INTO t1 SELECT * from t1 WHERE cola = 'foo'; + dec $1; +} + +let $1=13; +while ($1) +{ + eval INSERT INTO t1 SELECT * from t1 WHERE cola <> 'foo'; + dec $1; +} + +--enable_query_log + +OPTIMIZE TABLE t1; +select count(*) from t1; +explain select * from t1 WHERE cola = 'foo' AND colb = 'bar'; +explain select * from t1 force index(cola,colb) WHERE cola = 'foo' AND colb = 'bar'; +drop table t1; + +# +# BUG#17314: Index_merge/intersection not choosen by the optimizer for MERGE tables +# +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 ( + a int, b int, + filler1 char(200), filler2 char(200), + key(a),key(b) +); +insert into t1 select @v:= A.a, @v, 't1', 'filler2' from t0 A, t0 B, t0 C; +create table t2 like t1; + +create table t3 ( + a int, b int, + filler1 char(200), filler2 char(200), + key(a),key(b) +) engine=merge union=(t1,t2); + +--replace_column 9 # +explain select * from t1 where a=1 and b=1; +--replace_column 9 # +explain select * from t3 where a=1 and b=1; + +drop table t3; +drop table t0, t1, t2; + +# +# BUG#20256 - LOCK WRITE - MyISAM +# +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES(1); +CREATE TABLE t2(a INT, b INT, dummy CHAR(16) DEFAULT '', KEY(a), KEY(b)); +INSERT INTO t2(a,b) VALUES +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(1,2); +LOCK TABLES t1 WRITE, t2 WRITE; +INSERT INTO t2(a,b) VALUES(1,2); +SELECT t2.a FROM t1,t2 WHERE t2.b=2 AND t2.a=1; +UNLOCK TABLES; +DROP TABLE t1, t2; diff --git a/mysql-test/t/index_merge_bdb.test b/mysql-test/t/index_merge_bdb.test new file mode 100644 index 00000000000..c49e6ab3175 --- /dev/null +++ b/mysql-test/t/index_merge_bdb.test @@ -0,0 +1,52 @@ +# +# 2-sweeps read Index_merge test +# +-- source include/have_bdb.inc + +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1 ( + pk int primary key, + key1 int, + key2 int, + filler char(200), + filler2 char(200), + index(key1), + index(key2) +) engine=bdb; + + +--disable_query_log +let $1=1000; +while ($1) +{ + eval insert into t1 values($1, $1, $1, 'filler-data','filler-data-2'); + dec $1; +} +--enable_query_log + +select * from t1 where (key1 >= 2 and key1 <= 10) or (pk >= 4 and pk <=8 ); + +set @maxv=1000; + +select * from t1 where + (pk < 5) or (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 ) or (pk > @maxv-10) + or key1=18 or key1=60; + +select * from t1 where + (pk < 5) or (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 ) or (pk > @maxv-10) + or key1 < 3 or key1 > @maxv-11; + +select * from t1 where + (pk < 5) or (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 ) or (pk > @maxv-10) + or + (key1 < 5) or (key1 > 10 and key1 < 15) or (key1 >= 50 and key1 < 55 ) or (key1 > @maxv-10); + +select * from t1 where + (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 ) + or + (key1 < 5) or (key1 > @maxv-10); + +drop table t1; diff --git a/mysql-test/t/index_merge_innodb.test b/mysql-test/t/index_merge_innodb.test new file mode 100644 index 00000000000..25f4e0b4e65 --- /dev/null +++ b/mysql-test/t/index_merge_innodb.test @@ -0,0 +1,302 @@ +# +# Index merge tests +# +-- source include/have_innodb.inc + +--disable_warnings +drop table if exists t1,t2; +--enable_warnings + +create table t1 +( + key1 int not null, + key2 int not null, + + INDEX i1(key1), + INDEX i2(key2) +) engine=innodb; + +--disable_query_log +let $1=200; +while ($1) +{ + eval insert into t1 values (200-$1, $1); + dec $1; +} +--enable_query_log + +# No primary key +explain select * from t1 where key1 < 5 or key2 > 197; + +select * from t1 where key1 < 5 or key2 > 197; + +explain select * from t1 where key1 < 3 or key2 > 195; +select * from t1 where key1 < 3 or key2 > 195; + +# Primary key as case-sensitive string with \0s. +# also make primary key be longer then max. index length of MyISAM. +alter table t1 add str1 char (255) not null, + add zeroval int not null default 0, + add str2 char (255) not null, + add str3 char (255) not null; + +update t1 set str1='aaa', str2='bbb', str3=concat(key2, '-', key1 div 2, '_' ,if(key1 mod 2 = 0, 'a', 'A')); + +alter table t1 add primary key (str1, zeroval, str2, str3); + +explain select * from t1 where key1 < 5 or key2 > 197; + +select * from t1 where key1 < 5 or key2 > 197; + +explain select * from t1 where key1 < 3 or key2 > 195; +select * from t1 where key1 < 3 or key2 > 195; + +# Test for BUG#5401 +drop table t1; +create table t1 ( + pk integer not null auto_increment primary key, + key1 integer, + key2 integer not null, + filler char (200), + index (key1), + index (key2) +) engine=innodb; +show warnings; +--disable_query_log +let $1=30; +while ($1) +{ + eval insert into t1 (key1, key2, filler) values ($1/4, $1/8, 'filler-data'); + dec $1; +} +--enable_query_log +explain select pk from t1 where key1 = 1 and key2 = 1; +select pk from t1 where key2 = 1 and key1 = 1; +select pk from t1 ignore index(key1,key2) where key2 = 1 and key1 = 1; + +# More tests for BUG#5401. +drop table t1; +create table t1 ( + pk int primary key auto_increment, + key1a int, + key2a int, + key1b int, + key2b int, + dummy1 int, + dummy2 int, + dummy3 int, + dummy4 int, + key3a int, + key3b int, + filler1 char (200), + index i1(key1a, key1b), + index i2(key2a, key2b), + index i3(key3a, key3b) +) engine=innodb; + +create table t2 (a int); +insert into t2 values (0),(1),(2),(3),(4),(NULL); + +insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b) + select A.a, B.a, C.a, D.a, C.a, D.a from t2 A,t2 B,t2 C, t2 D; +insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b) + select key1a, key1b, key2a, key2b, key3a, key3b from t1; +insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b) + select key1a, key1b, key2a, key2b, key3a, key3b from t1; +analyze table t1; +select count(*) from t1; + +explain select count(*) from t1 where + key1a = 2 and key1b is null and key2a = 2 and key2b is null; + +select count(*) from t1 where + key1a = 2 and key1b is null and key2a = 2 and key2b is null; + +explain select count(*) from t1 where + key1a = 2 and key1b is null and key3a = 2 and key3b is null; + +select count(*) from t1 where + key1a = 2 and key1b is null and key3a = 2 and key3b is null; + +drop table t1,t2; + +# Test for BUG#8441 +create table t1 ( + id1 int, + id2 date , + index idx2 (id1,id2), + index idx1 (id2) +) engine = innodb; +insert into t1 values(1,'20040101'), (2,'20040102'); +select * from t1 where id1 = 1 and id2= '20040101'; +drop table t1; + +# Test for BUG#12720 +--disable_warnings +drop view if exists v1; +--enable_warnings +CREATE TABLE t1 ( + `oid` int(11) unsigned NOT NULL auto_increment, + `fk_bbk_niederlassung` int(11) unsigned NOT NULL, + `fk_wochentag` int(11) unsigned NOT NULL, + `uhrzeit_von` time NOT NULL COMMENT 'HH:MM', + `uhrzeit_bis` time NOT NULL COMMENT 'HH:MM', + `geloescht` tinyint(4) NOT NULL, + `version` int(5) NOT NULL, + PRIMARY KEY (`oid`), + KEY `fk_bbk_niederlassung` (`fk_bbk_niederlassung`), + KEY `fk_wochentag` (`fk_wochentag`), + KEY `ix_version` (`version`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +insert into t1 values +(1, 38, 1, '08:00:00', '13:00:00', 0, 1), +(2, 38, 2, '08:00:00', '13:00:00', 0, 1), +(3, 38, 3, '08:00:00', '13:00:00', 0, 1), +(4, 38, 4, '08:00:00', '13:00:00', 0, 1), +(5, 38, 5, '08:00:00', '13:00:00', 0, 1), +(6, 38, 5, '08:00:00', '13:00:00', 1, 2), +(7, 38, 3, '08:00:00', '13:00:00', 1, 2), +(8, 38, 1, '08:00:00', '13:00:00', 1, 2), +(9, 38, 2, '08:00:00', '13:00:00', 1, 2), +(10, 38, 4, '08:00:00', '13:00:00', 1, 2), +(11, 38, 1, '08:00:00', '13:00:00', 0, 3), +(12, 38, 2, '08:00:00', '13:00:00', 0, 3), +(13, 38, 3, '08:00:00', '13:00:00', 0, 3), +(14, 38, 4, '08:00:00', '13:00:00', 0, 3), +(15, 38, 5, '08:00:00', '13:00:00', 0, 3), +(16, 38, 4, '08:00:00', '13:00:00', 0, 4), +(17, 38, 5, '08:00:00', '13:00:00', 0, 4), +(18, 38, 1, '08:00:00', '13:00:00', 0, 4), +(19, 38, 2, '08:00:00', '13:00:00', 0, 4), +(20, 38, 3, '08:00:00', '13:00:00', 0, 4), +(21, 7, 1, '08:00:00', '13:00:00', 0, 1), +(22, 7, 2, '08:00:00', '13:00:00', 0, 1), +(23, 7, 3, '08:00:00', '13:00:00', 0, 1), +(24, 7, 4, '08:00:00', '13:00:00', 0, 1), +(25, 7, 5, '08:00:00', '13:00:00', 0, 1); + +create view v1 as +select + zeit1.oid AS oid, + zeit1.fk_bbk_niederlassung AS fk_bbk_niederlassung, + zeit1.fk_wochentag AS fk_wochentag, + zeit1.uhrzeit_von AS uhrzeit_von, + zeit1.uhrzeit_bis AS uhrzeit_bis, + zeit1.geloescht AS geloescht, + zeit1.version AS version +from + t1 zeit1 +where +(zeit1.version = + (select max(zeit2.version) AS `max(version)` + from t1 zeit2 + where + ((zeit1.fk_bbk_niederlassung = zeit2.fk_bbk_niederlassung) and + (zeit1.fk_wochentag = zeit2.fk_wochentag) and + (zeit1.uhrzeit_von = zeit2.uhrzeit_von) and + (zeit1.uhrzeit_bis = zeit2.uhrzeit_bis) + ) + ) +) +and (zeit1.geloescht = 0); + +select * from v1 where oid = 21; +drop view v1; +drop table t1; +## +CREATE TABLE t1( + t_cpac varchar(2) NOT NULL, + t_vers varchar(4) NOT NULL, + t_rele varchar(2) NOT NULL, + t_cust varchar(4) NOT NULL, + filler1 char(250) default NULL, + filler2 char(250) default NULL, + PRIMARY KEY (t_cpac,t_vers,t_rele,t_cust), + UNIQUE KEY IX_4 (t_cust,t_cpac,t_vers,t_rele), + KEY IX_5 (t_vers,t_rele,t_cust) +) ENGINE=InnoDB; + +insert into t1 values +('tm','2.5 ','a ',' ','',''), ('tm','2.5U','a ','stnd','',''), +('da','3.3 ','b ',' ','',''), ('da','3.3U','b ','stnd','',''), +('tl','7.6 ','a ',' ','',''), ('tt','7.6 ','a ',' ','',''), +('bc','B61 ','a ',' ','',''), ('bp','B61 ','a ',' ','',''), +('ca','B61 ','a ',' ','',''), ('ci','B61 ','a ',' ','',''), +('cp','B61 ','a ',' ','',''), ('dm','B61 ','a ',' ','',''), +('ec','B61 ','a ',' ','',''), ('ed','B61 ','a ',' ','',''), +('fm','B61 ','a ',' ','',''), ('nt','B61 ','a ',' ','',''), +('qm','B61 ','a ',' ','',''), ('tc','B61 ','a ',' ','',''), +('td','B61 ','a ',' ','',''), ('tf','B61 ','a ',' ','',''), +('tg','B61 ','a ',' ','',''), ('ti','B61 ','a ',' ','',''), +('tp','B61 ','a ',' ','',''), ('ts','B61 ','a ',' ','',''), +('wh','B61 ','a ',' ','',''), ('bc','B61U','a ','stnd','',''), +('bp','B61U','a ','stnd','',''), ('ca','B61U','a ','stnd','',''), +('ci','B61U','a ','stnd','',''), ('cp','B61U','a ','stnd','',''), +('dm','B61U','a ','stnd','',''), ('ec','B61U','a ','stnd','',''), +('fm','B61U','a ','stnd','',''), ('nt','B61U','a ','stnd','',''), +('qm','B61U','a ','stnd','',''), ('tc','B61U','a ','stnd','',''), +('td','B61U','a ','stnd','',''), ('tf','B61U','a ','stnd','',''), +('tg','B61U','a ','stnd','',''), ('ti','B61U','a ','stnd','',''), +('tp','B61U','a ','stnd','',''), ('ts','B61U','a ','stnd','',''), +('wh','B61U','a ','stnd','',''); +show create table t1; + +select t_vers,t_rele,t_cust,filler1 from t1 where t_vers = '7.6'; +select t_vers,t_rele,t_cust,filler1 from t1 where t_vers = '7.6' + and t_rele='a' and t_cust = ' '; + +drop table t1; + +# BUG#19021: Crash in index_merge/ROR-intersection optimizer under +# specific circumstances. +create table t1 ( + pk int(11) not null auto_increment, + a int(11) not null default '0', + b int(11) not null default '0', + c int(11) not null default '0', + + filler1 datetime, filler2 varchar(15), + filler3 longtext, + + kp1 varchar(4), kp2 varchar(7), + kp3 varchar(2), kp4 varchar(4), + kp5 varchar(7), + filler4 char(1), + + primary key (pk), + key idx1(a,b,c), + key idx2(c), + key idx3(kp1,kp2,kp3,kp4,kp5) +) engine=innodb default charset=latin1; +--disable_query_log +set @fill= uncompress(unhex(concat( +'F91D0000789CDD993D6FDB301086F7FE0A6D4E0105B8E3F1335D5BA028DA0EEDE28E1D320408', +'52A0713BF4D7571FB62C51A475924839080307B603E77DEE787C8FA41F9E9EEF7F1F8A87A7C3', +'AFE280C5DF9F8F7FEE9F8B1B2CB114D6902E918455245DB91300FA16E42D5201FA4EE29DA05D', +'B9FB3718A33718A3FA8C30AEFAFDE1F317D016AA67BA7A60FDE45BF5F8BA7B5BDE8812AA9F1A', +'069DB03C9804346644F3A3A6A1338DB572756A3C4D1BCC804CABF912C654AE9BB855A2B85962', +'3A479259CAE6A86C0411D01AE5483581EDCBD9A39C45252D532E533979EB9F82E971D979BDB4', +'8531105670740AFBFD1E34AAB0029E4AD0A1D46A6D0946A21A16038A5CD965CD2D524673F712', +'20C304477315CE18405EAF9BD0AFFEAC74FDA14F1FBF5BD34C769D73FBBEDF4750ADD4E5A99C', +'5C8DC04934AFA275D483D536D174C11B12AF27F8F888B41B6FC9DBA569E1FD7BD72D698130B7', +'91B23A98803512B3D31881E8DCDA2AC1754E3644C4BB3A8466750B911681274A39E35E8624B7', +'444A42AC1213F354758E3CF1A4CDD5A688C767CF1B11ABC5867CB15D8A18E0B91E9EC275BB94', +'58F33C2936F64690D55BC29E4A293D95A798D84217736CEAAA538CE1354269EE2162053FBC66', +'496D90CB53323CB279D3A6AF651B4B22B9E430743D83BE48E995A09D4FC9871C22D8D189B945', +'706911BCB8C3C774B9C08D2FC6ED853ADACA37A14A4CB2E027630E5B80ECACD939431B1CDF62', +'7D71487536EA2C678F59685E91F4B6C144BCCB94C1EBA9FA6F5552DDCA4E4539BE326A2720CB', +'45ED028EB3616AC93C46E775FEA9FA6DA7CFCEC6DEBA5FCD1F915EED4D983BDDB881528AD9AB', +'43C1576F29AAB35BDFBC21D422F52B307D350589D45225A887AC46C8EDD72D99EC3ED2E1BCEF', +'7AF26FC4C74097B6768A5EDAFA660CC64278F7E63F99AC954B'))); +prepare x from @fill; +execute x; +deallocate prepare x; +--enable_query_log +set @fill=NULL; +SELECT COUNT(*) FROM t1 WHERE b = 0 AND a = 0 AND c = 13286427 AND + kp1='279' AND kp2='ELM0678' AND kp3='6' AND kp4='10' AND kp5 = 'R '; + +drop table t1; + + diff --git a/mysql-test/t/index_merge_innodb2.test b/mysql-test/t/index_merge_innodb2.test new file mode 100644 index 00000000000..ec4ea672bc1 --- /dev/null +++ b/mysql-test/t/index_merge_innodb2.test @@ -0,0 +1,52 @@ +# +# 2-sweeps read Index_merge test +# +-- source include/have_innodb.inc + +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1 ( + pk int primary key, + key1 int, + key2 int, + filler char(200), + filler2 char(200), + index(key1), + index(key2) +) engine=innodb; + + +--disable_query_log +let $1=1000; +while ($1) +{ + eval insert into t1 values($1, $1, $1, 'filler-data','filler-data-2'); + dec $1; +} +--enable_query_log + +select * from t1 where (key1 >= 2 and key1 <= 10) or (pk >= 4 and pk <=8 ); + +set @maxv=1000; + +select * from t1 where + (pk < 5) or (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 ) or (pk > @maxv-10) + or key1=18 or key1=60; + +select * from t1 where + (pk < 5) or (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 ) or (pk > @maxv-10) + or key1 < 3 or key1 > @maxv-11; + +select * from t1 where + (pk < 5) or (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 ) or (pk > @maxv-10) + or + (key1 < 5) or (key1 > 10 and key1 < 15) or (key1 >= 50 and key1 < 55 ) or (key1 > @maxv-10); + +select * from t1 where + (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 ) + or + (key1 < 5) or (key1 > @maxv-10); + +drop table t1; diff --git a/mysql-test/t/index_merge_ror.test b/mysql-test/t/index_merge_ror.test new file mode 100644 index 00000000000..48fe5526f11 --- /dev/null +++ b/mysql-test/t/index_merge_ror.test @@ -0,0 +1,252 @@ +# +# ROR-index_merge tests. +# +--disable_warnings +drop table if exists t0,t1,t2; +--enable_warnings +--disable_query_log +create table t1 +( + /* Field names reflect value(rowid) distribution, st=STairs, swt= SaWTooth */ + st_a int not null default 0, + swt1a int not null default 0, + swt2a int not null default 0, + + st_b int not null default 0, + swt1b int not null default 0, + swt2b int not null default 0, + + /* fields/keys for row retrieval tests */ + key1 int, + key2 int, + key3 int, + key4 int, + + /* make rows much bigger then keys */ + filler1 char (200), + filler2 char (200), + filler3 char (200), + filler4 char (200), + filler5 char (200), + filler6 char (200), + + /* order of keys is important */ + key sta_swt12a(st_a,swt1a,swt2a), + key sta_swt1a(st_a,swt1a), + key sta_swt2a(st_a,swt2a), + key sta_swt21a(st_a,swt2a,swt1a), + + key st_a(st_a), + key stb_swt1a_2b(st_b,swt1b,swt2a), + key stb_swt1b(st_b,swt1b), + key st_b(st_b), + + key(key1), + key(key2), + key(key3), + key(key4) +) ; + +# Fill table +create table t0 as select * from t1; +let $cnt=1000; +while ($cnt) +{ + eval insert into t0 values (1, 2, 3, 1, 2, 3, 0, 0, 0, 0, 'data1', 'data2', 'data3', 'data4', 'data5', 'data6'); + dec $cnt; +} + +alter table t1 disable keys; +let $1=4; +while ($1) +{ + let $2=4; + while ($2) + { + let $3=4; + while ($3) + { + eval insert into t1 select $1, $2, $3, $1 ,$2, $3, key1, key2, key3, key4, filler1, filler2, filler3, filler4, filler5, filler6 from t0; + dec $3; + } + dec $2; + } + dec $1; +} + +# Row retrieval tests +# -1 is used for values 'out of any range we are using' +# insert enough rows for index intersection to be used for (key1,key2) +insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 100, 100,'key1-key2-key3-key4'); +let $cnt=400; +while ($cnt) +{ + eval insert into t1 (key1, key2, key3, key4, filler1) values (100, -1, 100, -1,'key1-key3'); + dec $cnt; +} +let $cnt=400; +while ($cnt) +{ + eval insert into t1 (key1, key2, key3, key4, filler1) values (-1, 100, -1, 100,'key2-key4'); + dec $cnt; +} +alter table t1 enable keys; +--enable_query_log +select count(*) from t1; + +# One row results tests for cases where a single row matches all conditions +explain select key1,key2 from t1 where key1=100 and key2=100; +select key1,key2 from t1 where key1=100 and key2=100; + +explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; +select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; + +# Several-rows results +insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, -1, -1, 'key1-key2'); +insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 100, 100, 'key4-key3'); + +# ROR-intersection, not covering +explain select key1,key2,filler1 from t1 where key1=100 and key2=100; +select key1,key2,filler1 from t1 where key1=100 and key2=100; + +# ROR-intersection, covering +explain select key1,key2 from t1 where key1=100 and key2=100; +select key1,key2 from t1 where key1=100 and key2=100; + +# ROR-union of ROR-intersections +explain select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100; +select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100; +explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; +select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; + +# 3-way ROR-intersection +explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100; +select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100; + +# ROR-union(ROR-intersection, ROR-range) +insert into t1 (key1,key2,key3,key4,filler1) values (101,101,101,101, 'key1234-101'); +explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101; +select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101; + +# Run some ROR updates/deletes +select key1,key2, filler1 from t1 where key1=100 and key2=100; +update t1 set filler1='to be deleted' where key1=100 and key2=100; +update t1 set key1=200,key2=200 where key1=100 and key2=100; +delete from t1 where key1=200 and key2=200; +select key1,key2,filler1 from t1 where key2=100 and key2=200; + +# ROR-union(ROR-intersection) with one of ROR-intersection giving empty +# results +explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; +select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; + +delete from t1 where key3=100 and key4=100; + +# ROR-union with all ROR-intersections giving empty results +explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; +select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; + +# ROR-intersection with empty result +explain select key1,key2 from t1 where key1=100 and key2=100; +select key1,key2 from t1 where key1=100 and key2=100; + +# ROR-union tests with various cases. +# All scans returning duplicate rows: +insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-1'); +insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-2'); +insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-3'); + +explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200; +select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200; + +insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, -1, 200,'key4'); + +explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200; +select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200; + +insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 200, -1,'key3'); + +explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200; +select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200; + +## +## Optimizer tests +## + +# Check that the shortest key is used for ROR-intersection, covering and non-covering. +explain select * from t1 where st_a=1 and st_b=1; +explain select st_a,st_b from t1 where st_a=1 and st_b=1; + +# Check if "ingore index" syntax works +explain select st_a from t1 ignore index (st_a) where st_a=1 and st_b=1; + +# Do many tests +# Check that keys that don't improve selectivity are skipped. +# + +# Different value on 32 and 64 bit +--replace_result sta_swt12a sta_swt21a sta_swt12a, sta_swt12a, +explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1; + +explain select * from t1 where st_b=1 and swt1b=1 and swt2b=1; + +explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; + +explain select * from t1 ignore index (sta_swt21a, stb_swt1a_2b) + where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; + +explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b) + where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; + +explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b, stb_swt1b) + where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; + +explain select * from t1 + where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1; + +explain select * from t1 + where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1; + +explain select st_a from t1 + where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1; + +explain select st_a from t1 + where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1; + +drop table t0,t1; + +# 'Partially' covered fields test + +create table t2 ( + a char(10), + b char(10), + filler1 char(255), + filler2 char(255), + key(a(5)), + key(b(5)) +); + +--disable_query_log +let $1=8; +while ($1) +{ + eval insert into t2 values (repeat(char($1+64), 8),repeat(char($1+64), 8),'filler1', 'filler2'); + dec $1; +} +insert into t2 select * from t2; +insert into t2 select * from t2; +--enable_query_log + +# The table row buffer is reused. Fill it with rows that don't match. +select count(a) from t2 where a='BBBBBBBB'; +select count(a) from t2 where b='BBBBBBBB'; + +# BUG#1: +--replace_result a a_or_b b a_or_b +explain select count(a) from t2 where a='AAAAAAAA' and b='AAAAAAAA'; +select count(a) from t2 where a='AAAAAAAA' and b='AAAAAAAA'; +select count(a) from t2 ignore index(a,b) where a='AAAAAAAA' and b='AAAAAAAA'; + +insert into t2 values ('ab', 'ab', 'uh', 'oh'); +explain select a from t2 where a='ab'; +drop table t2; diff --git a/mysql-test/t/index_merge_ror_cpk.test b/mysql-test/t/index_merge_ror_cpk.test new file mode 100644 index 00000000000..94abf395d0a --- /dev/null +++ b/mysql-test/t/index_merge_ror_cpk.test @@ -0,0 +1,111 @@ +# +# Clustered PK ROR-index_merge tests +# +-- source include/have_innodb.inc + +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1 +( + pk1 int not null, + pk2 int not null, + + key1 int not null, + key2 int not null, + + pktail1ok int not null, + pktail2ok int not null, + pktail3bad int not null, + pktail4bad int not null, + pktail5bad int not null, + + pk2copy int not null, + badkey int not null, + + filler1 char (200), + filler2 char (200), + key (key1), + key (key2), + + /* keys with tails from CPK members */ + key (pktail1ok, pk1), + key (pktail2ok, pk1, pk2), + key (pktail3bad, pk2, pk1), + key (pktail4bad, pk1, pk2copy), + key (pktail5bad, pk1, pk2, pk2copy), + + primary key (pk1, pk2) +) engine=innodb; + +--disable_query_log +set autocommit=0; +let $1=10000; +while ($1) +{ + eval insert into t1 values ($1 div 10,$1 mod 100, $1/100,$1/100, $1/100,$1/100,$1/100,$1/100,$1/100, $1 mod 100, $1/1000,'filler-data-$1','filler2'); + dec $1; +} +set autocommit=1; +--enable_query_log + +# Verify that range scan on CPK is ROR +# (use index_intersection because it is impossible to check that for index union) +explain select * from t1 where pk1 = 1 and pk2 < 80 and key1=0; +# CPK scan + 1 ROR range scan is a special case +select * from t1 where pk1 = 1 and pk2 < 80 and key1=0; + +# Verify that CPK fields are considered to be covered by index scans +explain select pk1,pk2 from t1 where key1 = 10 and key2=10 and 2*pk1+1 < 2*96+1; +select pk1,pk2 from t1 where key1 = 10 and key2=10 and 2*pk1+1 < 2*96+1; + +# Verify that CPK is always used for index intersection scans +# (this is because it is used as a filter, not for retrieval) +explain select * from t1 where badkey=1 and key1=10; +--replace_result 38 ROWS 37 ROWS +explain select * from t1 where pk1 < 7500 and key1 = 10; + +# Verify that keys with 'tails' of PK members are ok. +explain select * from t1 where pktail1ok=1 and key1=10; +explain select * from t1 where pktail2ok=1 and key1=10; + +select ' The following is actually a deficiency, it uses sort_union currently:' as 'note:'; +explain select * from t1 where (pktail2ok=1 and pk1< 50000) or key1=10; + +# The expected rows differs a bit from platform to platform +--replace_result 98 ROWS 99 ROWS +explain select * from t1 where pktail3bad=1 and key1=10; +explain select * from t1 where pktail4bad=1 and key1=10; +explain select * from t1 where pktail5bad=1 and key1=10; + +# Test for problem with innodb key values prefetch buffer: +explain select pk1,pk2,key1,key2 from t1 where key1 = 10 and key2=10 limit 10; +select pk1,pk2,key1,key2 from t1 where key1 = 10 and key2=10 limit 10; + +drop table t1; +# Testcase for BUG#4984 +create table t1 +( + RUNID varchar(22), + SUBMITNR varchar(5), + ORDERNR char(1) , + PROGRAMM varchar(8), + TESTID varchar(4), + UCCHECK char(1), + ETEXT varchar(80), + ETEXT_TYPE char(1), + INFO char(1), + SEVERITY tinyint(3), + TADIRFLAG char(1), + PRIMARY KEY (RUNID,SUBMITNR,ORDERNR,PROGRAMM,TESTID,UCCHECK), + KEY `TVERM~KEY` (PROGRAMM,TESTID,UCCHECK) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +update t1 set `ETEXT` = '', `ETEXT_TYPE`='', `INFO`='', `SEVERITY`='', `TADIRFLAG`='' +WHERE + `RUNID`= '' AND `SUBMITNR`= '' AND `ORDERNR`='' AND `PROGRAMM`='' AND + `TESTID`='' AND `UCCHECK`=''; + +drop table t1; + diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test new file mode 100644 index 00000000000..27007bbe16a --- /dev/null +++ b/mysql-test/t/information_schema.test @@ -0,0 +1,976 @@ +# This test uses grants, which can't get tested for embedded server +-- source include/not_embedded.inc + +# Test for information_schema.schemata & +# show databases + +--disable_warnings +DROP TABLE IF EXISTS t0,t1,t2,t3,t4,t5; +DROP VIEW IF EXISTS v1; +--enable_warnings + + +show variables where variable_name like "skip_show_database"; +grant select, update, execute on test.* to mysqltest_2@localhost; +grant select, update on test.* to mysqltest_1@localhost; +create user mysqltest_3@localhost; +create user mysqltest_3; + + +select * from information_schema.SCHEMATA where schema_name > 'm'; +select schema_name from information_schema.schemata; +show databases like 't%'; +show databases; +show databases where `database` = 't%'; + +# Test for information_schema.tables & +# show tables + +create database mysqltest; +create table mysqltest.t1(a int, b VARCHAR(30), KEY string_data (b)); +create table test.t2(a int); +create table t3(a int, KEY a_data (a)); +create table mysqltest.t4(a int); +create table t5 (id int auto_increment primary key); +insert into t5 values (10); +create view v1 (c) as select table_name from information_schema.TABLES; +select * from v1; + +select c,table_name from v1 +inner join information_schema.TABLES v2 on (v1.c=v2.table_name) +where v1.c like "t%"; + +select c,table_name from v1 +left join information_schema.TABLES v2 on (v1.c=v2.table_name) +where v1.c like "t%"; + +select c, v2.table_name from v1 +right join information_schema.TABLES v2 on (v1.c=v2.table_name) +where v1.c like "t%"; + +select table_name from information_schema.TABLES +where table_schema = "mysqltest" and table_name like "t%"; + +select * from information_schema.STATISTICS where TABLE_SCHEMA = "mysqltest"; +show keys from t3 where Key_name = "a_data"; + +show tables like 't%'; +--replace_column 8 # 12 # 13 # +show table status; +show full columns from t3 like "a%"; +show full columns from mysql.db like "Insert%"; +show full columns from v1; +select * from information_schema.COLUMNS where table_name="t1" +and column_name= "a"; +show columns from mysqltest.t1 where field like "%a%"; + +create view mysqltest.v1 (c) as select a from mysqltest.t1; +grant select (a) on mysqltest.t1 to mysqltest_2@localhost; +grant select on mysqltest.v1 to mysqltest_3; +connect (user3,localhost,mysqltest_2,,); +connection user3; +select table_name, column_name, privileges from information_schema.columns +where table_schema = 'mysqltest' and table_name = 't1'; +show columns from mysqltest.t1; +connect (user4,localhost,mysqltest_3,,mysqltest); +connection user4; +select table_name, column_name, privileges from information_schema.columns +where table_schema = 'mysqltest' and table_name = 'v1'; +connection default; + +drop view v1, mysqltest.v1; +drop tables mysqltest.t4, mysqltest.t1, t2, t3, t5; +drop database mysqltest; + +# Test for information_schema.CHARACTER_SETS & +# SHOW CHARACTER SET + +select * from information_schema.CHARACTER_SETS +where CHARACTER_SET_NAME like 'latin1%'; +SHOW CHARACTER SET LIKE 'latin1%'; +SHOW CHARACTER SET WHERE charset like 'latin1%'; + +# Test for information_schema.COLLATIONS & +# SHOW COLLATION + +--replace_column 5 # +select * from information_schema.COLLATIONS +where COLLATION_NAME like 'latin1%'; +--replace_column 5 # +SHOW COLLATION LIKE 'latin1%'; +--replace_column 5 # +SHOW COLLATION WHERE collation like 'latin1%'; + +select * from information_schema.COLLATION_CHARACTER_SET_APPLICABILITY +where COLLATION_NAME like 'latin1%'; + +# Test for information_schema.ROUTINES & +# + +--disable_warnings +drop procedure if exists sel2; +drop function if exists sub1; +drop function if exists sub2; +--enable_warnings + +create function sub1(i int) returns int + return i+1; +delimiter |; +create procedure sel2() +begin + select * from t1; + select * from t2; +end| +delimiter ;| + +# +# Bug#7222 information_schema: errors in "routines" +# +select parameter_style, sql_data_access, dtd_identifier +from information_schema.routines; + +--replace_column 5 # 6 # +show procedure status; +--replace_column 5 # 6 # +show function status; +select a.ROUTINE_NAME from information_schema.ROUTINES a, +information_schema.SCHEMATA b where +a.ROUTINE_SCHEMA = b.SCHEMA_NAME; +--replace_column 3 # +explain select a.ROUTINE_NAME from information_schema.ROUTINES a, +information_schema.SCHEMATA b where +a.ROUTINE_SCHEMA = b.SCHEMA_NAME; + +select a.ROUTINE_NAME, b.name from information_schema.ROUTINES a, +mysql.proc b where a.ROUTINE_NAME = convert(b.name using utf8) order by 1; +select count(*) from information_schema.ROUTINES; + +create view v1 as select routine_schema, routine_name from information_schema.routines +order by routine_schema, routine_name; +select * from v1; +drop view v1; + +connect (user1,localhost,mysqltest_1,,); +connection user1; +select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES; +--error 1305 +show create function sub1; +connection user3; +select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES; +connection default; +grant all privileges on test.* to mysqltest_1@localhost; +connect (user2,localhost,mysqltest_1,,); +connection user2; +select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES; +create function sub2(i int) returns int + return i+1; +select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES; +show create procedure sel2; +show create function sub1; +show create function sub2; +--replace_column 5 # 6 # +show function status like "sub2"; +connection default; +disconnect user1; +drop function sub2; +show create procedure sel2; + +# +# Test for views +# +create view v0 (c) as select schema_name from information_schema.schemata; +select * from v0; +--replace_column 3 # +explain select * from v0; +create view v1 (c) as select table_name from information_schema.tables +where table_name="v1"; +select * from v1; +create view v2 (c) as select column_name from information_schema.columns +where table_name="v2"; +select * from v2; +create view v3 (c) as select CHARACTER_SET_NAME from information_schema.character_sets +where CHARACTER_SET_NAME like "latin1%"; +select * from v3; +create view v4 (c) as select COLLATION_NAME from information_schema.collations +where COLLATION_NAME like "latin1%"; +select * from v4; +show keys from v4; +select * from information_schema.views where TABLE_NAME like "v%"; +drop view v0, v1, v2, v3, v4; + +# +# Test for privileges tables +# +create table t1 (a int); +grant select,update,insert on t1 to mysqltest_1@localhost; +grant select (a), update (a),insert(a), references(a) on t1 to mysqltest_1@localhost; +grant all on test.* to mysqltest_1@localhost with grant option; +select * from information_schema.USER_PRIVILEGES where grantee like '%mysqltest_1%'; +select * from information_schema.SCHEMA_PRIVILEGES where grantee like '%mysqltest_1%'; +select * from information_schema.TABLE_PRIVILEGES where grantee like '%mysqltest_1%'; +select * from information_schema.COLUMN_PRIVILEGES where grantee like '%mysqltest_1%'; +delete from mysql.user where user like 'mysqltest%'; +delete from mysql.db where user like 'mysqltest%'; +delete from mysql.tables_priv where user like 'mysqltest%'; +delete from mysql.columns_priv where user like 'mysqltest%'; +flush privileges; +drop table t1; + + +# +# Test for KEY_COLUMN_USAGE & TABLE_CONSTRAINTS tables +# + +create table t1 (a int null, primary key(a)); +alter table t1 add constraint constraint_1 unique (a); +alter table t1 add constraint unique key_1(a); +alter table t1 add constraint constraint_2 unique key_2(a); +show create table t1; +select * from information_schema.TABLE_CONSTRAINTS where +TABLE_SCHEMA= "test"; +select * from information_schema.KEY_COLUMN_USAGE where +TABLE_SCHEMA= "test"; + +connection user2; +select table_name from information_schema.TABLES where table_schema like "test%"; +select table_name,column_name from information_schema.COLUMNS where table_schema like "test%"; +select ROUTINE_NAME from information_schema.ROUTINES; +disconnect user2; +connection default; +delete from mysql.user where user='mysqltest_1'; +drop table t1; +drop procedure sel2; +drop function sub1; + +create table t1(a int); +create view v1 (c) as select a from t1 with check option; +create view v2 (c) as select a from t1 WITH LOCAL CHECK OPTION; +create view v3 (c) as select a from t1 WITH CASCADED CHECK OPTION; +select * from information_schema.views; +grant select (a) on test.t1 to joe@localhost with grant option; +select * from INFORMATION_SCHEMA.COLUMN_PRIVILEGES; +select * from INFORMATION_SCHEMA.TABLE_PRIVILEGES; +drop view v1, v2, v3; +drop table t1; +delete from mysql.user where user='joe'; +delete from mysql.db where user='joe'; +delete from mysql.tables_priv where user='joe'; +delete from mysql.columns_priv where user='joe'; +flush privileges; + +# QQ This results in NULLs instead of the version numbers when +# QQ a LOCK TABLES is in effect when selecting from +# QQ information_schema.tables. + +--disable_parsing # until bug is fixed +delimiter //; +create procedure px5 () +begin +declare v int; +declare c cursor for select version from +information_schema.tables where table_schema <> 'information_schema'; +open c; +fetch c into v; +select v; +close c; +end;// + +call px5()// +call px5()// +delimiter ;// +select sql_mode from information_schema.ROUTINES; +drop procedure px5; +--enable_parsing + +create table t1 (a int not null auto_increment,b int, primary key (a)); +insert into t1 values (1,1),(NULL,3),(NULL,4); +select AUTO_INCREMENT from information_schema.tables where table_name = 't1'; +drop table t1; + +create table t1 (s1 int); +insert into t1 values (0),(9),(0); +select s1 from t1 where s1 in (select version from +information_schema.tables) union select version from +information_schema.tables; +drop table t1; + +SHOW CREATE TABLE INFORMATION_SCHEMA.character_sets; +set names latin2; +SHOW CREATE TABLE INFORMATION_SCHEMA.character_sets; +set names latin1; + +create table t1 select * from information_schema.CHARACTER_SETS +where CHARACTER_SET_NAME like "latin1"; +select * from t1; +alter table t1 default character set utf8; +show create table t1; +drop table t1; + +create view v1 as select * from information_schema.TABLES; +drop view v1; +create table t1(a NUMERIC(5,3), b NUMERIC(5,1), c float(5,2), + d NUMERIC(6,4), e float, f DECIMAL(6,3), g int(11), h DOUBLE(10,3), + i DOUBLE); +select COLUMN_NAME,COLUMN_TYPE, CHARACTER_MAXIMUM_LENGTH, + CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE +from information_schema.columns where table_name= 't1'; +drop table t1; + +create table t115 as select table_name, column_name, column_type +from information_schema.columns where table_name = 'proc'; +select * from t115; +drop table t115; + +delimiter //; +create procedure p108 () begin declare c cursor for select data_type +from information_schema.columns; open c; open c; end;// +--error 1325 +call p108()// +delimiter ;// +drop procedure p108; + +create view v1 as select A1.table_name from information_schema.TABLES A1 +where table_name= "user"; +select * from v1; +drop view v1; + +create view vo as select 'a' union select 'a'; +show index from vo; +select * from information_schema.TABLE_CONSTRAINTS where +TABLE_NAME= "vo"; +select * from information_schema.KEY_COLUMN_USAGE where +TABLE_NAME= "vo"; +drop view vo; + +select TABLE_NAME,TABLE_TYPE,ENGINE +from information_schema.tables +where table_schema='information_schema' limit 2; +show tables from information_schema like "T%"; + +--error 1044 +create database information_schema; +use information_schema; +show full tables like "T%"; +--error 1109 +create table t1(a int); +use test; +show tables; +use information_schema; +show tables like "T%"; + +# +# Bug#7210: information_schema: can't access when table-name = reserved word +# +select table_name from tables where table_name='user'; +select column_name, privileges from columns +where table_name='user' and column_name like '%o%'; + +# +# Bug#7212: information_schema: "Can't find file" errors if storage engine gone +# Bug#7211: information_schema: crash if bad view +# +use test; +create function sub1(i int) returns int + return i+1; +create table t1(f1 int); +create view v2 (c) as select f1 from t1; +create view v3 (c) as select sub1(1); +create table t4(f1 int, KEY f1_key (f1)); +drop table t1; +drop function sub1; +select table_name from information_schema.views +where table_schema='test'; +select table_name from information_schema.views +where table_schema='test'; +select column_name from information_schema.columns +where table_schema='test'; +select index_name from information_schema.statistics where table_schema='test'; +select constraint_name from information_schema.table_constraints +where table_schema='test'; +show create view v2; +show create table v3; +drop view v2; +drop view v3; +drop table t4; + +# +# Bug#7213: information_schema: redundant non-standard TABLE_NAMES table +# +--error 1109 +select * from information_schema.table_names; + +# +# Bug#2719 information_schema: errors in "columns" +# +select column_type from information_schema.columns +where table_schema="information_schema" and table_name="COLUMNS" and +(column_name="character_set_name" or column_name="collation_name"); + +# +# Bug#2718 information_schema: errors in "tables" +# +select TABLE_ROWS from information_schema.tables where +table_schema="information_schema" and table_name="COLUMNS"; +select table_type from information_schema.tables +where table_schema="mysql" and table_name="user"; + +# test for 'show open tables ... where' +show open tables where `table` like "user"; +# test for 'show status ... where' +show status where variable_name like "%database%"; +# test for 'show variables ... where' +show variables where variable_name like "skip_show_databas"; + +# +# Bug #7981:SHOW GLOBAL STATUS crashes server +# +# We don't actually care about the value, just that it doesn't crash. +--replace_column 2 # +show global status like "Threads_running"; + +# +# Bug #7915 crash,JOIN VIEW, subquery, +# SELECT .. FROM INFORMATION_SCHEMA.COLUMNS +# +create table t1(f1 int); +create table t2(f2 int); +create view v1 as select * from t1, t2; +set @got_val= (select count(*) from information_schema.columns); +drop view v1; +drop table t1, t2; + +# +# Bug #7476: crash on SELECT * FROM INFORMATION_SCHEMA.TABLES +# + +CREATE TABLE t_crashme ( f1 BIGINT); +CREATE VIEW a1 (t_CRASHME) AS SELECT f1 FROM t_crashme GROUP BY f1; +CREATE VIEW a2 AS SELECT t_CRASHME FROM a1; +let $tab_count= 65; +--disable_query_log +while ($tab_count) +{ + EVAL CREATE TABLE t_$tab_count (f1 BIGINT); + dec $tab_count ; +} +--disable_result_log +SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES; +--enable_result_log +SELECT count(*) FROM INFORMATION_SCHEMA.TABLES; +let $tab_count= 65; +while ($tab_count) +{ + EVAL DROP TABLE t_$tab_count; + dec $tab_count ; +} +--enable_query_log +drop view a2, a1; +drop table t_crashme; + +# +# Bug #7215 information_schema: columns are longtext instead of varchar +# Bug #7217 information_schema: columns are varbinary() instead of timestamp +# +select table_schema,table_name, column_name from +information_schema.columns +where data_type = 'longtext'; +select table_name, column_name, data_type from information_schema.columns +where data_type = 'datetime'; + +# +# Bug #8164 subquery with INFORMATION_SCHEMA.COLUMNS, 100 % CPU +# +SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES A +WHERE NOT EXISTS +(SELECT * FROM INFORMATION_SCHEMA.COLUMNS B + WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA + AND A.TABLE_NAME = B.TABLE_NAME); + +# +# Bug #9344 INFORMATION_SCHEMA, wrong content, numeric columns +# + +create table t1 +( x_bigint BIGINT, + x_integer INTEGER, + x_smallint SMALLINT, + x_decimal DECIMAL(5,3), + x_numeric NUMERIC(5,3), + x_real REAL, + x_float FLOAT, + x_double_precision DOUBLE PRECISION ); +SELECT COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH +FROM INFORMATION_SCHEMA.COLUMNS +WHERE TABLE_NAME= 't1'; +drop table t1; + +# +# Bug#10261 INFORMATION_SCHEMA.COLUMNS, incomplete result for non root user +# + +grant select on test.* to mysqltest_4@localhost; +connect (user10261,localhost,mysqltest_4,,); +connection user10261; +SELECT TABLE_NAME, COLUMN_NAME, PRIVILEGES FROM INFORMATION_SCHEMA.COLUMNS +where COLUMN_NAME='TABLE_NAME'; +connection default; +delete from mysql.user where user='mysqltest_4'; +delete from mysql.db where user='mysqltest_4'; +flush privileges; + +# +# Bug #9404 information_schema: Weird error messages +# with SELECT SUM() ... GROUP BY queries +# +SELECT table_schema, count(*) FROM information_schema.TABLES GROUP BY TABLE_SCHEMA; + + +# +# TRIGGERS table test +# +create table t1 (i int, j int); + +delimiter |; +create trigger trg1 before insert on t1 for each row +begin + if new.j > 10 then + set new.j := 10; + end if; +end| +create trigger trg2 before update on t1 for each row +begin + if old.i % 2 = 0 then + set new.j := -1; + end if; +end| +create trigger trg3 after update on t1 for each row +begin + if new.j = -1 then + set @fired:= "Yes"; + end if; +end| +delimiter ;| +show triggers; +select * from information_schema.triggers; + +drop trigger trg1; +drop trigger trg2; +drop trigger trg3; +drop table t1; + + +# +# Bug #10964 Information Schema:Authorization check on privilege tables is improper +# + +create database mysqltest; +create table mysqltest.t1 (f1 int, f2 int); +create table mysqltest.t2 (f1 int); +grant select (f1) on mysqltest.t1 to user1@localhost; +grant select on mysqltest.t2 to user2@localhost; +grant select on mysqltest.* to user3@localhost; +grant select on *.* to user4@localhost; + +connect (con1,localhost,user1,,mysqltest); +connect (con2,localhost,user2,,mysqltest); +connect (con3,localhost,user3,,mysqltest); +connect (con4,localhost,user4,,); +connection con1; +select * from information_schema.column_privileges order by grantee; +select * from information_schema.table_privileges order by grantee; +select * from information_schema.schema_privileges order by grantee; +select * from information_schema.user_privileges order by grantee; +show grants; +connection con2; +select * from information_schema.column_privileges order by grantee; +select * from information_schema.table_privileges order by grantee; +select * from information_schema.schema_privileges order by grantee; +select * from information_schema.user_privileges order by grantee; +show grants; +connection con3; +select * from information_schema.column_privileges order by grantee; +select * from information_schema.table_privileges order by grantee; +select * from information_schema.schema_privileges order by grantee; +select * from information_schema.user_privileges order by grantee; +show grants; +connection con4; +select * from information_schema.column_privileges where grantee like '%user%' +order by grantee; +select * from information_schema.table_privileges where grantee like '%user%' +order by grantee; +select * from information_schema.schema_privileges where grantee like '%user%' +order by grantee; +select * from information_schema.user_privileges where grantee like '%user%' +order by grantee; +show grants; +connection default; +drop user user1@localhost, user2@localhost, user3@localhost, user4@localhost; +use test; +drop database mysqltest; + +# +# Bug #11055 information_schema: routines.sql_data_access has wrong value +# +--disable_warnings +drop procedure if exists p1; +drop procedure if exists p2; +--enable_warnings + +create procedure p1 () modifies sql data set @a = 5; +create procedure p2 () set @a = 5; +select sql_data_access from information_schema.routines +where specific_name like 'p%'; +drop procedure p1; +drop procedure p2; + +# +# Bug #9434 SHOW CREATE DATABASE information_schema; +# +show create database information_schema; + +# +# Bug #11057 information_schema: columns table has some questionable contents +# Bug #12301 information_schema: NUMERIC_SCALE must be 0 for integer columns +# +create table t1(f1 LONGBLOB, f2 LONGTEXT); +select column_name,data_type,CHARACTER_OCTET_LENGTH, + CHARACTER_MAXIMUM_LENGTH +from information_schema.columns +where table_name='t1'; +drop table t1; +create table t1(f1 tinyint, f2 SMALLINT, f3 mediumint, f4 int, + f5 BIGINT, f6 BIT, f7 bit(64)); +select column_name, NUMERIC_PRECISION, NUMERIC_SCALE +from information_schema.columns +where table_name='t1'; +drop table t1; + +# +# Bug #12127 triggers do not show in info_schema before they are used if set to the database +# +create table t1 (f1 integer); +create trigger tr1 after insert on t1 for each row set @test_var=42; +use information_schema; +select trigger_schema, trigger_name from triggers where +trigger_name='tr1'; +use test; +drop table t1; + +# +# Bug#12518 COLUMN_DEFAULT has wrong value if NOT NULL is set +# +create table t1 (a int not null, b int); +use information_schema; +select column_name, column_default from columns + where table_schema='test' and table_name='t1'; +use test; +show columns from t1; +drop table t1; + +# +# Bug #12636: SHOW TABLE STATUS with where condition containing a subquery +# over information schema +# + +CREATE TABLE t1 (a int); +CREATE TABLE t2 (b int); + +--replace_column 8 # 12 # 13 # +SHOW TABLE STATUS FROM test + WHERE name IN ( SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_SCHEMA='test' AND TABLE_TYPE='BASE TABLE'); + +DROP TABLE t1,t2; + +# +# Bug #12905 show fields from view behaving erratically with current database +# +create table t1(f1 int); +create view v1 (c) as select f1 from t1; +connect (con5,localhost,root,,*NO-ONE*); +select database(); +show fields from test.v1; +connection default; +drop view v1; +drop table t1; + +# +# Bug #9846 Inappropriate error displayed while dropping table from 'INFORMATION_SCHEMA' +# +--error 1044 +alter database information_schema; +--error 1044 +drop database information_schema; +--error 1044 +drop table information_schema.tables; +--error 1044 +alter table information_schema.tables; +# +# Bug #9683 INFORMATION_SCH: Creation of temporary table allowed in Information_schema DB +# +use information_schema; +--error 1044 +create temporary table schemata(f1 char(10)); +# +# Bug #10708 SP's can use INFORMATION_SCHEMA as ROUTINE_SCHEMA +# +delimiter |; +--error 1044 +CREATE PROCEDURE p1 () +BEGIN + SELECT 'foo' FROM DUAL; +END | +delimiter ;| +select ROUTINE_NAME from routines; +# +# Bug #10734 Grant of privileges other than 'select' and 'create view' should fail on schema +# +--error 1044 +grant all on information_schema.* to 'user1'@'localhost'; +--error 1044 +grant select on information_schema.* to 'user1'@'localhost'; + +# +# Bug#14089 FROM list subquery always fails when information_schema is current database +# +use test; +create table t1(id int); +insert into t1(id) values (1); +select 1 from (select 1 from test.t1) a; +use information_schema; +select 1 from (select 1 from test.t1) a; +use test; +drop table t1; + +# +# Bug#14476 `information_schema`.`TABLES`.`TABLE_TYPE` with empty value +# +create table t1 (f1 int(11)); +create view v1 as select * from t1; +drop table t1; +select table_type from information_schema.tables +where table_name="v1"; +drop view v1; + +# +# Bug #14387 SHOW COLUMNS doesn't work on temporary tables +# Bug #15224 SHOW INDEX from temporary table doesn't work +# Bug #12770 DESC cannot display the info. about temporary table +# +create temporary table t1(f1 int, index(f1)); +show columns from t1; +describe t1; +show indexes from t1; +drop table t1; + +# +# Bug#14271 I_S: columns has no size for (var)binary columns +# +create table t1(f1 binary(32), f2 varbinary(64)); +select character_maximum_length, character_octet_length +from information_schema.columns where table_name='t1'; +drop table t1; + +# +# Bug#15533 crash, information_schema, function, view +# +CREATE TABLE t1 (f1 BIGINT, f2 VARCHAR(20), f3 BIGINT); +INSERT INTO t1 SET f1 = 1, f2 = 'Schoenenbourg', f3 = 1; + +CREATE FUNCTION func2() RETURNS BIGINT RETURN 1; + +delimiter //; +CREATE FUNCTION func1() RETURNS BIGINT +BEGIN + RETURN ( SELECT COUNT(*) FROM INFORMATION_SCHEMA.VIEWS); +END// +delimiter ;// + +CREATE VIEW v1 AS SELECT 1 FROM t1 + WHERE f3 = (SELECT func2 ()); +SELECT func1(); +DROP TABLE t1; +DROP VIEW v1; +DROP FUNCTION func1; +DROP FUNCTION func2; + + +# +# Bug#15307 GROUP_CONCAT() with ORDER BY returns empty set on information_schema +# +select column_type, group_concat(table_schema, '.', table_name), count(*) as num +from information_schema.columns where +table_schema='information_schema' and +(column_type = 'varchar(7)' or column_type = 'varchar(20)') +group by column_type order by num; + +# +# Bug#19236 bad COLUMNS.CHARACTER_MAXIMUM_LENGHT and CHARACTER_OCTET_LENGTH +# +create table t1(f1 char(1) not null, f2 char(9) not null) +default character set utf8; +select CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH from +information_schema.columns where table_schema='test' and table_name = 't1'; +drop table t1; + +# +# Bug#18177 any access to INFORMATION_SCHEMA.ROUTINES crashes +# +use mysql; +INSERT INTO `proc` VALUES ('test','','PROCEDURE','','SQL','CONTAINS_SQL', +'NO','DEFINER','','','BEGIN\r\n \r\nEND','root@%','2006-03-02 18:40:03', +'2006-03-02 18:40:03','',''); +select routine_name from information_schema.routines; +delete from proc where name=''; +use test; + +# +# Bug#16681 information_schema shows forbidden VIEW details +# +grant select on test.* to mysqltest_1@localhost; +create table t1 (id int); +create view v1 as select * from t1; +create definer = mysqltest_1@localhost +sql security definer view v2 as select 1; + +connect (con16681,localhost,mysqltest_1,,test); +connection con16681; + +select * from information_schema.views +where table_name='v1' or table_name='v2'; +connection default; +drop view v1, v2; +drop table t1; +drop user mysqltest_1@localhost; + +# +# Bug#19599 duplication of information_schema column value in a CONCAT expr with user var +# +set @a:= '.'; +create table t1(f1 char(5)); +create table t2(f1 char(5)); +select concat(@a, table_name), @a, table_name +from information_schema.tables where table_schema = 'test'; +drop table t1,t2; + + +# +# Bug#20230: routine_definition is not null +# +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +CREATE PROCEDURE p1() SET @a= 1; +CREATE FUNCTION f1() RETURNS INT RETURN @a + 1; +CREATE USER mysql_bug20230@localhost; +GRANT EXECUTE ON PROCEDURE p1 TO mysql_bug20230@localhost; +GRANT EXECUTE ON FUNCTION f1 TO mysql_bug20230@localhost; + +SELECT ROUTINE_NAME, ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES; +SHOW CREATE PROCEDURE p1; +SHOW CREATE FUNCTION f1; + +connect (conn1, localhost, mysql_bug20230,,); + +SELECT ROUTINE_NAME, ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES; +SHOW CREATE PROCEDURE p1; +SHOW CREATE FUNCTION f1; +CALL p1(); +SELECT f1(); + +disconnect conn1; +connection default; + +DROP FUNCTION f1; +DROP PROCEDURE p1; +DROP USER mysql_bug20230@localhost; + +# +# Bug#18925: subqueries with MIN/MAX functions on INFORMARTION_SCHEMA +# + +SELECT t.table_name, c1.column_name + FROM information_schema.tables t + INNER JOIN + information_schema.columns c1 + ON t.table_schema = c1.table_schema AND + t.table_name = c1.table_name + WHERE t.table_schema = 'information_schema' AND + c1.ordinal_position = + ( SELECT COALESCE(MIN(c2.ordinal_position),1) + FROM information_schema.columns c2 + WHERE c2.table_schema = t.table_schema AND + c2.table_name = t.table_name AND + c2.column_name LIKE '%SCHEMA%' + ); +SELECT t.table_name, c1.column_name + FROM information_schema.tables t + INNER JOIN + information_schema.columns c1 + ON t.table_schema = c1.table_schema AND + t.table_name = c1.table_name + WHERE t.table_schema = 'information_schema' AND + c1.ordinal_position = + ( SELECT COALESCE(MIN(c2.ordinal_position),1) + FROM information_schema.columns c2 + WHERE c2.table_schema = 'information_schema' AND + c2.table_name = t.table_name AND + c2.column_name LIKE '%SCHEMA%' + ); + +# +# Bug#21231: query with a simple non-correlated subquery over +# INFORMARTION_SCHEMA.TABLES +# + +SELECT MAX(table_name) FROM information_schema.tables; +SELECT table_name from information_schema.tables + WHERE table_name=(SELECT MAX(table_name) + FROM information_schema.tables); + +# +# Bug #23037: Bug in field "Default" of query "SHOW COLUMNS FROM table" +# +# Note, MyISAM/InnoDB can't take more that 65532 chars, because the row +# size is limited to 65535 bytes (BLOBs not counted) +# +--disable_warnings +DROP TABLE IF EXISTS bug23037; +DROP FUNCTION IF EXISTS get_value; +--enable_warnings +--disable_query_log +DELIMITER |; +CREATE FUNCTION get_value() + RETURNS TEXT + DETERMINISTIC +BEGIN + DECLARE col1, col2, col3, col4, col6 CHAR(255); + DECLARE default_val VARCHAR(65532); + DECLARE done INT DEFAULT 0; + DECLARE cur1 CURSOR FOR SHOW COLUMNS FROM bug23037; + DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; + OPEN cur1; + FETCH cur1 INTO col1, col2, col3, col4, default_val, col6; + CLOSE cur1; + RETURN default_val; +end| +DELIMITER ;| + +let $body=`SELECT REPEAT('A', 65532)`; +eval CREATE TABLE bug23037(fld1 VARCHAR(65532) CHARACTER SET latin1 DEFAULT "$body"); +--enable_query_log + +SELECT COLUMN_NAME, MD5(COLUMN_DEFAULT), LENGTH(COLUMN_DEFAULT) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='bug23037'; + +SELECT MD5(get_value()); + +SELECT COLUMN_NAME, MD5(COLUMN_DEFAULT), LENGTH(COLUMN_DEFAULT), COLUMN_DEFAULT=get_value() FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='bug23037'; + +DROP TABLE bug23037; +DROP FUNCTION get_value; + + + +# End of 5.0 tests. diff --git a/mysql-test/t/information_schema_chmod.test b/mysql-test/t/information_schema_chmod.test new file mode 100644 index 00000000000..c7ea2b03890 --- /dev/null +++ b/mysql-test/t/information_schema_chmod.test @@ -0,0 +1,23 @@ +# +# Due to "Bug#18474 Unlistable directories yield no info from +# information_schema, part2" this test can't be run on Window with our +# current test framework. When "chmod -r" is done within cygwin the +# MySQL Server can still read the directory. +# Manual testing shows the functionalty to skip unlistable directories +# works on windows +# +--source include/not_windows.inc + +# This test uses chmod, can't be run with root permissions +-- source include/not_as_root.inc + + +# +# Bug #15851 Unlistable directories yield no info from information_schema +# +create database mysqltest; +create table mysqltest.t1(a int); +--exec chmod -r $MYSQLTEST_VARDIR/master-data/mysqltest +select table_schema from information_schema.tables where table_schema='mysqltest'; +--exec chmod +r $MYSQLTEST_VARDIR/master-data/mysqltest +drop database mysqltest; diff --git a/mysql-test/t/information_schema_db.test b/mysql-test/t/information_schema_db.test new file mode 100644 index 00000000000..4dfe1ad56b5 --- /dev/null +++ b/mysql-test/t/information_schema_db.test @@ -0,0 +1,157 @@ +-- source include/testdb_only.inc + +--disable_warnings +drop table if exists t1,t2; +drop view if exists v1,v2; +drop function if exists f1; +drop function if exists f2; +--enable_warnings + +use INFORMATION_SCHEMA; +--replace_result Tables_in_INFORMATION_SCHEMA Tables_in_information_schema +show tables; +--replace_result 'Tables_in_INFORMATION_SCHEMA (T%)' 'Tables_in_information_schema (T%)' +show tables from INFORMATION_SCHEMA like 'T%'; +create database `inf%`; +create database mbase; +use `inf%`; +show tables; + +# +# Bug#18113 SELECT * FROM information_schema.xxx crashes server +# Bug#17204 second CALL to procedure crashes Server +# Crash happened when one selected data from one of INFORMATION_SCHEMA +# tables and in order to build its contents server had to open view which +# used stored function and table or view on which one had not global or +# database-level privileges (e.g. had only table-level or had no +# privileges at all). +# +grant all privileges on `inf%`.* to 'mysqltest_1'@'localhost'; +grant all privileges on `mbase`.* to 'mysqltest_1'@'localhost'; +create table t1 (f1 int); +delimiter |; +create function func1(curr_int int) returns int +begin + declare ret_val int; + select max(f1) from t1 into ret_val; + return ret_val; +end| +delimiter ;| +create view v1 as select f1 from t1 where f1 = func1(f1); +create function func2() returns int return 1; + +use mbase; +delimiter |; +create procedure p1 () +begin +select table_name from information_schema.key_column_usage +order by table_name; +end| +delimiter ;| + +create table t1 +(f1 int(10) unsigned not null, + f2 varchar(100) not null, + primary key (f1), unique key (f2)); + +connect (user1,localhost,mysqltest_1,,); +connection user1; +--disable_result_log +select * from information_schema.tables; +call mbase.p1(); +call mbase.p1(); +call mbase.p1(); +--enable_result_log + +connection default; +use `inf%`; +drop user mysqltest_1@localhost; +drop table t1; +select table_name, table_type, table_comment from information_schema.tables +where table_schema='inf%' and func2(); +select table_name, table_type, table_comment from information_schema.tables +where table_schema='inf%' and func2(); +drop view v1; +drop function func1; +drop function func2; + +drop database `inf%`; +drop procedure mbase.p1; +drop database mbase; + +# +# Bug#18282 INFORMATION_SCHEMA.TABLES provides inconsistent info about invalid views +# +use test; +create table t1 (i int); +create function f1 () returns int return (select max(i) from t1); +create view v1 as select f1(); +create table t2 (id int); +create function f2 () returns int return (select max(i) from t2); +create view v2 as select f2(); +drop table t2; +select table_name, table_type, table_comment from information_schema.tables +where table_schema='test'; +drop table t1; +select table_name, table_type, table_comment from information_schema.tables +where table_schema='test'; +drop function f1; +drop function f2; +drop view v1, v2; + +# +# Bug#20543: select on information_schema strange warnings, view, different +# schemas/users +# +# +create database testdb_1; +create user testdb_1@localhost; +grant all on testdb_1.* to testdb_1@localhost with grant option; + +create user testdb_2@localhost; +grant all on test.* to testdb_2@localhost with grant option; + +connect (testdb_1,localhost,testdb_1,,test); +use testdb_1; +create table t1 (f1 char(4)); +create view v1 as select f1 from t1; +grant insert on v1 to testdb_2@localhost; + +create table t3 (f1 char(4), f2 char(4)); +create view v3 as select f1,f2 from t3; +grant insert(f1), insert(f2) on v3 to testdb_2@localhost; + +connect (testdb_2,localhost,testdb_2,,test); +create view v2 as select f1 from testdb_1.v1; +create view v4 as select f1,f2 from testdb_1.v3; + +connection testdb_1; +revoke insert(f1) on v3 from testdb_2@localhost; +connection testdb_2; + +--error 1345 +show create view v4; +--error 1345 +show fields from v4; + +show fields from v2; +show fields from testdb_1.v1; +show create view v2; +--error 1142 +show create view testdb_1.v1; + +select table_name from information_schema.columns a +where a.table_name = 'v2'; +select view_definition from information_schema.views a +where a.table_name = 'v2'; +select view_definition from information_schema.views a +where a.table_name = 'testdb_1.v1'; + +--error 1356 +select * from v2; + +connection default; +drop view testdb_1.v1,v2, testdb_1.v3, v4; +drop database testdb_1; +drop user testdb_1@localhost; +drop user testdb_2@localhost; diff --git a/mysql-test/t/information_schema_inno.test b/mysql-test/t/information_schema_inno.test new file mode 100644 index 00000000000..9cd64a54ad9 --- /dev/null +++ b/mysql-test/t/information_schema_inno.test @@ -0,0 +1,23 @@ +-- source include/have_innodb.inc +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3; +--enable_warnings + +# +# Test for KEY_COLUMN_USAGE & TABLE_CONSTRAINTS tables +# + +CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB; +CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id, id), +FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE, +FOREIGN KEY (t1_id) REFERENCES t1(id) ON UPDATE CASCADE) ENGINE=INNODB; + +CREATE TABLE t3 (id INT PRIMARY KEY, t2_id INT, INDEX par_ind (t2_id), +FOREIGN KEY (id, t2_id) REFERENCES t2(t1_id, id) ON DELETE CASCADE) ENGINE=INNODB; + +select * from information_schema.TABLE_CONSTRAINTS where +TABLE_SCHEMA= "test"; +select * from information_schema.KEY_COLUMN_USAGE where +TABLE_SCHEMA= "test"; + +drop table t3, t2, t1; diff --git a/mysql-test/t/init_connect.test b/mysql-test/t/init_connect.test index 7ceaef1aad7..31a98df33df 100644 --- a/mysql-test/t/init_connect.test +++ b/mysql-test/t/init_connect.test @@ -21,7 +21,7 @@ connect (con3,localhost,user_1,,); connection con3; select @a; connection con0; -set global init_connect="create table t1(a char(10));\ +set global init_connect="drop table if exists t1; create table t1(a char(10));\ insert into t1 values ('\0');insert into t1 values('abc')"; connect (con4,localhost,user_1,,); connection con4; @@ -35,4 +35,205 @@ select @a; connection con0; drop table t1; -# End of 4.1 tests +disconnect con1; +disconnect con2; +disconnect con3; +disconnect con4; +disconnect con5; + +--echo End of 4.1 tests +# +# Test 5.* features +# + +create table t1 (x int); +insert into t1 values (3), (5), (7); +create table t2 (y int); + +create user mysqltest1@localhost; +grant all privileges on test.* to mysqltest1@localhost; +# +# Create a simple procedure +# +set global init_connect="create procedure p1() select * from t1"; +connect (con1,localhost,mysqltest1,,); +connection con1; +call p1(); +drop procedure p1; + +connection con0; +disconnect con1; +# +# Create a multi-result set procedure +# +set global init_connect="create procedure p1(x int)\ +begin\ + select count(*) from t1;\ + select * from t1;\ + set @x = x; +end"; +connect (con1,localhost,mysqltest1,,); +connection con1; +call p1(42); +select @x; + +connection con0; +disconnect con1; +# +# Just call it - this will not generate any output +# +set global init_connect="call p1(4711)"; +connect (con1,localhost,mysqltest1,,); +connection con1; +select @x; + +connection con0; +disconnect con1; +# +# Drop the procedure +# +set global init_connect="drop procedure if exists p1"; +connect (con1,localhost,mysqltest1,,); +connection con1; +--error ER_SP_DOES_NOT_EXIST +call p1(); + +connection con0; +disconnect con1; +# +# Execution of a more complex procedure +# +delimiter |; +create procedure p1(out sum int) +begin + declare n int default 0; + declare c cursor for select * from t1; + declare exit handler for not found + begin + close c; + set sum = n; + end; + + open c; + loop + begin + declare x int; + + fetch c into x; + if x > 3 then + set n = n + x; + end if; + end; + end loop; +end| +delimiter ;| +# Call the procedure with a cursor +set global init_connect="call p1(@sum)"; +connect (con1,localhost,mysqltest1,,); +connection con1; +select @sum; + +connection con0; +disconnect con1; +drop procedure p1; +# +# Test Dynamic SQL +# +delimiter |; +create procedure p1(tbl char(10), v int) +begin + set @s = concat('insert into ', tbl, ' values (?)'); + set @v = v; + prepare stmt1 from @s; + execute stmt1 using @v; + deallocate prepare stmt1; +end| +delimiter ;| +# Call the procedure with prepared statements +set global init_connect="call p1('t1', 11)"; +connect (con1,localhost,mysqltest1,,); +connection con1; +select * from t1; + +connection con0; +disconnect con1; +drop procedure p1; +# +# Stored functions +# +delimiter |; +create function f1() returns int +begin + declare n int; + + select count(*) into n from t1; + return n; +end| +delimiter ;| +# Invoke a function +set global init_connect="set @x = f1()"; +connect (con1,localhost,mysqltest1,,); +connection con1; +select @x; + +connection con0; +disconnect con1; +# +# Create a view +# +set global init_connect="create view v1 as select f1()"; +connect (con1,localhost,mysqltest1,,); +connection con1; +select * from v1; + +connection con0; +disconnect con1; +# +# Drop the view +# +set global init_connect="drop view v1"; +connect (con1,localhost,mysqltest1,,); +connection con1; +--error ER_NO_SUCH_TABLE +select * from v1; + +connection con0; +disconnect con1; +drop function f1; + +# We can't test "create trigger", since this requires super privileges +# in 5.0, but with super privileges, init_connect is not executed. +# (However, this can be tested in 5.1) +# +#set global init_connect="create trigger trg1\ +# after insert on t2\ +# for each row\ +# insert into t1 values (new.y)"; +#connect (con1,localhost,mysqltest1,,); +#connection con1; +#insert into t2 values (2), (4); +#select * from t1; +# +#connection con0; +#disconnect con1; + +create trigger trg1 + after insert on t2 + for each row + insert into t1 values (new.y); + +# Invoke trigger +set global init_connect="insert into t2 values (13), (17), (19)"; +connect (con1,localhost,mysqltest1,,); +connection con1; +select * from t1; + +connection con0; +disconnect con1; + +drop trigger trg1; +set global init_connect=default; + +revoke all privileges, grant option from mysqltest1@localhost; +drop user mysqltest1@localhost; +drop table t1, t2; diff --git a/mysql-test/t/init_file.test b/mysql-test/t/init_file.test index bbe0c4ff884..31a6ef5a541 100644 --- a/mysql-test/t/init_file.test +++ b/mysql-test/t/init_file.test @@ -7,4 +7,14 @@ # --echo ok ---echo End of 4.1 tests +--echo end of 4.1 tests +# +# Chec 5.x features +# +# Expected: +# 3, 5, 7, 11, 13 +select * from t1; +# Expected: +# 30, 3, 11, 13 +select * from t2; +drop table t1, t2; diff --git a/mysql-test/t/innodb-big.test b/mysql-test/t/innodb-big.test new file mode 100644 index 00000000000..ade69ffdb45 --- /dev/null +++ b/mysql-test/t/innodb-big.test @@ -0,0 +1,46 @@ +# +# Test some things that takes a long time + +-- source include/big_test.inc +-- source include/have_innodb.inc + +--disable_warnings +DROP TABLE IF EXISTS t1, t2, t3, t4; +--enable_warnings + +# +# Test test how filesort and buffered-record-reads works with innodb +# + +CREATE TABLE t1 (id INTEGER) ENGINE=MYISAM; +CREATE TABLE t2 (id INTEGER primary key) ENGINE=INNODB; +CREATE TABLE t3 (a char(32) primary key,id INTEGER) ENGINE=INNODB; +CREATE TABLE t4 (a char(32) primary key,id INTEGER) ENGINE=MYISAM; + +INSERT INTO t1 (id) VALUES (1); +INSERT INTO t1 SELECT id+1 FROM t1; +INSERT INTO t1 SELECT id+2 FROM t1; +INSERT INTO t1 SELECT id+4 FROM t1; +INSERT INTO t1 SELECT id+8 FROM t1; +INSERT INTO t1 SELECT id+16 FROM t1; +INSERT INTO t1 SELECT id+32 FROM t1; +INSERT INTO t1 SELECT id+64 FROM t1; +INSERT INTO t1 SELECT id+128 FROM t1; +INSERT INTO t1 SELECT id+256 FROM t1; +INSERT INTO t1 SELECT id+512 FROM t1; +INSERT INTO t1 SELECT id+1024 FROM t1; +INSERT INTO t1 SELECT id+2048 FROM t1; +INSERT INTO t1 SELECT id+4096 FROM t1; +INSERT INTO t1 SELECT id+8192 FROM t1; +INSERT INTO t1 SELECT id+16384 FROM t1; +INSERT INTO t1 SELECT id+32768 FROM t1; +INSERT INTO t1 SELECT id+65536 FROM t1; +INSERT INTO t1 SELECT id+131072 FROM t1; +INSERT INTO t1 SELECT id+262144 FROM t1; +INSERT INTO t1 SELECT id+524288 FROM t1; +INSERT INTO t1 SELECT id+1048576 FROM t1; +INSERT INTO t2 SELECT * FROM t1; +INSERT INTO t3 SELECT concat(id),id from t2 ORDER BY -id; +INSERT INTO t4 SELECT * from t3 ORDER BY concat(a); +select sum(id) from t3; +drop table t1,t2,t3,t4; diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test index 3e53cadf76c..0c083ccdfd3 100644 --- a/mysql-test/t/innodb.test +++ b/mysql-test/t/innodb.test @@ -142,6 +142,32 @@ insert into t1 values (6); -- error 1062 insert into t1 values (4); select n from t1; +set autocommit=0; +# +# savepoints +# +begin; +savepoint `my_savepoint`; +insert into t1 values (7); +savepoint `savept2`; +insert into t1 values (3); +select n from t1; +savepoint savept3; +rollback to savepoint savept2; +--error 1305 +rollback to savepoint savept3; +rollback to savepoint savept2; +release savepoint `my_savepoint`; +select n from t1; +-- error 1305 +rollback to savepoint `my_savepoint`; +--error 1305 +rollback to savepoint savept2; +insert into t1 values (8); +savepoint sv; +commit; +savepoint sv; +set autocommit=1; # nop rollback; drop table t1; @@ -428,6 +454,7 @@ set @a:=now(); CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb; insert into t1 (a) values(1),(2),(3); select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a; +select a from t1 natural join t1 as t2 where b >= @a order by a; update t1 set a=5 where a=1; select a from t1; drop table t1; @@ -573,7 +600,7 @@ insert into mysqltest.t3 values(1); commit; drop database mysqltest; # Don't check error message ---error 12,12 +--error 1049 show tables from mysqltest; # @@ -647,9 +674,9 @@ CREATE TABLE t1 ( cname char(15) NOT NULL default '', carrier_id smallint(6) NOT NULL default '0', privacy tinyint(4) NOT NULL default '0', - last_mod_date timestamp(14) NOT NULL, + last_mod_date timestamp NOT NULL, last_mod_id smallint(6) NOT NULL default '0', - last_app_date timestamp(14) NOT NULL, + last_app_date timestamp NOT NULL, last_app_id smallint(6) default '-1', version smallint(6) NOT NULL default '0', assigned_scps int(11) default '0', @@ -666,9 +693,9 @@ CREATE TABLE t2 ( cname char(15) NOT NULL default '', carrier_id smallint(6) NOT NULL default '0', privacy tinyint(4) NOT NULL default '0', - last_mod_date timestamp(14) NOT NULL, + last_mod_date timestamp NOT NULL, last_mod_id smallint(6) NOT NULL default '0', - last_app_date timestamp(14) NOT NULL, + last_app_date timestamp NOT NULL, last_app_id smallint(6) default '-1', version smallint(6) NOT NULL default '0', assigned_scps int(11) default '0', @@ -964,11 +991,11 @@ create table `t2` (`id` int( 11 ) not null default '0',unique key `id` ( `id` ) insert into `t2`values ( 1 ) ; create table `t3` (`id` int( 11 ) not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = innodb; insert into `t3`values ( 1 ) ; ---error 1217 +--error 1451 delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id; ---error 1217 +--error 1451 update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id; ---error 1109 +--error 1054 update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id; drop table t3,t2,t1; @@ -982,7 +1009,7 @@ create table t1( foreign key(pid) references t1(id) on delete cascade) engine=innodb; insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6), (8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14); --- error 1217 +-- error 1451 delete from t1 where id=0; delete from t1 where id=15; delete from t1 where id=0; @@ -1011,7 +1038,7 @@ CREATE TABLE t1 ( `id` int(10) unsigned NOT NULL auto_increment, `id_object` int(10) unsigned default '0', `id_version` int(10) unsigned NOT NULL default '1', - label varchar(100) NOT NULL default '', + `label` varchar(100) NOT NULL default '', `description` text, PRIMARY KEY (`id`), KEY `id_object` (`id_object`), @@ -1029,8 +1056,8 @@ CREATE TABLE t2 ( INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9"); -SELECT t2.id, t1.label FROM t2 INNER JOIN -(SELECT t1.id_object as id_object FROM t1 WHERE t1.label LIKE '%test%') AS lbl +SELECT t2.id, t1.`label` FROM t2 INNER JOIN +(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object); drop table t1,t2; @@ -1052,7 +1079,7 @@ drop table t1,t2,t3; # create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb; insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt'); -select name2 from t1 union all select name from t1 union all select id from t1; +select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1; drop table t1; # @@ -1110,7 +1137,10 @@ show create table t2; drop table t2; # Test error handling ---replace_result \\ / $MYSQL_TEST_DIR . /var/master-data/ / + +# Clean up filename -- embedded server reports whole path without .frm, +# regular server reports relative path with .frm (argh!) +--replace_result \\ / $MYSQL_TEST_DIR . /var/master-data/ / t2.frm t2 --error 1005 create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb; @@ -1156,7 +1186,6 @@ delete from t1; commit; show status like "binlog_cache_use"; show status like "binlog_cache_disk_use"; - drop table t1; # @@ -1253,45 +1282,492 @@ select min(a) from t1; select min(b) from t1 where a='8'; drop table t1; +# End of 4.1 tests + +# +# range optimizer problem +# + +create table t1 (x bigint unsigned not null primary key) engine=innodb; +insert into t1(x) values (0xfffffffffffffff0),(0xfffffffffffffff1); +select * from t1; +select count(*) from t1 where x>0; +select count(*) from t1 where x=0; +select count(*) from t1 where x<0; +select count(*) from t1 where x < -16; +select count(*) from t1 where x = -16; +explain select count(*) from t1 where x > -16; +select count(*) from t1 where x > -16; +select * from t1 where x > -16; +select count(*) from t1 where x = 18446744073709551601; +drop table t1; + + +# Test for testable InnoDB status variables. This test +# uses previous ones(pages_created, rows_deleted, ...). +show status like "Innodb_buffer_pool_pages_total"; +show status like "Innodb_page_size"; +show status like "Innodb_rows_deleted"; +show status like "Innodb_rows_inserted"; +show status like "Innodb_rows_updated"; + +# Test for row locks InnoDB status variables. +show status like "Innodb_row_lock_waits"; +show status like "Innodb_row_lock_current_waits"; +show status like "Innodb_row_lock_time"; +show status like "Innodb_row_lock_time_max"; +show status like "Innodb_row_lock_time_avg"; + +# Test for innodb_sync_spin_loops variable +show variables like "innodb_sync_spin_loops"; +set global innodb_sync_spin_loops=1000; +show variables like "innodb_sync_spin_loops"; +set global innodb_sync_spin_loops=0; +show variables like "innodb_sync_spin_loops"; +set global innodb_sync_spin_loops=20; +show variables like "innodb_sync_spin_loops"; + +# Test for innodb_thread_concurrency variable +show variables like "innodb_thread_concurrency"; +set global innodb_thread_concurrency=1001; +show variables like "innodb_thread_concurrency"; +set global innodb_thread_concurrency=0; +show variables like "innodb_thread_concurrency"; +set global innodb_thread_concurrency=16; +show variables like "innodb_thread_concurrency"; + +# Test for innodb_concurrency_tickets variable +show variables like "innodb_concurrency_tickets"; +set global innodb_concurrency_tickets=1000; +show variables like "innodb_concurrency_tickets"; +set global innodb_concurrency_tickets=0; +show variables like "innodb_concurrency_tickets"; +set global innodb_concurrency_tickets=500; +show variables like "innodb_concurrency_tickets"; + +# Test for innodb_thread_sleep_delay variable +show variables like "innodb_thread_sleep_delay"; +set global innodb_thread_sleep_delay=100000; +show variables like "innodb_thread_sleep_delay"; +set global innodb_thread_sleep_delay=0; +show variables like "innodb_thread_sleep_delay"; +set global innodb_thread_sleep_delay=10000; +show variables like "innodb_thread_sleep_delay"; + +# +# Test varchar +# + +let $default=`select @@storage_engine`; +set storage_engine=INNODB; +source include/varchar.inc; + +# +# Some errors/warnings on create +# + +# Clean up filename -- embedded server reports whole path without .frm, +# regular server reports relative path with .frm (argh!) +--replace_result \\ / $MYSQL_TEST_DIR . /var/master-data/ / t1.frm t1 +create table t1 (v varchar(65530), key(v)); +drop table t1; +create table t1 (v varchar(65536)); +show create table t1; +drop table t1; +create table t1 (v varchar(65530) character set utf8); +show create table t1; +drop table t1; + +eval set storage_engine=$default; + +# InnoDB specific varchar tests +create table t1 (v varchar(16384)) engine=innodb; +drop table t1; + +# +# BUG#11039 Wrong key length in min() +# + +create table t1 (a char(1), b char(1), key(a, b)) engine=innodb; +insert into t1 values ('8', '6'), ('4', '7'); +select min(a) from t1; +select min(b) from t1 where a='8'; +drop table t1; + +# +# Bug #11080 & #11005 Multi-row REPLACE fails on a duplicate key error +# + +CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb; +insert into t1 (b) values (1); +replace into t1 (b) values (2), (1), (3); +select * from t1; +truncate table t1; +insert into t1 (b) values (1); +replace into t1 (b) values (2); +replace into t1 (b) values (1); +replace into t1 (b) values (3); +select * from t1; +drop table t1; + +create table t1 (rowid int not null auto_increment, val int not null,primary +key (rowid), unique(val)) engine=innodb; +replace into t1 (val) values ('1'),('2'); +replace into t1 (val) values ('1'),('2'); +--error 1062 +insert into t1 (val) values ('1'),('2'); +select * from t1; +drop table t1; + +# +# Test that update does not change internal auto-increment value +# + +create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB; +insert into t1 (val) values (1); +update t1 set a=2 where a=1; +# We should get the following error because InnoDB does not update the counter +--error 1062 +insert into t1 (val) values (1); +select * from t1; +drop table t1; +# +# Bug #10465 +# + +--disable_warnings +CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB; +--enable_warnings +INSERT INTO t1 (GRADE) VALUES (151),(252),(343); +SELECT GRADE FROM t1 WHERE GRADE > 160 AND GRADE < 300; +SELECT GRADE FROM t1 WHERE GRADE= 151; +DROP TABLE t1; + +# +# Bug #12340 multitable delete deletes only one record +# +create table t1 (f1 varchar(10), f2 varchar(10), primary key (f1,f2)) engine=innodb; +create table t2 (f3 varchar(10), f4 varchar(10), key (f4)) engine=innodb; +insert into t2 values ('aa','cc'); +insert into t1 values ('aa','bb'),('aa','cc'); +delete t1 from t1,t2 where f1=f3 and f4='cc'; +select * from t1; +drop table t1,t2; + +# +# Test that the slow TRUNCATE implementation resets autoincrement columns +# (bug #11946) +# + +CREATE TABLE t1 ( +id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) +) ENGINE=InnoDB; + +CREATE TABLE t2 ( +id INTEGER NOT NULL, +FOREIGN KEY (id) REFERENCES t1 (id) +) ENGINE=InnoDB; + +INSERT INTO t1 (id) VALUES (NULL); +SELECT * FROM t1; +TRUNCATE t1; +INSERT INTO t1 (id) VALUES (NULL); +SELECT * FROM t1; + +# continued from above; test that doing a slow TRUNCATE on a table with 0 +# rows resets autoincrement columns +DELETE FROM t1; +TRUNCATE t1; +INSERT INTO t1 (id) VALUES (NULL); +SELECT * FROM t1; +DROP TABLE t2, t1; + +-- Test that foreign keys in temporary tables are not accepted (bug #12084) +CREATE TABLE t1 +( + id INT PRIMARY KEY +) ENGINE=InnoDB; + +--error 1005,1005 +CREATE TEMPORARY TABLE t2 +( + id INT NOT NULL PRIMARY KEY, + b INT, + FOREIGN KEY (b) REFERENCES test.t1(id) +) ENGINE=InnoDB; +DROP TABLE t1; + +# +# Test that index column max sizes are honored (bug #13315) +# + +# prefix index +create table t1 (col1 varchar(2000), index (col1(767))) + character set = latin1 engine = innodb; + +# normal indexes +create table t2 (col1 char(255), index (col1)) + character set = latin1 engine = innodb; +create table t3 (col1 binary(255), index (col1)) + character set = latin1 engine = innodb; +create table t4 (col1 varchar(767), index (col1)) + character set = latin1 engine = innodb; +create table t5 (col1 varchar(767) primary key) + character set = latin1 engine = innodb; +create table t6 (col1 varbinary(767) primary key) + character set = latin1 engine = innodb; +create table t7 (col1 text, index(col1(767))) + character set = latin1 engine = innodb; +create table t8 (col1 blob, index(col1(767))) + character set = latin1 engine = innodb; + +# multi-column indexes are allowed to be longer +create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2)) + character set = latin1 engine = innodb; + +show create table t9; + +drop table t1, t2, t3, t4, t5, t6, t7, t8, t9; + +# these should have their index length trimmed +create table t1 (col1 varchar(768), index(col1)) + character set = latin1 engine = innodb; +create table t2 (col1 varbinary(768), index(col1)) + character set = latin1 engine = innodb; +create table t3 (col1 text, index(col1(768))) + character set = latin1 engine = innodb; +create table t4 (col1 blob, index(col1(768))) + character set = latin1 engine = innodb; + +show create table t1; + +drop table t1, t2, t3, t4; + +# these should be refused +--error 1071 +create table t1 (col1 varchar(768) primary key) + character set = latin1 engine = innodb; +--error 1071 +create table t2 (col1 varbinary(768) primary key) + character set = latin1 engine = innodb; +--error 1071 +create table t3 (col1 text, primary key(col1(768))) + character set = latin1 engine = innodb; +--error 1071 +create table t4 (col1 blob, primary key(col1(768))) + character set = latin1 engine = innodb; + +# +# Test improved foreign key error messages (bug #3443) +# + +CREATE TABLE t1 +( + id INT PRIMARY KEY +) ENGINE=InnoDB; + +CREATE TABLE t2 +( + v INT, + CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id) +) ENGINE=InnoDB; + +--error 1452 +INSERT INTO t2 VALUES(2); + +INSERT INTO t1 VALUES(1); +INSERT INTO t2 VALUES(1); + +--error 1451 +DELETE FROM t1 WHERE id = 1; + +--error 1217 +DROP TABLE t1; + +SET FOREIGN_KEY_CHECKS=0; +DROP TABLE t1; +SET FOREIGN_KEY_CHECKS=1; + +--error 1452 +INSERT INTO t2 VALUES(3); + +DROP TABLE t2; # # Test that checksum table uses a consistent read Bug #12669 # connect (a,localhost,root,,); connect (b,localhost,root,,); connection a; -create table test_checksum(a int not null) engine=innodb DEFAULT CHARSET=latin1; -insert into test_checksum values (1),(2); +create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1; +insert into t1 values (1),(2); set autocommit=0; -checksum table test_checksum; +checksum table t1; connection b; -insert into test_checksum values(3); +insert into t1 values(3); connection a; # # Here checksum should not see insert # -checksum table test_checksum; +checksum table t1; connection a; commit; -checksum table test_checksum; +checksum table t1; commit; -drop table test_checksum; +drop table t1; # # autocommit = 1 # connection a; -create table test_checksum(a int not null) engine=innodb DEFAULT CHARSET=latin1; -insert into test_checksum values (1),(2); +create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1; +insert into t1 values (1),(2); set autocommit=1; -checksum table test_checksum; +checksum table t1; connection b; set autocommit=1; -insert into test_checksum values(3); +insert into t1 values(3); connection a; # # Here checksum sees insert # -checksum table test_checksum; -drop table test_checksum; +checksum table t1; +drop table t1; + +connection default; +disconnect a; +disconnect b; + +# +# BUG 14056 Column prefix index on UTF-8 primary key column causes: Can't find record.. +# + +create table t1 ( + a int, b char(10), c char(10), filler char(10), primary key(a, b(2)), unique key (a, c(2)) +) character set utf8 engine = innodb; +create table t2 ( + a int, b char(10), c char(10), filler char(10), primary key(a, b(2)), unique key (a, c(2)) +) character set ucs2 engine = innodb; +insert into t1 values (1,'abcdefg','abcdefg','one'); +insert into t1 values (2,'ijkilmn','ijkilmn','two'); +insert into t1 values (3,'qrstuvw','qrstuvw','three'); +insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four'); +insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five'); +insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six'); +insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven'); +insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight'); +insert into t2 values (1,'abcdefg','abcdefg','one'); +insert into t2 values (2,'ijkilmn','ijkilmn','two'); +insert into t2 values (3,'qrstuvw','qrstuvw','three'); +insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four'); +insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five'); +insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six'); +insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven'); +insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight'); +insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten'); +insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven'); +insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point'); +insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken'); +update t1 set filler = 'boo' where a = 1; +update t2 set filler ='email' where a = 4; +select a,hex(b),hex(c),filler from t1 order by filler; +select a,hex(b),hex(c),filler from t2 order by filler; +drop table t1; +drop table t2; + +create table t1 ( + a int, b varchar(10), c varchar(10), filler varchar(10), primary key(a, b(2)), unique key (a, c(2)) +) character set utf8 engine = innodb; +create table t2 ( + a int, b varchar(10), c varchar(10), filler varchar(10), primary key(a, b(2)), unique key (a, c(2)) +) character set ucs2 engine = innodb; +insert into t1 values (1,'abcdefg','abcdefg','one'); +insert into t1 values (2,'ijkilmn','ijkilmn','two'); +insert into t1 values (3,'qrstuvw','qrstuvw','three'); +insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four'); +insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five'); +insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six'); +insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven'); +insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight'); +insert into t2 values (1,'abcdefg','abcdefg','one'); +insert into t2 values (2,'ijkilmn','ijkilmn','two'); +insert into t2 values (3,'qrstuvw','qrstuvw','three'); +insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four'); +insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five'); +insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six'); +insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven'); +insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight'); +insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten'); +insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven'); +insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point'); +insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken'); +update t1 set filler = 'boo' where a = 1; +update t2 set filler ='email' where a = 4; +select a,hex(b),hex(c),filler from t1 order by filler; +select a,hex(b),hex(c),filler from t2 order by filler; +drop table t1; +drop table t2; + +create table t1 ( + a int, b text(10), c text(10), filler text(10), primary key(a, b(2)), unique key (a, c(2)) +) character set utf8 engine = innodb; +create table t2 ( + a int, b text(10), c text(10), filler text(10), primary key(a, b(2)), unique key (a, c(2)) +) character set ucs2 engine = innodb; +insert into t1 values (1,'abcdefg','abcdefg','one'); +insert into t1 values (2,'ijkilmn','ijkilmn','two'); +insert into t1 values (3,'qrstuvw','qrstuvw','three'); +insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four'); +insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five'); +insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six'); +insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven'); +insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight'); +insert into t2 values (1,'abcdefg','abcdefg','one'); +insert into t2 values (2,'ijkilmn','ijkilmn','two'); +insert into t2 values (3,'qrstuvw','qrstuvw','three'); +insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four'); +insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five'); +insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six'); +insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven'); +insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight'); +insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten'); +insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven'); +insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point'); +insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken'); +update t1 set filler = 'boo' where a = 1; +update t2 set filler ='email' where a = 4; +select a,hex(b),hex(c),filler from t1 order by filler; +select a,hex(b),hex(c),filler from t2 order by filler; +drop table t1; +drop table t2; + +create table t1 ( + a int, b blob(10), c blob(10), filler blob(10), primary key(a, b(2)), unique key (a, c(2)) +) character set utf8 engine = innodb; +create table t2 ( + a int, b blob(10), c blob(10), filler blob(10), primary key(a, b(2)), unique key (a, c(2)) +) character set ucs2 engine = innodb; +insert into t1 values (1,'abcdefg','abcdefg','one'); +insert into t1 values (2,'ijkilmn','ijkilmn','two'); +insert into t1 values (3,'qrstuvw','qrstuvw','three'); +insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four'); +insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five'); +insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight'); +insert into t2 values (1,'abcdefg','abcdefg','one'); +insert into t2 values (2,'ijkilmn','ijkilmn','two'); +insert into t2 values (3,'qrstuvw','qrstuvw','three'); +insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four'); +insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five'); +insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six'); +insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven'); +insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight'); +insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten'); +insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken'); +update t1 set filler = 'boo' where a = 1; +update t2 set filler ='email' where a = 4; +select a,hex(b),hex(c),filler from t1 order by filler; +select a,hex(b),hex(c),filler from t2 order by filler; +drop table t1; +drop table t2; +commit; # tests for bugs #9802 and #13778 @@ -1299,6 +1775,7 @@ drop table test_checksum; set foreign_key_checks=0; create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb; +--replace_result $MYSQLTEST_VARDIR . master-data/ '' -- error 1005 create table t1(a char(10) primary key, b varchar(20)) engine = innodb; set foreign_key_checks=1; @@ -1309,6 +1786,7 @@ drop table t2; set foreign_key_checks=0; create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1; +--replace_result $MYSQLTEST_VARDIR . master-data/ '' -- error 1005 create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=utf8; set foreign_key_checks=1; @@ -1338,11 +1816,192 @@ drop table t2,t1; set foreign_key_checks=0; create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1; create table t3(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=utf8; +--replace_result $MYSQLTEST_VARDIR . master-data/ '' -- error 1025 rename table t3 to t1; set foreign_key_checks=1; drop table t2,t3; +# test that foreign key errors are reported correctly (Bug #15550) + +create table t1(a int primary key) row_format=redundant engine=innodb; +create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb; +create table t3(a int primary key) row_format=compact engine=innodb; +create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb; + +insert into t1 values(1); +insert into t3 values(1); +-- error 1452 +insert into t2 values(2); +-- error 1452 +insert into t4 values(2); +insert into t2 values(1); +insert into t4 values(1); +-- error 1451 +update t1 set a=2; +-- error 1452 +update t2 set a=2; +-- error 1451 +update t3 set a=2; +-- error 1452 +update t4 set a=2; +-- error 1451 +truncate t1; +-- error 1451 +truncate t3; +truncate t2; +truncate t4; +truncate t1; +truncate t3; + +drop table t4,t3,t2,t1; + + +# +# Test that we can create a large (>1K) key +# +create table t1 (a varchar(255) character set utf8, + b varchar(255) character set utf8, + c varchar(255) character set utf8, + d varchar(255) character set utf8, + key (a,b,c,d)) engine=innodb; +drop table t1; +--error ER_TOO_LONG_KEY +create table t1 (a varchar(255) character set utf8, + b varchar(255) character set utf8, + c varchar(255) character set utf8, + d varchar(255) character set utf8, + e varchar(255) character set utf8, + key (a,b,c,d,e)) engine=innodb; + + +# test the padding of BINARY types and collations (Bug #14189) + +create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb; +create table t2 (s1 binary(2),primary key (s1)) engine=innodb; +create table t3 (s1 varchar(2) binary,primary key (s1)) engine=innodb; +create table t4 (s1 char(2) binary,primary key (s1)) engine=innodb; + +insert into t1 values (0x41),(0x4120),(0x4100); +-- error 1062 +insert into t2 values (0x41),(0x4120),(0x4100); +insert into t2 values (0x41),(0x4120); +-- error 1062 +insert into t3 values (0x41),(0x4120),(0x4100); +insert into t3 values (0x41),(0x4100); +-- error 1062 +insert into t4 values (0x41),(0x4120),(0x4100); +insert into t4 values (0x41),(0x4100); +select hex(s1) from t1; +select hex(s1) from t2; +select hex(s1) from t3; +select hex(s1) from t4; +drop table t1,t2,t3,t4; + +create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb; +create table t2 (s1 binary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb; + +insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42); +-- error 1452 +insert into t2 values(0x42); +insert into t2 values(0x41); +select hex(s1) from t2; +update t1 set s1=0x123456 where a=2; +select hex(s1) from t2; +-- error 1451 +update t1 set s1=0x12 where a=1; +-- error 1451 +update t1 set s1=0x12345678 where a=1; +-- error 1451 +update t1 set s1=0x123457 where a=1; +update t1 set s1=0x1220 where a=1; +select hex(s1) from t2; +update t1 set s1=0x1200 where a=1; +select hex(s1) from t2; +update t1 set s1=0x4200 where a=1; +select hex(s1) from t2; +-- error 1451 +delete from t1 where a=1; +delete from t1 where a=2; +update t2 set s1=0x4120; +-- error 1451 +delete from t1; +delete from t1 where a!=3; +select a,hex(s1) from t1; +select hex(s1) from t2; + +drop table t2,t1; + +create table t1 (a int primary key,s1 varchar(2) binary not null unique) engine=innodb; +create table t2 (s1 char(2) binary not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb; + +insert into t1 values(1,0x4100),(2,0x41); +insert into t2 values(0x41); +select hex(s1) from t2; +update t1 set s1=0x1234 where a=1; +select hex(s1) from t2; +update t1 set s1=0x12 where a=2; +select hex(s1) from t2; +delete from t1 where a=1; +-- error 1451 +delete from t1 where a=2; +select a,hex(s1) from t1; +select hex(s1) from t2; + +drop table t2,t1; +# +# Test cases for bug #15308 Problem of Order with Enum Column in Primary Key +# +CREATE TABLE t1 ( + ind enum('0','1','2') NOT NULL default '0', + string1 varchar(250) NOT NULL, + PRIMARY KEY (ind) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE t2 ( + ind enum('0','1','2') NOT NULL default '0', + string1 varchar(250) NOT NULL, + PRIMARY KEY (ind) +) ENGINE=InnoDB DEFAULT CHARSET=ucs2; + +INSERT INTO t1 VALUES ('1', ''),('2', ''); +INSERT INTO t2 VALUES ('1', ''),('2', ''); +SELECT hex(ind),hex(string1) FROM t1 ORDER BY string1; +SELECT hex(ind),hex(string1) FROM t2 ORDER BY string1; +drop table t1,t2; + +CREATE TABLE t1 ( + ind set('0','1','2') NOT NULL default '0', + string1 varchar(250) NOT NULL, + PRIMARY KEY (ind) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE t2 ( + ind set('0','1','2') NOT NULL default '0', + string1 varchar(250) NOT NULL, + PRIMARY KEY (ind) +) ENGINE=InnoDB DEFAULT CHARSET=ucs2; + +INSERT INTO t1 VALUES ('1', ''),('2', ''); +INSERT INTO t2 VALUES ('1', ''),('2', ''); +SELECT hex(ind),hex(string1) FROM t1 ORDER BY string1; +SELECT hex(ind),hex(string1) FROM t2 ORDER BY string1; +drop table t1,t2; + +CREATE TABLE t1 ( + ind bit not null, + string1 varchar(250) NOT NULL, + PRIMARY KEY (ind) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE t2 ( + ind bit not null, + string1 varchar(250) NOT NULL, + PRIMARY KEY (ind) +) ENGINE=InnoDB DEFAULT CHARSET=ucs2; +insert into t1 values(0,''),(1,''); +insert into t2 values(0,''),(1,''); +select hex(ind),hex(string1) from t1 order by string1; +select hex(ind),hex(string1) from t2 order by string1; +drop table t1,t2; + # tests for bug #14056 Column prefix index on UTF-8 primary key column causes 'Can't find record..' create table t2 ( @@ -1391,4 +2050,162 @@ ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0; SHOW CREATE TABLE t2; DROP TABLE t2,t1; -# End of 4.1 tests +# +# Test case for bug #16229: MySQL/InnoDB uses full explicit table locks in trigger processing +# + +connect (a,localhost,root,,); +connect (b,localhost,root,,); +connection a; +create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb; +insert into t1(a) values (1),(2),(3); +commit; +connection b; +set autocommit = 0; +update t1 set b = 5 where a = 2; +connection a; +delimiter |; +create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end | +delimiter ;| +set autocommit = 0; +connection a; +insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100), +(11),(21),(31),(41),(51),(61),(71),(81),(91),(101), +(12),(22),(32),(42),(52),(62),(72),(82),(92),(102), +(13),(23),(33),(43),(53),(63),(73),(83),(93),(103), +(14),(24),(34),(44),(54),(64),(74),(84),(94),(104); +connection b; +commit; +connection a; +commit; +drop trigger t1t; +drop table t1; +disconnect a; +disconnect b; +# +# Another trigger test +# +connect (a,localhost,root,,); +connect (b,localhost,root,,); +connection a; +create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb; +create table t2(a int not null, b int, c int, d int, primary key(a)) engine=innodb; +create table t3(a int not null, b int, c int, d int, primary key(a)) engine=innodb; +create table t4(a int not null, b int, c int, d int, primary key(a)) engine=innodb; +create table t5(a int not null, b int, c int, d int, primary key(a)) engine=innodb; +insert into t1(a) values (1),(2),(3); +insert into t2(a) values (1),(2),(3); +insert into t3(a) values (1),(2),(3); +insert into t4(a) values (1),(2),(3); +insert into t3(a) values (5),(7),(8); +insert into t4(a) values (5),(7),(8); +insert into t5(a) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12); + +delimiter |; +create trigger t1t before insert on t1 for each row begin + INSERT INTO t2 SET a = NEW.a; +end | + +create trigger t2t before insert on t2 for each row begin + DELETE FROM t3 WHERE a = NEW.a; +end | + +create trigger t3t before delete on t3 for each row begin + UPDATE t4 SET b = b + 1 WHERE a = OLD.a; +end | + +create trigger t4t before update on t4 for each row begin + UPDATE t5 SET b = b + 1 where a = NEW.a; +end | +delimiter ;| +commit; +set autocommit = 0; +update t1 set b = b + 5 where a = 1; +update t2 set b = b + 5 where a = 1; +update t3 set b = b + 5 where a = 1; +update t4 set b = b + 5 where a = 1; +insert into t5(a) values(20); +connection b; +set autocommit = 0; +insert into t1(a) values(7); +insert into t2(a) values(8); +delete from t2 where a = 3; +update t4 set b = b + 1 where a = 3; +commit; +drop trigger t1t; +drop trigger t2t; +drop trigger t3t; +drop trigger t4t; +drop table t1, t2, t3, t4, t5; +connection default; +disconnect a; +disconnect b; + +# +# Bug #14360: problem with intervals +# + +create table t1(a date) engine=innodb; +create table t2(a date, key(a)) engine=innodb; +insert into t1 values('2005-10-01'); +insert into t2 values('2005-10-01'); +select * from t1, t2 + where t2.a between t1.a - interval 2 day and t1.a + interval 2 day; +drop table t1, t2; + +# bug 18934, "InnoDB crashes when table uses column names like DB_ROW_ID" +--error 1005 +CREATE TABLE t1 (DB_ROW_ID int) engine=innodb; + +# +# Bug #17152: Wrong result with BINARY comparison on aliased column +# + +CREATE TABLE t1 ( + a BIGINT(20) NOT NULL, + PRIMARY KEY (a) + ) ENGINE=INNODB DEFAULT CHARSET=UTF8; + +CREATE TABLE t2 ( + a BIGINT(20) NOT NULL, + b VARCHAR(128) NOT NULL, + c TEXT NOT NULL, + PRIMARY KEY (a,b), + KEY idx_t2_b_c (b,c(200)), + CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a) + ON DELETE CASCADE + ) ENGINE=INNODB DEFAULT CHARSET=UTF8; + +INSERT INTO t1 VALUES (1); +INSERT INTO t2 VALUES (1, 'bar', 'vbar'); +INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR'); +INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi'); +INSERT INTO t2 VALUES (1, 'customer_over', '1'); + +SELECT * FROM t2 WHERE b = 'customer_over'; +SELECT * FROM t2 WHERE BINARY b = 'customer_over'; +SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over'; +/* Bang: Empty result set, above was expected: */ +SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over'; +SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over'; + +drop table t2, t1; + +# +# Bug #15680 (SPATIAL key in innodb) +# +--error ER_TABLE_CANT_HANDLE_SPKEYS +create table t1 (g geometry not null, spatial gk(g)) engine=innodb; + +####################################################################### +# # +# Please, DO NOT TOUCH this file as well as the innodb.result file. # +# These files are to be modified ONLY BY INNOBASE guys. # +# # +# Use innodb_mysql.[test|result] files instead. # +# # +# If nevertheless you need to make some changes here, please, forward # +# your commit message To: dev@innodb.com Cc: dev-innodb@mysql.com # +# (otherwise your changes may be erased). # +# # +####################################################################### diff --git a/mysql-test/t/innodb_cache.test b/mysql-test/t/innodb_cache.test index a811d660bd7..8ed2853e4f7 100644 --- a/mysql-test/t/innodb_cache.test +++ b/mysql-test/t/innodb_cache.test @@ -63,6 +63,7 @@ drop table t1; # # one statement roll back inside transation # +let $save_query_cache_size=`select @@global.query_cache_size`; set GLOBAL query_cache_size=1355776; CREATE TABLE t1 ( id int(10) NOT NULL auto_increment, a varchar(25) default NULL, PRIMARY KEY (id), UNIQUE KEY a (a)) ENGINE=innodb; CREATE TABLE t2 ( id int(10) NOT NULL auto_increment, b varchar(25) default NULL, PRIMARY KEY (id), UNIQUE KEY b (b)) ENGINE=innodb; @@ -79,5 +80,8 @@ insert into t3 VALUES ( NULL, 1, 1, 2 ); commit; select t1.* from t1, t2, t3 where t3.state & 1 = 0 and t3.t1_id = t1.id and t3.t2_id = t2.id and t1.id = 1 order by t1.a asc; drop table t3,t2,t1; +--disable_query_log +eval set GLOBAL query_cache_size=$save_query_cache_size; +--enable_query_log # End of 4.1 tests diff --git a/mysql-test/t/innodb_gis.test b/mysql-test/t/innodb_gis.test new file mode 100644 index 00000000000..142b526af92 --- /dev/null +++ b/mysql-test/t/innodb_gis.test @@ -0,0 +1,3 @@ +--source include/have_innodb.inc +SET storage_engine=innodb; +--source include/gis_generic.inc diff --git a/mysql-test/t/innodb_mysql.test b/mysql-test/t/innodb_mysql.test index c5a5e997775..06cfe71ef11 100644 --- a/mysql-test/t/innodb_mysql.test +++ b/mysql-test/t/innodb_mysql.test @@ -118,6 +118,157 @@ INSERT INTO `t2`(`id1`,`id2`,`id3`,`id4`) VALUES SELECT `id1` FROM `t1` WHERE `id1` NOT IN (SELECT `id1` FROM `t2` WHERE `id2` = 1 AND `id3` = 2); DROP TABLE t1, t2; +# +# Bug #22728 - Handler_rollback value is growing +# + +let $before= `show /*!50002 GLOBAL */ status like 'Handler_rollback'`; +create table t1 (c1 int) engine=innodb; +connect (con1,localhost,root,,); +connect (con2,localhost,root,,); +connection con2; +handler t1 open; +handler t1 read first; +disconnect con2; +connection con1; +let $after= `show /*!50002 GLOBAL */ status like 'Handler_rollback'`; +# Compare the before and after value, it should be equal +--disable_query_log +eval select STRCMP("$before", "$after") as "Before and after comparison"; +--enable_query_log +connection default; +drop table t1; +disconnect con1; +--echo End of 4.1 tests +# +# Bug #12882 min/max inconsistent on empty table +# + +--disable_warnings +create table t1m (a int) engine=myisam; +create table t1i (a int) engine=innodb; +create table t2m (a int) engine=myisam; +create table t2i (a int) engine=innodb; +--enable_warnings +insert into t2m values (5); +insert into t2i values (5); + +# test with MyISAM +select min(a) from t1m; +select min(7) from t1m; +select min(7) from DUAL; +explain select min(7) from t2m join t1m; +select min(7) from t2m join t1m; + +select max(a) from t1m; +select max(7) from t1m; +select max(7) from DUAL; +explain select max(7) from t2m join t1m; +select max(7) from t2m join t1m; + +select 1, min(a) from t1m where a=99; +select 1, min(a) from t1m where 1=99; +select 1, min(1) from t1m where a=99; +select 1, min(1) from t1m where 1=99; + +select 1, max(a) from t1m where a=99; +select 1, max(a) from t1m where 1=99; +select 1, max(1) from t1m where a=99; +select 1, max(1) from t1m where 1=99; + +# test with InnoDB +select min(a) from t1i; +select min(7) from t1i; +select min(7) from DUAL; +explain select min(7) from t2i join t1i; +select min(7) from t2i join t1i; + +select max(a) from t1i; +select max(7) from t1i; +select max(7) from DUAL; +explain select max(7) from t2i join t1i; +select max(7) from t2i join t1i; + +select 1, min(a) from t1i where a=99; +select 1, min(a) from t1i where 1=99; +select 1, min(1) from t1i where a=99; +select 1, min(1) from t1i where 1=99; + +select 1, max(a) from t1i where a=99; +select 1, max(a) from t1i where 1=99; +select 1, max(1) from t1i where a=99; +select 1, max(1) from t1i where 1=99; + +# mixed MyISAM/InnoDB test +explain select count(*), min(7), max(7) from t1m, t1i; +select count(*), min(7), max(7) from t1m, t1i; + +explain select count(*), min(7), max(7) from t1m, t2i; +select count(*), min(7), max(7) from t1m, t2i; + +explain select count(*), min(7), max(7) from t2m, t1i; +select count(*), min(7), max(7) from t2m, t1i; + +drop table t1m, t1i, t2m, t2i; + +# +# Bug #12672: primary key implcitly included in every innodb index +# (was part of group_min_max.test) +# + +create table t1 ( + a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' ' +); + +insert into t1 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'), +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'); +--disable_warnings +create table t4 ( + pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' ' +) engine=innodb; +--enable_warnings +insert into t4 (a1, a2, b, c, d, dummy) select * from t1; + +create index idx12672_0 on t4 (a1); +create index idx12672_1 on t4 (a1,a2,b,c); +create index idx12672_2 on t4 (a1,a2,b); +analyze table t1; + +select distinct a1 from t4 where pk_col not in (1,2,3,4); + +drop table t1,t4; + # # BUG#18819: DELETE IGNORE hangs on foreign key parent delete @@ -145,20 +296,92 @@ SELECT * FROM t1, t2; DROP TABLE t2, t1; +--echo End of 4.1 tests. + + # -# Bug #22728 - Handler_rollback value is growing +# Bug #6142: a problem with the empty innodb table +# (was part of group_min_max.test) # -flush status; -create table t1 (c1 int) engine=innodb; -connect (con1,localhost,root,,); -connect (con2,localhost,root,,); -connection con2; -handler t1 open; -handler t1 read first; -disconnect con2; -connection con1; -show /*!50002 GLOBAL */ status like 'Handler_rollback'; -connection default; + +--disable_warnings +create table t1 ( + a varchar(30), b varchar(30), primary key(a), key(b) +) engine=innodb; +--enable_warnings +select distinct a from t1; drop table t1; -disconnect con1; ---echo End of 4.1 tests + +# +# Bug #9798: group by with rollup +# (was part of group_min_max.test) +# + +--disable_warnings +create table t1(a int, key(a)) engine=innodb; +--enable_warnings +insert into t1 values(1); +select a, count(a) from t1 group by a with rollup; +drop table t1; + +# +# Bug #13293 Wrongly used index results in endless loop. +# (was part of group_min_max.test) +# +create table t1 (f1 int, f2 char(1), primary key(f1,f2)) engine=innodb; +insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d"); +alter table t1 drop primary key, add primary key (f2, f1); +explain select distinct f1 a, f1 b from t1; +explain select distinct f1, f2 from t1; +drop table t1; + +# +# Test for bug #17164: ORed FALSE blocked conversion of outer join into join +# + +CREATE TABLE t1 (id int(11) NOT NULL PRIMARY KEY, name varchar(20), + INDEX (name)) ENGINE=InnoDB; +CREATE TABLE t2 (id int(11) NOT NULL PRIMARY KEY, fkey int(11), + FOREIGN KEY (fkey) REFERENCES t2(id)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1,'A1'),(2,'A2'),(3,'B'); +INSERT INTO t2 VALUES (1,1),(2,2),(3,2),(4,3),(5,3); + +EXPLAIN +SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id + WHERE t1.name LIKE 'A%'; + +EXPLAIN +SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id + WHERE t1.name LIKE 'A%' OR FALSE; + +DROP TABLE t1,t2; + +# +# Bug#17530: Incorrect key truncation on table creation caused server crash. +# +create table t1(f1 varchar(800) binary not null, key(f1)) engine = innodb + character set utf8 collate utf8_general_ci; +insert into t1 values('aaa'); +drop table t1; + + +# +# Bug#22781: SQL_BIG_RESULT fails to influence sort plan +# +CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB; + +INSERT INTO t1 VALUES ( 1 , 1 , 1); +INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1; + +EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b; +EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b; +DROP TABLE t1; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/innodb_notembedded.test b/mysql-test/t/innodb_notembedded.test new file mode 100644 index 00000000000..53332d9fda4 --- /dev/null +++ b/mysql-test/t/innodb_notembedded.test @@ -0,0 +1,40 @@ +-- source include/not_embedded.inc +-- source include/have_innodb.inc + +--disable_warnings +drop table if exists t1; +--enable_warnings + +connect (a,localhost,root,,); +connect (b,localhost,root,,); + + +# +# BUG#11238 - in prelocking mode SELECT .. FOR UPDATE is changed to +# non-blocking SELECT +# +create table t1 (col1 integer primary key, col2 integer) engine=innodb; +insert t1 values (1,100); +delimiter |; +create function f1 () returns integer begin +declare var1 int; +select col2 into var1 from t1 where col1=1 for update; +return var1; +end| +delimiter ;| +start transaction; +select f1(); +connection b; +send update t1 set col2=0 where col1=1; +connection default; +select * from t1; +connection a; +rollback; +connection b; +reap; +rollback; +connection default; +drop table t1; +drop function f1; +disconnect a; +disconnect b; diff --git a/mysql-test/t/innodb_unsafe_binlog-master.opt b/mysql-test/t/innodb_unsafe_binlog-master.opt new file mode 100644 index 00000000000..5c0136b5db3 --- /dev/null +++ b/mysql-test/t/innodb_unsafe_binlog-master.opt @@ -0,0 +1 @@ +--loose-innodb_locks_unsafe_for_binlog=true diff --git a/mysql-test/t/innodb_unsafe_binlog.test b/mysql-test/t/innodb_unsafe_binlog.test new file mode 100644 index 00000000000..fa240eb7608 --- /dev/null +++ b/mysql-test/t/innodb_unsafe_binlog.test @@ -0,0 +1,67 @@ +-- source include/have_innodb.inc +# +# Note that these tests uses a innodb_locks_unsafe_for_binlog option. +# +# Test cases for a bug #15650 DELETE with LEFT JOIN crashes server +# + +--disable_warnings +drop table if exists t1,t2; +--enable_warnings +create table t1 (id int not null, f_id int not null, f int not null, +primary key(f_id, id)) engine=innodb; +create table t2 (id int not null,s_id int not null,s varchar(200), +primary key(id)) engine=innodb; +INSERT INTO t1 VALUES (8, 1, 3); +INSERT INTO t1 VALUES (1, 2, 1); +INSERT INTO t2 VALUES (1, 0, ''); +INSERT INTO t2 VALUES (8, 1, ''); +commit; +DELETE ml.* FROM t1 AS ml LEFT JOIN t2 AS mm ON (mm.id=ml.id) +WHERE mm.id IS NULL; +select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id) +where mm.id is null lock in share mode; +drop table t1,t2; + +create table t1 (id int not null, f_id int not null, f int not null, +primary key(id),key(f_id)) engine=innodb; +create table t2 (id int not null,s_id int not null,s varchar(200), +primary key(id),key(s_id)) engine=innodb; +INSERT INTO t1 VALUES (8, 1, 3); +INSERT INTO t1 VALUES (1, 2, 1); +INSERT INTO t2 VALUES (1, 0, ''); +INSERT INTO t2 VALUES (8, 1, ''); +commit; +delete ml.* from t1 as ml left join t2 as mm on (mm.s_id=ml.f_id) where mm.s is null; +select ml.* from t1 as ml left join t2 as mm on (mm.s_id=ml.f_id) where mm.s is null lock in share mode; +drop table t1,t2; + +# +# Test case for unlock row bug where unlock releases all locks granted for +# a row. Only the latest lock should be released. +# + +connect (a,localhost,root,,); +connect (b,localhost,root,,); +connection a; +create table t1(a int not null, b int, primary key(a)) engine=innodb; +insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2); +commit; +set autocommit = 0; +select * from t1 lock in share mode; +update t1 set b = 5 where b = 1; +connection b; +set autocommit = 0; +# +# S-lock to records (2,2),(4,2), and (6,2) should not be released in a update +# +--error 1205 +select * from t1 where a = 2 and b = 2 for update; +connection a; +commit; +connection b; +commit; +drop table t1; +disconnect a; +disconnect b; + diff --git a/mysql-test/t/insert.test b/mysql-test/t/insert.test index 0c8252ad479..ac43d0bc818 100644 --- a/mysql-test/t/insert.test +++ b/mysql-test/t/insert.test @@ -3,7 +3,7 @@ # --disable_warnings -drop table if exists t1,t2; +drop table if exists t1,t2,t3; --enable_warnings create table t1 (a int not null); @@ -87,6 +87,7 @@ use mysqltest; create table t1 (c int); insert into mysqltest.t1 set mysqltest.t1.c = '1'; drop database mysqltest; +use test; # # Test of wrong values for float data (bug #2082) @@ -94,65 +95,118 @@ drop database mysqltest; # PS gives sligthly different numbers for max-float/max-double --disable_ps_protocol -use test; create table t1(number int auto_increment primary key, original_value varchar(50), f_double double, f_float float, f_double_7_2 double(7,2), f_float_4_3 float (4,3), f_double_u double unsigned, f_float_u float unsigned, f_double_15_1_u double(15,1) unsigned, f_float_3_1_u float (3,1) unsigned); set @value= "aa"; insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value); ---replace_result e-0 e- e+0 e+ --query_vertical select * from t1 where number =last_insert_id() set @value= "1aa"; insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value); ---replace_result e-0 e- e+0 e+ --query_vertical select * from t1 where number =last_insert_id() set @value= "aa1"; insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value); ---replace_result e-0 e- e+0 e+ --query_vertical select * from t1 where number =last_insert_id() set @value= "1e+1111111111a"; insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value); ---replace_result e-0 e- e+0 e+ --query_vertical select * from t1 where number =last_insert_id() set @value= "-1e+1111111111a"; insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value); ---replace_result e-0 e- e+0 e+ --query_vertical select * from t1 where number =last_insert_id() +--error 1367 set @value= 1e+1111111111; -insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value); ---replace_result e-0 e- e+0 e+ ---query_vertical select * from t1 where number =last_insert_id() - +--error 1367 set @value= -1e+1111111111; -insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value); ---replace_result e-0 e- e+0 e+ ---query_vertical select * from t1 where number =last_insert_id() + set @value= 1e+111; insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value); ---replace_result e-0 e- e+0 e+ --query_vertical select * from t1 where number =last_insert_id() set @value= -1e+111; insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value); ---replace_result e-0 e- e+0 e+ --query_vertical select * from t1 where number =last_insert_id() set @value= 1; insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value); ---replace_result e-0 e- e+0 e+ --query_vertical select * from t1 where number =last_insert_id() set @value= -1; insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value); ---replace_result e-0 e- e+0 e+ --query_vertical select * from t1 where number =last_insert_id() drop table t1; --enable_ps_protocol # End of 4.1 tests + +# +# Test automatic result buffering with INSERT INTO t1 ... SELECT ... FROM t1 +# + +create table t1(id1 int not null auto_increment primary key, t char(12)); +create table t2(id2 int not null, t char(12)); +create table t3(id3 int not null, t char(12), index(id3)); +disable_query_log; +let $1 = 100; +while ($1) + { + let $2 = 5; + eval insert into t1(t) values ('$1'); + while ($2) + { + eval insert into t2(id2,t) values ($1,'$2'); + let $3 = 10; + while ($3) + { + eval insert into t3(id3,t) values ($1,'$2'); + dec $3; + } + dec $2; + } + dec $1; + } +enable_query_log; +select count(*) from t2; +insert into t2 select t1.* from t1, t2 t, t3 where t1.id1 = t.id2 and t.id2 = t3.id3; +select count(*) from t2; +drop table t1,t2,t3; + +# +# Test for INSERT DELAYED INTO a <view> +# BUG#13683: INSERT DELAYED into a view creates an infinite loop +# + +create table t1 (n int); +create view v1 as select * from t1; +--error 1347 +insert delayed into v1 values (1); +drop table t1; +drop view v1; + +# +# Test for values returned by ROW_COUNT() function +# (and thus for values returned by mysql_affected_rows()) +# for various forms of INSERT +# +create table t1 (id int primary key, data int); +insert into t1 values (1, 1), (2, 2), (3, 3); +select row_count(); +insert ignore into t1 values (1, 1); +select row_count(); +# Reports that 2 rows are affected (1 deleted + 1 inserted) +replace into t1 values (1, 11); +select row_count(); +replace into t1 values (4, 4); +select row_count(); +# Reports that 2 rows are affected. This conforms to documentation. +# (Useful for differentiating inserts from updates). +insert into t1 values (2, 2) on duplicate key update data= data + 10; +select row_count(); +insert into t1 values (5, 5) on duplicate key update data= data + 10; +select row_count(); +drop table t1; diff --git a/mysql-test/t/insert_select.test b/mysql-test/t/insert_select.test index fcea489fcff..6f86ed897ac 100644 --- a/mysql-test/t/insert_select.test +++ b/mysql-test/t/insert_select.test @@ -105,9 +105,7 @@ insert into t2 values (2,"t2:2"), (3,"t2:3"); insert into t1 select * from t2; select * from t1; # REPLACE .. SELECT is not yet supported by PS ---disable_ps_protocol replace into t1 select * from t2; ---enable_ps_protocol select * from t1; drop table t1,t2; @@ -198,9 +196,9 @@ insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= a + #Some error cases --error 1052 insert into t1 select t2.a from t2 on duplicate key update a= a + t2.b; ---error 1109 +--error 1054 insert into t1 select t2.a from t2 on duplicate key update t2.a= a + t2.b; ---error 1109 +--error 1054 insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= t1.a + t2.b; drop table t1,t2,t3; @@ -222,7 +220,7 @@ create table t2(x int, z int); insert into t1(x,y) select x,z from t2 on duplicate key update x=values(x); --error 1054 insert into t1(x,y) select x,z from t2 on duplicate key update x=values(z); ---error 1109 +--error 1054 insert into t1(x,y) select x,z from t2 on duplicate key update x=values(t2.x); drop table t1,t2; @@ -240,3 +238,168 @@ INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1; DROP TABLE t1; # End of 4.1 tests + +# +# Bug #18080: INSERT ... SELECT ... JOIN results in ambiguous field list error +# +CREATE TABLE t1 (x int, y int); +CREATE TABLE t2 (z int, y int); +CREATE TABLE t3 (a int, b int); +INSERT INTO t3 (SELECT x, y FROM t1 JOIN t2 USING (y) WHERE z = 1); +DROP TABLE IF EXISTS t1,t2,t3; + +# +# Bug #21774: Column count doesn't match value count at row x +# +CREATE DATABASE bug21774_1; +CREATE DATABASE bug21774_2; + +CREATE TABLE bug21774_1.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255)); +CREATE TABLE bug21774_2.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255)); +CREATE TABLE bug21774_1.t2(id VARCHAR(10) NOT NULL,label VARCHAR(255)); + +INSERT INTO bug21774_2.t1 SELECT t1.* FROM bug21774_1.t1; + +use bug21774_1; +INSERT INTO bug21774_2.t1 SELECT t1.* FROM t1; + +DROP DATABASE bug21774_1; +DROP DATABASE bug21774_2; + +# +# Bug #20989: View '(null).(null)' references invalid table(s)... on +# SQL SECURITY INVOKER +# +# this is really the fact that REPLACE ... SELECT required additional +# INSERT privs (on tables that are part of a view) over the related +# REPLACE, SELECT +# + +CREATE DATABASE meow; + +connect (root,localhost,root,,meow); +connection root; + +CREATE TABLE table_target ( mexs_id CHAR(8), messzeit TIMESTAMP, PRIMARY KEY (mexs_id)); +CREATE TABLE table_target2 ( mexs_id CHAR(8), messzeit TIMESTAMP, PRIMARY KEY (mexs_id)); +CREATE TABLE table_target3 ( mexs_id CHAR(8), messzeit TIMESTAMP, PRIMARY KEY (mexs_id)); +CREATE VIEW view_target2 AS SELECT mexs_id,messzeit FROM table_target2; +CREATE SQL SECURITY INVOKER VIEW view_target3 AS SELECT mexs_id,messzeit FROM table_target3; + +CREATE TABLE table_stations ( mexs_id VARCHAR(8), icao VARCHAR(4), country CHAR(2), PRIMARY KEY (mexs_id), UNIQUE KEY icao (icao), KEY country (country), CONSTRAINT stations_ibfk_8 FOREIGN KEY (country) REFERENCES countries (country) ON UPDATE CASCADE); +INSERT INTO table_stations VALUES ('87654321','XXXX','YY'); + +CREATE TABLE table_countries ( country CHAR(2), iso_short_en VARCHAR(64), PRIMARY KEY (country)); +INSERT INTO table_countries VALUES ('YY','Entenhausen'); + +CREATE ALGORITHM=MERGE SQL SECURITY INVOKER VIEW view_stations AS select table_stations.mexs_id AS mexs_id, table_stations.icao AS icao, table_stations.country AS landescode from (table_stations join table_countries on((table_stations.country = table_countries.country))); + +CREATE TABLE table_source ( id varchar(4), datetime TIMESTAMP, PRIMARY KEY (id)); +INSERT INTO table_source VALUES ('XXXX','2006-07-12 07:50:00'); + +GRANT SELECT ON table_source TO user20989@localhost; +GRANT SELECT ON table_countries TO user20989@localhost; +GRANT SELECT ON table_stations TO user20989@localhost; +GRANT SELECT ON view_stations TO user20989@localhost; +GRANT SELECT ON table_target TO user20989@localhost; +GRANT SELECT ON table_target2 TO user20989@localhost; +GRANT INSERT,DELETE,SELECT ON view_target3 TO user20989@localhost; + +connect (user20989,localhost,user20989,,meow); +connection user20989; + +--error 1142 +REPLACE INTO table_target +SELECT stations.mexs_id AS mexs_id, datetime AS messzeit +FROM table_source +INNER JOIN view_stations AS stations +ON table_source.id = stations.icao +LEFT JOIN table_target AS old +USING (mexs_id); + +--error 1142 +REPLACE INTO view_target2 +SELECT stations.mexs_id AS mexs_id, datetime AS messzeit +FROM table_source +INNER JOIN view_stations AS stations +ON table_source.id = stations.icao +LEFT JOIN view_target2 AS old +USING (mexs_id); + +--error 1356 +REPLACE INTO view_target3 +SELECT stations.mexs_id AS mexs_id, datetime AS messzeit +FROM table_source +INNER JOIN view_stations AS stations +ON table_source.id = stations.icao +LEFT JOIN view_target3 AS old +USING (mexs_id); + +connection root; +disconnect user20989; + +GRANT INSERT,DELETE ON table_target TO user20989@localhost; +GRANT INSERT,DELETE,SELECT ON view_target2 TO user20989@localhost; +GRANT INSERT,DELETE,SELECT ON table_target3 TO user20989@localhost; + +connect (user20989,localhost,user20989,,meow); +connection user20989; + +REPLACE INTO table_target +SELECT stations.mexs_id AS mexs_id, datetime AS messzeit +FROM table_source +INNER JOIN view_stations AS stations +ON table_source.id = stations.icao +LEFT JOIN table_target AS old +USING (mexs_id); + +--error 1142 +REPLACE INTO table_target2 VALUES ('00X45Y78','2006-07-12 07:50:00'); +REPLACE INTO view_target2 VALUES ('12X45Y78','2006-07-12 07:50:00'); + +SELECT stations.mexs_id AS mexs_id, datetime AS messzeit +FROM table_source +INNER JOIN view_stations AS stations +ON table_source.id = stations.icao +LEFT JOIN view_target2 AS old +USING (mexs_id); + +REPLACE INTO view_target2 +SELECT stations.mexs_id AS mexs_id, datetime AS messzeit +FROM table_source +INNER JOIN view_stations AS stations +ON table_source.id = stations.icao +LEFT JOIN view_target2 AS old +USING (mexs_id); + +REPLACE INTO view_target3 +SELECT stations.mexs_id AS mexs_id, datetime AS messzeit +FROM table_source +INNER JOIN view_stations AS stations +ON table_source.id = stations.icao +LEFT JOIN view_target3 AS old +USING (mexs_id); + +connection root; +disconnect user20989; + +SELECT * FROM table_target; +SELECT * FROM view_target2; +SELECT * FROM view_target3; + +DROP VIEW view_stations; +DROP TABLE table_source; +DROP TABLE table_countries; +DROP TABLE table_stations; +DROP TABLE table_target; +DROP TABLE table_target2; +DROP TABLE table_target3; +DROP VIEW view_target2; +DROP VIEW view_target3; +DROP USER user20989@localhost; + +disconnect root; + +connection default; + +DROP DATABASE meow; diff --git a/mysql-test/t/insert_update.test b/mysql-test/t/insert_update.test index 56885a555fd..b3813864464 100644 --- a/mysql-test/t/insert_update.test +++ b/mysql-test/t/insert_update.test @@ -1,5 +1,5 @@ --disable_warnings -DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t1, t2; --enable_warnings CREATE TABLE t1 (a INT, b INT, c INT, UNIQUE (A), UNIQUE(B)); diff --git a/mysql-test/t/isam.test b/mysql-test/t/isam.test deleted file mode 100644 index 7fa841c11a3..00000000000 --- a/mysql-test/t/isam.test +++ /dev/null @@ -1,249 +0,0 @@ --- source include/have_isam.inc - ---disable_warnings -drop table if exists t1,t2; ---enable_warnings - -# -# Test possible problem with rows that are about 65535 bytes long -# - -create table t1 (a tinyint not null auto_increment, b blob not null, primary key (a)) engine=isam; - -let $1=100; -disable_query_log; ---disable_warnings -while ($1) -{ - eval insert into t1 (b) values(repeat(char(65+$1),65540-$1)); - dec $1; -} -enable_query_log; ---enable_warnings -delete from t1 where (a & 1); -select sum(length(b)) from t1; -drop table t1; - -# -# Test of auto_increment; The test for BDB tables is in bdb.test -# - -create table t1 (a int not null auto_increment,b int, primary key (a)) engine=isam; -insert into t1 values (1,1),(NULL,2),(3,3),(NULL,4); -delete from t1 where a=4 or a=2; -insert into t1 values (NULL,4),(NULL,5),(6,6); -select * from t1; -delete from t1 where a=6; -#show table status like "t1"; -replace t1 values (3,1); -replace t1 values (3,3); -ALTER TABLE t1 add c int; -insert into t1 values (NULL,6,6); -select * from t1; -drop table t1; - -# -# Test of some CREATE TABLE's that should fail -# ---error 1121 -create table t1 (a int,b text, index(a)) engine=isam; ---error 1073 -create table t1 (a int,b text, index(b)) engine=isam; ---error 1075 -create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ord,ordid)) engine=isam; ---error 1121 -create table t1 (ordid int(8), unique (ordid)) engine=isam; -drop table if exists t1; - -# -# Test of some show commands -# - -create table t1 (a int not null primary key, b int not null,c int not null, key(b,c)); -insert into t1 values (1,2,2),(2,2,3),(3,2,4),(4,2,4); -create table t2 engine=isam select * from t1; -optimize table t1; -check table t1,t2; -repair table t1,t2; -check table t2,t1; -lock tables t1 write; -check table t2,t1; -show columns from t1; -show full columns from t1; -show index from t1; -drop table t1,t2; - -# -# test of table with huge number of packed fields -# - -create table t1 (i1 int, i2 int, i3 int, i4 int, i5 int, i6 int, i7 int, i8 -int, i9 int, i10 int, i11 int, i12 int, i13 int, i14 int, i15 int, i16 int, i17 -int, i18 int, i19 int, i20 int, i21 int, i22 int, i23 int, i24 int, i25 int, -i26 int, i27 int, i28 int, i29 int, i30 int, i31 int, i32 int, i33 int, i34 -int, i35 int, i36 int, i37 int, i38 int, i39 int, i40 int, i41 int, i42 int, -i43 int, i44 int, i45 int, i46 int, i47 int, i48 int, i49 int, i50 int, i51 -int, i52 int, i53 int, i54 int, i55 int, i56 int, i57 int, i58 int, i59 int, -i60 int, i61 int, i62 int, i63 int, i64 int, i65 int, i66 int, i67 int, i68 -int, i69 int, i70 int, i71 int, i72 int, i73 int, i74 int, i75 int, i76 int, -i77 int, i78 int, i79 int, i80 int, i81 int, i82 int, i83 int, i84 int, i85 -int, i86 int, i87 int, i88 int, i89 int, i90 int, i91 int, i92 int, i93 int, -i94 int, i95 int, i96 int, i97 int, i98 int, i99 int, i100 int, i101 int, i102 -int, i103 int, i104 int, i105 int, i106 int, i107 int, i108 int, i109 int, i110 -int, i111 int, i112 int, i113 int, i114 int, i115 int, i116 int, i117 int, i118 -int, i119 int, i120 int, i121 int, i122 int, i123 int, i124 int, i125 int, i126 -int, i127 int, i128 int, i129 int, i130 int, i131 int, i132 int, i133 int, i134 -int, i135 int, i136 int, i137 int, i138 int, i139 int, i140 int, i141 int, i142 -int, i143 int, i144 int, i145 int, i146 int, i147 int, i148 int, i149 int, i150 -int, i151 int, i152 int, i153 int, i154 int, i155 int, i156 int, i157 int, i158 -int, i159 int, i160 int, i161 int, i162 int, i163 int, i164 int, i165 int, i166 -int, i167 int, i168 int, i169 int, i170 int, i171 int, i172 int, i173 int, i174 -int, i175 int, i176 int, i177 int, i178 int, i179 int, i180 int, i181 int, i182 -int, i183 int, i184 int, i185 int, i186 int, i187 int, i188 int, i189 int, i190 -int, i191 int, i192 int, i193 int, i194 int, i195 int, i196 int, i197 int, i198 -int, i199 int, i200 int, i201 int, i202 int, i203 int, i204 int, i205 int, i206 -int, i207 int, i208 int, i209 int, i210 int, i211 int, i212 int, i213 int, i214 -int, i215 int, i216 int, i217 int, i218 int, i219 int, i220 int, i221 int, i222 -int, i223 int, i224 int, i225 int, i226 int, i227 int, i228 int, i229 int, i230 -int, i231 int, i232 int, i233 int, i234 int, i235 int, i236 int, i237 int, i238 -int, i239 int, i240 int, i241 int, i242 int, i243 int, i244 int, i245 int, i246 -int, i247 int, i248 int, i249 int, i250 int, i251 int, i252 int, i253 int, i254 -int, i255 int, i256 int, i257 int, i258 int, i259 int, i260 int, i261 int, i262 -int, i263 int, i264 int, i265 int, i266 int, i267 int, i268 int, i269 int, i270 -int, i271 int, i272 int, i273 int, i274 int, i275 int, i276 int, i277 int, i278 -int, i279 int, i280 int, i281 int, i282 int, i283 int, i284 int, i285 int, i286 -int, i287 int, i288 int, i289 int, i290 int, i291 int, i292 int, i293 int, i294 -int, i295 int, i296 int, i297 int, i298 int, i299 int, i300 int, i301 int, i302 -int, i303 int, i304 int, i305 int, i306 int, i307 int, i308 int, i309 int, i310 -int, i311 int, i312 int, i313 int, i314 int, i315 int, i316 int, i317 int, i318 -int, i319 int, i320 int, i321 int, i322 int, i323 int, i324 int, i325 int, i326 -int, i327 int, i328 int, i329 int, i330 int, i331 int, i332 int, i333 int, i334 -int, i335 int, i336 int, i337 int, i338 int, i339 int, i340 int, i341 int, i342 -int, i343 int, i344 int, i345 int, i346 int, i347 int, i348 int, i349 int, i350 -int, i351 int, i352 int, i353 int, i354 int, i355 int, i356 int, i357 int, i358 -int, i359 int, i360 int, i361 int, i362 int, i363 int, i364 int, i365 int, i366 -int, i367 int, i368 int, i369 int, i370 int, i371 int, i372 int, i373 int, i374 -int, i375 int, i376 int, i377 int, i378 int, i379 int, i380 int, i381 int, i382 -int, i383 int, i384 int, i385 int, i386 int, i387 int, i388 int, i389 int, i390 -int, i391 int, i392 int, i393 int, i394 int, i395 int, i396 int, i397 int, i398 -int, i399 int, i400 int, i401 int, i402 int, i403 int, i404 int, i405 int, i406 -int, i407 int, i408 int, i409 int, i410 int, i411 int, i412 int, i413 int, i414 -int, i415 int, i416 int, i417 int, i418 int, i419 int, i420 int, i421 int, i422 -int, i423 int, i424 int, i425 int, i426 int, i427 int, i428 int, i429 int, i430 -int, i431 int, i432 int, i433 int, i434 int, i435 int, i436 int, i437 int, i438 -int, i439 int, i440 int, i441 int, i442 int, i443 int, i444 int, i445 int, i446 -int, i447 int, i448 int, i449 int, i450 int, i451 int, i452 int, i453 int, i454 -int, i455 int, i456 int, i457 int, i458 int, i459 int, i460 int, i461 int, i462 -int, i463 int, i464 int, i465 int, i466 int, i467 int, i468 int, i469 int, i470 -int, i471 int, i472 int, i473 int, i474 int, i475 int, i476 int, i477 int, i478 -int, i479 int, i480 int, i481 int, i482 int, i483 int, i484 int, i485 int, i486 -int, i487 int, i488 int, i489 int, i490 int, i491 int, i492 int, i493 int, i494 -int, i495 int, i496 int, i497 int, i498 int, i499 int, i500 int, i501 int, i502 -int, i503 int, i504 int, i505 int, i506 int, i507 int, i508 int, i509 int, i510 -int, i511 int, i512 int, i513 int, i514 int, i515 int, i516 int, i517 int, i518 -int, i519 int, i520 int, i521 int, i522 int, i523 int, i524 int, i525 int, i526 -int, i527 int, i528 int, i529 int, i530 int, i531 int, i532 int, i533 int, i534 -int, i535 int, i536 int, i537 int, i538 int, i539 int, i540 int, i541 int, i542 -int, i543 int, i544 int, i545 int, i546 int, i547 int, i548 int, i549 int, i550 -int, i551 int, i552 int, i553 int, i554 int, i555 int, i556 int, i557 int, i558 -int, i559 int, i560 int, i561 int, i562 int, i563 int, i564 int, i565 int, i566 -int, i567 int, i568 int, i569 int, i570 int, i571 int, i572 int, i573 int, i574 -int, i575 int, i576 int, i577 int, i578 int, i579 int, i580 int, i581 int, i582 -int, i583 int, i584 int, i585 int, i586 int, i587 int, i588 int, i589 int, i590 -int, i591 int, i592 int, i593 int, i594 int, i595 int, i596 int, i597 int, i598 -int, i599 int, i600 int, i601 int, i602 int, i603 int, i604 int, i605 int, i606 -int, i607 int, i608 int, i609 int, i610 int, i611 int, i612 int, i613 int, i614 -int, i615 int, i616 int, i617 int, i618 int, i619 int, i620 int, i621 int, i622 -int, i623 int, i624 int, i625 int, i626 int, i627 int, i628 int, i629 int, i630 -int, i631 int, i632 int, i633 int, i634 int, i635 int, i636 int, i637 int, i638 -int, i639 int, i640 int, i641 int, i642 int, i643 int, i644 int, i645 int, i646 -int, i647 int, i648 int, i649 int, i650 int, i651 int, i652 int, i653 int, i654 -int, i655 int, i656 int, i657 int, i658 int, i659 int, i660 int, i661 int, i662 -int, i663 int, i664 int, i665 int, i666 int, i667 int, i668 int, i669 int, i670 -int, i671 int, i672 int, i673 int, i674 int, i675 int, i676 int, i677 int, i678 -int, i679 int, i680 int, i681 int, i682 int, i683 int, i684 int, i685 int, i686 -int, i687 int, i688 int, i689 int, i690 int, i691 int, i692 int, i693 int, i694 -int, i695 int, i696 int, i697 int, i698 int, i699 int, i700 int, i701 int, i702 -int, i703 int, i704 int, i705 int, i706 int, i707 int, i708 int, i709 int, i710 -int, i711 int, i712 int, i713 int, i714 int, i715 int, i716 int, i717 int, i718 -int, i719 int, i720 int, i721 int, i722 int, i723 int, i724 int, i725 int, i726 -int, i727 int, i728 int, i729 int, i730 int, i731 int, i732 int, i733 int, i734 -int, i735 int, i736 int, i737 int, i738 int, i739 int, i740 int, i741 int, i742 -int, i743 int, i744 int, i745 int, i746 int, i747 int, i748 int, i749 int, i750 -int, i751 int, i752 int, i753 int, i754 int, i755 int, i756 int, i757 int, i758 -int, i759 int, i760 int, i761 int, i762 int, i763 int, i764 int, i765 int, i766 -int, i767 int, i768 int, i769 int, i770 int, i771 int, i772 int, i773 int, i774 -int, i775 int, i776 int, i777 int, i778 int, i779 int, i780 int, i781 int, i782 -int, i783 int, i784 int, i785 int, i786 int, i787 int, i788 int, i789 int, i790 -int, i791 int, i792 int, i793 int, i794 int, i795 int, i796 int, i797 int, i798 -int, i799 int, i800 int, i801 int, i802 int, i803 int, i804 int, i805 int, i806 -int, i807 int, i808 int, i809 int, i810 int, i811 int, i812 int, i813 int, i814 -int, i815 int, i816 int, i817 int, i818 int, i819 int, i820 int, i821 int, i822 -int, i823 int, i824 int, i825 int, i826 int, i827 int, i828 int, i829 int, i830 -int, i831 int, i832 int, i833 int, i834 int, i835 int, i836 int, i837 int, i838 -int, i839 int, i840 int, i841 int, i842 int, i843 int, i844 int, i845 int, i846 -int, i847 int, i848 int, i849 int, i850 int, i851 int, i852 int, i853 int, i854 -int, i855 int, i856 int, i857 int, i858 int, i859 int, i860 int, i861 int, i862 -int, i863 int, i864 int, i865 int, i866 int, i867 int, i868 int, i869 int, i870 -int, i871 int, i872 int, i873 int, i874 int, i875 int, i876 int, i877 int, i878 -int, i879 int, i880 int, i881 int, i882 int, i883 int, i884 int, i885 int, i886 -int, i887 int, i888 int, i889 int, i890 int, i891 int, i892 int, i893 int, i894 -int, i895 int, i896 int, i897 int, i898 int, i899 int, i900 int, i901 int, i902 -int, i903 int, i904 int, i905 int, i906 int, i907 int, i908 int, i909 int, i910 -int, i911 int, i912 int, i913 int, i914 int, i915 int, i916 int, i917 int, i918 -int, i919 int, i920 int, i921 int, i922 int, i923 int, i924 int, i925 int, i926 -int, i927 int, i928 int, i929 int, i930 int, i931 int, i932 int, i933 int, i934 -int, i935 int, i936 int, i937 int, i938 int, i939 int, i940 int, i941 int, i942 -int, i943 int, i944 int, i945 int, i946 int, i947 int, i948 int, i949 int, i950 -int, i951 int, i952 int, i953 int, i954 int, i955 int, i956 int, i957 int, i958 -int, i959 int, i960 int, i961 int, i962 int, i963 int, i964 int, i965 int, i966 -int, i967 int, i968 int, i969 int, i970 int, i971 int, i972 int, i973 int, i974 -int, i975 int, i976 int, i977 int, i978 int, i979 int, i980 int, i981 int, i982 -int, i983 int, i984 int, i985 int, i986 int, i987 int, i988 int, i989 int, i990 -int, i991 int, i992 int, i993 int, i994 int, i995 int, i996 int, i997 int, i998 -int, i999 int, i1000 int, b blob) row_format=dynamic; -insert into t1 values (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, "Sergei"); -update t1 set b=repeat('a',256); -update t1 set i1=0, i2=0, i3=0, i4=0, i5=0, i6=0, i7=0; -check table t1; -drop table t1; - -# End of 4.1 tests diff --git a/mysql-test/t/join.test b/mysql-test/t/join.test index 2715f30b6cf..27558a31d68 100644 --- a/mysql-test/t/join.test +++ b/mysql-test/t/join.test @@ -115,6 +115,10 @@ select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using --replace_result "31 tables" "XX tables" "61 tables" "XX tables" --error 1116 select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a); +select a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a); +--replace_result "31 tables" "XX tables" "61 tables" "XX tables" +--error 1116 +select a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a); drop table t1; # @@ -145,6 +149,7 @@ CREATE TABLE t1 (d DATE NOT NULL); CREATE TABLE t2 (d DATE NOT NULL); INSERT INTO t1 (d) VALUES ('2001-08-01'),('0000-00-00'); SELECT * FROM t1 LEFT JOIN t2 USING (d) WHERE t2.d IS NULL; +SELECT * FROM t1 LEFT JOIN t2 USING (d) WHERE d IS NULL; SELECT * from t1 WHERE t1.d IS NULL; SELECT * FROM t1 WHERE 1/0 IS NULL; DROP TABLE t1,t2; @@ -268,6 +273,8 @@ CREATE TABLE t2 ( INSERT INTO t2 VALUES ('rivercats','cust',20); SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE emp.emp_id = 'psmith' AND lr.siteid = 'rivercats'; SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE lr.siteid = 'rivercats' AND emp.emp_id = 'psmith'; +SELECT rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE emp.emp_id = 'psmith' AND siteid = 'rivercats'; +SELECT rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE siteid = 'rivercats' AND emp.emp_id = 'psmith'; drop table t1,t2; # @@ -327,3 +334,258 @@ select t1.i,t2.i,t3.i from t2 right join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i drop table t1,t2,t3; # End of 4.1 tests + +# +# Tests for WL#2486 Natural/using join according to SQL:2003. +# +# NOTICE: +# - The tests are designed so that all statements, except MySQL +# extensions run on any SQL server. Please do no change. +# - Tests marked with TODO will be submitted as bugs. +# + +create table t1 (c int, b int); +create table t2 (a int, b int); +create table t3 (b int, c int); +create table t4 (y int, c int); +create table t5 (y int, z int); +create table t6 (a int, c int); + +insert into t1 values (10,1); +insert into t1 values (3 ,1); +insert into t1 values (3 ,2); +insert into t2 values (2, 1); +insert into t3 values (1, 3); +insert into t3 values (1,10); +insert into t4 values (11,3); +insert into t4 values (2, 3); +insert into t5 values (11,4); +insert into t6 values (2, 3); + +-- Views with simple natural join. +create algorithm=merge view v1a as +select * from t1 natural join t2; +-- as above, but column names are cross-renamed: a->c, c->b, b->a +create algorithm=merge view v1b(a,b,c) as +select * from t1 natural join t2; +-- as above, but column names are aliased: a->c, c->b, b->a +create algorithm=merge view v1c as +select b as a, c as b, a as c from t1 natural join t2; +-- as above, but column names are cross-renamed, and aliased +-- a->c->b, c->b->a, b->a->c +create algorithm=merge view v1d(b, a, c) as +select a as c, c as b, b as a from t1 natural join t2; + +-- Views with JOIN ... ON +create algorithm=merge view v2a as +select t1.c, t1.b, t2.a from t1 join (t2 join t4 on b + 1 = y) on t1.c = t4.c; +create algorithm=merge view v2b as +select t1.c as b, t1.b as a, t2.a as c +from t1 join (t2 join t4 on b + 1 = y) on t1.c = t4.c; + +-- Views with bigger natural join +create algorithm=merge view v3a as +select * from t1 natural join t2 natural join t3; +create algorithm=merge view v3b as +select * from t1 natural join (t2 natural join t3); + +-- View over views with mixed natural join and join ... on +create algorithm=merge view v4 as +select * from v2a natural join v3a; + +-- Nested natural/using joins. +select * from (t1 natural join t2) natural join (t3 natural join t4); +select * from (t1 natural join t2) natural left join (t3 natural join t4); +select * from (t3 natural join t4) natural right join (t1 natural join t2); +select * from (t1 natural left join t2) natural left join (t3 natural left join t4); +select * from (t4 natural right join t3) natural right join (t2 natural right join t1); +select * from t1 natural join t2 natural join t3 natural join t4; +select * from ((t1 natural join t2) natural join t3) natural join t4; +select * from t1 natural join (t2 natural join (t3 natural join t4)); +-- BUG#15355: this query fails in 'prepared statements' mode +-- select * from ((t3 natural join (t1 natural join t2)) natural join t4) natural join t5; +-- select * from ((t3 natural left join (t1 natural left join t2)) natural left join t4) natural left join t5; +select * from t5 natural right join (t4 natural right join ((t2 natural right join t1) natural right join t3)); +select * from (t1 natural join t2), (t3 natural join t4); +-- MySQL extension - nested comma ',' operator instead of cross join. +select * from t5 natural join ((t1 natural join t2), (t3 natural join t4)); +select * from ((t1 natural join t2), (t3 natural join t4)) natural join t5; +select * from t5 natural join ((t1 natural join t2) cross join (t3 natural join t4)); +select * from ((t1 natural join t2) cross join (t3 natural join t4)) natural join t5; + +select * from (t1 join t2 using (b)) join (t3 join t4 using (c)) using (c); +select * from (t1 join t2 using (b)) natural join (t3 join t4 using (c)); + + +-- Other clauses refer to NJ columns. +select a,b,c from (t1 natural join t2) natural join (t3 natural join t4) +where b + 1 = y or b + 10 = y group by b,c,a having min(b) < max(y) order by a; +select * from (t1 natural join t2) natural left join (t3 natural join t4) +where b + 1 = y or b + 10 = y group by b,c,a,y having min(b) < max(y) order by a, y; +select * from (t3 natural join t4) natural right join (t1 natural join t2) +where b + 1 = y or b + 10 = y group by b,c,a,y having min(b) < max(y) order by a, y; + +-- Qualified column references to NJ columns. +select * from t1 natural join t2 where t1.c > t2.a; +select * from t1 natural join t2 where t1.b > t2.b; +select * from t1 natural left join (t4 natural join t5) where t5.z is not NULL; + +-- Nested 'join ... on' - name resolution of ON conditions +select * from t1 join (t2 join t4 on b + 1 = y) on t1.c = t4.c; +select * from (t2 join t4 on b + 1 = y) join t1 on t1.c = t4.c; +select * from t1 natural join (t2 join t4 on b + 1 = y); +select * from (t1 cross join t2) join (t3 cross join t4) on (a < y and t2.b < t3.c); + +-- MySQL extension - 'join ... on' over nested comma operator +select * from (t1, t2) join (t3, t4) on (a < y and t2.b < t3.c); +select * from (t1 natural join t2) join (t3 natural join t4) on a = y; +select * from ((t3 join (t1 join t2 on c > a) on t3.b < t2.a) join t4 on y > t1.c) join t5 on z = t1.b + 3; + +-- MySQL extension - refererence qualified coalesced columns +select * from t1 natural join t2 where t1.b > 0; +select * from t1 natural join (t4 natural join t5) where t4.y > 7; +select * from (t4 natural join t5) natural join t1 where t4.y > 7; +select * from t1 natural left join (t4 natural join t5) where t4.y > 7; +select * from (t4 natural join t5) natural right join t1 where t4.y > 7; +select * from (t1 natural join t2) join (t3 natural join t4) on t1.b = t3.b; + +-- MySQL extension - select qualified columns of NJ columns +select t1.*, t2.* from t1 natural join t2; +select t1.*, t2.*, t3.*, t4.* from (t1 natural join t2) natural join (t3 natural join t4); + +-- Queries over subselects in the FROM clause +select * from (select * from t1 natural join t2) as t12 + natural join + (select * from t3 natural join t4) as t34; +select * from (select * from t1 natural join t2) as t12 + natural left join + (select * from t3 natural join t4) as t34; +select * from (select * from t3 natural join t4) as t34 + natural right join + (select * from t1 natural join t2) as t12; + +-- Queries over views +select * from v1a; +select * from v1b; +select * from v1c; +select * from v1d; +select * from v2a; +select * from v2b; +select * from v3a; +select * from v3b; +select * from v4; +select * from v1a natural join v2a; +select v2a.* from v1a natural join v2a; +select * from v1b join v2a on v1b.b = v2a.c; +select * from v1c join v2a on v1c.b = v2a.c; +select * from v1d join v2a on v1d.a = v2a.c; +select * from v1a join (t3 natural join t4) on a = y; + +-- TODO: add tests with correlated subqueries for natural join/join on. +-- related to BUG#15269 + + +---------------------------------------------------------------------- +-- Negative tests (tests for errors) +---------------------------------------------------------------------- +-- error 1052 +select * from t1 natural join (t3 cross join t4); -- works in Oracle - bug +-- error 1052 +select * from (t3 cross join t4) natural join t1; -- works in Oracle - bug +-- error 1052 +select * from t1 join (t2, t3) using (b); +-- error 1052 +select * from ((t1 natural join t2), (t3 natural join t4)) natural join t6; +-- error 1052 +select * from ((t1 natural join t2), (t3 natural join t4)) natural join t6; +-- error 1052 +select * from t6 natural join ((t1 natural join t2), (t3 natural join t4)); +-- error 1052 +select * from (t1 join t2 on t1.b=t2.b) natural join (t3 natural join t4); +-- error 1052 +select * from (t3 natural join t4) natural join (t1 join t2 on t1.b=t2.b); +-- this one is OK, the next equivalent one is incorrect (bug in Oracle) +-- error 1052 +select * from (t3 join (t4 natural join t5) on (b < z)) + natural join + (t1 natural join t2); +-- error 1052 +select * from (t1 natural join t2) natural join (t3 join (t4 natural join t5) on (b < z)); + +-- error 1054 +select t1.b from v1a; +-- error 1054 +select * from v1a join v1b on t1.b = t2.b; + +# +# Bug #17523 natural join and information_schema +# +select * from information_schema.statistics join information_schema.columns + using(table_name,column_name) where table_name='user'; + +drop table t1; +drop table t2; +drop table t3; +drop table t4; +drop table t5; +drop table t6; + +drop view v1a; +drop view v1b; +drop view v1c; +drop view v1d; +drop view v2a; +drop view v2b; +drop view v3a; +drop view v3b; +drop view v4; + +# +# BUG#15229 - columns of nested joins that are not natural joins incorrectly +# materialized +# +create table t1 (a1 int, a2 int); +create table t2 (a1 int, b int); +create table t3 (c1 int, c2 int); +create table t4 (c2 int); + +insert into t1 values (1,1); +insert into t2 values (1,1); +insert into t3 values (1,1); +insert into t4 values (1); + +select * from t1 join t2 using (a1) join t3 on b=c1 join t4 using (c2); +select * from t3 join (t1 join t2 using (a1)) on b=c1 join t4 using (c2); +select a2 from t1 join t2 using (a1) join t3 on b=c1 join t4 using (c2); +select a2 from t3 join (t1 join t2 using (a1)) on b=c1 join t4 using (c2); +select a2 from ((t1 join t2 using (a1)) join t3 on b=c1) join t4 using (c2); +select a2 from ((t1 natural join t2) join t3 on b=c1) natural join t4; + +drop table t1,t2,t3,t4; + +# +# BUG#15355: Common natural join column not resolved in prepared statement nested query +# +create table t1 (c int, b int); +create table t2 (a int, b int); +create table t3 (b int, c int); +create table t4 (y int, c int); +create table t5 (y int, z int); + +insert into t1 values (3,2); +insert into t2 values (1,2); +insert into t3 values (2,3); +insert into t4 values (1,3); +insert into t5 values (1,4); + +-- this fails +prepare stmt1 from "select * from ((t3 natural join (t1 natural join t2)) +natural join t4) natural join t5"; +execute stmt1; + +-- this works +select * from ((t3 natural join (t1 natural join t2)) natural join t4) + natural join t5; +drop table t1, t2, t3, t4, t5; + +# End of tests for WL#2486 - natural/using join diff --git a/mysql-test/t/join_crash.test b/mysql-test/t/join_crash.test index 68fd9226e41..2ec96dc2c28 100644 --- a/mysql-test/t/join_crash.test +++ b/mysql-test/t/join_crash.test @@ -92,18 +92,11 @@ select distinct t1.comments as comments, sum( t3.amount_received ) + sum( t3.adjustment ) as total_budget from - t1 , t2 as client_period , - t2 as project_period - left join - t3 - on - t3.project_ptr = t1.project_id - and t3.date_received <= '2001-03-22 14:15:09' - left join - t4 - on - t4.client_id = t1.client_ptr + t2 as project_period, + t3 left join t1 on (t3.project_ptr = t1.project_id and + t3.date_received <= '2001-03-22 14:15:09') + left join t4 on t4.client_id = t1.client_ptr where 1 and ( client_period.period_type = 'client_table' diff --git a/mysql-test/t/join_nested.test b/mysql-test/t/join_nested.test new file mode 100644 index 00000000000..69886d035bf --- /dev/null +++ b/mysql-test/t/join_nested.test @@ -0,0 +1,996 @@ + +--disable_warnings +DROP TABLE IF EXISTS t0,t1,t2,t3,t4,t5,t6,t7,t8,t9; +--enable_warnings + +CREATE TABLE t0 (a int, b int, c int); +CREATE TABLE t1 (a int, b int, c int); +CREATE TABLE t2 (a int, b int, c int); +CREATE TABLE t3 (a int, b int, c int); +CREATE TABLE t4 (a int, b int, c int); +CREATE TABLE t5 (a int, b int, c int); +CREATE TABLE t6 (a int, b int, c int); +CREATE TABLE t7 (a int, b int, c int); +CREATE TABLE t8 (a int, b int, c int); +CREATE TABLE t9 (a int, b int, c int); + +INSERT INTO t0 VALUES (1,1,0), (1,2,0), (2,2,0); +INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0); +INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0); +INSERT INTO t3 VALUES (1,2,0), (2,2,0); +INSERT INTO t4 VALUES (3,2,0), (4,2,0); +INSERT INTO t5 VALUES (3,1,0), (2,2,0), (3,3,0); +INSERT INTO t6 VALUES (3,2,0), (6,2,0), (6,1,0); +INSERT INTO t7 VALUES (1,1,0), (2,2,0); +INSERT INTO t8 VALUES (0,2,0), (1,2,0); +INSERT INTO t9 VALUES (1,1,0), (1,2,0), (3,3,0); + + +SELECT t2.a,t2.b + FROM t2; + +SELECT t3.a,t3.b + FROM t3; + +SELECT t4.a,t4.b + FROM t4; + +SELECT t3.a,t3.b,t4.a,t4.b + FROM t3,t4; + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM t2 + LEFT JOIN + (t3, t4) + ON t2.b=t4.b; + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b; + +EXPLAIN EXTENDED +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM t2 + LEFT JOIN + (t3, t4) + ON t2.b=t4.b + WHERE t3.a=1 OR t3.c IS NULL; + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM t2 + LEFT JOIN + (t3, t4) + ON t2.b=t4.b + WHERE t3.a=1 OR t3.c IS NULL; + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM t2 + LEFT JOIN + (t3, t4) + ON t2.b=t4.b + WHERE t3.a>1 OR t3.c IS NULL; + +SELECT t5.a,t5.b + FROM t5; + +SELECT t3.a,t3.b,t4.a,t4.b,t5.a,t5.b + FROM t3,t4,t5; + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,t5.a,t5.b + FROM t2 + LEFT JOIN + (t3, t4, t5) + ON t2.b=t4.b; + +EXPLAIN EXTENDED +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,t5.a,t5.b + FROM t2 + LEFT JOIN + (t3, t4, t5) + ON t2.b=t4.b + WHERE t3.a>1 OR t3.c IS NULL; + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,t5.a,t5.b + FROM t2 + LEFT JOIN + (t3, t4, t5) + ON t2.b=t4.b + WHERE t3.a>1 OR t3.c IS NULL; + +EXPLAIN EXTENDED +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,t5.a,t5.b + FROM t2 + LEFT JOIN + (t3, t4, t5) + ON t2.b=t4.b + WHERE (t3.a>1 OR t3.c IS NULL) AND + (t5.a<3 OR t5.c IS NULL); + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,t5.a,t5.b + FROM t2 + LEFT JOIN + (t3, t4, t5) + ON t2.b=t4.b + WHERE (t3.a>1 OR t3.c IS NULL) AND + (t5.a<3 OR t5.c IS NULL); + +SELECT t6.a,t6.b + FROM t6; + +SELECT t7.a,t7.b + FROM t7; + +SELECT t6.a,t6.b,t7.a,t7.b + FROM t6,t7; + +SELECT t8.a,t8.b + FROM t8; + +EXPLAIN EXTENDED +SELECT t6.a,t6.b,t7.a,t7.b,t8.a,t8.b + FROM (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10; + +SELECT t6.a,t6.b,t7.a,t7.b,t8.a,t8.b + FROM (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10; + +SELECT t5.a,t5.b + FROM t5; + +SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b + FROM t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b; + +SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b + FROM t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b AND + (t8.a < 1 OR t8.c IS NULL); + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b; + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b + FROM t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b; + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b + FROM t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + WHERE t2.a > 3 AND + (t6.a < 6 OR t6.c IS NULL); + +SELECT t1.a,t1.b + FROM t1; + +SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b + FROM t1 + LEFT JOIN + ( + t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + ) + ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND + (t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND + (t1.a != 2); + +SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b + FROM t1 + LEFT JOIN + ( + t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + ) + ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND + (t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND + (t1.a != 2) + WHERE (t2.a >= 4 OR t2.c IS NULL); + +SELECT t0.a,t0.b + FROM t0; + +EXPLAIN EXTENDED +SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b + FROM t0,t1 + LEFT JOIN + ( + t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + ) + ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND + (t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND + (t1.a != 2) + WHERE t0.a=1 AND + t0.b=t1.b AND + (t2.a >= 4 OR t2.c IS NULL); + +SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b + FROM t0,t1 + LEFT JOIN + ( + t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + ) + ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND + (t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND + (t1.a != 2) + WHERE t0.a=1 AND + t0.b=t1.b AND + (t2.a >= 4 OR t2.c IS NULL); + +EXPLAIN EXTENDED +SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b + FROM t0,t1 + LEFT JOIN + ( + t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + ) + ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND + (t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND + (t1.a != 2), + t9 + WHERE t0.a=1 AND + t0.b=t1.b AND + (t2.a >= 4 OR t2.c IS NULL) AND + (t3.a < 5 OR t3.c IS NULL) AND + (t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND + (t5.a >=2 OR t5.c IS NULL) AND + (t6.a >=4 OR t6.c IS NULL) AND + (t7.a <= 2 OR t7.c IS NULL) AND + (t8.a < 1 OR t8.c IS NULL) AND + (t8.b=t9.b OR t8.c IS NULL) AND + (t9.a=1); + +SELECT t9.a,t9.b + FROM t9; + +SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b + FROM t0,t1 + LEFT JOIN + ( + t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + ) + ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND + (t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND + (t1.a != 2), + t9 + WHERE t0.a=1 AND + t0.b=t1.b AND + (t2.a >= 4 OR t2.c IS NULL) AND + (t3.a < 5 OR t3.c IS NULL) AND + (t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND + (t5.a >=2 OR t5.c IS NULL) AND + (t6.a >=4 OR t6.c IS NULL) AND + (t7.a <= 2 OR t7.c IS NULL) AND + (t8.a < 1 OR t8.c IS NULL) AND + (t8.b=t9.b OR t8.c IS NULL) AND + (t9.a=1); + +SELECT t1.a,t1.b + FROM t1; + +SELECT t2.a,t2.b + FROM t2; + +SELECT t3.a,t3.b + FROM t3; + +SELECT t2.a,t2.b,t3.a,t3.b + FROM t2 + LEFT JOIN + t3 + ON t2.b=t3.b; + +SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b + FROM t1, t2 + LEFT JOIN + t3 + ON t2.b=t3.b + WHERE t1.a <= 2; + +SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b + FROM t1, t3 + RIGHT JOIN + t2 + ON t2.b=t3.b + WHERE t1.a <= 2; + +SELECT t3.a,t3.b,t4.a,t4.b + FROM t3,t4; + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b; + +SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM t1, t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b + WHERE t1.a <= 2; + +SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM t1, (t3, t4) + RIGHT JOIN + t2 + ON t3.a=1 AND t2.b=t4.b + WHERE t1.a <= 2; + +SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM t1, (t3, t4) + RIGHT JOIN + t2 + ON t3.a=1 AND t2.b=t4.b + WHERE t1.a <= 2; + +EXPLAIN EXTENDED +SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM t1, (t3, t4) + RIGHT JOIN + t2 + ON t3.a=1 AND t2.b=t4.b + WHERE t1.a <= 2; + +CREATE INDEX idx_b ON t2(b); + +EXPLAIN EXTENDED +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM (t3,t4) + LEFT JOIN + (t1,t2) + ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b; + +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM (t3,t4) + LEFT JOIN + (t1,t2) + ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b; + +EXPLAIN EXTENDED +SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b + FROM t0,t1 + LEFT JOIN + ( + t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + ) + ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND + (t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND + (t1.a != 2), + t9 + WHERE t0.a=1 AND + t0.b=t1.b AND + (t2.a >= 4 OR t2.c IS NULL) AND + (t3.a < 5 OR t3.c IS NULL) AND + (t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND + (t5.a >=2 OR t5.c IS NULL) AND + (t6.a >=4 OR t6.c IS NULL) AND + (t7.a <= 2 OR t7.c IS NULL) AND + (t8.a < 1 OR t8.c IS NULL) AND + (t8.b=t9.b OR t8.c IS NULL) AND + (t9.a=1); + +CREATE INDEX idx_b ON t4(b); +CREATE INDEX idx_b ON t5(b); + +EXPLAIN EXTENDED +SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b + FROM t0,t1 + LEFT JOIN + ( + t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + ) + ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND + (t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND + (t1.a != 2), + t9 + WHERE t0.a=1 AND + t0.b=t1.b AND + (t2.a >= 4 OR t2.c IS NULL) AND + (t3.a < 5 OR t3.c IS NULL) AND + (t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND + (t5.a >=2 OR t5.c IS NULL) AND + (t6.a >=4 OR t6.c IS NULL) AND + (t7.a <= 2 OR t7.c IS NULL) AND + (t8.a < 1 OR t8.c IS NULL) AND + (t8.b=t9.b OR t8.c IS NULL) AND + (t9.a=1); + +CREATE INDEX idx_b ON t8(b); + +EXPLAIN EXTENDED +SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b + FROM t0,t1 + LEFT JOIN + ( + t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + ) + ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND + (t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND + (t1.a != 2), + t9 + WHERE t0.a=1 AND + t0.b=t1.b AND + (t2.a >= 4 OR t2.c IS NULL) AND + (t3.a < 5 OR t3.c IS NULL) AND + (t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND + (t5.a >=2 OR t5.c IS NULL) AND + (t6.a >=4 OR t6.c IS NULL) AND + (t7.a <= 2 OR t7.c IS NULL) AND + (t8.a < 1 OR t8.c IS NULL) AND + (t8.b=t9.b OR t8.c IS NULL) AND + (t9.a=1); + +CREATE INDEX idx_b ON t1(b); +CREATE INDEX idx_a ON t0(a); + +EXPLAIN EXTENDED +SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b + FROM t0,t1 + LEFT JOIN + ( + t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + ) + ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND + (t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND + (t1.a != 2), + t9 + WHERE t0.a=1 AND + t0.b=t1.b AND + (t2.a >= 4 OR t2.c IS NULL) AND + (t3.a < 5 OR t3.c IS NULL) AND + (t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND + (t5.a >=2 OR t5.c IS NULL) AND + (t6.a >=4 OR t6.c IS NULL) AND + (t7.a <= 2 OR t7.c IS NULL) AND + (t8.a < 1 OR t8.c IS NULL) AND + (t8.b=t9.b OR t8.c IS NULL) AND + (t9.a=1); + +SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, + t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b + FROM t0,t1 + LEFT JOIN + ( + t2 + LEFT JOIN + (t3, t4) + ON t3.a=1 AND t2.b=t4.b, + t5 + LEFT JOIN + ( + (t6, t7) + LEFT JOIN + t8 + ON t7.b=t8.b AND t6.b < 10 + ) + ON t6.b >= 2 AND t5.b=t7.b + ) + ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND + (t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND + (t1.a != 2), + t9 + WHERE t0.a=1 AND + t0.b=t1.b AND + (t2.a >= 4 OR t2.c IS NULL) AND + (t3.a < 5 OR t3.c IS NULL) AND + (t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND + (t5.a >=2 OR t5.c IS NULL) AND + (t6.a >=4 OR t6.c IS NULL) AND + (t7.a <= 2 OR t7.c IS NULL) AND + (t8.a < 1 OR t8.c IS NULL) AND + (t8.b=t9.b OR t8.c IS NULL) AND + (t9.a=1); + +SELECT t2.a,t2.b + FROM t2; + +SELECT t3.a,t3.b + FROM t3; + +SELECT t2.a,t2.b,t3.a,t3.b + FROM t2 LEFT JOIN t3 ON t2.b=t3.b + WHERE t2.a = 4 OR (t2.a > 4 AND t3.a IS NULL); + +SELECT t2.a,t2.b,t3.a,t3.b + FROM t2 LEFT JOIN (t3) ON t2.b=t3.b + WHERE t2.a = 4 OR (t2.a > 4 AND t3.a IS NULL); + +ALTER TABLE t3 + CHANGE COLUMN a a1 int, + CHANGE COLUMN c c1 int; + +SELECT t2.a,t2.b,t3.a1,t3.b + FROM t2 LEFT JOIN t3 ON t2.b=t3.b + WHERE t2.a = 4 OR (t2.a > 4 AND t3.a1 IS NULL); + +SELECT t2.a,t2.b,t3.a1,t3.b + FROM t2 NATURAL LEFT JOIN t3 + WHERE t2.a = 4 OR (t2.a > 4 AND t3.a1 IS NULL); + +DROP TABLE t0,t1,t2,t3,t4,t5,t6,t7,t8,t9; + +CREATE TABLE t1 (a int); +CREATE TABLE t2 (a int); +CREATE TABLE t3 (a int); + +INSERT INTO t1 VALUES (1); +INSERT INTO t2 VALUES (2); +INSERT INTO t3 VALUES (2); +INSERT INTO t1 VALUES (2); + +#check proper syntax for nested outer joins + +SELECT * FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON t2.a=t3.a) ON t1.a=t3.a; + +#must be equivalent to: + +SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN t3 ON t2.a=t3.a ON t1.a=t3.a; + +#check that everything is al right when all tables contain not more than 1 row +#(bug #4922) + +DELETE FROM t1 WHERE a=2; +SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN t3 ON t2.a=t3.a ON t1.a=t3.a; +DELETE FROM t2; +SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN t3 ON t2.a=t3.a ON t1.a=t3.a; + +DROP TABLE t1,t2,t3; + +#on expression for a nested outer join does not depend on the outer table +#bug #4976 + +CREATE TABLE t1(a int, key (a)); +CREATE TABLE t2(b int, key (b)); +CREATE TABLE t3(c int, key (c)); + +INSERT INTO t1 VALUES (NULL), (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(10), (11), (12), (13), (14), (15), (16), (17), (18), (19); + +INSERT INTO t2 VALUES (NULL), (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(10), (11), (12), (13), (14), (15), (16), (17), (18), (19); + +INSERT INTO t3 VALUES (0), (1), (2), (3), (4), (5); + +EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON c < 3 and b = c; +EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; +SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; + +DELETE FROM t3; +EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; +SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; + +DROP TABLE t1,t2,t3; + +# +# Test for bug #11284: empty table in a nested left join +# + +CREATE TABLE t1 (c11 int); +CREATE TABLE t2 (c21 int); +CREATE TABLE t3 (c31 int); + +INSERT INTO t1 VALUES (4), (5); + +SELECT * FROM t1 LEFT JOIN t2 ON c11=c21; +EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON c11=c21; + +SELECT * FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON c21=c31) ON c11=c21; +EXPLAIN SELECT * FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON c21=c31) ON c11=c21; + +DROP TABLE t1,t2,t3; + +# +# Bug #12154: creation of temp table for a query with nested outer join +# + +CREATE TABLE t1 (goods int(12) NOT NULL, price varchar(128) NOT NULL); +INSERT INTO t1 VALUES (23, 2340), (26, 9900); + +CREATE TABLE t2 (goods int(12), name varchar(50), shop char(2)); +INSERT INTO t2 VALUES (23, 'as300', 'fr'), (26, 'as600', 'fr'); + +create table t3 (groupid int(12) NOT NULL, goodsid int(12) NOT NULL); +INSERT INTO t3 VALUES (3,23), (6,26); + +CREATE TABLE t4 (groupid int(12)); +INSERT INTO t4 VALUES (1), (2), (3), (4), (5), (6); + +SELECT * FROM +(SELECT DISTINCT gl.groupid, gp.price + FROM t4 gl + LEFT JOIN + (t3 g INNER JOIN t2 p ON g.goodsid = p.goods + INNER JOIN t1 gp ON p.goods = gp.goods) + ON gl.groupid = g.groupid and p.shop = 'fr') t; + +CREATE VIEW v1 AS +SELECT g.groupid groupid, p.goods goods, + p.name name, p.shop shop, + gp.price price + FROM t3 g INNER JOIN t2 p ON g.goodsid = p.goods + INNER JOIN t1 gp on p.goods = gp.goods; + +CREATE VIEW v2 AS +SELECT DISTINCT g.groupid, fr.price + FROM t4 g + LEFT JOIN + v1 fr on g.groupid = fr.groupid and fr.shop = 'fr'; + +SELECT * FROM v2; + +SELECT * FROM +(SELECT DISTINCT g.groupid, fr.price + FROM t4 g + LEFT JOIN + v1 fr on g.groupid = fr.groupid and fr.shop = 'fr') t; + +DROP VIEW v1,v2; +DROP TABLE t1,t2,t3,t4; + +# +# Bug #13545: problem with NATURAL/USING joins. +# + +CREATE TABLE t1(a int); +CREATE TABLE t2(b int); +CREATE TABLE t3(c int, d int); +CREATE TABLE t4(d int); +CREATE TABLE t5(e int, f int); +CREATE TABLE t6(f int); +CREATE VIEW v1 AS + SELECT e FROM t5 JOIN t6 ON t5.e=t6.f; +CREATE VIEW v2 AS + SELECT e FROM t5 NATURAL JOIN t6; + +SELECT t1.a FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c JOIN t4 USING(d); +--error 1054 +SELECT t1.x FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c JOIN t4 USING(d); +SELECT t1.a FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c NATURAL JOIN t4; +--error 1054 +SELECT t1.x FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c NATURAL JOIN t4; +SELECT v1.e FROM v1 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d); +--error 1054 +SELECT v1.x FROM v1 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d); +SELECT v2.e FROM v2 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d); +--error 1054 +SELECT v2.x FROM v2 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d); + +DROP VIEW v1, v2; +DROP TABLE t1, t2, t3, t4, t5, t6; + +# +# BUG#13126 -test case from bug report +# +create table t1 (id1 int(11) not null); +insert into t1 values (1),(2); + +create table t2 (id2 int(11) not null); +insert into t2 values (1),(2),(3),(4); + +create table t3 (id3 char(16) not null); +insert into t3 values ('100'); + +create table t4 (id2 int(11) not null, id3 char(16)); + +create table t5 (id1 int(11) not null, key (id1)); +insert into t5 values (1),(2),(1); + +create view v1 as + select t4.id3 from t4 join t2 on t4.id2 = t2.id2; + +select t1.id1 from t1 inner join (t3 left join v1 on t3.id3 = v1.id3); + +drop view v1; +drop table t1, t2, t3, t4, t5; + +create table t0 (a int); +insert into t0 values (0),(1),(2),(3); +create table t1(a int); +insert into t1 select A.a + 10*(B.a) from t0 A, t0 B; + +create table t2 (a int, b int); +insert into t2 values (1,1), (2,2), (3,3); + +create table t3(a int, b int, filler char(200), key(a)); +insert into t3 select a,a,'filler' from t1; +insert into t3 select a,a,'filler' from t1; + +create table t4 like t3; +insert into t4 select * from t3; +insert into t4 select * from t3; + +create table t5 like t4; +insert into t5 select * from t4; +insert into t5 select * from t4; + +create table t6 like t5; +insert into t6 select * from t5; +insert into t6 select * from t5; + +create table t7 like t6; +insert into t7 select * from t6; +insert into t7 select * from t6; + +--replace_column 9 X +explain select * from t4 join + t2 left join (t3 join t5 on t5.a=t3.b) on t3.a=t2.b where t4.a<=>t3.b; + +--replace_column 9 X +explain select * from (t4 join t6 on t6.a=t4.b) right join t3 on t4.a=t3.b + join t2 left join (t5 join t7 on t7.a=t5.b) on t5.a=t2.b where t3.a<=>t2.b; + +--replace_column 9 X +explain select * from t2 left join + (t3 left join (t4 join t6 on t6.a=t4.b) on t4.a=t3.b + join t5 on t5.a=t3.b) on t3.a=t2.b; + +drop table t0, t1, t2, t3, t4, t5, t6, t7; + +# BUG#16393 +create table t1 (a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t2 (a int, filler char(100), key(a)); +insert into t2 select A.a + 10*B.a, '' from t1 A, t1 B; +create table t3 like t2; +insert into t3 select * from t2; + +explain select * from t1 left join + (t2 left join t3 on (t2.a = t3.a)) + on (t1.a = t2.a); +drop table t1, t2, t3; + +# +# Bug #16260: single row table in the inner nest of an outer join +# + +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, type varchar(10)); +CREATE TABLE t2 (pid int NOT NULL PRIMARY KEY, type varchar(10)); +CREATE TABLE t3 (cid int NOT NULL PRIMARY KEY, + id int NOT NULL, + pid int NOT NULL); + +INSERT INTO t1 VALUES (1, 'A'), (3, 'C'); +INSERT INTO t2 VALUES (1, 'A'), (3, 'C'); +INSERT INTO t3 VALUES (1, 1, 1), (3, 3, 3); + +SELECT * FROM t1 p LEFT JOIN (t3 JOIN t1) + ON (t1.id=t3.id AND t1.type='B' AND p.id=t3.id) + LEFT JOIN t2 ON (t3.pid=t2.pid) + WHERE p.id=1; + +CREATE VIEW v1 AS + SELECT t3.* FROM t3 JOIN t1 ON t1.id=t3.id AND t1.type='B'; + +SELECT * FROM t1 p LEFT JOIN v1 ON p.id=v1.id + LEFT JOIN t2 ON v1.pid=t2.pid + WHERE p.id=1; + +DROP VIEW v1; +DROP TABLE t1,t2,t3; + + +# +# Test for bug #18279: crash when on conditions are moved out of a nested join +# to the on conditions for the nest + +CREATE TABLE t1 (id1 int PRIMARY KEY, id2 int); +CREATE TABLE t2 (id1 int PRIMARY KEY, id2 int); +CREATE TABLE t3 (id1 int PRIMARY KEY, id2 int); +CREATE TABLE t4 (id1 int PRIMARY KEY, id2 int); +CREATE TABLE t5 (id1 int PRIMARY KEY, id2 int); + +SELECT t1.id1 AS id, t5.id1 AS ngroupbynsa + FROM t1 INNER JOIN t2 ON t2.id2 = t1.id1 + LEFT OUTER JOIN + (t3 INNER JOIN t4 ON t4.id1 = t3.id2 INNER JOIN t5 ON t4.id2 = t5.id1) + ON t3.id2 IS NOT NULL + WHERE t1.id1=2; + +PREPARE stmt FROM +"SELECT t1.id1 AS id, t5.id1 AS ngroupbynsa + FROM t1 INNER JOIN t2 ON t2.id2 = t1.id1 + LEFT OUTER JOIN + (t3 INNER JOIN t4 ON t4.id1 = t3.id2 INNER JOIN t5 ON t4.id2 = t5.id1) + ON t3.id2 IS NOT NULL + WHERE t1.id1=2"; + +EXECUTE stmt; +EXECUTE stmt; +EXECUTE stmt; +EXECUTE stmt; + +INSERT INTO t1 VALUES (1,1), (2,1), (3,2); +INSERT INTO t2 VALUES (2,1), (3,2), (4,3); +INSERT INTO t3 VALUES (1,1), (3,2), (2,NULL); +INSERT INTO t4 VALUES (1,1), (2,1), (3,3); +INSERT INTO t5 VALUES (1,1), (2,2), (3,3), (4,3); + +EXECUTE stmt; +EXECUTE stmt; +EXECUTE stmt; +EXECUTE stmt; + +SELECT t1.id1 AS id, t5.id1 AS ngroupbynsa + FROM t1 INNER JOIN t2 ON t2.id2 = t1.id1 + LEFT OUTER JOIN + (t3 INNER JOIN t4 ON t4.id1 = t3.id2 INNER JOIN t5 ON t4.id2 = t5.id1) + ON t3.id2 IS NOT NULL + WHERE t1.id1=2; + +DROP TABLE t1,t2,t3,t4,t5; + diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test index 05cd2fb152e..20462f2ca3f 100644 --- a/mysql-test/t/join_outer.test +++ b/mysql-test/t/join_outer.test @@ -3,7 +3,7 @@ # --disable_warnings -drop table if exists t1,t2,t3,t4,t5; +drop table if exists t0,t1,t2,t3,t4,t5; --enable_warnings CREATE TABLE t1 ( @@ -34,13 +34,13 @@ explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; select t1.*,t2.*,t3.a from t1 left join t2 on (t1.a=t2.a) left join t1 as t3 on (t2.a=t3.a); # The next query should rearange the left joins to get this to work ---error 1120 +--error 1054 explain select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a); ---error 1120 +--error 1054 select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a); # The next query should give an error in MySQL ---error 1120 +--error 1054 select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t2.a=t3.a); # Test of inner join @@ -135,7 +135,7 @@ INSERT INTO t1 VALUES (10363,'Tecniques de Comunicacio Oral i Escrita','Tecnicas INSERT INTO t1 VALUES (11403,'Projecte Fi de Carrera','Proyecto Fin de Carrera','Projecte Fi de Carrera','PFC',9.0,NULL,NULL,NULL); INSERT INTO t1 VALUES (11404,'+lgebra lineal','Algebra lineal','+lgebra lineal','+lgebra lineal',15.0,NULL,NULL,NULL); INSERT INTO t1 VALUES (11405,'+lgebra lineal','Algebra lineal','+lgebra lineal','+lgebra lineal',18.0,NULL,NULL,NULL); -INSERT INTO t1 VALUES (11406,'Calcul Infinitesimal','Cßlculo Infinitesimal','Calcul Infinitesimal','Calcul Infinitesimal',15.0,NULL,NULL,NULL); +INSERT INTO t1 VALUES (11406,'Calcul Infinitesimal','Cßlculo Infinitesimal','Calcul Infinitesimal','Calcul Infinitesimal',15.0,NULL,NULL,NULL); CREATE TABLE t2 ( idAssignatura int(11) DEFAULT '0' NOT NULL, @@ -292,7 +292,7 @@ insert into t3 values (1); insert into t4 values (1,1); insert into t5 values (1,1); ---error 1120 +--error 1054 explain select * from t3 left join t4 on t4.seq_1_id = t2.t2_id left join t1 on t1.t1_id = t4.seq_0_id left join t5 on t5.seq_0_id = t1.t1_id left join t2 on t2.t2_id = t5.seq_1_id where t3.t3_id = 23; drop table t1,t2,t3,t4,t5; @@ -430,6 +430,10 @@ insert into t1 values(1),(2); insert into t2 values(2),(3); insert into t3 values(2),(4); select * from t1 natural left join t2 natural left join t3; +select * from t1 natural left join t2 where (t2.i is not null)=0; +select * from t1 natural left join t2 where (t2.i is not null) is not null; +select * from t1 natural left join t2 where (i is not null)=0; +select * from t1 natural left join t2 where (i is not null) is not null; drop table t1,t2,t3; # @@ -438,7 +442,6 @@ drop table t1,t2,t3; create table t1 (f1 integer,f2 integer,f3 integer); create table t2 (f2 integer,f4 integer); create table t3 (f3 integer,f5 integer); ---error 1054 select * from t1 left outer join t2 using (f2) left outer join t3 using (f3); @@ -567,34 +570,68 @@ SELECT t1.flag_name,t2.flag_value DROP TABLE t1,t2; -CREATE TABLE invoice ( +CREATE TABLE t1 ( id int(11) unsigned NOT NULL auto_increment, text_id int(10) unsigned default NULL, PRIMARY KEY (id) ); -INSERT INTO invoice VALUES("1", "0"); -INSERT INTO invoice VALUES("2", "10"); +INSERT INTO t1 VALUES("1", "0"); +INSERT INTO t1 VALUES("2", "10"); -CREATE TABLE text_table ( +CREATE TABLE t2 ( text_id char(3) NOT NULL default '', language_id char(3) NOT NULL default '', text_data text, PRIMARY KEY (text_id,language_id) ); -INSERT INTO text_table VALUES("0", "EN", "0-EN"); -INSERT INTO text_table VALUES("0", "SV", "0-SV"); -INSERT INTO text_table VALUES("10", "EN", "10-EN"); -INSERT INTO text_table VALUES("10", "SV", "10-SV"); +INSERT INTO t2 VALUES("0", "EN", "0-EN"); +INSERT INTO t2 VALUES("0", "SV", "0-SV"); +INSERT INTO t2 VALUES("10", "EN", "10-EN"); +INSERT INTO t2 VALUES("10", "SV", "10-SV"); +SELECT t1.id, t1.text_id, t2.text_data + FROM t1 LEFT JOIN t2 + ON t1.text_id = t2.text_id + AND t2.language_id = 'SV' + WHERE (t1.id LIKE '%' OR t2.text_data LIKE '%'); + +DROP TABLE t1, t2; + +# Test for bug #5896 + +CREATE TABLE t0 (a0 int PRIMARY KEY); +CREATE TABLE t1 (a1 int PRIMARY KEY); +CREATE TABLE t2 (a2 int); +CREATE TABLE t3 (a3 int); +INSERT INTO t0 VALUES (1); +INSERT INTO t1 VALUES (1); +INSERT INTO t2 VALUES (1), (2); +INSERT INTO t3 VALUES (1), (2); + +SELECT * FROM t1 LEFT JOIN t2 ON a1=0; +EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON a1=0; +SELECT * FROM t1 LEFT JOIN (t2,t3) ON a1=0; +EXPLAIN SELECT * FROM t1 LEFT JOIN (t2,t3) ON a1=0; +SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=0 WHERE a0=a1; +EXPLAIN SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=0 WHERE a0=a1; + +INSERT INTO t0 VALUES (0); +INSERT INTO t1 VALUES (0); +SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=5 WHERE a0=a1 AND a0=1; +EXPLAIN SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=5 WHERE a0=a1 AND a0=1; + +# Test for BUG#4480 +drop table t1,t2; +create table t1 (a int, b int); +insert into t1 values (1,1),(2,2),(3,3); +create table t2 (a int, b int); +insert into t2 values (1,1), (2,2); -SELECT invoice.id, invoice.text_id, text_table.text_data - FROM invoice LEFT JOIN text_table - ON invoice.text_id = text_table.text_id - AND text_table.language_id = 'SV' - WHERE (invoice.id LIKE '%' OR text_table.text_data LIKE '%'); +select * from t2 right join t1 on t2.a=t1.a; +select straight_join * from t2 right join t1 on t2.a=t1.a; -DROP TABLE invoice, text_table; +DROP TABLE t0,t1,t2,t3; # # Test for bug #9017: left join mistakingly converted to inner join @@ -622,9 +659,60 @@ insert into t1 values (1,"aaaaaaaaaa"),(2,"bbbbbbbbbb"); insert into t2 values (1,"cccccccccc"),(2,"dddddddddd"); select group_concat(t1.b,t2.c) from t1 left join t2 using(a) group by t1.a; select group_concat(t1.b,t2.c) from t1 inner join t2 using(a) group by t1.a; +select group_concat(t1.b,t2.c) from t1 left join t2 using(a) group by a; +select group_concat(t1.b,t2.c) from t1 inner join t2 using(a) group by a; drop table t1, t2; set group_concat_max_len=default; +# End of 4.1 tests + +# +# BUG#10162 - ON is merged with WHERE, left join is convered to a regular join +# +create table t1 (gid smallint(5) unsigned not null, x int(11) not null, y int(11) not null, art int(11) not null, primary key (gid,x,y)); +insert t1 values (1, -5, -8, 2), (1, 2, 2, 1), (1, 1, 1, 1); +create table t2 (gid smallint(5) unsigned not null, x int(11) not null, y int(11) not null, id int(11) not null, primary key (gid,id,x,y), key id (id)); +insert t2 values (1, -5, -8, 1), (1, 1, 1, 1), (1, 2, 2, 1); +create table t3 ( set_id smallint(5) unsigned not null, id tinyint(4) unsigned not null, name char(12) not null, primary key (id,set_id)); +insert t3 values (0, 1, 'a'), (1, 1, 'b'), (0, 2, 'c'), (1, 2, 'd'), (1, 3, 'e'), (1, 4, 'f'), (1, 5, 'g'), (1, 6, 'h'); +explain select name from t1 left join t2 on t1.x = t2.x and t1.y = t2.y +left join t3 on t1.art = t3.id where t2.id =1 and t2.x = -5 and t2.y =-8 +and t1.gid =1 and t2.gid =1 and t3.set_id =1; +drop tables t1,t2,t3; + +# +# Test for bug #9938: invalid conversion from outer join to inner join +# for queries containing indirect reference in WHERE clause +# + +CREATE TABLE t1 (EMPNUM INT, GRP INT); +INSERT INTO t1 VALUES (0, 10); +INSERT INTO t1 VALUES (2, 30); + +CREATE TABLE t2 (EMPNUM INT, NAME CHAR(5)); +INSERT INTO t2 VALUES (0, 'KERI'); +INSERT INTO t2 VALUES (9, 'BARRY'); + +CREATE VIEW v1 AS +SELECT COALESCE(t2.EMPNUM,t1.EMPNUM) AS EMPNUM, NAME, GRP + FROM t2 LEFT OUTER JOIN t1 ON t2.EMPNUM=t1.EMPNUM; + +SELECT * FROM v1; +SELECT * FROM v1 WHERE EMPNUM < 10; + +DROP VIEW v1; +DROP TABLE t1,t2; + +# +# Test for bug #11285: false Item_equal on expression in outer join +# + +CREATE TABLE t1 (c11 int); +CREATE TABLE t2 (c21 int); +INSERT INTO t1 VALUES (30), (40), (50); +INSERT INTO t2 VALUES (300), (400), (500); +SELECT * FROM t1 LEFT JOIN t2 ON (c11=c21 AND c21=30) WHERE c11=40; +DROP TABLE t1, t2; # # Test for bugs # #12101: erroneously applied outer join elimination in case of WHERE NOT BETWEEN @@ -671,4 +759,46 @@ EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a > IF(t1.a = t2.b DROP TABLE t1,t2; -# End of 4.1 tests +# +# Bug 19396: LEFT OUTER JOIN over views in curly braces +# +--disable_warnings +DROP VIEW IF EXISTS v1,v2; +DROP TABLE IF EXISTS t1,t2; +--enable_warnings + +CREATE TABLE t1 (a int); +CREATE table t2 (b int); +INSERT INTO t1 VALUES (1), (2), (3), (4), (1), (1), (3); +INSERT INTO t2 VALUES (2), (3); + +CREATE VIEW v1 AS SELECT a FROM t1 JOIN t2 ON t1.a=t2.b; +CREATE VIEW v2 AS SELECT b FROM t2 JOIN t1 ON t2.b=t1.a; + +SELECT v1.a, v2. b + FROM v1 LEFT OUTER JOIN v2 ON (v1.a=v2.b) AND (v1.a >= 3) + GROUP BY v1.a; +SELECT v1.a, v2. b + FROM { OJ v1 LEFT OUTER JOIN v2 ON (v1.a=v2.b) AND (v1.a >= 3) } + GROUP BY v1.a; + +DROP VIEW v1,v2; +DROP TABLE t1,t2; + +# +# Bug 19816: LEFT OUTER JOIN with constant ORed predicates in WHERE clause +# + +CREATE TABLE t1 (a int); +CREATE TABLE t2 (b int); +INSERT INTO t1 VALUES (1), (2), (3), (4); +INSERT INTO t2 VALUES (2), (3); + +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1); + +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1 OR 1); +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (0 OR 1); +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 2=2); +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 1=0); + +DROP TABLE t1,t2; diff --git a/mysql-test/t/key.test b/mysql-test/t/key.test index 9aab8a13b06..3767f5f885e 100644 --- a/mysql-test/t/key.test +++ b/mysql-test/t/key.test @@ -129,7 +129,11 @@ create table t2 INSERT t2 select * from t1; SELECT * FROM t2 WHERE name='[T,U]_axpy'; SELECT * FROM t2 WHERE name='[T,U]_axpby'; -drop table t1,t2; +# Test possible problems with warnings in CREATE ... SELECT +CREATE TABLE t3 SELECT * FROM t2 WHERE name='[T,U]_axpby'; +SELECT * FROM t2 WHERE name='[T,U]_axpby'; + +drop table t1,t2,t3; # # Test bug with long primary key @@ -295,7 +299,7 @@ drop table t1; # create dedicated error code for this and # and change my_printf_error() to my_error ---error 1105 +--error 1391 create table t1 (c char(10), index (c(0))); # @@ -348,5 +352,35 @@ insert into t1 values (2,' \t\tTest String'); insert into t1 values (3,' \n\tTest String'); update t1 set c2 = 'New Test String' where c1 = 1; select * from t1; +drop table t1; + +# +# If we use a partial field for a key that is actually the length of the +# field, and we extend the field, we end up with a key that includes the +# whole new length of the field. +# +create table t1 (a varchar(10), b varchar(10), key(a(10),b(10))); +show create table t1; +alter table t1 modify b varchar(20); +show create table t1; +alter table t1 modify a varchar(20); +show create table t1; +drop table t1; + +# +# Bug #11227: Incorrectly reporting 'MUL' vs. 'UNI' on varchar +# +create table t1 (a int not null primary key, b varchar(20) not null unique); +desc t1; +drop table t1; +create table t1 (a int not null primary key, b int not null unique); +desc t1; +drop table t1; +create table t1 (a int not null primary key, b varchar(20) not null, unique (b(10))); +desc t1; +drop table t1; +create table t1 (a int not null primary key, b varchar(20) not null, c varchar(20) not null, unique(b(10),c(10))); +desc t1; +drop table t1; # End of 4.1 tests diff --git a/mysql-test/t/key_cache.test b/mysql-test/t/key_cache.test index 6e772a7a9ad..4001e0df4af 100644 --- a/mysql-test/t/key_cache.test +++ b/mysql-test/t/key_cache.test @@ -207,4 +207,11 @@ SELECT @@key_cache_block_size; CHECK TABLE t1; DROP TABLE t1,t2; +# +# Bug#10473 - Can't set 'key_buffer_size' system variable to ZERO +# (One cannot drop the default key cache.) +# +set @@global.key_buffer_size=0; +select @@global.key_buffer_size; + # End of 4.1 tests diff --git a/mysql-test/t/keywords.test b/mysql-test/t/keywords.test index 96c3dc3f17c..de0159a950e 100644 --- a/mysql-test/t/keywords.test +++ b/mysql-test/t/keywords.test @@ -6,10 +6,12 @@ drop table if exists t1; --enable_warnings -create table t1 (time time, date date, timestamp timestamp); -insert into t1 values ("12:22:22","97:02:03","1997-01-02"); +create table t1 (time time, date date, timestamp timestamp, +quarter int, week int, year int, timestampadd int, timestampdiff int); +insert into t1 values ("12:22:22","97:02:03","1997-01-02",1,2,3,4,5); select * from t1; -select t1.time+0,t1.date+0,t1.timestamp+0,concat(date," ",time) from t1; +select t1.time+0,t1.date+0,t1.timestamp+0,concat(date," ",time), + t1.quarter+t1.week, t1.year+timestampadd, timestampdiff from t1; drop table t1; create table events(binlog int); insert into events values(1); diff --git a/mysql-test/t/kill.test b/mysql-test/t/kill.test index 50c4239b45e..f8ba649b3eb 100644 --- a/mysql-test/t/kill.test +++ b/mysql-test/t/kill.test @@ -15,6 +15,7 @@ connection con1; drop table if exists t1, t2, t3; --enable_warnings +--disable_reconnect create table t1 (kill_id int); insert into t1 values(connection_id()); @@ -24,12 +25,18 @@ select ((@id := kill_id) - kill_id) from t1; kill @id; connection con1; ---sleep 1 +--sleep 2 ---disable_reconnect -# this statement should fail ---error 2006,2013 +--disable_query_log +--disable_result_log +# One of the following statements should fail +--error 0,2006,2013 select 1; +--error 0,2006,2013 +select 1; +--enable_query_log +--enable_result_log + --enable_reconnect # this should work, and we should have a new connection_id() select ((@id := kill_id) - kill_id) from t1; @@ -40,7 +47,6 @@ connection con2; select 4; drop table t1; connection default; -disconnect con2; --error 1064 kill (select count(*) from mysql.user); @@ -84,10 +90,27 @@ connection conn1; -- error 1053,2013 reap; -disconnect conn1; -disconnect conn2; connection default; drop table t1, t2, t3; # End of 4.1 tests + +# +# test of blocking of sending ERROR after OK or EOF +# +connection con1; +select get_lock("a", 10); +connection con2; +let $ID= `select connection_id()`; +send select get_lock("a", 10); +real_sleep 2; +connection con1; +disable_query_log; +eval kill query $ID; +enable_query_log; +connection con2; +reap; +select 1; +connection con1; +select RELEASE_LOCK("a"); diff --git a/mysql-test/t/kill_n_check.sh b/mysql-test/t/kill_n_check.sh new file mode 100755 index 00000000000..a54fb6ef8bb --- /dev/null +++ b/mysql-test/t/kill_n_check.sh @@ -0,0 +1,115 @@ +#!/bin/sh + +########################################################################### + +# NOTE: this script returns 0 (success) even in case of failure. This is +# because this script is executed under mysql-test-run[.pl] and it's better to +# examine particular problem in log file, than just having said that the test +# case has failed. + +########################################################################### + +check_restart() +{ + if [ ! -r "$pid_path" ]; then + user_msg='the process was killed' + return 1 + fi + + new_pid=`cat "$pid_path" 2>/dev/null` + + if [ $? -eq 0 -a "$original_pid" = "$new_pid" ]; then + user_msg='the process was not restarted' + return 1 + fi + + user_msg='the process was restarted' + return 0 +} + +########################################################################### + +if [ $# -ne 3 ]; then + echo "Usage: kill_n_check.sh <pid file path> killed|restarted <timeout>" + exit 0 +fi + +pid_path="$1" +expected_result="$2" +total_timeout="$3" + +if [ "$expected_result" != 'killed' -a \ + "$expected_result" != 'restarted' ]; then + echo "Error: invalid second argument ('killed' or 'restarted' expected)." + exit 0 +fi + +if [ -z "$pid_path" ]; then + echo "Error: invalid PID path ($pid_path)." + exit 0 +fi + +if [ ! -r "$pid_path" ]; then + echo "Error: PID file ($pid_path) does not exist." + exit 0 +fi + +if [ -z "$total_timeout" ]; then + echo "Error: timeout is not specified." + exit 0 +fi + +########################################################################### + +original_pid=`cat "$pid_path"` + +echo "Killing the process..." + +kill -9 $original_pid + +########################################################################### + +echo "Sleeping..." + +if [ "$expected_result" = "restarted" ]; then + + # Wait for the process to restart. + + cur_attempt=1 + + while true; do + + if check_restart; then + echo "Success: $user_msg." + exit 0 + fi + + [ $cur_attempt -ge $total_timeout ] && break + + sleep 1 + + cur_attempt=`expr $cur_attempt + 1` + + done + + echo "Error: $user_msg." + exit 0 + +else # $expected_result == killed + + # Here we have to sleep for some long time to ensure that the process will + # not be restarted. + + sleep $total_timeout + + new_pid=`cat "$pid_path" 2>/dev/null` + + if [ "$new_pid" -a "$new_pid" -ne "$original_pid" ]; then + echo "Error: the process was restarted." + else + echo "Success: the process was killed." + fi + + exit 0 + +fi diff --git a/mysql-test/t/limit.test b/mysql-test/t/limit.test index f70cf835588..cf7789428b2 100644 --- a/mysql-test/t/limit.test +++ b/mysql-test/t/limit.test @@ -6,7 +6,7 @@ drop table if exists t1; --enable_warnings -create table t1 (a int primary key, b int not null); +create table t1 (a int not null default 0 primary key, b int not null default 0); insert into t1 () values (); -- Testing default values insert into t1 values (1,1),(2,1),(3,1); update t1 set a=4 where b=1 limit 1; diff --git a/mysql-test/t/loaddata.test b/mysql-test/t/loaddata.test index e989cb0b2ac..27c8005ca0c 100644 --- a/mysql-test/t/loaddata.test +++ b/mysql-test/t/loaddata.test @@ -3,29 +3,29 @@ # --disable_warnings -drop table if exists t1; +drop table if exists t1, t2; --enable_warnings create table t1 (a date, b date, c date not null, d date); -load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ','; -load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES; +load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ','; +load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES; SELECT * from t1; truncate table t1; -load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d); +load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d); SELECT * from t1; drop table t1; create table t1 (a text, b text); -load data infile '../../std_data/loaddata2.dat' into table t1 fields terminated by ',' enclosed by ''''; +load data infile '../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by ''''; select concat('|',a,'|'), concat('|',b,'|') from t1; drop table t1; create table t1 (a int, b char(10)); -load data infile '../../std_data/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines; +load data infile '../std_data_ln/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines; select * from t1; truncate table t1; -load data infile '../../std_data/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines; +load data infile '../std_data_ln/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines; # The empty line last comes from the end line field in the file select * from t1; @@ -38,23 +38,23 @@ SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE=NO_AUTO_VALUE_ON_ZERO; create table t1(id integer not null auto_increment primary key); insert into t1 values(0); disable_query_log; -eval SELECT * INTO OUTFILE '$MYSQL_TEST_DIR/var/tmp/t1' from t1; +eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1' from t1; delete from t1; -eval load data infile '$MYSQL_TEST_DIR/var/tmp/t1' into table t1; +eval load data infile '$MYSQLTEST_VARDIR/tmp/t1' into table t1; enable_query_log; select * from t1; ---exec rm $MYSQL_TEST_DIR/var/tmp/t1 +--exec rm $MYSQLTEST_VARDIR/tmp/t1 disable_query_log; -eval SELECT * INTO OUTFILE '$MYSQL_TEST_DIR/var/tmp/t1' +eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1' FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n' FROM t1; delete from t1; -eval load data infile '$MYSQL_TEST_DIR/var/tmp/t1' into table t1 +eval load data infile '$MYSQLTEST_VARDIR/tmp/t1' into table t1 FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n'; enable_query_log; select * from t1; ---exec rm $MYSQL_TEST_DIR/var/tmp/t1 +--exec rm $MYSQLTEST_VARDIR/tmp/t1 SET @@SQL_MODE=@OLD_SQL_MODE; drop table t1; @@ -63,8 +63,54 @@ drop table t1; # ENCLOSED # create table t1 (a varchar(20), b varchar(20)); -load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by ',' enclosed by '"' escaped by '"' (a,b); +load data infile '../std_data_ln/loaddata_dq.dat' into table t1 fields terminated by ',' enclosed by '"' escaped by '"' (a,b); select * from t1; drop table t1; # End of 4.1 tests + +# +# Let us test extended LOAD DATA features +# +create table t1 (a int default 100, b int, c varchar(60)); +# we can do something like this +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set b=@b+10, c=concat("b=",@b); +select * from t1; +truncate table t1; +# we can use filled fields in expressions +# we also assigning NULL value to field with non-NULL default here +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set c= if(a is null,"oops",a); +select * from t1; +truncate table t1; +# we even can use variables in set clause, and missed columns will be set +# with default values +set @c:=123; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, b) set c= if(@a is null,@c,b); +select * from t1; +# let us test side-effect of such load +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, @b); +select * from t1; +select @a, @b; +truncate table t1; +# now going to test fixed field-row file format +load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c="Wow"; +select * from t1; +truncate table t1; +# this also should work +load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c=concat(a,"+",b,"+",@c,"+",b,"+",if(c is null,"NIL",c)); +select * from t1; +# and this should bark +--error 1409 +load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, @b); + +# Now let us test LOAD DATA with subselect +create table t2 (num int primary key, str varchar(10)); +insert into t2 values (10,'Ten'), (15,'Fifteen'); +truncate table t1; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@dummy,@n) set a= @n, c= (select str from t2 where num=@n); +select * from t1; + +# cleanup +drop table t1, t2; + +# End of 5.0 tests diff --git a/mysql-test/t/loaddata_autocom_innodb.test b/mysql-test/t/loaddata_autocom_innodb.test new file mode 100644 index 00000000000..d7f152cb286 --- /dev/null +++ b/mysql-test/t/loaddata_autocom_innodb.test @@ -0,0 +1,4 @@ +--source include/have_innodb.inc +let $engine_type= InnoDB; + +--source include/loaddata_autocom.inc diff --git a/mysql-test/t/loaddata_autocom_ndb.test b/mysql-test/t/loaddata_autocom_ndb.test new file mode 100644 index 00000000000..f4a6743aabe --- /dev/null +++ b/mysql-test/t/loaddata_autocom_ndb.test @@ -0,0 +1,4 @@ +--source include/have_ndb.inc +let $engine_type=ndbcluster; + +--source include/loaddata_autocom.inc diff --git a/mysql-test/t/lock.test b/mysql-test/t/lock.test index adf13fb4dd8..8300219b3d4 100644 --- a/mysql-test/t/lock.test +++ b/mysql-test/t/lock.test @@ -54,7 +54,7 @@ check table t1; lock tables t1 write; check table t2; --error 1100 -insert into t1 select nr from t1; +insert into t1 select index1,nr from t1; unlock tables; lock tables t1 write, t1 as t1_alias read; insert into t1 select index1,nr from t1 as t1_alias; diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index 2e40aeaccb7..33e268ccb11 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -96,3 +96,158 @@ connection locker; drop table t1; # End of 4.1 tests + +# +# BUG#9998 - MySQL client hangs on USE "database" +# +create table t1(a int); +lock tables t1 write; +connection reader; +show columns from t1; +connection locker; +unlock tables; +drop table t1; + +# +# Bug#19815 - CREATE/RENAME/DROP DATABASE can deadlock on a global read lock +# +connect (con1,localhost,root,,); +connect (con2,localhost,root,,); +# +connection con1; +CREATE DATABASE mysqltest_1; +FLUSH TABLES WITH READ LOCK; +# +# With bug in place: acquire LOCK_mysql_create_table and +# wait in wait_if_global_read_lock(). +connection con2; +send DROP DATABASE mysqltest_1; +--sleep 1 +# +# With bug in place: try to acquire LOCK_mysql_create_table... +# When fixed: Reject dropping db because of the read lock. +connection con1; +--error ER_CANT_UPDATE_WITH_READLOCK +DROP DATABASE mysqltest_1; +UNLOCK TABLES; +# +connection con2; +reap; +# +connection default; +disconnect con1; +disconnect con2; +# This must have been dropped by connection 2 already, +# which waited until the global read lock was released. +--error ER_DB_DROP_EXISTS +DROP DATABASE mysqltest_1; + +# +# Bug#16986 - Deadlock condition with MyISAM tables +# +connection locker; +use mysql; +LOCK TABLES columns_priv WRITE, db WRITE, host WRITE, user WRITE; +FLUSH TABLES; +--sleep 1 +# +connection reader; +use mysql; +#NOTE: This must be a multi-table select, otherwise the deadlock will not occur +send SELECT user.Select_priv FROM user, db WHERE user.user = db.user LIMIT 1; +--sleep 1 +# +connection locker; +# Make test case independent from earlier grants. +--replace_result "Table is already up to date" "OK" +OPTIMIZE TABLES columns_priv, db, host, user; +UNLOCK TABLES; +# +connection reader; +reap; +use test; +# +connection locker; +use test; +# +connection default; +# +# Test if CREATE TABLE with LOCK TABLE deadlocks. +# +connection writer; +CREATE TABLE t1 (c1 int); +LOCK TABLE t1 WRITE; +# +# This waits until t1 is unlocked. +connection locker; +send FLUSH TABLES WITH READ LOCK; +--sleep 1 +# +# This must not block. +connection writer; +CREATE TABLE t2 (c1 int); +UNLOCK TABLES; +# +# This awakes now. +connection locker; +reap; +UNLOCK TABLES; +# +connection default; +DROP TABLE t1, t2; +# +# Test if CREATE TABLE SELECT with LOCK TABLE deadlocks. +# +connection writer; +CREATE TABLE t1 (c1 int); +LOCK TABLE t1 WRITE; +# +# This waits until t1 is unlocked. +connection locker; +send FLUSH TABLES WITH READ LOCK; +--sleep 1 +# +# This must not block. +connection writer; +--error 1100 +CREATE TABLE t2 AS SELECT * FROM t1; +UNLOCK TABLES; +# +# This awakes now. +connection locker; +reap; +UNLOCK TABLES; +# +connection default; +DROP TABLE t1; + +# +# Bug #17264: MySQL Server freeze +# +connection locker; +# Disable warnings to allow test to run also without InnoDB +--disable_warnings +create table t1 (f1 int(12) unsigned not null auto_increment, primary key(f1)) engine=innodb; +--enable_warnings +lock tables t1 write; +connection writer; +--sleep 2 +delimiter //; +send alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; // +delimiter ;// +connection reader; +--sleep 2 +delimiter //; +send alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; // +delimiter ;// +connection locker; +--sleep 2 +unlock tables; +connection writer; +reap; +connection reader; +reap; +connection locker; +drop table t1; + +# End of 5.0 tests diff --git a/mysql-test/t/lowercase_table.test b/mysql-test/t/lowercase_table.test index 709743ce687..96437bc7636 100644 --- a/mysql-test/t/lowercase_table.test +++ b/mysql-test/t/lowercase_table.test @@ -7,6 +7,7 @@ drop table if exists t1,t2,t3,t4; # Clear up from other tests (to ensure that SHOW TABLES below is right) drop table if exists t0,t5,t6,t7,t8,t9; drop database if exists mysqltest; +drop view if exists v0, v1, v2, v3, v4; --enable_warnings create table T1 (id int primary key, Word varchar(40) not null, Index(Word)); diff --git a/mysql-test/t/lowercase_table2.test b/mysql-test/t/lowercase_table2.test index c02ae8f5073..521df01cc9b 100644 --- a/mysql-test/t/lowercase_table2.test +++ b/mysql-test/t/lowercase_table2.test @@ -139,3 +139,14 @@ select t1Aa.col1 from t1aA,t2Aa where t1Aa.col1 = t2aA.col1; drop table t2aA, t1Aa; # End of 4.1 tests + +# +# Bug#17661 information_schema.SCHEMATA returns uppercase with lower_case_table_names = 1 +# +create database mysqltest_LC2; +use mysqltest_LC2; +create table myUC (i int); +select TABLE_SCHEMA,TABLE_NAME FROM information_schema.TABLES +where TABLE_SCHEMA ='mysqltest_LC2'; +use test; +drop database mysqltest_LC2; diff --git a/mysql-test/t/lowercase_table3.test b/mysql-test/t/lowercase_table3.test index bf48710d4a6..75f6e5188c5 100644 --- a/mysql-test/t/lowercase_table3.test +++ b/mysql-test/t/lowercase_table3.test @@ -28,7 +28,7 @@ flush tables; # CREATE TABLE t1 (a int) ENGINE=INNODB; ---error 1030 +--error 1146 SELECT * from T1; drop table t1; diff --git a/mysql-test/t/lowercase_view-master.opt b/mysql-test/t/lowercase_view-master.opt new file mode 100644 index 00000000000..62ab6dad1e0 --- /dev/null +++ b/mysql-test/t/lowercase_view-master.opt @@ -0,0 +1 @@ +--lower_case_table_names=1 diff --git a/mysql-test/t/lowercase_view.test b/mysql-test/t/lowercase_view.test new file mode 100644 index 00000000000..e9cc26bec18 --- /dev/null +++ b/mysql-test/t/lowercase_view.test @@ -0,0 +1,140 @@ +--disable_warnings +drop table if exists t1Aa,t2Aa,v1Aa,v2Aa; +drop view if exists t1Aa,t2Aa,v1Aa,v2Aa; +drop database if exists MySQLTest; +--enable_warnings + +# +# different cases in VIEW +# +create database MySQLTest; +use MySQLTest; +create table TaB (Field int); +create view ViE as select * from TAb; +show create table VIe; +drop database MySQLTest; +use test; + +# +# test of updating and fetching from the same table check +# +create table t1Aa (col1 int); +create table t2aA (col1 int); +create view v1Aa as select * from t1aA; +create view v2aA as select * from v1aA; +create view v3Aa as select v2Aa.col1 from v2aA,t2Aa where v2Aa.col1 = t2aA.col1; +-- error 1443 +update v2aA set col1 = (select max(col1) from v1Aa); +-- error 1443 +update v2Aa set col1 = (select max(col1) from t1Aa); +-- error 1093 +update v2aA set col1 = (select max(col1) from v2Aa); +-- error 1443 +update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from v1aA) where v2aA.col1 = t2aA.col1; +-- error 1443 +update t1aA,t2Aa set t1Aa.col1 = (select max(col1) from v1Aa) where t1aA.col1 = t2aA.col1; +-- error 1093 +update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from v1aA) where v1Aa.col1 = t2aA.col1; +-- error 1443 +update t2Aa,v2Aa set v2aA.col1 = (select max(col1) from v1aA) where v2Aa.col1 = t2aA.col1; +-- error 1443 +update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from v1Aa) where t1Aa.col1 = t2aA.col1; +-- error 1443 +update t2Aa,v1aA set v1Aa.col1 = (select max(col1) from v1aA) where v1Aa.col1 = t2aA.col1; +-- error 1443 +update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from t1aA) where v2aA.col1 = t2aA.col1; +-- error 1093 +update t1Aa,t2Aa set t1aA.col1 = (select max(col1) from t1Aa) where t1aA.col1 = t2aA.col1; +-- error 1443 +update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from t1Aa) where v1aA.col1 = t2aA.col1; +-- error 1093 +update t2Aa,v2Aa set v2aA.col1 = (select max(col1) from t1aA) where v2Aa.col1 = t2aA.col1; +-- error 1093 +update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from t1Aa) where t1aA.col1 = t2aA.col1; +-- error 1093 +update t2Aa,v1Aa set v1aA.col1 = (select max(col1) from t1Aa) where v1Aa.col1 = t2aA.col1; +-- error 1093 +update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from v2aA) where v2Aa.col1 = t2aA.col1; +-- error 1443 +update t1aA,t2Aa set t1Aa.col1 = (select max(col1) from v2aA) where t1aA.col1 = t2aA.col1; +-- error 1443 +update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from v2Aa) where v1aA.col1 = t2aA.col1; +-- error 1443 +update t2Aa,v2aA set v2Aa.col1 = (select max(col1) from v2aA) where v2Aa.col1 = t2aA.col1; +-- error 1443 +update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from v2aA) where t1Aa.col1 = t2aA.col1; +-- error 1443 +update t2Aa,v1Aa set v1aA.col1 = (select max(col1) from v2Aa) where v1Aa.col1 = t2aA.col1; +-- error 1443 +update v3aA set v3Aa.col1 = (select max(col1) from v1aA); +-- error 1443 +update v3aA set v3Aa.col1 = (select max(col1) from t1aA); +-- error 1443 +update v3aA set v3Aa.col1 = (select max(col1) from v2aA); +-- error 1093 +update v3aA set v3Aa.col1 = (select max(col1) from v3aA); +-- error 1443 +delete from v2Aa where col1 = (select max(col1) from v1Aa); +-- error 1443 +delete from v2aA where col1 = (select max(col1) from t1Aa); +-- error 1093 +delete from v2Aa where col1 = (select max(col1) from v2aA); +-- error 1443 +delete v2Aa from v2aA,t2Aa where (select max(col1) from v1aA) > 0 and v2Aa.col1 = t2aA.col1; +-- error 1443 +delete t1aA from t1Aa,t2Aa where (select max(col1) from v1Aa) > 0 and t1aA.col1 = t2aA.col1; +-- error 1093 +delete v1aA from v1Aa,t2Aa where (select max(col1) from v1aA) > 0 and v1Aa.col1 = t2aA.col1; +-- error 1443 +delete v2aA from v2Aa,t2Aa where (select max(col1) from t1Aa) > 0 and v2aA.col1 = t2aA.col1; +-- error 1093 +delete t1aA from t1Aa,t2Aa where (select max(col1) from t1aA) > 0 and t1Aa.col1 = t2aA.col1; +-- error 1443 +delete v1aA from v1Aa,t2Aa where (select max(col1) from t1aA) > 0 and v1aA.col1 = t2aA.col1; +-- error 1093 +delete v2Aa from v2aA,t2Aa where (select max(col1) from v2Aa) > 0 and v2aA.col1 = t2aA.col1; +-- error 1443 +delete t1Aa from t1aA,t2Aa where (select max(col1) from v2Aa) > 0 and t1Aa.col1 = t2aA.col1; +-- error 1443 +delete v1Aa from v1aA,t2Aa where (select max(col1) from v2aA) > 0 and v1Aa.col1 = t2aA.col1; +-- error 1443 +insert into v2Aa values ((select max(col1) from v1aA)); +-- error 1443 +insert into t1aA values ((select max(col1) from v1Aa)); +-- error 1443 +insert into v2aA values ((select max(col1) from v1aA)); +-- error 1443 +insert into v2Aa values ((select max(col1) from t1Aa)); +-- error 1093 +insert into t1aA values ((select max(col1) from t1Aa)); +-- error 1443 +insert into v2aA values ((select max(col1) from t1aA)); +-- error 1093 +insert into v2Aa values ((select max(col1) from v2aA)); +-- error 1443 +insert into t1Aa values ((select max(col1) from v2Aa)); +-- error 1093 +insert into v2aA values ((select max(col1) from v2Aa)); +-- error 1443 +insert into v3Aa (col1) values ((select max(col1) from v1Aa)); +-- error 1443 +insert into v3aA (col1) values ((select max(col1) from t1aA)); +-- error 1443 +insert into v3Aa (col1) values ((select max(col1) from v2aA)); +drop view v3aA,v2Aa,v1aA; +drop table t1Aa,t2Aa; + +# +# aliases in VIEWs +# +create table t1Aa (col1 int); +create view v1Aa as select col1 from t1Aa as AaA; +show create view v1AA; +drop view v1AA; +select Aaa.col1 from t1Aa as AaA; +create view v1Aa as select Aaa.col1 from t1Aa as AaA; +drop view v1AA; +create view v1Aa as select AaA.col1 from t1Aa as AaA; +show create view v1AA; +drop view v1AA; +drop table t1Aa; diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index bb03b7b8d62..1308b0b83a4 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -284,6 +284,8 @@ insert into t2 values (1); create table t3 engine=merge union=(t1, t2) select * from t1; --error 1093 create table t3 engine=merge union=(t1, t2) select * from t2; +--error 1093 +create table t3 engine=merge union=(t1, t2) select (select max(a) from t2); drop table t1, t2; # @@ -402,3 +404,29 @@ SELECT * FROM t2; DROP TABLE t2; # End of 4.1 tests + +# +# BUG#19648 - Merge table does not work with bit types +# +create table t1 (b bit(1)); +create table t2 (b bit(1)); +create table tm (b bit(1)) engine = merge union = (t1,t2); +select * from tm; +drop table tm, t1, t2; + +# +# Bug #17766: The server accepts to create MERGE tables which cannot work +# +create table t1 (a int) insert_method = last engine = merge; +--error ER_OPEN_AS_READONLY +insert into t1 values (1); +create table t2 (a int) engine = myisam; +alter table t1 union (t2); +insert into t1 values (1); +alter table t1 insert_method = no; +--error ER_OPEN_AS_READONLY +insert into t1 values (1); +drop table t2; +drop table t1; + +--echo End of 5.0 tests diff --git a/mysql-test/t/mix_innodb_myisam_binlog.test b/mysql-test/t/mix_innodb_myisam_binlog.test index 4581736ac8c..66440f1236e 100644 --- a/mysql-test/t/mix_innodb_myisam_binlog.test +++ b/mysql-test/t/mix_innodb_myisam_binlog.test @@ -28,7 +28,9 @@ insert into t1 values(1); insert into t2 select * from t1; commit; -show binlog events from 79; +--replace_column 5 # +--replace_result "xid=15" "xid=8" +show binlog events from 98; delete from t1; delete from t2; @@ -40,7 +42,8 @@ insert into t2 select * from t1; # should say some changes to non-transact1onal tables couldn't be rolled back rollback; -show binlog events from 79; +--replace_column 5 # +show binlog events from 98; delete from t1; delete from t2; @@ -54,7 +57,9 @@ insert into t2 select * from t1; rollback to savepoint my_savepoint; commit; -show binlog events from 79; +--replace_column 5 # +--replace_result "xid=48" "xid=25" +show binlog events from 98; delete from t1; delete from t2; @@ -70,7 +75,9 @@ insert into t1 values(7); commit; select a from t1 order by a; # check that savepoints work :) -show binlog events from 79; +--replace_column 5 # +--replace_result "xid=70" "xid=37" +show binlog events from 98; # and when ROLLBACK is not explicit? delete from t1; @@ -90,7 +97,8 @@ connection con2; # so SHOW BINLOG EVENTS may come before con1 does the loggin. To be sure that # logging has been done, we use a user lock. select get_lock("a",10); -show binlog events from 79; +--replace_column 5 # +show binlog events from 98; # and when not in a transact1on? delete from t1; @@ -100,10 +108,12 @@ reset master; insert into t1 values(9); insert into t2 select * from t1; -show binlog events from 79; +--replace_column 5 # +--replace_result "xid=119" "xid=60" +show binlog events from 98; # Check that when the query updat1ng the MyISAM table is the first in the -# transact1on, we log it immediately. +# transaction, we log it immediately. delete from t1; delete from t2; reset master; @@ -111,11 +121,15 @@ reset master; insert into t1 values(10); # first make t1 non-empty begin; insert into t2 select * from t1; -show binlog events from 79; +--replace_column 5 # +--replace_result "xid=133" "xid=66" +show binlog events from 98; insert into t1 values(11); commit; -show binlog events from 79; +--replace_column 5 # +--replace_result "xid=133" "xid=66" "xid=136" "xid=68" +show binlog events from 98; # Check that things work like before this BEGIN/ROLLBACK code was added, @@ -132,7 +146,9 @@ insert into t1 values(12); insert into t2 select * from t1; commit; -show binlog events from 79; +--replace_column 5 # +--replace_result "xid=155" "xid=78" +show binlog events from 98; delete from t1; delete from t2; @@ -143,7 +159,8 @@ insert into t1 values(13); insert into t2 select * from t1; rollback; -show binlog events from 79; +--replace_column 5 # +show binlog events from 98; delete from t1; delete from t2; @@ -157,7 +174,9 @@ insert into t2 select * from t1; rollback to savepoint my_savepoint; commit; -show binlog events from 79; +--replace_column 5 # +--replace_result "xid=187" "xid=94" +show binlog events from 98; delete from t1; delete from t2; @@ -173,7 +192,9 @@ insert into t1 values(18); commit; select a from t1 order by a; # check that savepoints work :) -show binlog events from 79; +--replace_column 5 # +--replace_result "xid=208" "xid=105" +show binlog events from 98; # Test for BUG#5714, where a MyISAM update in the transaction used to # release row-level locks in InnoDB @@ -232,9 +253,43 @@ insert into t2 values (3); disconnect con2; connection con3; select get_lock("lock1",60); -show binlog events from 79; +--replace_column 5 # +--replace_result "xid=208" "xid=105" "xid=227" "xid=114" "xid=230" "xid=115" "xid=234" "xid=117" "xid=261" "xid=132" +show binlog events from 98; do release_lock("lock1"); drop table t0,t2; - # End of 4.1 tests + +# Test for BUG#16559 (ROLLBACK should always have a zero error code in +# binlog). Has to be here and not earlier, as the SELECTs influence +# XIDs differently between normal and ps-protocol (and SHOW BINLOG +# EVENTS above read XIDs). + +connect (con4,localhost,root,,); +connection con3; +reset master; +create table t1 (a int) engine=innodb; +create table t2 (a int) engine=myisam; +select get_lock("a",10); +begin; +insert into t1 values(8); +insert into t2 select * from t1; +disconnect con3; + +connection con4; +select get_lock("a",10); # wait for rollback to finish + +# we check that the error code of the "ROLLBACK" event is 0 and not +# ER_SERVER_SHUTDOWN (i.e. disconnection just rolls back transaction +# and does not make slave to stop) +--exec $MYSQL_BINLOG --start-position=547 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval select +(@a:=load_file("$MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output")) +is not null; +--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR +eval select +@a like "%#%error_code=0%ROLLBACK;%ROLLBACK /* added by mysqlbinlog */;%", +@a not like "%#%error_code=%error_code=%"; +drop table t1, t2; diff --git a/mysql-test/t/multi_statement.test b/mysql-test/t/multi_statement.test index eb8d867f3f0..785aa749f5e 100644 --- a/mysql-test/t/multi_statement.test +++ b/mysql-test/t/multi_statement.test @@ -1,6 +1,10 @@ # PS doesn't support multi-statements --disable_ps_protocol +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + select 1; delimiter ||||; select 2; diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test index e628e900c73..da19a18c73a 100644 --- a/mysql-test/t/multi_update.test +++ b/mysql-test/t/multi_update.test @@ -2,9 +2,13 @@ # Test of update statement that uses many tables. # +# Requires grants, so won't work with embedded server test +-- source include/not_embedded.inc + --disable_warnings drop table if exists t1,t2,t3; drop database if exists mysqltest; +drop view if exists v1; --error 0,1141,1147 revoke all privileges on mysqltest.t1 from mysqltest_1@localhost; --error 0,1141,1147 @@ -457,3 +461,76 @@ create table t2(a int); delete from t1,t2 using t1,t2 where t1.a=(select a from t1); drop table t1, t2; # End of 4.1 tests + +# +# Test for bug #1980. +# +--disable_warnings +create table t1 ( c char(8) not null ) engine=innodb; +--enable_warnings + +insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'); +insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F'); + +alter table t1 add b char(8) not null; +alter table t1 add a char(8) not null; +alter table t1 add primary key (a,b,c); +update t1 set a=c, b=c; + +create table t2 like t1; +insert into t2 select * from t1; + +delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b; + +drop table t1,t2; + +--disable_warnings +create table t1 ( c char(8) not null ) engine=bdb; +--enable_warnings + +insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'); +insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F'); + +alter table t1 add b char(8) not null; +alter table t1 add a char(8) not null; +alter table t1 add primary key (a,b,c); +update t1 set a=c, b=c; + +create table t2 like t1; +insert into t2 select * from t1; + +delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b; + +drop table t1,t2; + +create table t1 (a int, b int); +insert into t1 values (1, 2), (2, 3), (3, 4); +create table t2 (a int); +insert into t2 values (10), (20), (30); +create view v1 as select a as b, a/10 as a from t2; + +connect (locker,localhost,root,,test); +connection locker; +lock table t1 write; + +connect (changer,localhost,root,,test); +connection changer; +send alter table t1 add column c int default 100 after a; + +connect (updater,localhost,root,,test); +connection updater; +send update t1, v1 set t1.b=t1.a+t1.b+v1.b where t1.a=v1.a; + +connection locker; +sleep 2; +unlock tables; + +connection changer; +reap; + +connection updater; +reap; +select * from t1; +select * from t2; +drop view v1; +drop table t1, t2; diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test index 745e3a2e377..d785002abdd 100644 --- a/mysql-test/t/myisam.test +++ b/mysql-test/t/myisam.test @@ -450,11 +450,14 @@ drop table t1; # Test text and unique # create table t1 (a int not null auto_increment primary key, b text not null, unique b (b(20))); -insert into t1 (b) values ('a'),('a '),('a '); +insert into t1 (b) values ('a'),('b'),('c'); select concat(b,'.') from t1; update t1 set b='b ' where a=2; --error 1062 update t1 set b='b ' where a > 1; +--error 1062 +insert into t1 (b) values ('b'); +select * from t1; delete from t1 where b='b'; select a,concat(b,'.') from t1; drop table t1; @@ -609,20 +612,6 @@ check table t1; drop table t1; -# BUG#9622 - ANALYZE TABLE and ALTER TABLE .. ENABLE INDEX produce -# different statistics on the same table with NULL values. -create table t1 (a int, key(a)); - -insert into t1 values (1),(2),(3),(4),(NULL),(NULL),(NULL),(NULL); -analyze table t1; -show keys from t1; - -alter table t1 disable keys; -alter table t1 enable keys; -show keys from t1; - -drop table t1; - # # Bug#12296 - CHECKSUM TABLE reports 0 for the table # This happened if the first record was marked as deleted. @@ -638,7 +627,10 @@ checksum table t1; checksum table t2; drop table t1, t2; +# # BUG#12232: New myisam_stats_method variable. +# + show variables like 'myisam_stats_method'; create table t1 (a int, key(a)); @@ -854,6 +846,130 @@ DROP TABLE t1; # SET @@myisam_repair_threads=1; SHOW VARIABLES LIKE 'myisam_repair%'; +# Test varchar +# + +let $default=`select @@storage_engine`; +set storage_engine=MyISAM; +source include/varchar.inc; + +# +# Some errors/warnings on create +# + +create table t1 (v varchar(65530), key(v)); +drop table if exists t1; +create table t1 (v varchar(65536)); +show create table t1; +drop table t1; +create table t1 (v varchar(65530) character set utf8); +show create table t1; +drop table t1; + +# MyISAM specific varchar tests +--error 1118 +create table t1 (v varchar(65535)); + +eval set storage_engine=$default; + +# +# Test how DROP TABLE works if the index or data file doesn't exists + +create table t1 (a int) engine=myisam; +system rm $MYSQLTEST_VARDIR/master-data/test/t1.MYI ; +drop table if exists t1; +create table t1 (a int) engine=myisam; +system rm $MYSQLTEST_VARDIR/master-data/test/t1.MYI ; +--error 1051,6 +drop table t1; +create table t1 (a int) engine=myisam; +system rm $MYSQLTEST_VARDIR/master-data/test/t1.MYD ; +--error 1105,6,29 +drop table t1; +--error 1051 +drop table t1; + +# +# Test concurrent insert +# First with static record length +# +set @save_concurrent_insert=@@concurrent_insert; +set global concurrent_insert=1; +create table t1 (a int); +insert into t1 values (1),(2),(3),(4),(5); +lock table t1 read local; +connect (con1,localhost,root,,); +connection con1; +# Insert in table without hole +insert into t1 values(6),(7); +connection default; +unlock tables; +delete from t1 where a>=3 and a<=4; +lock table t1 read local; +connection con1; +set global concurrent_insert=2; +# Insert in table with hole -> Should insert at end +insert into t1 values (8),(9); +connection default; +unlock tables; +# Insert into hole +insert into t1 values (10),(11),(12); +select * from t1; +check table t1; +drop table t1; +disconnect con1; + +# Same test with dynamic record length +create table t1 (a int, b varchar(30) default "hello"); +insert into t1 (a) values (1),(2),(3),(4),(5); +lock table t1 read local; +connect (con1,localhost,root,,); +connection con1; +# Insert in table without hole +insert into t1 (a) values(6),(7); +connection default; +unlock tables; +delete from t1 where a>=3 and a<=4; +lock table t1 read local; +connection con1; +set global concurrent_insert=2; +# Insert in table with hole -> Should insert at end +insert into t1 (a) values (8),(9); +connection default; +unlock tables; +# Insert into hole +insert into t1 (a) values (10),(11),(12); +select a from t1; +check table t1; +drop table t1; +disconnect con1; +set global concurrent_insert=@save_concurrent_insert; + + +# BUG#9622 - ANALYZE TABLE and ALTER TABLE .. ENABLE INDEX produce +# different statistics on the same table with NULL values. +create table t1 (a int, key(a)); + +insert into t1 values (1),(2),(3),(4),(NULL),(NULL),(NULL),(NULL); +analyze table t1; +show keys from t1; + +alter table t1 disable keys; +alter table t1 enable keys; +show keys from t1; + +drop table t1; + +# +# Bug#10056 - PACK_KEYS option take values greater than 1 while creating table +# +create table t1 (c1 int) engine=myisam pack_keys=0; +create table t2 (c1 int) engine=myisam pack_keys=1; +create table t3 (c1 int) engine=myisam pack_keys=default; +--error 1064 +create table t4 (c1 int) engine=myisam pack_keys=2; +drop table t1, t2, t3; +# # Bug#8706 - temporary table with data directory option fails # connect (session1,localhost,root,,); @@ -861,21 +977,19 @@ connect (session2,localhost,root,,); connection session1; disable_query_log; -eval create temporary table t1 (a int) engine=myisam data directory="$MYSQL_TEST_DIR/var/log" select 9 a; +eval create temporary table t1 (a int) engine=myisam data directory="$MYSQLTEST_VARDIR/tmp" select 9 a; enable_query_log; -# If running test suite with a non standard tmp dir, the "show create table" -# will print "DATA_DIRECTORY=". Use replace_result to mask it out ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR +disable_result_log; show create table t1; +enable_result_log; connection session2; disable_query_log; -eval create temporary table t1 (a int) engine=myisam data directory="$MYSQL_TEST_DIR/var/log" select 99 a; +eval create temporary table t1 (a int) engine=myisam data directory="$MYSQLTEST_VARDIR/tmp" select 99 a; enable_query_log; -# If running test suite with a non standard tmp dir, the "show create table" -# will print "DATA_DIRECTORY=". Use replace_result to mask it out ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR +disable_result_log; show create table t1; +enable_result_log; connection default; create table t1 (a int) engine=myisam select 42 a; diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test new file mode 100644 index 00000000000..c06e52e2d78 --- /dev/null +++ b/mysql-test/t/mysql.test @@ -0,0 +1,226 @@ +# This test should work in embedded server after we fix mysqltest +-- source include/not_embedded.inc +# +# Testing the MySQL command line client(mysql) +# + +--disable_warnings +drop table if exists t1; +--enable_warnings + +# +# Test the "delimiter" functionality +# Bug#9879 +# +create table t1(a int); +insert into t1 values(1); + +# Test delimiters +--exec $MYSQL test 2>&1 < "./t/mysql_delimiter.sql" + +--disable_query_log +# Test delimiter : supplied on the command line +select "Test delimiter : from command line" as "_"; +--exec $MYSQL test --delimiter=":" -e "select * from t1:" +# Test delimiter :; supplied on the command line +select "Test delimiter :; from command line" as "_"; +--exec $MYSQL test --delimiter=":;" -e "select * from t1:;" +# Test 'go' command (vertical output) \G +select "Test 'go' command(vertical output) \G" as "_"; +--exec $MYSQL test -e "select * from t1\G" +# Test 'go' command \g +select "Test 'go' command \g" as "_"; +--exec $MYSQL test -e "select * from t1\g" +--enable_query_log +drop table t1; + +# +# BUG9998 - MySQL client hangs on USE "database" +# +create table t1(a int); +lock tables t1 write; +--exec $MYSQL -e "use test; select database();" +unlock tables; +drop table t1; + +# +# BUG#16217 - MySQL client misinterpretes multi-byte char as escape `\' +# + +# new command \C or charset +--exec $MYSQL --default-character-set=utf8 test -e "\C cp932 \g" +--exec $MYSQL --default-character-set=cp932 test -e "charset utf8;" + +# its usage to switch internally in mysql to requested charset +--exec $MYSQL --default-character-set=utf8 test -e "charset cp932; select 'ƒ\'; create table t1 (c_cp932 TEXT CHARACTER SET cp932); insert into t1 values('ƒ\'); select * from t1; drop table t1;" +--exec $MYSQL --default-character-set=utf8 test -e "charset cp932; select 'ƒ\'" +--exec $MYSQL --default-character-set=utf8 test -e "/*charset cp932 */; set character_set_client= cp932; select 'ƒ\'" +--exec $MYSQL --default-character-set=utf8 test -e "/*!\C cp932 */; set character_set_client= cp932; select 'ƒ\'" + +# +# Bug#16859 -- NULLs in columns must not truncate data as if a C-language "string". +# +--exec $MYSQL -t test -e "create table t1 (col1 binary(4), col2 varchar(10), col3 int); insert into t1 values ('a', 'b', 123421),('a ', '0123456789', 4), ('abcd', '', 4); select concat('>',col1,'<'), col2, col3 from t1; drop table t1;" 2>&1 + +# +# Bug#17939 Wrong table format when using UTF8 strings +# +--exec $MYSQL --default-character-set=utf8 --table -e "SELECT 'John Doe' as '__tañgè Ñãmé'" 2>&1 +--exec $MYSQL --default-character-set=utf8 --table -e "SELECT '__tañgè Ñãmé' as 'John Doe'" 2>&1 + +# +# Bug#18265 -- mysql client: No longer right-justifies numeric columns +# +--exec $MYSQL -t --default-character-set utf8 test -e "create table t1 (i int, j int, k char(25) charset utf8); insert into t1 (i) values (1); insert into t1 (k) values ('<----------------------->'); insert into t1 (k) values ('<-----'); insert into t1 (k) values ('Τη γλώσσα'); insert into t1 (k) values ('á›–áš´ áš·á›–á›'); select * from t1; DROP TABLE t1;" + +# +# "DESCRIBE" commands may return strange NULLness flags. +# +--exec $MYSQL --default-character-set utf8 test -e "create table t1 (i int, j int not null, k int); insert into t1 values (null, 1, null); select * from t1; describe t1; drop table t1;" +--exec $MYSQL -t --default-character-set utf8 test -e "create table t1 (i int, j int not null, k int); insert into t1 values (null, 1, null); select * from t1; describe t1; drop table t1;" + +# +# Bug#19564: mysql displays NULL instead of space +# +--exec $MYSQL test -e "create table b19564 (i int, s1 char(1)); insert into b19564 values (1, 'x'); insert into b19564 values (2, NULL); insert into b19564 values (3, ' '); select * from b19564 order by i; drop table b19564;" +--exec $MYSQL -t test -e "create table b19564 (i int, s1 char(1)); insert into b19564 values (1, 'x'); insert into b19564 values (2, NULL); insert into b19564 values (3, ' '); select * from b19564 order by i; drop table b19564;" + +# +# Bug#21618: NULL shown as empty string in client +# +--exec $MYSQL test -e "select unhex('zz');" +--exec $MYSQL -t test -e "select unhex('zz');" + +# Bug#19265 describe command does not work from mysql prompt +# + +create table t1(a int, b varchar(255), c int); +--exec $MYSQL test -e "desc t1" +--exec $MYSQL test -e "desc t1\g" +drop table t1; + +--disable_parsing +# +# Bug#21042 mysql client segfaults on importing a mysqldump export +# +--error 1 +--exec $MYSQL test -e "connect verylongdatabasenamethatshouldblowthe256byteslongbufferincom_connectfunctionxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxendcccccccdxxxxxxxxxxxxxxxxxkskskskskkskskskskskskskskskskkskskskskkskskskskskskskskskend" 2>&1 +--enable_parsing + + +# +# Bug #20432: mysql client interprets commands in comments +# + +# if the client sees the 'use' within the comment, we haven't fixed +--exec echo "/*" > $MYSQLTEST_VARDIR/tmp/bug20432.sql +--exec echo "use" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql +--exec echo "*/" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20432.sql 2>&1 + +# SQL can have embedded comments => workie +--exec echo "select /*" > $MYSQLTEST_VARDIR/tmp/bug20432.sql +--exec echo "use" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql +--exec echo "*/ 1" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20432.sql 2>&1 + +# client commands on the other hand must be at BOL => error +--exec echo "/*" > $MYSQLTEST_VARDIR/tmp/bug20432.sql +--exec echo "xxx" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql +--exec echo "*/ use" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql +--error 1 +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20432.sql 2>&1 + +# client comment recognized, but parameter missing => error +--exec echo "use" > $MYSQLTEST_VARDIR/tmp/bug20432.sql +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20432.sql 2>&1 + +# +# Bug #20328: mysql client interprets commands in comments +# +--exec $MYSQL -e 'help' > $MYSQLTEST_VARDIR/tmp/bug20328_1.result +--exec $MYSQL -e 'help ' > $MYSQLTEST_VARDIR/tmp/bug20328_2.result +--exec diff $MYSQLTEST_VARDIR/tmp/bug20328_1.result $MYSQLTEST_VARDIR/tmp/bug20328_2.result + +# +# Bug #20103: Escaping with backslash does not work +# +--exec echo "SET SQL_MODE = 'NO_BACKSLASH_ESCAPES';" > $MYSQLTEST_VARDIR/tmp/bug20103.sql +--exec echo "SELECT '\';" >> $MYSQLTEST_VARDIR/tmp/bug20103.sql +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20103.sql 2>&1 + +--exec echo "SET SQL_MODE = '';" > $MYSQLTEST_VARDIR/tmp/bug20103.sql +--exec echo "SELECT '\';';" >> $MYSQLTEST_VARDIR/tmp/bug20103.sql +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20103.sql 2>&1 + +# +# Bug#17583: mysql drops connection when stdout is not writable +# +create table t17583 (a int); +insert into t17583 (a) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +# Close to the minimal data needed to exercise bug. +select count(*) from t17583; +--exec echo "select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; " |$MYSQL test >&- +drop table t17583; + +# +# Bug#20984: Reproducible MySQL client segmentation fault +# + additional tests for the "com_connect" function in mysql +# +# +--echo Test connect without db- or host-name => reconnect +--exec $MYSQL test -e "\r" 2>&1 +--exec $MYSQL test -e "connect" 2>&1 + +--echo Test connect with dbname only => new dbname, old hostname +--exec $MYSQL test -e "\r test" 2>&1 +--exec $MYSQL test -e "connect test" 2>&1 +--exec $MYSQL test -e "\rtest" 2>&1 +--error 1 +--exec $MYSQL test -e "connecttest" 2>&1 + +--echo Test connect with _invalid_ dbname only => new invalid dbname, old hostname +--error 1 +--exec $MYSQL test -e "\r invalid" 2>&1 +--error 1 +--exec $MYSQL test -e "connect invalid" 2>&1 + +--echo Test connect with dbname + hostname +--exec $MYSQL test -e "\r test localhost" 2>&1 +--exec $MYSQL test -e "connect test localhost" 2>&1 + +--echo Test connect with dbname + _invalid_ hostname +# Mask the errno of the error message +--replace_regex /\([0-9]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "\r test invalid_hostname" 2>&1 +--replace_regex /\([0-9]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "connect test invalid_hostname" 2>&1 + +--echo The commands reported in the bug report +--replace_regex /\([0-9]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "\r\r\n\r\n cyril\ has\ found\ a\ bug\ :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 2>&1 + +#--replace_regex /\([0-9]*\)/(errno)/ +#--error 1 +#--exec echo '\r\r\n\r\n cyril\ has\ found\ a\ bug\ :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | $MYSQL 2>&1 + +--echo Too long dbname +--error 1 +--exec $MYSQL test -e "\r test_really_long_dbnamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx localhost" 2>&1 + +--echo Too long hostname +--replace_regex /\([0-9]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "\r test cyrils_superlonghostnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 2>&1 + +--echo End of 5.0 tests diff --git a/mysql-test/t/mysql_client.test b/mysql-test/t/mysql_client.test deleted file mode 100644 index 2a7f4a935bb..00000000000 --- a/mysql-test/t/mysql_client.test +++ /dev/null @@ -1,54 +0,0 @@ -# This test should work in embedded server after we fix mysqltest --- source include/not_embedded.inc - -# -# Bug #20432: mysql client interprets commands in comments -# - -# if the client sees the 'use' within the comment, we haven't fixed ---exec echo "/*" > $MYSQLTEST_VARDIR/tmp/bug20432.sql ---exec echo "use" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql ---exec echo "*/" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql ---exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20432.sql 2>&1 - -# SQL can have embedded comments => workie ---exec echo "select /*" > $MYSQLTEST_VARDIR/tmp/bug20432.sql ---exec echo "use" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql ---exec echo "*/ 1" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql ---exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20432.sql 2>&1 - -# client commands on the other hand must be at BOL => error ---exec echo "/*" > $MYSQLTEST_VARDIR/tmp/bug20432.sql ---exec echo "xxx" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql ---exec echo "*/ use" >> $MYSQLTEST_VARDIR/tmp/bug20432.sql ---error 1 ---exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20432.sql 2>&1 - -# client comment recognized, but parameter missing => error ---exec echo "use" > $MYSQLTEST_VARDIR/tmp/bug20432.sql ---exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20432.sql 2>&1 - -# -# Bug #20328: mysql client: dumb about trailing spaces on 'help' command -# ---exec echo 'help' | $MYSQL > $MYSQLTEST_VARDIR/tmp/bug20328.tmp ---exec echo 'help ' | $MYSQL > $MYSQLTEST_VARDIR/tmp/bug20328.tmp - -# -# Bug#17583: mysql drops connection when stdout is not writable -# -create table t17583 (a int); -insert into t17583 (a) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); -insert into t17583 select a from t17583; -insert into t17583 select a from t17583; -insert into t17583 select a from t17583; -insert into t17583 select a from t17583; -insert into t17583 select a from t17583; -insert into t17583 select a from t17583; -insert into t17583 select a from t17583; -# Close to the minimal data needed to exercise bug. -select count(*) from t17583; ---exec echo "select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; " |$MYSQL test >&- -drop table t17583; - ---echo End of 4.1 tests. diff --git a/mysql-test/t/mysql_client_test.opt b/mysql-test/t/mysql_client_test.opt new file mode 100644 index 00000000000..968ba95c6cc --- /dev/null +++ b/mysql-test/t/mysql_client_test.opt @@ -0,0 +1 @@ +--log diff --git a/mysql-test/t/mysql_client_test.test b/mysql-test/t/mysql_client_test.test index 2677e470289..66a27abd61a 100644 --- a/mysql-test/t/mysql_client_test.test +++ b/mysql-test/t/mysql_client_test.test @@ -8,8 +8,9 @@ # server or run mysql-test-run --debug mysql_client_test and check # var/log/mysql_client_test.trace ---exec echo "$MYSQL_CLIENT_TEST --getopt-ll-test=25600M" > $MYSQLTEST_VARDIR/log/mysql_client_test.log 2>&1 +--exec echo "$MYSQL_CLIENT_TEST" > $MYSQLTEST_VARDIR/log/mysql_client_test.log 2>&1 --exec $MYSQL_CLIENT_TEST --getopt-ll-test=25600M >> $MYSQLTEST_VARDIR/log/mysql_client_test.log 2>&1 # End of 4.1 tests echo ok; + diff --git a/mysql-test/t/mysql_delimiter.sql b/mysql-test/t/mysql_delimiter.sql new file mode 100644 index 00000000000..fa80c980b29 --- /dev/null +++ b/mysql-test/t/mysql_delimiter.sql @@ -0,0 +1,51 @@ + +# Test default delimiter ; +select "Test default delimiter ;" as " "; +select * from t1; + +# Test delimiter without argument +select "Test delimiter without arg" as " "; +# Nothing should be displayed, error is returned +delimiter +delimiter ; # Reset delimiter + +# Test delimiter : +select "Test delimiter :" as " "; +delimiter : +select * from t1: +delimiter ; # Reset delimiter + +# Test delimiter ':' +select "Test delimiter :" as " "; +delimiter ':' +select * from t1: +delimiter ; # Reset delimiter + +# Test delimiter :; +select "Test delimiter :;" as " "; +delimiter :; +select * from t1 :; +delimiter ; # Reset delimiter + +## Test delimiter // +select "Test delimiter //" as " "; +delimiter // +select * from t1// +delimiter ; # Reset delimiter + +# Test delimiter 'MySQL' +select "Test delimiter MySQL" as " "; +delimiter 'MySQL' +select * from t1MySQL +delimiter ; # Reset delimiter + +# Test delimiter 'delimiter'(should be allowed according to the code) +select "Test delimiter delimiter" as " "; +delimiter delimiter +select * from t1 delimiter +delimiter ; # Reset delimiter + +# +# Bug #11523: \d works differently than delimiter +# +source t/mysql_delimiter_source.sql diff --git a/mysql-test/t/mysql_delimiter_source.sql b/mysql-test/t/mysql_delimiter_source.sql new file mode 100644 index 00000000000..f645091f3d4 --- /dev/null +++ b/mysql-test/t/mysql_delimiter_source.sql @@ -0,0 +1,8 @@ +delimiter // +create table t2 (a int) // +delimiter ; +\d // +create table t3 (a int) // +\d ; +show tables; +drop table t2, t3; diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test index 6fed78fe4ae..0691cb7c76b 100644 --- a/mysql-test/t/mysqlbinlog.test +++ b/mysql-test/t/mysqlbinlog.test @@ -22,12 +22,11 @@ insert into t2 values (); # test for load data and load data distributed among the several # files (we need to fill up first binlog) -load data infile '../../std_data/words.dat' into table t1; -load data infile '../../std_data/words.dat' into table t1; -load data infile '../../std_data/words.dat' into table t1; -load data infile '../../std_data/words.dat' into table t1; -load data infile '../../std_data/words.dat' into table t1; -load data infile '../../std_data/words.dat' into table t1; +load data infile '../std_data_ln/words.dat' into table t1; +load data infile '../std_data_ln/words.dat' into table t1; +load data infile '../std_data_ln/words.dat' into table t1; +load data infile '../std_data_ln/words.dat' into table t1; +load data infile '../std_data_ln/words.dat' into table t1; # simple query to show more in second binlog insert into t1 values ("Alas"); flush logs; @@ -42,29 +41,29 @@ select "--- Local --" as ""; # be time dependend. Better than nothing. # ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ $MYSQL_TEST_DIR/var/log/master-bin.000001 +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLTEST_VARDIR/log/master-bin.000001 # this should not fail but shouldn't produce any working statements --disable_query_log select "--- Broken LOAD DATA --" as ""; --enable_query_log ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ $MYSQL_TEST_DIR/var/log/master-bin.000002 2> /dev/null +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLTEST_VARDIR/log/master-bin.000002 2> /dev/null # this should show almost nothing --disable_query_log select "--- --database --" as ""; --enable_query_log ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --database=nottest $MYSQL_TEST_DIR/var/log/master-bin.000001 2> /dev/null +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --database=nottest $MYSQLTEST_VARDIR/log/master-bin.000001 2> /dev/null # this test for position option --disable_query_log select "--- --position --" as ""; --enable_query_log ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --position=27 $MYSQL_TEST_DIR/var/log/master-bin.000002 +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --position=231 $MYSQLTEST_VARDIR/log/master-bin.000002 # These are tests for remote binlog. # They should return the same as previous test. @@ -74,30 +73,39 @@ select "--- Remote --" as ""; --enable_query_log # This is broken now ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 # This is broken too --disable_query_log select "--- Broken LOAD DATA --" as ""; --enable_query_log ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002 2> /dev/null +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002 2> /dev/null # And this too ! (altough it is documented) --disable_query_log select "--- --database --" as ""; --enable_query_log ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --database=nottest master-bin.000001 2> /dev/null +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --database=nottest master-bin.000001 2> /dev/null # Strangely but this works --disable_query_log select "--- --position --" as ""; --enable_query_log +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --position=231 --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002 + +# Bug#7853 (mysqlbinlog does not accept input from stdin) +--disable_query_log +select "--- reading stdin --" as ""; +--enable_query_log --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --read-from-remote-server --position=27 --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002 +--exec $MYSQL_BINLOG --short-form - < $MYSQL_TEST_DIR/std_data/trunc_binlog.000001 +--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR +--exec $MYSQL_BINLOG --short-form --position=79 - < $MYSQL_TEST_DIR/std_data/trunc_binlog.000001 # Bug#16217 (mysql client did not know how not switch its internal charset) flush logs; @@ -107,8 +115,7 @@ create table t4 (f text character set cp932); --exec $MYSQL --default-character-set=cp932 test -e "insert into t4 values(_cp932'ƒ\');" flush logs; rename table t3 to t03, t4 to t04; ---exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.000004 > $MYSQL_TEST_DIR/var/tmp/bug16217.sql ---exec $MYSQL --default-character-set=utf8 < $MYSQL_TEST_DIR/var/tmp/bug16217.sql +--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000004 | $MYSQL --default-character-set=utf8 # original and recovered data must be equal select HEX(f) from t03; select HEX(f) from t3; @@ -124,12 +131,10 @@ flush logs; # resulted binlog, parly consisting of multi-byte utf8 chars, # must be digestable for both client and server. In 4.1 the client # should use default-character-set same as the server. ---exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.000006 > $MYSQL_TEST_DIR/var/tmp/bug14157.sql ---exec $MYSQL < $MYSQL_TEST_DIR/var/tmp/bug14157.sql +--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000006 | $MYSQL select * from t5 /* must be (1),(1) */; # clean up drop table t1, t2, t03, t04, t3, t4, t5; -# End of 4.1 tests - +# End of 5.0 tests diff --git a/mysql-test/t/mysqlbinlog2.test b/mysql-test/t/mysqlbinlog2.test index 67131dd9d0d..6afae538f04 100644 --- a/mysql-test/t/mysqlbinlog2.test +++ b/mysql-test/t/mysqlbinlog2.test @@ -40,28 +40,28 @@ select "--- Local --" as ""; # be time dependent (the Start events). Better than nothing. # ---exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.000001 +--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001 --disable_query_log select "--- offset --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form --offset=2 $MYSQL_TEST_DIR/var/log/master-bin.000001 +--exec $MYSQL_BINLOG --short-form --offset=2 $MYSQLTEST_VARDIR/log/master-bin.000001 --disable_query_log select "--- start-position --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form --start-position=497 $MYSQL_TEST_DIR/var/log/master-bin.000001 +--exec $MYSQL_BINLOG --short-form --start-position=600 $MYSQLTEST_VARDIR/log/master-bin.000001 --disable_query_log select "--- stop-position --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form --stop-position=497 $MYSQL_TEST_DIR/var/log/master-bin.000001 +--exec $MYSQL_BINLOG --short-form --stop-position=600 $MYSQLTEST_VARDIR/log/master-bin.000001 --disable_query_log select "--- start-datetime --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form "--start-datetime=2020-01-21 15:32:24" $MYSQL_TEST_DIR/var/log/master-bin.000001 +--exec $MYSQL_BINLOG --short-form "--start-datetime=2020-01-21 15:32:24" $MYSQLTEST_VARDIR/log/master-bin.000001 --disable_query_log select "--- stop-datetime --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form "--stop-datetime=2020-01-21 15:32:24" $MYSQL_TEST_DIR/var/log/master-bin.000001 +--exec $MYSQL_BINLOG --short-form "--stop-datetime=2020-01-21 15:32:24" $MYSQLTEST_VARDIR/log/master-bin.000001 --disable_query_log select "--- Local with 2 binlogs on command line --" as ""; @@ -69,28 +69,28 @@ select "--- Local with 2 binlogs on command line --" as ""; # This is to verify that some options apply only to first, or last binlog ---exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002 +--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001 $MYSQLTEST_VARDIR/log/master-bin.000002 --disable_query_log select "--- offset --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form --offset=2 $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002 +--exec $MYSQL_BINLOG --short-form --offset=2 $MYSQLTEST_VARDIR/log/master-bin.000001 $MYSQLTEST_VARDIR/log/master-bin.000002 --disable_query_log select "--- start-position --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form --start-position=497 $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002 +--exec $MYSQL_BINLOG --short-form --start-position=600 $MYSQLTEST_VARDIR/log/master-bin.000001 $MYSQLTEST_VARDIR/log/master-bin.000002 --disable_query_log select "--- stop-position --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form --stop-position=32 $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002 +--exec $MYSQL_BINLOG --short-form --stop-position=126 $MYSQLTEST_VARDIR/log/master-bin.000001 $MYSQLTEST_VARDIR/log/master-bin.000002 --disable_query_log select "--- start-datetime --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form "--start-datetime=2020-01-21 15:32:24" $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002 +--exec $MYSQL_BINLOG --short-form "--start-datetime=2020-01-21 15:32:24" $MYSQLTEST_VARDIR/log/master-bin.000001 $MYSQLTEST_VARDIR/log/master-bin.000002 --disable_query_log select "--- stop-datetime --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form "--stop-datetime=2020-01-21 15:32:24" $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002 +--exec $MYSQL_BINLOG --short-form "--stop-datetime=2020-01-21 15:32:24" $MYSQLTEST_VARDIR/log/master-bin.000001 $MYSQLTEST_VARDIR/log/master-bin.000002 --disable_query_log select "--- Remote --" as ""; @@ -105,11 +105,11 @@ select "--- offset --" as ""; --disable_query_log select "--- start-position --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form --start-position=497 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 +--exec $MYSQL_BINLOG --short-form --start-position=600 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 --disable_query_log select "--- stop-position --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form --stop-position=497 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 +--exec $MYSQL_BINLOG --short-form --stop-position=600 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 --disable_query_log select "--- start-datetime --" as ""; --enable_query_log @@ -132,11 +132,11 @@ select "--- offset --" as ""; --disable_query_log select "--- start-position --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form --start-position=497 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002 +--exec $MYSQL_BINLOG --short-form --start-position=600 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002 --disable_query_log select "--- stop-position --" as ""; --enable_query_log ---exec $MYSQL_BINLOG --short-form --stop-position=32 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002 +--exec $MYSQL_BINLOG --short-form --stop-position=126 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002 --disable_query_log select "--- start-datetime --" as ""; --enable_query_log diff --git a/mysql-test/t/mysqlcheck.test b/mysql-test/t/mysqlcheck.test new file mode 100644 index 00000000000..338e16363ea --- /dev/null +++ b/mysql-test/t/mysqlcheck.test @@ -0,0 +1,25 @@ +# Embedded server doesn't support external clients +--source include/not_embedded.inc + +# +# Bug #13783 mysqlcheck tries to optimize and analyze information_schema +# +--replace_result 'Table is already up to date' OK +--exec $MYSQL_CHECK --all-databases --analyze --optimize +--replace_result 'Table is already up to date' OK +--exec $MYSQL_CHECK --analyze --optimize --databases test information_schema mysql +--exec $MYSQL_CHECK --analyze --optimize information_schema schemata + +# +# Bug #16502: mysqlcheck tries to check views +# +create table t1 (a int); +create view v1 as select * from t1; +--replace_result 'Table is already up to date' OK +--exec $MYSQL_CHECK --analyze --optimize --databases test +--replace_result 'Table is already up to date' OK +--exec $MYSQL_CHECK --all-in-1 --analyze --optimize --databases test +drop view v1; +drop table t1; + +--echo End of 5.0 tests diff --git a/mysql-test/t/mysqldump-max.test b/mysql-test/t/mysqldump-max.test new file mode 100644 index 00000000000..359c4ea5793 --- /dev/null +++ b/mysql-test/t/mysqldump-max.test @@ -0,0 +1,68 @@ +# Embedded server doesn't support external clients +--source include/not_embedded.inc +--source include/have_innodb.inc +--source include/have_archive.inc + +--disable_warnings +drop table if exists t1, t2, t3, t4, t5, t6; +--enable_warnings + +create table t1 (id int(8), name varchar(32)); +create table t2 (id int(8), name varchar(32)) ENGINE="MyISAM"; +create table t3 (id int(8), name varchar(32)) ENGINE="MEMORY"; +create table t4 (id int(8), name varchar(32)) ENGINE="HEAP"; +create table t5 (id int(8), name varchar(32)) ENGINE="ARCHIVE"; +create table t6 (id int(8), name varchar(32)) ENGINE="InnoDB"; + +insert into t1 values (1, 'first value'); +insert into t1 values (2, 'first value'); +insert into t1 values (3, 'first value'); +insert into t1 values (4, 'first value'); +insert into t1 values (5, 'first value'); + +insert into t2 values (1, 'first value'); +insert into t2 values (2, 'first value'); +insert into t2 values (3, 'first value'); +insert into t2 values (4, 'first value'); +insert into t2 values (5, 'first value'); + +insert into t3 values (1, 'first value'); +insert into t3 values (2, 'first value'); +insert into t3 values (3, 'first value'); +insert into t3 values (4, 'first value'); +insert into t3 values (5, 'first value'); + +insert into t4 values (1, 'first value'); +insert into t4 values (2, 'first value'); +insert into t4 values (3, 'first value'); +insert into t4 values (4, 'first value'); +insert into t4 values (5, 'first value'); + +insert into t5 values (1, 'first value'); +insert into t5 values (2, 'first value'); +insert into t5 values (3, 'first value'); +insert into t5 values (4, 'first value'); +insert into t5 values (5, 'first value'); + +insert into t6 values (1, 'first value'); +insert into t6 values (2, 'first value'); +insert into t6 values (3, 'first value'); +insert into t6 values (4, 'first value'); +insert into t6 values (5, 'first value'); + +select * from t1; +select * from t2; +select * from t3; +select * from t4; +select * from t5; +select * from t6; + +--exec $MYSQL_DUMP --skip-comments --delayed-insert --insert-ignore --databases test +--exec $MYSQL_DUMP --skip-comments --delayed-insert --databases test + +drop table t1; +drop table t2; +drop table t3; +drop table t4; +drop table t5; +drop table t6; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index b0df2bb9db2..72aad395ec0 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -2,7 +2,11 @@ --source include/not_embedded.inc --disable_warnings -DROP TABLE IF EXISTS t1, `"t"1`, t2, t3; +DROP TABLE IF EXISTS t1, `"t"1`, t1aa, t2, t2aa, t3; +drop database if exists mysqldump_test_db; +drop database if exists db1; +drop database if exists db2; +drop view if exists v1, v2, v3; --enable_warnings # XML output @@ -12,31 +16,31 @@ INSERT INTO t1 VALUES (1), (2); --exec $MYSQL_DUMP --skip-create --skip-comments -X test t1 DROP TABLE t1; -# -# Bug #2005 -# +--echo # +--echo # Bug #2005 +--echo # -CREATE TABLE t1 (a decimal(240, 20)); +CREATE TABLE t1 (a decimal(64, 20)); INSERT INTO t1 VALUES ("1234567890123456789012345678901234567890"), ("0987654321098765432109876543210987654321"); --exec $MYSQL_DUMP --compact test t1 DROP TABLE t1; -# -# Bug #2055 -# +--echo # +--echo # Bug #2055 +--echo # CREATE TABLE t1 (a double); -INSERT INTO t1 VALUES (-9e999999); +INSERT INTO t1 VALUES ('-9e999999'); # The following replaces is here because some systems replaces the above # double with '-inf' and others with MAX_DOUBLE --replace_result (-1.79769313486232e+308) (RES) (NULL) (RES) --exec $MYSQL_DUMP --compact test t1 DROP TABLE t1; -# -# Bug #3361 mysqldump quotes DECIMAL values inconsistently -# +--echo # +--echo # Bug #3361 mysqldump quotes DECIMAL values inconsistently +--echo # CREATE TABLE t1 (a DECIMAL(10,5), b FLOAT); @@ -65,28 +69,28 @@ INSERT INTO t1 VALUES (1, "test", "tes"), (2, "TEST", "TES"); --exec $MYSQL_DUMP --skip-create --compact -X test t1 DROP TABLE t1; -# -# Bug #1707 -# +--echo # +--echo # Bug #1707 +--echo # CREATE TABLE t1 (`a"b"` char(2)); INSERT INTO t1 VALUES ("1\""), ("\"2"); --exec $MYSQL_DUMP --compact --skip-create -X test t1 DROP TABLE t1; -# -# Bug #1994 -# Bug #4261 -# +--echo # +--echo # Bug #1994 +--echo # Bug #4261 +--echo # CREATE TABLE t1 (a VARCHAR(255)) DEFAULT CHARSET koi8r; INSERT INTO t1 VALUES (_koi8r x'C1C2C3C4C5'), (NULL); --exec $MYSQL_DUMP --skip-comments --skip-extended-insert test t1 DROP TABLE t1; -# -# Bug #2634 -# +--echo # +--echo # Bug #2634 +--echo # CREATE TABLE t1 (a int) ENGINE=MYISAM; INSERT INTO t1 VALUES (1), (2); @@ -94,17 +98,17 @@ INSERT INTO t1 VALUES (1), (2); --exec $MYSQL_DUMP --skip-comments --compatible=mysql323 test t1 DROP TABLE t1; -# -# Bug #2592 'mysqldump doesn't quote "tricky" names correctly' -# +--echo # +--echo # Bug #2592 'mysqldump doesn't quote "tricky" names correctly' +--echo # create table ```a` (i int); --exec $MYSQL_DUMP --compact test drop table ```a`; -# -# Bug #2591 "mysqldump quotes names inconsistently" -# +--echo # +--echo # Bug #2591 "mysqldump quotes names inconsistently" +--echo # create table t1(a int); --exec $MYSQL_DUMP --comments=0 test @@ -115,25 +119,25 @@ set global sql_mode='ANSI_QUOTES'; set global sql_mode=''; drop table t1; -# -# Bug #2705 'mysqldump --tab extra output' -# +--echo # +--echo # Bug #2705 'mysqldump --tab extra output' +--echo # create table t1(a int); insert into t1 values (1),(2),(3); ---exec $MYSQL_DUMP --skip-comments --tab=$MYSQL_TEST_DIR/var/tmp/ test ---exec cat $MYSQL_TEST_DIR/var/tmp/t1.sql ---exec cat $MYSQL_TEST_DIR/var/tmp/t1.txt ---exec rm $MYSQL_TEST_DIR/var/tmp/t1.sql ---exec rm $MYSQL_TEST_DIR/var/tmp/t1.txt ---exec $MYSQL_DUMP --tab=$MYSQL_TEST_DIR/var/tmp/ test ---exec rm $MYSQL_TEST_DIR/var/tmp/t1.sql ---exec rm $MYSQL_TEST_DIR/var/tmp/t1.txt +--exec $MYSQL_DUMP --skip-comments --tab=$MYSQLTEST_VARDIR/tmp/ test +--exec cat $MYSQLTEST_VARDIR/tmp/t1.sql +--exec cat $MYSQLTEST_VARDIR/tmp/t1.txt +--exec rm $MYSQLTEST_VARDIR/tmp/t1.sql +--exec rm $MYSQLTEST_VARDIR/tmp/t1.txt +--exec $MYSQL_DUMP --tab=$MYSQLTEST_VARDIR/tmp/ test +--exec rm $MYSQLTEST_VARDIR/tmp/t1.sql +--exec rm $MYSQLTEST_VARDIR/tmp/t1.txt drop table t1; -# -# Bug #6101: create database problem -# +--echo # +--echo # Bug #6101: create database problem +--echo # --exec $MYSQL_DUMP --skip-comments --databases test @@ -141,32 +145,34 @@ create database mysqldump_test_db character set latin2 collate latin2_bin; --exec $MYSQL_DUMP --skip-comments --databases mysqldump_test_db drop database mysqldump_test_db; -# -# Bug #7020 -# Check that we don't dump in UTF8 in compatible mode by default, -# but use the default compiled values, or the values given in -# --default-character-set=xxx. However, we should dump in UTF8 -# if it is explicitely set. +--echo # +--echo # Bug #7020 +--echo # Check that we don't dump in UTF8 in compatible mode by default, +--echo # but use the default compiled values, or the values given in +--echo # --default-character-set=xxx. However, we should dump in UTF8 +--echo # if it is explicitely set. CREATE TABLE t1 (a CHAR(10)); INSERT INTO t1 VALUES (_latin1 'ÄÖÜß'); --exec $MYSQL_DUMP --character-sets-dir=$CHARSETSDIR --skip-comments test t1 -# -# Bug#8063: make test mysqldump [ fail ] -# We cannot tes this command because its output depends -# on --default-character-set incompiled into "mysqldump" program. -# If the future we can move this command into a separate test with -# checking that "mysqldump" is compiled with "latin1" -# + +--echo # +--echo # Bug#8063: make test mysqldump [ fail ] +--echo # We cannot tes this command because its output depends +--echo # on --default-character-set incompiled into "mysqldump" program. +--echo # If the future we can move this command into a separate test with +--echo # checking that "mysqldump" is compiled with "latin1" +--echo # + #--exec $MYSQL_DUMP --character-sets-dir=$CHARSETSDIR --skip-comments --compatible=mysql323 test t1 --exec $MYSQL_DUMP --character-sets-dir=$CHARSETSDIR --skip-comments --compatible=mysql323 --default-character-set=cp850 test t1 --exec $MYSQL_DUMP --character-sets-dir=$CHARSETSDIR --skip-comments --default-character-set=cp850 --compatible=mysql323 test t1 --exec $MYSQL_DUMP --character-sets-dir=$CHARSETSDIR --skip-comments --default-character-set=utf8 --compatible=mysql323 test t1 DROP TABLE t1; -# -# WL #2319: Exclude Tables from dump -# +--echo # +--echo # WL #2319: Exclude Tables from dump +--echo # CREATE TABLE t1 (a int); CREATE TABLE t2 (a int); @@ -176,30 +182,30 @@ INSERT INTO t2 VALUES (4),(5),(6); DROP TABLE t1; DROP TABLE t2; -# -# Bug #8830 -# +--echo # +--echo # Bug #8830 +--echo # CREATE TABLE t1 (`b` blob); INSERT INTO `t1` VALUES (0x602010000280100005E71A); --exec $MYSQL_DUMP --skip-extended-insert --hex-blob test --skip-comments t1 DROP TABLE t1; -# -# Test for --insert-ignore -# +--echo # +--echo # Test for --insert-ignore +--echo # -CREATE TABLE t1 (a decimal(240, 20)); -INSERT INTO t1 VALUES ("1234567890123456789012345678901234567890"), -("0987654321098765432109876543210987654321"); ---exec $MYSQL_DUMP --insert-ignore --skip-comments test t1 ---exec $MYSQL_DUMP --insert-ignore --skip-comments --delayed-insert test t1 +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (1),(2),(3); +INSERT INTO t1 VALUES (4),(5),(6); +--exec $MYSQL_DUMP --skip-comments --insert-ignore test t1 +--exec $MYSQL_DUMP --skip-comments --insert-ignore --delayed-insert test t1 DROP TABLE t1; -# -# Bug #10286: mysqldump -c crashes on table that has many fields with long -# names -# +--echo # +--echo # Bug #10286: mysqldump -c crashes on table that has many fields with long +--echo # names +--echo # create table t1 ( F_c4ca4238a0b923820dcc509a6f75849b int, F_c81e728d9d4c2f636f067f89cc14862c int, @@ -535,18 +541,18 @@ insert into t1 (F_8d3bba7425e7c98c50f52ca1b52d3735) values (1); --exec $MYSQL_DUMP --skip-comments -c test drop table t1; -# -# Test for --add-drop-database -# +--echo # +--echo # Test for --add-drop-database +--echo # CREATE TABLE t1 (a int); INSERT INTO t1 VALUES (1),(2),(3); --exec $MYSQL_DUMP --add-drop-database --skip-comments --databases test DROP TABLE t1; -# -# Bug #9558 mysqldump --no-data db t1 t2 format still dumps data -# +--echo # +--echo # Bug #9558 mysqldump --no-data db t1 t2 format still dumps data +--echo # CREATE DATABASE mysqldump_test_db; USE mysqldump_test_db; @@ -556,14 +562,16 @@ INSERT INTO t1 VALUES (1), (2); INSERT INTO t2 VALUES (1), (2); --exec $MYSQL_DUMP --skip-comments --no-data mysqldump_test_db --exec $MYSQL_DUMP --skip-comments --no-data mysqldump_test_db t1 t2 +--exec $MYSQL_DUMP --skip-comments --skip-create --xml --no-data mysqldump_test_db +--exec $MYSQL_DUMP --skip-comments --skip-create --xml --no-data mysqldump_test_db t1 t2 DROP TABLE t1, t2; DROP DATABASE mysqldump_test_db; -# -# Testing with tables and databases that don't exists -# or contains illegal characters -# (Bug #9358 mysqldump crashes if tablename starts with \) -# +--echo # +--echo # Testing with tables and databases that don't exists +--echo # or contains illegal characters +--echo # (Bug #9358 mysqldump crashes if tablename starts with \) +--echo # create database mysqldump_test_db; use mysqldump_test_db; create table t1(a varchar(30) primary key, b int not null); @@ -595,19 +603,19 @@ select '------ Testing with illegal table names ------' as test_sequence ; --exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "t/1" 2>&1 --error 6 ---exec $MYSQL_DUMP --compact --skip-comments "mysqldump_test_db" "T_1" +--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "T_1" 2>&1 --error 6 ---exec $MYSQL_DUMP --compact --skip-comments "mysqldump_test_db" "T%1" +--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "T%1" 2>&1 --error 6 ---exec $MYSQL_DUMP --compact --skip-comments "mysqldump_test_db" "T'1" +--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "T'1" 2>&1 --error 6 ---exec $MYSQL_DUMP --compact --skip-comments "mysqldump_test_db" "T_1" +--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "T_1" 2>&1 --error 6 ---exec $MYSQL_DUMP --compact --skip-comments "mysqldump_test_db" "T_" +--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "T_" 2>&1 --disable_query_log select '------ Testing with illegal database names ------' as test_sequence ; @@ -623,9 +631,9 @@ drop database mysqldump_test_db; use test; -# -# Bug #9657 mysqldump xml ( -x ) does not format NULL fields correctly -# +--echo # +--echo # Bug #9657 mysqldump xml ( -x ) does not format NULL fields correctly +--echo # create table t1 (a int(10)); create table t2 (pk int primary key auto_increment, @@ -635,28 +643,30 @@ insert into t2 (a, b) values (NULL, NULL),(10, NULL),(NULL, "twenty"),(30, "thir --exec $MYSQL_DUMP --skip-comments --xml --no-create-info test drop table t1, t2; -# -# BUG #12123 -# +--echo # +--echo # BUG #12123 +--echo # + create table t1 (a text character set utf8, b text character set latin1); insert t1 values (0x4F736E616272C3BC636B, 0x4BF66C6E); select * from t1; ---exec $MYSQL_DUMP --tab=$MYSQL_TEST_DIR/var/tmp/ test ---exec $MYSQL test < $MYSQL_TEST_DIR/var/tmp/t1.sql ---exec $MYSQL_IMPORT test $MYSQL_TEST_DIR/var/tmp/t1.txt +--exec $MYSQL_DUMP --tab=$MYSQLTEST_VARDIR/tmp/ test +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/t1.sql +--exec $MYSQL_IMPORT test $MYSQLTEST_VARDIR/tmp/t1.txt select * from t1; drop table t1; -# -# BUG#15328 Segmentation fault occured if my.cnf is invalid for escape sequence -# +--echo # +--echo # BUG#15328 Segmentation fault occured if my.cnf is invalid for escape sequence +--echo # ---exec $MYSQL_MY_PRINT_DEFAULTS --defaults-file=$MYSQL_TEST_DIR/std_data/bug15328.cnf mysqldump +--exec $MYSQL_MY_PRINT_DEFAULTS --config-file=$MYSQL_TEST_DIR/std_data/bug15328.cnf mysqldump +--echo # +--echo # BUG #19025 mysqldump doesn't correctly dump "auto_increment = [int]" +--echo # -# BUG #19025 mysqldump doesn't correctly dump "auto_increment = [int]" -# create table `t1` ( t1_name varchar(255) default null, t1_id int(10) unsigned not null auto_increment, @@ -683,9 +693,9 @@ show create table `t1`; drop table `t1`; -# -# Bug #18536: wrong table order -# +--echo # +--echo # Bug #18536: wrong table order +--echo # create table t1(a int); create table t2(a int); @@ -694,12 +704,729 @@ create table t3(a int); --exec $MYSQL_DUMP --skip-comments --force --no-data test t3 t1 non_existing t2 drop table t1, t2, t3; -# -# Bug #21288: mysqldump segmentation fault when using --where -# +--echo # +--echo # Bug #21288: mysqldump segmentation fault when using --where +--echo # + create table t1 (a int); --error 2 --exec $MYSQL_DUMP --skip-comments --force test t1 --where='xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 2>&1 drop table t1; --echo End of 4.1 tests + +--echo # +--echo # Bug #10213 mysqldump crashes when dumping VIEWs(on MacOS X) +--echo # + +create database db1; +use db1; + +CREATE TABLE t2 ( + a varchar(30) default NULL, + KEY a (a(5)) +); + +INSERT INTO t2 VALUES ('alfred'); +INSERT INTO t2 VALUES ('angie'); +INSERT INTO t2 VALUES ('bingo'); +INSERT INTO t2 VALUES ('waffle'); +INSERT INTO t2 VALUES ('lemon'); +create view v2 as select * from t2 where a like 'a%' with check option; +--exec $MYSQL_DUMP --skip-comments db1 +drop table t2; +drop view v2; +drop database db1; +use test; + +--echo # +--echo # Bug 10713 mysqldump includes database in create view and referenced tables +--echo # + +# create table and views in db2 +create database db2; +use db2; +create table t1 (a int); +create table t2 (a int, b varchar(10), primary key(a)); +insert into t2 values (1, "on"), (2, "off"), (10, "pol"), (12, "meg"); +insert into t1 values (289), (298), (234), (456), (789); +create view v1 as select * from t2; +create view v2 as select * from t1; + +# dump tables and view from db2 +--exec $MYSQL_DUMP db2 > $MYSQLTEST_VARDIR/tmp/bug10713.sql + +# drop the db, tables and views +drop table t1, t2; +drop view v1, v2; +drop database db2; +use test; + +# create db1 and reload dump +create database db1; +use db1; +--exec $MYSQL db1 < $MYSQLTEST_VARDIR/tmp/bug10713.sql + +# check that all tables and views could be created +show tables; +select * from t2 order by a; + +drop table t1, t2; +drop database db1; +use test; + +# +# dump of view +# +create table t1(a int); +create view v1 as select * from t1; +--exec $MYSQL_DUMP --skip-comments test +drop view v1; +drop table t1; + +--echo # +--echo # Bug #10213 mysqldump crashes when dumping VIEWs(on MacOS X) +--echo # + +create database mysqldump_test_db; +use mysqldump_test_db; + +CREATE TABLE t2 ( + a varchar(30) default NULL, + KEY a (a(5)) +); + +INSERT INTO t2 VALUES ('alfred'); +INSERT INTO t2 VALUES ('angie'); +INSERT INTO t2 VALUES ('bingo'); +INSERT INTO t2 VALUES ('waffle'); +INSERT INTO t2 VALUES ('lemon'); +create view v2 as select * from t2 where a like 'a%' with check option; +--exec $MYSQL_DUMP --skip-comments mysqldump_test_db +drop table t2; +drop view v2; +drop database mysqldump_test_db; +use test; + +--echo # +--echo # Bug #9756 +--echo # + +CREATE TABLE t1 (a char(10)); +INSERT INTO t1 VALUES ('\''); +--exec $MYSQL_DUMP --skip-comments test t1 +DROP TABLE t1; + +--echo # +--echo # Bug #10927 mysqldump: Can't reload dump with view that consist of other view +--echo # + +create table t1(a int, b int, c varchar(30)); + +insert into t1 values(1, 2, "one"), (2, 4, "two"), (3, 6, "three"); + +create view v3 as +select * from t1; + +create view v1 as +select * from v3 where b in (1, 2, 3, 4, 5, 6, 7); + +create view v2 as +select v3.a from v3, v1 where v1.a=v3.a and v3.b=3 limit 1; + +--exec $MYSQL_DUMP --skip-comments test + +drop view v1, v2, v3; +drop table t1; + +--echo # +--echo # Test for dumping triggers +--echo # + +CREATE TABLE t1 (a int, b bigint default NULL); +CREATE TABLE t2 (a int); +delimiter |; +create trigger trg1 before insert on t1 for each row +begin + if new.a > 10 then + set new.a := 10; + set new.a := 11; + end if; +end| +create trigger trg2 before update on t1 for each row begin + if old.a % 2 = 0 then set new.b := 12; end if; +end| +set sql_mode="traditional"| +create trigger trg3 after update on t1 for each row +begin + if new.a = -1 then + set @fired:= "Yes"; + end if; +end| +create trigger trg4 before insert on t2 for each row +begin + if new.a > 10 then + set @fired:= "No"; + end if; +end| +set sql_mode=default| +delimiter ;| +--replace_column 6 '0000-00-00 00:00:00' +show triggers like "t1"; +INSERT INTO t1 (a) VALUES (1),(2),(3),(22); +update t1 set a = 4 where a=3; +# Triggers should be dumped by default +--exec $MYSQL_DUMP --skip-comments --databases test +# Skip dumping triggers +--exec $MYSQL_DUMP --skip-comments --databases --skip-triggers test +# Dump and reload... +--exec $MYSQL_DUMP --skip-comments --databases test > $MYSQLTEST_VARDIR/tmp/mysqldump.sql +drop table t1; +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqldump.sql +# Check that tables have been reloaded +show tables; +--replace_column 6 # +show triggers; +DROP TABLE t1, t2; + +--echo # +--echo # Bugs #9136, #12917: problems with --defaults-extra-file option +--echo # + +--system echo '[mysqltest1]' > $MYSQLTEST_VARDIR/tmp/tmp.cnf +--system echo 'port=1234' >> $MYSQLTEST_VARDIR/tmp/tmp.cnf +--exec $MYSQL_MY_PRINT_DEFAULTS -c $MYSQLTEST_VARDIR/tmp/tmp.cnf mysqltest1 +--exec $MYSQL_MY_PRINT_DEFAULTS -e $MYSQLTEST_VARDIR/tmp/tmp.cnf mysqltest1 mysqltest1 +--system rm $MYSQLTEST_VARDIR/tmp/tmp.cnf + +--echo # +--echo # Test of fix to BUG 12597 +--echo # + +DROP TABLE IF EXISTS `test1`; +CREATE TABLE `test1` ( + `a1` int(11) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `test2`; +CREATE TABLE `test2` ( + `a2` int(11) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DELIMITER //; +CREATE TRIGGER `testref` BEFORE INSERT ON `test1` FOR EACH ROW BEGIN +INSERT INTO test2 SET a2 = NEW.a1; END // +DELIMITER ;// + +INSERT INTO `test1` VALUES (1); +SELECT * FROM `test2`; + +# dump +--exec $MYSQL_DUMP --skip-comments --databases test > $MYSQLTEST_VARDIR/tmp/mysqldump.sql + +#DROP TRIGGER testref; +#DROP TABLE test1; +#DROP TABLE test2; +# restore +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqldump.sql +SHOW TRIGGERS; +SELECT * FROM `test1`; +SELECT * FROM `test2`; + +DROP TRIGGER testref; +DROP TABLE test1; +DROP TABLE test2; + +--echo # +--echo # BUG#9056 - mysqldump does not dump routines +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP FUNCTION IF EXISTS bug9056_func1; +DROP FUNCTION IF EXISTS bug9056_func2; +DROP PROCEDURE IF EXISTS bug9056_proc1; +DROP PROCEDURE IF EXISTS bug9056_proc2; +DROP PROCEDURE IF EXISTS `a'b`; +--enable_warnings + +CREATE TABLE t1 (id int); +INSERT INTO t1 VALUES(1), (2), (3), (4), (5); + +DELIMITER //; +CREATE FUNCTION `bug9056_func1`(a INT, b INT) RETURNS int(11) RETURN a+b // +CREATE PROCEDURE `bug9056_proc1`(IN a INT, IN b INT, OUT c INT) +BEGIN SELECT a+b INTO c; end // + +create function bug9056_func2(f1 char binary) returns char binary +begin + set f1= concat( 'hello', f1 ); + return f1; +end // + +CREATE PROCEDURE bug9056_proc2(OUT a INT) +BEGIN + select sum(id) from t1 into a; +END // + +DELIMITER ;// + +set sql_mode='ansi'; +create procedure `a'b` () select 1; # to fix syntax highlighting :') +set sql_mode=''; + +# Dump the DB and ROUTINES +--exec $MYSQL_DUMP --skip-comments --routines --databases test + +# ok, now blow it all away +DROP FUNCTION bug9056_func1; +DROP FUNCTION bug9056_func2; +DROP PROCEDURE bug9056_proc1; +DROP PROCEDURE bug9056_proc2; +DROP PROCEDURE `a'b`; +drop table t1; + +--echo # +--echo # BUG# 13052 - mysqldump timestamp reloads broken +--echo # + +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1 (`d` timestamp, unique (`d`)); +set time_zone='+00:00'; +insert into t1 values ('2003-10-25 22:00:00'),('2003-10-25 23:00:00'); +# results should show two different time values +select * from t1; +set time_zone='Europe/Moscow'; +# results should show two same time values, despite unique +select * from t1; +set global time_zone='Europe/Moscow'; +--exec $MYSQL_DUMP --skip-comments --databases test +--exec $MYSQL_DUMP --skip-tz-utc --skip-comments --databases test +drop table t1; +set global time_zone=default; +set time_zone=default; + +--echo # +--echo # Test of fix to BUG 13146 - ansi quotes break loading of triggers +--echo # + +--disable_warnings +DROP TABLE IF EXISTS `t1 test`; +DROP TABLE IF EXISTS `t2 test`; +--enable_warnings + +CREATE TABLE `t1 test` ( + `a1` int(11) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +CREATE TABLE `t2 test` ( + `a2` int(11) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DELIMITER //; +CREATE TRIGGER `test trig` BEFORE INSERT ON `t1 test` FOR EACH ROW BEGIN +INSERT INTO `t2 test` SET a2 = NEW.a1; END // +DELIMITER ;// + +INSERT INTO `t1 test` VALUES (1); +INSERT INTO `t1 test` VALUES (2); +INSERT INTO `t1 test` VALUES (3); +SELECT * FROM `t2 test`; +# dump with compatible=ansi. Everything except triggers should be double +# quoted +--exec $MYSQL_DUMP --skip-comments --compatible=ansi --triggers test + +DROP TRIGGER `test trig`; +DROP TABLE `t1 test`; +DROP TABLE `t2 test`; + +--echo # +--echo # BUG# 12838 mysqldump -x with views exits with error +--echo # + +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1 (a int, b varchar(32), c varchar(32)); +insert into t1 values (1, 'first value', 'xxxx'); +insert into t1 values (2, 'second value', 'tttt'); +insert into t1 values (3, 'third value', 'vvv vvv'); + +create view v1 as select * from t1; +create view v0 as select * from v1; +create view v2 as select * from v0; + +select * from v2; +--exec $MYSQL_DUMP -x --skip-comments --databases test + +drop view v2; +drop view v0; +drop view v1; +drop table t1; + +--echo # +--echo # BUG#14554 - mysqldump does not separate words "ROW" and "BEGIN" +--echo # for tables with trigger created in the IGNORE_SPACE sql mode. +--echo # + +SET @old_sql_mode = @@SQL_MODE; +SET SQL_MODE = IGNORE_SPACE; + +CREATE TABLE t1 (a INT); +DELIMITER |; +CREATE TRIGGER tr1 BEFORE INSERT ON t1 + FOR EACH ROW + BEGIN + SET new.a = 0; + END| +DELIMITER ;| + +SET SQL_MODE = @old_sql_mode; + +--exec $MYSQL_DUMP --skip-comments --databases test + +DROP TRIGGER tr1; +DROP TABLE t1; + +--echo # +--echo # Bug #13318: Bad result with empty field and --hex-blob +--echo # + +create table t1 (a binary(1), b blob); +insert into t1 values ('',''); +--exec $MYSQL_DUMP --skip-comments --skip-extended-insert --hex-blob test t1 +--exec $MYSQL_DUMP --skip-comments --hex-blob test t1 +drop table t1; + +--echo # +--echo # Bug 14871 Invalid view dump output +--echo # + +create table t1 (a int); +insert into t1 values (289), (298), (234), (456), (789); +create definer = CURRENT_USER view v1 as select * from t1; +create SQL SECURITY INVOKER view v2 as select * from t1; +create view v3 as select * from t1 with local check option; +create algorithm=merge view v4 as select * from t1 with cascaded check option; +create algorithm =temptable view v5 as select * from t1; + +# dump tables and views +--exec $MYSQL_DUMP test > $MYSQLTEST_VARDIR/tmp/bug14871.sql + +# drop the db, tables and views +drop table t1; +drop view v1, v2, v3, v4, v5; + +# Reload dump +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug14871.sql + +# check that all tables and views could be created +show tables; +select * from v3 order by a; + +drop table t1; +drop view v1, v2, v3, v4, v5; + +--echo # +--echo # Bug #16878 dump of trigger +--echo # + +create table t1 (a int, created datetime); +create table t2 (b int, created datetime); +create trigger tr1 before insert on t1 for each row set +new.created=now(); +delimiter |; +create trigger tr2 after insert on t1 +for each row +begin + insert into t2 set b=new.a and created=new.created; +end| +delimiter ;| + +# dump table and trigger +--exec $MYSQL_DUMP test > $MYSQLTEST_VARDIR/tmp/bug16878.sql +drop trigger tr1; +drop trigger tr2; +drop table t1, t2; + +# reload dump +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug16878.sql +--replace_column 6 # +show triggers; +drop trigger tr1; +drop trigger tr2; +drop table t1, t2; + +--echo # +--echo # Bug#18462 mysqldump does not dump view structures correctly +--echo # + +create table t (qty int, price int); +insert into t values(3, 50); +insert into t values(5, 51); +create view v1 as select qty, price, qty*price as value from t; +create view v2 as select qty from v1; +--echo mysqldump { +--exec $MYSQL_DUMP --compact -F --tab $MYSQLTEST_VARDIR/tmp test +--exec cat $MYSQLTEST_VARDIR/tmp/v1.sql +--echo } mysqldump { +--exec cat $MYSQLTEST_VARDIR/tmp/v2.sql +--echo } mysqldump +drop view v1; +drop view v2; +drop table t; + + +--echo # +--echo # Bug#14857 Reading dump files with single statement stored routines fails. +--echo # fixed by patch for bug#16878 +--echo # + +DELIMITER |; +/*!50003 CREATE FUNCTION `f`() RETURNS bigint(20) +return 42 */| +/*!50003 CREATE PROCEDURE `p`() +select 42 */| +DELIMITER ;| +show create function f; +show create procedure p; +drop function f; +drop procedure p; + +--echo # +--echo # Bug #17371 Unable to dump a schema with invalid views +--echo # + +create table t1 ( id serial ); +create view v1 as select * from t1; +drop table t1; +# mysqldump gets 1356 from server, but gives us 2 +--echo mysqldump { +--error 2 +--exec $MYSQL_DUMP --force -N --compact --skip-comments test +--echo } mysqldump +drop view v1; + +--echo # BUG#17201 Spurious 'DROP DATABASE' in output, +--echo # also confusion between tables and views. +--echo # Example code from Markus Popp + +create database mysqldump_test_db; +use mysqldump_test_db; +create table t1 (id int); +create view v1 as select * from t1; +insert into t1 values (1232131); +insert into t1 values (4711); +insert into t1 values (3231); +insert into t1 values (0815); +--exec $MYSQL_DUMP --skip-comments --add-drop-database --databases mysqldump_test_db +drop view v1; +drop table t1; +drop database mysqldump_test_db; + +--echo # +--echo # Bug21014 Segmentation fault of mysqldump on view +--echo # + +create database mysqldump_tables; +use mysqldump_tables; +create table basetable ( id serial, tag varchar(64) ); + +create database mysqldump_views; +use mysqldump_views; +create view nasishnasifu as select mysqldump_tables.basetable.id from mysqldump_tables.basetable; + +--exec $MYSQL_DUMP --skip-comments --compact --databases mysqldump_tables mysqldump_views; + +drop view nasishnasifu; +drop database mysqldump_views; +drop table mysqldump_tables.basetable; +drop database mysqldump_tables; + +--echo # +--echo # Bug20221 Dumping of multiple databases containing view(s) yields maleformed dumps +--echo # + +create database mysqldump_dba; +use mysqldump_dba; +create table t1 (f1 int, f2 int); +insert into t1 values (1,1); +create view v1 as select f1, f2 from t1; + +create database mysqldump_dbb; +use mysqldump_dbb; +create table t1 (f1 int, f2 int); +insert into t1 values (2,2); +create view v1 as select f1, f2 from t1; + +--exec $MYSQL_DUMP --skip-comments --add-drop-database --databases mysqldump_dba mysqldump_dbb > $MYSQLTEST_VARDIR/tmp/bug20221_backup; + +drop view v1; +drop table t1; +drop database mysqldump_dbb; +use mysqldump_dba; +drop view v1; +drop table t1; +drop database mysqldump_dba; + +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20221_backup; + +select * from mysqldump_dba.v1; +select * from mysqldump_dbb.v1; + +use mysqldump_dba; +drop view v1; +drop table t1; +drop database mysqldump_dba; +use mysqldump_dbb; +drop view v1; +drop table t1; +drop database mysqldump_dbb; +use test; + +--echo # +--echo # Bug#21215 mysqldump creating incomplete backups without warning +--echo # + +# Create user without sufficient privs to perform the requested operation +create user mysqltest_1@localhost; +create table t1(a int, b varchar(34)); + +# To get consistent output, reset the master, starts over from first log +reset master; + +# Execute mysqldump, will fail on FLUSH TABLES +--error 2 +--exec $MYSQL_DUMP --compact --master-data -u mysqltest_1 test 2>&1 + +# Execute mysqldump, will fail on FLUSH TABLES +# use --force, should no affect behaviour +--error 2 +--exec $MYSQL_DUMP --compact --force --master-data -u mysqltest_1 test 2>&1 + +# Add RELOAD grants +grant RELOAD on *.* to mysqltest_1@localhost; + +# Execute mysqldump, will fail on SHOW MASTER STATUS +--error 2 +--exec $MYSQL_DUMP --compact --master-data -u mysqltest_1 test 2>&1 + +# Execute mysqldump, will fail on SHOW MASTER STATUS. +# use --force, should not alter behaviour +--error 2 +--exec $MYSQL_DUMP --compact --force --master-data -u mysqltest_1 test 2>&1 + +# Add REPLICATION CLIENT grants +grant REPLICATION CLIENT on *.* to mysqltest_1@localhost; + +# Execute mysqldump, should now succeed +--exec $MYSQL_DUMP --compact --master-data -u mysqltest_1 test 2>&1 + +# Clean up +drop table t1; +drop user mysqltest_1@localhost; + +--echo # +--echo # Bug #21527 mysqldump incorrectly tries to LOCK TABLES on the +--echo # information_schema database. +--echo # +--echo # Bug #21424 mysqldump failing to export/import views +--echo # + +# Do as root +connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); +connection root; +create database mysqldump_myDB; +use mysqldump_myDB; +create user myDB_User; +grant create, create view, select, insert on mysqldump_myDB.* to myDB_User@localhost; +create table t1 (c1 int); +insert into t1 values (3); + +# Do as a user +connect (user1,localhost,myDB_User,,mysqldump_myDB,$MASTER_MYPORT,$MASTER_MYSOCK); +connection user1; +use mysqldump_myDB; +create table u1 (f1 int); +insert into u1 values (4); +create view v1 (c1) as select * from t1; + +# Backup should not fail for Bug #21527. Flush priviliges test begins. +--exec $MYSQL_DUMP --skip-comments --add-drop-table --flush-privileges --ignore-table=mysql.general_log --ignore-table=mysql.slow_log --databases mysqldump_myDB mysql > $MYSQLTEST_VARDIR/tmp/bug21527.sql + +# Clean up +connection root; +use mysqldump_myDB; +drop view v1; +drop table t1; +drop table u1; +revoke all privileges on mysqldump_myDB.* from myDB_User@localhost; +drop user myDB_User; +drop database mysqldump_myDB; +flush privileges; + +--echo # Bug #21424 continues from here. +--echo # Restore. Flush Privileges test ends. +--echo # + +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug21527.sql; + +# Do as a user +connection user1; +use mysqldump_myDB; + +# Ultimate test for correct data. +select * from mysqldump_myDB.v1; +select * from mysqldump_myDB.u1; + +#Final cleanup. +connection root; +use mysqldump_myDB; +drop view v1; +drop table t1; +drop table u1; +revoke all privileges on mysqldump_myDB.* from myDB_User@localhost; +drop user myDB_User; +drop database mysqldump_myDB; +use test; + +--echo # +--echo # BUG#13926: --order-by-primary fails if PKEY contains quote character +--echo # + +--disable_warnings +DROP TABLE IF EXISTS `t1`; +CREATE TABLE `t1` ( + `a b` INT, + `c"d` INT, + `e``f` INT, + PRIMARY KEY (`a b`, `c"d`, `e``f`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +insert into t1 values (0815, 4711, 2006); + +--exec $MYSQL_DUMP --skip-comments --compatible=ansi --order-by-primary test t1 +--exec $MYSQL_DUMP --skip-comments --order-by-primary test t1 +DROP TABLE `t1`; +--enable_warnings + +--echo # +--echo # Bug #19745: mysqldump --xml produces invalid xml +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (f1 int(10), data MEDIUMBLOB); +INSERT INTO t1 VALUES(1,0xff00fef0); + +--exec $MYSQL_DUMP --xml --hex-blob --skip-create-options test t1 + +DROP TABLE t1; + +--echo # +--echo # End of 5.0 tests +--echo # diff --git a/mysql-test/t/mysqlshow.test b/mysql-test/t/mysqlshow.test new file mode 100644 index 00000000000..9ed93079f57 --- /dev/null +++ b/mysql-test/t/mysqlshow.test @@ -0,0 +1,36 @@ +# Can't run test of external client with embedded server +-- source include/not_embedded.inc + +--disable_warnings +DROP TABLE IF EXISTS t1,t2,test1,test2; +--enable_warnings + +# +## Bug #5036 mysqlshow is missing a column +# +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (1),(2),(3); +CREATE TABLE t2 (a int, b int); +show tables; +select "--------------------" as ""; +--exec $MYSQL_SHOW test +select "---- -v ------------" as ""; +--exec $MYSQL_SHOW test -v +select "---- -v -v ---------" as ""; +--exec $MYSQL_SHOW test -v -v +select "----- -t -----------" as ""; +--exec $MYSQL_SHOW test -t +select "---- -v -t ---------" as ""; +--exec $MYSQL_SHOW test -v -t +select "---- -v -v -t ------" as ""; +--exec $MYSQL_SHOW test -v -v -t +DROP TABLE t1, t2; + +# +# Bug #19147: mysqlshow INFORMATION_SCHEMA does not work +# +--exec $MYSQL_SHOW information_schema +--exec $MYSQL_SHOW INFORMATION_SCHEMA +--exec $MYSQL_SHOW inf_rmation_schema + +--echo End of 5.0 tests diff --git a/mysql-test/t/ndb_alter_table.test b/mysql-test/t/ndb_alter_table.test index 22383a82bca..957b95c6fd9 100644 --- a/mysql-test/t/ndb_alter_table.test +++ b/mysql-test/t/ndb_alter_table.test @@ -3,7 +3,7 @@ -- source include/not_embedded.inc --disable_warnings -DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t1, t2; drop database if exists mysqltest; --enable_warnings @@ -56,10 +56,12 @@ col3 varchar (20) not null, col4 varchar(4) not null, col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null, col6 int not null, to_be_deleted int) ENGINE=ndbcluster; +--replace_column 7 # 8 # 10 # 12 # 13 # 14 # 18 # show table status; SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; insert into t1 values (0,4,3,5,"PENDING",1,7),(NULL,4,3,5,"PENDING",1,7),(31,4,3,5,"PENDING",1,7), (7,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7), (100,4,3,5,"PENDING",1,7), (99,4,3,5,"PENDING",1,7), (8,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7); +--replace_column 7 # 8 # 10 # 12 # 13 # 14 # 18 # show table status; select * from t1 order by col1; alter table t1 @@ -68,9 +70,11 @@ add column col7 varchar(30) not null after col5, add column col8 datetime not null, drop column to_be_deleted, change column col2 fourth varchar(30) not null after col3, modify column col6 int not null first; +--replace_column 7 # 8 # 10 # 12 # 13 # 14 # 18 # show table status; select * from t1 order by col1; insert into t1 values (2, NULL,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00'); +--replace_column 7 # 8 # 10 # 12 # 13 # 14 # 18 # show table status; select * from t1 order by col1; delete from t1; @@ -322,4 +326,20 @@ on t1 (c010, c011, c012, c013); drop table t1; +# simple test that auto incr is not lost at rename or alter +create table t1 (a int primary key auto_increment, b int) engine=ndb; +insert into t1 (b) values (101),(102),(103); +select * from t1 where a = 3; +alter table t1 rename t2; +insert into t2 (b) values (201),(202),(203); +select * from t2 where a = 6; +alter table t2 add c int; +insert into t2 (b) values (301),(302),(303); +select * from t2 where a = 9; +alter table t2 rename t1; +insert into t1 (b) values (401),(402),(403); +select * from t1 where a = 12; +drop table t1; + # End of 4.1 tests + diff --git a/mysql-test/t/ndb_alter_table2.test b/mysql-test/t/ndb_alter_table2.test new file mode 100644 index 00000000000..3861fcc6c9d --- /dev/null +++ b/mysql-test/t/ndb_alter_table2.test @@ -0,0 +1,83 @@ +-- source include/have_ndb.inc +-- source include/have_multi_ndb.inc +-- source include/not_embedded.inc + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +connect (con1,localhost,root,,test); +connect (con2,localhost,root,,test); +connect (con3,localhost,root,,test); +connect (con4,localhost,root,,test); +connect (con5,localhost,root,,test); +connect (con6,localhost,root,,test); + +CREATE TABLE t1 ( + a INT NOT NULL PRIMARY KEY, + b INT NOT NULL +) ENGINE=ndbcluster; + +connection con1; +BEGIN; +INSERT INTO t1 VALUES (9410,9412); +connection con2; +BEGIN; +--send +INSERT INTO t1 VALUES (9411,9412); +connection con3; +BEGIN; +--send +INSERT INTO t1 VALUES (9412,9412); +connection con4; +BEGIN; +--send +INSERT INTO t1 VALUES (9413,9412); +connection con5; +BEGIN; +--send +INSERT INTO t1 VALUES (9414,9412); +connection con6; +BEGIN; +--send +INSERT INTO t1 VALUES (9415,9412); +connection con1; +sleep 1; + +ROLLBACK; +connection con2; +reap; +ROLLBACK; +connection con3; +reap; +ROLLBACK; +connection con4; +reap; +ROLLBACK; +connection con5; +reap; +ROLLBACK; +connection con6; +reap; +ROLLBACK; + +connection server2; + +drop table t1; +CREATE TABLE t1 ( + a INT NOT NULL PRIMARY KEY, + b INT NOT NULL, + c INT NOT NULL +) ENGINE=ndbcluster; + +connection server1; + +--error 1296 +select * from t1; +select * from t1; +select * from t1; +select * from t1; +select * from t1; +select * from t1; + +drop table t1; diff --git a/mysql-test/t/ndb_autodiscover.test b/mysql-test/t/ndb_autodiscover.test index e45133afbca..6eb039c2df2 100644 --- a/mysql-test/t/ndb_autodiscover.test +++ b/mysql-test/t/ndb_autodiscover.test @@ -24,7 +24,7 @@ create table t1( insert into t1 values(1, "Autodiscover"); flush tables; -system rm var/master-data/test/t1.frm ; +system rm $MYSQLTEST_VARDIR/master-data/test/t1.frm ; select * from t1; show status like 'handler_discover%'; @@ -33,13 +33,13 @@ show status like 'handler_discover%'; # flush tables; -system rm var/master-data/test/t1.frm ; +system rm $MYSQLTEST_VARDIR/master-data/test/t1.frm ; insert into t1 values (2, "Auto 2"); show status like 'handler_discover%'; insert into t1 values (3, "Discover 3"); show status like 'handler_discover%'; flush tables; -system rm var/master-data/test/t1.frm ; +system rm $MYSQLTEST_VARDIR/master-data/test/t1.frm ; select * from t1 order by id; show status like 'handler_discover%'; @@ -48,7 +48,7 @@ show status like 'handler_discover%'; # flush tables; -system rm var/master-data/test/t1.frm ; +system rm $MYSQLTEST_VARDIR/master-data/test/t1.frm ; update t1 set name="Autodiscover" where id = 2; show status like 'handler_discover%'; select * from t1 order by id; @@ -59,7 +59,7 @@ show status like 'handler_discover%'; # flush tables; -system rm var/master-data/test/t1.frm ; +system rm $MYSQLTEST_VARDIR/master-data/test/t1.frm ; delete from t1 where id = 3; select * from t1 order by id; show status like 'handler_discover%'; @@ -85,7 +85,7 @@ show status like 'handler_discover%'; flush tables; # Modify the frm file on disk -system echo "blaj" >> var/master-data/test/t2.frm ; +system echo "blaj" >> $MYSQLTEST_VARDIR/master-data/test/t2.frm ; select * from t2; show status like 'handler_discover%'; @@ -111,7 +111,7 @@ show status like 'handler_discover%'; flush tables; # Remove the frm file from disk -system rm var/master-data/test/t3.frm ; +system rm $MYSQLTEST_VARDIR/master-data/test/t3.frm ; --error 1050 create table t3( @@ -168,16 +168,16 @@ show status like 'handler_discover%'; # Remove the frm file from disk flush tables; -system rm var/master-data/test/t7.frm ; +system rm $MYSQLTEST_VARDIR/master-data/test/t7.frm ; show tables from test; show status like 'handler_discover%'; # Remove the frm file from disk again flush tables; -system rm var/master-data/test/t7.frm ; +system rm $MYSQLTEST_VARDIR/master-data/test/t7.frm ; ---replace_column 7 # 8 # 9 # 12 # 13 # 15 # +--replace_column 7 # 8 # 9 # 12 # 13 # 15 # 18 # show table status; show status like 'handler_discover%'; @@ -210,8 +210,30 @@ select * from t4; select * from t4; show status like 'handler_discover%'; +--error 1051 drop table t4; +create table t4( + id int not null primary key, + name char(27) +) engine=ndb; +insert into t4 values (1, "Automatic"); +select * from t4; + +# Remove the table from NDB +system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t4 >> $NDB_TOOLS_OUTPUT ; + +--error 1146 +select * from t4; + +drop table if exists t4; + +# Test that dropping a table that does not exists +# on disk or in NDB gives same result as above +--error 1051 +drop table t5; +drop table if exists t5; + ####################################################### # Test that a table that has been dropped from NDB @@ -268,8 +290,8 @@ insert into t9 values (9); system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t3 >> $NDB_TOOLS_OUTPUT ; system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t5 >> $NDB_TOOLS_OUTPUT ; # Remove t6, t7 from disk -system rm var/master-data/test/t6.frm > /dev/null ; -system rm var/master-data/test/t7.frm > /dev/null ; +system rm $MYSQLTEST_VARDIR/master-data/test/t6.frm > /dev/null ; +system rm $MYSQLTEST_VARDIR/master-data/test/t7.frm > /dev/null ; SHOW TABLES; @@ -310,8 +332,8 @@ insert into t9 values (9); system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t3 > /dev/null ; system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t5 > /dev/null ; # Remove t6, t7 from disk -system rm var/master-data/test/t6.frm > /dev/null ; -system rm var/master-data/test/t7.frm > /dev/null ; +system rm $MYSQLTEST_VARDIR/master-data/test/t6.frm > /dev/null ; +system rm $MYSQLTEST_VARDIR/master-data/test/t7.frm > /dev/null ; SHOW TABLES LIKE 't6'; @@ -353,9 +375,9 @@ insert into t3 values (3, "ndb table 3"); insert into t4 values (4); # Remove t1, t2, t3 from disk -system rm var/master-data/test/t1.frm > /dev/null ; -system rm var/master-data/test/t2.frm > /dev/null ; -system rm var/master-data/test/t3.frm > /dev/null ; +system rm $MYSQLTEST_VARDIR/master-data/test/t1.frm > /dev/null ; +system rm $MYSQLTEST_VARDIR/master-data/test/t2.frm > /dev/null ; +system rm $MYSQLTEST_VARDIR/master-data/test/t3.frm > /dev/null ; flush tables; # Select from the table which only exists in NDB. @@ -450,9 +472,28 @@ drop table t1; use test2; drop table t2; drop database test2; -show databases; use test; +######################################################### +# Bug#8035 +# mysqld would segfault on second select * before bug was fixed +# +--disable_warnings +drop database if exists test_only_ndb_tables; +--enable_warnings +create database test_only_ndb_tables; +use test_only_ndb_tables; +create table t1 (a int primary key) engine=ndb; +select * from t1; +--exec $NDB_MGM --no-defaults -e "all restart -n" > /dev/null +--exec $NDB_TOOLS_DIR/ndb_waiter --no-defaults --not-started > /dev/null +--error 1015 +select * from t1; +--exec $NDB_MGM --no-defaults -e "all start" > /dev/null +--exec $NDB_TOOLS_DIR/ndb_waiter --no-defaults > /dev/null +use test; +drop database test_only_ndb_tables; + ##################################################### # Test that it's not possible to create tables # with same name as NDB internal tables @@ -489,7 +530,7 @@ CREATE TABLE t9 ( insert t9 values(1, 2), (2,3), (3, 4), (4, 5); #Don't drop the table, instead remove the frm file -system rm var/master-data/test/t9.frm ; +system rm $MYSQLTEST_VARDIR/master-data/test/t9.frm ; # Now leave test case, when ndb_autodiscover2 will run, this # MySQL Server will have been restarted because it has a diff --git a/mysql-test/t/ndb_basic.test b/mysql-test/t/ndb_basic.test index fdc87382308..6c1a4e44f4b 100644 --- a/mysql-test/t/ndb_basic.test +++ b/mysql-test/t/ndb_basic.test @@ -551,7 +551,7 @@ create table t1 (a bigint, b bigint, c bigint, d bigint, primary key (a,b,c,d)) engine=ndb - max_rows=200000000; + max_rows=800000000; insert into t1 values (1,2,3,4),(2,3,4,5),(3,4,5,6), (3,2,3,4),(1,3,4,5),(2,4,5,6), @@ -681,3 +681,32 @@ drop table t2; drop table t3; # End of 4.1 tests + +# +# Test long table name +# +create table atablewithareallylongandirritatingname (a int); +insert into atablewithareallylongandirritatingname values (2); +select * from atablewithareallylongandirritatingname; +drop table atablewithareallylongandirritatingname; + +# +# Bug#15682 +# +create table t1 (f1 varchar(50), f2 text,f3 int, primary key(f1)) engine=NDB; +insert into t1 (f1,f2,f3)VALUES("111111","aaaaaa",1); +insert into t1 (f1,f2,f3)VALUES("222222","bbbbbb",2); +select * from t1 order by f1; +select * from t1 order by f2; +select * from t1 order by f3; +drop table t1; + +# +# Bug#16561 Unknown ERROR msg "ERROR 1186 (HY000): Binlog closed" by perror +# + +# As long there is no error code 1186 defined by NDB +# we should get a message "Illegal ndb error code: 1186" +--error 1 +--exec $MY_PERROR --ndb 1186 2>&1 + diff --git a/mysql-test/t/ndb_bitfield.test b/mysql-test/t/ndb_bitfield.test new file mode 100644 index 00000000000..59d6e56577e --- /dev/null +++ b/mysql-test/t/ndb_bitfield.test @@ -0,0 +1,122 @@ +-- source include/have_ndb.inc +-- source include/not_embedded.inc + +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1 ( + pk1 int not null primary key, + b bit(64) +) engine=ndbcluster; + +show create table t1; +insert into t1 values +(0,b'1111111111111111111111111111111111111111111111111111111111111111'), +(1,b'1000000000000000000000000000000000000000000000000000000000000000'), +(2,b'0000000000000000000000000000000000000000000000000000000000000001'), +(3,b'1010101010101010101010101010101010101010101010101010101010101010'), +(4,b'0101010101010101010101010101010101010101010101010101010101010101'); +select hex(b) from t1 order by pk1; +drop table t1; + +create table t1 ( + pk1 int not null primary key, + b bit(9) +) engine=ndbcluster; +insert into t1 values +(0,b'000000000'), +(1,b'000000001'), +(2,b'000000010'), +(3,b'000000011'), +(4,b'000000100'); +select hex(b) from t1 order by pk1; +update t1 set b = b + b'101010101'; +select hex(b) from t1 order by pk1; +drop table t1; + +create table t1 (a bit(7), b bit(9)) engine = ndbcluster; +insert into t1 values +(94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177), +(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380), +(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36), +(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499), +(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403), +(44, 307), (68, 454), (57, 135); +select a+0 from t1 order by a; +select b+0 from t1 order by b; +drop table t1; + +create table t1 ( + dummyKey INTEGER NOT NULL, + a001 TINYINT, + a010 TINYINT, + a012 TINYINT, + a015 TINYINT, + a016 TINYINT, + a017 TINYINT, + a019 TINYINT, + a029 TINYINT, + a030 TINYINT, + a031 TINYINT, + a032 TINYINT, + a042 TINYINT, + a043 TINYINT, + a044 TINYINT, + a3001 TINYINT, + a3002 TINYINT, + a3003 TINYINT, + a3004 TINYINT, + a3005 TINYINT, + a3021 TINYINT, + a3022 TINYINT, + a BIT(6), + b BIT(6), + c BIT(6), + d TINYINT, + e TINYINT, + f TINYINT, + g TINYINT, + h TINYINT, + i TINYINT, + j TINYINT, + k TINYINT, + l TINYINT, + m TINYINT, + n TINYINT, + o TINYINT, + a034 TINYINT, +PRIMARY KEY USING HASH (dummyKey) ) engine=ndb; +INSERT INTO `t1` VALUES +(1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'000001',b'111111',b'111110',4,5,5,5,5,5,5,5,5,5,3,2,1), +(2,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'000010',b'000000',b'111101',4,5,5,5,5,5,5,5,5,5,3,2,1), +(3,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'000100',b'001111',b'111011',4,5,5,5,5,5,5,5,5,5,3,2,1), +(4,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'001000',b'110000',b'110111',4,5,5,5,5,5,5,5,5,5,3,2,1), +(5,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'010000',b'100001',b'101111',4,5,5,5,5,5,5,5,5,5,3,2,1), +(6,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'100000',b'010010',b'011111',4,5,5,5,5,5,5,5,5,5,3,2,1), +(7,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'000000',b'001100',b'111111',4,5,5,5,5,5,5,5,5,5,3,2,1), +(8,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'111111',b'000000',b'000000',4,5,5,5,5,5,5,5,5,5,3,2,1); +--exec $MYSQL_DUMP --hex-blob --compact --order-by-primary --skip-extended-insert --no-create-info test t1 +drop table t1; + +--error 1005 +create table t1 ( + pk1 bit(9) not null primary key, + b int +) engine=ndbcluster; + +--error 1005 +create table t1 ( + pk1 int not null primary key, + b bit(9), + key(b) +) engine=ndbcluster; + +# bug#16125 +create table t1 ( + pk1 int primary key, + b bit(32) not null +) engine=ndbcluster; + +insert into t1 values (1,1); +drop table t1; diff --git a/mysql-test/t/ndb_blob.test b/mysql-test/t/ndb_blob.test index bf82a793049..d6e0edc89f0 100644 --- a/mysql-test/t/ndb_blob.test +++ b/mysql-test/t/ndb_blob.test @@ -428,4 +428,60 @@ truncate t1; select count(*) from t1; drop table t1; +# -- bug#19956 - var* key, complex key + +create table t1 ( + a varchar(40) not null, + b mediumint not null, + t text, + c varchar(2) not null, + d bigint not null, + primary key (a,b,c), + key (c,a), + unique key (d) +) engine=ndb; + +--disable_query_log +set @s1 = 'rggurloniukyehuxdbfkkyzlceixzrehqhvxvxbpwizzvjzpucqmzrhzxzfau'; +set @s2 = 'ykyymbzqgqlcjhlhmyqelfoaaohvtbekvifukdtnvcrrjveevfakxarxexomz'; +set @s3 = 'dbnfqyzgtqxalcrwtfsqabknvtfcbpoonxsjiqvmhnfikxxhcgoexlkoezvah'; +set @v1 = repeat(@s1,123); +set @v2 = repeat(@s2,234); +set @v3 = repeat(@s3,345); +set @v4 = NULL; +--enable_query_log + +insert into t1 (a,b,c,d,t) values ('a',1110,'a',1,@v1); +insert into t1 (a,b,c,d,t) values ('b',1110,'a',2,@v2); +insert into t1 (a,b,c,d,t) values ('a',1110,'b',3,@v3); +insert into t1 (a,b,c,d,t) values ('b',1110,'b',4,@v4); +select a,b,c,d,sha1(t) from t1 order by c,a; + +select a,b,c,d,sha1(t) from t1 where a='a' and b=1110 and c='a'; +select a,b,c,d,sha1(t) from t1 where a='a' and b=1110 and c='b'; + +update t1 set t=@v4 where a='b' and b=1110 and c='a'; +update t1 set t=@v2 where a='b' and b=1110 and c='b'; +select a,b,c,d,sha1(t) from t1 order by c,a; + +update t1 set t=@v2 where d=2; +update t1 set t=@v4 where d=4; +select a,b,c,d,sha1(t) from t1 order by c,a; + +update t1 set t=@v4 where a='b' and c='a'; +update t1 set t=@v2 where a='b' and c='b'; +select a,b,c,d,sha1(t) from t1 order by c,a; + +update t1 set t=@v2 where b+d=1112; +update t1 set t=@v4 where b+d=1114; +select a,b,c,d,sha1(t) from t1 order by c,a; + +delete from t1 where a='a' and b=1110 and c='a'; +delete from t1 where a='b' and c='a'; +delete from t1 where d=3; +delete from t1 where b+d=1114; +select count(*) from t1; + +drop table t1; + # End of 4.1 tests diff --git a/mysql-test/t/ndb_cache.test b/mysql-test/t/ndb_cache.test index 481ec156307..9c299b61c24 100644 --- a/mysql-test/t/ndb_cache.test +++ b/mysql-test/t/ndb_cache.test @@ -2,32 +2,120 @@ -- source include/have_ndb.inc -- source include/not_embedded.inc +--disable_warnings +drop table if exists t1; +--enable_warnings + +# Turn on and reset query cache +set GLOBAL query_cache_type=on; set GLOBAL query_cache_size=1355776; reset query cache; flush status; ---disable_warnings -drop table if exists t1,t2; ---enable_warnings +# Create test table in NDB +CREATE TABLE t1 ( pk int not null primary key, + a int, b int not null, c varchar(20)) ENGINE=ndbcluster; +insert into t1 value (1, 2, 3, 'First row'); -CREATE TABLE t1 (a int) ENGINE=ndbcluster; -CREATE TABLE t2 (a int); +# Perform one query which should be inerted in query cache +select * from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +# Perform the same query and make sure the query cache is hit +select * from t1; +show status like "Qcache_hits"; +# Update the table and make sure the correct data is returned +update t1 set a=3 where pk=1; select * from t1; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +# Insert a new record and make sure the correct data is returned +insert into t1 value (2, 7, 8, 'Second row'); +insert into t1 value (4, 5, 6, 'Fourth row'); +select * from t1 order by pk; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from t1 order by pk; +show status like "Qcache_hits"; + +# Perform a "new" query and make sure the query cache is not hit +select * from t1 where b=3; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_hits"; + +# Same query again... +select * from t1 where b=3; +show status like "Qcache_hits"; + +# Delete from the table +delete from t1 where c='Fourth row'; show status like "Qcache_queries_in_cache"; +select * from t1 where b=3; +show status like "Qcache_hits"; + +# Start another connection and check that the query cache is hit +connect (con1,localhost,root,,); +connection con1; +use test; +select * from t1 order by pk; +select * from t1 where b=3; +show status like "Qcache_hits"; + +# Update the table and switch to other connection +update t1 set a=4 where b=3; +connect (con2,localhost,root,,); +connection con2; +use test; +show status like "Qcache_queries_in_cache"; +select * from t1 order by pk desc; +select * from t1 order by pk desc; show status like "Qcache_inserts"; show status like "Qcache_hits"; -select * from t2; +connection con1; +select * from t1 order by pk desc; +select * from t1 order by pk desc; show status like "Qcache_queries_in_cache"; show status like "Qcache_inserts"; show status like "Qcache_hits"; -select * from t1; -select * from t2; + +# Use transactions and make sure the query cache is not updated until +# transaction is commited +begin; +update t1 set a=5 where pk=1; +# Note!! the below test shows that table is invalidated +# before transaction is committed +# TODO Fix so that cache is not invalidated HERE! +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con2; +select * from t1 order by pk desc; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con1; +commit; +# TODO Here query is invalidated once again, commit count in NDB has changed +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con2; +select * from t1 order by pk desc; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con1; +select * from t1 order by pk desc; show status like "Qcache_queries_in_cache"; show status like "Qcache_inserts"; show status like "Qcache_hits"; -drop table t1, t2; +drop table t1; + +show status like "Qcache_queries_in_cache"; SET GLOBAL query_cache_size=0; diff --git a/mysql-test/t/ndb_cache2.test b/mysql-test/t/ndb_cache2.test new file mode 100644 index 00000000000..352b01ef73f --- /dev/null +++ b/mysql-test/t/ndb_cache2.test @@ -0,0 +1,361 @@ +-- source include/have_query_cache.inc +-- source include/have_ndb.inc +-- source include/not_embedded.inc + +--disable_warnings +drop table if exists t1, t2, t3, t4, t5; +--enable_warnings + + +# Turn on and reset query cache +set GLOBAL query_cache_type=on; +set GLOBAL query_cache_size=1355776; +# Turn on thread that will fetch commit count for open tables +set GLOBAL ndb_cache_check_time=100; +reset query cache; +flush status; + +# Create test tables in NDB +CREATE TABLE t1 ( + pk int not null primary key, + a1 int, + b1 int not null, + c1 varchar(20) +) ENGINE=ndb; +CREATE TABLE t2 ( + pk int not null primary key, + a2 int, + b2 int not null +) ENGINE=ndb; +CREATE TABLE t3 ( + pk int not null primary key, + a3 int, + b3 int not null, + c3 int not null, + d3 varchar(20) +) ENGINE=ndb; +CREATE TABLE t4 ( + a4 int, + b4 int not null, + c4 char(20) +) ENGINE=ndbcluster; +CREATE TABLE t5 ( + pk int not null primary key, + a5 int, + b5 int not null, + c5 varchar(255) +) ENGINE=ndbcluster; +insert into t1 value (1, 2, 3, 'First row'); +insert into t2 value (1, 2, 3); +insert into t3 value (1, 2, 3, 4, '3 - First row'); +insert into t4 value (2, 3, '4 - First row'); +insert into t5 value (1, 2, 3, '5 - First row'); + +# Perform one query which should be inserted in query cache +select * from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +# Perform the same query and make sure the query cache is hit +select * from t1; +show status like "Qcache_hits"; + +# Update the table and make sure the correct data is returned +update t1 set a1=3 where pk=1; +select * from t1; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +# Insert a new record and make sure the correct data is returned +insert into t1 value (2, 7, 8, 'Second row'); +insert into t1 value (4, 5, 6, 'Fourth row'); +select * from t1 order by pk desc; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from t1 order by pk desc; +show status like "Qcache_hits"; + +# Perform a "new" query and make sure the query cache is not hit +select * from t1 where b1=3; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_hits"; + +# Same query again... +select * from t1 where b1=3; +show status like "Qcache_hits"; + +# Delete from the table +delete from t1 where c1='Fourth row'; +show status like "Qcache_queries_in_cache"; +select * from t1 where b1=3; +show status like "Qcache_hits"; + +# Start another connection and check that the query cache is hit +connect (con1,localhost,root,,); +connection con1; +use test; +select * from t1 order by pk desc; +select * from t1 where b1=3; +show status like "Qcache_hits"; + +# Update the table and switch to other connection +update t1 set a1=4 where b1=3; +connect (con2,localhost,root,,); +connection con2; +use test; +show status like "Qcache_queries_in_cache"; +select * from t1 order by pk desc; +select * from t1 order by pk desc; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con1; +select * from t1 order by pk desc; +select * from t1 order by pk desc; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +# Load all tables into cache +select * from t2; +select * from t3; +select * from t4; +select * from t5; +show status like "Qcache_queries_in_cache"; + +##################################################################### +# Start transaction and perform update +# Switch to other transaction and check that update does not show up +# Switch back and commit transaction +# Switch to other transaction and check that update shows up +##################################################################### +connection con1; +flush status; +begin; +update t1 set a1=5 where pk=1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con2; +select * from t1 order by pk desc; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con1; +commit; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con2; +select * from t1 order by pk desc; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con1; +select * from t1 order by pk desc; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +##################################################################### +# Start transaction and perform update +# Switch to other transaction and check that update does not show up +# Switch back, perform selects and commit transaction +# Switch to other transaction and check that update shows up +##################################################################### +connection con1; +flush status; +begin; +update t1 set a1=6 where pk=1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con2; +select * from t1 order by pk desc; +select * from t1 order by pk desc; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con1; +# The two queries below will not hit cache since transaction is ongoing +select * from t1 order by pk desc; +select * from t1 order by pk desc; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +commit; + +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con2; +select * from t1 order by pk desc; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con1; +select * from t1 order by pk desc; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +##################################################################### +# Start transaction and perform insert +# Switch to other transaction and check that insert does not show up +# Switch back, perform selects and commit transaction +# Switch to other transaction and check that update shows up +##################################################################### +connection con1; +flush status; +begin; +insert into t1 set pk=5, a1=6, b1=3, c1="New row"; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con2; +select * from t1 where pk=5; +select * from t1 order by pk desc; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con1; +# The below four queries will not be cached, trans is ongoing +select * from t1 where pk=5; +select * from t1 where pk=5; +select * from t1 order by pk desc; +select * from t1 order by pk desc; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +commit; + +connection con2; +select * from t1 order by pk desc; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +connection con1; + +##################################################################### +# Start transaction and perform delete +# Switch to other transaction and check that delete does not show up +# Switch back, perform selects and commit transaction +# Switch to other transaction and check that update shows up +##################################################################### +connection con1; +flush status; +begin; +delete from t1 where pk=2; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con2; +select * from t1 where pk=2; +select * from t1 order by pk desc; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con1; +# The below four queries will not be cached, trans is ongoing +select * from t1 where pk=2; +select * from t1 order by pk desc; +select * from t1 order by pk desc; +select * from t1 where pk=2; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +commit; + +connection con2; +select * from t1 order by pk desc; +select * from t1 where pk=2; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +connection con1; + +##################################################################### +# Start a transaction which updates all tables +# Switch to other transaction and check updates does not show up +# Switch back, perform selects and commit transaction +# Switch to other transaction and check that update shows up +##################################################################### +flush status; +begin; +update t1 set a1=9 where pk=1; +update t2 set a2=9 where pk=1; +update t3 set a3=9 where pk=1; +update t4 set a4=9 where a4=2; +update t5 set a5=9 where pk=1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con2; +select * from t1 order by pk desc; +select * from t2; +select * from t3; +select * from t4; +select * from t5; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +connection con1; +# The below five queries will not be cached, trans is ongoing +select * from t1 order by pk desc; +select * from t1 order by pk desc; +select * from t2; +select * from t3; +select * from t4; +select * from t5; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +commit; + +connection con2; +select * from t1 order by pk desc; +select * from t2; +select * from t3; +select * from t4; +select * from t5; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +connection con1; +select * from t1 order by pk desc; +select * from t2; +select * from t3; +select * from t4; +select * from t5; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from t1 order by pk desc; +select * from t2; +select * from t3; +select * from t4; +select * from t5; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +connection con2; +select * from t1 order by pk desc; +select * from t2; +select * from t3; +select * from t4; +select * from t5; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +drop table t1, t2, t3, t4, t5; + +# There should be no queries in cache, when tables have been dropped +show status like "Qcache_queries_in_cache"; + +SET GLOBAL query_cache_size=0; +SET GLOBAL ndb_cache_check_time=0; + + diff --git a/mysql-test/t/ndb_cache_multi.test b/mysql-test/t/ndb_cache_multi.test new file mode 100644 index 00000000000..beb8e4bc2ac --- /dev/null +++ b/mysql-test/t/ndb_cache_multi.test @@ -0,0 +1,65 @@ +-- source include/have_query_cache.inc +-- source include/have_ndb.inc +-- source include/have_multi_ndb.inc +-- source include/not_embedded.inc + +--disable_warnings +drop table if exists t1, t2; +--enable_warnings + + +# Turn on and reset query cache on server1 +connection server1; +set GLOBAL query_cache_type=on; +set GLOBAL query_cache_size=1355776; +reset query cache; +flush status; + +# Turn on and reset query cache on server2 +connection server2; +set GLOBAL query_cache_type=on; +set GLOBAL query_cache_size=1355776; +reset query cache; +flush status; + + + +# Create test tables in NDB and load them into cache +# on server1 +connection server1; +create table t1 (a int) engine=ndbcluster; +create table t2 (a int) engine=ndbcluster; +insert into t1 value (2); +insert into t2 value (3); +select * from t1; +select * from t2; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + + +# Connect server2, load table in to cache, then update the table +connection server2; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +update t1 set a=3 where a=2; + +# Connect to server1 and check that cache is invalidated +# and correct data is returned +connection server1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +drop table t1, t2; + + diff --git a/mysql-test/t/ndb_cache_multi2.test b/mysql-test/t/ndb_cache_multi2.test new file mode 100644 index 00000000000..4abb537624a --- /dev/null +++ b/mysql-test/t/ndb_cache_multi2.test @@ -0,0 +1,95 @@ +-- source include/have_query_cache.inc +-- source include/have_ndb.inc +-- source include/have_multi_ndb.inc +-- source include/not_embedded.inc + +--disable_warnings +drop table if exists t1, t2; +--enable_warnings + + +# Turn on and reset query cache on server1 +connection server1; +echo == Connected to server1 ==; +set GLOBAL query_cache_type=on; +set GLOBAL query_cache_size=1355776; +set GLOBAL ndb_cache_check_time=1; +reset query cache; +flush status; + +# Turn on and reset query cache on server2 +connection server2; +echo == Connected to server2 ==; +set GLOBAL query_cache_type=on; +set GLOBAL query_cache_size=1355776; +set GLOBAL ndb_cache_check_time=1; +reset query cache; +flush status; + +# Create test tables in NDB and load them into cache +# on server1 +connection server1; +echo == Connected to server1 ==; +create table t1 (a int) engine=ndbcluster; +create table t2 (a int) engine=ndbcluster; +insert into t1 value (2); +insert into t2 value (3); +select * from t1; +# Run the check query once to load it into qc on server1 +select a != 3 from t1; +select * from t2; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + + +# Connect server2, load table in to cache, then update the table +connection server2; +echo == Connected to server2 ==; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +update t1 set a=3 where a=2; + +# Connect to server1 and check that cache is invalidated +# and correct data is returned +connection server1; +echo == Connected to server1 ==; + +# Loop and wait for max 10 seconds until query cache thread +# has invalidated the cache and the column a in t1 is equal to 3 +let $retries=20; +while (`select a != 3 from t1`) +{ + dec $retries; + if (!$retries) + { + The query_cache thread failed to invalidate query_cache in 10 seconds; + } + sleep 0.5; +} + +# Select from t1 one last time for the result file +# Column a should be 3 +select * from t1; + +# There should now be three queries in the cache +show status like "Qcache_queries_in_cache"; + +drop table t1, t2; + +# Turn off and reset query cache on server1 and server2 +connection server1; +set GLOBAL query_cache_size=0; +set GLOBAL ndb_cache_check_time=0; +reset query cache; +flush status; +connection server2; +set GLOBAL query_cache_size=0; +set GLOBAL ndb_cache_check_time=0; +reset query cache; +flush status; diff --git a/mysql-test/t/ndb_charset.test b/mysql-test/t/ndb_charset.test index a885427f593..5941e5750db 100644 --- a/mysql-test/t/ndb_charset.test +++ b/mysql-test/t/ndb_charset.test @@ -54,6 +54,25 @@ select * from t1 where a = 'AaA'; select * from t1 where a = 'AAA'; drop table t1; +# pk - varchar + +create table t1 ( + a varchar(20) character set latin1 collate latin1_swedish_ci primary key +) engine=ndb; +# +insert into t1 values ('A'),('b '),('C '),('d '),('E'),('f'); +-- error 1062 +insert into t1 values('b'); +-- error 1062 +insert into t1 values('a '); +# +select a,length(a) from t1 order by a; +select a,length(a) from t1 order by a desc; +select * from t1 where a = 'a'; +select * from t1 where a = 'a '; +select * from t1 where a = 'd'; +drop table t1; + # unique hash index - binary create table t1 ( @@ -103,6 +122,27 @@ select * from t1 where a = 'AaA'; select * from t1 where a = 'AAA'; drop table t1; +# unique hash index - varchar + +create table t1 ( + p int primary key, + a varchar(20) character set latin1 collate latin1_swedish_ci not null, + unique key(a) +) engine=ndb; +# +insert into t1 values (1,'A'),(2,'b '),(3,'C '),(4,'d '),(5,'E'),(6,'f'); +-- error 1062 +insert into t1 values(99,'b'); +-- error 1062 +insert into t1 values(99,'a '); +# +select a,length(a) from t1 order by a; +select a,length(a) from t1 order by a desc; +select * from t1 where a = 'a'; +select * from t1 where a = 'a '; +select * from t1 where a = 'd'; +drop table t1; + # ordered index - binary create table t1 ( @@ -159,6 +199,44 @@ select * from t1 where a = 'AaA' order by p; select * from t1 where a = 'AAA' order by p; drop table t1; +# ordered index - varchar + +create table t1 ( + p int primary key, + a varchar(20) character set latin1 collate latin1_swedish_ci not null, + index(a, p) +) engine=ndb; +# +insert into t1 values (1,'A'),(2,'b '),(3,'C '),(4,'d '),(5,'E'),(6,'f'); +insert into t1 values (7,'a'),(8,'B '),(9,'c '),(10,'D'),(11,'e'),(12,'F '); +select p,a,length(a) from t1 order by a, p; +select * from t1 where a = 'a ' order by a desc, p desc; +select * from t1 where a >= 'D' order by a, p; +select * from t1 where a < 'D' order by a, p; +# +select count(*) from t1 x, t1 y, t1 z where x.a = y.a and y.a = z.a; +drop table t1; + +# minimal multi-byte test +# removed by jonas as this requires a configure --with-extra-charsets +#create table t1 ( +# a char(5) character set ucs2, +# b varchar(7) character set utf8, +# primary key(a, b) +#) engine=ndb; +# +#insert into t1 values +# ('a','A '),('B ','b'),('c','C '),('D','d'),('e ','E'),('F','f '), +# ('A','b '),('b ','C'),('C','d '),('d','E'),('E ','f'), +# ('a','C '),('B ','d'),('c','E '),('D','f'); +#-- error 1062 +#insert into t1 values('d','f'); +# +#select a,b,length(a),length(b) from t1 order by a,b limit 3; +#select a,b,length(a),length(b) from t1 order by a desc, b desc limit 3; +#select a,b,length(a),length(b) from t1 where a='c' and b='c'; +#drop table t1; + # bug#14007 create table t1 ( a char(10) primary key @@ -173,3 +251,5 @@ select * from t1; replace into t1 set a = 'aaabb'; select * from t1; drop table t1; + +# End of 4.1 tests diff --git a/mysql-test/t/ndb_condition_pushdown.test b/mysql-test/t/ndb_condition_pushdown.test new file mode 100644 index 00000000000..748c26e2a9a --- /dev/null +++ b/mysql-test/t/ndb_condition_pushdown.test @@ -0,0 +1,1722 @@ +-- source include/have_ndb.inc +-- source include/not_embedded.inc + +--disable_warnings +DROP TABLE IF EXISTS t1,t2; +--enable_warnings + +# +# Test of condition pushdown to storage engine +# +CREATE TABLE t1 ( + auto int(5) unsigned NOT NULL auto_increment, + string char(10), + vstring varchar(10), + bin binary(2), + vbin varbinary(7), + tiny tinyint(4) DEFAULT '0' NOT NULL , + short smallint(6) DEFAULT '1' NOT NULL , + medium mediumint(8) DEFAULT '0' NOT NULL, + long_int int(11) DEFAULT '0' NOT NULL, + longlong bigint(13) DEFAULT '0' NOT NULL, + real_float float(13,1) DEFAULT 0.0 NOT NULL, + real_double double(16,4), + real_decimal decimal(16,4), + utiny tinyint(3) unsigned DEFAULT '0' NOT NULL, + ushort smallint(5) unsigned zerofill DEFAULT '00000' NOT NULL, + umedium mediumint(8) unsigned DEFAULT '0' NOT NULL, + ulong int(11) unsigned DEFAULT '0' NOT NULL, + ulonglong bigint(13) unsigned DEFAULT '0' NOT NULL, + bits bit(3), + options enum('zero','one','two','three','four') not null, + flags set('zero','one','two','three','four') not null, + date_field date, + year_field year, + time_field time, + date_time datetime, + time_stamp timestamp, + PRIMARY KEY (auto) +) engine=ndb; + +insert into t1 values +(NULL,"aaaa","aaaa",0xAAAA,0xAAAA,-1,-1,-1,-1,-1,1.1,1.1,1.1,1,1,1,1,1, + b'001','one','one', + '1901-01-01','1901', +'01:01:01','1901-01-01 01:01:01',NULL), +(NULL,"bbbb","bbbb",0xBBBB,0xBBBB,-2,-2,-2,-2,-2,2.2,2.2,2.2,2,2,2,2,2, + b'010','two','one,two', + '1902-02-02','1902', +'02:02:02','1902-02-02 02:02:02',NULL), +(NULL,"cccc","cccc",0xCCCC,0xCCCC,-3,-3,-3,-3,-3,3.3,3.3,3.3,3,3,3,3,3, + b'011','three','one,two,three', + '1903-03-03','1903', +'03:03:03','1903-03-03 03:03:03',NULL), +(NULL,"dddd","dddd",0xDDDD,0xDDDD,-4,-4,-4,-4,-4,4.4,4.4,4.4,4,4,4,4,4, + b'100','four','one,two,three,four', + '1904-04-04','1904', +'04:04:04','1904-04-04 04:04:04',NULL); + +CREATE TABLE t2 (pk1 int unsigned NOT NULL PRIMARY KEY, attr1 int unsigned NOT NULL, attr2 int unsigned, attr3 VARCHAR(10) ) ENGINE=ndbcluster; + +insert into t2 values (0,0,0, "a"),(1,1,1,"b"),(2,2,NULL,NULL),(3,3,3,"d"),(4,4,4,"e"),(5,5,5,"f"); + +CREATE TABLE t3 (pk1 int unsigned NOT NULL PRIMARY KEY, attr1 int unsigned NOT NULL, attr2 bigint unsigned, attr3 tinyint unsigned, attr4 VARCHAR(10) ) ENGINE=ndbcluster; + +insert into t3 values (0,0,0,0,"a"),(1,1,9223372036854775803,1,"b"),(2,2,9223372036854775804,2,"c"),(3,3,9223372036854775805,3,"d"),(4,4,9223372036854775806,4,"e"),(5,5,9223372036854775807,5,"f"); + +CREATE TABLE t4 (pk1 int unsigned NOT NULL PRIMARY KEY, attr1 int unsigned NOT NULL, attr2 bigint unsigned, attr3 tinyint unsigned, attr4 VARCHAR(10) , KEY (attr1)) ENGINE=ndbcluster; + +insert into t4 values (0,0,0,0,"a"),(1,1,9223372036854775803,1,"b"),(2,2,9223372036854775804,2,"c"),(3,3,9223372036854775805,3,"d"),(4,4,9223372036854775806,4,"e"),(5,5,9223372036854775807,5,"f"); + +set @old_ecpd = @@session.engine_condition_pushdown; +set engine_condition_pushdown = off; + +# Test all types and compare operators +select auto from t1 where +string = "aaaa" and +vstring = "aaaa" and +bin = 0xAAAA and +vbin = 0xAAAA and +tiny = -1 and +short = -1 and +medium = -1 and +long_int = -1 and +longlong = -1 and +real_float > 1.0 and real_float < 2.0 and +real_double > 1.0 and real_double < 2.0 and +real_decimal > 1.0 and real_decimal < 2.0 and +utiny = 1 and +ushort = 1 and +umedium = 1 and +ulong = 1 and +ulonglong = 1 and +bits = b'001' and +options = 'one' and +flags = 'one' and +date_field = '1901-01-01' and +year_field = '1901' and +time_field = '01:01:01' and +date_time = '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string != "aaaa" and +vstring != "aaaa" and +bin != 0xAAAA and +vbin != 0xAAAA and +tiny != -1 and +short != -1 and +medium != -1 and +long_int != -1 and +longlong != -1 and +(real_float < 1.0 or real_float > 2.0) and +(real_double < 1.0 or real_double > 2.0) and +(real_decimal < 1.0 or real_decimal > 2.0) and +utiny != 1 and +ushort != 1 and +umedium != 1 and +ulong != 1 and +ulonglong != 1 and +bits != b'001' and +options != 'one' and +flags != 'one' and +date_field != '1901-01-01' and +year_field != '1901' and +time_field != '01:01:01' and +date_time != '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string > "aaaa" and +vstring > "aaaa" and +bin > 0xAAAA and +vbin > 0xAAAA and +tiny < -1 and +short < -1 and +medium < -1 and +long_int < -1 and +longlong < -1 and +real_float > 1.1 and +real_double > 1.1 and +real_decimal > 1.1 and +utiny > 1 and +ushort > 1 and +umedium > 1 and +ulong > 1 and +ulonglong > 1 and +bits > b'001' and +(options = 'two' or options = 'three' or options = 'four') and +(flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field > '1901-01-01' and +year_field > '1901' and +time_field > '01:01:01' and +date_time > '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string >= "aaaa" and +vstring >= "aaaa" and +bin >= 0xAAAA and +vbin >= 0xAAAA and +tiny <= -1 and +short <= -1 and +medium <= -1 and +long_int <= -1 and +longlong <= -1 and +real_float >= 1.0 and +real_double >= 1.0 and +real_decimal >= 1.0 and +utiny >= 1 and +ushort >= 1 and +umedium >= 1 and +ulong >= 1 and +ulonglong >= 1 and +bits >= b'001' and +(options = 'one' or options = 'two' or options = 'three' or options = 'four') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field >= '1901-01-01' and +year_field >= '1901' and +time_field >= '01:01:01' and +date_time >= '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string < "dddd" and +vstring < "dddd" and +bin < 0xDDDD and +vbin < 0xDDDD and +tiny > -4 and +short > -4 and +medium > -4 and +long_int > -4 and +longlong > -4 and +real_float < 4.4 and +real_double < 4.4 and +real_decimal < 4.4 and +utiny < 4 and +ushort < 4 and +umedium < 4 and +ulong < 4 and +ulonglong < 4 and +bits < b'100' and +(options = 'one' or options = 'two' or options = 'three') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three') and +date_field < '1904-01-01' and +year_field < '1904' and +time_field < '04:04:04' and +date_time < '1904-04-04 04:04:04' +order by auto; + +select auto from t1 where +string <= "dddd" and +vstring <= "dddd" and +bin <= 0xDDDD and +vbin <= 0xDDDD and +tiny >= -4 and +short >= -4 and +medium >= -4 and +long_int >= -4 and +longlong >= -4 and +real_float <= 4.5 and +real_double <= 4.5 and +real_decimal <= 4.5 and +utiny <= 4 and +ushort <= 4 and +umedium <= 4 and +ulong <= 4 and +ulonglong <= 4 and +bits <= b'100' and +(options = 'one' or options = 'two' or options = 'three' or options = 'four') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field <= '1904-04-04' and +year_field <= '1904' and +time_field <= '04:04:04' and +date_time <= '1904-04-04 04:04:04' +order by auto; + +# Test LIKE/NOT LIKE +select auto from t1 where +string like "b%" and +vstring like "b%" and +bin like concat(0xBB, '%') and +vbin like concat(0xBB, '%') +order by auto; + +select auto from t1 where +string not like "b%" and +vstring not like "b%" and +bin not like concat(0xBB, '%') and +vbin not like concat(0xBB, '%') +order by auto; + +# BETWEEN +select auto from t1 where +(string between "aaaa" and "cccc") and +(vstring between "aaaa" and "cccc") and +(bin between 0xAAAA and 0xCCCC) and +(vbin between 0xAAAA and 0xCCCC) and +(tiny between -3 and -1) and +(short between -3 and -1) and +(medium between -3 and -1) and +(long_int between -3 and -1) and +(longlong between -3 and -1) and +(utiny between 1 and 3) and +(ushort between 1 and 3) and +(umedium between 1 and 3) and +(ulong between 1 and 3) and +(ulonglong between 1 and 3) and +(bits between b'001' and b'011') and +(options between 'one' and 'three') and +(flags between 'one' and 'one,two,three') and +(date_field between '1901-01-01' and '1903-03-03') and +(year_field between '1901' and '1903') and +(time_field between '01:01:01' and '03:03:03') and +(date_time between '1901-01-01 01:01:01' and '1903-03-03 03:03:03') +order by auto; + +select auto from t1 where +("aaaa" between string and string) and +("aaaa" between vstring and vstring) and +(0xAAAA between bin and bin) and +(0xAAAA between vbin and vbin) and +(-1 between tiny and tiny) and +(-1 between short and short) and +(-1 between medium and medium) and +(-1 between long_int and long_int) and +(-1 between longlong and longlong) and +(1 between utiny and utiny) and +(1 between ushort and ushort) and +(1 between umedium and umedium) and +(1 between ulong and ulong) and +(1 between ulonglong and ulonglong) and +(b'001' between bits and bits) and +('one' between options and options) and +('one' between flags and flags) and +('1901-01-01' between date_field and date_field) and +('1901' between year_field and year_field) and +('01:01:01' between time_field and time_field) and +('1901-01-01 01:01:01' between date_time and date_time) +order by auto; + +# NOT BETWEEN +select auto from t1 where +(string not between "aaaa" and "cccc") and +(vstring not between "aaaa" and "cccc") and +(bin not between 0xAAAA and 0xCCCC) and +(vbin not between 0xAAAA and 0xCCCC) and +(tiny not between -3 and -1) and +(short not between -3 and -1) and +(medium not between -3 and -1) and +(long_int not between -3 and -1) and +(longlong not between -3 and -1) and +(utiny not between 1 and 3) and +(ushort not between 1 and 3) and +(umedium not between 1 and 3) and +(ulong not between 1 and 3) and +(ulonglong not between 1 and 3) and +(bits not between b'001' and b'011') and +(options not between 'one' and 'three') and +(flags not between 'one' and 'one,two,three') and +(date_field not between '1901-01-01' and '1903-03-03') and +(year_field not between '1901' and '1903') and +(time_field not between '01:01:01' and '03:03:03') and +(date_time not between '1901-01-01 01:01:01' and '1903-03-03 03:03:03') +order by auto; + +select auto from t1 where +("aaaa" not between string and string) and +("aaaa" not between vstring and vstring) and +(0xAAAA not between bin and bin) and +(0xAAAA not between vbin and vbin) and +(-1 not between tiny and tiny) and +(-1 not between short and short) and +(-1 not between medium and medium) and +(-1 not between long_int and long_int) and +(-1 not between longlong and longlong) and +(1 not between utiny and utiny) and +(1 not between ushort and ushort) and +(1 not between umedium and umedium) and +(1 not between ulong and ulong) and +(1 not between ulonglong and ulonglong) and +(b'001' not between bits and bits) and +('one' not between options and options) and +('one' not between flags and flags) and +('1901-01-01' not between date_field and date_field) and +('1901' not between year_field and year_field) and +('01:01:01' not between time_field and time_field) and +('1901-01-01 01:01:01' not between date_time and date_time) +order by auto; + +# IN +select auto from t1 where +string in("aaaa","cccc") and +vstring in("aaaa","cccc") and +bin in(0xAAAA,0xCCCC) and +vbin in(0xAAAA,0xCCCC) and +tiny in(-1,-3) and +short in(-1,-3) and +medium in(-1,-3) and +long_int in(-1,-3) and +longlong in(-1,-3) and +utiny in(1,3) and +ushort in(1,3) and +umedium in(1,3) and +ulong in(1,3) and +ulonglong in(1,3) and +bits in(b'001',b'011') and +options in('one','three') and +flags in('one','one,two,three') and +date_field in('1901-01-01','1903-03-03') and +year_field in('1901','1903') and +time_field in('01:01:01','03:03:03') and +date_time in('1901-01-01 01:01:01','1903-03-03 03:03:03') +order by auto; + +select auto from t1 where +"aaaa" in(string) and +"aaaa" in(vstring) and +0xAAAA in(bin) and +0xAAAA in(vbin) and +(-1 in(tiny)) and +(-1 in(short)) and +(-1 in(medium)) and +(-1 in(long_int)) and +(-1 in(longlong)) and +1 in(utiny) and +1 in(ushort) and +1 in(umedium) and +1 in(ulong) and +1 in(ulonglong) and +b'001' in(bits) and +'one' in(options) and +'one' in(flags) and +'1901-01-01' in(date_field) and +'1901' in(year_field) and +'01:01:01' in(time_field) and +'1901-01-01 01:01:01' in(date_time) +order by auto; + +# NOT IN +select auto from t1 where +string not in("aaaa","cccc") and +vstring not in("aaaa","cccc") and +bin not in(0xAAAA,0xCCCC) and +vbin not in(0xAAAA,0xCCCC) and +tiny not in(-1,-3) and +short not in(-1,-3) and +medium not in(-1,-3) and +long_int not in(-1,-3) and +longlong not in(-1,-3) and +utiny not in(1,3) and +ushort not in(1,3) and +umedium not in(1,3) and +ulong not in(1,3) and +ulonglong not in(1,3) and +bits not in(b'001',b'011') and +options not in('one','three') and +flags not in('one','one,two,three') and +date_field not in('1901-01-01','1903-03-03') and +year_field not in('1901','1903') and +time_field not in('01:01:01','03:03:03') and +date_time not in('1901-01-01 01:01:01','1903-03-03 03:03:03') +order by auto; + +select auto from t1 where +"aaaa" not in(string) and +"aaaa" not in(vstring) and +0xAAAA not in(bin) and +0xAAAA not in(vbin) and +(-1 not in(tiny)) and +(-1 not in(short)) and +(-1 not in(medium)) and +(-1 not in(long_int)) and +(-1 not in(longlong)) and +1 not in(utiny) and +1 not in(ushort) and +1 not in(umedium) and +1 not in(ulong) and +1 not in(ulonglong) and +b'001' not in(bits) and +'one' not in(options) and +'one' not in(flags) and +'1901-01-01' not in(date_field) and +'1901' not in(year_field) and +'01:01:01' not in(time_field) and +'1901-01-01 01:01:01' not in(date_time) +order by auto; + +# Various tests +select * from t2 where attr3 is null or attr1 > 2 and pk1= 3 order by pk1; +select * from t2 where attr3 is not null and attr1 > 2 order by pk1; +select * from t3 where attr2 > 9223372036854775803 and attr3 != 3 order by pk1; +select * from t2,t3 where t2.attr1 < 1 and t2.attr2 = t3.attr2 and t3.attr1 < 5 order by t2.pk1; +select * from t4 where attr1 < 5 and attr2 > 9223372036854775803 and attr3 != 3 order by t4.pk1; +select * from t3,t4 where t4.attr1 > 1 and t4.attr2 = t3.attr2 and t4.attr3 < 5 order by t4.pk1; + +set engine_condition_pushdown = on; + +# Test all types and compare operators +explain +select auto from t1 where +string = "aaaa" and +vstring = "aaaa" and +bin = 0xAAAA and +vbin = 0xAAAA and +tiny = -1 and +short = -1 and +medium = -1 and +long_int = -1 and +longlong = -1 and +real_float > 1.0 and real_float < 2.0 and +real_double > 1.0 and real_double < 2.0 and +real_decimal > 1.0 and real_decimal < 2.0 and +utiny = 1 and +ushort = 1 and +umedium = 1 and +ulong = 1 and +ulonglong = 1 and +/* bits = b'001' and */ +options = 'one' and +flags = 'one' and +date_field = '1901-01-01' and +year_field = '1901' and +time_field = '01:01:01' and +date_time = '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string = "aaaa" and +vstring = "aaaa" and +bin = 0xAAAA and +vbin = 0xAAAA and +tiny = -1 and +short = -1 and +medium = -1 and +long_int = -1 and +longlong = -1 and +real_float > 1.0 and real_float < 2.0 and +real_double > 1.0 and real_double < 2.0 and +real_decimal > 1.0 and real_decimal < 2.0 and +utiny = 1 and +ushort = 1 and +umedium = 1 and +ulong = 1 and +ulonglong = 1 and +/* bits = b'001' and */ +options = 'one' and +flags = 'one' and +date_field = '1901-01-01' and +year_field = '1901' and +time_field = '01:01:01' and +date_time = '1901-01-01 01:01:01' +order by auto; + +explain +select auto from t1 where +string != "aaaa" and +vstring != "aaaa" and +bin != 0xAAAA and +vbin != 0xAAAA and +tiny != -1 and +short != -1 and +medium != -1 and +long_int != -1 and +longlong != -1 and +(real_float < 1.0 or real_float > 2.0) and +(real_double < 1.0 or real_double > 2.0) and +(real_decimal < 1.0 or real_decimal > 2.0) and +utiny != 1 and +ushort != 1 and +umedium != 1 and +ulong != 1 and +ulonglong != 1 and +/* bits != b'001' and */ +options != 'one' and +flags != 'one' and +date_field != '1901-01-01' and +year_field != '1901' and +time_field != '01:01:01' and +date_time != '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string != "aaaa" and +vstring != "aaaa" and +bin != 0xAAAA and +vbin != 0xAAAA and +tiny != -1 and +short != -1 and +medium != -1 and +long_int != -1 and +longlong != -1 and +(real_float < 1.0 or real_float > 2.0) and +(real_double < 1.0 or real_double > 2.0) and +(real_decimal < 1.0 or real_decimal > 2.0) and +utiny != 1 and +ushort != 1 and +umedium != 1 and +ulong != 1 and +ulonglong != 1 and +/* bits != b'001' and */ +options != 'one' and +flags != 'one' and +date_field != '1901-01-01' and +year_field != '1901' and +time_field != '01:01:01' and +date_time != '1901-01-01 01:01:01' +order by auto; + +explain +select auto from t1 where +string > "aaaa" and +vstring > "aaaa" and +bin > 0xAAAA and +vbin > 0xAAAA and +tiny < -1 and +short < -1 and +medium < -1 and +long_int < -1 and +longlong < -1 and +real_float > 1.1 and +real_double > 1.1 and +real_decimal > 1.1 and +utiny > 1 and +ushort > 1 and +umedium > 1 and +ulong > 1 and +ulonglong > 1 and +/* bits > b'001' and */ +(options = 'two' or options = 'three' or options = 'four') and +(flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field > '1901-01-01' and +year_field > '1901' and +time_field > '01:01:01' and +date_time > '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string > "aaaa" and +vstring > "aaaa" and +bin > 0xAAAA and +vbin > 0xAAAA and +tiny < -1 and +short < -1 and +medium < -1 and +long_int < -1 and +longlong < -1 and +real_float > 1.1 and +real_double > 1.1 and +real_decimal > 1.1 and +utiny > 1 and +ushort > 1 and +umedium > 1 and +ulong > 1 and +ulonglong > 1 and +/* bits > b'001' and */ +(options = 'two' or options = 'three' or options = 'four') and +(flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field > '1901-01-01' and +year_field > '1901' and +time_field > '01:01:01' and +date_time > '1901-01-01 01:01:01' +order by auto; + +explain +select auto from t1 where +string >= "aaaa" and +vstring >= "aaaa" and +bin >= 0xAAAA and +vbin >= 0xAAAA and +tiny <= -1 and +short <= -1 and +medium <= -1 and +long_int <= -1 and +longlong <= -1 and +real_float >= 1.0 and +real_double >= 1.0 and +real_decimal >= 1.0 and +utiny >= 1 and +ushort >= 1 and +umedium >= 1 and +ulong >= 1 and +ulonglong >= 1 and +/* bits >= b'001' and */ +(options = 'one' or options = 'two' or options = 'three' or options = 'four') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field >= '1901-01-01' and +year_field >= '1901' and +time_field >= '01:01:01' and +date_time >= '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string >= "aaaa" and +vstring >= "aaaa" and +bin >= 0xAAAA and +vbin >= 0xAAAA and +tiny <= -1 and +short <= -1 and +medium <= -1 and +long_int <= -1 and +longlong <= -1 and +real_float >= 1.0 and +real_double >= 1.0 and +real_decimal >= 1.0 and +utiny >= 1 and +ushort >= 1 and +umedium >= 1 and +ulong >= 1 and +ulonglong >= 1 and +/* bits >= b'001' and */ +(options = 'one' or options = 'two' or options = 'three' or options = 'four') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field >= '1901-01-01' and +year_field >= '1901' and +time_field >= '01:01:01' and +date_time >= '1901-01-01 01:01:01' +order by auto; + +explain +select auto from t1 where +string < "dddd" and +vstring < "dddd" and +bin < 0xDDDD and +vbin < 0xDDDD and +tiny > -4 and +short > -4 and +medium > -4 and +long_int > -4 and +longlong > -4 and +real_float < 4.4 and +real_double < 4.4 and +real_decimal < 4.4 and +utiny < 4 and +ushort < 4 and +umedium < 4 and +ulong < 4 and +ulonglong < 4 and +/* bits < b'100' and */ +(options = 'one' or options = 'two' or options = 'three') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three') and +date_field < '1904-01-01' and +year_field < '1904' and +time_field < '04:04:04' and +date_time < '1904-04-04 04:04:04' +order by auto; + +select auto from t1 where +string < "dddd" and +vstring < "dddd" and +bin < 0xDDDD and +vbin < 0xDDDD and +tiny > -4 and +short > -4 and +medium > -4 and +long_int > -4 and +longlong > -4 and +real_float < 4.4 and +real_double < 4.4 and +real_decimal < 4.4 and +utiny < 4 and +ushort < 4 and +umedium < 4 and +ulong < 4 and +ulonglong < 4 and +/* bits < b'100' and */ +(options = 'one' or options = 'two' or options = 'three') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three') and +date_field < '1904-01-01' and +year_field < '1904' and +time_field < '04:04:04' and +date_time < '1904-04-04 04:04:04' +order by auto; + +explain +select auto from t1 where +string <= "dddd" and +vstring <= "dddd" and +bin <= 0xDDDD and +vbin <= 0xDDDD and +tiny >= -4 and +short >= -4 and +medium >= -4 and +long_int >= -4 and +longlong >= -4 and +real_float <= 4.5 and +real_double <= 4.5 and +real_decimal <= 4.5 and +utiny <= 4 - 1 + 1 and /* Checking function composition */ +ushort <= 4 and +umedium <= 4 and +ulong <= 4 and +ulonglong <= 4 and +/* bits <= b'100' and */ +(options = 'one' or options = 'two' or options = 'three' or options = 'four') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field <= '1904-04-04' and +year_field <= '1904' and +time_field <= '04:04:04' and +date_time <= '1904-04-04 04:04:04' +order by auto; + +select auto from t1 where +string <= "dddd" and +vstring <= "dddd" and +bin <= 0xDDDD and +vbin <= 0xDDDD and +tiny >= -4 and +short >= -4 and +medium >= -4 and +long_int >= -4 and +longlong >= -4 and +real_float <= 4.5 and +real_double <= 4.5 and +real_decimal <= 4.5 and +utiny <= 4 - 1 + 1 and /* Checking function composition */ +ushort <= 4 and +umedium <= 4 and +ulong <= 4 and +ulonglong <= 4 and +/* bits <= b'100' and */ +(options = 'one' or options = 'two' or options = 'three' or options = 'four') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field <= '1904-04-04' and +year_field <= '1904' and +time_field <= '04:04:04' and +date_time <= '1904-04-04 04:04:04' +order by auto; + +# Test index scan with filter +create index medium_index on t1(medium); + +# Test all types and compare operators +explain +select auto from t1 where +string = "aaaa" and +vstring = "aaaa" and +bin = 0xAAAA and +vbin = 0xAAAA and +tiny = -1 and +short = -1 and +medium = -1 and +long_int = -1 and +longlong = -1 and +real_float > 1.0 and real_float < 2.0 and +real_double > 1.0 and real_double < 2.0 and +real_decimal > 1.0 and real_decimal < 2.0 and +utiny = 1 and +ushort = 1 and +umedium = 1 and +ulong = 1 and +ulonglong = 1 and +/* bits = b'001' and */ +options = 'one' and +flags = 'one' and +date_field = '1901-01-01' and +year_field = '1901' and +time_field = '01:01:01' and +date_time = '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string = "aaaa" and +vstring = "aaaa" and +bin = 0xAAAA and +vbin = 0xAAAA and +tiny = -1 and +short = -1 and +medium = -1 and +long_int = -1 and +longlong = -1 and +real_float > 1.0 and real_float < 2.0 and +real_double > 1.0 and real_double < 2.0 and +real_decimal > 1.0 and real_decimal < 2.0 and +utiny = 1 and +ushort = 1 and +umedium = 1 and +ulong = 1 and +ulonglong = 1 and +/* bits = b'001' and */ +options = 'one' and +flags = 'one' and +date_field = '1901-01-01' and +year_field = '1901' and +time_field = '01:01:01' and +date_time = '1901-01-01 01:01:01' +order by auto; + +explain +select auto from t1 where +string != "aaaa" and +vstring != "aaaa" and +bin != 0xAAAA and +vbin != 0xAAAA and +tiny != -1 and +short != -1 and +medium != -1 and +long_int != -1 and +longlong != -1 and +(real_float < 1.0 or real_float > 2.0) and +(real_double < 1.0 or real_double > 2.0) and +(real_decimal < 1.0 or real_decimal > 2.0) and +utiny != 1 and +ushort != 1 and +umedium != 1 and +ulong != 1 and +ulonglong != 1 and +/* bits != b'001' and */ +options != 'one' and +flags != 'one' and +date_field != '1901-01-01' and +year_field != '1901' and +time_field != '01:01:01' and +date_time != '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string != "aaaa" and +vstring != "aaaa" and +bin != 0xAAAA and +vbin != 0xAAAA and +tiny != -1 and +short != -1 and +medium != -1 and +long_int != -1 and +longlong != -1 and +(real_float < 1.0 or real_float > 2.0) and +(real_double < 1.0 or real_double > 2.0) and +(real_decimal < 1.0 or real_decimal > 2.0) and +utiny != 1 and +ushort != 1 and +umedium != 1 and +ulong != 1 and +ulonglong != 1 and +/* bits != b'001' and */ +options != 'one' and +flags != 'one' and +date_field != '1901-01-01' and +year_field != '1901' and +time_field != '01:01:01' and +date_time != '1901-01-01 01:01:01' +order by auto; + +explain +select auto from t1 where +string > "aaaa" and +vstring > "aaaa" and +bin > 0xAAAA and +vbin > 0xAAAA and +tiny < -1 and +short < -1 and +medium < -1 and +long_int < -1 and +longlong < -1 and +real_float > 1.1 and +real_double > 1.1 and +real_decimal > 1.1 and +utiny > 1 and +ushort > 1 and +umedium > 1 and +ulong > 1 and +ulonglong > 1 and +/* bits > b'001' and */ +(options = 'two' or options = 'three' or options = 'four') and +(flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field > '1901-01-01' and +year_field > '1901' and +time_field > '01:01:01' and +date_time > '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string > "aaaa" and +vstring > "aaaa" and +bin > 0xAAAA and +vbin > 0xAAAA and +tiny < -1 and +short < -1 and +medium < -1 and +long_int < -1 and +longlong < -1 and +real_float > 1.1 and +real_double > 1.1 and +real_decimal > 1.1 and +utiny > 1 and +ushort > 1 and +umedium > 1 and +ulong > 1 and +ulonglong > 1 and +/* bits > b'001' and */ +(options = 'two' or options = 'three' or options = 'four') and +(flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field > '1901-01-01' and +year_field > '1901' and +time_field > '01:01:01' and +date_time > '1901-01-01 01:01:01' +order by auto; + +explain +select auto from t1 where +string >= "aaaa" and +vstring >= "aaaa" and +bin >= 0xAAAA and +vbin >= 0xAAAA and +tiny <= -1 and +short <= -1 and +medium <= -1 and +long_int <= -1 and +longlong <= -1 and +real_float >= 1.0 and +real_double >= 1.0 and +real_decimal >= 1.0 and +utiny >= 1 and +ushort >= 1 and +umedium >= 1 and +ulong >= 1 and +ulonglong >= 1 and +/* bits >= b'001' and */ +(options = 'one' or options = 'two' or options = 'three' or options = 'four') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field >= '1901-01-01' and +year_field >= '1901' and +time_field >= '01:01:01' and +date_time >= '1901-01-01 01:01:01' +order by auto; + +select auto from t1 where +string >= "aaaa" and +vstring >= "aaaa" and +bin >= 0xAAAA and +vbin >= 0xAAAA and +tiny <= -1 and +short <= -1 and +medium <= -1 and +long_int <= -1 and +longlong <= -1 and +real_float >= 1.0 and +real_double >= 1.0 and +real_decimal >= 1.0 and +utiny >= 1 and +ushort >= 1 and +umedium >= 1 and +ulong >= 1 and +ulonglong >= 1 and +/* bits >= b'001' and */ +(options = 'one' or options = 'two' or options = 'three' or options = 'four') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field >= '1901-01-01' and +year_field >= '1901' and +time_field >= '01:01:01' and +date_time >= '1901-01-01 01:01:01' +order by auto; + +explain +select auto from t1 where +string < "dddd" and +vstring < "dddd" and +bin < 0xDDDD and +vbin < 0xDDDD and +tiny > -4 and +short > -4 and +medium > -4 and +long_int > -4 and +longlong > -4 and +real_float < 4.4 and +real_double < 4.4 and +real_decimal < 4.4 and +utiny < 4 and +ushort < 4 and +umedium < 4 and +ulong < 4 and +ulonglong < 4 and +/* bits < b'100' and */ +(options = 'one' or options = 'two' or options = 'three') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three') and +date_field < '1904-01-01' and +year_field < '1904' and +time_field < '04:04:04' and +date_time < '1904-04-04 04:04:04' +order by auto; + +select auto from t1 where +string < "dddd" and +vstring < "dddd" and +bin < 0xDDDD and +vbin < 0xDDDD and +tiny > -4 and +short > -4 and +medium > -4 and +long_int > -4 and +longlong > -4 and +real_float < 4.4 and +real_double < 4.4 and +real_decimal < 4.4 and +utiny < 4 and +ushort < 4 and +umedium < 4 and +ulong < 4 and +ulonglong < 4 and +/* bits < b'100' and */ +(options = 'one' or options = 'two' or options = 'three') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three') and +date_field < '1904-01-01' and +year_field < '1904' and +time_field < '04:04:04' and +date_time < '1904-04-04 04:04:04' +order by auto; + +explain +select auto from t1 where +string <= "dddd" and +vstring <= "dddd" and +bin <= 0xDDDD and +vbin <= 0xDDDD and +tiny >= -4 and +short >= -4 and +medium >= -4 and +long_int >= -4 and +longlong >= -4 and +real_float <= 4.5 and +real_double <= 4.5 and +real_decimal <= 4.5 and +utiny <= 4 - 1 + 1 and /* Checking function composition */ +ushort <= 4 and +umedium <= 4 and +ulong <= 4 and +ulonglong <= 4 and +/* bits <= b'100' and */ +(options = 'one' or options = 'two' or options = 'three' or options = 'four') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field <= '1904-04-04' and +year_field <= '1904' and +time_field <= '04:04:04' and +date_time <= '1904-04-04 04:04:04' +order by auto; + +select auto from t1 where +string <= "dddd" and +vstring <= "dddd" and +bin <= 0xDDDD and +vbin <= 0xDDDD and +tiny >= -4 and +short >= -4 and +medium >= -4 and +long_int >= -4 and +longlong >= -4 and +real_float <= 4.5 and +real_double <= 4.5 and +real_decimal <= 4.5 and +utiny <= 4 - 1 + 1 and /* Checking function composition */ +ushort <= 4 and +umedium <= 4 and +ulong <= 4 and +ulonglong <= 4 and +/* bits <= b'100' and */ +(options = 'one' or options = 'two' or options = 'three' or options = 'four') and +(flags = 'one' or flags = 'one,two' or flags = 'one,two,three' or flags = 'one,two,three,four') and +date_field <= '1904-04-04' and +year_field <= '1904' and +time_field <= '04:04:04' and +date_time <= '1904-04-04 04:04:04' +order by auto; + +# Test LIKE/NOT LIKE +explain +select auto from t1 where +string like "b%" and +vstring like "b%" and +bin like concat(0xBB, '%') and +vbin like concat(0xBB, '%') +order by auto; + +select auto from t1 where +string like "b%" and +vstring like "b%" and +bin like concat(0xBB, '%') and +vbin like concat(0xBB, '%') +order by auto; + +explain +select auto from t1 where +string not like "b%" and +vstring not like "b%" and +bin not like concat(0xBB, '%') and +vbin not like concat(0xBB, '%') +order by auto; + +select auto from t1 where +string not like "b%" and +vstring not like "b%" and +bin not like concat(0xBB, '%') and +vbin not like concat(0xBB, '%') +order by auto; + +# BETWEEN +explain +select auto from t1 where +(string between "aaaa" and "cccc") and +(vstring between "aaaa" and "cccc") and +(bin between 0xAAAA and 0xCCCC) and +(vbin between 0xAAAA and 0xCCCC) and +(tiny between -3 and -1) and +(short between -3 and -1) and +(medium between -3 and -1) and +(long_int between -3 and -1) and +(longlong between -3 and -1) and +(utiny between 1 and 3) and +(ushort between 1 and 3) and +(umedium between 1 and 3) and +(ulong between 1 and 3) and +(ulonglong between 1 and 3) and +/* (bits between b'001' and b'011') and */ +(options between 'one' and 'three') and +(flags between 'one' and 'one,two,three') and +(date_field between '1901-01-01' and '1903-03-03') and +(year_field between '1901' and '1903') and +(time_field between '01:01:01' and '03:03:03') and +(date_time between '1901-01-01 01:01:01' and '1903-03-03 03:03:03') +order by auto; + +select auto from t1 where +(string between "aaaa" and "cccc") and +(vstring between "aaaa" and "cccc") and +(bin between 0xAAAA and 0xCCCC) and +(vbin between 0xAAAA and 0xCCCC) and +(tiny between -3 and -1) and +(short between -3 and -1) and +(medium between -3 and -1) and +(long_int between -3 and -1) and +(longlong between -3 and -1) and +(utiny between 1 and 3) and +(ushort between 1 and 3) and +(umedium between 1 and 3) and +(ulong between 1 and 3) and +(ulonglong between 1 and 3) and +/* (bits between b'001' and b'011') and */ +(options between 'one' and 'three') and +(flags between 'one' and 'one,two,three') and +(date_field between '1901-01-01' and '1903-03-03') and +(year_field between '1901' and '1903') and +(time_field between '01:01:01' and '03:03:03') and +(date_time between '1901-01-01 01:01:01' and '1903-03-03 03:03:03') +order by auto; + +explain +select auto from t1 where +("aaaa" between string and string) and +("aaaa" between vstring and vstring) and +(0xAAAA between bin and bin) and +(0xAAAA between vbin and vbin) and +(-1 between tiny and tiny) and +(-1 between short and short) and +(-1 between medium and medium) and +(-1 between long_int and long_int) and +(-1 between longlong and longlong) and +(1 between utiny and utiny) and +(1 between ushort and ushort) and +(1 between umedium and umedium) and +(1 between ulong and ulong) and +(1 between ulonglong and ulonglong) and +/* (b'001' between bits and bits) and */ +('one' between options and options) and +('one' between flags and flags) and +('1901-01-01' between date_field and date_field) and +('1901' between year_field and year_field) and +('01:01:01' between time_field and time_field) and +('1901-01-01 01:01:01' between date_time and date_time) +order by auto; + +select auto from t1 where +("aaaa" between string and string) and +("aaaa" between vstring and vstring) and +(0xAAAA between bin and bin) and +(0xAAAA between vbin and vbin) and +(-1 between tiny and tiny) and +(-1 between short and short) and +(-1 between medium and medium) and +(-1 between long_int and long_int) and +(-1 between longlong and longlong) and +(1 between utiny and utiny) and +(1 between ushort and ushort) and +(1 between umedium and umedium) and +(1 between ulong and ulong) and +(1 between ulonglong and ulonglong) and +/* (b'001' between bits and bits) and */ +('one' between options and options) and +('one' between flags and flags) and +('1901-01-01' between date_field and date_field) and +('1901' between year_field and year_field) and +('01:01:01' between time_field and time_field) and +('1901-01-01 01:01:01' between date_time and date_time) +order by auto; + +# NOT BETWEEN +explain +select auto from t1 where +(string not between "aaaa" and "cccc") and +(vstring not between "aaaa" and "cccc") and +(bin not between 0xAAAA and 0xCCCC) and +(vbin not between 0xAAAA and 0xCCCC) and +(tiny not between -3 and -1) and +(short not between -3 and -1) and +(medium not between -3 and -1) and +(long_int not between -3 and -1) and +(longlong not between -3 and -1) and +(utiny not between 1 and 3) and +(ushort not between 1 and 3) and +(umedium not between 1 and 3) and +(ulong not between 1 and 3) and +(ulonglong not between 1 and 3) and +/* (bits not between b'001' and b'011') and */ +(options not between 'one' and 'three') and +(flags not between 'one' and 'one,two,three') and +(date_field not between '1901-01-01' and '1903-03-03') and +(year_field not between '1901' and '1903') and +(time_field not between '01:01:01' and '03:03:03') and +(date_time not between '1901-01-01 01:01:01' and '1903-03-03 03:03:03') +order by auto; + +select auto from t1 where +(string not between "aaaa" and "cccc") and +(vstring not between "aaaa" and "cccc") and +(bin not between 0xAAAA and 0xCCCC) and +(vbin not between 0xAAAA and 0xCCCC) and +(tiny not between -3 and -1) and +(short not between -3 and -1) and +(medium not between -3 and -1) and +(long_int not between -3 and -1) and +(longlong not between -3 and -1) and +(utiny not between 1 and 3) and +(ushort not between 1 and 3) and +(umedium not between 1 and 3) and +(ulong not between 1 and 3) and +(ulonglong not between 1 and 3) and +/* (bits not between b'001' and b'011') and */ +(options not between 'one' and 'three') and +(flags not between 'one' and 'one,two,three') and +(date_field not between '1901-01-01' and '1903-03-03') and +(year_field not between '1901' and '1903') and +(time_field not between '01:01:01' and '03:03:03') and +(date_time not between '1901-01-01 01:01:01' and '1903-03-03 03:03:03') +order by auto; + +explain +select auto from t1 where +("aaaa" not between string and string) and +("aaaa" not between vstring and vstring) and +(0xAAAA not between bin and bin) and +(0xAAAA not between vbin and vbin) and +(-1 not between tiny and tiny) and +(-1 not between short and short) and +(-1 not between medium and medium) and +(-1 not between long_int and long_int) and +(-1 not between longlong and longlong) and +(1 not between utiny and utiny) and +(1 not between ushort and ushort) and +(1 not between umedium and umedium) and +(1 not between ulong and ulong) and +(1 not between ulonglong and ulonglong) and +/* (b'001' not between bits and bits) and */ +('one' not between options and options) and +('one' not between flags and flags) and +('1901-01-01' not between date_field and date_field) and +('1901' not between year_field and year_field) and +('01:01:01' not between time_field and time_field) and +('1901-01-01 01:01:01' not between date_time and date_time) +order by auto; + +select auto from t1 where +("aaaa" not between string and string) and +("aaaa" not between vstring and vstring) and +(0xAAAA not between bin and bin) and +(0xAAAA not between vbin and vbin) and +(-1 not between tiny and tiny) and +(-1 not between short and short) and +(-1 not between medium and medium) and +(-1 not between long_int and long_int) and +(-1 not between longlong and longlong) and +(1 not between utiny and utiny) and +(1 not between ushort and ushort) and +(1 not between umedium and umedium) and +(1 not between ulong and ulong) and +(1 not between ulonglong and ulonglong) and +/* (b'001' not between bits and bits) and */ +('one' not between options and options) and +('one' not between flags and flags) and +('1901-01-01' not between date_field and date_field) and +('1901' not between year_field and year_field) and +('01:01:01' not between time_field and time_field) and +('1901-01-01 01:01:01' not between date_time and date_time) +order by auto; + +# IN +explain +select auto from t1 where +string in("aaaa","cccc") and +vstring in("aaaa","cccc") and +bin in(0xAAAA,0xCCCC) and +vbin in(0xAAAA,0xCCCC) and +tiny in(-1,-3) and +short in(-1,-3) and +medium in(-1,-3) and +long_int in(-1,-3) and +longlong in(-1,-3) and +utiny in(1,3) and +ushort in(1,3) and +umedium in(1,3) and +ulong in(1,3) and +ulonglong in(1,3) and +/* bits in(b'001',b'011') and */ +options in('one','three') and +flags in('one','one,two,three') and +date_field in('1901-01-01','1903-03-03') and +year_field in('1901','1903') and +time_field in('01:01:01','03:03:03') and +date_time in('1901-01-01 01:01:01','1903-03-03 03:03:03') +order by auto; + +select auto from t1 where +string in("aaaa","cccc") and +vstring in("aaaa","cccc") and +bin in(0xAAAA,0xCCCC) and +vbin in(0xAAAA,0xCCCC) and +tiny in(-1,-3) and +short in(-1,-3) and +medium in(-1,-3) and +long_int in(-1,-3) and +longlong in(-1,-3) and +utiny in(1,3) and +ushort in(1,3) and +umedium in(1,3) and +ulong in(1,3) and +ulonglong in(1,3) and +/* bits in(b'001',b'011') and */ +options in('one','three') and +flags in('one','one,two,three') and +date_field in('1901-01-01','1903-03-03') and +year_field in('1901','1903') and +time_field in('01:01:01','03:03:03') and +date_time in('1901-01-01 01:01:01','1903-03-03 03:03:03') +order by auto; + +explain +select auto from t1 where +"aaaa" in(string) and +"aaaa" in(vstring) and +0xAAAA in(bin) and +0xAAAA in(vbin) and +(-1 in(tiny)) and +(-1 in (short)) and +(-1 in(medium)) and +(-1 in(long_int)) and +(-1 in(longlong)) and +1 in(utiny) and +1 in(ushort) and +1 in(umedium) and +1 in(ulong) and +1 in(ulonglong) and +/* b'001' in(bits) and */ +'one' in(options) and +'one' in(flags) and +'1901-01-01' in(date_field) and +'1901' in(year_field) and +'01:01:01' in(time_field) and +'1901-01-01 01:01:01' in(date_time) +order by auto; + +select auto from t1 where +"aaaa" in(string) and +"aaaa" in(vstring) and +0xAAAA in(bin) and +0xAAAA in(vbin) and +(-1 in(tiny)) and +(-1 in (short)) and +(-1 in(medium)) and +(-1 in(long_int)) and +(-1 in(longlong)) and +1 in(utiny) and +1 in(ushort) and +1 in(umedium) and +1 in(ulong) and +1 in(ulonglong) and +/* b'001' in(bits) and */ +'one' in(options) and +'one' in(flags) and +'1901-01-01' in(date_field) and +'1901' in(year_field) and +'01:01:01' in(time_field) and +'1901-01-01 01:01:01' in(date_time) +order by auto; + +# NOT IN +explain +select auto from t1 where +string not in("aaaa","cccc") and +vstring not in("aaaa","cccc") and +bin not in(0xAAAA,0xCCCC) and +vbin not in(0xAAAA,0xCCCC) and +tiny not in(-1,-3) and +short not in(-1,-3) and +medium not in(-1,-3) and +long_int not in(-1,-3) and +longlong not in(-1,-3) and +utiny not in(1,3) and +ushort not in(1,3) and +umedium not in(1,3) and +ulong not in(1,3) and +ulonglong not in(1,3) and +/* bits not in(b'001',b'011') and */ +options not in('one','three') and +flags not in('one','one,two,three') and +date_field not in('1901-01-01','1903-03-03') and +year_field not in('1901','1903') and +time_field not in('01:01:01','03:03:03') and +date_time not in('1901-01-01 01:01:01','1903-03-03 03:03:03') +order by auto; + +select auto from t1 where +string not in("aaaa","cccc") and +vstring not in("aaaa","cccc") and +bin not in(0xAAAA,0xCCCC) and +vbin not in(0xAAAA,0xCCCC) and +tiny not in(-1,-3) and +short not in(-1,-3) and +medium not in(-1,-3) and +long_int not in(-1,-3) and +longlong not in(-1,-3) and +utiny not in(1,3) and +ushort not in(1,3) and +umedium not in(1,3) and +ulong not in(1,3) and +ulonglong not in(1,3) and +/* bits not in(b'001',b'011') and */ +options not in('one','three') and +flags not in('one','one,two,three') and +date_field not in('1901-01-01','1903-03-03') and +year_field not in('1901','1903') and +time_field not in('01:01:01','03:03:03') and +date_time not in('1901-01-01 01:01:01','1903-03-03 03:03:03') +order by auto; + +explain +select auto from t1 where +"aaaa" not in(string) and +"aaaa" not in(vstring) and +0xAAAA not in(bin) and +0xAAAA not in(vbin) and +(-1 not in(tiny)) and +(-1 not in(short)) and +(-1 not in(medium)) and +(-1 not in(long_int)) and +(-1 not in(longlong)) and +1 not in(utiny) and +1 not in(ushort) and +1 not in(umedium) and +1 not in(ulong) and +1 not in(ulonglong) and +/* b'001' not in(bits) and */ +'one' not in(options) and +'one' not in(flags) and +'1901-01-01' not in(date_field) and +'1901' not in(year_field) and +'01:01:01' not in(time_field) and +'1901-01-01 01:01:01' not in(date_time) +order by auto; + +select auto from t1 where +"aaaa" not in(string) and +"aaaa" not in(vstring) and +0xAAAA not in(bin) and +0xAAAA not in(vbin) and +(-1 not in(tiny)) and +(-1 not in(short)) and +(-1 not in(medium)) and +(-1 not in(long_int)) and +(-1 not in(longlong)) and +1 not in(utiny) and +1 not in(ushort) and +1 not in(umedium) and +1 not in(ulong) and +1 not in(ulonglong) and +/* b'001' not in(bits) and */ +'one' not in(options) and +'one' not in(flags) and +'1901-01-01' not in(date_field) and +'1901' not in(year_field) and +'01:01:01' not in(time_field) and +'1901-01-01 01:01:01' not in(date_time) +order by auto; + +# Update test +update t1 +set medium = 17 +where +string = "aaaa" and +vstring = "aaaa" and +bin = 0xAAAA and +vbin = 0xAAAA and +tiny = -1 and +short = -1 and +medium = -1 and +long_int = -1 and +longlong = -1 and +real_float > 1.0 and real_float < 2.0 and +real_double > 1.0 and real_double < 2.0 and +real_decimal > 1.0 and real_decimal < 2.0 and +utiny = 1 and +ushort = 1 and +umedium = 1 and +ulong = 1 and +ulonglong = 1 and +/* bits = b'001' and */ +options = 'one' and +flags = 'one' and +date_field = '1901-01-01' and +year_field = '1901' and +time_field = '01:01:01' and +date_time = '1901-01-01 01:01:01'; + +# Delete test +delete from t1 +where +string = "aaaa" and +vstring = "aaaa" and +bin = 0xAAAA and +vbin = 0xAAAA and +tiny = -1 and +short = -1 and +medium = 17 and +long_int = -1 and +longlong = -1 and +real_float > 1.0 and real_float < 2.0 and +real_double > 1.0 and real_double < 2.0 and +real_decimal > 1.0 and real_decimal < 2.0 and +utiny = 1 and +ushort = 1 and +umedium = 1 and +ulong = 1 and +ulonglong = 1 and +/* bits = b'001' and */ +options = 'one' and +flags = 'one' and +date_field = '1901-01-01' and +year_field = '1901' and +time_field = '01:01:01' and +date_time = '1901-01-01 01:01:01'; + +select count(*) from t1; + +# Various tests +explain +select * from t2 where attr3 is null or attr1 > 2 and pk1= 3 order by pk1; +select * from t2 where attr3 is null or attr1 > 2 and pk1= 3 order by pk1; + +explain +select * from t2 where attr3 is not null and attr1 > 2 order by pk1; +select * from t2 where attr3 is not null and attr1 > 2 order by pk1; + +explain +select * from t3 where attr2 > 9223372036854775803 and attr3 != 3 order by pk1; +select * from t3 where attr2 > 9223372036854775803 and attr3 != 3 order by pk1; + +explain +select * from t2,t3 where t2.attr1 < 1 and t2.attr2 = t3.attr2 and t3.attr1 < 5 order by t2.pk1; +select * from t2,t3 where t2.attr1 < 1 and t2.attr2 = t3.attr2 and t3.attr1 < 5 order by t2.pk1; + +explain +select * from t4 where attr1 < 5 and attr2 > 9223372036854775803 and attr3 != 3 order by t4.pk1; +select * from t4 where attr1 < 5 and attr2 > 9223372036854775803 and attr3 != 3 order by t4.pk1; + +explain +select * from t3,t4 where t4.attr1 > 1 and t4.attr2 = t3.attr2 and t4.attr3 < 5 order by t4.pk1; +select * from t3,t4 where t4.attr1 > 1 and t4.attr2 = t3.attr2 and t4.attr3 < 5 order by t4.pk1; + +# Some tests that are currently not supported and should not push condition +explain +select auto from t1 where string = "aaaa" collate latin1_general_ci order by auto; +explain +select * from t2 where (attr1 < 2) = (attr2 < 2) order by pk1; +explain +select * from t3 left join t4 on t4.attr2 = t3.attr2 where t4.attr1 > 1 and t4.attr3 < 5 or t4.attr1 is null order by t4.pk1; + +# bug#15722 +create table t5 (a int primary key auto_increment, b tinytext not null) +engine = ndb; +insert into t5 (b) values ('jonas'), ('jensing'), ('johan'); +set engine_condition_pushdown = off; +select * from t5 where b like '%jo%' order by a; +set engine_condition_pushdown = on; +explain select * from t5 where b like '%jo%'; +select * from t5 where b like '%jo%' order by a; + +# bug#21056 ndb pushdown equal/setValue error on datetime +set engine_condition_pushdown = off; +select auto from t1 where date_time like '1902-02-02 %' order by auto; +select auto from t1 where date_time not like '1902-02-02 %' order by auto; +set engine_condition_pushdown = on; +explain select auto from t1 where date_time like '1902-02-02 %'; +select auto from t1 where date_time like '1902-02-02 %' order by auto; +explain select auto from t1 where date_time not like '1902-02-02 %'; +select auto from t1 where date_time not like '1902-02-02 %' order by auto; + +# bug#17421 -1 +drop table t1; +create table t1 (a int, b varchar(3), primary key using hash(a)) +engine=ndb; +insert into t1 values (1,'a'), (2,'ab'), (3,'abc'); +# in TUP the constants 'ab' 'abc' were expected in varchar format +# "like" returned error which became "false" +# scan filter negates "or" which exposes the bug +set engine_condition_pushdown = off; +select * from t1 where b like 'ab'; +select * from t1 where b like 'ab' or b like 'ab'; +select * from t1 where b like 'abc'; +select * from t1 where b like 'abc' or b like 'abc'; +set engine_condition_pushdown = on; +select * from t1 where b like 'ab'; +select * from t1 where b like 'ab' or b like 'ab'; +select * from t1 where b like 'abc'; +select * from t1 where b like 'abc' or b like 'abc'; + +# bug#17421 -2 +drop table t1; +create table t1 (a int, b char(3), primary key using hash(a)) +engine=ndb; +insert into t1 values (1,'a'), (2,'ab'), (3,'abc'); +# test that incorrect MySQL behaviour is preserved +# 'ab ' LIKE 'ab' is true in MySQL +set engine_condition_pushdown = off; +select * from t1 where b like 'ab'; +select * from t1 where b like 'ab' or b like 'ab'; +select * from t1 where b like 'abc'; +select * from t1 where b like 'abc' or b like 'abc'; +set engine_condition_pushdown = on; +select * from t1 where b like 'ab'; +select * from t1 where b like 'ab' or b like 'ab'; +select * from t1 where b like 'abc'; +select * from t1 where b like 'abc' or b like 'abc'; + +# bug#20406 (maybe same as bug#17421 -1, not seen on 32-bit x86) +drop table t1; +create table t1 ( fname varchar(255), lname varchar(255) ) +engine=ndbcluster; +insert into t1 values ("Young","Foo"); + +set engine_condition_pushdown = 0; +SELECT fname, lname FROM t1 WHERE (fname like 'Y%') or (lname like 'F%'); +set engine_condition_pushdown = 1; +SELECT fname, lname FROM t1 WHERE (fname like 'Y%') or (lname like 'F%'); + +# make sure optimizer does not do some crazy shortcut +insert into t1 values ("aaa", "aaa"); +insert into t1 values ("bbb", "bbb"); +insert into t1 values ("ccc", "ccc"); +insert into t1 values ("ddd", "ddd"); + +set engine_condition_pushdown = 0; +SELECT fname, lname FROM t1 WHERE (fname like 'Y%') or (lname like 'F%'); +set engine_condition_pushdown = 1; +SELECT fname, lname FROM t1 WHERE (fname like 'Y%') or (lname like 'F%'); + +set engine_condition_pushdown = @old_ecpd; +DROP TABLE t1,t2,t3,t4,t5; diff --git a/mysql-test/t/ndb_config.test b/mysql-test/t/ndb_config.test index 0c24c794dbc..f63c0087c1e 100644 --- a/mysql-test/t/ndb_config.test +++ b/mysql-test/t/ndb_config.test @@ -1,10 +1,23 @@ -- source include/have_ndb.inc +-- source include/ndb_default_cluster.inc -- source include/not_embedded.inc --exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=type,nodeid,host 2> /dev/null --exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=nodeid,host,DataMemory,IndexMemory --type=ndbd 2> /dev/null ---exec $NDB_TOOLS_DIR/ndb_config --no-defaults -r \\n -f " " --query=nodeid,host,DataMemory,IndexMemory --type=ndbd 2> /dev/null +--exec $NDB_TOOLS_DIR/ndb_config --no-defaults -r \\\n -f " " --query=nodeid,host,DataMemory,IndexMemory --type=ndbd 2> /dev/null --exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=nodeid --type=ndbd --host=localhost 2> /dev/null --exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=type,nodeid,host --config-file=$NDB_BACKUP_DIR/config.ini 2> /dev/null # End of 4.1 tests + +--exec $NDB_TOOLS_DIR/ndb_config --defaults-group-suffix=.jonas --defaults-file=$MYSQL_TEST_DIR/std_data/ndb_config_mycnf1.cnf --query=type,nodeid,host,IndexMemory,DataMemory --mycnf 2> /dev/null + +--exec $NDB_TOOLS_DIR/ndb_config --defaults-group-suffix=.cluster0 --defaults-file=$MYSQL_TEST_DIR/std_data/ndb_config_mycnf2.cnf --query=type,nodeid,host --mycnf 2> /dev/null +--exec $NDB_TOOLS_DIR/ndb_config --defaults-group-suffix=.cluster1 --defaults-file=$MYSQL_TEST_DIR/std_data/ndb_config_mycnf2.cnf --query=type,nodeid,host --mycnf 2> /dev/null +--exec $NDB_TOOLS_DIR/ndb_config --defaults-group-suffix=.cluster2 --defaults-file=$MYSQL_TEST_DIR/std_data/ndb_config_mycnf2.cnf --query=type,nodeid,host --mycnf 2> /dev/null +--exec $NDB_TOOLS_DIR/ndb_config --defaults-group-suffix=.cluster2 --defaults-file=$MYSQL_TEST_DIR/std_data/ndb_config_mycnf2.cnf --ndb-shm --connections --query=type,nodeid1,nodeid2,group,nodeidserver --mycnf 2> /dev/null + + +--exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=nodeid --host=localhost --config-file=$NDB_BACKUP_DIR/config.ini 2> /dev/null +--exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=nodeid --host=1.2.3.4 --config-file=$NDB_BACKUP_DIR/config.ini 2> /dev/null +--exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=nodeid --host=127.0.0.1 --config-file=$NDB_BACKUP_DIR/config.ini 2> /dev/null diff --git a/mysql-test/t/ndb_gis.test b/mysql-test/t/ndb_gis.test new file mode 100644 index 00000000000..e14f462c32d --- /dev/null +++ b/mysql-test/t/ndb_gis.test @@ -0,0 +1,5 @@ +--source include/have_ndb.inc +SET storage_engine=ndbcluster; +--source include/gis_generic.inc +set engine_condition_pushdown = on; +--source include/gis_generic.inc diff --git a/mysql-test/t/ndb_grant.later b/mysql-test/t/ndb_grant.later index 5258501d79e..5431d94e1f8 100644 --- a/mysql-test/t/ndb_grant.later +++ b/mysql-test/t/ndb_grant.later @@ -226,19 +226,23 @@ grant select on test.t1 to drop_user2@localhost; grant select on test.* to drop_user3@localhost; grant select on *.* to drop_user4@localhost; commit; ---error 1268 +flush privileges; +# Drop user now implicitly revokes all privileges. drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost, drop_user4@localhost; begin; +--error 1269 revoke all privileges, grant option from drop_user1@localhost, drop_user2@localhost, drop_user3@localhost, drop_user4@localhost; commit; +flush privileges; +#--error 1268 drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost, drop_user4@localhost; drop table t1; begin; grant usage on *.* to mysqltest_1@localhost identified by "password"; -grant select, update, insert on test.* to mysqltest@localhost; +grant select, update, insert on test.* to mysqltest_1@localhost; commit; show grants for mysqltest_1@localhost; drop user mysqltest_1@localhost; @@ -352,6 +356,11 @@ DROP DATABASE testdb9; DROP DATABASE testdb10; # +# just SHOW PRIVILEGES test +# +SHOW PRIVILEGES; + +# # Alter mysql system tables back to myisam # use mysql; diff --git a/mysql-test/t/ndb_index_ordered.test b/mysql-test/t/ndb_index_ordered.test index eb2b4e86343..e6827bdbe12 100644 --- a/mysql-test/t/ndb_index_ordered.test +++ b/mysql-test/t/ndb_index_ordered.test @@ -149,6 +149,37 @@ select * from t1 use index (bc) where b IS NOT NULL order by a; drop table t1; # +# Order by again, including descending. +# + +create table t1 ( + a int unsigned primary key, + b int unsigned, + c char(10), + key bc (b, c) +) engine=ndb; + +insert into t1 values(1,1,'a'),(2,2,'b'),(3,3,'c'),(4,4,'d'),(5,5,'e'); +insert into t1 select a*7,10*b,'f' from t1; +insert into t1 select a*13,10*b,'g' from t1; +insert into t1 select a*17,10*b,'h' from t1; +insert into t1 select a*19,10*b,'i' from t1; +insert into t1 select a*23,10*b,'j' from t1; +insert into t1 select a*29,10*b,'k' from t1; +# +select b, c from t1 where b <= 10 and c <'f' order by b, c; +select b, c from t1 where b <= 10 and c <'f' order by b desc, c desc; +# +select b, c from t1 where b=4000 and c<'k' order by b, c; +select b, c from t1 where b=4000 and c<'k' order by b desc, c desc; +select b, c from t1 where 1000<=b and b<=100000 and c<'j' order by b, c; +select b, c from t1 where 1000<=b and b<=100000 and c<'j' order by b desc, c desc; +# +select min(b), max(b) from t1; +# +drop table t1; + +# # Bug #6435 CREATE TABLE test1 ( SubscrID int(11) NOT NULL auto_increment, @@ -318,4 +349,10 @@ select a from t1 where b = 2; show tables; drop table t1; +# mysqld 5.0.13 crash, no bug# +create table t1 (a int, c varchar(10), + primary key using hash (a), index(c)) engine=ndb; +insert into t1 (a, c) values (1,'aaa'),(3,'bbb'); +select count(*) from t1 where c<'bbb'; + # End of 4.1 tests diff --git a/mysql-test/t/ndb_index_unique.test b/mysql-test/t/ndb_index_unique.test index 458f6a165f8..8561b3794c4 100644 --- a/mysql-test/t/ndb_index_unique.test +++ b/mysql-test/t/ndb_index_unique.test @@ -2,7 +2,7 @@ -- source include/not_embedded.inc --disable_warnings -drop table if exists t1, t2, t3, t4, t5, t6, t7; +drop table if exists t1, t2, t3, t4, t5, t6, t7, t8; --enable_warnings # @@ -183,8 +183,8 @@ INSERT INTO t3 VALUES (1,'V1',NULL); CREATE TABLE t4 ( uid bigint(20) unsigned NOT NULL default '0', gid bigint(20) unsigned NOT NULL, - rid bigint(20) unsigned NOT NULL default '-1', - cid bigint(20) unsigned NOT NULL default '-1', + rid bigint(20) unsigned NOT NULL, + cid bigint(20) unsigned NOT NULL, UNIQUE KEY m (uid,gid,rid,cid) ) engine=ndbcluster; INSERT INTO t4 VALUES (1,1,2,4); @@ -210,8 +210,8 @@ CREATE TABLE t7 ( mid bigint(20) unsigned NOT NULL PRIMARY KEY, uid bigint(20) unsigned NOT NULL default '0', gid bigint(20) unsigned NOT NULL, - rid bigint(20) unsigned NOT NULL default '-1', - cid bigint(20) unsigned NOT NULL default '-1', + rid bigint(20) unsigned NOT NULL, + cid bigint(20) unsigned NOT NULL, UNIQUE KEY m (uid,gid,rid,cid) ) engine=ndbcluster; INSERT INTO t7 VALUES(1, 1, 1, 1, 1); @@ -309,4 +309,18 @@ select * from t1 where code = '12' and month = 4 and year = 2004 ; drop table t1; +# bug#15918 Unique Key Limit in NDB Engine + +create table t1 (a int primary key, b varchar(1000) not null, unique key (b)) +engine=ndb charset=utf8; + +insert into t1 values (1, repeat(_utf8 0xe288ab6474, 200)); +--error 1062 +insert into t1 values (2, repeat(_utf8 0xe288ab6474, 200)); +select a, sha1(b) from t1; + +# perl -e 'print pack("H2000","e288ab6474"x200)' | sha1sum + +drop table t1; + # End of 4.1 tests diff --git a/mysql-test/t/ndb_insert.test b/mysql-test/t/ndb_insert.test index 92bc51bcf4f..bf25ca9a133 100644 --- a/mysql-test/t/ndb_insert.test +++ b/mysql-test/t/ndb_insert.test @@ -591,14 +591,14 @@ DELETE FROM t1 WHERE pk1 = 2 OR pk1 = 4 OR pk1 = 6; INSERT INTO t1 VALUES(1,1,1),(2,2,17),(3,4,5) ON DUPLICATE KEY UPDATE pk1=b; select * from t1 where pk1 = b and b != c order by pk1; -# The following test case currently does not work -#DELETE FROM t1; -#CREATE UNIQUE INDEX bi ON t1(b); -#INSERT INTO t1 VALUES -#(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5), -#(6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10); -#INSERT INTO t1 VALUES(0,1,0),(21,21,21) ON DUPLICATE KEY UPDATE pk1=b+10,c=b+10; -#select * from t1 order by pk1; +# Test handling of duplicate unique +DELETE FROM t1; +CREATE UNIQUE INDEX bi ON t1(b); +INSERT INTO t1 VALUES +(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5), +(6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10); +INSERT INTO t1 VALUES(0,1,0),(21,21,21) ON DUPLICATE KEY UPDATE pk1=b+10,b=b+10; +select * from t1 order by pk1; DROP TABLE t1; @@ -614,7 +614,20 @@ INSERT IGNORE INTO t1 SELECT a FROM t1; INSERT IGNORE INTO t1 SELECT a FROM t1; INSERT IGNORE INTO t1 VALUES (1); INSERT IGNORE INTO t1 VALUES (1); -SELECT * FROM t1; +SELECT * FROM t1 ORDER BY a; +DELETE FROM t1; +CREATE UNIQUE INDEX ai ON t1(a); +INSERT IGNORE INTO t1 VALUES (1); +INSERT IGNORE INTO t1 VALUES (1); +INSERT IGNORE INTO t1 VALUES (NULL),(2); +SELECT * FROM t1 ORDER BY a; +DROP TABLE t1; + +# Ignore and NULL values +CREATE TABLE t1(pk INT NOT NULL PRIMARY KEY, a INT, UNIQUE (a)) ENGINE=ndb; +INSERT IGNORE INTO t1 VALUES (1,1),(2,2),(3,3); +INSERT IGNORE INTO t1 VALUES (4,NULL),(5,NULL),(6,NULL),(7,4); +SELECT * FROM t1 ORDER BY pk; DROP TABLE t1; # End of 4.1 tests diff --git a/mysql-test/t/ndb_load.test b/mysql-test/t/ndb_load.test index 72a5b53eaad..af2df70b74e 100644 --- a/mysql-test/t/ndb_load.test +++ b/mysql-test/t/ndb_load.test @@ -12,12 +12,12 @@ DROP TABLE IF EXISTS t1; # should give duplicate key CREATE TABLE t1 (word CHAR(20) NOT NULL PRIMARY KEY) ENGINE=NDB; --error 1022 -LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 ; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1 ; DROP TABLE t1; # now without a primary key we should be ok CREATE TABLE t1 (word CHAR(20) NOT NULL) ENGINE=NDB; -LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 ; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1 ; SELECT * FROM t1 ORDER BY word; DROP TABLE t1; diff --git a/mysql-test/t/ndb_lock.test b/mysql-test/t/ndb_lock.test index 3804782b150..48a8b77dcd7 100644 --- a/mysql-test/t/ndb_lock.test +++ b/mysql-test/t/ndb_lock.test @@ -110,7 +110,8 @@ connection con2; begin; # Have to check with pk access here since scans take locks on # all rows and then release them in chunks -select * from t1 where x = 2 for update; +# Bug #20390 SELECT FOR UPDATE does not release locks of untouched rows in full table scans +#select * from t1 where x = 2 for update; --error 1205 select * from t1 where x = 1 for update; rollback; @@ -163,7 +164,8 @@ begin; select * from t1 where y = 'one' lock in share mode; # Have to check with pk access here since scans take locks on # all rows and then release them in chunks -select * from t1 where x = 2 for update; +# Bug #20390 SELECT FOR UPDATE does not release locks of untouched rows in full table scans +#select * from t1 where x = 2 for update; --error 1205 select * from t1 where x = 1 for update; rollback; diff --git a/mysql-test/t/ndb_multi.test b/mysql-test/t/ndb_multi.test index ce8ce420793..3bc735b60d4 100644 --- a/mysql-test/t/ndb_multi.test +++ b/mysql-test/t/ndb_multi.test @@ -37,9 +37,6 @@ drop table t1; create table t1 (a int) engine=ndbcluster; insert into t1 value (2); connection server1; -# Currently a retry is required remotely ---error 1296 -select * from t1; flush table t1; select * from t1; diff --git a/mysql-test/t/ndb_read_multi_range.test b/mysql-test/t/ndb_read_multi_range.test new file mode 100644 index 00000000000..855f7789032 --- /dev/null +++ b/mysql-test/t/ndb_read_multi_range.test @@ -0,0 +1,240 @@ +-- source include/have_ndb.inc +-- source include/not_embedded.inc + +--disable_warnings +DROP TABLE IF EXISTS t1, t2, r1; +--enable_warnings + +# +# Basic test to see that batching is working +# + +create table t1 ( + a int primary key, + b int not null, + c int not null, + index(b), unique index using hash(c) +) engine = ndb; +insert into t1 values + (1,2,1),(2,3,2),(3,4,3),(4,5,4), + (5,2,12),(6,3,11),(7,4,10),(8,5,9), + (9,2,8),(10,3,7),(11,4,6),(12,5,5); + +# batch on primary key +create table r1 as select * from t1 where a in (2,8,12); +select * from r1 order by a; +drop table r1; + +# batch on ordered index +create table r1 as select * from t1 where b in (1,2,5); +select * from r1 order by a; +drop table r1; + +# batch on unique hash index +create table r1 as select * from t1 where c in (2,8,12); +select * from r1 order by a; +drop table r1; + +# batch mixed +create table r1 as select * from t1 where a in (2,8) or (a > 11) or (a <= 1); +select * from r1 order by a; +drop table r1; + +# batch on primary key, missing values +create table r1 as select * from t1 where a in (33,8,12); +select * from r1 order by a; +drop table r1; +create table r1 as select * from t1 where a in (2,33,8,12,34); +select * from r1 order by a; +drop table r1; + +# batch on ordered index, missing values +create table r1 as select * from t1 where b in (1,33,5); +select * from r1 order by a; +drop table r1; +select * from t1 where b in (1,33,5) order by a; +create table r1 as select * from t1 where b in (45,1,33,5,44); +select * from r1 order by a; +drop table r1; +select * from t1 where b in (45,22) order by a; + +# batch on unique hash index, missing values +create table r1 as select * from t1 where c in (2,8,33); +select * from r1 order by a; +drop table r1; +create table r1 as select * from t1 where c in (13,2,8,33,12); +select * from r1 order by a; +drop table r1; + +select * from t1 where a in (33,8,12) order by a; +select * from t1 where a in (33,34,35) order by a; +select * from t1 where a in (2,8) or (a > 11) or (a <= 1) order by a; +select * from t1 where b in (6,7) or (b <= 5) or (b >= 10) order by b,a; +select * from t1 where c in (13,2,8,33,12) order by c,a; +drop table t1; + +# +# Somewhat more complicated +# + +create table t1 ( + a int not null, + b int not null, + c int not null, + d int not null, + e int not null, + primary key (a,b,c,d), index (d) +) engine = ndb; + +insert into t1 values + (1,2,1,1,1),(2,3,2,3,1),(3,4,3,1,1),(4,5,4,7,1), + (5,2,12,12,1),(6,3,11,1,1),(7,4,10,3,1),(8,5,9,5,1), + (9,2,8,6,1),(10,3,7,5,1),(11,4,6,3,1),(12,5,5,2,1), + (1,2,1,2,1), + (1,2,1,3,1), + (1,2,1,4,1), + (1,2,1,5,1); + +# batch on primary key +create table r1 as select * from t1 + where a=1 and b=2 and c=1 and d in (1,4,3,2); +select * from r1 order by a,b,c,d; +drop table r1; + +# batched update ordered index, one value for all +update t1 set e = 100 + where d in (12,6,7); +select * from t1 where d in (12,6,7) order by a,b,c,d; +select * from t1 where d not in (12,6,7) and e = 100; + +# batched update primary key, one value for all +update t1 + set e = 101 + where a=1 and + b=2 and + c=1 and + d in (1,4,3,2); +select * + from t1 + where a=1 and b=2 and c=1 and d in (1,4,3,2) + order by a,b,c,d; +select * + from t1 + where not (a=1 and b=2 and c=1 and d in (1,4,3,2)) + and e=101; + + +# batched update ordered index, different values +update t1 + set e = + (case d + when 12 then 112 + when 6 then 106 + when 7 then 107 + end) + where d in (12,6,7); +select * from t1 where d in (12,6,7) order by a,b,c,d; + +# batched update primary key, different values +update t1 + set e = + (case d + when 1 then 111 + when 4 then 444 + when 3 then 333 + when 2 then 222 + end) + where a=1 and + b=2 and + c=1 and + d in (1,4,3,2); +select * + from t1 + where a=1 and b=2 and c=1 and d in (1,4,3,2) + order by a,b,c,d; + +# batched delete +delete from t1 where d in (12,6,7); +select * from t1 where d in (12,6,7); + +drop table t1; + +# null handling +create table t1 ( + a int not null primary key, + b int, + c int, + d int, + unique index (b), + index(c) +) engine = ndb; + +insert into t1 values + (1,null,1,1), + (2,2,2,2), + (3,null,null,3), + (4,4,null,4), + (5,null,5,null), + (6,6,6,null), + (7,null,null,null), + (8,8,null,null), + (9,null,9,9), + (10,10,10,10), + (11,null,null,11), + (12,12,null,12), + (13,null,13,null), + (14,14,14,null), + (15,null,null,null), + (16,16,null,null); + +create table t2 as select * from t1 where a in (5,6,7,8,9,10); +select * from t2 order by a; +drop table t2; + +create table t2 as select * from t1 where b in (5,6,7,8,9,10); +select * from t2 order by a; +drop table t2; + +create table t2 as select * from t1 where c in (5,6,7,8,9,10); +select * from t2 order by a; +drop table t2; + +drop table t1; + +# bug17729 + +CREATE TABLE t1 ( + a int(11) NOT NULL, + b int(11) NOT NULL, + c datetime default NULL, + PRIMARY KEY (a), + KEY idx_bc (b,c) +) ENGINE=ndbcluster; + +INSERT INTO t1 VALUES +(406989,67,'2006-02-23 17:08:46'), (150078,67,'2005-10-26 11:17:45'), +(406993,67,'2006-02-27 11:20:57'), (245655,67,'2005-12-08 15:59:08'), +(406994,67,'2006-02-27 11:26:46'), (256,67,NULL), +(398341,67,'2006-02-20 04:48:44'), (254,67,NULL),(1120,67,NULL), +(406988,67,'2006-02-23 17:07:22'), (255,67,NULL), +(398340,67,'2006-02-20 04:38:53'),(406631,67,'2006-02-23 10:49:42'), +(245653,67,'2005-12-08 15:59:07'),(406992,67,'2006-02-24 16:47:18'), +(245654,67,'2005-12-08 15:59:08'),(406995,67,'2006-02-28 11:55:00'), +(127261,67,'2005-10-13 12:17:58'),(406991,67,'2006-02-24 16:42:32'), +(245652,67,'2005-12-08 15:58:27'),(398545,67,'2006-02-20 04:53:13'), +(154504,67,'2005-10-28 11:53:01'),(9199,67,NULL),(1,67,'2006-02-23 15:01:35'), +(223456,67,NULL),(4101,67,NULL),(1133,67,NULL), +(406990,67,'2006-02-23 18:01:45'),(148815,67,'2005-10-25 15:34:17'), +(148812,67,'2005-10-25 15:30:01'),(245651,67,'2005-12-08 15:58:27'), +(154503,67,'2005-10-28 11:52:38'); + +create table t11 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 asc; +create table t12 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 desc; +create table t21 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 asc; +create table t22 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 desc; + +select * from t11 order by 1,2,3; +select * from t12 order by 1,2,3; +select * from t21 order by 1,2,3; +select * from t22 order by 1,2,3; +DROP TABLE t1, t11, t12, t21, t22; diff --git a/mysql-test/t/ndb_replace.test b/mysql-test/t/ndb_replace.test index b97a0322a6a..476a607ed44 100644 --- a/mysql-test/t/ndb_replace.test +++ b/mysql-test/t/ndb_replace.test @@ -6,7 +6,7 @@ # --disable_warnings -drop table if exists t1; +drop table if exists t1,t2; --enable_warnings CREATE TABLE t1 ( @@ -28,3 +28,77 @@ select * from t1 order by gesuchnr; drop table t1; # End of 4.1 tests + +# bug#17431 +CREATE TABLE t1(i INT PRIMARY KEY AUTO_INCREMENT, + j INT, + k INT, + UNIQUE INDEX(j) + ) ENGINE = ndb; +INSERT INTO t1 VALUES (1,1,23),(2,2,24); +REPLACE INTO t1 (j,k) VALUES (1,42); +REPLACE INTO t1 (i,j) VALUES (17,2); +SELECT * from t1 ORDER BY i; +DROP TABLE t1; + +# bug#19906 +CREATE TABLE t2 (a INT(11) NOT NULL, + b INT(11) NOT NULL, + c INT(11) NOT NULL, + x TEXT, + y TEXT, + z TEXT, + id INT(10) unsigned NOT NULL AUTO_INCREMENT, + i INT(11) DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY a (a,b,c) +) ENGINE=ndbcluster; + +REPLACE INTO t2 (a,b,c,x,y,z,i) VALUES (1,1,1,'a','a','a',1),(1,1,1,'b','b','b',2), (1,1,1,'c','c','c',3); + +SELECT * FROM t2 ORDER BY id; + +REPLACE INTO t2(a,b,c,x,y,z,i) values (1,1,1,'a','a','a',1); +REPLACE INTO t2(a,b,c,x,y,z,i) values (1,1,1,'b','b','b',2); + +SELECT * FROM t2 ORDER BY id; + +DROP TABLE t2; + +# +# Bug #20728 "REPLACE does not work correctly for NDB table with PK and +# unique index" +# +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1 (pk int primary key, apk int unique, data int) engine=ndbcluster; +# Test for plain replace which updates pk +insert into t1 values (1, 1, 1), (2, 2, 2), (3, 3, 3); +replace into t1 (pk, apk) values (4, 1), (5, 2); +select * from t1 order by pk; +delete from t1; +# Another test for plain replace which doesn't touch pk +insert into t1 values (1, 1, 1), (2, 2, 2), (3, 3, 3); +replace into t1 (pk, apk) values (1, 4), (2, 5); +select * from t1 order by pk; +delete from t1; +# Test for load data replace which updates pk +insert into t1 values (1, 1, 1), (4, 4, 4), (6, 6, 6); +load data infile '../std_data_ln/loaddata5.dat' replace into table t1 fields terminated by '' enclosed by '' ignore 1 lines (pk, apk); +select * from t1 order by pk; +delete from t1; +# Now test for load data replace which doesn't touch pk +insert into t1 values (1, 1, 1), (3, 3, 3), (5, 5, 5); +load data infile '../std_data_ln/loaddata5.dat' replace into table t1 fields terminated by '' enclosed by '' ignore 1 lines (pk, apk); +select * from t1 order by pk; +delete from t1; +# Finally test for both types of replace ... select +insert into t1 values (1, 1, 1), (2, 2, 2), (3, 3, 3); +replace into t1 (pk, apk) select 4, 1; +replace into t1 (pk, apk) select 2, 4; +select * from t1 order by pk; +# Clean-up +drop table t1; + +--echo End of 5.0 tests. diff --git a/mysql-test/t/ndb_restore.test b/mysql-test/t/ndb_restore.test index 586c39ed96b..39c7ab67efb 100644 --- a/mysql-test/t/ndb_restore.test +++ b/mysql-test/t/ndb_restore.test @@ -1,10 +1,11 @@ -- source include/have_ndb.inc +-- source include/ndb_default_cluster.inc -- source include/not_embedded.inc --disable_warnings use test; -drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; -drop table if exists t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9,t10; +drop table if exists t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c,t10_c; --enable_warnings CREATE TABLE `t1` ( @@ -131,6 +132,13 @@ CREATE TABLE `t9` ( ) ENGINE=myisam DEFAULT CHARSET=latin1; INSERT INTO `t9` VALUES ('3g4jh8gar2t','joe','q3.net','elredun.com','q3.net','436643316120','436643316939','91341234568968','695595699','1.1.1.1','2.2.6.2','3','86989','34','x','x','2012-03-12 18:35:04','2012-12-05 12:35:04',3123123,9569,6565,1),('4tt45345235','pap','q3plus.qt','q3plus.qt','q3.net','436643316120','436643316939','8956234534568968','5254595969','1.1.1.1','8.6.2.2','4','86989','34','x','x','2012-03-12 12:55:34','2012-12-05 11:20:04',3223433,3369,9565,2),('4545435545','john','q3.net','q3.net','acne.li','436643316120','436643316939','45345234568968','995696699','1.1.1.1','2.9.9.2','2','86998','34','x','x','2012-03-12 11:35:03','2012-12-05 08:50:04',8823123,169,3565,3); +# Bug #20820 +# auto inc table not handled correctly when restored from cluster backup +# - before fix ndb_restore would not set auto inc value correct, +# seen by select below +create table t10 (a int auto_increment key); +insert into t10 values (1),(2),(3); + create table t1_c engine=ndbcluster as select * from t1; create table t2_c engine=ndbcluster as select * from t2; create table t3_c engine=ndbcluster as select * from t3; @@ -140,10 +148,11 @@ create table t6_c engine=ndbcluster as select * from t6; create table t7_c engine=ndbcluster as select * from t7; create table t8_c engine=ndbcluster as select * from t8; create table t9_c engine=ndbcluster as select * from t9; +create table t10_c engine=ndbcluster as select * from t10; --exec $NDB_MGM --no-defaults -e "start backup" >> $NDB_TOOLS_OUTPUT -drop table t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; +drop table t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c, t10_c; --exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b 1 -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-1 >> $NDB_TOOLS_OUTPUT --exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b 1 -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-1 >> $NDB_TOOLS_OUTPUT @@ -204,9 +213,12 @@ select count(*) from (select * from t9 union select * from t9_c) a; +# Bug #20820 cont'd +select * from t10_c order by a; + --disable_warnings -drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; -drop table if exists t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9, t10; +drop table if exists t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c, t10_c; --enable_warnings # @@ -215,4 +227,4 @@ drop table if exists t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; --exec $NDB_TOOLS_DIR/ndb_select_all --no-defaults -d sys -D , SYSTAB_0 | grep 520093696 -# End of 4.1 tests +# End of 5.0 tests (4.1 test intermixed to save test time) diff --git a/mysql-test/t/ndb_subquery.test b/mysql-test/t/ndb_subquery.test index 135dc4fb862..93c45c521a0 100644 --- a/mysql-test/t/ndb_subquery.test +++ b/mysql-test/t/ndb_subquery.test @@ -39,3 +39,27 @@ drop table t2; ########## # End of 4.1 tests + +# +# bug#11205 +# +create table t1 (p int not null primary key, u int not null) engine=ndb; +insert into t1 values (1,1),(2,2),(3,3); + +create table t2 as +select t1.* +from t1 as t1, t1 as t2, t1 as t3, t1 as t4, t1 as t5, t1 as t6, t1 as t7, t1 as t8 +where t1.u = t2.u + and t2.u = t3.u + and t3.u = t4.u + and t4.u = t5.u + and t5.u = t6.u + and t6.u = t7.u + and t7.u = t8.u; + +select * from t2 order by 1; + +drop table t1; +drop table t2; + + diff --git a/mysql-test/t/ndb_trigger.test b/mysql-test/t/ndb_trigger.test new file mode 100644 index 00000000000..2521ef17842 --- /dev/null +++ b/mysql-test/t/ndb_trigger.test @@ -0,0 +1,92 @@ +# Tests which involve triggers and NDB storage engine +--source include/have_ndb.inc +--source include/not_embedded.inc + +# +# Test for bug#18437 "Wrong values inserted with a before update +# trigger on NDB table". SQL-layer didn't properly inform handler +# about fields which were read and set in triggers. In some cases +# this resulted in incorrect (garbage) values of OLD variables and +# lost changes to NEW variables. +# You can find similar tests for ON INSERT triggers in federated.test +# since this engine so far is the only engine in MySQL which cares +# about field mark-up during handler::write_row() operation. +# + +--disable_warnings +drop table if exists t1, t2, t3; +--enable_warnings + +create table t1 (id int primary key, a int not null, b decimal (63,30) default 0) engine=ndb; +create table t2 (op char(1), a int not null, b decimal (63,30)); +create table t3 select 1 as i; + +delimiter //; +create trigger t1_bu before update on t1 for each row +begin + insert into t2 values ("u", old.a, old.b); + set new.b = old.b + 10; +end;// +create trigger t1_bd before delete on t1 for each row +begin + insert into t2 values ("d", old.a, old.b); +end;// +delimiter ;// +insert into t1 values (1, 1, 1.05), (2, 2, 2.05), (3, 3, 3.05), (4, 4, 4.05); + +# Check that usual update works as it should +update t1 set a=5 where a != 3; +select * from t1 order by id; +select * from t2 order by op, a, b; +delete from t2; +# Check that everything works for multi-update +update t1, t3 set a=6 where a = 5; +select * from t1 order by id; +select * from t2 order by op, a, b; +delete from t2; +# Check for delete +delete from t1 where a != 3; +select * from t1 order by id; +select * from t2 order by op, a, b; +delete from t2; +# Check for multi-delete +insert into t1 values (1, 1, 1.05), (2, 2, 2.05), (4, 4, 4.05); +delete t1 from t1, t3 where a != 3; +select * from t1 order by id; +select * from t2 order by op, a, b; +delete from t2; +# Check for insert ... on duplicate key update +insert into t1 values (4, 4, 4.05); +insert into t1 (id, a) values (4, 1), (3, 1) on duplicate key update a= a + 1; +select * from t1 order by id; +select * from t2 order by op, a, b; +delete from t2; +# Check for insert ... select ... on duplicate key update +delete from t3; +insert into t3 values (4), (3); +insert into t1 (id, a) (select i, 1 from t3) on duplicate key update a= a + 1; +select * from t1 order by id; +select * from t2 order by op, a, b; +delete from t2; +# Check for replace +replace into t1 (id, a) values (4, 1), (3, 1); +select * from t1 order by id; +select * from t2 order by op, a, b; +delete from t1; +delete from t2; +# Check for replace ... select ... +insert into t1 values (3, 1, 1.05), (4, 1, 2.05); +replace into t1 (id, a) (select i, 2 from t3); +select * from t1 order by id; +select * from t2 order by op, a, b; +delete from t1; +delete from t2; +# Check for load data replace +insert into t1 values (3, 1, 1.05), (5, 2, 2.05); +load data infile '../std_data_ln/loaddata5.dat' replace into table t1 fields terminated by '' enclosed by '' ignore 1 lines (id, a); +select * from t1 order by id; +select * from t2 order by op, a, b; + +drop tables t1, t2, t3; + +--echo End of 5.0 tests diff --git a/mysql-test/t/ndb_types.test b/mysql-test/t/ndb_types.test index 1ca89447892..10b8eb87e2c 100644 --- a/mysql-test/t/ndb_types.test +++ b/mysql-test/t/ndb_types.test @@ -12,7 +12,7 @@ CREATE TABLE t1 ( auto int(5) unsigned NOT NULL auto_increment, string char(10) default "hello", vstring varchar(10) default "hello", - bin binary(7), + bin binary(2), vbin varbinary(7), tiny tinyint(4) DEFAULT '0' NOT NULL , short smallint(6) DEFAULT '1' NOT NULL , @@ -21,11 +21,13 @@ CREATE TABLE t1 ( longlong bigint(13) DEFAULT '0' NOT NULL, real_float float(13,1) DEFAULT 0.0 NOT NULL, real_double double(16,4), + real_decimal decimal(16,4), utiny tinyint(3) unsigned DEFAULT '0' NOT NULL, ushort smallint(5) unsigned zerofill DEFAULT '00000' NOT NULL, umedium mediumint(8) unsigned DEFAULT '0' NOT NULL, ulong int(11) unsigned DEFAULT '0' NOT NULL, ulonglong bigint(13) unsigned DEFAULT '0' NOT NULL, + bits bit(3), options enum('one','two','tree') not null, flags set('one','two','tree') not null, date_field date, @@ -51,15 +53,15 @@ set @now = now(); sleep 1; insert into t1 (string,vstring,bin,vbin,tiny,short,medium,long_int,longlong, - real_float,real_double, utiny, ushort, umedium,ulong,ulonglong, - options,flags,date_field,year_field,time_field,date_time) + real_float,real_double, real_decimal,utiny, ushort, umedium,ulong,ulonglong, + bits,options,flags,date_field,year_field,time_field,date_time) values -("aaaa","aaaa",0xAAAA,0xAAAA,-1,-1,-1,-1,-1,1.1,1.1,1,1,1,1,1, - 'one','one', '1901-01-01','1901','01:01:01','1901-01-01 01:01:01'); +("aaaa","aaaa",0xAAAA,0xAAAA,-1,-1,-1,-1,-1,1.1,1.1,1.1,1,1,1,1,1, + b'001','one','one', '1901-01-01','1901','01:01:01','1901-01-01 01:01:01'); select auto,string,vstring,bin,vbin,tiny,short,medium,long_int,longlong, - real_float,real_double, utiny, ushort, umedium,ulong,ulonglong, - options,flags,date_field,year_field,time_field,date_time + real_float,real_double,real_decimal,utiny,ushort,umedium,ulong,ulonglong, + bits,options,flags,date_field,year_field,time_field,date_time from t1; select time_stamp>@now from t1; @@ -67,13 +69,14 @@ set @now = now(); sleep 1; update t1 set string="bbbb",vstring="bbbb",bin=0xBBBB,vbin=0xBBBB, tiny=-2,short=-2,medium=-2,long_int=-2,longlong=-2,real_float=2.2, -real_double=2.2,utiny=2,ushort=2,umedium=2,ulong=2,ulonglong=2, +real_double=2.2,real_decimal=2.2,utiny=2,ushort=2,umedium=2,ulong=2, +ulonglong=2, bits=b'010', options='one',flags='one', date_field='1902-02-02',year_field='1902', time_field='02:02:02',date_time='1902-02-02 02:02:02' where auto=1; select auto,string,vstring,bin,vbin,tiny,short,medium,long_int,longlong, - real_float,real_double, utiny, ushort, umedium,ulong,ulonglong, - options,flags,date_field,year_field,time_field,date_time + real_float,real_double,real_decimal,utiny,ushort,umedium,ulong,ulonglong, + bits,options,flags,date_field,year_field,time_field,date_time from t1; select time_stamp>@now from t1; diff --git a/mysql-test/t/null.test b/mysql-test/t/null.test index b405b8fb852..4aec745f3f7 100644 --- a/mysql-test/t/null.test +++ b/mysql-test/t/null.test @@ -59,7 +59,7 @@ drop table t1; # # Test inserting and updating with NULL # -CREATE TABLE t1 (a varchar(16) NOT NULL, b smallint(6) NOT NULL, c datetime NOT NULL, d smallint(6) NOT NULL); +CREATE TABLE t1 (a varchar(16) NOT NULL default '', b smallint(6) NOT NULL default 0, c datetime NOT NULL default '0000-00-00 00:00:00', d smallint(6) NOT NULL default 0); INSERT INTO t1 SET a = "", d= "2003-01-14 03:54:55"; UPDATE t1 SET d=1/NULL; UPDATE t1 SET d=NULL; @@ -100,9 +100,9 @@ drop table t1; select cast(NULL as signed); # -# Test case for bug #4256 +# IS NULL is unable to use index in range if column is declared not null +# (Bug #4256) # - create table t1(i int, key(i)); insert into t1 values(1); insert into t1 select i*2 from t1; @@ -114,9 +114,12 @@ insert into t1 select i*2 from t1; insert into t1 select i*2 from t1; insert into t1 select i*2 from t1; insert into t1 select i*2 from t1; +insert into t1 values(null); explain select * from t1 where i=2 or i is null; +select count(*) from t1 where i=2 or i is null; alter table t1 change i i int not null; explain select * from t1 where i=2 or i is null; +select count(*) from t1 where i=2 or i is null; drop table t1; # diff --git a/mysql-test/t/null_key.test b/mysql-test/t/null_key.test index a43916d6397..e15aec01d2a 100644 --- a/mysql-test/t/null_key.test +++ b/mysql-test/t/null_key.test @@ -26,6 +26,8 @@ select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3; select * from t1 where (a is null or a > 0 and a < 3) and b > 7 limit 3; select * from t1 where (a is null or a = 7) and b=7; select * from t1 where a is null and b=9 or a is null and b=7 limit 3; +select * from t1 where a > 1 and a < 3 limit 1; +select * from t1 where a > 8 and a < 9; create table t2 like t1; insert into t2 select * from t1; alter table t1 modify b blob not null, add c int not null, drop key a, add unique key (a,b(20),c), drop key b, add key (b(10)); diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test index 683e1402678..4e5e7b72fc8 100644 --- a/mysql-test/t/olap.test +++ b/mysql-test/t/olap.test @@ -2,6 +2,10 @@ drop table if exists t1,t2; --enable_warnings +set @sav_dpi= @@div_precision_increment; +set div_precision_increment= 5; +show variables like 'div_precision_increment'; + create table t1 (product varchar(32), country_id int not null, year int, profit int); insert into t1 values ( 'Computer', 2,2000, 1200), ( 'TV', 1, 1999, 150), @@ -153,6 +157,13 @@ SELECT DISTINCT SUM(b), COUNT(DISTINCT b), COUNT(*) FROM t1 SELECT a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP; SELECT DISTINCT a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP; +SELECT b, a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP; +SELECT DISTINCT b,a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP; + +ALTER TABLE t1 ADD COLUMN c INT; +SELECT a,b,sum(c) FROM t1 GROUP BY a,b,c WITH ROLLUP; +SELECT distinct a,b,sum(c) FROM t1 GROUP BY a,b,c WITH ROLLUP; + DROP TABLE t1; # @@ -184,6 +195,7 @@ SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP; SELECT * FROM ( SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP ) t2; DROP TABLE t1; +set div_precision_increment= @sav_dpi; # # Tests for bug #7914: ROLLUP over expressions on temporary table @@ -250,9 +262,8 @@ SELECT a, b, a AS c, COUNT(*) AS count FROM t1 GROUP BY a, b, c WITH ROLLUP; DROP TABLE t1; -# -# Bug #11885: derived table specified by a subquery with -# ROLLUP over expressions on not nullable group by attributes +# Bug #12885(1): derived table specified by a subquery with +# ROLLUP over expressions on not nullable group by attributes # CREATE TABLE t1 (a int(11) NOT NULL); @@ -282,3 +293,37 @@ select left(a,10) x, a, sum(b) from t1 group by x,a with rollup; drop table t1; # End of 4.1 tests + +# +# Tests for bug #11639: ROLLUP over view executed through filesort +# + +CREATE TABLE t1(id int, type char(1)); +INSERT INTO t1 VALUES + (1,"A"),(2,"C"),(3,"A"),(4,"A"),(5,"B"), + (6,"B"),(7,"A"),(8,"C"),(9,"A"),(10,"C"); +CREATE VIEW v1 AS SELECT * FROM t1; + +SELECT type FROM t1 GROUP BY type WITH ROLLUP; +SELECT type FROM v1 GROUP BY type WITH ROLLUP; +EXPLAIN SELECT type FROM v1 GROUP BY type WITH ROLLUP; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #12885(2): view specified by a subquery with +# ROLLUP over expressions on not nullable group by attributes +# + +CREATE TABLE t1 (a int(11) NOT NULL); +INSERT INTO t1 VALUES (1),(2); + +CREATE VIEW v1 AS + SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP; + +DESC v1; +SELECT * FROM v1; + +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/t/openssl_1.test b/mysql-test/t/openssl_1.test index 3f398a91834..49f8fc4d7d4 100644 --- a/mysql-test/t/openssl_1.test +++ b/mysql-test/t/openssl_1.test @@ -1,6 +1,6 @@ # We test openssl. Result set is optimized to be compiled with --with-openssl. # Use mysql-test-run with --with-openssl option. --- source include/have_openssl_1.inc +-- source include/have_openssl.inc --disable_warnings drop table if exists t1; @@ -10,38 +10,89 @@ insert into t1 values (5); grant select on test.* to ssl_user1@localhost require SSL; grant select on test.* to ssl_user2@localhost require cipher "DHE-RSA-AES256-SHA"; -grant select on test.* to ssl_user3@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/L=Uppsala/O=MySQL AB/CN=MySQL Client/Email=abstract.mysql.developer@mysql.com"; -grant select on test.* to ssl_user4@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/L=Uppsala/O=MySQL AB/CN=MySQL Client/Email=abstract.mysql.developer@mysql.com" ISSUER "/C=SE/L=Uppsala/O=MySQL AB/CN=Abstract MySQL Developer/Email=abstract.mysql.developer@mysql.com"; +grant select on test.* to ssl_user3@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/ST=Uppsala/L=Uppsala/O=MySQL AB"; +grant select on test.* to ssl_user4@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/ST=Uppsala/L=Uppsala/O=MySQL AB" ISSUER "/C=SE/ST=Uppsala/L=Uppsala/O=MySQL AB"; +grant select on test.* to ssl_user5@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "xxx"; flush privileges; -connect (con1,localhost,ssl_user1,,); -connect (con2,localhost,ssl_user2,,); -connect (con3,localhost,ssl_user3,,); -connect (con4,localhost,ssl_user4,,); + +connect (con1,localhost,ssl_user1,,,,,SSL); +connect (con2,localhost,ssl_user2,,,,,SSL); +connect (con3,localhost,ssl_user3,,,,,SSL); +connect (con4,localhost,ssl_user4,,,,,SSL); +--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT +--error 1045 +connect (con5,localhost,ssl_user5,,,,,SSL); connection con1; +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; select * from t1; ---error 1044 +--error 1142 delete from t1; connection con2; +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; select * from t1; ---error 1044 +--error 1142 delete from t1; connection con3; +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; select * from t1; ---error 1044 +--error 1142 delete from t1; connection con4; +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; select * from t1; ---error 1044 +--error 1142 delete from t1; connection default; -delete from mysql.user where user='ssl_user%'; -delete from mysql.db where user='ssl_user%'; -flush privileges; +drop user ssl_user1@localhost, ssl_user2@localhost, +ssl_user3@localhost, ssl_user4@localhost, ssl_user5@localhost; + drop table t1; # End of 4.1 tests + +# +# Test that we can't open connection to server if we are using +# a different cacert +# +--exec echo "this query should not execute;" > $MYSQLTEST_VARDIR/tmp/test.sql +--error 1 +--exec $MYSQL_TEST --ssl-ca=$MYSQL_TEST_DIR/std_data/untrusted-cacert.pem --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 + +# +# Test that we can't open connection to server if we are using +# a blank ca +# +--error 1 +--exec $MYSQL_TEST --ssl-ca= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 + +# +# Test that we can't open connection to server if we are using +# a nonexistent ca file +# +--error 1 +--exec $MYSQL_TEST --ssl-ca=nonexisting_file.pem --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 + +# +# Test that we can't open connection to server if we are using +# a blank client-key +# +--error 1 +--exec $MYSQL_TEST --ssl-key= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 + +# +# Test that we can't open connection to server if we are using +# a blank client-cert +# +--error 1 +--exec $MYSQL_TEST --ssl-cert= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 + + diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test index 1664afc70f9..1104c859ab8 100644 --- a/mysql-test/t/order_by.test +++ b/mysql-test/t/order_by.test @@ -158,10 +158,21 @@ LEFT JOIN t3 ON t3.c = t1.c; SELECT a,b,if(b = 1,i,if(b = 2,v,'')) FROM t1 +LEFT JOIN t2 ON t1.c = t2.c +LEFT JOIN t3 ON t3.c = t1.c; + +SELECT a,b,if(b = 1,i,if(b = 2,v,'')) +FROM t1 LEFT JOIN t2 USING(c) LEFT JOIN t3 ON t3.c = t1.c ORDER BY a; +SELECT a,b,if(b = 1,i,if(b = 2,v,'')) +FROM t1 +LEFT JOIN t2 ON t1.c = t2.c +LEFT JOIN t3 ON t3.c = t1.c +ORDER BY a; + drop table t1,t2,t3; # @@ -206,7 +217,7 @@ CREATE TABLE t1 ( favo_tv varchar(50) NOT NULL default '', favo_eten varchar(50) NOT NULL default '', favo_muziek varchar(30) NOT NULL default '', - info text NOT NULL, + info text NOT NULL default '', ipnr varchar(30) NOT NULL default '', PRIMARY KEY (member_id) ) ENGINE=MyISAM PACK_KEYS=1; @@ -340,7 +351,9 @@ CREATE TABLE t2 ( INSERT INTO t1 (titre,auteur,dest) VALUES ('test','joce','bug'); INSERT INTO t2 (numeropost,pseudo) VALUES (1,'joce'),(1,'bug'); SELECT titre,t1.numeropost,auteur,icone,nbrep,0,date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30; +SELECT titre,numeropost,auteur,icone,nbrep,0,date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30; SELECT titre,t1.numeropost,auteur,icone,nbrep,'0',date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30; +SELECT titre,numeropost,auteur,icone,nbrep,'0',date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30; drop table t1,t2; # @@ -501,6 +514,11 @@ set max_sort_length=20; select a from t1 order by a; drop table t1; +create table t1 (a int not null, b int not null, c int not null); +insert t1 values (1,1,1),(1,1,2),(1,2,1); +select a, b from t1 group by a, b order by sum(c); +drop table t1; + # # Bug #7331 # @@ -560,3 +578,35 @@ INSERT INTO t1 VALUES (1,30), (2,20), (1,10), (2,30), (1,20), (2,10); DROP TABLE t1; # End of 4.1 tests + +# +# Bug#21302: Result not properly sorted when using an ORDER BY on a second +# table in a join +# +CREATE TABLE t1 (a int, b int, PRIMARY KEY (a)); +INSERT INTO t1 VALUES (1,1), (2,2), (3,3); + +explain SELECT t1.b as a, t2.b as c FROM + t1 LEFT JOIN t1 t2 ON (t1.a = t2.a AND t2.a = 2) +ORDER BY c; +SELECT t2.b as c FROM + t1 LEFT JOIN t1 t2 ON (t1.a = t2.a AND t2.a = 2) +ORDER BY c; + +# check that it still removes sort of const table +explain SELECT t1.b as a, t2.b as c FROM + t1 JOIN t1 t2 ON (t1.a = t2.a AND t2.a = 2) +ORDER BY c; + +CREATE TABLE t2 LIKE t1; +INSERT INTO t2 SELECT * from t1; +CREATE TABLE t3 LIKE t1; +INSERT INTO t3 SELECT * from t1; +CREATE TABLE t4 LIKE t1; +INSERT INTO t4 SELECT * from t1; +INSERT INTO t1 values (0,0),(4,4); + +SELECT t2.b FROM t1 LEFT JOIN (t2, t3 LEFT JOIN t4 ON t3.a=t4.a) +ON (t1.a=t2.a AND t1.b=t3.b) order by t2.b; + +DROP TABLE t1,t2,t3,t4; diff --git a/mysql-test/t/outfile.test b/mysql-test/t/outfile.test index 81fcc7fd564..c48e6c9730d 100644 --- a/mysql-test/t/outfile.test +++ b/mysql-test/t/outfile.test @@ -1,6 +1,7 @@ disable_query_log; -- source include/test_outfile.inc -eval set @tmpdir="$MYSQL_TEST_DIR/var/tmp"; +# Server are started in "var/master-data", so "../tmp" will be "var/tmp" +eval set @tmpdir="../tmp"; enable_query_log; -- source include/have_outfile.inc @@ -15,41 +16,42 @@ drop table if exists t1; create table t1 (`a` blob); insert into t1 values("hello world"),("Hello mars"),(NULL); disable_query_log; -eval select * into outfile "$MYSQL_TEST_DIR/var/tmp/outfile-test.1" from t1; +eval select * into outfile "../tmp/outfile-test.1" from t1; enable_query_log; select load_file(concat(@tmpdir,"/outfile-test.1")); disable_query_log; -eval select * into dumpfile "$MYSQL_TEST_DIR/var/tmp/outfile-test.2" from t1 limit 1; +eval select * into dumpfile "../tmp/outfile-test.2" from t1 limit 1; enable_query_log; select load_file(concat(@tmpdir,"/outfile-test.2")); disable_query_log; -eval select * into dumpfile "$MYSQL_TEST_DIR/var/tmp/outfile-test.3" from t1 where a is null; +eval select * into dumpfile "../tmp/outfile-test.3" from t1 where a is null; enable_query_log; select load_file(concat(@tmpdir,"/outfile-test.3")); # the following should give errors -#disabled as error message has variable path -#disable_query_log; -#--error 1086 -#eval select * into outfile "$MYSQL_TEST_DIR/var/tmp/outfile-test.1" from t1; -#--error 1086 -#eval select * into dumpfile "$MYSQL_TEST_DIR/var/tmp/outfile-test.2" from t1; -#--error 1086 -#eval select * into dumpfile "$MYSQL_TEST_DIR/var/tmp/outfile-test.3" from t1; -#enable_query_log; +disable_query_log; +--error 1086 +eval select * into outfile "../tmp/outfile-test.1" from t1; + +--error 1086 +eval select * into dumpfile "../tmp/outfile-test.2" from t1; + +--error 1086 +eval select * into dumpfile "../tmp/outfile-test.3" from t1; +enable_query_log; select load_file(concat(@tmpdir,"/outfile-test.not-exist")); ---exec rm $MYSQL_TEST_DIR/var/tmp/outfile-test.1 ---exec rm $MYSQL_TEST_DIR/var/tmp/outfile-test.2 ---exec rm $MYSQL_TEST_DIR/var/tmp/outfile-test.3 +--exec rm $MYSQLTEST_VARDIR/tmp/outfile-test.1 +--exec rm $MYSQLTEST_VARDIR/tmp/outfile-test.2 +--exec rm $MYSQLTEST_VARDIR/tmp/outfile-test.3 drop table t1; # Bug#8191 disable_query_log; -eval select 1 into outfile "$MYSQL_TEST_DIR/var/tmp/outfile-test.4"; +eval select 1 into outfile "../tmp/outfile-test.4"; enable_query_log; select load_file(concat(@tmpdir,"/outfile-test.4")); ---exec rm $MYSQL_TEST_DIR/var/tmp/outfile-test.4 +--exec rm $MYSQLTEST_VARDIR/tmp/outfile-test.4 # # Bug #5382: 'explain select into outfile' crashes the server @@ -64,3 +66,21 @@ EXPLAIN DROP TABLE t1; # End of 4.1 tests + +# +# Bug#13202 SELECT * INTO OUTFILE ... FROM information_schema.schemata now fails +# +disable_query_log; +eval SELECT * INTO OUTFILE "../tmp/outfile-test.4" +FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' +FROM information_schema.schemata LIMIT 0, 5; +# enable_query_log; +--exec rm $MYSQLTEST_VARDIR/tmp/outfile-test.4 + +use information_schema; +# disable_query_log; +eval SELECT * INTO OUTFILE "../tmp/outfile-test.4" +FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' +FROM schemata LIMIT 0, 5; +enable_query_log; +--exec rm $MYSQLTEST_VARDIR/tmp/outfile-test.4 diff --git a/mysql-test/t/perror.test b/mysql-test/t/perror.test new file mode 100644 index 00000000000..a4b99d8aa22 --- /dev/null +++ b/mysql-test/t/perror.test @@ -0,0 +1,19 @@ +# +# Check if the variable MY_PERROR is set +# +--require r/have_perror.require +disable_query_log; +eval select LENGTH("$MY_PERROR") > 0 as "have_perror"; +enable_query_log; + +--exec $MY_PERROR 150 > /dev/null +--exec $MY_PERROR --silent 120 > /dev/null + +# +# Bug#16561 Unknown ERROR msg "ERROR 1186 (HY000): Binlog closed" by perror +# + +# Test with error code 10000 as it's a common "unknown error" +# As there is no error code defined for 10000, expect error +--error 1 +--exec $MY_PERROR 10000 2>&1 diff --git a/mysql-test/t/ps-master.opt b/mysql-test/t/ps-master.opt new file mode 100644 index 00000000000..3eb98fc3d6b --- /dev/null +++ b/mysql-test/t/ps-master.opt @@ -0,0 +1 @@ +--log-slow-queries --log-long-format --log-queries-not-using-indexes diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 5b488ae4393..8d01277b515 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -3,6 +3,9 @@ # --disable_warnings drop table if exists t1,t2; + +# Avoid wrong warnings if mysql_client_test fails +drop database if exists client_test_db; --enable_warnings create table t1 @@ -149,7 +152,7 @@ create table t1 c1 tinyint, c2 smallint, c3 mediumint, c4 int, c5 integer, c6 bigint, c7 float, c8 double, c9 double precision, c10 real, c11 decimal(7, 4), c12 numeric(8, 4), - c13 date, c14 datetime, c15 timestamp(14), c16 time, + c13 date, c14 datetime, c15 timestamp, c16 time, c17 year, c18 bit, c19 bool, c20 char, c21 char(10), c22 varchar(30), c23 tinyblob, c24 tinytext, c25 blob, c26 text, c27 mediumblob, c28 mediumtext, @@ -487,6 +490,42 @@ execute stmt; deallocate prepare stmt; drop table t1, t2; +# +# +# Bug#19399 "Stored Procedures 'Lost Connection' when dropping/creating +# tables" +# Check that multi-delete tables are also cleaned up before re-execution. +# +--disable_warnings +drop table if exists t1; +create temporary table if not exists t1 (a1 int); +--enable_warnings +# exact delete syntax is essential +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); +# the server crashed on the next statement without the fix +execute 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 case +execute stmt; +drop temporary table t1; +create temporary table if not exists t1 (a1 int); +execute stmt; +drop temporary table t1; +deallocate prepare stmt; + +# 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 1305 +prepare stmt FROM 'SELECT char_length (a) FROM t1'; +drop table t1; # # Bug #6089: FOUND_ROWS returns wrong values when no table/view is used @@ -524,6 +563,7 @@ set @a=200887, @b=860; # this query did not return all matching rows execute stmt using @a, @b; deallocate prepare stmt; + drop table t1; # @@ -583,7 +623,6 @@ execute stmt; execute stmt; deallocate prepare stmt; drop table t1; - # # Bug#11458 "Prepared statement with subselects return random data": # drop PARAM_TABLE_BIT from the list of tables used by a subquery @@ -652,7 +691,6 @@ execute stmt using @user_id, @id; execute stmt using @user_id, @id; deallocate prepare stmt; drop table t1, t2, t3, t4; - # # Bug#9379: make sure that Item::collation is reset when one sets # a parameter marker from a string variable. @@ -767,7 +805,6 @@ execute stmt using @like; deallocate prepare stmt; drop table t1; - # # Bug#13134 "Length of VARCHAR() utf8 column is increasing when table is # recreated with PS/SP" @@ -838,17 +875,17 @@ set global max_prepared_stmt_count=10000000000000000; select @@max_prepared_stmt_count; set global max_prepared_stmt_count=default; select @@max_prepared_stmt_count; ---error 1229 # ER_GLOBAL_VARIABLE +--error ER_GLOBAL_VARIABLE set @@max_prepared_stmt_count=1; ---error 1229 # ER_GLOBAL_VARIABLE +--error ER_GLOBAL_VARIABLE set max_prepared_stmt_count=1; ---error 1229 # ER_GLOBAL_VARIABLE +--error ER_GLOBAL_VARIABLE set local max_prepared_stmt_count=1; ---error 1229 # ER_GLOBAL_VARIABLE +--error ER_INCORRECT_GLOBAL_LOCAL_VAR set local prepared_stmt_count=0; ---error 1229 # ER_GLOBAL_VARIABLE +--error ER_INCORRECT_GLOBAL_LOCAL_VAR 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 to a reasonable limit works set global max_prepared_stmt_count=1; @@ -858,13 +895,13 @@ select @@max_prepared_stmt_count; # set global max_prepared_stmt_count=0; 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"; select @@prepared_stmt_count; set global max_prepared_stmt_count=1; prepare stmt from "select 1"; select @@prepared_stmt_count; ---error 1105 # ER_UNKNOWN_ERROR +--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt1 from "select 1"; select @@prepared_stmt_count; deallocate prepare stmt; @@ -883,13 +920,13 @@ select @@prepared_stmt_count; # select @@prepared_stmt_count, @@max_prepared_stmt_count; set global max_prepared_stmt_count=0; ---error 1105 # ER_UNKNOWN_ERROR +--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt from "select 1"; # Result: the old statement is deallocated, the new is not created. --error 1243 # ER_UNKNOWN_STMT_HANDLER execute stmt; select @@prepared_stmt_count; ---error 1105 # ER_UNKNOWN_ERROR +--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt from "select 1"; select @@prepared_stmt_count; # @@ -903,10 +940,10 @@ connect (con1,localhost,root,,); connection con1; prepare stmt from "select 2"; prepare stmt1 from "select 3"; ---error 1105 # ER_UNKNOWN_ERROR +--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt2 from "select 4"; connection default; ---error 1105 # ER_UNKNOWN_ERROR +--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt2 from "select 4"; select @@max_prepared_stmt_count, @@prepared_stmt_count; disconnect con1; @@ -1077,3 +1114,436 @@ 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 1305 +prepare 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 query +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; +execute stmt; +execute stmt; + +# original query +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; +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 mode +delimiter |; +--disable_warnings +drop procedure if exists p1| +drop table if exists t1| +--enable_warnings +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| +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 1235 +prepare 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; + + + +# +# Bug #14956: ROW_COUNT() returns incorrect result after EXECUTE of prepared +# statement +# +create table t1 (id int); +prepare ins_call from "insert into t1 (id) values (1)"; +execute ins_call; +select row_count(); +drop table t1; + +# +# BUG#16474: SP crashed MySQL +# (when using "order by localvar", where 'localvar' is just that. +# The actual bug test is in sp.test, this is just testing that we get the +# expected result for prepared statements too, i.e. place holders work as +# textual substitution. If it's a single integer, it works as the (deprecated) +# "order by column#", otherwise it's an expression. +# +create table t1 (a int, b int); +insert into t1 (a,b) values (2,8),(1,9),(3,7); + +# Will order by index +prepare stmt from "select * from t1 order by ?"; +set @a=NULL; +execute stmt using @a; +set @a=1; +execute stmt using @a; +set @a=2; +execute stmt using @a; +deallocate prepare stmt; +# For reference: +select * from t1 order by 1; + +# Will not order by index. +prepare stmt from "select * from t1 order by ?+1"; +set @a=0; +execute stmt using @a; +set @a=1; +execute stmt using @a; +deallocate prepare stmt; +# For reference: +select * from t1 order by 1+1; + +drop table t1; + +# +# Bug#19308 "REPAIR/OPTIMIZE/ANALYZE supported in SP but not in PS". +# Add test coverage for the added commands. +# +create table t1 (a int); +create table t2 like t1; +create table t3 like t2; +prepare stmt from "repair table t1"; +execute stmt; +execute stmt; +prepare stmt from "optimize table t1"; +execute stmt; +execute stmt; +prepare stmt from "analyze table t1"; +execute stmt; +execute stmt; +prepare stmt from "repair table t1, t2, t3"; +execute stmt; +execute stmt; +prepare stmt from "optimize table t1, t2, t3"; +execute stmt; +execute stmt; +prepare stmt from "analyze table t1, t2, t3"; +execute stmt; +execute stmt; +prepare stmt from "repair table t1, t4, t3"; +execute stmt; +execute stmt; +prepare stmt from "optimize table t1, t3, t4"; +execute stmt; +execute stmt; +prepare stmt from "analyze table t4, t1"; +execute stmt; +execute stmt; +deallocate prepare stmt; +drop table t1, t2, t3; + +# +# Bug#17199 "Table not found" error occurs if the query contains a call +# to a function from another database. +# Test prepared statements- related behaviour. +# +# +# ALTER TABLE RENAME and Prepared Statements: wrong DB name buffer was used +# in ALTER ... RENAME which caused memory corruption in prepared statements. +# No need to fix this problem in 4.1 as ALTER TABLE is not allowed in +# Prepared Statements in 4.1. +# +create database mysqltest_long_database_name_to_thrash_heap; +use test; +create table t1 (i int); +prepare stmt from "alter table test.t1 rename t1"; +use mysqltest_long_database_name_to_thrash_heap; +execute stmt; +show tables like 't1'; +prepare stmt from "alter table test.t1 rename t1"; +use test; +execute stmt; +show tables like 't1'; +use mysqltest_long_database_name_to_thrash_heap; +show tables like 't1'; +deallocate prepare stmt; +# +# Check that a prepared statement initializes its current database at +# PREPARE, and then works correctly even if the current database has been +# changed. +# +use mysqltest_long_database_name_to_thrash_heap; +# Necessary for preparation of INSERT/UPDATE/DELETE to succeed +prepare stmt_create from "create table t1 (i int)"; +prepare stmt_insert from "insert into t1 (i) values (1)"; +prepare stmt_update from "update t1 set i=2"; +prepare stmt_delete from "delete from t1 where i=2"; +prepare stmt_select from "select * from t1"; +prepare stmt_alter from "alter table t1 add column (b int)"; +prepare stmt_alter1 from "alter table t1 drop column b"; +prepare stmt_analyze from "analyze table t1"; +prepare stmt_optimize from "optimize table t1"; +prepare stmt_show from "show tables like 't1'"; +prepare stmt_truncate from "truncate table t1"; +prepare stmt_drop from "drop table t1"; +# Drop the table that was used to prepare INSERT/UPDATE/DELETE: we will +# create a new one by executing stmt_create +drop table t1; +# Switch the current database +use test; +# Check that all prepared statements operate on the database that was +# active at PREPARE +execute stmt_create; +# should return empty set +show tables like 't1'; +use mysqltest_long_database_name_to_thrash_heap; +show tables like 't1'; +use test; +execute stmt_insert; +select * from mysqltest_long_database_name_to_thrash_heap.t1; +execute stmt_update; +select * from mysqltest_long_database_name_to_thrash_heap.t1; +execute stmt_delete; +execute stmt_select; +execute stmt_alter; +show columns from mysqltest_long_database_name_to_thrash_heap.t1; +execute stmt_alter1; +show columns from mysqltest_long_database_name_to_thrash_heap.t1; +execute stmt_analyze; +execute stmt_optimize; +execute stmt_show; +execute stmt_truncate; +execute stmt_drop; +show tables like 't1'; +use mysqltest_long_database_name_to_thrash_heap; +show tables like 't1'; +# +# Attempt a statement PREPARE when there is no current database: +# is expected to return an error. +# +drop database mysqltest_long_database_name_to_thrash_heap; +--error ER_NO_DB_ERROR +prepare stmt_create from "create table t1 (i int)"; +--error ER_NO_DB_ERROR +prepare stmt_insert from "insert into t1 (i) values (1)"; +--error ER_NO_DB_ERROR +prepare stmt_update from "update t1 set i=2"; +--error ER_NO_DB_ERROR +prepare stmt_delete from "delete from t1 where i=2"; +--error ER_NO_DB_ERROR +prepare stmt_select from "select * from t1"; +--error ER_NO_DB_ERROR +prepare stmt_alter from "alter table t1 add column (b int)"; +--error ER_NO_DB_ERROR +prepare stmt_alter1 from "alter table t1 drop column b"; +--error ER_NO_DB_ERROR +prepare stmt_analyze from "analyze table t1"; +--error ER_NO_DB_ERROR +prepare stmt_optimize from "optimize table t1"; +--error ER_NO_DB_ERROR +prepare stmt_show from "show tables like 't1'"; +--error ER_NO_DB_ERROR +prepare stmt_truncate from "truncate table t1"; +--error ER_NO_DB_ERROR +prepare stmt_drop from "drop table t1"; +# +# The above has automatically deallocated all our statements. +# +# Attempt to CREATE a temporary table when no DB used: it should fail +# This proves that no table can be used without explicit specification of +# its database if there is no current database. +# +--error ER_NO_DB_ERROR +create temporary table t1 (i int); +# +# Restore the old environemnt +# +use test; + + +# +# BUG#21166: Prepared statement causes signal 11 on second execution +# +# Changes in an item tree done by optimizer weren't properly +# registered and went unnoticed, which resulted in preliminary freeing +# of used memory. +# +--disable_warnings +DROP TABLE IF EXISTS t1, t2, t3; +--enable_warnings + +CREATE TABLE t1 (i BIGINT, j BIGINT); +CREATE TABLE t2 (i BIGINT); +CREATE TABLE t3 (i BIGINT, j BIGINT); + +PREPARE stmt FROM "SELECT * FROM t1 JOIN t2 ON (t2.i = t1.i) + LEFT JOIN t3 ON ((t3.i, t3.j) = (t1.i, t1.j)) + WHERE t1.i = ?"; + +SET @a= 1; +EXECUTE stmt USING @a; +EXECUTE stmt USING @a; + +DEALLOCATE PREPARE stmt; +DROP TABLE IF EXISTS t1, t2, t3; + + +# +# BUG#21081: SELECT inside stored procedure returns wrong results +# +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings + +CREATE TABLE t1 (i INT KEY); +CREATE TABLE t2 (i INT); + +INSERT INTO t1 VALUES (1), (2); +INSERT INTO t2 VALUES (1); + +PREPARE stmt FROM "SELECT t2.i FROM t1 LEFT JOIN t2 ON t2.i = t1.i + WHERE t1.i = ?"; + +SET @arg= 1; +EXECUTE stmt USING @arg; +SET @arg= 2; +EXECUTE stmt USING @arg; +SET @arg= 1; +EXECUTE stmt USING @arg; + +DEALLOCATE PREPARE stmt; +DROP TABLE t1, t2; + + +# +# BUG#21856: Prepared Statments: crash if bad create +# +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +let $iterations= 100; +--disable_query_log +--disable_result_log +while ($iterations > 0) +{ + --error ER_PARSE_ERROR + PREPARE stmt FROM "CREATE PROCEDURE p1()"; + dec $iterations; +} +--enable_query_log +--enable_result_log + +# +# Bug 19764: SHOW commands end up in the slow log as table scans +# + +flush status; +prepare sq from 'show status like "slow_queries"'; +execute sq; +prepare no_index from 'select 1 from information_schema.tables limit 1'; +execute sq; +execute no_index; +execute sq; +deallocate prepare no_index; +deallocate prepare sq; + +--echo End of 5.0 tests. diff --git a/mysql-test/t/ps_11bugs.test b/mysql-test/t/ps_11bugs.test index ff1c87f3bd8..515bcc03c1a 100644 --- a/mysql-test/t/ps_11bugs.test +++ b/mysql-test/t/ps_11bugs.test @@ -144,3 +144,37 @@ prepare st_18492 from 'select * from t1 where 3 in (select (1+1) union select 1) execute st_18492; drop table t1; + +# +# Bug#19356: Assertion failure with undefined @uservar in prepared statement execution +# +create table t1 (a int, b varchar(4)); +create table t2 (a int, b varchar(4), primary key(a)); + +prepare stmt1 from 'insert into t1 (a, b) values (?, ?)'; +prepare stmt2 from 'insert into t2 (a, b) values (?, ?)'; + +set @intarg= 11; +set @varchararg= '2222'; +execute stmt1 using @intarg, @varchararg; +execute stmt2 using @intarg, @varchararg; +set @intarg= 12; +execute stmt1 using @intarg, @UNDEFINED; +execute stmt2 using @intarg, @UNDEFINED; +set @intarg= 13; +execute stmt1 using @UNDEFINED, @varchararg; +--error 1048 +execute stmt2 using @UNDEFINED, @varchararg; +set @intarg= 14; +set @nullarg= Null; +execute stmt1 using @UNDEFINED, @nullarg; +--error 1048 +execute stmt2 using @nullarg, @varchararg; + +select * from t1; +select * from t2; + +drop table t1; +drop table t2; + +--echo End of 5.0 tests. diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test index ec4964d116a..33b86dde9ed 100644 --- a/mysql-test/t/ps_1general.test +++ b/mysql-test/t/ps_1general.test @@ -11,7 +11,12 @@ --disable_warnings drop table if exists t5, t6, t7, t8; drop database if exists mysqltest ; + +# Cleanup from other tests drop database if exists client_test_db; +drop database if exists testtets; +drop table if exists t1Aa,t2Aa,v1Aa,v2Aa; +drop view if exists t1Aa,t2Aa,v1Aa,v2Aa; --enable_warnings --disable_query_log @@ -287,6 +292,14 @@ prepare stmt4 from ' show databases '; execute stmt4; prepare stmt4 from ' show tables from test like ''t2%'' '; execute stmt4; +prepare stmt4 from ' show columns from t2 where field in (select ?) '; +SET @arg00="a"; +execute stmt4 using @arg00; +SET @arg00="b"; +execute stmt4 using @arg00; +SET @arg00=1; +execute stmt4 using @arg00; + prepare stmt4 from ' show columns from t2 from test like ''a%'' '; execute stmt4; create index t2_idx on t2(b); @@ -294,15 +307,13 @@ prepare stmt4 from ' show index from t2 from test '; execute stmt4; prepare stmt4 from ' show table status from test like ''t2%'' '; # egalize date and time values ---replace_column 12 # 13 # 14 # ---replace_result 2147483647 64424509439 +--replace_column 8 # 12 # 13 # 14 # # Bug#4288 : prepared statement 'show table status ..', wrong output on execute execute stmt4; # try the same with the big table prepare stmt4 from ' show table status from test like ''t9%'' '; # egalize date and time values ---replace_column 12 # 13 # 14 # ---replace_result 2147483647 4294967295 +--replace_column 8 # 12 # 13 # 14 # # Bug#4288 execute stmt4; prepare stmt4 from ' show status like ''Threads_running'' '; @@ -424,20 +435,6 @@ create database mysqltest ; prepare stmt3 from ' drop database mysqltest '; drop database mysqltest ; -## grant/revoke + drop user ---error 1295 -prepare stmt3 from ' grant all on test.t1 to drop_user@localhost -identified by ''looser'' '; -grant all on test.t1 to drop_user@localhost -identified by 'looser' ; ---error 1295 -prepare stmt3 from ' revoke all privileges on test.t1 from -drop_user@localhost '; -revoke all privileges on test.t1 from drop_user@localhost ; ---error 1295 -prepare stmt3 from ' drop user drop_user@localhost '; -drop user drop_user@localhost; - #### table related commands ## describe prepare stmt3 from ' describe t2 '; @@ -457,13 +454,10 @@ into table t1 fields terminated by ''\t'' '; prepare stmt1 from ' select * into outfile ''data.txt'' from t1 '; execute stmt1 ; ## ---error 1295 prepare stmt1 from ' optimize table t1 ' ; ---error 1295 prepare stmt1 from ' analyze table t1 ' ; --error 1295 prepare stmt1 from ' checksum table t1 ' ; ---error 1295 prepare stmt1 from ' repair table t1 ' ; --error 1295 prepare stmt1 from ' restore table t1 from ''data.txt'' ' ; @@ -473,9 +467,7 @@ prepare stmt1 from ' handler t1 open '; ## commit/rollback ---error 1295 prepare stmt3 from ' commit ' ; ---error 1295 prepare stmt3 from ' rollback ' ; @@ -487,10 +479,10 @@ select 'a' || 'b' ; prepare stmt4 from ' SET sql_mode="" '; execute stmt4; # check if the sql_mode is not ansi -select 'a' || 'b' ; +select '2' || '3' ; # Will a switch of the sqlmode affect the execution of already prepared # statements ? -prepare stmt5 from ' select ''a'' || ''b'' ' ; +prepare stmt5 from ' select ''2'' || ''3'' ' ; execute stmt5; SET sql_mode=ansi; execute stmt5; @@ -576,11 +568,8 @@ execute stmt3 using @arg00; select m from t3; drop table t3; ---error 1295 prepare stmt3 from ' create index t2_idx on t2(b) '; ---error 1295 prepare stmt3 from ' drop index t2_idx on t2 ' ; ---error 1295 prepare stmt3 from ' alter table t2 drop primary key '; ## RENAME TABLE @@ -599,7 +588,7 @@ prepare stmt1 from ' rename table t5 to t6, t7 to t8 ' ; create table t5 (a int) ; # rename must fail, t7 does not exist # Clean up the filename here because embedded server reports whole path ---replace_result \\ / $MYSQL_TEST_DIR . /var/master-data/ / +--replace_result \\ / $MYSQL_TEST_DIR . /var/master-data/ / t7.frm t7 --error 1017 execute stmt1 ; create table t7 (a int) ; @@ -840,7 +829,7 @@ execute stmt1 ; --disable_metadata --horizontal_results -drop table t5 ; +drop table t1, t5, t9; ##### RULES OF THUMB TO PRESERVE THE SYSTEMATICS OF THE PS TEST CASES ##### # diff --git a/mysql-test/t/ps_4heap.test b/mysql-test/t/ps_4heap.test index 9538224bb95..f16d4599a74 100644 --- a/mysql-test/t/ps_4heap.test +++ b/mysql-test/t/ps_4heap.test @@ -31,11 +31,11 @@ eval create table t9 c1 tinyint, c2 smallint, c3 mediumint, c4 int, c5 integer, c6 bigint, c7 float, c8 double, c9 double precision, c10 real, c11 decimal(7, 4), c12 numeric(8, 4), - c13 date, c14 datetime, c15 timestamp(14), c16 time, - c17 year, c18 bit, c19 bool, c20 char, - c21 char(10), c22 varchar(30), c23 char(100), c24 char(100), - c25 char(100), c26 char(100), c27 char(100), c28 char(100), - c29 char(100), c30 char(100), c31 enum('one', 'two', 'three'), + c13 date, c14 datetime, c15 timestamp, c16 time, + c17 year, c18 tinyint, c19 bool, c20 char, + c21 char(10), c22 varchar(30), c23 varchar(100), c24 varchar(100), + c25 varchar(100), c26 varchar(100), c27 varchar(100), c28 varchar(100), + c29 varchar(100), c30 varchar(100), c31 enum('one', 'two', 'three'), c32 set('monday', 'tuesday', 'wednesday'), primary key(c1) ) engine = $type ; diff --git a/mysql-test/t/ps_5merge.test b/mysql-test/t/ps_5merge.test index 3f4468d569f..e6ce9bf42d3 100644 --- a/mysql-test/t/ps_5merge.test +++ b/mysql-test/t/ps_5merge.test @@ -31,8 +31,8 @@ create table t9 c1 tinyint, c2 smallint, c3 mediumint, c4 int, c5 integer, c6 bigint, c7 float, c8 double, c9 double precision, c10 real, c11 decimal(7, 4), c12 numeric(8, 4), - c13 date, c14 datetime, c15 timestamp(14), c16 time, - c17 year, c18 bit, c19 bool, c20 char, + c13 date, c14 datetime, c15 timestamp, c16 time, + c17 year, c18 tinyint, c19 bool, c20 char, c21 char(10), c22 varchar(30), c23 tinyblob, c24 tinytext, c25 blob, c26 text, c27 mediumblob, c28 mediumtext, c29 longblob, c30 longtext, c31 enum('one', 'two', 'three'), @@ -62,8 +62,8 @@ create table t9 c1 tinyint, c2 smallint, c3 mediumint, c4 int, c5 integer, c6 bigint, c7 float, c8 double, c9 double precision, c10 real, c11 decimal(7, 4), c12 numeric(8, 4), - c13 date, c14 datetime, c15 timestamp(14), c16 time, - c17 year, c18 bit, c19 bool, c20 char, + c13 date, c14 datetime, c15 timestamp, c16 time, + c17 year, c18 tinyint, c19 bool, c20 char, c21 char(10), c22 varchar(30), c23 tinyblob, c24 tinytext, c25 blob, c26 text, c27 mediumblob, c28 mediumtext, c29 longblob, c30 longtext, c31 enum('one', 'two', 'three'), diff --git a/mysql-test/t/ps_grant.test b/mysql-test/t/ps_grant.test index afd543caacc..22ac8675328 100644 --- a/mysql-test/t/ps_grant.test +++ b/mysql-test/t/ps_grant.test @@ -113,3 +113,19 @@ show grants for second_user@localhost ; drop database mysqltest; # End of 4.1 tests + +# +# grant/revoke + drop user +# +--error 1295 +prepare stmt3 from ' grant all on test.t1 to drop_user@localhost +identified by ''looser'' '; +grant all on test.t1 to drop_user@localhost +identified by 'looser' ; +--error 1295 +prepare stmt3 from ' revoke all privileges on test.t1 from +drop_user@localhost '; +revoke all privileges on test.t1 from drop_user@localhost ; +--error 1295 +prepare stmt3 from ' drop user drop_user@localhost '; +drop user drop_user@localhost; diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test index 3140739309e..d86f1a464b1 100644 --- a/mysql-test/t/query_cache.test +++ b/mysql-test/t/query_cache.test @@ -554,9 +554,8 @@ set character_set_results=cp1251; SELECT a,'Â','â'='Â' FROM t1; show status like "Qcache_hits"; show status like "Qcache_queries_in_cache"; -# -# Keep things tidy -# +SET NAMES default; + DROP TABLE t1; # @@ -576,7 +575,6 @@ DROP TABLE t1; set character_set_results=null; select @@character_set_results; set character_set_results=default; - # # query cache and environment variables # @@ -611,7 +609,36 @@ select group_concat(a) FROM t1 group by b; set group_concat_max_len=default; drop table t1; +# comments before command +# +create table t1 (a int); +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +/**/ select * from t1; +/**/ select * from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +# +# Keep things tidy +# +DROP TABLE t1; +SET GLOBAL query_cache_size=0; + +# +# Information schema & query cache test +# +SET SESSION query_cache_type = 2; +create table t1(a int); +select table_name from information_schema.tables +where table_schema="test"; +drop table t1; +select table_name from information_schema.tables +where table_schema="test"; # Bug #8480: REPAIR TABLE needs to flush the table from the query cache +SET SESSION query_cache_type = 1; set global query_cache_size=1024*1024; flush query cache; create table t1 ( a int ); @@ -623,9 +650,10 @@ repair table t1; show status like 'qcache_queries_in_cache'; drop table t1; +# # Bug #9549: Make sure cached queries that span more than one cache block # are handled properly in the embedded server. - +# # We just want a small query cache, so we can fragment it easily set GLOBAL query_cache_size=64*1024; # This actually gives us a usable cache size of about 48K @@ -667,6 +695,8 @@ select a from t1; flush query cache; drop table t1, t2; +set GLOBAL query_cache_size=1355776; + # # Query with warning prohibited to query cache (BUG#9414) @@ -726,7 +756,117 @@ show status like "Qcache_queries_in_cache"; show status like "Qcache_inserts"; show status like "Qcache_hits"; drop table t1; +# SP cursors and selects with query cache (BUG#9715) +# +create table t1 (a int); +insert into t1 values (1),(2); +delimiter //; +CREATE PROCEDURE `p1`() +begin +Declare c1 cursor for select a from t1; +open c1; +select * from t1; +end// +call p1()// +drop procedure p1; + +create function f1() returns int +begin +Declare var1 int; +select max(a) from t1 into var1; +return var1; +end// +create procedure `p1`() +begin + select a, f1() from t1; +end// +call p1()// +drop procedure p1// +drop function f1// + +drop table t1// +delimiter ;// + +# +# query in QC from normal execution and SP (BUG#6897) +# improved to also test BUG#3583 and BUG#12990 +# +flush query cache; +reset query cache; +flush status; +delimiter //; +create table t1 (s1 int)// +create procedure f1 () begin +select sql_cache * from t1; +select sql_cache * from t1; +select sql_cache * from t1; +end;// +create procedure f2 () begin +select sql_cache * from t1 where s1=1; +select sql_cache * from t1; +end;// +create procedure f3 () begin +select sql_cache * from t1; +select sql_cache * from t1 where s1=1; +end;// +create procedure f4 () begin +select sql_cache * from t1; +select sql_cache * from t1 where s1=1; +select sql_cache * from t1; +select sql_cache * from t1 where s1=1; +select sql_cache * from t1 where s1=1; +end;// +delimiter ;// +call f1(); +call f1(); +call f1(); +select sql_cache * from t1; +insert into t1 values (1); +select sql_cache * from t1; +call f1(); +call f1(); +select sql_cache * from t1; +flush query cache; +reset query cache; +flush status; +select sql_cache * from t1; +select sql_cache * from t1 where s1=1; +call f1(); +call f2(); +call f3(); +call f4(); +call f4(); +call f3(); +call f2(); +select sql_cache * from t1 where s1=1; +insert into t1 values (2); +call f1(); +select sql_cache * from t1 where s1=1; +select sql_cache * from t1; +call f1(); +call f3(); +call f3(); +call f1(); + +drop procedure f1; +drop procedure f2; +drop procedure f3; +drop procedure f4; +drop table t1; set GLOBAL query_cache_size=0; # End of 4.1 tests + +# +# Bug #10303: problem with last_query_cost +# + +SET GLOBAL query_cache_size=102400; +create table t1(a int); +insert into t1 values(0), (1), (4), (5); +select * from t1 where a > 3; +select * from t1 where a > 3; +show status like 'last_query_cost'; +drop table t1; +SET GLOBAL query_cache_size=0; diff --git a/mysql-test/t/query_cache_notembedded.test b/mysql-test/t/query_cache_notembedded.test index fd4785ffe95..97be9f9f7ca 100644 --- a/mysql-test/t/query_cache_notembedded.test +++ b/mysql-test/t/query_cache_notembedded.test @@ -97,4 +97,128 @@ connection root; SELECT * FROM t1; drop table t1; +# +# query in QC from normal execution and SP (BUG#6897) +# improved to also test BUG#3583 and BUG#12990 +# +flush query cache; +reset query cache; +flush status; +delimiter //; +create table t1 (s1 int)// +create procedure f1 () begin +select sql_cache * from t1; +select sql_cache * from t1; +select sql_cache * from t1; +end;// +create procedure f2 () begin +select sql_cache * from t1 where s1=1; +select sql_cache * from t1; +end;// +create procedure f3 () begin +select sql_cache * from t1; +select sql_cache * from t1 where s1=1; +end;// +create procedure f4 () begin +select sql_cache * from t1; +select sql_cache * from t1 where s1=1; +select sql_cache * from t1; +select sql_cache * from t1 where s1=1; +select sql_cache * from t1 where s1=1; +end;// +delimiter ;// +call f1(); +--replace_result 1 3 +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +call f1(); +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +call f1(); +select sql_cache * from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +insert into t1 values (1); +select sql_cache * from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +call f1(); +call f1(); +select sql_cache * from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +flush query cache; +reset query cache; +flush status; +select sql_cache * from t1; +select sql_cache * from t1 where s1=1; +call f1(); +call f2(); +call f3(); +call f4(); +call f4(); +call f3(); +call f2(); +select sql_cache * from t1 where s1=1; +insert into t1 values (2); +call f1(); +select sql_cache * from t1 where s1=1; +select sql_cache * from t1; +call f1(); +call f3(); +call f3(); +call f1(); + +drop procedure f1; +drop procedure f2; +drop procedure f3; +drop procedure f4; +drop table t1; + +# +# bug#14767: INSERT in SF + concurrent SELECT with query cache +# +reset query cache; +--disable_warnings +drop function if exists f1; +--enable_warnings +create table t1 (id int); +delimiter |; +create function f1 () + returns int +begin + declare i_var int; + set i_var = sleep(3); + insert into t1 values(3); + set i_var = sleep(3); + return 0; +end;| +delimiter ;| + +connect (con1,localhost,root,,); +connect (con2,localhost,root,,); + +connection con1; +send select f1(); +connection con2; +select sleep(4); +select * from t1; +connection con1; +reap; +connection con2; +# This gives wrong result i.e. 't' table seems to be empty +select * from t1; +reset query cache; +select * from t1; +drop table t1; +drop function f1; +disconnect con1; +disconnect con2; +connection default; + set GLOBAL query_cache_size=0; diff --git a/mysql-test/t/range.test b/mysql-test/t/range.test index 245178d7d4a..5a146bbcf86 100644 --- a/mysql-test/t/range.test +++ b/mysql-test/t/range.test @@ -3,7 +3,7 @@ # --disable_warnings -drop table if exists t1, t2; +drop table if exists t1, t2, t3; --enable_warnings CREATE TABLE t1 ( @@ -181,8 +181,8 @@ create table t1 (x int, y int, index(x), index(y)); insert into t1 (x) values (1),(2),(3),(4),(5),(6),(7),(8),(9); update t1 set y=x; # between with only one end fixed -explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 7 and t1.y+0; -explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 7 and t2.x <= t1.y+0; +explain select * from t1, t1 t2 where t1.y = 8 and t2.x between 7 and t1.y+0; +explain select * from t1, t1 t2 where t1.y = 8 and t2.x >= 7 and t2.x <= t1.y+0; # between with both expressions on both ends explain select * from t1, t1 t2 where t1.y = 2 and t2.x between t1.y-1 and t1.y+1; explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= t1.y-1 and t2.x <= t1.y+1; @@ -195,13 +195,15 @@ explain select count(*) from t1 where x in (1,2); drop table t1; # -# bug #1172 +# bug #1172: "Force index" option caused server crash # CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1)); -INSERT INTO t1 VALUES (0),(0),(1),(1); +INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1); CREATE TABLE t2 (keya int(11) NOT NULL default '0', KEY j1 (keya)); INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2); explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3; +explain select * from t1 force index(i1), t2 force index(j1) where + (t1.key1 <t2.keya + 1) and t2.keya=3; DROP TABLE t1,t2; # @@ -376,8 +378,12 @@ insert into t2(id, uid, name) select id, uid, name from t1; select count(*) from t1; select count(*) from t2; +analyze table t1,t2; + explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0; +explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid > 0; explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0; +explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid != 0; select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0; select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0; @@ -400,8 +406,8 @@ select count(*) from t1 where x = 18446744073709551601; create table t2 (x bigint not null); -insert into t2(x) values (0xfffffffffffffff0); -insert into t2(x) values (0xfffffffffffffff1); +insert into t2(x) values (cast(0xfffffffffffffff0+0 as signed)); +insert into t2(x) values (cast(0xfffffffffffffff1+0 as signed)); select * from t2; select count(*) from t2 where x>0; select count(*) from t2 where x=0; @@ -410,8 +416,8 @@ select count(*) from t2 where x < -16; select count(*) from t2 where x = -16; select count(*) from t2 where x > -16; select count(*) from t2 where x = 18446744073709551601; +drop table t1,t2; -drop table t1; --disable_warnings create table t1 (x bigint unsigned not null primary key) engine=innodb; --enable_warnings @@ -489,7 +495,6 @@ drop table t1; create table t1 (a int); insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); -DROP TABLE IF EXISTS t2; CREATE TABLE t2 ( pk1 int(11) NOT NULL, pk2 int(11) NOT NULL, @@ -521,3 +526,227 @@ select a from t1 where a > 'x'; drop table t1; --echo End of 4.1 tests + +# +# Test for optimization request #10561: to use keys for +# NOT IN (c1,...,cn) and NOT BETWEEN c1 AND c2 +# + +CREATE TABLE t1 ( + id int(11) NOT NULL auto_increment, + status varchar(20), + PRIMARY KEY (id), + KEY (status) +); + +INSERT INTO t1 VALUES +(1,'B'), (2,'B'), (3,'B'), (4,'B'), (5,'B'), (6,'B'), +(7,'B'), (8,'B'), (9,'B'), (10,'B'), (11,'B'), (12,'B'), +(13,'B'), (14,'B'), (15,'B'), (16,'B'), (17,'B'), (18,'B'), +(19,'B'), (20,'B'), (21,'B'), (22,'B'), (23,'B'), (24,'B'), +(25,'A'), (26,'A'), (27,'A'), (28,'A'), (29,'A'), (30,'A'), +(31,'A'), (32,'A'), (33,'A'), (34,'A'), (35,'A'), (36,'A'), +(37,'A'), (38,'A'), (39,'A'), (40,'A'), (41,'A'), (42,'A'), +(43,'A'), (44,'A'), (45,'A'), (46,'A'), (47,'A'), (48,'A'), +(49,'A'), (50,'A'), (51,'A'), (52,'A'), (53,'C'), (54,'C'), +(55,'C'), (56,'C'), (57,'C'), (58,'C'), (59,'C'), (60,'C'); + +EXPLAIN SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B'; +EXPLAIN SELECT * FROM t1 WHERE status NOT IN ('A','B'); + +SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B'; +SELECT * FROM t1 WHERE status NOT IN ('A','B'); + +EXPLAIN SELECT status FROM t1 WHERE status <> 'A' AND status <> 'B'; +EXPLAIN SELECT status FROM t1 WHERE status NOT IN ('A','B'); + +EXPLAIN SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B'; +EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B'; + +SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B'; +SELECT * FROM t1 WHERE status < 'A' OR status > 'B'; + +DROP TABLE t1; + +# +# Test for bug #10031: range to be used over a view +# + +CREATE TABLE t1 (a int, b int, primary key(a,b)); + +INSERT INTO t1 VALUES + (1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3),(4,1),(4,2),(4,3); + +CREATE VIEW v1 as SELECT a,b FROM t1 WHERE b=3; + +EXPLAIN SELECT a,b FROM t1 WHERE a < 2 and b=3; +EXPLAIN SELECT a,b FROM v1 WHERE a < 2 and b=3; + +EXPLAIN SELECT a,b FROM t1 WHERE a < 2; +EXPLAIN SELECT a,b FROM v1 WHERE a < 2; + +SELECT a,b FROM t1 WHERE a < 2 and b=3; +SELECT a,b FROM v1 WHERE a < 2 and b=3; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #11853: DELETE statement with a NOT (LIKE/<=>) where condition +# for an indexed attribute +# + +CREATE TABLE t1 (name varchar(15) NOT NULL, KEY idx(name)); +INSERT INTO t1 VALUES ('Betty'), ('Anna'); + +SELECT * FROM t1; +DELETE FROM t1 WHERE name NOT LIKE 'A%a'; +SELECT * FROM t1; + +DROP TABLE t1; + +CREATE TABLE t1 (a int, KEY idx(a)); +INSERT INTO t1 VALUES (NULL), (1), (2), (3); + +SELECT * FROM t1; +DELETE FROM t1 WHERE NOT(a <=> 2); +SELECT * FROM t1; + +DROP TABLE t1; + +# +# BUG#13317: range optimization doesn't work for IN over VIEW. +# +create table t1 (a int, b int, primary key(a,b)); +create view v1 as select a, b from t1; + +INSERT INTO `t1` VALUES +(0,0),(1,0),(2,0),(3,0),(4,0),(5,1),(6,1),(7,1),(8,1),(9,1),(10,2),(11,2),(12,2) +,(13,2),(14,2),(15,3),(16,3),(17,3),(18,3),(19,3); + +--replace_column 9 # +explain select * from t1 where a in (3,4) and b in (1,2,3); +--replace_column 9 # +explain select * from v1 where a in (3,4) and b in (1,2,3); +--replace_column 9 # +explain select * from t1 where a between 3 and 4 and b between 1 and 2; +--replace_column 9 # +explain select * from v1 where a between 3 and 4 and b between 1 and 2; + +drop view v1; +drop table t1; + +# BUG#13455: +create table t3 (a int); +insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1 (a varchar(10), filler char(200), key(a)) charset=binary; +insert into t1 values ('a',''); +insert into t1 values ('a ',''); +insert into t1 values ('a ', ''); +insert into t1 select concat('a', 1000 + A.a + 10 * (B.a + 10 * C.a)), '' + from t3 A, t3 B, t3 C; + +create table t2 (a varchar(10), filler char(200), key(a)); +insert into t2 select * from t1; + +--replace_column 9 # +explain select * from t1 where a between 'a' and 'a '; +--replace_column 9 # +explain select * from t1 where a = 'a' or a='a '; + +--replace_column 9 # +explain select * from t2 where a between 'a' and 'a '; +--replace_column 9 # +explain select * from t2 where a = 'a' or a='a '; + +update t1 set a='b' where a<>'a'; +--replace_column 9 # +explain select * from t1 where a not between 'b' and 'b'; +select a, hex(filler) from t1 where a not between 'b' and 'b'; + +drop table t1,t2,t3; + +# +# BUG#21282 +# +create table t1 (a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t2 (a int, key(a)); +insert into t2 select 2*(A.a + 10*(B.a + 10*C.a)) from t1 A, t1 B, t1 C; + +set @a="select * from t2 force index (a) where a NOT IN(0"; +select count(*) from (select @a:=concat(@a, ',', a) from t2 ) Z; +set @a=concat(@a, ')'); + +insert into t2 values (11),(13),(15); + +set @b= concat("explain ", @a); + +prepare stmt1 from @b; +execute stmt1; + +prepare stmt1 from @a; +execute stmt1; + +drop table t1, t2; + +# +# Bug #18165: range access for BETWEEN with a constant for the first argument +# + +CREATE TABLE t1 ( + id int NOT NULL DEFAULT '0', + b int NOT NULL DEFAULT '0', + c int NOT NULL DEFAULT '0', + INDEX idx1(b,c), INDEX idx2(c)); + +INSERT INTO t1(id) VALUES (1), (2), (3), (4), (5), (6), (7), (8); + +INSERT INTO t1(b,c) VALUES (3,4), (3,4); + +SELECT * FROM t1 WHERE b<=3 AND 3<=c; +SELECT * FROM t1 WHERE 3 BETWEEN b AND c; + +EXPLAIN SELECT * FROM t1 WHERE b<=3 AND 3<=c; +EXPLAIN SELECT * FROM t1 WHERE 3 BETWEEN b AND c; + +SELECT * FROM t1 WHERE 0 < b OR 0 > c; +SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c; + +EXPLAIN SELECT * FROM t1 WHERE 0 < b OR 0 > c; +EXPLAIN SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c; + +DROP TABLE t1; + +# +# Bug #16249: different results for a range with an without index +# when a range condition use an invalid datetime constant +# + +CREATE TABLE t1 ( + item char(20) NOT NULL default '', + started datetime NOT NULL default '0000-00-00 00:00:00', + price decimal(16,3) NOT NULL default '0.000', + PRIMARY KEY (item,started) +) ENGINE=MyISAM; + +INSERT INTO t1 VALUES +('A1','2005-11-01 08:00:00',1000), +('A1','2005-11-15 00:00:00',2000), +('A1','2005-12-12 08:00:00',3000), +('A2','2005-12-01 08:00:00',1000); + +EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; +SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; +SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00'; + +DROP INDEX `PRIMARY` ON t1; + +EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; +SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; +SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00'; + +DROP TABLE t1; + +# End of 5.0 tests diff --git a/mysql-test/t/read_only.test b/mysql-test/t/read_only.test new file mode 100644 index 00000000000..175a5bba6fa --- /dev/null +++ b/mysql-test/t/read_only.test @@ -0,0 +1,108 @@ +# Test of the READ_ONLY global variable: +# check that it blocks updates unless they are only on temporary tables. + +# should work with embedded server after mysqltest is fixed +-- source include/not_embedded.inc + +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3; +--enable_warnings + +# READ_ONLY does nothing to SUPER users +# so we use a non-SUPER one: + +grant CREATE, SELECT, DROP on *.* to test@localhost; + +connect (con1,localhost,test,,test); + +connection default; + +set global read_only=0; + +connection con1; + +create table t1 (a int); + +insert into t1 values(1); + +create table t2 select * from t1; + +connection default; + +set global read_only=1; + +# We check that SUPER can: + +create table t3 (a int); +drop table t3; + +connection con1; + +select @@global.read_only; + +--error 1290 +create table t3 (a int); + +--error 1290 +insert into t1 values(1); + +# if a statement, after parse stage, looks like it will update a +# non-temp table, it will be rejected, even if at execution it would +# have turned out that 0 rows would be updated +--error 1290 +update t1 set a=1 where 1=0; + +# multi-update is special (see sql_parse.cc) so we test it +--error 1290 +update t1,t2 set t1.a=t2.a+1 where t1.a=t2.a; + +# check multi-delete to be sure +--error 1290 +delete t1,t2 from t1,t2 where t1.a=t2.a; + +# With temp tables updates should be accepted: + +create temporary table t3 (a int); + +create temporary table t4 (a int) select * from t3; + +insert into t3 values(1); + +insert into t4 select * from t3; + +# a non-temp table updated: +--error 1290 +update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a; + +# no non-temp table updated (just swapped): +update t1,t3 set t3.a=t1.a+1 where t1.a=t3.a; + +update t4,t3 set t4.a=t3.a+1 where t4.a=t3.a; + +--error 1290 +delete t1 from t1,t3 where t1.a=t3.a; + +delete t3 from t1,t3 where t1.a=t3.a; + +delete t4 from t3,t4 where t4.a=t3.a; + +# and even homonymous ones + +create temporary table t1 (a int); + +insert into t1 values(1); + +update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a; + +delete t1 from t1,t3 where t1.a=t3.a; + +drop table t1; + +--error 1290 +insert into t1 values(1); + +connection default; +drop table t1,t2; +drop user test@localhost; + +set global read_only=0; diff --git a/mysql-test/t/rename.test b/mysql-test/t/rename.test index b0fb60c0ee4..09a02344203 100644 --- a/mysql-test/t/rename.test +++ b/mysql-test/t/rename.test @@ -60,6 +60,9 @@ send RENAME TABLE t1 TO t2, t3 to t4; connection con2; show tables; UNLOCK TABLES; +connection con1; +reap; +connection con2; # Wait for the the tables to be renamed # i.e the query below succeds @@ -70,4 +73,27 @@ show tables; drop table t2, t4; -# End of 4.1 tests +disconnect con2; +disconnect con1; +connection default; + + +--echo End of 4.1 tests + + +# +# Bug#14959: ALTER TABLE isn't able to rename a view +# +create table t1(f1 int); +create view v1 as select * from t1; +alter table v1 rename to v2; +--error 1146 +alter table v1 rename to v2; +rename table v2 to v1; +--error 1050 +rename table v2 to v1; +drop view v1; +drop table t1; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/repair.test b/mysql-test/t/repair.test index 35e5e485cb9..f2e4c328218 100644 --- a/mysql-test/t/repair.test +++ b/mysql-test/t/repair.test @@ -29,7 +29,7 @@ repair table t1 use_frm; create table t1 engine=myisam SELECT 1,"table 1"; flush tables; -system echo 1 > $MYSQL_TEST_DIR/var/master-data/test/t1.MYI ; +system echo 1 > $MYSQLTEST_VARDIR/master-data/test/t1.MYI ; repair table t1; repair table t1 use_frm; drop table t1; diff --git a/mysql-test/t/replace.test b/mysql-test/t/replace.test index 81f7b0089b8..269854fb180 100644 --- a/mysql-test/t/replace.test +++ b/mysql-test/t/replace.test @@ -1,7 +1,5 @@ --- source include/have_isam.inc - # -# Test of REPLACE with ISAM and MyISAM and HEAP +# Test of REPLACE with MyISAM and HEAP # --disable_warnings @@ -12,13 +10,11 @@ CREATE TABLE t1 ( gesuchnr int(11) DEFAULT '0' NOT NULL, benutzer_id int(11) DEFAULT '0' NOT NULL, PRIMARY KEY (gesuchnr,benutzer_id) -) engine=ISAM; +); replace into t1 (gesuchnr,benutzer_id) values (2,1); replace into t1 (gesuchnr,benutzer_id) values (1,1); replace into t1 (gesuchnr,benutzer_id) values (1,1); -alter table t1 engine=myisam; -replace into t1 (gesuchnr,benutzer_id) values (1,1); alter table t1 engine=heap; replace into t1 (gesuchnr,benutzer_id) values (1,1); drop table t1; @@ -39,3 +35,13 @@ select * from t1; drop table t1; # End of 4.1 tests + +# +# Bug#19789: REPLACE was allowed for a VIEW with CHECK OPTION enabled. +# +CREATE TABLE t1 (f1 INT); +CREATE VIEW v1 AS SELECT f1 FROM t1 WHERE f1 = 0 WITH CHECK OPTION; +--error 1369 +REPLACE INTO v1 (f1) VALUES (1); +DROP TABLE t1; +DROP VIEW v1; diff --git a/mysql-test/t/round.test b/mysql-test/t/round.test new file mode 100644 index 00000000000..d018fa7e34e --- /dev/null +++ b/mysql-test/t/round.test @@ -0,0 +1,145 @@ +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (sint8 tinyint not null); +INSERT INTO t1 VALUES ('0.1'); +INSERT INTO t1 VALUES ('0.5'); +INSERT INTO t1 VALUES ('127.4'); +INSERT INTO t1 VALUES ('127.5'); +INSERT INTO t1 VALUES ('-0.1'); +INSERT INTO t1 VALUES ('-0.5'); +INSERT INTO t1 VALUES ('-127.4'); +INSERT INTO t1 VALUES ('-127.5'); +INSERT INTO t1 VALUES ('-128.4'); +INSERT INTO t1 VALUES ('-128.5'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (uint8 tinyint unsigned not null); +INSERT INTO t1 VALUES ('0.1'); +INSERT INTO t1 VALUES ('0.5'); +INSERT INTO t1 VALUES ('127.4'); +INSERT INTO t1 VALUES ('127.5'); +INSERT INTO t1 VALUES ('-0.1'); +INSERT INTO t1 VALUES ('-0.5'); +INSERT INTO t1 VALUES ('255.4'); +INSERT INTO t1 VALUES ('255.5'); +SELECT * FROM t1; +DROP TABLE t1; + + +CREATE TABLE t1 (sint16 smallint not null); +INSERT INTO t1 VALUES ('0.1'); +INSERT INTO t1 VALUES ('0.5'); +INSERT INTO t1 VALUES ('32767.4'); +INSERT INTO t1 VALUES ('32767.5'); +INSERT INTO t1 VALUES ('-0.1'); +INSERT INTO t1 VALUES ('-0.5'); +INSERT INTO t1 VALUES ('-32767.4'); +INSERT INTO t1 VALUES ('-32767.5'); +INSERT INTO t1 VALUES ('-32768.4'); +INSERT INTO t1 VALUES ('-32768.5'); +SELECT * FROM t1; +DROP TABLE t1; + + +CREATE TABLE t1 (uint16 smallint unsigned not null); +INSERT INTO t1 VALUES ('0.1'); +INSERT INTO t1 VALUES ('0.5'); +INSERT INTO t1 VALUES ('32767.4'); +INSERT INTO t1 VALUES ('32767.5'); +INSERT INTO t1 VALUES ('-0.1'); +INSERT INTO t1 VALUES ('-0.5'); +INSERT INTO t1 VALUES ('65535.4'); +INSERT INTO t1 VALUES ('65535.5'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (sint24 mediumint not null); +INSERT INTO t1 VALUES ('0.1'); +INSERT INTO t1 VALUES ('0.5'); +INSERT INTO t1 VALUES ('8388607.4'); +INSERT INTO t1 VALUES ('8388607.5'); +INSERT INTO t1 VALUES ('-0.1'); +INSERT INTO t1 VALUES ('-0.5'); +INSERT INTO t1 VALUES ('-8388607.4'); +INSERT INTO t1 VALUES ('-8388607.5'); +INSERT INTO t1 VALUES ('-8388608.4'); +INSERT INTO t1 VALUES ('-8388608.5'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (uint24 mediumint unsigned not null); +INSERT INTO t1 VALUES ('0.1'); +INSERT INTO t1 VALUES ('0.5'); +INSERT INTO t1 VALUES ('8388607.4'); +INSERT INTO t1 VALUES ('8388607.5'); +INSERT INTO t1 VALUES ('-0.1'); +INSERT INTO t1 VALUES ('-0.5'); +INSERT INTO t1 VALUES ('16777215.4'); +INSERT INTO t1 VALUES ('16777215.5'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (sint64 bigint not null); +INSERT INTO t1 VALUES ('0.1'); +INSERT INTO t1 VALUES ('0.5'); +INSERT INTO t1 VALUES ('9223372036854775807.4'); +INSERT INTO t1 VALUES ('9223372036854775807.5'); +INSERT INTO t1 VALUES ('-0.1'); +INSERT INTO t1 VALUES ('-0.5'); +INSERT INTO t1 VALUES ('-9223372036854775807.4'); +INSERT INTO t1 VALUES ('-9223372036854775807.5'); +INSERT INTO t1 VALUES ('-9223372036854775808.4'); +INSERT INTO t1 VALUES ('-9223372036854775808.5'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (uint64 bigint unsigned not null); +INSERT INTO t1 VALUES ('0.1'); +INSERT INTO t1 VALUES ('0.5'); +INSERT INTO t1 VALUES ('9223372036854775807.4'); +INSERT INTO t1 VALUES ('9223372036854775807.5'); +INSERT INTO t1 VALUES ('-0.1'); +INSERT INTO t1 VALUES ('-0.5'); +INSERT INTO t1 VALUES ('18446744073709551615.4'); +INSERT INTO t1 VALUES ('18446744073709551615.5'); +INSERT INTO t1 VALUES ('1844674407370955161.0'); +INSERT INTO t1 VALUES ('1844674407370955161.1'); +INSERT INTO t1 VALUES ('1844674407370955161.2'); +INSERT INTO t1 VALUES ('1844674407370955161.3'); +INSERT INTO t1 VALUES ('1844674407370955161.4'); +INSERT INTO t1 VALUES ('1844674407370955161.5'); +INSERT INTO t1 VALUES ('1844674407370955161.0e1'); +INSERT INTO t1 VALUES ('1844674407370955161.1e1'); +INSERT INTO t1 VALUES ('1844674407370955161.2e1'); +INSERT INTO t1 VALUES ('1844674407370955161.3e1'); +INSERT INTO t1 VALUES ('1844674407370955161.4e1'); +INSERT INTO t1 VALUES ('1844674407370955161.5e1'); +INSERT INTO t1 VALUES ('18446744073709551610e-1'); +INSERT INTO t1 VALUES ('18446744073709551611e-1'); +INSERT INTO t1 VALUES ('18446744073709551612e-1'); +INSERT INTO t1 VALUES ('18446744073709551613e-1'); +INSERT INTO t1 VALUES ('18446744073709551614e-1'); +INSERT INTO t1 VALUES ('18446744073709551615e-1'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (str varchar(128), sint64 bigint not null default 0); +INSERT INTO t1 (str) VALUES ('1.5'); +INSERT INTO t1 (str) VALUES ('1.00005e4'); +INSERT INTO t1 (str) VALUES ('1.0005e3'); +INSERT INTO t1 (str) VALUES ('1.005e2'); +INSERT INTO t1 (str) VALUES ('1.05e1'); +INSERT INTO t1 (str) VALUES ('1.5e0'); +INSERT INTO t1 (str) VALUES ('100005e-1'); +INSERT INTO t1 (str) VALUES ('100050e-2'); +INSERT INTO t1 (str) VALUES ('100500e-3'); +INSERT INTO t1 (str) VALUES ('105000e-4'); +INSERT INTO t1 (str) VALUES ('150000e-5'); +UPDATE t1 SET sint64=str; +SELECT * FROM t1; +DROP TABLE t1; + + diff --git a/mysql-test/t/row.test b/mysql-test/t/row.test index d8d9a244134..63c611e6be6 100644 --- a/mysql-test/t/row.test +++ b/mysql-test/t/row.test @@ -7,9 +7,11 @@ select (1,2,3) IN ((3,2,3), (1,2,3), (1,3,3)); select row(10,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3)); select row(1,2,3) IN (row(3,NULL,3), row(1,2,3), row(1,3,3)); select row(10,2,3) IN (row(3,NULL,3), row(1,2,3), row(1,3,3)); +--disable_ps_warnings select row('a',1.5,3) IN (row(1,2,3), row('a',1.5,3), row('a','a','a')); -select row('a',0,3) IN (row(3,2,3), row('a','0','3'), row(1,3,3)); select row('a',0,3) IN (row(3,2,3), row('a','a','3'), row(1,3,3)); +--enable_ps_warnings +select row('a',0,3) IN (row(3,2,3), row('a','0','3'), row(1,3,3)); select row('a',1.5,3) IN (row(3,NULL,3), row('a',1.5,3), row(1,3,3)); select row('b',1.5,3) IN (row(3,NULL,3), row('a',1.5,3), row(1,3,3)); select row('b',1.5,3) IN (row('b',NULL,3), row('a',1.5,3), row(1,3,3)); @@ -84,3 +86,56 @@ SELECT ROW(2,10) <=> ROW(3,4); SELECT ROW(NULL,10) <=> ROW(3,NULL); # End of 4.1 tests + +# +# Correct NULL handling in row comporison (BUG#12509) +# +SELECT ROW(1,1,1) = ROW(1,1,1) as `1`, ROW(1,1,1) = ROW(1,2,1) as `0`, ROW(1,NULL,1) = ROW(2,2,1) as `0`, ROW(1,NULL,1) = ROW(1,2,2) as `0`, ROW(1,NULL,1) = ROW(1,2,1) as `null` ; +select row(NULL,1)=(2,0); + +# +# Bug #16081: row equalities are to be used for query optimizations +# + +CREATE TABLE t1 (a int, b int, PRIMARY KEY (a,b)); +INSERT INTO t1 VALUES (1,1), (2,1), (3,1), (1,2), (3,2), (3,3); + +EXPLAIN SELECT * FROM t1 WHERE a=3 AND b=2; +EXPLAIN SELECT * FROM t1 WHERE (a,b)=(3,2); +SELECT * FROM t1 WHERE a=3 and b=2; +SELECT * FROM t1 WHERE (a,b)=(3,2); + +CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a,b,c)); +INSERT INTO t2 VALUES + (1,1,2), (3,1,3), (1,2,2), (4,4,2), + (1,1,1), (3,1,1), (1,2,1); + +EXPLAIN SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b=t2.b; +EXPLAIN SELECT * FROM t1,t2 WHERE (t1.a,t1.b)=(t2.a,t2.b); +SELECT * FROM t1,t2 WHERE t1.a=t2.a and t1.b=t2.b; +SELECT * FROM t1,t2 WHERE (t1.a,t1.b)=(t2.a,t2.b); + +EXPLAIN SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b=2; +EXPLAIN SELECT * FROM t1,t2 WHERE (t1.a,t1.b)=(t2.a,2); +SELECT * FROM t1,t2 WHERE t1.a=1 and t1.b=t2.b; +SELECT * FROM t1,t2 WHERE (t1.a,t1.b)=(t2.a,2); + +EXPLAIN EXTENDED SELECT * FROM t1,t2 WHERE (t1.a,t1.b)=(t2.a,t2.b+1); +SELECT * FROM t1,t2 WHERE (t1.a,t1.b)=(t2.a,t2.b+1); + +EXPLAIN EXTENDED SELECT * FROM t1,t2 WHERE (t1.a-1,t1.b)=(t2.a-1,t2.b+1); +SELECT * FROM t1,t2 WHERE (t1.a-1,t1.b)=(t2.a-1,t2.b+1); + +EXPLAIN SELECT * FROM t2 WHERE a=3 AND b=2; +EXPLAIN SELECT * FROM t2 WHERE (a,b)=(3,2); +SELECT * FROM t2 WHERE a=3 and b=2; +SELECT * FROM t2 WHERE (a,b)=(3,2); + +EXPLAIN SELECT * FROM t1,t2 WHERE t2.a=t1.a AND t2.b=2 AND t2.c=1; +EXPLAIN EXTENDED SELECT * FROM t1,t2 WHERE (t2.a,(t2.b,t2.c))=(t1.a,(2,1)); +SELECT * FROM t1,t2 WHERE (t2.a,(t2.b,t2.c))=(t1.a,(2,1)); + +EXPLAIN EXTENDED SELECT * FROM t1,t2 WHERE t2.a=t1.a AND (t2.b,t2.c)=(2,1); +SELECT * FROM t1,t2 WHERE t2.a=t1.a AND (t2.b,t2.c)=(2,1); + +DROP TABLE t1,t2; diff --git a/mysql-test/t/rowid_order_bdb.test b/mysql-test/t/rowid_order_bdb.test new file mode 100644 index 00000000000..ef133054c35 --- /dev/null +++ b/mysql-test/t/rowid_order_bdb.test @@ -0,0 +1,108 @@ +# +# Test for rowid ordering (and comparison) functions. +# do index_merge select for tables with PK of various types. +# +--disable_warnings +drop table if exists t1, t2, t3,t4; +--enable_warnings + +-- source include/have_bdb.inc + +# Signed number as rowid +create table t1 ( + pk1 int not NULL, + key1 int(11), + key2 int(11), + PRIMARY KEY (pk1), + KEY key1 (key1), + KEY key2 (key2) +) engine=bdb; +insert into t1 values (-5, 1, 1), + (-100, 1, 1), + (3, 1, 1), + (0, 1, 1), + (10, 1, 1); +explain select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +drop table t1; + +# Unsigned numbers as rowids +create table t1 ( + pk1 int unsigned not NULL, + key1 int(11), + key2 int(11), + PRIMARY KEY (pk1), + KEY key1 (key1), + KEY key2 (key2) +) engine=bdb; +insert into t1 values (0, 1, 1), + (0xFFFFFFFF, 1, 1), + (0xFFFFFFFE, 1, 1), + (1, 1, 1), + (2, 1, 1); +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +drop table t1; + +# Case-insensitive char(N) +create table t1 ( + pk1 char(4) not NULL, + key1 int(11), + key2 int(11), + PRIMARY KEY (pk1), + KEY key1 (key1), + KEY key2 (key2) +) engine=bdb collate latin2_general_ci; +insert into t1 values ('a1', 1, 1), + ('b2', 1, 1), + ('A3', 1, 1), + ('B4', 1, 1); +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +drop table t1; + +# Multi-part PK +create table t1 ( + pk1 int not NULL, + pk2 char(4) not NULL collate latin1_german1_ci, + pk3 char(4) not NULL collate latin1_bin, + key1 int(11), + key2 int(11), + PRIMARY KEY (pk1,pk2,pk3), + KEY key1 (key1), + KEY key2 (key2) +) engine=bdb; +insert into t1 values + (1, 'u', 'u', 1, 1), + (1, 'u', char(0xEC), 1, 1), + (1, 'u', 'x', 1, 1); +insert ignore into t1 select pk1, char(0xEC), pk3, key1, key2 from t1; +insert ignore into t1 select pk1, 'x', pk3, key1, key2 from t1 where pk2='u'; +insert ignore into t1 select 2, pk2, pk3, key1, key2 from t1; +select * from t1; +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; + +# Hidden PK +alter table t1 drop primary key; +select * from t1; +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +drop table t1; + +# Variable-length PK +# this is also test for Bug#2688 +create table t1 ( + pk1 varchar(8) NOT NULL default '', + pk2 varchar(4) NOT NULL default '', + key1 int(11), + key2 int(11), + primary key(pk1, pk2), + KEY key1 (key1), + KEY key2 (key2) +) engine=bdb; +insert into t1 values ('','empt',2,2), + ('a','a--a',2,2), + ('bb','b--b',2,2), + ('ccc','c--c',2,2), + ('dddd','d--d',2,2); +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; + +drop table t1; + diff --git a/mysql-test/t/rowid_order_innodb.test b/mysql-test/t/rowid_order_innodb.test new file mode 100644 index 00000000000..fb4959d78e6 --- /dev/null +++ b/mysql-test/t/rowid_order_innodb.test @@ -0,0 +1,108 @@ +# +# Test for rowid ordering (and comparison) functions. +# do index_merge select for tables with PK of various types. +# +--disable_warnings +drop table if exists t1, t2, t3,t4; +--enable_warnings + +-- source include/have_innodb.inc + +# Signed number as rowid +create table t1 ( + pk1 int not NULL, + key1 int(11), + key2 int(11), + PRIMARY KEY (pk1), + KEY key1 (key1), + KEY key2 (key2) +) engine=innodb; +insert into t1 values (-5, 1, 1), + (-100, 1, 1), + (3, 1, 1), + (0, 1, 1), + (10, 1, 1); +explain select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +drop table t1; + +# Unsigned numbers as rowids +create table t1 ( + pk1 int unsigned not NULL, + key1 int(11), + key2 int(11), + PRIMARY KEY (pk1), + KEY key1 (key1), + KEY key2 (key2) +) engine=innodb; +insert into t1 values (0, 1, 1), + (0xFFFFFFFF, 1, 1), + (0xFFFFFFFE, 1, 1), + (1, 1, 1), + (2, 1, 1); +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +drop table t1; + +# Case-insensitive char(N) +create table t1 ( + pk1 char(4) not NULL, + key1 int(11), + key2 int(11), + PRIMARY KEY (pk1), + KEY key1 (key1), + KEY key2 (key2) +) engine=innodb collate latin2_general_ci; +insert into t1 values ('a1', 1, 1), + ('b2', 1, 1), + ('A3', 1, 1), + ('B4', 1, 1); +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +drop table t1; + +# Multi-part PK +create table t1 ( + pk1 int not NULL, + pk2 char(4) not NULL collate latin1_german1_ci, + pk3 char(4) not NULL collate latin1_bin, + key1 int(11), + key2 int(11), + PRIMARY KEY (pk1,pk2,pk3), + KEY key1 (key1), + KEY key2 (key2) +) engine=innodb; +insert into t1 values + (1, 'u', 'u', 1, 1), + (1, 'u', char(0xEC), 1, 1), + (1, 'u', 'x', 1, 1); +insert ignore into t1 select pk1, char(0xEC), pk3, key1, key2 from t1; +insert ignore into t1 select pk1, 'x', pk3, key1, key2 from t1 where pk2='u'; +insert ignore into t1 select 2, pk2, pk3, key1, key2 from t1; +select * from t1; +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; + +# Hidden PK +alter table t1 drop primary key; +select * from t1; +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +drop table t1; + +# Variable-length PK +# this is also test for Bug#2688 +create table t1 ( + pk1 varchar(8) NOT NULL default '', + pk2 varchar(4) NOT NULL default '', + key1 int(11), + key2 int(11), + primary key(pk1, pk2), + KEY key1 (key1), + KEY key2 (key2) +) engine=innodb; +insert into t1 values ('','empt',2,2), + ('a','a--a',2,2), + ('bb','b--b',2,2), + ('ccc','c--c',2,2), + ('dddd','d--d',2,2); +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; + +drop table t1; + diff --git a/mysql-test/t/rpl000001.test b/mysql-test/t/rpl000001.test index 8f7ba50476a..5b4b29addc4 100644 --- a/mysql-test/t/rpl000001.test +++ b/mysql-test/t/rpl000001.test @@ -1,7 +1,7 @@ source include/master-slave.inc; create table t1 (word char(20) not null); -load data infile '../../std_data/words.dat' into table t1; +load data infile '../std_data_ln/words.dat' into table t1; --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR eval load data local infile '$MYSQL_TEST_DIR/std_data/words.dat' into table t1; select * from t1 limit 10; @@ -39,7 +39,13 @@ save_master_pos; connection slave; sync_with_master; -#test handling of aborted connection in the middle of update +# Test if the slave SQL thread can be more than 16K behind the slave +# I/O thread (> IO_SIZE) + +connection master; +# we'll use table-level locking to delay slave SQL thread +create table t1 (n int) engine=myisam; +sync_slave_with_master; connection master; reset master; connection slave; @@ -47,29 +53,26 @@ stop slave; reset slave; connection master; -create table t1(n int); -#we want the log to exceed 16K to test deal with the log that is bigger than -#IO_SIZE let $1=5000; +# Generate 16K of relay log disable_query_log; while ($1) { - eval insert into t1 values($1+get_lock("hold_slave",10)*0); + eval insert into t1 values($1); dec $1; } enable_query_log; -# Try to cause a large relay log lag on the slave +# Try to cause a large relay log lag on the slave by locking t1 connection slave; -select get_lock("hold_slave",10); -explain extended select get_lock("hold_slave",10); +lock tables t1 read; start slave; #hope this is long enough for I/O thread to fetch over 16K relay log data sleep 3; -select release_lock("hold_slave"); -explain extended select release_lock("hold_slave"); unlock tables; +#test handling of aborted connection in the middle of update + connection master; create table t2(id int); insert into t2 values(connection_id()); @@ -89,7 +92,7 @@ kill @id; # We don't drop t3 as this is a temporary table drop table t2; connection master; ---error 1053 +--error 1053,2013 reap; connection slave; # The SQL slave thread should now have stopped because the query was killed on @@ -120,6 +123,7 @@ select n from t1; select select_priv,user from mysql.user where user = _binary'blafasel2'; connection master1; drop table t1; +delete from mysql.user where user="blafasel2"; save_master_pos; connection slave; sync_with_master; diff --git a/mysql-test/t/rpl000004.test b/mysql-test/t/rpl000004.test index f2a02bd4dd6..9c8c535c67d 100644 --- a/mysql-test/t/rpl000004.test +++ b/mysql-test/t/rpl000004.test @@ -2,9 +2,9 @@ source include/master-slave.inc; set SQL_LOG_BIN=0; create table t1 (word char(20) not null, index(word)); -load data infile '../../std_data/words.dat' into table t1; +load data infile '../std_data_ln/words.dat' into table t1; create table t2 (word char(20) not null); -load data infile '../../std_data/words.dat' into table t2; +load data infile '../std_data_ln/words.dat' into table t2; create table t3 (word char(20) not null primary key); connection slave; load table t1 from master; diff --git a/mysql-test/t/rpl000009.test b/mysql-test/t/rpl000009.test index 81e9860c186..161e01ad293 100644 --- a/mysql-test/t/rpl000009.test +++ b/mysql-test/t/rpl000009.test @@ -138,10 +138,10 @@ select * from mysqltest.t1; # DISABLED FOR NOW AS chmod IS NOT PORTABLE ON NON-UNIX # insert into mysqltest.t1 values(10, 'should be there'); # flush tables; -# system chmod 500 var/slave-data/mysqltest/; +# system chmod 500 $MYSQLTEST_VARDIR/slave-data/mysqltest/; # --error 6 # load data from master; # should fail (errno 13) -# system chmod 700 var/slave-data/mysqltest/; +# system chmod 700 $MYSQLTEST_VARDIR/slave-data/mysqltest/; # select * from mysqltest.t1; # should contain the row (10, ...) diff --git a/mysql-test/t/rpl000010-slave.opt b/mysql-test/t/rpl000010-slave.opt index 429a7f63f7b..0dbfb311e33 100644 --- a/mysql-test/t/rpl000010-slave.opt +++ b/mysql-test/t/rpl000010-slave.opt @@ -1 +1 @@ ---disconnect-slave-event-count=1 +--disconnect-slave-event-count=2 diff --git a/mysql-test/t/rpl000015-slave.sh b/mysql-test/t/rpl000015-slave.sh index 62748605af1..7deeca3d2d6 100755 --- a/mysql-test/t/rpl000015-slave.sh +++ b/mysql-test/t/rpl000015-slave.sh @@ -1 +1 @@ -rm -f $MYSQL_TEST_DIR/var/slave-data/master.info +rm -f $MYSQLTEST_VARDIR/slave-data/master.info diff --git a/mysql-test/t/rpl000015.test b/mysql-test/t/rpl000015.test index 4e329fc87ea..df4bf6f977b 100644 --- a/mysql-test/t/rpl000015.test +++ b/mysql-test/t/rpl000015.test @@ -1,4 +1,4 @@ -connect (master,localhost,root,,test,$MASTER_MYPORT,master.sock); +connect (master,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); connect (slave,localhost,root,,test,$SLAVE_MYPORT,slave.sock); connection master; reset master; @@ -12,7 +12,7 @@ show slave status; change master to master_host='127.0.0.1'; # The following needs to be cleaned up when change master is fixed ---replace_result $MASTER_MYPORT MASTER_PORT $MYSQL_TCP_PORT MASTER_PORT +--replace_result $MYSQL_TCP_PORT MASTER_PORT --replace_column 1 # 8 # 9 # 23 # 33 # show slave status; --replace_result $MASTER_MYPORT MASTER_PORT diff --git a/mysql-test/t/rpl000017-slave.sh b/mysql-test/t/rpl000017-slave.sh index 4dbbaec31ce..17188aba0db 100755 --- a/mysql-test/t/rpl000017-slave.sh +++ b/mysql-test/t/rpl000017-slave.sh @@ -1,6 +1,6 @@ -rm -f $MYSQL_TEST_DIR/var/log/*relay* -rm -f $MYSQL_TEST_DIR/var/slave-data/relay-log.info -cat > $MYSQL_TEST_DIR/var/slave-data/master.info <<EOF +rm -f $MYSQLTEST_VARDIR/log/*relay* +rm -f $MYSQLTEST_VARDIR/slave-data/relay-log.info +cat > $MYSQLTEST_VARDIR/slave-data/master.info <<EOF master-bin.000001 4 127.0.0.1 diff --git a/mysql-test/t/rpl000017.test b/mysql-test/t/rpl000017.test index 7b4e6bf4d3a..866b7fd1c25 100644 --- a/mysql-test/t/rpl000017.test +++ b/mysql-test/t/rpl000017.test @@ -1,4 +1,4 @@ -connect (master,localhost,root,,test,$MASTER_MYPORT,master.sock); +connect (master,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); connect (slave,localhost,root,,test,$SLAVE_MYPORT,slave.sock); connection master; reset master; @@ -16,6 +16,7 @@ sync_slave_with_master; select * from t1; connection master; drop table t1; +delete from mysql.user where user="replicate"; sync_slave_with_master; # End of 4.1 tests diff --git a/mysql-test/t/rpl_EE_error.test b/mysql-test/t/rpl_EE_error.test index 5f68b699e9f..640a2b1a88c 100644 --- a/mysql-test/t/rpl_EE_error.test +++ b/mysql-test/t/rpl_EE_error.test @@ -8,8 +8,8 @@ source include/master-slave.inc; create table t1 (a int) engine=myisam; flush tables; -system rm ./var/master-data/test/t1.MYI ; -drop table t1; +system rm $MYSQLTEST_VARDIR/master-data/test/t1.MYI ; +drop table if exists t1; save_master_pos; connection slave; sync_with_master; diff --git a/mysql-test/t/rpl_auto_increment-master.opt b/mysql-test/t/rpl_auto_increment-master.opt new file mode 100644 index 00000000000..a8a6af19da9 --- /dev/null +++ b/mysql-test/t/rpl_auto_increment-master.opt @@ -0,0 +1 @@ +--auto-increment-increment=10 --auto-increment-offset=2 diff --git a/mysql-test/t/rpl_auto_increment.test b/mysql-test/t/rpl_auto_increment.test new file mode 100644 index 00000000000..caa2b79feb5 --- /dev/null +++ b/mysql-test/t/rpl_auto_increment.test @@ -0,0 +1,142 @@ +# +# Test of auto_increment with offset +# +source include/have_innodb.inc; +source include/master-slave.inc; + +create table t1 (a int not null auto_increment,b int, primary key (a)) engine=myisam auto_increment=3; +insert into t1 values (NULL,1),(NULL,2),(NULL,3); +select * from t1; + +sync_slave_with_master; +select * from t1; +connection master; +drop table t1; + +create table t1 (a int not null auto_increment,b int, primary key (a)) engine=myisam; +insert into t1 values (1,1),(NULL,2),(3,3),(NULL,4); +delete from t1 where b=4; +insert into t1 values (NULL,5),(NULL,6); +select * from t1; + +sync_slave_with_master; +select * from t1; +connection master; + +drop table t1; + +set @@session.auto_increment_increment=100, @@session.auto_increment_offset=10; +show variables like "%auto_inc%"; + +create table t1 (a int not null auto_increment, primary key (a)) engine=myisam; +# Insert with 2 insert statements to get better testing of logging +insert into t1 values (NULL),(5),(NULL); +insert into t1 values (250),(NULL); +select * from t1; +insert into t1 values (1000); +set @@insert_id=400; +insert into t1 values(NULL),(NULL); +select * from t1; + +sync_slave_with_master; +select * from t1; +connection master; +drop table t1; + +# +# Same test with innodb (as the innodb code is a bit different) +# +create table t1 (a int not null auto_increment, primary key (a)) engine=innodb; +# Insert with 2 insert statements to get better testing of logging +insert into t1 values (NULL),(5),(NULL); +insert into t1 values (250),(NULL); +select * from t1; +insert into t1 values (1000); +set @@insert_id=400; +insert into t1 values(NULL),(NULL); +select * from t1; + +sync_slave_with_master; +select * from t1; +connection master; +drop table t1; + +set @@session.auto_increment_increment=1, @@session.auto_increment_offset=1; +create table t1 (a int not null auto_increment, primary key (a)) engine=myisam; +# Insert with 2 insert statements to get better testing of logging +insert into t1 values (NULL),(5),(NULL),(NULL); +insert into t1 values (500),(NULL),(502),(NULL),(NULL); +select * from t1; +set @@insert_id=600; +--error 1062 +insert into t1 values(600),(NULL),(NULL); +set @@insert_id=600; +insert ignore into t1 values(600),(NULL),(NULL),(610),(NULL); +select * from t1; + +sync_slave_with_master; +select * from t1; +connection master; +drop table t1; + +# +# Test that auto-increment works when slave has rows in the table +# +set @@session.auto_increment_increment=10, @@session.auto_increment_offset=1; + +create table t1 (a int not null auto_increment, primary key (a)) engine=myisam; + +sync_slave_with_master; +insert into t1 values(2),(12),(22),(32),(42); +connection master; + +insert into t1 values (NULL),(NULL); +insert into t1 values (3),(NULL),(NULL); +select * from t1; + +sync_slave_with_master; +select * from t1; + +# Test for BUG#20524 "auto_increment_* not observed when inserting +# a too large value". When an autogenerated value was bigger than the +# maximum possible value of the field, it was truncated to that max +# possible value, without being "rounded down" to still honour +# auto_increment_* variables. + +connection master; +drop table t1; +create table t1 (a tinyint not null auto_increment primary key) engine=myisam; +insert into t1 values(103); +set auto_increment_increment=11; +set auto_increment_offset=4; +insert into t1 values(null); +insert into t1 values(null); +--error 1062 +insert into t1 values(null); +select a, mod(a-@@auto_increment_offset,@@auto_increment_increment) from t1 order by a; + +# same but with a larger value +create table t2 (a tinyint unsigned not null auto_increment primary key) engine=myisam; +set auto_increment_increment=10; +set auto_increment_offset=1; +set insert_id=1000; +insert into t2 values(null); +select a, mod(a-@@auto_increment_offset,@@auto_increment_increment) from t2 order by a; + +# An offset so big that even first value does not fit +create table t3 like t1; +set auto_increment_increment=1000; +set auto_increment_offset=700; +insert into t3 values(null); +select * from t3 order by a; +sync_slave_with_master; +select * from t1 order by a; +select * from t2 order by a; +select * from t3 order by a; + +connection master; + +drop table t1,t2,t3; + +# End cleanup +sync_slave_with_master; diff --git a/mysql-test/t/rpl_auto_increment_11932.test b/mysql-test/t/rpl_auto_increment_11932.test new file mode 100644 index 00000000000..d4b7872fb2b --- /dev/null +++ b/mysql-test/t/rpl_auto_increment_11932.test @@ -0,0 +1,63 @@ +# +# Test of auto_increment +# BUG#11932 +# +# Bug reported that master and slave get out of sync after TRUNCATE +# TABLE. +# +# Test supplied by Are Casilla + +source include/master-slave.inc; +--disable_warnings +connection master; +drop database if exists test1; +--enable_warnings +create database test1; +use test1; + +CREATE TABLE `t1` ( + `id` int(10) unsigned NOT NULL auto_increment, + `fname` varchar(100) default NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; + +INSERT INTO `t1` VALUES (1, 'blablabla'); + +CREATE TABLE `t2` ( + `id` int(10) NOT NULL auto_increment, + `comment` varchar(255) NOT NULL default '', + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=3 ; + +INSERT INTO `t2` VALUES (1, 'testtest 1'); +INSERT INTO `t2` VALUES (2, 'test 2'); + +DELIMITER $; +CREATE PROCEDURE simpleproc3 () + NOT DETERMINISTIC + BEGIN + INSERT INTO t1 (fname) (SELECT t2.comment FROM t2 WHERE t2.id = '1'); + INSERT INTO t1 (fname) VALUES('test'); + END + $ +DELIMITER ;$ + +CALL simpleproc3(); + +select * from t2; + +TRUNCATE TABLE `t1`; +CALL simpleproc3(); + +select * from t1; + +save_master_pos; +connection slave; +sync_with_master; + +use test1; +select * from t1; + +drop database test1; +connection master; +drop database test1; diff --git a/mysql-test/t/rpl_change_master.test b/mysql-test/t/rpl_change_master.test index e7ae798b1a7..6c055a81ceb 100644 --- a/mysql-test/t/rpl_change_master.test +++ b/mysql-test/t/rpl_change_master.test @@ -1,26 +1,30 @@ +# Verify that after CHANGE MASTER, replication (I/O thread and SQL +# thread) restart from where SQL thread left, not from where +# I/O thread left (some old bug fixed in 4.0.17) + source include/master-slave.inc; -connection slave; -select get_lock("a",5); connection master; +# Make SQL slave thread advance a bit create table t1(n int); -insert into t1 values(1+get_lock("a",15)*0); +sync_slave_with_master; +select * from t1; +# Now stop it and make I/O slave thread be ahead +stop slave sql_thread; +connection master; +insert into t1 values(1); insert into t1 values(2); save_master_pos; connection slave; ---real_sleep 3 # can't sync_with_master as we should be blocked +--real_sleep 3 # wait for I/O thread to have read updates stop slave; -select * from t1; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 8 # 9 # 23 # 33 # ---replace_column 1 # 33 # show slave status; change master to master_user='root'; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 8 # 9 # 23 # 33 # show slave status; -# Will restart from after the values(2), which is bug -select release_lock("a"); start slave; sync_with_master; select * from t1; diff --git a/mysql-test/t/rpl_charset.test b/mysql-test/t/rpl_charset.test index a6f4c2ba9be..e916ae9ad6c 100644 --- a/mysql-test/t/rpl_charset.test +++ b/mysql-test/t/rpl_charset.test @@ -1,11 +1,9 @@ # Replication of character sets. # This test will fail if the server/client does not support enough charsets. -# Remember that there currently exists -# Bug #2326: Charset of table is determined by charset of db only if "USE db;" - source include/master-slave.inc; --disable_warnings +set timestamp=1000000000; drop database if exists mysqltest2; drop database if exists mysqltest3; --enable_warnings @@ -46,7 +44,7 @@ set character_set_client=cp850, collation_connection=latin2_croatian_ci; insert into t1 (b) values(@@character_set_server); insert into t1 (b) values(@@collation_server); # character_set_database and collation_database are not tested as they -# are not replicated (Bar said that this variable may be removed shortly). +# needn't be replicated (Bar said in Jan 2005). insert into t1 (b) values(@@character_set_client); # collation_client does not exist insert into t1 (b) values(@@character_set_connection); @@ -79,9 +77,10 @@ select "--- --slave--" as ""; --enable_query_log select * from mysqltest2.t1 order by a; -# See if SET ONE_SHOT gets into binlog when LOAD DATA -connection master; -load data infile '../../std_data/words.dat' into table t1 (b); +# Presently charset info is not logged with LOAD DATA but it will +# change in Jan 2005 when Dmitri pushes his new LOAD DATA, +# before 5.0.3 goes out. When done, LOAD DATA INFILE should be tested +# here. # See if user var is prefixed with collation in binlog and replicated well. # Note: replication of user variables is broken as far as derivation is @@ -90,6 +89,7 @@ load data infile '../../std_data/words.dat' into table t1 (b); # know if the collation was explicit or not, so we use DERIVATION_NONE, # which provokes error messages (like 'Illegal mix of collation') when # we replay the master's INSERT/etc statements. +connection master; set @a= _cp850 'Müller' collate cp850_general_ci; truncate table t1; insert into t1 (b) values(collation(@a)); @@ -106,18 +106,17 @@ select * from mysqltest2.t1 order by a; connection master; drop database mysqltest2; drop database mysqltest3; -# file_id: xx can vary depending on previous tests ---replace_regex /file_id=[0-9]/file_id=x/ -show binlog events from 79; +--replace_column 2 # 5 # +show binlog events from 98; sync_slave_with_master; -# Check that we can't change global.collation_server +# Check that we can change global.collation_server (since 5.0.3) -error 1105; set global character_set_server=latin2; +set global character_set_server=latin1; # back connection master; -error 1105; set global character_set_server=latin2; +set global character_set_server=latin1; # back # Check that SET ONE_SHOT is really one shot @@ -130,7 +129,7 @@ select @@character_set_server; select @@character_set_server; # ONE_SHOT on not charset/collation stuff is not allowed -error 1105; +-- error 1382 set one_shot max_join_size=10; # Test of wrong character set numbers; @@ -151,24 +150,10 @@ select hex(c1), hex(c2) from t1; sync_slave_with_master; select hex(c1), hex(c2) from t1; -# Now test for BUG##5705: SET CHARATER_SET_SERVERetc will be lost if -# STOP SLAVE before following query - -stop slave; -delete from t1; -change master to master_log_pos=5847; -start slave until master_log_file='master-bin.000001', master_log_pos=5983; -# Slave is supposed to stop _after_ the INSERT, even though 5983 is -# the position of the beginning of the INSERT; after SET slave is not -# supposed to increment position. -wait_for_slave_to_stop; -# When you merge this into 5.0 you will have to adjust positions -# above; the first master_log_pos above should be the one of the SET, -# the second should be the one of the INSERT. -start slave; -sync_with_master; -select hex(c1), hex(c2) from t1; connection master; +# Let's have a look at generated SETs. +--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR +--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001 drop table t1; sync_slave_with_master; diff --git a/mysql-test/t/rpl_create_database.test b/mysql-test/t/rpl_create_database.test index 96781b25f20..cfccc4567b5 100644 --- a/mysql-test/t/rpl_create_database.test +++ b/mysql-test/t/rpl_create_database.test @@ -56,6 +56,7 @@ USE mysqltest_sisyfos; CREATE TABLE t2 (a INT); let $VERSION=`select version()`; --replace_result $VERSION VERSION +--replace_column 2 # 5 # SHOW BINLOG EVENTS; SHOW DATABASES; sync_slave_with_master; diff --git a/mysql-test/t/rpl_ddl.test b/mysql-test/t/rpl_ddl.test index ce9518e80ec..d2a41a305b6 100644 --- a/mysql-test/t/rpl_ddl.test +++ b/mysql-test/t/rpl_ddl.test @@ -34,6 +34,10 @@ ############################################################### # Some preparations ############################################################### +# The sync_slave_with_master is needed to make the xids deterministic. +sync_slave_with_master; +connection master; + SET AUTOCOMMIT = 1; # # 1. DROP all objects, which probably already exist, but must be created here @@ -336,6 +340,164 @@ connection master; SELECT '-------- switch to master -------' as ""; --enable_query_log +# End of 4.1 tests + +############################################################### +# Cases with stored procedures +############################################################### +let $my_stmt= CREATE PROCEDURE p1() READS SQL DATA SELECT "this is p1"; +let $my_master_commit= true; +let $my_slave_commit= true; +--source include/rpl_stmt_seq.inc +--vertical_results +--replace_column 5 # 6 # +SHOW PROCEDURE STATUS LIKE 'p1'; +--disable_query_log +SELECT '-------- switch to slave -------' as ""; +--enable_query_log +connection slave; +--replace_column 5 # 6 # +SHOW PROCEDURE STATUS LIKE 'p1'; +connection master; +--horizontal_results + +let $my_stmt= ALTER PROCEDURE p1 COMMENT "I have been altered"; +let $my_master_commit= true; +let $my_slave_commit= true; +--source include/rpl_stmt_seq.inc +--vertical_results +--replace_column 5 # 6 # +SHOW PROCEDURE STATUS LIKE 'p1'; +--disable_query_log +SELECT '-------- switch to slave -------' as ""; +--enable_query_log +connection slave; +--replace_column 5 # 6 # +SHOW PROCEDURE STATUS LIKE 'p1'; +connection master; +--horizontal_results + +let $my_stmt= DROP PROCEDURE p1; +let $my_master_commit= true; +let $my_slave_commit= true; +--source include/rpl_stmt_seq.inc +--vertical_results +SHOW PROCEDURE STATUS LIKE 'p1'; +--disable_query_log +SELECT '-------- switch to slave -------' as ""; +--enable_query_log +connection slave; +SHOW PROCEDURE STATUS LIKE 'p1'; +connection master; +--horizontal_results + +############################################################### +# Cases with VIEWs +############################################################### +let $my_stmt= CREATE OR REPLACE VIEW v1 as select * from t1; +let $my_master_commit= true; +let $my_slave_commit= true; +--source include/rpl_stmt_seq.inc +SHOW CREATE VIEW v1; +--disable_query_log +SELECT '-------- switch to slave -------' as ""; +--enable_query_log +connection slave; +SHOW CREATE VIEW v1; +connection master; + +let $my_stmt= ALTER VIEW v1 AS select f1 from t1; +let $my_master_commit= true; +let $my_slave_commit= true; +--source include/rpl_stmt_seq.inc +SHOW CREATE VIEW v1; +--disable_query_log +SELECT '-------- switch to slave -------' as ""; +--enable_query_log +connection slave; +SHOW CREATE VIEW v1; +connection master; + +let $my_stmt= DROP VIEW IF EXISTS v1; +let $my_master_commit= true; +let $my_slave_commit= true; +--source include/rpl_stmt_seq.inc +--error 1146 +SHOW CREATE VIEW v1; +--disable_query_log +SELECT '-------- switch to slave -------' as ""; +--enable_query_log +connection slave; +--error 1146 +SHOW CREATE VIEW v1; +connection master; + +############################################################### +# Cases with TRIGGERs +############################################################### +let $my_stmt= CREATE TRIGGER trg1 BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +let $my_master_commit= true; +let $my_slave_commit= true; +--source include/rpl_stmt_seq.inc +SHOW TRIGGERS; +--disable_query_log +SELECT '-------- switch to slave -------' as ""; +--enable_query_log +connection slave; +SHOW TRIGGERS; +connection master; + +let $my_stmt= DROP TRIGGER trg1; +let $my_master_commit= true; +let $my_slave_commit= true; +--source include/rpl_stmt_seq.inc +SHOW TRIGGERS; +--disable_query_log +SELECT '-------- switch to slave -------' as ""; +--enable_query_log +connection slave; +SHOW TRIGGERS; +connection master; + +############################################################### +# Cases with USERs +############################################################### +let $my_stmt= CREATE USER user1@localhost; +let $my_master_commit= true; +let $my_slave_commit= true; +--source include/rpl_stmt_seq.inc +SELECT user FROM mysql.user WHERE user = 'user1'; +--disable_query_log +SELECT '-------- switch to slave -------' as ""; +--enable_query_log +connection slave; +SELECT user FROM mysql.user WHERE user = 'user1'; +connection master; + +let $my_stmt= RENAME USER user1@localhost TO rename1@localhost; +let $my_master_commit= true; +let $my_slave_commit= true; +--source include/rpl_stmt_seq.inc +SELECT user FROM mysql.user WHERE user = 'rename1'; +--disable_query_log +SELECT '-------- switch to slave -------' as ""; +--enable_query_log +connection slave; +SELECT user FROM mysql.user WHERE user = 'rename1'; +connection master; + +let $my_stmt= DROP USER rename1@localhost; +let $my_master_commit= true; +let $my_slave_commit= true; +--source include/rpl_stmt_seq.inc +SELECT user FROM mysql.user WHERE user = 'rename1'; +--disable_query_log +SELECT '-------- switch to slave -------' as ""; +--enable_query_log +connection slave; +SELECT user FROM mysql.user WHERE user = 'rename1'; +connection master; + ############################################################### # Cleanup ############################################################### @@ -345,4 +507,4 @@ DROP DATABASE IF EXISTS mysqltest2; DROP DATABASE IF EXISTS mysqltest3; --enable_warnings -# End of 4.1 tests + diff --git a/mysql-test/t/rpl_deadlock.test b/mysql-test/t/rpl_deadlock.test index e8ba6d6faec..684cb54611c 100644 --- a/mysql-test/t/rpl_deadlock.test +++ b/mysql-test/t/rpl_deadlock.test @@ -74,7 +74,7 @@ show slave status; # 2) Test lock wait timeout stop slave; -change master to master_log_pos=401; # the BEGIN log event +change master to master_log_pos=532; # the BEGIN log event begin; select * from t2 for update; # hold lock start slave; @@ -97,7 +97,7 @@ set global max_relay_log_size=0; # This is really copy-paste of 2) of above stop slave; -change master to master_log_pos=401; +change master to master_log_pos=532; begin; select * from t2 for update; start slave; diff --git a/mysql-test/t/rpl_delete_all.test b/mysql-test/t/rpl_delete_all.test index db33ee3bb86..e0c0757bbc2 100644 --- a/mysql-test/t/rpl_delete_all.test +++ b/mysql-test/t/rpl_delete_all.test @@ -7,7 +7,7 @@ drop database if exists mysqltest; sync_slave_with_master; # can't read dir --replace_result "Errcode: 1" "Errcode: X" "Errcode: 2" "Errcode: X" \\ / ---error 12 +--error 1049 show tables from mysqltest; connection slave; diff --git a/mysql-test/t/rpl_drop_db.test b/mysql-test/t/rpl_drop_db.test index 98afc6e3d02..3ac0d593fee 100644 --- a/mysql-test/t/rpl_drop_db.test +++ b/mysql-test/t/rpl_drop_db.test @@ -53,5 +53,5 @@ sync_slave_with_master; #cleanup connection slave; stop slave; -system rm -rf var/master-data/mysqltest1; +system rm -rf $MYSQLTEST_VARDIR/master-data/mysqltest1; diff --git a/mysql-test/t/rpl_empty_master_crash.test b/mysql-test/t/rpl_empty_master_crash.test index eae967a4bb1..5f26bedc9fe 100644 --- a/mysql-test/t/rpl_empty_master_crash.test +++ b/mysql-test/t/rpl_empty_master_crash.test @@ -1,6 +1,6 @@ source include/master-slave.inc; ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; # diff --git a/mysql-test/t/rpl_error_ignored_table.test b/mysql-test/t/rpl_error_ignored_table.test index 8076d835ac0..339d966dbb3 100644 --- a/mysql-test/t/rpl_error_ignored_table.test +++ b/mysql-test/t/rpl_error_ignored_table.test @@ -45,10 +45,11 @@ select (@id := id) - id from t3; kill @id; drop table t2,t3; connection master; ---error 0,1053 +--error 0,1053,2013 reap; connection master1; -show binlog events from 79; +--replace_column 2 # 5 # +show binlog events from 98; save_master_pos; connection slave; # SQL slave thread should not have stopped (because table of the killed @@ -56,3 +57,4 @@ connection slave; sync_with_master; # End of 4.1 tests +# Adding comment for force manual merge 5.0 -> wl1012. delete me if needed diff --git a/mysql-test/t/rpl_failed_optimize.test b/mysql-test/t/rpl_failed_optimize.test index 57afaa89e83..8c4698c0d9b 100644 --- a/mysql-test/t/rpl_failed_optimize.test +++ b/mysql-test/t/rpl_failed_optimize.test @@ -17,4 +17,7 @@ OPTIMIZE TABLE t1; OPTIMIZE TABLE non_existing; sync_slave_with_master; +connection master; +drop table t1; +sync_slave_with_master; # End of 4.1 tests diff --git a/mysql-test/t/rpl_flush_log_loop-master.opt b/mysql-test/t/rpl_flush_log_loop-master.opt index 4f6e0f3d00c..a4d1d403dc9 100644 --- a/mysql-test/t/rpl_flush_log_loop-master.opt +++ b/mysql-test/t/rpl_flush_log_loop-master.opt @@ -1 +1 @@ --O max_binlog_size=1M --relay-log=$MYSQL_TEST_DIR/var/master-data/relay-log +-O max_binlog_size=1M --relay-log=$MYSQLTEST_VARDIR/master-data/relay-log diff --git a/mysql-test/t/rpl_flush_log_loop-master.sh b/mysql-test/t/rpl_flush_log_loop-master.sh index 9e56af99f5c..a321dd690cd 100755 --- a/mysql-test/t/rpl_flush_log_loop-master.sh +++ b/mysql-test/t/rpl_flush_log_loop-master.sh @@ -1,5 +1,5 @@ -rm -f $MYSQL_TEST_DIR/var/slave-data/*-bin.* -rm -f $MYSQL_TEST_DIR/var/slave-data/master.info -rm -f $MYSQL_TEST_DIR/var/slave-data/*.index +rm -f $MYSQLTEST_VARDIR/slave-data/*-bin.* +rm -f $MYSQLTEST_VARDIR/slave-data/master.info +rm -f $MYSQLTEST_VARDIR/slave-data/*.index diff --git a/mysql-test/t/rpl_flush_log_loop-slave.opt b/mysql-test/t/rpl_flush_log_loop-slave.opt index d1373f139b1..95839c831c9 100644 --- a/mysql-test/t/rpl_flush_log_loop-slave.opt +++ b/mysql-test/t/rpl_flush_log_loop-slave.opt @@ -1 +1 @@ --O max_binlog_size=1M --relay-log=$MYSQL_TEST_DIR/var/slave-data/relay-log +-O max_binlog_size=1M --relay-log=$MYSQLTEST_VARDIR/slave-data/relay-log diff --git a/mysql-test/t/rpl_flush_log_loop-slave.sh b/mysql-test/t/rpl_flush_log_loop-slave.sh index b8814e059a9..e46ea6d400b 100755 --- a/mysql-test/t/rpl_flush_log_loop-slave.sh +++ b/mysql-test/t/rpl_flush_log_loop-slave.sh @@ -1,4 +1,4 @@ -rm -f $MYSQL_TEST_DIR/var/master-data/master.info -rm -f $MYSQL_TEST_DIR/var/master-data/*-bin.* -rm -f $MYSQL_TEST_DIR/var/master-data/*.index +rm -f $MYSQLTEST_VARDIR/master-data/master.info +rm -f $MYSQLTEST_VARDIR/master-data/*-bin.* +rm -f $MYSQLTEST_VARDIR/master-data/*.index diff --git a/mysql-test/t/rpl_flush_log_loop.test b/mysql-test/t/rpl_flush_log_loop.test index e08f1a23ef3..6e45047bd30 100644 --- a/mysql-test/t/rpl_flush_log_loop.test +++ b/mysql-test/t/rpl_flush_log_loop.test @@ -18,7 +18,7 @@ sleep 5; flush logs; sleep 5; --replace_result $SLAVE_MYPORT SLAVE_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; # End of 4.1 tests diff --git a/mysql-test/t/rpl_flush_tables.test b/mysql-test/t/rpl_flush_tables.test index aea8d7a5353..f7c8774286a 100644 --- a/mysql-test/t/rpl_flush_tables.test +++ b/mysql-test/t/rpl_flush_tables.test @@ -23,6 +23,7 @@ rename table t1 to t5, t2 to t1; flush no_write_to_binlog tables; # Check that it's not in the binlog. --replace_result $SERVER_VERSION SERVER_VERSION +--replace_column 2 # 5 # show binlog events; # Check that the master is not confused. select * from t3; @@ -30,6 +31,7 @@ select * from t3; flush tables; # Check that it's in the binlog. --replace_result $SERVER_VERSION SERVER_VERSION +--replace_column 2 # 5 # show binlog events; save_master_pos; connection slave; @@ -49,4 +51,8 @@ sleep 1; --error 1192 stop slave; +connection master; +drop table t3, t4, t5; + # End of 4.1 tests +# Adding comment for force manual merge 5.0 -> wl1012. Delete me if needed. diff --git a/mysql-test/t/rpl_get_lock.test b/mysql-test/t/rpl_get_lock.test index a0e3c829c11..945bd98c993 100644 --- a/mysql-test/t/rpl_get_lock.test +++ b/mysql-test/t/rpl_get_lock.test @@ -22,6 +22,13 @@ connection slave; sync_with_master; select get_lock("lock",3); select * from t1; +# There is no point in testing REPLICATIION of the IS_*_LOCK +# functions; slave does not run with the same concurrency context as +# master (generally in slave we can't know that on master this lock +# was already held by another connection and so that the the +# get_lock() we're replicating timed out on master hence returned 0, +# or that the is_free_lock() we're playing returned 0 etc. +# But here all we do is test these functions outside of replication. select is_free_lock("lock"), is_used_lock("lock") = connection_id(); explain extended select is_free_lock("lock"), is_used_lock("lock"); # Check lock functions diff --git a/mysql-test/t/rpl_ignore_revoke-slave.opt b/mysql-test/t/rpl_ignore_revoke-slave.opt new file mode 100644 index 00000000000..e931bfbd37e --- /dev/null +++ b/mysql-test/t/rpl_ignore_revoke-slave.opt @@ -0,0 +1 @@ +--replicate-wild-ignore-table=mysql.% diff --git a/mysql-test/t/rpl_ignore_revoke.test b/mysql-test/t/rpl_ignore_revoke.test new file mode 100644 index 00000000000..cdeb40df069 --- /dev/null +++ b/mysql-test/t/rpl_ignore_revoke.test @@ -0,0 +1,47 @@ +# test verifies that REVOKE must not be replicated when +# slave server starts with --replicate-wild-ignore-table=mysql.% +# the option is set in rpl_ignore_revoke-slave.opt +# The first part of BUG#9483 for GRANT is checked by +# existed specific rpl_ignore_grant test case (BUG#980) + + +source include/master-slave.inc; + +### CLEAN-UP: create an account and manually duplicate it on the slave + +connection master; +grant select on *.* to 'user_foo'@'%' identified by 'user_foopass'; +revoke select on *.* from 'user_foo'@'%'; +select select_priv from mysql.user where user='user_foo' /* master:must be N */; + +sync_slave_with_master; +#connection slave; +grant select on *.* to 'user_foo'@'%' identified by 'user_foopass'; +revoke select on *.* from 'user_foo'@'%'; +select select_priv from mysql.user where user='user_foo' /* slave:must be N */; + + +### TEST + +#connection slave; +grant select on *.* to 'user_foo'@'%' identified by 'user_foopass'; +select select_priv from mysql.user where user='user_foo' /* slave:must be Y */; + +connection master; +revoke select on *.* from 'user_foo'; +select select_priv from mysql.user where user='user_foo' /* master:must be N */; + +sync_slave_with_master; +#connection slave; +select select_priv from mysql.user where user='user_foo' /* slave:must get Y */; + +### CLEAN-UP + +connection slave; +--disable_abort_on_error +revoke select on *.* FROM 'user_foo'; +--enable_abort_on_error + +connection master; +delete from mysql.user where user="user_foo"; +sync_slave_with_master; diff --git a/mysql-test/t/rpl_innodb.test b/mysql-test/t/rpl_innodb.test index 551657fd7e3..b88276e2107 100644 --- a/mysql-test/t/rpl_innodb.test +++ b/mysql-test/t/rpl_innodb.test @@ -18,7 +18,7 @@ CREATE TABLE t4 ( --disable_warnings LOAD DATA - INFILE '../../std_data/loaddata_pair.dat' + INFILE '../std_data_ln/loaddata_pair.dat' REPLACE INTO TABLE t4 (name,number); --enable_warnings @@ -30,7 +30,7 @@ SELECT * FROM t4; connection master; --disable_warnings LOAD DATA - INFILE '../../std_data/loaddata_pair.dat' + INFILE '../std_data_ln/loaddata_pair.dat' REPLACE INTO TABLE t4 (name,number); --enable_warnings diff --git a/mysql-test/t/rpl_insert_id.test b/mysql-test/t/rpl_insert_id.test index 7fb514fb7af..331a913256c 100644 --- a/mysql-test/t/rpl_insert_id.test +++ b/mysql-test/t/rpl_insert_id.test @@ -87,13 +87,16 @@ SET FOREIGN_KEY_CHECKS=0; --error 1062 INSERT INTO t1 VALUES (1),(1); sync_slave_with_master; + +connection master; +drop table t1; +sync_slave_with_master; --echo # --echo # Bug#14553: NULL in WHERE resets LAST_INSERT_ID --echo # connection master; -drop table t1; create table t1(a int auto_increment, key(a)); create table t2(a int); insert into t1 (a) values (null); @@ -108,38 +111,272 @@ drop table t1; drop table t2; sync_slave_with_master; +--echo # +--echo # End of 4.1 tests +--echo # # -# BUG#21726: Incorrect result with multiple invocations of -# LAST_INSERT_ID +# BUG#15728: LAST_INSERT_ID function inside a stored function returns 0 +# +# The solution is not to reset last_insert_id on enter to sub-statement. # connection master; +--disable_warnings +drop function if exists bug15728; +drop function if exists bug15728_insert; +drop table if exists t1, t2; +--enable_warnings + +create table t1 ( + id int not null auto_increment, + last_id int, + primary key (id) +); +create function bug15728() returns int(11) + return last_insert_id(); + +insert into t1 (last_id) values (0); +insert into t1 (last_id) values (last_insert_id()); +insert into t1 (last_id) values (bug15728()); + +# Check that nested call replicates too. +create table t2 ( + id int not null auto_increment, + last_id int, + primary key (id) +); +delimiter |; +create function bug15728_insert() returns int(11) modifies sql data +begin + insert into t2 (last_id) values (bug15728()); + return bug15728(); +end| +create trigger t1_bi before insert on t1 for each row +begin + declare res int; + select bug15728_insert() into res; + set NEW.last_id = res; +end| +delimiter ;| + +insert into t1 (last_id) values (0); + +drop trigger t1_bi; + +# Check that nested call doesn't affect outer context. +select last_insert_id(); +select bug15728_insert(); +select last_insert_id(); +insert into t1 (last_id) values (bug15728()); +# This should be exactly one greater than in the previous call. +select last_insert_id(); + +save_master_pos; +connection slave; +sync_with_master; +select * from t1; +select * from t2; +connection master; + +drop function bug15728; +drop function bug15728_insert; +drop table t1, t2; +# test of BUG#20188 REPLACE or ON DUPLICATE KEY UPDATE in +# auto_increment breaks binlog + +create table t1 (n int primary key auto_increment not null, +b int, unique(b)); + +# First, test that we do not call restore_auto_increment() too early +# in write_record(): +set sql_log_bin=0; +insert into t1 values(null,100); +replace into t1 values(null,50),(null,100),(null,150); +select * from t1 order by n; +truncate table t1; +set sql_log_bin=1; + +insert into t1 values(null,100); +select * from t1 order by n; +sync_slave_with_master; +# make slave's table autoinc counter bigger +insert into t1 values(null,200),(null,300); +delete from t1 where b <> 100; +# check that slave's table content is identical to master +select * from t1 order by n; +# only the auto_inc counter differs. + +connection master; +replace into t1 values(null,100),(null,350); +select * from t1 order by n; +sync_slave_with_master; +select * from t1 order by n; + +# Same test as for REPLACE, but for ON DUPLICATE KEY UPDATE + +# We first check that if we update a row using a value larger than the +# table's counter, the counter for next row is bigger than the +# after-value of the updated row. +connection master; +insert into t1 values (NULL,400),(3,500),(NULL,600) on duplicate key UPDATE n=1000; +select * from t1 order by n; +sync_slave_with_master; +select * from t1 order by n; + +# and now test for the bug: +connection master; +drop table t1; +create table t1 (n int primary key auto_increment not null, +b int, unique(b)); +insert into t1 values(null,100); +select * from t1 order by n; +sync_slave_with_master; +insert into t1 values(null,200),(null,300); +delete from t1 where b <> 100; +select * from t1 order by n; + +connection master; +insert into t1 values(null,100),(null,350) on duplicate key update n=2; +select * from t1 order by n; +sync_slave_with_master; +select * from t1 order by n; + +connection master; +drop table t1; + +# +# BUG#20339: stored procedure using LAST_INSERT_ID() does not +# replicate statement-based +# --disable_warnings -DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +DROP TABLE IF EXISTS t1, t2; +--enable_warnings + +# Reset result of LAST_INSERT_ID(). +SELECT LAST_INSERT_ID(0); + +CREATE TABLE t1 ( + id INT NOT NULL DEFAULT 0, + last_id INT, + PRIMARY KEY (id) +); + +CREATE TABLE t2 ( + id INT NOT NULL AUTO_INCREMENT, + last_id INT, + PRIMARY KEY (id) +); + +delimiter |; +CREATE PROCEDURE p1() +BEGIN + INSERT INTO t2 (last_id) VALUES (LAST_INSERT_ID()); + INSERT INTO t1 (last_id) VALUES (LAST_INSERT_ID()); +END| +delimiter ;| + +CALL p1(); +SELECT * FROM t1; +SELECT * FROM t2; + +sync_slave_with_master; +SELECT * FROM t1; +SELECT * FROM t2; + +connection master; + +DROP PROCEDURE p1; +DROP TABLE t1, t2; + + +# +# BUG#21726: Incorrect result with multiple invocations of +# LAST_INSERT_ID +# +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP TABLE IF EXISTS t1, t2; --enable_warnings CREATE TABLE t1 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, j INT DEFAULT 0 ); +CREATE TABLE t2 (i INT); + +delimiter |; +CREATE PROCEDURE p1() +BEGIN + INSERT INTO t1 (i) VALUES (NULL); + INSERT INTO t2 (i) VALUES (LAST_INSERT_ID()); + INSERT INTO t1 (i) VALUES (NULL), (NULL); + INSERT INTO t2 (i) VALUES (LAST_INSERT_ID()); +END | + +CREATE FUNCTION f1() RETURNS INT MODIFIES SQL DATA +BEGIN + INSERT INTO t1 (i) VALUES (NULL); + INSERT INTO t2 (i) VALUES (LAST_INSERT_ID()); + INSERT INTO t1 (i) VALUES (NULL), (NULL); + INSERT INTO t2 (i) VALUES (LAST_INSERT_ID()); + RETURN 0; +END | + +CREATE FUNCTION f2() RETURNS INT NOT DETERMINISTIC + RETURN LAST_INSERT_ID() | + +CREATE FUNCTION f3() RETURNS INT MODIFIES SQL DATA +BEGIN + INSERT INTO t2 (i) VALUES (LAST_INSERT_ID()); + RETURN 0; +END | +delimiter ;| INSERT INTO t1 VALUES (NULL, -1); +CALL p1(); +SELECT f1(); +INSERT INTO t1 VALUES (NULL, f2()), (NULL, LAST_INSERT_ID()), + (NULL, LAST_INSERT_ID()), (NULL, f2()), (NULL, f2()); +INSERT INTO t1 VALUES (NULL, f2()); INSERT INTO t1 VALUES (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID(5)), (NULL, @@LAST_INSERT_ID); # Test replication of substitution "IS NULL" -> "= LAST_INSERT_ID". INSERT INTO t1 VALUES (NULL, 0), (NULL, LAST_INSERT_ID()); UPDATE t1 SET j= -1 WHERE i IS NULL; +# Test statement-based replication of function calls. +INSERT INTO t1 (i) VALUES (NULL); + +connection master1; +INSERT INTO t1 (i) VALUES (NULL); + +connection master; +SELECT f3(); + SELECT * FROM t1; +SELECT * FROM t2; sync_slave_with_master; SELECT * FROM t1; +SELECT * FROM t2; connection master; -DROP TABLE t1; +DROP PROCEDURE p1; +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP FUNCTION f3; +DROP TABLE t1, t2; + + +sync_slave_with_master; + +--echo +--echo # End of 5.0 tests +--echo ---echo # ---echo # End of 4.1 tests ---echo # diff --git a/mysql-test/t/rpl_loaddata.test b/mysql-test/t/rpl_loaddata.test index 65855dd3ceb..5ebdec6f761 100644 --- a/mysql-test/t/rpl_loaddata.test +++ b/mysql-test/t/rpl_loaddata.test @@ -18,10 +18,10 @@ reset master; connection master; create table t1(a int not null auto_increment, b int, primary key(a) ); -load data infile '../../std_data/rpl_loaddata.dat' into table t1; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1; create temporary table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60)); -load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines; +load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines; create table t3 (day date,id int(9),category enum('a','b','c'),name varchar(60)); insert into t3 select * from t2; @@ -36,8 +36,7 @@ select * from t3; # But we can't simply read this binlog, because as the slave has not been # restarted for this test, the file_id is uncertain (would cause test # failures). So instead, we test if the binlog looks long enough to -# contain LOAD DATA. That is, I (Guilhem) have done SHOW BINLOG EVENTS on my -# machine, saw that the binlog is of size 964 when things go fine. +# contain LOAD DATA. Since 5.0.3 we assume that binlog of 1292 is ok. # If LOAD DATA was not logged, the binlog would be shorter. show master status; @@ -57,7 +56,7 @@ sync_with_master; insert into t1 values(1,10); connection master; -load data infile '../../std_data/rpl_loaddata.dat' into table t1; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1; save_master_pos; connection slave; @@ -81,10 +80,12 @@ connection master; set sql_log_bin=0; delete from t1; set sql_log_bin=1; -load data infile '../../std_data/rpl_loaddata.dat' into table t1; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1; save_master_pos; connection slave; -# The SQL slave thread should be stopped now. +# The SQL slave thread should be stopped now. +# Exec_Master_Log_Pos should point to the start of Execute event +# for last load data. wait_for_slave_to_stop; # CHANGE MASTER and see if error is cleared in SHOW SLAVE STATUS. @@ -104,7 +105,7 @@ connection master; set sql_log_bin=0; delete from t1; set sql_log_bin=1; -load data infile '../../std_data/rpl_loaddata.dat' into table t1; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1; save_master_pos; connection slave; # The SQL slave thread should be stopped now. @@ -122,14 +123,32 @@ show slave status; connection master; reset master; create table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60), -unique(day)); +unique(day)) engine=MyISAM; # no transactions --error 1062 -load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields +load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines; -# To test that there is Create_file & Delete_file, we test if the binlog is as -# long as expected (can't do SHOW BINLOG EVENTS because of varying file_id). -show master status; -drop table t2; +select * from t2; +save_master_pos; +connection slave; +start slave; +sync_with_master; +select * from t2; + +# verify that if no error on slave, this is an error +alter table t2 drop key day; +connection master; +delete from t2; +--error 1062 +load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields +terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by +'\n##\n' starting by '>' ignore 1 lines; +connection slave; +wait_for_slave_to_stop; +drop table t2; +connection master; +drop table t2; +drop table t1; +sync_with_master; # End of 4.1 tests diff --git a/mysql-test/t/rpl_loaddata_rule_m.test b/mysql-test/t/rpl_loaddata_rule_m.test index 1ece82122ea..4b8e5326c98 100644 --- a/mysql-test/t/rpl_loaddata_rule_m.test +++ b/mysql-test/t/rpl_loaddata_rule_m.test @@ -18,8 +18,16 @@ connection master; create database mysqltest; create table t1(a int, b int, unique(b)); use mysqltest; -load data infile '../../std_data/rpl_loaddata.dat' into table test.t1; -show binlog events from 79; # should be nothing +load data infile '../std_data_ln/rpl_loaddata.dat' into table test.t1; +# Starting from 5.0.3 LOAD DATA is replicated much in the same way as ordinary +# query so "show binlog ..." should show two events (before 5.0.3 no events +# were returned). +--replace_column 2 # 5 # +show binlog events from 98; + drop database mysqltest; +use test; +drop table t1; # End of 4.1 tests +# Adding comment for force manual merge 5.0 -> wl1012: Delete me diff --git a/mysql-test/t/rpl_loaddata_rule_s.test b/mysql-test/t/rpl_loaddata_rule_s.test index b4a9b5b2ee0..2061e898811 100644 --- a/mysql-test/t/rpl_loaddata_rule_s.test +++ b/mysql-test/t/rpl_loaddata_rule_s.test @@ -9,7 +9,7 @@ reset master; connection master; # 'test' is the current database create table t1(a int, b int, unique(b)); -load data infile '../../std_data/rpl_loaddata.dat' into table test.t1; +load data infile '../std_data_ln/rpl_loaddata.dat' into table test.t1; # Test logging on slave; @@ -17,6 +17,9 @@ save_master_pos; connection slave; sync_with_master; select count(*) from t1; # check that LOAD was replicated -show binlog events from 79; # should be nothing +show binlog events from 98; # should be nothing + +connection master; +drop table t1; # End of 4.1 tests diff --git a/mysql-test/t/rpl_loaddatalocal.test b/mysql-test/t/rpl_loaddatalocal.test index fd91aba856a..af4fd0106bd 100644 --- a/mysql-test/t/rpl_loaddatalocal.test +++ b/mysql-test/t/rpl_loaddatalocal.test @@ -14,8 +14,7 @@ disable_query_log; set SQL_LOG_BIN=0; while ($1) { -#eval means expand $ expressions - eval insert into t1 values(1); + insert into t1 values(1); dec $1; } set SQL_LOG_BIN=1; @@ -26,7 +25,7 @@ eval select * into outfile '$MYSQLTEST_VARDIR/master-data/rpl_loaddatalocal.sele truncate table t1; --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR eval load data local infile '$MYSQLTEST_VARDIR/master-data/rpl_loaddatalocal.select_outfile' into table t1; ---remove_file $MYSQLTEST_VARDIR/master-data/rpl_loaddatalocal.select_outfile +system rm $MYSQLTEST_VARDIR/master-data/rpl_loaddatalocal.select_outfile ; save_master_pos; connection slave; sync_with_master; @@ -38,3 +37,29 @@ connection slave; sync_with_master; # End of 4.1 tests + +# +# Now let us test how well we replicate LOAD DATA LOCAL in situation when +# we met duplicates in tables to which we are adding rows. +# (It supposed that LOAD DATA LOCAL ignores such errors) +# +connection master; +create table t1(a int); +insert into t1 values (1), (2), (2), (3); +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval select * into outfile '$MYSQLTEST_VARDIR/master-data/rpl_loaddatalocal.select_outfile' from t1; +drop table t1; +create table t1(a int primary key); +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval load data local infile '$MYSQLTEST_VARDIR/master-data/rpl_loaddatalocal.select_outfile' into table t1; +system rm $MYSQLTEST_VARDIR/master-data/rpl_loaddatalocal.select_outfile ; +select * from t1; +save_master_pos; +connection slave; +sync_with_master; +select * from t1; +connection master; +drop table t1; +save_master_pos; +connection slave; +sync_with_master; diff --git a/mysql-test/t/rpl_log.test b/mysql-test/t/rpl_log.test index 40fc36cad4a..578a39efd6e 100644 --- a/mysql-test/t/rpl_log.test +++ b/mysql-test/t/rpl_log.test @@ -33,14 +33,14 @@ create table t1(n int not null auto_increment primary key); insert into t1 values (NULL); drop table t1; create table t1 (word char(20) not null); -load data infile '../../std_data/words.dat' into table t1 ignore 1 lines; +load data infile '../std_data_ln/words.dat' into table t1 ignore 1 lines; select count(*) from t1; drop table t1; --replace_result $VERSION VERSION show binlog events; -show binlog events from 79 limit 1; -show binlog events from 79 limit 2; -show binlog events from 79 limit 2,1; +show binlog events from 98 limit 1; +show binlog events from 98 limit 2; +show binlog events from 98 limit 2,1; flush logs; # We need an extra update before doing save_master_pos. @@ -82,6 +82,7 @@ insert into t1 values (1); drop table t1; --replace_result $VERSION VERSION show binlog events; +--replace_result $VERSION VERSION show binlog events in 'master-bin.000002'; show binary logs; save_master_pos; @@ -123,3 +124,4 @@ select * from t1; drop table t1; # End of 4.1 tests +# Adding comment for force manual merge 5.0 -> wl1012: Delete me diff --git a/mysql-test/t/rpl_log_pos.test b/mysql-test/t/rpl_log_pos.test index 25a485c7947..979b146bb22 100644 --- a/mysql-test/t/rpl_log_pos.test +++ b/mysql-test/t/rpl_log_pos.test @@ -5,7 +5,7 @@ source include/master-slave.inc; show master status; sync_slave_with_master; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; stop slave; change master to master_log_pos=73; @@ -15,19 +15,19 @@ stop slave; change master to master_log_pos=73; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; start slave; sleep 5; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; stop slave; change master to master_log_pos=173; start slave; sleep 2; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; connection master; show master status; @@ -38,7 +38,7 @@ insert into t1 values (1),(2),(3); save_master_pos; connection slave; stop slave; -change master to master_log_pos=79; +change master to master_log_pos=98; start slave; sync_with_master; select * from t1; diff --git a/mysql-test/t/rpl_max_relay_size.test b/mysql-test/t/rpl_max_relay_size.test index 003f60df28f..be1fbf172fc 100644 --- a/mysql-test/t/rpl_max_relay_size.test +++ b/mysql-test/t/rpl_max_relay_size.test @@ -127,4 +127,6 @@ connection master; flush logs; show master status; -# End of 4.1 tests +--echo # +--echo # End of 4.1 tests +--echo # diff --git a/mysql-test/t/rpl_misc_functions-slave.sh b/mysql-test/t/rpl_misc_functions-slave.sh index c293715e16f..8ce79797822 100755 --- a/mysql-test/t/rpl_misc_functions-slave.sh +++ b/mysql-test/t/rpl_misc_functions-slave.sh @@ -1 +1 @@ -rm -f $MYSQL_TEST_DIR/var/master-data/test/rpl_misc_functions.outfile +rm -f $MYSQLTEST_VARDIR/master-data/test/rpl_misc_functions.outfile diff --git a/mysql-test/t/rpl_misc_functions.test b/mysql-test/t/rpl_misc_functions.test index f20d0aa83e4..6e0bda90503 100644 --- a/mysql-test/t/rpl_misc_functions.test +++ b/mysql-test/t/rpl_misc_functions.test @@ -24,9 +24,14 @@ select * into outfile 'rpl_misc_functions.outfile' from t1; sync_slave_with_master; create table t2 like t1; # read the values from the master table -load data local infile './var/master-data/test/rpl_misc_functions.outfile' into table t2; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval load data local infile '$MYSQLTEST_VARDIR/master-data/test/rpl_misc_functions.outfile' into table t2; # compare them with the replica; the SELECT below should return no row select * from t1, t2 where (t1.id=t2.id) and not(t1.i=t2.i and t1.r1=t2.r1 and t1.r2=t2.r2 and t1.p=t2.p); stop slave; +drop table t1; + +connection master; +drop table t1; # End of 4.1 tests diff --git a/mysql-test/t/rpl_multi_delete.test b/mysql-test/t/rpl_multi_delete.test index 2fd7b820b1a..4a8c0ab6912 100644 --- a/mysql-test/t/rpl_multi_delete.test +++ b/mysql-test/t/rpl_multi_delete.test @@ -16,10 +16,26 @@ sync_with_master; select * from t1; select * from t2; +# End of 4.1 tests + +# Check if deleting 0 rows is binlogged (BUG#13348) + connection master; -drop table t1,t2; -save_master_pos; -connection slave; -sync_with_master; +delete from t1; +delete from t2; -# End of 4.1 tests +sync_slave_with_master; +# force a difference to see if master's multi-DELETE will correct it +insert into t1 values(1); +insert into t2 values(1); + +connection master; +DELETE t1.*, t2.* from t1, t2; + +sync_slave_with_master; +select * from t1; +select * from t2; + +connection master; +drop table t1,t2; +sync_slave_with_master; diff --git a/mysql-test/t/rpl_multi_query.test b/mysql-test/t/rpl_multi_query.test index 7c764bd4ea2..b4cd88f756e 100644 --- a/mysql-test/t/rpl_multi_query.test +++ b/mysql-test/t/rpl_multi_query.test @@ -24,8 +24,9 @@ sync_slave_with_master; select * from mysqltest.t1; connection master; --replace_column 2 # 5 # -show binlog events from 79; +show binlog events from 98; drop database mysqltest; sync_slave_with_master; # End of 4.1 tests +# diff --git a/mysql-test/t/rpl_multi_update.test b/mysql-test/t/rpl_multi_update.test index dd75edb3055..f6a960434ad 100644 --- a/mysql-test/t/rpl_multi_update.test +++ b/mysql-test/t/rpl_multi_update.test @@ -24,3 +24,26 @@ connection slave; sync_with_master; # End of 4.1 tests + +# Check if updating 0 rows is binlogged (BUG#13348) + +connection master; +delete from t1; +delete from t2; +insert into t1 values(1,1); +insert into t2 values(1,1); + +sync_slave_with_master; +# force a difference to see if master's multi-UPDATE will correct it +update t1 set a=2; + +connection master; +UPDATE t1, t2 SET t1.a = t2.a; + +sync_slave_with_master; +select * from t1; +select * from t2; + +connection master; +drop table t1, t2; +sync_slave_with_master; diff --git a/mysql-test/t/rpl_multi_update3.test b/mysql-test/t/rpl_multi_update3.test index 36ac7a59cb3..8d566764ad9 100644 --- a/mysql-test/t/rpl_multi_update3.test +++ b/mysql-test/t/rpl_multi_update3.test @@ -217,4 +217,7 @@ select "-- SLAVE AFTER JOIN --" as ""; select * from t1; select * from t2; +connection master; +drop table t1, t2; +sync_slave_with_master; # End of 4.1 tests diff --git a/mysql-test/t/rpl_ndb_innodb_trans-slave.opt b/mysql-test/t/rpl_ndb_innodb_trans-slave.opt new file mode 100644 index 00000000000..627becdbfb5 --- /dev/null +++ b/mysql-test/t/rpl_ndb_innodb_trans-slave.opt @@ -0,0 +1 @@ +--innodb diff --git a/mysql-test/t/rpl_ndb_innodb_trans.test b/mysql-test/t/rpl_ndb_innodb_trans.test new file mode 100644 index 00000000000..127c2464570 --- /dev/null +++ b/mysql-test/t/rpl_ndb_innodb_trans.test @@ -0,0 +1,66 @@ +# Test of a transaction mixing the two engines + +-- source include/have_ndb.inc +-- source include/have_innodb.inc +-- source include/master-slave.inc + +create table t1 (a int, unique(a)) engine=ndbcluster; +create table t2 (a int, unique(a)) engine=innodb; + + +begin; +insert into t1 values(1); +insert into t2 values(1); +rollback; + +select count(*) from t1; +select count(*) from t2; +sync_slave_with_master; +select count(*) from t1; +select count(*) from t2; +connection master; + +begin; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t2; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1; +rollback; + +select count(*) from t1; +select count(*) from t2; +sync_slave_with_master; +select count(*) from t1; +select count(*) from t2; +connection master; + +delete from t1; +delete from t2; +begin; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t2; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1; +rollback; + +select count(*) from t1; +select count(*) from t2; +sync_slave_with_master; +select count(*) from t1; +select count(*) from t2; +connection master; + +delete from t1; +delete from t2; +begin; +insert into t2 values(3),(4); +insert into t1 values(3),(4); +load data infile '../std_data_ln/rpl_loaddata.dat' into table t2; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1; +rollback; + +select count(*) from t1; +select count(*) from t2; +sync_slave_with_master; +select count(*) from t1; +select count(*) from t2; +connection master; + +drop table t1,t2; +sync_slave_with_master; diff --git a/mysql-test/t/rpl_openssl.test b/mysql-test/t/rpl_openssl.test index 83a3a340e6d..af70a1a9453 100644 --- a/mysql-test/t/rpl_openssl.test +++ b/mysql-test/t/rpl_openssl.test @@ -1,4 +1,8 @@ -source include/have_openssl_1.inc; +# TODO: THIS TEST DOES NOT WORK ON WINDOWS +# This should be fixed. +--source include/not_windows.inc + +source include/have_openssl.inc; source include/master-slave.inc; # We don't test all types of ssl auth params here since it's a bit hard @@ -45,7 +49,7 @@ select * from t1; #checking show slave status --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR $MASTER_MYPORT MASTER_MYPORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; #checking if replication works without ssl also performing clean up @@ -53,12 +57,13 @@ stop slave; change master to master_user='root',master_password='', master_ssl=0; start slave; connection master; +drop user replssl@localhost; drop table t1; save_master_pos; connection slave; sync_with_master; --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR $MASTER_MYPORT MASTER_MYPORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; # End of 4.1 tests diff --git a/mysql-test/t/rpl_redirect.test b/mysql-test/t/rpl_redirect.test index 18f68b1fd03..beb18348b40 100644 --- a/mysql-test/t/rpl_redirect.test +++ b/mysql-test/t/rpl_redirect.test @@ -14,7 +14,7 @@ sync_with_master; #discover slaves connection master; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # SHOW SLAVE STATUS; --replace_result $SLAVE_MYPORT SLAVE_PORT SHOW SLAVE HOSTS; diff --git a/mysql-test/t/rpl_relayrotate-slave.opt b/mysql-test/t/rpl_relayrotate-slave.opt index 8b671423363..3a4abbf091e 100644 --- a/mysql-test/t/rpl_relayrotate-slave.opt +++ b/mysql-test/t/rpl_relayrotate-slave.opt @@ -1,4 +1,3 @@ --O max_binlog_size=16384 +-O max_relay_log_size=16384 --innodb --log-warnings - diff --git a/mysql-test/t/rpl_replicate_do.test b/mysql-test/t/rpl_replicate_do.test index b8559af2394..9dec8c06c79 100644 --- a/mysql-test/t/rpl_replicate_do.test +++ b/mysql-test/t/rpl_replicate_do.test @@ -12,7 +12,7 @@ create table t2 (n int); insert into t2 values(4); connection master; create table t2 (s char(20)); -load data infile '../../std_data/words.dat' into table t2; +load data infile '../std_data_ln/words.dat' into table t2; insert into t2 values('five'); create table t1 (m int); insert into t1 values(15),(16),(17); @@ -54,4 +54,8 @@ connection slave; set one_shot time_zone='met'; select * from t1; +connection master; +drop table t1; +sync_slave_with_master; + # End of 4.1 tests diff --git a/mysql-test/t/rpl_reset_slave.test b/mysql-test/t/rpl_reset_slave.test index 102c72d9882..00b1cf68294 100644 --- a/mysql-test/t/rpl_reset_slave.test +++ b/mysql-test/t/rpl_reset_slave.test @@ -11,24 +11,24 @@ save_master_pos; connection slave; sync_with_master; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; stop slave; change master to master_user='test'; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; reset slave; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; start slave; sync_with_master; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; # test of crash with temp tables & RESET SLAVE @@ -48,3 +48,4 @@ sync_with_master; show status like 'slave_open_temp_tables'; # End of 4.1 tests +# diff --git a/mysql-test/t/rpl_rewrite_db.test b/mysql-test/t/rpl_rewrite_db.test index 1e8e5a992d8..6b8624aff39 100644 --- a/mysql-test/t/rpl_rewrite_db.test +++ b/mysql-test/t/rpl_rewrite_db.test @@ -31,8 +31,8 @@ create database rewrite; connection master; use test; create table t1 (a date, b date, c date not null, d date); -load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ','; -load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES; +load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ','; +load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES; sync_slave_with_master; connection slave; @@ -40,7 +40,7 @@ select * from rewrite.t1; connection master; truncate table t1; -load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d); +load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d); sync_slave_with_master; connection slave; @@ -49,7 +49,7 @@ select * from rewrite.t1; connection master; drop table t1; create table t1 (a text, b text); -load data infile '../../std_data/loaddata2.dat' into table t1 fields terminated by ',' enclosed by ''''; +load data infile '../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by ''''; sync_slave_with_master; connection slave; @@ -58,7 +58,7 @@ select concat('|',a,'|'), concat('|',b,'|') from rewrite.t1; connection master; drop table t1; create table t1 (a int, b char(10)); -load data infile '../../std_data/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines; +load data infile '../std_data_ln/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines; sync_slave_with_master; connection slave; @@ -66,7 +66,7 @@ select * from rewrite.t1; connection master; truncate table t1; -load data infile '../../std_data/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines; +load data infile '../std_data_ln/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines; sync_slave_with_master; connection slave; diff --git a/mysql-test/t/rpl_rotate_logs-slave.sh b/mysql-test/t/rpl_rotate_logs-slave.sh index 9259f593e54..81490a54b4b 100755 --- a/mysql-test/t/rpl_rotate_logs-slave.sh +++ b/mysql-test/t/rpl_rotate_logs-slave.sh @@ -1,2 +1,2 @@ -rm -f $MYSQL_TEST_DIR/var/slave-data/master.info -rm -f $MYSQL_TEST_DIR/var/slave-data/*relay* +rm -f $MYSQLTEST_VARDIR/slave-data/master.info +rm -f $MYSQLTEST_VARDIR/slave-data/*relay* diff --git a/mysql-test/t/rpl_rotate_logs.test b/mysql-test/t/rpl_rotate_logs.test index 891582a167c..ee49f92910a 100644 --- a/mysql-test/t/rpl_rotate_logs.test +++ b/mysql-test/t/rpl_rotate_logs.test @@ -1,3 +1,6 @@ +# This test uses chmod, can't be run with root permissions +-- source include/not_as_root.inc + # # Test is run with max_binlog_size=2048 to force automatic rotation of the # binary log @@ -9,13 +12,13 @@ # changes # - Test creating a duplicate key error and recover from it -connect (master,localhost,root,,test,$MASTER_MYPORT,master.sock); +connect (master,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); --disable_warnings drop table if exists t1, t2, t3, t4; --enable_warnings connect (slave,localhost,root,,test,$SLAVE_MYPORT,slave.sock); -system cat /dev/null > var/slave-data/master.info; -system chmod 000 var/slave-data/master.info; +system cat /dev/null > $MYSQLTEST_VARDIR/slave-data/master.info; +system chmod 000 $MYSQLTEST_VARDIR/slave-data/master.info; connection slave; --disable_warnings drop table if exists t1, t2, t3, t4; @@ -23,9 +26,10 @@ drop table if exists t1, t2, t3, t4; # START SLAVE will fail because it can't read the file (mode 000) # (system error 13) ---error 1201 +--replace_result $MYSQL_TEST_DIR TESTDIR +--error 1105,1105,29 start slave; -system chmod 600 var/slave-data/master.info; +system chmod 600 $MYSQLTEST_VARDIR/slave-data/master.info; # It will fail again because the file is empty so the slave cannot get valuable # info about how to connect to the master from it (failure in # init_strvar_from_file() in init_master_info()). @@ -55,7 +59,7 @@ create table t1 (s text); insert into t1 values('Could not break slave'),('Tried hard'); sync_slave_with_master; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; select * from t1; connection master; @@ -108,7 +112,7 @@ show binary logs; insert into t2 values (65); sync_slave_with_master; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; select * from t2; @@ -140,7 +144,7 @@ sync_with_master; select * from t4; --replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 33 # +--replace_column 1 # 8 # 9 # 23 # 33 # show slave status; # because of concurrent insert, the table may not be up to date # if we do not lock diff --git a/mysql-test/t/rpl_session_var.test b/mysql-test/t/rpl_session_var.test new file mode 100644 index 00000000000..a6f4b496a23 --- /dev/null +++ b/mysql-test/t/rpl_session_var.test @@ -0,0 +1,42 @@ +# Replication of session variables. +# FOREIGN_KEY_CHECKS is tested in rpl_insert_id.test + +source include/master-slave.inc; +drop table if exists t1; +create table t1(a varchar(100),b int); +set @@session.sql_mode=pipes_as_concat; +insert into t1 values('My'||'SQL', 1); +set @@session.sql_mode=default; +insert into t1 values('1'||'2', 2); +select * from t1 where b<3 order by a; +save_master_pos; +connection slave; +sync_with_master; +select * from t1 where b<3 order by a; +connection master; +# if the slave does the next sync_with_master fine, then it means it accepts the +# two lines of ANSI syntax below, which is what we want to check. +set @@session.sql_mode=ignore_space; +insert into t1 values(password ('MySQL'), 3); +set @@session.sql_mode=ansi_quotes; +create table "t2" ("a" int); +drop table t1, t2; +set @@session.sql_mode=default; +create table t1(a int auto_increment primary key); +create table t2(b int, a int); +set @@session.sql_auto_is_null=1; +insert into t1 values(null); +insert into t2 select 1,a from t1 where a is null; +set @@session.sql_auto_is_null=0; +insert into t1 values(null); +insert into t2 select 2,a from t1 where a is null; +select * from t2 order by b; +save_master_pos; +connection slave; +sync_with_master; +select * from t2 order by b; +connection master; +drop table t1,t2; +save_master_pos; +connection slave; +sync_with_master; diff --git a/mysql-test/t/rpl_skip_error.test b/mysql-test/t/rpl_skip_error.test index e0e569a65b7..f6fc73f58f2 100644 --- a/mysql-test/t/rpl_skip_error.test +++ b/mysql-test/t/rpl_skip_error.test @@ -13,4 +13,7 @@ connection slave; sync_with_master; select * from t1; +connection master; +drop table t1; +sync_with_master; # End of 4.1 tests diff --git a/mysql-test/t/rpl_slave_status.test b/mysql-test/t/rpl_slave_status.test index cb12198bae2..b97b769d181 100644 --- a/mysql-test/t/rpl_slave_status.test +++ b/mysql-test/t/rpl_slave_status.test @@ -29,4 +29,8 @@ start slave; --vertical_results show slave status; +connection master; +drop table t1; +sync_with_master; + # end of 4.1 tests diff --git a/mysql-test/t/rpl_sp-master.opt b/mysql-test/t/rpl_sp-master.opt new file mode 100644 index 00000000000..709a224fd92 --- /dev/null +++ b/mysql-test/t/rpl_sp-master.opt @@ -0,0 +1 @@ +--log_bin_trust_routine_creators=0 diff --git a/mysql-test/t/rpl_sp-slave.opt b/mysql-test/t/rpl_sp-slave.opt new file mode 100644 index 00000000000..709a224fd92 --- /dev/null +++ b/mysql-test/t/rpl_sp-slave.opt @@ -0,0 +1 @@ +--log_bin_trust_routine_creators=0 diff --git a/mysql-test/t/rpl_sp.test b/mysql-test/t/rpl_sp.test new file mode 100644 index 00000000000..7479794eded --- /dev/null +++ b/mysql-test/t/rpl_sp.test @@ -0,0 +1,521 @@ +# Test of replication of stored procedures (WL#2146 for MySQL 5.0) +# Modified by WL#2971. + +# Note that in the .opt files we still use the old variable name +# log-bin-trust-routine-creators so that this test checks that it's +# still accepted (this test also checks that the new name is +# accepted). The old name could be removed in 5.1 or 6.0. + +source include/master-slave.inc; + +# we need a db != test, where we don't have automatic grants +--disable_warnings +drop database if exists mysqltest1; +--enable_warnings +create database mysqltest1; +use mysqltest1; +create table t1 (a varchar(100)); +sync_slave_with_master; +use mysqltest1; + +# ********************** PART 1 : STORED PROCEDURES *************** + +# Does the same proc as on master get inserted into mysql.proc ? +# (same definer, same properties...) + +connection master; + +delimiter |; + +# Stored procedures don't have the limitations that functions have +# regarding binlogging: it's ok to create a procedure as not +# deterministic and updating data, while it's not ok to create such a +# function. We test this. + +create procedure foo() +begin + declare b int; + set b = 8; + insert into t1 values (b); + insert into t1 values (unix_timestamp()); +end| +delimiter ;| + +# we replace columns having times +# (even with fixed timestamp displayed time may changed based on TZ) +--replace_result localhost.localdomain localhost 127.0.0.1 localhost +--replace_column 13 # 14 # +select * from mysql.proc where name='foo' and db='mysqltest1'; +sync_slave_with_master; +# You will notice in the result that the definer does not match what +# it is on master, it is a known bug on which Alik is working +--replace_result localhost.localdomain localhost 127.0.0.1 localhost +--replace_column 13 # 14 # +select * from mysql.proc where name='foo' and db='mysqltest1'; + +connection master; +# see if timestamp used in SP on slave is same as on master +set timestamp=1000000000; +call foo(); +select * from t1; +sync_slave_with_master; +select * from t1; + +# Now a SP which is not updating tables + +connection master; +delete from t1; +create procedure foo2() + select * from mysqltest1.t1; +call foo2(); + +# check that this is allowed (it's not for functions): +alter procedure foo2 contains sql; + +# SP with definer's right + +drop table t1; +create table t1 (a int); +create table t2 like t1; + +create procedure foo3() + deterministic + insert into t1 values (15); + +# let's create a non-privileged user +grant CREATE ROUTINE, EXECUTE on mysqltest1.* to "zedjzlcsjhd"@127.0.0.1; +grant SELECT on mysqltest1.t1 to "zedjzlcsjhd"@127.0.0.1; +grant SELECT, INSERT on mysqltest1.t2 to "zedjzlcsjhd"@127.0.0.1; + +# ToDo: BUG#14931: There is a race between the last grant binlogging, and +# the binlogging in the new connection made below, causing sporadic test +# failures due to switched statement order in binlog. To fix this we do +# SELECT 1 in the first connection before starting the second, ensuring +# that binlogging is done in the expected order. +# Please remove this SELECT 1 when BUG#14931 is fixed. +SELECT 1; + +connect (con1,127.0.0.1,zedjzlcsjhd,,mysqltest1,$MASTER_MYPORT,); +connection con1; + +# this routine will fail in the second INSERT because of privileges +delimiter |; +create procedure foo4() + deterministic + begin + insert into t2 values(3); + insert into t1 values (5); + end| + +delimiter ;| + +# I add ,0 so that it does not print the error in the test output, +# because this error is hostname-dependent +--error 1142,0 +call foo4(); # invoker has no INSERT grant on table t1 => failure + +connection master; +call foo3(); # success (definer == root) +show warnings; + +--error 1142,0 +call foo4(); # definer's rights => failure + +# we test replication of ALTER PROCEDURE +alter procedure foo4 sql security invoker; +call foo4(); # invoker's rights => success +show warnings; + +# Note that half-failed procedure calls are ok with binlogging; +# if we compare t2 on master and slave we see they are identical: + +select * from t1; +select * from t2; +sync_slave_with_master; +select * from t1; +select * from t2; + +# Let's check another failing-in-the-middle procedure +connection master; +delete from t2; +alter table t2 add unique (a); + +drop procedure foo4; +delimiter |; +create procedure foo4() + deterministic + begin + insert into t2 values(20),(20); + end| + +delimiter ;| + +--error 1062 +call foo4(); +show warnings; + +select * from t2; +sync_slave_with_master; +# check that this failed-in-the-middle replicated right: +select * from t2; + +# Test of DROP PROCEDURE + +--replace_result localhost.localdomain localhost 127.0.0.1 localhost +--replace_column 13 # 14 # +select * from mysql.proc where name="foo4" and db='mysqltest1'; +connection master; +drop procedure foo4; +select * from mysql.proc where name="foo4" and db='mysqltest1'; +sync_slave_with_master; +select * from mysql.proc where name="foo4" and db='mysqltest1'; + +# ********************** PART 2 : FUNCTIONS *************** + +connection master; +drop procedure foo; +drop procedure foo2; +drop procedure foo3; + +delimiter |; +# check that needs "deterministic" +--error 1418 +create function fn1(x int) + returns int +begin + insert into t1 values (x); + return x+2; +end| +create function fn1(x int) + returns int + deterministic +begin + insert into t1 values (x); + return x+2; +end| + +delimiter ;| +delete t1,t2 from t1,t2; +select fn1(20); +insert into t2 values(fn1(21)); +select * from t1; +select * from t2; +sync_slave_with_master; +select * from t1; +select * from t2; + +connection master; +delimiter |; + +drop function fn1; + +create function fn1() + returns int + no sql +begin + return unix_timestamp(); +end| + +delimiter ;| +# check that needs "deterministic" +--error 1418 +alter function fn1 contains sql; + +delete from t1; +set timestamp=1000000000; +insert into t1 values(fn1()); + +connection con1; + +delimiter |; +--error 1419 # only full-global-privs user can create a function +create function fn2() + returns int + no sql +begin + return unix_timestamp(); +end| +delimiter ;| +connection master; +# test old variable name: +set global log_bin_trust_routine_creators=1; +# now use new name: +set global log_bin_trust_function_creators=0; +set global log_bin_trust_function_creators=1; +# slave needs it too otherwise will not execute what master allowed: +connection slave; +set global log_bin_trust_function_creators=1; + +connection con1; + +delimiter |; +create function fn2() + returns int + no sql +begin + return unix_timestamp(); +end| +delimiter ;| + +connection master; + +# Now a function which is supposed to not update tables +# as it's "reads sql data", so should not give error even if +# non-deterministic. + +delimiter |; +create function fn3() + returns int + not deterministic + reads sql data +begin + return 0; +end| +delimiter ;| + +select fn3(); +--replace_result localhost.localdomain localhost 127.0.0.1 localhost +--replace_column 13 # 14 # +select * from mysql.proc where db='mysqltest1'; +select * from t1; + +sync_slave_with_master; +use mysqltest1; +select * from t1; +--replace_result localhost.localdomain localhost 127.0.0.1 localhost +--replace_column 13 # 14 # +select * from mysql.proc where db='mysqltest1'; + +# Let's check a failing-in-the-middle function +connection master; +delete from t2; +alter table t2 add unique (a); + +drop function fn1; + +delimiter |; +create function fn1(x int) + returns int +begin + insert into t2 values(x),(x); + return 10; +end| + +delimiter ;| + +do fn1(100); + +--error 1062 +select fn1(20); + +select * from t2; +sync_slave_with_master; + +# check that this failed-in-the-middle replicated right: +select * from t2; + +# ********************** PART 3 : TRIGGERS *************** + +connection con1; +--error 1227 +create trigger trg before insert on t1 for each row set new.a= 10; + +connection master; +delete from t1; +# TODO: when triggers can contain an update, test that this update +# does not go into binlog. +# I'm not setting user vars in the trigger, because replication of user vars +# would take care of propagating the user var's value to slave, so even if +# the trigger was not executed on slave it would not be discovered. +create trigger trg before insert on t1 for each row set new.a= 10; +insert into t1 values (1); +select * from t1; +sync_slave_with_master; +select * from t1; + +connection master; +delete from t1; +drop trigger trg; +insert into t1 values (1); +select * from t1; +--replace_column 2 # 5 # +show binlog events in 'master-bin.000001' from 98; +sync_slave_with_master; +select * from t1; + + +# +# Test for bug #13969 "Routines which are replicated from master can't be +# executed on slave". +# +connection master; +create procedure foo() + not deterministic + reads sql data + select * from t1; +sync_slave_with_master; +# This should not fail +call foo(); +connection master; +drop procedure foo; +sync_slave_with_master; + + +# Clean up +connection master; +drop function fn1; +drop database mysqltest1; +drop user "zedjzlcsjhd"@127.0.0.1; +use test; +sync_slave_with_master; +use test; + +# +# Bug#14077 "Failure to replicate a stored function with a cursor": +# verify that stored routines with cursors work on slave. +# +connection master; +--disable_warnings +drop function if exists f1; +--enable_warnings +delimiter |; +create function f1() returns int reads sql data +begin + declare var integer; + declare c cursor for select a from v1; + open c; + fetch c into var; + close c; + return var; +end| +delimiter ;| +create view v1 as select 1 as a; +create table t1 (a int); +insert into t1 (a) values (f1()); +select * from t1; +drop view v1; +drop function f1; +sync_slave_with_master; +connection slave; +select * from t1; + +# +# Bug#16621 "INSERTs in Stored Procedures causes data corruption in the Binary +# Log for 5.0.18" +# + +# Prepare environment. + +connection master; + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP TABLE IF EXISTS t1; +--enable_warnings + +# Test case. + +CREATE TABLE t1(col VARCHAR(10)); + +CREATE PROCEDURE p1(arg VARCHAR(10)) + INSERT INTO t1 VALUES(arg); + +CALL p1('test'); + +SELECT * FROM t1; + +sync_slave_with_master; +connection slave; + +SELECT * FROM t1; + +# Cleanup. + +connection master; + +DROP PROCEDURE p1; + + +# +# BUG#20438: CREATE statements for views, stored routines and triggers can be +# not replicable. +# + +--echo +--echo ---> Test for BUG#20438 + +# Prepare environment. + +--echo +--echo ---> Preparing environment... +--echo ---> connection: master +--connection master + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo +--echo ---> connection: master +--connection master + +# Test. + +--echo +--echo ---> Creating procedure... + +/*!50003 CREATE PROCEDURE p1() SET @a = 1 */; + +/*!50003 CREATE FUNCTION f1() RETURNS INT RETURN 0 */; + +--echo +--echo ---> Checking on master... + +SHOW CREATE PROCEDURE p1; +SHOW CREATE FUNCTION f1; + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo ---> connection: master + +--echo +--echo ---> Checking on slave... + +SHOW CREATE PROCEDURE p1; +SHOW CREATE FUNCTION f1; + +# Cleanup. + +--echo +--echo ---> connection: master +--connection master + +--echo +--echo ---> Cleaning up... + +DROP PROCEDURE p1; +DROP FUNCTION f1; + +--save_master_pos +--connection slave +--sync_with_master +--connection master + + +# cleanup +connection master; +drop table t1; +sync_slave_with_master; diff --git a/mysql-test/t/rpl_sp_effects-master.opt b/mysql-test/t/rpl_sp_effects-master.opt new file mode 100644 index 00000000000..61dd7a6ad0e --- /dev/null +++ b/mysql-test/t/rpl_sp_effects-master.opt @@ -0,0 +1 @@ +--log_bin_trust_routine_creators=1 diff --git a/mysql-test/t/rpl_sp_effects-slave.opt b/mysql-test/t/rpl_sp_effects-slave.opt new file mode 100644 index 00000000000..61dd7a6ad0e --- /dev/null +++ b/mysql-test/t/rpl_sp_effects-slave.opt @@ -0,0 +1 @@ +--log_bin_trust_routine_creators=1 diff --git a/mysql-test/t/rpl_sp_effects.test b/mysql-test/t/rpl_sp_effects.test new file mode 100644 index 00000000000..9da5723b993 --- /dev/null +++ b/mysql-test/t/rpl_sp_effects.test @@ -0,0 +1,203 @@ +# Test of replication of stored procedures (WL#2146 for MySQL 5.0) + +source include/master-slave.inc; + +# **************************************************************** +connection master; + +# cleanup +--disable_warnings +drop procedure if exists p1; +drop procedure if exists p2; +drop function if exists f1; +drop table if exists t1,t2; +drop view if exists v1; +--enable_warnings +create table t1 (a int); + +# 1. Test simple variables use. +delimiter //; +create procedure p1() +begin + declare spv int default 0; + while spv < 5 do + insert into t1 values(spv+1); + set spv=spv+1; + end while; +end// +delimiter ;// + +call p1(); + +sync_slave_with_master; +connection slave; +select * from t1; +connection master; +delete from t1; + +# 2. Test SP variable name +delimiter //; +create procedure p2() +begin + declare a int default 4; + create table t2 as select a; +end// +delimiter ;// + +call p2(); +select * from t2; +sync_slave_with_master; +connection slave; +select * from t2; + +connection master; +drop procedure p1; +drop procedure p2; +drop table t2; + +# 3. Test FUNCTIONs in various places + +delimiter //; +create function f1(x int) returns int +begin + insert into t1 values(x); + return x+1; +end// + +create procedure p1(a int, b int) +begin + declare v int default f1(5); + if (f1(6)) then + select 'yes'; + end if; + set v = f1(7); + while f1(8) < 1 do + select 'this cant be'; + end while; + +end// +delimiter ;// + +call p1(f1(1), f1(2)); +select * from t1; + +create table t2(a int); +insert into t2 values (10),(11); +select a,f1(a) from t2; + +# This shouldn't put separate 'call f1(3)' into binlog: +insert into t2 select f1(3); +select 'master:',a from t1; + +sync_slave_with_master; +connection slave; +select 'slave:',a from t1; + +connection master; +drop procedure p1; +delete from t1; +delete from t2; + +# 4. VIEWs +delete from t1; +insert into t2 values(1),(2); +create view v1 as select f1(a) from t2; +select * from v1; +select 'master:',a from t1; + +sync_slave_with_master; +connection slave; +select 'slave:',a from t1; + +connection master; +drop view v1; +delete from t1; + +# 5. Prepared statements. +prepare s1 from 'select f1(?)'; +set @xx=123; +execute s1 using @xx; +select 'master:',a from t1; + +sync_slave_with_master; +connection slave; +select 'slave:',a from t1; + +connection master; +delete from t1; + +# 5. Cursors. +# t2 has (1),(2); +delimiter //; +create procedure p1(spv int) +begin + declare c cursor for select f1(spv) from t2; + while (spv > 2) do + open c; + fetch c into spv; + close c; + set spv= spv - 10; + end while; +end// +delimiter ;// + +call p1(15); +select 'master:',a from t1; +sync_slave_with_master; +connection slave; +select 'slave:',a from t1; + +connection master; +drop procedure p1; +drop function f1; +drop table t1,t2; + +# BUG#12637: User variables + SPs replication +create table t1 (a int); +delimiter //; +create procedure p1() +begin + insert into t1 values(@x); + set @x=@x+1; + insert into t1 values(@x); + if (f2()) then + insert into t1 values(1243); + end if; +end// + +create function f2() returns int +begin + insert into t1 values(@z); + set @z=@z+1; + insert into t1 values(@z); + return 0; +end// + +create function f1() returns int +begin + insert into t1 values(@y); + call p1(); + return 0; +end// + +delimiter ;// + +set @x=10; +set @y=20; +set @z=100; +select f1(); + +set @x=30; +call p1(); + +select 'master', a from t1; +sync_slave_with_master; +connection slave; +select 'slave', a from t1; + +connection master; +drop table t1; +drop function f1; +drop function f2; +drop procedure p1; +sync_slave_with_master; diff --git a/mysql-test/t/rpl_temporary.test b/mysql-test/t/rpl_temporary.test index bc1b0e64565..81f0e8a0af7 100644 --- a/mysql-test/t/rpl_temporary.test +++ b/mysql-test/t/rpl_temporary.test @@ -82,6 +82,7 @@ drop temporary table t3; select * from t2; --replace_result $VERSION VERSION +--replace_column 2 # 5 # show binlog events; drop table t1, t2; @@ -128,6 +129,33 @@ drop table t1,t2; create temporary table t3 (f int); sync_with_master; +# The server will now close done + +# +# Bug#17284 erroneous temp table cleanup on slave +# + +connection master; +create temporary table t4 (f int); +create table t5 (f int); +sync_with_master; +# find dumper's $id +source include/get_binlog_dump_thread_id.inc; +insert into t4 values (1); +# a hint how to do that in 5.1 +--replace_result $id "`select id from information_schema.processlist where command='Binlog Dump'`" +eval kill $id; # to stimulate reconnection by slave w/o timeout +insert into t5 select * from t4; +save_master_pos; + +connection slave; +sync_with_master; +select * from t5 /* must be 1 after reconnection */; + +connection master; +drop temporary table t4; +drop table t5; + # # BUG#17263 incorrect generation DROP temp tables # Temporary tables of connection are dropped in batches @@ -173,4 +201,4 @@ select * from t1; connection master; drop table t1; -# End of 4.1 tests +# End of 5.0 tests diff --git a/mysql-test/t/rpl_timezone-slave.opt b/mysql-test/t/rpl_timezone-slave.opt index 8e43bfbbb7e..191182c329c 100644 --- a/mysql-test/t/rpl_timezone-slave.opt +++ b/mysql-test/t/rpl_timezone-slave.opt @@ -1 +1 @@ ---default-time-zone=Europe/Moscow +--default-time-zone=Japan diff --git a/mysql-test/t/rpl_timezone.test b/mysql-test/t/rpl_timezone.test index d371e8b62e5..0f35c9dc0b6 100644 --- a/mysql-test/t/rpl_timezone.test +++ b/mysql-test/t/rpl_timezone.test @@ -1,23 +1,38 @@ # Test of replication of time zones. + +# There is currently some bug possibly in prepared statements (this +# test fails with --ps-protocol): sys_var_thd_time_zone::value_ptr() +# is called only at prepare time, not at execution time. So, +# thd->time_zone_used is not equal to 1 (it is back to 0, because of +# reset_thd_for_next_command called at execution time), so the +# timezone used in CONVERT_TZ is not binlogged. To debug (by Guilhem +# and possibly Konstantin). + +--disable_ps_protocol + source include/master-slave.inc; # Some preparations let $VERSION=`select version()`; +set timestamp=100000000; # for fixed output of mysqlbinlog create table t1 (t timestamp); create table t2 (t char(32)); +connection slave; +select @@time_zone; + # # Let us check how well replication works when we are saving datetime # value in TIMESTAMP field. # connection master; select @@time_zone; +insert into t1 values ('20050101000000'), ('20050611093902'); set time_zone='UTC'; insert into t1 values ('20040101000000'), ('20040611093902'); select * from t1; -# On slave we still in 'Europe/Moscow' so we should see equivalent but -# textually different values. sync_slave_with_master; +set time_zone='UTC'; select * from t1; # Let us check also that setting of time_zone back to default also works @@ -28,11 +43,29 @@ set time_zone='Europe/Moscow'; insert into t1 values ('20040101000000'), ('20040611093902'); select * from t1; sync_slave_with_master; +set time_zone='Europe/Moscow'; select * from t1; connection master; -# We should not see SET ONE_SHOT time_zone before second insert ---replace_result $VERSION VERSION -show binlog events; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001 + +# Let us check with LOAD DATA INFILE +# (we do it after mysqlbinlog because the temp files names are not constant) +connection master; +delete from t1; +set time_zone='UTC'; +load data infile '../std_data_ln/rpl_timezone.dat' into table t1; +select * from t1; +sync_slave_with_master; +set time_zone='UTC'; +select * from t1; +set time_zone='Europe/Moscow'; + +# Put back values of before the LOAD +connection master; +set time_zone='Europe/Moscow'; +delete from t1; +insert into t1 values ('20040101000000'), ('20040611093902'); # # Now let us check how well we replicate statments reading TIMESTAMP fields @@ -53,10 +86,6 @@ delete from t2; set timestamp=1000072000; insert into t2 values (current_timestamp), (current_date), (current_time); sync_slave_with_master; -# Values in ouput of these to queries should differ because we are in -# in 'MET' on master and in 'Europe/Moscow on slave... -set timestamp=1000072000; -select current_timestamp, current_date, current_time; select * from t2; # @@ -72,14 +101,25 @@ sync_slave_with_master; select * from t2; # -# Let us check that we are not allowing to set global time_zone with +# Let us check that we are allowing to set global time_zone with # replication # connection master; ---error 1105 set global time_zone='MET'; +# +# Let us see if CONVERT_TZ(@@time_zone) replicates +# +delete from t2; +set time_zone='UTC'; +insert into t2 values(convert_tz('2004-01-01 00:00:00','MET',@@time_zone)); +insert into t2 values(convert_tz('2005-01-01 00:00:00','MET','Japan')); +select * from t2; +sync_slave_with_master; +select * from t2; + # Clean up +connection master; drop table t1, t2; sync_slave_with_master; diff --git a/mysql-test/t/rpl_trigger.test b/mysql-test/t/rpl_trigger.test new file mode 100644 index 00000000000..d6e9410b1d3 --- /dev/null +++ b/mysql-test/t/rpl_trigger.test @@ -0,0 +1,432 @@ +# +# Test of triggers with replication +# + +source include/master-slave.inc; + +# +# #12482: Triggers has side effects with auto_increment values +# + +create table t1 (a int auto_increment, primary key (a), b int, rand_value double not null); +create table t2 (a int auto_increment, primary key (a), b int); +create table t3 (a int auto_increment, primary key (a), name varchar(64) not null, old_a int, old_b int, rand_value double not null); + +delimiter |; +create trigger t1 before insert on t1 for each row +begin + insert into t3 values (NULL, "t1", new.a, new.b, rand()); +end| + +create trigger t2 after insert on t2 for each row +begin + insert into t3 values (NULL, "t2", new.a, new.b, rand()); +end| +delimiter ;| + +insert into t3 values(100,"log",0,0,0); + +# Ensure we always have same random numbers +SET @@RAND_SEED1=658490765, @@RAND_SEED2=635893186; + +# Emulate that we have rows 2-9 deleted on the slave +insert into t1 values(1,1,rand()),(NULL,2,rand()); +insert into t2 (b) values(last_insert_id()); +insert into t2 values(3,0),(NULL,0); +insert into t2 values(NULL,0),(500,0); + +select a,b, truncate(rand_value,4) from t1; +select * from t2; +select a,name, old_a, old_b, truncate(rand_value,4) from t3; +save_master_pos; +connection slave; +sync_with_master; +--disable_query_log +select "--- On slave --" as ""; +--enable_query_log +select a,b, truncate(rand_value,4) from t1; +select * from t2; +select a,name, old_a, old_b, truncate(rand_value,4) from t3; +connection master; +drop table t1,t2,t3; + +# +# #12480: NOW() is not constant in a trigger +# #12481: Using NOW() in a stored function breaks statement based replication +# + +# Start by getting a lock on 'bug12480' to be able to use get_lock() as sleep() +connect (con2,localhost,root,,); +connection con2; +select get_lock("bug12480",2); +connection default; + +create table t1 (a datetime,b datetime, c datetime); +--disable_warnings +drop function if exists bug12480; +--enable_warnings + +delimiter |; + +create function bug12480() returns datetime +begin + set @a=get_lock("bug12480",2); + return now(); +end| + +create trigger t1_first before insert on t1 +for each row begin + set @a=get_lock("bug12480",2); + set new.b= now(); + set new.c= bug12480(); +end +| + +delimiter ;| +insert into t1 set a = now(); +select a=b && a=c from t1; +let $time=`select a from t1`; + +# Check that definer attribute is replicated properly: +# - dump definers on the master; +# - wait for the slave to synchronize with the master; +# - dump definers on the slave; + +SELECT routine_name, definer +FROM information_schema.routines; + +SELECT trigger_name, definer +FROM information_schema.triggers; + +save_master_pos; +connection slave; +sync_with_master; +--disable_query_log +select "--- On slave --" as ""; +--enable_query_log + +# XXX: Definers of stored procedures and functions are not replicated. WL#2897 +# (Complete definer support in the stored routines) addresses this issue. So, +# the result file is expected to be changed after implementation of this WL +# item. + +SELECT routine_name, definer +FROM information_schema.routines; + +SELECT trigger_name, definer +FROM information_schema.triggers; + +select a=b && a=c from t1; +--disable_query_log +eval select a='$time' as 'test' from t1; +--enable_query_log + +connection master; +disconnect con2; + +truncate table t1; +drop trigger t1_first; + +insert into t1 values ("2003-03-03","2003-03-03","2003-03-03"),(bug12480(),bug12480(),bug12480()),(now(),now(),now()); +select a=b && a=c from t1; + +drop function bug12480; +drop table t1; + +# +# #14614: Replication of tables with trigger generates error message if databases is changed +# Note. The error message is emitted by _myfree() using fprintf() to the stderr +# and because of that does not fall into the .result file. +# + +create table t1 (i int); +create table t2 (i int); + +delimiter |; +create trigger tr1 before insert on t1 for each row +begin + insert into t2 values (1); +end| +delimiter ;| + +create database other; +use other; +insert into test.t1 values (1); + +save_master_pos; +connection slave; +sync_with_master; + +connection master; +use test; +drop table t1,t2; +drop database other; + + +# +# Test specific triggers including SELECT into var with replication +# BUG#13227: +# slave performs an update to the replicatable table, t1, +# and modifies its local data, t3, by mean of its local trigger that uses +# another local table t2. +# Expected values are commented into queries. +# +# Body of the test executes in a loop since the problem occurred randomly. +# + +let $max_rows=5; +let $rnd=10; + +--echo test case for BUG#13227 +while ($rnd) +{ + --echo ------------------- + echo $rnd; + --echo ------------------- + +### SETUP + +--disable_warnings + connection master; + eval drop table if exists t1$rnd; + connection slave; + eval drop table if exists t2$rnd,t3$rnd; +--enable_warnings + + connection master; + eval create table t1$rnd (f1 int) /* 2 replicate */; + let $i=$max_rows; + while ($i) + { + eval insert into t1$rnd values (-$i); + dec $i; + } + + sync_slave_with_master; +#connection slave; + eval select * from t1$rnd; + delimiter |; + eval create trigger trg1$rnd before update on t1$rnd /* slave local */ + for each row + begin + DECLARE r integer; + SELECT f2 INTO r FROM t2$rnd where f1=NEW.f1; + INSERT INTO t3$rnd values (r); + end| + delimiter ;| + eval create table t2$rnd (f1 int, f2 int) /* slave local */; + eval create table t3$rnd (f3 int) /* slave local */; + let $i=$max_rows; + while ($i) + { + eval insert into t2$rnd values ($i, $i*100); + dec $i; + } + +### Test + +#connection slave; + +# trigger works as specified when updates from slave + eval select * from t2$rnd; + eval UPDATE t1$rnd SET f1=$max_rows where f1=-$max_rows; + eval SELECT * from t1$rnd /* must be f1 $max_rows, 1 - $max_rows 2 - $max_rows ... -1 */; + eval SELECT * from t3$rnd /* must be f3 $max_rows*100 */; + + connection master; + let $i=$max_rows; + while ($i) + { + eval UPDATE t1$rnd SET f1=$i where f1=-$i; + dec $i; + } + + sync_slave_with_master; +#connection slave; + eval SELECT * from t1$rnd /* must be f1 $max_rows ... 1 */; + eval SELECT * from t3$rnd /* must be f3 $max_rows * 100 ... 100 */; + +### CLEANUP +#connection slave; + eval drop trigger trg1$rnd; + eval drop table t2$rnd,t3$rnd; + + connection master; + eval drop table t1$rnd; + + dec $rnd; +} + + +# +# BUG#16266: Definer is not fully qualified error during replication. +# +# The idea of this test is to emulate replication of a trigger from the old +# master (master w/o "DEFINER in triggers" support) to the new slave and check +# that: +# 1. the trigger on the slave will be replicated w/o errors; +# 2. the trigger on the slave will be non-SUID (will have no DEFINER); +# 3. the trigger can be activated later on the slave w/o errors. +# +# In order to emulate this kind of replication, we make the slave playing the binlog, +# recorded by 5.0.16 master. This binlog contains the following statements: +# CREATE TABLE t1(c INT); +# CREATE TABLE t2(s CHAR(200)); +# CREATE TRIGGER trg1 AFTER INSERT ON t1 +# FOR EACH ROW +# INSERT INTO t2 VALUES(CURRENT_USER()); +# INSERT INTO t1 VALUES(1); +# + +# 1. Check that the trigger's replication is succeeded. + +# Stop the slave. + +connection slave; +STOP SLAVE; + +# Replace master's binlog. + +connection master; +FLUSH LOGS; +exec cp $MYSQL_TEST_DIR/std_data/bug16266.000001 $MYSQLTEST_VARDIR/log/master-bin.000001; + +# Make the slave to replay the new binlog. + +connection slave; +RESET SLAVE; +START SLAVE; + +SELECT MASTER_POS_WAIT('master-bin.000001', 513) >= 0; + +# Check that the replication succeeded. + +SHOW TABLES LIKE 't_'; +SHOW TRIGGERS; +SELECT * FROM t1; +SELECT * FROM t2; + +# 2. Check that the trigger is non-SUID on the slave; +# 3. Check that the trigger can be activated on the slave. + +INSERT INTO t1 VALUES(2); + +SELECT * FROM t1; +SELECT * FROM t2; + +# That's all, cleanup. + +DROP TRIGGER trg1; +DROP TABLE t1; +DROP TABLE t2; + +STOP SLAVE; +RESET SLAVE; + +# The master should be clean. + +connection master; +SHOW TABLES LIKE 't_'; +SHOW TRIGGERS; + +RESET MASTER; + +# Restart slave. + +connection slave; +START SLAVE; + + +# +# BUG#20438: CREATE statements for views, stored routines and triggers can be +# not replicable. +# + +--echo +--echo ---> Test for BUG#20438 + +# Prepare environment. + +--echo +--echo ---> Preparing environment... +--echo ---> connection: master +--connection master + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +--enable_warnings + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo +--echo ---> connection: master +--connection master + +# Test. + +--echo +--echo ---> Creating objects... + +CREATE TABLE t1(c INT); +CREATE TABLE t2(c INT); + +/*!50003 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 + FOR EACH ROW + INSERT INTO t2 VALUES(NEW.c * 10) */; + +--echo +--echo ---> Inserting value... + +INSERT INTO t1 VALUES(1); + +--echo +--echo ---> Checking on master... + +SELECT * FROM t1; +SELECT * FROM t2; + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo ---> connection: master + +--echo +--echo ---> Checking on slave... + +SELECT * FROM t1; +SELECT * FROM t2; + +# Cleanup. + +--echo +--echo ---> connection: master +--connection master + +--echo +--echo ---> Cleaning up... + +DROP TABLE t1; +DROP TABLE t2; + +--save_master_pos +--connection slave +--sync_with_master +--connection master + + +# +# End of tests +# +save_master_pos; +connection slave; +sync_with_master; diff --git a/mysql-test/t/rpl_trunc_binlog.test b/mysql-test/t/rpl_trunc_binlog.test deleted file mode 100644 index 9cdf1d8ddbd..00000000000 --- a/mysql-test/t/rpl_trunc_binlog.test +++ /dev/null @@ -1,27 +0,0 @@ -# We are testing if a binlog which contains BEGIN but not COMMIT (the -# master did while writing the transaction to the binlog) triggers an -# error on slave. So we use such a truncated binlog and simulate that -# the master restarted after this. - -source include/master-slave.inc; - -connection slave; -# If we are not supporting transactions in the slave, the unfinished transaction -# won't cause any error, so we need to skip the test. In the 4.0 testsuite, the -# slave always runs without InnoDB, so we check for BDB. -source include/have_bdb.inc; -stop slave; -connection master; -flush logs; -system mv -f var/log/master-bin.000001 var/log/master-bin.000002; -system cp std_data/trunc_binlog.000001 var/log/master-bin.000001; -connection slave; -reset slave; -start slave; -# can't sync_with_master so we must sleep -sleep 3; ---replace_result $MASTER_MYPORT MASTER_PORT ---replace_column 1 # 23 # 33 # -show slave status; - -# End of 4.1 tests diff --git a/mysql-test/t/rpl_until.test b/mysql-test/t/rpl_until.test index 990f00fdc63..c404ea7e58b 100644 --- a/mysql-test/t/rpl_until.test +++ b/mysql-test/t/rpl_until.test @@ -24,14 +24,14 @@ show binlog events; # try to replicate all queries until drop of t1 connection slave; -start slave until master_log_file='master-bin.000001', master_log_pos=244; +start slave until master_log_file='master-bin.000001', master_log_pos=319; sleep 2; wait_for_slave_to_stop; # here table should be still not deleted select * from t1; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 9 # 11 # 23 # 33 # -show slave status; +--query_vertical SHOW SLAVE STATUS # this should fail right after start start slave until master_log_file='master-no-such-bin.000001', master_log_pos=291; @@ -41,16 +41,16 @@ sleep 2; wait_for_slave_to_stop; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 9 # 11 # 23 # 33 # -show slave status; +--query_vertical SHOW SLAVE STATUS # try replicate all until second insert to t2; -start slave until relay_log_file='slave-relay-bin.000002', relay_log_pos=537; -sleep 4; +start slave until relay_log_file='slave-relay-bin.000004', relay_log_pos=746; +sleep 2; wait_for_slave_to_stop; select * from t2; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 9 # 11 # 23 # 33 # -show slave status; +--query_vertical SHOW SLAVE STATUS # clean up start slave; @@ -60,15 +60,14 @@ connection slave; sync_with_master; stop slave; -# this should stop immideately -start slave until master_log_file='master-bin.000001', master_log_pos=561; -# 2 is not enough when running with valgrind ---real_sleep 4 +# this should stop immediately as we are already there +start slave until master_log_file='master-bin.000001', master_log_pos=776; +sleep 2; wait_for_slave_to_stop; # here the sql slave thread should be stopped --replace_result $MASTER_MYPORT MASTER_MYPORT bin.000005 bin.000004 bin.000006 bin.000004 bin.000007 bin.000004 --replace_column 1 # 9 # 23 # 33 # -show slave status; +--query_vertical SHOW SLAVE STATUS #testing various error conditions --error 1277 @@ -81,8 +80,8 @@ start slave until master_log_file='master-bin.000001'; start slave until relay_log_file='slave-relay-bin.000002'; --error 1277 start slave until relay_log_file='slave-relay-bin.000002', master_log_pos=561; - +# Warning should be given for second command start slave sql_thread; -start slave until master_log_file='master-bin.000001', master_log_pos=561; +start slave until master_log_file='master-bin.000001', master_log_pos=776; # End of 4.1 tests diff --git a/mysql-test/t/rpl_user_variables.test b/mysql-test/t/rpl_user_variables.test index 6597413c22e..dbe75a15038 100644 --- a/mysql-test/t/rpl_user_variables.test +++ b/mysql-test/t/rpl_user_variables.test @@ -46,11 +46,12 @@ save_master_pos; connection slave; sync_with_master; select * from t1; -show binlog events from 141; - +--replace_column 2 # 5 # +show binlog events from 98; # # BUG19136: Crashing log-bin and uninitialized user variables in a derived table # just to check nothing bad happens anymore +# connection master; insert into t1 select * FROM (select @var1 union select @var2) AS t2; drop table t1; diff --git a/mysql-test/t/rpl_variables-master.opt b/mysql-test/t/rpl_variables-master.opt new file mode 100644 index 00000000000..a668c6bfbe8 --- /dev/null +++ b/mysql-test/t/rpl_variables-master.opt @@ -0,0 +1 @@ +--slave-skip-errors=3,100,137,643,1752 diff --git a/mysql-test/t/rpl_variables.test b/mysql-test/t/rpl_variables.test index 8c5279c0420..57ae2b9c3c4 100644 --- a/mysql-test/t/rpl_variables.test +++ b/mysql-test/t/rpl_variables.test @@ -4,3 +4,11 @@ set global slave_net_timeout=100; set global sql_slave_skip_counter=100; # End of 4.1 tests + +# BUG #7800: Add various-slave related variables to SHOW VARIABLES +show variables like 'slave_compressed_protocol'; +--replace_column 2 SLAVE_LOAD_TMPDIR +show variables like 'slave_load_tmpdir'; +# We just set some arbitrary values in variables-master.opt so we can test +# that a list of values works correctly +show variables like 'slave_skip_errors'; diff --git a/mysql-test/t/rpl_view-slave.opt b/mysql-test/t/rpl_view-slave.opt new file mode 100644 index 00000000000..79b3bf6174b --- /dev/null +++ b/mysql-test/t/rpl_view-slave.opt @@ -0,0 +1 @@ +--replicate-ignore-table=test.foo diff --git a/mysql-test/t/rpl_view.test b/mysql-test/t/rpl_view.test new file mode 100644 index 00000000000..812e5d44d58 --- /dev/null +++ b/mysql-test/t/rpl_view.test @@ -0,0 +1,152 @@ +source include/master-slave.inc; +--disable_warnings +drop table if exists t1,v1; +drop view if exists t1,v1; +sync_slave_with_master; +reset master; +--enable_warnings + +# +# Check that createion drop of view is replicated, also check replication of +# updating of view +# +connection master; +create table t1 (a int); +insert into t1 values (1); +create view v1 as select a from t1; +insert into v1 values (2); +select * from v1 order by a; +sync_slave_with_master; +# view already have to be on slave +select * from v1 order by a; +connection master; +update v1 set a=3 where a=1; +select * from v1 order by a; +sync_slave_with_master; +select * from v1 order by a; +connection master; +delete from v1 where a=2; +select * from v1 order by a; +sync_slave_with_master; +select * from v1 order by a; +connection master; +# 'alter view' internally maped to creation, but still check that it works +alter view v1 as select a as b from t1; +sync_slave_with_master; +select * from v1 order by 1; +connection master; +drop view v1; +sync_slave_with_master; +#error, because view have to be removed from slave +-- error 1146 +select * from v1 order by a; +connection master; +drop table t1; +sync_slave_with_master; +--replace_column 2 # 5 # +show binlog events limit 1,100; + + + +# +# BUG#20438: CREATE statements for views, stored routines and triggers can be +# not replicable. +# + +--echo +--echo ---> Test for BUG#20438 + +# Prepare environment. + +--echo +--echo ---> Preparing environment... +--echo ---> connection: master +--connection master + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP VIEW IF EXISTS v1; +--enable_warnings + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo +--echo ---> connection: master +--connection master + +# Test. + +--echo +--echo ---> Creating objects... + +CREATE TABLE t1(c INT); + +/*!50003 CREATE VIEW v1 AS SELECT * FROM t1 */; + +--echo +--echo ---> Inserting value... + +INSERT INTO t1 VALUES(1); + +--echo +--echo ---> Checking on master... + +SELECT * FROM t1; + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo ---> connection: master + +--echo +--echo ---> Checking on slave... + +SELECT * FROM t1; + +# Cleanup. + +--echo +--echo ---> connection: master +--connection master + +--echo +--echo ---> Cleaning up... + +DROP VIEW v1; +DROP TABLE t1; + +--save_master_pos +--connection slave +--sync_with_master +--connection master + +# +# BUG#19419: "VIEW: View that the column name is different +# by master and slave is made". +# +connection master; +create table t1(a int, b int); +insert into t1 values (1, 1), (1, 2), (1, 3); +create view v1(a, b) as select a, sum(b) from t1 group by a; + +sync_slave_with_master; +explain v1; +show create table v1; +select * from v1; + +connection master; +drop table t1; +drop view v1; + +sync_slave_with_master; + +--echo End of 5.0 tests diff --git a/mysql-test/t/schema.test b/mysql-test/t/schema.test new file mode 100644 index 00000000000..a08d9b38935 --- /dev/null +++ b/mysql-test/t/schema.test @@ -0,0 +1,14 @@ +# +# Just a couple of tests to make sure that schema works. +# +# Drop mysqltest1 database, as it can left from the previous tests. +# + +--disable_warnings +drop database if exists mysqltest1; +--enable_warnings + +create schema foo; +show create schema foo; +show schemas; +drop schema foo; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 3f9fb59d26f..0f096d97d25 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -7,9 +7,10 @@ # --disable_warnings -drop table if exists t1,t2,t3,t4; +drop table if exists t1,t2,t3,t4,t11; # The following may be left from older tests -drop table if exists t1_1,t1_2,t9_1,t9_2; +drop table if exists t1_1,t1_2,t9_1,t9_2,t1aa,t2aa; +drop view if exists v1; --enable_warnings CREATE TABLE t1 ( @@ -1541,6 +1542,11 @@ select t2.companynr,companyname from t2 left join t4 using (companynr) where t4. select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null; explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null; + +select companynr,companyname from t2 left join t4 using (companynr) where companynr is null; +select count(*) from t2 left join t4 using (companynr) where companynr is not null; +explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null; +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null; delete from t2 where fld1=999999; # @@ -1549,11 +1555,19 @@ delete from t2 where fld1=999999; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0; + +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0; +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0; +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0; # Following can't be optimized explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0 or t4.companynr > 0; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0; +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null; +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0; +explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0; + # # Joins with forms. # @@ -1764,9 +1778,9 @@ DO benchmark(100,1+1),1,1; # Bug #6449: do default; # ---error 1064 +--error ER_PARSE_ERROR do default; ---error 1054 +--error ER_BAD_FIELD_ERROR do foobar; # @@ -1788,11 +1802,14 @@ DROP TABLE t1; # Test of bug with SUM(CASE...) # -CREATE TABLE t1 (gvid int(10) unsigned default NULL, hmid int(10) unsigned default NULL, volid int(10) unsigned default NULL, mmid int(10) unsigned default NULL, hdid int(10) unsigned default NULL, fsid int(10) unsigned default NULL, ctid int(10) unsigned default NULL, dtid int(10) unsigned default NULL, cost int(10) unsigned default NULL, performance int(10) unsigned default NULL, serialnumber bigint(20) unsigned default NULL, monitored tinyint(3) unsigned default '1', removed tinyint(3) unsigned default '0', target tinyint(3) unsigned default '0', dt_modified timestamp(14) NOT NULL, name varchar(255) binary default NULL, description varchar(255) default NULL, UNIQUE KEY hmid (hmid,volid)) ENGINE=MyISAM; +CREATE TABLE t1 (gvid int(10) unsigned default NULL, hmid int(10) unsigned default NULL, volid int(10) unsigned default NULL, mmid int(10) unsigned default NULL, hdid int(10) unsigned default NULL, fsid int(10) unsigned default NULL, ctid int(10) unsigned default NULL, dtid int(10) unsigned default NULL, cost int(10) unsigned default NULL, performance int(10) unsigned default NULL, serialnumber bigint(20) unsigned default NULL, monitored tinyint(3) unsigned default '1', removed tinyint(3) unsigned default '0', target tinyint(3) unsigned default '0', dt_modified timestamp NOT NULL, name varchar(255) binary default NULL, description varchar(255) default NULL, UNIQUE KEY hmid (hmid,volid)) ENGINE=MyISAM; INSERT INTO t1 VALUES (200001,2,1,1,100,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\E$',''),(200002,2,2,1,101,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\C$',''),(200003,1,3,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0,1,20020425060427,'c:',NULL); CREATE TABLE t2 ( hmid int(10) unsigned default NULL, volid int(10) unsigned default NULL, sampletid smallint(5) unsigned default NULL, sampletime datetime default NULL, samplevalue bigint(20) unsigned default NULL, KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM; INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35); +# Disable PS becasue we get more warnings from PS than from normal execution +--disable_ps_protocol SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid; +--enable_ps_protocol # Testing the same select with NULL's instead of invalid datetime values SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid; DROP TABLE t1,t2; @@ -2118,8 +2135,8 @@ WHERE drop table t1,t2,t3; # -# Bug #11482 4.1.12 produces different resultset for a complex query -# than in previous 4.1.x +# Bug #11482 Wrongly applied optimization was erroneously rejecting valid +# rows create table t1 (f1 int); insert into t1 values (1),(NULL); create table t2 (f2 int, f3 int, f4 int); @@ -2200,31 +2217,21 @@ show table status like 't1%'; select 123 as a from t1 where f1 is null; drop table t1,t11; -# Bug 7672 Unknown column error in order clause -# -CREATE TABLE t1 (a INT, b INT); -(SELECT a, b AS c FROM t1) ORDER BY c+1; -(SELECT a, b AS c FROM t1) ORDER BY b+1; -SELECT a, b AS c FROM t1 ORDER BY c+1; -SELECT a, b AS c FROM t1 ORDER BY b+1; -drop table t1; - # # Bug #3874 (function in GROUP and LEFT JOIN) # CREATE TABLE t1 ( a INT NOT NULL, b INT NOT NULL, UNIQUE idx (a,b) ); INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4); -CREATE TABLE t2 ( a INT NOT NULL, b INT NOT NULL, c INT ); -INSERT INTO t2 VALUES ( 1,10,1), (1,10,2), (1,11,1), (1,11,2), (1,2,1), (1,2,2), - (1,2,3); -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2 LEFT JOIN +CREATE TABLE t2 ( a INT NOT NULL, b INT NOT NULL, e INT ); +INSERT INTO t2 VALUES ( 1,10,1), (1,10,2), (1,11,1), (1,11,2), (1,2,1), (1,2,2),(1,2,3); +SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2 LEFT JOIN t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY a, b, c; -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2 LEFT JOIN +SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2 LEFT JOIN t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY t1.a, t1.b, c; -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2 LEFT JOIN +SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2 LEFT JOIN t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY t2.a, t2.b, c; -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2,t1 +SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2,t1 WHERE t2.a = t1.a AND t2.b = t1.b GROUP BY a, b, c; DROP TABLE IF EXISTS t1, t2; @@ -2294,7 +2301,7 @@ DROP TABLE t1; # CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL); INSERT INTO t1 VALUES (10); -SELECT i='1e+01',i=1e+01, i in (1e+01), i in ('1e+01') FROM t1; +SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1; DROP TABLE t1; # @@ -2343,3 +2350,745 @@ DROP TABLE t1,t2; --enable_ps_protocol # End of 4.1 tests + +# +# Test for bug #6474 +# + +CREATE TABLE t1 ( +K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '', +K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000', +F2I4 int(11) NOT NULL default '0' +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +INSERT INTO t1 VALUES +('W%RT', '0100', 1), +('W-RT', '0100', 1), +('WART', '0100', 1), +('WART', '0200', 1), +('WERT', '0100', 2), +('WORT','0200', 2), +('WT', '0100', 2), +('W_RT', '0100', 2), +('WaRT', '0100', 3), +('WART', '0300', 3), +('WRT' , '0400', 3), +('WURM', '0500', 3), +('W%T', '0600', 4), +('WA%T', '0700', 4), +('WA_T', '0800', 4); + +SELECT K2C4, K4N4, F2I4 FROM t1 + WHERE K2C4 = 'WART' AND + (F2I4 = 2 AND K2C4 = 'WART' OR (F2I4 = 2 OR K4N4 = '0200')); +SELECT K2C4, K4N4, F2I4 FROM t1 + WHERE K2C4 = 'WART' AND (K2C4 = 'WART' OR K4N4 = '0200'); +DROP TABLE t1; + +# +# Bug#8670 +# +create table t1 (a int, b int); +create table t2 like t1; +select t1.a from (t1 inner join t2 on t1.a=t2.a) where t2.a=1; +select t1.a from ((t1 inner join t2 on t1.a=t2.a)) where t2.a=1; +select x.a, y.a, z.a from ( (t1 x inner join t2 y on x.a=y.a) inner join t2 z on y.a=z.a) WHERE x.a=1; +drop table t1,t2; + +# +# Bug#9820 +# + +create table t1 (s1 varchar(5)); +insert into t1 values ('Wall'); +select min(s1) from t1 group by s1 with rollup; +drop table t1; + +# +# Bug#9799 +# + +create table t1 (s1 int) engine=myisam; +insert into t1 values (0); +select avg(distinct s1) from t1 group by s1 with rollup; +drop table t1; + +# +# Bug#9800 +# + +create table t1 (s1 int); +insert into t1 values (null),(1); +select distinct avg(s1) as x from t1 group by s1 with rollup; +drop table t1; + + +# +# Test for bug #10084: STRAIGHT_JOIN with ON expression +# + +CREATE TABLE t1 (a int); +CREATE TABLE t2 (a int); +INSERT INTO t1 VALUES (1), (2), (3), (4), (5); +INSERT INTO t2 VALUES (2), (4), (6); + +SELECT t1.a FROM t1 STRAIGHT_JOIN t2 ON t1.a=t2.a; + +EXPLAIN SELECT t1.a FROM t1 STRAIGHT_JOIN t2 ON t1.a=t2.a; +EXPLAIN SELECT t1.a FROM t1 INNER JOIN t2 ON t1.a=t2.a; + +DROP TABLE t1,t2; + +# +# Bug #10650 +# + +select x'10' + 0, X'10' + 0, b'10' + 0, B'10' + 0; + +# +# Bug #11398 Bug in field_conv() results in wrong result of join with index +# +create table t1 (f1 varchar(6) default NULL, f2 int(6) primary key not null); +create table t2 (f3 varchar(5) not null, f4 varchar(5) not null, UNIQUE KEY UKEY (f3,f4)); +insert into t1 values (" 2", 2); +insert into t2 values (" 2", " one "),(" 2", " two "); +select * from t1 left join t2 on f1 = f3; +drop table t1,t2; + +# +# Bug #6558 Views: CREATE VIEW fails with JOIN ... USING +# + +create table t1 (empnum smallint, grp int); +create table t2 (empnum int, name char(5)); +insert into t1 values(1,1); +insert into t2 values(1,'bob'); +create view v1 as select * from t2 inner join t1 using (empnum); +select * from v1; +drop table t1,t2; +drop view v1; + +# +# Bug #10646 Columns included in the join between two tables are ambigious +# in the select +# + +create table t1 (pk int primary key, b int); +create table t2 (pk int primary key, c int); +select pk from t1 inner join t2 using (pk); +drop table t1,t2; + +# +# Bug #10972 Natural join of view and underlying table gives wrong result +# + +create table t1 (s1 int, s2 char(5), s3 decimal(10)); +create view v1 as select s1, s2, 'x' as s3 from t1; +select * from t1 natural join v1; +insert into t1 values (1,'x',5); +select * from t1 natural join v1; +drop table t1; +drop view v1; + +# +# Bug #6276 A SELECT that does a NATURAL OUTER JOIN without common +# columns crashes server because of empty ON condition +# + +create table t1(a1 int); +create table t2(a2 int); +insert into t1 values(1),(2); +insert into t2 values(1),(2); +create view v2 (c) as select a1 from t1; + +select * from t1 natural left join t2; +select * from t1 natural right join t2; + +select * from v2 natural left join t2; +select * from v2 natural right join t2; + +drop table t1, t2; +drop view v2; + + +# +# Bug #4789 Incosistent results of more than 2-way natural joins due to +# incorrect transformation to join ... on. +# + +create table t1 (a int(10), t1_val int(10)); +create table t2 (b int(10), t2_val int(10)); +create table t3 (a int(10), b int(10)); +insert into t1 values (1,1),(2,2); +insert into t2 values (1,1),(2,2),(3,3); +insert into t3 values (1,1),(2,1),(3,1),(4,1); +# the following two queries must return the same result +select * from t1 natural join t2 natural join t3; +select * from t1 natural join t3 natural join t2; +drop table t1, t2, t3; + + +# +# Bug #12841: Server crash on DO IFNULL(NULL,NULL) +# +# (testing returning of int, decimal, real, string) +DO IFNULL(NULL, NULL); +SELECT CAST(IFNULL(NULL, NULL) AS DECIMAL); +SELECT ABS(IFNULL(NULL, NULL)); +SELECT IFNULL(NULL, NULL); + +# +# BUG #12595 (ESCAPE must be exactly one) +# +SET @OLD_SQL_MODE12595=@@SQL_MODE, @@SQL_MODE=''; +SHOW LOCAL VARIABLES LIKE 'SQL_MODE'; + +CREATE TABLE BUG_12595(a varchar(100)); +INSERT INTO BUG_12595 VALUES ('hakan%'), ('hakank'), ("ha%an"); +SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%'; +SELECT * FROM BUG_12595 WHERE a LIKE 'hakan*%' ESCAPE '*'; +-- error 1210 +SELECT * FROM BUG_12595 WHERE a LIKE 'hakan**%' ESCAPE '**'; +# this should work when sql_mode is not NO_BACKSLASH_ESCAPES +SELECT * FROM BUG_12595 WHERE a LIKE 'hakan%' ESCAPE ''; +SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%' ESCAPE ''; +SELECT * FROM BUG_12595 WHERE a LIKE 'ha\%an' ESCAPE 0x5c; +SELECT * FROM BUG_12595 WHERE a LIKE 'ha%%an' ESCAPE '%'; +SELECT * FROM BUG_12595 WHERE a LIKE 'ha\%an' ESCAPE '\\'; +SELECT * FROM BUG_12595 WHERE a LIKE 'ha|%an' ESCAPE '|'; + +SET @@SQL_MODE='NO_BACKSLASH_ESCAPES'; +SHOW LOCAL VARIABLES LIKE 'SQL_MODE'; +SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%'; +SELECT * FROM BUG_12595 WHERE a LIKE 'hakan*%' ESCAPE '*'; +-- error 1210 +SELECT * FROM BUG_12595 WHERE a LIKE 'hakan**%' ESCAPE '**'; +-- error 1210 +SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%' ESCAPE '\\'; +#this gives an error when NO_BACKSLASH_ESCAPES is set +-- error 1210 +SELECT * FROM BUG_12595 WHERE a LIKE 'hakan%' ESCAPE ''; +SELECT * FROM BUG_12595 WHERE a LIKE 'ha\%an' ESCAPE 0x5c; +SELECT * FROM BUG_12595 WHERE a LIKE 'ha|%an' ESCAPE '|'; +-- error 1210 +SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\n%' ESCAPE '\n'; + +SET @@SQL_MODE=@OLD_SQL_MODE12595; +DROP TABLE BUG_12595; + +# +# Bug #6495 Illogical requirement for column qualification in NATURAL join +# + +create table t1 (a char(1)); +create table t2 (a char(1)); +insert into t1 values ('a'),('b'),('c'); +insert into t2 values ('b'),('c'),('d'); +select a from t1 natural join t2; +select * from t1 natural join t2 where a = 'b'; +drop table t1, t2; + +# +# Bug #12977 Compare table names with qualifying field tables only +# for base tables, search all nested join operands of natural joins. +# + +CREATE TABLE t1 (`id` TINYINT); +CREATE TABLE t2 (`id` TINYINT); +CREATE TABLE t3 (`id` TINYINT); +INSERT INTO t1 VALUES (1),(2),(3); +INSERT INTO t2 VALUES (2); +INSERT INTO t3 VALUES (3); +-- error 1052 +SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id); +-- error 1052 +SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.notacolumn=t1.id) LEFT JOIN t3 USING (id); +-- error 1052 +SELECT id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id); +-- error 1052 +SELECT id,t3.id FROM (t1 JOIN t2 ON (t2.id=t1.id)) LEFT JOIN t3 USING (id); + +drop table t1, t2, t3; + +# +# Bug #13067 JOIN xxx USING is case sensitive +# + +create table t1 (a int(10),b int(10)); +create table t2 (a int(10),b int(10)); +insert into t1 values (1,10),(2,20),(3,30); +insert into t2 values (1,10); +# both queries should produce the same result +select * from t1 inner join t2 using (A); +select * from t1 inner join t2 using (a); +drop table t1, t2; + +# +# Bug #12943 Incorrect nesting of [INNER| CROSS] JOIN due to unspecified +# associativity in the parser. +# + +create table t1 (a int, c int); +create table t2 (b int); +create table t3 (b int, a int); +create table t4 (c int); +insert into t1 values (1,1); +insert into t2 values (1); +insert into t3 values (1,1); +insert into t4 values (1); + +select * from t1 join t2 join t3 on (t2.b = t3.b and t1.a = t3.a); +# Notice that ',' has lower priority than 'join', thus we have that: +# t1, t2 join t3 <==> t1, (t2 join t3). +-- error 1054 +select * from t1, t2 join t3 on (t2.b = t3.b and t1.a = t3.a); +select * from t1 join t2 join t3 join t4 on (t1.a = t4.c and t2.b = t4.c); +select * from t1 join t2 join t4 using (c); +drop table t1, t2, t3, t4; + +# +# Bug #12291 Table wasn't reinited for index scan after sequential scan +# +create table t1(x int, y int); +create table t2(x int, y int); +create table t3(x int, primary key(x)); +insert into t1 values (1, 1), (2, 1), (3, 1), (4, 3), (5, 6), (6, 6); +insert into t2 values (1, 1), (2, 1), (3, 3), (4, 6), (5, 6); +insert into t3 values (1), (2), (3), (4), (5); +select t1.x, t3.x from t1, t2, t3 where t1.x = t2.x and t3.x >= t1.y and t3.x <= t2.y; +drop table t1,t2,t3; + +# +# Bug #13127 LEFT JOIN against a VIEW returns NULL instead of correct value +# + +create table t1 (id char(16) not null default '', primary key (id)); +insert into t1 values ('100'),('101'),('102'); +create table t2 (id char(16) default null); +insert into t2 values (1); +create view v1 as select t1.id from t1; +create view v2 as select t2.id from t2; +create view v3 as select (t1.id+2) as id from t1 natural left join t2; + +# all queries must return the same result +select t1.id from t1 left join v2 using (id); +select t1.id from v2 right join t1 using (id); +select t1.id from t1 left join v3 using (id); +select * from t1 left join v2 using (id); +select * from v2 right join t1 using (id); +select * from t1 left join v3 using (id); + +select v1.id from v1 left join v2 using (id); +select v1.id from v2 right join v1 using (id); +select v1.id from v1 left join v3 using (id); +select * from v1 left join v2 using (id); +select * from v2 right join v1 using (id); +select * from v1 left join v3 using (id); + +drop table t1, t2; +drop view v1, v2, v3; + +# +# Bug #13597 Column in ON condition not resolved if references a table in +# nested right join. +# + +create table t1 (id int(11) not null default '0'); +insert into t1 values (123),(191),(192); +create table t2 (id char(16) character set utf8 not null); +insert into t2 values ('58013'),('58014'),('58015'),('58016'); +create table t3 (a_id int(11) not null, b_id char(16) character set utf8); +insert into t3 values (123,null),(123,null),(123,null),(123,null),(123,null),(123,'58013'); + +-- both queries are equivalent +select count(*) +from t1 inner join (t3 left join t2 on t2.id = t3.b_id) on t1.id = t3.a_id; + +select count(*) +from t1 inner join (t2 right join t3 on t2.id = t3.b_id) on t1.id = t3.a_id; + +drop table t1,t2,t3; + +# +# Bug #13832 Incorrect parse order of join productions due to unspecified +# operator priorities results in incorrect join tree. +# + +create table t1 (a int); +create table t2 (b int); +create table t3 (c int); +select * from t1 join t2 join t3 on (t1.a=t3.c); +select * from t1 join t2 left join t3 on (t1.a=t3.c); +select * from t1 join t2 right join t3 on (t1.a=t3.c); +select * from t1 join t2 straight_join t3 on (t1.a=t3.c); +drop table t1, t2 ,t3; + +# +# Bug #14093 Query takes a lot of time when date format is not valid +# fix optimizes execution. so here we just check that returned set is +# correct. +create table t1(f1 int, f2 date); +insert into t1 values(1,'2005-01-01'),(2,'2005-09-01'),(3,'2005-09-30'), + (4,'2005-10-01'),(5,'2005-12-30'); +# should return all records +select * from t1 where f2 >= 0; +select * from t1 where f2 >= '0000-00-00'; +# should return 4,5 +select * from t1 where f2 >= '2005-09-31'; +select * from t1 where f2 >= '2005-09-3a'; +# should return 1,2,3 +select * from t1 where f2 <= '2005-09-31'; +select * from t1 where f2 <= '2005-09-3a'; +drop table t1; + +# +# Bug ##14662 ORDER BY on column of a view, with an alias of the same +# column causes ambiguous +# + +create table t1 (f1 int, f2 int); +insert into t1 values (1, 30), (2, 20), (3, 10); +create algorithm=merge view v1 as select f1, f2 from t1; +create algorithm=merge view v2 (f2, f1) as select f1, f2 from t1; +create algorithm=merge view v3 as select t1.f1 as f2, t1.f2 as f1 from t1; +select t1.f1 as x1, f1 from t1 order by t1.f1; +select v1.f1 as x1, f1 from v1 order by v1.f1; +select v2.f1 as x1, f1 from v2 order by v2.f1; +select v3.f1 as x1, f1 from v3 order by v3.f1; +select f1, f2, v1.f1 as x1 from v1 order by v1.f1; +select f1, f2, v2.f1 as x1 from v2 order by v2.f1; +select f1, f2, v3.f1 as x1 from v3 order by v3.f1; +drop table t1; +drop view v1, v2, v3; + +# +# Bug #15106: lost equality predicate of the form field=const in a join query +# + +CREATE TABLE t1(key_a int4 NOT NULL, optimus varchar(32), PRIMARY KEY(key_a)); +CREATE TABLE t2(key_a int4 NOT NULL, prime varchar(32), PRIMARY KEY(key_a)); +CREATE table t3(key_a int4 NOT NULL, key_b int4 NOT NULL, foo varchar(32), + PRIMARY KEY(key_a,key_b)); + +INSERT INTO t1 VALUES (0,''); +INSERT INTO t1 VALUES (1,'i'); +INSERT INTO t1 VALUES (2,'j'); +INSERT INTO t1 VALUES (3,'k'); + +INSERT INTO t2 VALUES (1,'r'); +INSERT INTO t2 VALUES (2,'s'); +INSERT INTO t2 VALUES (3,'t'); + +INSERT INTO t3 VALUES (1,5,'x'); +INSERT INTO t3 VALUES (1,6,'y'); +INSERT INTO t3 VALUES (2,5,'xx'); +INSERT INTO t3 VALUES (2,6,'yy'); +INSERT INTO t3 VALUES (2,7,'zz'); +INSERT INTO t3 VALUES (3,5,'xxx'); + +SELECT t2.key_a,foo + FROM t1 INNER JOIN t2 ON t1.key_a = t2.key_a + INNER JOIN t3 ON t1.key_a = t3.key_a + WHERE t2.key_a=2 and key_b=5; +EXPLAIN SELECT t2.key_a,foo + FROM t1 INNER JOIN t2 ON t1.key_a = t2.key_a + INNER JOIN t3 ON t1.key_a = t3.key_a + WHERE t2.key_a=2 and key_b=5; + +SELECT t2.key_a,foo + FROM t1 INNER JOIN t2 ON t2.key_a = t1.key_a + INNER JOIN t3 ON t1.key_a = t3.key_a + WHERE t2.key_a=2 and key_b=5; +EXPLAIN SELECT t2.key_a,foo + FROM t1 INNER JOIN t2 ON t2.key_a = t1.key_a + INNER JOIN t3 ON t1.key_a = t3.key_a + WHERE t2.key_a=2 and key_b=5; + +DROP TABLE t1,t2,t3; + +# +# Bug#15347 Wrong result of subselect when records cache and set functions +# are involved +# +create table t1 (f1 int); +insert into t1 values(1),(2); +create table t2 (f2 int, f3 int, key(f2)); +insert into t2 values(1,1),(2,2); +create table t3 (f4 int not null); +insert into t3 values (2),(2),(2); +select f1,(select count(*) from t2,t3 where f2=f1 and f3=f4) as count from t1; +drop table t1,t2,t3; + +# +# Bug #15633 Evaluation of Item_equal for non-const table caused wrong +# select result +# +create table t1 (f1 int unique); +create table t2 (f2 int unique); +create table t3 (f3 int unique); +insert into t1 values(1),(2); +insert into t2 values(1),(2); +insert into t3 values(1),(NULL); +select * from t3 where f3 is null; +select t2.f2 from t1 left join t2 on f1=f2 join t3 on f1=f3 where f1=1; +drop table t1,t2,t3; + +# +# Bug#15268 Unchecked null value caused server crash +# +create table t1(f1 char, f2 char not null); +insert into t1 values(null,'a'); +create table t2 (f2 char not null); +insert into t2 values('b'); +select * from t1 left join t2 on f1=t2.f2 where t1.f2='a'; +drop table t1,t2; + +# +# Bug#15538 unchecked table absense caused server crash. +# +--error 1064 +select * from (select * left join t on f1=f2) tt; + +# +# Bug #16504: re-evaluation of Item_equal object after reading const table +# + +CREATE TABLE t1 (sku int PRIMARY KEY, pr int); +CREATE TABLE t2 (sku int PRIMARY KEY, sppr int, name varchar(255)); + +INSERT INTO t1 VALUES + (10, 10), (20, 10), (30, 20), (40, 30), (50, 10), (60, 10); + +INSERT INTO t2 VALUES + (10, 10, 'aaa'), (20, 10, 'bbb'), (30, 10, 'ccc'), (40, 20, 'ddd'), + (50, 10, 'eee'), (60, 20, 'fff'), (70, 20, 'ggg'), (80, 30, 'hhh'); + +SELECT t2.sku, t2.sppr, t2.name, t1.sku, t1.pr + FROM t2, t1 WHERE t2.sku=20 AND (t2.sku=t1.sku OR t2.sppr=t1.sku); +EXPLAIN +SELECT t2.sku, t2.sppr, t2.name, t1.sku, t1.pr + FROM t2, t1 WHERE t2.sku=20 AND (t2.sku=t1.sku OR t2.sppr=t1.sku); + + +DROP TABLE t1,t2; + +# +# Bug#18712: Truncation problem (needs just documenting and test +# cases to prevent fixing this accidently. It is intended behaviour) +# + +CREATE TABLE t1 (i TINYINT UNSIGNED NOT NULL); +INSERT t1 SET i = 0; +UPDATE t1 SET i = -1; +SELECT * FROM t1; +UPDATE t1 SET i = CAST(i - 1 AS SIGNED); +SELECT * FROM t1; +UPDATE t1 SET i = i - 1; +SELECT * FROM t1; +DROP TABLE t1; + +# BUG#17379 + +create table t1 (a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t2 (a int, b int, c int, e int, primary key(a,b,c)); +insert into t2 select A.a, B.a, C.a, C.a from t1 A, t1 B, t1 C; +analyze table t2; +select 'In next EXPLAIN, B.rows must be exactly 10:' Z; + +explain select * from t2 A, t2 B where A.a=5 and A.b=5 and A.C<5 + and B.a=5 and B.b=A.e and (B.b =1 or B.b = 3 or B.b=5); +drop table t1, t2; + +# +#Bug #18940: selection of optimal execution plan caused by equality +# propagation (the bug was fixed by the patch for bug #17379) + +CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX(b)); +INSERT INTO t1 VALUES (1, 3), (9,4), (7,5), (4,5), (6,2), + (3,1), (5,1), (8,9), (2,2), (0,9); + +CREATE TABLE t2 (c int, d int, f int, INDEX(c,f)); +INSERT INTO t2 VALUES + (1,0,0), (1,0,1), (2,0,0), (2,0,1), (3,0,0), (4,0,1), + (5,0,0), (5,0,1), (6,0,0), (0,0,1), (7,0,0), (7,0,1), + (0,0,0), (0,0,1), (8,0,0), (8,0,1), (9,0,0), (9,0,1); + +EXPLAIN +SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6; +EXPLAIN +SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6 AND a > 0; + +DROP TABLE t1, t2; + +# +# Bug #18895: BIT values cause joins to fail +# +create table t1 ( + a int unsigned not null auto_increment primary key, + b bit not null, + c bit not null +); + +create table t2 ( + a int unsigned not null auto_increment primary key, + b bit not null, + c int unsigned not null, + d varchar(50) +); + +insert into t1 (b,c) values (0,1), (0,1); +insert into t2 (b,c) values (0,1); + +-- Row 1 should succeed. Row 2 should fail. Both fail. +select t1.a, t1.b + 0, t1.c + 0, t2.a, t2.b + 0, t2.c, t2.d +from t1 left outer join t2 on t1.a = t2.c and t2.b <> 1 +where t1.b <> 1 order by t1.a; + +drop table t1,t2; + +# +# Bug #20569: Garbage in DECIMAL results from some mathematical functions +# +SELECT 0.9888889889 * 1.011111411911; + +# +# Bug #10977: No warning issued if a column name is truncated +# +prepare stmt from 'select 1 as " a "'; +execute stmt; + +# +# Bug #21390: wrong estimate of rows after elimination of const tables +# + +CREATE TABLE t1 (a int NOT NULL PRIMARY KEY, b int NOT NULL); +INSERT INTO t1 VALUES (1,1), (2,2), (3,3), (4,4); + +CREATE TABLE t2 (c int NOT NULL, INDEX idx(c)); +INSERT INTO t2 VALUES + (1), (1), (1), (1), (1), (1), (1), (1), + (2), (2), (2), (2), + (3), (3), + (4); + +EXPLAIN SELECT b FROM t1, t2 WHERE b=c AND a=1; +EXPLAIN SELECT b FROM t1, t2 WHERE b=c AND a=4; + +DROP TABLE t1, t2; + +# +# No matches for a join after substitution of a const table +# + +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a int); +INSERT INTO t1 VALUES (1,2), (2,NULL), (3,2); + +CREATE TABLE t2 (b int, c INT, INDEX idx1(b)); +INSERT INTO t2 VALUES (2,1), (3,2); + +CREATE TABLE t3 (d int, e int, INDEX idx1(d)); +INSERT INTO t3 VALUES (2,10), (2,20), (1,30), (2,40), (2,50); + +EXPLAIN +SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id + WHERE t1.id=2; +SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id + WHERE t1.id=2; + +DROP TABLE t1,t2,t3; + +# +# Bug#20503: Server crash due to the ORDER clause isn't taken into account +# while space allocation +# +create table t1 (c1 varchar(1), c2 int, c3 int, c4 int, c5 int, c6 int, +c7 int, c8 int, c9 int, fulltext key (`c1`)); +select distinct match (`c1`) against ('z') , c2, c3, c4,c5, c6,c7, c8 + from t1 where c9=1 order by c2, c2; +drop table t1; + +# +# Bug #22735: no equality propagation for BETWEEN and IN with STRING arguments +# + +CREATE TABLE t1 (pk varchar(10) PRIMARY KEY, fk varchar(16)); +CREATE TABLE t2 (pk varchar(16) PRIMARY KEY, fk varchar(10)); + +INSERT INTO t1 VALUES + ('d','dddd'), ('i','iii'), ('a','aa'), ('b','bb'), ('g','gg'), + ('e','eee'), ('c','cccc'), ('h','hhh'), ('j','jjj'), ('f','fff'); +INSERT INTO t2 VALUES + ('jjj', 'j'), ('cc','c'), ('ccc','c'), ('aaa', 'a'), ('jjjj','j'), + ('hhh','h'), ('gg','g'), ('fff','f'), ('ee','e'), ('ffff','f'), + ('bbb','b'), ('ff','f'), ('cccc','c'), ('dddd','d'), ('jj','j'), + ('aaaa','a'), ('bb','b'), ('eeee','e'), ('aa','a'), ('hh','h'); + +EXPLAIN SELECT t2.* + FROM t1 JOIN t2 ON t2.fk=t1.pk + WHERE t2.fk < 'c' AND t2.pk=t1.fk; +EXPLAIN SELECT t2.* + FROM t1 JOIN t2 ON t2.fk=t1.pk + WHERE t2.fk BETWEEN 'a' AND 'b' AND t2.pk=t1.fk; +EXPLAIN SELECT t2.* + FROM t1 JOIN t2 ON t2.fk=t1.pk + WHERE t2.fk IN ('a','b') AND t2.pk=t1.fk; + +DROP TABLE t1,t2; + +# +# Bug #22367: Optimizer uses ref join type instead of eq_ref for simple +# join on strings +# +CREATE TABLE t1 (a int, b varchar(20) NOT NULL, PRIMARY KEY(a)); +CREATE TABLE t2 (a int, b varchar(20) NOT NULL, + PRIMARY KEY (a), UNIQUE KEY (b)); +INSERT INTO t1 VALUES (1,'a'),(2,'b'),(3,'c'); +INSERT INTO t2 VALUES (1,'a'),(2,'b'),(3,'c'); + +EXPLAIN SELECT t1.a FROM t1 LEFT JOIN t2 ON t2.b=t1.b WHERE t1.a=3; + +DROP TABLE t1,t2; + +# +# Bug #19579: predicates that become sargable after reading const tables +# are not taken into account by optimizer +# + +CREATE TABLE t1(id int PRIMARY KEY, b int, e int); +CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a)); +CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c)); + +INSERT INTO t1 VALUES + (1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79), + (6,63,67), (5,55,58), (3,38,39), (8,81,89); +INSERT INTO t2 VALUES + (21,210), (41,410), (82,820), (83,830), (84,840), + (65,650), (51,510), (37,370), (94,940), (76,760), + (22,220), (33,330), (40,400), (95,950), (38,380), + (67,670), (88,880), (57,570), (96,960), (97,970); +INSERT INTO t3 VALUES + (210,'bb'), (950,'ii'), (400,'ab'), (500,'ee'), (220,'gg'), + (440,'gg'), (310,'eg'), (380,'ee'), (840,'bb'), (830,'ff'), + (230,'aa'), (960,'ii'), (410,'aa'), (510,'ee'), (290,'bb'), + (450,'gg'), (320,'dd'), (390,'hh'), (850,'jj'), (860,'ff'); + +EXPLAIN +SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3 + WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND + t3.a=t2.a AND t3.c IN ('bb','ee'); +EXPLAIN +SELECT t3.a FROM t1,t2,t3 + WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND + t3.a=t2.a AND t3.c IN ('bb','ee') ; + +EXPLAIN +SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3 + WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND + t3.c IN ('bb','ee'); +EXPLAIN +SELECT t3.a FROM t1,t2,t3 + WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND + t3.c IN ('bb','ee'); + +DROP TABLE t1,t2,t3; diff --git a/mysql-test/t/select_safe.test b/mysql-test/t/select_safe.test index 236370bef03..481779e76d7 100644 --- a/mysql-test/t/select_safe.test +++ b/mysql-test/t/select_safe.test @@ -56,7 +56,6 @@ SELECT * from t1; # # Test MAX_SEEKS_FOR_KEY # -SELECT @@MAX_SEEKS_FOR_KEY; analyze table t1; insert into t1 values (null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"); explain select STRAIGHT_JOIN * from t1,t1 as t2 where t1.b=t2.b; @@ -79,7 +78,7 @@ select * from (select * from t1) x; set local max_join_size=1; --error 1104 -select * from (select * from t1 a, t1 b) x; +select * from (select a.a as aa, b.a as ba from t1 a, t1 b) x; set local max_join_size=1; --error 1104 diff --git a/mysql-test/t/show_check-master.opt b/mysql-test/t/show_check-master.opt new file mode 100644 index 00000000000..3eb98fc3d6b --- /dev/null +++ b/mysql-test/t/show_check-master.opt @@ -0,0 +1 @@ +--log-slow-queries --log-long-format --log-queries-not-using-indexes diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index d70903adbc4..849be577893 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -8,7 +8,9 @@ --disable_warnings drop table if exists t1,t2; +drop table if exists t1aa,t2aa; drop database if exists mysqltest; +drop database if exists mysqltest1; delete from mysql.user where user='mysqltest_1' || user='mysqltest_2' || user='mysqltest_3'; delete from mysql.db where user='mysqltest_1' || user='mysqltest_2' || user='mysqltest_3'; @@ -105,7 +107,7 @@ drop table t1; # Do a create table that tries to cover all types and options # create table t1 ( -type_bool bool not null, +type_bool bool not null default 0, type_tiny tinyint not null auto_increment primary key, type_short smallint(3), type_mediumint mediumint, @@ -116,9 +118,9 @@ empty_char char(0), type_char char(2), type_varchar varchar(10), type_timestamp timestamp not null, -type_date date not null, -type_time time not null, -type_datetime datetime not null, +type_date date not null default '0000-00-00', +type_time time not null default '00:00:00', +type_datetime datetime not null default '0000-00-00 00:00:00', type_year year, type_enum enum ('red', 'green', 'blue'), type_set enum ('red', 'green', 'blue'), @@ -176,16 +178,24 @@ CREATE TABLE `a/b` (i INT); #CREATE TABLE ```ab````cd``` (i INT); #SHOW CREATE TABLE ```ab````cd```; #DROP TABLE ```ab````cd```; - +# #CREATE TABLE ```a` (i INT); #SHOW CREATE TABLE ```a`; #DROP TABLE ```a`; - -SET sql_mode= 'ANSI_QUOTES'; - +# +#SET sql_mode= 'ANSI_QUOTES'; +# #CREATE TABLE """a" (i INT); #SHOW CREATE TABLE """a"; #DROP TABLE """a"; +# +#Bug #4374 SHOW TABLE STATUS FROM ignores collation_connection +#set names latin1; +#create database `ä`; +#create table `ä`.`ä` (a int) engine=heap; +#--replace_column 7 # 8 # 9 # +#show table status from `ä` LIKE 'ä'; +#drop database `ä`; ######################################################### # end of part that must be uncommented when WL#1324 is done ######################################################### @@ -214,7 +224,7 @@ select @@max_heap_table_size; CREATE TABLE t1 ( a int(11) default NULL, - KEY a TYPE BTREE (a) + KEY a USING BTREE (a) ) ENGINE=HEAP; CREATE TABLE t2 ( @@ -225,7 +235,7 @@ CREATE TABLE t2 ( CREATE TABLE t3 ( a int(11) default NULL, b int(11) default NULL, - KEY a TYPE BTREE (a), + KEY a USING BTREE (a), index(b) ) ENGINE=HEAP; @@ -283,25 +293,25 @@ connect (con1,localhost,mysqltest_1,,mysqltest); connection con1; select * from t1; show create database mysqltest; ---error 1044 +--error 1142 drop table t1; --error 1044 drop database mysqltest; connect (con2,localhost,mysqltest_2,,test); connection con2; ---error 1044 +--error 1142 select * from mysqltest.t1; --error 1044 show create database mysqltest; ---error 1044 +--error 1142 drop table mysqltest.t1; --error 1044 drop database mysqltest; connect (con3,localhost,mysqltest_3,,test); connection con3; ---error 1044 +--error 1142 select * from mysqltest.t1; --error 1044 show create database mysqltest; @@ -316,7 +326,6 @@ delete from mysql.db where user='mysqltest_1' || user='mysqltest_2' || user='mysqltest_3'; flush privileges; -#Bug #4374 SHOW TABLE STATUS FROM ignores collation_connection # This test fails on MAC OSX, so it is temporary disabled. # This needs WL#1324 to be done. #set names latin1; @@ -383,7 +392,7 @@ DROP TABLE t1; flush tables; # Create a junk frm file on disk -system echo "this is a junk file for test" >> var/master-data/test/t1.frm ; +system echo "this is a junk file for test" >> $MYSQLTEST_VARDIR/master-data/test/t1.frm ; --replace_column 6 # 7 # 8 # 9 # SHOW TABLE STATUS like 't1'; --error 1033 @@ -391,4 +400,123 @@ show create table t1; drop table t1; -# End of 4.1 tests +--echo End of 4.1 tests + +# +# BUG 12183 - SHOW OPEN TABLES behavior doesn't match grammar +# First we close all open tables with FLUSH tables and then we open some. +CREATE TABLE txt1(a int); +CREATE TABLE tyt2(a int); +CREATE TABLE urkunde(a int); +FLUSH TABLES; +SELECT 1 FROM mysql.db, mysql.proc, mysql.user, mysql.time_zone, mysql.time_zone_name, txt1, tyt2, urkunde LIMIT 0; +SHOW OPEN TABLES; +SHOW OPEN TABLES FROM mysql; +SHOW OPEN TABLES FROM mysql LIKE 'u%'; +SHOW OPEN TABLES LIKE 't%'; +SHOW OPEN TABLES LIKE '%o%'; +FLUSH TABLES; +SHOW OPEN TABLES; +DROP TABLE txt1; +DROP TABLE tyt2; +DROP TABLE urkunde; +# +# BUG #12591 (SHOW TABLES FROM dbname produces wrong error message) +# +--error 1049 +SHOW TABLES FROM non_existing_database; + + +# +# Bug#17203: "sql_no_cache sql_cache" in views created from prepared +# statement +# +# The problem was that initial user setting was forgotten, and current +# runtime-determined values of the flags were shown instead. +# +--disable_warnings +DROP VIEW IF EXISTS v1; +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +# Check that SHOW CREATE VIEW shows SQL_CACHE flag exaclty as +# specified by the user. +CREATE VIEW v1 AS SELECT 1; +SHOW CREATE VIEW v1; +DROP VIEW v1; + +CREATE VIEW v1 AS SELECT SQL_CACHE 1; +SHOW CREATE VIEW v1; +DROP VIEW v1; + +CREATE VIEW v1 AS SELECT SQL_NO_CACHE 1; +SHOW CREATE VIEW v1; +DROP VIEW v1; + +# Usage of NOW() disables caching, but we still have show what the +# user have specified. +CREATE VIEW v1 AS SELECT NOW(); +SHOW CREATE VIEW v1; +DROP VIEW v1; + +CREATE VIEW v1 AS SELECT SQL_CACHE NOW(); +SHOW CREATE VIEW v1; +DROP VIEW v1; + +CREATE VIEW v1 AS SELECT SQL_NO_CACHE NOW(); +SHOW CREATE VIEW v1; +DROP VIEW v1; + +# Check that SQL_NO_CACHE always wins. +CREATE VIEW v1 AS SELECT SQL_CACHE SQL_NO_CACHE NOW(); +SHOW CREATE VIEW v1; +DROP VIEW v1; + +CREATE VIEW v1 AS SELECT SQL_NO_CACHE SQL_CACHE NOW(); +SHOW CREATE VIEW v1; +DROP VIEW v1; + +CREATE VIEW v1 AS SELECT SQL_CACHE SQL_NO_CACHE SQL_CACHE NOW(); +SHOW CREATE VIEW v1; +DROP VIEW v1; + +# Check CREATE VIEW in a prepared statement in a procedure. +delimiter |; +CREATE PROCEDURE p1() +BEGIN + SET @s= 'CREATE VIEW v1 AS SELECT SQL_CACHE 1'; + PREPARE stmt FROM @s; + EXECUTE stmt; + DROP PREPARE stmt; +END | +delimiter ;| +CALL p1(); +SHOW CREATE VIEW v1; + +DROP PROCEDURE p1; +DROP VIEW v1; + + +# +# Check that SHOW TABLES and SHOW COLUMNS give a error if there is no +# referenced database and table respectively. +# +--error ER_BAD_DB_ERROR +SHOW TABLES FROM no_such_database; +--error ER_NO_SUCH_TABLE +SHOW COLUMNS FROM no_such_table; + + +# +# Bug #19764: SHOW commands end up in the slow log as table scans +# +flush status; +show status like 'slow_queries'; +show tables; +show status like 'slow_queries'; +# Table scan query, to ensure that slow_queries does still get incremented +# (mysqld is started with --log-queries-not-using-indexes) +select 1 from information_schema.tables limit 1; +show status like 'slow_queries'; + +--echo End of 5.0 tests diff --git a/mysql-test/t/skip_grants-master.opt b/mysql-test/t/skip_grants-master.opt new file mode 100644 index 00000000000..5699a3387b8 --- /dev/null +++ b/mysql-test/t/skip_grants-master.opt @@ -0,0 +1 @@ +--skip-grant-tables diff --git a/mysql-test/t/skip_grants.test b/mysql-test/t/skip_grants.test new file mode 100644 index 00000000000..6dda97fcf8a --- /dev/null +++ b/mysql-test/t/skip_grants.test @@ -0,0 +1,110 @@ +# This tests not performed with embedded server +-- source include/not_embedded.inc + +use test; + +# +# BUG#16777: Can not create trigger nor view w/o definer if --skip-grant-tables +# specified +# +# Also, the following test cases have been moved here: +# - test that we can create VIEW if privileges check switched off has been +# moved here; +# - test that we can create and drop procedure without warnings (BUG#9993); +# - BUG#17595: "DROP FUNCTION IF EXISTS" crashes server; +# - BUG#13504: creation view with DEFINER clause if --skip-grant-tables +# + +# Prepare. + +--disable_warnings + +DROP VIEW IF EXISTS v1; +DROP VIEW IF EXISTS v2; +DROP VIEW IF EXISTS v3; + +DROP TABLE IF EXISTS t1; + +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; + +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; + +--enable_warnings + +# Test case. + +CREATE TABLE t1(c INT); + +# - try to create with implicit definer (definer would be ''@''); + +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 + FOR EACH ROW + SET @a = 1; + +CREATE VIEW v1 AS SELECT * FROM t1; + +CREATE PROCEDURE p1() + SELECT 1; + +CREATE FUNCTION f1() RETURNS INT + RETURN 1; + +# - try to create with explicit definer; + +CREATE DEFINER=a@b TRIGGER ti_ai AFTER INSERT ON t1 + FOR EACH ROW + SET @b = 1; + +CREATE DEFINER=a@b VIEW v2 AS SELECT * FROM t1; + +CREATE DEFINER=a@b PROCEDURE p2() + SELECT 2; + +CREATE DEFINER=a@b FUNCTION f2() RETURNS INT + RETURN 2; + +# - try to create with explicit definer with empty host; + +CREATE DEFINER=a@'' TRIGGER ti_bu BEFORE UPDATE ON t1 + FOR EACH ROW + SET @c = 1; + +CREATE DEFINER=a@'' VIEW v3 AS SELECT * FROM t1; + +CREATE DEFINER=a@'' PROCEDURE p3() + SELECT 3; + +CREATE DEFINER=a@'' FUNCTION f3() RETURNS INT + RETURN 3; + +# - check that empty host name is treated correctly; + +SHOW CREATE VIEW v3; + +SHOW CREATE PROCEDURE p3; + +SHOW CREATE FUNCTION f3; + +# Cleanup. + +DROP TRIGGER t1_bi; +DROP TRIGGER ti_ai; +DROP TRIGGER ti_bu; + +DROP VIEW v1; +DROP VIEW v2; +DROP VIEW v3; + +DROP TABLE t1; + +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP PROCEDURE p3; + +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP FUNCTION f3; diff --git a/mysql-test/t/skip_name_resolve.test b/mysql-test/t/skip_name_resolve.test index 02339ca14c5..3f732c8912b 100644 --- a/mysql-test/t/skip_name_resolve.test +++ b/mysql-test/t/skip_name_resolve.test @@ -8,3 +8,13 @@ REVOKE ALL ON test.* FROM mysqltest_1@'127.0.0.1/255.255.255.255'; DROP USER mysqltest_1@'127.0.0.1/255.255.255.255'; # End of 4.1 tests + +# Bug #13407 "Remote connecting crashes server". +# Server crashed when one used USER() function in connection for which +# was impossible to obtain peer hostname. +connect (con1, 127.0.0.1, root, , test, $MASTER_MYPORT, ); +--replace_column 1 # +select user(); +--replace_column 1 <id> 3 <host> 5 <command> 6 <time> 7 <state> 8 <info> +show processlist; +connection default; diff --git a/mysql-test/t/sp-big.test b/mysql-test/t/sp-big.test new file mode 100644 index 00000000000..90a3a79dd53 --- /dev/null +++ b/mysql-test/t/sp-big.test @@ -0,0 +1,85 @@ +# +# Bug #11602: SP with very large body not handled well +# + +--disable_warnings +drop procedure if exists test.longprocedure; +drop table if exists t1; +--enable_warnings + +create table t1 (a int); +insert into t1 values (1),(2),(3); + +let $body=`select repeat('select count(*) into out1 from t1;\n', 3072)`; + +delimiter //; +--disable_query_log +eval select length('$body') as length// +eval create procedure test.longprocedure (out out1 int) deterministic +begin + $body +end// +--enable_query_log + +delimiter ;// + +# this is larger than the length above, because it includes the 'begin' and +# 'end' bits and some whitespace +select length(routine_definition) from information_schema.routines where routine_schema = 'test' and routine_name = 'longprocedure'; + +call test.longprocedure(@value); select @value; + +drop procedure test.longprocedure; +drop table t1; +# +# Bug #9819 "Cursors: Mysql Server Crash while fetching from table with 5 +# million records.": +# To really test the bug, increase the number of loop iterations ($1). +# For 4 millions set $1 to 22. +create table t1 (f1 char(100) , f2 mediumint , f3 int , f4 real, f5 numeric); +insert into t1 (f1, f2, f3, f4, f5) values +("This is a test case for for Bug#9819", 1, 2, 3.0, 4.598); +create table t2 like t1; +let $1=8; +--disable_query_log +--disable_result_log +while ($1) +{ + eval insert into t1 select * from t1; + dec $1; +} +--enable_result_log +--enable_query_log +select count(*) from t1; +select count(*) from t2; +--disable_warnings +drop procedure if exists p1; +--enable_warnings +delimiter |; +create procedure p1() +begin + declare done integer default 0; + declare vf1 char(100) ; + declare vf2 mediumint; + declare vf3 int ; + declare vf4 real ; + declare vf5 numeric ; + declare cur1 cursor for select f1,f2,f3,f4,f5 from t1; + declare continue handler for sqlstate '02000' set done = 1; + open cur1; + while done <> 1 do + fetch cur1 into vf1, vf2, vf3, vf4, vf5; + if not done then + insert into t2 values (vf1, vf2, vf3, vf4, vf5); + end if; + end while; + close cur1; +end| +delimiter ;| +call p1(); +select count(*) from t1; +select count(*) from t2; +select f1 from t1 limit 1; +select f1 from t2 limit 1; +drop procedure p1; +drop table t1, t2; diff --git a/mysql-test/t/sp-code.test b/mysql-test/t/sp-code.test new file mode 100644 index 00000000000..72efa831059 --- /dev/null +++ b/mysql-test/t/sp-code.test @@ -0,0 +1,214 @@ +# +# Test the debugging feature "show procedure/function code <name>" +# + +-- source include/is_debug_build.inc + +--disable_warnings +drop procedure if exists empty; +drop procedure if exists code_sample; +--enable_warnings + +create procedure empty() +begin +end; +show procedure code empty; +drop procedure empty; + +create function almost_empty() + returns int + return 0; +show function code almost_empty; +drop function almost_empty; + +delimiter //; +create procedure code_sample(x int, out err int, out nulls int) +begin + declare count int default 0; + + set nulls = 0; + begin + declare c cursor for select name from t1; + declare exit handler for not found close c; + + open c; + loop + begin + declare n varchar(20); + declare continue handler for sqlexception set err=1; + + fetch c into n; + if isnull(n) then + set nulls = nulls + 1; + else + set count = count + 1; + update t2 set idx = count where name=n; + end if; + end; + end loop; + end; + select t.name, t.idx from t2 t order by idx asc; +end// +delimiter ;// +show procedure code code_sample; +drop procedure code_sample; + + +# +# BUG#15737: Stored procedure optimizer bug with LEAVE +# +# This is a much more extensive test case than is strictly needed, +# but it was kept as is for two reasons: +# - The bug occurs under some quite special circumstances, so it +# wasn't trivial to create a smaller test, +# - There's some value in having another more complex code sample +# in this test file. This might catch future code generation bugs +# that doesn't show in behaviour in any obvious way. + +--disable_warnings +drop procedure if exists sudoku_solve; +--enable_warnings + +delimiter //; +create procedure sudoku_solve(p_naive boolean, p_all boolean) + deterministic + modifies sql data +begin + drop temporary table if exists sudoku_work, sudoku_schedule; + + create temporary table sudoku_work + ( + row smallint not null, + col smallint not null, + dig smallint not null, + cnt smallint, + key using btree (cnt), + key using btree (row), + key using btree (col), + unique key using hash (row,col) + ); + + create temporary table sudoku_schedule + ( + idx int not null auto_increment primary key, + row smallint not null, + col smallint not null + ); + + call sudoku_init(); + + if p_naive then + update sudoku_work set cnt = 0 where dig = 0; + else + call sudoku_count(); + end if; + insert into sudoku_schedule (row,col) + select row,col from sudoku_work where cnt is not null order by cnt desc; + + begin + declare v_scounter bigint default 0; + declare v_i smallint default 1; + declare v_dig smallint; + declare v_schedmax smallint; + + select count(*) into v_schedmax from sudoku_schedule; + + more: + loop + begin + declare v_tcounter bigint default 0; + + sched: + while v_i <= v_schedmax do + begin + declare v_row, v_col smallint; + + select row,col into v_row,v_col from sudoku_schedule where v_i = idx; + + select dig into v_dig from sudoku_work + where v_row = row and v_col = col; + + case v_dig + when 0 then + set v_dig = 1; + update sudoku_work set dig = 1 + where v_row = row and v_col = col; + when 9 then + if v_i > 0 then + update sudoku_work set dig = 0 + where v_row = row and v_col = col; + set v_i = v_i - 1; + iterate sched; + else + select v_scounter as 'Solutions'; + leave more; + end if; + else + set v_dig = v_dig + 1; + update sudoku_work set dig = v_dig + where v_row = row and v_col = col; + end case; + + set v_tcounter = v_tcounter + 1; + if not sudoku_digit_ok(v_row, v_col, v_dig) then + iterate sched; + end if; + set v_i = v_i + 1; + end; + end while sched; + + select dig from sudoku_work; + select v_tcounter as 'Tests'; + set v_scounter = v_scounter + 1; + + if p_all and v_i > 0 then + set v_i = v_i - 1; + else + leave more; + end if; + end; + end loop more; + end; + + drop temporary table sudoku_work, sudoku_schedule; +end// +delimiter ;// + +# The interestings parts are where the code for the two "leave" are: +# ... +#| 26 | jump_if_not 30 (v_i@3 > 0) | +# ... +#| 30 | stmt 0 "select v_scounter as 'Solutions'" | +#| 31 | jump 45 | +# ... +#| 42 | jump_if_not 45 (p_all@1 and (v_i@3 > 0)) | +#| 43 | set v_i@3 (v_i@3 - 1) | +#| 44 | jump 14 | +#| 45 | stmt 9 "drop temporary table sudoku_work, sud..." | +#+-----+-----------------------------------------------------------------------+ +# The bug appeared at position 42 (with the wrong destination). +show procedure code sudoku_solve; + +drop procedure sudoku_solve; + + +# +# Bug#19207: Final parenthesis omitted for CREATE INDEX in Stored +# Procedure +# +# Wrong criteria was used to distinguish the case when there was no +# lookahead performed in the parser. Bug affected only statements +# ending in one-character token without any optional tail, like CREATE +# INDEX and CALL. +# +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +CREATE PROCEDURE p1() CREATE INDEX idx ON t1 (c1); +SHOW PROCEDURE CODE p1; + +DROP PROCEDURE p1; + + +--echo End of 5.0 tests. diff --git a/mysql-test/t/sp-destruct.test b/mysql-test/t/sp-destruct.test new file mode 100644 index 00000000000..4f5f1cdcb9b --- /dev/null +++ b/mysql-test/t/sp-destruct.test @@ -0,0 +1,136 @@ +# +# Destructive stored procedure tests +# +# We do horrible things to the mysql.proc table here, so any unexpected +# failures here might leave it in an undetermined state. +# +# In the case of trouble you might want to skip this. +# + +# We're using --system things that probably doesn't work on Windows. +--source include/not_windows.inc + +# Backup proc table +--system rm -rf $MYSQLTEST_VARDIR/master-data/mysql/backup +--system mkdir $MYSQLTEST_VARDIR/master-data/mysql/backup +--system cp $MYSQLTEST_VARDIR/master-data/mysql/proc.* $MYSQLTEST_VARDIR/master-data/mysql/backup/ + +use test; + +--disable_warnings +drop procedure if exists bug14233; +drop function if exists bug14233; +drop table if exists t1; +drop view if exists v1; +--enable_warnings + +create procedure bug14233() + set @x = 42; + +create function bug14233_f() returns int + return 42; + +create table t1 (id int); +create trigger t1_ai after insert on t1 for each row call bug14233(); + +# Unsupported tampering with the mysql.proc definition +alter table mysql.proc drop type; +--error ER_SP_PROC_TABLE_CORRUPT +call bug14233(); +--error ER_SP_PROC_TABLE_CORRUPT +create view v1 as select bug14233_f(); +--error ER_SP_PROC_TABLE_CORRUPT +insert into t1 values (0); + +flush table mysql.proc; + +# Thrashing the .frm file +--system echo 'saljdlfa' > $MYSQLTEST_VARDIR/master-data/mysql/proc.frm +--replace_result $MYSQLTEST_VARDIR . master-data// '' +--error ER_NOT_FORM_FILE +call bug14233(); +--replace_result $MYSQLTEST_VARDIR . master-data// '' +--error ER_NOT_FORM_FILE +create view v1 as select bug14233_f(); +--replace_result $MYSQLTEST_VARDIR . master-data// '' +--error ER_NOT_FORM_FILE +insert into t1 values (0); + + +flush table mysql.proc; + +# Drop the mysql.proc table +--system rm $MYSQLTEST_VARDIR/master-data/mysql/proc.* +--error ER_NO_SUCH_TABLE +call bug14233(); +--error ER_NO_SUCH_TABLE +create view v1 as select bug14233_f(); +--error ER_NO_SUCH_TABLE +insert into t1 values (0); + +# Restore mysql.proc +--system mv $MYSQLTEST_VARDIR/master-data/mysql/backup/* $MYSQLTEST_VARDIR/master-data/mysql/ +--system rmdir $MYSQLTEST_VARDIR/master-data/mysql/backup + +flush table mysql.proc; +flush privileges; + +delete from mysql.proc where name like 'bug14233%'; + +# Unsupported editing of mysql.proc, circumventing checks in "create ..." +insert into mysql.proc +( + db, name, type, specific_name, language, sql_data_access, is_deterministic, + security_type, param_list, returns, body, definer, created, modified, + sql_mode, comment +) +values +( + 'test', 'bug14233_1', 'FUNCTION', 'bug14233_1', 'SQL', 'READS_SQL_DATA', 'NO', + 'DEFINER', '', 'int(10)', + 'select count(*) from mysql.user', + 'root@localhost', NOW() , '0000-00-00 00:00:00', '', '' +), +( + 'test', 'bug14233_2', 'FUNCTION', 'bug14233_2', 'SQL', 'READS_SQL_DATA', 'NO', + 'DEFINER', '', 'int(10)', + 'begin declare x int; select count(*) into x from mysql.user; end', + 'root@localhost', NOW() , '0000-00-00 00:00:00', '', '' +), +( + 'test', 'bug14233_3', 'PROCEDURE', 'bug14233_3', 'SQL', 'READS_SQL_DATA','NO', + 'DEFINER', '', '', + 'alksj wpsj sa ^#!@ ', + 'root@localhost', NOW() , '0000-00-00 00:00:00', '', '' +); + +--error ER_SP_PROC_TABLE_CORRUPT +select bug14233_1(); +--error ER_SP_PROC_TABLE_CORRUPT +create view v1 as select bug14233_1(); + +--error ER_SP_PROC_TABLE_CORRUPT +select bug14233_2(); +--error ER_SP_PROC_TABLE_CORRUPT +create view v1 as select bug14233_2(); + +--error ER_SP_PROC_TABLE_CORRUPT +call bug14233_3(); +drop trigger t1_ai; +create trigger t1_ai after insert on t1 for each row call bug14233_3(); +--error ER_SP_PROC_TABLE_CORRUPT +insert into t1 values (0); + +# Clean-up +drop trigger t1_ai; +drop table t1; + +# +# BUG#16303: erroneus stored procedures and functions should be droppable +# +drop function bug14233_1; +drop function bug14233_2; +drop procedure bug14233_3; +# Assert: These should show nothing. +show procedure status; +show function status; diff --git a/mysql-test/t/sp-dynamic.test b/mysql-test/t/sp-dynamic.test new file mode 100644 index 00000000000..6546a5ab548 --- /dev/null +++ b/mysql-test/t/sp-dynamic.test @@ -0,0 +1,352 @@ +delimiter |; + +--disable_warnings +drop procedure if exists p1| +drop procedure if exists p2| +--enable_warnings + +###################################################################### +# Test Dynamic SQL in stored procedures. ############################# +###################################################################### +# +# A. Basics +# +create procedure p1() +begin + prepare stmt from "select 1"; + execute stmt; + execute stmt; + execute stmt; + deallocate prepare stmt; +end| +call p1()| +call p1()| +call p1()| +drop procedure p1| +# +# B. Recursion. Recusion is disabled in SP, and recursive use of PS is not +# possible as well. +# +create procedure p1() +begin + execute stmt; +end| +prepare stmt from "call p1()"| +# Allow SP resursion to be show that it has not influence here +set @SAVE_SP_RECURSION_LEVELS=@@max_sp_recursion_depth| +set @@max_sp_recursion_depth=100| +--error ER_PS_NO_RECURSION +execute stmt| +--error ER_PS_NO_RECURSION +execute stmt| +--error ER_PS_NO_RECURSION +execute stmt| +--error ER_PS_NO_RECURSION +call p1()| +--error ER_PS_NO_RECURSION +call p1()| +--error ER_PS_NO_RECURSION +call p1()| +set @@max_sp_recursion_depth=@SAVE_SP_RECURSION_LEVELS| +--error ER_SP_RECURSION_LIMIT +call p1()| +--error ER_SP_RECURSION_LIMIT +call p1()| +--error ER_SP_RECURSION_LIMIT +call p1()| + +drop procedure p1| +# +# C. Create/drop a stored procedure in Dynamic SQL. +# One cannot create stored procedure from a stored procedure because of +# the way MySQL SP cache works: it's important that this limitation is not +# possible to circumvent by means of Dynamic SQL. +# +create procedure p1() +begin + prepare stmt from "create procedure p2() begin select 1; end"; + execute stmt; + deallocate prepare stmt; +end| +--error ER_UNSUPPORTED_PS +call p1()| +--error ER_UNSUPPORTED_PS +call p1()| +drop procedure p1| +create procedure p1() +begin + prepare stmt from "drop procedure p2"; + execute stmt; + deallocate prepare stmt; +end| +--error ER_UNSUPPORTED_PS +call p1()| +--error ER_UNSUPPORTED_PS +call p1()| +drop procedure p1| +# +# D. Create/Drop a table (a DDL that issues a commit) in Dynamic SQL. +# (should work ok). +# +create procedure p1() +begin + prepare stmt_drop from "drop table if exists t1"; + execute stmt_drop; + prepare stmt from "create table t1 (a int)"; + execute stmt; + insert into t1 (a) values (1); + select * from t1; + deallocate prepare stmt; + deallocate prepare stmt_drop; +end| +call p1()| +call p1()| +drop procedure p1| +# +# A more real example (a case similar to submitted by 24/7). +# +create procedure p1() +begin + set @tab_name=concat("tab_", replace(curdate(), '-', '_')); + set @drop_sql=concat("drop table if exists ", @tab_name); + set @create_sql=concat("create table ", @tab_name, " (a int)"); + set @insert_sql=concat("insert into ", @tab_name, " values (1), (2), (3)"); + set @select_sql=concat("select * from ", @tab_name); + select @tab_name; + select @drop_sql; + select @create_sql; + select @insert_sql; + select @select_sql; + prepare stmt_drop from @drop_sql; + execute stmt_drop; + prepare stmt from @create_sql; + execute stmt; + prepare stmt from @insert_sql; + execute stmt; + prepare stmt from @select_sql; + execute stmt; + execute stmt_drop; + deallocate prepare stmt; + deallocate prepare stmt_drop; +end| +--disable_result_log +call p1()| +call p1()| +--enable_result_log +drop procedure p1| +# +# E. Calling a stored procedure with Dynamic SQL +# from a stored function (currently disabled). +# +create procedure p1() +begin + prepare stmt_drop from "drop table if exists t1"; + execute stmt_drop; + prepare stmt from "create table t1 (a int)"; + execute stmt; + deallocate prepare stmt; + deallocate prepare stmt_drop; +end| +--disable_warnings +drop function if exists f1| +--enable_warnings +create function f1(a int) returns int +begin + call p1(); + return 1; +end| + +# Every stored procedure that contains Dynamic SQL is marked as +# such. Stored procedures that contain Dynamic SQL are not +# allowed in a stored function or trigger, and here we get the +# corresponding error message. + +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +select f1(0)| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +select f1(f1(0))| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +select f1(f1(f1(0)))| +drop function f1| +drop procedure p1| +# +# F. Rollback and cleanup lists management in Dynamic SQL. +# +create procedure p1() +begin + drop table if exists t1; + create table t1 (id integer not null primary key, + name varchar(20) not null); + insert into t1 (id, name) values (1, 'aaa'), (2, 'bbb'), (3, 'ccc'); + prepare stmt from "select name from t1"; + execute stmt; + select name from t1; + execute stmt; + prepare stmt from + "select name from t1 where name=(select name from t1 where id=2)"; + execute stmt; + select name from t1 where name=(select name from t1 where id=2); + execute stmt; +end| +call p1()| +call p1()| +drop procedure p1| +# +# H. Executing a statement prepared externally in SP. +# +prepare stmt from "select * from t1"| +create procedure p1() +begin + execute stmt; + deallocate prepare stmt; +end| +call p1()| +--error ER_UNKNOWN_STMT_HANDLER +call p1()| +drop procedure p1| +# +# I. Use of an SP variable in Dynamic SQL is not possible and +# this limitation is necessary for correct binary logging: prepared +# statements do not substitute SP variables with their values for binlog, so +# SP variables must be not accessible in Dynamic SQL. +# +create procedure p1() +begin + declare a char(10); + set a="sp-variable"; + set @a="mysql-variable"; + prepare stmt from "select 'dynamic sql:', @a, a"; + execute stmt; +end| +--error ER_BAD_FIELD_ERROR +call p1()| +--error ER_BAD_FIELD_ERROR +call p1()| +drop procedure p1| +# +# J. Use of placeholders in Dynamic SQL. +# +create procedure p1() +begin + prepare stmt from 'select ? as a'; + execute stmt using @a; +end| +set @a=1| +call p1()| +call p1()| +drop procedure p1| +# +# K. Use of continue handlers with Dynamic SQL. +# +drop table if exists t1| +create table t1 (id integer primary key auto_increment, + stmt_text char(35), status varchar(20))| +insert into t1 (stmt_text) values + ("select 1"), ("flush tables"), ("handler t1 open as ha"), + ("analyze table t1"), ("check table t1"), ("checksum table t1"), + ("check table t1"), ("optimize table t1"), ("repair table t1"), + ("describe extended select * from t1"), + ("help help"), ("show databases"), ("show tables"), + ("show table status"), ("show open tables"), ("show storage engines"), + ("insert into t1 (id) values (1)"), ("update t1 set status=''"), + ("delete from t1"), ("truncate t1"), ("call p1()"), ("foo bar")| +create procedure p1() +begin + declare v_stmt_text varchar(255); + declare v_id integer; + declare done int default 0; + declare c cursor for select id, stmt_text from t1; + declare continue handler for 1295 -- ER_UNSUPPORTED_PS + set @status='not supported'; + declare continue handler for 1064 -- ER_SYNTAX_ERROR + set @status='syntax error'; + declare continue handler for sqlstate '02000' set done = 1; + + prepare update_stmt from "update t1 set status=? where id=?"; + open c; + repeat + if not done then + fetch c into v_id, v_stmt_text; + set @id=v_id, @stmt_text=v_stmt_text; + set @status="supported"; + prepare stmt from @stmt_text; + execute update_stmt using @status, @id; + end if; + until done end repeat; + deallocate prepare update_stmt; +end| +call p1()| +select * from t1| +drop procedure p1| +drop table t1| +# +# Bug#7115 "Prepared Statements: packet error if execution within stored +# procedure". +# +prepare stmt from 'select 1'| +create procedure p1() execute stmt| +call p1()| +call p1()| +drop procedure p1| +# +# Bug#10975 "Prepared statements: crash if function deallocates" +# Check that a prepared statement that is currently in use +# can't be deallocated. +# +# a) Prepared statements and stored procedure cache: +# +# TODO: add when the corresponding bug (Bug #12093 "SP not found on second +# PS execution if another thread drops other SP in between") is fixed. +# +# b) attempt to deallocate a prepared statement that is being executed +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function f1() returns int +begin + deallocate prepare stmt; + return 1; +end| + +# b)-2 a crash (#1) spotted by Sergey Petrunia during code review +create procedure p1() +begin + prepare stmt from 'select 1 A'; + execute stmt; +end| +prepare stmt from 'call p1()'| +--error ER_PS_NO_RECURSION +execute stmt| +--error ER_PS_NO_RECURSION +execute stmt| +drop procedure p1| + +# +# Bug#10605 "Stored procedure with multiple SQL prepared statements +# disconnects client" +# +--disable_warnings +drop table if exists t1, t2| +--enable_warnings +create procedure p1 (a int) language sql deterministic +begin + declare rsql varchar(100); + drop table if exists t1, t2; + set @rsql= "create table t1 (a int)"; + select @rsql; + prepare pst from @rsql; + execute pst; + set @rsql= null; + set @rsql= "create table t2 (a int)"; + select @rsql; + prepare pst from @rsql; + execute pst; + drop table if exists t1, t2; +end| +set @a:=0| +call p1(@a)| +select @a| +call p1(@a)| +select @a| +drop procedure if exists p1| + +# End of the test +delimiter ;| diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test new file mode 100644 index 00000000000..77bd5259eb5 --- /dev/null +++ b/mysql-test/t/sp-error.test @@ -0,0 +1,1817 @@ +# +# Stored PROCEDURE error tests +# + +--disable_warnings +drop table if exists t1, t2; +--enable_warnings + +# Make sure we don't have any procedures left. +delete from mysql.proc; + +delimiter |; + +# This should give three syntax errors (sometimes crashed; bug #643) +# (Unfortunately, this is not a 100% test, on some platforms this +# passed despite the bug.) +--error 1064 +create procedure syntaxerror(t int)| +--error 1064 +create procedure syntaxerror(t int)| +--error 1064 +create procedure syntaxerror(t int)| + +# Check that we get the right error, i.e. UDF declaration parses correctly, +# but foo.so doesn't exist. +# This generates an error message containing a misleading errno which +# might vary between systems (it usually doesn't have anything to do with +# the actual failing dlopen()). +#--error 1126 +#create function foo returns real soname "foo.so"| + + +--disable_warnings +drop table if exists t3| +--enable_warnings +create table t3 ( x int )| +insert into t3 values (2), (3)| + +create procedure bad_into(out param int) + select x from t3 into param| + +--error 1172 +call bad_into(@x)| + +drop procedure bad_into| +drop table t3| + + +create procedure proc1() + set @x = 42| + +create function func1() returns int + return 42| + +# Can't create recursively +--error 1303 +create procedure foo() + create procedure bar() set @x=3| +--error 1303 +create procedure foo() + create function bar() returns double return 2.3| + +# Already exists +--error 1304 +create procedure proc1() + set @x = 42| +--error 1304 +create function func1() returns int + return 42| + +drop procedure proc1| +drop function func1| + +# Does not exist +--error 1305 +alter procedure foo| +--error 1305 +alter function foo| +--error 1305 +drop procedure foo| +--error 1305 +drop function foo| +--error 1305 +call foo()| +drop procedure if exists foo| +--error 1305 +show create procedure foo| +--error 1305 +show create function foo| + +# LEAVE/ITERATE with no match +--error 1308 +create procedure foo() +foo: loop + leave bar; +end loop| +--error 1308 +create procedure foo() +foo: loop + iterate bar; +end loop| +--error 1308 +create procedure foo() +foo: begin + iterate foo; +end| + +# Redefining label +--error 1309 +create procedure foo() +foo: loop + foo: loop + set @x=2; + end loop foo; +end loop foo| + +# End label mismatch +--error 1310 +create procedure foo() +foo: loop + set @x=2; +end loop bar| + +# RETURN in FUNCTION only +--error 1313 +create procedure foo() + return 42| + +# Wrong number of arguments +create procedure p(x int) + set @x = x| +create function f(x int) returns int + return x+42| + +--error 1318 +call p()| +--error 1318 +call p(1, 2)| +--error 1318 +select f()| +--error 1318 +select f(1, 2)| + +drop procedure p| +drop function f| + +--error 1319 +create procedure p(val int, out res int) +begin + declare x int default 0; + declare continue handler for foo set x = 1; + + insert into test.t1 values (val); + if (x) then + set res = 0; + else + set res = 1; + end if; +end| + +--error 1319 +create procedure p(val int, out res int) +begin + declare x int default 0; + declare foo condition for 1146; + declare continue handler for bar set x = 1; + + insert into test.t1 values (val); + if (x) then + set res = 0; + else + set res = 1; + end if; +end| + +--error 1320 +create function f(val int) returns int +begin + declare x int; + + set x = val+3; +end| + +create function f(val int) returns int +begin + declare x int; + + set x = val+3; + if x < 4 then + return x; + end if; +end| + +--error 1321 +select f(10)| + +drop function f| + +--error 1322 +create procedure p() +begin + declare c cursor for insert into test.t1 values ("foo", 42); + + open c; + close c; +end| + +--error 1323 +create procedure p() +begin + declare x int; + declare c cursor for select * into x from test.t limit 1; + + open c; + close c; +end| + +--error 1324 +create procedure p() +begin + declare c cursor for select * from test.t; + + open cc; + close c; +end| + +--disable_warnings +drop table if exists t1| +--enable_warnings +create table t1 (val int)| + +create procedure p() +begin + declare c cursor for select * from test.t1; + + open c; + open c; + close c; +end| +--error 1325 +call p()| +drop procedure p| + +create procedure p() +begin + declare c cursor for select * from test.t1; + + open c; + close c; + close c; +end| +--error 1326 +call p()| +drop procedure p| + +--error 1305 +alter procedure bar3 sql security invoker| + +drop table t1| + +--disable_warnings +drop table if exists t1| +--enable_warnings +create table t1 (val int, x float)| +insert into t1 values (42, 3.1), (19, 1.2)| + +--error 1327 +create procedure p() +begin + declare x int; + declare c cursor for select * from t1; + + open c; + fetch c into x, y; + close c; +end| + +create procedure p() +begin + declare x int; + declare c cursor for select * from t1; + + open c; + fetch c into x; + close c; +end| +--error 1328 +call p()| +drop procedure p| + +create procedure p() +begin + declare x int; + declare y float; + declare z int; + declare c cursor for select * from t1; + + open c; + fetch c into x, y, z; + close c; +end| +--error 1328 +call p()| +drop procedure p| + +--error 1330 +create procedure p(in x int, x char(10)) +begin +end| +--error 1330 +create function p(x int, x char(10)) +begin +end| + +--error 1331 +create procedure p() +begin + declare x float; + declare x int; +end| + +--error 1332 +create procedure p() +begin + declare c condition for 1064; + declare c condition for 1065; +end| + +--error 1333 +create procedure p() +begin + declare c cursor for select * from t1; + declare c cursor for select field from t1; +end| + +# USE is not allowed +--error ER_SP_BADSTATEMENT +create procedure u() + use sptmp| + +# Enforced standard order of declarations +--error 1337 +create procedure p() +begin + declare c cursor for select * from t1; + declare x int; +end| +--error 1337 +create procedure p() +begin + declare x int; + declare continue handler for sqlstate '42S99' set x = 1; + declare foo condition for sqlstate '42S99'; +end| + +--error 1338 +create procedure p() +begin + declare x int; + declare continue handler for sqlstate '42S99' set x = 1; + declare c cursor for select * from t1; +end| + +# Check in and inout arguments. +--disable_warnings +drop procedure if exists p| +--enable_warnings +create procedure p(in x int, inout y int, out z int) +begin + set y = x+y; + set z = x+y; +end| + +set @tmp_x = 42| +set @tmp_y = 3| +set @tmp_z = 0| +# For reference: this is ok +call p(@tmp_x, @tmp_y, @tmp_z)| +select @tmp_x, @tmp_y, @tmp_z| + +--error ER_SP_NOT_VAR_ARG +call p(42, 43, @tmp_z)| +--error ER_SP_NOT_VAR_ARG +call p(42, @tmp_y, 43)| + +drop procedure p| + + +# +# Let us test that we can access mysql.proc table for routines +# definitions lookup without locking it explicitly. +# +create procedure p() begin end| +lock table t1 read| +# This should succeed +call p()| +unlock tables| +drop procedure p| +# Let us check restrictions which this ability puts on mysql.proc locking. +--error ER_WRONG_LOCK_OF_SYSTEM_TABLE +lock tables t1 read, mysql.proc write| +--error ER_WRONG_LOCK_OF_SYSTEM_TABLE +lock tables mysql.proc write, mysql.user write| +# Locking for read should be OK +lock tables t1 read, mysql.proc read| +unlock tables| +# You also should be able lock only mysql.proc for write +lock tables mysql.proc write| +unlock tables| + + +# +# Check that in functions we don't allow to update tables which +# are used by statements which invoke these functions. +# +--disable_warnings +drop function if exists f1| +--enable_warnings +create function f1(i int) returns int +begin + insert into t1 (val) values (i); + return 0; +end| +--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG +select val, f1(val) from t1| +# Table alias should not matter +--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG +select val, f1(val) from t1 as tab| +select * from t1| +--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG +update t1 set val= f1(val)| +select * from t1| +# But this should be OK +select f1(17)| +select * from t1| +# Cleanup +delete from t1 where val= 17| +drop function f1| + + +# +# BUG#1965 +# +create procedure bug1965() +begin + declare c cursor for select val from t1 order by valname; + open c; + close c; +end| + +--error 1054 +call bug1965()| +drop procedure bug1965| + +# +# BUG#1966 +# +--error 1327 +select 1 into a| + +# +# BUG#1653 +# +--disable_warnings +drop table if exists t3| +--enable_warnings +create table t3 (column_1_0 int)| + +create procedure bug1653() + update t3 set column_1 = 0| + +--error 1054 +call bug1653()| +drop table t3| +create table t3 (column_1 int)| +call bug1653()| + +drop procedure bug1653| +drop table t3| + +# +# BUG#2259 +# +# Note: When this bug existed, it did not necessarily cause a crash +# in all builds, but valgrind did give warnings. +create procedure bug2259() +begin + declare v1 int; + declare c1 cursor for select s1 from t1; + + fetch c1 into v1; +end| + +--error 1326 +call bug2259()| +drop procedure bug2259| + +# +# BUG#2272 +# +create procedure bug2272() +begin + declare v int; + + update t1 set v = 42; +end| + +insert into t1 values (666, 51.3)| +--error 1054 +call bug2272()| +delete from t1| +drop procedure bug2272| + +# +# BUG#2329 +# +create procedure bug2329_1() +begin + declare v int; + + insert into t1 (v) values (5); +end| + +create procedure bug2329_2() +begin + declare v int; + + replace t1 set v = 5; +end| + +--error 1054 +call bug2329_1()| +--error 1054 +call bug2329_2()| +drop procedure bug2329_1| +drop procedure bug2329_2| + +# +# BUG#3287 +# +create function bug3287() returns int +begin + declare v int default null; + + case + when v is not null then return 1; + end case; + return 2; +end| +--error 1339 +select bug3287()| +drop function bug3287| + +create procedure bug3287(x int) +case x +when 0 then + insert into test.t1 values (x, 0.1); +when 1 then + insert into test.t1 values (x, 1.1); +end case| +--error 1339 +call bug3287(2)| +drop procedure bug3287| + +# +# BUG#3297 +# +--disable_warnings +drop table if exists t3| +--enable_warnings +create table t3 (s1 int, primary key (s1))| +insert into t3 values (5),(6)| + +create procedure bug3279(out y int) +begin + declare x int default 0; + begin + declare exit handler for sqlexception set x = x+1; + insert into t3 values (5); + end; + if x < 2 then + set x = x+1; + insert into t3 values (6); + end if; + set y = x; +end| + +set @x = 0| +--error 1062 +call bug3279(@x)| +select @x| +drop procedure bug3279| +drop table t3| + +# +# BUG#3339 +# +--error 1049 +create procedure nodb.bug3339() begin end| + +# +# BUG#2653 +# +create procedure bug2653_1(a int, out b int) + set b = aa| + +create procedure bug2653_2(a int, out b int) +begin + if aa < 0 then + set b = - a; + else + set b = a; + end if; +end| + +--error 1054 +call bug2653_1(1, @b)| +--error 1054 +call bug2653_2(2, @b)| + +drop procedure bug2653_1| +drop procedure bug2653_2| + +# +# BUG#4344 +# +--error 1357 +create procedure bug4344() drop procedure bug4344| +--error 1357 +create procedure bug4344() drop function bug4344| + +# +# BUG#3294: Stored procedure crash if table dropped before use +# (Actually, when an error occurs within an error handler.) +--disable_warnings +drop procedure if exists bug3294| +--enable_warnings +create procedure bug3294() +begin + declare continue handler for sqlexception drop table t5; + drop table t5; + drop table t5; +end| + +create table t5 (x int)| +--error 1051 +call bug3294()| +drop procedure bug3294| + +# +# BUG#876: Stored Procedures: Invalid SQLSTATE is allowed in +# a DECLARE ? HANDLER FOR stmt. +# +--disable_warnings +drop procedure if exists bug8776_1| +drop procedure if exists bug8776_2| +drop procedure if exists bug8776_3| +drop procedure if exists bug8776_4| +--enable_warnings +--error ER_SP_BAD_SQLSTATE +create procedure bug8776_1() +begin + declare continue handler for sqlstate '42S0200test' begin end; + begin end; +end| + +--error ER_SP_BAD_SQLSTATE +create procedure bug8776_2() +begin + declare continue handler for sqlstate '4200' begin end; + begin end; +end| + +--error ER_SP_BAD_SQLSTATE +create procedure bug8776_3() +begin + declare continue handler for sqlstate '420000' begin end; + begin end; +end| + +--error ER_SP_BAD_SQLSTATE +create procedure bug8776_4() +begin + declare continue handler for sqlstate '42x00' begin end; + begin end; +end| + + +# +# BUG#6600: Stored procedure crash after repeated calls with check table +# +--error ER_SP_BADSTATEMENT +create procedure bug6600() + check table t1| + +# Check these two as well, while we're at it. (Although it isn't really +# related to the bug report, but to the fix.) +--error ER_SP_BADSTATEMENT +create procedure bug6600() + lock table t1 read| +--error ER_SP_BADSTATEMENT +create procedure bug6600() + unlock table t1| + +# +# BUG#9566: explicit LOCK TABLE and store procedures result in illegal state +# +# We should not think that mysql.proc table does not exist if we are unable +# to open it under LOCK TABLE or in prelocked mode. +# +--disable_warnings +drop procedure if exists bug9566| +--enable_warnings +create procedure bug9566() +begin + select * from t1; +end| +lock table t1 read| +# This should fail since we forgot to lock mysql.proc for writing +# explicitly, and we can't open mysql.proc for _writing_ if there +# are locked tables. +--error 1100 +alter procedure bug9566 comment 'Some comment'| +unlock tables| +# This should succeed +drop procedure bug9566| + + +# +# BUG#7299: Stored procedures: exception handler catches not-found conditions +# +--disable_warnings +drop procedure if exists bug7299| +--enable_warnings +create procedure bug7299() +begin + declare v int; + declare c cursor for select val from t1; + declare exit handler for sqlexception select 'Error!'; + + open c; + fetch c into v; +end| + +delete from t1| +--error ER_SP_FETCH_NO_DATA +call bug7299()| +drop procedure bug7299| + + +# +# BUG#9073: Able to declare two handlers for same condition in same scope +# +--error ER_SP_DUP_HANDLER +create procedure bug9073() +begin + declare continue handler for sqlexception select 1; + declare continue handler for sqlexception select 2; +end| +--error ER_SP_DUP_HANDLER +create procedure bug9073() +begin + declare condname1 condition for 1234; + declare continue handler for condname1 select 1; + declare exit handler for condname1 select 2; +end| +--error ER_SP_DUP_HANDLER +create procedure bug9073() +begin + declare condname1 condition for sqlstate '42000'; + declare condname2 condition for sqlstate '42000'; + declare exit handler for condname1 select 1; + declare continue handler for condname2 select 2; +end| +--error ER_SP_DUP_HANDLER +create procedure bug9073() +begin + declare condname1 condition for sqlstate '42000'; + declare exit handler for condname1 select 1; + declare exit handler for sqlstate '42000' select 2; +end| + +# This should still work. +--disable_warnings +drop procedure if exists bug9073| +--enable_warnings +create procedure bug9073() +begin + declare condname1 condition for sqlstate '42000'; + declare continue handler for condname1 select 1; + begin + declare exit handler for sqlstate '42000' select 2; + begin + declare continue handler for sqlstate '42000' select 3; + end; + end; +end| +drop procedure bug9073| + + +# +# BUG#7047: Stored procedure crash if alter procedure +# +--error ER_SP_NO_DROP_SP +create procedure bug7047() + alter procedure bug7047| +--error ER_SP_NO_DROP_SP +create function bug7047() returns int +begin + alter function bug7047; + return 0; +end| + + +# +# BUG#8408: Stored procedure crash if function contains SHOW +# BUG#9058: Stored Procedures: Crash if function included SELECT +# + +# Some things are caught when parsing +--error ER_SP_NO_RETSET +create function bug8408() returns int +begin + select * from t1; + return 0; +end| +--error ER_SP_NO_RETSET +create function bug8408() returns int +begin + show warnings; + return 0; +end| +--error ER_SP_NO_RETSET +create function bug8408(a int) returns int +begin + declare b int; + select b; + return b; +end| + +--disable_warnings +drop function if exists bug8408_f| +drop procedure if exists bug8408_p| +--enable_warnings + +# Some things must be caught at invokation time +create function bug8408_f() returns int +begin + call bug8408_p(); + return 0; +end| +create procedure bug8408_p() + select * from t1| + +call bug8408_p()| +--error ER_SP_NO_RETSET +select bug8408_f()| + +drop procedure bug8408_p| +drop function bug8408_f| + +# But this is ok +create function bug8408() returns int +begin + declare n int default 0; + select count(*) into n from t1; + return n; +end| + +insert into t1 value (2, 2.7), (3, 3.14), (7, 7.0)| +select *,bug8408() from t1| + +drop function bug8408| +delete from t1| + + +# +# BUG#10537: Server crashes while loading data file into table through +# procedure. +# Disable load until it's PS and SP safe +--disable_warnings +drop procedure if exists bug10537| +--enable_warnings +--error ER_SP_BADSTATEMENT +create procedure bug10537() + load data local infile '/tmp/somefile' into table t1| + + +# +# BUG#8409: Stored procedure crash if function contains FLUSH +# +--disable_warnings +drop function if exists bug8409| +--enable_warnings +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() + returns int +begin + flush tables; + return 5; +end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin reset query cache; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin reset master; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin reset slave; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin flush hosts; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin flush privileges; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin flush tables with read lock; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin flush tables; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin flush logs; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin flush status; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin flush slave; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin flush master; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin flush des_key_file; +return 1; end| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create function bug8409() returns int begin flush user_resources; +return 1; end| + + +# +# BUG#9529: Stored Procedures: No Warning on truncation of procedure name +# during creation. +# BUG#17015: Routine name truncation not an error +# When we started using utf8 for mysql.proc, this limit appeared +# to be higher, but in reality the names were truncated. +--error ER_TOO_LONG_IDENT +create procedure bug9529_901234567890123456789012345678901234567890123456789012345() +begin +end| + +--disable_warnings +drop procedure if exists bug17015_0123456789012345678901234567890123456789012345678901234| +--enable_warnings +# Check the upper limit, just to make sure. +create procedure bug17015_0123456789012345678901234567890123456789012345678901234() +begin +end| + +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like 'bug17015%'| +drop procedure bug17015_0123456789012345678901234567890123456789012345678901234| + + +# +# BUG#10969: Stored procedures: crash if default() function +# +--disable_warnings +drop procedure if exists bug10969| +--enable_warnings +--error ER_WRONG_COLUMN_NAME +create procedure bug10969() +begin + declare s1 int default 0; + select default(s1) from t30; +end| + +# This should work +create procedure bug10969() +begin + declare s1 int default 0; + select default(t30.s1) from t30; +end| + +drop procedure bug10969| + + +drop table t1| + +delimiter ;| + +# BUG#9814: Closing a cursor that is not open +create table t1(f1 int); +create table t2(f1 int); + +delimiter |; +CREATE PROCEDURE SP001() +P1: BEGIN + DECLARE ENDTABLE INT DEFAULT 0; + DECLARE TEMP_NUM INT; + DECLARE TEMP_SUM INT; + DECLARE C1 CURSOR FOR SELECT F1 FROM t1; + DECLARE C2 CURSOR FOR SELECT F1 FROM t2; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET ENDTABLE = 1; + + SET ENDTABLE=0; + SET TEMP_SUM=0; + SET TEMP_NUM=0; + + OPEN C1; + + FETCH C1 INTO TEMP_NUM; + WHILE ENDTABLE = 0 DO + SET TEMP_SUM=TEMP_NUM+TEMP_SUM; + FETCH C1 INTO TEMP_NUM; + END WHILE; + SELECT TEMP_SUM; + CLOSE C1; + CLOSE C1; + SELECT 'end of proc'; +END P1| +delimiter ;| +--error 1326 +call SP001(); +drop procedure SP001; +drop table t1, t2; + +# Bug #11394 "Recursion in SP crash server" and bug #11600 "Stored +# procedures: crash with function calling itself". +# We have to disable recursion since in many cases LEX and many +# Item's can't be used in reentrant way nowdays. +delimiter |; +--disable_warnings +drop function if exists bug11394| +drop function if exists bug11394_1| +drop function if exists bug11394_2| +drop procedure if exists bug11394| +--enable_warnings +create function bug11394(i int) returns int +begin + if i <= 0 then + return 0; + else + return (i in (100, 200, bug11394(i-1), 400)); + end if; +end| +# If we allow recursive functions without additional modifications +# this will crash server since Item for "IN" is not reenterable. +--error 1424 +select bug11394(2)| +drop function bug11394| +create function bug11394_1(i int) returns int +begin + if i <= 0 then + return 0; + else + return (select bug11394_1(i-1)); + end if; +end| +# The following statement will crash because some LEX members responsible +# for selects cannot be used in reentrant fashion. +--error 1424 +select bug11394_1(2)| +drop function bug11394_1| +# Note that the following should be allowed since it does not contains +# recursion +create function bug11394_2(i int) returns int return i| +select bug11394_2(bug11394_2(10))| +drop function bug11394_2| +create procedure bug11394(i int, j int) +begin + if i > 0 then + call bug11394(i - 1,(select 1)); + end if; +end| +--error ER_SP_RECURSION_LIMIT +call bug11394(2, 1)| +set @@max_sp_recursion_depth=10| +call bug11394(2, 1)| +set @@max_sp_recursion_depth=default| +drop procedure bug11394| +delimiter ;| + + +# +# BUG 12490 (Packets out of order if calling HELP CONTENTS from Stored Procedure) +# +--error 1314 +CREATE PROCEDURE BUG_12490() HELP CONTENTS; +--error 1314 +CREATE FUNCTION BUG_12490() RETURNS INT HELP CONTENTS; +CREATE TABLE t_bug_12490(a int); +--error 1314 +CREATE TRIGGER BUG_12490 BEFORE UPDATE ON t_bug_12490 FOR EACH ROW HELP CONTENTS; +DROP TABLE t_bug_12490; + +# +# Bug#11834 "Re-execution of prepared statement with dropped function +# crashes server". Also tests handling of prepared stmts which use +# stored functions but does not require prelocking. +# +--disable_warnings +drop function if exists bug11834_1; +drop function if exists bug11834_2; +--enable_warnings +create function bug11834_1() returns int return 10; +create function bug11834_2() returns int return bug11834_1(); +prepare stmt from "select bug11834_2()"; +execute stmt; +# Re-execution of statement should not crash server. +execute stmt; +drop function bug11834_1; +# Attempt to execute statement should return proper error and +# should not crash server. +--error ER_SP_DOES_NOT_EXIST +execute stmt; +deallocate prepare stmt; +drop function bug11834_2; + +# +# Bug#12953 "Stored procedures: crash if OPTIMIZE TABLE in function" +# +delimiter |; +--disable_warnings +DROP FUNCTION IF EXISTS bug12953| +--enable_warnings +--error ER_SP_NO_RETSET +CREATE FUNCTION bug12953() RETURNS INT +BEGIN + OPTIMIZE TABLE t1; + RETURN 1; +END| +delimiter ;| + +# +# Bug##12995 "Inside function "Table 't4' was not locked with LOCK TABLES" +# +delimiter |; +--disable_warnings +DROP FUNCTION IF EXISTS bug12995| +--enable_warnings +--error ER_SP_BADSTATEMENT +CREATE FUNCTION bug12995() RETURNS INT +BEGIN + HANDLER t1 OPEN; + RETURN 1; +END| +--error ER_SP_BADSTATEMENT +CREATE FUNCTION bug12995() RETURNS INT +BEGIN + HANDLER t1 READ FIRST; + RETURN 1; +END| +--error ER_SP_BADSTATEMENT +CREATE FUNCTION bug12995() RETURNS INT +BEGIN + HANDLER t1 CLOSE; + RETURN 1; +END| +--error 1305 +SELECT bug12995()| +delimiter ;| + + +# +# BUG#12712: SET AUTOCOMMIT should fail within SP/functions/triggers +# +--disable_warnings +drop procedure if exists bug12712; +drop function if exists bug12712; +--enable_warnings +# Can... +create procedure bug12712() + set session autocommit = 0; + +select @@autocommit; +set @au = @@autocommit; +call bug12712(); +select @@autocommit; +set session autocommit = @au; + +delimiter |; +create function bug12712() + returns int +begin + call bug12712(); + return 0; +end| + +# Can't... +--error ER_SP_CANT_SET_AUTOCOMMIT +set @x = bug12712()| +drop procedure bug12712| +drop function bug12712| +--error ER_SP_CANT_SET_AUTOCOMMIT +create function bug12712() + returns int +begin + set session autocommit = 0; + return 0; +end| +--error ER_SP_CANT_SET_AUTOCOMMIT +create function bug12712() + returns int +begin + set @@autocommit = 0; + return 0; +end| +--error ER_SP_CANT_SET_AUTOCOMMIT +create function bug12712() + returns int +begin + set local autocommit = 0; + return 0; +end| +delimiter ;| +--error ER_SP_CANT_SET_AUTOCOMMIT +create trigger bug12712 + before insert on t1 for each row set session autocommit = 0; + +# +# BUG#9367: Stored procedures: client hang after "show warnings" +# +--disable_parsing +--disable_warnings +drop procedure if exists bug9367; +--enable_warnings +create table t1 (s1 int); +select s1 from t1; +delimiter |; +create procedure bug9367() +begin + declare v int; + declare c cursor for select s1 from t1; + open c; + show warnings; + fetch c into v; + select v; +end| +delimiter ;| +call bug9367(); +drop procedure bug9367; +drop table t1; +--enable_parsing + +# +# BUG#13510: Setting password local variable changes current password +# +delimiter |; +--disable_warnings +drop procedure if exists bug13510_1| +drop procedure if exists bug13510_2| +drop procedure if exists bug13510_3| +drop procedure if exists bug13510_4| +--enable_warnings + +--error ER_SP_BAD_VAR_SHADOW +create procedure bug13510_1() +begin + declare password varchar(10); + + set password = 'foo1'; + select password; +end| + +# Check that an error message is sent +--error ER_PARSE_ERROR +set names='foo2'| + +--error ER_SP_BAD_VAR_SHADOW +create procedure bug13510_2() +begin + declare names varchar(10); + + set names = 'foo2'; + select names; +end| + +create procedure bug13510_3() +begin + declare password varchar(10); + + set `password` = 'foo3'; + select password; +end| + +create procedure bug13510_4() +begin + declare names varchar(10); + + set `names` = 'foo4'; + select names; +end| + +call bug13510_3()| +call bug13510_4()| + +drop procedure bug13510_3| +drop procedure bug13510_4| + + +# +# Test that statements which implicitly commit transaction are prohibited +# in stored function and triggers. Attempt to create function or trigger +# containing such statement should produce error (includes test for +# bug #13627). +# +--disable_warnings +drop function if exists bug_13627_f| +--enable_warnings + +CREATE TABLE t1 (a int)| +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN DROP TRIGGER test1; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN DROP TRIGGER test1; return 1; END | + +-- error ER_SP_BADSTATEMENT +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN load table t1 from master; END | +-- error ER_SP_BADSTATEMENT +CREATE FUNCTION bug_13627_f() returns int BEGIN load table t1 from master; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create table t2 (a int); END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN create table t2 (a int); return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create index t1_i on t1 (a); END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN create index t1_i on t1 (a); return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN alter table t1 add column b int; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN alter table t1 add column b int; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN rename table t1 to t2; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN rename table t1 to t2; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN truncate table t1; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN truncate table t1; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop table t1; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN drop table t1; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop index t1_i on t1; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN drop index t1_i on t1; return 1; END | + +-- error ER_SP_BADSTATEMENT +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN unlock tables; END | +-- error ER_SP_BADSTATEMENT +CREATE FUNCTION bug_13627_f() returns int BEGIN unlock tables; return 1; END | + +-- error ER_SP_BADSTATEMENT +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN LOCK TABLE t1 READ; END | +-- error ER_SP_BADSTATEMENT +CREATE FUNCTION bug_13627_f() returns int BEGIN LOCK TABLE t1 READ; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create database mysqltest; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN create database mysqltest; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop database mysqltest; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN drop database mysqltest; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create user 'mysqltest_1'; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN create user 'mysqltest_1'; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop user 'mysqltest_1'; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN drop user 'mysqltest_1'; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN rename user 'mysqltest_2' to 'mysqltest_1'; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN rename user 'mysqltest_2' to 'mysqltest_1'; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create view v1 as select 1; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN create view v1 as select 1; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN alter view v1 as select 1; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN alter view v1 as select 1; return 1; END | + +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop view v1; END | +-- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION bug_13627_f() returns int BEGIN drop view v1; return 1; END | + +-- error ER_SP_NO_RECURSIVE_CREATE +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create trigger tr2 before insert on t1 for each row do select 1; END | +-- error ER_SP_NO_RECURSIVE_CREATE +CREATE FUNCTION bug_13627_f() returns int BEGIN create trigger tr2 before insert on t1 for each row do select 1; return 1; END | + +-- error ER_SP_NO_DROP_SP +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop function bug_13627_f; END | +-- error ER_SP_NO_DROP_SP +CREATE FUNCTION bug_13627_f() returns int BEGIN drop function bug_13627_f; return 1; END | + +-- error ER_SP_NO_RECURSIVE_CREATE +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create function f2 () returns int return 1; END | +-- error ER_SP_NO_RECURSIVE_CREATE +CREATE FUNCTION bug_13627_f() returns int BEGIN create function f2 () returns int return 1; return 1; END | + +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW + BEGIN + CREATE TEMPORARY TABLE t2 (a int); + DROP TEMPORARY TABLE t2; + END | +CREATE FUNCTION bug_13627_f() returns int + BEGIN + CREATE TEMPORARY TABLE t2 (a int); + DROP TEMPORARY TABLE t2; + return 1; + END | + +drop table t1| +drop function bug_13627_f| + +delimiter ;| + +# BUG#12329: "Bogus error msg when executing PS with stored procedure after +# SP was re-created". See also test for related bug#13399 in trigger.test +drop function if exists bug12329; +--enable_warnings +create table t1 as select 1 a; +create table t2 as select 1 a; +create function bug12329() returns int return (select a from t1); +prepare stmt1 from 'select bug12329()'; +execute stmt1; +drop function bug12329; +create function bug12329() returns int return (select a+100 from t2); +select bug12329(); +# Until we implement proper mechanism for invalidation of PS/SP when table +# or SP's are changed the following statement will fail with 'Table ... was +# not locked' error (this mechanism should be based on the new TDC). +--error 1100 +execute stmt1; +deallocate prepare stmt1; +drop function bug12329; +drop table t1, t2; + +# +# Bug#13514 "server crash when create a stored procedure before choose a +# database" and +# Bug#13587 "Server crash when SP is created without database +# selected" +# +create database mysqltest1; +use mysqltest1; +drop database mysqltest1; +--error ER_NO_DB_ERROR +create function f1() returns int return 1; +delimiter |; +--error ER_NO_DB_ERROR +create procedure p1(out param1 int) +begin + select count(*) into param1 from t3; +end| +delimiter ;| +use test; + + +# +# BUG#13037: undefined variable in IF cause erroneous error-message +# + +--disable_warnings +DROP PROCEDURE IF EXISTS bug13037_p1; +DROP PROCEDURE IF EXISTS bug13037_p2; +DROP PROCEDURE IF EXISTS bug13037_p3; +--enable_warnings + +delimiter |; + +CREATE PROCEDURE bug13037_p1() +BEGIN + IF bug13037_foo THEN + SELECT 1; + END IF; +END| + +CREATE PROCEDURE bug13037_p2() +BEGIN + SET @bug13037_foo = bug13037_bar; +END| + +CREATE PROCEDURE bug13037_p3() +BEGIN + SELECT bug13037_foo; +END| + +delimiter ;| + +--echo + +--error 1054 +CALL bug13037_p1(); +--error 1054 +CALL bug13037_p2(); +--error 1054 +CALL bug13037_p3(); + +--error 1054 +CALL bug13037_p1(); +--error 1054 +CALL bug13037_p2(); +--error 1054 +CALL bug13037_p3(); + +DROP PROCEDURE bug13037_p1; +DROP PROCEDURE bug13037_p2; +DROP PROCEDURE bug13037_p3; + +# +# Bug#14569 "editing a stored procedure kills mysqld-nt" +# +create database mysqltest1; +create database mysqltest2; +use mysqltest1; +drop database mysqltest1; +create procedure mysqltest2.p1() select version(); +--error ER_NO_DB_ERROR +create procedure p2() select version(); +use mysqltest2; +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status; +drop database mysqltest2; +use test; + +# +# Bug#13012 "SP: REPAIR/BACKUP/RESTORE TABLE crashes the server" +# +delimiter |; +--disable_warnings +DROP FUNCTION IF EXISTS bug13012| +--enable_warnings +--error ER_SP_NO_RETSET +CREATE FUNCTION bug13012() RETURNS INT +BEGIN + REPAIR TABLE t1; + RETURN 1; +END| +--error ER_SP_NO_RETSET +CREATE FUNCTION bug13012() RETURNS INT +BEGIN + BACKUP TABLE t1 TO '/tmp'; + RETURN 1; +END| +--error ER_SP_NO_RETSET +CREATE FUNCTION bug13012() RETURNS INT +BEGIN + RESTORE TABLE t1 FROM '/tmp'; + RETURN 1; +END| +create table t1 (a int)| +CREATE PROCEDURE bug13012_1() REPAIR TABLE t1| +CREATE FUNCTION bug13012_2() RETURNS INT +BEGIN + CALL bug13012_1(); + RETURN 1; +END| +--error ER_SP_NO_RETSET +SELECT bug13012_2()| +drop table t1| +drop procedure bug13012_1| +drop function bug13012_2| +delimiter ;| + +# +# BUG#11555 "Stored procedures: current SP tables locking make +# impossible view security". We should not expose names of tables +# which are implicitly used by view (via stored routines/triggers). +# +# Note that SQL standard assumes that you simply won't be able drop table +# and leave some objects (routines/views/triggers) which were depending on +# it. Such objects should be dropped in advance (by default) or will be +# dropped simultaneously with table (DROP TABLE with CASCADE clause). +# So these tests probably should go away once we will implement standard +# behavior. +--disable_warnings +drop function if exists bug11555_1; +drop function if exists bug11555_2; +drop view if exists v1, v2, v3, v4; +--enable_warnings +create function bug11555_1() returns int return (select max(i) from t1); +create function bug11555_2() returns int return bug11555_1(); +# It is OK to report name of implicitly used table which is missing +# when we create view. +--error ER_NO_SUCH_TABLE +create view v1 as select bug11555_1(); +--error ER_NO_SUCH_TABLE +create view v2 as select bug11555_2(); +# But we should hide name of missing implicitly used table when we use view +create table t1 (i int); +create view v1 as select bug11555_1(); +create view v2 as select bug11555_2(); +create view v3 as select * from v1; +drop table t1; +--error ER_VIEW_INVALID +select * from v1; +--error ER_VIEW_INVALID +select * from v2; +--error ER_VIEW_INVALID +select * from v3; +# Note that creation of view which depends on broken view is yet +# another form of view usage. +--error ER_VIEW_INVALID +create view v4 as select * from v1; +drop view v1, v2, v3; +# We also should hide details about broken triggers which are +# invoked for view. +drop function bug11555_1; +drop function bug11555_2; +create table t1 (i int); +create table t2 (i int); +create trigger t1_ai after insert on t1 for each row insert into t2 values (new.i); +create view v1 as select * from t1; +drop table t2; +--error ER_VIEW_INVALID +insert into v1 values (1); +drop trigger t1_ai; +create function bug11555_1() returns int return (select max(i) from t2); +create trigger t1_ai after insert on t1 for each row set @a:=bug11555_1(); +--error ER_VIEW_INVALID +insert into v1 values (2); +drop function bug11555_1; +drop table t1; +drop view v1; + +# +# BUG#15658: Server crashes after creating function as empty string +# +--disable_warnings +drop procedure if exists ` bug15658`; +--enable_warnings + +--error ER_SP_WRONG_NAME +create procedure ``() select 1; +--error ER_SP_WRONG_NAME +create procedure ` `() select 1; +--error ER_SP_WRONG_NAME +create procedure `bug15658 `() select 1; +--error ER_WRONG_DB_NAME +create procedure ``.bug15658() select 1; +--error ER_WRONG_DB_NAME +create procedure `x `.bug15658() select 1; + +# This should work +create procedure ` bug15658`() select 1; +call ` bug15658`(); +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status; +drop procedure ` bug15658`; + + +# +# BUG#14270: Stored procedures: crash if load index +# +--disable_warnings +drop function if exists bug14270; +drop table if exists t1; +--enable_warnings + +create table t1 (s1 int primary key); + +delimiter |; +--error ER_SP_NO_RETSET +create function bug14270() returns int +begin + load index into cache t1; + return 1; +end| + +--error ER_SP_NO_RETSET +create function bug14270() returns int +begin + cache index t1 key (`primary`) in keycache1; + return 1; +end| +delimiter ;| + +drop table t1; + + +# +# BUG#15091: Sp Returns Unknown error in order clause....and +# there is no order by clause +# +--disable_warnings +drop procedure if exists bug15091; +--enable_warnings + +delimiter |; +create procedure bug15091() +begin + declare selectstr varchar(6000) default ' '; + declare conditionstr varchar(5000) default ''; + + set selectstr = concat(selectstr, + ' and ', + c.operatorid, + 'in (',conditionstr, ')'); +end| +delimiter ;| + +# The error message used to be: +# ERROR 1109 (42S02): Unknown table 'c' in order clause +# but is now rephrased to something less misleading: +# ERROR 1109 (42S02): Unknown table 'c' in field list +--error ER_UNKNOWN_TABLE +call bug15091(); + +drop procedure bug15091; + + +# +# BUG#16896: Stored function: unused AGGREGATE-clause in CREATE FUNCTION +# +--disable_warnings +drop function if exists bug16896; +--enable_warnings + +--error ER_SP_NO_AGGREGATE +create aggregate function bug16896() returns int return 1; + + +# +# BUG#14702: misleading error message when syntax error in CREATE +# PROCEDURE +# +# Misleading error message was given when IF NOT EXISTS was used in +# CREATE PROCEDURE. +# +--disable_warnings +DROP PROCEDURE IF EXISTS bug14702; +--enable_warnings + +--error ER_PARSE_ERROR +CREATE IF NOT EXISTS PROCEDURE bug14702() +BEGIN +END; + +--error ER_PARSE_ERROR +CREATE PROCEDURE IF NOT EXISTS bug14702() +BEGIN +END; + + +# +# BUG#20953: create proc with a create view that uses local +# vars/params should fail to create +# +# See test case for what syntax is forbidden in a view. +# +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (i INT); + +# We do not have to drop this procedure and view because they won't be +# created. +--error ER_VIEW_SELECT_CLAUSE +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO @a; +--error ER_VIEW_SELECT_CLAUSE +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO DUMPFILE "file"; +--error ER_VIEW_SELECT_CLAUSE +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO OUTFILE "file"; +--error ER_VIEW_SELECT_CLAUSE +CREATE PROCEDURE bug20953() + CREATE VIEW v AS SELECT i FROM t1 PROCEDURE ANALYSE(); +--error ER_VIEW_SELECT_DERIVED +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1; +--error ER_VIEW_SELECT_VARIABLE +CREATE PROCEDURE bug20953(i INT) CREATE VIEW v AS SELECT i; +delimiter |; +--error ER_VIEW_SELECT_VARIABLE +CREATE PROCEDURE bug20953() +BEGIN + DECLARE i INT; + CREATE VIEW v AS SELECT i; +END | +delimiter ;| +--error ER_VIEW_SELECT_VARIABLE +PREPARE stmt FROM "CREATE VIEW v AS SELECT ?"; + +DROP TABLE t1; + + +# +# BUG#NNNN: New bug synopsis +# +#--disable_warnings +#drop procedure if exists bugNNNN| +#--enable_warnings +#create procedure bugNNNN... diff --git a/mysql-test/t/sp-prelocking.test b/mysql-test/t/sp-prelocking.test new file mode 100644 index 00000000000..b94de6236d3 --- /dev/null +++ b/mysql-test/t/sp-prelocking.test @@ -0,0 +1,305 @@ +# +# Tests of prelocking-free execution of stored procedures. +# Currently two properties of prelocking-free SP execution are checked: +# - It is possible to execute DDL statements in prelocking-free stored +# procedure +# - The same procedure can be called in prelocking-free mode and +# in prelocked mode (from within a function). + +--disable_warnings +drop database if exists mysqltest; +drop table if exists t1, t2, t3, t4; +drop procedure if exists sp1; +drop procedure if exists sp2; +drop procedure if exists sp3; +drop procedure if exists sp4; +drop function if exists f1; +drop function if exists f2; +drop function if exists f3; +--enable_warnings + +# BUG#8072 + +create database mysqltest; +delimiter //; +use mysqltest// +create procedure sp1 () +begin + drop table if exists t1; + select 1 as "my-col"; +end; +// +delimiter ;// + +select database(); +call sp1(); +select database(); + +use test; +select database(); +call mysqltest.sp1(); +select database(); + +drop procedure mysqltest.sp1; +drop database mysqltest; + +# BUG#8766 + +delimiter //; +create procedure sp1() +begin + create table t1 (a int); + insert into t1 values (10); +end// + +create procedure sp2() +begin + create table t2(a int); + insert into t2 values(1); + call sp1(); +end// + +create function f1() returns int +begin + return (select max(a) from t1); +end// + +create procedure sp3() +begin + call sp1(); + select 'func', f1(); +end// + +delimiter ;// + +call sp1(); +select 't1',a from t1; + +drop table t1; +call sp2(); +select 't1',a from t1; +select 't2',a from t2; +drop table t1, t2; + +call sp3(); +select 't1',a from t1; + +drop table t1; + +drop procedure sp1; +drop procedure sp2; +drop procedure sp3; +drop function f1; + +delimiter //; +create procedure sp1() +begin + create temporary table t2(a int); + insert into t2 select * from t1; +end// + +create procedure sp2() +begin + create temporary table t1 (a int); + insert into t1 values(1); + call sp1(); + select 't1', a from t1; + select 't2', a from t2; + drop table t1; + drop table t2; +end// + +delimiter ;// +call sp2(); + +drop procedure sp1; +drop procedure sp2; + +# Miscelaneous tests +create table t1 (a int); +insert into t1 values(1),(2); +create table t2 as select * from t1; +create table t3 as select * from t1; +create table t4 as select * from t1; +delimiter //; +create procedure sp1(a int) +begin + select a; +end // + +create function f1() returns int +begin + return (select max(a) from t1); +end // + +delimiter ;// + +CALL sp1(f1()); + +############# +delimiter //; +create procedure sp2(a int) +begin + select * from t3; + select a; +end // + +create procedure sp3() +begin + select * from t1; + call sp2(5); +end // + +create procedure sp4() +begin + select * from t2; + call sp3(); +end // + +delimiter ;// +call sp4(); + +drop procedure sp1; +drop procedure sp2; +drop procedure sp3; +drop procedure sp4; +drop function f1; + +# Test that prelocking state restoration works with cursors +--disable_warnings +drop view if exists v1; +--enable_warnings +delimiter //; + +create function f1(ab int) returns int +begin + declare i int; + set i= (select max(a) from t1 where a < ab) ; + return i; +end // + +create function f2(ab int) returns int +begin + declare i int; + set i= (select max(a) from t2 where a < ab) ; + return i; +end // + +create view v1 as + select t3.a as x, t4.a as y, f2(3) as z + from t3, t4 where t3.a = t4.a // + +create procedure sp1() +begin + declare a int; + set a= (select f1(4) + count(*) A from t1, v1); +end // + + +create function f3() returns int +begin + call sp1(); + return 1; +end // + +call sp1() // + +select f3() // +select f3() // + +call sp1() // + +--------------- +drop procedure sp1// +drop function f3// + +create procedure sp1() +begin + declare x int; + declare c cursor for select f1(3) + count(*) from v1; + open c; + fetch c into x; +end;// + +create function f3() returns int +begin + call sp1(); + return 1; +end // + +call sp1() // +call sp1() // + +select f3() // +call sp1() // + +delimiter ;// +drop view v1; +drop table t1,t2,t3,t4; +drop function f1; +drop function f2; +drop function f3; +drop procedure sp1; + +# +# Bug#15683 "crash, Function on nested VIEWs, Prepared statement" +# Check that when creating the prelocking list a nested view +# is not merged until it's used. +# +--disable_warnings +drop table if exists t1; +drop view if exists v1, v2, v3; +drop function if exists bug15683; +--enable_warnings +create table t1 (f1 bigint, f2 varchar(20), f3 bigint); +insert into t1 set f1 = 1, f2 = 'schoenenbourg', f3 = 1; +create view v1 as select 1 from t1 union all select 1; +create view v2 as select 1 from v1; +create view v3 as select 1 as f1 from v2; + +delimiter |; +create function bug15683() returns bigint +begin +return (select count(*) from v3); +end| +delimiter ;| + +prepare stmt from "select bug15683()"; +execute stmt; +execute stmt; +deallocate prepare stmt; +drop table t1; +drop view v1, v2, v3; +drop function bug15683; + + +# +# Bug#19634 "Re-execution of multi-delete which involve trigger/stored +# function crashes server" +# +--disable_warnings +drop table if exists t1, t2, t3; +drop function if exists bug19634; +--enable_warnings +create table t1 (id int, data int); +create table t2 (id int); +create table t3 (data int); +create function bug19634() returns int return (select count(*) from t3); +prepare stmt from "delete t1 from t1, t2 where t1.id = t2.id and bug19634()"; +# This should not crash server +execute stmt; +execute stmt; +deallocate prepare stmt; + +create trigger t1_bi before delete on t1 for each row insert into t3 values (old.data); +prepare stmt from "delete t1 from t1, t2 where t1.id = t2.id"; + +execute stmt; +execute stmt; +deallocate prepare stmt; + +drop function bug19634; +drop table t1, t2, t3; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/sp-security.test b/mysql-test/t/sp-security.test new file mode 100644 index 00000000000..a5d509f29b7 --- /dev/null +++ b/mysql-test/t/sp-security.test @@ -0,0 +1,869 @@ +# +# Testing SQL SECURITY of stored procedures +# + +# Can't test with embedded server that doesn't support grants +-- source include/not_embedded.inc + +connect (con1root,localhost,root,,); + +connection con1root; +use test; + +# Create user user1 with no particular access rights +grant usage on *.* to user1@localhost; +flush privileges; + +--disable_warnings +drop table if exists t1; +drop database if exists db1_secret; +--enable_warnings +# Create our secret database +create database db1_secret; + +# Can create a procedure in other db +create procedure db1_secret.dummy() begin end; +drop procedure db1_secret.dummy; + +use db1_secret; + +create table t1 ( u varchar(64), i int ); + +# A test procedure and function +create procedure stamp(i int) + insert into db1_secret.t1 values (user(), i); +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like 'stamp'; + +create function db() returns varchar(64) return database(); +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show function status like 'db'; + +# root can, of course +call stamp(1); +select * from t1; +select db(); + +grant execute on procedure db1_secret.stamp to user1@'%'; +grant execute on function db1_secret.db to user1@'%'; +grant execute on procedure db1_secret.stamp to ''@'%'; +grant execute on function db1_secret.db to ''@'%'; + +connect (con2user1,localhost,user1,,); +connect (con3anon,localhost,anon,,); + + +# +# User1 can +# +connection con2user1; + +# This should work... +call db1_secret.stamp(2); +select db1_secret.db(); + +# ...but not this +--error 1142 +select * from db1_secret.t1; + +# ...and not this +--error 1044 +create procedure db1_secret.dummy() begin end; +--error 1305 +drop procedure db1_secret.dummy; + + +# +# Anonymous can +# +connection con3anon; + +# This should work... +call db1_secret.stamp(3); +select db1_secret.db(); + +# ...but not this +--error 1142 +select * from db1_secret.t1; + +# ...and not this +--error 1044 +create procedure db1_secret.dummy() begin end; +--error 1305 +drop procedure db1_secret.dummy; + + +# +# Check it out +# +connection con1root; +select * from t1; + +# +# Change to invoker's rights +# +alter procedure stamp sql security invoker; +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like 'stamp'; + +alter function db sql security invoker; +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show function status like 'db'; + +# root still can +call stamp(4); +select * from t1; +select db(); + +# +# User1 cannot +# +connection con2user1; + +# This should not work +--error 1044 +call db1_secret.stamp(5); +--error 1044 +select db1_secret.db(); + +# +# Anonymous cannot +# +connection con3anon; + +# This should not work +--error 1044 +call db1_secret.stamp(6); +--error 1044 +select db1_secret.db(); + +# +# BUG#2777 +# + +connection con1root; +--disable_warnings +drop database if exists db2; +--enable_warnings +create database db2; + +use db2; + +create table t2 (s1 int); +insert into t2 values (0); + +grant usage on db2.* to user1@localhost; +grant select on db2.* to user1@localhost; +grant usage on db2.* to user2@localhost; +grant select,insert,update,delete,create routine on db2.* to user2@localhost; +grant create routine on db2.* to user1@localhost; +flush privileges; + +connection con2user1; +use db2; + +create procedure p () insert into t2 values (1); + +# Check that this doesn't work. +--error 1142 +call p(); + +connect (con4user2,localhost,user2,,); + +connection con4user2; +use db2; + +# This should not work, since p is executed with definer's (user1's) rights. +--error 1370 +call p(); +select * from t2; + +create procedure q () insert into t2 values (2); + +call q(); +select * from t2; + +connection con1root; +grant usage on procedure db2.q to user2@localhost with grant option; + +connection con4user2; +grant execute on procedure db2.q to user1@localhost; + +connection con2user1; +use db2; + +# This should work +call q(); +select * from t2; + +# +# BUG#6030: Stored procedure has no appropriate DROP privilege +# (or ALTER for that matter) + +# still connection con2user1 in db2 + +# This should work: +alter procedure p modifies sql data; +drop procedure p; + +# This should NOT work +--error 1370 +alter procedure q modifies sql data; +--error 1370 +drop procedure q; + +connection con1root; +use db2; +# But root always can +alter procedure q modifies sql data; +drop procedure q; + + +# Clean up +#Still connection con1root; +disconnect con2user1; +disconnect con3anon; +disconnect con4user2; +use test; +select type,db,name from mysql.proc; +drop database db1_secret; +drop database db2; +# Make sure the routines are gone +select type,db,name from mysql.proc; +# Get rid of the users +delete from mysql.user where user='user1' or user='user2'; +delete from mysql.user where user='' and host='%'; +# And any routine privileges +delete from mysql.procs_priv where user='user1' or user='user2'; +# Delete the grants to user ''@'%' that was created above +delete from mysql.procs_priv where user='' and host='%'; +delete from mysql.db where user='user2'; +flush privileges; +# +# Test the new security acls +# +grant usage on *.* to usera@localhost; +grant usage on *.* to userb@localhost; +grant usage on *.* to userc@localhost; +create database sptest; +create table t1 ( u varchar(64), i int ); +create procedure sptest.p1(i int) insert into test.t1 values (user(), i); +grant insert on t1 to usera@localhost; +grant execute on procedure sptest.p1 to usera@localhost; +show grants for usera@localhost; +grant execute on procedure sptest.p1 to userc@localhost with grant option; +show grants for userc@localhost; + +connect (con2usera,localhost,usera,,); +connect (con3userb,localhost,userb,,); +connect (con4userc,localhost,userc,,); + +connection con2usera; +call sptest.p1(1); +--error 1370 +grant execute on procedure sptest.p1 to userb@localhost; +--error 1370 +drop procedure sptest.p1; + +connection con3userb; +--error 1370 +call sptest.p1(2); +--error 1370 +grant execute on procedure sptest.p1 to userb@localhost; +--error 1370 +drop procedure sptest.p1; + +connection con4userc; +call sptest.p1(3); +grant execute on procedure sptest.p1 to userb@localhost; +--error 1370 +drop procedure sptest.p1; + +connection con3userb; +call sptest.p1(4); +--error 1370 +grant execute on procedure sptest.p1 to userb@localhost; +--error 1370 +drop procedure sptest.p1; + +connection con1root; +select * from t1; + +grant all privileges on procedure sptest.p1 to userc@localhost; +show grants for userc@localhost; +show grants for userb@localhost; + +connection con4userc; +revoke all privileges on procedure sptest.p1 from userb@localhost; + +connection con1root; +show grants for userb@localhost; + +#cleanup +disconnect con4userc; +disconnect con3userb; +disconnect con2usera; +use test; +drop database sptest; +delete from mysql.user where user='usera' or user='userb' or user='userc'; +delete from mysql.procs_priv where user='usera' or user='userb' or user='userc'; +delete from mysql.tables_priv where user='usera'; +flush privileges; +drop table t1; + +# +# BUG#9503: reseting correct parameters of thread after error in SP function +# +connect (root,localhost,root,,test); +connection root; + +--disable_warnings +drop function if exists bug_9503; +--enable_warnings +delimiter //; +create database mysqltest// +use mysqltest// +create table t1 (s1 int)// +grant select on t1 to user1@localhost// +create function bug_9503 () returns int sql security invoker begin declare v int; +select min(s1) into v from t1; return v; end// +delimiter ;// + +connect (user1,localhost,user1,,test); +connection user1; +use mysqltest; +-- error 1370 +select bug_9503(); + +connection root; +grant execute on function bug_9503 to user1@localhost; + +connection user1; +do 1; +use test; + +disconnect user1; +connection root; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM user1@localhost; +drop function bug_9503; +use test; +drop database mysqltest; + +# +# correct value from current_user() in function run from "security definer" +# (BUG#7291) +# +connection con1root; +use test; + +select current_user(); +select user(); +create procedure bug7291_0 () sql security invoker select current_user(), user(); +create procedure bug7291_1 () sql security definer call bug7291_0(); +create procedure bug7291_2 () sql security invoker call bug7291_0(); +grant execute on procedure bug7291_0 to user1@localhost; +grant execute on procedure bug7291_1 to user1@localhost; +grant execute on procedure bug7291_2 to user1@localhost; + +connect (user1,localhost,user1,,); +connection user1; + +call bug7291_2(); +call bug7291_1(); + +connection con1root; +drop procedure bug7291_1; +drop procedure bug7291_2; +drop procedure bug7291_0; +disconnect user1; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM user1@localhost; +drop user user1@localhost; + +# +# Bug #12318: Wrong error message when accessing an inaccessible stored +# procedure in another database when the current database is +# information_schema. +# + +--disable_warnings +drop database if exists mysqltest_1; +--enable_warnings + +create database mysqltest_1; +delimiter //; +create procedure mysqltest_1.p1() +begin + select 1 from dual; +end// +delimiter ;// + +grant usage on *.* to mysqltest_1@localhost; + +connect (n1,localhost,mysqltest_1,,information_schema,$MASTER_MYPORT,$MASTER_MYSOCK); +connection n1; +--error 1370 +call mysqltest_1.p1(); +disconnect n1; +# Test also without a current database +connect (n2,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,$MASTER_MYSOCK); +connection n2; +--error 1370 +call mysqltest_1.p1(); +disconnect n2; + +connection default; + +drop procedure mysqltest_1.p1; +drop database mysqltest_1; + +revoke usage on *.* from mysqltest_1@localhost; +drop user mysqltest_1@localhost; + +# +# BUG#12812 create view calling a function works without execute right +# on function +delimiter |; +--disable_warnings +drop function if exists bug12812| +--enable_warnings +create function bug12812() returns char(2) +begin + return 'ok'; +end; +create user user_bug12812@localhost IDENTIFIED BY 'ABC'| +--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK +connect (test_user_12812,localhost,user_bug12812,ABC,test)| +--error 1370 +SELECT test.bug12812()| +--error 1370 +CREATE VIEW v1 AS SELECT test.bug12812()| +# Cleanup +connection default| +disconnect test_user_12812| +DROP USER user_bug12812@localhost| +drop function bug12812| +delimiter ;| + + +# +# BUG#14834: Server denies to execute Stored Procedure +# +# The problem here was with '_' in the database name. +# +create database db_bug14834; + +create user user1_bug14834@localhost identified by ''; +# The exact name of the database (no wildcard) +grant all on `db\_bug14834`.* to user1_bug14834@localhost; + +create user user2_bug14834@localhost identified by ''; +# The exact name of the database (no wildcard) +grant all on `db\_bug14834`.* to user2_bug14834@localhost; + +create user user3_bug14834@localhost identified by ''; +# Wildcards in the database name +grant all on `db__ug14834`.* to user3_bug14834@localhost; + +connect (user1_bug14834,localhost,user1_bug14834,,db_bug14834); +# Create the procedure and check that we can call it +create procedure p_bug14834() select user(), current_user(); +call p_bug14834(); + +connect (user2_bug14834,localhost,user2_bug14834,,db_bug14834); +# This didn't work before +call p_bug14834(); + +connect (user3_bug14834,localhost,user3_bug14834,,db_bug14834); +# Should also work +call p_bug14834(); + +# Cleanup +connection default; +disconnect user1_bug14834; +disconnect user2_bug14834; +disconnect user3_bug14834; +drop user user1_bug14834@localhost; +drop user user2_bug14834@localhost; +drop user user3_bug14834@localhost; +drop database db_bug14834; + + +# +# BUG#14533: 'desc tbl' in stored procedure causes error 1142 +# +create database db_bug14533; +use db_bug14533; +create table t1 (id int); +create user user_bug14533@localhost identified by ''; + +create procedure bug14533_1() + sql security definer + desc db_bug14533.t1; + +create procedure bug14533_2() + sql security definer + select * from db_bug14533.t1; + +grant execute on procedure db_bug14533.bug14533_1 to user_bug14533@localhost; +grant execute on procedure db_bug14533.bug14533_2 to user_bug14533@localhost; + +connect (user_bug14533,localhost,user_bug14533,,test); + +# These should work +call db_bug14533.bug14533_1(); +call db_bug14533.bug14533_2(); + +# For reference, these should not work +--error ER_TABLEACCESS_DENIED_ERROR +desc db_bug14533.t1; +--error ER_TABLEACCESS_DENIED_ERROR +select * from db_bug14533.t1; + +# Cleanup +connection default; +disconnect user_bug14533; +drop user user_bug14533@localhost; +drop database db_bug14533; + + +# +# BUG#7787: Stored procedures: improper warning for "grant execute" statement +# + +# Prepare. + +CREATE DATABASE db_bug7787; +use db_bug7787; + +# Test. + +CREATE PROCEDURE p1() + SHOW INNODB STATUS; + +GRANT EXECUTE ON PROCEDURE p1 TO user_bug7787@localhost; + +# Cleanup. + +DROP DATABASE db_bug7787; +drop user user_bug7787@localhost; +use test; + + +# +# WL#2897: Complete definer support in the stored routines. +# +# The following cases are tested: +# 1. check that if DEFINER-clause is not explicitly specified, stored routines +# are created with CURRENT_USER privileges; +# 2. check that if DEFINER-clause specifies non-current user, SUPER privilege +# is required to create a stored routine; +# 3. check that if DEFINER-clause specifies non-existent user, a warning is +# emitted. +# 4. check that SHOW CREATE PROCEDURE | FUNCTION works correctly; +# +# The following cases are tested in other test suites: +# - check that mysqldump dumps new attribute correctly; +# - check that slave replicates CREATE-statements with explicitly specified +# DEFINER correctly. +# + +# Setup the environment. + +--echo +--echo ---> connection: root +--connection con1root + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest; +--enable_warnings + +CREATE DATABASE mysqltest; + +CREATE USER mysqltest_1@localhost; +GRANT ALL PRIVILEGES ON mysqltest.* TO mysqltest_1@localhost; + +CREATE USER mysqltest_2@localhost; +GRANT SUPER ON *.* TO mysqltest_2@localhost; +GRANT ALL PRIVILEGES ON mysqltest.* TO mysqltest_2@localhost; + +--connect (mysqltest_2_con,localhost,mysqltest_2,,mysqltest) +--connect (mysqltest_1_con,localhost,mysqltest_1,,mysqltest) + +# test case (1). + +--echo +--echo ---> connection: mysqltest_2_con +--connection mysqltest_2_con + +use mysqltest; + +CREATE PROCEDURE wl2897_p1() SELECT 1; + +CREATE FUNCTION wl2897_f1() RETURNS INT RETURN 1; + +# test case (2). + +--echo +--echo ---> connection: mysqltest_1_con +--connection mysqltest_1_con + +use mysqltest; + +--error ER_SPECIFIC_ACCESS_DENIED_ERROR +CREATE DEFINER=root@localhost PROCEDURE wl2897_p2() SELECT 2; + +--error ER_SPECIFIC_ACCESS_DENIED_ERROR +CREATE DEFINER=root@localhost FUNCTION wl2897_f2() RETURNS INT RETURN 2; + +# test case (3). + +--echo +--echo ---> connection: mysqltest_2_con +--connection mysqltest_2_con + +use mysqltest; + +CREATE DEFINER='a @ b @ c'@localhost PROCEDURE wl2897_p3() SELECT 3; + +CREATE DEFINER='a @ b @ c'@localhost FUNCTION wl2897_f3() RETURNS INT RETURN 3; + +# test case (4). + +--echo +--echo ---> connection: con1root +--connection con1root + +use mysqltest; + +SHOW CREATE PROCEDURE wl2897_p1; +SHOW CREATE PROCEDURE wl2897_p3; + +SHOW CREATE FUNCTION wl2897_f1; +SHOW CREATE FUNCTION wl2897_f3; + +# Cleanup. + +DROP USER mysqltest_1@localhost; +DROP USER mysqltest_2@localhost; + +DROP DATABASE mysqltest; + +--disconnect mysqltest_1_con +--disconnect mysqltest_2_con + + +# +# BUG#13198: SP executes if definer does not exist +# + +# Prepare environment. + +--echo +--echo ---> connection: root +--connection con1root + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest; +--enable_warnings + +CREATE DATABASE mysqltest; + +CREATE USER mysqltest_1@localhost; +GRANT ALL PRIVILEGES ON mysqltest.* TO mysqltest_1@localhost; + +CREATE USER mysqltest_2@localhost; +GRANT ALL PRIVILEGES ON mysqltest.* TO mysqltest_2@localhost; + +--connect (mysqltest_1_con,localhost,mysqltest_1,,mysqltest) +--connect (mysqltest_2_con,localhost,mysqltest_2,,mysqltest) + +# Create a procedure/function under u1. + +--echo +--echo ---> connection: mysqltest_1_con +--connection mysqltest_1_con + +use mysqltest; + +CREATE PROCEDURE bug13198_p1() + SELECT 1; + +CREATE FUNCTION bug13198_f1() RETURNS INT + RETURN 1; + +CALL bug13198_p1(); + +SELECT bug13198_f1(); + +# Check that u2 can call the procedure/function. + +--echo +--echo ---> connection: mysqltest_2_con +--connection mysqltest_2_con + +use mysqltest; + +CALL bug13198_p1(); + +SELECT bug13198_f1(); + +# Drop user u1 (definer of the object); + +--echo +--echo ---> connection: root +--connection con1root + +--disconnect mysqltest_1_con + +DROP USER mysqltest_1@localhost; + +# Check that u2 can not call the procedure/function. + +--echo +--echo ---> connection: mysqltest_2_con +--connection mysqltest_2_con + +use mysqltest; + +--error ER_NO_SUCH_USER +CALL bug13198_p1(); + +--error ER_NO_SUCH_USER +SELECT bug13198_f1(); + +# Cleanup. + +--echo +--echo ---> connection: root +--connection con1root + +--disconnect mysqltest_2_con + +DROP USER mysqltest_2@localhost; + +DROP DATABASE mysqltest; + + +# +# Bug#19857 - When a user with CREATE ROUTINE priv creates a routine, +# it results in NULL p/w +# + +# Can't test with embedded server that doesn't support grants + +GRANT USAGE ON *.* TO user19857@localhost IDENTIFIED BY 'meow'; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ROUTINE, ALTER ROUTINE ON test.* TO +user19857@localhost; +SELECT Host,User,Password FROM mysql.user WHERE User='user19857'; + +--connect (mysqltest_2_con,localhost,user19857,meow,test) +--echo +--echo ---> connection: mysqltest_2_con +--connection mysqltest_2_con + +use test; + +DELIMITER //; + CREATE PROCEDURE sp19857() DETERMINISTIC + BEGIN + DECLARE a INT; + SET a=1; + SELECT a; + END // +DELIMITER ;// + +SHOW CREATE PROCEDURE test.sp19857; + +--disconnect mysqltest_2_con +--connect (mysqltest_2_con,localhost,user19857,meow,test) +--connection mysqltest_2_con + +DROP PROCEDURE IF EXISTS test.sp19857; + +--echo +--echo ---> connection: root +--connection con1root + +--disconnect mysqltest_2_con + +SELECT Host,User,Password FROM mysql.user WHERE User='user19857'; + +DROP USER user19857@localhost; + +--disconnect con1root +--connection default + + +# +# BUG#18630: Arguments of suid routine calculated in wrong security +# context +# +# Arguments of suid routines were calculated in definer's security +# context instead of caller's context thus creating security hole. +# +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP VIEW IF EXISTS v1; +DROP FUNCTION IF EXISTS f_suid; +DROP PROCEDURE IF EXISTS p_suid; +DROP FUNCTION IF EXISTS f_evil; +--enable_warnings +DELETE FROM mysql.user WHERE user LIKE 'mysqltest\_%'; +DELETE FROM mysql.db WHERE user LIKE 'mysqltest\_%'; +DELETE FROM mysql.tables_priv WHERE user LIKE 'mysqltest\_%'; +DELETE FROM mysql.columns_priv WHERE user LIKE 'mysqltest\_%'; +FLUSH PRIVILEGES; + +CREATE TABLE t1 (i INT); +CREATE FUNCTION f_suid(i INT) RETURNS INT SQL SECURITY DEFINER RETURN 0; +CREATE PROCEDURE p_suid(IN i INT) SQL SECURITY DEFINER SET @c:= 0; + +CREATE USER mysqltest_u1@localhost; +# Thanks to this grant statement privileges of anonymous users on +# 'test' database are not applicable for mysqltest_u1@localhost. +GRANT EXECUTE ON test.* TO mysqltest_u1@localhost; + +delimiter |; +CREATE DEFINER=mysqltest_u1@localhost FUNCTION f_evil () RETURNS INT + SQL SECURITY INVOKER +BEGIN + SET @a:= CURRENT_USER(); + SET @b:= (SELECT COUNT(*) FROM t1); + RETURN @b; +END| +delimiter ;| + +CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT f_evil(); + +connect (conn1, localhost, mysqltest_u1,,); + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT COUNT(*) FROM t1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT f_evil(); +SELECT @a, @b; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT f_suid(f_evil()); +SELECT @a, @b; + +--error ER_TABLEACCESS_DENIED_ERROR +CALL p_suid(f_evil()); +SELECT @a, @b; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1; +SELECT @a, @b; + +disconnect conn1; +connection default; + +DROP VIEW v1; +DROP FUNCTION f_evil; +DROP USER mysqltest_u1@localhost; +DROP PROCEDURE p_suid; +DROP FUNCTION f_suid; +DROP TABLE t1; + +--echo End of 5.0 tests. diff --git a/mysql-test/t/sp-threads.test b/mysql-test/t/sp-threads.test new file mode 100644 index 00000000000..d8a8ce5dae7 --- /dev/null +++ b/mysql-test/t/sp-threads.test @@ -0,0 +1,185 @@ +# This test should work in embedded server after mysqltest is fixed +-- source include/not_embedded.inc +# +# Testing stored procedures with multiple connections, +# except security/privilege tests, they go to sp-security.test +# + +connect (con1root,localhost,root,,); +connect (con2root,localhost,root,,); +connect (con3root,localhost,root,,); + +connection con1root; +use test; + +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1 (s1 int, s2 int, s3 int); + +delimiter //; +create procedure bug4934() +begin + insert into t1 values (1,0,1); +end// +delimiter ;// + + +connection con2root; +use test; + +call bug4934(); +select * from t1; + + +connection con1root; + +drop table t1; +create table t1 (s1 int, s2 int, s3 int); + +drop procedure bug4934; +delimiter //; +create procedure bug4934() +begin +end// +delimiter ;// + + +connection con2root; + +select * from t1; +call bug4934(); +select * from t1; + +connection con1root; + +drop table t1; +drop procedure bug4934; + + +# +# BUG #9486 "Can't perform multi-update in stored procedure" +# +--disable_warnings +drop procedure if exists bug9486; +drop table if exists t1, t2; +--enable_warnings +create table t1 (id1 int, val int); +create table t2 (id2 int); + +create procedure bug9486() + update t1, t2 set val= 1 where id1=id2; +call bug9486(); +# Let us check that SP invocation requires write lock for t2. +connection con2root; +lock tables t2 write; +connection con1root; +send call bug9486(); +connection con2root; +--sleep 2 +# There should be call statement in locked state. +--replace_column 1 # 3 localhost 6 # +show processlist; +unlock tables; +connection con1root; +reap; + +drop procedure bug9486; +drop table t1, t2; + +# +# BUG#11158: Can't perform multi-delete in stored procedure +# +--disable_warnings +drop procedure if exists bug11158; +--enable_warnings +create procedure bug11158() delete t1 from t1, t2 where t1.id = t2.id; +create table t1 (id int, j int); +insert into t1 values (1, 1), (2, 2); +create table t2 (id int); +insert into t2 values (1); +# Procedure should work and cause proper effect (delete only first row) +call bug11158(); +select * from t1; +# Also let us test that we obtain only read (and thus non exclusive) lock +# for table from which we are not going to delete rows. +connection con2root; +lock tables t2 read; +connection con1root; +call bug11158(); +connection con2root; +unlock tables; +connection con1root; +# Clean-up +drop procedure bug11158; +drop table t1, t2; + +# +# BUG#11554: Server crashes on statement indirectly using non-cached function +# +--disable_warnings +drop function if exists bug11554; +drop view if exists v1; +--enable_warnings +create table t1 (i int); +create function bug11554 () returns int return 1; +create view v1 as select bug11554() as f; +connection con2root; +# This should not crash server +insert into t1 (select f from v1); +# Clean-up +connection con1root; +drop function bug11554; +drop table t1; +drop view v1; + + +# BUG#12228 +--disable_warnings +drop procedure if exists p1; +drop procedure if exists p2; +--enable_warnings + +connection con1root; +delimiter |; +create table t1 (s1 int)| +create procedure p1() select * from t1| +create procedure p2() +begin + insert into t1 values (1); + call p1(); + select * from t1; +end| +delimiter ;| + +connection con2root; +use test; +lock table t1 write; + +connection con1root; +send call p2(); + +connection con3root; +use test; +drop procedure p1; +create procedure p1() select * from t1; + +connection con2root; +unlock tables; + +connection con1root; +# Crash will be here if we hit BUG#12228 +reap; + +drop procedure p1; +drop procedure p2; +drop table t1; + +# +# BUG#NNNN: New bug synopsis +# +#--disable_warnings +#drop procedure if exists bugNNNN; +#--enable_warnings +#create procedure bugNNNN... + diff --git a/mysql-test/t/sp-vars.test b/mysql-test/t/sp-vars.test new file mode 100644 index 00000000000..7cf92dc5d0d --- /dev/null +++ b/mysql-test/t/sp-vars.test @@ -0,0 +1,1319 @@ +########################################################################### +# +# Cleanup. +# +########################################################################### + +--disable_warnings + +# Drop stored routines (if any) for general SP-vars test cases. These routines +# are created in include/sp-vars.inc file. + +DROP PROCEDURE IF EXISTS sp_vars_check_dflt; +DROP PROCEDURE IF EXISTS sp_vars_check_assignment; +DROP FUNCTION IF EXISTS sp_vars_check_ret1; +DROP FUNCTION IF EXISTS sp_vars_check_ret2; +DROP FUNCTION IF EXISTS sp_vars_check_ret3; +DROP FUNCTION IF EXISTS sp_vars_check_ret4; +DROP FUNCTION IF EXISTS sp_vars_div_zero; + +--enable_warnings + +########################################################################### +# +# Some general tests for SP-vars functionality. +# +########################################################################### + +# Create the procedure in ANSI mode. Check that all necessary warnings are +# emitted properly. + +SET @@sql_mode = 'ansi'; + +--source include/sp-vars.inc + +--echo +--echo --------------------------------------------------------------- +--echo Calling the routines, created in ANSI mode. +--echo --------------------------------------------------------------- +--echo + +CALL sp_vars_check_dflt(); + +CALL sp_vars_check_assignment(); + +SELECT sp_vars_check_ret1(); + +SELECT sp_vars_check_ret2(); + +SELECT sp_vars_check_ret3(); + +SELECT sp_vars_check_ret4(); + +SELECT sp_vars_div_zero(); + +# Check that changing sql_mode after creating a store procedure does not +# matter. + +SET @@sql_mode = 'traditional'; + +--echo +--echo --------------------------------------------------------------- +--echo Calling in TRADITIONAL mode the routines, created in ANSI mode. +--echo --------------------------------------------------------------- +--echo + +CALL sp_vars_check_dflt(); + +CALL sp_vars_check_assignment(); + +SELECT sp_vars_check_ret1(); + +SELECT sp_vars_check_ret2(); + +SELECT sp_vars_check_ret3(); + +SELECT sp_vars_check_ret4(); + +SELECT sp_vars_div_zero(); + +# Create the procedure in TRADITIONAL mode. Check that error will be thrown on +# execution. + +DROP PROCEDURE sp_vars_check_dflt; +DROP PROCEDURE sp_vars_check_assignment; +DROP FUNCTION sp_vars_check_ret1; +DROP FUNCTION sp_vars_check_ret2; +DROP FUNCTION sp_vars_check_ret3; +DROP FUNCTION sp_vars_check_ret4; +DROP FUNCTION sp_vars_div_zero; + +--source include/sp-vars.inc + +--echo +--echo --------------------------------------------------------------- +--echo Calling the routines, created in TRADITIONAL mode. +--echo --------------------------------------------------------------- +--echo + +--error ER_WARN_DATA_OUT_OF_RANGE +CALL sp_vars_check_dflt(); + +--error ER_WARN_DATA_OUT_OF_RANGE +CALL sp_vars_check_assignment(); + +--error ER_WARN_DATA_OUT_OF_RANGE +SELECT sp_vars_check_ret1(); + +--error ER_WARN_DATA_OUT_OF_RANGE +SELECT sp_vars_check_ret2(); + +--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD +SELECT sp_vars_check_ret3(); + +# TODO: Is it an error, that only a warning is emitted here? Check the same +# behaviour with tables. + +SELECT sp_vars_check_ret4(); + +--error ER_DIVISION_BY_ZERO +SELECT sp_vars_div_zero(); + +SET @@sql_mode = 'ansi'; + +# +# Cleanup. +# + +DROP PROCEDURE sp_vars_check_dflt; +DROP PROCEDURE sp_vars_check_assignment; +DROP FUNCTION sp_vars_check_ret1; +DROP FUNCTION sp_vars_check_ret2; +DROP FUNCTION sp_vars_check_ret3; +DROP FUNCTION sp_vars_check_ret4; +DROP FUNCTION sp_vars_div_zero; + +########################################################################### +# +# Tests for BIT data type. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BIT data type tests +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +# +# Test case. +# + +delimiter |; +CREATE PROCEDURE p1() +BEGIN + DECLARE v1 BIT; + DECLARE v2 BIT(1); + DECLARE v3 BIT(3) DEFAULT b'101'; + DECLARE v4 BIT(64) DEFAULT 0x5555555555555555; + DECLARE v5 BIT(3); + DECLARE v6 BIT(64); + DECLARE v7 BIT(8) DEFAULT 128; + DECLARE v8 BIT(8) DEFAULT '128'; + DECLARE v9 BIT(8) DEFAULT ' 128'; + DECLARE v10 BIT(8) DEFAULT 'x 128'; + + SET v1 = v4; + SET v2 = 0; + SET v5 = v4; # check overflow + SET v6 = v3; # check padding + + SELECT HEX(v1); + SELECT HEX(v2); + SELECT HEX(v3); + SELECT HEX(v4); + SELECT HEX(v5); + SELECT HEX(v6); + SELECT HEX(v7); + SELECT HEX(v8); + SELECT HEX(v9); + SELECT HEX(v10); +END| +delimiter ;| + +CALL p1(); + +# +# Cleanup. +# + +DROP PROCEDURE p1; + +########################################################################### +# +# Tests for CASE statements functionality: +# - test for general functionality (scopes, nested cases, CASE in loops); +# - test that if type of the CASE expression is changed on each iteration, +# the execution will be correct. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo CASE expression tests. +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP TABLE IF EXISTS t1; + +# +# Test case. +# + +CREATE TABLE t1(log_msg VARCHAR(1024)); + +delimiter |; + +CREATE PROCEDURE p1(arg VARCHAR(255)) +BEGIN + INSERT INTO t1 VALUES('p1: step1'); + + CASE arg * 10 + WHEN 10 * 10 THEN + INSERT INTO t1 VALUES('p1: case1: on 10'); + WHEN 10 * 10 + 10 * 10 THEN + BEGIN + CASE arg / 10 + WHEN 1 THEN + INSERT INTO t1 VALUES('p1: case1: case2: on 1'); + WHEN 2 THEN + BEGIN + DECLARE i TINYINT DEFAULT 10; + + WHILE i > 0 DO + INSERT INTO t1 VALUES(CONCAT('p1: case1: case2: loop: i: ', i)); + + CASE MOD(i, 2) + WHEN 0 THEN + INSERT INTO t1 VALUES('p1: case1: case2: loop: i is even'); + WHEN 1 THEN + INSERT INTO t1 VALUES('p1: case1: case2: loop: i is odd'); + ELSE + INSERT INTO t1 VALUES('p1: case1: case2: loop: ERROR'); + END CASE; + + SET i = i - 1; + END WHILE; + END; + ELSE + INSERT INTO t1 VALUES('p1: case1: case2: ERROR'); + END CASE; + + CASE arg + WHEN 10 THEN + INSERT INTO t1 VALUES('p1: case1: case3: on 10'); + WHEN 20 THEN + INSERT INTO t1 VALUES('p1: case1: case3: on 20'); + ELSE + INSERT INTO t1 VALUES('p1: case1: case3: ERROR'); + END CASE; + END; + ELSE + INSERT INTO t1 VALUES('p1: case1: ERROR'); + END CASE; + + CASE arg * 10 + WHEN 10 * 10 THEN + INSERT INTO t1 VALUES('p1: case4: on 10'); + WHEN 10 * 10 + 10 * 10 THEN + BEGIN + CASE arg / 10 + WHEN 1 THEN + INSERT INTO t1 VALUES('p1: case4: case5: on 1'); + WHEN 2 THEN + BEGIN + DECLARE i TINYINT DEFAULT 10; + + WHILE i > 0 DO + INSERT INTO t1 VALUES(CONCAT('p1: case4: case5: loop: i: ', i)); + + CASE MOD(i, 2) + WHEN 0 THEN + INSERT INTO t1 VALUES('p1: case4: case5: loop: i is even'); + WHEN 1 THEN + INSERT INTO t1 VALUES('p1: case4: case5: loop: i is odd'); + ELSE + INSERT INTO t1 VALUES('p1: case4: case5: loop: ERROR'); + END CASE; + + SET i = i - 1; + END WHILE; + END; + ELSE + INSERT INTO t1 VALUES('p1: case4: case5: ERROR'); + END CASE; + + CASE arg + WHEN 10 THEN + INSERT INTO t1 VALUES('p1: case4: case6: on 10'); + WHEN 20 THEN + INSERT INTO t1 VALUES('p1: case4: case6: on 20'); + ELSE + INSERT INTO t1 VALUES('p1: case4: case6: ERROR'); + END CASE; + END; + ELSE + INSERT INTO t1 VALUES('p1: case4: ERROR'); + END CASE; +END| + +CREATE PROCEDURE p2() +BEGIN + DECLARE i TINYINT DEFAULT 3; + + WHILE i > 0 DO + IF MOD(i, 2) = 0 THEN + SET @_test_session_var = 10; + ELSE + SET @_test_session_var = 'test'; + END IF; + + CASE @_test_session_var + WHEN 10 THEN + INSERT INTO t1 VALUES('p2: case: numerical type'); + WHEN 'test' THEN + INSERT INTO t1 VALUES('p2: case: string type'); + ELSE + INSERT INTO t1 VALUES('p2: case: ERROR'); + END CASE; + + SET i = i - 1; + END WHILE; +END| + +delimiter ;| + +CALL p1(10); +CALL p1(20); + +CALL p2(); + +SELECT * FROM t1; + +# +# Cleanup. +# + +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP TABLE t1; + +########################################################################### +# +# Test case for BUG#14161: Stored procedure cannot retrieve bigint unsigned. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#14161 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +# +# Test case. +# + +CREATE TABLE t1(col BIGINT UNSIGNED); + +INSERT INTO t1 VALUE(18446744073709551614); + +delimiter |; +CREATE PROCEDURE p1(IN arg BIGINT UNSIGNED) +BEGIN + SELECT arg; + SELECT * FROM t1; + SELECT * FROM t1 WHERE col = arg; +END| +delimiter ;| + +CALL p1(18446744073709551614); + +# +# Cleanup. +# + +DROP TABLE t1; +DROP PROCEDURE p1; + +########################################################################### +# +# Test case for BUG#13705: parameters to stored procedures are not verified. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#13705 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +# +# Test case. +# + +delimiter |; +CREATE PROCEDURE p1(x VARCHAR(10), y CHAR(3)) READS SQL DATA +BEGIN + SELECT x, y; +END| +delimiter ;| + +CALL p1('alpha', 'abc'); +CALL p1('alpha', 'abcdef'); + +# +# Cleanup. +# + +DROP PROCEDURE p1; + +########################################################################### +# +# Test case for BUG#13675: DATETIME/DATE type in store proc param seems to be +# converted as varbinary. +# +# TODO: test case failed. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#13675 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +# Test case. +# + +delimiter |; +CREATE PROCEDURE p1(x DATETIME) +BEGIN + CREATE TABLE t1 SELECT x; + SHOW CREATE TABLE t1; + DROP TABLE t1; +END| +delimiter ;| + +CALL p1(NOW()); + +CALL p1('test'); + +# +# Cleanup. +# + +DROP PROCEDURE p1; + +########################################################################### +# +# Test case for BUG#12976: Boolean values reversed in stored procedures? +# +# TODO: test case failed. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#12976 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +--enable_warnings + +# +# Test case. +# + +CREATE TABLE t1(b BIT(1)); + +INSERT INTO t1(b) VALUES(b'0'), (b'1'); + +delimiter |; +CREATE PROCEDURE p1() +BEGIN + SELECT HEX(b), + b = 0, + b = FALSE, + b IS FALSE, + b = 1, + b = TRUE, + b IS TRUE + FROM t1; +END| + +CREATE PROCEDURE p2() +BEGIN + DECLARE vb BIT(1); + SELECT b INTO vb FROM t1 WHERE b = 0; + + SELECT HEX(vb), + vb = 0, + vb = FALSE, + vb IS FALSE, + vb = 1, + vb = TRUE, + vb IS TRUE; + + SELECT b INTO vb FROM t1 WHERE b = 1; + + SELECT HEX(vb), + vb = 0, + vb = FALSE, + vb IS FALSE, + vb = 1, + vb = TRUE, + vb IS TRUE; +END| +delimiter ;| + +# The expected and correct result. + +call p1(); + +# The wrong result. Note that only hex(vb) works, but is printed with two +# digits for some reason in this case. + +call p2(); + +# +# Cleanup. +# + +DROP TABLE t1; +DROP PROCEDURE p1; +DROP PROCEDURE p2; + +########################################################################### +# +# Test case for BUG#9572: Stored procedures: variable type declarations +# ignored. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#9572 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; + +DROP PROCEDURE IF EXISTS p4; +DROP PROCEDURE IF EXISTS p5; +DROP PROCEDURE IF EXISTS p6; +--enable_warnings + +# +# Test case. +# + +SET @@sql_mode = 'traditional'; + +delimiter |; + +CREATE PROCEDURE p1() +BEGIN + DECLARE v TINYINT DEFAULT 1e200; + SELECT v; +END| + +CREATE PROCEDURE p2() +BEGIN + DECLARE v DECIMAL(5) DEFAULT 1e200; + SELECT v; +END| + +CREATE PROCEDURE p3() +BEGIN + DECLARE v CHAR(5) DEFAULT 'abcdef'; + SELECT v LIKE 'abc___'; +END| + +CREATE PROCEDURE p4(arg VARCHAR(2)) +BEGIN + DECLARE var VARCHAR(1); + SET var := arg; + SELECT arg, var; +END| + +CREATE PROCEDURE p5(arg CHAR(2)) +BEGIN + DECLARE var CHAR(1); + SET var := arg; + SELECT arg, var; +END| + +CREATE PROCEDURE p6(arg DECIMAL(2)) +BEGIN + DECLARE var DECIMAL(1); + SET var := arg; + SELECT arg, var; +END| + +delimiter ;| + +--error ER_WARN_DATA_OUT_OF_RANGE +CALL p1(); +--error ER_WARN_DATA_OUT_OF_RANGE +CALL p2(); +--error ER_DATA_TOO_LONG +CALL p3(); + +--error ER_DATA_TOO_LONG +CALL p4('aaa'); +--error ER_DATA_TOO_LONG +CALL p5('aa'); +--error ER_WARN_DATA_OUT_OF_RANGE +CALL p6(10); + +# +# Cleanup. +# + +SET @@sql_mode = 'ansi'; + +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP PROCEDURE p3; + +DROP PROCEDURE p4; +DROP PROCEDURE p5; +DROP PROCEDURE p6; + +########################################################################### +# +# Test case for BUG#9078: STORED PROCDURE: Decimal digits are not displayed +# when we use DECIMAL datatype. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#9078 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +# +# Test case. +# + +delimiter |; +CREATE PROCEDURE p1 (arg DECIMAL(64,2)) +BEGIN + DECLARE var DECIMAL(64,2); + + SET var = arg; + SELECT var; +END| +delimiter ;| + +CALL p1(1929); +CALL p1(1929.00); +CALL p1(1929.003); + +# +# Cleanup. +# + +DROP PROCEDURE p1; + +########################################################################### +# +# Test case for BUG#8768: Functions: For any unsigned data type, -ve values can +# be passed and returned. +# +# TODO: there is a bug here -- the function created in ANSI mode should not +# throw errors instead of warnings if called in TRADITIONAL mode. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#8768 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +# +# Test case. +# + +# Create a function in ANSI mode. + +delimiter |; +CREATE FUNCTION f1(arg TINYINT UNSIGNED) RETURNS TINYINT +BEGIN + RETURN arg; +END| +delimiter ;| + +SELECT f1(-2500); + +# Call in TRADITIONAL mode the function created in ANSI mode. + +SET @@sql_mode = 'traditional'; + +# TODO: a warning should be emitted here. +--error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(-2500); + +# Recreate the function in TRADITIONAL mode. + +DROP FUNCTION f1; + +delimiter |; +CREATE FUNCTION f1(arg TINYINT UNSIGNED) RETURNS TINYINT +BEGIN + RETURN arg; +END| +delimiter ;| + +--error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(-2500); + +# +# Cleanup. +# + +SET @@sql_mode = 'ansi'; + +DROP FUNCTION f1; + +########################################################################### +# +# Test case for BUG#8769: Functions: For Int datatypes, out of range values can +# be passed and returned. +# +# TODO: there is a bug here -- the function created in ANSI mode should not +# throw errors instead of warnings if called in TRADITIONAL mode. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#8769 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +# +# Test case. +# + +# Create a function in ANSI mode. + +delimiter |; +CREATE FUNCTION f1(arg MEDIUMINT) RETURNS MEDIUMINT +BEGIN + RETURN arg; +END| +delimiter ;| + +SELECT f1(8388699); + +# Call in TRADITIONAL mode the function created in ANSI mode. + +SET @@sql_mode = 'traditional'; + +# TODO: a warning should be emitted here. +--error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(8388699); + +# Recreate the function in TRADITIONAL mode. + +DROP FUNCTION f1; + +delimiter |; +CREATE FUNCTION f1(arg MEDIUMINT) RETURNS MEDIUMINT +BEGIN + RETURN arg; +END| +delimiter ;| + +--error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(8388699); + +# +# Cleanup. +# + +SET @@sql_mode = 'ansi'; + +DROP FUNCTION f1; + +########################################################################### +# +# Test case for BUG#8702: Stored Procedures: No Error/Warning shown for +# inappropriate data type matching. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#8702 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +# Test case. +# + +CREATE TABLE t1(col VARCHAR(255)); + +INSERT INTO t1(col) VALUES('Hello, world!'); + +delimiter |; +CREATE PROCEDURE p1() +BEGIN + DECLARE sp_var INTEGER; + + SELECT col INTO sp_var FROM t1 LIMIT 1; + SET @user_var = sp_var; + + SELECT sp_var; + SELECT @user_var; +END| +delimiter ;| + +CALL p1(); + +# +# Cleanup. +# + +DROP PROCEDURE p1; +DROP TABLE t1; + +########################################################################### +# +# Test case for BUG#12903: upper function does not work inside a function. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#12903 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +# Test case. +# + +CREATE TABLE t1(txt VARCHAR(255)); + +delimiter |; +CREATE FUNCTION f1(arg VARCHAR(255)) RETURNS VARCHAR(255) +BEGIN + DECLARE v1 VARCHAR(255); + DECLARE v2 VARCHAR(255); + + SET v1 = CONCAT(LOWER(arg), UPPER(arg)); + SET v2 = CONCAT(LOWER(v1), UPPER(v1)); + + INSERT INTO t1 VALUES(v1), (v2); + + RETURN CONCAT(LOWER(arg), UPPER(arg)); +END| +delimiter ;| + +SELECT f1('_aBcDe_'); + +SELECT * FROM t1; + +# +# Cleanup. +# + +DROP FUNCTION f1; +DROP TABLE t1; + +########################################################################### +# +# Test case for BUG#13808: ENUM type stored procedure parameter accepts +# non-enumerated data. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#13808 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +# +# Test case. +# + +delimiter |; + +CREATE PROCEDURE p1(arg ENUM('a', 'b')) +BEGIN + SELECT arg; +END| + +CREATE PROCEDURE p2(arg ENUM('a', 'b')) +BEGIN + DECLARE var ENUM('c', 'd') DEFAULT arg; + + SELECT arg, var; +END| + +CREATE FUNCTION f1(arg ENUM('a', 'b')) RETURNS ENUM('c', 'd') +BEGIN + RETURN arg; +END| + +delimiter ;| + +CALL p1('c'); + +CALL p2('a'); + +SELECT f1('a'); + +# +# Cleanup. +# + +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP FUNCTION f1; + +########################################################################### +# +# Test case for BUG#13909: Varchar Stored Procedure Parameter always BINARY +# string (ignores CHARACTER SET). +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#13909 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +--enable_warnings + +# +# Test case. +# + +delimiter |; + +CREATE PROCEDURE p1(arg VARCHAR(255)) +BEGIN + SELECT CHARSET(arg); +END| + +CREATE PROCEDURE p2(arg VARCHAR(255) CHARACTER SET UTF8) +BEGIN + SELECT CHARSET(arg); +END| + +delimiter ;| + +CALL p1('t'); +CALL p1(_UTF8 't'); + + +CALL p2('t'); +CALL p2(_LATIN1 't'); + +# +# Cleanup. +# + +DROP PROCEDURE p1; +DROP PROCEDURE p2; + +########################################################################### +# +# Test case for BUG#14188: BINARY variables have no 0x00 padding. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#14188 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +# +# Test case. +# + +delimiter |; +CREATE PROCEDURE p1(arg1 BINARY(2), arg2 VARBINARY(2)) +BEGIN + DECLARE var1 BINARY(2) DEFAULT 0x41; + DECLARE var2 VARBINARY(2) DEFAULT 0x42; + + SELECT HEX(arg1), HEX(arg2); + SELECT HEX(var1), HEX(var2); +END| +delimiter ;| + +CALL p1(0x41, 0x42); + +# +# Cleanup. +# + +DROP PROCEDURE p1; + +########################################################################### +# +# Test case for BUG#15148: Stored procedure variables accept non-scalar values. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#15148 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +# Test case. +# + +CREATE TABLE t1(col1 TINYINT, col2 TINYINT); + +INSERT INTO t1 VALUES(1, 2), (11, 12); + +delimiter |; +CREATE PROCEDURE p1(arg TINYINT) +BEGIN + SELECT arg; +END| +delimiter ;| + +--error ER_OPERAND_COLUMNS +CALL p1((1, 2)); + +--error ER_OPERAND_COLUMNS +CALL p1((SELECT * FROM t1 LIMIT 1)); + +--error ER_OPERAND_COLUMNS +CALL p1((SELECT col1, col2 FROM t1 LIMIT 1)); + +# +# Cleanup. +# + +DROP PROCEDURE p1; +DROP TABLE t1; + +########################################################################### +# +# Test case for BUG#13613: substring function in stored procedure. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#13613 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +# +# Test case. +# + +delimiter |; + +CREATE PROCEDURE p1(x VARCHAR(50)) +BEGIN + SET x = SUBSTRING(x, 1, 3); + SELECT x; +END| + +CREATE FUNCTION f1(x VARCHAR(50)) RETURNS VARCHAR(50) +BEGIN + RETURN SUBSTRING(x, 1, 3); +END| + +delimiter ;| + +CALL p1('abcdef'); + +SELECT f1('ABCDEF'); + +# +# Cleanup. +# + +DROP PROCEDURE p1; +DROP FUNCTION f1; + +########################################################################### +# +# Test case for BUG#13665: concat with '' produce incorrect results in SP. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#13665 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +# +# Test case. +# + +delimiter |; +CREATE FUNCTION f1() RETURNS VARCHAR(20000) +BEGIN + DECLARE var VARCHAR(2000); + + SET var = ''; + SET var = CONCAT(var, 'abc'); + SET var = CONCAT(var, ''); + + RETURN var; +END| +delimiter ;| + +SELECT f1(); + +# +# Cleanup. +# + +DROP FUNCTION f1; + + +# +# Bug#17226: Variable set in cursor on first iteration is assigned +# second iterations value +# +# The problem was in incorrect handling of local variables of type +# TEXT (BLOB). +# +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +delimiter |; +CREATE PROCEDURE p1() +BEGIN + DECLARE v_char VARCHAR(255); + DECLARE v_text TEXT DEFAULT ''; + + SET v_char = 'abc'; + + SET v_text = v_char; + + SET v_char = 'def'; + + SET v_text = concat(v_text, '|', v_char); + + SELECT v_text; +END| +delimiter ;| + +CALL p1(); + +DROP PROCEDURE p1; + +# End of 5.0 tests. diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test new file mode 100644 index 00000000000..fc6e8714a65 --- /dev/null +++ b/mysql-test/t/sp.test @@ -0,0 +1,6604 @@ +# +# Basic stored PROCEDURE tests +# +# Test cases for bugs are added at the end. See template there. +# +# Some tests that require --error go into sp-error.test +# Tests that require inndb go into sp_trans.test +# Tests that check privilege and security issues go to sp-security.test. +# Tests that require multiple connections, except security/privilege tests, +# go to sp-thread. +# Tests that uses 'goto' to into sp-goto.test (currently disabled) +# Tests that destroys system tables (e.g. mysql.proc) for error testing +# go to sp-destruct. + +use test; + +# Test tables +# +# t1 and t2 are reused throughout the file, and dropped at the end. +# t3 and up are created and dropped when needed. +# +--disable_warnings +drop table if exists t1,t2,t3,t4; +--enable_warnings +create table t1 ( + id char(16) not null default '', + data int not null +); +create table t2 ( + s char(16), + i int, + d double +); + + +# Single statement, no params. +--disable_warnings +drop procedure if exists foo42; +--enable_warnings +create procedure foo42() + insert into test.t1 values ("foo", 42); + +call foo42(); +select * from t1; +delete from t1; +drop procedure foo42; + + +# Single statement, two IN params. +--disable_warnings +drop procedure if exists bar; +--enable_warnings +create procedure bar(x char(16), y int) + insert into test.t1 values (x, y); + +call bar("bar", 666); +select * from t1; +delete from t1; +# Don't drop procedure yet... + + +# Now for multiple statements... +delimiter |; + +# Empty statement +--disable_warnings +drop procedure if exists empty| +--enable_warnings +create procedure empty() +begin +end| + +call empty()| +drop procedure empty| + +# Scope test. This is legal (warnings might be possible in the future, +# but for the time being, we just accept it). +--disable_warnings +drop procedure if exists scope| +--enable_warnings +create procedure scope(a int, b float) +begin + declare b int; + declare c float; + + begin + declare c int; + end; +end| + +drop procedure scope| + +# Two statements. +--disable_warnings +drop procedure if exists two| +--enable_warnings +create procedure two(x1 char(16), x2 char(16), y int) +begin + insert into test.t1 values (x1, y); + insert into test.t1 values (x2, y); +end| + +call two("one", "two", 3)| +select * from t1| +delete from t1| +drop procedure two| + + +# Simple test of local variables and SET. +--disable_warnings +drop procedure if exists locset| +--enable_warnings +create procedure locset(x char(16), y int) +begin + declare z1, z2 int; + set z1 = y; + set z2 = z1+2; + insert into test.t1 values (x, z2); +end| + +call locset("locset", 19)| +select * from t1| +delete from t1| +drop procedure locset| + + +# In some contexts local variables are not recognized +# (and in some, you have to qualify the identifier). +--disable_warnings +drop procedure if exists setcontext| +--enable_warnings +create procedure setcontext() +begin + declare data int default 2; + + insert into t1 (id, data) values ("foo", 1); + replace t1 set data = data, id = "bar"; + update t1 set id = "kaka", data = 3 where t1.data = data; +end| + +call setcontext()| +select * from t1| +delete from t1| +drop procedure setcontext| + + +# Set things to null +create table t3 ( d date, i int, f double, s varchar(32) )| + +--disable_warnings +drop procedure if exists nullset| +--enable_warnings +create procedure nullset() +begin + declare ld date; + declare li int; + declare lf double; + declare ls varchar(32); + + set ld = null, li = null, lf = null, ls = null; + insert into t3 values (ld, li, lf, ls); + + insert into t3 (i, f, s) values ((ld is null), 1, "ld is null"), + ((li is null), 1, "li is null"), + ((li = 0), null, "li = 0"), + ((lf is null), 1, "lf is null"), + ((lf = 0), null, "lf = 0"), + ((ls is null), 1, "ls is null"); +end| + +call nullset()| +select * from t3| +drop table t3| +drop procedure nullset| + + +# The peculiar (non-standard) mixture of variables types in SET. +--disable_warnings +drop procedure if exists mixset| +--enable_warnings +create procedure mixset(x char(16), y int) +begin + declare z int; + + set @z = y, z = 666, max_join_size = 100; + insert into test.t1 values (x, z); +end| + +call mixset("mixset", 19)| +show variables like 'max_join_size'| +select id,data,@z from t1| +delete from t1| +drop procedure mixset| + + +# Multiple CALL statements, one with OUT parameter. +--disable_warnings +drop procedure if exists zip| +--enable_warnings +create procedure zip(x char(16), y int) +begin + declare z int; + call zap(y, z); + call bar(x, z); +end| + +# SET local variables and OUT parameter. +--disable_warnings +drop procedure if exists zap| +--enable_warnings +create procedure zap(x int, out y int) +begin + declare z int; + set z = x+1, y = z; +end| + +call zip("zip", 99)| +select * from t1| +delete from t1| +drop procedure zip| +drop procedure bar| + +# Top-level OUT parameter +call zap(7, @zap)| +select @zap| + +drop procedure zap| + + +# "Deep" calls... +--disable_warnings +drop procedure if exists c1| +--enable_warnings +create procedure c1(x int) + call c2("c", x)| +--disable_warnings +drop procedure if exists c2| +--enable_warnings +create procedure c2(s char(16), x int) + call c3(x, s)| +--disable_warnings +drop procedure if exists c3| +--enable_warnings +create procedure c3(x int, s char(16)) + call c4("level", x, s)| +--disable_warnings +drop procedure if exists c4| +--enable_warnings +create procedure c4(l char(8), x int, s char(16)) + insert into t1 values (concat(l,s), x)| + +call c1(42)| +select * from t1| +delete from t1| +drop procedure c1| +drop procedure c2| +drop procedure c3| +drop procedure c4| + +# INOUT test +--disable_warnings +drop procedure if exists iotest| +--enable_warnings +create procedure iotest(x1 char(16), x2 char(16), y int) +begin + call inc2(x2, y); + insert into test.t1 values (x1, y); +end| + +--disable_warnings +drop procedure if exists inc2| +--enable_warnings +create procedure inc2(x char(16), y int) +begin + call inc(y); + insert into test.t1 values (x, y); +end| + +--disable_warnings +drop procedure if exists inc| +--enable_warnings +create procedure inc(inout io int) + set io = io + 1| + +call iotest("io1", "io2", 1)| +select * from t1| +delete from t1| +drop procedure iotest| +drop procedure inc2| + +# Propagating top-level @-vars +--disable_warnings +drop procedure if exists incr| +--enable_warnings +create procedure incr(inout x int) + call inc(x)| + +# Before +select @zap| +call incr(@zap)| +# After +select @zap| + +drop procedure inc| +drop procedure incr| + +# Call-by-value test +# The expected result is: +# ("cbv2", 4) +# ("cbv1", 4711) +--disable_warnings +drop procedure if exists cbv1| +--enable_warnings +create procedure cbv1() +begin + declare y int default 3; + + call cbv2(y+1, y); + insert into test.t1 values ("cbv1", y); +end| + +--disable_warnings +drop procedure if exists cbv2| +--enable_warnings +create procedure cbv2(y1 int, inout y2 int) +begin + set y2 = 4711; + insert into test.t1 values ("cbv2", y1); +end| + +call cbv1()| +select * from t1| +delete from t1| +drop procedure cbv1| +drop procedure cbv2| + + +# Subselect arguments + +insert into t2 values ("a", 1, 1.1), ("b", 2, 1.2), ("c", 3, 1.3)| + +--disable_warnings +drop procedure if exists sub1| +--enable_warnings +create procedure sub1(id char(16), x int) + insert into test.t1 values (id, x)| + +--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| +--enable_warnings +create function sub3(i int) returns int + return i+1| + +call sub1("sub1a", (select 7))| +call sub1("sub1b", (select max(i) from t2))| +--error ER_OPERAND_COLUMNS +call sub1("sub1c", (select i,d from t2 limit 1))| +call sub1("sub1d", (select 1 from (select 1) a))| +call sub2("sub2")| +select * from t1| +select sub3((select max(i) from t2))| +drop procedure sub1| +drop procedure sub2| +drop function sub3| +delete from t1| +delete from t2| + +# Basic tests of the flow control constructs + +# Just test on 'x'... +--disable_warnings +drop procedure if exists a0| +--enable_warnings +create procedure a0(x int) +while x do + set x = x-1; + insert into test.t1 values ("a0", x); +end while| + +call a0(3)| +select * from t1| +delete from t1| +drop procedure a0| + + +# The same, but with a more traditional test. +--disable_warnings +drop procedure if exists a| +--enable_warnings +create procedure a(x int) +while x > 0 do + set x = x-1; + insert into test.t1 values ("a", x); +end while| + +call a(3)| +select * from t1| +delete from t1| +drop procedure a| + + +# REPEAT +--disable_warnings +drop procedure if exists b| +--enable_warnings +create procedure b(x int) +repeat + insert into test.t1 values (repeat("b",3), x); + set x = x-1; +until x = 0 end repeat| + +call b(3)| +select * from t1| +delete from t1| +drop procedure b| + + +# Check that repeat isn't parsed the wrong way +--disable_warnings +drop procedure if exists b2| +--enable_warnings +create procedure b2(x int) +repeat(select 1 into outfile 'b2'); + insert into test.t1 values (repeat("b2",3), x); + set x = x-1; +until x = 0 end repeat| + +# We don't actually want to call it. +drop procedure b2| + + +# Labelled WHILE with ITERATE (pointless really) +--disable_warnings +drop procedure if exists c| +--enable_warnings +create procedure c(x int) +hmm: while x > 0 do + insert into test.t1 values ("c", x); + set x = x-1; + iterate hmm; + insert into test.t1 values ("x", x); +end while hmm| + +call c(3)| +select * from t1| +delete from t1| +drop procedure c| + + +# Labelled WHILE with LEAVE +--disable_warnings +drop procedure if exists d| +--enable_warnings +create procedure d(x int) +hmm: while x > 0 do + insert into test.t1 values ("d", x); + set x = x-1; + leave hmm; + insert into test.t1 values ("x", x); +end while| + +call d(3)| +select * from t1| +delete from t1| +drop procedure d| + + +# LOOP, with simple IF statement +--disable_warnings +drop procedure if exists e| +--enable_warnings +create procedure e(x int) +foo: loop + if x = 0 then + leave foo; + end if; + insert into test.t1 values ("e", x); + set x = x-1; +end loop foo| + +call e(3)| +select * from t1| +delete from t1| +drop procedure e| + + +# A full IF statement +--disable_warnings +drop procedure if exists f| +--enable_warnings +create procedure f(x int) +if x < 0 then + insert into test.t1 values ("f", 0); +elseif x = 0 then + insert into test.t1 values ("f", 1); +else + insert into test.t1 values ("f", 2); +end if| + +call f(-2)| +call f(0)| +call f(4)| +select * from t1| +delete from t1| +drop procedure f| + + +# This form of CASE is really just syntactic sugar for IF-ELSEIF-... +--disable_warnings +drop procedure if exists g| +--enable_warnings +create procedure g(x int) +case +when x < 0 then + insert into test.t1 values ("g", 0); +when x = 0 then + insert into test.t1 values ("g", 1); +else + insert into test.t1 values ("g", 2); +end case| + +call g(-42)| +call g(0)| +call g(1)| +select * from t1| +delete from t1| +drop procedure g| + + +# The "simple CASE" +--disable_warnings +drop procedure if exists h| +--enable_warnings +create procedure h(x int) +case x +when 0 then + insert into test.t1 values ("h0", x); +when 1 then + insert into test.t1 values ("h1", x); +else + insert into test.t1 values ("h?", x); +end case| + +call h(0)| +call h(1)| +call h(17)| +select * from t1| +delete from t1| +drop procedure h| + + +# It's actually possible to LEAVE a BEGIN-END block +--disable_warnings +drop procedure if exists i| +--enable_warnings +create procedure i(x int) +foo: +begin + if x = 0 then + leave foo; + end if; + insert into test.t1 values ("i", x); +end foo| + +call i(0)| +call i(3)| +select * from t1| +delete from t1| +drop procedure i| + + +# SELECT with one of more result set sent back to the clinet +insert into t1 values ("foo", 3), ("bar", 19)| +insert into t2 values ("x", 9, 4.1), ("y", -1, 19.2), ("z", 3, 2.2)| + +--disable_warnings +drop procedure if exists sel1| +--enable_warnings +create procedure sel1() +begin + select * from t1; +end| + +call sel1()| +drop procedure sel1| + +--disable_warnings +drop procedure if exists sel2| +--enable_warnings +create procedure sel2() +begin + select * from t1; + select * from t2; +end| + +call sel2()| +drop procedure sel2| +delete from t1| +delete from t2| + +# SELECT INTO local variables +--disable_warnings +drop procedure if exists into_test| +--enable_warnings +create procedure into_test(x char(16), y int) +begin + insert into test.t1 values (x, y); + select id,data into x,y from test.t1 limit 1; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +call into_test("into", 100)| +select * from t1| +delete from t1| +drop procedure into_test| + + +# SELECT INTO with a mix of local and global variables +--disable_warnings +drop procedure if exists into_tes2| +--enable_warnings +create procedure into_test2(x char(16), y int) +begin + insert into test.t1 values (x, y); + select id,data into x,@z from test.t1 limit 1; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +call into_test2("into", 100)| +select id,data,@z from t1| +delete from t1| +drop procedure into_test2| + + +# SELECT * INTO ... (bug test) +--disable_warnings +drop procedure if exists into_test3| +--enable_warnings +create procedure into_test3() +begin + declare x char(16); + declare y int; + + select * into x,y from test.t1 limit 1; + insert into test.t2 values (x, y, 0.0); +end| + +insert into t1 values ("into3", 19)| +# Two call needed for bug test +call into_test3()| +call into_test3()| +select * from t2| +delete from t1| +delete from t2| +drop procedure into_test3| + + +# SELECT INTO with no data is a warning ("no data", which we will +# not see normally). When not caught, execution proceeds. +--disable_warnings +drop procedure if exists into_test4| +--enable_warnings +create procedure into_test4() +begin + declare x int; + + select data into x from test.t1 limit 1; + insert into test.t3 values ("into4", x); +end| + +delete from t1| +create table t3 ( s char(16), d int)| +call into_test4()| +select * from t3| +insert into t1 values ("i4", 77)| +call into_test4()| +select * from t3| +delete from t1| +drop table t3| +drop procedure into_test4| + + +# These two (and the two procedures above) caused an assert() to fail in +# sql_base.cc:lock_tables() at some point. +--disable_warnings +drop procedure if exists into_outfile| +--enable_warnings +--replace_result $MYSQLTEST_VARDIR .. +eval create procedure into_outfile(x char(16), y int) +begin + insert into test.t1 values (x, y); + select * into outfile "$MYSQLTEST_VARDIR/tmp/spout" from test.t1; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +--system rm -f $MYSQLTEST_VARDIR/tmp/spout +call into_outfile("ofile", 1)| +--system rm -f $MYSQLTEST_VARDIR/tmp/spout +delete from t1| +drop procedure into_outfile| + +--disable_warnings +drop procedure if exists into_dumpfile| +--enable_warnings +--replace_result $MYSQLTEST_VARDIR .. +eval create procedure into_dumpfile(x char(16), y int) +begin + insert into test.t1 values (x, y); + select * into dumpfile "$MYSQLTEST_VARDIR/tmp/spdump" from test.t1 limit 1; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +--system rm -f $MYSQLTEST_VARDIR/tmp/spdump +call into_dumpfile("dfile", 1)| +--system rm -f $MYSQLTEST_VARDIR/tmp/spdump +delete from t1| +drop procedure into_dumpfile| + +--disable_warnings +drop procedure if exists create_select| +--enable_warnings +create procedure create_select(x char(16), y int) +begin + insert into test.t1 values (x, y); + create temporary table test.t3 select * from test.t1; + insert into test.t3 values (concat(x, "2"), y+2); +end| + +call create_select("cs", 90)| +select * from t1, t3| +drop table t3| +delete from t1| +drop procedure create_select| + + +# A minimal, constant FUNCTION. +--disable_warnings +drop function if exists e| +--enable_warnings +create function e() returns double + return 2.7182818284590452354| + +set @e = e()| +select e(), @e| + +# A minimal function with one argument +--disable_warnings +drop function if exists inc| +--enable_warnings +create function inc(i int) returns int + return i+1| + +select inc(1), inc(99), inc(-71)| + +# A minimal function with two arguments +--disable_warnings +drop function if exists mul| +--enable_warnings +create function mul(x int, y int) returns int + return x*y| + +select mul(1,1), mul(3,5), mul(4711, 666)| + +# A minimal string function +--disable_warnings +drop function if exists append| +--enable_warnings +create function append(s1 char(8), s2 char(8)) returns char(16) + return concat(s1, s2)| + +select append("foo", "bar")| + +# A function with flow control +--disable_warnings +drop function if exists fac| +--enable_warnings +create function fac(n int unsigned) returns bigint unsigned +begin + declare f bigint unsigned default 1; + + while n > 1 do + set f = f * n; + set n = n - 1; + end while; + return f; +end| + +select fac(1), fac(2), fac(5), fac(10)| + +# Nested calls +--disable_warnings +drop function if exists fun| +--enable_warnings +create function fun(d double, i int, u int unsigned) returns double + return mul(inc(i), fac(u)) / e()| + +select fun(2.3, 3, 5)| + + +# Various function calls in differen statements + +insert into t2 values (append("xxx", "yyy"), mul(4,3), e())| +insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))| + +# Disable PS because double's give a bit different values +--disable_ps_protocol +select * from t2 where s = append("a", "b")| +select * from t2 where i = mul(4,3) or i = mul(mul(3,4),2)| +select * from t2 where d = e()| +select * from t2| +--enable_ps_protocol +delete from t2| + +drop function e| +drop function inc| +drop function mul| +drop function append| +drop function fun| + + +# +# CONDITIONs and HANDLERs +# + +--disable_warnings +drop procedure if exists hndlr1| +--enable_warnings +create procedure hndlr1(val int) +begin + declare x int default 0; + declare foo condition for 1136; + declare bar condition for sqlstate '42S98'; # Just for testing syntax + declare zip condition for sqlstate value '42S99'; # Just for testing syntax + declare continue handler for foo set x = 1; + + insert into test.t1 values ("hndlr1", val, 2); # Too many values + if (x) then + insert into test.t1 values ("hndlr1", val); # This instead then + end if; +end| + +call hndlr1(42)| +select * from t1| +delete from t1| +drop procedure hndlr1| + +--disable_warnings +drop procedure if exists hndlr2| +--enable_warnings +create procedure hndlr2(val int) +begin + declare x int default 0; + + begin + declare exit handler for sqlstate '21S01' set x = 1; + + insert into test.t1 values ("hndlr2", val, 2); # Too many values + end; + + insert into test.t1 values ("hndlr2", x); +end| + +call hndlr2(42)| +select * from t1| +delete from t1| +drop procedure hndlr2| + + +--disable_warnings +drop procedure if exists hndlr3| +--enable_warnings +create procedure hndlr3(val int) +begin + declare x int default 0; + declare continue handler for sqlexception # Any error + begin + declare z int; + + set z = 2 * val; + set x = 1; + end; + + if val < 10 then + begin + declare y int; + + set y = val + 10; + insert into test.t1 values ("hndlr3", y, 2); # Too many values + if x then + insert into test.t1 values ("hndlr3", y); + end if; + end; + end if; +end| + +call hndlr3(3)| +select * from t1| +delete from t1| +drop procedure hndlr3| + + +# Variables might be uninitialized when using handlers +# (Otherwise the compiler can detect if a variable is not set, but +# not in this case.) +create table t3 ( id char(16), data int )| + +--disable_warnings +drop procedure if exists hndlr4| +--enable_warnings +create procedure hndlr4() +begin + declare x int default 0; + declare val int; # No default + declare continue handler for sqlstate '02000' set x=1; + + select data into val from test.t3 where id='z' limit 1; # No hits + + insert into test.t3 values ('z', val); +end| + +call hndlr4()| +select * from t3| +drop table t3| +drop procedure hndlr4| + + +# +# Cursors +# +--disable_warnings +drop procedure if exists cur1| +--enable_warnings +create procedure cur1() +begin + declare a char(16); + declare b int; + declare c double; + declare done int default 0; + declare c cursor for select * from test.t2; + declare continue handler for sqlstate '02000' set done = 1; + + open c; + repeat + fetch c into a, b, c; + if not done then + insert into test.t1 values (a, b+c); + end if; + until done end repeat; + close c; +end| + +insert into t2 values ("foo", 42, -1.9), ("bar", 3, 12.1), ("zap", 666, -3.14)| +call cur1()| +select * from t1| +drop procedure cur1| + +create table t3 ( s char(16), i int )| + +--disable_warnings +drop procedure if exists cur2| +--enable_warnings +create procedure cur2() +begin + declare done int default 0; + declare c1 cursor for select id,data from test.t1; + declare c2 cursor for select i from test.t2; + declare continue handler for sqlstate '02000' set done = 1; + + open c1; + open c2; + repeat + begin + declare a char(16); + declare b,c int; + + fetch from c1 into a, b; + fetch next from c2 into c; + if not done then + if b < c then + insert into test.t3 values (a, b); + else + insert into test.t3 values (a, c); + end if; + end if; + end; + until done end repeat; + close c1; + close c2; +end| + +call cur2()| +select * from t3| +delete from t1| +delete from t2| +drop table t3| +drop procedure cur2| + + +# The few characteristics we parse +--disable_warnings +drop procedure if exists chistics| +--enable_warnings +create procedure chistics() + language sql + modifies sql data + not deterministic + sql security definer + comment 'Characteristics procedure test' + insert into t1 values ("chistics", 1)| + +show create procedure chistics| +# Call it, just to make sure. +call chistics()| +select * from t1| +delete from t1| +alter procedure chistics sql security invoker| +show create procedure chistics| +drop procedure chistics| + +--disable_warnings +drop function if exists chistics| +--enable_warnings +create function chistics() returns int + language sql + deterministic + sql security invoker + comment 'Characteristics procedure test' + return 42| + +show create function chistics| +# Call it, just to make sure. +select chistics()| +alter function chistics + no sql + comment 'Characteristics function test'| +show create function chistics| +drop function chistics| + + +# Check mode settings +insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3)| + +set @@sql_mode = 'ANSI'| +delimiter $| +--disable_warnings +drop procedure if exists modes$ +--enable_warnings +create procedure modes(out c1 int, out c2 int) +begin + declare done int default 0; + declare x int; + declare c cursor for select data from t1; + declare continue handler for sqlstate '02000' set done = 1; + + select 1 || 2 into c1; + set c2 = 0; + open c; + repeat + fetch c into x; + if not done then + set c2 = c2 + 1; + end if; + until done end repeat; + close c; +end$ +delimiter |$ +set @@sql_mode = ''| + +set sql_select_limit = 1| +call modes(@c1, @c2)| +set sql_select_limit = default| + +select @c1, @c2| +delete from t1| +drop procedure modes| + + +# Check that dropping a database without routines works. +# (Dropping with routines is tested in sp-security.test) +# First an empty db. +create database sp_db1| +drop database sp_db1| + +# Again, with a table. +create database sp_db2| +use sp_db2| +# Just put something in here... +create table t3 ( s char(4), t int )| +insert into t3 values ("abcd", 42), ("dcba", 666)| +use test| +drop database sp_db2| + +# And yet again, with just a procedure. +create database sp_db3| +use sp_db3| +--disable_warnings +drop procedure if exists dummy| +--enable_warnings +create procedure dummy(out x int) + set x = 42| +use test| +drop database sp_db3| +# Check that it's gone +select type,db,name from mysql.proc where db = 'sp_db3'| + + +# ROW_COUNT() function after a CALL +# We test the other cases here too, although it's not strictly SP specific +--disable_warnings +drop procedure if exists rc| +--enable_warnings +create procedure rc() +begin + delete from t1; + insert into t1 values ("a", 1), ("b", 2), ("c", 3); +end| + +call rc()| +select row_count()| +--disable_ps_protocol +update t1 set data=42 where id = "b"; +select row_count()| +--enable_ps_protocol +delete from t1| +select row_count()| +delete from t1| +select row_count()| +select * from t1| +select row_count()| +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 function if exists f9| +drop function if exists f10| +drop function if exists f11| +drop function if exists f12_1| +drop function if exists f12_2| +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)| +# Since currently recursive functions are disallowed ER_SP_NO_RECURSION +# error will be returned, once we will allow them error about +# insufficient number of locked tables will be returned instead. +--error ER_SP_NO_RECURSION +select f5(2)| +--error ER_SP_NO_RECURSION +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| + +# +# 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)| +--error ER_SP_NO_RECURSION +select f1()| +--error ER_SP_NO_RECURSION +select * from v1| +--error ER_SP_NO_RECURSION +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. +# +lock tables t1 read, t1 as t11 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, t1| +--error 1100 +select f4()| +unlock tables| + +# Tests for handling of temporary tables in functions. +# +# Unlike for permanent tables we should be able to create, use +# and drop such tables in functions. +# +# Simplest function using temporary table. It is also test case for bug +# #12198 "Temporary table aliasing does not work inside stored functions" +create function f9() returns int +begin + declare a, b int; + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + set a:= (select count(*) from t3); + set b:= (select count(*) from t3 t3_alias); + return a + b; +end| +# This will emit warning as t3 was not existing before. +select f9()| +select f9() from t1 limit 1| + +# Function which uses both temporary and permanent tables. +create function f10() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 select id from t4; + return (select count(*) from t3); +end| +# Check that we don't ignore completely tables used in function +--error ER_NO_SUCH_TABLE +select f10()| +create table t4 as select 1 as id| +select f10()| + +# Practical cases which we don't handle well (yet) +# +# Function which does not work because of well-known and documented +# limitation of MySQL. We can't use the several instances of the +# same temporary table in statement. +create function f11() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + return (select count(*) from t3 as a, t3 as b); +end| +--error ER_CANT_REOPEN_TABLE +select f11()| +--error ER_CANT_REOPEN_TABLE +select f11() from t1| +# We don't handle temporary tables used by nested functions well +create function f12_1() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + return f12_2(); +end| +create function f12_2() returns int + return (select count(*) from t3)| +# We need clean start to get error +drop temporary table t3| +--error ER_NO_SUCH_TABLE +select f12_1()| +--error ER_NO_SUCH_TABLE +select f12_1() from t1 limit 1| + +# 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 function f9| +drop function f10| +drop function f11| +drop function f12_1| +drop function f12_2| +drop view v0| +drop view v1| +drop view v2| +delete from t1 | +delete from t2 | +drop table t4| + +# End of non-bug tests + + +# +# Some "real" examples +# + +# fac + +--disable_warnings +drop table if exists t3| +--enable_warnings +create table t3 (n int unsigned not null primary key, f bigint unsigned)| + +--disable_warnings +drop procedure if exists ifac| +--enable_warnings +create procedure ifac(n int unsigned) +begin + declare i int unsigned default 1; + + if n > 20 then + set n = 20; # bigint overflow otherwise + end if; + while i <= n do + begin + insert into test.t3 values (i, fac(i)); + set i = i + 1; + end; + end while; +end| + +call ifac(20)| +select * from t3| +drop table t3| +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show function status like '%f%'| +drop procedure ifac| +drop function fac| +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show function status like '%f%'| + + +# primes + +--disable_warnings +drop table if exists t3| +--enable_warnings + +create table t3 ( + i int unsigned not null primary key, + p bigint unsigned not null +)| + +insert into t3 values + ( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13), + ( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31), + (10, 37), (11, 41), (12, 43), (13, 47), (14, 53), + (15, 59), (16, 61), (17, 67), (18, 71), (19, 73), + (20, 79), (21, 83), (22, 89), (23, 97), (24, 101), + (25, 103), (26, 107), (27, 109), (28, 113), (29, 127), + (30, 131), (31, 137), (32, 139), (33, 149), (34, 151), + (35, 157), (36, 163), (37, 167), (38, 173), (39, 179), + (40, 181), (41, 191), (42, 193), (43, 197), (44, 199)| + +--disable_warnings +drop procedure if exists opp| +--enable_warnings +create procedure opp(n bigint unsigned, out pp bool) +begin + declare r double; + declare b, s bigint unsigned default 0; + + set r = sqrt(n); + + again: + loop + if s = 45 then + set b = b+200, s = 0; + else + begin + declare p bigint unsigned; + + select t.p into p from test.t3 t where t.i = s; + if b+p > r then + set pp = 1; + leave again; + end if; + if mod(n, b+p) = 0 then + set pp = 0; + leave again; + end if; + set s = s+1; + end; + end if; + end loop; +end| + +--disable_warnings +drop procedure if exists ip| +--enable_warnings +create procedure ip(m int unsigned) +begin + declare p bigint unsigned; + declare i int unsigned; + + set i=45, p=201; + + while i < m do + begin + declare pp bool default 0; + + call opp(p, pp); + if pp then + insert into test.t3 values (i, p); + set i = i+1; + end if; + set p = p+2; + end; + end while; +end| +show create procedure opp| +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like '%p%'| + +# This isn't the fastest way in the world to compute prime numbers, so +# don't be too ambitious. ;-) +call ip(200)| +# We don't want to select the entire table here, just pick a few +# examples. +# The expected result is: +# i p +# --- ---- +# 45 211 +# 100 557 +# 199 1229 +select * from t3 where i=45 or i=100 or i=199| +drop table t3| +drop procedure opp| +drop procedure ip| +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like '%p%'| + + +# Fibonacci, for recursion test. (Yet Another Numerical series :) +# +--disable_warnings +drop table if exists t3| +--enable_warnings +create table t3 ( f bigint unsigned not null )| + +# We deliberately do it the awkward way, fetching the last two +# values from the table, in order to exercise various statements +# and table accesses at each turn. +--disable_warnings +drop procedure if exists fib| +--enable_warnings +create procedure fib(n int unsigned) +begin + if n > 1 then + begin + declare x, y bigint unsigned; + declare c cursor for select f from t3 order by f desc limit 2; + + open c; + fetch c into y; + fetch c into x; + close c; + insert into t3 values (x+y); + call fib(n-1); + end; + end if; +end| + +# Enable recursion +set @@max_sp_recursion_depth= 20| + +# Minimum test: recursion of 3 levels + +insert into t3 values (0), (1)| + +call fib(3)| + +select * from t3 order by f asc| + +delete from t3| + +# The original test, 20 levels, ran into memory limits on some machines +# and builds. Try 10 instead... + +insert into t3 values (0), (1)| + +call fib(10)| + +select * from t3 order by f asc| +drop table t3| +drop procedure fib| +set @@max_sp_recursion_depth= 0| + +# +# Comment & suid +# + +--disable_warnings +drop procedure if exists bar| +--enable_warnings +create procedure bar(x char(16), y int) + comment "111111111111" sql security invoker + insert into test.t1 values (x, y)| +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like 'bar'| +alter procedure bar comment "2222222222" sql security definer| +alter procedure bar comment "3333333333"| +alter procedure bar| +show create procedure bar| +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like 'bar'| +drop procedure bar| + +# +# rexecution +# +--disable_warnings +drop procedure if exists p1| +--enable_warnings +create procedure p1 () + select (select s1 from t3) from t3| + +create table t3 (s1 int)| + +call p1()| +insert into t3 values (1)| +call p1()| +drop procedure p1| +drop table t3| + +# +# backticks +# +--disable_warnings +drop function if exists foo| +--enable_warnings +create function `foo` () returns int + return 5| +select `foo` ()| +drop function `foo`| + +# +# Implicit LOCK/UNLOCK TABLES for table access in functions +# + +--disable_warnings +drop function if exists t1max| +--enable_warnings +create function t1max() returns int +begin + declare x int; + select max(data) into x from t1; + return x; +end| + +insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)| +select t1max()| +drop function t1max| + +create table t3 ( + v char(16) not null primary key, + c int unsigned not null +)| + +create function getcount(s char(16)) returns int +begin + declare x int; + + select count(*) into x from t3 where v = s; + if x = 0 then + insert into t3 values (s, 1); + else + update t3 set c = c+1 where v = s; + end if; + return x; +end| + +select * from t1 where data = getcount("bar")| +select * from t3| +select getcount("zip")| +select getcount("zip")| +select * from t3| +select getcount(id) from t1 where data = 3| +select getcount(id) from t1 where data = 5| +select * from t3| +drop table t3| +drop function getcount| + + +# Test cases for different combinations of condition handlers in nested +# begin-end blocks in stored procedures. +# +# Note that the standard specifies that the most specific handler should +# be triggered even if it's an outer handler masked by a less specific +# handler in an inner block. +# Note also that '02000' is more specific than NOT FOUND; there might be +# other '02xxx' states, even if we currently do not issue them in any +# situation (e.g. '02001'). +# +# The combinations we test are these: +# +# Inner +# errcode sqlstate not found sqlwarning sqlexception +# Outer +------------+------------+------------+------------+------------+ +#errcode | h_ee (i) | h_es (o) | h_en (o) | h_ew (o) | h_ex (o) | +#sqlstate | h_se (i) | h_ss (i) | h_sn (o) | h_sw (o) | h_sx (o) | +#not found | h_ne (i) | h_ns (i) | h_nn (i) | | | +#sqlwarning | h_we (i) | h_ws (i) | | h_ww (i) | | +#sqlexception | h_xe (i) | h_xs (i) | | | h_xx (i) | +# +------------+---------------------------------------------------+ +# +# (i) means that the inner handler is the one that should be invoked, +# (o) means that the outer handler should be invoked. +# +# ('not found', 'sqlwarning' and 'sqlexception' are mutually exclusive, hence +# no tests for those combinations.) +# + +--disable_warnings +drop table if exists t3| +drop procedure if exists h_ee| +drop procedure if exists h_es| +drop procedure if exists h_en| +drop procedure if exists h_ew| +drop procedure if exists h_ex| +drop procedure if exists h_se| +drop procedure if exists h_ss| +drop procedure if exists h_sn| +drop procedure if exists h_sw| +drop procedure if exists h_sx| +drop procedure if exists h_ne| +drop procedure if exists h_ns| +drop procedure if exists h_nn| +drop procedure if exists h_we| +drop procedure if exists h_ws| +drop procedure if exists h_ww| +drop procedure if exists h_xe| +drop procedure if exists h_xs| +drop procedure if exists h_xx| +--enable_warnings + +# smallint - to get out of range warnings +# primary key - to get constraint errors +create table t3 (a smallint primary key)| + +insert into t3 (a) values (1)| + +create procedure h_ee() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (bad)' as 'h_ee'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_ee'; + + insert into t3 values (1); + end; +end| + +create procedure h_es() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (good)' as 'h_es'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (bad)' as 'h_es'; + + insert into t3 values (1); + end; +end| + +create procedure h_en() + deterministic +begin + declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA + select 'Outer (good)' as 'h_en'; + + begin + declare x int; + declare continue handler for sqlstate '02000' -- no data + select 'Inner (bad)' as 'h_en'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_ew() + deterministic +begin + declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE + select 'Outer (good)' as 'h_ew'; + + begin + declare continue handler for sqlwarning + select 'Inner (bad)' as 'h_ew'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ex() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (good)' as 'h_ex'; + + begin + declare continue handler for sqlexception + select 'Inner (bad)' as 'h_ex'; + + insert into t3 values (1); + end; +end| + +create procedure h_se() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (bad)' as 'h_se'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_se'; + + insert into t3 values (1); + end; +end| + +create procedure h_ss() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (bad)' as 'h_ss'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_ss'; + + insert into t3 values (1); + end; +end| + +create procedure h_sn() + deterministic +begin + -- Note: '02000' is more specific than NOT FOUND ; + -- there might be other not found states + declare continue handler for sqlstate '02000' -- no data + select 'Outer (good)' as 'h_sn'; + + begin + declare x int; + declare continue handler for not found + select 'Inner (bad)' as 'h_sn'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_sw() + deterministic +begin + -- data exception - numeric value out of range + declare continue handler for sqlstate '22003' + select 'Outer (good)' as 'h_sw'; + + begin + declare continue handler for sqlwarning + select 'Inner (bad)' as 'h_sw'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_sx() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (good)' as 'h_sx'; + + begin + declare continue handler for sqlexception + select 'Inner (bad)' as 'h_sx'; + + insert into t3 values (1); + end; +end| + +create procedure h_ne() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_ne'; + + begin + declare x int; + declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA + select 'Inner (good)' as 'h_ne'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_ns() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_ns'; + + begin + declare x int; + declare continue handler for sqlstate '02000' -- no data + select 'Inner (good)' as 'h_ns'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_nn() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_nn'; + + begin + declare x int; + declare continue handler for not found + select 'Inner (good)' as 'h_nn'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_we() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_we'; + + begin + declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE + select 'Inner (good)' as 'h_we'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ws() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_ws'; + + begin + -- data exception - numeric value out of range + declare continue handler for sqlstate '22003' + select 'Inner (good)' as 'h_ws'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ww() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_ww'; + + begin + declare continue handler for sqlwarning + select 'Inner (good)' as 'h_ww'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_xe() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xe'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_xe'; + + insert into t3 values (1); + end; +end| + +create procedure h_xs() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xs'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_xs'; + + insert into t3 values (1); + end; +end| + +create procedure h_xx() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xx'; + + begin + declare continue handler for sqlexception + select 'Inner (good)' as 'h_xx'; + + insert into t3 values (1); + end; +end| + +call h_ee()| +call h_es()| +call h_en()| +call h_ew()| +call h_ex()| +call h_se()| +call h_ss()| +call h_sn()| +call h_sw()| +call h_sx()| +call h_ne()| +call h_ns()| +call h_nn()| +call h_we()| +call h_ws()| +call h_ww()| +call h_xe()| +call h_xs()| +call h_xx()| + +drop table t3| +drop procedure h_ee| +drop procedure h_es| +drop procedure h_en| +drop procedure h_ew| +drop procedure h_ex| +drop procedure h_se| +drop procedure h_ss| +drop procedure h_sn| +drop procedure h_sw| +drop procedure h_sx| +drop procedure h_ne| +drop procedure h_ns| +drop procedure h_nn| +drop procedure h_we| +drop procedure h_ws| +drop procedure h_ww| +drop procedure h_xe| +drop procedure h_xs| +drop procedure h_xx| + + +# +# Test cases for old bugs +# + +# +# BUG#822 +# +--disable_warnings +drop procedure if exists bug822| +--enable_warnings +create procedure bug822(a_id char(16), a_data int) +begin + declare n int; + select count(*) into n from t1 where id = a_id and data = a_data; + if n = 0 then + insert into t1 (id, data) values (a_id, a_data); + end if; +end| + +delete from t1| +call bug822('foo', 42)| +call bug822('foo', 42)| +call bug822('bar', 666)| +select * from t1| +delete from t1| +drop procedure bug822| + +# +# BUG#1495 +# +--disable_warnings +drop procedure if exists bug1495| +--enable_warnings +create procedure bug1495() +begin + declare x int; + + select data into x from t1 order by id limit 1; + if x > 10 then + insert into t1 values ("less", x-10); + else + insert into t1 values ("more", x+10); + end if; +end| + +insert into t1 values ('foo', 12)| +call bug1495()| +delete from t1 where id='foo'| +insert into t1 values ('bar', 7)| +call bug1495()| +delete from t1 where id='bar'| +select * from t1| +delete from t1| +drop procedure bug1495| + +# +# BUG#1547 +# +--disable_warnings +drop procedure if exists bug1547| +--enable_warnings +create procedure bug1547(s char(16)) +begin + declare x int; + + select data into x from t1 where s = id limit 1; + if x > 10 then + insert into t1 values ("less", x-10); + else + insert into t1 values ("more", x+10); + end if; +end| + +insert into t1 values ("foo", 12), ("bar", 7)| +call bug1547("foo")| +call bug1547("bar")| +select * from t1| +delete from t1| +drop procedure bug1547| + +# +# BUG#1656 +# +--disable_warnings +drop table if exists t70| +--enable_warnings +create table t70 (s1 int,s2 int)| +insert into t70 values (1,2)| + +--disable_warnings +drop procedure if exists bug1656| +--enable_warnings +create procedure bug1656(out p1 int, out p2 int) + select * into p1, p1 from t70| + +call bug1656(@1, @2)| +select @1, @2| +drop table t70| +drop procedure bug1656| + +# +# BUG#1862 +# +create table t3(a int)| + +--disable_warnings +drop procedure if exists bug1862| +--enable_warnings +create procedure bug1862() +begin + insert into t3 values(2); + flush tables; +end| + +call bug1862()| +# the second call caused a segmentation +call bug1862()| +select * from t3| +drop table t3| +drop procedure bug1862| + +# +# BUG#1874 +# +--disable_warnings +drop procedure if exists bug1874| +--enable_warnings +create procedure bug1874() +begin + declare x int; + declare y double; + select max(data) into x from t1; + insert into t2 values ("max", x, 0); + select min(data) into x from t1; + insert into t2 values ("min", x, 0); + select sum(data) into x from t1; + insert into t2 values ("sum", x, 0); + select avg(data) into y from t1; + insert into t2 values ("avg", 0, y); +end| + +insert into t1 (data) values (3), (1), (5), (9), (4)| +call bug1874()| +select * from t2| +delete from t1| +delete from t2| +drop procedure bug1874| + +# +# BUG#2260 +# +--disable_warnings +drop procedure if exists bug2260| +--enable_warnings +create procedure bug2260() +begin + declare v1 int; + declare c1 cursor for select data from t1; + declare continue handler for not found set @x2 = 1; + + open c1; + fetch c1 into v1; + set @x2 = 2; + close c1; +end| + +call bug2260()| +select @x2| +drop procedure bug2260| + +# +# BUG#2267 "Lost connect if stored procedure has SHOW FUNCTION STATUS" +# +--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| +drop function if exists bug2267_4| +--enable_warnings +create procedure bug2267_4() +begin + show create function bug2267_4; +end| +create function bug2267_4() returns int return 100| + +--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| +drop function bug2267_4| + +# +# BUG#2227 +# +--disable_warnings +drop procedure if exists bug2227| +--enable_warnings +create procedure bug2227(x int) +begin + declare y float default 2.6; + declare z char(16) default "zzz"; + + select 1.3, x, y, 42, z; +end| + +call bug2227(9)| +drop procedure bug2227| + +# +# BUG#2614 "Stored procedure with INSERT ... SELECT that does not +# contain any tables crashes server" +# +--disable_warnings +drop procedure if exists bug2614| +--enable_warnings +create procedure bug2614() +begin + drop table if exists t3; + create table t3 (id int default '0' not null); + insert into t3 select 12; + insert into t3 select * from t3; +end| + +--disable_warnings +call bug2614()| +--enable_warnings +call bug2614()| +drop table t3| +drop procedure bug2614| + +# +# BUG#2674 +# +--disable_warnings +drop function if exists bug2674| +--enable_warnings +create function bug2674() returns int + return @@sort_buffer_size| + +set @osbs = @@sort_buffer_size| +set @@sort_buffer_size = 262000| +select bug2674()| +drop function bug2674| +set @@sort_buffer_size = @osbs| + +# +# BUG#3259 +# +--disable_warnings +drop procedure if exists bug3259_1 | +--enable_warnings +create procedure bug3259_1 () begin end| +--disable_warnings +drop procedure if exists BUG3259_2 | +--enable_warnings +create procedure BUG3259_2 () begin end| +--disable_warnings +drop procedure if exists Bug3259_3 | +--enable_warnings +create procedure Bug3259_3 () begin end| + +call BUG3259_1()| +call BUG3259_1()| +call bug3259_2()| +call Bug3259_2()| +call bug3259_3()| +call bUG3259_3()| + +drop procedure bUg3259_1| +drop procedure BuG3259_2| +drop procedure BUG3259_3| + +# +# BUG#2772 +# +--disable_warnings +drop function if exists bug2772| +--enable_warnings +create function bug2772() returns char(10) character set latin2 + return 'a'| + +select bug2772()| +drop function bug2772| + +# +# BUG#2776 +# +--disable_warnings +drop procedure if exists bug2776_1| +--enable_warnings +create procedure bug2776_1(out x int) +begin + declare v int; + + set v = default; + set x = v; +end| + +--disable_warnings +drop procedure if exists bug2776_2| +--enable_warnings +create procedure bug2776_2(out x int) +begin + declare v int default 42; + + set v = default; + set x = v; +end| + +set @x = 1| +call bug2776_1(@x)| +select @x| +call bug2776_2(@x)| +select @x| +drop procedure bug2776_1| +drop procedure bug2776_2| + +# +# BUG#2780 +# +create table t3 (s1 smallint)| + +insert into t3 values (123456789012)| + +--disable_warnings +drop procedure if exists bug2780| +--enable_warnings +create procedure bug2780() +begin + declare exit handler for sqlwarning set @x = 1; + + set @x = 0; + insert into t3 values (123456789012); + insert into t3 values (0); +end| + +call bug2780()| +select @x| +select * from t3| + +drop procedure bug2780| +drop table t3| + +# +# BUG#1863 +# +create table t3 (content varchar(10) )| +insert into t3 values ("test1")| +insert into t3 values ("test2")| +create table t4 (f1 int, rc int, t3 int)| + +--disable_warnings +drop procedure if exists bug1863| +--enable_warnings +create procedure bug1863(in1 int) +begin + + declare ind int default 0; + declare t1 int; + declare t2 int; + declare t3 int; + + declare rc int default 0; + declare continue handler for 1065 set rc = 1; + + drop temporary table if exists temp_t1; + create temporary table temp_t1 ( + f1 int auto_increment, f2 varchar(20), primary key (f1) + ); + + insert into temp_t1 (f2) select content from t3; + + select f2 into t3 from temp_t1 where f1 = 10; + + if (rc) then + insert into t4 values (1, rc, t3); + end if; + + insert into t4 values (2, rc, t3); + +end| + +call bug1863(10)| +call bug1863(10)| +select * from t4| + +drop procedure bug1863| +drop temporary table temp_t1; +drop table t3, t4| + +# +# BUG#2656 +# + +create table t3 ( + OrderID int not null, + MarketID int, + primary key (OrderID) +)| + +create table t4 ( + MarketID int not null, + Market varchar(60), + Status char(1), + primary key (MarketID) +)| + +insert t3 (OrderID,MarketID) values (1,1)| +insert t3 (OrderID,MarketID) values (2,2)| +insert t4 (MarketID,Market,Status) values (1,"MarketID One","A")| +insert t4 (MarketID,Market,Status) values (2,"MarketID Two","A")| + +--disable_warnings +drop procedure if exists bug2656_1| +--enable_warnings +create procedure bug2656_1() +begin + select + m.Market + from t4 m JOIN t3 o + ON o.MarketID != 1 and o.MarketID = m.MarketID; +end | + +--disable_warnings +drop procedure if exists bug2656_2| +--enable_warnings +create procedure bug2656_2() +begin + select + m.Market + from + t4 m, t3 o + where + m.MarketID != 1 and m.MarketID = o.MarketID; + +end | + +call bug2656_1()| +call bug2656_1()| +call bug2656_2()| +call bug2656_2()| +drop procedure bug2656_1| +drop procedure bug2656_2| +drop table t3, t4| + + +# +# BUG#3426 +# +--disable_warnings +drop procedure if exists bug3426| +--enable_warnings +create procedure bug3426(in_time int unsigned, out x int) +begin + if in_time is null then + set @stamped_time=10; + set x=1; + else + set @stamped_time=in_time; + set x=2; + end if; +end| + +call bug3426(1000, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +call bug3426(NULL, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +# Clear SP cache +alter procedure bug3426 sql security invoker| +call bug3426(NULL, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +call bug3426(1000, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| + +drop procedure bug3426| + +# +# BUG#3734 +# +create table t3 ( + id int unsigned auto_increment not null primary key, + title VARCHAR(200), + body text, + fulltext (title,body) +)| + +insert into t3 (title,body) values + ('MySQL Tutorial','DBMS stands for DataBase ...'), + ('How To Use MySQL Well','After you went through a ...'), + ('Optimizing MySQL','In this tutorial we will show ...'), + ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'), + ('MySQL vs. YourSQL','In the following database comparison ...'), + ('MySQL Security','When configured properly, MySQL ...')| + +--disable_warnings +drop procedure if exists bug3734 | +--enable_warnings +create procedure bug3734 (param1 varchar(100)) + select * from t3 where match (title,body) against (param1)| + +call bug3734('database')| +call bug3734('Security')| + +drop procedure bug3734| +drop table t3| + +# +# BUG#3863 +# +--disable_warnings +drop procedure if exists bug3863| +--enable_warnings +create procedure bug3863() +begin + set @a = 0; + while @a < 5 do + set @a = @a + 1; + end while; +end| + +call bug3863()| +select @a| +call bug3863()| +select @a| + +drop procedure bug3863| + +# +# BUG#2460 +# + +create table t3 ( + id int(10) unsigned not null default 0, + rid int(10) unsigned not null default 0, + msg text not null, + primary key (id), + unique key rid (rid, id) +)| + +--disable_warnings +drop procedure if exists bug2460_1| +--enable_warnings +create procedure bug2460_1(in v int) +begin + ( select n0.id from t3 as n0 where n0.id = v ) + union + ( select n0.id from t3 as n0, t3 as n1 + where n0.id = n1.rid and n1.id = v ) + union + ( select n0.id from t3 as n0, t3 as n1, t3 as n2 + where n0.id = n1.rid and n1.id = n2.rid and n2.id = v ); +end| + +call bug2460_1(2)| +call bug2460_1(2)| +insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')| +call bug2460_1(2)| +call bug2460_1(2)| + +--disable_warnings +drop procedure if exists bug2460_2| +--enable_warnings +create procedure bug2460_2() +begin + drop table if exists t3; + create temporary table t3 (s1 int); + insert into t3 select 1 union select 1; +end| + +call bug2460_2()| +call bug2460_2()| +select * from t3| + +drop procedure bug2460_1| +drop procedure bug2460_2| +drop table t3| + + +# +# BUG#2564 +# +set @@sql_mode = ''| +--disable_warnings +drop procedure if exists bug2564_1| +--enable_warnings +create procedure bug2564_1() + comment 'Joe''s procedure' + insert into `t1` values ("foo", 1)| + +set @@sql_mode = 'ANSI_QUOTES'| +--disable_warnings +drop procedure if exists bug2564_2| +--enable_warnings +create procedure bug2564_2() + insert into "t1" values ('foo', 1)| + +delimiter $| +set @@sql_mode = ''$ +--disable_warnings +drop function if exists bug2564_3$ +--enable_warnings +create function bug2564_3(x int, y int) returns int + return x || y$ + +set @@sql_mode = 'ANSI'$ +--disable_warnings +drop function if exists bug2564_4$ +--enable_warnings +create function bug2564_4(x int, y int) returns int + return x || y$ +delimiter |$ + +set @@sql_mode = ''| +show create procedure bug2564_1| +show create procedure bug2564_2| +show create function bug2564_3| +show create function bug2564_4| + +drop procedure bug2564_1| +drop procedure bug2564_2| +drop function bug2564_3| +drop function bug2564_4| + +# +# BUG#3132 +# +--disable_warnings +drop function if exists bug3132| +--enable_warnings +create function bug3132(s char(20)) returns char(50) + return concat('Hello, ', s, '!')| + +select bug3132('Bob') union all select bug3132('Judy')| +drop function bug3132| + +# +# BUG#3843 +# +--disable_warnings +drop procedure if exists bug3843| +--enable_warnings +create procedure bug3843() + analyze table t1| + +# Testing for packets out of order +call bug3843()| +call bug3843()| +select 1+2| + +drop procedure bug3843| + +# +# BUG#3368 +# +create table t3 ( s1 char(10) )| +insert into t3 values ('a'), ('b')| + +--disable_warnings +drop procedure if exists bug3368| +--enable_warnings +create procedure bug3368(v char(10)) +begin + select group_concat(v) from t3; +end| + +call bug3368('x')| +call bug3368('yz')| +drop procedure bug3368| +drop table t3| + +# +# BUG#4579 +# +create table t3 (f1 int, f2 int)| +insert into t3 values (1,1)| + +--disable_warnings +drop procedure if exists bug4579_1| +--enable_warnings +create procedure bug4579_1 () +begin + declare sf1 int; + + select f1 into sf1 from t3 where f1=1 and f2=1; + update t3 set f2 = f2 + 1 where f1=1 and f2=1; + call bug4579_2(); +end| + +--disable_warnings +drop procedure if exists bug4579_2| +--enable_warnings +create procedure bug4579_2 () +begin +end| + +call bug4579_1()| +call bug4579_1()| +call bug4579_1()| + +drop procedure bug4579_1| +drop procedure bug4579_2| +drop table t3| + +# +# BUG#2773: Function's data type ignored in stored procedures +# +--disable_warnings +drop procedure if exists bug2773| +--enable_warnings + +create function bug2773() returns int return null| +create table t3 as select bug2773()| +show create table t3| +drop table t3| +drop function bug2773| + +# +# BUG#3788: Stored procedure packet error +# +--disable_warnings +drop procedure if exists bug3788| +--enable_warnings + +create function bug3788() returns date return cast("2005-03-04" as date)| +select bug3788()| +drop function bug3788| + +create function bug3788() returns binary(1) return 5| +select bug3788()| +drop function bug3788| + + +# +# BUG#4726 +# +create table t3 (f1 int, f2 int, f3 int)| +insert into t3 values (1,1,1)| + +--disable_warnings +drop procedure if exists bug4726| +--enable_warnings +create procedure bug4726() +begin + declare tmp_o_id INT; + declare tmp_d_id INT default 1; + + while tmp_d_id <= 2 do + begin + select f1 into tmp_o_id from t3 where f2=1 and f3=1; + set tmp_d_id = tmp_d_id + 1; + end; + end while; +end| + +call bug4726()| +call bug4726()| +call bug4726()| + +drop procedure bug4726| +drop table t3| + +# +# BUG#4318 +# + +--disable_parsing # Don't know if HANDLER commands can work with SPs, or at all.. +create table t3 (s1 int)| +insert into t3 values (3), (4)| + +--disable_warnings +drop procedure if exists bug4318| +--enable_warnings +create procedure bug4318() + handler t3 read next| + +handler t3 open| +# Expect no results, as tables are closed, but there shouldn't be any errors +call bug4318()| +call bug4318()| +handler t3 close| + +drop procedure bug4318| +drop table t3| +--enable_parsing + +# +# BUG#4902: Stored procedure with SHOW WARNINGS leads to packet error +# +# Added tests for most other show commands we could find too. +# (Skipping those already tested, and the ones depending on optional handlers.) +# +# Note: This will return a large number of results of different formats, +# which makes it impossible to filter with --replace_column. +# It's possible that some of these are not deterministic across +# platforms. If so, just remove the offending command. +# +--disable_warnings +drop procedure if exists bug4902| +--enable_warnings +create procedure bug4902() +begin + show charset like 'foo'; + show collation like 'foo'; + show column types; + show create table t1; + show create database test; + show databases like 'foo'; + show errors; + show columns from t1; + show keys from t1; + show open tables like 'foo'; + show privileges; + show status like 'foo'; + show tables like 'foo'; + show variables like 'foo'; + show warnings; +end| +--disable_parsing +show binlog events| +show storage engines| +show master status| +show slave hosts| +show slave status| +--enable_parsing + +call bug4902()| +call bug4902()| + +drop procedure bug4902| + +# +# BUG#4904 +# +--disable_warnings +drop procedure if exists bug4904| +--enable_warnings +create procedure bug4904() +begin + declare continue handler for sqlstate 'HY000' begin end; + + create table t2 as select * from t3; +end| + +-- error 1146 +call bug4904()| + +drop procedure bug4904| + +create table t3 (s1 char character set latin1, s2 char character set latin2)| + +--disable_warnings +drop procedure if exists bug4904| +--enable_warnings +create procedure bug4904 () +begin + declare continue handler for sqlstate 'HY000' begin end; + + select s1 from t3 union select s2 from t3; +end| + +call bug4904()| + +drop procedure bug4904| +drop table t3| + +# +# BUG#336 +# +--disable_warnings +drop procedure if exists bug336| +--enable_warnings +create procedure bug336(out y int) +begin + declare x int; + set x = (select sum(t.data) from test.t1 t); + set y = x; +end| + +insert into t1 values ("a", 2), ("b", 3)| +call bug336(@y)| +select @y| +delete from t1| +drop procedure bug336| + +# +# BUG#3157 +# +--disable_warnings +drop procedure if exists bug3157| +--enable_warnings +create procedure bug3157() +begin + if exists(select * from t1) then + set @n= @n + 1; + end if; + if (select count(*) from t1) then + set @n= @n + 1; + end if; +end| + +set @n = 0| +insert into t1 values ("a", 1)| +call bug3157()| +select @n| +delete from t1| +drop procedure bug3157| + +# +# BUG#5251: mysql changes creation time of a procedure/function when altering +# +--disable_warnings +drop procedure if exists bug5251| +--enable_warnings +create procedure bug5251() +begin +end| + +select created into @c1 from mysql.proc + where db='test' and name='bug5251'| +--sleep 2 +alter procedure bug5251 comment 'foobar'| +select count(*) from mysql.proc + where db='test' and name='bug5251' and created = @c1| + +drop procedure bug5251| + +# +# BUG#5279: Stored procedure packets out of order if CHECKSUM TABLE +# +--disable_warnings +drop procedure if exists bug5251| +--enable_warnings +create procedure bug5251() + checksum table t1| + +call bug5251()| +call bug5251()| +drop procedure bug5251| + +# +# BUG#5287: Stored procedure crash if leave outside loop +# +--disable_warnings +drop procedure if exists bug5287| +--enable_warnings +create procedure bug5287(param1 int) +label1: + begin + declare c cursor for select 5; + + loop + if param1 >= 0 then + leave label1; + end if; + end loop; +end| +call bug5287(1)| +drop procedure bug5287| + + +# +# BUG#5307: Stored procedure allows statement after BEGIN ... END +# +--disable_warnings +drop procedure if exists bug5307| +--enable_warnings +create procedure bug5307() +begin +end; set @x = 3| + +call bug5307()| +select @x| +drop procedure bug5307| + +# +# BUG#5258: Stored procedure modified date is 0000-00-00 +# (This was a design flaw) +--disable_warnings +drop procedure if exists bug5258| +--enable_warnings +create procedure bug5258() +begin +end| + +--disable_warnings +drop procedure if exists bug5258_aux| +--enable_warnings +create procedure bug5258_aux() +begin + declare c, m char(19); + + select created,modified into c,m from mysql.proc where name = 'bug5258'; + if c = m then + select 'Ok'; + else + select c, m; + end if; +end| + +call bug5258_aux()| + +drop procedure bug5258| +drop procedure bug5258_aux| + +# +# BUG#4487: Stored procedure connection aborted if uninitialized char +# +--disable_warnings +drop function if exists bug4487| +--enable_warnings +create function bug4487() returns char +begin + declare v char; + return v; +end| + +select bug4487()| +drop function bug4487| + + +# +# BUG#4941: Stored procedure crash fetching null value into variable. +# +--disable_warnings +drop procedure if exists bug4941| +--enable_warnings +--disable_warnings +drop procedure if exists bug4941| +--enable_warnings +create procedure bug4941(out x int) +begin + declare c cursor for select i from t2 limit 1; + open c; + fetch c into x; + close c; +end| + +insert into t2 values (null, null, null)| +set @x = 42| +call bug4941(@x)| +select @x| +delete from t1| +drop procedure bug4941| + +# +# BUG#4905: Stored procedure doesn't clear for "Rows affected" +# +--disable_warnings +drop procedure if exists bug4905| +--enable_warnings + +create table t3 (s1 int,primary key (s1))| + +--disable_warnings +drop procedure if exists bug4905| +--enable_warnings +create procedure bug4905() +begin + declare v int; + declare continue handler for sqlstate '23000' set v = 5; + + insert into t3 values (1); +end| + +call bug4905()| +select row_count()| +call bug4905()| +select row_count()| +call bug4905()| +select row_count()| +select * from t3| + +drop procedure bug4905| +drop table t3| + +# +# BUG#6022: Stored procedure shutdown problem with self-calling function. +# + +--disable_parsing # until we implement support for recursive stored functions. +--disable_warnings +drop function if exists bug6022| +--enable_warnings + +--disable_warnings +drop function if exists bug6022| +--enable_warnings +create function bug6022(x int) returns int +begin + if x < 0 then + return 0; + else + return bug6022(x-1); + end if; +end| + +select bug6022(5)| +drop function bug6022| +--enable_parsing + +# +# BUG#6029: Stored procedure specific handlers should have priority +# +--disable_warnings +drop procedure if exists bug6029| +--enable_warnings + +--disable_warnings +drop procedure if exists bug6029| +--enable_warnings +create procedure bug6029() +begin + declare exit handler for 1136 select '1136'; + declare exit handler for sqlstate '23000' select 'sqlstate 23000'; + declare continue handler for sqlexception select 'sqlexception'; + + insert into t3 values (1); + insert into t3 values (1,2); +end| + +create table t3 (s1 int, primary key (s1))| +insert into t3 values (1)| +call bug6029()| +delete from t3| +call bug6029()| + +drop procedure bug6029| +drop table t3| + +# +# BUG#8540: Local variable overrides an alias +# +--disable_warnings +drop procedure if exists bug8540| +--enable_warnings + +create procedure bug8540() +begin + declare x int default 1; + select x as y, x+0 as z; +end| + +call bug8540()| +drop procedure bug8540| + +# +# BUG#6642: Stored procedure crash if expression with set function +# +create table t3 (s1 int)| + +--disable_warnings +drop procedure if exists bug6642| +--enable_warnings + +create procedure bug6642() + select abs(count(s1)) from t3| + +call bug6642()| +call bug6642()| +drop procedure bug6642| + +# +# BUG#7013: Stored procedure crash if group by ... with rollup +# +insert into t3 values (0),(1)| +--disable_warnings +drop procedure if exists bug7013| +--enable_warnings +create procedure bug7013() + select s1,count(s1) from t3 group by s1 with rollup| +call bug7013()| +call bug7013()| +drop procedure bug7013| + +# +# BUG#7743: 'Lost connection to MySQL server during query' on Stored Procedure +# +--disable_warnings +drop table if exists t4| +--enable_warnings +create table t4 ( + a mediumint(8) unsigned not null auto_increment, + b smallint(5) unsigned not null, + c char(32) not null, + primary key (a) +) engine=myisam default charset=latin1| +insert into t4 values (1, 2, 'oneword')| +insert into t4 values (2, 2, 'anotherword')| + +--disable_warnings +drop procedure if exists bug7743| +--enable_warnings +create procedure bug7743 ( searchstring char(28) ) +begin + declare var mediumint(8) unsigned; + select a into var from t4 where b = 2 and c = binary searchstring limit 1; + select var; +end| + +call bug7743("oneword")| +call bug7743("OneWord")| +call bug7743("anotherword")| +call bug7743("AnotherWord")| +drop procedure bug7743| +drop table t4| + +# +# BUG#7992: SELECT .. INTO variable .. within Stored Procedure crashes +# the server +# +delete from t3| +insert into t3 values(1)| +drop procedure if exists bug7992_1| +drop procedure if exists bug7992_2| +create procedure bug7992_1() +begin + declare i int; + select max(s1)+1 into i from t3; +end| +create procedure bug7992_2() + insert into t3 (s1) select max(t4.s1)+1 from t3 as t4| + +call bug7992_1()| +call bug7992_1()| +call bug7992_2()| +call bug7992_2()| + +drop procedure bug7992_1| +drop procedure bug7992_2| +drop table t3| + +# +# BUG#8116: calling simple stored procedure twice in a row results +# in server crash +# +create table t3 ( userid bigint(20) not null default 0 )| + +--disable_warnings +drop procedure if exists bug8116| +--enable_warnings +create procedure bug8116(in _userid int) + select * from t3 where userid = _userid| + +call bug8116(42)| +call bug8116(42)| +drop procedure bug8116| +drop table t3| + +# +# BUG#6857: current_time() in STORED PROCEDURES +# +--disable_warnings +drop procedure if exists bug6857| +--enable_warnings +create procedure bug6857(counter int) +begin + declare t0, t1 int; + declare plus bool default 0; + + set t0 = current_time(); + while counter > 0 do + set counter = counter - 1; + end while; + set t1 = current_time(); + if t1 > t0 then + set plus = 1; + end if; + select plus; +end| + +# QQ: This is currently disabled. Not only does it slow down a normal test +# run, it makes running with valgrind (or similar tools) extremely +# painful. +# Make sure this takes at least one second on all machines in all builds. +# 30000 makes it about 3 seconds on an old 1.1GHz linux. +#call bug6857(300000)| + +drop procedure bug6857| + +# +# BUG#8757: Stored Procedures: Scope of Begin and End Statements do not +# work properly. +--disable_warnings +drop procedure if exists bug8757| +--enable_warnings +create procedure bug8757() +begin + declare x int; + declare c1 cursor for select data from t1 limit 1; + + begin + declare y int; + declare c2 cursor for select i from t2 limit 1; + + open c2; + fetch c2 into y; + close c2; + select 2,y; + end; + open c1; + fetch c1 into x; + close c1; + select 1,x; +end| + +delete from t1| +delete from t2| +insert into t1 values ("x", 1)| +insert into t2 values ("y", 2, 0.0)| + +call bug8757()| + +delete from t1| +delete from t2| +drop procedure bug8757| + + +# +# BUG#8762: Stored Procedures: Inconsistent behavior +# of DROP PROCEDURE IF EXISTS statement. +--disable_warnings +drop procedure if exists bug8762| +--enable_warnings +# Doesn't exist +drop procedure if exists bug8762; create procedure bug8762() begin end| +# Does exist +drop procedure if exists bug8762; create procedure bug8762() begin end| +drop procedure bug8762| + + +# +# BUG#5240: Stored procedure crash if function has cursor declaration +# +--disable_warnings +drop function if exists bug5240| +--enable_warnings +create function bug5240 () returns int +begin + declare x int; + declare c cursor for select data from t1 limit 1; + + open c; + fetch c into x; + close c; + return x; +end| + +delete from t1| +insert into t1 values ("answer", 42)| +select id, bug5240() from t1| +drop function bug5240| + +# +# BUG#7992: rolling back temporary Item tree changes in SP +# +--disable_warnings +drop procedure if exists p1| +--enable_warnings +create table t3(id int)| +insert into t3 values(1)| +create procedure bug7992() +begin + declare i int; + select max(id)+1 into i from t3; +end| + +call bug7992()| +call bug7992()| +drop procedure bug7992| +drop table t3| +delimiter ;| + +# +# BUG#8849: problem with insert statement with table alias's +# +# Rolling back changes to AND/OR structure of ON and WHERE clauses in SP +# + +delimiter |; +create table t3 ( + lpitnumber int(11) default null, + lrecordtype int(11) default null +)| + +create table t4 ( + lbsiid int(11) not null default '0', + ltradingmodeid int(11) not null default '0', + ltradingareaid int(11) not null default '0', + csellingprice decimal(19,4) default null, + primary key (lbsiid,ltradingmodeid,ltradingareaid) +)| + +create table t5 ( + lbsiid int(11) not null default '0', + ltradingareaid int(11) not null default '0', + primary key (lbsiid,ltradingareaid) +)| + +--disable_warnings +drop procedure if exists bug8849| +--enable_warnings +create procedure bug8849() +begin + insert into t5 + ( + t5.lbsiid, + t5.ltradingareaid + ) + select distinct t3.lpitnumber, t4.ltradingareaid + from + t4 join t3 on + t3.lpitnumber = t4.lbsiid + and t3.lrecordtype = 1 + left join t4 as price01 on + price01.lbsiid = t4.lbsiid and + price01.ltradingmodeid = 1 and + t4.ltradingareaid = price01.ltradingareaid; +end| + +call bug8849()| +call bug8849()| +call bug8849()| +drop procedure bug8849| +drop tables t3,t4,t5| + +# +# BUG#8937: Stored Procedure: AVG() works as SUM() in SELECT ... INTO statement +# +--disable_warnings +drop procedure if exists bug8937| +--enable_warnings +create procedure bug8937() +begin + declare s,x,y,z int; + declare a float; + + select sum(data),avg(data),min(data),max(data) into s,x,y,z from t1; + select s,x,y,z; + select avg(data) into a from t1; + select a; +end| + +delete from t1| +insert into t1 (data) values (1), (2), (3), (4), (6)| +call bug8937()| + +drop procedure bug8937| +delete from t1| + + +# +# BUG#6900: Stored procedure inner handler ignored +# BUG#9074: STORED PROC: The scope of every handler declared is not +# properly applied +# +--disable_warnings +drop procedure if exists bug6900| +drop procedure if exists bug9074| +drop procedure if exists bug6900_9074| +--enable_warnings + +create table t3 (w char unique, x char)| +insert into t3 values ('a', 'b')| + +create procedure bug6900() +begin + declare exit handler for sqlexception select '1'; + + begin + declare exit handler for sqlexception select '2'; + + insert into t3 values ('x', 'y', 'z'); + end; +end| + +create procedure bug9074() +begin + declare x1, x2, x3, x4, x5, x6 int default 0; + + begin + declare continue handler for sqlstate '23000' set x5 = 1; + + insert into t3 values ('a', 'b'); + set x6 = 1; + end; + + begin1_label: + begin + declare continue handler for sqlstate '23000' set x1 = 1; + + insert into t3 values ('a', 'b'); + set x2 = 1; + + begin2_label: + begin + declare exit handler for sqlstate '23000' set x3 = 1; + + set x4= 1; + insert into t3 values ('a','b'); + set x4= 0; + end begin2_label; + end begin1_label; + + select x1, x2, x3, x4, x5, x6; +end| + +create procedure bug6900_9074(z int) +begin + declare exit handler for sqlstate '23000' select '23000'; + + begin + declare exit handler for sqlexception select 'sqlexception'; + + if z = 1 then + insert into t3 values ('a', 'b'); + else + insert into t3 values ('x', 'y', 'z'); + end if; + end; +end| + +call bug6900()| +call bug9074()| +call bug6900_9074(0)| +call bug6900_9074(1)| + +drop procedure bug6900| +drop procedure bug9074| +drop procedure bug6900_9074| +drop table t3| + + +# +# BUG#7185: Stored procedure crash if identifier is AVG +# +--disable_warnings +drop procedure if exists avg| +--enable_warnings +create procedure avg () +begin +end| + +call avg ()| +drop procedure avg| + + +# +# BUG#6129: Stored procedure won't display @@sql_mode value +# +--disable_warnings +drop procedure if exists bug6129| +--enable_warnings +set @old_mode= @@sql_mode; +set @@sql_mode= "ERROR_FOR_DIVISION_BY_ZERO"; +create procedure bug6129() + select @@sql_mode| +call bug6129()| +set @@sql_mode= "NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO"| +call bug6129()| +set @@sql_mode= "NO_ZERO_IN_DATE"| +call bug6129()| +set @@sql_mode=@old_mode; + +drop procedure bug6129| + + +# +# BUG#9856: Stored procedures: crash if handler for sqlexception, not found +# +--disable_warnings +drop procedure if exists bug9856| +--enable_warnings +create procedure bug9856() +begin + declare v int; + declare c cursor for select data from t1; + declare exit handler for sqlexception, not found select '16'; + + open c; + fetch c into v; + select v; +end| + +delete from t1| +call bug9856()| +call bug9856()| +drop procedure bug9856| + + +# +# BUG##9674: Stored Procs: Using declared vars in algebric operation causes +# system crash. +# +--disable_warnings +drop procedure if exists bug9674_1| +drop procedure if exists bug9674_2| +--enable_warnings +create procedure bug9674_1(out arg int) +begin + declare temp_in1 int default 0; + declare temp_fl1 int default 0; + + set temp_in1 = 100; + set temp_fl1 = temp_in1/10; + set arg = temp_fl1; +end| + +create procedure bug9674_2() +begin + declare v int default 100; + + select v/10; +end| + +call bug9674_1(@sptmp)| +call bug9674_1(@sptmp)| +select @sptmp| +call bug9674_2()| +call bug9674_2()| +drop procedure bug9674_1| +drop procedure bug9674_2| + + +# +# BUG#9598: stored procedure call within stored procedure overwrites IN variable +# +--disable_warnings +drop procedure if exists bug9598_1| +drop procedure if exists bug9598_2| +--enable_warnings +create procedure bug9598_1(in var_1 char(16), + out var_2 integer, out var_3 integer) +begin + set var_2 = 50; + set var_3 = 60; +end| + +create procedure bug9598_2(in v1 char(16), + in v2 integer, + in v3 integer, + in v4 integer, + in v5 integer) +begin + select v1,v2,v3,v4,v5; + call bug9598_1(v1,@tmp1,@tmp2); + select v1,v2,v3,v4,v5; +end| + +call bug9598_2('Test',2,3,4,5)| +select @tmp1, @tmp2| + +drop procedure bug9598_1| +drop procedure bug9598_2| + + +# +# BUG#9902: Crash with simple stored function using user defined variables +# +--disable_warnings +drop procedure if exists bug9902| +--enable_warnings +create function bug9902() returns int(11) +begin + set @x = @x + 1; + return @x; +end| + +set @qcs1 = @@query_cache_size| +set global query_cache_size = 100000| +set @x = 1| +insert into t1 values ("qc", 42)| +select bug9902() from t1| +select bug9902() from t1| +select @x| + +set global query_cache_size = @qcs1| +delete from t1| +drop function bug9902| + + +# +# BUG#9102: Stored proccedures: function which returns blob causes crash +# +--disable_warnings +drop function if exists bug9102| +--enable_warnings +create function bug9102() returns blob return 'a'| +select bug9102()| +drop function bug9102| + + +# +# BUG#7648: Stored procedure crash when invoking a function that returns a bit +# +--disable_warnings +drop function if exists bug7648| +--enable_warnings +create function bug7648() returns bit(8) return 'a'| +select bug7648()| +drop function bug7648| + + +# +# BUG#9775: crash if create function that returns enum or set +# +--disable_warnings +drop function if exists bug9775| +--enable_warnings +create function bug9775(v1 char(1)) returns enum('a','b') return v1| +select bug9775('a'),bug9775('b'),bug9775('c')| +drop function bug9775| +create function bug9775(v1 int) returns enum('a','b') return v1| +select bug9775(1),bug9775(2),bug9775(3)| +drop function bug9775| + +create function bug9775(v1 char(1)) returns set('a','b') return v1| +select bug9775('a'),bug9775('b'),bug9775('a,b'),bug9775('c')| +drop function bug9775| +create function bug9775(v1 int) returns set('a','b') return v1| +select bug9775(1),bug9775(2),bug9775(3),bug9775(4)| +drop function bug9775| + + +# +# BUG#8861: If Return is a YEAR data type, value is not shown in year format +# +--disable_warnings +drop function if exists bug8861| +--enable_warnings +create function bug8861(v1 int) returns year return v1| +select bug8861(05)| +set @x = bug8861(05)| +select @x| +drop function bug8861| + + +# +# BUG#9004: Inconsistent behaviour of SP re. warnings +# +--disable_warnings +drop procedure if exists bug9004_1| +drop procedure if exists bug9004_2| +--enable_warnings +create procedure bug9004_1(x char(16)) +begin + insert into t1 values (x, 42); + insert into t1 values (x, 17); +end| +create procedure bug9004_2(x char(16)) + call bug9004_1(x)| + +# Truncation warnings expected... +call bug9004_1('12345678901234567')| +call bug9004_2('12345678901234567890')| + +delete from t1| +drop procedure bug9004_1| +drop procedure bug9004_2| + +# +# BUG#7293: Stored procedure crash with soundex +# +--disable_warnings +drop procedure if exists bug7293| +--enable_warnings +insert into t1 values ('secret', 0)| +create procedure bug7293(p1 varchar(100)) +begin + if exists (select id from t1 where soundex(p1)=soundex(id)) then + select 'yes'; + end if; +end;| +call bug7293('secret')| +call bug7293 ('secrete')| +drop procedure bug7293| +delete from t1| + + +# +# BUG#9841: Unexpected read lock when trying to update a view in a +# stored procedure +# +--disable_warnings +drop procedure if exists bug9841| +drop view if exists v1| +--enable_warnings + +create view v1 as select * from t1, t2 where id = s| +create procedure bug9841 () + update v1 set data = 10| +call bug9841()| + +drop view v1| +drop procedure bug9841| + + +# +# BUG#5963 subqueries in SET/IF +# +--disable_warnings +drop procedure if exists bug5963| +--enable_warnings + +create procedure bug5963_1 () begin declare v int; set v = (select s1 from t3); select v; end;| +create table t3 (s1 int)| +insert into t3 values (5)| +call bug5963_1()| +call bug5963_1()| +drop procedure bug5963_1| +drop table t3| + +create procedure bug5963_2 (cfk_value int) +begin + if cfk_value in (select cpk from t3) then + set @x = 5; + end if; + end; +| +create table t3 (cpk int)| +insert into t3 values (1)| +call bug5963_2(1)| +call bug5963_2(1)| +drop procedure bug5963_2| +drop table t3| + + +# +# BUG#9559: Functions: Numeric Operations using -ve value gives incorrect +# results. +# +--disable_warnings +drop function if exists bug9559| +--enable_warnings +create function bug9559() + returns int +begin + set @y = -6/2; + return @y; +end| + +select bug9559()| + +drop function bug9559| + + +# +# BUG#10961: Stored procedures: crash if select * from dual +# +--disable_warnings +drop procedure if exists bug10961| +--enable_warnings +# "select * from dual" results in an error, so the cursor will not open +create procedure bug10961() +begin + declare v char; + declare x int; + declare c cursor for select * from dual; + declare continue handler for sqlexception select x; + + set x = 1; + open c; + set x = 2; + fetch c into v; + set x = 3; + close c; +end| + +call bug10961()| +call bug10961()| + +drop procedure bug10961| + +# +# BUG #6866: Second call of a stored procedure using a view with on expressions +# + +--disable_warnings +DROP PROCEDURE IF EXISTS bug6866| +--enable_warnings + +DROP VIEW IF EXISTS tv| +DROP TABLE IF EXISTS tt1,tt2,tt3| + +CREATE TABLE tt1 (a1 int, a2 int, a3 int, data varchar(10))| +CREATE TABLE tt2 (a2 int, data2 varchar(10))| +CREATE TABLE tt3 (a3 int, data3 varchar(10))| + +INSERT INTO tt1 VALUES (1, 1, 4, 'xx')| + +INSERT INTO tt2 VALUES (1, 'a')| +INSERT INTO tt2 VALUES (2, 'b')| +INSERT INTO tt2 VALUES (3, 'c')| + +INSERT INTO tt3 VALUES (4, 'd')| +INSERT INTO tt3 VALUES (5, 'e')| +INSERT INTO tt3 VALUES (6, 'f')| + +CREATE VIEW tv AS +SELECT tt1.*, tt2.data2, tt3.data3 + FROM tt1 INNER JOIN tt2 ON tt1.a2 = tt2.a2 + LEFT JOIN tt3 ON tt1.a3 = tt3.a3 + ORDER BY tt1.a1, tt2.a2, tt3.a3| + +CREATE PROCEDURE bug6866 (_a1 int) +BEGIN +SELECT * FROM tv WHERE a1 = _a1; +END| + +CALL bug6866(1)| +CALL bug6866(1)| +CALL bug6866(1)| + +DROP PROCEDURE bug6866; + +DROP VIEW tv| +DROP TABLE tt1, tt2, tt3| + +# +# BUG#10136: items cleunup +# +--disable_warnings +DROP PROCEDURE IF EXISTS bug10136| +--enable_warnings +create table t3 ( name char(5) not null primary key, val float not null)| +insert into t3 values ('aaaaa', 1), ('bbbbb', 2), ('ccccc', 3)| +create procedure bug10136() +begin + declare done int default 3; + + repeat + select * from t3; + set done = done - 1; + until done <= 0 end repeat; + +end| +call bug10136()| +call bug10136()| +call bug10136()| +drop procedure bug10136| +drop table t3| + +# +# BUG#11529: crash server after use stored procedure +# +--disable_warnings +drop procedure if exists bug11529| +--enable_warnings +create procedure bug11529() +begin + declare c cursor for select id, data from t1 where data in (10,13); + + open c; + begin + declare vid char(16); + declare vdata int; + declare exit handler for not found begin end; + + while true do + fetch c into vid, vdata; + end while; + end; + close c; +end| + +insert into t1 values + ('Name1', 10), + ('Name2', 11), + ('Name3', 12), + ('Name4', 13), + ('Name5', 14)| + +call bug11529()| +call bug11529()| +delete from t1| +drop procedure bug11529| + + +# +# BUG#6063: Stored procedure labels are subject to restrictions (partial) +# BUG#7088: Stored procedures: labels won't work if character set is utf8 +# +--disable_warnings +drop procedure if exists bug6063| +drop procedure if exists bug7088_1| +drop procedure if exists bug7088_2| +--enable_warnings + +--disable_parsing # temporarily disabled until Bar fixes BUG#11986 +create procedure bug6063() + lâbel: begin end| +call bug6063()| +# QQ Known bug: this will not show the label correctly. +show create procedure bug6063| + +set character set utf8| +create procedure bug7088_1() + label1: begin end label1| +create procedure bug7088_2() + läbel1: begin end| +call bug7088_1()| +call bug7088_2()| +set character set default| +show create procedure bug7088_1| +show create procedure bug7088_2| + +drop procedure bug6063| +drop procedure bug7088_1| +drop procedure bug7088_2| +--enable_parsing + +# +# BUG#9565: "Wrong locking in stored procedure if a sub-sequent procedure +# is called". +# +--disable_warnings +drop procedure if exists bug9565_sub| +drop procedure if exists bug9565| +--enable_warnings +create procedure bug9565_sub() +begin + select * from t1; +end| +create procedure bug9565() +begin + insert into t1 values ("one", 1); + call bug9565_sub(); +end| +call bug9565()| +delete from t1| +drop procedure bug9565_sub| +drop procedure bug9565| + + +# +# BUG#9538: SProc: Creation fails if we try to SET system variable +# using @@var_name in proc +# +--disable_warnings +drop procedure if exists bug9538| +--enable_warnings +create procedure bug9538() + set @@sort_buffer_size = 1000000| + +set @x = @@sort_buffer_size| +set @@sort_buffer_size = 2000000| +select @@sort_buffer_size| +call bug9538()| +select @@sort_buffer_size| +set @@sort_buffer_size = @x| + +drop procedure bug9538| + + +# +# BUG#8692: Cursor fetch of empty string +# +--disable_warnings +drop procedure if exists bug8692| +--enable_warnings +create table t3 (c1 varchar(5), c2 char(5), c3 enum('one','two'), c4 text, c5 blob, c6 char(5), c7 varchar(5))| +insert into t3 values ('', '', '', '', '', '', NULL)| + +create procedure bug8692() +begin + declare v1 VARCHAR(10); + declare v2 VARCHAR(10); + declare v3 VARCHAR(10); + declare v4 VARCHAR(10); + declare v5 VARCHAR(10); + declare v6 VARCHAR(10); + declare v7 VARCHAR(10); + declare c8692 cursor for select c1,c2,c3,c4,c5,c6,c7 from t3; + open c8692; + fetch c8692 into v1,v2,v3,v4,v5,v6,v7; + select v1, v2, v3, v4, v5, v6, v7; +end| + +call bug8692()| +drop procedure bug8692| +drop table t3| + +# +# Bug#10055 "Using stored function with information_schema causes empty +# result set" +# +--disable_warnings +drop function if exists bug10055| +--enable_warnings +create function bug10055(v char(255)) returns char(255) return lower(v)| +# This select should not crash server and should return all fields in t1 +select t.column_name, bug10055(t.column_name) +from information_schema.columns as t +where t.table_schema = 'test' and t.table_name = 't1'| +drop function bug10055| + +# +# Bug #12297 "SP crashes the server if data inserted inside a lon loop" +# The test for memleak bug, so actually there is no way to test it +# from the suite. The test below could be used to check SP memory +# consumption by passing large input parameter. +# + +--disable_warnings +drop procedure if exists bug12297| +--enable_warnings + +create procedure bug12297(lim int) +begin + set @x = 0; + repeat + insert into t1(id,data) + values('aa', @x); + set @x = @x + 1; + until @x >= lim + end repeat; +end| + +call bug12297(10)| +drop procedure bug12297| + +# +# Bug #11247 "Stored procedures: Function calls in long loops leak memory" +# One more memleak bug test. One could use this test to check that the memory +# isn't leaking by increasing the input value for p_bug11247. +# + +--disable_warnings +drop function if exists f_bug11247| +drop procedure if exists p_bug11247| +--enable_warnings + +create function f_bug11247(param int) + returns int +return param + 1| + +create procedure p_bug11247(lim int) +begin + declare v int default 0; + + while v < lim do + set v= f_bug11247(v); + end while; +end| + +call p_bug11247(10)| +drop function f_bug11247| +drop procedure p_bug11247| +# +# BUG#12168: "'DECLARE CONTINUE HANDLER FOR NOT FOUND ...' in conditional +# handled incorrectly" +# +--disable_warnings +drop procedure if exists bug12168| +drop table if exists t3, t4| +--enable_warnings + +create table t3 (a int)| +insert into t3 values (1),(2),(3),(4)| + +create table t4 (a int)| + +create procedure bug12168(arg1 char(1)) +begin + declare b, c integer; + if arg1 = 'a' then + begin + declare c1 cursor for select a from t3 where a % 2; + declare continue handler for not found set b = 1; + set b = 0; + open c1; + c1_repeat: repeat + fetch c1 into c; + if (b = 1) then + leave c1_repeat; + end if; + + insert into t4 values (c); + until b = 1 + end repeat; + end; + end if; + if arg1 = 'b' then + begin + declare c2 cursor for select a from t3 where not a % 2; + declare continue handler for not found set b = 1; + set b = 0; + open c2; + c2_repeat: repeat + fetch c2 into c; + if (b = 1) then + leave c2_repeat; + end if; + + insert into t4 values (c); + until b = 1 + end repeat; + end; + end if; +end| + +call bug12168('a')| +select * from t4| +truncate t4| +call bug12168('b')| +select * from t4| +truncate t4| +call bug12168('a')| +select * from t4| +truncate t4| +call bug12168('b')| +select * from t4| +truncate t4| +drop table t3, t4| +drop procedure if exists bug12168| + +# +# Bug #11333 "Stored Procedure: Memory blow up on repeated SELECT ... INTO +# query" +# One more memleak bug. Use the test to check memory consumption. +# + +--disable_warnings +drop table if exists t3| +drop procedure if exists bug11333| +--enable_warnings + +create table t3 (c1 char(128))| + +insert into t3 values + ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')| + + +create procedure bug11333(i int) +begin + declare tmp varchar(128); + set @x = 0; + repeat + select c1 into tmp from t3 + where c1 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; + set @x = @x + 1; + until @x >= i + end repeat; +end| + +call bug11333(10)| + +drop procedure bug11333| +drop table t3| + +# +# BUG#9048: Creating a function with char binary IN parameter fails +# +--disable_warnings +drop function if exists bug9048| +--enable_warnings +create function bug9048(f1 char binary) returns char binary +begin + set f1= concat( 'hello', f1 ); + return f1; +end| +drop function bug9048| + +# Bug #12849 Stored Procedure: Crash on procedure call with CHAR type +# 'INOUT' parameter +# + +--disable_warnings +drop procedure if exists bug12849_1| +--enable_warnings +create procedure bug12849_1(inout x char) select x into x| +set @var='a'| +call bug12849_1(@var)| +select @var| +drop procedure bug12849_1| + +--disable_warnings +drop procedure if exists bug12849_2| +--enable_warnings +create procedure bug12849_2(inout foo varchar(15)) +begin +select concat(foo, foo) INTO foo; +end| +set @var='abcd'| +call bug12849_2(@var)| +select @var| +drop procedure bug12849_2| + +# +# BUG#13133: Local variables in stored procedures are not initialized correctly. +# +--disable_warnings +drop procedure if exists bug131333| +drop function if exists bug131333| +--enable_warnings +create procedure bug131333() +begin + begin + declare a int; + + select a; + set a = 1; + select a; + end; + begin + declare b int; + + select b; + end; +end| + +create function bug131333() + returns int +begin + begin + declare a int; + + set a = 1; + end; + begin + declare b int; + + return b; + end; +end| + +call bug131333()| +select bug131333()| + +drop procedure bug131333| +drop function bug131333| + +# +# BUG#12379: PROCEDURE with HANDLER calling FUNCTION with error get +# strange result +# +--disable_warnings +drop function if exists bug12379| +drop procedure if exists bug12379_1| +drop procedure if exists bug12379_2| +drop procedure if exists bug12379_3| +drop table if exists t3| +--enable_warnings + +create table t3 (c1 char(1) primary key not null)| + +create function bug12379() + returns integer +begin + insert into t3 values('X'); + insert into t3 values('X'); + return 0; +end| + +create procedure bug12379_1() +begin + declare exit handler for sqlexception select 42; + + select bug12379(); +END| +create procedure bug12379_2() +begin + declare exit handler for sqlexception begin end; + + select bug12379(); +end| +create procedure bug12379_3() +begin + select bug12379(); +end| + +--error 1062 +select bug12379()| +select 1| +call bug12379_1()| +select 2| +call bug12379_2()| +select 3| +--error 1062 +call bug12379_3()| +select 4| + +drop function bug12379| +drop procedure bug12379_1| +drop procedure bug12379_2| +drop procedure bug12379_3| +drop table t3| + +# +# Bug #13124 Stored Procedure using SELECT INTO crashes server +# + +--disable_warnings +drop procedure if exists bug13124| +--enable_warnings +create procedure bug13124() +begin + declare y integer; + set @x=y; +end| +call bug13124()| +drop procedure bug13124| + +# +# Bug #12979 Stored procedures: crash if inout decimal parameter +# + +# check NULL inout parameters processing + +--disable_warnings +drop procedure if exists bug12979_1| +--enable_warnings +create procedure bug12979_1(inout d decimal(5)) set d = d / 2| +set @bug12979_user_var = NULL| +call bug12979_1(@bug12979_user_var)| +drop procedure bug12979_1| + +# check NULL local variables processing + +--disable_warnings +drop procedure if exists bug12979_2| +--enable_warnings +create procedure bug12979_2() +begin +declare internal_var decimal(5); +set internal_var= internal_var / 2; +select internal_var; +end| +call bug12979_2()| +drop procedure bug12979_2| + + +# +# BUG#6127: Stored procedure handlers within handlers don't work +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug6127| +--enable_warnings +create table t3 (s1 int unique)| + +set @sm=@@sql_mode| +set sql_mode='traditional'| + +create procedure bug6127() +begin + declare continue handler for sqlstate '23000' + begin + declare continue handler for sqlstate '22003' + insert into t3 values (0); + + insert into t3 values (1000000000000000); + end; + + insert into t3 values (1); + insert into t3 values (1); +end| + +call bug6127()| +select * from t3| +--error ER_DUP_ENTRY +call bug6127()| +select * from t3| +set sql_mode=@sm| +drop table t3| +drop procedure bug6127| + + +# +# BUG#12589: Assert when creating temp. table from decimal stored procedure +# variable +# +--disable_warnings +drop procedure if exists bug12589_1| +drop procedure if exists bug12589_2| +drop procedure if exists bug12589_3| +--enable_warnings +create procedure bug12589_1() +begin + declare spv1 decimal(3,3); + set spv1= 123.456; + + set spv1 = 'test'; + create temporary table tm1 as select spv1; + show create table tm1; + drop temporary table tm1; +end| + +create procedure bug12589_2() +begin + declare spv1 decimal(6,3); + set spv1= 123.456; + + create temporary table tm1 as select spv1; + show create table tm1; + drop temporary table tm1; +end| + +create procedure bug12589_3() +begin + declare spv1 decimal(6,3); + set spv1= -123.456; + + create temporary table tm1 as select spv1; + show create table tm1; + drop temporary table tm1; +end| + +# Note: The type of the field will match the value, not the declared +# type of the variable. (This is a type checking issue which +# might be changed later.) + +# Warning expected from "set spv1 = 'test'", the value is set to decimal "0". +call bug12589_1()| +# No warnings here +call bug12589_2()| +call bug12589_3()| +drop procedure bug12589_1| +drop procedure bug12589_2| +drop procedure bug12589_3| + +# +# BUG#7049: Stored procedure CALL errors are ignored +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug7049_1| +drop procedure if exists bug7049_2| +drop procedure if exists bug7049_3| +drop procedure if exists bug7049_4| +drop function if exists bug7049_1| +drop function if exists bug7049_2| +--enable_warnings + +create table t3 ( x int unique )| + +create procedure bug7049_1() +begin + insert into t3 values (42); + insert into t3 values (42); +end| + +create procedure bug7049_2() +begin + declare exit handler for sqlexception + select 'Caught it' as 'Result'; + + call bug7049_1(); + select 'Missed it' as 'Result'; +end| + +create procedure bug7049_3() + call bug7049_1()| + +create procedure bug7049_4() +begin + declare exit handler for sqlexception + select 'Caught it' as 'Result'; + + call bug7049_3(); + select 'Missed it' as 'Result'; +end| + +create function bug7049_1() + returns int +begin + insert into t3 values (42); + insert into t3 values (42); + return 42; +end| + +create function bug7049_2() + returns int +begin + declare x int default 0; + declare continue handler for sqlexception + set x = 1; + + set x = bug7049_1(); + return x; +end| + +call bug7049_2()| +select * from t3| +delete from t3| +call bug7049_4()| +select * from t3| +select bug7049_2()| + +drop table t3| +drop procedure bug7049_1| +drop procedure bug7049_2| +drop procedure bug7049_3| +drop procedure bug7049_4| +drop function bug7049_1| +drop function bug7049_2| + + +# +# BUG#13941: replace() string fuction behaves badly inside stored procedure +# (BUG#13914: IFNULL is returning garbage in stored procedure) +# +--disable_warnings +drop function if exists bug13941| +drop procedure if exists bug13941| +--enable_warnings + +create function bug13941(p_input_str text) + returns text +begin + declare p_output_str text; + + set p_output_str = p_input_str; + + set p_output_str = replace(p_output_str, 'xyzzy', 'plugh'); + set p_output_str = replace(p_output_str, 'test', 'prova'); + set p_output_str = replace(p_output_str, 'this', 'questo'); + set p_output_str = replace(p_output_str, ' a ', 'una '); + set p_output_str = replace(p_output_str, 'is', ''); + + return p_output_str; +end| + +create procedure bug13941(out sout varchar(128)) +begin + set sout = 'Local'; + set sout = ifnull(sout, 'DEF'); +end| + +# Note: The bug showed different behaviour in different types of builds, +# giving garbage results in some, and seemingly working in others. +# Running with valgrind (or purify) is the safe way to check that it's +# really working correctly. +select bug13941('this is a test')| +call bug13941(@a)| +select @a| + +drop function bug13941| +drop procedure bug13941| + + +# +# BUG#13095: Cannot create VIEWs in prepared statements +# + +delimiter ;| + +--disable_warnings +DROP PROCEDURE IF EXISTS bug13095; +DROP TABLE IF EXISTS bug13095_t1; +DROP VIEW IF EXISTS bug13095_v1; +--enable_warnings + +delimiter |; + +CREATE PROCEDURE bug13095(tbl_name varchar(32)) +BEGIN + SET @str = + CONCAT("CREATE TABLE ", tbl_name, "(stuff char(15))"); + SELECT @str; + PREPARE stmt FROM @str; + EXECUTE stmt; + + SET @str = + CONCAT("INSERT INTO ", tbl_name, " VALUES('row1'),('row2'),('row3')" ); + SELECT @str; + PREPARE stmt FROM @str; + EXECUTE stmt; + + SET @str = + CONCAT("CREATE VIEW bug13095_v1(c1) AS SELECT stuff FROM ", tbl_name); + SELECT @str; + PREPARE stmt FROM @str; + EXECUTE stmt; + + SELECT * FROM bug13095_v1; + + SET @str = + "DROP VIEW bug13095_v1"; + SELECT @str; + PREPARE stmt FROM @str; + EXECUTE stmt; +END| + +delimiter ;| + +CALL bug13095('bug13095_t1'); + +--disable_warnings +DROP PROCEDURE IF EXISTS bug13095; +DROP VIEW IF EXISTS bug13095_v1; +DROP TABLE IF EXISTS bug13095_t1; +--enable_warnings + +delimiter |; + +# +# BUG#1473: Dumping of stored functions seems to cause corruption in +# the function body +# +--disable_warnings +drop function if exists bug14723| +drop procedure if exists bug14723| +--enable_warnings + +delimiter ;;| +/*!50003 create function bug14723() + returns bigint(20) +main_loop: begin + return 42; +end */;; +show create function bug14723;; +select bug14723();; + +/*!50003 create procedure bug14723() +main_loop: begin + select 42; +end */;; +show create procedure bug14723;; +call bug14723();; + +delimiter |;; + +drop function bug14723| +drop procedure bug14723| + +# +# Bug#14845 "mysql_stmt_fetch returns MYSQL_NO_DATA when COUNT(*) is 0" +# Check that when fetching from a cursor, COUNT(*) works properly. +# +create procedure bug14845() +begin + declare a char(255); + declare done int default 0; + declare c cursor for select count(*) from t1 where 1 = 0; + declare continue handler for sqlstate '02000' set done = 1; + open c; + repeat + fetch c into a; + if not done then + select a; + end if; + until done end repeat; + close c; +end| +call bug14845()| +drop procedure bug14845| + +# +# BUG#13549 "Server crash with nested stored procedures". +# Server should not crash when during execution of stored procedure +# we have to parse trigger/function definition and this new trigger/ +# function has more local variables declared than invoking stored +# procedure and last of these variables is used in argument of NOT +# operator. +# +--disable_warnings +drop procedure if exists bug13549_1| +drop procedure if exists bug13549_2| +--enable_warnings +CREATE PROCEDURE `bug13549_2`() +begin + call bug13549_1(); +end| +CREATE PROCEDURE `bug13549_1`() +begin + declare done int default 0; + set done= not done; +end| +CALL bug13549_2()| +drop procedure bug13549_2| +drop procedure bug13549_1| + +# +# BUG#10100: function (and stored procedure?) recursivity problem +# +--disable_warnings +drop function if exists bug10100f| +drop procedure if exists bug10100p| +drop procedure if exists bug10100t| +drop procedure if exists bug10100pt| +drop procedure if exists bug10100pv| +drop procedure if exists bug10100pd| +drop procedure if exists bug10100pc| +--enable_warnings +# routines with simple recursion +create function bug10100f(prm int) returns int +begin + if prm > 1 then + return prm * bug10100f(prm - 1); + end if; + return 1; +end| +create procedure bug10100p(prm int, inout res int) +begin + set res = res * prm; + if prm > 1 then + call bug10100p(prm - 1, res); + end if; +end| +create procedure bug10100t(prm int) +begin + declare res int; + set res = 1; + call bug10100p(prm, res); + select res; +end| + +# a procedure which use tables and recursion +create table t3 (a int)| +insert into t3 values (0)| +create view v1 as select a from t3; +create procedure bug10100pt(level int, lim int) +begin + if level < lim then + update t3 set a=level; + FLUSH TABLES; + call bug10100pt(level+1, lim); + else + select * from t3; + end if; +end| +# view & recursion +create procedure bug10100pv(level int, lim int) +begin + if level < lim then + update v1 set a=level; + FLUSH TABLES; + call bug10100pv(level+1, lim); + else + select * from v1; + end if; +end| +# dynamic sql & recursion +prepare stmt2 from "select * from t3;"; +create procedure bug10100pd(level int, lim int) +begin + if level < lim then + select level; + prepare stmt1 from "update t3 set a=a+2"; + execute stmt1; + FLUSH TABLES; + execute stmt1; + FLUSH TABLES; + execute stmt1; + FLUSH TABLES; + deallocate prepare stmt1; + execute stmt2; + select * from t3; + call bug10100pd(level+1, lim); + else + execute stmt2; + end if; +end| +# cursor & recursion +create procedure bug10100pc(level int, lim int) +begin + declare lv int; + declare c cursor for select a from t3; + open c; + if level < lim then + select level; + fetch c into lv; + select lv; + update t3 set a=level+lv; + FLUSH TABLES; + call bug10100pc(level+1, lim); + else + select * from t3; + end if; + close c; +end| + +set @@max_sp_recursion_depth=4| +select @@max_sp_recursion_depth| +-- error ER_SP_NO_RECURSION +select bug10100f(3)| +-- error ER_SP_NO_RECURSION +select bug10100f(6)| +call bug10100t(5)| +call bug10100pt(1,5)| +call bug10100pv(1,5)| +update t3 set a=1| +call bug10100pd(1,5)| +select * from t3| +update t3 set a=1| +call bug10100pc(1,5)| +select * from t3| +set @@max_sp_recursion_depth=0| +select @@max_sp_recursion_depth| +-- error ER_SP_NO_RECURSION +select bug10100f(5)| +-- error ER_SP_RECURSION_LIMIT +call bug10100t(5)| + +#end of the stack checking +deallocate prepare stmt2| + +drop function bug10100f| +drop procedure bug10100p| +drop procedure bug10100t| +drop procedure bug10100pt| +drop procedure bug10100pv| +drop procedure bug10100pd| +drop procedure bug10100pc| +drop view v1| + +# +# BUG#13729: Stored procedures: packet error after exception handled +# +--disable_warnings +drop procedure if exists bug13729| +drop table if exists t3| +--enable_warnings + +create table t3 (s1 int, primary key (s1))| + +insert into t3 values (1),(2)| + +create procedure bug13729() +begin + declare continue handler for sqlexception select 55; + + update t3 set s1 = 1; +end| + +call bug13729()| +# Used to cause Packets out of order +select * from t3| + +drop procedure bug13729| +drop table t3| + +# +# BUG#14643: Stored Procedure: Continuing after failed var. initialization +# crashes server. +# +--disable_warnings +drop procedure if exists bug14643_1| +drop procedure if exists bug14643_2| +--enable_warnings + +create procedure bug14643_1() +begin + declare continue handler for sqlexception select 'boo' as 'Handler'; + + begin + declare v int default undefined_var; + + if v = 1 then + select 1; + else + select v, isnull(v); + end if; + end; +end| + +create procedure bug14643_2() +begin + declare continue handler for sqlexception select 'boo' as 'Handler'; + + case undefined_var + when 1 then + select 1; + else + select 2; + end case; + + select undefined_var; +end| + +call bug14643_1()| +call bug14643_2()| + +drop procedure bug14643_1| +drop procedure bug14643_2| + +# +# BUG#14304: auto_increment field incorrect set in SP +# +--disable_warnings +drop procedure if exists bug14304| +drop table if exists t3, t4| +--enable_warnings + +create table t3(a int primary key auto_increment)| +create table t4(a int primary key auto_increment)| + +create procedure bug14304() +begin + insert into t3 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 select null as a; + + insert into t3 set a=null; + insert into t3 set a=null; + + select * from t3; +end| + +call bug14304()| + +drop procedure bug14304| +drop table t3, t4| + +# +# BUG#14376: MySQL crash on scoped variable (re)initialization +# +--disable_warnings +drop procedure if exists bug14376| +--enable_warnings + +create procedure bug14376() +begin + declare x int default x; +end| + +# Not the error we want, but that's what we got for now... +--error ER_BAD_FIELD_ERROR +call bug14376()| +drop procedure bug14376| + +create procedure bug14376() +begin + declare x int default 42; + + begin + declare x int default x; + + select x; + end; +end| + +call bug14376()| + +drop procedure bug14376| + +create procedure bug14376(x int) +begin + declare x int default x; + + select x; +end| + +call bug14376(4711)| + +drop procedure bug14376| + +# +# Bug#5967 "Stored procedure declared variable used instead of column" +# The bug should be fixed later. +# Test precedence of names of parameters, variable declarations, +# variable declarations in nested compound statements, table columns, +# table columns in cursor declarations. +# According to the standard, table columns take precedence over +# variable declarations. In MySQL 5.0 it's vice versa. +# + +--disable_warnings +drop procedure if exists bug5967| +drop table if exists t3| +--enable_warnings +create table t3 (a varchar(255))| +insert into t3 (a) values ("a - table column")| +create procedure bug5967(a varchar(255)) +begin + declare i varchar(255); + declare c cursor for select a from t3; + select a; + select a from t3 into i; + select i as 'Parameter takes precedence over table column'; open c; + fetch c into i; + close c; + select i as 'Parameter takes precedence over table column in cursors'; + begin + declare a varchar(255) default 'a - local variable'; + declare c1 cursor for select a from t3; + select a as 'A local variable takes precedence over parameter'; + open c1; + fetch c1 into i; + close c1; + select i as 'A local variable takes precedence over parameter in cursors'; + begin + declare a varchar(255) default 'a - local variable in a nested compound statement'; + declare c2 cursor for select a from t3; + select a as 'A local variable in a nested compound statement takes precedence over a local variable in the outer statement'; + select a from t3 into i; + select i as 'A local variable in a nested compound statement takes precedence over table column'; + open c2; + fetch c2 into i; + close c2; + select i as 'A local variable in a nested compound statement takes precedence over table column in cursors'; + end; + end; +end| +call bug5967("a - stored procedure parameter")| +drop procedure bug5967| + +# +# Bug#13012 "SP: REPAIR/BACKUP/RESTORE TABLE crashes the server" +# +--disable_warnings +drop procedure if exists bug13012| +--enable_warnings +create procedure bug13012() +BEGIN + REPAIR TABLE t1; + BACKUP TABLE t1 to '../tmp'; + DROP TABLE t1; + RESTORE TABLE t1 FROM '../tmp'; +END| +call bug13012()| +drop procedure bug13012| +create view v1 as select * from t1| +create procedure bug13012() +BEGIN + REPAIR TABLE t1,t2,t3,v1; + OPTIMIZE TABLE t1,t2,t3,v1; + ANALYZE TABLE t1,t2,t3,v1; +END| +call bug13012()| +call bug13012()| +call bug13012()| +drop procedure bug13012| +drop view v1; +select * from t1| + +# +# A test case for Bug#15392 "Server crashes during prepared statement +# execute": make sure that stored procedure check for error conditions +# properly and do not continue execution if an error has been set. +# +# It's necessary to use several DBs because in the original code +# the successful return of mysql_change_db overrode the error from +# execution. +drop schema if exists mysqltest1| +drop schema if exists mysqltest2| +drop schema if exists mysqltest3| +create schema mysqltest1| +create schema mysqltest2| +create schema mysqltest3| +use mysqltest3| + +create procedure mysqltest1.p1 (out prequestid varchar(100)) +begin + call mysqltest2.p2('call mysqltest3.p3(1, 2)'); +end| + +create procedure mysqltest2.p2(in psql text) +begin + declare lsql text; + set @lsql= psql; + prepare lstatement from @lsql; + execute lstatement; + deallocate prepare lstatement; +end| + +create procedure mysqltest3.p3(in p1 int) +begin + select p1; +end| + +--error ER_SP_WRONG_NO_OF_ARGS +call mysqltest1.p1(@rs)| +--error ER_SP_WRONG_NO_OF_ARGS +call mysqltest1.p1(@rs)| +--error ER_SP_WRONG_NO_OF_ARGS +call mysqltest1.p1(@rs)| +drop schema if exists mysqltest1| +drop schema if exists mysqltest2| +drop schema if exists mysqltest3| +use test| + +# +# Bug#15441 "Running SP causes Server to Crash": check that an SP variable +# can not be used in VALUES() function. +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug15441| +--enable_warnings +create table t3 (id int not null primary key, county varchar(25))| +insert into t3 (id, county) values (1, 'York')| + +# First check that a stored procedure that refers to a parameter in VALUES() +# function won't parse. + +create procedure bug15441(c varchar(25)) +begin + update t3 set id=2, county=values(c); +end| +--error ER_BAD_FIELD_ERROR +call bug15441('county')| +drop procedure bug15441| + +# Now check the case when there is an ambiguity between column names +# and stored procedure parameters: the parser shall resolve the argument +# of VALUES() function to the column name. + +# It's hard to deduce what county refers to in every case (INSERT statement): +# 1st county refers to the column +# 2nd county refers to the procedure parameter +# 3d and 4th county refers to the column, again, but +# for 4th county it has the value of SP parameter + +# In UPDATE statement, just check that values() function returns NULL for +# non- INSERT...UPDATE statements, as stated in the manual. + +create procedure bug15441(county varchar(25)) +begin + declare c varchar(25) default "hello"; + + insert into t3 (id, county) values (1, county) + on duplicate key update county= values(county); + select * from t3; + + update t3 set id=2, county=values(id); + select * from t3; +end| +call bug15441('Yale')| +drop table t3| +drop procedure bug15441| + +# +# BUG#14498: Stored procedures: hang if undefined variable and exception +# +--disable_warnings +drop procedure if exists bug14498_1| +drop procedure if exists bug14498_2| +drop procedure if exists bug14498_3| +drop procedure if exists bug14498_4| +drop procedure if exists bug14498_5| +--enable_warnings + +create procedure bug14498_1() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + if v then + select 'yes' as 'v'; + else + select 'no' as 'v'; + end if; + select 'done' as 'End'; +end| + +create procedure bug14498_2() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + while v do + select 'yes' as 'v'; + end while; + select 'done' as 'End'; +end| + +create procedure bug14498_3() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + repeat + select 'maybe' as 'v'; + until v end repeat; + select 'done' as 'End'; +end| + +create procedure bug14498_4() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + case v + when 1 then + select '1' as 'v'; + when 2 then + select '2' as 'v'; + else + select '?' as 'v'; + end case; + select 'done' as 'End'; +end| + +create procedure bug14498_5() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + case + when v = 1 then + select '1' as 'v'; + when v = 2 then + select '2' as 'v'; + else + select '?' as 'v'; + end case; + select 'done' as 'End'; +end| + +call bug14498_1()| +call bug14498_2()| +call bug14498_3()| +call bug14498_4()| +call bug14498_5()| + +drop procedure bug14498_1| +drop procedure bug14498_2| +drop procedure bug14498_3| +drop procedure bug14498_4| +drop procedure bug14498_5| + +# +# BUG#15231: Stored procedure bug with not found condition handler +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug15231_1| +drop procedure if exists bug15231_2| +drop procedure if exists bug15231_3| +drop procedure if exists bug15231_4| +--enable_warnings + +create table t3 (id int not null)| + +create procedure bug15231_1() +begin + declare xid integer; + declare xdone integer default 0; + declare continue handler for not found set xdone = 1; + + set xid=null; + call bug15231_2(xid); + select xid, xdone; +end| + +create procedure bug15231_2(inout ioid integer) +begin + select "Before NOT FOUND condition is triggered" as '1'; + select id into ioid from t3 where id=ioid; + select "After NOT FOUND condtition is triggered" as '2'; + + if ioid is null then + set ioid=1; + end if; +end| + +create procedure bug15231_3() +begin + declare exit handler for sqlwarning + select 'Caught it (wrong)' as 'Result'; + + call bug15231_4(); +end| + +create procedure bug15231_4() +begin + declare x decimal(2,1); + + set x = 'zap'; + select 'Missed it (correct)' as 'Result'; +end| + +call bug15231_1()| +call bug15231_3()| + +drop table if exists t3| +drop procedure if exists bug15231_1| +drop procedure if exists bug15231_2| +drop procedure if exists bug15231_3| +drop procedure if exists bug15231_4| + + +# +# BUG#15011: error handler in nested block not activated +# +--disable_warnings +drop procedure if exists bug15011| +--enable_warnings + +create table t3 (c1 int primary key)| + +insert into t3 values (1)| + +create procedure bug15011() + deterministic +begin + declare continue handler for 1062 + select 'Outer' as 'Handler'; + + begin + declare continue handler for 1062 + select 'Inner' as 'Handler'; + + insert into t3 values (1); + end; +end| + +call bug15011()| + +drop procedure bug15011| +drop table t3| + + +# +# BUG#17615: problem with character set +# +--disable_warnings +drop function if exists bug17615| +--enable_warnings + +create table t3 (a varchar(256) unicode)| + +create function bug17615() returns varchar(256) unicode +begin + declare tmp_res varchar(256) unicode; + set tmp_res= 'foo string'; + return tmp_res; +end| + +insert into t3 values(bug17615())| +select * from t3| + +drop function bug17615| +drop table t3| + + +# +# BUG#17476: Stored procedure not returning data when it is called first +# time per connection +# +--disable_warnings +drop procedure if exists bug17476| +--enable_warnings + +create table t3 ( d date )| +insert into t3 values + ( '2005-01-01' ), ( '2005-01-02' ), ( '2005-01-03' ), + ( '2005-01-04' ), ( '2005-02-01' ), ( '2005-02-02' )| + +create procedure bug17476(pDateFormat varchar(10)) + select date_format(t3.d, pDateFormat), count(*) + from t3 + group by date_format(t3.d, pDateFormat)| + +call bug17476('%Y-%m')| +call bug17476('%Y-%m')| + +drop table t3| +drop procedure bug17476| + + +# +# BUG#16887: Cursor causes server segfault +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug16887| +--enable_warnings + +create table t3 ( c varchar(1) )| + +insert into t3 values + (' '),('.'),(';'),(','),('-'),('_'),('('),(')'),('/'),('\\')| + +create procedure bug16887() +begin + declare i int default 10; + + again: + while i > 0 do + begin + declare breakchar varchar(1); + declare done int default 0; + declare t3_cursor cursor for select c from t3; + declare continue handler for not found set done = 1; + + set i = i - 1; + select i; + + if i = 3 then + iterate again; + end if; + + open t3_cursor; + + loop + fetch t3_cursor into breakchar; + + if done = 1 then + begin + close t3_cursor; + iterate again; + end; + end if; + end loop; + end; + end while; +end| + +call bug16887()| + +drop table t3| +drop procedure bug16887| + +# +# Bug#13575 SP funcs in select with distinct/group and order by can +# produce bad data +# +# Disable warnings to allow test to run also without InnoDB +--disable_warnings +create table t3 (f1 int, f2 varchar(3), primary key(f1)) engine=innodb| +--enable_warnings +insert into t3 values (1,'aaa'),(2,'bbb'),(3,'ccc')| +CREATE FUNCTION bug13575 ( p1 integer ) +returns varchar(3) +BEGIN +DECLARE v1 VARCHAR(10) DEFAULT null; +SELECT f2 INTO v1 FROM t3 WHERE f1 = p1; +RETURN v1; +END| +select distinct f1, bug13575(f1) from t3 order by f1| +drop function bug13575; +drop table t3| + +# +# BUG#16474: SP crashed MySQL +# (when using "order by localvar", where 'localvar' is just that. +# +--disable_warnings +drop procedure if exists bug16474_1| +drop procedure if exists bug16474_2| +--enable_warnings + +delete from t1| +insert into t1 values ('c', 2), ('b', 3), ('a', 1)| + +create procedure bug16474_1() +begin + declare x int; + + select id from t1 order by x; +end| + +# +# BUG#14945: Truncate table doesn't reset the auto_increment counter +# +--disable_warnings +drop procedure if exists bug14945| +--enable_warnings +create table t3 (id int not null auto_increment primary key)| +create procedure bug14945() deterministic truncate t3| +insert into t3 values (null)| +call bug14945()| +insert into t3 values (null)| +select * from t3| +drop table t3| +drop procedure bug14945| + +# This does NOT order by column index; variable is an expression. +create procedure bug16474_2(x int) + select id from t1 order by x| + +call bug16474_1()| +call bug16474_2(1)| +call bug16474_2(2)| +drop procedure bug16474_1| +drop procedure bug16474_2| + +# For reference: user variables are expressions too and do not affect ordering. +set @x = 2| +select * from t1 order by @x| + +delete from t1| + + +# +# BUG#15728: LAST_INSERT_ID function inside a stored function returns 0 +# +# The solution is not to reset last_insert_id on enter to sub-statement. +# +--disable_warnings +drop function if exists bug15728| +drop table if exists t3| +--enable_warnings + +create table t3 ( + id int not null auto_increment, + primary key (id) +)| +create function bug15728() returns int(11) + return last_insert_id()| + +insert into t3 values (0)| +select last_insert_id()| +select bug15728()| + +drop function bug15728| +drop table t3| + + +# +# BUG#18787: Server crashed when calling a stored procedure containing +# a misnamed function +# +--disable_warnings +drop procedure if exists bug18787| +--enable_warnings +create procedure bug18787() +begin + declare continue handler for sqlexception begin end; + + select no_such_function(); +end| + +call bug18787()| +drop procedure bug18787| + + +# +# BUG#18344: DROP DATABASE does not drop associated routines +# (... if the database name is longer than 21 characters) +# +# 1234567890123456789012 +create database bug18344_012345678901| +use bug18344_012345678901| +create procedure bug18344() begin end| +create procedure bug18344_2() begin end| + +create database bug18344_0123456789012| +use bug18344_0123456789012| +create procedure bug18344() begin end| +create procedure bug18344_2() begin end| + +use test| + +select schema_name from information_schema.schemata where + schema_name like 'bug18344%'| +select routine_name,routine_schema from information_schema.routines where + routine_schema like 'bug18344%'| + +drop database bug18344_012345678901| +drop database bug18344_0123456789012| + +# Should be nothing left. +select schema_name from information_schema.schemata where + schema_name like 'bug18344%'| +select routine_name,routine_schema from information_schema.routines where + routine_schema like 'bug18344%'| + + +# +# BUG#12472/BUG#15137 'CREATE TABLE ... SELECT ... which explicitly or +# implicitly uses stored function gives "Table not locked" error'. +# +--disable_warnings +drop function if exists bug12472| +--enable_warnings +create function bug12472() returns int return (select count(*) from t1)| +# Check case when function is used directly +create table t3 as select bug12472() as i| +show create table t3| +select * from t3| +drop table t3| +# Check case when function is used indirectly through view +create view v1 as select bug12472() as j| +create table t3 as select * from v1| +show create table t3| +select * from t3| +drop table t3| +drop view v1| +drop function bug12472| + + +# +# BUG#18587: Function that accepts and returns TEXT garbles data if longer than +# 766 chars +# + +# Prepare. + +--disable_warnings +DROP FUNCTION IF EXISTS bug18589_f1| +DROP PROCEDURE IF EXISTS bug18589_p1| +DROP PROCEDURE IF EXISTS bug18589_p2| +--enable_warnings + +CREATE FUNCTION bug18589_f1(arg TEXT) RETURNS TEXT +BEGIN + RETURN CONCAT(arg, ""); +END| + +CREATE PROCEDURE bug18589_p1(arg TEXT, OUT ret TEXT) +BEGIN + SET ret = CONCAT(arg, ""); +END| + +CREATE PROCEDURE bug18589_p2(arg TEXT) +BEGIN + DECLARE v TEXT; + CALL bug18589_p1(arg, v); + SELECT v; +END| + +# Test case. + +SELECT bug18589_f1(REPEAT("a", 767))| + +SET @bug18589_v1 = ""| +CALL bug18589_p1(REPEAT("a", 767), @bug18589_v1)| +SELECT @bug18589_v1| + +CALL bug18589_p2(REPEAT("a", 767))| + +# Cleanup. + +DROP FUNCTION bug18589_f1| +DROP PROCEDURE bug18589_p1| +DROP PROCEDURE bug18589_p2| + + +# +# BUG#18037: Server crash when returning system variable in stored procedures +# BUG#19633: Stack corruption in fix_fields()/THD::rollback_item_tree_changes() +# + +# Prepare. + +--disable_warnings +DROP FUNCTION IF EXISTS bug18037_f1| +DROP PROCEDURE IF EXISTS bug18037_p1| +DROP PROCEDURE IF EXISTS bug18037_p2| +--enable_warnings + +# Test case. + +CREATE FUNCTION bug18037_f1() RETURNS INT +BEGIN + RETURN @@server_id; +END| + +CREATE PROCEDURE bug18037_p1() +BEGIN + DECLARE v INT DEFAULT @@server_id; +END| + +CREATE PROCEDURE bug18037_p2() +BEGIN + CASE @@server_id + WHEN -1 THEN + SELECT 0; + ELSE + SELECT 1; + END CASE; +END| + +SELECT bug18037_f1()| +CALL bug18037_p1()| +CALL bug18037_p2()| + +# Cleanup. + +DROP FUNCTION bug18037_f1| +DROP PROCEDURE bug18037_p1| +DROP PROCEDURE bug18037_p2| + +# +# Bug#17199: "Table not found" error occurs if the query contains a call +# to a function from another database. +# See also ps.test for an additional test case for this bug. +# +use test| +create table t3 (i int)| +insert into t3 values (1), (2)| +create database mysqltest1| +use mysqltest1| +create function bug17199() returns varchar(2) deterministic return 'ok'| +use test| +select *, mysqltest1.bug17199() from t3| +# +# Bug#18444: Fully qualified stored function names don't work correctly +# in select statements +# +use mysqltest1| +create function bug18444(i int) returns int no sql deterministic return i + 1| +use test| +select mysqltest1.bug18444(i) from t3| +drop database mysqltest1| +# +# Check that current database has no influence to a stored procedure +# +create database mysqltest1 charset=utf8| +create database mysqltest2 charset=utf8| +create procedure mysqltest1.p1() +begin +-- alters the default collation of database test + alter database character set koi8r; +end| +use mysqltest1| +call p1()| +show create database mysqltest1| +show create database mysqltest2| +alter database mysqltest1 character set utf8| +use mysqltest2| +call mysqltest1.p1()| +show create database mysqltest1| +show create database mysqltest2| +drop database mysqltest1| +drop database mysqltest2| +# +# Restore the old environemnt +use test| +# +# Bug#15217 "Using a SP cursor on a table created with PREPARE fails with +# weird error". Check that the code that is supposed to work at +# the first execution of a stored procedure actually works for +# sp_instr_copen. + +--disable_warnings +drop table if exists t3| +drop procedure if exists bug15217| +--enable_warnings +create table t3 as select 1| +create procedure bug15217() +begin + declare var1 char(255); + declare cur1 cursor for select * from t3; + open cur1; + fetch cur1 into var1; + select concat('data was: /', var1, '/'); + close cur1; +end | +# Returns expected result +call bug15217()| +flush tables | +# Returns error with garbage as column name +call bug15217()| +drop table t3| +drop procedure bug15217| + + +# +# BUG#21013: Performance Degrades when importing data that uses +# Trigger and Stored Procedure +# +# This is a performance and memory leak test. Run with large number +# passed to bug21013() procedure. +# +--disable_warnings +DROP PROCEDURE IF EXISTS bug21013 | +--enable_warnings + +CREATE PROCEDURE bug21013(IN lim INT) +BEGIN + DECLARE i INT DEFAULT 0; + WHILE (i < lim) DO + SET @b = LOCATE(_latin1'b', @a, 1); + SET i = i + 1; + END WHILE; +END | + +SET @a = _latin2"aaaaaaaaaa" | +CALL bug21013(10) | + +DROP PROCEDURE bug21013 | + + +# +# BUG#16211: Stored function return type for strings is ignored +# + +# Prepare: create database with fixed, pre-defined character set. + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest1| +DROP DATABASE IF EXISTS mysqltest2| +--enable_warnings + +CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| +CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET utf8| + +# Test case: + +use mysqltest1| + +# - Create two stored functions -- with and without explicit CHARSET-clause +# for return value; + +CREATE FUNCTION bug16211_f1() RETURNS CHAR(10) + RETURN ""| + +CREATE FUNCTION bug16211_f2() RETURNS CHAR(10) CHARSET koi8r + RETURN ""| + +CREATE FUNCTION mysqltest2.bug16211_f3() RETURNS CHAR(10) + RETURN ""| + +CREATE FUNCTION mysqltest2.bug16211_f4() RETURNS CHAR(10) CHARSET koi8r + RETURN ""| + +# - Check that CHARSET-clause is specified for the second function; + +SHOW CREATE FUNCTION bug16211_f1| +SHOW CREATE FUNCTION bug16211_f2| + +SHOW CREATE FUNCTION mysqltest2.bug16211_f3| +SHOW CREATE FUNCTION mysqltest2.bug16211_f4| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| + +SELECT CHARSET(bug16211_f1())| +SELECT CHARSET(bug16211_f2())| + +SELECT CHARSET(mysqltest2.bug16211_f3())| +SELECT CHARSET(mysqltest2.bug16211_f4())| + +# - Alter database character set. + +ALTER DATABASE mysqltest1 CHARACTER SET cp1251| +ALTER DATABASE mysqltest2 CHARACTER SET cp1251| + +# - Check that CHARSET-clause has not changed. + +SHOW CREATE FUNCTION bug16211_f1| +SHOW CREATE FUNCTION bug16211_f2| + +SHOW CREATE FUNCTION mysqltest2.bug16211_f3| +SHOW CREATE FUNCTION mysqltest2.bug16211_f4| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| + +SELECT CHARSET(bug16211_f1())| +SELECT CHARSET(bug16211_f2())| + +SELECT CHARSET(mysqltest2.bug16211_f3())| +SELECT CHARSET(mysqltest2.bug16211_f4())| + +# Cleanup. + +use test| + +DROP DATABASE mysqltest1| +DROP DATABASE mysqltest2| + + +# +# BUG#16676: Database CHARSET not used for stored procedures +# + +# Prepare: create database with fixed, pre-defined character set. + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest1| +--enable_warnings + +CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| + +# Test case: + +use mysqltest1| + +# - Create two stored procedures -- with and without explicit CHARSET-clause; + +CREATE PROCEDURE bug16676_p1( + IN p1 CHAR(10), + INOUT p2 CHAR(10), + OUT p3 CHAR(10)) +BEGIN + SELECT CHARSET(p1), COLLATION(p1); + SELECT CHARSET(p2), COLLATION(p2); + SELECT CHARSET(p3), COLLATION(p3); +END| + +CREATE PROCEDURE bug16676_p2( + IN p1 CHAR(10) CHARSET koi8r, + INOUT p2 CHAR(10) CHARSET cp1251, + OUT p3 CHAR(10) CHARSET greek) +BEGIN + SELECT CHARSET(p1), COLLATION(p1); + SELECT CHARSET(p2), COLLATION(p2); + SELECT CHARSET(p3), COLLATION(p3); +END| + +# - Call procedures. + +SET @v2 = 'b'| +SET @v3 = 'c'| + +CALL bug16676_p1('a', @v2, @v3)| +CALL bug16676_p2('a', @v2, @v3)| + +# Cleanup. + +use test| + +DROP DATABASE mysqltest1| +# +# BUG#8153: Stored procedure with subquery and continue handler, wrong result +# + +--disable_warnings +drop table if exists t3| +drop table if exists t4| +drop procedure if exists bug8153_subselect| +drop procedure if exists bug8153_subselect_a| +drop procedure if exists bug8153_subselect_b| +drop procedure if exists bug8153_proc_a| +drop procedure if exists bug8153_proc_b| +--enable_warnings + +create table t3 (a int)| +create table t4 (a int)| +insert into t3 values (1), (1), (2), (3)| +insert into t4 values (1), (1)| + +## Testing the use case reported in Bug#8153 + +create procedure bug8153_subselect() +begin + declare continue handler for sqlexception + begin + select 'statement failed'; + end; + update t3 set a=a+1 where (select a from t4 where a=1) is null; + select 'statement after update'; +end| + +call bug8153_subselect()| +select * from t3| + +call bug8153_subselect()| +select * from t3| + +drop procedure bug8153_subselect| + +## Testing a subselect with a non local handler + +create procedure bug8153_subselect_a() +begin + declare continue handler for sqlexception + begin + select 'in continue handler'; + end; + + select 'reachable code a1'; + call bug8153_subselect_b(); + select 'reachable code a2'; +end| + +create procedure bug8153_subselect_b() +begin + select 'reachable code b1'; + update t3 set a=a+1 where (select a from t4 where a=1) is null; + select 'unreachable code b2'; +end| + +call bug8153_subselect_a()| +select * from t3| + +call bug8153_subselect_a()| +select * from t3| + +drop procedure bug8153_subselect_a| +drop procedure bug8153_subselect_b| + +## Testing extra use cases, found while investigating +## This is related to BUG#18787, with a non local handler + +create procedure bug8153_proc_a() +begin + declare continue handler for sqlexception + begin + select 'in continue handler'; + end; + + select 'reachable code a1'; + call bug8153_proc_b(); + select 'reachable code a2'; +end| + +create procedure bug8153_proc_b() +begin + select 'reachable code b1'; + select no_such_function(); + select 'unreachable code b2'; +end| + +call bug8153_proc_a()| + +drop procedure bug8153_proc_a| +drop procedure bug8153_proc_b| +drop table t3| +drop table t4| + +# +# BUG#19862: Sort with filesort by function evaluates function twice +# +--disable_warnings +drop procedure if exists bug19862| +--enable_warnings +CREATE TABLE t11 (a INT)| +CREATE TABLE t12 (a INT)| +CREATE FUNCTION bug19862(x INT) RETURNS INT + BEGIN + INSERT INTO t11 VALUES (x); + RETURN x+1; + END| +INSERT INTO t12 VALUES (1), (2)| +SELECT bug19862(a) FROM t12 ORDER BY 1| +SELECT * FROM t11| +DROP TABLE t11, t12| +DROP FUNCTION bug19862| +# Bug#21002 "Derived table not selecting from a "real" table fails in JOINs" +# +# A regression caused by the fix for Bug#18444: for derived tables we should +# set an empty string as the current database. They do not belong to any +# database and must be usable even if there is no database +# selected. +--disable_warnings +drop table if exists t3| +drop database if exists mysqltest1| +--enable_warnings +create table t3 (a int)| +insert into t3 (a) values (1), (2)| + +create database mysqltest1| +use mysqltest1| +drop database mysqltest1| + +# No current database +select database()| + +select * from (select 1 as a) as t1 natural join (select * from test.t3) as t2| +use test| +drop table t3| + + +# +# Test for BUG#16899: Possible buffer overflow in handling of DEFINER-clause. +# + +# Prepare. + +--disable_warnings +DROP PROCEDURE IF EXISTS bug16899_p1| +DROP FUNCTION IF EXISTS bug16899_f1| +--enable_warnings + +--error ER_WRONG_STRING_LENGTH +CREATE DEFINER=1234567890abcdefGHIKL@localhost PROCEDURE bug16899_p1() +BEGIN + SET @a = 1; +END| + +--error ER_WRONG_STRING_LENGTH +CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY + FUNCTION bug16899_f1() RETURNS INT +BEGIN + RETURN 1; +END| + + +# +# BUG#21416: SP: Recursion level higher than zero needed for non-recursive call +# +--disable_warnings +drop procedure if exists bug21416| +--enable_warnings +create procedure bug21416() show create procedure bug21416| +call bug21416()| +drop procedure bug21416| + + +# +# BUG#21414: SP: Procedure undroppable, to some extent +# +--disable_warnings +DROP PROCEDURE IF EXISTS bug21414| +--enable_warnings + +CREATE PROCEDURE bug21414() SELECT 1| + +FLUSH TABLES WITH READ LOCK| + +--error ER_CANT_UPDATE_WITH_READLOCK +DROP PROCEDURE bug21414| + +UNLOCK TABLES| + +--echo The following should succeed. +DROP PROCEDURE bug21414| + + +# +# BUG#21311: Possible stack overrun if SP has non-latin1 name +# +set names utf8| +--disable_warnings +drop database if exists това_е_дълго_име_за_база_данни_нали| +--enable_warnings +create database това_е_дълго_име_за_база_данни_нали| +INSERT INTO mysql.proc VALUES ('това_е_дълго_име_за_база_данни_нали','това_е_процедура_Ñ_доÑта_дълго_име_нали_и_още_по_дълго','PROCEDURE','това_е_процедура_Ñ_доÑта_дълго_име_нали_и_още_по_дълго','SQL','CONTAINS_SQL','NO','DEFINER','','','bad_body','root@localhost',now(), now(),'','')| +--error ER_SP_PROC_TABLE_CORRUPT +call това_е_дълго_име_за_база_данни_нали.това_е_процедура_Ñ_доÑта_дълго_име_нали_и_още_по_дълго()| +drop database това_е_дълго_име_за_база_данни_нали| + + +# +# BUG#21493: Crash on the second call of a procedure containing +# a select statement that uses an IN aggregating subquery +# + +CREATE TABLE t3 ( + Member_ID varchar(15) NOT NULL, + PRIMARY KEY (Member_ID) +)| + +CREATE TABLE t4 ( + 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 t3(Member_ID) VALUES + ('111111'), ('222222'), ('333333'), ('444444'), ('555555'), ('666666')| + +INSERT INTO t4(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' )| + +--disable_warnings +DROP FUNCTION IF EXISTS bug21493| +--enable_warnings + +CREATE FUNCTION bug21493(paramMember VARCHAR(15)) RETURNS varchar(45) +BEGIN +DECLARE tracks VARCHAR(45); +SELECT GROUP_CONCAT(Track SEPARATOR ', ') INTO tracks FROM t4 + WHERE Member_ID=paramMember AND Action='Enrolled' AND + (Track,Action_Date) IN (SELECT Track, MAX(Action_Date) FROM t4 + WHERE Member_ID=paramMember GROUP BY Track); +RETURN tracks; +END| + +SELECT bug21493('111111')| +SELECT bug21493('222222')| + +SELECT bug21493(Member_ID) FROM t3| + +DROP FUNCTION bug21493| +DROP TABLE t3,t4| + +# +# Bug#20028 Function with select return no data +# + +--disable_warnings +drop function if exists func_20028_a| +drop function if exists func_20028_b| +drop function if exists func_20028_c| +drop procedure if exists proc_20028_a| +drop procedure if exists proc_20028_b| +drop procedure if exists proc_20028_c| +drop table if exists table_20028| +--enable_warnings + +create table table_20028 (i int)| + +SET @save_sql_mode=@@sql_mode| + +SET sql_mode=''| + +create function func_20028_a() returns integer +begin + declare temp integer; + select i into temp from table_20028 limit 1; + return ifnull(temp, 0); +end| + +create function func_20028_b() returns integer +begin + return func_20028_a(); +end| + +create function func_20028_c() returns integer +begin + declare div_zero integer; + set SQL_MODE='TRADITIONAL'; + select 1/0 into div_zero; + return div_zero; +end| + +create procedure proc_20028_a() +begin + declare temp integer; + select i into temp from table_20028 limit 1; +end| + +create procedure proc_20028_b() +begin + call proc_20028_a(); +end| + +create procedure proc_20028_c() +begin + declare div_zero integer; + set SQL_MODE='TRADITIONAL'; + select 1/0 into div_zero; +end| + +select func_20028_a()| +select func_20028_b()| +--error ER_DIVISION_BY_ZERO +select func_20028_c()| +call proc_20028_a()| +call proc_20028_b()| +--error ER_DIVISION_BY_ZERO +call proc_20028_c()| + +SET sql_mode='TRADITIONAL'| + +drop function func_20028_a| +drop function func_20028_b| +drop function func_20028_c| +drop procedure proc_20028_a| +drop procedure proc_20028_b| +drop procedure proc_20028_c| + +create function func_20028_a() returns integer +begin + declare temp integer; + select i into temp from table_20028 limit 1; + return ifnull(temp, 0); +end| + +create function func_20028_b() returns integer +begin + return func_20028_a(); +end| + +create function func_20028_c() returns integer +begin + declare div_zero integer; + set SQL_MODE=''; + select 1/0 into div_zero; + return div_zero; +end| + +create procedure proc_20028_a() +begin + declare temp integer; + select i into temp from table_20028 limit 1; +end| + +create procedure proc_20028_b() +begin + call proc_20028_a(); +end| + +create procedure proc_20028_c() +begin + declare div_zero integer; + set SQL_MODE=''; + select 1/0 into div_zero; +end| + +select func_20028_a()| +select func_20028_b()| +select func_20028_c()| +call proc_20028_a()| +call proc_20028_b()| +call proc_20028_c()| + +SET @@sql_mode=@save_sql_mode| + +drop function func_20028_a| +drop function func_20028_b| +drop function func_20028_c| +drop procedure proc_20028_a| +drop procedure proc_20028_b| +drop procedure proc_20028_c| +drop table table_20028| + +# +# Bug#21462 Stored procedures with no arguments require parenthesis +# + +--disable_warnings +drop procedure if exists proc_21462_a| +drop procedure if exists proc_21462_b| +--enable_warnings + +create procedure proc_21462_a() +begin + select "Called A"; +end| + +create procedure proc_21462_b(x int) +begin + select "Called B"; +end| + +call proc_21462_a| +call proc_21462_a()| +-- error ER_SP_WRONG_NO_OF_ARGS +call proc_21462_a(1)| + +-- error ER_SP_WRONG_NO_OF_ARGS +call proc_21462_b| +-- error ER_SP_WRONG_NO_OF_ARGS +call proc_21462_b()| +call proc_21462_b(1)| + +drop procedure proc_21462_a| +drop procedure proc_21462_b| + +--echo End of 5.0 tests + + +# +# BUG#NNNN: New bug synopsis +# +#--disable_warnings +#drop procedure if exists bugNNNN| +#--enable_warnings +#create procedure bugNNNN... + +# Add bugs above this line. Use existing tables t1 and t2 when +# practical, or create table t3, t4 etc temporarily (and drop them). +delimiter ;| +drop table t1,t2; diff --git a/mysql-test/t/sp_notembedded.test b/mysql-test/t/sp_notembedded.test new file mode 100644 index 00000000000..4e18e69d3d2 --- /dev/null +++ b/mysql-test/t/sp_notembedded.test @@ -0,0 +1,287 @@ +# Can't test with embedded server +-- source include/not_embedded.inc + +--sleep 2 +--disable_warnings +drop table if exists t1,t3; +--enable_warnings +delimiter |; + +# +# BUG#4902: Stored procedure with SHOW WARNINGS leads to packet error +# +# Added tests for show grants command +--disable_warnings +drop procedure if exists bug4902| +--enable_warnings +create procedure bug4902() +begin + show grants for 'root'@'localhost'; +end| +--disable_parsing +show binlog events| +show storage engines| +show master status| +show slave hosts| +show slave status| +--enable_parsing + +call bug4902()| +call bug4902()| + +drop procedure bug4902| + +# We need separate SP for SHOW PROCESSLIST since we want use replace_column +--disable_warnings +drop procedure if exists bug4902_2| +--enable_warnings +create procedure bug4902_2() +begin + show processlist; +end| +--replace_column 1 # 6 # 3 localhost +call bug4902_2()| +--replace_column 1 # 6 # 3 localhost +call bug4902_2()| +drop procedure bug4902_2| + + +# +# BUG#5278: Stored procedure packets out of order if SET PASSWORD. +# +--disable_warnings +drop function if exists bug5278| +--enable_warnings +create function bug5278 () returns char +begin + SET PASSWORD FOR 'bob'@'%.loc.gov' = PASSWORD('newpass'); + return 'okay'; +end| + +--error 1133 +select bug5278()| +--error 1133 +select bug5278()| +drop function bug5278| + + +--disable_warnings +drop table if exists t1| +--enable_warnings +create table t1 ( + id char(16) not null default '', + data int not null +)| +# +# BUG#3583: query cache doesn't work for stored procedures +# +--disable_warnings +drop procedure if exists bug3583| +--enable_warnings +--disable_warnings +drop procedure if exists bug3583| +--enable_warnings +create procedure bug3583() +begin + declare c int; + + select * from t1; + select count(*) into c from t1; + select c; +end| + +insert into t1 values ("x", 3), ("y", 5)| +set @x = @@query_cache_size| +set global query_cache_size = 10*1024*1024| + +flush status| +flush query cache| +show status like 'Qcache_hits'| +call bug3583()| +show status like 'Qcache_hits'| +call bug3583()| +call bug3583()| +show status like 'Qcache_hits'| + +set global query_cache_size = @x| +flush status| +flush query cache| +delete from t1| +drop procedure bug3583| +drop table t1| + +# +# BUG#6807: Stored procedure crash if CREATE PROCEDURE ... KILL QUERY +# +--disable_warnings +drop procedure if exists bug6807| +--enable_warnings +create procedure bug6807() +begin + declare id int; + + set id = connection_id(); + kill query id; + select 'Not reached'; +end| + +--error 1317 +call bug6807()| +--error 1317 +call bug6807()| + +drop procedure bug6807| + + +# +# BUG#10100: function (and stored procedure?) recursivity problem +# +--disable_warnings +drop function if exists bug10100f| +drop procedure if exists bug10100p| +drop procedure if exists bug10100t| +drop procedure if exists bug10100pt| +drop procedure if exists bug10100pv| +drop procedure if exists bug10100pd| +drop procedure if exists bug10100pc| +--enable_warnings +# routines with simple recursion +create function bug10100f(prm int) returns int +begin + if prm > 1 then + return prm * bug10100f(prm - 1); + end if; + return 1; +end| +create procedure bug10100p(prm int, inout res int) +begin + set res = res * prm; + if prm > 1 then + call bug10100p(prm - 1, res); + end if; +end| +create procedure bug10100t(prm int) +begin + declare res int; + set res = 1; + call bug10100p(prm, res); + select res; +end| + +# a procedure which use tables and recursion +create table t3 (a int)| +insert into t3 values (0)| +create view v1 as select a from t3; +create procedure bug10100pt(level int, lim int) +begin + if level < lim then + update t3 set a=level; + FLUSH TABLES; + call bug10100pt(level+1, lim); + else + select * from t3; + end if; +end| +# view & recursion +create procedure bug10100pv(level int, lim int) +begin + if level < lim then + update v1 set a=level; + FLUSH TABLES; + call bug10100pv(level+1, lim); + else + select * from v1; + end if; +end| +# dynamic sql & recursion +prepare stmt2 from "select * from t3;"; +create procedure bug10100pd(level int, lim int) +begin + if level < lim then + select level; + prepare stmt1 from "update t3 set a=a+2"; + execute stmt1; + FLUSH TABLES; + execute stmt1; + FLUSH TABLES; + execute stmt1; + FLUSH TABLES; + deallocate prepare stmt1; + execute stmt2; + select * from t3; + call bug10100pd(level+1, lim); + else + execute stmt2; + end if; +end| +# cursor & recursion +create procedure bug10100pc(level int, lim int) +begin + declare lv int; + declare c cursor for select a from t3; + open c; + if level < lim then + select level; + fetch c into lv; + select lv; + update t3 set a=level+lv; + FLUSH TABLES; + call bug10100pc(level+1, lim); + else + select * from t3; + end if; + close c; +end| + +#end of the stack checking +set @@max_sp_recursion_depth=255| +set @var=1| +#disable log because error about stack overrun contains numbers which +#depend on a system +-- disable_result_log +-- error ER_STACK_OVERRUN_NEED_MORE +call bug10100p(255, @var)| +-- error ER_STACK_OVERRUN_NEED_MORE +call bug10100pt(1,255)| +-- error ER_STACK_OVERRUN_NEED_MORE +call bug10100pv(1,255)| +-- error ER_STACK_OVERRUN_NEED_MORE +call bug10100pd(1,255)| +-- error ER_STACK_OVERRUN_NEED_MORE +call bug10100pc(1,255)| +-- enable_result_log +set @@max_sp_recursion_depth=0| + +deallocate prepare stmt2| + +drop function bug10100f| +drop procedure bug10100p| +drop procedure bug10100t| +drop procedure bug10100pt| +drop procedure bug10100pv| +drop procedure bug10100pd| +drop procedure bug10100pc| +drop view v1| +drop table t3| + +delimiter ;| + +# +# Bug#15298 SHOW GRANTS FOR CURRENT_USER: Incorrect output in DEFINER context +# +--disable_warnings +drop procedure if exists bug15298_1; +drop procedure if exists bug15298_2; +--enable_warnings +grant all privileges on test.* to 'mysqltest_1'@'localhost'; +create procedure 15298_1 () sql security definer show grants for current_user; +create procedure 15298_2 () sql security definer show grants; + +connect (con1,localhost,mysqltest_1,,test); +call 15298_1(); +call 15298_2(); + +connection default; +drop user mysqltest_1@localhost; +drop procedure 15298_1; +drop procedure 15298_2; diff --git a/mysql-test/t/sp_trans.test b/mysql-test/t/sp_trans.test new file mode 100644 index 00000000000..1ea32316f1e --- /dev/null +++ b/mysql-test/t/sp_trans.test @@ -0,0 +1,564 @@ +# +# tests that require InnoDB... +# + +-- source include/have_innodb.inc + +--disable_warnings +drop table if exists t1, t2, t3; +--enable_warnings + +delimiter |; + +# +# BUG#8850: Truncate table in a stored procedure locks the tables +# +--disable_warnings +drop procedure if exists bug8850| +--enable_warnings +create table t1 (a int) engine=innodb| +create procedure bug8850() +begin + truncate table t1; insert t1 values (1); rollback; +end| + +set autocommit=0| +insert t1 values (2)| +call bug8850()| +commit| +select * from t1| + +call bug8850()| +set autocommit=1| +select * from t1| +drop table t1| +drop procedure bug8850| + + +# +# BUG#10015: Crash in InnoDB if stored routines are used +# (crash happens in auto-commit mode) +# +--disable_warnings +drop function if exists bug10015_1| +drop function if exists bug10015_2| +drop function if exists bug10015_3| +drop function if exists bug10015_4| +drop function if exists bug10015_5| +drop function if exists bug10015_6| +drop function if exists bug10015_7| +drop procedure if exists bug10015_8| +--enable_warnings +create table t1 (id int) engine=innodb| +create table t2 (id int primary key, j int) engine=innodb| +insert into t1 values (1),(2),(3)| +create function bug10015_1() returns int return (select count(*) from t1)| +select *, bug10015_1() from t1| +drop function bug10015_1| +# Test couple of a bit more complex cases +create function bug10015_2() returns int + begin + declare i, s int; + set i:= (select min(id) from t1); + set s:= (select max(id) from t1); + return (s - i); + end| +select *, bug10015_2() from t1| +drop function bug10015_2| +create function bug10015_3() returns int + return (select max(a.id - b.id) from t1 as a, t1 as b where a.id >= b.id)| +select *, bug10015_3() from t1| +drop function bug10015_3| +create function bug10015_4(i int) returns int + begin + declare m int; + set m:= (select max(id) from t2); + insert into t2 values (i, m); + return m; + end| +select *, bug10015_4(id) from t1| +select * from t2| +drop function bug10015_4| +# Now let us test how statement rollback works +# This function will cause the whole stmt to be rolled back, +# there should not be any traces left. +create function bug10015_5(i int) returns int + begin + if (i = 5) then + insert into t2 values (1, 0); + end if; + return i; + end| +--error 1062 +insert into t1 values (bug10015_5(4)), (bug10015_5(5))| +select * from t1| +drop function bug10015_5| +# Thanks to error-handler this function should not cause rollback +# of statement calling it. But insert statement in it should be +# rolled back completely and don't leave any traces in t2. +# Unfortunately we can't implement such behavior in 5.0, so it +# is something to be fixed in later 5.* releases (TODO). +create function bug10015_6(i int) returns int + begin + declare continue handler for sqlexception set @error_in_func:= 1; + if (i = 5) then + insert into t2 values (4, 0), (1, 0); + end if; + return i; + end| +set @error_in_func:= 0| +insert into t1 values (bug10015_6(5)), (bug10015_6(6))| +select @error_in_func| +select * from t1| +select * from t2| +drop function bug10015_6| +# Let us test that we don't allow any statements causing transaction +# commit in stored functions (we test only most interesting cases here). +# Cases which can be caught at creation time: +--error 1422 +create function bug10015_7() returns int + begin + alter table t1 add k int; + return 1; + end| +--error 1422 +create function bug10015_7() returns int + begin + start transaction; + return 1; + end| +--error 1422 +create function bug10015_7() returns int + begin + drop table t1; + return 1; + end| +# It should be OK to drop temporary table. +create function bug10015_7() returns int + begin + drop temporary table t1; + return 1; + end| +drop function bug10015_7| +--error 1422 +create function bug10015_7() returns int + begin + commit; + return 1; + end| +# Now let us test cases which we can catch only at run-time: +create function bug10015_7() returns int + begin + call bug10015_8(); + return 1; + end| +create procedure bug10015_8() alter table t1 add k int| +--error 1422 +select *, bug10015_7() from t1| +drop procedure bug10015_8| +create procedure bug10015_8() start transaction| +--error 1422 +select *, bug10015_7() from t1| +drop procedure bug10015_8| +# Again it is OK to drop temporary table +# We are surpressing warnings since they are not essential +create procedure bug10015_8() drop temporary table if exists t1_temp| +--disable_warnings +select *, bug10015_7() from t1| +--enable_warnings +drop procedure bug10015_8| +create procedure bug10015_8() commit| +--error 1422 +select *, bug10015_7() from t1| +drop procedure bug10015_8| +drop function bug10015_7| +drop table t1, t2| + + +# +# BUG#13825 "Triggers: crash if release savepoint". +# Also general test for handling of savepoints in stored routines. +# +# According to SQL standard we should establish new savepoint +# level before executing stored function/trigger and destroy +# this savepoint level after execution. Stored procedures by +# default should be executed using the same savepoint level +# as their caller (to execute stored procedure using new +# savepoint level one should explicitly specify NEW SAVEPOINT +# LEVEL clause in procedure creation statement which MySQL +# does not support yet). +--disable_warnings +drop function if exists bug13825_0| +drop function if exists bug13825_1| +drop function if exists bug13825_2| +drop function if exists bug13825_3| +drop function if exists bug13825_4| +drop function if exists bug13825_5| +drop procedure if exists bug13825_0| +drop procedure if exists bug13825_1| +drop procedure if exists bug13825_2| +drop table if exists t1| +--enable_warnings +create table t1 (i int) engine=innodb| +create table t2 (i int) engine=innodb| +create function bug13825_0() returns int +begin + rollback to savepoint x; + return 1; +end| +create function bug13825_1() returns int +begin + release savepoint x; + return 1; +end| +create function bug13825_2() returns int +begin + insert into t1 values (2); + savepoint x; + insert into t1 values (3); + rollback to savepoint x; + insert into t1 values (4); + return 1; +end| +create procedure bug13825_0() +begin + rollback to savepoint x; +end| +create procedure bug13825_1() +begin + release savepoint x; +end| +create procedure bug13825_2() +begin + savepoint x; +end| +insert into t2 values (1)| +create trigger t2_bi before insert on t2 for each row + rollback to savepoint x| +create trigger t2_bu before update on t2 for each row + release savepoint x| +create trigger t2_bd before delete on t2 for each row +begin + insert into t1 values (2); + savepoint x; + insert into t1 values (3); + rollback to savepoint x; + insert into t1 values (4); +end| +create function bug13825_3(rb int) returns int +begin + insert into t1 values(1); + savepoint x; + insert into t1 values(2); + if rb then + rollback to savepoint x; + end if; + insert into t1 values(3); + return rb; +end| +create function bug13825_4() returns int +begin + savepoint x; + insert into t1 values(2); + rollback to savepoint x; + return 0; +end| +create function bug13825_5(p int) returns int +begin + savepoint x; + insert into t2 values(p); + rollback to savepoint x; + insert into t2 values(p+1); + return p; +end| +set autocommit= 0| +# Test of savepoint level handling for stored functions and triggers +begin | +insert into t1 values (1)| +savepoint x| +--error ER_SP_DOES_NOT_EXIST +set @a:= bug13825_0()| +--error ER_SP_DOES_NOT_EXIST +insert into t2 values (2)| +--error ER_SP_DOES_NOT_EXIST +set @a:= bug13825_1()| +--error ER_SP_DOES_NOT_EXIST +update t2 set i = 2| +set @a:= bug13825_2()| +select * from t1| +rollback to savepoint x| +select * from t1| +delete from t2| +select * from t1| +rollback to savepoint x| +select * from t1| +# Of course savepoints set in function should not be visible from its caller +release savepoint x| +set @a:= bug13825_2()| +select * from t1| +--error ER_SP_DOES_NOT_EXIST +rollback to savepoint x| +delete from t1| +commit| +# Test of savepoint level handling for stored procedures +begin| +insert into t1 values (5)| +savepoint x| +insert into t1 values (6)| +call bug13825_0()| +select * from t1| +call bug13825_1()| +--error ER_SP_DOES_NOT_EXIST +rollback to savepoint x| +savepoint x| +insert into t1 values (7)| +call bug13825_2()| +rollback to savepoint x| +select * from t1| +delete from t1| +commit| +set autocommit= 1| +# Let us test that savepoints work inside of functions +# even in auto-commit mode +select bug13825_3(0)| +select * from t1| +delete from t1| +select bug13825_3(1)| +select * from t1| +delete from t1| +# Curious case: rolling back to savepoint which is set by first +# statement in function should not rollback whole transaction. +set autocommit= 0| +begin| +insert into t1 values (1)| +set @a:= bug13825_4()| +select * from t1| +delete from t1| +commit| +set autocommit= 1| +# Other curious case: savepoint in the middle of statement +drop table t2| +create table t2 (i int) engine=innodb| +insert into t1 values (1), (bug13825_5(2)), (3)| +select * from t1| +select * from t2| +# Cleanup +drop function bug13825_0| +drop function bug13825_1| +drop function bug13825_2| +drop function bug13825_3| +drop function bug13825_4| +drop function bug13825_5| +drop procedure bug13825_0| +drop procedure bug13825_1| +drop procedure bug13825_2| +drop table t1, t2| + + +# +# BUG#14840: CONTINUE handler problem +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug14840_1| +drop procedure if exists bug14840_2| +--enable_warnings + +create table t3 +( + x int, + y int, + primary key (x) +) engine=InnoDB| + +# This used to hang the client since the insert returned with an +# error status (left over from the update) even though it succeeded, +# which caused the execution to end at that point. +create procedure bug14840_1() +begin + declare err int default 0; + declare continue handler for sqlexception + set err = err + 1; + + start transaction; + update t3 set x = 1, y = 42 where x = 2; + insert into t3 values (3, 4711); + if err > 0 then + rollback; + else + commit; + end if; + select * from t3; +end| + +# A simpler (non-transactional) case: insert at select should be done +create procedure bug14840_2() +begin + declare err int default 0; + declare continue handler for sqlexception + begin + set err = err + 1; + select err as 'Ping'; + end; + + update t3 set x = 1, y = 42 where x = 2; + update t3 set x = 1, y = 42 where x = 2; + insert into t3 values (3, 4711); + select * from t3; +end| + +insert into t3 values (1, 3), (2, 5)| +call bug14840_1()| + +delete from t3| +insert into t3 values (1, 3), (2, 5)| +call bug14840_2()| + +drop procedure bug14840_1| +drop procedure bug14840_2| +drop table t3| + + +# +# BUG#10656: Stored Procedure - Create index and Truncate table command error +# +--disable_warnings +drop procedure if exists bug10656_create_index| +drop procedure if exists bug10656_myjoin| +drop procedure if exists bug10656_truncate_table| +--enable_warnings + +CREATE TABLE t3 ( + `ID` int(11) default NULL, + `txt` char(5) default NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1| + +INSERT INTO t3 (`ID`,`txt`) VALUES + (1,'a'), (2,'b'), (3,'c'), (4,'d')| + +CREATE TABLE t4 ( + `ID` int(11) default NULL, + `txt` char(5) default NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1| + +INSERT INTO t4 (`ID`,`txt`) VALUES + (1,'a'), (2,'b'), (3,'c'), (4,'d')| + +create procedure bug10656_create_index() +begin + create index bug10656_my_index on t3 (ID); +end| +call bug10656_create_index()| + +create procedure bug10656_myjoin() +begin + update t3, t4 set t3.txt = t4.txt where t3.id = t4.id; +end| +call bug10656_myjoin()| + +create procedure bug10656_truncate_table() +begin + truncate table t3; +end| +call bug10656_truncate_table()| + + +drop procedure bug10656_create_index| +drop procedure bug10656_myjoin| +drop procedure bug10656_truncate_table| +drop table t3, t4| + +# +# BUG#3448 +# +--disable_warnings +create table t3 ( + a int primary key, + ach char(1) +) engine = innodb| + +create table t4 ( + b int primary key, + bch char(1) +) engine = innodb| +--enable_warnings + +insert into t3 values (1 , 'aCh1' ) , ('2' , 'aCh2')| +insert into t4 values (1 , 'bCh1' )| + +--disable_warnings +drop procedure if exists bug3448| +--enable_warnings +create procedure bug3448() + select * from t3 inner join t4 on t3.a = t4.b| + +select * from t3 inner join t4 on t3.a = t4.b| +call bug3448()| +call bug3448()| + +drop procedure bug3448| +drop table t3, t4| + +# +# BUG#14210: "Simple query with > operator on large table gives server +# crash" +# Check that cursors work in case when HEAP tables are converted to +# MyISAM +# +--disable_warnings +drop procedure if exists bug14210| +--enable_warnings +set @@session.max_heap_table_size=16384| +select @@session.max_heap_table_size| +# To trigger the memory corruption the original table must be InnoDB. +# No harm if it's not, so don't warn if the suite is run with --skip-innodb +--disable_warnings +create table t3 (a char(255)) engine=InnoDB| +--enable_warnings +create procedure bug14210_fill_table() +begin + declare table_size, max_table_size int default 0; + select @@session.max_heap_table_size into max_table_size; + delete from t3; + insert into t3 (a) values (repeat('a', 255)); + repeat + insert into t3 select a from t3; + select count(*)*255 from t3 into table_size; + until table_size > max_table_size*2 end repeat; +end| +call bug14210_fill_table()| +drop procedure bug14210_fill_table| +create table t4 like t3| + +create procedure bug14210() +begin + declare a char(255); + declare done int default 0; + declare c cursor for select * from t3; + declare continue handler for sqlstate '02000' set done = 1; + open c; + repeat + fetch c into a; + if not done then + insert into t4 values (upper(a)); + end if; + until done end repeat; + close c; +end| +call bug14210()| +select count(*) from t4| + +drop table t3, t4| +drop procedure bug14210| +set @@session.max_heap_table_size=default| + + +# +# BUG#NNNN: New bug synopsis +# +#--disable_warnings +#drop procedure if exists bugNNNN| +#--enable_warnings +#create procedure bugNNNN... + +delimiter ;| diff --git a/mysql-test/t/sql_mode.test b/mysql-test/t/sql_mode.test index 7877f9acc40..2699cb66471 100644 --- a/mysql-test/t/sql_mode.test +++ b/mysql-test/t/sql_mode.test @@ -1,5 +1,6 @@ --disable_warnings -drop table if exists t1; +drop table if exists t1,t2,v1,v2; +drop view if exists t1,t2,v1,v2; --enable_warnings CREATE TABLE `t1` ( @@ -99,3 +100,171 @@ show create table t1; drop table t1; # End of 4.1 tests + +# +# test for +# WL 1941 "NO_C_ESCAPES sql_mode" +# +# an sql_mode to disable \n, \r, \b, etc escapes in string literals. actually, to +# disable special meaning of backslash completely. It's not in the SQL standard +# and it causes some R/3 tests to fail. +# + +SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE=''; +show local variables like 'SQL_MODE'; + +CREATE TABLE t1 (p int not null auto_increment, a varchar(20), primary key(p)); +INSERT t1 (a) VALUES +('\\'), +('\n'), +('\b'), +('\r'), +('\t'), +('\x'), +('\a'), +('\aa'), +('\\a'), +('\\aa'), +('_'), +('\_'), +('\\_'), +('\\\_'), +('\\\\_'), +('%'), +('\%'), +('\\%'), +('\\\%'), +('\\\\%') +; + +SELECT p, hex(a) FROM t1; + +delete from t1 where a in ('\n','\r','\t', '\b'); + +select + masks.p, + masks.a as mask, + examples.a as example +from + t1 as masks + left join t1 as examples on examples.a LIKE masks.a +order by masks.p, example; + +DROP TABLE t1; + +SET @@SQL_MODE='NO_BACKSLASH_ESCAPES'; +show local variables like 'SQL_MODE'; + +CREATE TABLE t1 (p int not null auto_increment, a varchar(20), primary key(p)); +INSERT t1 (a) VALUES +('\\'), +('\n'), +('\b'), +('\r'), +('\t'), +('\x'), +('\a'), +('\aa'), +('\\a'), +('\\aa'), +('_'), +('\_'), +('\\_'), +('\\\_'), +('\\\\_'), +('%'), +('\%'), +('\\%'), +('\\\%'), +('\\\\%') +; + +SELECT p, hex(a) FROM t1; + +delete from t1 where a in ('\n','\r','\t', '\b'); + +select + masks.p, + masks.a as mask, + examples.a as example +from + t1 as masks + left join t1 as examples on examples.a LIKE masks.a +order by masks.p, example; + +DROP TABLE t1; + +# Bug #6368: Make sure backslashes mixed with doubled quotes are handled +# correctly in NO_BACKSLASH_ESCAPES mode +SET @@SQL_MODE='NO_BACKSLASH_ESCAPES'; +SELECT 'a\\b', 'a\\\"b', 'a''\\b', 'a''\\\"b'; +SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b"; + +SET @@SQL_MODE=''; +SELECT 'a\\b', 'a\\\"b', 'a''\\b', 'a''\\\"b'; +SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b"; + +# +# Bug#6877: MySQL should give an error if the requested table type +# is not available +# + +set session sql_mode = 'NO_ENGINE_SUBSTITUTION'; +--error 1289 +create table t1 (a int) engine=isam; +--error 1146 +show create table t1; +drop table if exists t1; + +# for comparison, lets see the warnings... +set session sql_mode = ''; +create table t1 (a int) engine=isam; +show create table t1; +drop table t1; + +# +# Bug #6903: ANSI_QUOTES does not come into play with SHOW CREATE FUNCTION +# or PROCEDURE because it displays the SQL_MODE used to create the routine. +# +SET @@SQL_MODE=''; +create function `foo` () returns int return 5; +show create function `foo`; +SET @@SQL_MODE='ANSI_QUOTES'; +show create function `foo`; +drop function `foo`; + +create function `foo` () returns int return 5; +show create function `foo`; +SET @@SQL_MODE=''; +show create function `foo`; +drop function `foo`; + +# +# Bug #6903: ANSI_QUOTES should have effect for SHOW CREATE VIEW (Bug #6903) +# +SET @@SQL_MODE=''; +create table t1 (a int); +create table t2 (a int); +create view v1 as select a from t1; +show create view v1; +SET @@SQL_MODE='ANSI_QUOTES'; +show create view v1; +# Test a view with a subselect, which will get shown incorrectly without +# thd->lex->view_prepare_mode set properly. +create view v2 as select a from t2 where a in (select a from v1); +drop view v2, v1; +drop table t1, t2; + +select @@sql_mode; +set sql_mode=2097152; +select @@sql_mode; +# BUG#14675 +set sql_mode=4194304; +select @@sql_mode; +set sql_mode=16384+(65536*4); +select @@sql_mode; +--error 1231 +set sql_mode=2147483648; # that mode does not exist +select @@sql_mode; + +SET @@SQL_MODE=@OLD_SQL_MODE; diff --git a/mysql-test/t/ssl.test b/mysql-test/t/ssl.test new file mode 100644 index 00000000000..de88569d74a --- /dev/null +++ b/mysql-test/t/ssl.test @@ -0,0 +1,17 @@ +# Turn on ssl between the client and server +# and run a number of tests + +-- source include/have_openssl.inc + +connect (ssl_con,localhost,root,,,,,SSL); + +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; + +# Source select test case +-- source include/common-tests.inc + +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; + + diff --git a/mysql-test/t/ssl_compress.test b/mysql-test/t/ssl_compress.test new file mode 100644 index 00000000000..f5fe86e9a81 --- /dev/null +++ b/mysql-test/t/ssl_compress.test @@ -0,0 +1,22 @@ +# Turn on compression between the client and server +# and run a number of tests + +-- source include/have_openssl.inc +-- source include/have_compress.inc + +connect (ssl_compress_con,localhost,root,,,,,SSL COMPRESS); + +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; + +# Check compression turned on +SHOW STATUS LIKE 'Compression'; + +# Source select test case +-- source include/common-tests.inc + +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; + +# Check compression turned on +SHOW STATUS LIKE 'Compression'; diff --git a/mysql-test/t/ssl_des-master.opt b/mysql-test/t/ssl_des-master.opt new file mode 100644 index 00000000000..0b2b8cb85ac --- /dev/null +++ b/mysql-test/t/ssl_des-master.opt @@ -0,0 +1 @@ +--loose_ssl-cert=std_data/server-cert-des.pem --loose_ssl-key=std_data/server-key-des.pem diff --git a/mysql-test/t/ssl_des.test b/mysql-test/t/ssl_des.test new file mode 100644 index 00000000000..7cf2c920ab5 --- /dev/null +++ b/mysql-test/t/ssl_des.test @@ -0,0 +1,19 @@ +# Tell the server to use a DES-encrypted cert +# then turn on ssl between the client and server +# and run a number of standard tests + +-- source include/have_openssl.inc + +# Connect by ip to avoid turning on "ssl-verify-server-cert" +connect (ssl_con,127.0.0.1,root,,,,$MASTER_MYPORT,SSL); + +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; + +# Source select test case +-- source include/common-tests.inc + +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; + + diff --git a/mysql-test/t/status.test b/mysql-test/t/status.test index 7fea51c9327..1a71425d2a7 100644 --- a/mysql-test/t/status.test +++ b/mysql-test/t/status.test @@ -36,4 +36,111 @@ reap; show status like 'Table_lock%'; drop table t1; +disconnect con2; +disconnect con1; +connection default; + # End of 4.1 tests + +# +# last_query_cost +# + +select 1; +show status like 'last_query_cost'; + +# +# Test for Bug #15933 max_used_connections is wrong after FLUSH STATUS +# if connections are cached +# +# +# The first suggested fix from the bug report was chosen +# (see http://bugs.mysql.com/bug.php?id=15933): +# +# a) On flushing the status, set max_used_connections to +# threads_connected, not to 0. +# +# b) Check if it is necessary to increment max_used_connections when +# taking a thread from the cache as well as when creating new threads +# + +# Wait for at most $disconnect_timeout seconds for disconnects to finish. +let $disconnect_timeout = 10; + +# Wait for any previous disconnects to finish. +FLUSH STATUS; +--disable_query_log +--disable_result_log +eval SET @wait_left = $disconnect_timeout; +let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`; +eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0; +let $wait_more = `SELECT @max_used_connections != 1 && @wait_left > 0`; +while ($wait_more) +{ + sleep 1; + FLUSH STATUS; + SET @wait_left = @wait_left - 1; + let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`; + eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0; + let $wait_more = `SELECT @max_used_connections != 1 && @wait_left > 0`; +} +--enable_query_log +--enable_result_log + +# Prerequisite. +SHOW STATUS LIKE 'max_used_connections'; + +# Save original setting. +SET @save_thread_cache_size=@@thread_cache_size; +SET GLOBAL thread_cache_size=3; + +connect (con1,localhost,root,,); +connect (con2,localhost,root,,); + +connection con1; +disconnect con2; + +# Check that max_used_connections still reflects maximum value. +SHOW STATUS LIKE 'max_used_connections'; + +# Check that after flush max_used_connections equals to current number +# of connections. First wait for previous disconnect to finish. +FLUSH STATUS; +--disable_query_log +--disable_result_log +eval SET @wait_left = $disconnect_timeout; +let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`; +eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0; +let $wait_more = `SELECT @max_used_connections != 2 && @wait_left > 0`; +while ($wait_more) +{ + sleep 1; + FLUSH STATUS; + SET @wait_left = @wait_left - 1; + let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`; + eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0; + let $wait_more = `SELECT @max_used_connections != 2 && @wait_left > 0`; +} +--enable_query_log +--enable_result_log +# Check that we don't count disconnected thread any longer. +SHOW STATUS LIKE 'max_used_connections'; + +# Check that max_used_connections is updated when cached thread is +# reused... +connect (con2,localhost,root,,); +SHOW STATUS LIKE 'max_used_connections'; + +# ...and when new thread is created. +connect (con3,localhost,root,,); +SHOW STATUS LIKE 'max_used_connections'; + +# Restore original setting. +connection default; +SET GLOBAL thread_cache_size=@save_thread_cache_size; + +disconnect con3; +disconnect con2; +disconnect con1; + +# End of 5.0 tests diff --git a/mysql-test/t/strict.test b/mysql-test/t/strict.test new file mode 100644 index 00000000000..6ebbb53ed8e --- /dev/null +++ b/mysql-test/t/strict.test @@ -0,0 +1,1210 @@ +# Testing of "strict" mode + +-- source include/have_innodb.inc + +set @org_mode=@@sql_mode; +set @@sql_mode='ansi,traditional'; +select @@sql_mode; + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +# Test INSERT with DATE + +CREATE TABLE t1 (col1 date); +INSERT INTO t1 VALUES('2004-01-01'),('2004-02-29'); +--error 1292 +INSERT INTO t1 VALUES('0000-10-31'); + +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid date value> +--error 1292 +INSERT INTO t1 VALUES('2004-0-31'); +--error 1292 +INSERT INTO t1 VALUES('2004-01-02'),('2004-0-31'); +--error 1292 +INSERT INTO t1 VALUES('2004-10-0'); +--error 1292 +INSERT INTO t1 VALUES('2004-09-31'); +--error 1292 +INSERT INTO t1 VALUES('2004-10-32'); +--error 1292 +INSERT INTO t1 VALUES('2003-02-29'); +--error 1292 +INSERT INTO t1 VALUES('2004-13-15'); +--error 1292 +INSERT INTO t1 VALUES('0000-00-00'); +# Standard says we should return SQLSTATE 22018 +--error 1292 +INSERT INTO t1 VALUES ('59'); + +# Test the different related modes +set @@sql_mode='STRICT_ALL_TABLES'; +INSERT INTO t1 VALUES('2004-01-03'),('2004-0-31'); +set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_IN_DATE'; +--error 1292 +INSERT INTO t1 VALUES('2004-0-30'); +--error 1292 +INSERT INTO t1 VALUES('2004-01-04'),('2004-0-31'),('2004-01-05'); +INSERT INTO t1 VALUES('0000-00-00'); +INSERT IGNORE INTO t1 VALUES('2004-0-29'); +set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_DATE'; +--error 1292 +INSERT INTO t1 VALUES('0000-00-00'); +INSERT IGNORE INTO t1 VALUES('0000-00-00'); +INSERT INTO t1 VALUES ('2004-0-30'); +--error 1292 +INSERT INTO t1 VALUES ('2004-2-30'); +set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES'; +INSERT INTO t1 VALUES ('2004-2-30'); +set @@sql_mode='ansi,traditional'; +INSERT IGNORE INTO t1 VALUES('2004-02-29'),('2004-13-15'),('0000-00-00'); + +select * from t1; +drop table t1; + +# Test difference in behaviour with InnoDB and MyISAM tables + +set @@sql_mode='strict_trans_tables'; +CREATE TABLE t1 (col1 date) engine=myisam; +--error 1292 +INSERT INTO t1 VALUES('2004-13-31'),('2004-1-1'); +INSERT INTO t1 VALUES ('2004-1-2'), ('2004-13-31'),('2004-1-3'); +INSERT IGNORE INTO t1 VALUES('2004-13-31'),('2004-1-4'); +--error 1292 +INSERT INTO t1 VALUES ('2003-02-29'); +INSERT ignore INTO t1 VALUES('2003-02-30'); +set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES'; +INSERT ignore INTO t1 VALUES('2003-02-31'); +select * from t1; +drop table t1; + +set @@sql_mode='strict_trans_tables'; +CREATE TABLE t1 (col1 date) engine=innodb; +--error 1292 +INSERT INTO t1 VALUES('2004-13-31'),('2004-1-1'); +--error 1292 +INSERT INTO t1 VALUES ('2004-1-2'), ('2004-13-31'),('2004-1-3'); +INSERT IGNORE INTO t1 VALUES('2004-13-31'),('2004-1-4'); +--error 1292 +INSERT INTO t1 VALUES ('2003-02-29'); +INSERT ignore INTO t1 VALUES('2003-02-30'); +set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES'; +INSERT ignore INTO t1 VALUES('2003-02-31'); +select * from t1; +drop table t1; +set @@sql_mode='ansi,traditional'; + +# Test INSERT with DATETIME + +CREATE TABLE t1 (col1 datetime); +INSERT INTO t1 VALUES('2004-10-31 15:30:00'),('2004-02-29 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('0000-10-31 15:30:00'); + +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid datetime value> +--error 1292 +INSERT INTO t1 VALUES('2004-0-31 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-10-0 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-09-31 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-10-32 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2003-02-29 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-13-15 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('0000-00-00 15:30:00'); +# Standard says we should return SQLSTATE 22018 +--error 1292 +INSERT INTO t1 VALUES ('59'); +select * from t1; +drop table t1; + +# Test INSERT with TIMESTAMP + +CREATE TABLE t1 (col1 timestamp); +INSERT INTO t1 VALUES('2004-10-31 15:30:00'),('2004-02-29 15:30:00'); + +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid datetime value> +# Standard says we should return ok, but we can't as this is out of range +--error 1292 +INSERT INTO t1 VALUES('0000-10-31 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-0-31 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-10-0 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-09-31 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-10-32 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2003-02-29 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-13-15 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-02-29 25:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-02-29 15:65:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-02-29 15:31:61'); +--error 1292 +INSERT INTO t1 VALUES('0000-00-00 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('0000-00-00 00:00:00'); +INSERT IGNORE INTO t1 VALUES('0000-00-00 00:00:00'); +# Standard says we should return SQLSTATE 22018 +--error 1292 +INSERT INTO t1 VALUES ('59'); + +set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES'; +--error 1292 +INSERT INTO t1 VALUES('2004-0-31 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-10-0 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-10-32 15:30:00'); +--error 1292 +INSERT INTO t1 VALUES('2004-02-30 15:30:04'); +INSERT INTO t1 VALUES('0000-00-00 00:00:00'); +set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_IN_DATE'; +INSERT INTO t1 VALUES('0000-00-00 00:00:00'); +set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_DATE'; +--error 1292 +INSERT INTO t1 VALUES('0000-00-00 00:00:00'); +set @@sql_mode='ansi,traditional'; +SELECT * FROM t1; +DROP TABLE t1; + + +#### Test INSERT with STR_TO_DATE into DATE/DATETIME/TIMESTAMP + +CREATE TABLE t1 (col1 date, col2 datetime, col3 timestamp); + +INSERT INTO t1 (col1) VALUES (STR_TO_DATE('15.10.2004','%d.%m.%Y')); +INSERT INTO t1 (col2) VALUES (STR_TO_DATE('15.10.2004 10.15','%d.%m.%Y %H.%i')); +INSERT INTO t1 (col3) VALUES (STR_TO_DATE('15.10.2004 10.15','%d.%m.%Y %H.%i')); + +## Test INSERT with STR_TO_DATE into DATE +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid date value> + +--error 1292 +INSERT INTO t1 (col1) VALUES(STR_TO_DATE('31.10.0000 15.30','%d.%m.%Y %H.%i')); + +--error 1292 +INSERT INTO t1 (col1) VALUES(STR_TO_DATE('31.0.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col1) VALUES(STR_TO_DATE('0.10.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col1) VALUES(STR_TO_DATE('31.9.2004 15.30','%d.%m.%Y %H.%i')); +--error 1411 +INSERT INTO t1 (col1) VALUES(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col1) VALUES(STR_TO_DATE('29.02.2003 15.30','%d.%m.%Y %H.%i')); +--error 1411 +INSERT INTO t1 (col1) VALUES(STR_TO_DATE('15.13.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col1) VALUES(STR_TO_DATE('00.00.0000','%d.%m.%Y')); + +## Test INSERT with STR_TO_DATE into DATETIME +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid datetime value> + +--error 1292 +INSERT INTO t1 (col2) VALUES(STR_TO_DATE('31.10.0000 15.30','%d.%m.%Y %H.%i')); + +--error 1292 +INSERT INTO t1 (col2) VALUES(STR_TO_DATE('31.0.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col2) VALUES(STR_TO_DATE('0.10.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col2) VALUES(STR_TO_DATE('31.9.2004 15.30','%d.%m.%Y %H.%i')); +--error 1411 +INSERT INTO t1 (col2) VALUES(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col2) VALUES(STR_TO_DATE('29.02.2003 15.30','%d.%m.%Y %H.%i')); +--error 1411 +INSERT INTO t1 (col2) VALUES(STR_TO_DATE('15.13.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col2) VALUES(STR_TO_DATE('00.00.0000','%d.%m.%Y')); + +## Test INSERT with STR_TO_DATE into TIMESTAMP +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid datetime value> + +--error 1292 +INSERT INTO t1 (col3) VALUES(STR_TO_DATE('31.10.0000 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col3) VALUES(STR_TO_DATE('31.0.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col3) VALUES(STR_TO_DATE('0.10.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col3) VALUES(STR_TO_DATE('31.9.2004 15.30','%d.%m.%Y %H.%i')); +--error 1411 +INSERT INTO t1 (col3) VALUES(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col3) VALUES(STR_TO_DATE('29.02.2003 15.30','%d.%m.%Y %H.%i')); +--error 1411 +INSERT INTO t1 (col3) VALUES(STR_TO_DATE('15.13.2004 15.30','%d.%m.%Y %H.%i')); +--error 1292 +INSERT INTO t1 (col3) VALUES(STR_TO_DATE('00.00.0000','%d.%m.%Y')); + +drop table t1; + + +#### Test INSERT with CAST AS DATE/DATETIME into DATE/DATETIME/TIMESTAMP + +CREATE TABLE t1 (col1 date, col2 datetime, col3 timestamp); + +INSERT INTO t1 (col1) VALUES (CAST('2004-10-15' AS DATE)); +INSERT INTO t1 (col2) VALUES (CAST('2004-10-15 10:15' AS DATETIME)); +INSERT INTO t1 (col3) VALUES (CAST('2004-10-15 10:15' AS DATETIME)); + + +## Test INSERT with CAST AS DATE into DATE +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid date value> + +--error 1292 +INSERT INTO t1 (col1) VALUES(CAST('0000-10-31' AS DATE)); + +--error 1292 +INSERT INTO t1 (col1) VALUES(CAST('2004-10-0' AS DATE)); +--error 1292 +INSERT INTO t1 (col1) VALUES(CAST('2004-0-10' AS DATE)); + +# deactivated because of Bug#8294 +# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE +# --error 1292 +# INSERT INTO t1 (col1) VALUES(CAST('2004-9-31' AS DATE)); +# --error 1292 +# INSERT INTO t1 (col1) VALUES(CAST('2004-10-32' AS DATE)); +# --error 1292 +# INSERT INTO t1 (col1) VALUES(CAST('2003-02-29' AS DATE)); +# --error 1292 +# INSERT INTO t1 (col1) VALUES(CAST('2004-13-15' AS DATE)); + +# deactivated because of Bug#6145 +# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values +--error 1292 +INSERT INTO t1 (col1) VALUES(CAST('0000-00-00' AS DATE)); + +## Test INSERT with CAST AS DATETIME into DATETIME +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid datetime value> + +--error 1292 +INSERT INTO t1 (col2) VALUES(CAST('0000-10-31 15:30' AS DATETIME)); + +--error 1292 +INSERT INTO t1 (col2) VALUES(CAST('2004-10-0 15:30' AS DATETIME)); +--error 1292 +INSERT INTO t1 (col2) VALUES(CAST('2004-0-10 15:30' AS DATETIME)); + +# deactivated because of Bug#8294 +# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE +#--error 1292 +#INSERT INTO t1 (col2) VALUES(CAST('2004-9-31 15:30' AS DATETIME)); +#--error 1292 +#INSERT INTO t1 (col2) VALUES(CAST('2004-10-32 15:30' AS DATETIME)); +#--error 1292 +#INSERT INTO t1 (col2) VALUES(CAST('2003-02-29 15:30' AS DATETIME)); +#--error 1292 +#INSERT INTO t1 (col2) VALUES(CAST('2004-13-15 15:30' AS DATETIME)); + +# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values +--error 1292 +INSERT INTO t1 (col2) VALUES(CAST('0000-00-00' AS DATETIME)); + +## Test INSERT with CAST AS DATETIME into TIMESTAMP +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid datetime value> +--error 1292 +INSERT INTO t1 (col3) VALUES(CAST('0000-10-31 15:30' AS DATETIME)); +-- should return OK +-- We accept this to be a failure + +--error 1292 +INSERT INTO t1 (col3) VALUES(CAST('2004-10-0 15:30' AS DATETIME)); +--error 1292 +INSERT INTO t1 (col3) VALUES(CAST('2004-0-10 15:30' AS DATETIME)); +-- should return SQLSTATE 22007 <invalid datetime value> + +# deactivated because of Bug#8294 +# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE +#--error 1292 +#INSERT INTO t1 (col3) VALUES(CAST('2004-9-31 15:30' AS DATETIME)); +#--error 1292 +#INSERT INTO t1 (col3) VALUES(CAST('2004-10-32 15:30' AS DATETIME)); +#--error 1292 +#INSERT INTO t1 (col3) VALUES(CAST('2003-02-29 15:30' AS DATETIME)); +#--error 1292 +#INSERT INTO t1 (col3) VALUES(CAST('2004-13-15 15:30' AS DATETIME)); + +# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values +--error 1292 +INSERT INTO t1 (col3) VALUES(CAST('0000-00-00' AS DATETIME)); + +drop table t1; + + +#### Test INSERT with CONVERT to DATE/DATETIME into DATE/DATETIME/TIMESTAMP + +CREATE TABLE t1 (col1 date, col2 datetime, col3 timestamp); + +INSERT INTO t1 (col1) VALUES (CONVERT('2004-10-15',DATE)); +INSERT INTO t1 (col2) VALUES (CONVERT('2004-10-15 10:15',DATETIME)); +INSERT INTO t1 (col3) VALUES (CONVERT('2004-10-15 10:15',DATETIME)); + + +## Test INSERT with CONVERT to DATE into DATE +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid date value> + +--error 1292 +INSERT INTO t1 (col1) VALUES(CONVERT('0000-10-31' , DATE)); + +--error 1292 +INSERT INTO t1 (col1) VALUES(CONVERT('2004-10-0' , DATE)); +--error 1292 +INSERT INTO t1 (col1) VALUES(CONVERT('2004-0-10' , DATE)); + +# deactivated because of Bug#8294 +# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE +#--error 1292 +#INSERT INTO t1 (col1) VALUES(CONVERT('2004-9-31' , DATE)); +#--error 1292 +#INSERT INTO t1 (col1) VALUES(CONVERT('2004-10-32' , DATE)); +#--error 1292 +#INSERT INTO t1 (col1) VALUES(CONVERT('2003-02-29' , DATE)); +#--error 1292 +#INSERT INTO t1 (col1) VALUES(CONVERT('2004-13-15',DATE)); + +# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values +--error 1292 +INSERT INTO t1 (col1) VALUES(CONVERT('0000-00-00',DATE)); + +## Test INSERT with CONVERT to DATETIME into DATETIME +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid datetime value> + +--error 1292 +INSERT INTO t1 (col2) VALUES(CONVERT('0000-10-31 15:30',DATETIME)); + +--error 1292 +INSERT INTO t1 (col2) VALUES(CONVERT('2004-10-0 15:30',DATETIME)); +--error 1292 +INSERT INTO t1 (col2) VALUES(CONVERT('2004-0-10 15:30',DATETIME)); + +# deactivated because of Bug#8294 +# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE +#--error 1292 +#INSERT INTO t1 (col2) VALUES(CONVERT('2004-9-31 15:30',DATETIME)); +#--error 1292 +#INSERT INTO t1 (col2) VALUES(CONVERT('2004-10-32 15:30',DATETIME)); +#--error 1292 +#INSERT INTO t1 (col2) VALUES(CONVERT('2003-02-29 15:30',DATETIME)); +#--error 1292 +#INSERT INTO t1 (col2) VALUES(CONVERT('2004-13-15 15:30',DATETIME)); + +# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values +--error 1292 +INSERT INTO t1 (col2) VALUES(CONVERT('0000-00-00',DATETIME)); + +## Test INSERT with CONVERT to DATETIME into DATETIME +# All test cases expected to fail should return +# SQLSTATE 22007 <invalid datetime value> +--error 1292 +INSERT INTO t1 (col3) VALUES(CONVERT('0000-10-31 15:30',DATETIME)); +-- should return OK +-- We accept this to be a failure + +--error 1292 +INSERT INTO t1 (col3) VALUES(CONVERT('2004-10-0 15:30',DATETIME)); +--error 1292 +INSERT INTO t1 (col3) VALUES(CONVERT('2004-0-10 15:30',DATETIME)); + +# deactivated because of Bug#8294 +# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE +#--error 1292 +#INSERT INTO t1 (col3) VALUES(CONVERT('2004-9-31 15:30',DATETIME)); +#--error 1292 +#INSERT INTO t1 (col3) VALUES(CONVERT('2004-10-32 15:30',DATETIME)); +#--error 1292 +#INSERT INTO t1 (col3) VALUES(CONVERT('2003-02-29 15:30',DATETIME)); +#--error 1292 +#INSERT INTO t1 (col3) VALUES(CONVERT('2004-13-15 15:30',DATETIME)); + +# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values +--error 1292 +INSERT INTO t1 (col3) VALUES(CONVERT('0000-00-00',DATETIME)); + +drop table t1; + + +# Test INSERT with TINYINT + +CREATE TABLE t1(col1 TINYINT, col2 TINYINT UNSIGNED); +INSERT INTO t1 VALUES(-128,0),(0,0),(127,255),('-128','0'),('0','0'),('127','255'),(-128.0,0.0),(0.0,0.0),(127.0,255.0); +# Test that we restored the mode checking properly after an ok query +SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 2; +-- error 1264 +INSERT INTO t1 (col1) VALUES(-129); +-- error 1264 +INSERT INTO t1 (col1) VALUES(128); +-- error 1264 +INSERT INTO t1 (col2) VALUES(-1); +-- error 1264 +INSERT INTO t1 (col2) VALUES(256); +-- error 1264 +INSERT INTO t1 (col1) VALUES('-129'); +-- error 1264 +INSERT INTO t1 (col1) VALUES('128'); +-- error 1264 +INSERT INTO t1 (col2) VALUES('-1'); +-- error 1264 +INSERT INTO t1 (col2) VALUES('256'); +-- error 1264 +INSERT INTO t1 (col1) VALUES(128.0); +-- error 1264 +INSERT INTO t1 (col2) VALUES(-1.0); +-- error 1264 +INSERT INTO t1 (col2) VALUES(256.0); +SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 1; +--error 1264 +UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0; +--error 1264 +UPDATE t1 SET col2=col2 + 50 WHERE col2 > 0; +--error 1365 +UPDATE t1 SET col1=col1 / 0 WHERE col1 > 0; +set @@sql_mode='ERROR_FOR_DIVISION_BY_ZERO'; +INSERT INTO t1 values (1/0,1/0); +set @@sql_mode='ansi,traditional'; +SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 2; +# Should return SQLSTATE 22018 invalid character value for cast +--error 1366 +INSERT INTO t1 (col1) VALUES (''); +--error 1366 +INSERT INTO t1 (col1) VALUES ('a59b'); +--error 1265 +INSERT INTO t1 (col1) VALUES ('1a'); +INSERT IGNORE INTO t1 (col1) VALUES ('2a'); +INSERT IGNORE INTO t1 values (1/0,1/0); +set @@sql_mode='ansi'; +INSERT INTO t1 values (1/0,1/0); +set @@sql_mode='ansi,traditional'; +INSERT IGNORE INTO t1 VALUES('-129','-1'),('128','256'); +INSERT IGNORE INTO t1 VALUES(-129.0,-1.0),(128.0,256.0); +UPDATE IGNORE t1 SET col2=1/NULL where col1=0; + +SELECT * FROM t1; +DROP TABLE t1; + +# Test INSERT with SMALLINT + +CREATE TABLE t1(col1 SMALLINT, col2 SMALLINT UNSIGNED); +INSERT INTO t1 VALUES(-32768,0),(0,0),(32767,65535),('-32768','0'),('32767','65535'),(-32768.0,0.0),(32767.0,65535.0); + +--error 1264 +INSERT INTO t1 (col1) VALUES(-32769); +--error 1264 +INSERT INTO t1 (col1) VALUES(32768); +--error 1264 +INSERT INTO t1 (col2) VALUES(-1); +--error 1264 +INSERT INTO t1 (col2) VALUES(65536); +--error 1264 +INSERT INTO t1 (col1) VALUES('-32769'); +--error 1264 +INSERT INTO t1 (col1) VALUES('32768'); +--error 1264 +INSERT INTO t1 (col2) VALUES('-1'); +--error 1264 +INSERT INTO t1 (col2) VALUES('65536'); +--error 1264 +INSERT INTO t1 (col1) VALUES(-32769.0); +--error 1264 +INSERT INTO t1 (col1) VALUES(32768.0); +--error 1264 +INSERT INTO t1 (col2) VALUES(-1.0); +--error 1264 +INSERT INTO t1 (col2) VALUES(65536.0); +--error 1264 +UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0; +--error 1264 +UPDATE t1 SET col2 = col2 + 50 WHERE col2 > 0; +--error 1365 +UPDATE t1 SET col1 = col1 / 0 WHERE col1 > 0; +--error 1365 +UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0; +--error 1366 +INSERT INTO t1 (col1) VALUES (''); +--error 1366 +INSERT INTO t1 (col1) VALUES ('a59b'); +--error 1265 +INSERT INTO t1 (col1) VALUES ('1a'); +INSERT IGNORE INTO t1 (col1) VALUES ('2a'); +INSERT IGNORE INTO t1 values (1/0,1/0); +INSERT IGNORE INTO t1 VALUES(-32769,-1),(32768,65536); +INSERT IGNORE INTO t1 VALUES('-32769','-1'),('32768','65536'); +INSERT IGNORE INTO t1 VALUES(-32769,-1.0),(32768.0,65536.0); +UPDATE IGNORE t1 SET col2=1/NULL where col1=0; + +SELECT * FROM t1; +DROP TABLE t1; + +# Test INSERT with MEDIUMINT + +CREATE TABLE t1 (col1 MEDIUMINT, col2 MEDIUMINT UNSIGNED); +INSERT INTO t1 VALUES(-8388608,0),(0,0),(8388607,16777215),('-8388608','0'),('8388607','16777215'),(-8388608.0,0.0),(8388607.0,16777215.0); +--error 1264 +INSERT INTO t1 (col1) VALUES(-8388609); +--error 1264 +INSERT INTO t1 (col1) VALUES(8388608); +--error 1264 +INSERT INTO t1 (col2) VALUES(-1); +--error 1264 +INSERT INTO t1 (col2) VALUES(16777216); +--error 1264 +INSERT INTO t1 (col1) VALUES('-8388609'); +--error 1264 +INSERT INTO t1 (col1) VALUES('8388608'); +--error 1264 +INSERT INTO t1 (col2) VALUES('-1'); +--error 1264 +INSERT INTO t1 (col2) VALUES('16777216'); +--error 1264 +INSERT INTO t1 (col1) VALUES(-8388609.0); +--error 1264 +INSERT INTO t1 (col1) VALUES(8388608.0); +--error 1264 +INSERT INTO t1 (col2) VALUES(-1.0); +--error 1264 +INSERT INTO t1 (col2) VALUES(16777216.0); + +--error 1264 +UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0; +--error 1264 +UPDATE t1 SET col2 = col2 + 50 WHERE col2 > 0; +--error 1365 +UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0; +--error 1365 +UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0; +--error 1366 +INSERT INTO t1 (col1) VALUES (''); +--error 1366 +INSERT INTO t1 (col1) VALUES ('a59b'); +--error 1265 +INSERT INTO t1 (col1) VALUES ('1a'); +INSERT IGNORE INTO t1 (col1) VALUES ('2a'); +INSERT IGNORE INTO t1 values (1/0,1/0); +INSERT IGNORE INTO t1 VALUES(-8388609,-1),(8388608,16777216); +INSERT IGNORE INTO t1 VALUES('-8388609','-1'),('8388608','16777216'); +INSERT IGNORE INTO t1 VALUES(-8388609.0,-1.0),(8388608.0,16777216.0); +UPDATE IGNORE t1 SET col2=1/NULL where col1=0; + +SELECT * FROM t1; +DROP TABLE t1; + +# Test INSERT with INT + +CREATE TABLE t1 (col1 INT, col2 INT UNSIGNED); +INSERT INTO t1 VALUES(-2147483648,0),(0,0),(2147483647,4294967295),('-2147483648','0'),('2147483647','4294967295'),(-2147483648.0,0.0),(2147483647.0,4294967295.0); +--error 1264 +INSERT INTO t1 (col1) VALUES(-2147483649); +--error 1264 +INSERT INTO t1 (col1) VALUES(2147643648); +--error 1264 +INSERT INTO t1 (col2) VALUES(-1); +--error 1264 +INSERT INTO t1 (col2) VALUES(4294967296); +--error 1264 +INSERT INTO t1 (col1) VALUES('-2147483649'); +--error 1264 +INSERT INTO t1 (col1) VALUES('2147643648'); +--error 1264 +INSERT INTO t1 (col2) VALUES('-1'); +--error 1264 +INSERT INTO t1 (col2) VALUES('4294967296'); +--error 1264 +INSERT INTO t1 (col1) VALUES(-2147483649.0); +--error 1264 +INSERT INTO t1 (col1) VALUES(2147643648.0); +--error 1264 +INSERT INTO t1 (col2) VALUES(-1.0); +--error 1264 +INSERT INTO t1 (col2) VALUES(4294967296.0); + +--error 1264 +UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0; +--error 1264 +UPDATE t1 SET col2 =col2 + 50 WHERE col2 > 0; +--error 1365 +UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0; +--error 1365 +UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0; +--error 1366 +INSERT INTO t1 (col1) VALUES (''); +--error 1366 +INSERT INTO t1 (col1) VALUES ('a59b'); +--error 1265 +INSERT INTO t1 (col1) VALUES ('1a'); +INSERT IGNORE INTO t1 (col1) VALUES ('2a'); +INSERT IGNORE INTO t1 values (1/0,1/0); +INSERT IGNORE INTO t1 values (-2147483649, -1),(2147643648,4294967296); +INSERT IGNORE INTO t1 values ('-2147483649', '-1'),('2147643648','4294967296'); +INSERT IGNORE INTO t1 values (-2147483649.0, -1.0),(2147643648.0,4294967296.0); +UPDATE IGNORE t1 SET col2=1/NULL where col1=0; +SELECT * FROM t1; +DROP TABLE t1; + +# Test INSERT with BIGINT +# Note that this doesn't behave 100 % to standard as we rotate +# integers when it's too big/small (just like C) + +CREATE TABLE t1 (col1 BIGINT, col2 BIGINT UNSIGNED); +INSERT INTO t1 VALUES(-9223372036854775808,0),(0,0),(9223372036854775807,18446744073709551615); +INSERT INTO t1 VALUES('-9223372036854775808','0'),('9223372036854775807','18446744073709551615'); +INSERT INTO t1 VALUES(-9223372036854774000.0,0.0),(9223372036854775700.0,1844674407370954000.0); + +--error 1264 +INSERT INTO t1 (col1) VALUES(-9223372036854775809); +--error 1264 +INSERT INTO t1 (col1) VALUES(9223372036854775808); +--error 1264 +INSERT INTO t1 (col2) VALUES(-1); + +--error 1264 +INSERT INTO t1 (col2) VALUES(18446744073709551616); +--error 1264 +INSERT INTO t1 (col1) VALUES('-9223372036854775809'); +--error 1264 +INSERT INTO t1 (col1) VALUES('9223372036854775808'); +--error 1264 +INSERT INTO t1 (col2) VALUES('-1'); +--error 1264 +INSERT INTO t1 (col2) VALUES('18446744073709551616'); + +# Note that the following two double numbers are slighty bigger than max/min +# bigint becasue of rounding errors when converting it to bigint +--error 1264 +INSERT INTO t1 (col1) VALUES(-9223372036854785809.0); +--error 1264 +INSERT INTO t1 (col1) VALUES(9223372036854785808.0); +--error 1264 +INSERT INTO t1 (col2) VALUES(-1.0); +--error 1264 +INSERT INTO t1 (col2) VALUES(18446744073709551616.0); + +# The following doesn't give an error as it's done in integer context +# UPDATE t1 SET col1=col1 - 5000 WHERE col1 < 0; +# UPDATE t1 SET col2 =col2 + 5000 WHERE col2 > 0; + +--error 1365 +UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0; +--error 1365 +UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0; +--error 1366 +INSERT INTO t1 (col1) VALUES (''); +--error 1366 +INSERT INTO t1 (col1) VALUES ('a59b'); +--error 1265 +INSERT INTO t1 (col1) VALUES ('1a'); +INSERT IGNORE INTO t1 (col1) VALUES ('2a'); +INSERT IGNORE INTO t1 values (1/0,1/0); +INSERT IGNORE INTO t1 VALUES(-9223372036854775809,-1),(9223372036854775808,18446744073709551616); +INSERT IGNORE INTO t1 VALUES('-9223372036854775809','-1'),('9223372036854775808','18446744073709551616'); +INSERT IGNORE INTO t1 VALUES(-9223372036854785809.0,-1.0),(9223372036854785808.0,18446744073709551616.0); +UPDATE IGNORE t1 SET col2=1/NULL where col1=0; +SELECT * FROM t1; +DROP TABLE t1; + +# Test INSERT with NUMERIC + +CREATE TABLE t1 (col1 NUMERIC(4,2)); +INSERT INTO t1 VALUES (10.55),(10.5555),(0),(-10.55),(-10.5555),(11),(1e+01); +-- Note that the +/-10.5555 is inserted as +/-10.55, not +/-10.56 ! +INSERT INTO t1 VALUES ('10.55'),('10.5555'),('-10.55'),('-10.5555'),('11'),('1e+01'); + +-- The 2 following inserts should generate a warning, but doesn't yet +-- because NUMERIC works like DECIMAL +--error 1264 +INSERT INTO t1 VALUES (101.55); +--error 1264 +INSERT INTO t1 VALUES (101); +--error 1264 +INSERT INTO t1 VALUES (-101.55); +--error 1264 +INSERT INTO t1 VALUES (1010.55); +--error 1264 +INSERT INTO t1 VALUES (1010); +-- The 2 following inserts should generate a warning, but doesn't yet +-- because NUMERIC works like DECIMAL +--error 1264 +INSERT INTO t1 VALUES ('101.55'); +--error 1264 +INSERT INTO t1 VALUES ('101'); +--error 1264 +INSERT INTO t1 VALUES ('-101.55'); +--error 1264 +INSERT INTO t1 VALUES ('-1010.55'); +--error 1264 +INSERT INTO t1 VALUES ('-100E+1'); +--error 1366 +INSERT INTO t1 VALUES ('-100E'); +--error 1264 +UPDATE t1 SET col1 =col1 * 50000 WHERE col1 =11; +--error 1365 +UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0; +--error 1365 +UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0; +#--error 1265 +--error 1366 +INSERT INTO t1 (col1) VALUES (''); +#--error 1265 +--error 1366 +INSERT INTO t1 (col1) VALUES ('a59b'); +--error 1366 +INSERT INTO t1 (col1) VALUES ('1a'); +INSERT IGNORE INTO t1 (col1) VALUES ('2a'); +INSERT IGNORE INTO t1 values (1/0); +INSERT IGNORE INTO t1 VALUES(1000),(-1000); +INSERT IGNORE INTO t1 VALUES('1000'),('-1000'); +INSERT IGNORE INTO t1 VALUES(1000.0),(-1000.0); +UPDATE IGNORE t1 SET col1=1/NULL where col1=0; +SELECT * FROM t1; +DROP TABLE t1; + +# Test INSERT with FLOAT + +CREATE TABLE t1 (col1 FLOAT, col2 FLOAT UNSIGNED); +INSERT INTO t1 VALUES (-1.1E-37,0),(+3.4E+38,+3.4E+38); +INSERT INTO t1 VALUES ('-1.1E-37',0),('+3.4E+38','+3.4E+38'); +# We don't give warnings for underflow +INSERT INTO t1 (col1) VALUES (3E-46); +--error 1264 +INSERT INTO t1 (col1) VALUES (+3.4E+39); +--error 1264 +INSERT INTO t1 (col2) VALUES (-1.1E-3); +--error 1264 +INSERT INTO t1 (col1) VALUES ('+3.4E+39'); +--error 1264 +INSERT INTO t1 (col2) VALUES ('-1.1E-3'); +--error 1264 +UPDATE t1 SET col1 =col1 * 5000 WHERE col1 > 0; +--error 1365 +UPDATE t1 SET col2 =col2 / 0 WHERE col2 > 0; +--error 1365 +UPDATE t1 SET col2= MOD(col2,0) WHERE col2 > 0; +--error 1265 +INSERT INTO t1 (col1) VALUES (''); +--error 1265 +INSERT INTO t1 (col1) VALUES ('a59b'); +--error 1265 +INSERT INTO t1 (col1) VALUES ('1a'); +INSERT IGNORE INTO t1 (col1) VALUES ('2a'); +INSERT IGNORE INTO t1 (col1) VALUES (1/0); +INSERT IGNORE INTO t1 VALUES (+3.4E+39,-3.4E+39); +INSERT IGNORE INTO t1 VALUES ('+3.4E+39','-3.4E+39'); +SELECT * FROM t1; +DROP TABLE t1; + +# Test INSERT with DOUBLE + +CREATE TABLE t1 (col1 DOUBLE PRECISION, col2 DOUBLE PRECISION UNSIGNED); +INSERT INTO t1 VALUES (-2.2E-307,0),(2E-307,0),(+1.7E+308,+1.7E+308); +INSERT INTO t1 VALUES ('-2.2E-307',0),('-2E-307',0),('+1.7E+308','+1.7E+308'); +# We don't give warnings for underflow +INSERT INTO t1 (col1) VALUES (-2.2E-330); +--error 1367,1264 +INSERT INTO t1 (col1) VALUES (+1.7E+309); +--error 1264 +INSERT INTO t1 (col2) VALUES (-1.1E-3); +--error 1264 +INSERT INTO t1 (col1) VALUES ('+1.8E+309'); +--error 1264 +INSERT INTO t1 (col2) VALUES ('-1.2E-3'); +--error 1264 +UPDATE t1 SET col1 =col1 * 5000 WHERE col1 > 0; +--error 1365 +UPDATE t1 SET col2 =col2 / 0 WHERE col2 > 0; +--error 1365 +UPDATE t1 SET col2= MOD(col2,0) WHERE col2 > 0; +--error 1265 +INSERT INTO t1 (col1) VALUES (''); +--error 1265 +INSERT INTO t1 (col1) VALUES ('a59b'); +--error 1265 +INSERT INTO t1 (col1) VALUES ('1a'); +INSERT IGNORE INTO t1 (col1) VALUES ('2a'); +INSERT IGNORE INTO t1 (col1) values (1/0); +--error 1367 +INSERT IGNORE INTO t1 VALUES (+1.9E+309,-1.9E+309); +INSERT IGNORE INTO t1 VALUES ('+2.0E+309','-2.0E+309'); +# stupid... +--replace_result -0 0 1.7976931348623e+308 1.79769313486232e+308 +SELECT * FROM t1; +DROP TABLE t1; + +# Testing INSERT with CHAR/VARCHAR + +CREATE TABLE t1 (col1 CHAR(5), col2 VARCHAR(6)); +INSERT INTO t1 VALUES ('hello', 'hello'),('he', 'he'),('hello ', 'hello '); +--error 1406 +INSERT INTO t1 (col1) VALUES ('hellobob'); +--error 1406 +INSERT INTO t1 (col2) VALUES ('hellobob'); +INSERT INTO t1 (col2) VALUES ('hello '); +--error 1406 +UPDATE t1 SET col1 ='hellobob' WHERE col1 ='he'; +--error 1406 +UPDATE t1 SET col2 ='hellobob' WHERE col2 ='he'; +INSERT IGNORE INTO t1 VALUES ('hellobob', 'hellobob'); +UPDATE IGNORE t1 SET col2 ='hellotrudy' WHERE col2 ='he'; +SELECT * FROM t1; +DROP TABLE t1; + +# Testing INSERT with ENUM + +CREATE TABLE t1 (col1 enum('red','blue','green')); +INSERT INTO t1 VALUES ('red'),('blue'),('green'); +--error 1265 +INSERT INTO t1 (col1) VALUES ('yellow'); +--error 1265 +INSERT INTO t1 (col1) VALUES ('redd'); +--error 1265 +INSERT INTO t1 VALUES (''); +--error 1265 +UPDATE t1 SET col1 ='yellow' WHERE col1 ='green'; +INSERT IGNORE INTO t1 VALUES ('yellow'); +UPDATE IGNORE t1 SET col1 ='yellow' WHERE col1 ='blue'; +SELECT * FROM t1; +DROP TABLE t1; + +# Testing of insert of NULL in not NULL column + +CREATE TABLE t1 (col1 INT NOT NULL, col2 CHAR(5) NOT NULL, col3 DATE NOT NULL); +INSERT INTO t1 VALUES (100, 'hello', '2004-08-20'); +INSERT INTO t1 (col1,col2,col3) VALUES (101, 'hell2', '2004-08-21'); +--error 1048 +INSERT INTO t1 (col1,col2,col3) VALUES (NULL, '', '2004-01-01'); +--error 1048 +INSERT INTO t1 (col1,col2,col3) VALUES (102, NULL, '2004-01-01'); +--error 1048 +INSERT INTO t1 VALUES (103,'',NULL); +--error 1263 +UPDATE t1 SET col1=NULL WHERE col1 =100; +--error 1263 +UPDATE t1 SET col2 =NULL WHERE col2 ='hello'; +--error 1263 +UPDATE t1 SET col2 =NULL where col3 IS NOT NULL; +INSERT IGNORE INTO t1 values (NULL,NULL,NULL); +SELECT * FROM t1; +DROP TABLE t1; + +# Testing of default values + +CREATE TABLE t1 (col1 INT NOT NULL default 99, col2 CHAR(6) NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (1, 'hello'); +INSERT INTO t1 (col2) VALUES ('hello2'); +--error 1048 +INSERT INTO t1 (col2) VALUES (NULL); +--error 1364 +INSERT INTO t1 (col1) VALUES (2); +--error 1364 +INSERT INTO t1 VALUES(default(col1),default(col2)); +--error 1364 +INSERT INTO t1 (col1) SELECT 1; +--error 1263 +INSERT INTO t1 SELECT 1,NULL; +INSERT IGNORE INTO t1 values (NULL,NULL); +INSERT IGNORE INTO t1 (col1) values (3); +INSERT IGNORE INTO t1 () values (); +SELECT * FROM t1; +DROP TABLE t1; + +# +# Bug #9029 Traditional: Wrong SQLSTATE returned for string truncation +# + +set sql_mode='traditional'; +create table t1 (charcol char(255), varcharcol varchar(255), +binarycol binary(255), varbinarycol varbinary(255), tinytextcol tinytext, +tinyblobcol tinyblob); +--error 1406 +insert into t1 (charcol) values (repeat('x',256)); +--error 1406 +insert into t1 (varcharcol) values (repeat('x',256)); +--error 1406 +insert into t1 (binarycol) values (repeat('x',256)); +--error 1406 +insert into t1 (varbinarycol) values (repeat('x',256)); +--error 1406 +insert into t1 (tinytextcol) values (repeat('x',256)); +--error 1406 +insert into t1 (tinyblobcol) values (repeat('x',256)); +select * from t1; +drop table t1; + +# +# Bug #5902: STR_TO_DATE() didn't give errors in traditional mode +# + +set sql_mode='traditional'; +create table t1 (col1 datetime); +--error 1292 +insert into t1 values(STR_TO_DATE('31.10.2004 15.30 abc','%d.%m.%Y %H.%i')); +--error 1411 +insert into t1 values(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i')); +--error 1411 +insert into t1 values(STR_TO_DATE('2004.12.12 22:22:33 AM','%Y.%m.%d %r')); +--error 1411 +insert into t1 values(STR_TO_DATE('2004.12.12 abc','%Y.%m.%d %T')); +set sql_mode=''; +insert into t1 values(STR_TO_DATE('31.10.2004 15.30 abc','%d.%m.%Y %H.%i')); +insert into t1 values(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i')); +insert into t1 values(STR_TO_DATE('2004.12.12 22:22:33 AM','%Y.%m.%d %r')); +insert into t1 values(STR_TO_DATE('2004.12.12 abc','%Y.%m.%d %T')); + +# Some correct values, just to test the functions +insert into t1 values(STR_TO_DATE('31.10.2004 15.30','%d.%m.%Y %H.%i')); +insert into t1 values(STR_TO_DATE('2004.12.12 11:22:33 AM','%Y.%m.%d %r')); +insert into t1 values(STR_TO_DATE('2004.12.12 10:22:59','%Y.%m.%d %T')); + +select * from t1; + +# Check that select don't abort even in strict mode (for now) +set sql_mode='traditional'; + +--disable_ps_warnings +select count(*) from t1 where STR_TO_DATE('2004.12.12 10:22:61','%Y.%m.%d %T') IS NULL; +--enable_ps_warnings + +drop table t1; + +# +# Check insert with wrong CAST() (Bug #5912) +# + +create table t1 (col1 char(3), col2 integer); +--error 1292 +insert into t1 (col1) values (cast(1000 as char(3))); +--error 1292 +insert into t1 (col1) values (cast(1000E+0 as char(3))); +--error 1292 +insert into t1 (col1) values (cast(1000.0 as char(3))); +--error 1292 +insert into t1 (col2) values (cast('abc' as signed integer)); +--error 1292 +insert into t1 (col2) values (10E+0 + 'a'); +--error 1292 +insert into t1 (col2) values (cast('10a' as unsigned integer)); +insert into t1 (col2) values (cast('10' as unsigned integer)); +insert into t1 (col2) values (cast('10' as signed integer)); +insert into t1 (col2) values (10E+0 + '0 '); +select * from t1; +drop table t1; + +# +# Zero dates using numbers was not checked properly (Bug #5933 & #6145) +# + +create table t1 (col1 date, col2 datetime, col3 timestamp); +--error 1292 +insert into t1 values (0,0,0); +--error 1292 +insert into t1 values (0.0,0.0,0.0); +--error 1292 +insert into t1 (col1) values (convert('0000-00-00',date)); +--error 1292 +insert into t1 (col1) values (cast('0000-00-00' as date)); + +set sql_mode='no_zero_date'; +insert into t1 values (0,0,0); +insert into t1 values (0.0,0.0,0.0); +drop table t1; +set sql_mode='traditional'; +create table t1 (col1 date); +insert ignore into t1 values ('0000-00-00'); +--error 1292 +insert into t1 select * from t1; +insert ignore into t1 values ('0000-00-00'); +insert ignore into t1 (col1) values (cast('0000-00-00' as date)); +--error 1292 +insert into t1 select * from t1; +--error 1292 +alter table t1 modify col1 datetime; +alter ignore table t1 modify col1 datetime; +--error 1292 +insert into t1 select * from t1; +select * from t1; +drop table t1; + +# +# Test of inserting an invalid value via a stored procedure (Bug #5907) +# +create table t1 (col1 tinyint); +drop procedure if exists t1; +delimiter |; +create procedure t1 () begin declare exit handler for sqlexception +select'a'; insert into t1 values (200); end;| +delimiter ;| +call t1(); +select * from t1; +drop procedure t1; +drop table t1; + +# +# Restore mode +# +set sql_mode=@org_mode; + +# Test fields with no default value that are NOT NULL (Bug #5986) +SET @@sql_mode = 'traditional'; +CREATE TABLE t1 (i int not null); +--error 1364 +INSERT INTO t1 VALUES (); +--error 1364 +INSERT INTO t1 VALUES (DEFAULT); +--error 1364 +INSERT INTO t1 VALUES (DEFAULT(i)); +ALTER TABLE t1 ADD j int; +--error 1364 +INSERT INTO t1 SET j = 1; +--error 1364 +INSERT INTO t1 SET j = 1, i = DEFAULT; +--error 1364 +INSERT INTO t1 SET j = 1, i = DEFAULT(i); +--error 1364 +INSERT INTO t1 VALUES (DEFAULT,1); +DROP TABLE t1; +SET @@sql_mode = ''; +CREATE TABLE t1 (i int not null); +INSERT INTO t1 VALUES (); +INSERT INTO t1 VALUES (DEFAULT); +# DEFAULT(i) is an error even with the default sql_mode +--error 1364 +INSERT INTO t1 VALUES (DEFAULT(i)); +ALTER TABLE t1 ADD j int; +INSERT INTO t1 SET j = 1; +INSERT INTO t1 SET j = 1, i = DEFAULT; +--error 1364 +INSERT INTO t1 SET j = 1, i = DEFAULT(i); +INSERT INTO t1 VALUES (DEFAULT,1); +DROP TABLE t1; + +# +# Bugs #8295 and #8296: varchar and varbinary conversion +# + +set @@sql_mode='traditional'; +--error 1074 +create table t1(a varchar(65537)); +--error 1074 +create table t1(a varbinary(65537)); + +# +# Bug #9881: problem with altering table +# + +set @@sql_mode='traditional'; +create table t1(a int, b date not null); +alter table t1 modify a bigint unsigned not null; +show create table t1; +drop table t1; + +# +# Bug #5906: handle invalid date due to conversion +# +set @@sql_mode='traditional'; +create table t1 (d date); +--error 1292 +insert into t1 values ('2000-10-00'); +--error 1292 +insert into t1 values (1000); +insert into t1 values ('2000-10-01'); +--error 1292 +update t1 set d = 1100; +select * from t1; +drop table t1; + +# +# Bug #11964: alter table with timestamp field +# + +set @@sql_mode='traditional'; +create table t1(a int, b timestamp); +alter table t1 add primary key(a); +show create table t1; +drop table t1; +create table t1(a int, b timestamp default 20050102030405); +alter table t1 add primary key(a); +show create table t1; +drop table t1; + +# +# BIT fields +# + +set @@sql_mode='traditional'; +create table t1(a bit(2)); +--error 1406 +insert into t1 values(b'101'); +select * from t1; +drop table t1; + +# +# Bug#17626 CREATE TABLE ... SELECT failure with TRADITIONAL SQL mode +# +set sql_mode='traditional'; +create table t1 (date date not null); +create table t2 select date from t1; +show create table t2; +drop table t2,t1; +set @@sql_mode= @org_mode; + +# +# Bug #13934 Silent truncation of table comments +# +set @@sql_mode='traditional'; +--error 1105 +create table t1 (i int) +comment '123456789*123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789*123456789*'; +--error 1105 +create table t1 ( +i int comment +'123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789*'); +set @@sql_mode= @org_mode; +create table t1 +(i int comment + '123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789* + 123456789*123456789*123456789*123456789*'); + +select column_name, column_comment from information_schema.columns where +table_schema = 'test' and table_name = 't1'; +drop table t1; + +set names utf8; +create table t1 (i int) +comment '123456789*123456789*123456789*123456789*123456789*123456789*'; +show create table t1; +drop table t1; diff --git a/mysql-test/t/strict_autoinc_1myisam.test b/mysql-test/t/strict_autoinc_1myisam.test new file mode 100644 index 00000000000..d9ecce30974 --- /dev/null +++ b/mysql-test/t/strict_autoinc_1myisam.test @@ -0,0 +1,8 @@ +# +# Bug#20573 Strict mode auto-increment +# + +let $type= 'MYISAM' ; +--source include/strict_autoinc.inc + +# end of test diff --git a/mysql-test/t/strict_autoinc_2innodb.test b/mysql-test/t/strict_autoinc_2innodb.test new file mode 100644 index 00000000000..83dfe950938 --- /dev/null +++ b/mysql-test/t/strict_autoinc_2innodb.test @@ -0,0 +1,10 @@ +-- source include/have_innodb.inc + +# +# Bug#20573 Strict mode auto-increment +# + +let $type= 'InnoDB' ; +--source include/strict_autoinc.inc + +# end of test diff --git a/mysql-test/t/strict_autoinc_3heap.test b/mysql-test/t/strict_autoinc_3heap.test new file mode 100644 index 00000000000..f266ecdfda2 --- /dev/null +++ b/mysql-test/t/strict_autoinc_3heap.test @@ -0,0 +1,8 @@ +# +# Bug#20573 Strict mode auto-increment +# + +let $type= 'MEMORY' ; +--source include/strict_autoinc.inc + +# end of test diff --git a/mysql-test/t/strict_autoinc_4bdb.test b/mysql-test/t/strict_autoinc_4bdb.test new file mode 100644 index 00000000000..10d6bfd41e7 --- /dev/null +++ b/mysql-test/t/strict_autoinc_4bdb.test @@ -0,0 +1,10 @@ +-- source include/have_bdb.inc + +# +# Bug#20573 Strict mode auto-increment +# + +let $type= 'BDB' ; +--source include/strict_autoinc.inc + +# end of test diff --git a/mysql-test/t/strict_autoinc_5ndb.test b/mysql-test/t/strict_autoinc_5ndb.test new file mode 100644 index 00000000000..9e2090fddef --- /dev/null +++ b/mysql-test/t/strict_autoinc_5ndb.test @@ -0,0 +1,10 @@ +-- source include/have_ndb.inc + +# +# Bug#20573 Strict mode auto-increment +# + +let $type= 'NDB' ; +--source include/strict_autoinc.inc + +# end of test diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index f3877b301d6..dee5b1e4fb0 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -46,9 +46,9 @@ SELECT ROW(1,2,3) > (SELECT 1,2,1); SELECT ROW(1,2,3) = (SELECT 1,2,NULL); SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a'); SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b'); -SELECT (SELECT 1.5,2,'a') = ROW('b',2,'b'); +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b'); SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a'); -SELECT (SELECT 1.5,2,'a') = ROW(1.5,'c','a'); +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a'); SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a'); -- error 1241 @@ -352,7 +352,9 @@ INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2)); select * from t1; INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2; select * from t1; +# After this, only data based on old t1 records should have been added. INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2; +select * from t1; -- error 1054 INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2)); INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2)); @@ -507,6 +509,9 @@ select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a'); select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2); drop table t1; +# +# DO & SET +# create table t1 (a int); insert into t1 values (1); do @a:=(SELECT a from t1); @@ -660,7 +665,7 @@ CREATE TABLE t2 ( ) ENGINE=MyISAM; INSERT INTO t2 VALUES ('AUS','Australia','Oceania','Australia and New Zealand',7741220.00,1901,18886000,79.8,351182.00,392911.00,'Australia','Constitutional Monarchy, Federation','Elisabeth II',135,'AU'); -INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,7734000,62.9,4127.00,4100.00,'Azärbaycan','Federal Republic','Heydär Äliyev',144,'AZ'); +INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,7734000,62.9,4127.00,4100.00,'Azärbaycan','Federal Republic','Heydär Äliyev',144,'AZ'); select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1.t2 where t1.Population IN (select max(t1.Population) AS Population from t1, t2 where t1.t2 = t2.Code group by Continent); @@ -691,7 +696,7 @@ CREATE TABLE `t1` ( INSERT INTO t1 VALUES (1); UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i)); UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i)); --- error 1109 +-- error 1054 UPDATE t1 SET t.i=i+(SELECT MAX(i) FROM (SELECT 1) t); select * from t1; drop table t1; @@ -1000,7 +1005,7 @@ create table t2 (s1 int); select * from t1 where (select count(*) from t2 where t1.s2) = 1; -- error 1054 select * from t1 where (select count(*) from t2 group by t1.s2) = 1; --- error 1109 +-- error 1054 select count(*) from t2 group by t1.s2; drop table t1, t2; @@ -1128,7 +1133,9 @@ CREATE TABLE t2 (id INT); INSERT INTO t1 VALUES (1), (2); INSERT INTO t2 VALUES (1); SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id); +SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id); SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY t1.id; +SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY id; DROP TABLE t1,t2; # @@ -1519,7 +1526,7 @@ CREATE TABLE t1 ( ) ENGINE=MyISAM; INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX'); INSERT INTO t1 VALUES ('ASM','American Samoa','Oceania','Polynesia',199.00,0,68000,75.1,334.00,NULL,'Amerika Samoa','US Territory','George W. Bush',54,'AS'); -INSERT INTO t1 VALUES ('ATF','French Southern territories','Antarctica','Antarctica',7780.00,0,0,NULL,0.00,NULL,'Terres australes françaises','Nonmetropolitan Territory of France','Jacques Chirac',NULL,'TF'); +INSERT INTO t1 VALUES ('ATF','French Southern territories','Antarctica','Antarctica',7780.00,0,0,NULL,0.00,NULL,'Terres australes françaises','Nonmetropolitan Territory of France','Jacques Chirac',NULL,'TF'); INSERT INTO t1 VALUES ('UMI','United States Minor Outlying Islands','Oceania','Micronesia/Caribbean',16.00,0,0,NULL,0.00,NULL,'United States Minor Outlying Islands','Dependent Territory of the US','George W. Bush',NULL,'UM'); /*!40000 ALTER TABLE t1 ENABLE KEYS */; SELECT DISTINCT Continent AS c FROM t1 WHERE Code <> SOME ( SELECT Code FROM t1 WHERE Continent = c AND Population < 200); @@ -1949,3 +1956,473 @@ SELECT field1, field2 DROP TABLE t1, t2; # End of 4.1 tests + +# +#decimal-related tests +# +create table t1 (df decimal(5,1)); +insert into t1 values(1.1); +insert into t1 values(2.2); + +select * from t1 where df <= all (select avg(df) from t1 group by df); +select * from t1 where df >= all (select avg(df) from t1 group by df); +drop table t1; + +create table t1 (df decimal(5,1)); +insert into t1 values(1.1); +select 1.1 * exists(select * from t1); +drop table t1; + +CREATE TABLE t1 ( + grp int(11) default NULL, + a decimal(10,2) default NULL); + +insert into t1 values (1, 1), (2, 2), (2, 3), (3, 4), (3, 5), (3, 6), (NULL, NULL); +select * from t1; +select min(a) from t1 group by grp; +drop table t1; + +# +# Test for bug #9338: lame substitution of c1 instead of c2 +# + +CREATE table t1 ( c1 integer ); +INSERT INTO t1 VALUES ( 1 ); +INSERT INTO t1 VALUES ( 2 ); +INSERT INTO t1 VALUES ( 3 ); + +CREATE TABLE t2 ( c2 integer ); +INSERT INTO t2 VALUES ( 1 ); +INSERT INTO t2 VALUES ( 4 ); +INSERT INTO t2 VALUES ( 5 ); + +SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2 WHERE c2 IN (1); + +SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2 + WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2 IN ( 1 ) ); + +DROP TABLE t1,t2; + +# +# Test for bug #9516: wrong evaluation of not_null_tables attribute in SQ +# +CREATE TABLE t1 ( c1 integer ); +INSERT INTO t1 VALUES ( 1 ); +INSERT INTO t1 VALUES ( 2 ); +INSERT INTO t1 VALUES ( 3 ); +INSERT INTO t1 VALUES ( 6 ); + +CREATE TABLE t2 ( c2 integer ); +INSERT INTO t2 VALUES ( 1 ); +INSERT INTO t2 VALUES ( 4 ); +INSERT INTO t2 VALUES ( 5 ); +INSERT INTO t2 VALUES ( 6 ); + +CREATE TABLE t3 ( c3 integer ); +INSERT INTO t3 VALUES ( 7 ); +INSERT INTO t3 VALUES ( 8 ); + +SELECT c1,c2 FROM t1 LEFT JOIN t2 ON c1 = c2 + WHERE EXISTS (SELECT c3 FROM t3 WHERE c2 IS NULL ); + +DROP TABLE t1,t2,t3; + +# +# Item_int_with_ref check (BUG#10020) +# +CREATE TABLE `t1` ( + `itemid` bigint(20) unsigned NOT NULL auto_increment, + `sessionid` bigint(20) unsigned default NULL, + `time` int(10) unsigned NOT NULL default '0', + `type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT +NULL default '', + `data` text collate latin1_general_ci NOT NULL, + PRIMARY KEY (`itemid`) +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; +INSERT INTO `t1` VALUES (1, 1, 1, 'D', ''); +CREATE TABLE `t2` ( + `sessionid` bigint(20) unsigned NOT NULL auto_increment, + `pid` int(10) unsigned NOT NULL default '0', + `date` int(10) unsigned NOT NULL default '0', + `ip` varchar(15) collate latin1_general_ci NOT NULL default '', + PRIMARY KEY (`sessionid`) +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; +INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1'); +SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30; +drop tables t1,t2; + +# +# Correct building of equal fields list (do not include outer +# fields) (BUG#6384) +# +CREATE TABLE t1 (EMPNUM CHAR(3)); +CREATE TABLE t2 (EMPNUM CHAR(3) ); +INSERT INTO t1 VALUES ('E1'),('E2'); +INSERT INTO t2 VALUES ('E1'); +DELETE FROM t1 +WHERE t1.EMPNUM NOT IN + (SELECT t2.EMPNUM + FROM t2 + WHERE t1.EMPNUM = t2.EMPNUM); +select * from t1; +DROP TABLE t1,t2; + +# +# Test for bug #11487: range access in a subquery +# + +CREATE TABLE t1(select_id BIGINT, values_id BIGINT); +INSERT INTO t1 VALUES (1, 1); +CREATE TABLE t2 (select_id BIGINT, values_id BIGINT, + PRIMARY KEY(select_id,values_id)); +INSERT INTO t2 VALUES (0, 1), (0, 2), (0, 3), (1, 5); + +SELECT values_id FROM t1 +WHERE values_id IN (SELECT values_id FROM t2 + WHERE select_id IN (1, 0)); +SELECT values_id FROM t1 +WHERE values_id IN (SELECT values_id FROM t2 + WHERE select_id BETWEEN 0 AND 1); +SELECT values_id FROM t1 +WHERE values_id IN (SELECT values_id FROM t2 + WHERE select_id = 0 OR select_id = 1); + +DROP TABLE t1, t2; + +# BUG#11821 : Select from subselect using aggregate function on an enum +# segfaults: +create table t1 (fld enum('0','1')); +insert into t1 values ('1'); +select * from (select max(fld) from t1) as foo; +drop table t1; + +# +# Test for bug #11762: subquery with an aggregate function in HAVING +# + +CREATE TABLE t1 (a int, b int); +CREATE TABLE t2 (c int, d int); +CREATE TABLE t3 (e int); + +INSERT INTO t1 VALUES + (1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40); +INSERT INTO t2 VALUES + (2,10), (2,20), (4,10), (5,10), (3,20), (2,40); +INSERT INTO t3 VALUES (10), (30), (10), (20) ; + +SELECT a, MAX(b), MIN(b) FROM t1 GROUP BY a; +SELECT * FROM t2; +SELECT * FROM t3; + +SELECT a FROM t1 GROUP BY a + HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20); +SELECT a FROM t1 GROUP BY a + HAVING a IN (SELECT c FROM t2 WHERE MAX(b)<d); +SELECT a FROM t1 GROUP BY a + HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>d); +SELECT a FROM t1 GROUP BY a + HAVING a IN (SELECT c FROM t2 + WHERE d >= SOME(SELECT e FROM t3 WHERE MAX(b)=e)); +SELECT a FROM t1 GROUP BY a + HAVING a IN (SELECT c FROM t2 + WHERE EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d)); +SELECT a FROM t1 GROUP BY a + HAVING a IN (SELECT c FROM t2 + WHERE d > SOME(SELECT e FROM t3 WHERE MAX(b)=e)); +SELECT a FROM t1 GROUP BY a + HAVING a IN (SELECT c FROM t2 + WHERE EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e < d)); +SELECT a FROM t1 GROUP BY a + HAVING a IN (SELECT c FROM t2 + WHERE MIN(b) < d AND + EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d)); + +SELECT a, SUM(a) FROM t1 GROUP BY a; + +SELECT a FROM t1 + WHERE EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c) GROUP BY a; +SELECT a FROM t1 GROUP BY a + HAVING EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c); + +SELECT a FROM t1 + WHERE a < 3 AND + EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c) GROUP BY a; +SELECT a FROM t1 + WHERE a < 3 AND + EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c); + +SELECT t1.a FROM t1 GROUP BY t1.a + HAVING t1.a < ALL(SELECT t2.c FROM t2 GROUP BY t2.c + HAVING EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e + HAVING SUM(t1.a+t2.c) < t3.e/4)); +SELECT t1.a FROM t1 GROUP BY t1.a + HAVING t1.a > ALL(SELECT t2.c FROM t2 + WHERE EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e + HAVING SUM(t1.a+t2.c) < t3.e/4)); +-- error 1111 +SELECT t1.a FROM t1 GROUP BY t1.a + HAVING t1.a > ALL(SELECT t2.c FROM t2 + WHERE EXISTS(SELECT t3.e FROM t3 + WHERE SUM(t1.a+t2.c) < t3.e/4)); +-- error 1111 +SELECT t1.a from t1 GROUP BY t1.a HAVING AVG(SUM(t1.b)) > 20; + +SELECT t1.a FROM t1 GROUP BY t1.a + HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c + HAVING AVG(t2.c+SUM(t1.b)) > 20); +SELECT t1.a FROM t1 GROUP BY t1.a + HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c + HAVING AVG(SUM(t1.b)) > 20); + +SELECT t1.a, SUM(b) AS sum FROM t1 GROUP BY t1.a + HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c + HAVING t2.c+sum > 20); + +DROP TABLE t1,t2,t3; + +# +# Test for bug #16603: GROUP BY in a row subquery with a quantifier +# when an index is defined on the grouping field + +CREATE TABLE t1 (a varchar(5), b varchar(10)); +INSERT INTO t1 VALUES + ('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2), + ('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8); + +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); +EXPLAIN +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); + +ALTER TABLE t1 ADD INDEX(a); + +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); +EXPLAIN +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); + +DROP TABLE t1; + +# +# Bug#17366: Unchecked Item_int results in server crash +# +create table t1( f1 int,f2 int); +insert into t1 values (1,1),(2,2); +select tt.t from (select 'crash1' as t, f2 from t1) as tt left join t1 on tt.t = 'crash2' and tt.f2 = t1.f2 where tt.t = 'crash1'; +drop table t1; + +# +# Bug #18306: server crash on delete using subquery. +# + +create table t1 (c int, key(c)); +insert into t1 values (1142477582), (1142455969); +create table t2 (a int, b int); +insert into t2 values (2, 1), (1, 0); +delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1; +drop table t1, t2; + +# +# Bug #7549: Missing error message for invalid view selection with subquery +# + +CREATE TABLE t1 (a INT); + +--error 1054 +CREATE VIEW v1 AS SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1); +--error 1054 +CREATE VIEW v2 AS SELECT * FROM t1 WHERE no_such_column = (SELECT 1); +--error 1054 +SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1); + +DROP TABLE t1; + +# +# Bug#19077: A nested materialized derived table is used before being populated. +# +create table t1 (i int, j bigint); +insert into t1 values (1, 2), (2, 2), (3, 2); +select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3; +drop table t1; + +# +# Bug#19700: subselect returning BIGINT always returned it as SIGNED +# +CREATE TABLE t1 (i BIGINT UNSIGNED); +INSERT INTO t1 VALUES (10000000000000000000); -- > MAX SIGNED BIGINT 9323372036854775807 +INSERT INTO t1 VALUES (1); + +CREATE TABLE t2 (i BIGINT UNSIGNED); +INSERT INTO t2 VALUES (10000000000000000000); -- same as first table +INSERT INTO t2 VALUES (1); + +/* simple test */ +SELECT t1.i FROM t1 JOIN t2 ON t1.i = t2.i; + +/* subquery test */ +SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2); + +/* subquery test with cast*/ +SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED); + +DROP TABLE t1; +DROP TABLE t2; + +# +# Bug#20519: subselect with LIMIT M, N +# + +CREATE TABLE t1 ( + id bigint(20) unsigned NOT NULL auto_increment, + name varchar(255) NOT NULL, + PRIMARY KEY (id) +); +INSERT INTO t1 VALUES + (1, 'Balazs'), (2, 'Joe'), (3, 'Frank'); + +CREATE TABLE t2 ( + id bigint(20) unsigned NOT NULL auto_increment, + mid bigint(20) unsigned NOT NULL, + date date NOT NULL, + PRIMARY KEY (id) +); +INSERT INTO t2 VALUES + (1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'), + (4, 2, '2006-04-20'), (5, 1, '2006-05-01'); + +SELECT *, + (SELECT date FROM t2 WHERE mid = t1.id + ORDER BY date DESC LIMIT 0, 1) AS date_last, + (SELECT date FROM t2 WHERE mid = t1.id + ORDER BY date DESC LIMIT 3, 1) AS date_next_to_last + FROM t1; +SELECT *, + (SELECT COUNT(*) FROM t2 WHERE mid = t1.id + ORDER BY date DESC LIMIT 1, 1) AS date_count + FROM t1; +SELECT *, + (SELECT date FROM t2 WHERE mid = t1.id + ORDER BY date DESC LIMIT 0, 1) AS date_last, + (SELECT date FROM t2 WHERE mid = t1.id + ORDER BY date DESC LIMIT 1, 1) AS date_next_to_last + FROM t1; +DROP TABLE t1,t2; + +# +# Bug#20869: subselect with range access by DESC +# + +CREATE TABLE t1 ( + i1 int(11) NOT NULL default '0', + i2 int(11) NOT NULL default '0', + t datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (i1,i2,t) +); +INSERT INTO t1 VALUES +(24,1,'2005-03-03 16:31:31'),(24,1,'2005-05-27 12:40:07'), +(24,1,'2005-05-27 12:40:08'),(24,1,'2005-05-27 12:40:10'), +(24,1,'2005-05-27 12:40:25'),(24,1,'2005-05-27 12:40:30'), +(24,2,'2005-03-03 13:43:05'),(24,2,'2005-03-03 16:23:31'), +(24,2,'2005-03-03 16:31:30'),(24,2,'2005-05-27 12:37:02'), +(24,2,'2005-05-27 12:40:06'); + +CREATE TABLE t2 ( + i1 int(11) NOT NULL default '0', + i2 int(11) NOT NULL default '0', + t datetime default NULL, + PRIMARY KEY (i1) +); +INSERT INTO t2 VALUES (24,1,'2006-06-20 12:29:40'); + +EXPLAIN +SELECT * FROM t1,t2 + WHERE t1.t = (SELECT t1.t FROM t1 + WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 + ORDER BY t1.t DESC LIMIT 1); +SELECT * FROM t1,t2 + WHERE t1.t = (SELECT t1.t FROM t1 + WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 + ORDER BY t1.t DESC LIMIT 1); + +DROP TABLE t1, t2; + +# +# Bug#14654 : Cannot select from the same table twice within a UNION +# statement +# +CREATE TABLE t1 (i INT); + +(SELECT i FROM t1) UNION (SELECT i FROM t1); +SELECT sql_no_cache * FROM t1 WHERE NOT EXISTS + ( + (SELECT i FROM t1) UNION + (SELECT i FROM t1) + ); + +SELECT * FROM t1 +WHERE NOT EXISTS (((SELECT i FROM t1) UNION (SELECT i FROM t1))); + +#TODO:not supported +--error 1064 +explain select ((select t11.i from t1 t11) union (select t12.i from t1 t12)) + from t1; +#supported +explain select * from t1 where not exists + ((select t11.i from t1 t11) union (select t12.i from t1 t12)); + +DROP TABLE t1; + +# +# Bug#21798: memory leak during query execution with subquery in column +# list using a function +# +CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); +insert into t1 (a) values (FLOOR(rand() * 100)); +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; + +SELECT a, + (SELECT REPEAT(' ',250) FROM t1 i1 + WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a +FROM t1 ORDER BY a LIMIT 5; +DROP TABLE t1; + +# +# Bug #21540: Subqueries with no from and aggregate functions return +# wrong results +CREATE TABLE t1 (a INT, b INT); +CREATE TABLE t2 (a INT); +INSERT INTO t2 values (1); +INSERT INTO t1 VALUES (1,1),(1,2),(2,3),(3,4); +SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a; +SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) + FROM t1 GROUP BY t1.a; +SELECT COUNT(DISTINCT t1.b), (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a; +SELECT COUNT(DISTINCT t1.b), + (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) + FROM t1 GROUP BY t1.a; +SELECT ( + SELECT ( + SELECT COUNT(DISTINCT t1.b) + ) +) +FROM t1 GROUP BY t1.a; +SELECT ( + SELECT ( + SELECT ( + SELECT COUNT(DISTINCT t1.b) + ) + ) + FROM t1 GROUP BY t1.a LIMIT 1) +FROM t1 t2 +GROUP BY t2.a; +DROP TABLE t1,t2; diff --git a/mysql-test/t/subselect_innodb.test b/mysql-test/t/subselect_innodb.test index 3b1d2f393c2..573fe0c1810 100644 --- a/mysql-test/t/subselect_innodb.test +++ b/mysql-test/t/subselect_innodb.test @@ -161,3 +161,80 @@ deallocate prepare my_stmt; drop table t1,t2; # End of 4.1 tests + +CREATE TABLE t1 ( + school_name varchar(45) NOT NULL, + country varchar(45) NOT NULL, + funds_requested float NOT NULL, + schooltype varchar(45) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +insert into t1 values ("the school", "USA", 1200, "Human"); + +select count(country) as countrycount, sum(funds_requested) as smcnt, + country, (select sum(funds_requested) from t1) as total_funds +from t1 +group by country; + +select count(country) as countrycount, sum(funds_requested) as smcnt, + country, (select sum(funds_requested) from t1) as total_funds +from t1 +group by country; + +drop table t1; + +# +# BUG#14342: wrong placement of subquery internals in complex queries +# +CREATE TABLE `t1` ( + `t3_id` int NOT NULL, + `t1_id` int NOT NULL, + PRIMARY KEY (`t1_id`) +); +CREATE TABLE `t2` ( + `t2_id` int NOT NULL, + `t1_id` int NOT NULL, + `b` int NOT NULL, + PRIMARY KEY (`t2_id`), + UNIQUE KEY `idx_t2_t1_b` (`t1_id`,`b`) +) ENGINE=InnoDB; +CREATE TABLE `t3` ( + `t3_id` int NOT NULL +); +INSERT INTO `t3` VALUES (3); +select + (SELECT rs.t2_id + FROM t2 rs + WHERE rs.t1_id= + (SELECT lt.t1_id + FROM t1 lt + WHERE lt.t3_id=a.t3_id) + ORDER BY b DESC LIMIT 1) +from t3 AS a; +# repeat above query in SP +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings +delimiter //; +create procedure p1() +begin + declare done int default 3; + repeat + select + (SELECT rs.t2_id + FROM t2 rs + WHERE rs.t1_id= + (SELECT lt.t1_id + FROM t1 lt + WHERE lt.t3_id=a.t3_id) + ORDER BY b DESC LIMIT 1) as x + from t3 AS a; + set done= done-1; + until done <= 0 end repeat; +end// +delimiter ;// +call p1(); +call p1(); +call p1(); +drop procedure p1; +drop tables t1,t2,t3; diff --git a/mysql-test/t/subselect_notembedded.test b/mysql-test/t/subselect_notembedded.test new file mode 100644 index 00000000000..c5b23f6dac8 --- /dev/null +++ b/mysql-test/t/subselect_notembedded.test @@ -0,0 +1,8 @@ +-- source include/not_embedded.inc + +# +# BUG #10308: purge log with subselect +# + +purge master logs before (select adddate(current_timestamp(), interval -4 day)); + diff --git a/mysql-test/t/sum_distinct-big.test b/mysql-test/t/sum_distinct-big.test new file mode 100644 index 00000000000..0859f4b3d89 --- /dev/null +++ b/mysql-test/t/sum_distinct-big.test @@ -0,0 +1,67 @@ +# +# Various tests for SUM(DISTINCT ...) +# + +--source include/big_test.inc +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings + +# +# Test the case when distinct values doesn't fit in memory and +# filesort is used (see uniques.cc:merge_walk) +# + +CREATE TABLE t1 (id INTEGER); +CREATE TABLE t2 (id INTEGER); + +INSERT INTO t1 (id) VALUES (1), (1), (1),(1); +INSERT INTO t1 (id) SELECT id FROM t1; /* 8 */ +INSERT INTO t1 (id) SELECT id FROM t1; /* 12 */ +INSERT INTO t1 (id) SELECT id FROM t1; /* 16 */ +INSERT INTO t1 (id) SELECT id FROM t1; /* 20 */ +INSERT INTO t1 (id) SELECT id FROM t1; /* 24 */ +INSERT INTO t1 SELECT id+1 FROM t1; +INSERT INTO t1 SELECT id+2 FROM t1; +INSERT INTO t1 SELECT id+4 FROM t1; +INSERT INTO t1 SELECT id+8 FROM t1; +INSERT INTO t1 SELECT id+16 FROM t1; +INSERT INTO t1 SELECT id+32 FROM t1; +INSERT INTO t1 SELECT id+64 FROM t1; +INSERT INTO t1 SELECT id+128 FROM t1; +INSERT INTO t1 SELECT id+256 FROM t1; +INSERT INTO t1 SELECT id+512 FROM t1; + +# Just test that AVG(DISTINCT) is there +SELECT AVG(DISTINCT id) FROM t1 GROUP BY id % 13; +SELECT SUM(DISTINCT id)/COUNT(DISTINCT id) FROM t1 GROUP BY id % 13; + +INSERT INTO t1 SELECT id+1024 FROM t1; +INSERT INTO t1 SELECT id+2048 FROM t1; +INSERT INTO t1 SELECT id+4096 FROM t1; +INSERT INTO t1 SELECT id+8192 FROM t1; +INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand(); + +# SELECT '++++++++++++++++++++++++++++++++++++++++++++++++++'; + +SELECT SUM(DISTINCT id) sm FROM t1; +SELECT SUM(DISTINCT id) sm FROM t2; +SELECT SUM(DISTINCT id) sm FROM t1 group by id % 13; + +# this limit for max_heap_table_size is set to force testing the case, when +# all distinct sum values can not fit in memory and must be stored in a +# temporary table + +SET max_heap_table_size=16384; + +# to check that max_heap_table_size was actually set (hard limit for minimum +# max_heap_table_size is set in mysqld.cc): + +SHOW variables LIKE 'max_heap_table_size'; + +SELECT SUM(DISTINCT id) sm FROM t1; +SELECT SUM(DISTINCT id) sm FROM t2; +SELECT SUM(DISTINCT id) sm FROM t1 GROUP BY id % 13; + +DROP TABLE t1; +DROP TABLE t2; diff --git a/mysql-test/t/sum_distinct.test b/mysql-test/t/sum_distinct.test new file mode 100644 index 00000000000..c58155a8e25 --- /dev/null +++ b/mysql-test/t/sum_distinct.test @@ -0,0 +1,95 @@ +# +# Various tests for SUM(DISTINCT ...) +# +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings + +CREATE TABLE t1 ( + id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, + gender CHAR(1), + name VARCHAR(20) +); + +# According to ANSI SQL, SUM(DISTINCT ...) should return NULL for empty +# record set + +SELECT SUM(DISTINCT LENGTH(name)) s1 FROM t1; + +# According to ANSI SQL, SUM(DISTINCT ...) should return NULL for records sets +# entirely consisting of NULLs + +INSERT INTO t1 (gender, name) VALUES (NULL, NULL); +INSERT INTO t1 (gender, name) VALUES (NULL, NULL); +INSERT INTO t1 (gender, name) VALUES (NULL, NULL); + +SELECT SUM(DISTINCT LENGTH(name)) s1 FROM t1; + + +# Filling table with t1 + +INSERT INTO t1 (gender, name) VALUES ('F', 'Helen'), ('F', 'Anastasia'), +('F', 'Katherine'), ('F', 'Margo'), ('F', 'Magdalene'), ('F', 'Mary'); + +CREATE TABLE t2 SELECT name FROM t1; + +SELECT (SELECT SUM(DISTINCT LENGTH(name)) FROM t1) FROM t2; + +DROP TABLE t2; + +INSERT INTO t1 (gender, name) VALUES ('F', 'Eva'), ('F', 'Sofia'), +('F', 'Sara'), ('F', 'Golda'), ('F', 'Toba'), ('F', 'Victory'), +('F', 'Faina'), ('F', 'Miriam'), ('F', 'Beki'), ('F', 'America'), +('F', 'Susan'), ('F', 'Glory'), ('F', 'Priscilla'), ('F', 'Rosmary'), +('F', 'Rose'), ('F', 'Margareth'), ('F', 'Elizabeth'), ('F', 'Meredith'), +('F', 'Julie'), ('F', 'Xenia'), ('F', 'Zena'), ('F', 'Olga'), +('F', 'Brunhilda'), ('F', 'Nataly'), ('F', 'Lara'), ('F', 'Svetlana'), +('F', 'Grethem'), ('F', 'Irene'); + +SELECT + SUM(DISTINCT LENGTH(name)) s1, + SUM(DISTINCT SUBSTRING(NAME, 1, 3)) s2, + SUM(DISTINCT LENGTH(SUBSTRING(name, 1, 4))) s3 +FROM t1; + +SELECT + SUM(DISTINCT LENGTH(g1.name)) s1, + SUM(DISTINCT SUBSTRING(g2.name, 1, 3)) s2, + SUM(DISTINCT LENGTH(SUBSTRING(g3.name, 1, 4))) s3 +FROM t1 g1, t1 g2, t1 g3; + +SELECT + SUM(DISTINCT LENGTH(g1.name)) s1, + SUM(DISTINCT SUBSTRING(g2.name, 1, 3)) s2, + SUM(DISTINCT LENGTH(SUBSTRING(g3.name, 1, 4))) s3 +FROM t1 g1, t1 g2, t1 g3 GROUP BY LENGTH(SUBSTRING(g3.name, 5, 10)); + +# here we explicitly request summing through temporary table (so +# Item_sum_sum_distinct::copy_or_same() is called) + +SELECT SQL_BUFFER_RESULT + SUM(DISTINCT LENGTH(name)) s1, + SUM(DISTINCT SUBSTRING(NAME, 1, 3)) s2, + SUM(DISTINCT LENGTH(SUBSTRING(name, 1, 4))) s3 +FROM t1; + +SELECT SQL_BUFFER_RESULT + SUM(DISTINCT LENGTH(g1.name)) s1, + SUM(DISTINCT SUBSTRING(g2.name, 1, 3)) s2, + SUM(DISTINCT LENGTH(SUBSTRING(g3.name, 1, 4))) s3 +FROM t1 g1, t1 g2, t1 g3 GROUP BY LENGTH(SUBSTRING(g3.name, 5, 10)); + +# this test demonstrates that strings are automatically converted to numbers +# before summing + +SET @l=1; +UPDATE t1 SET name=CONCAT(name, @l:=@l+1); + +SELECT SUM(DISTINCT RIGHT(name, 1)) FROM t1; + +# this is a test case for ordinary t1 + +SELECT SUM(DISTINCT id) FROM t1; +SELECT SUM(DISTINCT id % 11) FROM t1; + +DROP TABLE t1; diff --git a/mysql-test/t/symlink.test b/mysql-test/t/symlink.test index c0c1db3d553..19a720a4fb8 100644 --- a/mysql-test/t/symlink.test +++ b/mysql-test/t/symlink.test @@ -43,7 +43,7 @@ drop table t2; # disable_query_log; -eval create table t9 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam data directory="$MYSQL_TEST_DIR/var/tmp" index directory="$MYSQL_TEST_DIR/var/run"; +eval create table t9 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam data directory="$MYSQLTEST_VARDIR/tmp" index directory="$MYSQLTEST_VARDIR/run"; enable_query_log; insert into t9 select * from t1; @@ -51,7 +51,8 @@ check table t9; optimize table t9; repair table t9; alter table t9 add column c int not null; ---replace_result $MYSQL_TEST_DIR TEST_DIR + +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR show create table t9; # Test renames @@ -66,6 +67,9 @@ drop table t1; # Note that we are using the above table t9 here! # +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +SHOW CREATE TABLE t9; + disable_query_log; --error 1103,1103 create table t1 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam data directory="tmp"; @@ -80,11 +84,13 @@ create table mysqltest.t9 (a int not null auto_increment, b char(16) not null, p --error 1103,1103 create table mysqltest.t9 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam index directory="not-hard-path"; ---error 1,1 -eval create table mysqltest.t9 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam index directory="$MYSQL_TEST_DIR/var/run"; +# Should fail becasue the file t9.MYI already exist in 'run' +--error 1,1,1105 +eval create table mysqltest.t9 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam index directory="$MYSQLTEST_VARDIR/run"; +# Should fail becasue the file t9.MYD already exist in 'tmp' --error 1,1 -eval create table mysqltest.t9 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam data directory="$MYSQL_TEST_DIR/var/tmp"; +eval create table mysqltest.t9 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam data directory="$MYSQLTEST_VARDIR/tmp"; enable_query_log; # Check moving table t9 from default database to mysqltest; @@ -92,7 +98,7 @@ enable_query_log; alter table t9 rename mysqltest.t9; select count(*) from mysqltest.t9; ---replace_result $MYSQL_TEST_DIR TEST_DIR +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR show create table mysqltest.t9; drop database mysqltest; @@ -102,18 +108,18 @@ drop database mysqltest; create table t1 (a int not null) engine=myisam; disable_query_log; -eval alter table t1 data directory="$MYSQL_TEST_DIR/var/tmp"; +eval alter table t1 data directory="$MYSQLTEST_VARDIR/tmp"; enable_query_log; ---replace_result $MYSQL_TEST_DIR TEST_DIR +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR show create table t1; alter table t1 add b int; disable_query_log; -eval alter table t1 data directory="$MYSQL_TEST_DIR/var/log"; +eval alter table t1 data directory="$MYSQLTEST_VARDIR/log"; enable_query_log; ---replace_result $MYSQL_TEST_DIR TEST_DIR +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR show create table t1; disable_query_log; -eval alter table t1 index directory="$MYSQL_TEST_DIR/var/log"; +eval alter table t1 index directory="$MYSQLTEST_VARDIR/log"; enable_query_log; show create table t1; drop table t1; @@ -123,12 +129,12 @@ drop table t1; # have been chosen. (Bug #8707) # disable_query_log; -eval create table t1 (i int) data directory = "$MYSQL_TEST_DIR/var/master-data/test/"; +eval create table t1 (i int) data directory = "$MYSQLTEST_VARDIR/master-data/test/"; enable_query_log; show create table t1; drop table t1; disable_query_log; -eval create table t1 (i int) index directory = "$MYSQL_TEST_DIR/var/master-data/test/"; +eval create table t1 (i int) index directory = "$MYSQLTEST_VARDIR/master-data/test/"; enable_query_log; show create table t1; drop table t1; diff --git a/mysql-test/t/synchronization.test b/mysql-test/t/synchronization.test index ec7c7dd6545..c7696195ee0 100644 --- a/mysql-test/t/synchronization.test +++ b/mysql-test/t/synchronization.test @@ -1,7 +1,12 @@ # -# Test for Bug #2385 CREATE TABLE LIKE lacks locking on source and destination table +# Test for Bug #2385 CREATE TABLE LIKE lacks locking on source and destination +# table # +--disable_warnings +drop table if exists t1; +--enable_warnings + connect (con1,localhost,root,,); connect (con2,localhost,root,,); diff --git a/mysql-test/t/sysdate_is_now-master.opt b/mysql-test/t/sysdate_is_now-master.opt new file mode 100644 index 00000000000..97a58d28032 --- /dev/null +++ b/mysql-test/t/sysdate_is_now-master.opt @@ -0,0 +1 @@ +--sysdate-is-now diff --git a/mysql-test/t/sysdate_is_now.test b/mysql-test/t/sysdate_is_now.test new file mode 100644 index 00000000000..166914e20c8 --- /dev/null +++ b/mysql-test/t/sysdate_is_now.test @@ -0,0 +1,11 @@ +# +# BUG#15101 restore aliasing of SYSDATE to NOW in 5.0 +# this feature is activated via --sysdate-is-now mysqld init opt +# +# To test here +# 1. SYSDATE() does not distiguish from NOW() +# 2. SYSDATE() obeys set timestamp + +set timestamp=1; +SELECT sleep(1),NOW()-SYSDATE() as zero; +# End of 5.0 tests diff --git a/mysql-test/t/system_mysql_db.test b/mysql-test/t/system_mysql_db.test index 0892af77fb2..27c17da2731 100644 --- a/mysql-test/t/system_mysql_db.test +++ b/mysql-test/t/system_mysql_db.test @@ -2,6 +2,11 @@ # This test must examine integrity of system database "mysql" # +# First delete some tables maybe left over from previous tests +--disable_warnings +drop table if exists t1,t1aa,t2aa; +--enable_warnings + -- disable_query_log use mysql; -- enable_query_log diff --git a/mysql-test/t/system_mysql_db_fix.test b/mysql-test/t/system_mysql_db_fix.test index 5e8822569b7..c50b641b7e2 100644 --- a/mysql-test/t/system_mysql_db_fix.test +++ b/mysql-test/t/system_mysql_db_fix.test @@ -1,9 +1,20 @@ # Embedded server doesn't support external clients --source include/not_embedded.inc +# Windows doesn't support execution of shell scripts (to fix!!) +--source include/not_windows.inc + # # This is the test for mysql_fix_privilege_tables # +# Note: If this test fails, don't be confused about the errors reported +# by mysql-test-run; This shows warnings from generated by +# mysql_fix_system_tables which should be ignored. +# Instead, concentrate on the errors in r/system_mysql_db.reject + +--disable_warnings +drop table if exists t1,t1aa,t2aa; +--enable_warnings -- disable_result_log -- disable_query_log @@ -69,7 +80,8 @@ type=ISAM; INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y'); INSERT INTO user VALUES ('localhost','', '','N','N','N','N','N','N','N','N','N'); --- exec $MYSQL_FIX_SYSTEM_TABLES --database=test +# Call the "shell script" $MYSQL_FIX_SYSTEM_TABLES using system +-- system $MYSQL_FIX_SYSTEM_TABLES --database=test > /dev/null -- enable_query_log -- enable_result_log @@ -77,7 +89,7 @@ INSERT INTO user VALUES ('localhost','', '','N','N','N','N','N','N','N','N',' -- disable_query_log -DROP TABLE db, host, user, func, tables_priv, columns_priv, help_category, help_keyword, help_relation, help_topic, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type; +DROP TABLE db, host, user, func, tables_priv, columns_priv, procs_priv, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type; -- enable_query_log diff --git a/mysql-test/t/temp_table-master.opt b/mysql-test/t/temp_table-master.opt index 026d3d4640c..5ac2ca8495b 100644 --- a/mysql-test/t/temp_table-master.opt +++ b/mysql-test/t/temp_table-master.opt @@ -1 +1 @@ ---tmpdir=$MYSQL_TEST_DIR/var//tmp +--tmpdir=$MYSQLTEST_VARDIR//tmp diff --git a/mysql-test/t/temp_table.test b/mysql-test/t/temp_table.test index 69082840988..8cb9e34ca08 100644 --- a/mysql-test/t/temp_table.test +++ b/mysql-test/t/temp_table.test @@ -1,9 +1,12 @@ +# mysqltest should be fixed +-- source include/not_embedded.inc # # Test of temporary tables # --disable_warnings drop table if exists t1,t2; +drop view if exists v1; --enable_warnings CREATE TABLE t1 (c int not null, d char (10) not null); @@ -90,6 +93,20 @@ select * from t1 group by d; show status like "created_tmp%tables"; drop table t1; +# Fix for BUG#8921: Check that temporary table is ingored by view commands. +create temporary table v1 as select 'This is temp. table' A; +create view v1 as select 'This is view' A; +select * from v1; +show create table v1; +show create view v1; +drop view v1; +select * from v1; +create view v1 as select 'This is view again' A; +select * from v1; +drop table v1; +select * from v1; +drop view v1; + # Bug #8497: tmpdir with extra slashes would cause failures # create table t1 (a int, b int, index(a), index(b)); diff --git a/mysql-test/t/timezone.test b/mysql-test/t/timezone.test index 34bbb365c70..157b18f57fa 100644 --- a/mysql-test/t/timezone.test +++ b/mysql-test/t/timezone.test @@ -52,11 +52,12 @@ INSERT INTO t1 (ts) VALUES ('2003-03-30 01:59:59'), DROP TABLE t1; # -# Test for fix for Bug#2523 +# Test for fix for Bug#2523 Check that boundary dates are processed +# correctly. # select unix_timestamp('1970-01-01 01:00:00'), unix_timestamp('1970-01-01 01:00:01'), - unix_timestamp('2038-01-01 00:59:59'), - unix_timestamp('2038-01-01 01:00:00'); + unix_timestamp('2038-01-19 04:14:07'), + unix_timestamp('2038-01-19 04:14:08'); # End of 4.1 tests diff --git a/mysql-test/t/timezone2.test b/mysql-test/t/timezone2.test index 523249a3a2c..75e5d4bfe81 100644 --- a/mysql-test/t/timezone2.test +++ b/mysql-test/t/timezone2.test @@ -3,6 +3,7 @@ # Preparing playground --disable_warnings drop table if exists t1, t2; +drop function if exists f1; --enable_warnings @@ -48,6 +49,11 @@ insert into t1 (i, ts) values (unix_timestamp('2003-03-30 01:59:59'),'2003-03-30 01:59:59'), (unix_timestamp('2003-03-30 02:30:00'),'2003-03-30 02:30:00'), (unix_timestamp('2003-03-30 03:00:00'),'2003-03-30 03:00:00'); +# Values around and in spring time-gap +insert into t1 (i, ts) values + (unix_timestamp(20030330015959),20030330015959), + (unix_timestamp(20030330023000),20030330023000), + (unix_timestamp(20030330030000),20030330030000); # Normal value with DST insert into t1 (i, ts) values (unix_timestamp('2003-05-01 00:00:00'),'2003-05-01 00:00:00'); @@ -107,21 +113,21 @@ create table t1 (ts timestamp); set time_zone='UTC'; insert into t1 values ('0000-00-00 00:00:00'),('1969-12-31 23:59:59'), ('1970-01-01 00:00:00'),('1970-01-01 00:00:01'), - ('2037-12-31 23:59:59'),('2038-01-01 00:00:00'); + ('2038-01-19 03:14:07'),('2038-01-19 03:14:08'); select * from t1; delete from t1; # MET time zone has range shifted by one hour set time_zone='MET'; insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 00:30:00'), ('1970-01-01 01:00:00'),('1970-01-01 01:00:01'), - ('2038-01-01 00:59:59'),('2038-01-01 01:00:00'); + ('2038-01-19 04:14:07'),('2038-01-19 04:14:08'); select * from t1; delete from t1; # same for +01:30 time zone set time_zone='+01:30'; insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 01:00:00'), ('1970-01-01 01:30:00'),('1970-01-01 01:30:01'), - ('2038-01-01 01:29:59'),('2038-01-01 01:30:00'); + ('2038-01-19 04:44:07'),('2038-01-19 04:44:08'); select * from t1; drop table t1; @@ -171,8 +177,8 @@ select convert_tz('2003-10-26 01:00:00', 'MET', 'UTC'); select convert_tz('2003-10-26 02:00:00', 'MET', 'UTC'); select convert_tz('2003-10-26 02:59:59', 'MET', 'UTC'); select convert_tz('2003-10-26 04:00:00', 'MET', 'UTC'); -select convert_tz('2038-01-01 00:59:59', 'MET', 'UTC'); -select convert_tz('2038-01-01 01:00:00', 'MET', 'UTC'); +select convert_tz('2038-01-19 04:14:07', 'MET', 'UTC'); +select convert_tz('2038-01-19 04:14:08', 'MET', 'UTC'); select convert_tz('2103-01-01 04:00:00', 'MET', 'UTC'); # Let us test variable time zone argument @@ -200,7 +206,7 @@ select convert_tz(ts, @@time_zone, 'Japan') from t1; drop table t1; # -# Test for bug #7705 "CONVERT_TZ() crashes with subquery/WHERE on index +# Test for bug #7705 "CONVERT_TZ() crashes with subquery/WHERE on index # column". Queries in which one of time zone arguments of CONVERT_TZ() is # determined as constant only at val() stage (not at fix_fields() stage), # should not crash server. @@ -217,3 +223,22 @@ select * from t1; drop table t1; # End of 4.1 tests + +# +# Test for bug #11081 "Using a CONVERT_TZ function in a stored function +# or trigger fails". +# +create table t1 (ldt datetime, udt datetime); +create function f1(i datetime) returns datetime + return convert_tz(i, 'UTC', 'Europe/Moscow'); +create trigger t1_bi before insert on t1 for each row + set new.udt:= convert_tz(new.ldt, 'Europe/Moscow', 'UTC'); +# This should work without errors +insert into t1 (ldt) values ('2006-04-19 16:30:00'); +select * from t1; +# This should work without errors as well +select ldt, f1(udt) as ldt2 from t1; +drop table t1; +drop function f1; + +# End of 5.0 tests diff --git a/mysql-test/t/timezone4-master.opt b/mysql-test/t/timezone4-master.opt new file mode 100644 index 00000000000..d1ab6207933 --- /dev/null +++ b/mysql-test/t/timezone4-master.opt @@ -0,0 +1 @@ +--timezone=GMT+10 diff --git a/mysql-test/t/timezone4.test b/mysql-test/t/timezone4.test new file mode 100644 index 00000000000..d7372c75d5a --- /dev/null +++ b/mysql-test/t/timezone4.test @@ -0,0 +1,13 @@ +# +# Tests for time functions. The difference from func_time test is the +# timezone. In func_time it's GMT-3. In our case it's GMT+10 +# + +# +# Test for bug bug #9191 "TIMESTAMP/from_unixtime() no longer accepts 2^31-1" +# + +select from_unixtime(0); +# check 0 boundary +select unix_timestamp('1969-12-31 14:00:01'); + diff --git a/mysql-test/t/timezone_grant.test b/mysql-test/t/timezone_grant.test index d02901b162b..450c1edc47e 100644 --- a/mysql-test/t/timezone_grant.test +++ b/mysql-test/t/timezone_grant.test @@ -1,6 +1,11 @@ # Embedded server testing does not support grants -- source include/not_embedded.inc +--disable_warnings +drop tables if exists t1, t2; +drop view if exists v1; +--enable_warnings + # # Test for bug #6116 "SET time_zone := ... requires access to mysql.time_zone # tables". We should allow implicit access to time zone description tables @@ -28,9 +33,9 @@ select convert_tz(b, 'Europe/Moscow', 'UTC') from t1; update t1, t2 set t1.b = convert_tz('2004-10-21 19:00:00', 'Europe/Moscow', 'UTC') where t1.a = t2.c and t2.d = (select max(d) from t2); # But still these two statements should not work: ---error 1044 +--error 1142 select * from mysql.time_zone_name; ---error 1044 +--error 1142 select Name, convert_tz('2004-10-21 19:00:00', Name, 'UTC') from mysql.time_zone_name; # @@ -82,3 +87,29 @@ flush privileges; drop table t1, t2; # End of 4.1 tests + +# +# Additional test for bug #15153: CONVERT_TZ() is not allowed in all +# places in views. +# +# Let us check that usage of CONVERT_TZ() function in view does not +# require additional privileges. + +# Let us rely on that previous tests done proper cleanups +create table t1 (a int, b datetime); +insert into t1 values (1, 20010101000000), (2, 20020101000000); +grant all privileges on test.* to mysqltest_1@localhost; +connect (tzuser3, localhost, mysqltest_1,,); +create view v1 as select a, convert_tz(b, 'UTC', 'Europe/Moscow') as lb from t1; +select * from v1; +# Of course we should not be able select from mysql.time_zone tables +--error ER_TABLEACCESS_DENIED_ERROR +select * from v1, mysql.time_zone; +drop view v1; +--error ER_TABLEACCESS_DENIED_ERROR +create view v1 as select a, convert_tz(b, 'UTC', 'Europe/Moscow') as lb from t1, mysql.time_zone; +connection default; +drop table t1; +drop user mysqltest_1@localhost; + +# End of 5.0 tests diff --git a/mysql-test/t/trigger-compat.test b/mysql-test/t/trigger-compat.test new file mode 100644 index 00000000000..f2e350cb161 --- /dev/null +++ b/mysql-test/t/trigger-compat.test @@ -0,0 +1,96 @@ +# Test case(s) in this file contain(s) GRANT/REVOKE statements, which are not +# supported in embedded server. So, this test should not be run on embedded +# server. + +-- source include/not_embedded.inc + +########################################################################### +# +# Tests for WL#2818: +# - Check that triggers created w/o DEFINER information work well: +# - create the first trigger; +# - manually remove definer information from corresponding TRG file; +# - create the second trigger (the first trigger will be reloaded; check +# that we receive a warning); +# - check that the triggers loaded correctly; +# +########################################################################### + +# +# Prepare environment. +# + +DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%'; +FLUSH PRIVILEGES; + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest_db1; +--enable_warnings + +CREATE DATABASE mysqltest_db1; + +CREATE USER mysqltest_dfn@localhost; +CREATE USER mysqltest_inv@localhost; + +GRANT SUPER ON *.* TO mysqltest_dfn@localhost; +GRANT CREATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; + +# +# Create a table and the first trigger. +# + +--connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1) +--connection wl2818_definer_con +--echo +--echo ---> connection: wl2818_definer_con + +CREATE TABLE t1(num_value INT); +CREATE TABLE t2(user_str TEXT); + +CREATE TRIGGER wl2818_trg1 BEFORE INSERT ON t1 + FOR EACH ROW + INSERT INTO t2 VALUES(CURRENT_USER()); + +# +# Remove definers from TRG file. +# + +--echo +--echo ---> patching t1.TRG... + +--exec grep -v 'definers=' $MYSQLTEST_VARDIR/master-data/mysqltest_db1/t1.TRG > $MYSQLTEST_VARDIR/tmp/t1.TRG +--exec mv $MYSQLTEST_VARDIR/tmp/t1.TRG $MYSQLTEST_VARDIR/master-data/mysqltest_db1/t1.TRG + +# +# Create a new trigger. +# + +--echo + +CREATE TRIGGER wl2818_trg2 AFTER INSERT ON t1 + FOR EACH ROW + INSERT INTO t2 VALUES(CURRENT_USER()); + +--echo + +SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; + +--echo + +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; + +# Clean up +DROP TRIGGER wl2818_trg1; +DROP TRIGGER wl2818_trg2; +disconnect wl2818_definer_con; +connection default; +use mysqltest_db1; +DROP TABLE t1; +DROP TABLE t2; +DROP USER mysqltest_dfn@localhost; +DROP USER mysqltest_inv@localhost; +DROP DATABASE mysqltest_db1; + diff --git a/mysql-test/t/trigger-grant.test b/mysql-test/t/trigger-grant.test new file mode 100644 index 00000000000..12b929898a8 --- /dev/null +++ b/mysql-test/t/trigger-grant.test @@ -0,0 +1,739 @@ +# Test case(s) in this file contain(s) GRANT/REVOKE statements, which are not +# supported in embedded server. So, this test should not be run on embedded +# server. + +-- source include/not_embedded.inc + +########################################################################### +# +# Tests for WL#2818: +# - Check that triggers are executed under the authorization of the definer. +# - Check DEFINER clause of CREATE TRIGGER statement; +# - Check that SUPER privilege required to create a trigger with different +# definer. +# - Check that if the user specified as DEFINER does not exist, a warning +# is emitted. +# - Check that the definer of a trigger does not exist, the trigger will +# not be activated. +# - Check that SHOW TRIGGERS statement provides "Definer" column. +# - Check that if trigger contains NEW/OLD variables, the definer must have +# SELECT privilege on the subject table (aka BUG#15166/BUG#15196). +# +# Let's also check that user name part of definer can contain '@' symbol (to +# check that triggers are not affected by BUG#13310 "incorrect user parsing +# by SP"). +# +########################################################################### + +# +# Prepare environment. +# + +DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%'; +FLUSH PRIVILEGES; + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest_db1; +--enable_warnings + +CREATE DATABASE mysqltest_db1; + +CREATE USER mysqltest_dfn@localhost; +CREATE USER mysqltest_inv@localhost; + +GRANT SUPER ON *.* TO mysqltest_dfn@localhost; +GRANT CREATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; + +# +# Check that triggers are executed under the authorization of the definer: +# - create two tables under "definer"; +# - grant all privileges on the test db to "definer"; +# - grant all privileges on the first table to "invoker"; +# - grant only select privilege on the second table to "invoker"; +# - create a trigger, which inserts a row into the second table after +# inserting into the first table. +# - insert a row into the first table under "invoker". A row also should be +# inserted into the second table. +# + +--connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1) +--connection wl2818_definer_con +--echo +--echo ---> connection: wl2818_definer_con + +CREATE TABLE t1(num_value INT); +CREATE TABLE t2(user_str TEXT); + +CREATE TRIGGER trg1 AFTER INSERT ON t1 + FOR EACH ROW + INSERT INTO t2 VALUES(CURRENT_USER()); + +--connection default +--echo +--echo ---> connection: default + +# Setup definer's privileges. + +GRANT ALL PRIVILEGES ON mysqltest_db1.t1 TO mysqltest_dfn@localhost; +GRANT ALL PRIVILEGES ON mysqltest_db1.t2 TO mysqltest_dfn@localhost; + +# Setup invoker's privileges. + +GRANT ALL PRIVILEGES ON mysqltest_db1.t1 + TO 'mysqltest_inv'@localhost; + +GRANT SELECT ON mysqltest_db1.t2 + TO 'mysqltest_inv'@localhost; + +--connection wl2818_definer_con +--echo +--echo ---> connection: wl2818_definer_con + +use mysqltest_db1; + +INSERT INTO t1 VALUES(1); + +SELECT * FROM t1; +SELECT * FROM t2; + +--connect (wl2818_invoker_con,localhost,mysqltest_inv,,mysqltest_db1) +--connection wl2818_invoker_con +--echo +--echo ---> connection: wl2818_invoker_con + +use mysqltest_db1; + +INSERT INTO t1 VALUES(2); + +SELECT * FROM t1; +SELECT * FROM t2; + +# +# Check that if definer lost some privilege required to execute (activate) a +# trigger, the trigger will not be activated: +# - create a trigger on insert into the first table, which will insert a row +# into the second table; +# - revoke INSERT privilege on the second table from the definer; +# - insert a row into the first table; +# - check that an error has been risen; +# - check that no row has been inserted into the second table; +# + +--connection default +--echo +--echo ---> connection: default + +use mysqltest_db1; + +REVOKE INSERT ON mysqltest_db1.t2 FROM mysqltest_dfn@localhost; + +--connection wl2818_invoker_con +--echo +--echo ---> connection: wl2818_invoker_con + +use mysqltest_db1; + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO t1 VALUES(3); + +SELECT * FROM t1; +SELECT * FROM t2; + +# +# Check DEFINER clause of CREATE TRIGGER statement. +# +# NOTE: there is no dedicated TRIGGER privilege for CREATE TRIGGER statement. +# SUPER privilege is used instead. I.e., if one invokes CREATE TRIGGER, it should +# have SUPER privilege, so this test is meaningless right now. +# +# - Check that SUPER privilege required to create a trigger with different +# definer: +# - try to create a trigger with DEFINER="definer@localhost" under +# "invoker"; +# - analyze error code; +# - Check that if the user specified as DEFINER does not exist, a warning is +# emitted: +# - create a trigger with DEFINER="non_existent_user@localhost" from +# "definer"; +# - check that a warning emitted; +# - Check that the definer of a trigger does not exist, the trigger will not +# be activated: +# - activate just created trigger; +# - check error code; +# + +--connection wl2818_definer_con +--echo +--echo ---> connection: wl2818_definer_con + +use mysqltest_db1; + +DROP TRIGGER trg1; + +# Check that SUPER is required to specify different DEFINER. +# NOTE: meaningless at the moment + +CREATE DEFINER='mysqltest_inv'@'localhost' + TRIGGER trg1 BEFORE INSERT ON t1 + FOR EACH ROW + SET @new_sum = 0; + +# Create with non-existent user. + +CREATE DEFINER='mysqltest_nonexs'@'localhost' + TRIGGER trg2 AFTER INSERT ON t1 + FOR EACH ROW + SET @new_sum = 0; + +# Check that trg2 will not be activated. + +--error ER_SPECIFIC_ACCESS_DENIED_ERROR +INSERT INTO t1 VALUES(6); + +# +# Check that SHOW TRIGGERS statement provides "Definer" column. +# + +SHOW TRIGGERS; + +# +# Check that weird definer values do not break functionality. I.e. check the +# following definer values: +# - ''; +# - '@'; +# - '@abc@def@@'; +# - '@hostname'; +# - '@abc@def@@@hostname'; +# + +DROP TRIGGER trg1; +DROP TRIGGER trg2; + +CREATE TRIGGER trg1 BEFORE INSERT ON t1 + FOR EACH ROW + SET @a = 1; + +CREATE TRIGGER trg2 AFTER INSERT ON t1 + FOR EACH ROW + SET @a = 2; + +CREATE TRIGGER trg3 BEFORE UPDATE ON t1 + FOR EACH ROW + SET @a = 3; + +CREATE TRIGGER trg4 AFTER UPDATE ON t1 + FOR EACH ROW + SET @a = 4; + +CREATE TRIGGER trg5 BEFORE DELETE ON t1 + FOR EACH ROW + SET @a = 5; + +--system grep -v '^definers=' $MYSQLTEST_VARDIR/master-data/mysqltest_db1/t1.TRG > $MYSQLTEST_VARDIR/tmp/t1.TRG +--system echo "definers='' '@' '@abc@def@@' '@hostname' '@abcdef@@@hostname'" >> $MYSQLTEST_VARDIR/tmp/t1.TRG +--system mv $MYSQLTEST_VARDIR/tmp/t1.TRG $MYSQLTEST_VARDIR/master-data/mysqltest_db1/t1.TRG + +--echo + +SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; + +--echo + +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; + +# +# Cleanup +# + +--connection default +--echo +--echo ---> connection: default + +DROP USER mysqltest_dfn@localhost; +DROP USER mysqltest_inv@localhost; + +DROP DATABASE mysqltest_db1; + +########################################################################### +# +# BUG#15166: Wrong update [was: select/update] permissions required to execute +# triggers. +# +# BUG#15196: Wrong select permission required to execute triggers. +# +########################################################################### + +# +# Prepare environment. +# + +DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%'; +FLUSH PRIVILEGES; + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest_db1; +--enable_warnings + +CREATE DATABASE mysqltest_db1; + +use mysqltest_db1; + +# Tables for tesing table-level privileges: +CREATE TABLE t1(col CHAR(20)); # table for "read-value" trigger +CREATE TABLE t2(col CHAR(20)); # table for "write-value" trigger + +# Tables for tesing column-level privileges: +CREATE TABLE t3(col CHAR(20)); # table for "read-value" trigger +CREATE TABLE t4(col CHAR(20)); # table for "write-value" trigger + +CREATE USER mysqltest_u1@localhost; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost; +GRANT SUPER ON *.* TO mysqltest_u1@localhost; +GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_u1@localhost; # to allow connect + +SET @mysqltest_var = NULL; + +--connect (bug15166_u1_con,localhost,mysqltest_u1,,mysqltest_db1) + +# parsing (CREATE TRIGGER) time: +# - check that nor SELECT either UPDATE is required to execute triggger w/o +# NEW/OLD variables. + +--connection default +--echo +--echo ---> connection: default + +use mysqltest_db1; + +REVOKE SELECT ON mysqltest_db1.t1 FROM mysqltest_u1@localhost; +GRANT DELETE ON mysqltest_db1.* TO mysqltest_u1@localhost; +SHOW GRANTS FOR mysqltest_u1@localhost; + +--connection bug15166_u1_con +--echo +--echo ---> connection: bug15166_u1_con + +use mysqltest_db1; + +CREATE TRIGGER t1_trg_after_delete AFTER DELETE ON t1 + FOR EACH ROW + SET @mysqltest_var = 'Hello, world!'; + +# parsing (CREATE TRIGGER) time: +# - check that UPDATE is not enough to read the value; +# - check that UPDATE is required to modify the value; + +--connection default +--echo +--echo ---> connection: default + +use mysqltest_db1; + +GRANT UPDATE ON mysqltest_db1.t1 TO mysqltest_u1@localhost; +GRANT UPDATE ON mysqltest_db1.t2 TO mysqltest_u1@localhost; + +GRANT UPDATE(col) ON mysqltest_db1.t3 TO mysqltest_u1@localhost; +GRANT UPDATE(col) ON mysqltest_db1.t4 TO mysqltest_u1@localhost; + +--connection bug15166_u1_con +--echo +--echo ---> connection: bug15166_u1_con + +use mysqltest_db1; + +# - table-level privileges + +# TODO: check privileges at CREATE TRIGGER time. +# --error ER_COLUMNACCESS_DENIED_ERROR +CREATE TRIGGER t1_trg_err_1 BEFORE INSERT ON t1 + FOR EACH ROW + SET @mysqltest_var = NEW.col; +DROP TRIGGER t1_trg_err_1; + +# TODO: check privileges at CREATE TRIGGER time. +# --error ER_COLUMNACCESS_DENIED_ERROR +CREATE TRIGGER t1_trg_err_2 BEFORE DELETE ON t1 + FOR EACH ROW + SET @mysqltest_var = OLD.col; +DROP TRIGGER t1_trg_err_2; + +CREATE TRIGGER t2_trg_before_insert BEFORE INSERT ON t2 + FOR EACH ROW + SET NEW.col = 't2_trg_before_insert'; + +# - column-level privileges + +# TODO: check privileges at CREATE TRIGGER time. +# --error ER_COLUMNACCESS_DENIED_ERROR +CREATE TRIGGER t3_trg_err_1 BEFORE INSERT ON t3 + FOR EACH ROW + SET @mysqltest_var = NEW.col; +DROP TRIGGER t3_trg_err_1; + +# TODO: check privileges at CREATE TRIGGER time. +# --error ER_COLUMNACCESS_DENIED_ERROR +CREATE TRIGGER t3_trg_err_2 BEFORE DELETE ON t3 + FOR EACH ROW + SET @mysqltest_var = OLD.col; +DROP TRIGGER t3_trg_err_2; + +CREATE TRIGGER t4_trg_before_insert BEFORE INSERT ON t4 + FOR EACH ROW + SET NEW.col = 't4_trg_before_insert'; + +# parsing (CREATE TRIGGER) time: +# - check that SELECT is required to read the value; +# - check that SELECT is not enough to modify the value; + +--connection default +--echo +--echo ---> connection: default + +use mysqltest_db1; + +REVOKE UPDATE ON mysqltest_db1.t1 FROM mysqltest_u1@localhost; +REVOKE UPDATE ON mysqltest_db1.t2 FROM mysqltest_u1@localhost; +GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_u1@localhost; +GRANT SELECT ON mysqltest_db1.t2 TO mysqltest_u1@localhost; + +REVOKE UPDATE(col) ON mysqltest_db1.t3 FROM mysqltest_u1@localhost; +REVOKE UPDATE(col) ON mysqltest_db1.t4 FROM mysqltest_u1@localhost; +GRANT SELECT(col) on mysqltest_db1.t3 TO mysqltest_u1@localhost; +GRANT SELECT(col) on mysqltest_db1.t4 TO mysqltest_u1@localhost; + +--connection bug15166_u1_con +--echo +--echo ---> connection: bug15166_u1_con + +use mysqltest_db1; + +# - table-level privileges + +CREATE TRIGGER t1_trg_after_insert AFTER INSERT ON t1 + FOR EACH ROW + SET @mysqltest_var = NEW.col; + +CREATE TRIGGER t1_trg_after_update AFTER UPDATE ON t1 + FOR EACH ROW + SET @mysqltest_var = OLD.col; + +# TODO: check privileges at CREATE TRIGGER time. +# --error ER_COLUMNACCESS_DENIED_ERROR +CREATE TRIGGER t2_trg_err_1 BEFORE UPDATE ON t2 + FOR EACH ROW + SET NEW.col = 't2_trg_err_1'; +DROP TRIGGER t2_trg_err_1; + +# TODO: check privileges at CREATE TRIGGER time. +# --error ER_COLUMNACCESS_DENIED_ERROR +CREATE TRIGGER t2_trg_err_2 BEFORE UPDATE ON t2 + FOR EACH ROW + SET NEW.col = CONCAT(OLD.col, '(updated)'); +DROP TRIGGER t2_trg_err_2; + +# - column-level privileges + +CREATE TRIGGER t3_trg_after_insert AFTER INSERT ON t3 + FOR EACH ROW + SET @mysqltest_var = NEW.col; + +CREATE TRIGGER t3_trg_after_update AFTER UPDATE ON t3 + FOR EACH ROW + SET @mysqltest_var = OLD.col; + +# TODO: check privileges at CREATE TRIGGER time. +# --error ER_COLUMNACCESS_DENIED_ERROR +CREATE TRIGGER t4_trg_err_1 BEFORE UPDATE ON t4 + FOR EACH ROW + SET NEW.col = 't4_trg_err_1'; +DROP TRIGGER t4_trg_err_1; + +# TODO: check privileges at CREATE TRIGGER time. +# --error ER_COLUMNACCESS_DENIED_ERROR +CREATE TRIGGER t4_trg_err_2 BEFORE UPDATE ON t4 + FOR EACH ROW + SET NEW.col = CONCAT(OLD.col, '(updated)'); +DROP TRIGGER t4_trg_err_2; + +# execution time: +# - check that UPDATE is not enough to read the value; +# - check that UPDATE is required to modify the value; + +--connection default +--echo +--echo ---> connection: default + +use mysqltest_db1; + +REVOKE SELECT ON mysqltest_db1.t1 FROM mysqltest_u1@localhost; +REVOKE SELECT ON mysqltest_db1.t2 FROM mysqltest_u1@localhost; +GRANT UPDATE ON mysqltest_db1.t1 TO mysqltest_u1@localhost; +GRANT UPDATE ON mysqltest_db1.t2 TO mysqltest_u1@localhost; + +REVOKE SELECT(col) ON mysqltest_db1.t3 FROM mysqltest_u1@localhost; +REVOKE SELECT(col) ON mysqltest_db1.t4 FROM mysqltest_u1@localhost; +GRANT UPDATE(col) ON mysqltest_db1.t3 TO mysqltest_u1@localhost; +GRANT UPDATE(col) ON mysqltest_db1.t4 TO mysqltest_u1@localhost; + +# - table-level privileges + +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t1 VALUES('line1'); + +SELECT * FROM t1; +SELECT @mysqltest_var; + +INSERT INTO t2 VALUES('line2'); + +SELECT * FROM t2; + +# - column-level privileges + +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t3 VALUES('t3_line1'); + +SELECT * FROM t3; +SELECT @mysqltest_var; + +INSERT INTO t4 VALUES('t4_line2'); + +SELECT * FROM t4; + +# execution time: +# - check that SELECT is required to read the value; +# - check that SELECT is not enough to modify the value; + +--connection default +--echo +--echo ---> connection: default + +use mysqltest_db1; + +REVOKE UPDATE ON mysqltest_db1.t1 FROM mysqltest_u1@localhost; +REVOKE UPDATE ON mysqltest_db1.t2 FROM mysqltest_u1@localhost; +GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_u1@localhost; +GRANT SELECT ON mysqltest_db1.t2 TO mysqltest_u1@localhost; + +REVOKE UPDATE(col) ON mysqltest_db1.t3 FROM mysqltest_u1@localhost; +REVOKE UPDATE(col) ON mysqltest_db1.t4 FROM mysqltest_u1@localhost; +GRANT SELECT(col) ON mysqltest_db1.t3 TO mysqltest_u1@localhost; +GRANT SELECT(col) ON mysqltest_db1.t4 TO mysqltest_u1@localhost; + +# - table-level privileges + +INSERT INTO t1 VALUES('line3'); + +SELECT * FROM t1; +SELECT @mysqltest_var; + +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t2 VALUES('line4'); + +SELECT * FROM t2; + +# - column-level privileges + +INSERT INTO t3 VALUES('t3_line2'); + +SELECT * FROM t3; +SELECT @mysqltest_var; + +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t4 VALUES('t4_line2'); + +SELECT * FROM t4; + +# execution time: +# - check that nor SELECT either UPDATE is required to execute triggger w/o +# NEW/OLD variables. + +DELETE FROM t1; + +SELECT @mysqltest_var; + +# +# Cleanup. +# + +DROP USER mysqltest_u1@localhost; + +DROP DATABASE mysqltest_db1; + + +# +# Test for bug #14635 Accept NEW.x as INOUT parameters to stored +# procedures from within triggers +# +# We require UPDATE privilege when NEW.x passed as OUT parameter, and +# SELECT and UPDATE when NEW.x passed as INOUT parameter. +# +DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%'; +FLUSH PRIVILEGES; + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest_db1; +--enable_warnings + +CREATE DATABASE mysqltest_db1; +USE mysqltest_db1; + +CREATE TABLE t1 (i1 INT); +CREATE TABLE t2 (i1 INT); + +CREATE USER mysqltest_dfn@localhost; +CREATE USER mysqltest_inv@localhost; + +GRANT EXECUTE, CREATE ROUTINE, SUPER ON *.* TO mysqltest_dfn@localhost; +GRANT INSERT ON mysqltest_db1.* TO mysqltest_inv@localhost; + +connect (definer,localhost,mysqltest_dfn,,mysqltest_db1); +connect (invoker,localhost,mysqltest_inv,,mysqltest_db1); + +connection definer; +CREATE PROCEDURE p1(OUT i INT) DETERMINISTIC NO SQL SET i = 3; +CREATE PROCEDURE p2(INOUT i INT) DETERMINISTIC NO SQL SET i = i * 5; + +# Check that having no privilege won't work. +connection definer; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW + CALL p2(NEW.i1); + +connection invoker; +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t1 VALUES (7); +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t2 VALUES (11); + +connection definer; +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; + +# Check that having only SELECT privilege is not enough. +connection default; +GRANT SELECT ON mysqltest_db1.* TO mysqltest_dfn@localhost; + +connection definer; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW + CALL p2(NEW.i1); + +connection invoker; +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t1 VALUES (13); +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t2 VALUES (17); + +connection default; +REVOKE SELECT ON mysqltest_db1.* FROM mysqltest_dfn@localhost; + +connection definer; +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; + +# Check that having only UPDATE privilege is enough for OUT parameter, +# but not for INOUT parameter. +connection default; +GRANT UPDATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; + +connection definer; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW + CALL p2(NEW.i1); + +connection invoker; +INSERT INTO t1 VALUES (19); +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t2 VALUES (23); + +connection default; +REVOKE UPDATE ON mysqltest_db1.* FROM mysqltest_dfn@localhost; + +connection definer; +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; + +# Check that having SELECT and UPDATE privileges is enough. +connection default; +GRANT SELECT, UPDATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; + +connection definer; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW + CALL p2(NEW.i1); + +connection invoker; +INSERT INTO t1 VALUES (29); +INSERT INTO t2 VALUES (31); + +connection default; +REVOKE SELECT, UPDATE ON mysqltest_db1.* FROM mysqltest_dfn@localhost; + +connection definer; +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; + +connection default; +DROP PROCEDURE p2; +DROP PROCEDURE p1; + +# Check that late procedure redefining won't open a security hole. +connection default; +GRANT UPDATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; + +connection definer; +CREATE PROCEDURE p1(OUT i INT) DETERMINISTIC NO SQL SET i = 37; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + CALL p1(NEW.i1); + +connection invoker; +INSERT INTO t1 VALUES (41); + +connection definer; +DROP PROCEDURE p1; +CREATE PROCEDURE p1(IN i INT) DETERMINISTIC NO SQL SET @v1 = i + 43; + +connection invoker; +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t1 VALUES (47); + +connection definer; +DROP PROCEDURE p1; +CREATE PROCEDURE p1(INOUT i INT) DETERMINISTIC NO SQL SET i = i + 51; + +connection invoker; +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t1 VALUES (53); + +connection default; +DROP PROCEDURE p1; +REVOKE UPDATE ON mysqltest_db1.* FROM mysqltest_dfn@localhost; + +connection definer; +DROP TRIGGER t1_bi; + +# Cleanup. +disconnect definer; +disconnect invoker; +connection default; +DROP USER mysqltest_inv@localhost; +DROP USER mysqltest_dfn@localhost; +DROP TABLE t2; +DROP TABLE t1; +DROP DATABASE mysqltest_db1; +USE test; + +--echo End of 5.0 tests. diff --git a/mysql-test/t/trigger-trans.test b/mysql-test/t/trigger-trans.test new file mode 100644 index 00000000000..5c135d98878 --- /dev/null +++ b/mysql-test/t/trigger-trans.test @@ -0,0 +1,52 @@ +# Tests which involve triggers and transactions +# (or just InnoDB storage engine) +--source include/have_innodb.inc + +--disable_warnings +drop table if exists t1; +--enable_warnings + +# Test for bug #18153 "OPTIMIZE/ALTER on transactional tables corrupt +# triggers/triggers are lost". + +create table t1 (a varchar(16), b int) engine=innodb; +delimiter |; +create trigger t1_bi before insert on t1 for each row +begin + set new.a := upper(new.a); + set new.b := new.b + 3; +end| +delimiter ;| +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test' and event_object_table = 't1'; +insert into t1 values ('The Lion', 10); +select * from t1; +optimize table t1; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test' and event_object_table = 't1'; +insert into t1 values ('The Unicorn', 20); +select * from t1; +alter table t1 add column c int default 0; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test' and event_object_table = 't1'; +insert into t1 values ('Alice', 30, 1); +select * from t1; +# Special tricky cases allowed by ALTER TABLE ... RENAME +alter table t1 rename to t1; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test' and event_object_table = 't1'; +insert into t1 values ('The Crown', 40, 1); +select * from t1; +alter table t1 rename to t1, add column d int default 0; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test' and event_object_table = 't1'; +insert into t1 values ('The Pie', 50, 1, 1); +select * from t1; +drop table t1; + +# End of 5.0 tests diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test new file mode 100644 index 00000000000..92320648033 --- /dev/null +++ b/mysql-test/t/trigger.test @@ -0,0 +1,1502 @@ +# +# Basic triggers test +# + +--disable_warnings +drop table if exists t1, t2, t3, t4; +drop view if exists v1; +drop database if exists mysqltest; +drop function if exists f1; +drop function if exists f2; +drop procedure if exists p1; +--enable_warnings + +# Create additional connections used through test +connect (addconroot1, localhost, root,,); +connect (addconroot2, localhost, root,,); +# Connection without current database set +connect (addconwithoutdb, localhost, root,,*NO-ONE*); +connection default; + +create table t1 (i int); + +# let us test some very simple trigger +create trigger trg before insert on t1 for each row set @a:=1; +set @a:=0; +select @a; +insert into t1 values (1); +select @a; +drop trigger trg; + +# let us test simple trigger reading some values +create trigger trg before insert on t1 for each row set @a:=new.i; +insert into t1 values (123); +select @a; +drop trigger trg; + +drop table t1; + +# Let us test before insert trigger +# Such triggers can be used for setting complex default values +create table t1 (i int not null, j int); +delimiter |; +create trigger trg before insert on t1 for each row +begin + if isnull(new.j) then + set new.j:= new.i * 10; + end if; +end| +insert into t1 (i) values (1)| +insert into t1 (i,j) values (2, 3)| +select * from t1| +drop trigger trg| +drop table t1| +delimiter ;| + +# After insert trigger +# Useful for aggregating data +create table t1 (i int not null primary key); +create trigger trg after insert on t1 for each row + set @a:= if(@a,concat(@a, ":", new.i), new.i); +set @a:=""; +insert into t1 values (2),(3),(4),(5); +select @a; +drop trigger trg; +drop table t1; + +# PS doesn't work with multi-row statements +--disable_ps_protocol +# Before update trigger +# (In future we will achieve this via proper error handling in triggers) +create table t1 (aid int not null primary key, balance int not null default 0); +insert into t1 values (1, 1000), (2,3000); +delimiter |; +create trigger trg before update on t1 for each row +begin + declare loc_err varchar(255); + if abs(new.balance - old.balance) > 1000 then + set new.balance:= old.balance; + set loc_err := concat("Too big change for aid = ", new.aid); + set @update_failed:= if(@update_failed, concat(@a, ":", loc_err), loc_err); + end if; +end| +set @update_failed:=""| +update t1 set balance=1500| +select @update_failed; +select * from t1| +drop trigger trg| +drop table t1| +delimiter ;| +--enable_ps_protocol + +# After update trigger +create table t1 (i int); +insert into t1 values (1),(2),(3),(4); +create trigger trg after update on t1 for each row + set @total_change:=@total_change + new.i - old.i; +set @total_change:=0; +update t1 set i=3; +select @total_change; +drop trigger trg; +drop table t1; + +# Before delete trigger +# This can be used for aggregation too :) +create table t1 (i int); +insert into t1 values (1),(2),(3),(4); +create trigger trg before delete on t1 for each row + set @del_sum:= @del_sum + old.i; +set @del_sum:= 0; +delete from t1 where i <= 3; +select @del_sum; +drop trigger trg; +drop table t1; + +# After delete trigger. +# Just run out of imagination. +create table t1 (i int); +insert into t1 values (1),(2),(3),(4); +create trigger trg after delete on t1 for each row set @del:= 1; +set @del:= 0; +delete from t1 where i <> 0; +select @del; +drop trigger trg; +drop table t1; + +# Several triggers on one table +create table t1 (i int, j int); + +delimiter |; +create trigger trg1 before insert on t1 for each row +begin + if new.j > 10 then + set new.j := 10; + end if; +end| +create trigger trg2 before update on t1 for each row +begin + if old.i % 2 = 0 then + set new.j := -1; + end if; +end| +create trigger trg3 after update on t1 for each row +begin + if new.j = -1 then + set @fired:= "Yes"; + end if; +end| +delimiter ;| +set @fired:=""; +insert into t1 values (1,2),(2,3),(3,14); +select @fired; +select * from t1; +update t1 set j= 20; +select @fired; +select * from t1; + +drop trigger trg1; +drop trigger trg2; +drop trigger trg3; +drop table t1; + + +# Let us test how triggers work for special forms of INSERT such as +# REPLACE and INSERT ... ON DUPLICATE KEY UPDATE +create table t1 (id int not null primary key, data int); +create trigger t1_bi before insert on t1 for each row + set @log:= concat(@log, "(BEFORE_INSERT: new=(id=", new.id, ", data=", new.data,"))"); +create trigger t1_ai after insert on t1 for each row + set @log:= concat(@log, "(AFTER_INSERT: new=(id=", new.id, ", data=", new.data,"))"); +create trigger t1_bu before update on t1 for each row + set @log:= concat(@log, "(BEFORE_UPDATE: old=(id=", old.id, ", data=", old.data, + ") new=(id=", new.id, ", data=", new.data,"))"); +create trigger t1_au after update on t1 for each row + set @log:= concat(@log, "(AFTER_UPDATE: old=(id=", old.id, ", data=", old.data, + ") new=(id=", new.id, ", data=", new.data,"))"); +create trigger t1_bd before delete on t1 for each row + set @log:= concat(@log, "(BEFORE_DELETE: old=(id=", old.id, ", data=", old.data,"))"); +create trigger t1_ad after delete on t1 for each row + set @log:= concat(@log, "(AFTER_DELETE: old=(id=", old.id, ", data=", old.data,"))"); +# Simple INSERT - both triggers should be called +set @log:= ""; +insert into t1 values (1, 1); +select @log; +# INSERT IGNORE for already existing key - only before trigger should fire +set @log:= ""; +insert ignore t1 values (1, 2); +select @log; +# INSERT ... ON DUPLICATE KEY UPDATE ... +set @log:= ""; +insert into t1 (id, data) values (1, 3), (2, 2) on duplicate key update data= data + 1; +select @log; +# REPLACE (also test for bug#13479 "REPLACE activates UPDATE trigger, +# not the DELETE and INSERT triggers") +# We define REPLACE as INSERT which DELETEs old rows which conflict with +# row being inserted. So for the first record in statement below we will +# call before insert trigger, then delete will be executed (and both delete +# triggers should fire). Finally after insert trigger will be called. +# For the second record we will just call both on insert triggers. +set @log:= ""; +replace t1 values (1, 4), (3, 3); +select @log; +# Now we will drop ON DELETE triggers to test REPLACE which is internally +# executed via update +drop trigger t1_bd; +drop trigger t1_ad; +set @log:= ""; +replace t1 values (1, 5); +select @log; + +# This also drops associated triggers +drop table t1; + + +# +# Let us test triggers which access other tables. +# +# Trivial trigger which inserts data into another table +create table t1 (id int primary key, data varchar(10), fk int); +create table t2 (event varchar(100)); +create table t3 (id int primary key); +create trigger t1_ai after insert on t1 for each row + insert into t2 values (concat("INSERT INTO t1 id=", new.id, " data='", new.data, "'")); +insert into t1 (id, data) values (1, "one"), (2, "two"); +select * from t1; +select * from t2; +drop trigger t1_ai; +# Trigger which uses couple of tables (and partially emulates FK constraint) +delimiter |; +create trigger t1_bi before insert on t1 for each row +begin + if exists (select id from t3 where id=new.fk) then + insert into t2 values (concat("INSERT INTO t1 id=", new.id, " data='", new.data, "' fk=", new.fk)); + else + insert into t2 values (concat("INSERT INTO t1 FAILED id=", new.id, " data='", new.data, "' fk=", new.fk)); + set new.id= NULL; + end if; +end| +delimiter ;| +insert into t3 values (1); +--error ER_BAD_NULL_ERROR +insert into t1 values (4, "four", 1), (5, "five", 2); +select * from t1; +select * from t2; +drop table t1, t2, t3; +# Trigger which invokes function +create table t1 (id int primary key, data varchar(10)); +create table t2 (seq int); +insert into t2 values (10); +create function f1 () returns int return (select max(seq) from t2); +delimiter |; +create trigger t1_bi before insert on t1 for each row +begin + if new.id > f1() then + set new.id:= f1(); + end if; +end| +delimiter ;| +insert into t1 values (1, "first"); +insert into t1 values (f1(), "max"); +select * from t1; +drop table t1, t2; +drop function f1; +# Trigger which forces invocation of another trigger +# (emulation of FK on delete cascade policy) +create table t1 (id int primary key, fk_t2 int); +create table t2 (id int primary key, fk_t3 int); +create table t3 (id int primary key); +insert into t1 values (1,1), (2,1), (3,2); +insert into t2 values (1,1), (2,2); +insert into t3 values (1), (2); +create trigger t3_ad after delete on t3 for each row + delete from t2 where fk_t3=old.id; +create trigger t2_ad after delete on t2 for each row + delete from t1 where fk_t2=old.id; +delete from t3 where id = 1; +select * from t1 left join (t2 left join t3 on t2.fk_t3 = t3.id) on t1.fk_t2 = t2.id; +drop table t1, t2, t3; +# Trigger which assigns value selected from table to field of row +# being inserted/updated. +create table t1 (id int primary key, copy int); +create table t2 (id int primary key, data int); +insert into t2 values (1,1), (2,2); +create trigger t1_bi before insert on t1 for each row + set new.copy= (select data from t2 where id = new.id); +create trigger t1_bu before update on t1 for each row + set new.copy= (select data from t2 where id = new.id); +insert into t1 values (1,3), (2,4), (3,3); +update t1 set copy= 1 where id = 2; +select * from t1; +drop table t1, t2; + +# +# Test of wrong column specifiers in triggers +# +create table t1 (i int); +create table t3 (i int); + +--error ER_TRG_NO_SUCH_ROW_IN_TRG +create trigger trg before insert on t1 for each row set @a:= old.i; +--error ER_TRG_NO_SUCH_ROW_IN_TRG +create trigger trg before delete on t1 for each row set @a:= new.i; +--error ER_TRG_CANT_CHANGE_ROW +create trigger trg before update on t1 for each row set old.i:=1; +--error ER_TRG_NO_SUCH_ROW_IN_TRG +create trigger trg before delete on t1 for each row set new.i:=1; +--error ER_TRG_CANT_CHANGE_ROW +create trigger trg after update on t1 for each row set new.i:=1; +--error ER_BAD_FIELD_ERROR +create trigger trg before update on t1 for each row set new.j:=1; +--error ER_BAD_FIELD_ERROR +create trigger trg before update on t1 for each row set @a:=old.j; + + +# +# Let us test various trigger creation errors +# Also quickly test table namespace (bug#5892/6182) +# +--error ER_NO_SUCH_TABLE +create trigger trg before insert on t2 for each row set @a:=1; + +create trigger trg before insert on t1 for each row set @a:=1; +--error ER_TRG_ALREADY_EXISTS +create trigger trg after insert on t1 for each row set @a:=1; +--error ER_NOT_SUPPORTED_YET +create trigger trg2 before insert on t1 for each row set @a:=1; +--error ER_TRG_ALREADY_EXISTS +create trigger trg before insert on t3 for each row set @a:=1; +create trigger trg2 before insert on t3 for each row set @a:=1; +drop trigger trg2; +drop trigger trg; + +--error ER_TRG_DOES_NOT_EXIST +drop trigger trg; + +create view v1 as select * from t1; +--error ER_WRONG_OBJECT +create trigger trg before insert on v1 for each row set @a:=1; +drop view v1; + +drop table t1; +drop table t3; + +create temporary table t1 (i int); +--error ER_TRG_ON_VIEW_OR_TEMP_TABLE +create trigger trg before insert on t1 for each row set @a:=1; +drop table t1; + + + +# +# Tests for various trigger-related bugs +# + +# Test for bug #5887 "Triggers with string literals cause errors". +# New .FRM parser was not handling escaped strings properly. +create table t1 (x1col char); +create trigger tx1 before insert on t1 for each row set new.x1col = 'x'; +insert into t1 values ('y'); +drop trigger tx1; +drop table t1; + +# +# Test for bug #5890 "Triggers fail for DELETE without WHERE". +# If we are going to delete all rows in table but DELETE triggers exist +# we should perform row-by-row deletion instead of using optimized +# delete_all_rows() method. +# +create table t1 (i int) engine=myisam; +insert into t1 values (1), (2); +create trigger trg1 before delete on t1 for each row set @del_before:= @del_before + old.i; +create trigger trg2 after delete on t1 for each row set @del_after:= @del_after + old.i; +set @del_before:=0, @del_after:= 0; +delete from t1; +select @del_before, @del_after; +drop trigger trg1; +drop trigger trg2; +drop table t1; + +# Test for bug #5859 "DROP TABLE does not drop triggers". Trigger should not +# magically reappear when we recreate dropped table. +create table t1 (a int); +create trigger trg1 before insert on t1 for each row set new.a= 10; +drop table t1; +create table t1 (a int); +insert into t1 values (); +select * from t1; +drop table t1; + +# Test for bug #6559 "DROP DATABASE forgets to drop triggers". +create database mysqltest; +use mysqltest; +create table t1 (i int); +create trigger trg1 before insert on t1 for each row set @a:= 1; +# This should succeed +drop database mysqltest; +use test; + +# Test for bug #8791 +# "Triggers: Allowed to create triggers on a subject table in a different DB". +create database mysqltest; +create table mysqltest.t1 (i int); +--error ER_TRG_IN_WRONG_SCHEMA +create trigger trg1 before insert on mysqltest.t1 for each row set @a:= 1; +use mysqltest; +--error ER_TRG_IN_WRONG_SCHEMA +create trigger test.trg1 before insert on t1 for each row set @a:= 1; +drop database mysqltest; +use test; + + +# Test for bug #5860 "Multi-table UPDATE does not activate update triggers" +# We will also test how delete triggers wor for multi-table DELETE. +create table t1 (i int, j int default 10, k int not null, key (k)); +create table t2 (i int); +insert into t1 (i, k) values (1, 1); +insert into t2 values (1); +create trigger trg1 before update on t1 for each row set @a:= @a + new.j - old.j; +create trigger trg2 after update on t1 for each row set @b:= "Fired"; +set @a:= 0, @b:= ""; +# Check that trigger works in case of update on the fly +update t1, t2 set j = j + 10 where t1.i = t2.i; +select @a, @b; +insert into t1 values (2, 13, 2); +insert into t2 values (2); +set @a:= 0, @b:= ""; +# And now let us check that triggers work in case of multi-update which +# is done through temporary tables... +update t1, t2 set j = j + 15 where t1.i = t2.i and t1.k >= 2; +select @a, @b; +# Let us test delete triggers for multi-delete now. +# We create triggers for both tables because we want test how they +# work in both on-the-fly and via-temp-tables cases. +create trigger trg3 before delete on t1 for each row set @c:= @c + old.j; +create trigger trg4 before delete on t2 for each row set @d:= @d + old.i; +create trigger trg5 after delete on t1 for each row set @e:= "After delete t1 fired"; +create trigger trg6 after delete on t2 for each row set @f:= "After delete t2 fired"; +set @c:= 0, @d:= 0, @e:= "", @f:= ""; +delete t1, t2 from t1, t2 where t1.i = t2.i; +select @c, @d, @e, @f; +# This also will drop triggers +drop table t1, t2; + +# Test for bug #6812 "Triggers are not activated for INSERT ... SELECT". +# (We also check the fact that trigger modifies some field does not affect +# value of next record inserted). +delimiter |; +create table t1 (i int, j int default 10)| +create table t2 (i int)| +insert into t2 values (1), (2)| +create trigger trg1 before insert on t1 for each row +begin + if new.i = 1 then + set new.j := 1; + end if; +end| +create trigger trg2 after insert on t1 for each row set @a:= 1| +set @a:= 0| +insert into t1 (i) select * from t2| +select * from t1| +select @a| +# This also will drop triggers +drop table t1, t2| +delimiter ;| + +# Test for bug #8755 "Trigger is not activated by LOAD DATA" +create table t1 (i int, j int, k int); +create trigger trg1 before insert on t1 for each row set new.k = new.i; +create trigger trg2 after insert on t1 for each row set @b:= "Fired"; +set @b:=""; +# Test triggers with file with separators +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, i); +select *, @b from t1; +set @b:=""; +# Test triggers with fixed size row file +load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, j); +select *, @b from t1; +# This also will drop triggers +drop table t1; + +# Test for bug #5894 "Triggers with altered tables cause corrupt databases" +# Also tests basic error handling for various kinds of triggers. +create table t1 (i int, at int, k int, key(k)) engine=myisam; +create table t2 (i int); +insert into t1 values (1, 1, 1); +# We need at least 3 elements in t2 to test multi-update properly +insert into t2 values (1), (2), (3); +# Create and then break "after" triggers +create trigger ai after insert on t1 for each row set @a:= new.at; +create trigger au after update on t1 for each row set @a:= new.at; +create trigger ad after delete on t1 for each row set @a:= old.at; +alter table t1 drop column at; +# We still should be able select data from tables. +select * from t1; +# The following statements changing t1 should fail, but still cause +# their main effect. This is because operation on the table row is +# executed before "after" trigger and its effect cannot be rolled back +# when whole statement fails, because t1 is MyISAM table. +--error ER_BAD_FIELD_ERROR +insert into t1 values (2, 1); +select * from t1; +--error ER_BAD_FIELD_ERROR +update t1 set k = 2 where i = 2; +select * from t1; +--error ER_BAD_FIELD_ERROR +delete from t1 where i = 2; +select * from t1; +# Should fail and insert only 1 row +--error ER_BAD_FIELD_ERROR +load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, k); +select * from t1; +--error ER_BAD_FIELD_ERROR +insert into t1 select 3, 3; +select * from t1; +# Multi-update working on the fly, again it will update only +# one row even if more matches +--error ER_BAD_FIELD_ERROR +update t1, t2 set k = k + 10 where t1.i = t2.i; +select * from t1; +# The same for multi-update via temp table +--error ER_BAD_FIELD_ERROR +update t1, t2 set k = k + 10 where t1.i = t2.i and k < 3; +select * from t1; +# Multi-delete on the fly +--error ER_BAD_FIELD_ERROR +delete t1, t2 from t1 straight_join t2 where t1.i = t2.i; +select * from t1; +# And via temporary storage +--error ER_BAD_FIELD_ERROR +delete t2, t1 from t2 straight_join t1 where t1.i = t2.i; +select * from t1; +# Prepare table for testing of REPLACE and INSERT ... ON DUPLICATE KEY UPDATE +alter table t1 add primary key (i); +--error ER_BAD_FIELD_ERROR +insert into t1 values (3, 4) on duplicate key update k= k + 10; +select * from t1; +# The following statement will delete old row and won't +# insert new one since after delete trigger will fail. +--error ER_BAD_FIELD_ERROR +replace into t1 values (3, 3); +select * from t1; +# Also drops all triggers +drop table t1, t2; + +create table t1 (i int, bt int, k int, key(k)) engine=myisam; +create table t2 (i int); +insert into t1 values (1, 1, 1), (2, 2, 2); +insert into t2 values (1), (2), (3); +# Create and then break "before" triggers +create trigger bi before insert on t1 for each row set @a:= new.bt; +create trigger bu before update on t1 for each row set @a:= new.bt; +create trigger bd before delete on t1 for each row set @a:= old.bt; +alter table t1 drop column bt; +# The following statements changing t1 should fail and should not +# cause any effect on table, since "before" trigger is executed +# before operation on the table row. +--error ER_BAD_FIELD_ERROR +insert into t1 values (3, 3); +select * from t1; +--error ER_BAD_FIELD_ERROR +update t1 set i = 2; +select * from t1; +--error ER_BAD_FIELD_ERROR +delete from t1; +select * from t1; +--error ER_BAD_FIELD_ERROR +load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, k); +select * from t1; +--error ER_BAD_FIELD_ERROR +insert into t1 select 3, 3; +select * from t1; +# Both types of multi-update (on the fly and via temp table) +--error ER_BAD_FIELD_ERROR +update t1, t2 set k = k + 10 where t1.i = t2.i; +select * from t1; +--error ER_BAD_FIELD_ERROR +update t1, t2 set k = k + 10 where t1.i = t2.i and k < 2; +select * from t1; +# Both types of multi-delete +--error ER_BAD_FIELD_ERROR +delete t1, t2 from t1 straight_join t2 where t1.i = t2.i; +select * from t1; +--error ER_BAD_FIELD_ERROR +delete t2, t1 from t2 straight_join t1 where t1.i = t2.i; +select * from t1; +# Let us test REPLACE/INSERT ... ON DUPLICATE KEY UPDATE. +# To test properly code-paths different from those that are used +# in ordinary INSERT we need to drop "before insert" trigger. +alter table t1 add primary key (i); +drop trigger bi; +--error ER_BAD_FIELD_ERROR +insert into t1 values (2, 4) on duplicate key update k= k + 10; +select * from t1; +--error ER_BAD_FIELD_ERROR +replace into t1 values (2, 4); +select * from t1; +# Also drops all triggers +drop table t1, t2; + +# Test for bug #5893 "Triggers with dropped functions cause crashes" +# Appropriate error should be reported instead of crash. +# Also test for bug #11889 "Server crashes when dropping trigger +# using stored routine". +--disable_warnings +drop function if exists bug5893; +--enable_warnings +create table t1 (col1 int, col2 int); +insert into t1 values (1, 2); +create function bug5893 () returns int return 5; +create trigger t1_bu before update on t1 for each row set new.col1= bug5893(); +drop function bug5893; +--error ER_SP_DOES_NOT_EXIST +update t1 set col2 = 4; +# This should not crash server too. +drop trigger t1_bu; +drop table t1; + +# +# storing and restoring parsing modes for triggers (BUG#5891) +# +set sql_mode='ansi'; +create table t1 ("t1 column" int); +create trigger t1_bi before insert on t1 for each row set new."t1 column" = 5; +set sql_mode=""; +insert into t1 values (0); +# create trigger with different sql_mode +create trigger t1_af after insert on t1 for each row set @a=10; +insert into t1 values (0); +select * from t1; +select @a; +--replace_column 6 # +show triggers; +drop table t1; +# check that rigger preserve sql_mode during execution +set sql_mode="traditional"; +create table t1 (a date); +-- error 1292 +insert into t1 values ('2004-01-00'); +set sql_mode=""; +create trigger t1_bi before insert on t1 for each row set new.a = '2004-01-00'; +set sql_mode="traditional"; +insert into t1 values ('2004-01-01'); +select * from t1; +set sql_mode=default; +show create table t1; +--replace_column 6 # +show triggers; +drop table t1; + +# Test for bug #12280 "Triggers: crash if flush tables" +# FLUSH TABLES and FLUSH PRIVILEGES should be disallowed inside +# of functions and triggers. +create table t1 (id int); +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row reset query cache; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row reset master; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row reset slave; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row flush hosts; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row flush tables with read lock; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row flush logs; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row flush status; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row flush slave; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row flush master; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row flush des_key_file; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row flush user_resources; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row flush tables; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +create trigger t1_ai after insert on t1 for each row flush privileges; +--disable_warnings +drop procedure if exists p1; +--enable_warnings + +create trigger t1_ai after insert on t1 for each row call p1(); +create procedure p1() flush tables; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() reset query cache; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() reset master; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() reset slave; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() flush hosts; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() flush privileges; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() flush tables with read lock; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() flush tables; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() flush logs; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() flush status; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() flush slave; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() flush master; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() flush des_key_file; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +create procedure p1() flush user_resources; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +insert into t1 values (0); + +drop procedure p1; +drop table t1; + +# Test for bug #11973 "SELECT .. INTO var_name; in trigger cause +# crash on update" + +create table t1 (id int, data int, username varchar(16)); +insert into t1 (id, data) values (1, 0); +delimiter |; +create trigger t1_whoupdated before update on t1 for each row +begin + declare user varchar(32); + declare i int; + select user() into user; + set NEW.username = user; + select count(*) from ((select 1) union (select 2)) as d1 into i; +end| +delimiter ;| +update t1 set data = 1; + +connection addconroot1; +update t1 set data = 2; + +connection default; +drop table t1; + +# +# #11587 Trigger causes lost connection error +# + +create table t1 (c1 int, c2 datetime); +delimiter |; +--error ER_SP_NO_RETSET +create trigger tr1 before insert on t1 for each row +begin + set new.c2= '2004-04-01'; + select 'hello'; +end| +delimiter ;| + +insert into t1 (c1) values (1),(2),(3); +select * from t1; + +--disable_warnings +drop procedure if exists bug11587; +--enable_warnings + +delimiter |; +create procedure bug11587(x char(16)) +begin + select "hello"; + select "hello again"; +end| + +create trigger tr1 before insert on t1 for each row +begin + call bug11587(); + set new.c2= '2004-04-02'; +end| +delimiter ;| + +--error ER_SP_NO_RETSET +insert into t1 (c1) values (4),(5),(6); +select * from t1; + +drop procedure bug11587; +drop table t1; + +# Test for bug #11896 "Partial locking in case of recursive trigger +# definitions". Recursion in triggers should not be allowed. +# We also should not allow to change tables which are used in +# statements invoking this trigger. +create table t1 (f1 integer); +create table t2 (f2 integer); +create trigger t1_ai after insert on t1 + for each row insert into t2 values (new.f1+1); +create trigger t2_ai after insert on t2 + for each row insert into t1 values (new.f2+1); +# Allow SP resursion to be show that it has not influence here +set @SAVE_SP_RECURSION_LEVELS=@@max_sp_recursion_depth; +set @@max_sp_recursion_depth=100; +--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG +insert into t1 values (1); +set @@max_sp_recursion_depth=@SAVE_SP_RECURSION_LEVELS; +select * from t1; +select * from t2; +drop trigger t1_ai; +drop trigger t2_ai; +create trigger t1_bu before update on t1 + for each row insert into t1 values (2); +--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG +update t1 set f1= 10; +select * from t1; +drop trigger t1_bu; +create trigger t1_bu before update on t1 + for each row delete from t1 where f1=new.f1; +--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG +update t1 set f1= 10; +select * from t1; +drop trigger t1_bu; +# This should work tough +create trigger t1_bi before insert on t1 + for each row set new.f1=(select sum(f1) from t1); +insert into t1 values (3); +select * from t1; +drop trigger t1_bi; +drop tables t1, t2; + +# Tests for bug #12704 "Server crashes during trigger execution". +# If we run DML statements and CREATE TRIGGER statements concurrently +# it may happen that trigger will be created while DML statement is +# waiting for table lock. In this case we have to reopen tables and +# recalculate prelocking set. +# Unfortunately these tests rely on the order in which tables are locked +# by statement so they are non determenistic and are disabled. +--disable_parsing +create table t1 (id int); +create table t2 (id int); +create table t3 (id int); +create function f1() returns int return (select max(id)+2 from t2); +create view v1 as select f1() as f; + +# Let us check that we notice trigger at all +connection addconroot1; +lock tables t2 write; +connection default; +send insert into t1 values ((select max(id) from t2)), (2); +--sleep 1 +connection addconroot2; +create trigger t1_trg before insert on t1 for each row set NEW.id:= 1; +connection addconroot1; +unlock tables; +connection default; +reap; +select * from t1; + +# Check that we properly calculate new prelocking set +insert into t2 values (3); +connection addconroot1; +lock tables t2 write; +connection default; +send insert into t1 values ((select max(id) from t2)), (4); +--sleep 1 +connection addconroot2; +drop trigger t1_trg; +create trigger t1_trg before insert on t1 for each row + insert into t3 values (new.id); +connection addconroot1; +unlock tables; +connection default; +reap; +select * from t1; +select * from t3; + +# We should be able to do this even if fancy views are involved +connection addconroot1; +lock tables t2 write; +connection default; +send insert into t1 values ((select max(f) from v1)), (6); +--sleep 1 +connection addconroot2; +drop trigger t1_trg; +create trigger t1_trg before insert on t1 for each row + insert into t3 values (new.id + 100); +connection addconroot1; +unlock tables; +connection default; +reap; +select * from t1; +select * from t3; + +# This also should work for multi-update +# Let us drop trigger to demonstrate that prelocking set is really +# rebuilt +drop trigger t1_trg; +connection addconroot1; +lock tables t2 write; +connection default; +send update t1, t2 set t1.id=10 where t1.id=t2.id; +--sleep 1 +connection addconroot2; +create trigger t1_trg before update on t1 for each row + insert into t3 values (new.id); +connection addconroot1; +unlock tables; +connection default; +reap; +select * from t1; +select * from t3; + +# And even for multi-update converted from ordinary update thanks to view +drop view v1; +drop trigger t1_trg; +create view v1 as select t1.id as id1 from t1, t2 where t1.id= t2.id; +insert into t2 values (10); +connection addconroot1; +lock tables t2 write; +connection default; +send update v1 set id1= 11; +--sleep 1 +connection addconroot2; +create trigger t1_trg before update on t1 for each row + insert into t3 values (new.id + 100); +connection addconroot1; +unlock tables; +connection default; +reap; +select * from t1; +select * from t3; + +drop function f1; +drop view v1; +drop table t1, t2, t3; +--enable_parsing + +# +# Test for bug #13399 "Crash when executing PS/SP which should activate +# trigger which is now dropped". See also test for similar bug for stored +# routines in sp-error.test (#12329). +create table t1 (id int); +create table t2 (id int); +create trigger t1_bi before insert on t1 for each row insert into t2 values (new.id); +prepare stmt1 from "insert into t1 values (10)"; +create procedure p1() insert into t1 values (10); +call p1(); +# Actually it is enough to do FLUSH TABLES instead of DROP TRIGGER +drop trigger t1_bi; +# Server should not crash on these two statements +execute stmt1; +call p1(); +deallocate prepare stmt1; +drop procedure p1; + +# Let us test more complex situation when we alter trigger in such way that +# it uses different set of tables (or simply add new trigger). +create table t3 (id int); +create trigger t1_bi after insert on t1 for each row insert into t2 values (new.id); +prepare stmt1 from "insert into t1 values (10)"; +create procedure p1() insert into t1 values (10); +call p1(); +# Altering trigger forcing it use different set of tables +drop trigger t1_bi; +create trigger t1_bi after insert on t1 for each row insert into t3 values (new.id); +# Until we implement proper mechanism for invalidation of PS/SP when table +# or SP's are changed these two statements will fail with 'Table ... was +# not locked' error (this mechanism should be based on the new TDC). +--error 1100 #ER_TABLE_NOT_LOCKED +execute stmt1; +--error 1100 #ER_TABLE_NOT_LOCKED +call p1(); +deallocate prepare stmt1; +drop procedure p1; +drop table t1, t2, t3; + +# +# BUG#13549 "Server crash with nested stored procedures". +# Server should not crash when during execution of stored procedure +# we have to parse trigger/function definition and this new trigger/ +# function has more local variables declared than invoking stored +# procedure and last of these variables is used in argument of NOT +# operator. +# +create table t1 (a int); +DELIMITER //; +CREATE PROCEDURE `p1`() +begin + insert into t1 values (1); +end// +create trigger trg before insert on t1 for each row +begin + declare done int default 0; + set done= not done; +end// +DELIMITER ;// +CALL p1(); +drop procedure p1; +drop table t1; + +# +# Test for bug #14863 "Triggers: crash if create and there is no current +# database". We should not crash and give proper error when database for +# trigger or its table is not specified and there is no current database. +# +connection addconwithoutdb; +--error ER_NO_DB_ERROR +create trigger t1_bi before insert on test.t1 for each row set @a:=0; +--error ER_NO_DB_ERROR +create trigger test.t1_bi before insert on t1 for each row set @a:=0; +--error ER_NO_DB_ERROR +drop trigger t1_bi; +connection default; + +# +# Tests for bug #13525 "Rename table does not keep info of triggers" +# and bug #17866 "Problem with renaming table with triggers with fully +# qualified subject table". +# +create table t1 (id int); +create trigger t1_bi before insert on t1 for each row set @a:=new.id; +create trigger t1_ai after insert on test.t1 for each row set @b:=new.id; +insert into t1 values (101); +select @a, @b; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +rename table t1 to t2; +# Trigger should work after rename +insert into t2 values (102); +select @a, @b; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +# Let us check that the same works for simple ALTER TABLE ... RENAME +alter table t2 rename to t3; +insert into t3 values (103); +select @a, @b; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +# And for more complex ALTER TABLE +alter table t3 rename to t4, add column val int default 0; +insert into t4 values (104, 1); +select @a, @b; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +# .TRN file should be updated with new table name +drop trigger t1_bi; +drop trigger t1_ai; +drop table t4; +# Rename between different databases if triggers exist should fail +create database mysqltest; +use mysqltest; +create table t1 (id int); +create trigger t1_bi before insert on t1 for each row set @a:=new.id; +insert into t1 values (101); +select @a; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test' or event_object_schema = 'mysqltest'; +--error ER_TRG_IN_WRONG_SCHEMA +rename table t1 to test.t2; +insert into t1 values (102); +select @a; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test' or event_object_schema = 'mysqltest'; +# There should be no fantom .TRN files +--error ER_TRG_DOES_NOT_EXIST +drop trigger test.t1_bi; +# Let us also check handling of this restriction in ALTER TABLE ... RENAME +--error ER_TRG_IN_WRONG_SCHEMA +alter table t1 rename to test.t1; +insert into t1 values (103); +select @a; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test' or event_object_schema = 'mysqltest'; +# Again there should be no fantom .TRN files +--error ER_TRG_DOES_NOT_EXIST +drop trigger test.t1_bi; +--error ER_TRG_IN_WRONG_SCHEMA +alter table t1 rename to test.t1, add column val int default 0; +insert into t1 values (104); +select @a; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test' or event_object_schema = 'mysqltest'; +# Table definition should not change +show create table t1; +# And once again check for fantom .TRN files +--error ER_TRG_DOES_NOT_EXIST +drop trigger test.t1_bi; +drop trigger t1_bi; +drop table t1; +drop database mysqltest; +use test; +# And now let us check that the properly handle rename if there is some +# error during it (that we rollback such renames completely). +create table t1 (id int); +create trigger t1_bi before insert on t1 for each row set @a:=new.id; +create trigger t1_ai after insert on t1 for each row set @b:=new.id; +insert into t1 values (101); +select @a, @b; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +# Trick which makes update of second .TRN file impossible +system echo dummy >$MYSQLTEST_VARDIR/master-data/test/t1_ai.TRN~; +system chmod 000 $MYSQLTEST_VARDIR/master-data/test/t1_ai.TRN~; +--error 1 +rename table t1 to t2; +# 't1' should be still there and triggers should work correctly +insert into t1 values (102); +select @a, @b; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +system chmod 600 $MYSQLTEST_VARDIR/master-data/test/t1_ai.TRN~; +system rm $MYSQLTEST_VARDIR/master-data/test/t1_ai.TRN~; +# Let us check that updates to .TRN files were rolled back too +drop trigger t1_bi; +drop trigger t1_ai; +drop table t1; + +# Test for bug #16829 "Firing trigger with RETURN crashes the server" +# RETURN is not supposed to be used anywhere except functions, so error +# should be returned when one attempts to create trigger with RETURN. +create table t1 (i int); +--error ER_SP_BADRETURN +create trigger t1_bi before insert on t1 for each row return 0; +insert into t1 values (1); +drop table t1; + +# Test for bug #17764 "Trigger crashes MyISAM table" +# +# Table was reported as crashed when it was subject table of trigger invoked +# by insert statement which was executed with enabled bulk insert mode (which +# is actually set of optimizations enabled by handler::start_bulk_insert()) +# and this trigger also explicitly referenced it. +# The same problem arose when table to which bulk insert was done was also +# referenced in function called by insert statement. +create table t1 (a varchar(64), b int); +create table t2 like t1; +create trigger t1_ai after insert on t1 for each row + set @a:= (select max(a) from t1); +insert into t1 (a) values + ("Twas"),("brillig"),("and"),("the"),("slithy"),("toves"), + ("Did"),("gyre"),("and"),("gimble"),("in"),("the"),("wabe"); +create trigger t2_ai after insert on t2 for each row + set @a:= (select max(a) from t2); +insert into t2 select * from t1; +load data infile '../std_data_ln/words.dat' into table t1 (a); +drop trigger t1_ai; +drop trigger t2_ai; +# Test that the problem for functions is fixed as well +create function f1() returns int return (select max(b) from t1); +insert into t1 values + ("All",f1()),("mimsy",f1()),("were",f1()),("the",f1()),("borogoves",f1()), + ("And",f1()),("the",f1()),("mome", f1()),("raths",f1()),("outgrabe",f1()); +create function f2() returns int return (select max(b) from t2); +insert into t2 select a, f2() from t1; +load data infile '../std_data_ln/words.dat' into table t1 (a) set b:= f1(); +drop table t1, t2; +drop function f1; +drop function f2; + +# +# Test for bug #16021 "Wrong index given to function in trigger" which +# was caused by the same bulk insert optimization as bug #17764 but had +# slightly different symptoms (instead of reporting table as crashed +# storage engine reported error number 124) +# +create table t1(i int not null, j int not null, n numeric(15,2), primary key(i,j)); +create table t2(i int not null, n numeric(15,2), primary key(i)); +delimiter |; +create trigger t1_ai after insert on t1 for each row +begin + declare sn numeric(15,2); + select sum(n) into sn from t1 where i=new.i; + replace into t2 values(new.i, sn); +end| +delimiter ;| +insert into t1 values + (1,1,10.00),(1,2,10.00),(1,3,10.00),(1,4,10.00),(1,5,10.00), + (1,6,10.00),(1,7,10.00),(1,8,10.00),(1,9,10.00),(1,10,10.00), + (1,11,10.00),(1,12,10.00),(1,13,10.00),(1,14,10.00),(1,15,10.00); +select * from t1; +select * from t2; +drop tables t1, t2; + +# +# Test for Bug #16461 connection_id() does not work properly inside trigger +# +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 ( + conn_id INT, + trigger_conn_id INT +); +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + SET NEW.trigger_conn_id = CONNECTION_ID(); + +INSERT INTO t1 (conn_id, trigger_conn_id) VALUES (CONNECTION_ID(), -1); + +connect (con1,localhost,root,,); +INSERT INTO t1 (conn_id, trigger_conn_id) VALUES (CONNECTION_ID(), -1); +connection default; +disconnect con1; + +SELECT * FROM t1 WHERE conn_id != trigger_conn_id; + +DROP TRIGGER t1_bi; +DROP TABLE t1; + + +# +# Bug#6951: Triggers/Traditional: SET @ result wrong +# +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (i1 INT); + +SET @save_sql_mode=@@sql_mode; + +SET SQL_MODE=''; + +CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW + SET @x = 5/0; + +SET SQL_MODE='traditional'; + +CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW + SET @x = 5/0; + +SET @x=1; +INSERT INTO t1 VALUES (@x); +SELECT @x; + +SET @x=2; +UPDATE t1 SET i1 = @x; +SELECT @x; + +SET SQL_MODE=''; + +SET @x=3; +INSERT INTO t1 VALUES (@x); +SELECT @x; + +SET @x=4; +UPDATE t1 SET i1 = @x; +SELECT @x; + +SET @@sql_mode=@save_sql_mode; + +DROP TRIGGER t1_ai; +DROP TRIGGER t1_au; +DROP TABLE t1; + + +# +# Test for bug #14635 Accept NEW.x as INOUT parameters to stored +# procedures from within triggers +# +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +--enable_warnings + +CREATE TABLE t1 (i1 INT); + +# Check that NEW.x pseudo variable is accepted as INOUT and OUT +# parameter to stored routine. +INSERT INTO t1 VALUES (3); +CREATE PROCEDURE p1(OUT i1 INT) DETERMINISTIC NO SQL SET i1 = 5; +CREATE PROCEDURE p2(INOUT i1 INT) DETERMINISTIC NO SQL SET i1 = i1 * 7; +delimiter //; +CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW +BEGIN + CALL p1(NEW.i1); + CALL p2(NEW.i1); +END// +delimiter ;// +UPDATE t1 SET i1 = 11 WHERE i1 = 3; +DROP TRIGGER t1_bu; +DROP PROCEDURE p2; +DROP PROCEDURE p1; + +# Check that OLD.x pseudo variable is not accepted as INOUT and OUT +# parameter to stored routine. +INSERT INTO t1 VALUES (13); +CREATE PROCEDURE p1(OUT i1 INT) DETERMINISTIC NO SQL SET @a = 17; +CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW + CALL p1(OLD.i1); +--error ER_SP_NOT_VAR_ARG +UPDATE t1 SET i1 = 19 WHERE i1 = 13; +DROP TRIGGER t1_bu; +DROP PROCEDURE p1; + +INSERT INTO t1 VALUES (23); +CREATE PROCEDURE p1(INOUT i1 INT) DETERMINISTIC NO SQL SET @a = i1 * 29; +CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW + CALL p1(OLD.i1); +--error ER_SP_NOT_VAR_ARG +UPDATE t1 SET i1 = 31 WHERE i1 = 23; +DROP TRIGGER t1_bu; +DROP PROCEDURE p1; + +# Check that NEW.x pseudo variable is read-only in the AFTER TRIGGER. +INSERT INTO t1 VALUES (37); +CREATE PROCEDURE p1(OUT i1 INT) DETERMINISTIC NO SQL SET @a = 41; +CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW + CALL p1(NEW.i1); +--error ER_SP_NOT_VAR_ARG +UPDATE t1 SET i1 = 43 WHERE i1 = 37; +DROP TRIGGER t1_au; +DROP PROCEDURE p1; + +INSERT INTO t1 VALUES (47); +CREATE PROCEDURE p1(INOUT i1 INT) DETERMINISTIC NO SQL SET @a = i1 * 49; +CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW + CALL p1(NEW.i1); +--error ER_SP_NOT_VAR_ARG +UPDATE t1 SET i1 = 51 WHERE i1 = 47; +DROP TRIGGER t1_au; +DROP PROCEDURE p1; + +# Post requisite. +SELECT * FROM t1; + +DROP TABLE t1; + +# +# Bug #18005: Creating a trigger on mysql.event leads to server crash on +# scheduler startup +# +# Bug #18361: Triggers on mysql.user table cause server crash +# +# We don't allow triggers on the mysql schema +delimiter |; +--error ER_NO_TRIGGERS_ON_SYSTEM_SCHEMA +create trigger wont_work after update on mysql.user for each row +begin + set @a:= 1; +end| +# Try when we're already using the mysql schema +use mysql| +--error ER_NO_TRIGGERS_ON_SYSTEM_SCHEMA +create trigger wont_work after update on event for each row +begin + set @a:= 1; +end| +use test| +delimiter ;| + + +# +# Test for BUG#16899: Possible buffer overflow in handling of DEFINER-clause. +# + +# Prepare. + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +--enable_warnings + +CREATE TABLE t1(c INT); +CREATE TABLE t2(c INT); + +--error ER_WRONG_STRING_LENGTH +CREATE DEFINER=1234567890abcdefGHIKL@localhost + TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a = 1; + +--error ER_WRONG_STRING_LENGTH +CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY + TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW SET @a = 2; + +# Cleanup. + +DROP TABLE t1; +DROP TABLE t2; + +# +# Bug#20028 Function with select return no data +# + +--disable_warnings +drop table if exists t1; +drop table if exists t2; +drop table if exists t3; +drop table if exists t4; +--enable_warnings + +SET @save_sql_mode=@@sql_mode; + +delimiter |; +SET sql_mode='TRADITIONAL'| +create table t1 (id int(10) not null primary key, v int(10) )| +create table t2 (id int(10) not null primary key, v int(10) )| +create table t3 (id int(10) not null primary key, v int(10) )| +create table t4 (c int)| + +create trigger t4_bi before insert on t4 for each row set @t4_bi_called:=1| +create trigger t4_bu before update on t4 for each row set @t4_bu_called:=1| + +insert into t1 values(10, 10)| +set @a:=1/0| +select 1/0 from t1| + +create trigger t1_bi before insert on t1 for each row set @a:=1/0| + +insert into t1 values(20, 20)| + +drop trigger t1_bi| +create trigger t1_bi before insert on t1 for each row +begin + insert into t2 values (new.id, new.v); + update t2 set v=v+1 where id= new.id; + replace t3 values (new.id, 0); + update t2, t3 set t2.v=new.v, t3.v=new.v where t2.id=t3.id; + create temporary table t5 select * from t1; + delete from t5; + insert into t5 select * from t1; + insert into t4 values (0); + set @check= (select count(*) from t5); + update t4 set c= @check; + drop temporary table t5; + + set @a:=1/0; +end| + +set @check=0, @t4_bi_called=0, @t4_bu_called=0| +insert into t1 values(30, 30)| +select @check, @t4_bi_called, @t4_bu_called| + +delimiter ;| + +SET @@sql_mode=@save_sql_mode; + +drop table t1; +drop table t2; +drop table t3; +drop table t4; + +# +# Bug#20670 "UPDATE using key and invoking trigger that modifies +# this key does not stop" +# + +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1 (i int, j int key); +insert into t1 values (1,1), (2,2), (3,3); +create trigger t1_bu before update on t1 for each row + set new.j = new.j + 10; +# This should not work indefinitely and should cause +# expected result +update t1 set i= i+ 10 where j > 2; +select * from t1; +drop table t1; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/type_binary.test b/mysql-test/t/type_binary.test new file mode 100644 index 00000000000..1639aff4711 --- /dev/null +++ b/mysql-test/t/type_binary.test @@ -0,0 +1,94 @@ +# check 0x00 padding +create table t1 (s1 binary(3)); +insert into t1 values (0x61), (0x6120), (0x612020); +select hex(s1) from t1; +drop table t1; + +# check that 0x00 is not stripped in val_str +create table t1 (s1 binary(2), s2 varbinary(2)); +insert into t1 values (0x4100,0x4100); +select length(concat('*',s1,'*',s2,'*')) from t1; +delete from t1; +insert into t1 values (0x4120,0x4120); +select length(concat('*',s1,'*',s2,'*')) from t1; +drop table t1; + +# check that trailing 0x00 and 0x20 do matter on comparison +create table t1 (s1 varbinary(20), s2 varbinary(20)); +show create table t1; +insert into t1 values (0x41,0x4100),(0x41,0x4120),(0x4100,0x4120); +select hex(s1), hex(s2) from t1; +select count(*) from t1 where s1 < s2; +drop table t1; + +# check that trailing 0x00 do matter on filesort +create table t1 (s1 varbinary(2), s2 varchar(1)); +insert into t1 values (0x41,'a'), (0x4100,'b'), (0x41,'c'), (0x4100,'d'); +select hex(s1),s2 from t1 order by s1,s2; +drop table t1; + +# check that 0x01 is padded to 0x0100 and thus we get a duplicate value +create table t1 (s1 binary(2) primary key); +insert into t1 values (0x01); +insert into t1 values (0x0120); +--error 1062 +insert into t1 values (0x0100); +select hex(s1) from t1 order by s1; +# check index search +select hex(s1) from t1 where s1=0x01; +select hex(s1) from t1 where s1=0x0120; +select hex(s1) from t1 where s1=0x0100; +select count(distinct s1) from t1; +alter table t1 drop primary key; +# check non-indexed search +select hex(s1) from t1 where s1=0x01; +select hex(s1) from t1 where s1=0x0120; +select hex(s1) from t1 where s1=0x0100; +select count(distinct s1) from t1; +drop table t1; + +# check that 0x01 is not padded, and all three values are unique +create table t1 (s1 varbinary(2) primary key); +insert into t1 values (0x01); +insert into t1 values (0x0120); +insert into t1 values (0x0100); +select hex(s1) from t1 order by s1; +# check index search +select hex(s1) from t1 where s1=0x01; +select hex(s1) from t1 where s1=0x0120; +select hex(s1) from t1 where s1=0x0100; +select count(distinct s1) from t1; +alter table t1 drop primary key; +# check non-indexed search +select hex(s1) from t1 where s1=0x01; +select hex(s1) from t1 where s1=0x0120; +select hex(s1) from t1 where s1=0x0100; +select count(distinct s1) from t1; +drop table t1; + +# check that cast appends trailing zeros +select hex(cast(0x10 as binary(2))); + +# +# Bug #14299: BINARY space truncation should cause warning or error +# +create table t1 (b binary(2), vb varbinary(2)); +insert into t1 values(0x4120, 0x4120); +insert into t1 values(0x412020, 0x412020); +drop table t1; +create table t1 (c char(2), vc varchar(2)); +insert into t1 values(0x4120, 0x4120); +insert into t1 values(0x412020, 0x412020); +drop table t1; + +set @old_sql_mode= @@sql_mode, sql_mode= 'traditional'; +create table t1 (b binary(2), vb varbinary(2)); +insert into t1 values(0x4120, 0x4120); +--error ER_DATA_TOO_LONG +insert into t1 values(0x412020, NULL); +--error ER_DATA_TOO_LONG +insert into t1 values(NULL, 0x412020); +drop table t1; +set @@sql_mode= @old_sql_mode; + +--echo End of 5.0 tests diff --git a/mysql-test/t/type_bit.test b/mysql-test/t/type_bit.test new file mode 100644 index 00000000000..d46ba667665 --- /dev/null +++ b/mysql-test/t/type_bit.test @@ -0,0 +1,264 @@ +# +# testing of the BIT column type +# + +select 0 + b'1'; +select 0 + b'0'; +select 0 + b'000001'; +select 0 + b'000011'; +select 0 + b'000101'; +select 0 + b'000000'; +select 0 + b'10000000'; +select 0 + b'11111111'; +select 0 + b'10000001'; +select 0 + b'1000000000000000'; +select 0 + b'1111111111111111'; +select 0 + b'1000000000000001'; + +--disable_warnings +drop table if exists t1,t2; +--enable_warnings + +--error 1439 +create table t1 (a bit(65)); + +create table t1 (a bit(0)); +show create table t1; +drop table t1; + +create table t1 (a bit(64)); +insert into t1 values +(b'1111111111111111111111111111111111111111111111111111111111111111'), +(b'1000000000000000000000000000000000000000000000000000000000000000'), +(b'0000000000000000000000000000000000000000000000000000000000000001'), +(b'1010101010101010101010101010101010101010101010101010101010101010'), +(b'0101010101010101010101010101010101010101010101010101010101010101'); +select hex(a) from t1; +drop table t1; + +create table t1 (a bit); +insert into t1 values (b'0'), (b'1'), (b'000'), (b'100'), (b'001'); +select hex(a) from t1; +--error 1062 +alter table t1 add unique (a); +drop table t1; + +create table t1 (a bit(2)); +insert into t1 values (b'00'), (b'01'), (b'10'), (b'100'); +select a+0 from t1; +alter table t1 add key (a); +explain select a+0 from t1; +select a+0 from t1; +drop table t1; + +create table t1 (a bit(7), b bit(9), key(a, b)); +insert into t1 values +(94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177), +(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380), +(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36), +(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499), +(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403), +(44, 307), (68, 454), (57, 135); +explain select a+0 from t1; +select a+0 from t1; +explain select b+0 from t1; +select b+0 from t1; +explain select a+0, b+0 from t1; +select a+0, b+0 from t1; +explain select a+0, b+0 from t1 where a > 40 and b > 200 order by 1; +select a+0, b+0 from t1 where a > 40 and b > 200 order by 1; +explain select a+0, b+0 from t1 where a > 40 and a < 70 order by 2; +select a+0, b+0 from t1 where a > 40 and a < 70 order by 2; +set @@max_length_for_sort_data=0; +select a+0, b+0 from t1 where a > 40 and a < 70 order by 2; +select hex(min(a)) from t1; +select hex(min(b)) from t1; +select hex(min(a)), hex(max(a)), hex(min(b)), hex(max(b)) from t1; +drop table t1; + +create table t1 (a int not null, b bit, c bit(9), key(a, b, c)); +insert into t1 values +(4, NULL, 1), (4, 0, 3), (2, 1, 4), (1, 1, 100), (4, 0, 23), (4, 0, 54), +(56, 0, 22), (4, 1, 100), (23, 0, 1), (4, 0, 34); +select a+0, b+0, c+0 from t1; +select hex(min(b)) from t1 where a = 4; +select hex(min(c)) from t1 where a = 4 and b = 0; +select hex(max(b)) from t1; +select a+0, b+0, c+0 from t1 where a = 4 and b = 0 limit 2; +select a+0, b+0, c+0 from t1 where a = 4 and b = 1; +select a+0, b+0, c+0 from t1 where a = 4 and b = 1 and c=100; +select a+0, b+0, c+0 from t1 order by b desc; +select a+0, b+0, c+0 from t1 order by c; +drop table t1; + +create table t1(a bit(2), b bit(2)); +insert into t1 (a) values (0x01), (0x03), (0x02); +update t1 set b= concat(a); +select a+0, b+0 from t1; +drop table t1; + +# Some magic numbers + +create table t1 (a bit(7), key(a)); +insert into t1 values (44), (57); +select a+0 from t1; +drop table t1; + +# +# Test conversion to and from strings +# +create table t1 (a bit(3), b bit(12)); +insert into t1 values (7,(1<<12)-2), (0x01,0x01ff); +select hex(a),hex(b) from t1; +select hex(concat(a)),hex(concat(b)) from t1; +drop table t1; + +# +# Bug #9571: problem with primary key creation +# + +create table t1(a int, b bit not null); +alter table t1 add primary key (a); +drop table t1; + +# +# myisam <-> heap +# + +create table t1 (a bit(19), b bit(5)); +insert into t1 values (1000, 10), (3, 8), (200, 6), (2303, 2), (12345, 4), (1, 0); +select a+0, b+0 from t1; +alter table t1 engine=heap; +select a+0, b+0 from t1; +alter table t1 add key(a, b); +select a+0, b+0 from t1; +alter table t1 engine=myisam; +select a+0, b+0 from t1; +create table t2 engine=heap select * from t1; +select a+0, b+0 from t2; +drop table t1; +create table t1 select * from t2; +select a+0, b+0 from t1; +drop table t1, t2; + +# +# Bug #10179: problem with NULLs and default values +# + +create table t1 (a int, b time, c tinyint, d bool, e char(10), f bit(1), + g bit(1) NOT NULL default 1, h char(1) default 'a'); +insert into t1 set a=1; +select hex(g), h from t1; +drop table t1; + +create table t1 (a int, b time, c tinyint, d bool, e char(10), f bit(1), + g bit(1) NOT NULL default 1); +insert into t1 set a=1; +select hex(g) from t1; +drop table t1; + +create table t1 (a int, b time, c tinyint, d bool, e char(10), f bit(1), + h char(1) default 'a') engine=myisam; +insert into t1 set a=1; +select h from t1; +drop table t1; + +# +# Bug #10539 +# + +create table t1 (a bit(8)) engine=heap; +insert into t1 values ('1111100000'); +select a+0 from t1; +drop table t1; + +# +# Bug #11091: union +# + +create table t1 (a bit(7)); +insert into t1 values (120), (0), (111); +select a+0 from t1 union select a+0 from t1; +select a+0 from t1 union select NULL; +select NULL union select a+0 from t1; +create table t2 select a from t1 union select a from t1; +select a+0 from t2; +show create table t2; +drop table t1, t2; + +# +# Bug #11572: view +# + +create table t1 (id1 int(11), b1 bit(1)); +create table t2 (id2 int(11), b2 bit(1)); +insert into t1 values (1, 1), (2, 0), (3, 1); +insert into t2 values (2, 1), (3, 0), (4, 0); +create algorithm=undefined view v1 as + select b1+0, b2+0 from t1, t2 where id1 = id2 and b1 = 0 + union + select b1+0, b2+0 from t1, t2 where id1 = id2 and b2 = 1; +select * from v1; +drop table t1, t2; +drop view v1; + +# +# Bug #10617: bulk-insert +# + +create table t1(a bit(4)); +insert into t1(a) values (1), (2), (5), (4), (3); +insert into t1 select * from t1; +select a+0 from t1; +drop table t1; + +# +# join +# + +create table t1 (a1 int(11), b1 bit(2)); +create table t2 (a2 int(11), b2 bit(2)); +insert into t1 values (1, 1), (2, 0), (3, 1), (4, 2); +insert into t2 values (2, 1), (3, 0), (4, 1), (5, 2); +select a1, a2, b1+0, b2+0 from t1 join t2 on a1 = a2; +select a1, a2, b1+0, b2+0 from t1 join t2 on a1 = a2 order by a1; +select a1, a2, b1+0, b2+0 from t1 join t2 on b1 = b2; +select sum(a1), b1+0, b2+0 from t1 join t2 on b1 = b2 group by b1 order by 1; +select 1 from t1 join t2 on b1 = b2 group by b1 order by 1; +select b1+0,sum(b1), sum(b2) from t1 join t2 on b1 = b2 group by b1 order by 1; +drop table t1, t2; + +# +# Bug #13601: Wrong field length reported for BIT fields +# +create table t1 (a bit(7)); +insert into t1 values (0x60); +--enable_metadata +select * from t1; +--disable_metadata +drop table t1; + +# +# Bug#15583: BIN()/OCT()/CONV() do not work with BIT values +# +create table bug15583(b BIT(8), n INT); +insert into bug15583 values(128, 128); +insert into bug15583 values(null, null); +insert into bug15583 values(0, 0); +insert into bug15583 values(255, 255); +select hex(b), bin(b), oct(b), hex(n), bin(n), oct(n) from bug15583; +select hex(b)=hex(n) as should_be_onetrue, bin(b)=bin(n) as should_be_onetrue, oct(b)=oct(n) as should_be_onetrue from bug15583; +select hex(b + 0), bin(b + 0), oct(b + 0), hex(n), bin(n), oct(n) from bug15583; +select conv(b, 10, 2), conv(b + 0, 10, 2) from bug15583; +drop table bug15583; + +# +# Bug #22271: data casting may affect data stored in the next column(s?) +# + +create table t1(a bit(1), b smallint unsigned); +insert into t1 (b, a) values ('2', '1'); +select hex(a), b from t1; +drop table t1; + +--echo End of 5.0 tests diff --git a/mysql-test/t/type_bit_innodb.test b/mysql-test/t/type_bit_innodb.test new file mode 100644 index 00000000000..dbca69d67f0 --- /dev/null +++ b/mysql-test/t/type_bit_innodb.test @@ -0,0 +1,147 @@ +--source include/have_innodb.inc +# +# testing of the BIT column type +# + +select 0 + b'1'; +select 0 + b'0'; +select 0 + b'000001'; +select 0 + b'000011'; +select 0 + b'000101'; +select 0 + b'000000'; +select 0 + b'10000000'; +select 0 + b'11111111'; +select 0 + b'10000001'; +select 0 + b'1000000000000000'; +select 0 + b'1111111111111111'; +select 0 + b'1000000000000001'; + +--disable_warnings +drop table if exists t1; +--enable_warnings + +--error 1439 +create table t1 (a bit(65)) engine=innodb; + +create table t1 (a bit(0)) engine=innodb; +show create table t1; +drop table t1; + +create table t1 (a bit(64)) engine=innodb; +insert into t1 values +(b'1111111111111111111111111111111111111111111111111111111111111111'), +(b'1000000000000000000000000000000000000000000000000000000000000000'), +(b'0000000000000000000000000000000000000000000000000000000000000001'), +(b'1010101010101010101010101010101010101010101010101010101010101010'), +(b'0101010101010101010101010101010101010101010101010101010101010101'); +select hex(a) from t1; +drop table t1; + +create table t1 (a bit) engine=innodb; +insert into t1 values (b'0'), (b'1'), (b'000'), (b'100'), (b'001'); +select hex(a) from t1; +--error 1062 +alter table t1 add unique (a); +drop table t1; + +create table t1 (a bit(2)) engine=innodb; +insert into t1 values (b'00'), (b'01'), (b'10'), (b'100'); +select a+0 from t1; +alter table t1 add key (a); +explain select a+0 from t1; +select a+0 from t1; +drop table t1; + +create table t1 (a bit(7), b bit(9), key(a, b)) engine=innodb; +insert into t1 values +(94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177), +(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380), +(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36), +(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499), +(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403), +(44, 307), (68, 454), (57, 135); +explain select a+0 from t1; +select a+0 from t1; +explain select b+0 from t1; +select b+0 from t1; +explain select a+0, b+0 from t1; +select a+0, b+0 from t1; +explain select a+0, b+0 from t1 where a > 40 and b > 200 order by 1; +select a+0, b+0 from t1 where a > 40 and b > 200 order by 1; +explain select a+0, b+0 from t1 where a > 40 and a < 70 order by 2; +select a+0, b+0 from t1 where a > 40 and a < 70 order by 2; +set @@max_length_for_sort_data=0; +select a+0, b+0 from t1 where a > 40 and a < 70 order by 2; +select hex(min(a)) from t1; +select hex(min(b)) from t1; +select hex(min(a)), hex(max(a)), hex(min(b)), hex(max(b)) from t1; +drop table t1; + +create table t1 (a int not null, b bit, c bit(9), key(a, b, c)) engine=innodb; +insert into t1 values +(4, NULL, 1), (4, 0, 3), (2, 1, 4), (1, 1, 100), (4, 0, 23), (4, 0, 54), +(56, 0, 22), (4, 1, 100), (23, 0, 1), (4, 0, 34); +select a+0, b+0, c+0 from t1; +select hex(min(b)) from t1 where a = 4; +select hex(min(c)) from t1 where a = 4 and b = 0; +select hex(max(b)) from t1; +select a+0, b+0, c+0 from t1 where a = 4 and b = 0 limit 2; +select a+0, b+0, c+0 from t1 where a = 4 and b = 1; +select a+0, b+0, c+0 from t1 where a = 4 and b = 1 and c=100; +select a+0, b+0, c+0 from t1 order by b desc; +select a+0, b+0, c+0 from t1 order by c; +drop table t1; + +create table t1(a bit(2), b bit(2)) engine=innodb; +insert into t1 (a) values (0x01), (0x03), (0x02); +update t1 set b= concat(a); +select a+0, b+0 from t1; +drop table t1; + +# Some magic numbers + +create table t1 (a bit(7), key(a)) engine=innodb; +insert into t1 values (44), (57); +select a+0 from t1; +drop table t1; + +# +# Test conversion to and from strings +# +create table t1 (a bit(3), b bit(12)) engine=innodb; +insert into t1 values (7,(1<<12)-2), (0x01,0x01ff); +select hex(a),hex(b) from t1; +select hex(concat(a)),hex(concat(b)) from t1; +drop table t1; + +# +# Bug #9571: problem with primary key creation +# + +create table t1(a int, b bit not null) engine=innodb; +alter table t1 add primary key (a); +drop table t1; + +# +# altering tables +# + +create table t1 (a bit, b bit(10)) engine=innodb; +show create table t1; +alter table t1 engine=heap; +show create table t1; +alter table t1 engine=innodb; +show create table t1; +drop table t1; + +# +# Bug #13601: Wrong field length reported for BIT fields +# +create table t1 (a bit(7)) engine=innodb; +insert into t1 values (0x60); +--enable_metadata +select * from t1; +--disable_metadata +drop table t1; + +--echo End of 5.0 tests diff --git a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test index 2c3f4e5efce..6d79dcc863b 100644 --- a/mysql-test/t/type_blob.test +++ b/mysql-test/t/type_blob.test @@ -17,13 +17,13 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7; CREATE TABLE t1 (a blob, b text, c blob(250), d text(70000), e text(70000000)); show columns from t1; # PS doesn't give errors on prepare yet ---disable_ps_protocol -CREATE TABLE t2 (a char(257), b varbinary(70000), c varchar(70000000)); ---enable_ps_protocol +CREATE TABLE t2 (a char(255), b varbinary(70000), c varchar(70000000)); +CREATE TABLE t4 (c varchar(65530) character set utf8 not null); show columns from t2; create table t3 (a long, b long byte); show create TABLE t3; -drop table t1,t2,t3; +show create TABLE t4; +drop table t1,t2,t3,t4; # # Check errors with blob @@ -31,6 +31,10 @@ drop table t1,t2,t3; --error 1074 CREATE TABLE t1 (a char(257) default "hello"); +--error 1074 +CREATE TABLE t2 (a char(256)); +--error 1074 +CREATE TABLE t1 (a varchar(70000) default "hello"); --error 1101 CREATE TABLE t2 (a blob default "hello"); @@ -63,9 +67,9 @@ select * from t1; drop table t1; # -# test of blob, text, char and char binary +# test of blob, text, char and varbinary # -create table t1 (t text,c char(10),b blob, d binary(10)); +create table t1 (t text,c char(10),b blob, d varbinary(10)); insert into t1 values (NULL,NULL,NULL,NULL); insert into t1 values ("","","",""); insert into t1 values ("hello","hello","hello","hello"); @@ -300,7 +304,7 @@ drop table t1; # Bug when blob is updated # -create table t1 (id integer auto_increment unique,imagem LONGBLOB not null); +create table t1 (id integer auto_increment unique,imagem LONGBLOB not null default ''); insert into t1 (id) values (1); # We have to clean up the path in the results for safe comparison --replace_result $MYSQL_TEST_DIR ../.. @@ -326,10 +330,16 @@ drop table t1; # # Test blob's with end space (Bug #1651) +# This is a bit changed since we now have true varchar # create table t1 (id integer primary key auto_increment, txt text not null, unique index txt_index (txt (20))); +--error 1062 insert into t1 (txt) values ('Chevy'), ('Chevy '); +--error 1062 +insert into t1 (txt) values ('Chevy'), ('CHEVY'); +alter table t1 drop index txt_index, add index txt_index (txt(20)); +insert into t1 (txt) values ('Chevy '); select * from t1 where txt='Chevy'; select * from t1 where txt='Chevy '; select * from t1 where txt='Chevy ' or txt='Chevy'; @@ -350,7 +360,7 @@ select * from t1 where txt > 'Chevy'; select * from t1 where txt >= 'Chevy'; drop table t1; -create table t1 (id integer primary key auto_increment, txt text, unique index txt_index (txt (20))); +create table t1 (id integer primary key auto_increment, txt text, index txt_index (txt (20))); insert into t1 (txt) values ('Chevy'), ('Chevy '), (NULL); select * from t1 where txt='Chevy' or txt is NULL; explain select * from t1 where txt='Chevy' or txt is NULL; @@ -385,3 +395,46 @@ select max(i) from t1 where c = ''; drop table t1; # End of 4.1 tests + +# +# Bug#11657: Creation of secondary index fails +# +create table t1 (a int, b int, c tinyblob, d int, e int); +alter table t1 add primary key (a,b,c(255),d); +alter table t1 add key (a,b,d,e); +show create table t1; +drop table t1; + +# +# Test that blob's and varbinary are sorted according to length +# + +CREATE table t1 (a blob); +insert into t1 values ('b'),('a\0'),('a'),('a '),('aa'),(NULL); +select hex(a) from t1 order by a; +select hex(concat(a,'\0')) as b from t1 order by concat(a,'\0'); +alter table t1 modify a varbinary(5); +select hex(a) from t1 order by a; +select hex(concat(a,'\0')) as b from t1 order by concat(a,'\0'); +alter table t1 modify a char(5); +select hex(a) from t1 order by a; +select hex(concat(a,'\0')) as b from t1 order by concat(a,'\0'); +alter table t1 modify a binary(5); +select hex(a) from t1 order by a; +select hex(concat(a,'\0')) as b from t1 order by concat(a,'\0'); +drop table t1; + +# +# Bug #19489: Inconsistent support for DEFAULT in TEXT columns +# +create table t1 (a text default ''); +show create table t1; +insert into t1 values (default); +select * from t1; +drop table t1; +set @@sql_mode='TRADITIONAL'; +--error ER_BLOB_CANT_HAVE_DEFAULT +create table t1 (a text default ''); +set @@sql_mode=''; + +--echo End of 5.0 tests diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index 4b6741b4242..cdf73bf6c89 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -114,3 +114,14 @@ select * from t1; drop table t1; # End of 4.1 tests + +# +# Bug#21475: Wrongly applied constant propagation leads to a false comparison. +# +CREATE TABLE t1(a DATETIME NOT NULL); +INSERT INTO t1 VALUES ('20060606155555'); +SELECT a FROM t1 WHERE a=(SELECT MAX(a) FROM t1) AND (a="20060606155555"); +PREPARE s FROM 'SELECT a FROM t1 WHERE a=(SELECT MAX(a) FROM t1) AND (a="20060606155555")'; +EXECUTE s; +DROP PREPARE s; +DROP TABLE t1; diff --git a/mysql-test/t/type_decimal.test b/mysql-test/t/type_decimal.test index cc5e9278b12..4fdb0c8458f 100644 --- a/mysql-test/t/type_decimal.test +++ b/mysql-test/t/type_decimal.test @@ -1,7 +1,7 @@ # bug in decimal() with negative numbers by kaido@tradenet.ee --disable_warnings -DROP TABLE IF EXISTS t1, t2, t3; +DROP TABLE IF EXISTS t1, t2; --enable_warnings SET SQL_WARNINGS=1; @@ -165,6 +165,8 @@ insert into t1 values ("00000000000001"),("+0000000000001"),("-0000000000001"); insert into t1 values ("+111111111.11"),("111111111.11"),("-11111111.11"); insert into t1 values ("-111111111.11"),("+1111111111.11"),("1111111111.11"); insert into t1 values ("1e+1000"),("1e-1000"),("-1e+1000"); +insert into t1 values ("1e+4294967296"),("1e-4294967296"); +insert into t1 values ("1e+18446744073709551615"),("1e+18446744073709551616"),("1e-9223372036854775807"),("1e-9223372036854775809"); insert into t1 values ("123.4e"),("123.4e+2"),("123.4e-2"),("123e1"),("123e+0"); select * from t1; drop table t1; @@ -201,6 +203,7 @@ insert into t1 values (+111111111.11),(111111111.11),(-11111111.11); insert into t1 values (-111111111.11),(+1111111111.11),(1111111111.11); insert into t1 values (1e+100),(1e-100),(-1e+100); insert into t1 values (123.4e0),(123.4e+2),(123.4e-2),(123e1),(123e+0); +insert into t1 values (MID("987",1,2)),("987 "),("987.6e+2 "); select * from t1; drop table t1; @@ -244,9 +247,8 @@ CREATE TABLE t1 (a_dec DECIMAL(-1,0)); CREATE TABLE t1 (a_dec DECIMAL(-2,1)); --error 1064 CREATE TABLE t1 (a_dec DECIMAL(-1,1)); +--error 1427 CREATE TABLE t1 (a_dec DECIMAL(0,11)); -SHOW CREATE TABLE t1; -DROP TABLE t1; # # Zero prepend overflow bug @@ -276,16 +278,119 @@ update t1 set b=a; select * from t1; drop table t1; +# End of 4.1 tests + # -# Bug #13372 (decimal union) +# Test for BUG#8397: decimal type in subselects (Item_cache_decimal) # -create table t1 (d decimal(10,1)); -create table t2 (d decimal(10,9)); -insert into t1 values ("100000000.0"); -insert into t2 values ("1.23456780"); -create table t3 select * from t2 union select * from t1; -select * from t3; -show create table t3; -drop table t1, t2, t3; +CREATE TABLE t1 +(EMPNUM CHAR(3) NOT NULL, +HOURS DECIMAL(5)); +CREATE TABLE t2 +(EMPNUM CHAR(3) NOT NULL, +HOURS BIGINT); -# End of 4.1 tests +INSERT INTO t1 VALUES ('E1',40); +INSERT INTO t1 VALUES ('E8',NULL); +INSERT INTO t2 VALUES ('E1',40); + +SELECT EMPNUM FROM t1 WHERE HOURS IN (SELECT HOURS FROM t2); +SELECT EMPNUM FROM t1 WHERE HOURS IN (SELECT HOURS FROM t1); + +DROP TABLE t1,t2; + +# +# Test limits of decimal +# +create table t1 (d decimal(64,0)); +insert into t1 values (1); +select * from t1; +drop table t1; +create table t1 (d decimal(5)); +show create table t1; +drop table t1; +create table t1 (d decimal); +show create table t1; +drop table t1; +--error 1426 +create table t1 (d decimal(66,0)); + +# +# Test example from manual +# + +CREATE TABLE t1 (i INT, d1 DECIMAL(9,2), d2 DECIMAL(9,2)); +INSERT INTO t1 VALUES (1, 101.40, 21.40), (1, -80.00, 0.00), +(2, 0.00, 0.00), (2, -13.20, 0.00), (2, 59.60, 46.40), +(2, 30.40, 30.40), (3, 37.00, 7.40), (3, -29.60, 0.00), +(4, 60.00, 15.40), (4, -10.60, 0.00), (4, -34.00, 0.00), +(5, 33.00, 0.00), (5, -25.80, 0.00), (5, 0.00, 7.20), +(6, 0.00, 0.00), (6, -51.40, 0.00); + +SELECT i, SUM(d1) AS a, SUM(d2) AS b FROM t1 GROUP BY i HAVING a <> b; +SELECT i, ROUND(SUM(d1), 2) AS a, ROUND(SUM(d2), 2) AS b FROM t1 GROUP BY i +HAVING a <> b; +drop table t1; + +# +# A test case for Bug#4956 "strange result, insert into longtext, parameter +# with numeric value": ensure that conversion is done identically no matter +# where the input data comes from. +# +create table t1 (c1 varchar(100), c2 longtext); +insert into t1 set c1= 'non PS, 1.0 as constant', c2=1.0; +prepare stmt from "insert into t1 set c1='PS, 1.0 as constant ', c2=1.0"; +execute stmt; +set @a=1.0; +insert into t1 set c1='non PS, 1.0 in parameter', c2=@a; +prepare stmt from "insert into t1 set c1='PS, 1.0 in parameter ', c2=?"; +execute stmt using @a; +select * from t1; +deallocate prepare stmt; +drop table t1; + +# +# A test case for Bug#5673 "Rounding problem in 4.0.21 inserting decimal +# value into a char field": this is a regression bug in 4.0 tree caused by +# a fix for some other decimal conversion issue. The patch never was +# approved to get into 4.0 (maybe because it was considered too intrusive) +# + +create table t1 ( + strippedproductid char(15) not null default '', + zlevelprice decimal(10,2) default null, + primary key (strippedproductid) +); + +create table t2 ( + productid char(15) not null default '', + zlevelprice char(21) default null, + primary key (productid) +); + +insert into t1 values ('002trans','49.99'); +insert into t1 values ('003trans','39.98'); +insert into t1 values ('004trans','31.18'); + +insert INTO t2 SELECT * FROM t1; + +select * from t2; +drop table t1, t2; + +# +# Bug #17826 'type_decimal' fails with ps-protocol +# +create table t1 (f1 decimal(5)); +insert into t1 values (40); +flush tables; +select f1 from t1 where f1 in (select f1 from t1); +drop table t1; + +# +# Bug#22183: Unhandled NULL caused server crash +# +create table t1 as + select from_days(s) as date,t + from (select 1 as s,'t' as t union select null, null ) as sub1; +select group_concat(t) from t1 group by week(date)/10; +drop table t1; diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test index 8a484f7bcd0..965826629bd 100644 --- a/mysql-test/t/type_float.test +++ b/mysql-test/t/type_float.test @@ -6,9 +6,7 @@ drop table if exists t1,t2; --enable_warnings ---replace_result e-0 e- e+0 e+ SELECT 10,10.0,10.,.1e+2,100.0e-1; ---replace_result e-00 e-0 SELECT 6e-05, -6e-05, --6e-05, -6e-05+1.000000; SELECT 1e1,1.e1,1.0e1,1e+1,1.e+1,1.0e+1,1e-1,1.e-1,1.0e-1; SELECT 0.001e+1,0.001e-1, -0.001e+01,-0.001e-01; @@ -21,7 +19,6 @@ create table t1 (f1 float(24),f2 float(52)); show full columns from t1; insert into t1 values(10,10),(1e+5,1e+5),(1234567890,1234567890),(1e+10,1e+10),(1e+15,1e+15),(1e+20,1e+20),(1e+50,1e+50),(1e+150,1e+150); insert into t1 values(-10,-10),(1e-5,1e-5),(1e-10,1e-10),(1e-15,1e-15),(1e-20,1e-20),(1e-50,1e-50),(1e-150,1e-150); ---replace_result e-0 e- e+0 e+ select * from t1; drop table t1; @@ -67,7 +64,7 @@ drop table t1; # FLOAT/DOUBLE/DECIMAL handling # -create table t1 (f float, f2 float(24), f3 float(6,2), d double, d2 float(53), d3 double(10,3), de decimal, de2 decimal(6), de3 decimal(5,2), n numeric, n2 numeric(8), n3 numeric(5,6)); +create table t1 (f float, f2 float(24), f3 float(6,2), d double, d2 float(53), d3 double(10,3), de decimal, de2 decimal(6), de3 decimal(5,2), n numeric, n2 numeric(8), n3 numeric(7,6)); # We mask out Privileges column because it differs for embedded server --replace_column 8 # show full columns from t1; @@ -79,11 +76,8 @@ select a from t1 order by a; select min(a) from t1; drop table t1; +--error 1425 create table t1 (a float(200,100), b double(200,100)); -insert t1 values (1.0, 2.0); -select * from t1; -show create table t1; -drop table t1; # # float in a char(1) field @@ -122,10 +116,15 @@ drop table if exists t1; # Check conversion of floats to character field (Bug #7774) create table t1 (c char(20)); insert into t1 values (5e-28); +# Expected result is "5e-28", but windows returns "5e-028" +--replace_result 5e-028 5e-28 select * from t1; drop table t1; create table t1 (c char(6)); insert into t1 values (2e5),(2e6),(2e-4),(2e-5); +# Expected result is "2e+06", but windows returns "2e+006" +# Expected result is "2e-05", but windows returns "2e-005" +--replace_result 2e+006 2e+06 2e-005 2e-05 select * from t1; drop table t1; @@ -189,3 +188,12 @@ select 1e-308, 1.00000001e-300, 100000000e-300; select 10e307; --echo End of 4.1 tests + +# +# bug #12694 (float(m,d) specifications) +# + +--error 1427 +create table t1 (s1 float(0,2)); +--error 1427 +create table t1 (s1 float(1,2)); diff --git a/mysql-test/t/type_newdecimal-big.test b/mysql-test/t/type_newdecimal-big.test new file mode 100644 index 00000000000..9a1104e4fe6 --- /dev/null +++ b/mysql-test/t/type_newdecimal-big.test @@ -0,0 +1,50 @@ +--source include/big_test.inc + +--disable_warnings +drop procedure if exists sp1; +--enable_warnings + +# +#-- 2. Adding (one millionth) one million times should be the same as +#-- adding 1. So a stored procedure with many iterations will show if +#-- small errors accumulate. +# + +delimiter //; +# +CREATE PROCEDURE sp1() +BEGIN + DECLARE v1, v2, v3, v4 DECIMAL(28,12); + DECLARE v3_2, v4_2 DECIMAL(28, 12); + DECLARE counter INT; + + SET v1 = 1; + SET v2 = 2; + SET v3 = 1000000000000; + SET v4 = 2000000000000; + SET counter = 0; + + WHILE counter < 100000 DO + SET v1 = v1 + 0.000000000001; + SET v2 = v2 - 0.000000000001; + SET v3 = v3 + 1; + SET v4 = v4 - 1; + SET counter = counter + 1; + END WHILE; + + SET v3_2 = v3 * 0.000000000001; + SET v4_2 = v4 * 0.000000000001; + + SELECT v1, v2, v3, v3_2, v4, v4_2; +END// +# +call sp1()// +#-- should return +# -- v1=1.0000001 +# -- v2=1.999999900000 +# -- v3=1.0000001 +# -- v4=1.999999900000 +# +delimiter ;// +# +drop procedure sp1; diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test new file mode 100644 index 00000000000..e4843c3b83e --- /dev/null +++ b/mysql-test/t/type_newdecimal.test @@ -0,0 +1,1110 @@ +--disable_warnings +drop table if exists t1; +--enable_warnings +# +# constant IN function test +# +select 1.1 IN (1.0, 1.2); +select 1.1 IN (1.0, 1.2, 1.1, 1.4, 0.5); +select 1.1 IN (1.0, 1.2, NULL, 1.4, 0.5); +select 0.5 IN (1.0, 1.2, NULL, 1.4, 0.5); +select 1 IN (1.11, 1.2, 1.1, 1.4, 1, 0.5); +select 1 IN (1.11, 1.2, 1.1, 1.4, NULL, 0.5); + +# +# case function test +# +select case 1.0 when 0.1 then "a" when 1.0 then "b" else "c" END; +select case 0.1 when 0.1 then "a" when 1.0 then "b" else "c" END; +select case 1 when 0.1 then "a" when 1.0 then "b" else "c" END; +select case 1.0 when 0.1 then "a" when 1 then "b" else "c" END; +select case 1.001 when 0.1 then "a" when 1 then "b" else "c" END; + +# +# non constant IN test +# +create table t1 (a decimal(6,3)); +insert into t1 values (1.0), (NULL), (0.1); +select * from t1; +select 0.1 in (1.0, 1.2, 1.1, a, 1.4, 0.5) from t1; +drop table t1; + +# +# if function test +# +create table t1 select if(1, 1.1, 1.2), if(0, 1.1, 1.2), if(0.1, 1.1, 1.2), if(0, 1, 1.1), if(0, NULL, 1.2), if(1, 0.22e1, 1.1), if(1E0, 1.1, 1.2); +select * from t1; +show create table t1; +drop table t1; + +# +# NULLIF +# +create table t1 select nullif(1.1, 1.1), nullif(1.1, 1.2), nullif(1.1, 0.11e1), nullif(1.0, 1), nullif(1, 1.0), nullif(1, 1.1); +select * from t1; +show create table t1; +drop table t1; + +# +# saving in decimal field with overflow +# + +create table t1 (a decimal(4,2)); +insert into t1 value (10000), (1.1e10), ("11111"), (100000.1); +insert into t1 value (-10000), (-1.1e10), ("-11111"), (-100000.1); +select a from t1; +drop table t1; +create table t1 (a decimal(4,2) unsigned); +insert into t1 value (10000), (1.1e10), ("11111"), (100000.1); +insert into t1 value (-10000), (-1.1e10), ("-11111"), (-100000.1); +select a from t1; +drop table t1; + + +# +# saving in field with overflow from decimal +# +create table t1 (a bigint); +insert into t1 values (18446744073709551615.0); +insert into t1 values (9223372036854775808.0); +insert into t1 values (-18446744073709551615.0); +select * from t1; +drop table t1; +create table t1 (a bigint unsigned); +insert into t1 values (18446744073709551615.0); +insert into t1 values (9223372036854775808.0); +insert into t1 values (9999999999999999999999999.000); +insert into t1 values (-1.0); +select * from t1; +drop table t1; +create table t1 (a tinyint); +insert into t1 values (18446744073709551615.0); +insert into t1 values (9223372036854775808.0); +select * from t1; +drop table t1; + +# +# test that functions create decimal fields +# +create table t1 select round(15.4,-1), truncate(-5678.123451,-3), abs(-1.1), -(-1.1); +show create table t1; +drop table t1; + +# +# Trydy's tests +# +set session sql_mode='traditional'; +select 1e10/0e0; +create table wl1612 (col1 int, col2 decimal(38,10), col3 numeric(38,10)); +insert into wl1612 values(1,12345678901234567890.1234567890,12345678901234567890.1234567890); +select * from wl1612; +insert into wl1612 values(2,01234567890123456789.0123456789,01234567890123456789.0123456789); +select * from wl1612 where col1=2; +insert into wl1612 values(3,1234567890123456789012345678.0123456789,1234567890123456789012345678.0123456789); +select * from wl1612 where col1=3; + +select col1/0 from wl1612; +select col2/0 from wl1612; +select col3/0 from wl1612; + +insert into wl1612 values(5,5000.0005,5000.0005); +insert into wl1612 values(6,5000.0005,5000.0005); +select sum(col2),sum(col3) from wl1612; +#select avg(col2),avg(col3) from wl1612; + +insert into wl1612 values(7,500000.000005,500000.000005); +insert into wl1612 values(8,500000.000005,500000.000005); +select sum(col2),sum(col3) from wl1612 where col1>4; +#select avg(col2),avg(col3) from wl1612 where col1>4; + +#insert into wl1612 (col1,col2) values(9,123456789012345678901234567890); +#insert into wl1612 (col1,col3) values(9,123456789012345678901234567890); + +insert into wl1612 (col1, col2) values(9,1.01234567891); +insert into wl1612 (col1, col2) values(10,1.01234567894); +insert into wl1612 (col1, col2) values(11,1.01234567895); +insert into wl1612 (col1, col2) values(12,1.01234567896); +select col1,col2 from wl1612 where col1>8; + +insert into wl1612 (col1, col3) values(13,1.01234567891); +insert into wl1612 (col1, col3) values(14,1.01234567894); +insert into wl1612 (col1, col3) values(15,1.01234567895); +insert into wl1612 (col1, col3) values(16,1.01234567896); +select col1,col3 from wl1612 where col1>12; + +select col1 from wl1612 where col1>4 and col2=1.01234567891; +#-- should return 0 rows +# +select col1 from wl1612 where col1>4 and col2=1.0123456789; +#-- should return col1 values 9 & 10 +# +select col1 from wl1612 where col1>4 and col2<>1.0123456789; +#-- should return col1 values 5,6,7,8,11,12 +# +select col1 from wl1612 where col1>4 and col2<1.0123456789; +#-- should return 0 rows +# +select col1 from wl1612 where col1>4 and col2<=1.0123456789; +#-- should return col1 values 9 & 10 +# +select col1 from wl1612 where col1>4 and col2>1.0123456789; +#-- should return col1 values 5,6,7,8,11,12 +# +select col1 from wl1612 where col1>4 and col2>=1.0123456789; +#-- should return col1 values 5,6,7,8,910,11,12 +# +#select col1, col2 from wl1612 where col1=11 or col1=12; +select col1 from wl1612 where col1>4 and col2=1.012345679; +#-- should return col1 values 11,12 +# +select col1 from wl1612 where col1>4 and col2<>1.012345679; +#-- should return col1 values 5,6,7,8,9,10 +# +select col1 from wl1612 where col1>4 and col3=1.01234567891; +#-- should return 0 rows +# +select col1 from wl1612 where col1>4 and col3=1.0123456789; +#-- should return col1 values 13,14 +# +select col1 from wl1612 where col1>4 and col3<>1.0123456789; +#-- should return col1 values 5,6,7,8,15,16 +# +select col1 from wl1612 where col1>4 and col3<1.0123456789; +#-- should return 0 rows +# +select col1 from wl1612 where col1>4 and col3<=1.0123456789; +#-- should return col1 values 13,14 +# +select col1 from wl1612 where col1>4 and col3>1.0123456789; +#-- should return col1 values 5,6,7,8,15,16 +# +select col1 from wl1612 where col1>4 and col3>=1.0123456789; +#-- should return col1 values 5,6,7,8,13,14,15,16 +# +select col1 from wl1612 where col1>4 and col3=1.012345679; +#-- should return col1 values 15,16 +# +select col1 from wl1612 where col1>4 and col3<>1.012345679; +#-- should return col1 values 5,6,7,8,13,14 +# +drop table wl1612; +# +select 1/3; +# +select 0.8=0.7+0.1; +#-- should return 1 (true) +# +select 0.7+0.1; +# +create table wl1612_1 (col1 int); +insert into wl1612_1 values(10); +# +select * from wl1612_1 where 0.8=0.7+0.1; +#--should return 1 row (col1=10) +# +select 0.07+0.07 from wl1612_1; +# +select 0.07-0.07 from wl1612_1; +# +select 0.07*0.07 from wl1612_1; +# +select 0.07/0.07 from wl1612_1; +# +drop table wl1612_1; +# +create table wl1612_2 (col1 decimal(10,2), col2 numeric(10,2)); +insert into wl1612_2 values(1,1); +insert into wl1612_2 values(+1,+1); +insert into wl1612_2 values(+01,+01); +insert into wl1612_2 values(+001,+001); +# +select col1,count(*) from wl1612_2 group by col1; +# +select col2,count(*) from wl1612_2 group by col2; +# +drop table wl1612_2; +# +create table wl1612_3 (col1 decimal(10,2), col2 numeric(10,2)); +insert into wl1612_3 values('1','1'); +insert into wl1612_3 values('+1','+1'); +# +insert into wl1612_3 values('+01','+01'); +insert into wl1612_3 values('+001','+001'); +# +select col1,count(*) from wl1612_3 group by col1; +# +select col2,count(*) from wl1612_3 group by col2; +# +drop table wl1612_3; +# +select mod(234,10) ; +#-- should return 4 +# +select mod(234.567,10.555); +#-- should return 2.357 +# +select mod(-234.567,10.555); +#-- should return -2.357 +# +select mod(234.567,-10.555); +#-- should return 2.357 +# +select round(15.1); +#-- should return 15 +# +select round(15.4); +#-- should return 15 +# +select round(15.5); +#-- should return 16 +# +select round(15.6); +#-- should return 16 +# +select round(15.9); +#-- should return 16 +# +select round(-15.1); +#-- should return -15 +# +select round(-15.4); +#-- should return -15 +# +select round(-15.5); +#-- should return -16 +# +select round(-15.6); +#-- should return -16 +# +select round(-15.9); +#-- should return -16 +# +select round(15.1,1); +#-- should return 15.1 +# +select round(15.4,1); +#-- should return 15.4 +# +select round(15.5,1); +#-- should return 15.5 +# +select round(15.6,1); +#-- should return 15.6 +# +select round(15.9,1); +#-- should return 15.9 +# +select round(-15.1,1); +#-- should return -15.1 +# +select round(-15.4,1); +#-- should return -15.4 +# +select round(-15.5,1); +#-- should return -15.5 +# +select round(-15.6,1); +#-- should return -15.6 +# +select round(-15.9,1); +#-- should return -15.9 +# +select round(15.1,0); +#-- should return 15 +# +select round(15.4,0); +#-- should return 15 +# +select round(15.5,0); +#-- should return 16 +# +select round(15.6,0); +#-- should return 16 +# +select round(15.9,0); +#-- should return 16 +# +select round(-15.1,0); +#-- should return -15 +# +select round(-15.4,0); +#-- should return -15 +# +select round(-15.5,0); +#-- should return -16 +# +select round(-15.6,0); +#-- should return -16 +# +select round(-15.9,0); +#-- should return -16 +# +select round(15.1,-1); +#-- should return 20 +# +select round(15.4,-1); +#-- should return 20 +# +select round(15.5,-1); +#-- should return 20 +# +select round(15.6,-1); +#-- should return 20 +# +select round(15.9,-1); +#-- should return 20 +# +select round(-15.1,-1); +#-- should return -20 +# +select round(-15.4,-1); +#-- should return -20 +# +select round(-15.5,-1); +#-- should return -20 +# +select round(-15.6,-1); +#-- should return -20 +# +select round(-15.91,-1); +#-- should return -20 +# +select truncate(5678.123451,0); +#-- should return 5678 +# +select truncate(5678.123451,1); +#-- should return 5678.1 +# +select truncate(5678.123451,2); +#-- should return 5678.12 +# +select truncate(5678.123451,3); +#-- should return 5678.123 +# +select truncate(5678.123451,4); +#-- should return 5678.1234 +# +select truncate(5678.123451,5); +#-- should return 5678.12345 +# +select truncate(5678.123451,6); +#-- should return 5678.123451 +# +select truncate(5678.123451,-1); +#-- should return 5670 +# +select truncate(5678.123451,-2); +#-- should return 5600 +# +select truncate(5678.123451,-3); +#-- should return 5000 +# +select truncate(5678.123451,-4); +#-- should return 0 +# +select truncate(-5678.123451,0); +#-- should return -5678 +# +select truncate(-5678.123451,1); +#-- should return -5678.1 +# +select truncate(-5678.123451,2); +#-- should return -5678.12 +# +select truncate(-5678.123451,3); +#-- should return -5678.123 +# +select truncate(-5678.123451,4); +#-- should return -5678.1234 +# +select truncate(-5678.123451,5); +#-- should return -5678.12345 +# +select truncate(-5678.123451,6); +#-- should return -5678.123451 +# +select truncate(-5678.123451,-1); +#-- should return -5670 +# +select truncate(-5678.123451,-2); +#-- should return -5600 +# +select truncate(-5678.123451,-3); +#-- should return -5000 +# +select truncate(-5678.123451,-4); +#-- should return 0 +# +#drop table if exists wl1612_4; +create table wl1612_4 (col1 int, col2 decimal(30,25), col3 numeric(30,25)); +# +insert into wl1612_4 values(1,0.0123456789012345678912345,0.0123456789012345678912345); +# +select col2/9999999999 from wl1612_4 where col1=1; +# +select col3/9999999999 from wl1612_4 where col1=1; +# +select 9999999999/col2 from wl1612_4 where col1=1; +# +select 9999999999/col3 from wl1612_4 where col1=1; +# +select col2*9999999999 from wl1612_4 where col1=1; +# +select col3*9999999999 from wl1612_4 where col1=1; +# +insert into wl1612_4 values(2,55555.0123456789012345678912345,55555.0123456789012345678912345); +# +select col2/9999999999 from wl1612_4 where col1=2; +# +select col3/9999999999 from wl1612_4 where col1=2; +# +select 9999999999/col2 from wl1612_4 where col1=2; +# +select 9999999999/col3 from wl1612_4 where col1=2; +# +select col2*9999999999 from wl1612_4 where col1=2; +# +select col3*9999999999 from wl1612_4 where col1=2; +# +drop table wl1612_4; +# +# +# +# +#-- Additional tests for WL#1612 Precision math +# +#-- Comparisons should show that a number is +#-- exactly equal to its value as displayed. +# +set sql_mode=''; +# +select 23.4 + (-41.7), 23.4 - (41.7) = -18.3; +# +select -18.3=-18.3; +# +select 18.3=18.3; +# +select -18.3=18.3; +# +select 0.8 = 0.7 + 0.1; + +# +#-- It should be possible to define a column +#-- with up to 38 digits precision either before +#-- or after the decimal point. Any number which +#-- is inserted, if it's within the range, should +#-- be exactly the same as the number that gets +#-- selected. +# +drop table if exists t1; +# +create table t1 (col1 decimal(38)); +# +insert into t1 values (12345678901234567890123456789012345678); +# +select * from t1; +#-- should return: +#+----------------------------------------+ +#| col1 | +#+----------------------------------------+ +#| 12345678901234567890123456789012345678 | +#+----------------------------------------+ +# +#drop table t1; +# +#create table t1 (col1 decimal(38,38)); +# +#insert into t1 values (.12345678901234567890123456789012345678); +# +#select * from t1; +#-- should return: +#+------------------------------------------+ +#| col1 | +#+------------------------------------------+ +#| 0.12345678901234567890123456789012345678 | +#+------------------------------------------+ +# +drop table t1; +# +create table t1 (col1 decimal(31,30)); +# +insert into t1 values (0.00000000001); +# +select * from t1; +#-- should return: +#+---------------+ +#|col1 | +#+---------------+ +#| 0.00000000001 | +#+---------------+ +# +drop table t1; +# +#-- The usual arithmetic operators / * + - should work. +# +#select 77777777777777777777777777777777777777 / 7777777777777777777777777777777777777 = 10; +#-- should return 0 (false). +# +select 7777777777777777777777777777777777777 * 10; +#-- should return 77777777777777777777777777777777777770 +# +select .7777777777777777777777777777777777777 * + 1000000000000000000; +#-- should return 777777777777777777.7777777777777777777 +# +select .7777777777777777777777777777777777777 - 0.1; +#-- should return .6777777777777777777777777777777777777 +# +select .343434343434343434 + .343434343434343434; +#-- should return .686868686868686868 +# +#-- 5. All arithmetic functions mentioned in the +#MySQL Reference Manual should work. +# +select abs(9999999999999999999999); +#-- should return 9999999999999999999999 +# +select abs(-9999999999999999999999); +#-- should return 9999999999999999999999 +# +select ceiling(999999999999999999); +select ceiling(99999999999999999999); +#-- should return 99999999999999999999 +# +select ceiling(9.9999999999999999999); +#-- should return 10 +# +select ceiling(-9.9999999999999999999); +#-- should return 9 +# +select floor(999999999999999999); +select floor(9999999999999999999999); +#-- should return 9999999999999999999999 +# +select floor(9.999999999999999999999); +#-- should return 9 +# +select floor(-9.999999999999999999999); +#-- should return -10 +# +select floor(-999999999999999999999.999); +select ceiling(999999999999999999999.999); +# +# +select 99999999999999999999999999999999999999 mod 3; +#-- should return 0 +# +select round(99999999999999999.999); +#-- should return 100000000000000000 +# +select round(-99999999999999999.999); +#-- should return -100000000000000000 +# +select round(99999999999999999.999,3); +#-- should return 100000000000000000.000 +# +select round(-99999999999999999.999,3); +#-- should return -100000000000000000.000 +# +select truncate(99999999999999999999999999999999999999,31); +#-- should return 99999999999999999999999999999999999999.000 +# +select truncate(99.999999999999999999999999999999999999,31); +#-- should return 99.9999999999999999999999999999999 +# +select truncate(99999999999999999999999999999999999999,-31); +-- should return 90000000000000000000000000000000 +# +#-- 6. Set functions (AVG, SUM, COUNT) should work. +# +#drop table if exists t1; +# +#delimiter // +# +#create procedure p1 () begin +# declare v1 int default 1; declare v2 decimal(0,38) default 0; +# create table t1 (col1 decimal(0,38)); +# while v1 <= 10000 do +# insert into t1 values (-v2); +# set v2 = v2 + 0.00000000000000000000000000000000000001; +# set v1 = v1 + 1; +# end while; +# select avg(col1),sum(col1),count(col1) from t1; end;// +# +#call p1()// +#-- should return +# -- avg(col1)=0.00000000000000000000000000000000000001 added 10,000 times, then divided by 10,000 +# -- sum(col1)=0.00000000000000000000000000000000000001 added 10,000 times +# +# -- count(col1)=10000 +# +#delimiter ;// +# +#drop procedure p1; +#drop table t1; +# +#-- When I say DECIMAL(x) I should be able to store x digits. +#-- If I can't, there should be an error at CREATE time. +# +#drop table if exists t1; +# +#create table t1 (col1 decimal(254)); +#-- should return SQLSTATE 22003 numeric value out of range +# +#-- When I say DECIMAL(x,y) there should be no silent change of precision or +#-- scale. +# +#drop table if exists t1; +# +#create table t1 (col1 decimal(0,38)); +# +#show create table t1; +#-- should return: +#+-------+--------------------------------+ +#| Table | Create Table | +#+-------+--------------------------------+ +#| t9 | CREATE TABLE `t1` ( | +#|`s1` decimal(0,38) default NULL | +#| ) ENGINE=MyISAM DEFAULT CHARSET=latin1 | +#+-------+--------------------------------+ +# +#drop table t1; +# +#-- From WL#1612 "The future" point 2.: +#-- The standard requires that we treat numbers like "0.5" as +#-- DECIMAL or NUMERIC, not as floating-point. +# +#drop table if exists t1; +# +# +create table t1 as select 0.5; +# +show create table t1; +#-- should return: +#+-------+-----------------------------------+ +#| Table | Create Table | +#+-------+-----------------------------------+ +#| t7 | CREATE TABLE `t1` ( | +#| `0.5` decimal(3,1) NOT NULL default '0.0' | +#| ) ENGINE=MyISAM DEFAULT CHARSET=latin1 | +#+-------+-----------------------------------+ +# +drop table t1; +# +#-- From WL#1612, "The future", point 3.: We have to start rounding correctly. +# +select round(1.5),round(2.5); +#-- should return: +#+------------+------------+ +#| round(1.5) | round(2.5) | +#+------------+------------+ +#| 2 | 3 | +#+------------+------------+ +# +#-- From WL#1612, "The future", point 4.: "select 0.07 * 0.07;" should return 0.0049, not 0.00. +#-- If operand#1 has scale X and operand#2 has scale Y, then result should have scale (X+Y). +# +select 0.07 * 0.07; +#-- should return 0.0049 +# +#-- From WL#1612, "The future", point 5.: Division by zero is an error. +# +set sql_mode='traditional'; +# +select 1E-500 = 0; +#-- should return 1 (true). +# +select 1 / 1E-500; +# +#-- should return SQLSTATE 22012 division by zero. +# +select 1 / 0; +#-- should return SQLSTATE 22012 division by zero. +# +#+-------+ +#| 1 / 0 | +#+-------+ +#| NULL | +#+-------+ +#1 row in set, 1 warning (0.00 sec) +# +#-- From WL#1612 "The future" point 6.: Overflow is an error. +# +#set sql_mode=''; +# +#select 1E300 * 1E300; +#-- should return SQLSTATE 22003 numeric value out of range +# +#select 18446744073709551615 + 1; +#-- should return SQLSTATE 22003 numeric value out of range +# +#-- 14. From WL#1612 "The future" point 7.: +#-- If s1 is INTEGER and s2 is DECIMAL, then +#-- "create table tk7 as select avg(s1),avg(s2) from tk;" +#-- should not create a table with "double(17,4)" data types. +#-- The result of AVG must still be exact numeric, with a +#-- scale the same or greater than the operand's scale. +#-- The result of SUM must still be exact numeric, with +#-- a scale the same as the operand's scale. +# +#drop table if exists t1; +#drop table if exists t2; +# +#create table t1 (col1 int, col2 decimal(5)); +# +#create table t2 as select avg(col1),avg(col2) from t1; +# +# +#show create table t2; +#-- should return: +#+-------+---------------------------------+ +#| Table | Create Table | +#+-------+---------------------------------+ +#| t2 | CREATE TABLE `t2` ( | +#| `avg(col1)` decimal(17,4) default NULL, | +#| `avg(col2)` decimal(17,5) default NULL | +#| ) ENGINE=MyISAM DEFAULT CHARSET=latin1 | +#+-------+---------------------------------+ +# +#drop table t2; +#drop table t1; +# +#-- From WL#1612 "The future" point 8.: Stop storing leading "+" signs and +# leading "0"s. +# +#drop table if exists t1; +# +#create table t1 (col1 decimal(5,2),col2 decimal(5) zerofill, col3 decimal(3,1)); +# +#insert into t1 values (1,1,1); +# +#select col1 from t1 union select col2 from t1 union select col3 from t1; +# +#drop table t1; +# +#-- From WL#1612, The future" point 9.: +#-- Accept the data type and precision and scale as the user +#-- asks, or return an error, but don't change to something else. +# +#drop table if exists t1; +# +#create table t1 (col1 numeric(4,2)); +# +#show create table t1; +# +#drop table t1; +# +#-- The scripts in the following bugs should work: +# + +#BUG#559 Maximum precision for DECIMAL column ... +#BUG#1499 INSERT/UPDATE into decimal field rounding problem +#BUG#1845 Not correctly recognising value for decimal field +#BUG#2493 Round function doesn't work correctly +#BUG#2649 round(0.5) gives 0 (should be 1) +#BUG#3612 impicite rounding of VARCHARS during aritchmetic operations... +#BUG#3722 SELECT fails for certain values in Double(255,10) column. +#BUG#4485 Floating point conversions are inconsistent +#BUG#4891 MATH +#BUG#5931 Out-of-range values are accepted +#BUG#6048 Stored procedure causes operating system reboot +#BUG#6053 DOUBLE PRECISION literal + +-- Tests from 'traditional' mode tests +# +set sql_mode='ansi,traditional'; +# +CREATE TABLE Sow6_2f (col1 NUMERIC(4,2)); +#-- should return OK +INSERT INTO Sow6_2f VALUES (10.55); +#-- should return OK +INSERT INTO Sow6_2f VALUES (10.5555); +#-- should return OK +INSERT INTO Sow6_2f VALUES (-10.55); +#-- should return OK +INSERT INTO Sow6_2f VALUES (-10.5555); +#-- should return OK +INSERT INTO Sow6_2f VALUES (11); +#-- should return OK +-- error 1264 +INSERT INTO Sow6_2f VALUES (101.55); +#-- should return SQLSTATE 22003 numeric value out of range +-- error 1264 +UPDATE Sow6_2f SET col1 = col1 * 50 WHERE col1 = 11; +#-- should return SQLSTATE 22003 numeric value out of range +-- error 1365 +UPDATE Sow6_2f SET col1 = col1 / 0 WHERE col1 > 0; +#-- should return SQLSTATE 22012 division by zero +SELECT MOD(col1,0) FROM Sow6_2f; +#-- should return SQLSTATE 22012 division by zero +-- error 1366 +INSERT INTO Sow6_2f VALUES ('a59b'); +#-- should return SQLSTATE 22018 invalid character value for cast +drop table Sow6_2f; + +# +# bug#9501 +# +select 10.3330000000000/12.34500000; + +# +# Bug #10404 +# + +set sql_mode=''; +select 0/0; + +# +# bug #9546 +# +--disable_ps_protocol +select 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 as x; +select 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 + 1 as x; +--enable_ps_protocol +# +# Bug #10004 +# +select 0.190287977636363637 + 0.040372670 * 0 - 0; +# +# Bug #9527 +# +select -0.123 * 0; + +# +# Bug #10232 +# + +CREATE TABLE t1 (f1 DECIMAL (12,9), f2 DECIMAL(2,2)); +INSERT INTO t1 VALUES (10.5, 0); +UPDATE t1 SET f1 = 4.5; +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (f1 DECIMAL (64,20), f2 DECIMAL(2,2)); +INSERT INTO t1 VALUES (9999999999999999999999999999999999, 0); +SELECT * FROM t1; +DROP TABLE t1; + +# +# Bug #10599: problem with NULL +# + +select abs(10/0); +select abs(NULL); + +# +# Bug #9894 (negative to unsigned column) +# +set @@sql_mode='traditional'; +create table t1( d1 decimal(18) unsigned, d2 decimal(20) unsigned, d3 decimal (22) unsigned); +--error 1264 +insert into t1 values(1,-1,-1); +drop table t1; +create table t1 (col1 decimal(5,2), col2 numeric(5,2)); +--error 1264 +insert into t1 values (999.999,999.999); +--error 1264 +insert into t1 values (-999.999,-999.999); +select * from t1; +drop table t1; +set sql_mode=''; + +# +# Bug #8425 (insufficient precision of the division) +# +set @sav_dpi= @@div_precision_increment; +set @@div_precision_increment=15; +create table t1 (col1 int, col2 decimal(30,25), col3 numeric(30,25)); +insert into t1 values (1,0.0123456789012345678912345,0.0123456789012345678912345); +select col2/9999999999 from t1 where col1=1; +select 9999999999/col2 from t1 where col1=1; +select 77777777/7777777; +drop table t1; +set div_precision_increment= @sav_dpi; + +# +# Bug #10896 (0.00 > -0.00) +# +create table t1 (a decimal(4,2)); +insert into t1 values (0.00); +select * from t1 where a > -0.00; +select * from t1 where a = -0.00; +drop table t1; + +# +# Bug #11215: a problem with LONGLONG_MIN +# + +create table t1 (col1 bigint default -9223372036854775808); +insert into t1 values (default); +select * from t1; +drop table t1; + +# +# Bug #10891 (converting to decimal crashes server) +# +select cast('1.00000001335143196001808973960578441619873046875E-10' as decimal(30,15)); + +# +# Bug #11708 (conversion to decimal fails in decimal part) +# +select ln(14000) c1, convert(ln(14000),decimal(5,3)) c2, cast(ln(14000) as decimal(5,3)) c3; +--error 1427 +select convert(ln(14000),decimal(2,3)) c1; +--error 1427 +select cast(ln(14000) as decimal(2,3)) c1; + +# +# Bug #8449 (Silent column changes) +# +--error 1426 +create table t1 (sl decimal(70,30)); +--error 1425 +create table t1 (sl decimal(32,31)); +--error 1425 +create table t1 (sl decimal(0,38)); +--error 1427 +create table t1 (sl decimal(0,30)); +create table t1 (sl decimal(5, 5)); +show create table t1; +drop table t1; +# Test limits +create table t1 (sl decimal(65, 30)); +show create table t1; +drop table t1; + +# +# Bug 11557 (DEFAULT values rounded improperly +# +create table t1 ( + f1 decimal unsigned not null default 17.49, + f2 decimal unsigned not null default 17.68, + f3 decimal unsigned not null default 99.2, + f4 decimal unsigned not null default 99.7, + f5 decimal unsigned not null default 104.49, + f6 decimal unsigned not null default 199.91, + f7 decimal unsigned not null default 999.9, + f8 decimal unsigned not null default 9999.99); +insert into t1 (f1) values (1); +select * from t1; +drop table t1; + +# +# Bug 12173 (show create table fails) +# +create table t1 ( + f0 decimal (30,30) zerofill not null DEFAULT 0, + f1 decimal (0,0) zerofill not null default 0); +show create table t1; +drop table t1; + +# +# Bug 12938 (arithmetic loop's zero) +# +--disable_warnings +drop procedure if exists wg2; +--enable_warnings +delimiter //; +create procedure wg2() +begin + declare v int default 1; + declare tdec decimal(5) default 0; + while v <= 9 do set tdec =tdec * 10; + select v, tdec; + set v = v + 1; + end while; +end// + +call wg2()// + +delimiter ;// +drop procedure wg2; + +# +# Bug #12979 Stored procedures: crash if inout decimal parameter +# (not a SP bug in fact) +# + +select cast(@non_existing_user_var/2 as DECIMAL); + +# +# Bug #13667 (Inconsistency for decimal(m,d) specification +# +--error 1427 +create table t (d decimal(0,10)); + +# +# Bug #14268 (bad FLOAT->DECIMAL conversion) +# + +CREATE TABLE t1 ( + my_float FLOAT, + my_double DOUBLE, + my_varchar VARCHAR(50), + my_decimal DECIMAL(65,30) +); +SHOW CREATE TABLE t1; + +let $max_power= 32; +while ($max_power) +{ + eval INSERT INTO t1 SET my_float = 1.175494345e-$max_power, + my_double = 1.175494345e-$max_power, + my_varchar = '1.175494345e-$max_power'; + dec $max_power; +} +SELECT my_float, my_double, my_varchar FROM t1; + +# Expected result 0.000000000011754943372854760000 +# On windows we get 0.000000000011754943372854770000 +# use replace_result to correct it +--replace_result 0.000000000011754943372854770000 0.000000000011754943372854760000 +SELECT CAST(my_float AS DECIMAL(65,30)), my_float FROM t1; +SELECT CAST(my_double AS DECIMAL(65,30)), my_double FROM t1; +SELECT CAST(my_varchar AS DECIMAL(65,30)), my_varchar FROM t1; + +# We have to disable warnings here as the test in +# Field_new_decimal::store(double): +# if (nr2 != nr) +# fails randomly depending on compiler options + +--disable_warnings +UPDATE t1 SET my_decimal = my_float; + +# Expected result 0.000000000011754943372854760000 +# On windows we get 0.000000000011754943372854770000 +# use replace_result to correct it +--replace_result 0.000000000011754943372854770000 0.000000000011754943372854760000 +SELECT my_decimal, my_float FROM t1; + +UPDATE t1 SET my_decimal = my_double; +SELECT my_decimal, my_double FROM t1; +--enable_warnings +UPDATE t1 SET my_decimal = my_varchar; +SELECT my_decimal, my_varchar FROM t1; + +DROP TABLE t1; + +# +# Bug #13573 (Wrong data inserted for too big values) +# + +create table t1 (c1 decimal(64)); +--disable_ps_protocol +insert into t1 values( +89000000000000000000000000000000000000000000000000000000000000000000000000000000000000000); +insert into t1 values( +99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * +99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999); +--enable_ps_protocol +insert into t1 values(1e100); +select * from t1; +drop table t1; + +# +# Bug#19667 group by a decimal expression yields wrong result +# +create table t1 (i int, j int); +insert into t1 values (1,1), (1,2), (2,3), (2,4); +select i, count(distinct j) from t1 group by i; +select i+0.0 as i2, count(distinct j) from t1 group by i2; +drop table t1; diff --git a/mysql-test/t/type_ranges.test b/mysql-test/t/type_ranges.test index 945d3577046..03ee91f14d8 100644 --- a/mysql-test/t/type_ranges.test +++ b/mysql-test/t/type_ranges.test @@ -28,10 +28,10 @@ CREATE TABLE t1 ( date_time datetime, blob_col blob, tinyblob_col tinyblob, - mediumblob_col mediumblob not null, - longblob_col longblob not null, - options enum('one','two','tree') not null, - flags set('one','two','tree') not null, + mediumblob_col mediumblob not null default '', + longblob_col longblob not null default '', + options enum('one','two','tree') not null , + flags set('one','two','tree') not null default '', PRIMARY KEY (auto), KEY (utiny), KEY (tiny), @@ -71,7 +71,7 @@ ALTER TABLE t1 add new_field char(10) default "new" not null, change blob_col new_blob_col varchar(20), change date_field date_field char(10), -alter column string set default "new default", +alter column string set default "newdefault", alter short drop default, DROP INDEX utiny, DROP INDEX ushort, @@ -132,11 +132,11 @@ select t1.auto,t2.auto from t1,t2 where t1.auto=t2.auto and not (t1.string<=>t2. drop table t2; -create table t2 (primary key (auto)) select auto+1 as auto,1 as t1, "a" as t2, repeat("a",256) as t3, binary repeat("b",256) as t4 from t1; +create table t2 (primary key (auto)) select auto+1 as auto,1 as t1, 'a' as t2, repeat('a',256) as t3, binary repeat('b',256) as t4, repeat('a',4096) as t5, binary repeat('b',4096) as t6, '' as t7, binary '' as t8 from t1; # We mask out the Privileges column because it differs with embedded server --replace_column 8 # show full columns from t2; -select * from t2; +select t1,t2,length(t3),length(t4),length(t5),length(t6),t7,t8 from t2; drop table t1,t2; create table t1 (c int); @@ -158,12 +158,19 @@ create table t2 ( id integer unsigned not null primary key ); insert into t1 values (1), (2); insert into t2 values (1); select t1.id as id_A, t2.id as id_B from t1 left join t2 using ( id ); +select t1.id as id_A, t2.id as id_B from t1 left join t2 on (t1.id = t2.id); create table t3 (id_A integer unsigned not null, id_B integer unsigned null ); insert into t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 using ( id ); select * from t3; +delete from t3; +insert into t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 on (t1.id = t2.id); +select * from t3; drop table t3; create table t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 using ( id ); select * from t3; +drop table t3; +create table t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 on (t1.id = t2.id); +select * from t3; drop table t1,t2,t3; # End of 4.1 tests diff --git a/mysql-test/t/type_timestamp.test b/mysql-test/t/type_timestamp.test index 81c547c32f6..7b4af9e0c69 100644 --- a/mysql-test/t/type_timestamp.test +++ b/mysql-test/t/type_timestamp.test @@ -6,6 +6,9 @@ drop table if exists t1,t2; --enable_warnings +# Set timezone to GMT-3, to make it possible to use "interval 3 hour" +set time_zone="+03:00"; + CREATE TABLE t1 (a int, t timestamp); CREATE TABLE t2 (a int, t datetime); SET TIMESTAMP=1234; @@ -29,6 +32,8 @@ INSERT INTO t1 VALUES ("my value", "myKey","1999-04-02 00:00:00"); SELECT stamp FROM t1 WHERE id="myKey"; UPDATE t1 SET value="my value" WHERE id="myKey"; SELECT stamp FROM t1 WHERE id="myKey"; +UPDATE t1 SET id="myKey" WHERE value="my value"; +SELECT stamp FROM t1 WHERE id="myKey"; drop table t1; create table t1 (a timestamp); @@ -320,3 +325,17 @@ select * from t1; drop table t1; # End of 4.1 tests + +# Restore timezone to default +set time_zone= @@global.time_zone; + +CREATE TABLE t1 ( +`id` int(11) NOT NULL auto_increment, +`username` varchar(80) NOT NULL default '', +`posted_on` timestamp NOT NULL default '0000-00-00 00:00:00', +PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; + +show fields from t1; +select is_nullable from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='t1' and COLUMN_NAME='posted_on'; +drop table t1; diff --git a/mysql-test/t/type_varchar.test b/mysql-test/t/type_varchar.test new file mode 100644 index 00000000000..439e98471b2 --- /dev/null +++ b/mysql-test/t/type_varchar.test @@ -0,0 +1,189 @@ +--disable_warnings +drop table if exists t1, t2; +--enable_warnings + +create table t1 (v varchar(30), c char(3), e enum('abc','def','ghi'), t text); +system cp $MYSQL_TEST_DIR/std_data/vchar.frm $MYSQLTEST_VARDIR/master-data/test/; +truncate table vchar; +show create table t1; +show create table vchar; +insert into t1 values ('abc', 'de', 'ghi', 'jkl'); +insert into t1 values ('abc ', 'de ', 'ghi', 'jkl '); +insert into t1 values ('abc ', 'd ', 'ghi', 'jkl '); +insert into vchar values ('abc', 'de', 'ghi', 'jkl'); +insert into vchar values ('abc ', 'de ', 'ghi', 'jkl '); +insert into vchar values ('abc ', 'd ', 'ghi', 'jkl '); +select length(v),length(c),length(e),length(t) from t1; +select length(v),length(c),length(e),length(t) from vchar; +alter table vchar add i int; +show create table vchar; +select length(v),length(c),length(e),length(t) from vchar; +drop table t1, vchar; +create table t1 (v varchar(20)); +insert into t1 values('a '); +select v='a' from t1; +select binary v='a' from t1; +select binary v='a ' from t1; +insert into t1 values('a'); +--error 1062 +alter table t1 add primary key (v); +drop table t1; +create table t1 (v varbinary(20)); +insert into t1 values('a'); +insert into t1 values('a '); +alter table t1 add primary key (v); +drop table t1; + +# +# Test with varchar of lengths 254,255,256,258 & 258 to ensure we don't +# have any problems with varchar with one or two byte length_bytes +# + +create table t1 (v varchar(254), index (v)); +insert into t1 values ("This is a test "); +insert into t1 values ("Some sample data"); +insert into t1 values (" garbage "); +insert into t1 values (" This is a test "); +insert into t1 values ("This is a test"); +insert into t1 values ("Hello world"); +insert into t1 values ("Foo bar"); +insert into t1 values ("This is a test"); +insert into t1 values ("MySQL varchar test"); +insert into t1 values ("test MySQL varchar"); +insert into t1 values ("This is a long string to have some random length data included"); +insert into t1 values ("Short string"); +insert into t1 values ("VSS"); +insert into t1 values ("Some samples"); +insert into t1 values ("Bar foo"); +insert into t1 values ("Bye"); +let $i= 255; +let $j= 5; +while ($j) +{ + select * from t1 where v like 'This is a test' order by v; + select * from t1 where v='This is a test' order by v; + select * from t1 where v like 'S%' order by v; + explain select * from t1 where v like 'This is a test' order by v; + explain select * from t1 where v='This is a test' order by v; + explain select * from t1 where v like 'S%' order by v; + eval alter table t1 change v v varchar($i); + inc $i; + dec $j; +} +let $i= 258; +let $j= 6; +while ($j) +{ + select * from t1 where v like 'This is a test' order by v; + select * from t1 where v='This is a test' order by v; + select * from t1 where v like 'S%' order by v; + explain select * from t1 where v like 'This is a test' order by v; + explain select * from t1 where v='This is a test' order by v; + explain select * from t1 where v like 'S%' order by v; + eval alter table t1 change v v varchar($i); + dec $i; + dec $j; +} +alter table t1 change v v varchar(254), drop key v; + +# Test with length(varchar) > 256 and key < 256 (to ensure things works with +# different kind of packing + +alter table t1 change v v varchar(300), add key (v(10)); +select * from t1 where v like 'This is a test' order by v; +select * from t1 where v='This is a test' order by v; +select * from t1 where v like 'S%' order by v; +explain select * from t1 where v like 'This is a test' order by v; +explain select * from t1 where v='This is a test' order by v; +explain select * from t1 where v like 'S%' order by v; +drop table t1; + +# +# bug#9339 - meaningless Field_varstring::get_key_image +# +create table t1 (pkcol varchar(16), othercol varchar(16), primary key (pkcol)); +insert into t1 values ('test', 'something'); +update t1 set othercol='somethingelse' where pkcol='test'; +select * from t1; +drop table t1; + +# +# Bug #9489: problems with key handling +# + +create table t1 (a int, b varchar(12)); +insert into t1 values (1, 'A'), (22, NULL); +create table t2 (a int); +insert into t2 values (22), (22); +select t1.a, t1.b, min(t1.b) from t1 inner join t2 ON t2.a = t1.a + group by t1.b, t1.a; +drop table t1, t2; + +# +# Bug #10543: convert varchar with index to text +# +create table t1 (f1 varchar(65500)); +create index index1 on t1(f1(10)); +show create table t1; +alter table t1 modify f1 varchar(255); +show create table t1; +alter table t1 modify f1 tinytext; +show create table t1; +drop table t1; + +# +# BUG#15588: String overrun +# + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1(f1 VARCHAR(100) DEFAULT 'test'); +INSERT INTO t1 VALUES(SUBSTR(f1, 1, 3)); +DROP TABLE IF EXISTS t1; + +CREATE TABLE t1(f1 CHAR(100) DEFAULT 'test'); +INSERT INTO t1 VALUES(SUBSTR(f1, 1, 3)); +DROP TABLE IF EXISTS t1; + +# +# Bug#14897 "ResultSet.getString("table.column") sometimes doesn't find the +# column" +# Test that after upgrading an old 4.1 VARCHAR column to 5.0 VARCHAR we preserve +# the original column metadata. +# +--disable_warnings +drop table if exists t1, t2, t3; +--enable_warnings + +create table t3 ( + id int(11), + en varchar(255) character set utf8, + cz varchar(255) character set utf8 +); +system cp $MYSQL_TEST_DIR/std_data/14897.frm $MYSQLTEST_VARDIR/master-data/test/t3.frm; +truncate table t3; +insert into t3 (id, en, cz) values +(1,'en string 1','cz string 1'), +(2,'en string 2','cz string 2'), +(3,'en string 3','cz string 3'); + +create table t1 ( + id int(11), + name_id int(11) +); +insert into t1 (id, name_id) values (1,1), (2,3), (3,3); + +create table t2 (id int(11)); +insert into t2 (id) values (1), (2), (3); + +# max_length is different for varchar fields in ps-protocol and we can't +# replace a single metadata column, disable PS protocol +--disable_ps_protocol +--enable_metadata +select t1.*, t2.id, t3.en, t3.cz from t1 left join t2 on t1.id=t2.id +left join t3 on t1.id=t3.id order by t3.id; +--disable_metadata +--enable_ps_protocol +drop table t1, t2, t3; diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test new file mode 100644 index 00000000000..96e559f5c05 --- /dev/null +++ b/mysql-test/t/udf.test @@ -0,0 +1,146 @@ +--source include/have_udf.inc +# +# To run this tests the "sql/udf_example.c" need to be compiled into +# udf_example.so and LD_LIBRARY_PATH should be setup to point out where +# the library are. +# + + +--disable_warnings +drop table if exists t1; +--enable_warnings + +# +# Create the example functions from udf_example +# + +--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB +eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_LIB"; +--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB +eval CREATE FUNCTION myfunc_double RETURNS REAL SONAME "$UDF_EXAMPLE_LIB"; + +--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB +--error ER_CANT_FIND_DL_ENTRY +eval CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB"; +--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB +eval CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB"; +--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB +eval CREATE FUNCTION sequence RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB"; +--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB +eval CREATE FUNCTION lookup RETURNS STRING SONAME "$UDF_EXAMPLE_LIB"; +--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB +eval CREATE FUNCTION reverse_lookup + RETURNS STRING SONAME "$UDF_EXAMPLE_LIB"; +--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB +eval CREATE AGGREGATE FUNCTION avgcost + RETURNS REAL SONAME "$UDF_EXAMPLE_LIB"; + +--error 0 +select myfunc_double(); +select myfunc_double(1); +select myfunc_double(78654); +--error 1305 +select myfunc_nonexist(); +select myfunc_int(); +--error 0 +select lookup(); +select lookup("127.0.0.1"); +--error 0 +select lookup(127,0,0,1); +select lookup("localhost"); +--error 0 +select reverse_lookup(); + +# These two functions should return "localhost", but it's +# depending on configuration, so just call them and don't log the result +--disable_result_log +select reverse_lookup("127.0.0.1"); +select reverse_lookup(127,0,0,1); +--enable_result_log + +select reverse_lookup("localhost"); +--error 0 +select avgcost(); +--error 0 +select avgcost(100,23.76); +create table t1(sum int, price float(24)); +insert into t1 values(100, 50.00), (100, 100.00); +select avgcost(sum, price) from t1; +delete from t1; +insert into t1 values(100, 54.33), (200, 199.99); +select avgcost(sum, price) from t1; +drop table t1; + +#------------------------------------------------------------------------ +# BUG#17261 Passing a variable from a stored procedure to UDF crashes mysqld +#------------------------------------------------------------------------ + +select metaphon('hello'); + +delimiter //; +CREATE PROCEDURE `XXX1`(in testval varchar(10)) +begin +select metaphon(testval); +end// +delimiter ;// + +call XXX1('hello'); +drop procedure xxx1; + +delimiter //; +CREATE PROCEDURE `XXX2`() +begin +declare testval varchar(10); +set testval = 'hello'; +select metaphon(testval); +end// +delimiter ;// + +call XXX2(); +drop procedure xxx2; + +# +# Bug#19904: UDF: not initialized *is_null per row +# + +CREATE TABLE bug19904(n INT, v varchar(10)); +INSERT INTO bug19904 VALUES (1,'one'),(2,'two'),(NULL,NULL),(3,'three'),(4,'four'); +SELECT myfunc_double(n) AS f FROM bug19904; +SELECT metaphon(v) AS f FROM bug19904; +DROP TABLE bug19904; + +# +# Bug#21269: DEFINER-clause is allowed for UDF-functions +# + +--error ER_WRONG_USAGE +CREATE DEFINER=CURRENT_USER() FUNCTION should_not_parse +RETURNS STRING SONAME "should_not_parse.so"; + +--error ER_WRONG_USAGE +CREATE DEFINER=someone@somewhere FUNCTION should_not_parse +RETURNS STRING SONAME "should_not_parse.so"; +# +# Bug#19862: Sort with filesort by function evaluates function twice +# +create table t1(f1 int); +insert into t1 values(1),(2); +explain select myfunc_int(f1) from t1 order by 1; +drop table t1; +--echo End of 5.0 tests. + +# +# Drop the example functions from udf_example +# + +DROP FUNCTION metaphon; +DROP FUNCTION myfunc_double; +--error ER_SP_DOES_NOT_EXIST +DROP FUNCTION myfunc_nonexist; +DROP FUNCTION myfunc_int; +DROP FUNCTION sequence; +DROP FUNCTION lookup; +DROP FUNCTION reverse_lookup; +DROP FUNCTION avgcost; + + diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index 994546e9d97..bf5c5e066f0 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -5,9 +5,6 @@ --disable_warnings drop table if exists t1,t2,t3,t4,t5,t6; --enable_warnings -# PS doesn't work correctly with found_rows: to be fixed ---disable_ps_protocol - CREATE TABLE t1 (a int not null, b char (10) not null); insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c'); @@ -258,7 +255,7 @@ create temporary table t1 select a from t1 union select a from t2; drop temporary table t1; --error 1093 create table t1 select a from t1 union select a from t2; ---error 1109 +--error 1054 select a from t1 union select a from t2 order by t2.a; drop table t1,t2; @@ -393,8 +390,8 @@ create table t1 SELECT da from t2 UNION select dt from t2; select * from t1; show create table t1; drop table t1; -create table t1 SELECT dt from t2 UNION select sc from t2; -select * from t1; +create table t1 SELECT dt from t2 UNION select trim(sc) from t2; +select trim(dt) from t1; show create table t1; drop table t1; create table t1 SELECT dt from t2 UNION select sv from t2; @@ -744,6 +741,36 @@ create table t2 select a from t1 union select b from t1; show columns from t2; drop table t2, t1; +# +# Bug #14216: UNION + DECIMAL wrong values in result +# +create table t1 (f1 decimal(60,25), f2 decimal(60,25)); +insert into t1 values (0.0,0.0); +select f1 from t1 union all select f2 from t1; +select 'XXXXXXXXXXXXXXXXXXXX' as description, f1 from t1 +union all +select 'YYYYYYYYYYYYYYYYYYYY' as description, f2 from t1; +drop table t1; +create table t1 (f1 decimal(60,24), f2 decimal(60,24)); +insert into t1 values (0.0,0.0); +select f1 from t1 union all select f2 from t1; +select 'XXXXXXXXXXXXXXXXXXXX' as description, f1 from t1 +union all +select 'YYYYYYYYYYYYYYYYYYYY' as description, f2 from t1; +drop table t1; + +# +# Test that union with VARCHAR produces dynamic row tables +# + +create table t1 (a varchar(5)); +create table t2 select * from t1 union select 'abcdefghijkl'; +show create table t2; +select row_format from information_schema.TABLES where table_schema="test" and table_name="t2"; +alter table t2 ROW_FORMAT=fixed; +show create table t2; +drop table t1,t2; + # # correct conversion long string to TEXT (BUG#10025) # @@ -765,22 +792,67 @@ select 99 union all select id from t1 order by 1; select id from t1 union all select 99 order by 1; drop table t1; -# -# Bug #14216: UNION + DECIMAL wrong values in result +# End of 4.1 tests + # -create table t1 (f1 decimal(60,25), f2 decimal(60,25)); -insert into t1 values (0.0,0.0); -select f1 from t1 union all select f2 from t1; -select 'XXXXXXXXXXXXXXXXXXXX' as description, f1 from t1 -union all -select 'YYYYYYYYYYYYYYYYYYYY' as description, f2 from t1; -drop table t1; -create table t1 (f1 decimal(60,24), f2 decimal(60,24)); -insert into t1 values (0.0,0.0); -select f1 from t1 union all select f2 from t1; -select 'XXXXXXXXXXXXXXXXXXXX' as description, f1 from t1 -union all -select 'YYYYYYYYYYYYYYYYYYYY' as description, f2 from t1; -drop table t1; +# Bug#12185: Data type aggregation may produce wrong result +# +create table t1(f1 char(1), f2 char(5), f3 binary(1), f4 binary(5), f5 timestamp, f6 varchar(1) character set utf8 collate utf8_general_ci, f7 text); +create table t2 as select *, f6 as f8 from t1 union select *, f7 from t1; +show create table t2; +drop table t1, t2; -# End of 4.1 tests +# +# Bug#18175: Union select over 129 tables with a sum function fails. +# +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)) union +(select avg(1)) union (select avg(1)) union (select avg(1)); + +# +# Bug #16881: password() and union select +# (The issue was poor handling of character set aggregation.) +# +select _utf8'12' union select _latin1'12345'; + +--echo End of 5.0 tests diff --git a/mysql-test/t/update.test b/mysql-test/t/update.test index c69c56f0331..5a49de248b1 100644 --- a/mysql-test/t/update.test +++ b/mysql-test/t/update.test @@ -31,7 +31,7 @@ CREATE TABLE t1 clicks int(10) unsigned DEFAULT '0' NOT NULL, iclicks int(10) unsigned DEFAULT '0' NOT NULL, uclicks int(10) unsigned DEFAULT '0' NOT NULL, - ts timestamp(14), + ts timestamp, PRIMARY KEY (place_id,ts) ); @@ -52,7 +52,7 @@ CREATE TABLE t1 ( replyto varchar(255) NOT NULL default '', subject varchar(100) NOT NULL default '', timestamp int(10) unsigned NOT NULL default '0', - tstamp timestamp(14) NOT NULL, + tstamp timestamp NOT NULL, status int(3) NOT NULL default '0', type varchar(15) NOT NULL default '', assignment int(10) unsigned NOT NULL default '0', diff --git a/mysql-test/t/user_limits.test b/mysql-test/t/user_limits.test new file mode 100644 index 00000000000..af0f6545ac4 --- /dev/null +++ b/mysql-test/t/user_limits.test @@ -0,0 +1,169 @@ +# +# Test behavior of various per-account limits (aka quotas) +# + +# Requires privileges to be enabled +-- source include/not_embedded.inc + +# Prepare play-ground +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1 (i int); +# Just be sure that nothing will bother us +delete from mysql.user where user like 'mysqltest\_%'; +delete from mysql.db where user like 'mysqltest\_%'; +delete from mysql.tables_priv where user like 'mysqltest\_%'; +delete from mysql.columns_priv where user like 'mysqltest\_%'; +flush privileges; + +# Limits doesn't work with prepared statements (yet) +--disable_ps_protocol + +# Test of MAX_QUERIES_PER_HOUR limit +grant usage on *.* to mysqltest_1@localhost with max_queries_per_hour 2; +# This ensures that counters are reset and makes test scheduling independent +flush user_resources; +connect (mqph, localhost, mysqltest_1,,); +connection mqph; +select * from t1; +select * from t1; +--error 1226 +select * from t1; +connect (mqph2, localhost, mysqltest_1,,); +connection mqph2; +--error 1226 +select * from t1; +# cleanup +connection default; +drop user mysqltest_1@localhost; +disconnect mqph; +disconnect mqph2; + +# Test of MAX_UPDATES_PER_HOUR limit +grant usage on *.* to mysqltest_1@localhost with max_updates_per_hour 2; +flush user_resources; +connect (muph, localhost, mysqltest_1,,); +connection muph; +select * from t1; +select * from t1; +select * from t1; +delete from t1; +delete from t1; +--error 1226 +delete from t1; +select * from t1; +connect (muph2, localhost, mysqltest_1,,); +connection muph2; +--error 1226 +delete from t1; +select * from t1; +# Cleanup +connection default; +drop user mysqltest_1@localhost; +disconnect muph; +disconnect muph2; + +# Test of MAX_CONNECTIONS_PER_HOUR limit +grant usage on *.* to mysqltest_1@localhost with max_connections_per_hour 2; +flush user_resources; +connect (mcph1, localhost, mysqltest_1,,); +connection mcph1; +select * from t1; +connect (mcph2, localhost, mysqltest_1,,); +connection mcph2; +select * from t1; +--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK +--error 1226 +connect (mcph3, localhost, mysqltest_1,,); +# Old connection is still ok +select * from t1; +# Let us try to close old connections and try again. This will also test that +# counters are not thrown away if there are no connections for this user. +disconnect mcph1; +disconnect mcph2; +--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK +--error 1226 +connect (mcph3, localhost, mysqltest_1,,); +# Cleanup +connection default; +drop user mysqltest_1@localhost; + +# Test of MAX_USER_CONNECTIONS limit +# We need this to reset internal mqh_used variable +flush privileges; +grant usage on *.* to mysqltest_1@localhost with max_user_connections 2; +flush user_resources; +connect (muc1, localhost, mysqltest_1,,); +connection muc1; +select * from t1; +connect (muc2, localhost, mysqltest_1,,); +connection muc2; +select * from t1; +--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK +--error 1226 +connect (muc3, localhost, mysqltest_1,,); +# Closing of one of connections should help +disconnect muc1; +connect (muc3, localhost, mysqltest_1,,); +select * from t1; +# Changing of limit should also help (and immediately) +connection default; +grant usage on *.* to mysqltest_1@localhost with max_user_connections 3; +flush user_resources; +connect (muc4, localhost, mysqltest_1,,); +connection muc4; +select * from t1; +--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK +--error 1226 +connect (muc5, localhost, mysqltest_1,,); +# Clean up +connection default; +disconnect muc2; +disconnect muc3; +disconnect muc4; +drop user mysqltest_1@localhost; + +# Now let us test interaction between global and per-account +# max_user_connections limits +select @@session.max_user_connections, @@global.max_user_connections; +# Local max_user_connections variable can't be set directly +# since this limit is per-account +--error 1229 +set session max_user_connections= 2; +# But it is ok to set global max_user_connections +set global max_user_connections= 2; +select @@session.max_user_connections, @@global.max_user_connections; +# Let us check that global limit works +grant usage on *.* to mysqltest_1@localhost; +flush user_resources; +connect (muca1, localhost, mysqltest_1,,); +connection muca1; +select @@session.max_user_connections, @@global.max_user_connections; +connect (muca2, localhost, mysqltest_1,,); +connection muca2; +select * from t1; +--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK +--error 1203 +connect (muca3, localhost, mysqltest_1,,); +# Now we are testing that per-account limit prevails over gloabl limit +connection default; +grant usage on *.* to mysqltest_1@localhost with max_user_connections 3; +flush user_resources; +connect (muca3, localhost, mysqltest_1,,); +connection muca3; +select @@session.max_user_connections, @@global.max_user_connections; +--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK +--error 1226 +connect (muca4, localhost, mysqltest_1,,); +# Cleanup +connection default; +disconnect muca1; +disconnect muca2; +disconnect muca3; +set global max_user_connections= 0; +drop user mysqltest_1@localhost; +--enable_ps_protocol + +# Final cleanup +drop table t1; diff --git a/mysql-test/t/user_var-binlog.test b/mysql-test/t/user_var-binlog.test index 6373a1cc426..12a5e616fa2 100644 --- a/mysql-test/t/user_var-binlog.test +++ b/mysql-test/t/user_var-binlog.test @@ -10,12 +10,12 @@ INSERT INTO t1 VALUES(@`a b`); set @var1= "';aaa"; SET @var2=char(ascii('a')); insert into t1 values (@var1),(@var2); -show binlog events from 79; +show binlog events from 98; # more important than SHOW BINLOG EVENTS, mysqlbinlog (where we # absolutely need variables names to be quoted and strings to be # escaped). --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.000001 +--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001 drop table t1; # End of 4.1 tests diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test index 7691a574a2a..65ca1b2c1b7 100644 --- a/mysql-test/t/user_var.test +++ b/mysql-test/t/user_var.test @@ -20,6 +20,7 @@ insert into t2 select distinct i from t1; select * from t2; select distinct t2.i,@vv1:=if(sv1.i,1,0),@vv2:=if(sv2.i,1,0),@vv3:=if(sv3.i,1,0), @vv1+@vv2+@vv3 from t2 left join t1 as sv1 on sv1.i=t2.i and sv1.v=1 left join t1 as sv2 on sv2.i=t2.i and sv2.v=2 left join t1 as sv3 on sv3.i=t2.i and sv3.v=3; explain select * from t1 where i=@vv1; +select @vv1,i,v from t1 where i=@vv1; explain select * from t1 where @vv1:=@vv1+1 and i=@vv1; explain select @vv1:=i from t1 where i=@vv1; explain select * from t1 where i=@vv1; @@ -69,6 +70,10 @@ create table t1 (i int not null); insert t1 values (1),(2),(2),(3),(3),(3); select @a:=0; select @a, @a:=@a+count(*), count(*), @a from t1 group by i; select @a:=0; select @a+0, @a:=@a+0+count(*), count(*), @a+0 from t1 group by i; + +set @a=0; +select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i; +select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i; drop table t1; # @@ -117,7 +122,7 @@ select coercibility(@v1),coercibility(@v2),coercibility(@v3),coercibility(@v4); # --error 1064 set session @honk=99; ---error 1105 +--error 1382 set one_shot @honk=99; # @@ -138,7 +143,79 @@ select @@Max_Allowed_Packet; select @@version; --replace_column 1 # select @@global.version; ---replace_column 1 # -select @@session.VERSION; -# End of 4.1 tests +--echo End of 4.1 tests + +# Bug #6598: problem with cast(NULL as signed integer); +# + +set @first_var= NULL; +create table t1 select @first_var; +show create table t1; +drop table t1; +set @first_var= cast(NULL as signed integer); +create table t1 select @first_var; +show create table t1; +drop table t1; +set @first_var= NULL; +create table t1 select @first_var; +show create table t1; +drop table t1; +set @first_var= concat(NULL); +create table t1 select @first_var; +show create table t1; +drop table t1; +set @first_var=1; +set @first_var= cast(NULL as CHAR); +create table t1 select @first_var; +show create table t1; +drop table t1; + +# +# Bug #7498 User variable SET saves SIGNED BIGINT as UNSIGNED BIGINT +# + +# First part, set user var to large number and select it +set @a=18446744071710965857; +select @a; + +# Second part, set user var from large number in table +# then select it +CREATE TABLE `bigfailure` ( + `afield` BIGINT UNSIGNED NOT NULL +); +INSERT INTO `bigfailure` VALUES (18446744071710965857); +SELECT * FROM bigfailure; +select * from (SELECT afield FROM bigfailure) as b; +select * from bigfailure where afield = (SELECT afield FROM bigfailure); +select * from bigfailure where afield = 18446744071710965857; +# This is fixed in 5.0, to be uncommented there +#select * from bigfailure where afield = '18446744071710965857'; +select * from bigfailure where afield = 18446744071710965856+1; + +SET @a := (SELECT afield FROM bigfailure); +SELECT @a; +SET @a := (select afield from (SELECT afield FROM bigfailure) as b); +SELECT @a; +SET @a := (select * from bigfailure where afield = (SELECT afield FROM bigfailure)); +SELECT @a; + +drop table bigfailure; + +# +# Bug#16861: User defined variable can have a wrong value if a tmp table was +# used. +# +create table t1(f1 int, f2 int); +insert into t1 values (1,2),(2,3),(3,1); +select @var:=f2 from t1 group by f1 order by f2 desc limit 1; +select @var; +drop table t1; + +# +# Bug#19024 - SHOW COUNT(*) WARNINGS not return Errors +# +--error 1064 +insert into city 'blah'; +SHOW COUNT(*) WARNINGS; +SHOW COUNT(*) ERRORS; diff --git a/mysql-test/t/variables-master.opt b/mysql-test/t/variables-master.opt deleted file mode 100644 index a0577107f74..00000000000 --- a/mysql-test/t/variables-master.opt +++ /dev/null @@ -1 +0,0 @@ ---max_join_size=10 diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 8322c0f84bd..d855b4d8266 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -5,10 +5,54 @@ drop table if exists t1,t2; --enable_warnings -set @`test`=1,@TEST=3,@select=2,@t5=1.23456; -select @test,@`select`,@TEST,@not_used; +# +# Bug #19263: variables.test doesn't clean up after itself (I/II -- save) +# +set @my_binlog_cache_size =@@global.binlog_cache_size; +set @my_connect_timeout =@@global.connect_timeout; +set @my_delayed_insert_timeout =@@global.delayed_insert_timeout; +set @my_delayed_queue_size =@@global.delayed_queue_size; +set @my_flush =@@global.flush; +set @my_flush_time =@@global.flush_time; +set @my_key_buffer_size =@@global.key_buffer_size; +set @my_max_binlog_cache_size =@@global.max_binlog_cache_size; +set @my_max_binlog_size =@@global.max_binlog_size; +set @my_max_connect_errors =@@global.max_connect_errors; +set @my_max_delayed_threads =@@global.max_delayed_threads; +set @my_max_heap_table_size =@@global.max_heap_table_size; +set @my_max_insert_delayed_threads=@@global.max_insert_delayed_threads; +set @my_max_join_size =@@global.max_join_size; +set @my_max_user_connections =@@global.max_user_connections; +set @my_max_write_lock_count =@@global.max_write_lock_count; +set @my_myisam_data_pointer_size =@@global.myisam_data_pointer_size; +set @my_net_buffer_length =@@global.net_buffer_length; +set @my_net_write_timeout =@@global.net_write_timeout; +set @my_net_read_timeout =@@global.net_read_timeout; +set @my_query_cache_limit =@@global.query_cache_limit; +set @my_query_cache_type =@@global.query_cache_type; +set @my_rpl_recovery_rank =@@global.rpl_recovery_rank; +set @my_server_id =@@global.server_id; +set @my_slow_launch_time =@@global.slow_launch_time; +set @my_storage_engine =@@global.storage_engine; +set @my_thread_cache_size =@@global.thread_cache_size; + +# case insensitivity tests (new in 5.0) +set @`test`=1; +select @test, @`test`, @TEST, @`TEST`, @"teSt"; +set @TEST=2; +select @test, @`test`, @TEST, @`TEST`, @"teSt"; +set @"tEST"=3; +select @test, @`test`, @TEST, @`TEST`, @"teSt"; +set @`TeST`=4; +select @test, @`test`, @TEST, @`TEST`, @"teSt"; +select @`teST`:=5; +select @test, @`test`, @TEST, @`TEST`, @"teSt"; + +set @select=2,@t5=1.23456; +select @`select`,@not_used; set @test_int=10,@test_double=1e-10,@test_string="abcdeghi",@test_string2="abcdefghij",@select=NULL; ---replace_result e-0 e- e+0 e+ +# Expected result "1e-10", windows returns "1e-010" +--replace_result 1e-010 1e-10 select @test_int,@test_double,@test_string,@test_string2,@select; set @test_int="hello",@test_double="hello",@test_string="hello",@test_string2="hello"; select @test_int,@test_double,@test_string,@test_string2; @@ -36,7 +80,7 @@ drop table t1; # # Test system variables # - +set GLOBAL max_join_size=10; set max_join_size=100; show variables like 'max_join_size'; --replace_result 18446744073709551615 HA_POS_ERROR 4294967295 HA_POS_ERROR @@ -60,16 +104,19 @@ explain extended select @@IDENTITY,last_insert_id(), @@identity; set big_tables=OFF, big_tables=ON, big_tables=0, big_tables=1, big_tables="OFF", big_tables="ON"; -set global concurrent_insert=ON; +set global concurrent_insert=2; show variables like 'concurrent_insert'; set global concurrent_insert=1; show variables like 'concurrent_insert'; set global concurrent_insert=0; show variables like 'concurrent_insert'; -set global concurrent_insert=OFF; -show variables like 'concurrent_insert'; set global concurrent_insert=DEFAULT; -show variables like 'concurrent_insert'; +select @@concurrent_insert; + +set global timed_mutexes=ON; +show variables like 'timed_mutexes'; +set global timed_mutexes=0; +show variables like 'timed_mutexes'; set storage_engine=MYISAM, storage_engine="HEAP", global storage_engine="MERGE"; show local variables like 'storage_engine'; @@ -153,7 +200,7 @@ set collation_connection=NULL; set global autocommit=1; --error 1238 select @@global.timestamp; ---error 1193 +--error 1238 set @@version=''; --error 1229 set @@concurrent_insert=1; @@ -163,8 +210,6 @@ set @@global.sql_auto_is_null=1; select @@global.sql_auto_is_null; --error 1229 set myisam_max_sort_file_size=100; ---error 1229 -set myisam_max_extra_sort_file_size=100; --error 1231 set @@SQL_WARNINGS=NULL; @@ -211,9 +256,6 @@ set max_tmp_tables=100; set global max_user_connections=100; select @@max_user_connections; set global max_write_lock_count=100; -set global myisam_max_extra_sort_file_size=100; -select @@myisam_max_extra_sort_file_size; -set global myisam_max_sort_file_size=100; set myisam_sort_buffer_size=100; set net_buffer_length=100; set net_read_timeout=100; @@ -227,6 +269,10 @@ set global rpl_recovery_rank=100; set global server_id=100; set global slow_launch_time=100; set sort_buffer_size=100; +set @@max_sp_recursion_depth=10; +select @@max_sp_recursion_depth; +set @@max_sp_recursion_depth=0; +select @@max_sp_recursion_depth; set sql_auto_is_null=1; select @@sql_auto_is_null; set @@sql_auto_is_null=0; @@ -243,6 +289,8 @@ select @@sql_max_join_size,@@max_join_size; set sql_quote_show_create=1; set sql_safe_updates=1; set sql_select_limit=1; +# reset it, so later tests don't get confused +set sql_select_limit=default; set sql_warnings=1; set global table_cache=100; set storage_engine=myisam; @@ -254,6 +302,22 @@ set wait_timeout=100; set log_warnings=1; # +# Bugs: #20392: INSERT_ID session variable has weird value +# +select @@session.insert_id; +set @save_insert_id=@@session.insert_id; +set session insert_id=20; +select @@session.insert_id; + +set session last_insert_id=100; +select @@session.insert_id; +select @@session.last_insert_id; +select @@session.insert_id; + +set @@session.insert_id=@save_insert_id; +select @@session.insert_id; + +# # key buffer # @@ -355,8 +419,8 @@ show create table t1; drop table t1; # # What types and widths have variables? -set @arg00= 8, @arg01= 8.8, @arg02= 'a string'; -create table t1 as select @arg00 as c1, @arg01 as c2, @arg02 as c3; +set @arg00= 8, @arg01= 8.8, @arg02= 'a string', @arg03= 0.2e0; +create table t1 as select @arg00 as c1, @arg01 as c2, @arg02 as c3, @arg03 as c4; show create table t1; drop table t1; @@ -404,3 +468,166 @@ set @@query_prealloc_size = @test; select @@query_prealloc_size = @test; # End of 4.1 tests + +# +# Bug#6282 Packet error with SELECT INTO +# + +create table t1 (a int); +select a into @x from t1; +show warnings; +drop table t1; + +# +# Bug #10339: read only variables. +# + +--error 1238 +set @@warning_count=1; +--error 1238 +set @@global.error_count=1; + +# +# Bug #10351: Setting ulong variable to > MAX_ULONG fails on 32-bit platform +# + +set @@max_heap_table_size= 4294967296; +select @@max_heap_table_size > 0; +set global max_heap_table_size= 4294967296; +select @@max_heap_table_size > 0; +set @@max_heap_table_size= 4294967296; +select @@max_heap_table_size > 0; + +# +# Bug #11775 Variable character_set_system does not exist (sometimes) +# +select @@character_set_system; +--error 1238 +set global character_set_system = latin1; +--error 1238 +set @@global.version_compile_os='234'; + +# +# Check character_set_filesystem variable +# +set character_set_filesystem=latin1; +select @@character_set_filesystem; +set @@global.character_set_filesystem=latin2; +set character_set_filesystem=latin1; +select @@character_set_filesystem; +set @@global.character_set_filesystem=latin2; +set character_set_filesystem=default; +select @@character_set_filesystem; +set @@global.character_set_filesystem=default; +select @@global.character_set_filesystem; + +# +# Bug #17849: Show sql_big_selects in SHOW VARIABLES +# +set @old_sql_big_selects = @@sql_big_selects; +set @@sql_big_selects = 1; +show variables like 'sql_big_selects'; +set @@sql_big_selects = @old_sql_big_selects; + +# +# Bug #16195: SHOW VARIABLES doesn't report correctly sql_warnings and +# sql_notes values +# +set @@sql_notes = 0, @@sql_warnings = 0; +show variables like 'sql_notes'; +show variables like 'sql_warnings'; +set @@sql_notes = 1, @@sql_warnings = 1; +show variables like 'sql_notes'; +show variables like 'sql_warnings'; + +# +# Bug #12792: @@system_time_zone is not SELECTable. +# +# Don't actually output, since it depends on the system +--replace_column 1 # +select @@system_time_zone; + +# +# Bug #15684: system variables cannot be SELECTed (e.g. @@version_comment) +# +# Don't actually output, since it depends on the system +--replace_column 1 # 2 # 3 # 4 # +select @@version, @@version_comment, @@version_compile_machine, + @@version_compile_os; + +# +# Bug #1039: make tmpdir and datadir available as @@variables (also included +# basedir) +# +# Don't actually output, since it depends on the system +--replace_column 1 # 2 # 3 # +select @@basedir, @@datadir, @@tmpdir; +--replace_column 2 # +show variables like 'basedir'; +--replace_column 2 # +show variables like 'datadir'; +--replace_column 2 # +show variables like 'tmpdir'; + +# +# Bug #19606: make ssl settings available via SHOW VARIABLES and @@variables +# +# Don't actually output, since it depends on the system +--replace_column 1 # 2 # 3 # 4 # 5 # +select @@ssl_ca, @@ssl_capath, @@ssl_cert, @@ssl_cipher, @@ssl_key; +--replace_column 2 # +show variables like 'ssl%'; + +# +# Bug #19616: make log_queries_not_using_indexes available in SHOW VARIABLES +# and as @@log_queries_not_using_indexes +# +select @@log_queries_not_using_indexes; +show variables like 'log_queries_not_using_indexes'; + +# +# Bug#20908: Crash if select @@"" +# +--error ER_PARSE_ERROR +select @@""; +--error ER_PARSE_ERROR +select @@&; +--error ER_PARSE_ERROR +select @@@; + +--echo End of 5.0 tests + +# This is at the very after the versioned tests, since it involves doing +# cleanup +# +# Bug #19263: variables.test doesn't clean up after itself (II/II -- +# restore) +# +set global binlog_cache_size =@my_binlog_cache_size; +set global connect_timeout =@my_connect_timeout; +set global delayed_insert_timeout =@my_delayed_insert_timeout; +set global delayed_queue_size =@my_delayed_queue_size; +set global flush =@my_flush; +set global flush_time =@my_flush_time; +set global key_buffer_size =@my_key_buffer_size; +set global max_binlog_cache_size =default; #@my_max_binlog_cache_size; +set global max_binlog_size =@my_max_binlog_size; +set global max_connect_errors =@my_max_connect_errors; +set global max_delayed_threads =@my_max_delayed_threads; +set global max_heap_table_size =@my_max_heap_table_size; +set global max_insert_delayed_threads=@my_max_insert_delayed_threads; +set global max_join_size =@my_max_join_size; +set global max_user_connections =@my_max_user_connections; +set global max_write_lock_count =@my_max_write_lock_count; +set global myisam_data_pointer_size =@my_myisam_data_pointer_size; +set global net_buffer_length =@my_net_buffer_length; +set global net_write_timeout =@my_net_write_timeout; +set global net_read_timeout =@my_net_read_timeout; +set global query_cache_limit =@my_query_cache_limit; +set global query_cache_type =@my_query_cache_type; +set global rpl_recovery_rank =@my_rpl_recovery_rank; +set global server_id =@my_server_id; +set global slow_launch_time =@my_slow_launch_time; +set global storage_engine =@my_storage_engine; +set global thread_cache_size =@my_thread_cache_size; + diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test new file mode 100644 index 00000000000..8473458ae15 --- /dev/null +++ b/mysql-test/t/view.test @@ -0,0 +1,2963 @@ +--disable_warnings +drop table if exists t1,t2,t3,t4,t9,`t1a``b`,v1,v2,v3,v4,v5,v6; +drop view if exists t1,t2,`t1a``b`,v1,v2,v3,v4,v5,v6; +drop database if exists mysqltest; +--enable_warnings +use test; + +# +# some basic test of views and its functionality +# + +# create view on nonexistent table +-- error 1146 +create view v1 (c,d) as select a,b from t1; + +create temporary table t1 (a int, b int); +# view on temporary table +-- error 1352 +create view v1 (c) as select b+1 from t1; +drop table t1; + +create table t1 (a int, b int); +insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10); + +# view with variable +-- error ER_VIEW_SELECT_VARIABLE +create view v1 (c,d) as select a,b+@@global.max_user_connections from t1; +-- error ER_VIEW_SELECT_VARIABLE +create view v1 (c,d) as select a,b from t1 + where a = @@global.max_user_connections; + +# simple view +create view v1 (c) as select b+1 from t1; +select c from v1; + +# temporary table should not hide table of view +create temporary table t1 (a int, b int); +# this is empty +select * from t1; +# but this based on normal t1 +select c from v1; +show create table v1; +show create view v1; +-- error 1347 +show create view t1; +drop table t1; + +# try to use fields from underlying table +-- error 1054 +select a from v1; +-- error 1054 +select v1.a from v1; +-- error 1054 +select b from v1; +-- error 1054 +select v1.b from v1; + +# view with different algorithms (explain output differs) +explain extended select c from v1; +create algorithm=temptable view v2 (c) as select b+1 from t1; +show create view v2; +select c from v2; +explain extended select c from v2; + +# try to use underlying table fields in VIEW creation process +-- error 1054 +create view v3 (c) as select a+1 from v1; +-- error 1054 +create view v3 (c) as select b+1 from v1; + + +# VIEW on VIEW test with mixing different algorithms on different order +create view v3 (c) as select c+1 from v1; +select c from v3; +explain extended select c from v3; +create algorithm=temptable view v4 (c) as select c+1 from v2; +select c from v4; +explain extended select c from v4; +create view v5 (c) as select c+1 from v2; +select c from v5; +explain extended select c from v5; +create algorithm=temptable view v6 (c) as select c+1 from v1; +select c from v6; +explain extended select c from v6; + +# show table/table status test +show tables; +show full tables; +--replace_column 8 # 12 # 13 # +show table status; + +drop view v1,v2,v3,v4,v5,v6; + +# +# alter/create view test +# + +# view with subqueries of different types +create view v1 (c,d,e,f) as select a,b, +a in (select a+2 from t1), a = all (select a from t1) from t1; +create view v2 as select c, d from v1; +select * from v1; +select * from v2; + +# try to create VIEW with name of existing VIEW +-- error 1050 +create view v1 (c,d,e,f) as select a,b, a in (select a+2 from t1), a = all (select a from t1) from t1; + +# 'or replace' should work in this case +create or replace view v1 (c,d,e,f) as select a,b, a in (select a+2 from t1), a = all (select a from t1) from t1; + +# try to ALTER unexisting VIEW +drop view v2; +-- error 1146 +alter view v2 as select c, d from v1; + +# 'or replace' on unexisting view +create or replace view v2 as select c, d from v1; + +# alter view on existing view +alter view v1 (c,d) as select a,max(b) from t1 group by a; + +# check that created view works +select * from v1; +select * from v2; + +# try to drop nonexistent VIEW +-- error 1051 +drop view v100; + +# try to drop table with DROP VIEW +-- error 1347 +drop view t1; + +# try to drop VIEW with DROP TABLE +-- error 1051 +drop table v1; + +# try to drop table with DROP VIEW + +drop view v1,v2; +drop table t1; + +# +# outer left join with merged views +# +create table t1 (a int); +insert into t1 values (1), (2), (3); + +create view v1 (a) as select a+1 from t1; +create view v2 (a) as select a-1 from t1; + +select * from t1 natural left join v1; +select * from v2 natural left join t1; +select * from v2 natural left join v1; + +drop view v1, v2; +drop table t1; + + +# +# DISTINCT option for VIEW +# +create table t1 (a int); +insert into t1 values (1), (2), (3), (1), (2), (3); +create view v1 as select distinct a from t1; +select * from v1; +explain select * from v1; +select * from t1; +drop view v1; +drop table t1; + +# +# syntax compatibility +# +create table t1 (a int); +-- error 1368 +create view v1 as select distinct a from t1 WITH CHECK OPTION; +create view v1 as select a from t1 WITH CHECK OPTION; +create view v2 as select a from t1 WITH CASCADED CHECK OPTION; +create view v3 as select a from t1 WITH LOCAL CHECK OPTION; +drop view v3 RESTRICT; +drop view v2 CASCADE; +drop view v1; +drop table t1; + +# +# aliases +# +create table t1 (a int, b int); +insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10); +create view v1 (c) as select b+1 from t1; +select test.c from v1 test; +create algorithm=temptable view v2 (c) as select b+1 from t1; +select test.c from v2 test; +select test1.* from v1 test1, v2 test2 where test1.c=test2.c; +select test2.* from v1 test1, v2 test2 where test1.c=test2.c; +drop table t1; +drop view v1,v2; + +# +# LIMIT clause test +# +create table t1 (a int); +insert into t1 values (1), (2), (3), (4); +create view v1 as select a+1 from t1 order by 1 desc limit 2; +select * from v1; +explain select * from v1; +drop view v1; +drop table t1; + +# +# CREATE ... SELECT view test +# +create table t1 (a int); +insert into t1 values (1), (2), (3), (4); +create view v1 as select a+1 from t1; +create table t2 select * from v1; +show columns from t2; +select * from t2; +drop view v1; +drop table t1,t2; + +# +# simple view + simple update +# +create table t1 (a int, b int, primary key(a)); +insert into t1 values (10,2), (20,3), (30,4), (40,5), (50,10); +create view v1 (a,c) as select a, b+1 from t1; +create algorithm=temptable view v2 (a,c) as select a, b+1 from t1; +# try to update expression +-- error 1348 +update v1 set c=a+c; +# try to update VIEW with forced TEMPORARY TABLE algorithm +-- error 1288 +update v2 set a=a+c; +# updatable field of updateable view +update v1 set a=a+c; +select * from v1; +select * from t1; +drop table t1; +drop view v1,v2; + +# +# simple view + simple multi-update +# +create table t1 (a int, b int, primary key(a)); +insert into t1 values (10,2), (20,3), (30,4), (40,5), (50,10); +create table t2 (x int); +insert into t2 values (10), (20); +create view v1 (a,c) as select a, b+1 from t1; +create algorithm=temptable view v2 (a,c) as select a, b+1 from t1; +# try to update expression +-- error 1348 +update t2,v1 set v1.c=v1.a+v1.c where t2.x=v1.a; +# try to update VIEW with forced TEMPORARY TABLE algorithm +-- error 1288 +update t2,v2 set v2.a=v2.v2.a+c where t2.x=v2.a; +# updatable field of updateable view +update t2,v1 set v1.a=v1.a+v1.c where t2.x=v1.a; +select * from v1; +select * from t1; +drop table t1,t2; +drop view v1,v2; + +# +# MERGE VIEW with WHERE clause +# +create table t1 (a int, b int, primary key(b)); +insert into t1 values (1,20), (2,30), (3,40), (4,50), (5,100); +create view v1 (c) as select b from t1 where a<3; +# simple select and explaint to be sure that it is MERGE +select * from v1; +explain extended select * from v1; +# update test +update v1 set c=c+1; +select * from t1; +# join of such VIEWs test +create view v2 (c) as select b from t1 where a>=3; +select * from v1, v2; +drop view v1, v2; +drop table t1; + +# +# simple view + simple delete +# +create table t1 (a int, b int, primary key(a)); +insert into t1 values (1,2), (2,3), (3,4), (4,5), (5,10); +create view v1 (a,c) as select a, b+1 from t1; +create algorithm=temptable view v2 (a,c) as select a, b+1 from t1; +# try to update VIEW with forced TEMPORARY TABLE algorithm +-- error 1288 +delete from v2 where c < 4; +# updatable field of updateable view +delete from v1 where c < 4; +select * from v1; +select * from t1; +drop table t1; +drop view v1,v2; + +# +# simple view + simple multi-delete +# +create table t1 (a int, b int, primary key(a)); +insert into t1 values (1,2), (2,3), (3,4), (4,5), (5,10); +create table t2 (x int); +insert into t2 values (1), (2), (3), (4); +create view v1 (a,c) as select a, b+1 from t1; +create algorithm=temptable view v2 (a,c) as select a, b+1 from t1; +# try to update VIEW with forced TEMPORARY TABLE algorithm +-- error 1288 +delete v2 from t2,v2 where t2.x=v2.a; +# updatable field of updateable view +delete v1 from t2,v1 where t2.x=v1.a; +select * from v1; +select * from t1; +drop table t1,t2; +drop view v1,v2; + +# +# key presence check +# +create table t1 (a int, b int, c int, primary key(a,b)); +insert into t1 values (10,2,-1), (20,3,-2), (30,4,-3), (40,5,-4), (50,10,-5); +create view v1 (x,y) as select a, b from t1; +create view v2 (x,y) as select a, c from t1; +set updatable_views_with_limit=NO; +update v1 set x=x+1; +update v2 set x=x+1; +update v1 set x=x+1 limit 1; +-- error 1288 +update v2 set x=x+1 limit 1; +set updatable_views_with_limit=YES; +update v1 set x=x+1 limit 1; +update v2 set x=x+1 limit 1; +set updatable_views_with_limit=DEFAULT; +show variables like "updatable_views_with_limit"; +select * from t1; +drop table t1; +drop view v1,v2; + +# +# simple insert +# +create table t1 (a int, b int, c int, primary key(a,b)); +insert into t1 values (10,2,-1), (20,3,-2); +create view v1 (x,y,z) as select c, b, a from t1; +create view v2 (x,y) as select b, a from t1; +create view v3 (x,y,z) as select b, a, b from t1; +create view v4 (x,y,z) as select c+1, b, a from t1; +create algorithm=temptable view v5 (x,y,z) as select c, b, a from t1; +# try insert to VIEW with fields duplicate +-- error 1471 +insert into v3 values (-60,4,30); +# try insert to VIEW with expression in SELECT list +-- error 1471 +insert into v4 values (-60,4,30); +# try insert to VIEW using temporary table algorithm +-- error 1471 +insert into v5 values (-60,4,30); +insert into v1 values (-60,4,30); +insert into v1 (z,y,x) values (50,6,-100); +insert into v2 values (5,40); +select * from t1; +drop table t1; +drop view v1,v2,v3,v4,v5; + +# +# insert ... select +# +create table t1 (a int, b int, c int, primary key(a,b)); +insert into t1 values (10,2,-1), (20,3,-2); +create table t2 (a int, b int, c int, primary key(a,b)); +insert into t2 values (30,4,-60); +create view v1 (x,y,z) as select c, b, a from t1; +create view v2 (x,y) as select b, a from t1; +create view v3 (x,y,z) as select b, a, b from t1; +create view v4 (x,y,z) as select c+1, b, a from t1; +create algorithm=temptable view v5 (x,y,z) as select c, b, a from t1; +# try insert to VIEW with fields duplicate +-- error 1471 +insert into v3 select c, b, a from t2; +# try insert to VIEW with expression in SELECT list +-- error 1471 +insert into v4 select c, b, a from t2; +# try insert to VIEW using temporary table algorithm +-- error 1471 +insert into v5 select c, b, a from t2; +insert into v1 select c, b, a from t2; +insert into v1 (z,y,x) select a+20,b+2,-100 from t2; +insert into v2 select b+1, a+10 from t2; +select * from t1; +drop table t1, t2; +drop view v1,v2,v3,v4,v5; + +# +# outer join based on VIEW with WHERE clause +# +create table t1 (a int, primary key(a)); +insert into t1 values (1), (2), (3); +create view v1 (x) as select a from t1 where a > 1; +select t1.a, v1.x from t1 left join v1 on (t1.a= v1.x); +drop table t1; +drop view v1; + +# +# merging WHERE condition on VIEW on VIEW +# +create table t1 (a int, primary key(a)); +insert into t1 values (1), (2), (3), (200); +create view v1 (x) as select a from t1 where a > 1; +create view v2 (y) as select x from v1 where x < 100; +select * from v2; +drop table t1; +drop view v1,v2; + +# +# VIEW on non-updatable view +# +create table t1 (a int, primary key(a)); +insert into t1 values (1), (2), (3), (200); +create ALGORITHM=TEMPTABLE view v1 (x) as select a from t1; +create view v2 (y) as select x from v1; +-- error 1288 +update v2 set y=10 where y=2; +drop table t1; +drop view v1,v2; + +# +# auto_increment field out of VIEW +# +create table t1 (a int not null auto_increment, b int not null, primary key(a), unique(b)); +create view v1 (x) as select b from t1; +insert into v1 values (1); +select last_insert_id(); +insert into t1 (b) values (2); +select last_insert_id(); +select * from t1; +drop view v1; +drop table t1; + +# +# VIEW fields quoting +# +set sql_mode='ansi'; +create table t1 ("a*b" int); +create view v1 as select "a*b" from t1; +show create view v1; +drop view v1; +drop table t1; +set sql_mode=default; + +# +# VIEW without tables +# +create table t1 (t_column int); +create view v1 as select 'a'; +select * from v1, t1; +drop view v1; +drop table t1; + +# +# quote mark inside table name +# +create table `t1a``b` (col1 char(2)); +create view v1 as select * from `t1a``b`; +select * from v1; +describe v1; +drop view v1; +drop table `t1a``b`; + +# +# Changing of underlying table +# +create table t1 (col1 char(5),col2 char(5)); +create view v1 as select * from t1; +drop table t1; +create table t1 (col1 char(5),newcol2 char(5)); +-- error 1356 +insert into v1 values('a','aa'); +drop table t1; +-- error 1356 +select * from v1; +drop view v1; + +# +# check of duplication of column names +# +-- error 1060 +create view v1 (a,a) as select 'a','a'; + +# +# updatablity should be transitive +# +create table t1 (col1 int,col2 char(22)); +insert into t1 values(5,'Hello, world of views'); +create view v1 as select * from t1; +create view v2 as select * from v1; +update v2 set col2='Hello, view world'; +select * from t1; +drop view v2, v1; +drop table t1; + +# +# check 'use index' on view with temporary table +# +create table t1 (a int, b int); +create view v1 as select a, sum(b) from t1 group by a; +-- error 1176 +select b from v1 use index (some_index) where b=1; +drop view v1; +drop table t1; + +# +# using VIEW fields several times in query resolved via temporary tables +# +create table t1 (col1 char(5),col2 char(5)); +create view v1 (col1,col2) as select col1,col2 from t1; +insert into v1 values('s1','p1'),('s1','p2'),('s1','p3'),('s1','p4'),('s2','p1'),('s3','p2'),('s4','p4'); +select distinct first.col2 from t1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1); +select distinct first.col2 from v1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1); +drop view v1; +drop table t1; + +# +# Test of view updatability in prepared statement +# +create table t1 (a int); +create view v1 as select a from t1; +insert into t1 values (1); + +#update +SET @v0 = '2'; +PREPARE stmt FROM 'UPDATE v1 SET a = ?'; +EXECUTE stmt USING @v0; +DEALLOCATE PREPARE stmt; + +#insert without field list +SET @v0 = '3'; +PREPARE stmt FROM 'insert into v1 values (?)'; +EXECUTE stmt USING @v0; +DEALLOCATE PREPARE stmt; + +#insert with field list +SET @v0 = '4'; +PREPARE stmt FROM 'insert into v1 (a) values (?)'; +EXECUTE stmt USING @v0; +DEALLOCATE PREPARE stmt; + +select * from t1; + +drop view v1; +drop table t1; + +# +# error on preparation +# +-- error 1096 +CREATE VIEW v02 AS SELECT * FROM DUAL; +SHOW TABLES; + +# +# EXISTS with UNION VIEW +# +CREATE VIEW v1 AS SELECT EXISTS (SELECT 1 UNION SELECT 2); +select * from v1; +drop view v1; + +# +# using VIEW where table is required +# +create table t1 (col1 int,col2 char(22)); +create view v1 as select * from t1; +-- error 1347 +create index i1 on v1 (col1); +drop view v1; +drop table t1; + +# +# connection_id(), pi(), current_user(), version() representation test +# +CREATE VIEW v1 (f1,f2,f3,f4) AS SELECT connection_id(), pi(), current_user(), version(); +SHOW CREATE VIEW v1; +drop view v1; + +# +# VIEW built over UNION +# +create table t1 (s1 int); +create table t2 (s2 int); +insert into t1 values (1), (2); +insert into t2 values (2), (3); +create view v1 as select * from t1,t2 union all select * from t1,t2; +select * from v1; +drop view v1; +drop tables t1, t2; + +# +# Aggregate functions in view list +# +create table t1 (col1 int); +insert into t1 values (1); +create view v1 as select count(*) from t1; +insert into t1 values (null); +select * from v1; +drop view v1; +drop table t1; + +# +# Showing VIEW with VIEWs in subquery +# +create table t1 (a int); +create table t2 (a int); +create view v1 as select a from t1; +create view v2 as select a from t2 where a in (select a from v1); +show create view v2; +drop view v2, v1; +drop table t1, t2; + +# +# SHOW VIEW view with name with spaces +# +CREATE VIEW `v 1` AS select 5 AS `5`; +show create view `v 1`; +drop view `v 1`; + +# +# Removing database with .frm archives +# +create database mysqltest; +create table mysqltest.t1 (a int, b int); +create view mysqltest.v1 as select a from mysqltest.t1; +alter view mysqltest.v1 as select b from mysqltest.t1; +alter view mysqltest.v1 as select a from mysqltest.t1; +drop database mysqltest; + +# +# VIEW with full text +# +CREATE TABLE t1 (c1 int not null auto_increment primary key, c2 varchar(20), fulltext(c2)); +insert into t1 (c2) VALUES ('real Beer'),('Water'),('Kossu'),('Coca-Cola'),('Vodka'),('Wine'),('almost real Beer'); +select * from t1 WHERE match (c2) against ('Beer'); +CREATE VIEW v1 AS SELECT * from t1 WHERE match (c2) against ('Beer'); +select * from v1; +drop view v1; +drop table t1; + +# +# distinct in temporary table with a VIEW +# +create table t1 (a int); +insert into t1 values (1),(1),(2),(2),(3),(3); +create view v1 as select a from t1; +select distinct a from v1; +select distinct a from v1 limit 2; +select distinct a from t1 limit 2; +prepare stmt1 from "select distinct a from v1 limit 2"; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; +drop view v1; +drop table t1; + +# +# aggregate function of aggregate function +# +create table t1 (tg_column bigint); +create view v1 as select count(tg_column) as vg_column from t1; +select avg(vg_column) from v1; +drop view v1; +drop table t1; + +# +# VIEW of VIEW with column renaming +# +create table t1 (col1 bigint not null, primary key (col1)); +create table t2 (col1 bigint not null, key (col1)); +create view v1 as select * from t1; +create view v2 as select * from t2; +insert into v1 values (1); +insert into v2 values (1); +create view v3 (a,b) as select v1.col1 as a, v2.col1 as b from v1, v2 where v1.col1 = v2.col1; +select * from v3; +show create view v3; +drop view v3, v2, v1; +drop table t2, t1; + +# +# VIEW based on functions with complex names +# +create function `f``1` () returns int return 5; +create view v1 as select test.`f``1` (); +show create view v1; +select * from v1; +drop view v1; +drop function `f``1`; + +# +# tested problem when function name length close to ALIGN_SIZE +# +create function x () returns int return 5; +create view v1 as select x (); +select * from v1; +drop view v1; +drop function x; + +# +# VIEW with collation +# +create table t2 (col1 char collate latin1_german2_ci); +create view v2 as select col1 collate latin1_german1_ci from t2; +show create view v2; +show create view v2; +drop view v2; +drop table t2; + +# +# order by refers on integer field +# +create table t1 (a int); +insert into t1 values (1), (2); +create view v1 as select 5 from t1 order by 1; +select * from v1; +drop view v1; +drop table t1; + +# +# VIEW over dropped function +# +create function x1 () returns int return 5; +create table t1 (s1 int); +create view v1 as select x1() from t1; +drop function x1; +-- error 1356 +select * from v1; +--replace_column 8 # 12 # 13 # +show table status; +drop view v1; +drop table t1; + +# +# VIEW with floating point (long number) as column +# +create view v1 as select 99999999999999999999999999999999999999999999999999999 as col1; +show create view v1; +drop view v1; + +# +# VIEWs with national characters +# +create table tü (cü char); +create view vü as select cü from tü; +insert into vü values ('ü'); +select * from vü; +drop view vü; +drop table tü; + +# +# problem with used_tables() of outer reference resolved in VIEW +# +create table t1 (a int, b int); +insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10); +create view v1(c) as select a+1 from t1 where b >= 4; +select c from v1 where exists (select * from t1 where a=2 and b=c); +drop view v1; +drop table t1; + +# +# view with cast operation +# +create view v1 as select cast(1 as char(3)); +show create view v1; +select * from v1; +drop view v1; + +# +# renaming views +# +create table t1 (a int); +create view v1 as select a from t1; +create view v3 as select a from t1; +create database mysqltest; +-- error 1450 +rename table v1 to mysqltest.v1; +rename table v1 to v2; +--error 1050 +rename table v3 to v1, v2 to t1; +drop table t1; +drop view v2,v3; +drop database mysqltest; + +# +# bug handling from VIEWs +# +create view v1 as select 'a',1; +create view v2 as select * from v1 union all select * from v1; +create view v3 as select * from v2 where 1 = (select `1` from v2); +create view v4 as select * from v3; +-- error 1242 +select * from v4; +drop view v4, v3, v2, v1; + +# +# VIEW over SELECT with prohibited clauses +# +-- error 1350 +create view v1 as select 5 into @w; +-- error 1350 +create view v1 as select 5 into outfile 'ttt'; +create table t1 (a int); +-- error 1350 +create view v1 as select a from t1 procedure analyse(); +-- error ER_VIEW_SELECT_DERIVED +create view v1 as select 1 from (select 1) as d1; +drop table t1; + +# +# INSERT into VIEW with ON DUPLICATE +# +create table t1 (s1 int, primary key (s1)); +create view v1 as select * from t1; +insert into v1 values (1) on duplicate key update s1 = 7; +insert into v1 values (1) on duplicate key update s1 = 7; +select * from t1; +drop view v1; +drop table t1; + +# +# test of updating and fetching from the same table check +# +create table t1 (col1 int); +create table t2 (col1 int); +create view v1 as select * from t1; +create view v2 as select * from v1; +create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1; +-- error 1443 +update v2 set col1 = (select max(col1) from v1); +-- error 1443 +update v2 set col1 = (select max(col1) from t1); +-- error 1093 +update v2 set col1 = (select max(col1) from v2); +-- error 1443 +update v2,t2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1; +-- error 1443 +update t1,t2 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1; +-- error 1093 +update v1,t2 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1; +-- error 1443 +update t2,v2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1; +-- error 1443 +update t2,t1 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1; +-- error 1443 +update t2,v1 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1; +-- error 1443 +update v2,t2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1; +-- error 1093 +update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1; +-- error 1443 +update v1,t2 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1; +-- error 1093 +update t2,v2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1; +-- error 1093 +update t2,t1 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1; +-- error 1093 +update t2,v1 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1; +-- error 1093 +update v2,t2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1; +-- error 1443 +update t1,t2 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1; +-- error 1443 +update v1,t2 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1; +-- error 1443 +update t2,v2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1; +-- error 1443 +update t2,t1 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1; +-- error 1443 +update t2,v1 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1; +-- error 1443 +update v3 set v3.col1 = (select max(col1) from v1); +-- error 1443 +update v3 set v3.col1 = (select max(col1) from t1); +-- error 1443 +update v3 set v3.col1 = (select max(col1) from v2); +-- error 1093 +update v3 set v3.col1 = (select max(col1) from v3); +-- error 1443 +delete from v2 where col1 = (select max(col1) from v1); +-- error 1443 +delete from v2 where col1 = (select max(col1) from t1); +-- error 1093 +delete from v2 where col1 = (select max(col1) from v2); +-- error 1443 +delete v2 from v2,t2 where (select max(col1) from v1) > 0 and v2.col1 = t2.col1; +-- error 1443 +delete t1 from t1,t2 where (select max(col1) from v1) > 0 and t1.col1 = t2.col1; +-- error 1093 +delete v1 from v1,t2 where (select max(col1) from v1) > 0 and v1.col1 = t2.col1; +-- error 1443 +delete v2 from v2,t2 where (select max(col1) from t1) > 0 and v2.col1 = t2.col1; +-- error 1093 +delete t1 from t1,t2 where (select max(col1) from t1) > 0 and t1.col1 = t2.col1; +-- error 1443 +delete v1 from v1,t2 where (select max(col1) from t1) > 0 and v1.col1 = t2.col1; +-- error 1093 +delete v2 from v2,t2 where (select max(col1) from v2) > 0 and v2.col1 = t2.col1; +-- error 1443 +delete t1 from t1,t2 where (select max(col1) from v2) > 0 and t1.col1 = t2.col1; +-- error 1443 +delete v1 from v1,t2 where (select max(col1) from v2) > 0 and v1.col1 = t2.col1; +-- error 1443 +insert into v2 values ((select max(col1) from v1)); +-- error 1443 +insert into t1 values ((select max(col1) from v1)); +-- error 1443 +insert into v2 values ((select max(col1) from v1)); +-- error 1443 +insert into v2 values ((select max(col1) from t1)); +-- error 1093 +insert into t1 values ((select max(col1) from t1)); +-- error 1443 +insert into v2 values ((select max(col1) from t1)); +-- error 1093 +insert into v2 values ((select max(col1) from v2)); +-- error 1443 +insert into t1 values ((select max(col1) from v2)); +-- error 1093 +insert into v2 values ((select max(col1) from v2)); +-- error 1443 +insert into v3 (col1) values ((select max(col1) from v1)); +-- error 1443 +insert into v3 (col1) values ((select max(col1) from t1)); +-- error 1443 +insert into v3 (col1) values ((select max(col1) from v2)); +#check with TZ tables in list +-- error 1443 +insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from v2)); +insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2)); +-- error 1048 +insert into mysql.time_zone values ('', (select CONVERT_TZ('20050101000000','UTC','MET') from t2)); +# temporary table algorithm view should be equal to subquery in the from clause +create algorithm=temptable view v4 as select * from t1; +insert into t1 values (1),(2),(3); +insert into t1 (col1) values ((select max(col1) from v4)); +select * from t1; + +drop view v4,v3,v2,v1; +drop table t1,t2; + +# +# HANDLER with VIEW +# +create table t1 (s1 int); +create view v1 as select * from t1; +-- error 1347 +handler v1 open as xx; +drop view v1; +drop table t1; + +# +# view with WHERE in nested join +# +create table t1(a int); +insert into t1 values (0), (1), (2), (3); +create table t2 (a int); +insert into t2 select a from t1 where a > 1; +create view v1 as select a from t1 where a > 1; +select * from t1 left join (t2 as t, v1) on v1.a=t1.a; +select * from t1 left join (t2 as t, t2) on t2.a=t1.a; +drop view v1; +drop table t1, t2; + +# +# Collation with view update +# +create table t1 (s1 char); +create view v1 as select s1 collate latin1_german1_ci as s1 from t1; +insert into v1 values ('a'); +select * from v1; +update v1 set s1='b'; +select * from v1; +update v1,t1 set v1.s1='c' where t1.s1=v1.s1; +select * from v1; +prepare stmt1 from "update v1,t1 set v1.s1=? where t1.s1=v1.s1"; +set @arg='d'; +execute stmt1 using @arg; +select * from v1; +set @arg='e'; +execute stmt1 using @arg; +select * from v1; +deallocate prepare stmt1; +drop view v1; +drop table t1; + +# +# test view with LOCK TABLES (work around) +# +create table t1 (a int); +create table t2 (a int); +create view v1 as select * from t1; +lock tables t1 read, v1 read; +select * from v1; +-- error 1100 +select * from t2; +drop view v1; +drop table t1, t2; + +# +# WITH CHECK OPTION insert/update test +# +create table t1 (a int); +create view v1 as select * from t1 where a < 2 with check option; +# simple insert +insert into v1 values(1); +-- error 1369 +insert into v1 values(3); +# simple insert with ignore +insert ignore into v1 values (2),(3),(0); +select * from t1; +# prepare data for next check +delete from t1; +# INSERT SELECT test +insert into v1 SELECT 1; +-- error 1369 +insert into v1 SELECT 3; +# prepare data for next check +create table t2 (a int); +insert into t2 values (2),(3),(0); +# INSERT SELECT with ignore test +insert ignore into v1 SELECT a from t2; +select * from t1; +#simple UPDATE test +update v1 set a=-1 where a=0; +-- error 1369 +update v1 set a=2 where a=1; +select * from t1; +# prepare data for next check +update v1 set a=0 where a=0; +insert into t2 values (1); +# multiupdate test +update v1,t2 set v1.a=v1.a-1 where v1.a=t2.a; +select * from t1; +# prepare data for next check +update v1 set a=a+1; +# multiupdate with ignore test +update ignore v1,t2 set v1.a=v1.a+1 where v1.a=t2.a; +select * from t1; + +drop view v1; +drop table t1, t2; + +# +# CASCADED/LOCAL CHECK OPTION test +# +create table t1 (a int); +create view v1 as select * from t1 where a < 2 with check option; +create view v2 as select * from v1 where a > 0 with local check option; +create view v3 as select * from v1 where a > 0 with cascaded check option; +insert into v2 values (1); +insert into v3 values (1); +-- error 1369 +insert into v2 values (0); +-- error 1369 +insert into v3 values (0); +insert into v2 values (2); +-- error 1369 +insert into v3 values (2); +select * from t1; +drop view v3,v2,v1; +drop table t1; + +# +# CHECK OPTION with INSERT ... ON DUPLICATE KEY UPDATE +# +create table t1 (a int, primary key (a)); +create view v1 as select * from t1 where a < 2 with check option; +insert into v1 values (1) on duplicate key update a=2; +-- error 1369 +insert into v1 values (1) on duplicate key update a=2; +insert ignore into v1 values (1) on duplicate key update a=2; +select * from t1; +drop view v1; +drop table t1; + +# +# check cyclic referencing protection on altering view +# +create table t1 (s1 int); +create view v1 as select * from t1; +create view v2 as select * from v1; +-- error 1146 +alter view v1 as select * from v2; +-- error 1146 +alter view v1 as select * from v1; +-- error 1146 +create or replace view v1 as select * from v2; +-- error 1146 +create or replace view v1 as select * from v1; +drop view v2,v1; +drop table t1; + +# +# check altering differ options +# +create table t1 (a int); +create view v1 as select * from t1; +show create view v1; +alter algorithm=undefined view v1 as select * from t1 with check option; +show create view v1; +alter algorithm=merge view v1 as select * from t1 with cascaded check option; +show create view v1; +alter algorithm=temptable view v1 as select * from t1; +show create view v1; +drop view v1; +drop table t1; + +# +# updating view with subquery in the WHERE clause +# +create table t1 (s1 int); +create table t2 (s1 int); +create view v2 as select * from t2 where s1 in (select s1 from t1); +insert into v2 values (5); +insert into t1 values (5); +select * from v2; +update v2 set s1 = 0; +select * from v2; +select * from t2; +# check it with check option +alter view v2 as select * from t2 where s1 in (select s1 from t1) with check option; +insert into v2 values (5); +-- error 1369 +update v2 set s1 = 1; +insert into t1 values (1); +update v2 set s1 = 1; +select * from v2; +select * from t2; +# scheck how VIEWs with subqueries work with prepared statements +prepare stmt1 from "select * from v2;"; +execute stmt1; +insert into t1 values (0); +execute stmt1; +deallocate prepare stmt1; +drop view v2; +drop table t1, t2; + +# +# test of substring_index with view +# +create table t1 (t time); +create view v1 as select substring_index(t,':',2) as t from t1; +insert into t1 (t) values ('12:24:10'); +select substring_index(t,':',2) from t1; +select substring_index(t,':',2) from v1; +drop view v1; +drop table t1; + +# +# test of cascaded check option for whiew without WHERE clause +# +create table t1 (s1 tinyint); +create view v1 as select * from t1 where s1 <> 0 with local check option; +create view v2 as select * from v1 with cascaded check option; +-- error 1369 +insert into v2 values (0); +drop view v2, v1; +drop table t1; + +# +# inserting single value with check option failed always get error +# +create table t1 (s1 int); +create view v1 as select * from t1 where s1 < 5 with check option; +#single value +-- error 1369 +insert ignore into v1 values (6); +#several values +insert ignore into v1 values (6),(3); +select * from t1; +drop view v1; +drop table t1; + +# +# changing value by trigger and CHECK OPTION +# +create table t1 (s1 tinyint); +create trigger t1_bi before insert on t1 for each row set new.s1 = 500; +create view v1 as select * from t1 where s1 <> 127 with check option; +-- error 1369 +insert into v1 values (0); +select * from v1; +select * from t1; +drop trigger t1_bi; +drop view v1; +drop table t1; + +# +# CASCADED should be used for all underlaying VIEWs +# +create table t1 (s1 tinyint); +create view v1 as select * from t1 where s1 <> 0; +create view v2 as select * from v1 where s1 <> 1 with cascaded check option; +-- error 1369 +insert into v2 values (0); +select * from v2; +select * from t1; +drop view v2, v1; +drop table t1; + +# +# LOAD DATA with view and CHECK OPTION +# +# fixed length fields +create table t1 (a int, b char(10)); +create view v1 as select * from t1 where a != 0 with check option; +-- error 1369 +load data infile '../std_data_ln/loaddata3.dat' into table v1 fields terminated by '' enclosed by '' ignore 1 lines; +select * from t1; +select * from v1; +delete from t1; +load data infile '../std_data_ln/loaddata3.dat' ignore into table v1 fields terminated by '' enclosed by '' ignore 1 lines; +select * from t1; +select * from v1; +drop view v1; +drop table t1; +# variable length fields +create table t1 (a text, b text); +create view v1 as select * from t1 where a <> 'Field A' with check option; +-- error 1369 +load data infile '../std_data_ln/loaddata2.dat' into table v1 fields terminated by ',' enclosed by ''''; +select concat('|',a,'|'), concat('|',b,'|') from t1; +select concat('|',a,'|'), concat('|',b,'|') from v1; +delete from t1; +load data infile '../std_data_ln/loaddata2.dat' ignore into table v1 fields terminated by ',' enclosed by ''''; +select concat('|',a,'|'), concat('|',b,'|') from t1; +select concat('|',a,'|'), concat('|',b,'|') from v1; +drop view v1; +drop table t1; + +# +# Trys update table from which we select using views and subqueries +# +create table t1 (s1 smallint); +create view v1 as select * from t1 where 20 < (select (s1) from t1); +-- error 1471 +insert into v1 values (30); +create view v2 as select * from t1; +create view v3 as select * from t1 where 20 < (select (s1) from v2); +-- error 1471 +insert into v3 values (30); +create view v4 as select * from v2 where 20 < (select (s1) from t1); +-- error 1471 +insert into v4 values (30); +drop view v4, v3, v2, v1; +drop table t1; + +# +# CHECK TABLE with VIEW +# +create table t1 (a int); +create view v1 as select * from t1; +check table t1,v1; +check table v1,t1; +drop table t1; +check table v1; +drop view v1; + +# +# merge of VIEW with several tables +# +create table t1 (a int); +create table t2 (a int); +create table t3 (a int); +insert into t1 values (1), (2), (3); +insert into t2 values (1), (3); +insert into t3 values (1), (2), (4); +# view over tables +create view v3 (a,b) as select t1.a as a, t2.a as b from t1 left join t2 on (t1.a=t2.a); +select * from t3 left join v3 on (t3.a = v3.a); +explain extended select * from t3 left join v3 on (t3.a = v3.a); +# view over views +create view v1 (a) as select a from t1; +create view v2 (a) as select a from t2; +create view v4 (a,b) as select v1.a as a, v2.a as b from v1 left join v2 on (v1.a=v2.a); +select * from t3 left join v4 on (t3.a = v4.a); +explain extended select * from t3 left join v4 on (t3.a = v4.a); +# PS with view over views +prepare stmt1 from "select * from t3 left join v4 on (t3.a = v4.a);"; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; +drop view v4,v3,v2,v1; +drop tables t1,t2,t3; + +# +# updating of join view +# +create table t1 (a int, primary key (a), b int); +create table t2 (a int, primary key (a)); +insert into t1 values (1,100), (2,200); +insert into t2 values (1), (3); +# legal view for update +create view v3 (a,b) as select t1.a as a, t2.a as b from t1, t2; +update v3 set a= 10 where a=1; +select * from t1; +select * from t2; +# view without primary key +create view v2 (a,b) as select t1.b as a, t2.a as b from t1, t2; +set updatable_views_with_limit=NO; +-- error 1288 +update v2 set a= 10 where a=200 limit 1; +set updatable_views_with_limit=DEFAULT; +# just view selects +select * from v3; +select * from v2; +# prepare statement with updating join view +set @a= 10; +set @b= 100; +prepare stmt1 from "update v3 set a= ? where a=?"; +execute stmt1 using @a,@b; +select * from v3; +set @a= 300; +set @b= 10; +execute stmt1 using @a,@b; +select * from v3; +deallocate prepare stmt1; +drop view v3,v2; +drop tables t1,t2; + +# +# inserting/deleting join view +# +create table t1 (a int, primary key (a), b int); +create table t2 (a int, primary key (a), b int); +insert into t2 values (1000, 2000); +create view v3 (a,b) as select t1.a as a, t2.a as b from t1, t2; +# inserting into join view without field list +-- error 1394 +insert into v3 values (1,2); +-- error 1394 +insert into v3 select * from t2; +# inserting in several tables of join view +-- error 1393 +insert into v3(a,b) values (1,2); +-- error 1393 +insert into v3(a,b) select * from t2; +# correct inserts into join view +insert into v3(a) values (1); +insert into v3(b) values (10); +insert into v3(a) select a from t2; +insert into v3(b) select b from t2; +insert into v3(a) values (1) on duplicate key update a=a+10000+VALUES(a); +select * from t1; +select * from t2; +# try delete from join view +-- error 1395 +delete from v3; +-- error 1395 +delete v3,t1 from v3,t1; +-- error 1395 +delete t1,v3 from t1,v3; +# delete from t1 just to reduce result set size +delete from t1; +# prepare statement with insert join view +prepare stmt1 from "insert into v3(a) values (?);"; +set @a= 100; +execute stmt1 using @a; +set @a= 300; +execute stmt1 using @a; +deallocate prepare stmt1; +prepare stmt1 from "insert into v3(a) select ?;"; +set @a= 101; +execute stmt1 using @a; +set @a= 301; +execute stmt1 using @a; +deallocate prepare stmt1; +select * from v3; + +drop view v3; +drop tables t1,t2; + +# +# View field names should be case insensitive +# +create table t1(f1 int); +create view v1 as select f1 from t1; +select * from v1 where F1 = 1; +drop view v1; +drop table t1; + +# +# Resolving view fields in subqueries in VIEW (Bug #6394) +# +create table t1(c1 int); +create table t2(c2 int); +insert into t1 values (1),(2),(3); +insert into t2 values (1); +SELECT c1 FROM t1 WHERE c1 IN (SELECT c2 FROM t2); +SELECT c1 FROM t1 WHERE EXISTS (SELECT c2 FROM t2 WHERE c2 = c1); +create view v1 as SELECT c1 FROM t1 WHERE c1 IN (SELECT c2 FROM t2); +create view v2 as SELECT c1 FROM t1 WHERE EXISTS (SELECT c2 FROM t2 WHERE c2 = c1); +select * from v1; +select * from v2; +select * from (select c1 from v2) X; +drop view v2, v1; +drop table t1, t2; + +# +# view over other view setup (BUG#7433) +# +CREATE TABLE t1 (C1 INT, C2 INT); +CREATE TABLE t2 (C2 INT); +CREATE VIEW v1 AS SELECT C2 FROM t2; +CREATE VIEW v2 AS SELECT C1 FROM t1 LEFT OUTER JOIN v1 USING (C2); +SELECT * FROM v2; +drop view v2, v1; +drop table t1, t2; + +# +# view and group_concat() (BUG#7116) +# +create table t1 (col1 char(5),col2 int,col3 int); +insert into t1 values ('one',10,25), ('two',10,50), ('two',10,50), ('one',20,25), ('one',30,25); +create view v1 as select * from t1; +select col1,group_concat(col2,col3) from t1 group by col1; +select col1,group_concat(col2,col3) from v1 group by col1; +drop view v1; +drop table t1; + +# +# Item_ref resolved as view field (BUG#6894) +# +create table t1 (s1 int, s2 char); +create view v1 as select s1, s2 from t1; +-- error 1054 +select s2 from v1 vq1 where 2 = (select count(*) from v1 vq2 having vq1.s2 = vq2.s2); +select s2 from v1 vq1 where 2 = (select count(*) aa from v1 vq2 having vq1.s2 = aa); +drop view v1; +drop table t1; + +# +# Test case for bug #9398 CREATE TABLE with SELECT from a multi-table view +# +CREATE TABLE t1 (a1 int); +CREATE TABLE t2 (a2 int); +INSERT INTO t1 VALUES (1), (2), (3), (4); +INSERT INTO t2 VALUES (1), (2), (3); +CREATE VIEW v1(a,b) AS SELECT a1,a2 FROM t1 JOIN t2 ON a1=a2 WHERE a1>1; + +SELECT * FROM v1; +CREATE TABLE t3 SELECT * FROM v1; +SELECT * FROM t3; + +DROP VIEW v1; +DROP TABLE t1,t2,t3; + +# +# Test for BUG#8703 "insert into table select from view crashes" +# +create table t1 (a int); +create table t2 like t1; +create table t3 like t1; +create view v1 as select t1.a x, t2.a y from t1 join t2 where t1.a=t2.a; +insert into t3 select x from v1; +insert into t2 select x from v1; +drop view v1; +drop table t1,t2,t3; + +# +# Test for BUG #6106: query over a view using subquery for the underlying table +# + +CREATE TABLE t1 (col1 int PRIMARY KEY, col2 varchar(10)); +INSERT INTO t1 VALUES(1,'trudy'); +INSERT INTO t1 VALUES(2,'peter'); +INSERT INTO t1 VALUES(3,'sanja'); +INSERT INTO t1 VALUES(4,'monty'); +INSERT INTO t1 VALUES(5,'david'); +INSERT INTO t1 VALUES(6,'kent'); +INSERT INTO t1 VALUES(7,'carsten'); +INSERT INTO t1 VALUES(8,'ranger'); +INSERT INTO t1 VALUES(10,'matt'); +CREATE TABLE t2 (col1 int, col2 int, col3 char(1)); +INSERT INTO t2 VALUES (1,1,'y'); +INSERT INTO t2 VALUES (1,2,'y'); +INSERT INTO t2 VALUES (2,1,'n'); +INSERT INTO t2 VALUES (3,1,'n'); +INSERT INTO t2 VALUES (4,1,'y'); +INSERT INTO t2 VALUES (4,2,'n'); +INSERT INTO t2 VALUES (4,3,'n'); +INSERT INTO t2 VALUES (6,1,'n'); +INSERT INTO t2 VALUES (8,1,'y'); + +CREATE VIEW v1 AS SELECT * FROM t1; + +SELECT a.col1,a.col2,b.col2,b.col3 + FROM t1 a LEFT JOIN t2 b ON a.col1=b.col1 + WHERE b.col2 IS NULL OR + b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1); + +SELECT a.col1,a.col2,b.col2,b.col3 + FROM v1 a LEFT JOIN t2 b ON a.col1=b.col1 + WHERE b.col2 IS NULL OR + b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1); + +CREATE VIEW v2 AS SELECT * FROM t2; + +SELECT a.col1,a.col2,b.col2,b.col3 + FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1 + WHERE b.col2 IS NULL OR + b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1); + +# Tests from the report for bug #6107 + +SELECT a.col1,a.col2,b.col2,b.col3 + FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1 + WHERE a.col1 IN (1,5,9) AND + (b.col2 IS NULL OR + b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1)); + +CREATE VIEW v3 AS SELECT * FROM t1 WHERE col1 IN (1,5,9); + +SELECT a.col1,a.col2,b.col2,b.col3 + FROM v2 b RIGHT JOIN v3 a ON a.col1=b.col1 + WHERE b.col2 IS NULL OR + b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1); + +DROP VIEW v1,v2,v3; +DROP TABLE t1,t2; + +# +# BUG#8490 Select from views containing subqueries causes server to hang +# forever. +# +create table t1 as select 1 A union select 2 union select 3; +create table t2 as select * from t1; +create view v1 as select * from t1 where a in (select * from t2); +select * from v1 A, v1 B where A.a = B.a; +create table t3 as select a a,a b from t2; +create view v2 as select * from t3 where + a in (select * from t1) or b in (select * from t2); +select * from v2 A, v2 B where A.a = B.b; +drop view v1, v2; +drop table t1, t2, t3; + +# +# Test case for bug #8528: select from view over multi-table view +# +CREATE TABLE t1 (a int); +CREATE TABLE t2 (b int); +INSERT INTO t1 VALUES (1), (2), (3), (4); +INSERT INTO t2 VALUES (4), (2); + +CREATE VIEW v1 AS SELECT * FROM t1,t2 WHERE t1.a=t2.b; +SELECT * FROM v1; +CREATE VIEW v2 AS SELECT * FROM v1; +SELECT * FROM v2; + +DROP VIEW v2,v1; + +DROP TABLE t1, t2; +# +# Correct restoring view name in SP table locking BUG#9758 +# +create table t1 (a int); +create view v1 as select sum(a) from t1 group by a; +delimiter //; +create procedure p1() +begin +select * from v1; +end// +delimiter ;// +call p1(); +call p1(); +drop procedure p1; +drop view v1; +drop table t1; + +# +# Bug#7422 "order by" doesn't work +# +CREATE TABLE t1(a char(2) primary key, b char(2)); +CREATE TABLE t2(a char(2), b char(2), index i(a)); +INSERT INTO t1 VALUES ('a','1'), ('b','2'); +INSERT INTO t2 VALUES ('a','5'), ('a','6'), ('b','5'), ('b','6'); +CREATE VIEW v1 AS + SELECT t1.b as c, t2.b as d FROM t1,t2 WHERE t1.a=t2.a; +SELECT d, c FROM v1 ORDER BY d,c; +DROP VIEW v1; +DROP TABLE t1, t2; +# +# using sum(distinct ) & avg(distinct ) in views (BUG#7015) +# +create table t1 (s1 int); +create view v1 as select sum(distinct s1) from t1; +select * from v1; +drop view v1; +create view v1 as select avg(distinct s1) from t1; +select * from v1; +drop view v1; +drop table t1; + +# +# using cast(... as decimal) in views (BUG#11387); +# +create view v1 as select cast(1 as decimal); +select * from v1; +drop view v1; + +# +# Bug#11298 insert into select from VIEW produces incorrect result when +# using ORDER BY +create table t1(f1 int); +create table t2(f2 int); +insert into t1 values(1),(2),(3); +insert into t2 values(1),(2),(3); +create view v1 as select * from t1,t2 where f1=f2; +create table t3 (f1 int, f2 int); +insert into t3 select * from v1 order by 1; +select * from t3; +drop view v1; +drop table t1,t2,t3; + +# +# Generation unique names for columns, and correct names check (BUG#7448) +# +# names with ' and \ +create view v1 as select '\\','\\shazam'; +select * from v1; +drop view v1; +create view v1 as select '\'','\shazam'; +select * from v1; +drop view v1; +# autogenerated names differ by case only +create view v1 as select 'k','K'; +select * from v1; +drop view v1; +create table t1 (s1 int); +# same autogenerated names +create view v1 as select s1, 's1' from t1; +select * from v1; +drop view v1; +create view v1 as select 's1', s1 from t1; +select * from v1; +drop view v1; +# set name as one of expected autogenerated +create view v1 as select 's1', s1, 1 as My_exp_s1 from t1; +select * from v1; +drop view v1; +create view v1 as select 1 as My_exp_s1, 's1', s1 from t1; +select * from v1; +drop view v1; +# set name conflict with autogenerated names +create view v1 as select 1 as s1, 's1', 's1' from t1; +select * from v1; +drop view v1; +create view v1 as select 's1', 's1', 1 as s1 from t1; +select * from v1; +drop view v1; +# underlying field name conflict with autogenerated names +create view v1 as select s1, 's1', 's1' from t1; +select * from v1; +drop view v1; +create view v1 as select 's1', 's1', s1 from t1; +select * from v1; +drop view v1; +# underlying field name conflict with set name +-- error 1060 +create view v1 as select 1 as s1, 's1', s1 from t1; +-- error 1060 +create view v1 as select 's1', s1, 1 as s1 from t1; +drop table t1; +# set names differ by case only +-- error 1060 +create view v1(k, K) as select 1,2; + +# +# using time_format in view (BUG#7521) +# +create view v1 as SELECT TIME_FORMAT(SEC_TO_TIME(3600),'%H:%i') as t; +select * from v1; +drop view v1; + +# +# evaluation constant functions in WHERE (BUG#4663) +# +create table t1 (a timestamp default now()); +create table t2 (b timestamp default now()); +create view v1 as select a,b,t1.a < now() from t1,t2 where t1.a < now(); +SHOW CREATE VIEW v1; +drop view v1; +drop table t1, t2; +CREATE TABLE t1 ( a varchar(50) ); +CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = CURRENT_USER(); +SHOW CREATE VIEW v1; +DROP VIEW v1; +CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = VERSION(); +SHOW CREATE VIEW v1; +DROP VIEW v1; +CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = DATABASE(); +SHOW CREATE VIEW v1; +DROP VIEW v1; +DROP TABLE t1; + +# +# checking views after some view with error (BUG#11337) +# +CREATE TABLE t1 (col1 time); +CREATE TABLE t2 (col1 time); +CREATE VIEW v1 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1; +CREATE VIEW v2 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2; +CREATE VIEW v3 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1; +CREATE VIEW v4 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2; +CREATE VIEW v5 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1; +CREATE VIEW v6 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2; +DROP TABLE t1; +CHECK TABLE v1, v2, v3, v4, v5, v6; +drop view v1, v2, v3, v4, v5, v6; +drop table t2; + +--disable_warnings +drop function if exists f1; +drop function if exists f2; +--enable_warnings +CREATE TABLE t1 (col1 time); +CREATE TABLE t2 (col1 time); +CREATE TABLE t3 (col1 time); +create function f1 () returns int return (select max(col1) from t1); +create function f2 () returns int return (select max(col1) from t2); +CREATE VIEW v1 AS SELECT f1() FROM t3; +CREATE VIEW v2 AS SELECT f2() FROM t3; +CREATE VIEW v3 AS SELECT f1() FROM t3; +CREATE VIEW v4 AS SELECT f2() FROM t3; +CREATE VIEW v5 AS SELECT f1() FROM t3; +CREATE VIEW v6 AS SELECT f2() FROM t3; +drop function f1; +CHECK TABLE v1, v2, v3, v4, v5, v6; +create function f1 () returns int return (select max(col1) from t1); +DROP TABLE t1; +CHECK TABLE v1, v2, v3, v4, v5, v6; +drop function f1; +drop function f2; +drop view v1, v2, v3, v4, v5, v6; +drop table t2,t3; + +# +# bug #11325 Wrong date comparison in views +# +create table t1 (f1 date); +insert into t1 values ('2005-01-01'),('2005-02-02'); +create view v1 as select * from t1; +select * from v1 where f1='2005.02.02'; +select * from v1 where '2005.02.02'=f1; +drop view v1; +drop table t1; + +# +# using encrypt & substring_index in view (BUG#7024) +# +CREATE VIEW v1 AS SELECT ENCRYPT("dhgdhgd"); +disable_result_log; +SELECT * FROM v1; +enable_result_log; +drop view v1; +CREATE VIEW v1 AS SELECT SUBSTRING_INDEX("dkjhgd:kjhdjh", ":", 1); +SELECT * FROM v1; +drop view v1; + +# +# hide underlying tables names in case of imposibility to update (BUG#10773) +# +create table t1 (f59 int, f60 int, f61 int); +insert into t1 values (19,41,32); +create view v1 as select f59, f60 from t1 where f59 in + (select f59 from t1); +-- error 1288 +update v1 set f60=2345; +-- error 1443 +update t1 set f60=(select max(f60) from v1); +drop view v1; +drop table t1; + +# +# Using var_samp with view (BUG#10651) +# +create table t1 (s1 int); +create view v1 as select var_samp(s1) from t1; +show create view v1; +drop view v1; +drop table t1; + +# +# Correct inserting data check (absence of default value) for view +# underlying tables (BUG#6443) +# +set sql_mode='strict_all_tables'; +CREATE TABLE t1 (col1 INT NOT NULL, col2 INT NOT NULL); +CREATE VIEW v1 (vcol1) AS SELECT col1 FROM t1; +CREATE VIEW v2 (vcol1) AS SELECT col1 FROM t1 WHERE col2 > 2; +-- error 1364 +INSERT INTO t1 (col1) VALUES(12); +-- error 1423 +INSERT INTO v1 (vcol1) VALUES(12); +-- error 1423 +INSERT INTO v2 (vcol1) VALUES(12); +set sql_mode=default; +drop view v2,v1; +drop table t1; + +# +# Bug#11399 Use an alias in a select statement on a view +# +create table t1 (f1 int); +insert into t1 values (1); +create view v1 as select f1 from t1; +select f1 as alias from v1; +drop view v1; +drop table t1; + +# +# Test for bug #6120: SP cache to be invalidated when altering a view +# + +CREATE TABLE t1 (s1 int, s2 int); +INSERT INTO t1 VALUES (1,2); +CREATE VIEW v1 AS SELECT s2 AS s1, s1 AS s2 FROM t1; +SELECT * FROM v1; +CREATE PROCEDURE p1 () SELECT * FROM v1; +CALL p1(); +ALTER VIEW v1 AS SELECT s1 AS s1, s2 AS s2 FROM t1; +CALL p1(); +DROP VIEW v1; +CREATE VIEW v1 AS SELECT s2 AS s1, s1 AS s2 FROM t1; +CALL p1(); + +DROP PROCEDURE p1; +DROP VIEW v1; +DROP TABLE t1; + +# +# Test for bug #11709 View was ordered by wrong column +# +create table t1 (f1 int, f2 int); +create view v1 as select f1 as f3, f2 as f1 from t1; +insert into t1 values (1,3),(2,1),(3,2); +select * from v1 order by f1; +drop view v1; +drop table t1; + +# +# Test for bug #11771: wrong query_id in SELECT * FROM <view> +# +CREATE TABLE t1 (f1 char); +INSERT INTO t1 VALUES ('A'); +CREATE VIEW v1 AS SELECT * FROM t1; + +INSERT INTO t1 VALUES('B'); +SELECT * FROM v1; +SELECT * FROM t1; + +DROP VIEW v1; +DROP TABLE t1; + +# +# opening table in correct locking mode (BUG#9597) +# +CREATE TABLE t1 ( bug_table_seq INTEGER NOT NULL); +CREATE OR REPLACE VIEW v1 AS SELECT * from t1; +DROP PROCEDURE IF EXISTS p1; +delimiter //; +CREATE PROCEDURE p1 ( ) +BEGIN + DO (SELECT @next := IFNULL(max(bug_table_seq),0) + 1 FROM v1); + INSERT INTO t1 VALUES (1); +END // +delimiter ;// +CALL p1(); +DROP PROCEDURE p1; +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #11335 View redefines column types +# +create table t1 (f1 tinyint(1), f2 char(1), f3 varchar(1), f4 geometry, f5 datetime); +create view v1 as select * from t1; +desc v1; +drop view v1; +drop table t1; + +# +# Bug #11760 Typo in Item_func_add_time::print() results in NULLs returned +# subtime() in view +create table t1(f1 datetime); +insert into t1 values('2005.01.01 12:0:0'); +create view v1 as select f1, subtime(f1, '1:1:1') as sb from t1; +select * from v1; +drop view v1; +drop table t1; + +# +# Test for bug #11412: query over a multitable view with GROUP_CONCAT +# +CREATE TABLE t1 ( + aid int PRIMARY KEY, + fn varchar(20) NOT NULL, + ln varchar(20) NOT NULL +); +CREATE TABLE t2 ( + aid int NOT NULL, + pid int NOT NULL +); +INSERT INTO t1 VALUES(1,'a','b'), (2,'c','d'); +INSERT INTO t2 values (1,1), (2,1), (2,2); + +CREATE VIEW v1 AS SELECT t1.*,t2.pid FROM t1,t2 WHERE t1.aid = t2.aid; + +SELECT pid,GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) FROM t1,t2 + WHERE t1.aid = t2.aid GROUP BY pid; +SELECT pid,GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) FROM v1 GROUP BY pid; + +DROP VIEW v1; +DROP TABLE t1,t2; + +# +# Test for bug #12382: SELECT * FROM view after INSERT command +# + +CREATE TABLE t1 (id int PRIMARY KEY, f varchar(255)); +CREATE VIEW v1 AS SELECT id, f FROM t1 WHERE id <= 2; +INSERT INTO t1 VALUES (2, 'foo2'); +INSERT INTO t1 VALUES (1, 'foo1'); + +SELECT * FROM v1; +SELECT * FROM v1; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Test for bug #12470: crash for a simple select from a view defined +# as a join over 5 tables + +CREATE TABLE t1 (pk int PRIMARY KEY, b int); +CREATE TABLE t2 (pk int PRIMARY KEY, fk int, INDEX idx(fk)); +CREATE TABLE t3 (pk int PRIMARY KEY, fk int, INDEX idx(fk)); +CREATE TABLE t4 (pk int PRIMARY KEY, fk int, INDEX idx(fk)); +CREATE TABLE t5 (pk int PRIMARY KEY, fk int, INDEX idx(fk)); +CREATE VIEW v1 AS + SELECT t1.pk as a FROM t1,t2,t3,t4,t5 + WHERE t1.b IS NULL AND + t1.pk=t2.fk AND t2.pk=t3.fk AND t3.pk=t4.fk AND t4.pk=t5.fk; + +SELECT a FROM v1; + +DROP VIEW v1; +DROP TABLE t1,t2,t3,t4,t5; + +# +# Bug #12298 Typo in function name results in erroneous view being created. +# +create view v1 as select timestampdiff(day,'1997-01-01 00:00:00','1997-01-02 00:00:00') as f1; +select * from v1; +drop view v1; + +# +# repeatable CREATE VIEW statement BUG#12468 +# +create table t1(a int); +create procedure p1() create view v1 as select * from t1; +drop table t1; +-- error 1146 +call p1(); +-- error 1146 +call p1(); +drop procedure p1; + +# +# Bug #10624 Views with multiple UNION and UNION ALL produce incorrect results +# +create table t1 (f1 int); +create table t2 (f1 int); +insert into t1 values (1); +insert into t2 values (2); +create view v1 as select * from t1 union select * from t2 union all select * from t2; +select * from v1; +drop view v1; +drop table t1,t2; +# +# Test for bug #10970: view referring a temporary table indirectly +# + +CREATE TEMPORARY TABLE t1 (a int); +CREATE FUNCTION f1 () RETURNS int RETURN (SELECT COUNT(*) FROM t1); +-- error 1352 +CREATE VIEW v1 AS SELECT f1(); + +DROP FUNCTION f1; +DROP TABLE t1; + +# +# BUG #12533 (crash on DESCRIBE <view> after renaming base table column) +# +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP VIEW IF EXISTS v1; +--enable_warnings + +CREATE TABLE t1 (f4 CHAR(5)); +CREATE VIEW v1 AS SELECT * FROM t1; +DESCRIBE v1; + +ALTER TABLE t1 CHANGE COLUMN f4 f4x CHAR(5); +--error 1356 +DESCRIBE v1; +DROP TABLE t1; +DROP VIEW v1; + +# +# Bug #12489 wrongly printed strcmp() function results in creation of broken +# view +create table t1 (f1 char); +create view v1 as select strcmp(f1,'a') from t1; +select * from v1; +drop view v1; +drop table t1; + +# +# Bug #12922 if(sum(),...) with group from view returns wrong results +# +create table t1 (f1 int, f2 int,f3 int); +insert into t1 values (1,10,20),(2,0,0); +create view v1 as select * from t1; +select if(sum(f1)>1,f2,f3) from v1 group by f1; +drop view v1; +drop table t1; +# BUG#12941 +# +--disable_warnings +create table t1 ( + r_object_id char(16) NOT NULL, + group_name varchar(32) NOT NULL +) engine = InnoDB; + +create table t2 ( + r_object_id char(16) NOT NULL, + i_position int(11) NOT NULL, + users_names varchar(32) default NULL +) Engine = InnoDB; +--enable_warnings + +create view v1 as select r_object_id, group_name from t1; +create view v2 as select r_object_id, i_position, users_names from t2; + +create unique index r_object_id on t1(r_object_id); +create index group_name on t1(group_name); +create unique index r_object_id_i_position on t2(r_object_id,i_position); +create index users_names on t2(users_names); + +insert into t1 values('120001a080000542','tstgroup1'); +insert into t2 values('120001a080000542',-1, 'guser01'); +insert into t2 values('120001a080000542',-2, 'guser02'); + +select v1.r_object_id, v2.users_names from v1, v2 +where (v1.group_name='tstgroup1') and v2.r_object_id=v1.r_object_id +order by users_names; + +drop view v1, v2; +drop table t1, t2; + +# Bug #6808 - Views: CREATE VIEW v ... FROM t AS v fails +# + +create table t1 (s1 int); +create view abc as select * from t1 as abc; +drop table t1; +drop view abc; + +# +# Bug #12993 View column rename broken in subselect +# +create table t1(f1 char(1)); +create view v1 as select * from t1; +select * from (select f1 as f2 from v1) v where v.f2='a'; +drop view v1; +drop table t1; + +# +# Bug #11416 Server crash if using a view that uses function convert_tz +# +create view v1 as SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET'); +select * from v1; +drop view v1; + +# +# Bugs #12963, #13000: wrong creation of VIEW with DAYNAME, DAYOFWEEK, and WEEKDAY +# + +CREATE TABLE t1 (date DATE NOT NULL); +INSERT INTO t1 VALUES ('2005-09-06'); + +CREATE VIEW v1 AS SELECT DAYNAME(date) FROM t1; +SHOW CREATE VIEW v1; + +CREATE VIEW v2 AS SELECT DAYOFWEEK(date) FROM t1; +SHOW CREATE VIEW v2; + +CREATE VIEW v3 AS SELECT WEEKDAY(date) FROM t1; +SHOW CREATE VIEW v3; + +SELECT DAYNAME('2005-09-06'); +SELECT DAYNAME(date) FROM t1; +SELECT * FROM v1; + +SELECT DAYOFWEEK('2005-09-06'); +SELECT DAYOFWEEK(date) FROM t1; +SELECT * FROM v2; + +SELECT WEEKDAY('2005-09-06'); +SELECT WEEKDAY(date) FROM t1; +SELECT * FROM v3; + +DROP TABLE t1; +DROP VIEW v1, v2, v3; + +# +# Bug #13411: crash when using non-qualified view column in HAVING clause +# + +CREATE TABLE t1 ( a int, b int ); +INSERT INTO t1 VALUES (1,1),(2,2),(3,3); +CREATE VIEW v1 AS SELECT a,b FROM t1; +SELECT t1.a FROM t1 GROUP BY t1.a HAVING a > 1; +SELECT v1.a FROM v1 GROUP BY v1.a HAVING a > 1; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #13410: failed name resolution for qualified view column in HAVING +# + +CREATE TABLE t1 ( a int, b int ); +INSERT INTO t1 VALUES (1,1),(2,2),(3,3); +CREATE VIEW v1 AS SELECT a,b FROM t1; +SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > 1; +SELECT v1.a FROM v1 GROUP BY v1.a HAVING v1.a > 1; +SELECT t_1.a FROM t1 AS t_1 GROUP BY t_1.a HAVING t_1.a IN (1,2,3); +SELECT v_1.a FROM v1 AS v_1 GROUP BY v_1.a HAVING v_1.a IN (1,2,3); + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #13327 view wasn't using index for const condition +# + +CREATE TABLE t1 (a INT, b INT, INDEX(a,b)); +CREATE TABLE t2 LIKE t1; +CREATE TABLE t3 (a INT); +INSERT INTO t1 VALUES (1,1),(2,2),(3,3); +INSERT INTO t2 VALUES (1,1),(2,2),(3,3); +INSERT INTO t3 VALUES (1),(2),(3); +CREATE VIEW v1 AS SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a AND t1.b=t2.b; +CREATE VIEW v2 AS SELECT t3.* FROM t1,t3 WHERE t1.a=t3.a; +EXPLAIN SELECT t1.* FROM t1 JOIN t2 WHERE t1.a=t2.a AND t1.b=t2.b AND t1.a=1; +EXPLAIN SELECT * FROM v1 WHERE a=1; +EXPLAIN SELECT * FROM v2 WHERE a=1; +DROP VIEW v1,v2; +DROP TABLE t1,t2,t3; + +# +# Bug #13622 Wrong view .frm created if some field's alias contain \n +# +create table t1 (f1 int); +create view v1 as select t1.f1 as '123 +456' from t1; +select * from v1; +drop view v1; +drop table t1; + +# Bug #14466 lost sort order in GROUP_CONCAT() in a view +# +create table t1 (f1 int, f2 int); +insert into t1 values(1,1),(1,2),(1,3); +create view v1 as select f1 ,group_concat(f2 order by f2 asc) from t1 group by f1; +create view v2 as select f1 ,group_concat(f2 order by f2 desc) from t1 group by f1; +select * from v1; +select * from v2; +drop view v1,v2; +drop table t1; + +# +# BUG#14026 Crash on second PS execution when using views +# +create table t1 (x int, y int); +create table t2 (x int, y int, z int); +create table t3 (x int, y int, z int); +create table t4 (x int, y int, z int); + +create view v1 as +select t1.x +from ( + (t1 join t2 on ((t1.y = t2.y))) + join + (t3 left join t4 on (t3.y = t4.y) and (t3.z = t4.z)) +); + +prepare stmt1 from "select count(*) from v1 where x = ?"; +set @parm1=1; + +execute stmt1 using @parm1; +execute stmt1 using @parm1; +drop view v1; +drop table t1,t2,t3,t4; + +# +# Bug #14540: OPTIMIZE, ANALYZE, REPAIR applied to not a view +# + +CREATE TABLE t1(id INT); +CREATE VIEW v1 AS SELECT id FROM t1; + +OPTIMIZE TABLE v1; +ANALYZE TABLE v1; +REPAIR TABLE v1; + +DROP TABLE t1; +OPTIMIZE TABLE v1; + +DROP VIEW v1; + + +# +# BUG#14719: Views DEFINER grammar is incorrect +# + +create definer = current_user() sql security invoker view v1 as select 1; +show create view v1; +drop view v1; + +create definer = current_user sql security invoker view v1 as select 1; +show create view v1; +drop view v1; + +# +# Bug #14816 test_if_order_by_key() expected only Item_fields. +# +create table t1 (id INT, primary key(id)); +insert into t1 values (1),(2); +create view v1 as select * from t1; +explain select id from v1 order by id; +drop view v1; +drop table t1; + +# +# Bug #14850 Item_ref's values wasn't updated +# +create table t1(f1 int, f2 int); +insert into t1 values (null, 10), (null,2); +select f1, sum(f2) from t1 group by f1; +create view v1 as select * from t1; +select f1, sum(f2) from v1 group by f1; +drop view v1; +drop table t1; + +# +# BUG#14885: incorrect SOURCE in view created in a procedure +# TODO: here SOURCE string must be shown when it will be possible +# +--disable_warnings +drop procedure if exists p1; +--enable_warnings +delimiter //; +create procedure p1 () deterministic +begin +create view v1 as select 1; +end; +// +delimiter ;// +call p1(); +show create view v1; +drop view v1; +drop procedure p1; + +# +# BUG#15096: using function with view for view creation +# +CREATE VIEW v1 AS SELECT 42 AS Meaning; +--disable_warnings +DROP FUNCTION IF EXISTS f1; +--enable_warnings +DELIMITER //; +CREATE FUNCTION f1() RETURNS INTEGER +BEGIN + DECLARE retn INTEGER; + SELECT Meaning FROM v1 INTO retn; + RETURN retn; +END +// +DELIMITER ;// +CREATE VIEW v2 AS SELECT f1(); +select * from v2; +drop view v2,v1; +drop function f1; + +# +# Bug#14861: aliased column names are not preserved. +# +create table t1 (id numeric, warehouse_id numeric); +create view v1 as select id from t1; +create view v2 as +select t1.warehouse_id, v1.id as receipt_id +from t1, v1 where t1.id = v1.id; + +insert into t1 (id, warehouse_id) values(3, 2); +insert into t1 (id, warehouse_id) values(4, 2); +insert into t1 (id, warehouse_id) values(5, 1); + +select v2.receipt_id as alias1, v2.receipt_id as alias2 from v2 +order by v2.receipt_id; + +drop view v2, v1; +drop table t1; + +# +# Bug#16016: MIN/MAX optimization for views +# + +CREATE TABLE t1 (a int PRIMARY KEY, b int); +INSERT INTO t1 VALUES (2,20), (3,10), (1,10), (0,30), (5,10); + +CREATE VIEW v1 AS SELECT * FROM t1; + +SELECT MAX(a) FROM t1; +SELECT MAX(a) FROM v1; + +EXPLAIN SELECT MAX(a) FROM t1; +EXPLAIN SELECT MAX(a) FROM v1; + +SELECT MIN(a) FROM t1; +SELECT MIN(a) FROM v1; + +EXPLAIN SELECT MIN(a) FROM t1; +EXPLAIN SELECT MIN(a) FROM v1; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug#16382: grouping name is resolved against a view column name +# which coincides with a select column name + +CREATE TABLE t1 (x varchar(10)); +INSERT INTO t1 VALUES (null), ('foo'), ('bar'), (null); +CREATE VIEW v1 AS SELECT * FROM t1; + +SELECT IF(x IS NULL, 'blank', 'not blank') FROM v1 GROUP BY x; +SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM t1 GROUP BY x; +SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1; +SELECT IF(x IS NULL, 'blank', 'not blank') AS y FROM v1 GROUP BY y; +SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1 GROUP BY x; + +DROP VIEW v1; +DROP TABLE t1; + +# +# BUG#15943: mysql_next_result hangs on invalid SHOW CREATE VIEW +# + +delimiter //; +drop table if exists t1; +drop view if exists v1; +create table t1 (id int); +create view v1 as select * from t1; +drop table t1; +show create view v1; +drop view v1; +// +delimiter ;// + +# +# Bug#17726 Not checked empty list caused endless loop +# +create table t1(f1 int, f2 int); +create view v1 as select ta.f1 as a, tb.f1 as b from t1 ta, t1 tb where ta.f1=tb +.f1 and ta.f2=tb.f2; +insert into t1 values(1,1),(2,2); +create view v2 as select * from v1 where a > 1 with check option; +select * from v2; +update v2 set b=3 where a=2; +select * from v2; +drop view v2, v1; +drop table t1; + +# +# Bug #18386: select from view over a table with ORDER BY view_col clause +# given view_col is not an image of any column from the base table + +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (1), (2); + +CREATE VIEW v1 AS SELECT SQRT(a) my_sqrt FROM t1; + +SELECT my_sqrt FROM v1 ORDER BY my_sqrt; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #18237: invalid count optimization applied to an outer join with a view +# + +CREATE TABLE t1 (id int PRIMARY KEY); +CREATE TABLE t2 (id int PRIMARY KEY); + +INSERT INTO t1 VALUES (1), (3); +INSERT INTO t2 VALUES (1), (2), (3); + +CREATE VIEW v2 AS SELECT * FROM t2; + +SELECT COUNT(*) FROM t1 LEFT JOIN t2 ON t1.id=t2.id; +SELECT * FROM t1 LEFT JOIN t2 ON t1.id=t2.id; + +SELECT COUNT(*) FROM t1 LEFT JOIN v2 ON t1.id=v2.id; + +DROP VIEW v2; + +DROP TABLE t1, t2; + +# +# Bug #16069: VIEW does return the same results as underlying SELECT +# with WHERE condition containing BETWEEN over dates + +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, + td date DEFAULT NULL, KEY idx(td)); + +INSERT INTO t1 VALUES + (1, '2005-01-01'), (2, '2005-01-02'), (3, '2005-01-02'), + (4, '2005-01-03'), (5, '2005-01-04'), (6, '2005-01-05'), + (7, '2005-01-05'), (8, '2005-01-05'), (9, '2005-01-06'); + +CREATE VIEW v1 AS SELECT * FROM t1; + +SELECT * FROM t1 WHERE td BETWEEN CAST('2005.01.02' AS DATE) AND CAST('2005.01.04' AS DATE); +SELECT * FROM v1 WHERE td BETWEEN CAST('2005.01.02' AS DATE) AND CAST('2005.01.04' AS DATE); + +DROP VIEW v1; +DROP TABLE t1; + +# +# BUG#14308: Recursive view definitions +# +# using view only +create table t1 (a int); +create view v1 as select * from t1; +create view v2 as select * from v1; +drop table t1; +rename table v2 to t1; +-- error ER_VIEW_RECURSIVE +select * from v1; +drop view t1, v1; +# using SP function +create table t1 (a int); +delimiter //; +create function f1() returns int +begin + declare mx int; + select max(a) from t1 into mx; + return mx; +end// +delimiter ;// +create view v1 as select f1() as a; +create view v2 as select * from v1; +drop table t1; +rename table v2 to t1; +-- error ER_SP_NO_RECURSION +select * from v1; +drop function f1; +drop view t1, v1; + +# +# Bug #15153: CONVERT_TZ() is not allowed in all places in VIEWs +# +# Error was reported when one tried to use CONVERT_TZ() function +# select list of view which was processed using MERGE algorithm. +# (Also see additional test in timezone_grant.test) +create table t1 (dt datetime); +insert into t1 values (20040101000000), (20050101000000), (20060101000000); +# Let us test that convert_tz() can be used in view's select list +create view v1 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from t1; +select * from v1; +drop view v1; +# And in its where part +create view v1 as select * from t1 where convert_tz(dt, 'UTC', 'Europe/Moscow') >= 20050101000000; +select * from v1; +# Other interesting case - a view which uses convert_tz() function +# through other view. +create view v2 as select * from v1 where dt < 20060101000000; +select * from v2; +drop view v2; +# And even more interesting case when view uses convert_tz() both +# directly and indirectly +create view v2 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from v1; +select * from v2; +drop view v1, v2; +drop table t1; + +# +# Bug #19490: usage of view specified by a query with GROUP BY +# an expression containing non-constant interval + +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, d datetime); + +CREATE VIEW v1 AS +SELECT id, date(d) + INTERVAL TIME_TO_SEC(d) SECOND AS t, COUNT(*) + FROM t1 GROUP BY id, t; + +SHOW CREATE VIEW v1; +SELECT * FROM v1; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug#19077: A nested materialized view is used before being populated. +# +CREATE TABLE t1 (i INT, j BIGINT); +INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2); +CREATE VIEW v1 AS SELECT MIN(j) AS j FROM t1; +CREATE VIEW v2 AS SELECT MIN(i) FROM t1 WHERE j = ( SELECT * FROM v1 ); +SELECT * FROM v2; +DROP VIEW v2, v1; +DROP TABLE t1; + +# +# Bug #19573: VIEW with HAVING that refers an alias name +# + +CREATE TABLE t1( + fName varchar(25) NOT NULL, + lName varchar(25) NOT NULL, + DOB date NOT NULL, + uID int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY); + +INSERT INTO t1(fName, lName, DOB) VALUES + ('Hank', 'Hill', '1964-09-29'), + ('Tom', 'Adams', '1908-02-14'), + ('Homer', 'Simpson', '1968-03-05'); + +CREATE VIEW v1 AS + SELECT (year(now())-year(DOB)) AS Age + FROM t1 HAVING Age < 75; +SHOW CREATE VIEW v1; + +SELECT (year(now())-year(DOB)) AS Age FROM t1 HAVING Age < 75; +SELECT * FROM v1; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #19089: wrong inherited dafault values in temp table views +# + +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a char(6) DEFAULT 'xxx'); +INSERT INTO t1(id) VALUES (1), (2), (3), (4); +INSERT INTO t1 VALUES (5,'yyy'), (6,'yyy'); +SELECT * FROM t1; + +CREATE VIEW v1(a, m) AS SELECT a, MIN(id) FROM t1 GROUP BY a; +SELECT * FROM v1; + +CREATE TABLE t2 SELECT * FROM v1; +INSERT INTO t2(m) VALUES (0); +SELECT * FROM t2; + +DROP VIEW v1; +DROP TABLE t1,t2; + +CREATE TABLE t1 (id int PRIMARY KEY, e ENUM('a','b') NOT NULL DEFAULT 'b'); +INSERT INTO t1(id) VALUES (1), (2), (3); +INSERT INTO t1 VALUES (4,'a'); +SELECT * FROM t1; + +CREATE VIEW v1(m, e) AS SELECT MIN(id), e FROM t1 GROUP BY e; +CREATE TABLE t2 SELECT * FROM v1; +SELECT * FROM t2; + +DROP VIEW v1; +DROP TABLE t1,t2; + + +# +# Bug#16110: insert permitted into view col w/o default value +# +CREATE TABLE t1 (a INT NOT NULL, b INT NULL DEFAULT NULL); +CREATE VIEW v1 AS SELECT a, b FROM t1; + +INSERT INTO v1 (b) VALUES (2); + +SET SQL_MODE = STRICT_ALL_TABLES; +--error 1423 +INSERT INTO v1 (b) VALUES (4); +SET SQL_MODE = ''; + +SELECT * FROM t1; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #18243: expression over a view column that with the REVERSE function +# + +CREATE TABLE t1 (firstname text, surname text); +INSERT INTO t1 VALUES + ("Bart","Simpson"),("Milhouse","van Houten"),("Montgomery","Burns"); + +CREATE VIEW v1 AS SELECT CONCAT(firstname," ",surname) AS name FROM t1; +SELECT CONCAT(LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," ")), + LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," "))) AS f1 + FROM v1; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #19714: wrong type of a view column specified by an expressions over ints +# + +CREATE TABLE t1 (i int, j int); +CREATE VIEW v1 AS SELECT COALESCE(i,j) FROM t1; +DESCRIBE v1; +CREATE TABLE t2 SELECT COALESCE(i,j) FROM t1; +DESCRIBE t2; + +DROP VIEW v1; +DROP TABLE t1,t2; + +# +# Bug #17526: views with TRIM functions +# + +CREATE TABLE t1 (s varchar(10)); +INSERT INTO t1 VALUES ('yadda'), ('yady'); + +SELECT TRIM(BOTH 'y' FROM s) FROM t1; +CREATE VIEW v1 AS SELECT TRIM(BOTH 'y' FROM s) FROM t1; +SELECT * FROM v1; +DROP VIEW v1; + +SELECT TRIM(LEADING 'y' FROM s) FROM t1; +CREATE VIEW v1 AS SELECT TRIM(LEADING 'y' FROM s) FROM t1; +SELECT * FROM v1; +DROP VIEW v1; + +SELECT TRIM(TRAILING 'y' FROM s) FROM t1; +CREATE VIEW v1 AS SELECT TRIM(TRAILING 'y' FROM s) FROM t1; +SELECT * FROM v1; +DROP VIEW v1; + +DROP TABLE t1; + +# +#Bug #21080: ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM +# +CREATE TABLE t1 (x INT, y INT); +CREATE ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1; +SHOW CREATE VIEW v1; + +ALTER VIEW v1 AS SELECT x, y FROM t1; +SHOW CREATE VIEW v1; + +DROP VIEW v1; +DROP TABLE t1; +# Bug #21086: server crashes when VIEW defined with a SELECT with COLLATE +# clause is called +# +CREATE TABLE t1 (s1 char); +INSERT INTO t1 VALUES ('Z'); + +CREATE VIEW v1 AS SELECT s1 collate latin1_german1_ci AS col FROM t1; + +CREATE VIEW v2 (col) AS SELECT s1 collate latin1_german1_ci FROM t1; + +# either of these statements will cause crash +INSERT INTO v1 (col) VALUES ('b'); +INSERT INTO v2 (col) VALUES ('c'); + +SELECT s1 FROM t1; +DROP VIEW v1, v2; +DROP TABLE t1; + +# +# Bug #11551: Asymmetric + undocumented behaviour of DROP VIEW and DROP TABLE +# +CREATE TABLE t1 (id INT); +CREATE VIEW v1 AS SELECT id FROM t1; +SHOW TABLES; + +--error 1051 +DROP VIEW v2,v1; +SHOW TABLES; + +CREATE VIEW v1 AS SELECT id FROM t1; +--error 1347 +DROP VIEW t1,v1; +SHOW TABLES; + +DROP TABLE t1; +--disable_warnings +DROP VIEW IF EXISTS v1; +--enable_warnings + +# +# Bug #21261: Wrong access rights was required for an insert to a view +# +CREATE DATABASE bug21261DB; +USE bug21261DB; +CONNECT (root,localhost,root,,bug21261DB); +CONNECTION root; + +CREATE TABLE t1 (x INT); +CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1; +GRANT INSERT, UPDATE ON v1 TO 'user21261'@'localhost'; +GRANT INSERT, UPDATE ON t1 TO 'user21261'@'localhost'; +CREATE TABLE t2 (y INT); +GRANT SELECT ON t2 TO 'user21261'@'localhost'; + +CONNECT (user21261, localhost, user21261,, bug21261DB); +CONNECTION user21261; +INSERT INTO v1 (x) VALUES (5); +UPDATE v1 SET x=1; +CONNECTION root; +GRANT SELECT ON v1 TO 'user21261'@'localhost'; +GRANT SELECT ON t1 TO 'user21261'@'localhost'; +CONNECTION user21261; +UPDATE v1,t2 SET x=1 WHERE x=y; +CONNECTION root; +SELECT * FROM t1; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user21261'@'localhost'; +DROP USER 'user21261'@'localhost'; +DROP VIEW v1; +DROP TABLE t1; +DROP DATABASE bug21261DB; +USE test; + +# +# Bug #15950: NOW() optimized away in VIEWs +# +create table t1 (f1 datetime); +create view v1 as select * from t1 where f1 between now() and now() + interval 1 minute; +show create view v1; +drop view v1; +drop table t1; +# +# Test for BUG#16899: Possible buffer overflow in handling of DEFINER-clause. +# + +# Prepare. + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP VIEW IF EXISTS v1; +DROP VIEW IF EXISTS v2; +--enable_warnings + +CREATE TABLE t1(a INT, b INT); + +--error ER_WRONG_STRING_LENGTH +CREATE DEFINER=1234567890abcdefGHIKL@localhost + VIEW v1 AS SELECT a FROM t1; + +--error ER_WRONG_STRING_LENGTH +CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY + VIEW v2 AS SELECT b FROM t1; + +# Cleanup. + +DROP TABLE t1; + + +# +# BUG#17591: Updatable view not possible with trigger or stored +# function +# +# During prelocking phase we didn't update lock type of view tables, +# hence READ lock was always requested. +# +--disable_warnings +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP VIEW IF EXISTS v1, v2; +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (i INT); + +CREATE VIEW v1 AS SELECT * FROM t1; + +delimiter |; +CREATE FUNCTION f1() RETURNS INT +BEGIN + INSERT INTO v1 VALUES (0); + RETURN 0; +END | +delimiter ;| + +SELECT f1(); + +CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t1; + +delimiter |; +CREATE FUNCTION f2() RETURNS INT +BEGIN + INSERT INTO v2 VALUES (0); + RETURN 0; +END | +delimiter ;| + +--error ER_NON_INSERTABLE_TABLE +SELECT f2(); + +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP VIEW v1, v2; +DROP TABLE t1; + +# +# Bug #5500: wrong select_type in EXPLAIN output for queries over views +# + +CREATE TABLE t1 (s1 int); +CREATE VIEW v1 AS SELECT * FROM t1; + +EXPLAIN SELECT * FROM t1; +EXPLAIN SELECT * FROM v1; + +INSERT INTO t1 VALUES (1), (3), (2); + +EXPLAIN SELECT * FROM t1 t WHERE t.s1+1 < (SELECT MAX(t1.s1) FROM t1); +EXPLAIN SELECT * FROM v1 t WHERE t.s1+1 < (SELECT MAX(t1.s1) FROM t1); + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #5505: Wrong error message on INSERT into a view +# +create table t1 (s1 int); +create view v1 as select s1 as a, s1 as b from t1; +--error 1471 +insert into v1 values (1,1); +update v1 set a = 5; +drop view v1; +drop table t1; + +# +# Bug #21646: view qith a subquery in ON expression +# + +CREATE TABLE t1(pk int PRIMARY KEY); +CREATE TABLE t2(pk int PRIMARY KEY, fk int, ver int, org int); + +CREATE ALGORITHM=MERGE VIEW v1 AS +SELECT t1.* + FROM t1 JOIN t2 + ON t2.fk = t1.pk AND + t2.ver = (SELECT MAX(t.ver) FROM t2 t WHERE t.org = t2.org); +SHOW WARNINGS; +SHOW CREATE VIEW v1; + +DROP VIEW v1; +DROP TABLE t1, t2; + + +# +# Bug#19111: TRIGGERs selecting from a VIEW on the firing base table +# fail +# +# Allow to select from a view on a table being modified in a trigger +# and stored function, since plain select is allowed there. +# +--disable_warnings +DROP FUNCTION IF EXISTS f1; +DROP VIEW IF EXISTS v1; +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1); + +CREATE VIEW v1 AS SELECT MAX(i) FROM t1; + +# Plain 'SET NEW.i = (SELECT MAX(i) FROM t1) + 1' works, so select +# from a view should work too. +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + SET NEW.i = (SELECT * FROM v1) + 1; +INSERT INTO t1 VALUES (1); + +# Plain 'RETURN (SELECT MAX(i) FROM t1)' works in INSERT, so select +# from a view should work too. +CREATE FUNCTION f1() RETURNS INT RETURN (SELECT * FROM v1); +UPDATE t1 SET i= f1(); + +DROP FUNCTION f1; +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #16813 (WITH CHECK OPTION doesn't work with UPDATE) +# +CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL); +CREATE VIEW v1 AS SELECT id, val FROM t1 WHERE val >= 1 AND val <= 5 WITH CHECK OPTION; +INSERT INTO v1 (val) VALUES (2); +INSERT INTO v1 (val) VALUES (4); +-- error 1369 +INSERT INTO v1 (val) VALUES (6); +-- error 1369 +UPDATE v1 SET val=6 WHERE id=2; +DROP VIEW v1; +DROP TABLE t1; + + +# +# BUG#22584: last_insert_id not updated after inserting a record +# through a updatable view +# +# We still do not update LAST_INSERT_ID if AUTO_INCREMENT column is +# not accessible through a view. However, we do not reset the value +# of LAST_INSERT_ID, but keep it unchanged. +# +--disable_warnings +DROP VIEW IF EXISTS v1, v2; +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (i INT AUTO_INCREMENT PRIMARY KEY, j INT); +CREATE VIEW v1 AS SELECT j FROM t1; +CREATE VIEW v2 AS SELECT * FROM t1; + +INSERT INTO t1 (j) VALUES (1); +SELECT LAST_INSERT_ID(); + +INSERT INTO v1 (j) VALUES (2); +--echo # LAST_INSERT_ID() should not change. +SELECT LAST_INSERT_ID(); + +INSERT INTO v2 (j) VALUES (3); +--echo # LAST_INSERT_ID() should be updated. +SELECT LAST_INSERT_ID(); + +INSERT INTO v1 (j) SELECT j FROM t1; +--echo # LAST_INSERT_ID() should not change. +SELECT LAST_INSERT_ID(); + +SELECT * FROM t1; + +DROP VIEW v1, v2; +DROP TABLE t1; + + +--echo End of 5.0 tests. diff --git a/mysql-test/t/view_grant.test b/mysql-test/t/view_grant.test new file mode 100644 index 00000000000..8bc34cfe148 --- /dev/null +++ b/mysql-test/t/view_grant.test @@ -0,0 +1,930 @@ +# Can't test with embedded server +-- source include/not_embedded.inc + +# simple test of grants +grant create view on test.* to test@localhost; +show grants for test@localhost; +revoke create view on test.* from test@localhost; +show grants for test@localhost; +# The grant above creates a new user test@localhost, delete it +drop user test@localhost; + +# grant create view test +# +connect (root,localhost,root,,test); +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings + +create table mysqltest.t1 (a int, b int); +create table mysqltest.t2 (a int, b int); + +grant select on mysqltest.t1 to mysqltest_1@localhost; +grant create view,select on test.* to mysqltest_1@localhost; + +connect (user1,localhost,mysqltest_1,,test); +connection user1; + +-- error ER_SPECIFIC_ACCESS_DENIED_ERROR +create definer=root@localhost view v1 as select * from mysqltest.t1; +create view v1 as select * from mysqltest.t1; +# try to modify view without DROP privilege on it +-- error 1142 +alter view v1 as select * from mysqltest.t1; +-- error 1142 +create or replace view v1 as select * from mysqltest.t1; +# no CRETE VIEW privilege +-- error 1142 +create view mysqltest.v2 as select * from mysqltest.t1; +# no SELECT privilege +-- error 1142 +create view v2 as select * from mysqltest.t2; + +connection root; +# check view definer information +show create view v1; + +grant create view,drop,select on test.* to mysqltest_1@localhost; + +connection user1; +# following 'use' command is workaround of bug #9582 and should be removed +# when that bug will be fixed +use test; +alter view v1 as select * from mysqltest.t1; +create or replace view v1 as select * from mysqltest.t1; + +connection root; +revoke all privileges on mysqltest.t1 from mysqltest_1@localhost; +revoke all privileges on test.* from mysqltest_1@localhost; + +drop database mysqltest; +drop view test.v1; + +# +# grants per columns +# +# MERGE algorithm +--disable_warnings +create database mysqltest; +--enable_warnings + +create table mysqltest.t1 (a int, b int); +create view mysqltest.v1 (c,d) as select a+1,b+1 from mysqltest.t1; +grant select (c) on mysqltest.v1 to mysqltest_1@localhost; + +connection user1; +select c from mysqltest.v1; +# there are no privileges on column 'd' +-- error 1143 +select d from mysqltest.v1; + +connection root; +revoke all privileges on mysqltest.v1 from mysqltest_1@localhost; +delete from mysql.user where user='mysqltest_1'; +drop database mysqltest; + +# TEMPORARY TABLE algorithm +--disable_warnings +create database mysqltest; +--enable_warnings + +create table mysqltest.t1 (a int, b int); +create algorithm=temptable view mysqltest.v1 (c,d) as select a+1,b+1 from mysqltest.t1; +grant select (c) on mysqltest.v1 to mysqltest_1@localhost; + +connection user1; +select c from mysqltest.v1; +# there are no privileges on column 'd' +-- error 1143 +select d from mysqltest.v1; + +connection root; +revoke all privileges on mysqltest.v1 from mysqltest_1@localhost; +delete from mysql.user where user='mysqltest_1'; +drop database mysqltest; + +# +# EXPLAIN rights +# +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings +#prepare views and tables +create table mysqltest.t1 (a int, b int); +create table mysqltest.t2 (a int, b int); +create view mysqltest.v1 (c,d) as select a+1,b+1 from mysqltest.t1; +create algorithm=temptable view mysqltest.v2 (c,d) as select a+1,b+1 from mysqltest.t1; +create view mysqltest.v3 (c,d) as select a+1,b+1 from mysqltest.t2; +create algorithm=temptable view mysqltest.v4 (c,d) as select a+1,b+1 from mysqltest.t2; +grant select on mysqltest.v1 to mysqltest_1@localhost; +grant select on mysqltest.v2 to mysqltest_1@localhost; +grant select on mysqltest.v3 to mysqltest_1@localhost; +grant select on mysqltest.v4 to mysqltest_1@localhost; + +connection user1; +# all selects works +select c from mysqltest.v1; +select c from mysqltest.v2; +select c from mysqltest.v3; +select c from mysqltest.v4; +# test of show coluns +show columns from mysqltest.v1; +show columns from mysqltest.v2; +# but explain/show do not +-- error 1345 +explain select c from mysqltest.v1; +-- error 1142 +show create view mysqltest.v1; +-- error 1345 +explain select c from mysqltest.v2; +-- error 1142 +show create view mysqltest.v2; +-- error 1345 +explain select c from mysqltest.v3; +-- error 1142 +show create view mysqltest.v3; +-- error 1345 +explain select c from mysqltest.v4; +-- error 1142 +show create view mysqltest.v4; + +# allow to see one of underlying table +connection root; +grant select on mysqltest.t1 to mysqltest_1@localhost; +connection user1; +# EXPLAIN of view on above table works +explain select c from mysqltest.v1; +-- error 1142 +show create view mysqltest.v1; +explain select c from mysqltest.v2; +-- error 1142 +show create view mysqltest.v2; +# but other EXPLAINs do not +-- error 1345 +explain select c from mysqltest.v3; +-- error 1142 +show create view mysqltest.v3; +-- error 1345 +explain select c from mysqltest.v4; +-- error 1142 +show create view mysqltest.v4; + +# allow to see any view in mysqltest database +connection root; +grant show view on mysqltest.* to mysqltest_1@localhost; +connection user1; +explain select c from mysqltest.v1; +show create view mysqltest.v1; +explain select c from mysqltest.v2; +show create view mysqltest.v2; +explain select c from mysqltest.v3; +show create view mysqltest.v3; +explain select c from mysqltest.v4; +show create view mysqltest.v4; + +connection root; +revoke all privileges on mysqltest.* from mysqltest_1@localhost; +delete from mysql.user where user='mysqltest_1'; +drop database mysqltest; + +# +# UPDATE privileges on VIEW columns and whole VIEW +# +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings + +create table mysqltest.t1 (a int, b int, primary key(a)); +insert into mysqltest.t1 values (10,2), (20,3), (30,4), (40,5), (50,10); +create table mysqltest.t2 (x int); +insert into mysqltest.t2 values (3), (4), (5), (6); +create view mysqltest.v1 (a,c) as select a, b+1 from mysqltest.t1; +create view mysqltest.v2 (a,c) as select a, b from mysqltest.t1; +create view mysqltest.v3 (a,c) as select a, b+1 from mysqltest.t1; + +grant update (a) on mysqltest.v2 to mysqltest_1@localhost; +grant update on mysqltest.v1 to mysqltest_1@localhost; +grant select on mysqltest.* to mysqltest_1@localhost; + +connection user1; +use mysqltest; +# update with rights on VIEW column +update t2,v1 set v1.a=v1.a+v1.c where t2.x=v1.c; +select * from t1; +update v1 set a=a+c; +select * from t1; +# update with rights on whole VIEW +update t2,v2 set v2.a=v2.a+v2.c where t2.x=v2.c; +select * from t1; +update v2 set a=a+c; +select * from t1; +# no rights on column +-- error 1143 +update t2,v2 set v2.c=v2.a+v2.c where t2.x=v2.c; +-- error 1143 +update v2 set c=a+c; +# no rights for view +-- error 1142 +update t2,v3 set v3.a=v3.a+v3.c where t2.x=v3.c; +-- error 1142 +update v3 set a=a+c; + +use test; +connection root; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost; +drop database mysqltest; + +# +# DELETE privileges on VIEW +# +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings + +create table mysqltest.t1 (a int, b int, primary key(a)); +insert into mysqltest.t1 values (1,2), (2,3), (3,4), (4,5), (5,10); +create table mysqltest.t2 (x int); +insert into mysqltest.t2 values (3), (4), (5), (6); +create view mysqltest.v1 (a,c) as select a, b+1 from mysqltest.t1; +create view mysqltest.v2 (a,c) as select a, b+1 from mysqltest.t1; + +grant delete on mysqltest.v1 to mysqltest_1@localhost; +grant select on mysqltest.* to mysqltest_1@localhost; + +connection user1; +use mysqltest; +# update with rights on VIEW column +delete from v1 where c < 4; +select * from t1; +delete v1 from t2,v1 where t2.x=v1.c; +select * from t1; +# no rights for view +-- error 1142 +delete v2 from t2,v2 where t2.x=v2.c; +-- error 1142 +delete from v2 where c < 4; + +use test; +connection root; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost; +drop database mysqltest; + +# +# insert privileges on VIEW +# +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings + +create table mysqltest.t1 (a int, b int, primary key(a)); +insert into mysqltest.t1 values (1,2), (2,3); +create table mysqltest.t2 (x int, y int); +insert into mysqltest.t2 values (3,4); +create view mysqltest.v1 (a,c) as select a, b from mysqltest.t1; +create view mysqltest.v2 (a,c) as select a, b from mysqltest.t1; + +grant insert on mysqltest.v1 to mysqltest_1@localhost; +grant select on mysqltest.* to mysqltest_1@localhost; + +connection user1; +use mysqltest; +# update with rights on VIEW column +insert into v1 values (5,6); +select * from t1; +insert into v1 select x,y from t2; +select * from t1; +# no rights for view +-- error 1142 +insert into v2 values (5,6); +-- error 1142 +insert into v2 select x,y from t2; + +use test; +connection root; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost; +drop database mysqltest; + +# +# test of CREATE VIEW privileges if we have limited privileges +# +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings + +create table mysqltest.t1 (a int, b int); +create table mysqltest.t2 (a int, b int); + +grant update on mysqltest.t1 to mysqltest_1@localhost; +grant update(b) on mysqltest.t2 to mysqltest_1@localhost; +grant create view,update on test.* to mysqltest_1@localhost; + +connection user1; + +create view v1 as select * from mysqltest.t1; +create view v2 as select b from mysqltest.t2; +# There are not rights on mysqltest.v1 +-- error 1142 +create view mysqltest.v1 as select * from mysqltest.t1; +# There are not any rights on mysqltest.t2.a +-- error 1143 +create view v3 as select a from mysqltest.t2; + +# give CREATE VIEW privileges (without any privileges for result column) +connection root; +create table mysqltest.v3 (b int); +grant create view on mysqltest.v3 to mysqltest_1@localhost; +drop table mysqltest.v3; +connection user1; +create view mysqltest.v3 as select b from mysqltest.t2; + +# give UPDATE privileges +connection root; +grant create view, update on mysqltest.v3 to mysqltest_1@localhost; +drop view mysqltest.v3; +connection user1; +create view mysqltest.v3 as select b from mysqltest.t2; + +# give UPDATE and INSERT privilege (to get more privileges then underlying +# table) +connection root; +grant create view, update, insert on mysqltest.v3 to mysqltest_1@localhost; +drop view mysqltest.v3; +connection user1; +-- error 1143 +create view mysqltest.v3 as select b from mysqltest.t2; + + +# If we would get more privileges on VIEW then we have on +# underlying tables => creation prohibited +connection root; +create table mysqltest.v3 (b int); +grant select(b) on mysqltest.v3 to mysqltest_1@localhost; +drop table mysqltest.v3; +connection user1; +-- error 1143 +create view mysqltest.v3 as select b from mysqltest.t2; + +# Expression need select privileges +-- error 1143 +create view v4 as select b+1 from mysqltest.t2; + +connection root; +grant create view,update,select on test.* to mysqltest_1@localhost; +connection user1; +-- error 1143 +create view v4 as select b+1 from mysqltest.t2; + +connection root; +grant update,select(b) on mysqltest.t2 to mysqltest_1@localhost; +connection user1; +create view v4 as select b+1 from mysqltest.t2; + +connection root; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost; +drop database mysqltest; +drop view v1,v2,v4; + +# +# user with global DB privileges +# +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings +create table mysqltest.t1 (a int); +grant all privileges on mysqltest.* to mysqltest_1@localhost; + +connection user1; +use mysqltest; +create view v1 as select * from t1; +use test; + +connection root; +revoke all privileges on mysqltest.* from mysqltest_1@localhost; +drop database mysqltest; + +# +# view definer grants revoking +# +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings + +create table mysqltest.t1 (a int, b int); + +grant select on mysqltest.t1 to mysqltest_1@localhost; +grant create view,select on test.* to mysqltest_1@localhost; + +connection user1; + +create view v1 as select * from mysqltest.t1; + +connection root; +# check view definer information +show create view v1; +revoke select on mysqltest.t1 from mysqltest_1@localhost; +-- error ER_VIEW_INVALID +select * from v1; +grant select on mysqltest.t1 to mysqltest_1@localhost; +select * from v1; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost; +drop view v1; +drop database mysqltest; + +# +# rights on execution of view underlying functiond (BUG#9505) +# +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings + +use mysqltest; +create table t1 (a int); +insert into t1 values (1); +create table t2 (s1 int); +--disable_warnings +drop function if exists f2; +--enable_warnings +delimiter //; +create function f2 () returns int begin declare v int; select s1 from t2 +into v; return v; end// +delimiter ;// +create algorithm=TEMPTABLE view v1 as select f2() from t1; +create algorithm=MERGE view v2 as select f2() from t1; +create algorithm=TEMPTABLE SQL SECURITY INVOKER view v3 as select f2() from t1; +create algorithm=MERGE SQL SECURITY INVOKER view v4 as select f2() from t1; +create SQL SECURITY INVOKER view v5 as select * from v4; +grant select on v1 to mysqltest_1@localhost; +grant select on v2 to mysqltest_1@localhost; +grant select on v3 to mysqltest_1@localhost; +grant select on v4 to mysqltest_1@localhost; +grant select on v5 to mysqltest_1@localhost; + +connection user1; +use mysqltest; +select * from v1; +select * from v2; +-- error ER_VIEW_INVALID +select * from v3; +-- error ER_VIEW_INVALID +select * from v4; +-- error ER_VIEW_INVALID +select * from v5; +use test; + +connection root; +drop view v1, v2, v3, v4, v5; +drop function f2; +drop table t1, t2; +use test; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost; +drop database mysqltest; + +# +# revertion of previous test, definer of view lost his/her rights to execute +# function +# + +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings + +use mysqltest; +create table t1 (a int); +insert into t1 values (1); +create table t2 (s1 int); +--disable_warnings +drop function if exists f2; +--enable_warnings +delimiter //; +create function f2 () returns int begin declare v int; select s1 from t2 +into v; return v; end// +delimiter ;// +grant select on t1 to mysqltest_1@localhost; +grant execute on function f2 to mysqltest_1@localhost; +grant create view on mysqltest.* to mysqltest_1@localhost; + +connection user1; +use mysqltest; +create algorithm=TEMPTABLE view v1 as select f2() from t1; +create algorithm=MERGE view v2 as select f2() from t1; +create algorithm=TEMPTABLE SQL SECURITY INVOKER view v3 as select f2() from t1; +create algorithm=MERGE SQL SECURITY INVOKER view v4 as select f2() from t1; +use test; + +connection root; +create view v5 as select * from v1; +revoke execute on function f2 from mysqltest_1@localhost; +-- error ER_VIEW_INVALID +select * from v1; +-- error ER_VIEW_INVALID +select * from v2; +select * from v3; +select * from v4; +-- error ER_VIEW_INVALID +select * from v5; + +drop view v1, v2, v3, v4, v5; +drop function f2; +drop table t1, t2; +use test; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost; +drop database mysqltest; + +# +# definer/invoker rights for columns +# +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings + +use mysqltest; +create table t1 (a int); +create table v1 (a int); +insert into t1 values (1); +grant select on t1 to mysqltest_1@localhost; +grant select on v1 to mysqltest_1@localhost; +grant create view on mysqltest.* to mysqltest_1@localhost; +drop table v1; + +connection user1; +use mysqltest; +create algorithm=TEMPTABLE view v1 as select *, a as b from t1; +create algorithm=MERGE view v2 as select *, a as b from t1; +create algorithm=TEMPTABLE SQL SECURITY INVOKER view v3 as select *, a as b from t1; +create algorithm=MERGE SQL SECURITY INVOKER view v4 as select *, a as b from t1; +create view v5 as select * from v1; +use test; + +connection root; +revoke select on t1 from mysqltest_1@localhost; +-- error ER_VIEW_INVALID +select * from v1; +-- error ER_VIEW_INVALID +select * from v2; +select * from v3; +select * from v4; +-- error ER_VIEW_INVALID +select * from v5; + +#drop view v1, v2, v3, v4, v5; +drop table t1; +use test; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost; +drop database mysqltest; + + +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings + +use mysqltest; +create table t1 (a int); +insert into t1 values (1); +create algorithm=TEMPTABLE view v1 as select *, a as b from t1; +create algorithm=MERGE view v2 as select *, a as b from t1; +create algorithm=TEMPTABLE SQL SECURITY INVOKER view v3 as select *, a as b from t1; +create algorithm=MERGE SQL SECURITY INVOKER view v4 as select *, a as b from t1; +create SQL SECURITY INVOKER view v5 as select * from v4; +grant select on v1 to mysqltest_1@localhost; +grant select on v2 to mysqltest_1@localhost; +grant select on v3 to mysqltest_1@localhost; +grant select on v4 to mysqltest_1@localhost; +grant select on v5 to mysqltest_1@localhost; + +connection user1; +use mysqltest; +select * from v1; +select * from v2; +-- error ER_VIEW_INVALID +select * from v3; +-- error ER_VIEW_INVALID +select * from v4; +-- error ER_VIEW_INVALID +select * from v5; +use test; + +connection root; +drop view v1, v2, v3, v4, v5; +drop table t1; +use test; +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost; +drop database mysqltest; + +# +# BUG#14256: definer in view definition is not fully qualified +# +--disable_warnings +drop view if exists v1; +--enable_warnings + +# Backup anonymous users and remove them. (They get in the way of +# the one we test with here otherwise.) +create table t1 as select * from mysql.user where user=''; +delete from mysql.user where user=''; +flush privileges; + +# Create the test user +grant all on test.* to 'test14256'@'%'; + +connect (test14256,localhost,test14256,,test); +connection test14256; +use test; + +create view v1 as select 42; +show create view v1; + +select definer into @v1def1 from information_schema.views + where table_schema = 'test' and table_name='v1'; +drop view v1; + +create definer=`test14256`@`%` view v1 as select 42; +show create view v1; + +select definer into @v1def2 from information_schema.views + where table_schema = 'test' and table_name='v1'; +drop view v1; + +select @v1def1, @v1def2, @v1def1=@v1def2; + +connection root; +drop user test14256; + +# Restore the anonymous users. +insert into mysql.user select * from t1; +flush privileges; + +drop table t1; + +# +# BUG#14726: freeing stack variable in case of an error of opening +# a view when we have locked tables with LOCK TABLES statement. +# +connection root; +--disable_warnings +create database mysqltest; +--enable_warnings + +use mysqltest; +CREATE TABLE t1 (i INT); +CREATE VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; +GRANT SELECT, LOCK TABLES ON mysqltest.* TO mysqltest_1@localhost; + +connection user1; + +use mysqltest; +LOCK TABLES v1 READ; +-- error ER_TABLEACCESS_DENIED_ERROR +SHOW CREATE TABLE v1; +UNLOCK TABLES; +use test; + +connection root; +use test; +drop user mysqltest_1@localhost; +drop database mysqltest; + +# +# switch to default connaction +# +disconnect user1; +disconnect root; +connection default; + +# +# DEFINER information check +# +create definer=some_user@`` sql security invoker view v1 as select 1; +create definer=some_user@localhost sql security invoker view v2 as select 1; +show create view v1; +show create view v2; +drop view v1; +drop view v2; + +# +# Bug#18681: View privileges are broken +# +CREATE DATABASE mysqltest1; +CREATE USER readonly@localhost; +CREATE TABLE mysqltest1.t1 (x INT); +INSERT INTO mysqltest1.t1 VALUES (1), (2); +CREATE SQL SECURITY INVOKER VIEW mysqltest1.v_t1 AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_ts AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_ti AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tu AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tus AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_td AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tds AS SELECT * FROM mysqltest1.t1; +GRANT SELECT, INSERT, UPDATE, DELETE ON mysqltest1.v_t1 TO readonly; +GRANT SELECT ON mysqltest1.v_ts TO readonly; +GRANT INSERT ON mysqltest1.v_ti TO readonly; +GRANT UPDATE ON mysqltest1.v_tu TO readonly; +GRANT UPDATE,SELECT ON mysqltest1.v_tus TO readonly; +GRANT DELETE ON mysqltest1.v_td TO readonly; +GRANT DELETE,SELECT ON mysqltest1.v_tds TO readonly; + +CONNECT (n1,localhost,readonly,,); +CONNECTION n1; + +--error 1356 +SELECT * FROM mysqltest1.v_t1; +--error 1356 +INSERT INTO mysqltest1.v_t1 VALUES(4); +--error 1356 +DELETE FROM mysqltest1.v_t1 WHERE x = 1; +--error 1356 +UPDATE mysqltest1.v_t1 SET x = 3 WHERE x = 2; +--error 1356 +UPDATE mysqltest1.v_t1 SET x = 3; +--error 1356 +DELETE FROM mysqltest1.v_t1; +--error 1356 +SELECT 1 FROM mysqltest1.v_t1; +--error 1142 +SELECT * FROM mysqltest1.t1; + +SELECT * FROM mysqltest1.v_ts; +--error 1142 +SELECT * FROM mysqltest1.v_ts, mysqltest1.t1 WHERE mysqltest1.t1.x = mysqltest1.v_ts.x; +--error 1142 +SELECT * FROM mysqltest1.v_ti; + +--error 1142 +INSERT INTO mysqltest1.v_ts VALUES (100); +INSERT INTO mysqltest1.v_ti VALUES (100); + +--error 1142 +UPDATE mysqltest1.v_ts SET x= 200 WHERE x = 100; +--error 1142 +UPDATE mysqltest1.v_ts SET x= 200; +UPDATE mysqltest1.v_tu SET x= 200 WHERE x = 100; +UPDATE mysqltest1.v_tus SET x= 200 WHERE x = 100; +UPDATE mysqltest1.v_tu SET x= 200; + +--error 1142 +DELETE FROM mysqltest1.v_ts WHERE x= 200; +--error 1142 +DELETE FROM mysqltest1.v_ts; +--error 1143 +DELETE FROM mysqltest1.v_td WHERE x= 200; +DELETE FROM mysqltest1.v_tds WHERE x= 200; +DELETE FROM mysqltest1.v_td; + +CONNECTION default; +DROP VIEW mysqltest1.v_tds; +DROP VIEW mysqltest1.v_td; +DROP VIEW mysqltest1.v_tus; +DROP VIEW mysqltest1.v_tu; +DROP VIEW mysqltest1.v_ti; +DROP VIEW mysqltest1.v_ts; +DROP VIEW mysqltest1.v_t1; +DROP TABLE mysqltest1.t1; +DROP USER readonly@localhost; +DROP DATABASE mysqltest1; + +# +# BUG#14875: Bad view DEFINER makes SHOW CREATE VIEW fail +# +CREATE TABLE t1 (a INT PRIMARY KEY); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE DEFINER = 'no-such-user'@localhost VIEW v AS SELECT a from t1; +--warning 1448 +SHOW CREATE VIEW v; +--error 1449 +SELECT * FROM v; +DROP VIEW v; +DROP TABLE t1; +USE test; + +# +# Bug#20363: Create view on just created view is now denied +# +eval CREATE USER mysqltest_db1@localhost identified by 'PWD'; +eval GRANT ALL ON mysqltest_db1.* TO mysqltest_db1@localhost WITH GRANT OPTION; + +# The session with the non root user is needed. +--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK +connect (session1,localhost,mysqltest_db1,PWD,test); + +CREATE SCHEMA mysqltest_db1 ; +USE mysqltest_db1 ; + +CREATE TABLE t1 (f1 INTEGER); + +CREATE VIEW view1 AS +SELECT * FROM t1; +SHOW CREATE VIEW view1; + +CREATE VIEW view2 AS +SELECT * FROM view1; +--echo # Here comes a suspicious warning +SHOW CREATE VIEW view2; +--echo # But the view view2 is usable +SELECT * FROM view2; + +CREATE VIEW view3 AS +SELECT * FROM view2; + +SELECT * from view3; + +connection default; +DROP VIEW mysqltest_db1.view3; +DROP VIEW mysqltest_db1.view2; +DROP VIEW mysqltest_db1.view1; +DROP TABLE mysqltest_db1.t1; +DROP SCHEMA mysqltest_db1; +DROP USER mysqltest_db1@localhost; +# +# BUG#20482: failure on Create join view with sources views/tables +# in different schemas +# +--disable_warnings +CREATE DATABASE test1; +CREATE DATABASE test2; +--enable_warnings + +CREATE TABLE test1.t0 (a VARCHAR(20)); +CREATE TABLE test2.t1 (a VARCHAR(20)); +CREATE VIEW test2.t3 AS SELECT * FROM test1.t0; +CREATE OR REPLACE VIEW test.v1 AS + SELECT ta.a AS col1, tb.a AS col2 FROM test2.t3 ta, test2.t1 tb; + +DROP VIEW test.v1; +DROP VIEW test2.t3; +DROP TABLE test2.t1, test1.t0; +DROP DATABASE test2; +DROP DATABASE test1; + + +# +# BUG#20570: CURRENT_USER() in a VIEW with SQL SECURITY DEFINER +# returns invoker name +# +--disable_warnings +DROP VIEW IF EXISTS v1; +DROP VIEW IF EXISTS v2; +DROP VIEW IF EXISTS v3; +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +CREATE SQL SECURITY DEFINER VIEW v1 AS SELECT CURRENT_USER() AS cu; + +CREATE FUNCTION f1() RETURNS VARCHAR(77) SQL SECURITY INVOKER + RETURN CURRENT_USER(); +CREATE SQL SECURITY DEFINER VIEW v2 AS SELECT f1() AS cu; + +CREATE PROCEDURE p1(OUT cu VARCHAR(77)) SQL SECURITY INVOKER + SET cu= CURRENT_USER(); +delimiter |; +CREATE FUNCTION f2() RETURNS VARCHAR(77) SQL SECURITY INVOKER +BEGIN + DECLARE cu VARCHAR(77); + CALL p1(cu); + RETURN cu; +END| +delimiter ;| +CREATE SQL SECURITY DEFINER VIEW v3 AS SELECT f2() AS cu; + +CREATE USER mysqltest_u1@localhost; +GRANT ALL ON test.* TO mysqltest_u1@localhost; + +connect (conn1, localhost, mysqltest_u1,,); + +--echo +--echo The following tests should all return 1. +--echo +SELECT CURRENT_USER() = 'mysqltest_u1@localhost'; +SELECT f1() = 'mysqltest_u1@localhost'; +CALL p1(@cu); +SELECT @cu = 'mysqltest_u1@localhost'; +SELECT f2() = 'mysqltest_u1@localhost'; +SELECT cu = 'root@localhost' FROM v1; +SELECT cu = 'root@localhost' FROM v2; +SELECT cu = 'root@localhost' FROM v3; + +disconnect conn1; +connection default; + +DROP VIEW v3; +DROP FUNCTION f2; +DROP PROCEDURE p1; +DROP FUNCTION f1; +DROP VIEW v2; +DROP VIEW v1; +DROP USER mysqltest_u1@localhost; + +# End of 5.0 tests. diff --git a/mysql-test/t/view_query_cache.test b/mysql-test/t/view_query_cache.test new file mode 100644 index 00000000000..d4ebe45b7ac --- /dev/null +++ b/mysql-test/t/view_query_cache.test @@ -0,0 +1,130 @@ +-- source include/have_query_cache.inc +# +# QUERY CACHE options for VIEWs +# +--disable_warnings +drop table if exists t1,t2,v1,v2,v3; +drop view if exists t1,t2,v1,v2,v3; +--enable_warnings + +set GLOBAL query_cache_size=1355776; +flush status; +create table t1 (a int, b int); + +# queries with following views should not be in query cache +create view v1 (c,d) as select sql_no_cache a,b from t1; +create view v2 (c,d) as select a+rand(),b from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from v1; +select * from v2; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from v1; +select * from v2; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; + +drop view v1,v2; + +# SQL_CACHE option +set query_cache_type=demand; +flush status; +# query with view will be cached, but direct acess to table will not +create view v1 (c,d) as select sql_cache a,b from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from v1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from v1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from t1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +drop view v1; +set query_cache_type=default; + +drop table t1; + +# +# invalidation of view +# +create table t1 (a int); +insert into t1 values (1), (2), (3); +create view v1 as select a from t1 where a > 1; +select * from v1; +alter view v1 as select a from t1 where a > 2; +select * from v1; +drop view v1; +-- error 1146 +select * from v1; +drop table t1; + +# +# join view with QC +# +create table t1 (a int, primary key (a), b int); +create table t2 (a int, primary key (a), b int); +insert into t2 values (1000, 2000); +create view v3 (a,b) as select t1.a as a, t2.a as b from t1, t2; +select * from v3; +drop view v3; +drop table t1, t2; + +# +# Bug #13424 locking view with query cache enabled crashes server +# +create table t1(f1 int); +insert into t1 values(1),(2),(3); +create view v1 as select * from t1; +set query_cache_wlock_invalidate=1; +lock tables v1 read /*!32311 local */; +unlock tables; +set query_cache_wlock_invalidate=default; +drop view v1; +drop table t1; + +# +# BUG#15119: returning temptable view from the query cache. +# +flush status; +create table t1 (a int, b int); +create algorithm=temptable view v1 as select * from t1; +select * from v1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from v1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +insert into t1 values (1,1); +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +select * from v1; +select * from v1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +drop view v1; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_inserts"; +show status like "Qcache_hits"; +drop table t1; + +# Reset default environment. +set GLOBAL query_cache_size=default; diff --git a/mysql-test/t/wait_for_process.sh b/mysql-test/t/wait_for_process.sh new file mode 100755 index 00000000000..df0f4a17e3a --- /dev/null +++ b/mysql-test/t/wait_for_process.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +########################################################################### + +pid_path="$1" +total_attempts="$2" +event="$3" + +case "$3" in + started) + check_fn='check_started'; + ;; + + stopped) + check_fn='check_stopped'; + ;; + + *) + echo "Error: invalid third argument ('started' or 'stopped' expected)." + exit 0 +esac + +########################################################################### + +check_started() +{ + [ ! -r "$pid_path" ] && return 1 + + new_pid=`cat "$pid_path" 2>/dev/null` + + [ $? -eq 0 -a "$original_pid" = "$new_pid" ] && return 1 + + return 0 +} + +########################################################################### + +check_stopped() +{ + [ -r "$pid_path" ] && return 1 + + return 0 +} + +########################################################################### + +cur_attempt=1 + +while true; do + + if ( eval $check_fn ); then + echo "Success: the process has been $event." + exit 0 + fi + + [ $cur_attempt -ge $total_attempts ] && break + + sleep 1 + + cur_attempt=`expr $cur_attempt + 1` + +done + +echo "Error: the process has not been $event in $total_attempts secs." +exit 0 + diff --git a/mysql-test/t/wait_for_socket.sh b/mysql-test/t/wait_for_socket.sh new file mode 100755 index 00000000000..3b900fa2208 --- /dev/null +++ b/mysql-test/t/wait_for_socket.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +########################################################################### + +if [ $# -ne 6 ]; then + echo "Usage: wait_for_socket.sh <executable path> <socket path> <username> <password> <db> <timeout>" + exit 0 +fi + +client_exe="$1" +socket_path="$2" +username="$3" +password="$4" +db="$5" +total_timeout="$6" + +########################################################################### + +if [ -z "$client_exe" ]; then + echo "Error: invalid path to client executable ($client_exe)." + exit 0; +fi + +if [ ! -x "$client_exe" ]; then + echo "Error: client by path '$client_exe' is not available." + exit 0; +fi + +if [ -z "$socket_path" ]; then + echo "Error: invalid socket patch." + exit 0 +fi + +########################################################################### + +client_args="--silent --socket=$socket_path " + +[ -n "$username" ] && client_args="$client_args --user=$username " +[ -n "$password" ] && client_args="$client_args --password=$password " +[ -n "$db" ] && client_args="$client_args $db" + +########################################################################### + +cur_attempt=1 + +while true; do + + if ( echo 'quit' | "$client_exe" $client_args >/dev/null 2>&1 ); then + echo "Success: server is ready to accept connection on socket." + exit 0 + fi + + [ $cur_attempt -ge $total_timeout ] && break + + sleep 1 + + cur_attempt=`expr $cur_attempt + 1` + +done + +echo "Error: server does not accept connections after $total_timeout seconds." +exit 0 diff --git a/mysql-test/t/wait_timeout-master.opt b/mysql-test/t/wait_timeout-master.opt index 0ad622e9677..9e5c2289eb2 100644 --- a/mysql-test/t/wait_timeout-master.opt +++ b/mysql-test/t/wait_timeout-master.opt @@ -1 +1 @@ ---wait-timeout=2 +--wait-timeout=1 diff --git a/mysql-test/t/wait_timeout.test b/mysql-test/t/wait_timeout.test index 4c1aeee5c04..67ed8fedfeb 100644 --- a/mysql-test/t/wait_timeout.test +++ b/mysql-test/t/wait_timeout.test @@ -4,11 +4,94 @@ # # Bug #8731: wait_timeout does not work on Mac OS X # + + +# Connect with another connection and reset counters +--disable_query_log +connect (wait_con,localhost,root,,test,,); +connection wait_con; +set session wait_timeout=100; +let $retries=300; +set @aborted_clients= 0; +--enable_query_log + +# Disable reconnect and do the query +connection default; +# If slow host (Valgrind...), we may have already timed out here. +# So force a reconnect if necessary, using a dummy query. And issue a +# 'flush status' to reset the 'aborted_clients' counter. +--enable_reconnect +select 0; +flush status; +--disable_reconnect +select 1; + +# Switch to wait_con and wait until server has aborted the connection +--disable_query_log +connection wait_con; +while (!`select @aborted_clients`) +{ + sleep 0.1; + let $aborted_clients = `SHOW STATUS LIKE 'aborted_clients'`; + eval set @aborted_clients= SUBSTRING('$aborted_clients', 16)+0; + + dec $retries; + if (!$retries) + { + Failed to detect that client has been aborted; + } +} +--enable_query_log + +connection default; +# When the connection is closed in this way, the error code should +# be consistent see bug#2845 for an explanation +--error 2006 +select 2; +--enable_reconnect +select 3; +# Disconnect so that we will not be confused by a future abort from this +# connection. +disconnect default; + +# +# Do the same test as above on a TCP connection +# (which we get by specifying a ip adress) + +# Connect with another connection and reset counters +--disable_query_log +connection wait_con; +flush status; # Reset counters +let $retries=300; +set @aborted_clients= 0; +--enable_query_log + +connect (con1,127.0.0.1,root,,test,$MASTER_MYPORT,); --disable_reconnect select 1; -# wait_timeout is 2, so we should get disconnected now ---sleep 5 + +# Switch to wait_con and wait until server has aborted the connection +--disable_query_log +connection wait_con; +while (!`select @aborted_clients`) +{ + sleep 0.1; + let $aborted_clients = `SHOW STATUS LIKE 'aborted_clients'`; + eval set @aborted_clients= SUBSTRING('$aborted_clients', 16)+0; + + dec $retries; + if (!$retries) + { + Failed to detect that client has been aborted; + } +} +--enable_query_log + +connection con1; +# When the connection is closed in this way, the error code should +# be consistent see bug#2845 for an explanation --error 2006 select 2; --enable_reconnect select 3; +disconnect con1; diff --git a/mysql-test/t/warnings.test b/mysql-test/t/warnings.test index aee03b39353..5e9d25aa09b 100644 --- a/mysql-test/t/warnings.test +++ b/mysql-test/t/warnings.test @@ -39,9 +39,8 @@ show warnings limit 1; drop database if exists not_exists_db; show count(*) warnings; create table t1(id int); -# PS doesn't give warnings on prepare ---disable_ps_protocol create table if not exists t1(id int); +--disable_ps_protocol select @@warning_count; --enable_ps_protocol drop table t1; @@ -51,7 +50,7 @@ drop table t1; # create table t1(a tinyint, b int not null, c date, d char(5)); -load data infile '../../std_data/warnings_loaddata.dat' into table t1 fields terminated by ','; +load data infile '../std_data_ln/warnings_loaddata.dat' into table t1 fields terminated by ','; # PS doesn't work good with @@warning_count --disable_ps_protocol select @@warning_count; @@ -126,12 +125,9 @@ drop table t1; # Test for deprecated TYPE= syntax # -# PS doesn't give warnings on prepare ---disable_ps_protocol create table t1 (id int) type=heap; alter table t1 type=myisam; drop table t1; ---enable_ps_protocol # # Test for deprecated table_type variable @@ -160,4 +156,60 @@ select * from t1 limit 1, 0; select * from t1 limit 0, 0; drop table t1; -# End of 4.1 tests +--echo End of 4.1 tests + +# +# Bug#20778: strange characters in warning message 1366 when called in SP +# + +let $engine_type= innodb; + +CREATE TABLE t1( f1 CHAR(20) ); +CREATE TABLE t2( f1 CHAR(20), f2 CHAR(25) ); +CREATE TABLE t3( f1 CHAR(20), f2 CHAR(25), f3 DATE ); + +INSERT INTO t1 VALUES ( 'a`' ); +INSERT INTO t2 VALUES ( 'a`', 'a`' ); +INSERT INTO t3 VALUES ( 'a`', 'a`', '1000-01-1' ); + +DROP PROCEDURE IF EXISTS sp1; +DROP PROCEDURE IF EXISTS sp2; +DROP PROCEDURE IF EXISTS sp3; +delimiter //; +CREATE PROCEDURE sp1() +BEGIN + DECLARE x NUMERIC ZEROFILL; + SELECT f1 INTO x FROM t1 LIMIT 1; +END// +CREATE PROCEDURE sp2() +BEGIN + DECLARE x NUMERIC ZEROFILL; + SELECT f1 INTO x FROM t2 LIMIT 1; +END// +CREATE PROCEDURE sp3() +BEGIN + DECLARE x NUMERIC ZEROFILL; + SELECT f1 INTO x FROM t3 LIMIT 1; +END// +delimiter ;// +CALL sp1(); +CALL sp2(); +CALL sp3(); + +DROP PROCEDURE IF EXISTS sp1; +delimiter //; +CREATE PROCEDURE sp1() +BEGIN +declare x numeric unsigned zerofill; +SELECT f1 into x from t2 limit 1; +END// +delimiter ;// +CALL sp1(); +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t3; +DROP PROCEDURE sp1; +DROP PROCEDURE sp2; +DROP PROCEDURE sp3; + +--echo End of 5.0 tests diff --git a/mysql-test/t/xa.test b/mysql-test/t/xa.test new file mode 100644 index 00000000000..92405bac137 --- /dev/null +++ b/mysql-test/t/xa.test @@ -0,0 +1,76 @@ +# +# WL#1756 +# +-- source include/have_innodb.inc +--disable_warnings +drop table if exists t1, t2; +--enable_warnings +create table t1 (a int) engine=innodb; +xa start 'test1'; +insert t1 values (10); +xa end 'test1'; +xa prepare 'test1'; +xa rollback 'test1'; +select * from t1; + +xa start 'test2'; +--error 1399 +xa start 'test-bad'; +insert t1 values (20); +--error 1399 +xa prepare 'test2'; +xa end 'test2'; +xa prepare 'test2'; +xa commit 'test2'; +select * from t1; + +xa start 'testa','testb'; +insert t1 values (30); + +--error 1399 +commit; + +xa end 'testa','testb'; + +--error 1399 +begin; +--error 1399 +create table t2 (a int); + +connect (con1,localhost,,,); +connection con1; + +--error 1440 +xa start 'testa','testb'; +--error 1440 +xa start 'testa','testb', 123; + +# gtrid [ , bqual [ , formatID ] ] +xa start 0x7465737462, 0x2030405060, 0xb; +insert t1 values (40); +xa end 'testb',' 0@P`',11; +xa prepare 'testb',0x2030405060,11; + +--error 1399 +start transaction; + +xa recover; + +# uncomment the line below when binlog will be able to prepare +#disconnect con1; +connection default; + +xa prepare 'testa','testb'; + +xa recover; + +--error 1397 +xa commit 'testb',0x2030405060,11; +xa rollback 'testa','testb'; + +--error 1064 +xa start 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'; + +select * from t1; +drop table t1; + |