summaryrefslogtreecommitdiff
path: root/mysql-test/t
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test/t')
-rw-r--r--mysql-test/t/alias.test2
-rw-r--r--mysql-test/t/alter_table.test10
-rw-r--r--mysql-test/t/analyze.test1
-rwxr-xr-xmysql-test/t/backup-master.sh2
-rw-r--r--mysql-test/t/backup.test10
-rw-r--r--mysql-test/t/bdb.test29
-rw-r--r--mysql-test/t/bigint.test9
-rw-r--r--mysql-test/t/binary.test12
-rw-r--r--mysql-test/t/binlog.test5
-rw-r--r--mysql-test/t/blackhole.test3
-rw-r--r--mysql-test/t/client_xml.test12
-rw-r--r--mysql-test/t/compress.test3
-rw-r--r--mysql-test/t/create.test38
-rw-r--r--mysql-test/t/create_select_tmp.test1
-rw-r--r--mysql-test/t/ctype_cp932.test23
-rw-r--r--mysql-test/t/ctype_cp932_notembedded.test32
-rw-r--r--mysql-test/t/ctype_euckr.test33
-rw-r--r--mysql-test/t/ctype_gb2312.test33
-rw-r--r--mysql-test/t/ctype_recoding.test2
-rw-r--r--mysql-test/t/ctype_uca.test1
-rw-r--r--mysql-test/t/ctype_ucs.test10
-rw-r--r--mysql-test/t/ctype_ucs_binlog.test2
-rw-r--r--mysql-test/t/ctype_ujis.test2
-rw-r--r--mysql-test/t/ctype_utf8.test10
-rw-r--r--mysql-test/t/date_formats.test7
-rw-r--r--mysql-test/t/delayed.test3
-rw-r--r--mysql-test/t/disabled.def2
-rw-r--r--mysql-test/t/federated.test31
-rw-r--r--mysql-test/t/flush_read_lock_kill.test2
-rw-r--r--mysql-test/t/fulltext.test20
-rw-r--r--mysql-test/t/fulltext2.test38
-rw-r--r--mysql-test/t/fulltext_var.test8
-rw-r--r--mysql-test/t/func_gconcat.test2
-rw-r--r--mysql-test/t/func_if.test8
-rw-r--r--mysql-test/t/func_math.test38
-rw-r--r--mysql-test/t/func_str.test8
-rw-r--r--mysql-test/t/grant.test12
-rw-r--r--mysql-test/t/grant2.test70
-rw-r--r--mysql-test/t/group_by.test4
-rw-r--r--mysql-test/t/group_min_max.test21
-rw-r--r--mysql-test/t/handler.test5
-rw-r--r--mysql-test/t/having.test28
-rw-r--r--mysql-test/t/heap.test11
-rw-r--r--mysql-test/t/im_daemon_life_cycle-im.opt2
-rw-r--r--mysql-test/t/im_life_cycle.imtest24
-rw-r--r--mysql-test/t/im_options_set.imtest8
-rw-r--r--mysql-test/t/im_options_unset.imtest8
-rw-r--r--mysql-test/t/index_merge.test56
-rw-r--r--mysql-test/t/information_schema.test61
-rw-r--r--mysql-test/t/init_file.test1
-rw-r--r--mysql-test/t/innodb.test348
-rw-r--r--mysql-test/t/innodb_cache.test4
-rw-r--r--mysql-test/t/innodb_notembedded.test40
-rw-r--r--mysql-test/t/innodb_unsafe_binlog-master.opt1
-rw-r--r--mysql-test/t/innodb_unsafe_binlog.test67
-rw-r--r--mysql-test/t/insert.test9
-rw-r--r--mysql-test/t/join.test6
-rw-r--r--mysql-test/t/join_nested.test42
-rw-r--r--mysql-test/t/join_outer.test1
-rw-r--r--mysql-test/t/kill.test59
-rw-r--r--mysql-test/t/loaddata.test42
-rw-r--r--mysql-test/t/merge.test26
-rw-r--r--mysql-test/t/mix_innodb_myisam_binlog.test34
-rw-r--r--mysql-test/t/myisam.test6
-rw-r--r--mysql-test/t/mysql.test20
-rw-r--r--mysql-test/t/mysql_client_test.test6
-rw-r--r--mysql-test/t/mysql_protocols.test2
-rw-r--r--mysql-test/t/mysqlbinlog.test61
-rw-r--r--mysql-test/t/mysqlbinlog2.test24
-rw-r--r--mysql-test/t/mysqldump.test129
-rw-r--r--mysql-test/t/mysqlshow.test2
-rw-r--r--mysql-test/t/mysqltest.test284
-rw-r--r--mysql-test/t/ndb_autodiscover.test34
-rw-r--r--mysql-test/t/ndb_basic.test77
-rw-r--r--mysql-test/t/ndb_bitfield.test8
-rw-r--r--mysql-test/t/ndb_blob.test6
-rw-r--r--mysql-test/t/ndb_cache_multi2.test39
-rw-r--r--mysql-test/t/ndb_config.test2
-rw-r--r--mysql-test/t/ndb_index_unique.test14
-rw-r--r--mysql-test/t/ndb_load.test24
-rw-r--r--mysql-test/t/ndb_multi.test1
-rw-r--r--mysql-test/t/ndb_read_multi_range.test2
-rw-r--r--mysql-test/t/outfile.test46
-rw-r--r--mysql-test/t/ps.test51
-rw-r--r--mysql-test/t/ps_1general.test2
-rw-r--r--mysql-test/t/query_cache.test16
-rw-r--r--mysql-test/t/query_cache_notembedded.test84
-rw-r--r--mysql-test/t/read_only.test5
-rw-r--r--mysql-test/t/repair.test2
-rw-r--r--mysql-test/t/rpl000001.test5
-rw-r--r--mysql-test/t/rpl000004.test4
-rw-r--r--mysql-test/t/rpl000009.test4
-rwxr-xr-xmysql-test/t/rpl000015-slave.sh2
-rw-r--r--mysql-test/t/rpl000015.test2
-rwxr-xr-xmysql-test/t/rpl000017-slave.sh6
-rw-r--r--mysql-test/t/rpl000017.test1
-rw-r--r--mysql-test/t/rpl_EE_error.test2
-rw-r--r--mysql-test/t/rpl_charset.test2
-rw-r--r--mysql-test/t/rpl_deadlock.test6
-rw-r--r--mysql-test/t/rpl_drop_db.test2
-rw-r--r--mysql-test/t/rpl_error_ignored_table.test2
-rw-r--r--mysql-test/t/rpl_failed_optimize.test3
-rw-r--r--mysql-test/t/rpl_flush_log_loop-master.opt2
-rwxr-xr-xmysql-test/t/rpl_flush_log_loop-master.sh6
-rw-r--r--mysql-test/t/rpl_flush_log_loop-slave.opt2
-rwxr-xr-xmysql-test/t/rpl_flush_log_loop-slave.sh6
-rw-r--r--mysql-test/t/rpl_flush_tables.test3
-rw-r--r--mysql-test/t/rpl_ignore_revoke-slave.opt1
-rw-r--r--mysql-test/t/rpl_ignore_revoke.test47
-rw-r--r--mysql-test/t/rpl_ignore_table-slave.opt1
-rw-r--r--mysql-test/t/rpl_ignore_table.test28
-rw-r--r--mysql-test/t/rpl_innodb.test4
-rw-r--r--mysql-test/t/rpl_insert_id.test3
-rw-r--r--mysql-test/t/rpl_loaddata.test17
-rw-r--r--mysql-test/t/rpl_loaddata_rule_m.test5
-rw-r--r--mysql-test/t/rpl_loaddata_rule_s.test5
-rw-r--r--mysql-test/t/rpl_loaddatalocal.test19
-rw-r--r--mysql-test/t/rpl_log.test2
-rwxr-xr-xmysql-test/t/rpl_misc_functions-slave.sh2
-rw-r--r--mysql-test/t/rpl_misc_functions.test7
-rw-r--r--mysql-test/t/rpl_multi_update3.test3
-rw-r--r--mysql-test/t/rpl_multi_update4-slave.opt1
-rw-r--r--mysql-test/t/rpl_multi_update4.test44
-rw-r--r--mysql-test/t/rpl_relayrotate.test5
-rw-r--r--mysql-test/t/rpl_replicate_do.test6
-rw-r--r--mysql-test/t/rpl_rewrite_db.test12
-rwxr-xr-xmysql-test/t/rpl_rotate_logs-slave.sh4
-rw-r--r--mysql-test/t/rpl_rotate_logs.test6
-rw-r--r--mysql-test/t/rpl_skip_error.test3
-rw-r--r--mysql-test/t/rpl_slave_status.test4
-rw-r--r--mysql-test/t/rpl_sp-slave.opt2
-rw-r--r--mysql-test/t/rpl_sp.test56
-rw-r--r--mysql-test/t/rpl_timezone.test6
-rw-r--r--mysql-test/t/rpl_trigger.test127
-rw-r--r--mysql-test/t/rpl_until.test4
-rw-r--r--mysql-test/t/schema.test6
-rw-r--r--mysql-test/t/select.test43
-rw-r--r--mysql-test/t/show_check.test3
-rw-r--r--mysql-test/t/skip_grants.test6
-rw-r--r--mysql-test/t/skip_name_resolve.test2
-rw-r--r--mysql-test/t/sp-big.test3
-rw-r--r--mysql-test/t/sp-code.test143
-rw-r--r--mysql-test/t/sp-destruct.test28
-rw-r--r--mysql-test/t/sp-dynamic.test6
-rw-r--r--mysql-test/t/sp-error.test223
-rw-r--r--mysql-test/t/sp-prelocking.test3
-rw-r--r--mysql-test/t/sp-security.test114
-rw-r--r--mysql-test/t/sp-threads.test2
-rw-r--r--mysql-test/t/sp-vars.test1273
-rw-r--r--mysql-test/t/sp.test1052
-rw-r--r--mysql-test/t/sp.test.orig5716
-rw-r--r--mysql-test/t/sp_notembedded.test262
-rw-r--r--mysql-test/t/sp_trans.test2
-rw-r--r--mysql-test/t/sql_mode.test9
-rw-r--r--mysql-test/t/subselect.test103
-rw-r--r--mysql-test/t/subselect_innodb.test1
-rw-r--r--mysql-test/t/subselect_notembedded.test8
-rw-r--r--mysql-test/t/symlink.test28
-rw-r--r--mysql-test/t/system_mysql_db_fix.test3
-rw-r--r--mysql-test/t/temp_table-master.opt2
-rw-r--r--mysql-test/t/temp_table.test2
-rw-r--r--mysql-test/t/trigger-compat.test17
-rw-r--r--mysql-test/t/trigger-grant.test513
-rw-r--r--mysql-test/t/trigger.test133
-rw-r--r--mysql-test/t/type_bit.test1
-rw-r--r--mysql-test/t/type_decimal.test9
-rw-r--r--mysql-test/t/type_float.test20
-rw-r--r--mysql-test/t/type_newdecimal-big.test31
-rw-r--r--mysql-test/t/type_time.test18
-rw-r--r--mysql-test/t/type_varchar.test18
-rw-r--r--mysql-test/t/union.test21
-rw-r--r--mysql-test/t/update.test19
-rw-r--r--mysql-test/t/user_var-binlog.test2
-rw-r--r--mysql-test/t/variables-master.opt2
-rw-r--r--mysql-test/t/variables.test17
-rw-r--r--mysql-test/t/view.test95
-rw-r--r--mysql-test/t/view_grant.test13
-rw-r--r--mysql-test/t/wait_timeout-master.opt2
-rw-r--r--mysql-test/t/wait_timeout.test23
-rw-r--r--mysql-test/t/warnings.test2
180 files changed, 11952 insertions, 920 deletions
diff --git a/mysql-test/t/alias.test b/mysql-test/t/alias.test
index 2746409c7e5..6546581eef2 100644
--- a/mysql-test/t/alias.test
+++ b/mysql-test/t/alias.test
@@ -61,9 +61,7 @@ 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
---disable_ps_protocol
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;
---enable_ps_protocol
drop table t1;
diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test
index f4245abfe86..cfa6182543b 100644
--- a/mysql-test/t/alter_table.test
+++ b/mysql-test/t/alter_table.test
@@ -412,3 +412,13 @@ 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/analyze.test b/mysql-test/t/analyze.test
index 656ff752c9b..a8fd0a4283e 100644
--- a/mysql-test/t/analyze.test
+++ b/mysql-test/t/analyze.test
@@ -61,5 +61,6 @@ prepare stmt1 from "SELECT * FROM t1 PROCEDURE ANALYSE()";
execute stmt1;
execute stmt1;
deallocate prepare stmt1;
+drop table t1;
# End of 4.1 tests
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 3034129ad4b..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 ": 1" ": X" ": 2" ": X" ": 22" ": X" ": 23" ": X" $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--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 ": 7" ": X" ": 17" ": X" $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--replace_result ": 7" ": X" ": 17" ": X" $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
backup table t4 to '../tmp';
drop table t4;
restore table t4 from '../tmp';
@@ -23,7 +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" $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--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;
@@ -52,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 72b3ee89ed5..d017d91bfb1 100644
--- a/mysql-test/t/bdb.test
+++ b/mysql-test/t/bdb.test
@@ -938,7 +938,25 @@ SELECT id FROM t1 WHERE (list_id = 1) AND (term = "lettera");
SELECT id FROM t1 WHERE (list_id = 1) AND (term = "letterd");
DROP TABLE t1;
-# End of 4.1 tests
+#
+# Bug #15536: Crash when DELETE with subquery using BDB tables
+#
+create table t1 (a int, key(a)) engine=bdb;
+create table t2 (b int, key(b)) engine=bdb;
+insert into t1 values (1),(1),(2),(3),(4);
+insert into t2 values (1),(5),(6),(7);
+delete from t1 where (a in (select b from t2));
+select count(*) from t1;
+# INSERT also blows up
+--error 1242
+insert into t1 set a=(select b from t2);
+select count(*) from t1;
+# UPDATE also blows up
+update t1 set a = a + 1 where (a in (select b from t2));
+select count(*) from t1;
+drop table t1, t2;
+
+--echo End of 4.1 tests
#
# alter temp table
@@ -992,4 +1010,13 @@ create table t1 (a 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;
+
--echo End of 5.0 tests
diff --git a/mysql-test/t/bigint.test b/mysql-test/t/bigint.test
index 7871b3647e3..35cda11646a 100644
--- a/mysql-test/t/bigint.test
+++ b/mysql-test/t/bigint.test
@@ -270,3 +270,12 @@ VALUES (9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999,
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 1ac0cfebb28..4ab6ee9eaf1 100644
--- a/mysql-test/t/binary.test
+++ b/mysql-test/t/binary.test
@@ -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.test b/mysql-test/t/binlog.test
index 2310e800df7..1063940d378 100644
--- a/mysql-test/t/binlog.test
+++ b/mysql-test/t/binlog.test
@@ -1,6 +1,7 @@
#
# 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
@@ -18,7 +19,7 @@ begin;
insert t2 values (5);
commit;
# first COMMIT must be Query_log_event, second - Xid_log_event
---replace_result "xid=18" "xid=11"
+--replace_result "xid=21" "xid=12"
--replace_column 2 # 5 #
show binlog events from 98;
drop table t1,t2;
@@ -40,7 +41,7 @@ while ($1)
--enable_query_log
commit;
drop table t1;
---replace_result "xid=29" "xid=18"
+--replace_result "xid=32" "xid=19"
--replace_column 2 # 5 #
show binlog events in 'master-bin.000001' from 98;
--replace_column 2 # 5 #
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/client_xml.test b/mysql-test/t/client_xml.test
index 58e9178ef3a..017b7a1569a 100644
--- a/mysql-test/t/client_xml.test
+++ b/mysql-test/t/client_xml.test
@@ -9,13 +9,13 @@ create table t1 (
`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 --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'
+--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/compress.test b/mysql-test/t/compress.test
index 46244edd2a8..3f1892b5dec 100644
--- a/mysql-test/t/compress.test
+++ b/mysql-test/t/compress.test
@@ -1,6 +1,9 @@
# 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);
diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test
index 6f3bc67cb30..9fcbb53e24d 100644
--- a/mysql-test/t/create.test
+++ b/mysql-test/t/create.test
@@ -218,13 +218,6 @@ create table if not exists t1 select 1,2,3,4;
create table if not exists t1 select 1;
select * from t1;
drop table t1;
-create table t1 select 1,2,3;
-create table if not exists t1 select 1,2;
---error 1136
-create table if not exists t1 select 1,2,3,4;
-create table if not exists t1 select 1;
-select * from t1;
-drop table t1;
#
# Test create table if not exists with duplicate key error
@@ -512,6 +505,13 @@ DESC t2;
DROP TABLE t1,t2;
#
+# Bug#12913 Simple SQL can crash server or connection
+#
+CREATE TABLE t12913 (f1 ENUM ('a','b')) AS SELECT 'a' AS f1;
+SELECT * FROM t12913;
+DROP TABLE t12913;
+
+#
# Bug#11028: Crash on create table like
#
create database mysqltest;
@@ -573,6 +573,22 @@ 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)
) select 'a' as a , 1 as b from t2 ;
@@ -644,4 +660,12 @@ alter table t1 max_rows=100000000000;
show create table t1;
drop table t1;
+#
+# 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;
+
# 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/ctype_cp932.test b/mysql-test/t/ctype_cp932.test
index 082786e38af..688d06c4dde 100644
--- a/mysql-test/t/ctype_cp932.test
+++ b/mysql-test/t/ctype_cp932.test
@@ -398,28 +398,6 @@ DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
-# 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
-
SET collation_connection='cp932_japanese_ci';
-- source include/ctype_filesort.inc
SET collation_connection='cp932_bin';
@@ -434,3 +412,4 @@ 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_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_euckr.test b/mysql-test/t/ctype_euckr.test
new file mode 100644
index 00000000000..56939817b2f
--- /dev/null
+++ b/mysql-test/t/ctype_euckr.test
@@ -0,0 +1,33 @@
+-- source include/have_euckr.inc
+
+#
+# Tests with the euckr character set
+#
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+SET @test_character_set= 'euckr';
+SET @test_collation= 'euckr_korean_ci';
+-- source include/ctype_common.inc
+
+SET NAMES euckr;
+SET collation_connection='euckr_korean_ci';
+-- source include/ctype_filesort.inc
+-- source include/ctype_innodb_like.inc
+-- source include/ctype_like_escape.inc
+SET collation_connection='euckr_bin';
+-- source include/ctype_filesort.inc
+-- source include/ctype_innodb_like.inc
+-- source include/ctype_like_escape.inc
+
+#
+# Bug#15377 Valid multibyte sequences are truncated on INSERT
+#
+SET NAMES euckr;
+CREATE TABLE t1 (a text) character set euckr;
+INSERT INTO t1 VALUES (0xA2E6),(0xFEF7);
+SELECT hex(a) FROM t1 ORDER BY a;
+DROP TABLE t1;
+
+# End of 4.1 tests
diff --git a/mysql-test/t/ctype_gb2312.test b/mysql-test/t/ctype_gb2312.test
new file mode 100644
index 00000000000..835818d441c
--- /dev/null
+++ b/mysql-test/t/ctype_gb2312.test
@@ -0,0 +1,33 @@
+-- source include/have_gb2312.inc
+
+#
+# Tests with the gb2312 character set
+#
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+SET @test_character_set= 'gb2312';
+SET @test_collation= 'gb2312_chinese_ci';
+-- source include/ctype_common.inc
+
+SET NAMES gb2312;
+SET collation_connection='gb2312_chinese_ci';
+-- source include/ctype_filesort.inc
+-- source include/ctype_innodb_like.inc
+-- source include/ctype_like_escape.inc
+SET collation_connection='gb2312_bin';
+-- source include/ctype_filesort.inc
+-- source include/ctype_innodb_like.inc
+-- source include/ctype_like_escape.inc
+
+#
+# Bug#15377 Valid multibyte sequences are truncated on INSERT
+#
+SET NAMES gb2312;
+CREATE TABLE t1 (a text) character set gb2312;
+INSERT INTO t1 VALUES (0xA2A1),(0xD7FE);
+SELECT hex(a) FROM t1 ORDER BY a;
+DROP TABLE t1;
+
+# End of 4.1 tests
diff --git a/mysql-test/t/ctype_recoding.test b/mysql-test/t/ctype_recoding.test
index 5648cea7fd3..2d6b55600b1 100644
--- a/mysql-test/t/ctype_recoding.test
+++ b/mysql-test/t/ctype_recoding.test
@@ -186,5 +186,5 @@ select rpad(c1,3,'ö'), rpad('ö',3,c1) from t1;
# TODO
#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;
# End of 4.1 tests
diff --git a/mysql-test/t/ctype_uca.test b/mysql-test/t/ctype_uca.test
index 6d8713f4910..3e49b9de883 100644
--- a/mysql-test/t/ctype_uca.test
+++ b/mysql-test/t/ctype_uca.test
@@ -212,6 +212,7 @@ 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;
diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test
index 626c7e0e1b6..d4ea8dd57ad 100644
--- a/mysql-test/t/ctype_ucs.test
+++ b/mysql-test/t/ctype_ucs.test
@@ -421,6 +421,16 @@ insert into t1 values (0x005b);
select hex(a) from t1;
drop table t1;
+#
+# Bug #14583 Bug on query using a LIKE on indexed field with ucs2_bin collation
+#
+--disable_warnings
+create table t1(f1 varchar(5) CHARACTER SET ucs2 COLLATE ucs2_bin NOT NULL) engine=InnoDB;
+--enable_warnings
+insert into t1 values('a');
+create index t1f1 on t1(f1);
+select f1 from t1 where f1 like 'a%';
+drop table t1;
# End of 4.1 tests
#
diff --git a/mysql-test/t/ctype_ucs_binlog.test b/mysql-test/t/ctype_ucs_binlog.test
index 1ce55edd469..2467d34386c 100644
--- a/mysql-test/t/ctype_ucs_binlog.test
+++ b/mysql-test/t/ctype_ucs_binlog.test
@@ -14,7 +14,7 @@ show binlog events from 98;
# 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 c1d6c67387b..77d250b5c45 100644
--- a/mysql-test/t/ctype_ujis.test
+++ b/mysql-test/t/ctype_ujis.test
@@ -1170,7 +1170,7 @@ INSERT INTO t1 VALUES(_ujis 0xA4A2);
DELIMITER |;
CREATE PROCEDURE sp1()
BEGIN
- DECLARE a CHAR(1);
+ DECLARE a CHAR(2) CHARSET ujis;
DECLARE cur1 CURSOR FOR SELECT c1 FROM t1;
OPEN cur1;
FETCH cur1 INTO a;
diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test
index a96564f4e76..c9b2b9fc18f 100644
--- a/mysql-test/t/ctype_utf8.test
+++ b/mysql-test/t/ctype_utf8.test
@@ -868,6 +868,16 @@ set names utf8;
select distinct char(a) from t1;
drop table t1;
+#
+# Bug#15581: COALESCE function truncates mutli-byte TINYTEXT values
+#
+CREATE TABLE t1 (t TINYTEXT CHARACTER SET utf8);
+INSERT INTO t1 VALUES(REPEAT('a', 100));
+CREATE TEMPORARY TABLE t2 SELECT COALESCE(t) AS bug FROM t1;
+SELECT LENGTH(bug) FROM t2;
+DROP TABLE t2;
+DROP TABLE t1;
+
# End of 4.1 tests
#
diff --git a/mysql-test/t/date_formats.test b/mysql-test/t/date_formats.test
index c007c2f5205..b4c6cf0d72a 100644
--- a/mysql-test/t/date_formats.test
+++ b/mysql-test/t/date_formats.test
@@ -269,4 +269,11 @@ insert into t1 (f1) values ("2005-01-01");
insert into t1 (f1) values ("2005-02-01");
select date_format(f1, "%m") as d1, date_format(f1, "%M") as d2 from t1 order by date_format(f1, "%M");
drop table t1;
+
+#
+# Bug #15828
+#
+select str_to_date( 1, NULL );
+select str_to_date( NULL, 1 );
+select str_to_date( 1, IF(1=1,NULL,NULL) );
# End of 4.1 tests
diff --git a/mysql-test/t/delayed.test b/mysql-test/t/delayed.test
index ca34cc020f3..5ae757b1fde 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
diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index 4f5e11e7fbd..f71e24ff3ed 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -11,4 +11,4 @@
##############################################################################
sp-goto : GOTO is currently is disabled - will be fixed in the future
-kill : Unstable test case, bug#9712
+ndb_load : Bug#17233
diff --git a/mysql-test/t/federated.test b/mysql-test/t/federated.test
index b6b3b90c083..d1e03f8a05a 100644
--- a/mysql-test/t/federated.test
+++ b/mysql-test/t/federated.test
@@ -1224,4 +1224,35 @@ 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;
+
source include/federated_cleanup.inc;
diff --git a/mysql-test/t/flush_read_lock_kill.test b/mysql-test/t/flush_read_lock_kill.test
index de2576300dc..19a47b2893a 100644
--- a/mysql-test/t/flush_read_lock_kill.test
+++ b/mysql-test/t/flush_read_lock_kill.test
@@ -42,7 +42,7 @@ connection con1;
# 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
+--error 0,1053,2013
reap;
connection con2;
diff --git a/mysql-test/t/fulltext.test b/mysql-test/t/fulltext.test
index ea92ec944ed..91033fe2ba9 100644
--- a/mysql-test/t/fulltext.test
+++ b/mysql-test/t/fulltext.test
@@ -357,4 +357,24 @@ SELECT a FROM t1 WHERE MATCH a AGAINST('testword' IN BOOLEAN MODE);
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')";
+EXECUTE stmt;
+EXECUTE stmt;
+DEALLOCATE PREPARE stmt;
+DROP TABLE t1;
+
# End of 4.1 tests
diff --git a/mysql-test/t/fulltext2.test b/mysql-test/t/fulltext2.test
index bcd39b9ea04..fd97f795534 100644
--- a/mysql-test/t/fulltext2.test
+++ b/mysql-test/t/fulltext2.test
@@ -179,7 +179,45 @@ update t1 set a='aaaxxx' where a = 'aaayyy';
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
+drop table t1;
+#
+# BUG#11336
+#
+# for uca collation isalnum and strnncollsp don't agree on whether
+# 0xC2A0 is a space (strnncollsp is right, isalnum is wrong).
+#
+# they still don't, the bug was fixed by avoiding strnncollsp
+#
+
+set names utf8;
+create table t1(a text,fulltext(a)) collate=utf8_swedish_ci;
+insert into t1 values('test test '),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
+('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test');
+delete from t1 limit 1;
+
+#
+# BUG#16489: utf8 + fulltext leads to corrupt index file.
+#
+truncate table t1;
+insert into t1 values('ab c d');
+update t1 set a='ab c d';
+select * from t1 where match a against('ab c' in boolean mode);
drop table t1;
+set names latin1;
# End of 4.1 tests
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_gconcat.test b/mysql-test/t/func_gconcat.test
index cd686585dd8..058df9af56b 100644
--- a/mysql-test/t/func_gconcat.test
+++ b/mysql-test/t/func_gconcat.test
@@ -69,7 +69,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;
diff --git a/mysql-test/t/func_if.test b/mysql-test/t/func_if.test
index 4e0f426c10b..beaa371f847 100644
--- a/mysql-test/t/func_if.test
+++ b/mysql-test/t/func_if.test
@@ -89,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_math.test b/mysql-test/t/func_math.test
index 24dd18daab1..4041c267134 100644
--- a/mysql-test/t/func_math.test
+++ b/mysql-test/t/func_math.test
@@ -121,7 +121,9 @@ drop table t1;
#
# InnoDB is required to reproduce the fault, but it is okay if we default to
# MyISAM when testing.
+--disable_warnings
create table t1 (a varchar(90), ts datetime not null, index (a)) engine=innodb default charset=utf8;
+--enable_warnings
insert into t1 values ('http://www.foo.com/', now());
select a from t1 where a='http://www.foo.com/' order by abs(timediff(ts, 0));
drop table t1;
@@ -139,3 +141,39 @@ 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_str.test b/mysql-test/t/func_str.test
index ac2bf820257..ef20d766bce 100644
--- a/mysql-test/t/func_str.test
+++ b/mysql-test/t/func_str.test
@@ -676,4 +676,12 @@ 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;
+
# End of 5.0 tests
diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test
index e806df5e91c..9a8b7a19c59 100644
--- a/mysql-test/t/grant.test
+++ b/mysql-test/t/grant.test
@@ -499,4 +499,16 @@ revoke all privileges on ÂÄ.* from root@localhost;
show grants for root@localhost;
set names latin1;
+#
+# Bug #15598 Server crashes in specific case during setting new password
+# - Caused by a user with host ''
+#
+create user mysqltest_7@;
+set password for mysqltest_7@ = password('systpass');
+show grants for mysqltest_7@;
+drop user mysqltest_7@;
+flush privileges; # BUG#16297(flush should be removed when that bug is fixed)
+--error 1141
+show grants for mysqltest_7@;
+
# End of 4.1 tests
diff --git a/mysql-test/t/grant2.test b/mysql-test/t/grant2.test
index 2fa82ce5dce..2c62d2f1bd3 100644
--- a/mysql-test/t/grant2.test
+++ b/mysql-test/t/grant2.test
@@ -155,6 +155,38 @@ 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;
+
#
# Create and drop user
#
@@ -254,6 +286,7 @@ drop user 'mysqltest_1b', 'mysqltest_2b', 'mysqltest_3b';
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';
@@ -293,6 +326,7 @@ 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;
@@ -395,3 +429,39 @@ disconnect con2root;
disconnect con3root;
# End of 4.1 tests
+
+#
+# Bug#17279 user with no global privs and with create
+# priv in db can create databases
+#
+
+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;
+
+connect (con1,localhost,mysqltest_1,password,TESTDB);
+
+# 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;
+
+# 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;
+
diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test
index bf557029a55..fb9835c5d7f 100644
--- a/mysql-test/t/group_by.test
+++ b/mysql-test/t/group_by.test
@@ -596,9 +596,7 @@ drop table t1;
CREATE TABLE t1 (n int);
INSERT INTO t1 VALUES (1);
---disable_ps_protocol
SELECT n+1 AS n FROM t1 GROUP BY n;
---enable_ps_protocol
DROP TABLE t1;
#
@@ -623,11 +621,9 @@ insert into t1 values ('aaa', 'bb1'), ('aaa', 'bb2');
insert into t2 values ('aaa', 'bb1'), ('aaa', 'bb2');
# query with ambiguous column reference 'c2'
---disable_ps_protocol
select t1.c1 as c2 from t1, t2 where t1.c2 = t2.c4
group by c2;
show warnings;
---enable_ps_protocol
# this query has no ambiguity
select t1.c1 as c2 from t1, t2 where t1.c2 = t2.c4
diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test
index e15ef92116c..8dc55532bbf 100644
--- a/mysql-test/t/group_min_max.test
+++ b/mysql-test/t/group_min_max.test
@@ -715,3 +715,24 @@ 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;
diff --git a/mysql-test/t/handler.test b/mysql-test/t/handler.test
index f3e14c3cd2b..a7f1eeaa2cc 100644
--- a/mysql-test/t/handler.test
+++ b/mysql-test/t/handler.test
@@ -2,8 +2,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));
diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test
index fb223d2a9af..78628bef198 100644
--- a/mysql-test/t/having.test
+++ b/mysql-test/t/having.test
@@ -123,6 +123,34 @@ group by a.id, a.description
having (a.description is not null) and (c=0);
drop table t1,t2,t3;
+#
+# Bug #14274: HAVING clause containing only set function
+#
+
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES (3), (4), (1), (3), (1);
+
+SELECT SUM(a) FROM t1 GROUP BY a HAVING SUM(a)>0;
+SELECT SUM(a) FROM t1 GROUP BY a HAVING SUM(a);
+
+DROP TABLE t1;
+
+#
+# Bug #14927: HAVING clause containing constant false conjunct
+#
+
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES (1), (2), (1), (3), (2), (1);
+
+SELECT a FROM t1 GROUP BY a HAVING a > 1;
+SELECT a FROM t1 GROUP BY a HAVING 1 != 1 AND a > 1;
+SELECT 0 AS x, a FROM t1 GROUP BY x,a HAVING x=1 AND a > 1;
+
+EXPLAIN SELECT a FROM t1 GROUP BY a HAVING 1 != 1 AND a > 1;
+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
#
diff --git a/mysql-test/t/heap.test b/mysql-test/t/heap.test
index fcaa4c41ece..82294db336d 100644
--- a/mysql-test/t/heap.test
+++ b/mysql-test/t/heap.test
@@ -436,6 +436,17 @@ insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
drop table t1;
+#
+# Bug 12796: Record doesn't show when selecting through index
+#
+CREATE TABLE t1 (a int, key(a)) engine=heap;
+insert into t1 values (0);
+delete from t1;
+select * from t1;
+insert into t1 values (0), (1);
+select * from t1 where a = 0;
+drop table t1;
+
# End of 4.1 tests
#
diff --git a/mysql-test/t/im_daemon_life_cycle-im.opt b/mysql-test/t/im_daemon_life_cycle-im.opt
index 6bfd9a24107..21c01191e4c 100644
--- a/mysql-test/t/im_daemon_life_cycle-im.opt
+++ b/mysql-test/t/im_daemon_life_cycle-im.opt
@@ -1,2 +1,2 @@
--run-as-service
---log=$MYSQL_TEST_DIR/var/log/im.log
+--log=$MYSQLTEST_VARDIR/log/im.log
diff --git a/mysql-test/t/im_life_cycle.imtest b/mysql-test/t/im_life_cycle.imtest
index c2b1c9a56ec..445ae7f72fa 100644
--- a/mysql-test/t/im_life_cycle.imtest
+++ b/mysql-test/t/im_life_cycle.imtest
@@ -140,3 +140,27 @@ SHOW INSTANCES;
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed
SHOW INSTANCES;
+
+###########################################################################
+#
+# 1.1.8. Check that Instance Manager returns an error on
+# incomplete SHOW INSTANCE STATUS command.
+#
+###########################################################################
+--error 1149
+SHOW INSTANCE STATUS;
+
+#
+# Tests for bug fixes
+#
+
+#
+# Bug #12813 Instance Manager: START/STOP INSTANCE commands accept
+# a list as argument.
+#
+
+--error 1149
+START INSTANCE mysqld1,mysqld2,mysqld3;
+
+--error 1149
+STOP INSTANCE mysqld1,mysqld2,mysqld3;
diff --git a/mysql-test/t/im_options_set.imtest b/mysql-test/t/im_options_set.imtest
index 785c6d05fef..a9b64861f99 100644
--- a/mysql-test/t/im_options_set.imtest
+++ b/mysql-test/t/im_options_set.imtest
@@ -48,7 +48,7 @@
# - check the configuration file;
---exec grep server_id $MYSQL_TEST_DIR/var/im.cnf ;
+--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ;
# - check the running instances.
@@ -79,7 +79,7 @@ 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 $MYSQL_TEST_DIR/var/im.cnf ;
+--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''
@@ -104,7 +104,7 @@ 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 $MYSQL_TEST_DIR/var/im.cnf ;
+--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).
@@ -122,7 +122,7 @@ FLUSH INSTANCES;
# - check that the configuration file has not been updated;
---exec grep server_id $MYSQL_TEST_DIR/var/im.cnf ;
+--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''
diff --git a/mysql-test/t/im_options_unset.imtest b/mysql-test/t/im_options_unset.imtest
index 74ec42ac3f9..40629805d45 100644
--- a/mysql-test/t/im_options_unset.imtest
+++ b/mysql-test/t/im_options_unset.imtest
@@ -55,7 +55,7 @@
# - check the configuration file;
---exec grep server_id $MYSQL_TEST_DIR/var/im.cnf ;
+--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ;
# - check the running instances.
@@ -86,7 +86,7 @@ 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 $MYSQL_TEST_DIR/var/im.cnf ;
+--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
@@ -111,7 +111,7 @@ 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 $MYSQL_TEST_DIR/var/im.cnf || true;
+--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);
@@ -130,7 +130,7 @@ 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 $MYSQL_TEST_DIR/var/im.cnf || true;
+--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''
diff --git a/mysql-test/t/index_merge.test b/mysql-test/t/index_merge.test
index 42175a757c2..3da5711bf7a 100644
--- a/mysql-test/t/index_merge.test
+++ b/mysql-test/t/index_merge.test
@@ -327,3 +327,59 @@ set join_buffer_size= @save_join_buffer_size;
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;
diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test
index acbc62f1364..5e0d57e10dd 100644
--- a/mysql-test/t/information_schema.test
+++ b/mysql-test/t/information_schema.test
@@ -748,3 +748,64 @@ 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 #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;
+
+#
+# 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;
diff --git a/mysql-test/t/init_file.test b/mysql-test/t/init_file.test
index de6aca455bd..8b4b788777b 100644
--- a/mysql-test/t/init_file.test
+++ b/mysql-test/t/init_file.test
@@ -7,3 +7,4 @@
#
# End of 4.1 tests
+echo ok;
diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test
index 735deba2b05..64d7d55294d 100644
--- a/mysql-test/t/innodb.test
+++ b/mysql-test/t/innodb.test
@@ -1316,7 +1316,7 @@ show variables like "innodb_sync_spin_loops";
# Test for innodb_thread_concurrency variable
show variables like "innodb_thread_concurrency";
-set global innodb_thread_concurrency=1000;
+set global innodb_thread_concurrency=1001;
show variables like "innodb_thread_concurrency";
set global innodb_thread_concurrency=0;
show variables like "innodb_thread_concurrency";
@@ -1619,33 +1619,7 @@ connection a;
checksum table t1;
drop table t1;
-#
-# 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;
@@ -1679,6 +1653,10 @@ 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;
@@ -1708,6 +1686,10 @@ 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;
@@ -1737,6 +1719,10 @@ 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;
@@ -1762,6 +1748,10 @@ 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;
@@ -1772,6 +1762,7 @@ commit;
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;
@@ -1782,6 +1773,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;
@@ -1811,11 +1803,47 @@ 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
#
@@ -1833,4 +1861,268 @@ create table t1 (a varchar(255) character set utf8,
e varchar(255) character set utf8,
key (a,b,c,d,e)) engine=innodb;
---echo End of 5.0 tests
+
+# 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 (
+ a int, b char(10), filler char(10), primary key(a, b(2))
+) character set utf8 engine = innodb;
+
+insert into t2 values (1,'abcdefg','one');
+insert into t2 values (2,'ijkilmn','two');
+insert into t2 values (3, 'qrstuvw','three');
+update t2 set a=5, filler='booo' where a=1;
+drop table t2;
+create table t2 (
+ a int, b char(10), filler char(10), primary key(a, b(2))
+) character set ucs2 engine = innodb;
+
+insert into t2 values (1,'abcdefg','one');
+insert into t2 values (2,'ijkilmn','two');
+insert into t2 values (3, 'qrstuvw','three');
+update t2 set a=5, filler='booo' where a=1;
+drop table t2;
+
+create table t1(a int not null, b char(110),primary key(a,b(100))) engine=innodb default charset=utf8;
+insert into t1 values(1,'abcdefg'),(2,'defghijk');
+insert into t1 values(6,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1);
+insert into t1 values(7,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2);
+select a,hex(b) from t1 order by b;
+update t1 set b = 'three' where a = 6;
+drop table t1;
+create table t1(a int not null, b text(110),primary key(a,b(100))) engine=innodb default charset=utf8;
+insert into t1 values(1,'abcdefg'),(2,'defghijk');
+insert into t1 values(6,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1);
+insert into t1 values(7,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2);
+select a,hex(b) from t1 order by b;
+update t1 set b = 'three' where a = 6;
+drop table t1;
+
+# Ensure that <tablename>_ibfk_0 is not mistreated as a
+# generated foreign key identifier. (Bug #16387)
+
+CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
+CREATE TABLE t2(a INT) ENGINE=InnoDB;
+ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
+ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
+ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
+ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
+SHOW CREATE TABLE t2;
+DROP TABLE t2,t1;
+
+#
+# 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;
+disconnect a;
+disconnect b;
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_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..503c8457b2c
--- /dev/null
+++ b/mysql-test/t/innodb_unsafe_binlog-master.opt
@@ -0,0 +1 @@
+--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 51d936f5b4f..ddde6cfa5d3 100644
--- a/mysql-test/t/insert.test
+++ b/mysql-test/t/insert.test
@@ -99,27 +99,22 @@ create table t1(number int auto_increment primary key, original_value varchar(50
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
@@ -130,22 +125,18 @@ set @value= -1e+1111111111;
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;
diff --git a/mysql-test/t/join.test b/mysql-test/t/join.test
index e58227df067..f6a57d5e230 100644
--- a/mysql-test/t/join.test
+++ b/mysql-test/t/join.test
@@ -517,6 +517,12 @@ 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;
diff --git a/mysql-test/t/join_nested.test b/mysql-test/t/join_nested.test
index 9f23e2d0e2f..8adcf05be93 100644
--- a/mysql-test/t/join_nested.test
+++ b/mysql-test/t/join_nested.test
@@ -900,3 +900,45 @@ explain select * from t2 left join
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;
diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test
index 367b98f2485..03ad56ed2b6 100644
--- a/mysql-test/t/join_outer.test
+++ b/mysql-test/t/join_outer.test
@@ -700,6 +700,7 @@ SELECT COALESCE(t2.EMPNUM,t1.EMPNUM) AS EMPNUM, NAME, GRP
SELECT * FROM v1;
SELECT * FROM v1 WHERE EMPNUM < 10;
+DROP VIEW v1;
DROP TABLE t1,t2;
#
diff --git a/mysql-test/t/kill.test b/mysql-test/t/kill.test
index 7f3a9932d31..8302c767985 100644
--- a/mysql-test/t/kill.test
+++ b/mysql-test/t/kill.test
@@ -12,7 +12,7 @@ connect (con2, localhost, root,,);
#remember id of con1
connection con1;
--disable_warnings
-drop table if exists t1;
+drop table if exists t1, t2, t3;
--enable_warnings
--disable_reconnect
@@ -25,11 +25,18 @@ select ((@id := kill_id) - kill_id) from t1;
kill @id;
connection con1;
---sleep 1
+--sleep 2
-# 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,6 +47,50 @@ connection con2;
select 4;
drop table t1;
+connection default;
+#
+# BUG#14851: killing long running subquery processed via a temporary table.
+#
+create table t1 (id int primary key);
+create table t2 (id int unsigned not null);
+
+connect (conn1, localhost, root,,);
+connection conn1;
+
+-- disable_result_log
+-- disable_query_log
+let $1 = 4096;
+while ($1)
+{
+ eval insert into t1 values ($1);
+ dec $1;
+}
+-- enable_query_log
+-- enable_result_log
+
+insert into t2 select id from t1;
+
+create table t3 (kill_id int);
+insert into t3 values(connection_id());
+
+-- disable_result_log
+send select id from t1 where id in (select distinct id from t2);
+-- enable_result_log
+
+connect (conn2, localhost, root,,);
+connection conn2;
+select ((@id := kill_id) - kill_id) from t3;
+-- sleep 1
+kill @id;
+
+connection conn1;
+-- error 1053,2013
+reap;
+
+connection default;
+
+drop table t1, t2, t3;
+
# End of 4.1 tests
#
diff --git a/mysql-test/t/loaddata.test b/mysql-test/t/loaddata.test
index 09d97a42714..27c8005ca0c 100644
--- a/mysql-test/t/loaddata.test
+++ b/mysql-test/t/loaddata.test
@@ -7,25 +7,25 @@ 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,7 +63,7 @@ drop table t1;
# ENCLOSED
#
create table t1 (a varchar(20), b varchar(20));
-load data infile '../../std_data/loaddata_dq.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;
@@ -74,40 +74,40 @@ drop table t1;
#
create table t1 (a int default 100, b int, c varchar(60));
# we can do something like this
-load data infile '../../std_data/rpl_loaddata.dat' into table t1 (a, @b) set b=@b+10, c=concat("b=",@b);
+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/rpl_loaddata.dat' into table t1 (a, @b) set c= if(a is null,"oops",a);
+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/rpl_loaddata.dat' into table t1 (@a, b) set c= if(@a is null,@c,b);
+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/rpl_loaddata.dat' into table t1 (@a, @b);
+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/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c="Wow";
+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/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));
+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/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, @b);
+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/rpl_loaddata.dat' into table t1 (@dummy,@n) set a= @n, c= (select str from t2 where num=@n);
+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
diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test
index ff05867b7c1..060f1ea167b 100644
--- a/mysql-test/t/merge.test
+++ b/mysql-test/t/merge.test
@@ -352,4 +352,30 @@ INSERT INTO t2 (b) VALUES (1) ON DUPLICATE KEY UPDATE b=3;
SELECT b FROM t2;
DROP TABLE t1, t2;
+
+#
+# BUG#5390 - problems with merge tables
+# Problem #1: INSERT...SELECT
+#
+#drop table if exists t1, t2, t3;
+create table t1(a int);
+create table t2(a int);
+insert into t1 values (1);
+insert into t2 values (2);
+create table t3 (a int) engine=merge union=(t1, t2) insert_method=first;
+select * from t3;
+#
+insert t2 select * from t2;
+select * from t2;
+#
+insert t3 select * from t1;
+select * from t3;
+#
+insert t1 select * from t3;
+select * from t1;
+select * from t2;
+select * from t3;
+check table t1, t2;
+drop table t1, t2, t3;
+
# End of 4.1 tests
diff --git a/mysql-test/t/mix_innodb_myisam_binlog.test b/mysql-test/t/mix_innodb_myisam_binlog.test
index 658584b625e..66440f1236e 100644
--- a/mysql-test/t/mix_innodb_myisam_binlog.test
+++ b/mysql-test/t/mix_innodb_myisam_binlog.test
@@ -259,5 +259,37 @@ 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/myisam.test b/mysql-test/t/myisam.test
index fb90c16bb86..4f07df4e4f2 100644
--- a/mysql-test/t/myisam.test
+++ b/mysql-test/t/myisam.test
@@ -711,14 +711,14 @@ 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 ./var/master-data/test/t1.MYI ;
+system rm $MYSQLTEST_VARDIR/master-data/test/t1.MYI ;
drop table if exists t1;
create table t1 (a int) engine=myisam;
-system rm ./var/master-data/test/t1.MYI ;
+system rm $MYSQLTEST_VARDIR/master-data/test/t1.MYI ;
--error 1051,6
drop table t1;
create table t1 (a int) engine=myisam;
-system rm ./var/master-data/test/t1.MYD ;
+system rm $MYSQLTEST_VARDIR/master-data/test/t1.MYD ;
--error 1105,6,29
drop table t1;
--error 1051
diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test
index 0783c043ef6..dbf65845e6a 100644
--- a/mysql-test/t/mysql.test
+++ b/mysql-test/t/mysql.test
@@ -1,3 +1,5 @@
+# This test should work in embedded server after we fix mysqltest
+-- source include/not_embedded.inc
#
# Testing the MySQL command line client(mysql)
#
@@ -41,3 +43,21 @@ lock tables t1 write;
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; set @@session.character_set_client= 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; set character_set_client= 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
diff --git a/mysql-test/t/mysql_client_test.test b/mysql-test/t/mysql_client_test.test
index 66b57dd5fb7..b61deeac001 100644
--- a/mysql-test/t/mysql_client_test.test
+++ b/mysql-test/t/mysql_client_test.test
@@ -1,3 +1,6 @@
+# This test should work in embedded server after we fix mysqltest
+-- source include/not_embedded.inc
+
# We run with different binaries for normal and --embedded-server
#
# If this test fails with "command "$MYSQL_CLIENT_TEST" failed",
@@ -6,7 +9,8 @@
# var/log/mysql_client_test.trace
--disable_result_log
---exec echo $MYSQL_CLIENT_TEST --getopt-ll-test=25600M
--exec $MYSQL_CLIENT_TEST --getopt-ll-test=25600M
# End of 4.1 tests
+echo ok;
+
diff --git a/mysql-test/t/mysql_protocols.test b/mysql-test/t/mysql_protocols.test
index 0253c2b5d17..5eba780420c 100644
--- a/mysql-test/t/mysql_protocols.test
+++ b/mysql-test/t/mysql_protocols.test
@@ -1,5 +1,7 @@
# Embedded server doesn't support external clients
--source include/not_embedded.inc
+# Windows does not have SOCKET, but will try to create a PIPE as well as MEMORY
+--source include/not_windows.inc
# test for Bug #4998 "--protocol doesn't reject bad values"
diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test
index 61d7d9994ba..28074fba7e4 100644
--- a/mysql-test/t/mysqlbinlog.test
+++ b/mysql-test/t/mysqlbinlog.test
@@ -22,11 +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_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;
@@ -41,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
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLTEST_VARDIR/log/master-bin.000002
# 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
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --database=nottest $MYSQLTEST_VARDIR/log/master-bin.000001
# 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=231 $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.
@@ -73,29 +73,29 @@ 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
+--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
# 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
+--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
# Strangely but this works
--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/ --read-from-remote-server --position=231 --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002
+--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
@@ -107,7 +107,24 @@ select "--- reading stdin --" as "";
--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;
+create table t3 (f text character set utf8);
+create table t4 (f text character set cp932);
+--exec $MYSQL --default-character-set=utf8 test -e "insert into t3 values(_utf8'ソ')"
+--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 $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;
+select HEX(f) from t04;
+select HEX(f) from t4;
+
+
+
# clean up
-drop table t1, t2;
+drop table t1, t2, t03, t04, t3, t4;
# End of 4.1 tests
diff --git a/mysql-test/t/mysqlbinlog2.test b/mysql-test/t/mysqlbinlog2.test
index a2f1aba05b0..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=600 $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=600 $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=600 $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=126 $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 "";
diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test
index e54bf6386c5..9008eff6642 100644
--- a/mysql-test/t/mysqldump.test
+++ b/mysql-test/t/mysqldump.test
@@ -125,14 +125,14 @@ drop table t1;
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;
#
@@ -587,7 +587,7 @@ create view v1 as select * from t2;
create view v2 as select * from t1;
# dump tables and view from db2
---exec $MYSQL_DUMP db2 > var/tmp/bug10713.sql
+--exec $MYSQL_DUMP db2 > $MYSQLTEST_VARDIR/tmp/bug10713.sql
# drop the db, tables and views
drop table t1, t2;
@@ -597,7 +597,7 @@ drop database db2;
# create db1 and reload dump
create database db1;
use db1;
---exec $MYSQL db1 < var/tmp/bug10713.sql
+--exec $MYSQL db1 < $MYSQLTEST_VARDIR/tmp/bug10713.sql
# check that all tables and views could be created
show tables;
@@ -705,9 +705,9 @@ drop table t1, t2;
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;
@@ -817,9 +817,9 @@ update t1 set a = 4 where a=3;
# Skip dumping triggers
--exec $MYSQL_DUMP --skip-comments --databases --skip-triggers test
# Dump and reload...
---exec $MYSQL_DUMP --skip-comments --databases test > var/tmp/mysqldump.sql
+--exec $MYSQL_DUMP --skip-comments --databases test > $MYSQLTEST_VARDIR/tmp/mysqldump.sql
drop table t1;
---exec $MYSQL test < var/tmp/mysqldump.sql
+--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqldump.sql
# Check that tables have been reloaded
show tables;
--replace_column 6 #
@@ -830,11 +830,11 @@ DROP TABLE t1, t2;
# Bugs #9136, #12917: problems with --defaults-extra-file option
#
---exec echo "[mysqltest1]" > $MYSQL_TEST_DIR/var/tmp/tmp.cnf
---exec echo "port=1234" >> $MYSQL_TEST_DIR/var/tmp/tmp.cnf
---exec $MYSQL_MY_PRINT_DEFAULTS -c $MYSQL_TEST_DIR/var/tmp/tmp.cnf mysqltest1
---exec $MYSQL_MY_PRINT_DEFAULTS -e $MYSQL_TEST_DIR/var/tmp/tmp.cnf mysqltest1 mysqltest1
---exec rm $MYSQL_TEST_DIR/var/tmp/tmp.cnf
+--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
#
# Test of fix to BUG 12597
@@ -859,13 +859,13 @@ INSERT INTO `test1` VALUES (1);
SELECT * FROM `test2`;
# dump
---exec $MYSQL_DUMP --skip-comments --databases test > var/tmp/mysqldump.sql
+--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 < var/tmp/mysqldump.sql
+--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqldump.sql
SHOW TRIGGERS;
SELECT * FROM `test1`;
SELECT * FROM `test2`;
@@ -950,15 +950,16 @@ set time_zone=default;
#
--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;
-DROP TABLE IF EXISTS `t2 test`;
CREATE TABLE `t2 test` (
`a2` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
---enable_warnings
DELIMITER //;
CREATE TRIGGER `test trig` BEFORE INSERT ON `t1 test` FOR EACH ROW BEGIN
@@ -973,11 +974,10 @@ SELECT * FROM `t2 test`;
# quoted
--exec $MYSQL_DUMP --skip-comments --compatible=ansi --triggers test
---disable_warnings
DROP TRIGGER `test trig`;
DROP TABLE `t1 test`;
DROP TABLE `t2 test`;
---enable_warnings
+
#
# BUG# 12838 mysqldump -x with views exits with error
#
@@ -1036,3 +1036,80 @@ insert into t1 values ('','');
drop table t1;
# End of 4.1 tests
+
+#
+# Bug 14871 Invalid view dump output
+#
+
+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;
+
+#
+# Bug #16878 dump of trigger
+#
+
+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;
+
+
+#
+# Bug#14857 Reading dump files with single statement stored routines fails.
+# fixed by patch for bug#16878
+#
+#
+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;
+
diff --git a/mysql-test/t/mysqlshow.test b/mysql-test/t/mysqlshow.test
index 1e2e97a4e07..78c4ae2b531 100644
--- a/mysql-test/t/mysqlshow.test
+++ b/mysql-test/t/mysqlshow.test
@@ -2,7 +2,7 @@
-- source include/not_embedded.inc
--disable_warnings
-DROP TABLE IF EXISTS t1,t2;
+DROP TABLE IF EXISTS t1,t2,test1,test2;
--enable_warnings
#
diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test
index 8ccf2cb0c7a..f28df916ca1 100644
--- a/mysql-test/t/mysqltest.test
+++ b/mysql-test/t/mysqltest.test
@@ -1,3 +1,5 @@
+# This test should work in embedded server after mysqltest is fixed
+-- source include/not_embedded.inc
# ============================================================================
#
@@ -358,11 +360,20 @@ select 3 from t1 ;
# Missing delimiter
# The comment will be "sucked into" the sleep command since
# delimiter is missing until after "show status"
---system echo "sleep 4" > var/tmp/mysqltest.sql
---system echo "# A comment" >> var/tmp/mysqltest.sql
---system echo "show status;" >> var/tmp/mysqltest.sql
+--system echo "sleep 4" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
+--system echo "# A comment" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
+--system echo "show status;" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--error 1
---exec $MYSQL_TEST < var/tmp/mysqltest.sql 2>&1
+--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
+
+#
+# Missing delimiter until eof
+# The comment will be "sucked into" the sleep command since
+# delimiter is missing
+--system echo "sleep 7" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
+--system echo "# Another comment" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
+--error 1
+--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
#
# Extra delimiter
@@ -420,7 +431,7 @@ echo ;
# Illegal use of echo
--error 1
---exec echo "echo $;" | $MYSQL_TEST 2>&1
+--exec echo "echo \$;" | $MYSQL_TEST 2>&1
# ----------------------------------------------------------------------------
@@ -507,22 +518,22 @@ echo $novar1;
--exec echo "let ;" | $MYSQL_TEST 2>&1
--error 1
---exec echo "let $=hi;" | $MYSQL_TEST 2>&1
+--exec echo "let \$=hi;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "let hi=hi;" | $MYSQL_TEST 2>&1
--error 1
---exec echo "let $1 hi;" | $MYSQL_TEST 2>&1
+--exec echo "let \$1 hi;" | $MYSQL_TEST 2>&1
--error 1
---exec echo "let $m hi;" | $MYSQL_TEST 2>&1
+--exec echo "let \$m hi;" | $MYSQL_TEST 2>&1
--error 1
---exec echo "let $hi;" | $MYSQL_TEST 2>&1
+--exec echo "let \$hi;" | $MYSQL_TEST 2>&1
--error 1
---exec echo "let $ hi;" | $MYSQL_TEST 2>&1
+--exec echo "let \$ hi;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "let =hi;" | $MYSQL_TEST 2>&1
@@ -530,6 +541,55 @@ echo $novar1;
--error 1
--exec echo "let hi;" | $MYSQL_TEST 2>&1
+# More advanced test for bug#17280
+let $success= 1;
+--echo # Execute: --echo # <whatever> success: \$success
+--echo # <whatever> success: $success
+--echo # Execute: echo # <whatever> success: \$success ;
+echo # <whatever> success: $success ;
+
+--echo # The next two variants work fine and expand the content of \$success
+--echo # Execute: --echo \$success
+--echo $success
+--echo # Execute: echo \$success ;
+echo $success ;
+
+# ----------------------------------------------------------------------------
+# Test to assign let from query
+# let $<var_name>=`<query>`;
+# ----------------------------------------------------------------------------
+--disable_parsing
+echo var1;
+let $var1= `select "hi" as "Col", 1 as "Column1", "hi there" as Col3`;
+echo $var1;
+echo $var1_Col;
+echo $var1_Column1;
+echo $var1_Col3;
+
+echo var2;
+let $var2= `select 2 as "Column num 2"`;
+echo $var2;
+echo $var2_Column num 2;
+echo $var2_Column;
+
+echo var2 again;
+let $var2= `select 2 as "Column num 2"`;
+echo $var2;
+echo $var2_Column num 2;
+echo $var2_Column_num_2;
+echo $var2_Column;
+
+echo var3 two columns with same name;
+let $var3= `select 1 as "Col", 2 as "Col", 3 as "var3"`;
+echo $var3;
+echo $var3_Col;
+echo $var3_Col;
+echo $var3_var3;
+
+#echo failing query in let;
+#--error 1
+#--exec echo "let $var2= `failing query;`" | $MYSQL_TEST 2>&1
+--enable_parsing
# ----------------------------------------------------------------------------
# Test source command
# ----------------------------------------------------------------------------
@@ -543,25 +603,26 @@ echo $novar1;
--exec echo "source non_existingFile;" | $MYSQL_TEST 2>&1
# Too many source
---exec echo "source var/tmp/recursive.sql;" > var/tmp/recursive.sql
+--exec echo "source $MYSQLTEST_VARDIR/tmp/recursive.sql;" > $MYSQLTEST_VARDIR/tmp/recursive.sql
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--error 1
---exec echo "source var/tmp/recursive.sql;" | $MYSQL_TEST 2>&1
+--exec echo "source $MYSQLTEST_VARDIR/tmp/recursive.sql;" | $MYSQL_TEST 2>&1
# Source a file with error
---exec echo "garbage ;" > var/tmp/error.sql
+--exec echo "garbage ;" > $MYSQLTEST_VARDIR/tmp/error.sql
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--error 1
---exec echo "source var/tmp/error.sql;" | $MYSQL_TEST 2>&1
+--exec echo "source $MYSQLTEST_VARDIR/tmp/error.sql;" | $MYSQL_TEST 2>&1
# Test execution of source in a while loop
---exec echo "echo here is the sourced script;" > var/tmp/sourced.sql
--disable_query_log
let $outer= 2; # Number of outer loops
while ($outer)
{
eval SELECT '$outer = outer loop variable after while' AS "";
- --source var/tmp/sourced.sql
+ --source include/sourced.inc
eval SELECT '$outer = outer loop variable before dec' AS "";
dec $outer;
@@ -582,7 +643,6 @@ while ($outer)
# Test execution of source in a while loop
---exec echo "--source var/tmp/sourced.sql" > var/tmp/sourced1.sql
--disable_abort_on_error
# Sourcing of a file within while loop, sourced file will
# source other file
@@ -590,7 +650,7 @@ let $num= 9;
while ($num)
{
SELECT 'In loop' AS "";
- --source var/tmp/sourced1.sql
+ --source include/sourced1.inc
dec $num;
}
--enable_abort_on_error
@@ -607,10 +667,14 @@ real_sleep 1;
# Missing parameter
--error 1
--exec echo "sleep ;" | $MYSQL_TEST 2>&1
+--error 1
+--exec echo "real_sleep ;" | $MYSQL_TEST 2>&1
# Illegal parameter
--error 1
--exec echo "sleep abc;" | $MYSQL_TEST 2>&1
+--error 1
+--exec echo "real_sleep abc;" | $MYSQL_TEST 2>&1
# ----------------------------------------------------------------------------
# Test inc
@@ -680,7 +744,7 @@ system echo "hej" > /dev/null;
--exec echo "system false;" | $MYSQL_TEST 2>&1
--disable_abort_on_error
-system NonExistsinfComamdn;
+system NonExistsinfComamdn 2> /dev/null;
--enable_abort_on_error
@@ -697,6 +761,30 @@ echo test3stop
--delimiter ;
echo test4;
+
+# ----------------------------------------------------------------------------
+# Test if
+# ----------------------------------------------------------------------------
+
+let $counter=10;
+if ($counter)
+{
+ echo Counter is greater than 0, (counter=10);
+}
+if (!$counter)
+{
+ echo Counter is not 0, (counter=10);
+}
+let $counter=0;
+if ($counter)
+{
+ echo Counter is greater than 0, (counter=0);
+}
+if (!$counter)
+{
+ echo Counter is not 0, (counter=0);
+}
+
# ----------------------------------------------------------------------------
# Test while, { and }
# ----------------------------------------------------------------------------
@@ -710,7 +798,12 @@ while ($i)
# One liner
#let $i=1;while ($i){echo $i;dec $i;}
-
+let $i=0;
+while (!$i)
+{
+ echo Testing while with not;
+ inc $i;
+}
# Exceed max nesting level
--error 1
@@ -728,20 +821,20 @@ while ($i)
--error 1
--exec echo "{;" | $MYSQL_TEST 2>&1
---system echo "while (0)" > var/log/mysqltest.sql
---system echo "echo hej;" >> var/log/mysqltest.sql
+--system echo "while (0)" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
+--system echo "echo hej;" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--error 1
---exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1
+--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
---system echo "while (0)" > var/log/mysqltest.sql
---system echo "{echo hej;" >> var/log/mysqltest.sql
+--system echo "while (0)" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
+--system echo "{echo hej;" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--error 1
---exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1
+--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
---system echo "while (0){" > var/log/mysqltest.sql
---system echo "echo hej;" >> var/log/mysqltest.sql
+--system echo "while (0){" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
+--system echo "echo hej;" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--error 1
---exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1
+--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
# ----------------------------------------------------------------------------
# Test error messages returned from comments starting with a command
@@ -769,7 +862,7 @@ select "a" as col1, "c" as col2;
--exec echo "replace_result a;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "replace_result a ;" | $MYSQL_TEST 2>&1
---exec echo "replace_result a b;" | $MYSQL_TEST 2>&1
+--exec echo "replace_result a b; echo OK;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "--replace_result a b c" | $MYSQL_TEST 2>&1
--error 1
@@ -832,40 +925,49 @@ select "a" as col1, "c" as col2;
--exec echo "connect (con1,localhost,root,,,,,SMTP POP);" | $MYSQL_TEST 2>&1
# Repeat connect/disconnect
---exec echo "let \$i=100;" > var/tmp/con.sql
---exec echo "while (\$i)" >> var/tmp/con.sql
---exec echo "{" >> var/tmp/con.sql
---exec echo " connect (test_con1,localhost,root,,); " >> var/tmp/con.sql
---exec echo " disconnect test_con1; " >> var/tmp/con.sql
---exec echo " dec \$i; " >> var/tmp/con.sql
---exec echo "}" >> var/tmp/con.sql
---exec echo "source var/tmp/con.sql;" | $MYSQL_TEST 2>&1
+--exec echo "let \$i=100;" > $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo "while (\$i)" >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo "{" >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo " connect (test_con1,localhost,root,,); " >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo " disconnect test_con1; " >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo " dec \$i; " >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo "}" >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo "source $MYSQLTEST_VARDIR/tmp/con.sql; echo OK;" | $MYSQL_TEST 2>&1
# Repeat connect/disconnect, exceed max number of connections
---exec echo "let \$i=200;" > var/tmp/con.sql
---exec echo "while (\$i)" >> var/tmp/con.sql
---exec echo "{" >> var/tmp/con.sql
---exec echo " connect (test_con1,localhost,root,,); " >> var/tmp/con.sql
---exec echo " disconnect test_con1; " >> var/tmp/con.sql
---exec echo " dec \$i; " >> var/tmp/con.sql
---exec echo "}" >> var/tmp/con.sql
+--exec echo "let \$i=200;" > $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo "while (\$i)" >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo "{" >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo " connect (test_con1,localhost,root,,); " >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo " disconnect test_con1; " >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo " dec \$i; " >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo "}" >> $MYSQLTEST_VARDIR/tmp/con.sql
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--error 1
---exec echo "source var/tmp/con.sql;" | $MYSQL_TEST 2>&1
+--exec echo "source $MYSQLTEST_VARDIR/tmp/con.sql;" | $MYSQL_TEST 2>&1
# Select disconnected connection
---exec echo "connect (test_con1,localhost,root,,);" > var/tmp/con.sql
---exec echo "disconnect test_con1; " >> var/tmp/con.sql
---exec echo "connection test_con1;" >> var/tmp/con.sql
+--exec echo "connect (test_con1,localhost,root,,);" > $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo "disconnect test_con1; " >> $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo "connection test_con1;" >> $MYSQLTEST_VARDIR/tmp/con.sql
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--error 1
---exec echo "source var/tmp/con.sql;" | $MYSQL_TEST 2>&1
+--exec echo "source $MYSQLTEST_VARDIR/tmp/con.sql;" | $MYSQL_TEST 2>&1
# Connection name already used
---exec echo "connect (test_con1,localhost,root,,);" > var/tmp/con.sql
---exec echo "connect (test_con1,localhost,root,,);" >> var/tmp/con.sql
+--exec echo "connect (test_con1,localhost,root,,);" > $MYSQLTEST_VARDIR/tmp/con.sql
+--exec echo "connect (test_con1,localhost,root,,);" >> $MYSQLTEST_VARDIR/tmp/con.sql
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--error 1
---exec echo "source var/tmp/con.sql;" | $MYSQL_TEST 2>&1
-
+--exec echo "source $MYSQLTEST_VARDIR/tmp/con.sql;" | $MYSQL_TEST 2>&1
+# connect when "disable_abort_on_error" caused "connection not found"
+--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
+--disable_abort_on_error
+connect (con1,localhost,root,,);
+connection default;
+connection con1;
+--enable_abort_on_error
# ----------------------------------------------------------------------------
# Test mysqltest arguments
@@ -946,52 +1048,74 @@ select "this will not be executed";
select "this will be executed";
--enable_query_log
+#
+# Test zero length result file. Should not pass
+#
+--exec touch $MYSQLTEST_VARDIR/tmp/zero_length_file.result
+--exec echo "echo ok;" > $MYSQLTEST_VARDIR/tmp/query.sql
+--error 1
+--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/zero_length_file.result 2>&1
+#
+# Test that a test file that does not generate any output fails.
+#
+--exec echo "let \$i= 1;" > $MYSQLTEST_VARDIR/tmp/query.sql
+--error 1
+--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql 2>&1
+
+#
+# Test that mysqltest fails when there are no queries executed
+# but a result file exist
+# NOTE! This will never happen as long as it's not allowed to have
+# test files that does not produce any output
+#--exec echo "something" > $MYSQLTEST_VARDIR/tmp/result_file.result
+#--exec echo "let \$i= 1;" > $MYSQLTEST_VARDIR/tmp/query.sql
+#--error 1
+#--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/result_file.result 2>&1
#
# Bug #11731 mysqltest in multi-statement queries ignores errors in
# non-1st queries
#
-# Failing multi statement query
+echo Failing multi statement query;
# PS does not support multi statement
---exec echo "--disable_ps_protocol" > var/tmp/bug11731.sql
---exec echo "delimiter ||||;" >> var/tmp/bug11731.sql
---exec echo "create table t1 (a int primary key);" >> var/tmp/bug11731.sql
---exec echo "insert into t1 values (1);" >> var/tmp/bug11731.sql
---exec echo "select 'select-me';" >> var/tmp/bug11731.sql
---exec echo "insertz 'error query'||||" >> var/tmp/bug11731.sql
---exec echo "delimiter ;||||" >> var/tmp/bug11731.sql
+--exec echo "--disable_ps_protocol" > $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "delimiter ||||;" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "create table t1 (a int primary key);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "insert into t1 values (1);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "select 'select-me';" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "insertz 'error query'||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "delimiter ;||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--error 1
---exec $MYSQL_TEST -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql 2>&1
+--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/bug11731.sql 2>&1
drop table t1;
--error 1
---exec $MYSQL_TEST --record -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql -R $MYSQL_TEST_DIR/var/tmp/bug11731.out
-# The .out file should be empty, cat will fail!
---error 1
---exec cat $MYSQL_TEST_DIR/var/tmp/bug11731.out
+--exec $MYSQL_TEST --record -x $MYSQLTEST_VARDIR/tmp/bug11731.sql -R $MYSQLTEST_VARDIR/tmp/bug11731.out 2>&1
+# The .out file should be non existent
+--exec test ! -s $MYSQLTEST_VARDIR/tmp/bug11731.out
drop table t1;
-# Using expected error
+echo Multi statement using expected error;
# PS does not support multi statement
---exec echo "--disable_ps_protocol" > var/tmp/bug11731.sql
---exec echo "delimiter ||||;" >> var/tmp/bug11731.sql
---exec echo "--error 1064" >> var/tmp/bug11731.sql
---exec echo "create table t1 (a int primary key);" >> var/tmp/bug11731.sql
---exec echo "insert into t1 values (1);" >> var/tmp/bug11731.sql
---exec echo "select 'select-me';" >> var/tmp/bug11731.sql
---exec echo "insertz "error query"||||" >> var/tmp/bug11731.sql
---exec echo "delimiter ;||||" >> var/tmp/bug11731.sql
+--exec echo "--disable_ps_protocol" > $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "delimiter ||||;" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "--error 1064" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "create table t1 (a int primary key);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "insert into t1 values (1);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "select 'select-me';" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "insertz "error query"||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
+--exec echo "delimiter ;||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
# These two should work since the error is expected
---exec $MYSQL_TEST -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql 2>&1
+--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/bug11731.sql 2>&1
drop table t1;
---exec $MYSQL_TEST --record -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql -R $MYSQL_TEST_DIR/var/tmp/bug11731.out
---exec cat $MYSQL_TEST_DIR/var/tmp/bug11731.out
+--exec $MYSQL_TEST --record -x $MYSQLTEST_VARDIR/tmp/bug11731.sql -R $MYSQLTEST_VARDIR/tmp/bug11731.out 2>&1
+# The .out file should exist
+--exec test -s $MYSQLTEST_VARDIR/tmp/bug11731.out
drop table t1;
-
diff --git a/mysql-test/t/ndb_autodiscover.test b/mysql-test/t/ndb_autodiscover.test
index 6bbb1c2f2f2..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,14 +168,14 @@ 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 # 18 #
show table status;
@@ -290,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;
@@ -332,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';
@@ -375,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.
@@ -530,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 0510651a417..5d79d5eb9f9 100644
--- a/mysql-test/t/ndb_basic.test
+++ b/mysql-test/t/ndb_basic.test
@@ -614,6 +614,72 @@ CREATE TABLE t1 ( b INT ) PACK_KEYS = 0 ENGINE = ndb;
select * from t1;
drop table t1;
+#
+# Bug #17249 delete statement with join where clause fails
+# when table do not have pk
+#
+
+create table t1 (a int) engine=ndb;
+create table t2 (a int) engine=ndb;
+insert into t1 values (1);
+insert into t2 values (1);
+delete t1.* from t1, t2 where t1.a = t2.a;
+select * from t1;
+select * from t2;
+drop table t1;
+drop table t2;
+
+#
+# Bug #17257 update fails for inner joins if tables
+# do not have Primary Key
+#
+
+CREATE TABLE t1 (
+ i INT,
+ j INT,
+ x INT,
+ y INT,
+ z INT
+) engine=ndb;
+
+CREATE TABLE t2 (
+ i INT,
+ k INT,
+ x INT,
+ y INT,
+ z INT
+) engine=ndb;
+
+CREATE TABLE t3 (
+ j INT,
+ k INT,
+ x INT,
+ y INT,
+ z INT
+) engine=ndb;
+
+INSERT INTO t1 VALUES ( 1, 2,13,14,15);
+INSERT INTO t2 VALUES ( 1, 3,23,24,25);
+INSERT INTO t3 VALUES ( 2, 3, 1,34,35), ( 2, 3, 1,34,36);
+
+UPDATE t1 AS a
+INNER JOIN t2 AS b
+ ON a.i = b.i
+INNER JOIN t3 AS c
+ ON a.j = c.j AND b.k = c.k
+SET a.x = b.x,
+ a.y = b.y,
+ a.z = (
+ SELECT sum(z)
+ FROM t3
+ WHERE y = 34
+ )
+WHERE b.x = 23;
+select * from t1;
+drop table t1;
+drop table t2;
+drop table t3;
+
# End of 4.1 tests
#
@@ -623,3 +689,14 @@ 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;
diff --git a/mysql-test/t/ndb_bitfield.test b/mysql-test/t/ndb_bitfield.test
index 0256ecf89ed..59d6e56577e 100644
--- a/mysql-test/t/ndb_bitfield.test
+++ b/mysql-test/t/ndb_bitfield.test
@@ -112,3 +112,11 @@ create table t1 (
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 a12ebee2f0d..f80b7f71281 100644
--- a/mysql-test/t/ndb_blob.test
+++ b/mysql-test/t/ndb_blob.test
@@ -338,7 +338,7 @@ select * from t1 order by a;
drop table t1;
drop database test2;
-# -- bug-5252 tinytext crashes plus no-commit result --
+# -- bug-5252 tinytext crashes + no-commit result + replace --
set autocommit=0;
create table t1 (
@@ -352,6 +352,10 @@ select * from t1;
delete from t1;
select * from t1;
commit;
+replace t1 set a=2, b='y';
+select * from t1;
+delete from t1;
+select * from t1;
drop table t1;
# -- bug-5013 insert empty string to text --
diff --git a/mysql-test/t/ndb_cache_multi2.test b/mysql-test/t/ndb_cache_multi2.test
index 9352505649c..4abb537624a 100644
--- a/mysql-test/t/ndb_cache_multi2.test
+++ b/mysql-test/t/ndb_cache_multi2.test
@@ -10,6 +10,7 @@ drop table if exists t1, t2;
# 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;
@@ -18,24 +19,24 @@ 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;
-# Sleep so that the query cache check thread has time to start
-sleep 15;
-
-
# 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";
@@ -44,6 +45,7 @@ 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";
@@ -53,19 +55,30 @@ show status like "Qcache_inserts";
show status like "Qcache_hits";
update t1 set a=3 where a=2;
-# Sleep so that the query cache check thread has time to run
-sleep 5;
-
-# Connect to server1 and check that cache is invalidated
+# 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";
+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";
-show status like "Qcache_inserts";
-show status like "Qcache_hits";
drop table t1, t2;
diff --git a/mysql-test/t/ndb_config.test b/mysql-test/t/ndb_config.test
index e40e89d76bd..4787abe86e2 100644
--- a/mysql-test/t/ndb_config.test
+++ b/mysql-test/t/ndb_config.test
@@ -4,7 +4,7 @@
--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
diff --git a/mysql-test/t/ndb_index_unique.test b/mysql-test/t/ndb_index_unique.test
index 2185276c2c6..8561b3794c4 100644
--- a/mysql-test/t/ndb_index_unique.test
+++ b/mysql-test/t/ndb_index_unique.test
@@ -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_load.test b/mysql-test/t/ndb_load.test
new file mode 100644
index 00000000000..af2df70b74e
--- /dev/null
+++ b/mysql-test/t/ndb_load.test
@@ -0,0 +1,24 @@
+-- source include/have_ndb.inc
+-- source include/not_embedded.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+#
+# Basic test for different types of loading data
+#
+
+# should give duplicate key
+CREATE TABLE t1 (word CHAR(20) NOT NULL PRIMARY KEY) ENGINE=NDB;
+--error 1022
+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_ln/words.dat' INTO TABLE t1 ;
+SELECT * FROM t1 ORDER BY word;
+DROP TABLE t1;
+
+# End of 4.1 tests
diff --git a/mysql-test/t/ndb_multi.test b/mysql-test/t/ndb_multi.test
index 760150c6f6a..1183f2b283f 100644
--- a/mysql-test/t/ndb_multi.test
+++ b/mysql-test/t/ndb_multi.test
@@ -40,6 +40,7 @@ connection server1;
# Currently a retry is required remotely
--error 1296
select * from t1;
+flush table t1;
select * from t1;
# Connect to server2 and use the tables from there
diff --git a/mysql-test/t/ndb_read_multi_range.test b/mysql-test/t/ndb_read_multi_range.test
index 9d1f918fef0..b1bf7fe4258 100644
--- a/mysql-test/t/ndb_read_multi_range.test
+++ b/mysql-test/t/ndb_read_multi_range.test
@@ -2,7 +2,7 @@
-- source include/not_embedded.inc
--disable_warnings
-DROP TABLE IF EXISTS t1, r1;
+DROP TABLE IF EXISTS t1, t2, r1;
--enable_warnings
#
diff --git a/mysql-test/t/outfile.test b/mysql-test/t/outfile.test
index 37e96d9d38d..d404a6fff9f 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,42 +16,43 @@ 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;
--error 13,2
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
@@ -70,16 +72,16 @@ DROP TABLE t1;
# Bug#13202 SELECT * INTO OUTFILE ... FROM information_schema.schemata now fails
#
disable_query_log;
-eval SELECT * INTO OUTFILE "$MYSQL_TEST_DIR/var/tmp/outfile-test.4"
+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 $MYSQL_TEST_DIR/var/tmp/outfile-test.4
+--exec rm $MYSQLTEST_VARDIR/tmp/outfile-test.4
use information_schema;
# disable_query_log;
-eval SELECT * INTO OUTFILE "$MYSQL_TEST_DIR/var/tmp/outfile-test.4"
+eval SELECT * INTO OUTFILE "../tmp/outfile-test.4"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
FROM schemata LIMIT 0, 5;
enable_query_log;
---exec rm $MYSQL_TEST_DIR/var/tmp/outfile-test.4
+--exec rm $MYSQLTEST_VARDIR/tmp/outfile-test.4
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index 22d0abf645e..d6b239c31bf 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -870,6 +870,57 @@ drop table t1;
set names default;
deallocate prepare stmt;
+#
+# A test case for Bug#12734 "prepared statement may return incorrect result
+# set for a select SQL request": test that canDoTurboBM is reset for each
+# execute of a prepared statement.
+#
+create table t1 (
+ word_id mediumint(8) unsigned not null default '0',
+ formatted varchar(20) not null default ''
+);
+
+insert into t1 values
+ (80,'pendant'), (475,'pretendants'), (989,'tendances'),
+ (1019,'cependant'),(1022,'abondance'),(1205,'independants'),
+ (13,'lessiver'),(25,'lambiner'),(46,'situer'),(71,'terminer'),
+ (82,'decrocher');
+
+select count(*) from t1 where formatted like '%NDAN%';
+select count(*) from t1 where formatted like '%ER';
+prepare stmt from "select count(*) from t1 where formatted like ?";
+set @like="%NDAN%";
+execute stmt using @like;
+set @like="%ER";
+execute stmt using @like;
+set @like="%NDAN%";
+execute stmt using @like;
+set @like="%ER";
+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"
+#
+
+prepare stmt from 'create table t1 (a varchar(10) character set utf8)';
+execute stmt;
+--disable_warnings
+insert into t1 (a) values (repeat('a', 20));
+--enable_warnings
+select length(a) from t1;
+drop table t1;
+execute stmt;
+--disable_warnings
+insert into t1 (a) values (repeat('a', 20));
+--enable_warnings
+# Check that the data is truncated to the same length
+select length(a) from t1;
+drop table t1;
+deallocate prepare stmt;
+
# End of 4.1 tests
#
diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test
index 6abfd8f28a7..89fad3fa4fb 100644
--- a/mysql-test/t/ps_1general.test
+++ b/mysql-test/t/ps_1general.test
@@ -831,7 +831,7 @@ execute stmt1 ;
--disable_metadata
--horizontal_results
-drop table t5, t9;
+drop table t1, t5, t9;
##### RULES OF THUMB TO PRESERVE THE SYSTEMATICS OF THE PS TEST CASES #####
#
diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test
index a9f171ff5b5..d416f34ce45 100644
--- a/mysql-test/t/query_cache.test
+++ b/mysql-test/t/query_cache.test
@@ -783,6 +783,7 @@ begin
end//
call p1()//
drop procedure p1//
+drop function f1//
drop table t1//
delimiter ;//
@@ -818,29 +819,14 @@ select sql_cache * from t1 where s1=1;
end;//
delimiter ;//
call f1();
-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;
diff --git a/mysql-test/t/query_cache_notembedded.test b/mysql-test/t/query_cache_notembedded.test
index fd4785ffe95..5e1ab7051e5 100644
--- a/mysql-test/t/query_cache_notembedded.test
+++ b/mysql-test/t/query_cache_notembedded.test
@@ -97,4 +97,88 @@ 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;
+
+
set GLOBAL query_cache_size=0;
diff --git a/mysql-test/t/read_only.test b/mysql-test/t/read_only.test
index 0861951a6a1..175a5bba6fa 100644
--- a/mysql-test/t/read_only.test
+++ b/mysql-test/t/read_only.test
@@ -1,6 +1,9 @@
# 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
@@ -101,3 +104,5 @@ 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/repair.test b/mysql-test/t/repair.test
index 5e39e0b6a50..16e1d76d460 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/rpl000001.test b/mysql-test/t/rpl000001.test
index 3d03823d474..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;
@@ -92,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
@@ -123,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/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 a53049386af..df4bf6f977b 100644
--- a/mysql-test/t/rpl000015.test
+++ b/mysql-test/t/rpl000015.test
@@ -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 3b4574e9547..866b7fd1c25 100644
--- a/mysql-test/t/rpl000017.test
+++ b/mysql-test/t/rpl000017.test
@@ -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 72df0c20ef8..640a2b1a88c 100644
--- a/mysql-test/t/rpl_EE_error.test
+++ b/mysql-test/t/rpl_EE_error.test
@@ -8,7 +8,7 @@ source include/master-slave.inc;
create table t1 (a int) engine=myisam;
flush tables;
-system rm ./var/master-data/test/t1.MYI ;
+system rm $MYSQLTEST_VARDIR/master-data/test/t1.MYI ;
drop table if exists t1;
save_master_pos;
connection slave;
diff --git a/mysql-test/t/rpl_charset.test b/mysql-test/t/rpl_charset.test
index e5ddf084461..e916ae9ad6c 100644
--- a/mysql-test/t/rpl_charset.test
+++ b/mysql-test/t/rpl_charset.test
@@ -153,7 +153,7 @@ 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 $MYSQL_TEST_DIR/var/log/master-bin.000001
+--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_deadlock.test b/mysql-test/t/rpl_deadlock.test
index 08921caf897..c74ed989ece 100644
--- a/mysql-test/t/rpl_deadlock.test
+++ b/mysql-test/t/rpl_deadlock.test
@@ -58,7 +58,7 @@ while ($1)
enable_query_log;
select * from t1 for update;
start slave;
---sleep 3 # hope that slave is blocked now
+--real_sleep 3 # hope that slave is blocked now
insert into t2 values(22); # provoke deadlock, slave should be victim
commit;
sync_with_master;
@@ -76,7 +76,7 @@ change master to master_log_pos=532; # the BEGIN log event
begin;
select * from t2 for update; # hold lock
start slave;
---sleep 10 # slave should have blocked, and be retrying
+--real_sleep 10 # slave should have blocked, and be retrying
commit;
sync_with_master;
select * from t1; # check that slave succeeded finally
@@ -97,7 +97,7 @@ change master to master_log_pos=532;
begin;
select * from t2 for update;
start slave;
---sleep 10
+--real_sleep 10
commit;
sync_with_master;
select * from t1;
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_error_ignored_table.test b/mysql-test/t/rpl_error_ignored_table.test
index cb4137c49e0..339d966dbb3 100644
--- a/mysql-test/t/rpl_error_ignored_table.test
+++ b/mysql-test/t/rpl_error_ignored_table.test
@@ -45,7 +45,7 @@ select (@id := id) - id from t3;
kill @id;
drop table t2,t3;
connection master;
---error 0,1053
+--error 0,1053,2013
reap;
connection master1;
--replace_column 2 # 5 #
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_tables.test b/mysql-test/t/rpl_flush_tables.test
index 92aef9c85d0..bbc5c33770c 100644
--- a/mysql-test/t/rpl_flush_tables.test
+++ b/mysql-test/t/rpl_flush_tables.test
@@ -49,5 +49,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_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_ignore_table-slave.opt b/mysql-test/t/rpl_ignore_table-slave.opt
new file mode 100644
index 00000000000..cb49119bfcb
--- /dev/null
+++ b/mysql-test/t/rpl_ignore_table-slave.opt
@@ -0,0 +1 @@
+--replicate-ignore-table=test.t1 --replicate-ignore-table=test.t2 --replicate-ignore-table=test.t3
diff --git a/mysql-test/t/rpl_ignore_table.test b/mysql-test/t/rpl_ignore_table.test
new file mode 100644
index 00000000000..bc651779208
--- /dev/null
+++ b/mysql-test/t/rpl_ignore_table.test
@@ -0,0 +1,28 @@
+source include/master-slave.inc;
+
+#
+# BUG#16487
+#
+# Requirement:
+# Multi-updates on ignored tables should not fail even if the slave does
+# not have the ignored tables.
+#
+# Note table t1, t2, and t3 are ignored in the option file to this test.
+#
+
+--echo **** Test case for BUG#16487 ****
+--echo **** Master ****
+connection master;
+CREATE TABLE test.t4 (a int);
+CREATE TABLE test.t1 (a int);
+
+# Expect: The row must *not* by updated on slave, since t1 is ignored
+UPDATE test.t4 NATURAL JOIN test.t1 SET t1.a=5;
+
+--echo **** Slave ****
+sync_slave_with_master;
+SELECT * FROM t4;
+
+connection master;
+DROP TABLE t1;
+DROP TABLE t4;
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 49d3a03640c..f025ae9e587 100644
--- a/mysql-test/t/rpl_insert_id.test
+++ b/mysql-test/t/rpl_insert_id.test
@@ -74,4 +74,7 @@ SET FOREIGN_KEY_CHECKS=0;
INSERT INTO t1 VALUES (1),(1);
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_loaddata.test b/mysql-test/t/rpl_loaddata.test
index 00121092bbf..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;
@@ -56,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;
@@ -80,7 +80,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.
@@ -105,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.
@@ -125,7 +125,7 @@ reset master;
create table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60),
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;
select * from t2;
@@ -141,7 +141,7 @@ alter table t2 drop key day;
connection master;
delete from t2;
--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;
connection slave;
@@ -149,5 +149,6 @@ 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 c956f2c7720..4b8e5326c98 100644
--- a/mysql-test/t/rpl_loaddata_rule_m.test
+++ b/mysql-test/t/rpl_loaddata_rule_m.test
@@ -18,13 +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;
+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 98fad3cc06f..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;
@@ -19,4 +19,7 @@ sync_with_master;
select count(*) from t1; # check that LOAD was replicated
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 0b54de8462e..af4fd0106bd 100644
--- a/mysql-test/t/rpl_loaddatalocal.test
+++ b/mysql-test/t/rpl_loaddatalocal.test
@@ -14,17 +14,18 @@ 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;
enable_query_log;
-select * into outfile '../../var/master-data/rpl_loaddatalocal.select_outfile' from t1;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval select * into outfile '$MYSQLTEST_VARDIR/master-data/rpl_loaddatalocal.select_outfile' from t1;
#This will generate a 20KB file, now test LOAD DATA LOCAL
truncate table t1;
-load data local infile './var/master-data/rpl_loaddatalocal.select_outfile' into table t1;
-system rm ./var/master-data/rpl_loaddatalocal.select_outfile ;
+--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 ;
save_master_pos;
connection slave;
sync_with_master;
@@ -45,11 +46,13 @@ sync_with_master;
connection master;
create table t1(a int);
insert into t1 values (1), (2), (2), (3);
-select * into outfile '../../var/master-data/rpl_loaddatalocal.select_outfile' from t1;
+--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);
-load data local infile './var/master-data/rpl_loaddatalocal.select_outfile' into table t1;
-system rm ./var/master-data/rpl_loaddatalocal.select_outfile ;
+--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;
diff --git a/mysql-test/t/rpl_log.test b/mysql-test/t/rpl_log.test
index 1f71d2981c5..6e614991d36 100644
--- a/mysql-test/t/rpl_log.test
+++ b/mysql-test/t/rpl_log.test
@@ -33,7 +33,7 @@ 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
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_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_multi_update4-slave.opt b/mysql-test/t/rpl_multi_update4-slave.opt
new file mode 100644
index 00000000000..fea27db43ee
--- /dev/null
+++ b/mysql-test/t/rpl_multi_update4-slave.opt
@@ -0,0 +1 @@
+--replicate-wild-do-table=d1.%
diff --git a/mysql-test/t/rpl_multi_update4.test b/mysql-test/t/rpl_multi_update4.test
new file mode 100644
index 00000000000..3d909b8e5cd
--- /dev/null
+++ b/mysql-test/t/rpl_multi_update4.test
@@ -0,0 +1,44 @@
+# Let's verify that multi-update is not always skipped by slave if
+# some replicate-* rules exist.
+# (BUG#15699)
+
+source include/master-slave.inc;
+
+### Clean-up
+
+connection master;
+--disable_warnings
+drop database if exists d1;
+drop database if exists d2;
+
+connection slave;
+drop database if exists d2;
+--enable_warnings
+
+### Test
+
+connection master;
+create database d1; # accepted by slave
+create table d1.t0 (id int);
+create database d2; # ignored by slave
+use d2;
+create table t1 (id int);
+create table t2 (id int);
+insert into t1 values (1), (2), (3), (4), (5);
+insert into t2 select id + 3 from t1;
+# a problematic query which must be filter out by slave
+update t1 join t2 using (id) set t1.id = 0;
+insert into d1.t0 values (0); # replication works
+
+sync_slave_with_master;
+use d1;
+#connection slave;
+select * from t0 where id=0; # must find
+
+### Clean-up
+connection master;
+drop database d1;
+drop database d2;
+
+
+# End of test
diff --git a/mysql-test/t/rpl_relayrotate.test b/mysql-test/t/rpl_relayrotate.test
index e9a4cdd05c5..04f03367e20 100644
--- a/mysql-test/t/rpl_relayrotate.test
+++ b/mysql-test/t/rpl_relayrotate.test
@@ -52,9 +52,8 @@ start slave;
# which proves that the transaction restarted at
# the right place.
# We must wait for the transaction to commit before
-# reading, MASTER_POS_WAIT() will do it for sure
-# (the only statement with position>=3000 is COMMIT).
-select master_pos_wait('master-bin.001',3000)>=0;
+# reading:
+sync_with_master;
select max(a) from t1;
connection master;
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_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 b125408d89e..77a8fb7d9a4 100644
--- a/mysql-test/t/rpl_rotate_logs.test
+++ b/mysql-test/t/rpl_rotate_logs.test
@@ -14,8 +14,8 @@ connect (master,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
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;
@@ -26,7 +26,7 @@ drop table if exists t1, t2, t3, t4;
--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()).
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 67d3816f443..985cebabe7e 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-slave.opt b/mysql-test/t/rpl_sp-slave.opt
index 611ee1f33be..709a224fd92 100644
--- a/mysql-test/t/rpl_sp-slave.opt
+++ b/mysql-test/t/rpl_sp-slave.opt
@@ -1 +1 @@
---log_bin_trust_routine_creators=0 --slave-skip-errors=1062
+--log_bin_trust_routine_creators=0
diff --git a/mysql-test/t/rpl_sp.test b/mysql-test/t/rpl_sp.test
index 386582f8f1b..8be17be3822 100644
--- a/mysql-test/t/rpl_sp.test
+++ b/mysql-test/t/rpl_sp.test
@@ -87,6 +87,14 @@ 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;
@@ -286,21 +294,19 @@ alter table t2 add unique (a);
drop function fn1;
delimiter |;
-create function fn1()
+create function fn1(x int)
returns int
begin
- insert into t2 values(20),(20);
+ insert into t2 values(x),(x);
return 10;
end|
delimiter ;|
-# Because of BUG#14769 the following statement requires that we start
-# slave with --slave-skip-errors=1062. When that bug is fixed, that
-# option can be removed.
+do fn1(100);
--error 1062
-select fn1();
+select fn1(20);
select * from t2;
sync_slave_with_master;
@@ -393,7 +399,43 @@ 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;
+
# cleanup
connection master;
drop table t1;
-reset master;
+sync_slave_with_master;
diff --git a/mysql-test/t/rpl_timezone.test b/mysql-test/t/rpl_timezone.test
index 2e9883141d8..0f35c9dc0b6 100644
--- a/mysql-test/t/rpl_timezone.test
+++ b/mysql-test/t/rpl_timezone.test
@@ -46,15 +46,15 @@ sync_slave_with_master;
set time_zone='Europe/Moscow';
select * from t1;
connection master;
---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
---exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.000001
+--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/rpl_timezone.dat' into table t1;
+load data infile '../std_data_ln/rpl_timezone.dat' into table t1;
select * from t1;
sync_slave_with_master;
set time_zone='UTC';
diff --git a/mysql-test/t/rpl_trigger.test b/mysql-test/t/rpl_trigger.test
index bf2836b6049..f3db1cb5841 100644
--- a/mysql-test/t/rpl_trigger.test
+++ b/mysql-test/t/rpl_trigger.test
@@ -134,7 +134,132 @@ drop function bug12480;
drop table t1;
#
-# End of test
+# #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;
+}
+
+
+
+#
+# End of tests
#
save_master_pos;
connection slave;
diff --git a/mysql-test/t/rpl_until.test b/mysql-test/t/rpl_until.test
index 708f44a1ab6..e0ecf981fea 100644
--- a/mysql-test/t/rpl_until.test
+++ b/mysql-test/t/rpl_until.test
@@ -30,7 +30,7 @@ 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 # 23 # 33 #
+--replace_column 1 # 9 # 11 # 23 # 33 #
show slave status;
# this should fail right after start
@@ -40,7 +40,7 @@ select * from t1;
sleep 2;
wait_for_slave_to_stop;
--replace_result $MASTER_MYPORT MASTER_MYPORT
---replace_column 1 # 9 # 23 # 33 #
+--replace_column 1 # 9 # 11 # 23 # 33 #
show slave status;
# try replicate all until second insert to t2;
diff --git a/mysql-test/t/schema.test b/mysql-test/t/schema.test
index d9bd607b2db..a08d9b38935 100644
--- a/mysql-test/t/schema.test
+++ b/mysql-test/t/schema.test
@@ -1,6 +1,12 @@
#
# 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;
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index a73d08f5f18..01d5f2eb4d1 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -2805,3 +2805,46 @@ EXPLAIN SELECT t2.key_a,foo
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;
diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test
index 89d281a2c58..52d262677ff 100644
--- a/mysql-test/t/show_check.test
+++ b/mysql-test/t/show_check.test
@@ -10,6 +10,7 @@
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';
@@ -391,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
diff --git a/mysql-test/t/skip_grants.test b/mysql-test/t/skip_grants.test
index 16b0fbc4d25..27220c9b507 100644
--- a/mysql-test/t/skip_grants.test
+++ b/mysql-test/t/skip_grants.test
@@ -1,3 +1,6 @@
+# This tests not performed with embedded server
+-- source include/not_embedded.inc
+
--disable_warnings
drop table if exists t1,v1;
drop view if exists t1,v1;
@@ -27,3 +30,6 @@ create table t1 (a int);
create definer='user'@'host' sql security definer view v1 as select * from t1;
drop view v1;
drop table t1;
+
+# BUG#17595: DROP FUNCTION IF EXISTS f1 crashes server
+drop function if exists f1;
diff --git a/mysql-test/t/skip_name_resolve.test b/mysql-test/t/skip_name_resolve.test
index b67869692d2..3f732c8912b 100644
--- a/mysql-test/t/skip_name_resolve.test
+++ b/mysql-test/t/skip_name_resolve.test
@@ -15,6 +15,6 @@ DROP USER mysqltest_1@'127.0.0.1/255.255.255.255';
connect (con1, 127.0.0.1, root, , test, $MASTER_MYPORT, );
--replace_column 1 #
select user();
---replace_column 1 # 6 # 3 #
+--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
index 389a6f04504..90a3a79dd53 100644
--- a/mysql-test/t/sp-big.test
+++ b/mysql-test/t/sp-big.test
@@ -52,6 +52,9 @@ while ($1)
--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
diff --git a/mysql-test/t/sp-code.test b/mysql-test/t/sp-code.test
index 6644bc3ab43..0a26ea644f6 100644
--- a/mysql-test/t/sp-code.test
+++ b/mysql-test/t/sp-code.test
@@ -4,6 +4,11 @@
-- 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;
@@ -47,3 +52,141 @@ 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;
diff --git a/mysql-test/t/sp-destruct.test b/mysql-test/t/sp-destruct.test
index a2a66090866..4f5f1cdcb9b 100644
--- a/mysql-test/t/sp-destruct.test
+++ b/mysql-test/t/sp-destruct.test
@@ -11,9 +11,9 @@
--source include/not_windows.inc
# Backup proc table
---system rm -rf var/master-data/mysql/backup
---system mkdir var/master-data/mysql/backup
---system cp var/master-data/mysql/proc.* var/master-data/mysql/backup/
+--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;
@@ -45,11 +45,14 @@ insert into t1 values (0);
flush table mysql.proc;
# Thrashing the .frm file
---system echo 'saljdlfa' > var/master-data/mysql/proc.frm
+--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);
@@ -57,7 +60,7 @@ insert into t1 values (0);
flush table mysql.proc;
# Drop the mysql.proc table
---system rm var/master-data/mysql/proc.*
+--system rm $MYSQLTEST_VARDIR/master-data/mysql/proc.*
--error ER_NO_SUCH_TABLE
call bug14233();
--error ER_NO_SUCH_TABLE
@@ -66,8 +69,8 @@ create view v1 as select bug14233_f();
insert into t1 values (0);
# Restore mysql.proc
---system mv var/master-data/mysql/backup/* var/master-data/mysql/
---system rmdir var/master-data/mysql/backup
+--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;
@@ -119,6 +122,15 @@ create trigger t1_ai after insert on t1 for each row call bug14233_3();
insert into t1 values (0);
# Clean-up
-delete from mysql.proc where name like 'bug14233%';
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
index 5416f5931ff..6546a5ab548 100644
--- a/mysql-test/t/sp-dynamic.test
+++ b/mysql-test/t/sp-dynamic.test
@@ -1,4 +1,10 @@
delimiter |;
+
+--disable_warnings
+drop procedure if exists p1|
+drop procedure if exists p2|
+--enable_warnings
+
######################################################################
# Test Dynamic SQL in stored procedures. #############################
######################################################################
diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
index 69e5f73817b..4b307de2ad0 100644
--- a/mysql-test/t/sp-error.test
+++ b/mysql-test/t/sp-error.test
@@ -648,28 +648,6 @@ call bug3294()|
drop procedure bug3294|
#
-# 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#876: Stored Procedures: Invalid SQLSTATE is allowed in
# a DECLARE ? HANDLER FOR stmt.
#
@@ -1095,7 +1073,7 @@ delimiter |;
--disable_warnings
DROP FUNCTION IF EXISTS bug12953|
--enable_warnings
---error ER_SP_BADSTATEMENT
+--error ER_SP_NO_RETSET
CREATE FUNCTION bug12953() RETURNS INT
BEGIN
OPTIMIZE TABLE t1;
@@ -1410,7 +1388,6 @@ 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
---disable_warnings
drop function if exists bug12329;
--enable_warnings
create table t1 as select 1 a;
@@ -1518,10 +1495,208 @@ 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#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
index e5f35b19fa7..049dcc576dd 100644
--- a/mysql-test/t/sp-prelocking.test
+++ b/mysql-test/t/sp-prelocking.test
@@ -234,7 +234,8 @@ select f3() //
call sp1() //
delimiter ;//
-drop table t1,t2,t3;
+drop view v1;
+drop table t1,t2,t3,t4;
drop function f1;
drop function f2;
drop function f3;
diff --git a/mysql-test/t/sp-security.test b/mysql-test/t/sp-security.test
index 8d4f99abd71..19f94a32d9c 100644
--- a/mysql-test/t/sp-security.test
+++ b/mysql-test/t/sp-security.test
@@ -196,7 +196,6 @@ use db2;
call q();
select * from t2;
-
#
# BUG#6030: Stored procedure has no appropriate DROP privilege
# (or ALTER for that matter)
@@ -233,9 +232,13 @@ drop database db2;
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
#
@@ -304,6 +307,9 @@ 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
@@ -437,4 +443,108 @@ 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;
+use test;
+
# End of 5.0 bugs.
diff --git a/mysql-test/t/sp-threads.test b/mysql-test/t/sp-threads.test
index 70c1efb1f0b..d8a8ce5dae7 100644
--- a/mysql-test/t/sp-threads.test
+++ b/mysql-test/t/sp-threads.test
@@ -1,3 +1,5 @@
+# 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
diff --git a/mysql-test/t/sp-vars.test b/mysql-test/t/sp-vars.test
new file mode 100644
index 00000000000..81504904797
--- /dev/null
+++ b/mysql-test/t/sp-vars.test
@@ -0,0 +1,1273 @@
+###########################################################################
+#
+# 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;
+
+--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();
+
+# 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();
+
+# 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;
+
+--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();
+
+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;
+
+###########################################################################
+#
+# 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;
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index b3760a1d7f5..e6823693b3d 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -367,6 +367,7 @@ create function sub3(i int) returns int
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")|
@@ -698,32 +699,34 @@ drop procedure into_test4|
--disable_warnings
drop procedure if exists into_outfile|
--enable_warnings
-create procedure into_outfile(x char(16), y int)
+--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 "/tmp/spout" from test.t1;
+ select * into outfile "$MYSQLTEST_VARDIR/tmp/spout" from test.t1;
insert into test.t1 values (concat(x, "2"), y+2);
end|
-system rm -f /tmp/spout|
+--system rm -f $MYSQLTEST_VARDIR/tmp/spout
call into_outfile("ofile", 1)|
-system rm -f /tmp/spout|
+--system rm -f $MYSQLTEST_VARDIR/tmp/spout
delete from t1|
drop procedure into_outfile|
--disable_warnings
drop procedure if exists into_dumpfile|
--enable_warnings
-create procedure into_dumpfile(x char(16), y int)
+--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 "/tmp/spdump" from test.t1 limit 1;
+ 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 /tmp/spdump|
+--system rm -f $MYSQLTEST_VARDIR/tmp/spdump
call into_dumpfile("dfile", 1)|
-system rm -f /tmp/spdump|
+--system rm -f $MYSQLTEST_VARDIR/tmp/spdump
delete from t1|
drop procedure into_dumpfile|
@@ -1156,6 +1159,11 @@ 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|
@@ -1233,8 +1241,6 @@ create function f7() returns int
select f6()|
select id, f6() from t1|
-# TODO Test temporary table handling
-
#
# Let us test how new locking work with views
#
@@ -1315,6 +1321,73 @@ select * from v1, t1|
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|
@@ -1326,11 +1399,17 @@ 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
@@ -1342,9 +1421,9 @@ delete from t2 |
# fac
--disable_warnings
-drop table if exists fac|
+drop table if exists t3|
--enable_warnings
-create table fac (n int unsigned not null primary key, f bigint unsigned)|
+create table t3 (n int unsigned not null primary key, f bigint unsigned)|
--disable_warnings
drop procedure if exists ifac|
@@ -1358,15 +1437,15 @@ begin
end if;
while i <= n do
begin
- insert into test.fac values (i, fac(i));
+ insert into test.t3 values (i, fac(i));
set i = i + 1;
end;
end while;
end|
call ifac(20)|
-select * from fac|
-drop table fac|
+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|
@@ -1378,15 +1457,15 @@ show function status like '%f%'|
# primes
--disable_warnings
-drop table if exists primes|
+drop table if exists t3|
--enable_warnings
-create table primes (
+create table t3 (
i int unsigned not null primary key,
p bigint unsigned not null
)|
-insert into primes values
+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),
@@ -1415,7 +1494,7 @@ begin
begin
declare p bigint unsigned;
- select t.p into p from test.primes t where t.i = s;
+ select t.p into p from test.t3 t where t.i = s;
if b+p > r then
set pp = 1;
leave again;
@@ -1446,7 +1525,7 @@ begin
call opp(p, pp);
if pp then
- insert into test.primes values (i, p);
+ insert into test.t3 values (i, p);
set i = i+1;
end if;
set p = p+2;
@@ -1454,7 +1533,7 @@ begin
end while;
end|
show create procedure opp|
---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
+--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
@@ -1468,20 +1547,20 @@ call ip(200)|
# 45 211
# 100 557
# 199 1229
-select * from primes where i=45 or i=100 or i=199|
-drop table primes|
+select * from t3 where i=45 or i=100 or i=199|
+drop table t3|
drop procedure opp|
drop procedure ip|
---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
+--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 fib|
+drop table if exists t3|
--enable_warnings
-create table fib ( f bigint unsigned not null )|
+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
@@ -1494,13 +1573,13 @@ begin
if n > 1 then
begin
declare x, y bigint unsigned;
- declare c cursor for select f from fib order by f desc limit 2;
+ 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 fib values (x+y);
+ insert into t3 values (x+y);
call fib(n-1);
end;
end if;
@@ -1511,22 +1590,23 @@ set @@max_sp_recursion_depth= 20|
# Minimum test: recursion of 3 levels
-insert into fib values (0), (1)|
+insert into t3 values (0), (1)|
call fib(3)|
-select * from fib order by f asc|
+select * from t3 order by f asc|
-delete from fib|
+delete from t3|
-# Original test: 20 levels (may run into memory limits!)
+# The original test, 20 levels, ran into memory limits on some machines
+# and builds. Try 10 instead...
-insert into fib values (0), (1)|
+insert into t3 values (0), (1)|
-call fib(20)|
+call fib(10)|
-select * from fib order by f asc|
-drop table fib|
+select * from t3 order by f asc|
+drop table t3|
drop procedure fib|
set @@max_sp_recursion_depth= 0|
@@ -1540,13 +1620,13 @@ drop procedure if exists bar|
create procedure bar(x char(16), y int)
comment "111111111111" sql security invoker
insert into test.t1 values (x, y)|
---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
+--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 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
+--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|
@@ -1582,7 +1662,7 @@ drop function `foo`|
# Implicit LOCK/UNLOCK TABLES for table access in functions
#
---disable_warning
+--disable_warnings
drop function if exists t1max|
--enable_warnings
create function t1max() returns int
@@ -1626,6 +1706,397 @@ 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
#
@@ -2496,7 +2967,6 @@ begin
show databases like 'foo';
show errors;
show columns from t1;
- show grants for 'root'@'localhost';
show keys from t1;
show open tables like 'foo';
show privileges;
@@ -2518,20 +2988,6 @@ 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#4904
#
@@ -2746,44 +3202,6 @@ select @x|
delete from t1|
drop procedure bug4941|
-
-#
-# 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|
-
#
# BUG#4905: Stored procedure doesn't clear for "Rows affected"
#
@@ -3093,24 +3511,6 @@ select id, bug5240() from t1|
drop function bug5240|
#
-# 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|
-
-#
# BUG#7992: rolling back temporary Item tree changes in SP
#
--disable_warnings
@@ -3747,7 +4147,7 @@ drop procedure if exists bug7088_2|
--disable_parsing # temporarily disabled until Bar fixes BUG#11986
create procedure bug6063()
- lâbel: begin end|
+ lâbel: begin end|
call bug6063()|
# QQ Known bug: this will not show the label correctly.
show create procedure bug6063|
@@ -4287,8 +4687,6 @@ 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 procedure if exists bug7049_5|
-drop procedure if exists bug7049_6|
drop function if exists bug7049_1|
drop function if exists bug7049_2|
--enable_warnings
@@ -4322,22 +4720,6 @@ begin
select 'Missed it' as 'Result';
end|
-create procedure bug7049_5()
-begin
- declare x decimal(2,1);
-
- set x = 'zap';
-end|
-
-create procedure bug7049_6()
-begin
- declare exit handler for sqlwarning
- select 'Caught it' as 'Result';
-
- call bug7049_5();
- select 'Missed it' as 'Result';
-end|
-
create function bug7049_1()
returns int
begin
@@ -4362,7 +4744,6 @@ select * from t3|
delete from t3|
call bug7049_4()|
select * from t3|
-call bug7049_6()|
select bug7049_2()|
drop table t3|
@@ -4370,8 +4751,6 @@ drop procedure bug7049_1|
drop procedure bug7049_2|
drop procedure bug7049_3|
drop procedure bug7049_4|
-drop procedure bug7049_5|
-drop procedure bug7049_6|
drop function bug7049_1|
drop function bug7049_2|
@@ -4728,24 +5107,6 @@ select bug10100f(5)|
call bug10100t(5)|
#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|
@@ -4797,12 +5158,12 @@ begin
declare continue handler for sqlexception select 'boo' as 'Handler';
begin
- declare v int default x;
+ declare v int default undefined_var;
if v = 1 then
select 1;
else
- select 2;
+ select v, isnull(v);
end if;
end;
end|
@@ -4811,12 +5172,14 @@ create procedure bug14643_2()
begin
declare continue handler for sqlexception select 'boo' as 'Handler';
- case x
+ case undefined_var
when 1 then
select 1;
else
select 2;
end case;
+
+ select undefined_var;
end|
call bug14643_1()|
@@ -4910,23 +5273,25 @@ drop procedure bug14376|
# variable declarations. In MySQL 5.0 it's vice versa.
#
-drop procedure if exists p1|
-drop table if exists t1|
-create table t1 (a varchar(255))|
-insert into t1 (a) values ("a - table column")|
-create procedure p1(a varchar(255))
+--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 t1;
+ declare c cursor for select a from t3;
select a;
- select a from t1 into i;
+ 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 t1;
+ declare c1 cursor for select a from t3;
select a as 'A local variable takes precedence over parameter';
open c1;
fetch c1 into i;
@@ -4934,9 +5299,9 @@ begin
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 t1;
+ 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 t1 into i;
+ 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;
@@ -4945,7 +5310,37 @@ begin
end;
end;
end|
-call p1("a - stored procedure parameter")|
+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
@@ -4994,6 +5389,335 @@ 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#NNNN: New bug synopsis
#
#--disable_warnings
diff --git a/mysql-test/t/sp.test.orig b/mysql-test/t/sp.test.orig
new file mode 100644
index 00000000000..a4b99620344
--- /dev/null
+++ b/mysql-test/t/sp.test.orig
@@ -0,0 +1,5716 @@
+#
+# Basic stored PROCEDURE tests
+#
+# Please keep this file free of --error cases and other
+# things that will not run in a single debugged mysqld
+# process (e.g. master-slave things).
+#
+# Test cases for bugs are added at the end. See template there.
+#
+# 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
+create procedure into_outfile(x char(16), y int)
+begin
+ insert into test.t1 values (x, y);
+ select * into outfile "../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
+create procedure into_dumpfile(x char(16), y int)
+begin
+ insert into test.t1 values (x, y);
+ select * into dumpfile "../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 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 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 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 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#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#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 grants for 'root'@'localhost';
+ 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|
+
+# 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#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#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|
+
+#
+# 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#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|
+
+#
+# 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#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#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
+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|
+
+#
+# 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#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..3854297ec0c
--- /dev/null
+++ b/mysql-test/t/sp_notembedded.test
@@ -0,0 +1,262 @@
+# Can't test with embedded server
+-- source include/not_embedded.inc
+
+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|
+
+delimiter ;|
diff --git a/mysql-test/t/sp_trans.test b/mysql-test/t/sp_trans.test
index 308d4ad5c33..b9bd4c938b3 100644
--- a/mysql-test/t/sp_trans.test
+++ b/mysql-test/t/sp_trans.test
@@ -5,7 +5,7 @@
-- source include/have_innodb.inc
--disable_warnings
-drop table if exists t1, t2;
+drop table if exists t1, t2, t3;
--enable_warnings
delimiter |;
diff --git a/mysql-test/t/sql_mode.test b/mysql-test/t/sql_mode.test
index 8ae9ced6c68..b67f1a73db6 100644
--- a/mysql-test/t/sql_mode.test
+++ b/mysql-test/t/sql_mode.test
@@ -255,4 +255,13 @@ 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;
+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/subselect.test b/mysql-test/t/subselect.test
index cc621fb5835..733403f482e 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -1963,8 +1963,107 @@ select * from (select max(fld) from t1) as foo;
drop table t1;
#
-# BUG #10308: purge log with subselect
+# Test for bug #11762: subquery with an aggregate function in HAVING
#
-purge master logs before (select adddate(current_timestamp(), interval -4 day));
+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;
diff --git a/mysql-test/t/subselect_innodb.test b/mysql-test/t/subselect_innodb.test
index 4bfc4d17588..573fe0c1810 100644
--- a/mysql-test/t/subselect_innodb.test
+++ b/mysql-test/t/subselect_innodb.test
@@ -236,4 +236,5 @@ 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/symlink.test b/mysql-test/t/symlink.test
index b7a7e83d569..19a720a4fb8 100644
--- a/mysql-test/t/symlink.test
+++ b/mysql-test/t/symlink.test
@@ -3,6 +3,8 @@ disable_query_log;
show variables like "have_symlink";
enable_query_log;
+--source include/not_windows.inc
+
--disable_warnings
drop table if exists t1,t2,t7,t8,t9;
drop database if exists mysqltest;
@@ -41,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;
@@ -50,7 +52,7 @@ 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
@@ -65,7 +67,7 @@ drop table t1;
# Note that we are using the above table t9 here!
#
---replace_result $MYSQL_TEST_DIR TEST_DIR
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
SHOW CREATE TABLE t9;
disable_query_log;
@@ -84,11 +86,11 @@ create table mysqltest.t9 (a int not null auto_increment, b char(16) not null, p
# 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="$MYSQL_TEST_DIR/var/run";
+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;
@@ -96,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;
@@ -106,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;
@@ -127,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/system_mysql_db_fix.test b/mysql-test/t/system_mysql_db_fix.test
index 4621b2f50ef..0a2ab180806 100644
--- a/mysql-test/t/system_mysql_db_fix.test
+++ b/mysql-test/t/system_mysql_db_fix.test
@@ -77,7 +77,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
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 6b3991c9c78..3920b305b78 100644
--- a/mysql-test/t/temp_table.test
+++ b/mysql-test/t/temp_table.test
@@ -1,3 +1,5 @@
+# mysqltest should be fixed
+-- source include/not_embedded.inc
#
# Test of temporary tables
#
diff --git a/mysql-test/t/trigger-compat.test b/mysql-test/t/trigger-compat.test
index ace18639172..f2e350cb161 100644
--- a/mysql-test/t/trigger-compat.test
+++ b/mysql-test/t/trigger-compat.test
@@ -61,8 +61,8 @@ CREATE TRIGGER wl2818_trg1 BEFORE INSERT ON t1
--echo
--echo ---> patching t1.TRG...
---exec grep --text -v 'definers=' $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG > $MYSQL_TEST_DIR/var/tmp/t1.TRG
---exec mv $MYSQL_TEST_DIR/var/tmp/t1.TRG $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/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.
@@ -81,3 +81,16 @@ SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_n
--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
index c058816ee75..297aa445322 100644
--- a/mysql-test/t/trigger-grant.test
+++ b/mysql-test/t/trigger-grant.test
@@ -8,8 +8,6 @@
#
# Tests for WL#2818:
# - Check that triggers are executed under the authorization of the definer.
-# - Check that if trigger contains NEW/OLD variables, the definer must have
-# SELECT privilege on the subject table.
# - Check DEFINER clause of CREATE TRIGGER statement;
# - Check that SUPER privilege required to create a trigger with different
# definer.
@@ -18,6 +16,8 @@
# - 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
@@ -143,28 +143,28 @@ SELECT * FROM t1;
SELECT * FROM t2;
#
-# Check that if trigger contains NEW/OLD variables, the definer must have
-# SELECT/UPDATE privilege on the subject table:
-# - drop the trigger;
-# - create a new trigger, which will use NEW variable;
-# - create another new trigger, which will use OLD variable;
-# - revoke SELECT/UPDATE privilege on the first table from "definer";
-# - insert a row into the first table;
-# - analyze error code;
+# 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.
#
-# SELECT privilege.
+# - 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 default
---echo
---echo ---> connection: default
-
-use mysqltest_db1;
-
-REVOKE SELECT ON mysqltest_db1.t1 FROM mysqltest_dfn@localhost;
-
--connection wl2818_definer_con
--echo
--echo ---> connection: wl2818_definer_con
@@ -173,95 +173,137 @@ use mysqltest_db1;
DROP TRIGGER trg1;
-SET @new_sum = 0;
-SET @old_sum = 0;
+# Check that SUPER is required to specify different DEFINER.
+# NOTE: meaningless at the moment
-# INSERT INTO statement; BEFORE timing
+CREATE DEFINER='mysqltest_inv'@'localhost'
+ TRIGGER trg1 BEFORE INSERT ON t1
+ FOR EACH ROW
+ SET @new_sum = 0;
---echo ---> INSERT INTO statement; BEFORE timing
+# Create with non-existent user.
-CREATE TRIGGER trg1 BEFORE INSERT ON t1
+CREATE DEFINER='mysqltest_nonexs'@'localhost'
+ TRIGGER trg2 AFTER INSERT ON t1
FOR EACH ROW
- SET @new_sum = @new_sum + NEW.num_value;
+ SET @new_sum = 0;
---error ER_TABLEACCESS_DENIED_ERROR
-INSERT INTO t1 VALUES(4);
+# Check that trg2 will not be activated.
-# INSERT INTO statement; AFTER timing
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+INSERT INTO t1 VALUES(6);
---echo ---> INSERT INTO statement; AFTER timing
+#
+# 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 AFTER INSERT ON t1
+CREATE TRIGGER trg1 BEFORE INSERT ON t1
FOR EACH ROW
- SET @new_sum = @new_sum + NEW.num_value;
-
---error ER_TABLEACCESS_DENIED_ERROR
-INSERT INTO t1 VALUES(5);
+ SET @a = 1;
-# UPDATE statement; BEFORE timing
+CREATE TRIGGER trg2 AFTER INSERT ON t1
+ FOR EACH ROW
+ SET @a = 2;
---echo ---> UPDATE statement; BEFORE timing
+CREATE TRIGGER trg3 BEFORE UPDATE ON t1
+ FOR EACH ROW
+ SET @a = 3;
-DROP TRIGGER trg1;
+CREATE TRIGGER trg4 AFTER UPDATE ON t1
+ FOR EACH ROW
+ SET @a = 4;
-CREATE TRIGGER trg1 BEFORE UPDATE ON t1
+CREATE TRIGGER trg5 BEFORE DELETE ON t1
FOR EACH ROW
- SET @old_sum = @old_sum + OLD.num_value;
+ SET @a = 5;
---error ER_TABLEACCESS_DENIED_ERROR
-UPDATE t1 SET num_value = 10;
+--exec egrep -v '^definers=' $MYSQLTEST_VARDIR/master-data/mysqltest_db1/t1.TRG > $MYSQLTEST_VARDIR/tmp/t1.TRG
+--exec echo "definers='' '@' '@abc@def@@' '@hostname' '@abcdef@@@hostname'" >> $MYSQLTEST_VARDIR/tmp/t1.TRG
+--exec mv $MYSQLTEST_VARDIR/tmp/t1.TRG $MYSQLTEST_VARDIR/master-data/mysqltest_db1/t1.TRG
-# UPDATE statement; AFTER timing
+--echo
---echo ---> UPDATE statement; AFTER timing
+SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
-DROP TRIGGER trg1;
+--echo
-CREATE TRIGGER trg1 AFTER UPDATE ON t1
- FOR EACH ROW
- SET @new_sum = @new_sum + NEW.num_value;
+SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
---error ER_TABLEACCESS_DENIED_ERROR
-UPDATE t1 SET num_value = 20;
+#
+# Cleanup
+#
-# DELETE statement; BEFORE timing
+--connection default
+--echo
+--echo ---> connection: default
---echo ---> DELETE statement; BEFORE timing
+DROP USER mysqltest_dfn@localhost;
+DROP USER mysqltest_inv@localhost;
-DROP TRIGGER trg1;
+DROP DATABASE mysqltest_db1;
-CREATE TRIGGER trg1 BEFORE DELETE ON t1
- FOR EACH ROW
- SET @old_sum = @old_sum + OLD.num_value;
+###########################################################################
+#
+# BUG#15166: Wrong update [was: select/update] permissions required to execute
+# triggers.
+#
+# BUG#15196: Wrong select permission required to execute triggers.
+#
+###########################################################################
---error ER_TABLEACCESS_DENIED_ERROR
-DELETE FROM t1;
+#
+# Prepare environment.
+#
-# DELETE statement; AFTER timing
+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;
---echo ---> DELETE statement; AFTER timing
+--disable_warnings
+DROP DATABASE IF EXISTS mysqltest_db1;
+--enable_warnings
-DROP TRIGGER trg1;
+CREATE DATABASE mysqltest_db1;
-CREATE TRIGGER trg1 AFTER DELETE ON t1
- FOR EACH ROW
- SET @old_sum = @old_sum + OLD.num_value;
+use mysqltest_db1;
---error ER_TABLEACCESS_DENIED_ERROR
-DELETE FROM t1;
+# 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
-#
-# UPDATE privilege
-#
-# NOTE: At the moment, UPDATE privilege is required if the trigger contains
-# NEW/OLD variables, whenever the trigger modifies them or not. Moreover,
-# UPDATE privilege is checked for whole table, not for individual columns.
-#
-# The following test cases should be changed when full support of UPDATE
-# privilege will be done.
-#
+# 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
@@ -269,207 +311,256 @@ DELETE FROM t1;
use mysqltest_db1;
-GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_dfn@localhost;
-REVOKE UPDATE ON mysqltest_db1.t1 FROM mysqltest_dfn@localhost;
+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 wl2818_definer_con
+--connection bug15166_u1_con
--echo
---echo ---> connection: wl2818_definer_con
+--echo ---> connection: bug15166_u1_con
use mysqltest_db1;
-DROP TRIGGER trg1;
+CREATE TRIGGER t1_trg_after_delete AFTER DELETE ON t1
+ FOR EACH ROW
+ SET @mysqltest_var = 'Hello, world!';
-SET @new_sum = 0;
-SET @old_sum = 0;
+# parsing (CREATE TRIGGER) time:
+# - check that UPDATE is not enough to read the value;
+# - check that UPDATE is required to modify the value;
-# INSERT INTO statement; BEFORE timing
+--connection default
+--echo
+--echo ---> connection: default
---echo ---> INSERT INTO statement; BEFORE timing
+use mysqltest_db1;
-CREATE TRIGGER trg1 BEFORE INSERT ON t1
- FOR EACH ROW
- SET @new_sum = @new_sum + NEW.num_value;
+GRANT UPDATE ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+GRANT UPDATE ON mysqltest_db1.t2 TO mysqltest_u1@localhost;
---error ER_TABLEACCESS_DENIED_ERROR
-INSERT INTO t1 VALUES(4);
+GRANT UPDATE(col) ON mysqltest_db1.t3 TO mysqltest_u1@localhost;
+GRANT UPDATE(col) ON mysqltest_db1.t4 TO mysqltest_u1@localhost;
-# INSERT INTO statement; AFTER timing
+--connection bug15166_u1_con
+--echo
+--echo ---> connection: bug15166_u1_con
---echo ---> INSERT INTO statement; AFTER timing
+use mysqltest_db1;
-DROP TRIGGER trg1;
+# - table-level privileges
-CREATE TRIGGER trg1 AFTER INSERT ON t1
+# 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 @new_sum = @new_sum + NEW.num_value;
+ SET @mysqltest_var = NEW.col;
+DROP TRIGGER t1_trg_err_1;
---error ER_TABLEACCESS_DENIED_ERROR
-INSERT INTO t1 VALUES(5);
+# 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;
-# UPDATE statement; BEFORE timing
+CREATE TRIGGER t2_trg_before_insert BEFORE INSERT ON t2
+ FOR EACH ROW
+ SET NEW.col = 't2_trg_before_insert';
---echo ---> UPDATE statement; BEFORE timing
+# - column-level privileges
-DROP TRIGGER trg1;
+# 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;
-CREATE TRIGGER trg1 BEFORE UPDATE ON t1
+# 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 @old_sum = @old_sum + OLD.num_value;
+ SET @mysqltest_var = OLD.col;
+DROP TRIGGER t3_trg_err_2;
---error ER_TABLEACCESS_DENIED_ERROR
-UPDATE t1 SET num_value = 10;
+CREATE TRIGGER t4_trg_before_insert BEFORE INSERT ON t4
+ FOR EACH ROW
+ SET NEW.col = 't4_trg_before_insert';
-# UPDATE statement; AFTER timing
+# parsing (CREATE TRIGGER) time:
+# - check that SELECT is required to read the value;
+# - check that SELECT is not enough to modify the value;
---echo ---> UPDATE statement; AFTER timing
+--connection default
+--echo
+--echo ---> connection: default
-DROP TRIGGER trg1;
+use mysqltest_db1;
-CREATE TRIGGER trg1 AFTER UPDATE ON t1
- FOR EACH ROW
- SET @new_sum = @new_sum + NEW.num_value;
+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;
---error ER_TABLEACCESS_DENIED_ERROR
-UPDATE t1 SET num_value = 20;
+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;
-# DELETE statement; BEFORE timing
+--connection bug15166_u1_con
+--echo
+--echo ---> connection: bug15166_u1_con
---echo ---> DELETE statement; BEFORE timing
+use mysqltest_db1;
-DROP TRIGGER trg1;
+# - table-level privileges
-CREATE TRIGGER trg1 BEFORE DELETE ON t1
- FOR EACH ROW
- SET @old_sum = @old_sum + OLD.num_value;
+CREATE TRIGGER t1_trg_after_insert AFTER INSERT ON t1
+ FOR EACH ROW
+ SET @mysqltest_var = NEW.col;
---error ER_TABLEACCESS_DENIED_ERROR
-DELETE FROM t1;
+CREATE TRIGGER t1_trg_after_update AFTER UPDATE ON t1
+ FOR EACH ROW
+ SET @mysqltest_var = OLD.col;
-# DELETE statement; AFTER timing
+# 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;
---echo ---> DELETE statement; AFTER timing
+# 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;
-DROP TRIGGER trg1;
+# - column-level privileges
-CREATE TRIGGER trg1 AFTER DELETE ON t1
+CREATE TRIGGER t3_trg_after_insert AFTER INSERT ON t3
FOR EACH ROW
- SET @old_sum = @old_sum + OLD.num_value;
-
---error ER_TABLEACCESS_DENIED_ERROR
-DELETE FROM t1;
+ SET @mysqltest_var = NEW.col;
-#
-# 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;
-#
+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 wl2818_definer_con
+--connection default
--echo
---echo ---> connection: wl2818_definer_con
+--echo ---> connection: default
use mysqltest_db1;
-DROP TRIGGER trg1;
+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;
-# Check that SUPER is required to specify different DEFINER.
-# NOTE: meaningless at the moment
+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;
-CREATE DEFINER='mysqltest_inv'@'localhost'
- TRIGGER trg1 BEFORE INSERT ON t1
- FOR EACH ROW
- SET @new_sum = 0;
+# - table-level privileges
-# Create with non-existent user.
+--error ER_COLUMNACCESS_DENIED_ERROR
+INSERT INTO t1 VALUES('line1');
-CREATE DEFINER='mysqltest_nonexs'@'localhost'
- TRIGGER trg2 AFTER INSERT ON t1
- FOR EACH ROW
- SET @new_sum = 0;
+SELECT * FROM t1;
+SELECT @mysqltest_var;
-# Check that trg2 will not be activated.
+INSERT INTO t2 VALUES('line2');
---error ER_SPECIFIC_ACCESS_DENIED_ERROR
-INSERT INTO t1 VALUES(6);
+SELECT * FROM t2;
-#
-# Check that SHOW TRIGGERS statement provides "Definer" column.
-#
+# - column-level privileges
-SHOW TRIGGERS;
+--error ER_COLUMNACCESS_DENIED_ERROR
+INSERT INTO t3 VALUES('t3_line1');
-#
-# Check that weird definer values do not break functionality. I.e. check the
-# following definer values:
-# - '';
-# - '@';
-# - '@abc@def@@';
-# - '@hostname';
-# - '@abc@def@@@hostname';
-#
+SELECT * FROM t3;
+SELECT @mysqltest_var;
-DROP TRIGGER trg1;
-DROP TRIGGER trg2;
+INSERT INTO t4 VALUES('t4_line2');
-CREATE TRIGGER trg1 BEFORE INSERT ON t1
- FOR EACH ROW
- SET @a = 1;
+SELECT * FROM t4;
-CREATE TRIGGER trg2 AFTER INSERT ON t1
- FOR EACH ROW
- SET @a = 2;
+# execution time:
+# - check that SELECT is required to read the value;
+# - check that SELECT is not enough to modify the value;
-CREATE TRIGGER trg3 BEFORE UPDATE ON t1
- FOR EACH ROW
- SET @a = 3;
+--connection default
+--echo
+--echo ---> connection: default
-CREATE TRIGGER trg4 AFTER UPDATE ON t1
- FOR EACH ROW
- SET @a = 4;
+use mysqltest_db1;
-CREATE TRIGGER trg5 BEFORE DELETE ON t1
- FOR EACH ROW
- SET @a = 5;
+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;
---exec egrep --text -v '^definers=' $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG > $MYSQL_TEST_DIR/var/tmp/t1.TRG
---exec echo "definers='' '@' '@abc@def@@' '@hostname' '@abcdef@@@hostname'" >> $MYSQL_TEST_DIR/var/tmp/t1.TRG
---exec mv $MYSQL_TEST_DIR/var/tmp/t1.TRG $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG
+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;
---echo
+# - table-level privileges
-SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
+INSERT INTO t1 VALUES('line3');
---echo
+SELECT * FROM t1;
+SELECT @mysqltest_var;
-SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
+--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
+# Cleanup.
#
---connection default
---echo
---echo ---> connection: default
-
-DROP USER mysqltest_dfn@localhost;
-DROP USER mysqltest_inv@localhost;
+DROP USER mysqltest_u1@localhost;
DROP DATABASE mysqltest_db1;
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test
index d4fa5268762..1d68b519f1d 100644
--- a/mysql-test/t/trigger.test
+++ b/mysql-test/t/trigger.test
@@ -3,7 +3,7 @@
#
--disable_warnings
-drop table if exists t1, t2, t3;
+drop table if exists t1, t2, t3, t4;
drop view if exists v1;
drop database if exists mysqltest;
drop function if exists f1;
@@ -13,6 +13,8 @@ drop procedure if exists p1;
# 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);
@@ -463,11 +465,11 @@ 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/rpl_loaddata.dat' into table t1 (@a, i);
+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/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, j);
+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;
@@ -501,7 +503,7 @@ delete from t1 where i = 2;
select * from t1;
# Should fail and insert only 1 row
--error 1054
-load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, k);
+load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, k);
select * from t1;
--error 1054
insert into t1 select 3, 3;
@@ -561,7 +563,7 @@ select * from t1;
delete from t1;
select * from t1;
--error 1054
-load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, k);
+load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, k);
select * from t1;
--error 1054
insert into t1 select 3, 3;
@@ -928,11 +930,8 @@ drop table t1, t2, t3;
# operator.
#
create table t1 (a int);
---disable_warnings
-drop procedure if exists p2;
---enable_warnings
DELIMITER //;
-CREATE PROCEDURE `p2`()
+CREATE PROCEDURE `p1`()
begin
insert into t1 values (1);
end//
@@ -942,7 +941,119 @@ begin
set done= not done;
end//
DELIMITER ;//
-CALL p2();
-drop procedure p2;
+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;
+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;
diff --git a/mysql-test/t/type_bit.test b/mysql-test/t/type_bit.test
index 0c45dea21bb..1f05a9574d6 100644
--- a/mysql-test/t/type_bit.test
+++ b/mysql-test/t/type_bit.test
@@ -226,3 +226,4 @@ 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;
diff --git a/mysql-test/t/type_decimal.test b/mysql-test/t/type_decimal.test
index 1f6310cb819..441d750004e 100644
--- a/mysql-test/t/type_decimal.test
+++ b/mysql-test/t/type_decimal.test
@@ -376,3 +376,12 @@ 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;
diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test
index 6a0814ef113..d223c315735 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;
@@ -159,6 +156,23 @@ show create table t3;
drop table t1, t2, t3;
+#
+# Bug #9855 (inconsistent column type for create select
+#
+create table t1 select 105213674794682365.00 + 0.0 x;
+show warnings;
+desc t1;
+drop table t1;
+
+create table t1 select 0.0 x;
+desc t1;
+create table t2 select 105213674794682365.00 y;
+desc t2;
+create table t3 select x+y a from t1,t2;
+show warnings;
+desc t3;
+drop table t1,t2,t3;
+
# End of 4.1 tests
#
diff --git a/mysql-test/t/type_newdecimal-big.test b/mysql-test/t/type_newdecimal-big.test
index e200017f2ba..9a1104e4fe6 100644
--- a/mysql-test/t/type_newdecimal-big.test
+++ b/mysql-test/t/type_newdecimal-big.test
@@ -12,12 +12,31 @@ drop procedure if exists sp1;
delimiter //;
#
-create procedure sp1 () begin
- declare v1, v2, v3, v4 decimal(16,12); declare v5 int;
- set v1 = 1; set v2 = 2; set v3 = 1000000000000; set v4 = 2000000000000; set v5 = 0;
- while v5 < 100000 do
- set v1 = v1 + 0.000000000001; set v2 = v2 - 0.000000000001; set v3 = v3 + 1; set v4 = v4 - 1; set v5 = v5 + 1;
- end while; select v1, v2, v3 * 0.000000000001, v4 * 0.000000000001; end;//
+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
diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test
index 7ae3f65f7cc..cb7e4f85ad1 100644
--- a/mysql-test/t/type_time.test
+++ b/mysql-test/t/type_time.test
@@ -21,4 +21,22 @@ select t, time_to_sec(t),sec_to_time(time_to_sec(t)) from t1;
select sec_to_time(time_to_sec(t)) from t1;
drop table t1;
+#
+# BUG #12440: Incorrect processing of time values containing
+# long fraction part and/or large exponent part.
+#
+# These must return normal result:
+# ##########################################################
+# To be uncommented after fix BUG #15805
+# ##########################################################
+# SELECT CAST(235959.123456 AS TIME);
+# SELECT CAST(0.235959123456e+6 AS TIME);
+# SELECT CAST(235959123456e-6 AS TIME);
+# These must cut fraction part and produce warning:
+# SELECT CAST(235959.1234567 AS TIME);
+# SELECT CAST(0.2359591234567e6 AS TIME);
+# This must return NULL and produce warning:
+# SELECT CAST(0.2359591234567e+30 AS TIME);
+# ##########################################################
+
# End of 4.1 tests
diff --git a/mysql-test/t/type_varchar.test b/mysql-test/t/type_varchar.test
index 1a3a93018a4..e5614afe4f6 100644
--- a/mysql-test/t/type_varchar.test
+++ b/mysql-test/t/type_varchar.test
@@ -3,7 +3,7 @@ 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 std_data/vchar.frm var/master-data/test/;
+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;
@@ -130,3 +130,19 @@ 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;
diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test
index 6de90dd446d..ce6153d2b78 100644
--- a/mysql-test/t/union.test
+++ b/mysql-test/t/union.test
@@ -27,12 +27,9 @@ select 't1',b,count(*) from t1 group by b UNION select 't2',b,count(*) from t2 g
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b;
explain extended (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc;
(select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2;
-# PS doesn't work correctly with found_rows: to be fixed
---disable_ps_protocol
select found_rows();
select sql_calc_found_rows a,b from t1 union all select a,b from t2 limit 2;
select found_rows();
---enable_ps_protocol
#
# Test some error conditions with UNION
@@ -210,27 +207,15 @@ insert into t2 values (3),(4),(5);
# Test global limits
(SELECT SQL_CALC_FOUND_ROWS * FROM t1) UNION all (SELECT * FROM t2) LIMIT 1;
-# PS doesn't work correctly with found_rows: to be fixed
---disable_ps_protocol
select found_rows();
---enable_ps_protocol
(SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1) UNION all (SELECT * FROM t2) LIMIT 2;
-# PS doesn't work correctly with found_rows: to be fixed
---disable_ps_protocol
select found_rows();
---enable_ps_protocol
# Test cases where found_rows() should return number of returned rows
(SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1) UNION all (SELECT * FROM t2);
-# PS doesn't work correctly with found_rows: to be fixed
---disable_ps_protocol
select found_rows();
---enable_ps_protocol
(SELECT SQL_CALC_FOUND_ROWS * FROM t1) UNION all (SELECT * FROM t2 LIMIT 1);
-# PS doesn't work correctly with found_rows: to be fixed
---disable_ps_protocol
select found_rows();
---enable_ps_protocol
# This used to work in 4.0 but not anymore in 4.1
--error 1064
(SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1) UNION SELECT * FROM t2 LIMIT 1;
@@ -238,15 +223,9 @@ select found_rows();
# In these case found_rows() should work
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1 UNION all SELECT * FROM t2 LIMIT 2;
-# PS doesn't work correctly with found_rows: to be fixed
---disable_ps_protocol
select found_rows();
---disable_ps_protocol
SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION all SELECT * FROM t2 LIMIT 2;
-# PS doesn't work correctly with found_rows: to be fixed
---disable_ps_protocol
select found_rows();
---disable_ps_protocol
# The following examples will not be exact
SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION SELECT * FROM t2 LIMIT 2;
diff --git a/mysql-test/t/update.test b/mysql-test/t/update.test
index d0496b48c7a..5a49de248b1 100644
--- a/mysql-test/t/update.test
+++ b/mysql-test/t/update.test
@@ -287,4 +287,23 @@ update t1 set f1=1 where f1=3;
update t2,t1 set f1=3,f2=3 where f1=f2 and f1=1;
--disable_info
drop table t1,t2;
+
+
+# BUG#15935
+create table t1 (a int);
+insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t2 (a int, filler1 char(200), filler2 char(200), key(a));
+insert into t2 select A.a + 10*B.a, 'filler','filler' from t1 A, t1 B;
+flush status;
+update t2 set a=3 where a=2;
+show status like 'handler_read%';
+drop table t1, t2;
+
+#
+# Bug #16510 Updating field named like '*name' caused server crash
+#
+create table t1(f1 int, `*f2` int);
+insert into t1 values (1,1);
+update t1 set `*f2`=1;
+drop table t1;
# End of 4.1 tests
diff --git a/mysql-test/t/user_var-binlog.test b/mysql-test/t/user_var-binlog.test
index 004154339b2..12a5e616fa2 100644
--- a/mysql-test/t/user_var-binlog.test
+++ b/mysql-test/t/user_var-binlog.test
@@ -15,7 +15,7 @@ show binlog events from 98;
# 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/variables-master.opt b/mysql-test/t/variables-master.opt
index a0577107f74..abd826bc7fa 100644
--- a/mysql-test/t/variables-master.opt
+++ b/mysql-test/t/variables-master.opt
@@ -1 +1 @@
---max_join_size=10
+--max_join_size=100
diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test
index 2d0e2dbc9c9..8df1d34ea5e 100644
--- a/mysql-test/t/variables.test
+++ b/mysql-test/t/variables.test
@@ -20,7 +20,6 @@ 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+
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;
@@ -48,7 +47,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
@@ -457,4 +456,18 @@ 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;
+
# End of 5.0 tests
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index d58d74cdb7c..b7e678c6f77 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -1221,11 +1221,11 @@ drop table t1;
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/loaddata3.dat' into table v1 fields terminated by '' enclosed by '' ignore 1 lines;
+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/loaddata3.dat' ignore into table v1 fields terminated by '' enclosed by '' ignore 1 lines;
+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;
@@ -1234,11 +1234,11 @@ drop table t1;
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/loaddata2.dat' into table v1 fields terminated by ',' enclosed by '''';
+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/loaddata2.dat' ignore into table v1 fields terminated by ',' enclosed by '''';
+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;
@@ -1744,7 +1744,6 @@ 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;
-# following will show underlying table until BUG#11555 fix
CHECK TABLE v1, v2, v3, v4, v5, v6;
drop function f1;
drop function f2;
@@ -2076,16 +2075,6 @@ order by users_names;
drop view v1, v2;
drop table t1, t2;
-#
-# DEFINER information check
-#
--- error ER_MALFORMED_DEFINER
-create definer=some_user@`` sql security invoker view v1 as select 1;
-create definer=some_user@localhost sql security invoker view v1 as select 1;
-show create view v1;
-drop view v1;
-
-#
# Bug #6808 - Views: CREATE VIEW v ... FROM t AS v fails
#
@@ -2276,6 +2265,7 @@ drop table t1;
#
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;
@@ -2320,3 +2310,78 @@ 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 ;//
diff --git a/mysql-test/t/view_grant.test b/mysql-test/t/view_grant.test
index 04d6d2f323b..87478a9d4b2 100644
--- a/mysql-test/t/view_grant.test
+++ b/mysql-test/t/view_grant.test
@@ -6,6 +6,8 @@ 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
#
@@ -700,3 +702,14 @@ drop database mysqltest;
disconnect user1;
disconnect root;
connection default;
+
+#
+# DEFINER information check
+#
+-- error ER_MALFORMED_DEFINER
+create definer=some_user@`` sql security invoker view v1 as select 1;
+create definer=some_user@localhost sql security invoker view v1 as select 1;
+show create view v1;
+drop view v1;
+
+
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 26f91569868..1fef3deea3c 100644
--- a/mysql-test/t/wait_timeout.test
+++ b/mysql-test/t/wait_timeout.test
@@ -1,11 +1,30 @@
+# This tests not performed with embedded server
+-- source include/not_embedded.inc
+
#
# Bug #8731: wait_timeout does not work on Mac OS X
#
--disable_reconnect
select 1;
-# wait_timeout is 2, so we should get disconnected now
---sleep 5
+# wait_timeout is 1, so we should get disconnected now
+--sleep 2
+# 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;
+
+# Do the same test as above on a TCP connection
+connect (con1,127.0.0.1,root,,test,$MASTER_MYPORT,);
+--disable_reconnect
+select 1;
+# wait_timeout is 1, so we should get disconnected now
+--sleep 2
+# 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 f6ae7cdaf30..71e847d1d8c 100644
--- a/mysql-test/t/warnings.test
+++ b/mysql-test/t/warnings.test
@@ -50,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;