summaryrefslogtreecommitdiff
path: root/mysql-test/t
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-04-15 15:09:22 +0200
committerSergei Golubchik <sergii@pisem.net>2013-04-15 15:09:22 +0200
commita9035be5b7a7b3865ddb4ef34a5d0cfc65dfc254 (patch)
treea9df7341e91623f62fe37cd47fce139d8888fc95 /mysql-test/t
parent3a1c91d87d69ef243b3e78be6089102cafef0a8e (diff)
parentf57ecb7786177e0af3b1e3ec94302720b2e0f967 (diff)
downloadmariadb-git-a9035be5b7a7b3865ddb4ef34a5d0cfc65dfc254.tar.gz
10.0-base merge
Diffstat (limited to 'mysql-test/t')
-rw-r--r--mysql-test/t/alter_table.test27
-rw-r--r--mysql-test/t/bug13633383.test10
-rw-r--r--mysql-test/t/cache_temporal_4265.test11
-rw-r--r--mysql-test/t/create.test29
-rw-r--r--mysql-test/t/derived.test15
-rw-r--r--mysql-test/t/derived_view.test34
-rw-r--r--mysql-test/t/dyncol.test56
-rw-r--r--mysql-test/t/fulltext.test11
-rw-r--r--mysql-test/t/fulltext_derived_4316.test14
-rw-r--r--mysql-test/t/func_date_add.test12
-rw-r--r--mysql-test/t/func_group.test11
-rw-r--r--mysql-test/t/func_group_innodb.test15
-rw-r--r--mysql-test/t/func_misc.test177
-rw-r--r--mysql-test/t/func_str.test36
-rw-r--r--mysql-test/t/func_time.test12
-rw-r--r--mysql-test/t/gis-rtree.test4
-rw-r--r--mysql-test/t/gis.test116
-rw-r--r--mysql-test/t/grant4.test4
-rw-r--r--mysql-test/t/group_by.test74
-rw-r--r--mysql-test/t/group_min_max.test59
-rw-r--r--mysql-test/t/information_schema_all_engines-master.opt3
-rw-r--r--mysql-test/t/information_schema_all_engines.test2
-rw-r--r--mysql-test/t/innodb_ext_key.test76
-rw-r--r--mysql-test/t/join.test26
-rw-r--r--mysql-test/t/join_cache.test2
-rw-r--r--mysql-test/t/join_outer_innodb.test207
-rw-r--r--mysql-test/t/keywords.test11
-rw-r--r--mysql-test/t/mdl_sync.test2
-rw-r--r--mysql-test/t/merge.test86
-rw-r--r--mysql-test/t/multi_update.test52
-rw-r--r--mysql-test/t/myisam-metadata.test49
-rw-r--r--mysql-test/t/myisam-system.test11
-rw-r--r--mysql-test/t/myisam.test20
-rw-r--r--mysql-test/t/mysql.test9
-rw-r--r--mysql-test/t/mysql_client_test.test2
-rw-r--r--mysql-test/t/mysql_client_test_nonblock.test1
-rw-r--r--mysql-test/t/mysqlcheck.test1
-rw-r--r--mysql-test/t/mysqld--help.test9
-rw-r--r--mysql-test/t/partition.test28
-rw-r--r--mysql-test/t/partition_debug_sync.test11
-rw-r--r--mysql-test/t/partition_disabled.test2
-rw-r--r--mysql-test/t/partition_not_windows.test2
-rw-r--r--mysql-test/t/partition_rename_longfilename.test1
-rw-r--r--mysql-test/t/plugin.test32
-rw-r--r--mysql-test/t/ps_1general.test5
-rw-r--r--mysql-test/t/quick_select_4161.test53
-rw-r--r--mysql-test/t/rename.test10
-rw-r--r--mysql-test/t/select.test19
-rw-r--r--mysql-test/t/show_check.test2
-rw-r--r--mysql-test/t/show_explain.test2
-rw-r--r--mysql-test/t/sp-destruct.test3
-rw-r--r--mysql-test/t/subselect4.test13
-rw-r--r--mysql-test/t/subselect_exists2in.test739
-rw-r--r--mysql-test/t/subselect_exists2in_costmat.test83
-rw-r--r--mysql-test/t/subselect_exists_to_in.test11
-rw-r--r--mysql-test/t/subselect_sj.test9
-rw-r--r--mysql-test/t/subselect_sj2_mat.test226
-rw-r--r--mysql-test/t/sum_distinct-big.test69
-rw-r--r--mysql-test/t/temporal_scale_4283.test13
-rw-r--r--mysql-test/t/truncate_badse.test15
-rw-r--r--mysql-test/t/type_datetime.test10
-rw-r--r--mysql-test/t/type_enum.test15
-rw-r--r--mysql-test/t/upgrade.test7
-rw-r--r--mysql-test/t/user_var.test48
-rw-r--r--mysql-test/t/variables.test16
65 files changed, 2584 insertions, 156 deletions
diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test
index eade7ba721e..d48b1687fa0 100644
--- a/mysql-test/t/alter_table.test
+++ b/mysql-test/t/alter_table.test
@@ -1231,3 +1231,30 @@ execute stmt1;
deallocate prepare stmt1;
drop table t2;
+#
+# Test of ALTER TABLE IF [NOT] EXISTS
+#
+
+CREATE TABLE t1 (
+ id INT(11) NOT NULL,
+ x_param INT(11) DEFAULT NULL,
+ PRIMARY KEY (id)
+);
+
+ALTER TABLE t1 ADD COLUMN IF NOT EXISTS id INT,
+ ADD COLUMN IF NOT EXISTS lol INT AFTER id;
+ALTER TABLE t1 ADD COLUMN IF NOT EXISTS lol INT AFTER id;
+ALTER TABLE t1 DROP COLUMN IF EXISTS lol;
+ALTER TABLE t1 DROP COLUMN IF EXISTS lol;
+
+ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param);
+ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param);
+ALTER TABLE t1 MODIFY IF EXISTS lol INT;
+
+DROP INDEX IF EXISTS x_param ON t1;
+DROP INDEX IF EXISTS x_param ON t1;
+CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param);
+CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
diff --git a/mysql-test/t/bug13633383.test b/mysql-test/t/bug13633383.test
index 72eb2f81c98..e31d4a8c9f6 100644
--- a/mysql-test/t/bug13633383.test
+++ b/mysql-test/t/bug13633383.test
@@ -5,19 +5,19 @@
CREATE TABLE t1 (
`a` int(11) DEFAULT NULL,
`col432` bit(8) DEFAULT NULL,
- `col433` multipoint DEFAULT NULL,
- `col434` polygon DEFAULT NULL,
+ `col433` geometry DEFAULT NULL,
+ `col434` geometry DEFAULT NULL,
`col435` decimal(50,17) unsigned DEFAULT NULL,
`col436` geometry NOT NULL,
`col437` tinyblob NOT NULL,
- `col438` multipolygon DEFAULT NULL,
+ `col438` geometry DEFAULT NULL,
`col439` mediumblob NOT NULL,
`col440` tinyblob NOT NULL,
`col441` double unsigned DEFAULT NULL
);
CREATE TABLE t2 (
- `a` multipoint DEFAULT NULL,
+ `a` geometry DEFAULT NULL,
`col460` date DEFAULT NULL,
`col461` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`col462` date NOT NULL,
@@ -34,7 +34,7 @@ CREATE TABLE t3 (
`col579` bit(38) NOT NULL,
`col580` varchar(93) NOT NULL,
`col581` datetime DEFAULT NULL,
- `col583` multipolygon DEFAULT NULL,
+ `col583` geometry DEFAULT NULL,
`col584` bit(47) NOT NULL
);
diff --git a/mysql-test/t/cache_temporal_4265.test b/mysql-test/t/cache_temporal_4265.test
new file mode 100644
index 00000000000..6135438f023
--- /dev/null
+++ b/mysql-test/t/cache_temporal_4265.test
@@ -0,0 +1,11 @@
+#
+# MDEV-4265 5.5 is slower than 5.3 because of many str_to_datetime calls
+#
+--source include/have_debug.inc
+
+create table t1 (a date);
+insert t1 values ('2000-01-02'), ('2001-02-03'), ('2002-03-04');
+set debug_dbug='d,str_to_datetime_warn';
+select * from t1 where a > date_add('2000-01-01', interval 5 day);
+drop table t1;
+
diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test
index a61f89539cb..f82d859243a 100644
--- a/mysql-test/t/create.test
+++ b/mysql-test/t/create.test
@@ -1559,29 +1559,26 @@ drop table t1,t2,t3;
--echo # -- End of Bug#45829
#
---echo # new table creation/renaming blocked if old encoded table present
+# new table creation/renaming is NOT blocked if old encoded table present
#
let $MYSQLD_DATADIR= `select @@datadir`;
-create table `t-1` (a int) engine=myisam;
-insert into `t-1` values (1);
+create table `#mysql50#t-1` (a int) engine=myisam;
+insert into `#mysql50#t-1` values (1);
show tables;
-flush tables;
---echo convert table files in mysql 5.0 file name encoding
---copy_file $MYSQLD_DATADIR/test/t@002d1.MYD $MYSQLD_DATADIR/test/t-1.MYD
---copy_file $MYSQLD_DATADIR/test/t@002d1.MYI $MYSQLD_DATADIR/test/t-1.MYI
---copy_file $MYSQLD_DATADIR/test/t@002d1.frm $MYSQLD_DATADIR/test/t-1.frm
---remove_file $MYSQLD_DATADIR/test/t@002d1.MYD
---remove_file $MYSQLD_DATADIR/test/t@002d1.MYI
---remove_file $MYSQLD_DATADIR/test/t@002d1.frm
-show tables;
---error ER_TABLE_EXISTS_ERROR
create table `t-1` (a int);
+show tables;
+# selects can distinguish between the two tables
+select * from `t-1`;
+select * from `#mysql50#t-1`;
+drop table `t-1`;
create table t1 (a int);
---error ER_TABLE_EXISTS_ERROR
alter table t1 rename `t-1`;
---error ER_TABLE_EXISTS_ERROR
+show tables;
+drop table `t-1`;
+create table t1 (a int);
rename table t1 to `t-1`;
-drop table `#mysql50#t-1`, t1;
+show tables;
+drop table `#mysql50#t-1`, `t-1`;
--echo
--echo End of 5.1 tests
diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test
index 4cf5cccc254..381c87c635c 100644
--- a/mysql-test/t/derived.test
+++ b/mysql-test/t/derived.test
@@ -343,3 +343,18 @@ SELECT 1 FROM t1 JOIN v1 ON 1 > (SELECT 1 FROM v2);
DROP TABLE t1, t2;
DROP VIEW v1, v2;
set optimizer_switch=@save_derived_optimizer_switch;
+
+#
+# MDEV-614 lp:1050806 - different result for a query using subquery between 5.5.25 and 5.5.27
+# MySQL Bug#66845 Wrong result (extra row) on a FROM subquery with a variable and ORDER BY
+#
+create table t1 (n bigint(20) unsigned, d1 datetime, d2 datetime, key (d1));
+insert t1 values (2085,'2012-01-01 00:00:00','2013-01-01 00:00:00');
+insert t1 values (2084,'2012-02-01 00:00:00','2013-01-01 00:00:00');
+insert t1 values (2088,'2012-03-01 00:00:00','2013-01-01 00:00:00');
+select * from (
+ select n, d1, d2, @result := 0 as result
+ from t1
+ where d1 < '2012-12-12 12:12:12' and n in (2085, 2084) order by d2 asc
+) as calculated_result;
+drop table t1;
diff --git a/mysql-test/t/derived_view.test b/mysql-test/t/derived_view.test
index c7705294ef2..4b7e76e11ca 100644
--- a/mysql-test/t/derived_view.test
+++ b/mysql-test/t/derived_view.test
@@ -1512,6 +1512,40 @@ set optimizer_switch=@save3912_optimizer_switch;
drop table t1, t2, t3;
--echo #
+--echo # MDEV-4209: equi-join on BLOB column from materialized view
+--echo # or derived table
+--echo #
+
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='derived_with_keys=on';
+
+CREATE TABLE t1 (c1 text, c2 int);
+INSERT INTO t1 VALUES ('a',1), ('c',3), ('g',7), ('d',4), ('c',3);
+CREATE TABLE t2 (c1 text, c2 int);
+INSERT INTO t2 VALUES ('b',2), ('c',3);
+CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
+
+EXPLAIN EXTENDED
+SELECT v1.c1, v1.c2 FROM v1, t2 WHERE v1.c1=t2.c1 AND v1.c2=t2.c2;
+SELECT v1.c1, v1.c2 FROM v1, t2 WHERE v1.c1=t2.c1 AND v1.c2=t2.c2;
+
+EXPLAIN EXTENDED
+SELECT t2.c1, t2.c2 FROM (SELECT c1 g, MAX(c2) m FROM t1 GROUP BY c1) t, t2
+ WHERE t.g=t2.c1 AND t.m=t2.c2;
+SELECT t2.c1, t2.c2 FROM (SELECT c1 g, MAX(c2) m FROM t1 GROUP BY c1) t, t2
+ WHERE t.g=t2.c1 AND t.m=t2.c2;
+
+EXPLAIN EXTENDED
+SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1;
+SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1;
+
+DROP VIEW v1;
+DROP TABLE t1,t2;
+
+set optimizer_switch=@save_optimizer_switch;
+
+
+--echo #
--echo # end of 5.3 tests
--echo #
diff --git a/mysql-test/t/dyncol.test b/mysql-test/t/dyncol.test
index de30cac610a..c817e7209f6 100644
--- a/mysql-test/t/dyncol.test
+++ b/mysql-test/t/dyncol.test
@@ -552,6 +552,62 @@ select hex(COLUMN_CREATE(0, COLUMN_GET(COLUMN_CREATE(0, 0.0 as decimal), 0 as de
select hex(COLUMN_CREATE(0, 0.0 as decimal));
--echo #
+--echo # MDEV-4292: parse error when selecting on views using dynamic column
+--echo #
+create table t1 (i int, d blob);
+
+create view v1 as select i, column_get(d, 1 as binary) as a from t1;
+select * from v1;
+show create view v1;
+drop view v1;
+
+create view v1 as select i, column_get(d, 1 as int) as a from t1;
+select * from v1;
+show create view v1;
+drop view v1;
+
+create view v1 as select i, column_get(d, 1 as unsigned int) as a from t1;
+select * from v1;
+show create view v1;
+drop view v1;
+
+create view v1 as select i, column_get(d, 1 as date) as a from t1;
+select * from v1;
+show create view v1;
+drop view v1;
+
+create view v1 as select i, column_get(d, 1 as time) as a from t1;
+select * from v1;
+show create view v1;
+drop view v1;
+
+create view v1 as select i, column_get(d, 1 as datetime) as a from t1;
+select * from v1;
+show create view v1;
+drop view v1;
+
+create view v1 as select i, column_get(d, 1 as decimal) as a from t1;
+select * from v1;
+show create view v1;
+drop view v1;
+
+create view v1 as select i, column_get(d, 1 as double) as a from t1;
+select * from v1;
+show create view v1;
+drop view v1;
+
+create view v1 as select i, column_get(d, 1 as char) as a from t1;
+select * from v1;
+show create view v1;
+drop view v1;
+
+drop table t1;
+
+--echo #
+--echo # end of 5.3 tests
+--echo #
+
+--echo #
--echo # test of symbolic names
--echo #
--echo # creation test (names)
diff --git a/mysql-test/t/fulltext.test b/mysql-test/t/fulltext.test
index b4b09413896..6e44b4c1578 100644
--- a/mysql-test/t/fulltext.test
+++ b/mysql-test/t/fulltext.test
@@ -646,3 +646,14 @@ DEALLOCATE PREPARE stmt;
DROP TABLE t1;
--echo End of 5.1 tests
+
+CREATE TABLE t1 (
+ id int(11) auto_increment,
+ title varchar(100) default '',
+ PRIMARY KEY (id),
+ KEY ind5 (title)
+) ENGINE=MyISAM;
+
+CREATE FULLTEXT INDEX IF NOT EXISTS ft1 ON t1(title);
+CREATE FULLTEXT INDEX IF NOT EXISTS ft1 ON t1(title);
+DROP TABLE t1;
diff --git a/mysql-test/t/fulltext_derived_4316.test b/mysql-test/t/fulltext_derived_4316.test
new file mode 100644
index 00000000000..ecf4a0e7722
--- /dev/null
+++ b/mysql-test/t/fulltext_derived_4316.test
@@ -0,0 +1,14 @@
+#
+# MATCH on the derived tables
+#
+
+#
+# MDEV-4316 MariaDB server crash with signal 11
+#
+
+create table t1 (ft text) engine=myisam;
+insert into t1 values ('test1'),('test2');
+select distinct match(ft) against("test1" in boolean mode) from
+ (select distinct ft from t1) as t;
+drop table t1;
+
diff --git a/mysql-test/t/func_date_add.test b/mysql-test/t/func_date_add.test
index fc5a5cb2823..5f27978347c 100644
--- a/mysql-test/t/func_date_add.test
+++ b/mysql-test/t/func_date_add.test
@@ -88,3 +88,15 @@ select b + interval a day from t1;
drop table t1;
--echo End of 5.0 tests
+
+#
+# MDEV-4284 Assertion `cmp_items[(uint)cmp_type]' fails in sql/item_cmpfunc.cc
+#
+
+create table t1 (a varchar(10));
+insert t1 values ('2000-12-03'),('2008-05-03');
+select * from t1 where case a when adddate( '2012-12-12', 7 ) then true end;
+drop table t1;
+
+--echo End of 5.5 tests
+
diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test
index 89c6c0fe534..97766fefa91 100644
--- a/mysql-test/t/func_group.test
+++ b/mysql-test/t/func_group.test
@@ -1372,7 +1372,16 @@ set @@optimizer_switch=@save_optimizer_switch;
--echo #
DROP TABLE IF EXISTS t1,t2,t3,empty1;
-###
+#
+# MDEV-4286 Server crashes in Protocol_text::store, stack smashing detected
+#
+create table t1 (i int, d date);
+insert into t1 values (1, '2008-10-02'), (2, '2010-12-12');
+select avg(export_set( 3, 'y', sha(i))), group_concat(d) from t1 group by d order by i;
+drop table t1;
+
+#### End of 5.3 tests
+
--echo #
--echo # Bug#52123 Assertion failed: aggregator == aggr->Aggrtype(),
--echo # file .\item_sum.cc, line 587
diff --git a/mysql-test/t/func_group_innodb.test b/mysql-test/t/func_group_innodb.test
index 6706792d162..06405808d79 100644
--- a/mysql-test/t/func_group_innodb.test
+++ b/mysql-test/t/func_group_innodb.test
@@ -159,7 +159,20 @@ SELECT member_id_to, COUNT(*) FROM t1 WHERE r_date =
DROP TABLE t1;
---echo # End of test BUG#12713907
+--echo #
+--echo # MDEV-4269: crash when grouping by values()
+--echo #
+
+SELECT @@storage_engine INTO @old_engine;
+set storage_engine=innodb;
+
+create table y select 1 b;
+select 1 from y group by b;
+select 1 from y group by values(b);
+drop table y;
+SET storage_engine=@old_engine;
+
+### End of 5.1 tests
--echo #
--echo # Bug#13723054 CRASH WITH MIN/MAX AFTER QUICK_GROUP_MIN_MAX_SELECT::NEXT_MIN
diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test
index 292db69a6e3..22ebb6248e2 100644
--- a/mysql-test/t/func_misc.test
+++ b/mysql-test/t/func_misc.test
@@ -369,6 +369,183 @@ drop table t1,tv;
--echo #
+--echo # GET_LOCK, RELEASE_LOCK, IS_USED_LOCK functions test
+--echo #
+
+--echo # IS_USED_LOCK, IS_FREE_LOCK: the lock is not acquired
+--echo # Note: IS_USED_LOCK returns NULL if the lock is unused
+select is_used_lock('test');
+select is_free_lock('test');
+
+--echo # GET_LOCK returns 1 if it manages to acquire a lock
+select get_lock('test', 0);
+
+--echo # IS_USED_LOCK, IS_FREE_LOCK: the lock is acquired
+select is_free_lock('test');
+select is_used_lock('test') = connection_id();
+
+connect (con1,localhost,root,,);
+--echo # -> Switching to connection 'con1'
+connection con1;
+--echo # IS_USED_LOCK, IS_FREE_LOCK: the lock is acquired in another
+--echo # connection
+select is_used_lock('test') = connection_id();
+select is_free_lock('test');
+
+--echo # GET_LOCK returns 0 if it can't acquire a lock (wait timeout)
+select get_lock('test', 0);
+
+--echo # RELEASE_LOCK returns 0 if the lock belongs to another connection
+select release_lock('test');
+
+--echo # -> Switching to connection 'default'
+connection default;
+
+--echo # RELEASE_LOCK returns 1 if it successfully releases a lock
+select release_lock('test');
+--echo # RELEASE_LOCK returns NULL if it doesn't release a lock and there is no such lock
+select release_lock('test');
+
+--echo # Test that get_lock() returns NULL if error.
+select get_lock('test', 0);
+--echo # -> Switching to connection 'con1'
+connection con1;
+create table t1 select connection_id() as id;
+send select get_lock('test', 7200);
+
+--echo # -> Switching to connection 'default'
+connection default;
+let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state='User lock';
+source include/wait_condition.inc;
+select (@id := id) - id from t1;
+kill query @id;
+
+--echo # -> Switching to connection 'con1'
+connection con1;
+reap;
+
+--echo # -> Switching to connection 'default'
+connection default;
+
+--echo # GET_LOCK() works recursively
+select get_lock('test', 0);
+select get_lock('test', 0);
+select get_lock('test', 0);
+
+--echo # RELEASE_LOCK() needs to be called recursively then, too
+select release_lock('test');
+select release_lock('test');
+select release_lock('test');
+
+--echo # Once the last instance of the lock is released,
+--echo # the next call returns NULL
+select release_lock('test');
+
+
+--echo # Multiple locks in the same session are OK
+select get_lock('test1', 0);
+select get_lock('test2', 0);
+select get_lock('test3', 0);
+
+select release_lock('test1');
+select release_lock('test2');
+select release_lock('test3');
+
+--echo # Deadlocks are detected e.g. in case of a mutual wait
+select get_lock('test1', 0);
+
+--echo # -> Switching to connection 'con1'
+connection con1;
+select get_lock('test2', 0);
+send select get_lock('test1', 7200);
+
+--echo # -> Switching to connection 'default'
+connection default;
+let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state='User lock';
+source include/wait_condition.inc;
+--error ER_LOCK_DEADLOCK
+select get_lock('test2', 7200);
+
+select release_lock('test1');
+
+--echo # -> Switching to connection 'con1'
+connection con1;
+reap;
+select release_lock('test2');
+select release_lock('test1');
+
+--echo # -> Switching to connection 'default'
+connection default;
+
+--echo # LOCK/UNLOCK TABLES works fine with a user lock.
+lock table t1 write;
+select get_lock('test', 0);
+unlock tables;
+commit;
+select release_lock('test');
+
+--echo # GLOBAL READ LOCK works with fine with user locks
+select get_lock('test1', 0);
+flush tables with read lock;
+select get_lock('test2', 0);
+unlock tables;
+commit;
+select release_lock('test1');
+select release_lock('test2');
+
+--echo # BEGIN/COMMIT/ROLLBACK don't unlock user locks.
+begin;
+select get_lock('test1', 0);
+select get_lock('test2', 0);
+select count(*) from t1;
+rollback;
+select release_lock('test1');
+select release_lock('test2');
+
+--echo # Deadlocks between user locks and LOCK TABLES locks
+--echo # are detected OK.
+select get_lock('test', 0);
+
+--echo # -> Switching to connection 'con1'
+connection con1;
+lock table t1 write;
+send select get_lock('test', 7200);
+
+--echo # -> Switching to connection 'default'
+connection default;
+let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state = 'User lock';
+source include/wait_condition.inc;
+--error ER_LOCK_DEADLOCK
+lock table t1 read;
+
+select release_lock('test');
+
+--echo # -> Switching to connection 'con1'
+connection con1;
+reap;
+select release_lock('test');
+unlock tables;
+
+--echo # cleanup
+disconnect con1;
+connection default;
+drop table t1;
+
+--echo # check too long identifier names
+select get_lock(repeat('a', 192), 0);
+select is_used_lock(repeat('a', 192)) = connection_id();
+select is_free_lock(repeat('a', 192));
+select release_lock(repeat('a', 192));
+--error ER_TOO_LONG_IDENT
+select get_lock(repeat('a', 193), 0);
+--error ER_TOO_LONG_IDENT
+select is_used_lock(repeat('a', 193));
+--error ER_TOO_LONG_IDENT
+select is_free_lock(repeat('a', 193));
+--error ER_TOO_LONG_IDENT
+select release_lock(repeat('a', 193));
+
+--echo #
--echo # End of 5.5 tests
--echo #
diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test
index d8d8f4538e1..f245b4f9f78 100644
--- a/mysql-test/t/func_str.test
+++ b/mysql-test/t/func_str.test
@@ -1385,6 +1385,24 @@ LOAD DATA INFILE 'bug58165.txt' INTO TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
+#
+# MDEV-759 lp:998340 - Valgrind complains on simple selects containing expression DAY(FROM_UNIXTIME(-1))
+#
+SELECT SUBSTRING('1', DAY(FROM_UNIXTIME(-1)));
+SELECT LEFT('1', DAY(FROM_UNIXTIME(-1)));
+SELECT RIGHT('1', DAY(FROM_UNIXTIME(-1)));
+SELECT REPEAT('1', DAY(FROM_UNIXTIME(-1)));
+SELECT RPAD('hi', DAY(FROM_UNIXTIME(-1)),'?');
+SELECT LPAD('hi', DAY(FROM_UNIXTIME(-1)),'?');
+
+#
+# MDEV-4289 Assertion `0' fails in make_sortkey with GROUP_CONCAT, MAKE_SET, GROUP BY
+#
+create table t1 (i int);
+insert into t1 values (null),(8);
+select group_concat( i ), make_set( i, 'a', 'b' ) field from t1 group by field;
+drop table t1;
+
--echo End of 5.1 tests
--echo Start of 5.4 tests
@@ -1502,11 +1520,6 @@ round(
--connection default
SET @@global.max_allowed_packet:= @tmp_max;
--disconnect newconn
-
---echo #
---echo # End of 5.5 tests
---echo #
-
#
# Bug#11765562 58545:
# EXPORT_SET() CAN BE USED TO MAKE ENTIRE SERVER COMPLETELY UNRESPONSIVE
@@ -1517,3 +1530,16 @@ SELECT @@global.max_allowed_packet;
SELECT CHAR_LENGTH(EXPORT_SET(1,1,1,REPEAT(1,100000000)));
SET @@global.max_allowed_packet:= @tmp_max;
+--echo #
+--echo # MDEV-4272: DIV operator crashes in Item_func_int_div::val_int
+--echo # (incorrect NULL value handling by convert)
+--echo #
+create table t1(a int) select null;
+select 1 div convert(a using utf8) from t1;
+drop table t1;
+
+
+--echo #
+--echo # End of 5.5 tests
+--echo #
+
diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
index 57ef68595bf..7a72c21d0ff 100644
--- a/mysql-test/t/func_time.test
+++ b/mysql-test/t/func_time.test
@@ -883,7 +883,9 @@ SELECT STR_TO_DATE(SPACE(2),'1');
--echo #
SET GLOBAL SQL_MODE='';
+--disable_warnings
DO STR_TO_DATE((''), FROM_DAYS(@@GLOBAL.SQL_MODE));
+--enable_warnings
SET GLOBAL SQL_MODE=DEFAULT;
--echo #
@@ -1174,3 +1176,13 @@ select microsecond('12:00:00.123456'), microsecond('2009-12-31 23:59:59.000010')
--error ER_TOO_BIG_PRECISION
select now(258);
+
+#
+# MDEV-4293 Valgrind warnings (Conditional jump or move depends on uninitialised value) in remove_eq_conds on time functions with NULL argument in WHERE
+#
+SELECT 1 FROM DUAL WHERE YEAR(TIMEDIFF(NULL, '12:12:12'));
+SELECT 1 FROM DUAL WHERE MONTH(TIMEDIFF(NULL, '12:12:12'));
+SELECT 1 FROM DUAL WHERE DAYOFMONTH(TIMEDIFF(NULL, '12:12:12'));
+SELECT 1 FROM DUAL WHERE HOUR(TIMEDIFF(NULL, '12:12:12'));
+SELECT 1 FROM DUAL WHERE MINUTE(TIMEDIFF(NULL, '12:12:12'));
+SELECT 1 FROM DUAL WHERE SECOND(TIMEDIFF(NULL, '12:12:12'));
diff --git a/mysql-test/t/gis-rtree.test b/mysql-test/t/gis-rtree.test
index e7e6fa59df0..731efe5648e 100644
--- a/mysql-test/t/gis-rtree.test
+++ b/mysql-test/t/gis-rtree.test
@@ -120,7 +120,7 @@ INSERT INTO t1 (g) VALUES (GeomFromText('LineString(1 2, 2 3)')),(GeomFromText('
drop table t1;
CREATE TABLE t1 (
- line LINESTRING NOT NULL,
+ line GEOMETRY NOT NULL,
kind ENUM('po', 'pp', 'rr', 'dr', 'rd', 'ts', 'cl') NOT NULL DEFAULT 'po',
name VARCHAR(32),
@@ -935,7 +935,7 @@ DROP TABLE t1;
--echo # and invalid spatial data
--echo #
-CREATE TABLE t1(a LINESTRING NOT NULL, b GEOMETRY NOT NULL,
+CREATE TABLE t1(a POINT NOT NULL, b GEOMETRY NOT NULL,
SPATIAL KEY(a), SPATIAL KEY(b)) ENGINE=MyISAM;
INSERT INTO t1 VALUES(GEOMFROMTEXT("point (0 0)"), GEOMFROMTEXT("point (1 1)"));
--error ER_CANT_CREATE_GEOMETRY_OBJECT
diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test
index b0ad8329cfb..cff93fc13ee 100644
--- a/mysql-test/t/gis.test
+++ b/mysql-test/t/gis.test
@@ -741,7 +741,7 @@ SET @a=POLYFROMWKB(@a);
# Bug #57321 crashes and valgrind errors from spatial types
#
-create table t1(a polygon NOT NULL)engine=myisam;
+create table t1(a geometry NOT NULL)engine=myisam;
insert into t1 values (geomfromtext("point(0 1)"));
insert into t1 values (geomfromtext("point(1 0)"));
select * from (select polygon(t1.a) as p from t1 order by t1.a) d;
@@ -759,6 +759,87 @@ create spatial index i on t1 (a);
drop table t1;
+#
+# Bug#11767480 - SPATIAL INDEXES ON NON-SPATIAL COLUMNS CAUSE CRASHES.
+#
+CREATE TABLE t0 (a BINARY(32) NOT NULL);
+--error ER_WRONG_ARGUMENTS
+CREATE SPATIAL INDEX i on t0 (a);
+INSERT INTO t0 VALUES (1);
+
+--error ER_WRONG_ARGUMENTS
+CREATE TABLE t1(
+ col0 BINARY NOT NULL,
+ col2 TIMESTAMP,
+ SPATIAL INDEX i1 (col0)
+) ENGINE=MyISAM;
+
+# Test other ways to add indices
+CREATE TABLE t1 (
+ col0 BINARY NOT NULL,
+ col2 TIMESTAMP
+) ENGINE=MyISAM;
+
+--error ER_WRONG_ARGUMENTS
+CREATE SPATIAL INDEX idx0 ON t1(col0);
+
+--error ER_WRONG_ARGUMENTS
+ALTER TABLE t1 ADD SPATIAL INDEX i1 (col0);
+
+CREATE TABLE t2 (
+ col0 INTEGER NOT NULL,
+ col1 POINT,
+ col2 POINT
+);
+
+--error ER_WRONG_ARGUMENTS
+CREATE SPATIAL INDEX idx0 ON t2 (col1, col2);
+
+--error ER_WRONG_ARGUMENTS
+CREATE TABLE t3 (
+ col0 INTEGER NOT NULL,
+ col1 POINT,
+ col2 LINESTRING,
+ SPATIAL INDEX i1 (col1, col2)
+);
+
+# cleanup
+DROP TABLE t0, t1, t2;
+
+
+--echo #
+--echo # BUG#12414917 - ISCLOSED() CRASHES ON 64-BIT BUILDS
+--echo #
+SELECT ISCLOSED(CONVERT(CONCAT(' ', 0x2), BINARY(20)));
+
+--echo #
+--echo # BUG#12537203 - CRASH WHEN SUBSELECTING GLOBAL VARIABLES IN
+--echo # GEOMETRY FUNCTION ARGUMENTS
+--echo #
+--replace_regex /non geometric .* value/non geometric '' value/
+--error ER_ILLEGAL_VALUE_FOR_TYPE
+SELECT GEOMETRYCOLLECTION((SELECT @@OLD));
+
+--echo #
+--echo # MDEV-4252 geometry query crashes server
+--echo #
+select astext(0x0100000000030000000100000000000010);
+select astext(st_centroid(0x0100000000030000000100000000000010));
+select astext(st_exteriorring(0x0100000000030000000100000000000010));
+select envelope(0x0100000000030000000100000000000010);
+select geometryn(0x0100000000070000000100000001030000000200000000000000ffff0000, 1);
+select geometryn(0x0100000000070000000100000001030000000200000000000000ffffff0f, 1);
+
+--echo #
+--echo # MDEV-4296 Assertion `n_linear_rings > 0' fails in Gis_polygon::centroid_xy
+--echo #
+
+SELECT Centroid( AsBinary( LineString(Point(0,0), Point(0,0), Point(0,0) )));
+
+--echo #
+--echo # MDEV-4295 Server crashes in get_point on a query with Area, AsBinary, MultiPoint
+--echo #
+SELECT Area(AsBinary(MultiPoint(Point(0,9), Point(0,1), Point(2,2))));
--echo End of 5.1 tests
#bug 850775 ST_AREA does not work on GEOMETRYCOLLECTIONs in maria-5.3-gis
@@ -1293,6 +1374,7 @@ WHERE ST_Contains(ST_Buffer(bridges.position, 15.0), buildings.footprint) = 1;
#WHERE lakes.name = 'Blue Lake';
DROP DATABASE gis_ogs;
+USE test;
--echo #
--echo # BUG #1043845 st_distance() results are incorrect depending on variable order
@@ -1308,25 +1390,18 @@ select st_distance(geomfromtext('point(-95.96269500000000000000 36.1418183333333
-95.9673057475387 36.1344478941074,
-95.9673063519371 36.134484524621,
-95.9673049102515 36.1343976584193) ')) ;
-USE test;
-
--echo #
---echo # BUG#12414917 - ISCLOSED() CRASHES ON 64-BIT BUILDS
+--echo # MDEV-4310 geometry function equals hangs forever.
--echo #
-SELECT ISCLOSED(CONVERT(CONCAT(' ', 0x2), BINARY(20)));
-
---echo #
---echo # BUG#12537203 - CRASH WHEN SUBSELECTING GLOBAL VARIABLES IN
---echo # GEOMETRY FUNCTION ARGUMENTS
---echo #
---replace_regex /non geometric .* value/non geometric '' value/
---error ER_ILLEGAL_VALUE_FOR_TYPE
-SELECT GEOMETRYCOLLECTION((SELECT @@OLD));
-
-
---echo End of 5.1 tests
+create table t1(a geometry not null)engine=myisam;
+insert into t1 values(geomfromtext("POINT(0 0)"));
+insert into t1 values(geomfromtext("POINT(0 9.2233720368548e18)"));
+insert into t1 values(geomfromtext("POINT(0 9.2233720368548e18)"));
+select equals(`a`,convert(`a` using utf8)) from `t1`;
+drop table t1;
+--echo End of 5.3 tests
--echo #
--echo # Bug#11908153: CRASH AND/OR VALGRIND ERRORS IN FIELD_BLOB::GET_KEY_IMAGE
@@ -1358,4 +1433,13 @@ SELECT 1 FROM g1 WHERE a >= ANY
DROP TABLE g1;
+--echo #
+--echo # MDEV-3819 missing constraints for spatial column types
+--echo #
+
+create table t1 (pt point);
+--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
+insert into t1 values(Geomfromtext('POLYGON((1 1, 2 2, 2 1, 1 1))'));
+drop table t1;
+
--echo End of 5.5 tests
diff --git a/mysql-test/t/grant4.test b/mysql-test/t/grant4.test
index f3e551cd623..c30e0c28f31 100644
--- a/mysql-test/t/grant4.test
+++ b/mysql-test/t/grant4.test
@@ -104,9 +104,7 @@ connection con1;
use mysqltest_db1;
--echo ** Connect as restricted user mysqltest_u1.
--echo ** SELECT FROM INFORMATION_SCHEMA.STATISTICS will succeed because any privileges will do (authentication is enough).
-#
-# this result is wrong. reported as bug#34104
-#
+--echo ** but will return no rows
SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_name='t5';
#
# Bug27145 EXTRA_ACL trouble
diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test
index b2dd84f63c7..b606d413608 100644
--- a/mysql-test/t/group_by.test
+++ b/mysql-test/t/group_by.test
@@ -1322,6 +1322,80 @@ SELECT 1 FROM t1 GROUP BY SUBSTRING(SYSDATE() FROM 'K' FOR 'jxW<');
DROP TABLE t1;
SET BIG_TABLES=0;
+--echo #
+--echo # MDEV-641 LP:1002108 - Wrong result (or crash) from a query with duplicated field in the group list and a limit clause
+--echo # Bug#11761078: 53534: INCORRECT 'SELECT SQL_BIG_RESULT...'
+--echo # WITH GROUP BY ON DUPLICATED FIELDS
+--echo #
+
+CREATE TABLE t1(
+ col1 int,
+ UNIQUE INDEX idx (col1));
+
+INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),
+ (11),(12),(13),(14),(15),(16),(17),(18),(19),(20);
+
+let $query0=SELECT col1 AS field1, col1 AS field2
+ FROM t1 GROUP BY field1, field2;
+
+# Needs to be range to exercise bug
+--eval EXPLAIN $query0;
+FLUSH STATUS;
+--eval $query0;
+SHOW SESSION STATUS LIKE 'Sort_scan%';
+
+let $query=SELECT SQL_BIG_RESULT col1 AS field1, col1 AS field2
+ FROM t1 GROUP BY field1, field2;
+
+# Needs to be range to exercise bug
+--eval EXPLAIN $query;
+FLUSH STATUS;
+--eval $query;
+SHOW SESSION STATUS LIKE 'Sort_scan%';
+
+CREATE VIEW v1 AS SELECT * FROM t1;
+
+SELECT SQL_BIG_RESULT col1 AS field1, col1 AS field2
+FROM v1
+GROUP BY field1, field2;
+
+SELECT SQL_BIG_RESULT tbl1.col1 AS field1, tbl2.col1 AS field2
+FROM t1 as tbl1, t1 as tbl2
+GROUP BY field1, field2
+LIMIT 3;
+
+explain
+select col1 f1, col1 f2 from t1 order by f2, f1;
+select col1 f1, col1 f2 from t1 order by f2, f1;
+
+explain
+select col1 f1, col1 f2 from t1 group by f2 order by f2, f1;
+select col1 f1, col1 f2 from t1 group by f2 order by f2, f1;
+
+explain
+select col1 f1, col1 f2 from t1 group by f1, f2 order by f2, f1;
+select col1 f1, col1 f2 from t1 group by f1, f2 order by f2, f1;
+
+CREATE TABLE t2(
+ col1 int,
+ col2 int,
+ UNIQUE INDEX idx (col1, col2));
+
+INSERT INTO t2(col1, col2) VALUES
+ (1,20),(2,19),(3,18),(4,17),(5,16),(6,15),(7,14),(8,13),(9,12),(10,11),
+ (11,10),(12,9),(13,8),(14,7),(15,6),(16,5),(17,4),(18,3),(19,2),(20,1);
+
+explain
+select col1 f1, col2 f2, col1 f3 from t2 group by f1, f2, f3;
+select col1 f1, col2 f2, col1 f3 from t2 group by f1, f2, f3;
+
+explain
+select col1 f1, col2 f2, col1 f3 from t2 order by f1, f2, f3;
+select col1 f1, col2 f2, col1 f3 from t2 order by f1, f2, f3;
+
+DROP VIEW v1;
+DROP TABLE t1, t2;
+
--echo # End of 5.1 tests
--echo #
diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test
index 19f7cbe40a1..82097c53fe0 100644
--- a/mysql-test/t/group_min_max.test
+++ b/mysql-test/t/group_min_max.test
@@ -1204,6 +1204,64 @@ drop table t1;
--echo End of 5.1 tests
+--echo #
+--echo # MDEV-765 lp:825075 - Wrong result with GROUP BY + multipart key + MIN/MAX loose scan
+--echo #
+
+CREATE TABLE t1 (a varchar(1), b varchar(1), KEY (b,a));
+INSERT INTO t1 VALUES
+('0',NULL),('9',NULL),('8','c'),('4','d'),('7','d'),(NULL,'f'),
+('7','f'),('8','g'),(NULL,'j');
+
+explain
+SELECT max(a) , b FROM t1 WHERE a IS NULL OR b = 'z' GROUP BY b;
+SELECT max(a) , b FROM t1 WHERE a IS NULL OR b = 'z' GROUP BY b;
+
+explain
+SELECT b, min(a) FROM t1 WHERE a = '7' OR b = 'z' GROUP BY b;
+SELECT b, min(a) FROM t1 WHERE a = '7' OR b = 'z' GROUP BY b;
+
+explain
+SELECT b, min(a) FROM t1 WHERE (a = b OR b = 'd' OR b is NULL) GROUP BY b;
+SELECT b, min(a) FROM t1 WHERE (a = b OR b = 'd' OR b is NULL) GROUP BY b;
+
+explain
+SELECT b, min(a) FROM t1 WHERE a > ('0' = b) AND b = 'z' GROUP BY b;
+SELECT b, min(a) FROM t1 WHERE a > ('0' = b) AND b = 'z' GROUP BY b;
+
+explain
+SELECT b, min(a) FROM t1 WHERE a > '0' AND (b < (a = '7')) GROUP BY b;
+SELECT b, min(a) FROM t1 WHERE a > '0' AND (b < (a = '7')) GROUP BY b;
+
+explain
+SELECT b, min(a) FROM t1 WHERE (a > '0' AND (a > '1' OR b = 'd')) GROUP BY b;
+SELECT b, min(a) FROM t1 WHERE (a > '0' AND (a > '1' OR b = 'd')) GROUP BY b;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-4140 Wrong result with GROUP BY + multipart key + MIN/MAX loose scan and a subquery
+--echo #
+
+CREATE TABLE t1 (a int, b int, KEY (b, a)) ;
+INSERT INTO t1 VALUES (0,99),(9,99),(4,0),(7,0),(99,0),(7,0),(8,0),(99,0),(1,0);
+CREATE TABLE t2 (c int) ;
+INSERT INTO t2 VALUES (0),(1);
+
+EXPLAIN
+SELECT MIN(a), b FROM t1 WHERE a > 0 GROUP BY b;
+SELECT MIN(a), b FROM t1 WHERE a > 0 GROUP BY b;
+EXPLAIN
+SELECT MIN(a), b FROM t1 WHERE a > ( SELECT c FROM t2 WHERE c = 0 ) GROUP BY b;
+SELECT MIN(a), b FROM t1 WHERE a > ( SELECT c FROM t2 WHERE c = 0 ) GROUP BY b;
+# this test is for 5.5 to ensure that the subquery is expensive
+EXPLAIN
+SELECT MIN(a), b FROM t1 WHERE a > ( SELECT min(c) FROM t2, t1 t1a, t1 t1b WHERE c = 0 ) GROUP BY b;
+SELECT MIN(a), b FROM t1 WHERE a > ( SELECT min(c) FROM t2, t1 t1a, t1 t1b WHERE c = 0 ) GROUP BY b;
+
+drop table t1, t2;
+
+--echo End of 5.3 tests
--echo #
--echo # WL#3220 (Loose index scan for COUNT DISTINCT)
@@ -1342,4 +1400,3 @@ explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
drop table t1;
--echo # End of test#50539.
-
diff --git a/mysql-test/t/information_schema_all_engines-master.opt b/mysql-test/t/information_schema_all_engines-master.opt
index 085c81d34bb..0a9fa574e49 100644
--- a/mysql-test/t/information_schema_all_engines-master.opt
+++ b/mysql-test/t/information_schema_all_engines-master.opt
@@ -2,9 +2,10 @@
--loose-innodb-buffer-pool-pages
--loose-innodb-buffer-pool-pages-blob
--loose-innodb-buffer-pool-pages-index
+--loose-innodb-changed-pages
--loose-innodb-cmp
---loose-innodb-cmpmem-reset
--loose-innodb-cmp-reset
+--loose-innodb-cmpmem-reset
--loose-innodb-index-stats
--loose-innodb-lock-waits
--loose-innodb-rseg
diff --git a/mysql-test/t/information_schema_all_engines.test b/mysql-test/t/information_schema_all_engines.test
index 553367d2b9a..73ed00376ab 100644
--- a/mysql-test/t/information_schema_all_engines.test
+++ b/mysql-test/t/information_schema_all_engines.test
@@ -49,7 +49,7 @@ SELECT t.table_name, c1.column_name
#
# Bug#24630 Subselect query crashes mysqld
#
-select 1 as f1 from information_schema.tables where "CHARACTER_SETS"=
+select 1 as f1 from information_schema.tables where "ALL_PLUGINS"=
(select cast(table_name as char) from information_schema.tables
order by table_name limit 1) limit 1;
diff --git a/mysql-test/t/innodb_ext_key.test b/mysql-test/t/innodb_ext_key.test
index 3e82403ddb5..31c6fca2b95 100644
--- a/mysql-test/t/innodb_ext_key.test
+++ b/mysql-test/t/innodb_ext_key.test
@@ -414,6 +414,7 @@ INSERT INTO t1 (a) VALUES (4), (6);
INSERT INTO t2 (b) VALUES (0), (8);
set @save_optimizer_switch=@@optimizer_switch;
+set @save_join_cache_level=@@join_cache_level;
SET join_cache_level=3;
SET optimizer_switch='join_cache_hashed=on';
@@ -424,6 +425,7 @@ EXPLAIN
SELECT * FROM t1, t2 WHERE b=a;
SELECT * FROM t1, t2 WHERE b=a;
+set join_cache_level=@save_join_cache_level;
set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1,t2;
@@ -466,6 +468,78 @@ set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1;
+--echo #
+--echo # Bug mdev-4220: using ref instead of eq_ref
+--echo # with extended_keys=on
+--echo # (performance regression introduced in the patch for mdev-3851)
+--echo #
+
+set @save_optimizer_switch=@@optimizer_switch;
+
+create table t1 (a int not null) engine=innodb;
+
+insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t2 (
+ pk int primary key, a int not null, b int, unique(a)
+)engine=innodb;
+
+insert into t2
+select
+ A.a + 10 * B.a, A.a + 10 * B.a, A.a + 10 * B.a
+from t1 A, t1 B;
+
+set optimizer_switch='extended_keys=off';
+explain
+select * from t1, t2 where t2.a=t1.a and t2.b < 2;
+flush status;
+select * from t1, t2 where t2.a=t1.a and t2.b < 2;
+show status like 'handler_read%';
+
+set optimizer_switch='extended_keys=on';
+explain
+select * from t1, t2 where t2.a=t1.a and t2.b < 2;
+flush status;
+select * from t1, t2 where t2.a=t1.a and t2.b < 2;
+show status like 'handler_read%';
+
+drop table t1,t2;
+
+# this test case did not demonstrate any regression
+# it is added for better testing
+
+create table t1(a int) engine=myisam;
+insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t2(a int) engine=myisam;
+insert into t2 select A.a + 10*B.a + 100*C.a from t1 A, t1 B, t1 C;
+
+create table t3 (
+ pk1 int not null, pk2 int not null, col1 int not null, col2 int not null)
+engine=innodb;
+insert into t3 select a,a,a,a from t2;
+alter table t3 add primary key (pk1, pk2);
+alter table t3 add key (col1, col2);
+
+set optimizer_switch='extended_keys=off';
+--replace_column 9 #
+explain
+select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a;
+--replace_column 9 #
+explain
+select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a and t3.pk1=t1.a;
+
+set optimizer_switch='extended_keys=on';
+--replace_column 9 #
+explain
+select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a;
+--replace_column 9 #
+explain
+select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a and t3.pk1=t1.a;
+
+drop table t1,t2,t3;
+
+set optimizer_switch=@save_optimizer_switch;
+
set optimizer_switch=@save_ext_key_optimizer_switch;
SET SESSION STORAGE_ENGINE=DEFAULT;
-
diff --git a/mysql-test/t/join.test b/mysql-test/t/join.test
index 907d39e95fe..33289f77c13 100644
--- a/mysql-test/t/join.test
+++ b/mysql-test/t/join.test
@@ -1136,3 +1136,29 @@ SET optimizer_switch=@tmp_optimizer_switch;
DROP TABLE t1,t2,t3,t4,t5;
SET optimizer_switch=@save_optimizer_switch;
+
+--echo #
+--echo # Bug #35268: Parser can't handle STRAIGHT_JOIN with USING
+--echo #
+
+CREATE TABLE t1 (a int);
+
+INSERT INTO t1 (a) VALUES (1),(2),(3),(4),(5),(6),(7),(8);
+
+CREATE TABLE t2 (a int);
+
+INSERT INTO t2 (a) VALUES (1),(2),(3),(4);
+
+EXPLAIN
+SELECT t1.a FROM t1 NATURAL INNER JOIN t2 ORDER BY t1.a;
+SELECT t1.a FROM t1 NATURAL INNER JOIN t2 ORDER BY t1.a;
+
+EXPLAIN
+SELECT t1.a FROM t1 STRAIGHT_JOIN t2 USING(a) ORDER BY t1.a;
+SELECT t1.a FROM t1 STRAIGHT_JOIN t2 USING(a) ORDER BY t1.a;
+
+EXPLAIN
+SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a;
+SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a;
+
+DROP TABLE t1,t2;
diff --git a/mysql-test/t/join_cache.test b/mysql-test/t/join_cache.test
index 9b04c264faf..2d06c3e2a30 100644
--- a/mysql-test/t/join_cache.test
+++ b/mysql-test/t/join_cache.test
@@ -3594,7 +3594,7 @@ DROP TABLE t1,t2,t3;
CREATE TABLE t1 (
col269 decimal(31,10) unsigned DEFAULT NULL,
- col280 multipoint DEFAULT NULL,
+ col280 geometry DEFAULT NULL,
col281 tinyint(1) DEFAULT NULL,
col282 time NOT NULL,
col284 datetime DEFAULT NULL,
diff --git a/mysql-test/t/join_outer_innodb.test b/mysql-test/t/join_outer_innodb.test
index cca1dde481d..adb555d5f85 100644
--- a/mysql-test/t/join_outer_innodb.test
+++ b/mysql-test/t/join_outer_innodb.test
@@ -143,3 +143,210 @@ eval SELECT $rest_of_query;
eval EXPLAIN SELECT $rest_of_query;
drop table t1,t2,t3,t4,t5,t6;
+
+--echo #
+--echo Bug mdev-4318: view over a complex query with outer joins
+--echo #
+
+CREATE TABLE t1 (
+ a1 int NOT NULL, a2 int NOT NULL, a3 int DEFAULT NULL, a4 tinyint NOT NULL,
+ a5 int NOT NULL, a6 tinyint NOT NULL, a7 tinyint(4) DEFAULT NULL,
+ a8 smallint(6) DEFAULT NULL, a9 smallint(6) DEFAULT NULL, a10 tinyint NOT NULL,
+ PRIMARY KEY (a1), KEY a2 (a2), KEY a3 (a3), KEY a4 (a4), KEY a6 (a6),
+ KEY a5 (a5), KEY a7 (a7), KEY a8 (a8), KEY a9 (a9)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t1 VALUES
+ (3360,5684,2219,1,316832,1,0,NULL,NULL,NULL),
+ (3362,2754,597,2,316844,1,0,NULL,NULL,NULL),
+ (3363,369,NULL,1,317295,1,0,NULL,NULL,NULL);
+
+CREATE TABLE t2 (
+ b1 int NOT NULL, b2 int NOT NULL, PRIMARY KEY (b1,b2), KEY b2 (b2)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE t3 (
+ c1 int NOT NULL, PRIMARY KEY (c1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t3 VALUES
+ (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),
+ (1000),(1001),(1002),(1003),(9999);
+
+CREATE TABLE t4 (
+ d1 int NOT NULL, PRIMARY KEY (d1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t4 VALUES (5674),(5676),(5680),(5684),(5685);
+
+CREATE TABLE t5 (
+ e1 int NOT NULL, e2 varchar(64) NOT NULL, PRIMARY KEY (e1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t5 VALUES
+ (5684,'51a5de7a9f56314e082094d78f58be082c3cf0c1'),
+ (5685,'754dc8292cb9f5eb9ade126fe7e961c62412a349'),
+ (5686,'75eeb33f1c819bac21f6d023b4c5b24185eeda5c');
+
+CREATE TABLE t6 (
+ f1 int NOT NULL, PRIMARY KEY (f1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t6 VALUES (5542),(5620),(5686);
+
+CREATE TABLE t7 (
+ g1 tinyint NOT NULL DEFAULT '0', g2 varchar(20) NOT NULL, PRIMARY KEY (g1)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t7 VALUES
+ (1,'60feec2b20ed19f55ad0'),(3,'9ddb18bff7fcbd1e3133'),
+ (5,'a05599df9222bb160d11'),(7,'e31bae372f7d01df0589'),
+ (9,'8f8372dd7fc8eb46c8a3'),(11,'f8d0e28529e990a09309');
+
+CREATE TABLE t8 (
+ h1 tinyint NOT NULL, h2 varchar(128) DEFAULT NULL, PRIMARY KEY (h1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t8 VALUES (1,'b'),(2,'c'),(3,'d'),(4,'e');
+
+CREATE TABLE t9 (
+ i1 tinyint NOT NULL, i2 varchar(7) NOT NULL, i3 varchar(128) NOT NULL,
+ PRIMARY KEY (i1,i2), KEY i2 (i2), KEY i3 (i3)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t9 VALUES
+ (2,'a','07630d223c7e5f7b1feb19b3caafb0833fd028eb'),
+ (3,'b','1ca53dcc50b68af86f4b1b4676dbed917b543c30'),
+ (1,'b','2c01ac36c1ce9a7de66be89f85d8aa5f0052e2e8'),
+ (4,'a','496c486b3a9edc439477fef7d34cbefdebba86df'),
+ (3,'a','98bf72d8d467201058a5f69bd7709bfc74a8637e'),
+ (2,'b','9a45425f6160fb59d7f8a02c721498d4ce945302'),
+ (4,'b','9c9a7300f3e708f8e430f9f3376d966f5951f583'),
+ (1,'a','c0af3f076b905f31cbb51af304b9c7ad539e0861');
+
+CREATE TABLE t10 (
+ j1 tinyint NOT NULL, j2 varchar(20) NOT NULL, PRIMARY KEY (j1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t10 VALUES (1,'b'),(2,'c'),(3,'d');
+
+CREATE TABLE t11 (
+ k1 int NOT NULL, k2 datetime DEFAULT NULL, k3 int DEFAULT NULL,
+ k4 int DEFAULT NULL, PRIMARY KEY (k1), KEY k3 (k3), KEY k4 (k4)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t11 VALUES
+ (317422,'2013-03-18 11:43:03',1,NULL),(317423,'2013-03-18 11:43:11',1,NULL),
+ (317424,'2013-03-18 11:52:01',1,1),(317425,'2013-03-18 11:52:01',1,1),
+ (317426,'2013-03-18 11:56:38',1,1),(317427,'2013-03-18 12:18:25',1,NULL),
+ (317428,'2013-03-18 12:46:28',1,NULL),(317429,'2013-03-18 12:46:28',1,NULL),
+ (317430,'2013-03-18 12:46:28',1,NULL),(317431,'2013-03-18 12:46:28',1,NULL),
+ (317432,'2013-03-18 12:46:28',1,NULL),(317433,'2013-03-18 12:46:28',1,NULL),
+ (317434,'2013-03-18 12:46:28',1,NULL),(317435,'2013-03-18 12:46:28',1,NULL),
+ (317436,'2013-03-18 12:46:28',1,NULL),(317437,'2013-03-18 12:46:28',1,NULL),
+ (317438,'2013-03-18 12:46:28',1,NULL),(317439,'2013-03-18 12:46:28',1,NULL),
+ (317440,'2013-03-18 12:55:20',1,NULL),(317441,'2013-03-18 12:58:29',1,NULL),
+ (317442,'2013-03-18 13:06:02',1,NULL),(317443,'2013-03-18 15:23:18',21,NULL);
+
+CREATE TABLE t12 (
+ l1 int NOT NULL, l2 varchar(64) NOT NULL, PRIMARY KEY (l1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t12 VALUES
+ (552,'59a498252ef59f96fbdc13a414abe244d8e8bc30'),
+ (554,'c6025c7cb2d9dfb1be7ce4a61f35b45bb9e61ba3'),
+ (555,'b245bcc672082bb6d10794b2b4ac972dd14b1cf5');
+
+CREATE TABLE t13 (
+ m1 int NOT NULL, m2 int NOT NULL, m3 int NOT NULL,
+ PRIMARY KEY (m1,m2,m3), KEY m3 (m3), KEY m2 (m2)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t13 VALUES (3324,43,4),(3332,263,1),(3348,27,3);
+
+CREATE TABLE t14 (
+ n1 smallint NOT NULL, n2 varchar(64) NOT NULL, PRIMARY KEY (n1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t14 VALUES
+ (21,'685bf7ca576af964c7cff564d5e4473b81499b8b'),
+ (23,'b8e42dab1ab952406b3accfb47089c61478138a8'),
+ (25,'3fea441e411db8c70bf039b50c8f18f59515be53'),
+ (27,'998aecc30fd0e0b8a1cac6590e5eccc2d7822223');
+
+CREATE TABLE t15 (
+ o1 smallint NOT NULL, PRIMARY KEY (o1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t15 VALUES (1),(3);
+
+CREATE TABLE t16 (
+ p1 smallint NOT NULL, p2 varchar(7) NOT NULL, p3 varchar(64) NOT NULL,
+ PRIMARY KEY (p1,p2)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO t16 VALUES
+ (1,'a','66bdbb389456f3ae97206da115a7b397c31400e8'),
+ (1,'b','66bdbb389456f3ae97206da115a7b397c31400e8'),
+ (3,'a','386c10e454278c6e27feb16258089166422f79b4'),
+ (3,'b','386c10e454278c6e27feb16258089166422f79b4');
+
+let $Q=
+select t3.c1,t5.e2,t1.a1,t14.n2,t16.p3,t10.j2,t7.g2,t11.k2,l3.l2,
+ t9.i3,t12.l2 AS l_l2,l2.l2 AS l2_l2,l4.l1 AS l4_l1,t6.f1
+from
+(
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ (
+ t1
+ left join t2 on t1.a1 = t2.b1
+ )
+ left join t3 on t2.b2 = t3.c1
+ )
+ left join t4 on t1.a2 = t4.d1
+ )
+ left join t5 on t4.d1 = t5.e1
+ )
+ left join t6 on t1.a3 = t6.f1
+ )
+ left join t5 e2 on t6.f1 = e2.e1
+ )
+ join t7 on t1.a7 = t7.g1
+ )
+ join t8 on t1.a4 = t8.h1
+ )
+ join t9 on t8.h1 = t9.i1
+ )
+ join t10 on t1.a6 = t10.j1
+ )
+ join t11 on t1.a5 = t11.k1
+ )
+ left join t12 on t11.k3 = t12.l1
+ )
+ left join t12 l2 on t11.k4 = l2.l1
+ )
+ left join t13 on t1.a1 = t13.m1 and t13.m3 = 4
+ )
+ left join t12 l4 on l4.l1 = t13.m2
+ )
+ left join t13 m2 on t1.a1 = m2.m1 and m2.m3 = 3
+ )
+ left join t12 l3 on l3.l1 = m2.m2
+ )
+ left join t14 on t1.a8 = t14.n1
+ )
+ left join t15 on t1.a9 = t15.o1
+)
+left join t16 on t15.o1 = t16.p1
+where t1.a10 = 1;
+
+eval create view v1 as $Q;
+
+eval explain $Q;
+
+explain select * from v1;
+
+drop view v1;
+
+drop table t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16;
diff --git a/mysql-test/t/keywords.test b/mysql-test/t/keywords.test
index 08016313ca7..54052e65014 100644
--- a/mysql-test/t/keywords.test
+++ b/mysql-test/t/keywords.test
@@ -162,3 +162,14 @@ call p2();
DROP PROCEDURE p1;
DROP PROCEDURE p2;
DROP TABLE t1;
+
+#
+# OPTION is not anymore a keyword
+#
+
+create table option (option int not null);
+drop table option;
+--error 1193
+set option=1;
+--error 1193
+set option option=1;
diff --git a/mysql-test/t/mdl_sync.test b/mysql-test/t/mdl_sync.test
index 197cad536e4..fef8a9848ca 100644
--- a/mysql-test/t/mdl_sync.test
+++ b/mysql-test/t/mdl_sync.test
@@ -4382,7 +4382,7 @@ connection default;
--echo # Connection con2
connection con2;
--echo # Reaping: RENAME TABLE db1.t1 TO test.t1
---error ER_FILE_NOT_FOUND, ER_FILE_NOT_FOUND
+--error ER_NO_SUCH_TABLE
--reap
--echo # Connection default
diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test
index 4066fcb264b..7e198275730 100644
--- a/mysql-test/t/merge.test
+++ b/mysql-test/t/merge.test
@@ -226,19 +226,19 @@ drop table t3,t1,t2;
#
# temporary merge tables
#
-CREATE TABLE t1 (c1 INT NOT NULL);
-CREATE TABLE t2 (c1 INT NOT NULL);
-INSERT INTO t1 VALUES (1);
-INSERT INTO t2 VALUES (2);
-CREATE TEMPORARY TABLE t3 (c1 INT NOT NULL) ENGINE=MRG_MYISAM UNION=(t1,t2);
-SELECT * FROM t3;
-CREATE TEMPORARY TABLE t4 (c1 INT NOT NULL);
-CREATE TEMPORARY TABLE t5 (c1 INT NOT NULL);
-INSERT INTO t4 VALUES (4);
-INSERT INTO t5 VALUES (5);
-CREATE TEMPORARY TABLE t6 (c1 INT NOT NULL) ENGINE=MRG_MYISAM UNION=(t4,t5);
-SELECT * FROM t6;
-DROP TABLE t6, t3, t1, t2, t4, t5;
+create table t1 (a int not null);
+create table t2 (a int not null);
+insert into t1 values (1);
+insert into t2 values (2);
+create temporary table t3 (a int not null) ENGINE=MERGE UNION=(t1,t2);
+select * from t3;
+create temporary table t4 (a int not null);
+create temporary table t5 (a int not null);
+insert into t4 values (1);
+insert into t5 values (2);
+create temporary table t6 (a int not null) ENGINE=MERGE UNION=(t4,t5);
+select * from t6;
+drop table t6, t3, t1, t2, t4, t5;
#
# Bug#19627 - temporary merge table locking
# MERGE table and its children must match in temporary type.
@@ -622,14 +622,6 @@ SHOW CREATE TABLE m1;
DROP TABLE t1, m1;
#
-# BUG#35274 - merge table doesn't need any base tables, gives error 124 when
-# key accessed
-#
-CREATE TABLE t1(a INT, KEY(a)) ENGINE=merge;
-SELECT MAX(a) FROM t1;
-DROP TABLE t1;
-
-#
# BUG#32047 - 'Spurious' errors while opening MERGE tables
#
CREATE TABLE t1(a INT);
@@ -1306,9 +1298,9 @@ DROP TABLE t1, t2, t3;
# Truncate failed with error message when table was in use by MERGE.
#
# Show that truncate of child table after use of parent table works.
-CREATE TABLE t1 (c1 INT) ENGINE=MyISAM;
-CREATE TABLE t2 (c1 INT) ENGINE=MyISAM;
-CREATE TABLE t3 (c1 INT) ENGINE=MRG_MYISAM UNION=(t1,t2);
+CREATE TABLE t1 (c1 INT) ENGINE= MyISAM;
+CREATE TABLE t2 (c1 INT) ENGINE= MyISAM;
+CREATE TABLE t3 (c1 INT) ENGINE= MRG_MYISAM UNION= (t1, t2);
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (2);
SELECT * FROM t3;
@@ -1840,6 +1832,51 @@ DROP TABLE m1, t1;
--echo End of 5.1 tests
+--echo #
+--echo # MDEV-4277: Crash inside mi_killed_in_mariadb() with myisammrg
+--echo #
+create table t1 (a int);
+insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t2 ( i int ) engine=myisam;
+insert into t2 values (1),(2);
+
+create table t3 (a int, b int, filler char(100), key(a), key(b)) engine=myisam;
+create table t4 like t3;
+insert into t3
+ select A.a+10*B.a+100*C.a,
+ A.a+10*B.a+100*C.a,
+ 'filler-data-FILLER-DATA-qqq'
+ from t1 A, t1 B, t1 C where C.a < 5;
+insert into t4
+ select A.a+10*B.a+100*C.a,
+ A.a+10*B.a+100*C.a,
+ 'filler-data-FILLER-DATA-qqq'
+ from t1 A, t1 B, t1 C where C.a >= 5;
+
+create table t5 like t3;
+alter table t5 engine=merge;
+alter table t5 union(t3, t4);
+
+update t5 set b=999, a=999 where b>950;
+
+explain
+select * from t2, t5 where t5.a=999 and t5.b=999;
+select * from t2, t5 where t5.a=999 and t5.b=999;
+
+drop table t5;
+drop table t1,t2,t3,t4;
+
+--echo End of 5.3 tests
+
+#
+# BUG#35274 - merge table doesn't need any base tables, gives error 124 when
+# key accessed
+#
+CREATE TABLE t1(a INT, KEY(a)) ENGINE=merge;
+SELECT MAX(a) FROM t1;
+DROP TABLE t1;
+
--echo #
--echo # An additional test case for Bug#27430 Crash in subquery code
--echo # when in PS and table DDL changed after PREPARE
@@ -2845,3 +2882,4 @@ eval set global storage_engine=$default;
# Check that all connections opened by test cases in this file are really
# gone so execution of other tests won't be affected by their presence.
--source include/wait_until_count_sessions.inc
+
diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test
index 48735304aad..e0a35ca2bb9 100644
--- a/mysql-test/t/multi_update.test
+++ b/mysql-test/t/multi_update.test
@@ -696,6 +696,55 @@ DROP FUNCTION f1;
DROP TABLE t1;
--echo #
+--echo # MDEV-4123: Incorrect results after multi-table update or
+--echo # assertion `!table || (!table->read_set ||
+--echo # bitmap_is_set(table->read_set, field_index))' failure
+--echo #
+
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (
+ id int(10) unsigned NOT NULL,
+ level tinyint(3) unsigned NOT NULL,
+ PRIMARY KEY (id)
+);
+INSERT INTO t1 VALUES (2519583,1);
+
+DROP TABLE IF EXISTS t2;
+CREATE TABLE t2 (
+ club_id int(11) NOT NULL DEFAULT '0',
+ profile_id int(11) NOT NULL DEFAULT '0',
+ member_level_id int(11) NOT NULL DEFAULT '0',
+ PRIMARY KEY (profile_id,club_id)
+);
+INSERT INTO t2 VALUES (2,2519583,12);
+
+DROP TABLE IF EXISTS t3;
+CREATE TABLE t3 (
+ member_level_id int(11) unsigned NOT NULL DEFAULT '0',
+ map_level int(11) unsigned NOT NULL DEFAULT '0',
+ map_status int(11) unsigned NOT NULL DEFAULT '0',
+ PRIMARY KEY (member_level_id)
+);
+INSERT INTO t3 VALUES (12,12,1);
+
+CREATE
+ VIEW v1 AS
+ select club_id,profile_id,
+ map_level AS member_level_id,map_status AS member_status
+ from (t2 tc join t3 map
+ on(((tc.member_level_id = map.member_level_id) and
+ (club_id = 2))));
+
+select level, count(*) as cnt from t1 group by level;
+UPDATE t1 c LEFT JOIN v1 t ON (c.id = t.profile_id AND t.club_id = 2)
+ SET c.level = IF (t.member_status IS NULL, 1, IF (t.member_status = 1, 2,3));
+select level, count(*) as cnt from t1 group by level;
+drop view v1;
+drop table t1,t2,t3;
+
+--echo end of tests
+
+--echo #
--echo # BUG#57373: Multi update+InnoDB reports ER_KEY_NOT_FOUND if a
--echo # table is updated twice
--echo #
@@ -759,6 +808,5 @@ SELECT * FROM t2;
DROP TABLE t1,t2;
-
-
+--echo end of 5.5 tests
diff --git a/mysql-test/t/myisam-metadata.test b/mysql-test/t/myisam-metadata.test
new file mode 100644
index 00000000000..c5327aa3a71
--- /dev/null
+++ b/mysql-test/t/myisam-metadata.test
@@ -0,0 +1,49 @@
+#
+# Test bugs in MyISAM that may cause problems for metadata
+#
+
+--source include/big_test.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+#
+# LP:989055 - Querying myisam table metadata may corrupt the table
+#
+
+CREATE TABLE t1 (
+ id INT PRIMARY KEY,
+ a VARCHAR(100),
+ INDEX(a)
+) ENGINE=MyISAM;
+ALTER TABLE t1 DISABLE KEYS;
+
+let $1=100000;
+--disable_query_log
+while ($1)
+{
+ eval insert into t1 values($1, "line number $1");
+ dec $1;
+}
+--enable_query_log
+
+--connect(con1,localhost,root,,)
+--send
+ ALTER TABLE t1 ENABLE KEYS;
+
+--connection default
+--let $wait_timeout=10
+--let $show_statement= SHOW PROCESSLIST
+--let $field= State
+--let $condition= = 'Repair by sorting'
+--source include/wait_show_condition.inc
+
+--replace_column 7 # 8 # 9 # 12 # 13 # 14 #
+SHOW TABLE STATUS LIKE 't1';
+
+--connection con1
+--reap
+--connection default
+--disconnect con1
+DROP TABLE t1;
diff --git a/mysql-test/t/myisam-system.test b/mysql-test/t/myisam-system.test
index d908e639a4e..cece33bb00b 100644
--- a/mysql-test/t/myisam-system.test
+++ b/mysql-test/t/myisam-system.test
@@ -9,14 +9,21 @@ drop table if exists t1,t2;
create table t1 (a int) engine=myisam;
let $MYSQLD_DATADIR= `select @@datadir`;
--remove_file $MYSQLD_DATADIR/test/t1.MYI
+--replace_result $MYSQLD_DATADIR ./
drop table if exists t1;
create table t1 (a int) engine=myisam;
--remove_file $MYSQLD_DATADIR/test/t1.MYI
---error ER_BAD_TABLE_ERROR,6
+--replace_result $MYSQLD_DATADIR ./
+--error ER_FILE_NOT_FOUND
+select * from t1;
+--replace_result $MYSQLD_DATADIR ./
drop table t1;
create table t1 (a int) engine=myisam;
--remove_file $MYSQLD_DATADIR/test/t1.MYD
---error ER_BAD_TABLE_ERROR,6,29
+--replace_result $MYSQLD_DATADIR ./
+--error 29
+select * from t1;
+--replace_result $MYSQLD_DATADIR ./
drop table t1;
--error ER_BAD_TABLE_ERROR
drop table t1;
diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test
index 4199d98073c..8323890b028 100644
--- a/mysql-test/t/myisam.test
+++ b/mysql-test/t/myisam.test
@@ -1536,10 +1536,10 @@ drop table t1;
#
CREATE TABLE t1 (line LINESTRING NOT NULL) engine=myisam;
-INSERT INTO t1 VALUES (GeomFromText("POINT(0 0)"));
+INSERT INTO t1 VALUES (GeomFromText("LINESTRING(0 0)"));
checksum table t1;
CREATE TABLE t2 (line LINESTRING NOT NULL) engine=myisam;
-INSERT INTO t2 VALUES (GeomFromText("POINT(0 0)"));
+INSERT INTO t2 VALUES (GeomFromText("LINESTRING(0 0)"));
checksum table t2;
CREATE TABLE t3 select * from t1;
checksum table t3;
@@ -1582,22 +1582,6 @@ SELECT h+0, d + 0, e, g + 0 FROM t1;
DROP TABLE t1;
---echo #
---echo # Test of BUG#35570 CHECKSUM TABLE unreliable if LINESTRING field
---echo # (same content / differen checksum)
---echo #
-
-CREATE TABLE t1 (line LINESTRING NOT NULL) engine=myisam;
-INSERT INTO t1 VALUES (GeomFromText("POINT(0 0)"));
-checksum table t1;
-CREATE TABLE t2 (line LINESTRING NOT NULL) engine=myisam;
-INSERT INTO t2 VALUES (GeomFromText("POINT(0 0)"));
-checksum table t2;
-CREATE TABLE t3 select * from t1;
-checksum table t3;
-drop table t1,t2,t3;
-
-
#
# BUG#47073 - valgrind errs, corruption,failed repair of partition,
# low myisam_sort_buffer_size
diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test
index 71a985654ef..662cd4c7c0c 100644
--- a/mysql-test/t/mysql.test
+++ b/mysql-test/t/mysql.test
@@ -593,6 +593,15 @@ create database `aa``bb````cc`;
--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/backticks.sql
drop database `aa``bb````cc`;
+#
+# MySQL Bug#13639125 DELIMITER STRIPS THE NEXT NEW LINE IN A SQL STATEMENT
+#
+--write_file $MYSQLTEST_VARDIR/tmp/13639125.sql
+select ">>
+delimiter
+<<" as a;
+EOF
+--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/13639125.sql
--echo
--echo End of tests
diff --git a/mysql-test/t/mysql_client_test.test b/mysql-test/t/mysql_client_test.test
index 90da022fb38..bf5331ca4f9 100644
--- a/mysql-test/t/mysql_client_test.test
+++ b/mysql-test/t/mysql_client_test.test
@@ -6,6 +6,8 @@
SET @old_general_log= @@global.general_log;
SET @old_slow_query_log= @@global.slow_query_log;
+call mtr.add_suppression(" Error reading file './client_test_db/test_frm_bug.frm'");
+
# We run with different binaries for normal and --embedded-server
#
# If this test fails with "command "$MYSQL_CLIENT_TEST" failed",
diff --git a/mysql-test/t/mysql_client_test_nonblock.test b/mysql-test/t/mysql_client_test_nonblock.test
index fc2e0b1d01b..51263854e58 100644
--- a/mysql-test/t/mysql_client_test_nonblock.test
+++ b/mysql-test/t/mysql_client_test_nonblock.test
@@ -5,6 +5,7 @@
SET @old_general_log= @@global.general_log;
SET @old_slow_query_log= @@global.slow_query_log;
+call mtr.add_suppression(" Error reading file './client_test_db/test_frm_bug.frm'");
# We run with different binaries for normal and --embedded-server
#
diff --git a/mysql-test/t/mysqlcheck.test b/mysql-test/t/mysqlcheck.test
index c0025f9e742..06d702495c2 100644
--- a/mysql-test/t/mysqlcheck.test
+++ b/mysql-test/t/mysqlcheck.test
@@ -93,6 +93,7 @@ drop view v1;
# Bug#37527: mysqlcheck fails to report entire database
# when frm file corruption
#
+call mtr.add_suppression("Error reading file './test/t1.frm'");
CREATE TABLE t1(a INT) engine=myisam;
CREATE TABLE t2(a INT) engine=myisam;
# backup then null t1.frm
diff --git a/mysql-test/t/mysqld--help.test b/mysql-test/t/mysqld--help.test
index 806e6f7f8d1..0f3df10ea70 100644
--- a/mysql-test/t/mysqld--help.test
+++ b/mysql-test/t/mysqld--help.test
@@ -20,11 +20,14 @@ perl;
# their paths may vary:
@skipvars=qw/basedir open-files-limit general-log-file log plugin-dir
log-slow-queries pid-file slow-query-log-file log-basename
- datadir slave-load-tmpdir tmpdir socket/;
+ datadir slave-load-tmpdir tmpdir socket thread-pool-size/;
# Plugins which may or may not be there:
- @plugins=qw/innodb ndb archive blackhole federated partition ndbcluster feedback debug temp-pool ssl des-key-file
- xtradb thread-concurrency super-large-pages mutex-deadlock-detector null-audit maria aria pbxt oqgraph sphinx thread-handling thread-pool/;
+ @plugins=qw/innodb ndb archive blackhole federated partition ndbcluster
+ feedback debug temp-pool ssl des-key-file xtradb sequence
+ thread-concurrency super-large-pages mutex-deadlock-detector
+ null-audit aria pbxt oqgraph sphinx thread-handling
+ test-sql-discovery rpl-semi-sync query-cache-info/;
# And substitute the content some environment variables with their
# names:
diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test
index 038907702d5..bad59ff09c3 100644
--- a/mysql-test/t/partition.test
+++ b/mysql-test/t/partition.test
@@ -2494,3 +2494,31 @@ INSERT INTO t1 VALUES (1),(2),(2),(3),(4);
ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
SELECT * from t1 order by i;
DROP TABLE t1;
+
+#
+# Test ALTER TABLE ADD/DROP PARTITION IF EXISTS
+#
+
+CREATE TABLE t1 ( d DATE NOT NULL)
+PARTITION BY RANGE( YEAR(d) ) (
+ PARTITION p0 VALUES LESS THAN (1960),
+ PARTITION p1 VALUES LESS THAN (1970),
+ PARTITION p2 VALUES LESS THAN (1980),
+ PARTITION p3 VALUES LESS THAN (1990)
+);
+
+ALTER TABLE t1 ADD PARTITION IF NOT EXISTS(
+PARTITION `p5` VALUES LESS THAN (2010)
+COMMENT 'APSTART \' APEND'
+);
+
+ALTER TABLE t1 ADD PARTITION IF NOT EXISTS(
+PARTITION `p5` VALUES LESS THAN (2010)
+COMMENT 'APSTART \' APEND'
+);
+
+alter table t1 drop partition if exists p5;
+alter table t1 drop partition if exists p5;
+
+DROP TABLE t1;
+
diff --git a/mysql-test/t/partition_debug_sync.test b/mysql-test/t/partition_debug_sync.test
index 027a4bd19a7..f8c00abafab 100644
--- a/mysql-test/t/partition_debug_sync.test
+++ b/mysql-test/t/partition_debug_sync.test
@@ -60,22 +60,19 @@ CREATE TABLE t2
b INTEGER NOT NULL,
KEY (b))
ENGINE = MYISAM
-/*!50100 PARTITION BY RANGE (a)
-(PARTITION p0 VALUES LESS THAN (2),
- PARTITION p1 VALUES LESS THAN (20),
- PARTITION p2 VALUES LESS THAN (100),
- PARTITION p3 VALUES LESS THAN MAXVALUE ) */;
+PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (2),
+ PARTITION p1 VALUES LESS THAN (20),
+ PARTITION p2 VALUES LESS THAN (100),
+ PARTITION p3 VALUES LESS THAN MAXVALUE);
SET DEBUG_SYNC= 'alter_table_before_open_tables SIGNAL removing_partitions WAIT_FOR waiting_for_alter';
SET DEBUG_SYNC= 'alter_table_before_rename_result_table WAIT_FOR delete_done';
--send ALTER TABLE t2 REMOVE PARTITIONING
connection default;
--echo # Con default
-SET SESSION debug_dbug= "+d,sleep_before_no_locks_delete_table";
SET DEBUG_SYNC= 'now WAIT_FOR removing_partitions';
SET DEBUG_SYNC= 'rm_table_no_locks_before_delete_table SIGNAL waiting_for_alter';
SET DEBUG_SYNC= 'rm_table_no_locks_before_binlog SIGNAL delete_done';
DROP TABLE IF EXISTS t2;
-SET SESSION debug_dbug= "-d,sleep_before_no_locks_delete_table";
--echo # Con 1
connection con1;
--error ER_NO_SUCH_TABLE
diff --git a/mysql-test/t/partition_disabled.test b/mysql-test/t/partition_disabled.test
index 320d6238502..798fb0aa59e 100644
--- a/mysql-test/t/partition_disabled.test
+++ b/mysql-test/t/partition_disabled.test
@@ -29,7 +29,9 @@ ALTER TABLE t1 ANALYZE PARTITION ALL;
ALTER TABLE t1 REBUILD PARTITION ALL;
ALTER TABLE t1 ENGINE Memory;
ALTER TABLE t1 ADD (new INT);
+--disable_warnings
DROP TABLE t1;
+--enable_warnings
--error ER_OPTION_PREVENTS_STATEMENT
CREATE TABLE t1 (
diff --git a/mysql-test/t/partition_not_windows.test b/mysql-test/t/partition_not_windows.test
index 333e12e2b16..429329c79bb 100644
--- a/mysql-test/t/partition_not_windows.test
+++ b/mysql-test/t/partition_not_windows.test
@@ -199,7 +199,7 @@ DROP TABLE example;
--rmdir $MYSQLTEST_VARDIR/p2Index
--rmdir $MYSQLTEST_VARDIR/p3Index
---error ER_CANT_CREATE_TABLE,1
+--error 1
CREATE TABLE `example` (
`ID_EXAMPLE` int(10) unsigned NOT NULL AUTO_INCREMENT,
`DESCRIPTION` varchar(30) NOT NULL,
diff --git a/mysql-test/t/partition_rename_longfilename.test b/mysql-test/t/partition_rename_longfilename.test
index 5e454f01da7..51d9c583f56 100644
--- a/mysql-test/t/partition_rename_longfilename.test
+++ b/mysql-test/t/partition_rename_longfilename.test
@@ -1,4 +1,5 @@
-- source include/not_windows.inc
+-- source include/support_long_file_names.inc
-- source include/have_partition.inc
-- source include/not_embedded.inc
--disable_warnings
diff --git a/mysql-test/t/plugin.test b/mysql-test/t/plugin.test
index 4412383f837..602b2e3c5c9 100644
--- a/mysql-test/t/plugin.test
+++ b/mysql-test/t/plugin.test
@@ -16,12 +16,13 @@ INSTALL SONAME 'ha_example';
--replace_regex /\.dll/.so/
--query_vertical select * from information_schema.plugins where plugin_library like 'ha_example%'
-CREATE TABLE t1(a int) ENGINE=EXAMPLE;
+CREATE TABLE t1 (a int) ENGINE=EXAMPLE;
+CREATE TABLE t2 (a int) ENGINE=EXAMPLE;
+FLUSH TABLES;
# Let's do some advanced ops with the example engine :)
SELECT * FROM t1;
-
# a couple of tests for variables
set global example_ulong_var=500;
set global example_enum_var= e1;
@@ -29,12 +30,26 @@ show status like 'example%';
show variables like 'example%';
UNINSTALL SONAME 'ha_example';
+
+# the engine is NOT uninstalled yet,
+# because the table `t1` is open, sitting in the table defintion cache
+
--replace_column 5 #
--replace_regex /\.dll/.so/
--query_vertical select * from information_schema.plugins where plugin_library like 'ha_example%'
-
DROP TABLE t1;
+# now the engine IS unloaded
+# and the table `t2` belongs to an unknown engine
+
+--replace_column 5 #
+--replace_regex /\.dll/.so/
+--query_vertical select * from information_schema.plugins where plugin_library like 'ha_example%'
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t2;
+DROP TABLE t2;
+
+
--error 1305
UNINSTALL PLUGIN EXAMPLE;
@@ -129,6 +144,7 @@ CREATE TABLE t1 (a int) ENGINE=example ULL=1e2;
CREATE TABLE t1 (a int) ENGINE=example ULL=0x1234;
SHOW CREATE TABLE t1;
+SET example_varopt_default=33; # does not affect varopt of t1
select create_options from information_schema.tables where table_schema='test' and table_name='t1';
@@ -137,6 +153,16 @@ SHOW CREATE TABLE t1;
DROP TABLE t1;
+create table t1 (a int) engine=example; # varopt is 10
+show create table t1;
+drop table t1;
+
+create table t1 (a int) engine=example varopt=15;
+show create table t1;
+alter table t1 varopt=default;
+show create table t1;
+drop table t1;
+
SET @@SQL_MODE=@OLD_SQL_MODE;
#
diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test
index 812b1b5ff94..22cad56a8e4 100644
--- a/mysql-test/t/ps_1general.test
+++ b/mysql-test/t/ps_1general.test
@@ -582,10 +582,7 @@ drop table t2;
# cases derived from client_test.c: test_rename()
prepare stmt1 from ' rename table t5 to t6, t7 to t8 ' ;
create table t5 (a int) ;
-# rename must fail, t7 does not exist
-# Clean up the filename here because embedded server reports whole path
---replace_result $MYSQLTEST_VARDIR . mysqld.1/data/ '' t7.frm t7
---error ER_FILE_NOT_FOUND
+--error ER_NO_SUCH_TABLE
execute stmt1 ;
create table t7 (a int) ;
# rename, t5 -> t6 and t7 -> t8
diff --git a/mysql-test/t/quick_select_4161.test b/mysql-test/t/quick_select_4161.test
new file mode 100644
index 00000000000..1e746754b41
--- /dev/null
+++ b/mysql-test/t/quick_select_4161.test
@@ -0,0 +1,53 @@
+#
+# MDEV-4161 Assertion `status_var.memory_used == 0' fails in virtual THD::~THD()
+#
+--source include/have_debug_sync.inc
+
+CREATE TABLE t1 (
+ event_date date DEFAULT '0000-00-00' NOT NULL,
+ type int(11) DEFAULT '0' NOT NULL,
+ event_id int(11) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (event_date,type,event_id)
+);
+
+INSERT INTO t1 VALUES ('1999-07-10',100100,24), ('1999-07-11',100100,25),
+('1999-07-13',100600,0), ('1999-07-13',100600,4), ('1999-07-13',100600,26),
+('1999-07-14',100600,10), ('1999-07-15',100600,16), ('1999-07-15',100800,45),
+('1999-07-15',101000,47), ('1999-07-16',100800,46), ('1999-07-20',100600,5),
+('1999-07-20',100600,27), ('1999-07-21',100600,11), ('1999-07-22',100600,17),
+('1999-07-23',100100,39), ('1999-07-24',100100,39), ('1999-07-24',100500,40),
+('1999-07-25',100100,39), ('1999-07-27',100600,1), ('1999-07-27',100600,6),
+('1999-07-27',100600,28), ('1999-07-28',100600,12), ('1999-07-29',100500,41),
+('1999-07-29',100600,18), ('1999-07-30',100500,41), ('1999-07-31',100500,41),
+('1999-08-01',100700,34), ('1999-08-03',100600,7), ('1999-08-03',100600,29),
+('1999-08-04',100600,13), ('1999-08-05',100500,42), ('1999-08-05',100600,19),
+('1999-08-06',100500,42), ('1999-08-07',100500,42), ('1999-08-08',100500,42),
+('1999-08-10',100600,2), ('1999-08-10',100600,9), ('1999-08-10',100600,30),
+('1999-08-11',100600,14), ('1999-08-12',100600,20), ('1999-08-17',100500,8),
+('1999-08-17',100600,31), ('1999-08-18',100600,15), ('1999-08-19',100600,22),
+('1999-08-24',100600,3), ('1999-08-24',100600,32), ('1999-08-27',100500,43),
+('1999-08-31',100600,33), ('1999-09-17',100100,37), ('1999-09-18',100100,37),
+('1999-09-19',100100,37), ('2000-12-18',100700,38);
+
+connect (killee, localhost, root);
+
+let $id=`select connection_id()`;
+
+set debug_sync='inside_make_join_statistics signal killme wait_for done';
+send select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date;
+
+connection default;
+set debug_sync='now wait_for killme';
+--replace_result $id %connection%
+eval kill $id;
+set debug_sync='now signal done';
+
+connection killee;
+--error 1053,1927,2006,2013
+reap;
+
+connection default;
+disconnect killee;
+
+drop table t1;
+
diff --git a/mysql-test/t/rename.test b/mysql-test/t/rename.test
index bb90cbafd74..a55bc845acc 100644
--- a/mysql-test/t/rename.test
+++ b/mysql-test/t/rename.test
@@ -21,16 +21,16 @@ rename table t3 to t4, t2 to t3, t1 to t2, t4 to t1;
select * from t1;
# The following should give errors
---error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
+--error ER_TABLE_EXISTS_ERROR
rename table t1 to t2;
---error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
+--error ER_TABLE_EXISTS_ERROR
rename table t1 to t1;
---error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
+--error ER_TABLE_EXISTS_ERROR
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t2;
show tables like "t_";
---error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
+--error ER_TABLE_EXISTS_ERROR
rename table t3 to t1, t2 to t3, t1 to t2, t4 to t1;
---error ER_FILE_NOT_FOUND,ER_FILE_NOT_FOUND
+--error ER_NO_SUCH_TABLE
rename table t3 to t4, t5 to t3, t1 to t2, t4 to t1;
select * from t1;
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index 44eaf7130a7..af507b1f7ef 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -4460,5 +4460,24 @@ INSERT INTO t2 VALUES (3),(4);
SELECT * FROM t1, t2 WHERE a=3 AND a=b;
drop table t1,t2;
+--echo #
+--echo # Bug mdev-4250: wrong transformation of WHERE condition with OR
+--echo #
+
+CREATE TABLE t1 (pk int PRIMARY KEY, a int);
+INSERT INTO t1 VALUES (3,0), (2,0), (4,1), (5,0), (1,0);
+
+SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
+
+DROP TABLE t1;
+
+SELECT * FROM mysql.time_zone
+WHERE ( NOT (Use_leap_seconds <= Use_leap_seconds AND Time_zone_id != 1)
+ AND Time_zone_id = Time_zone_id
+ OR Time_zone_id <> Time_zone_id )
+ AND Use_leap_seconds <> 'N';
+
--echo End of 5.3 tests
diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test
index c2edef87d41..32bf5417a0a 100644
--- a/mysql-test/t/show_check.test
+++ b/mysql-test/t/show_check.test
@@ -429,7 +429,9 @@ system echo "this is a junk file for test" >> $MYSQLD_DATADIR/test/t1.frm ;
SHOW TABLE STATUS like 't1';
--error ER_NOT_FORM_FILE
show create table t1;
+--disable_warnings
drop table if exists t1;
+--enable_warnings
--error 1,0
--remove_file $MYSQLD_DATADIR/test/t1.frm
diff --git a/mysql-test/t/show_explain.test b/mysql-test/t/show_explain.test
index 051d4b8b5fc..41091d7f5b9 100644
--- a/mysql-test/t/show_explain.test
+++ b/mysql-test/t/show_explain.test
@@ -466,7 +466,7 @@ explain SELECT * FROM t2 WHERE a =
WHERE pk= (SELECT MAX(pk) FROM t2 WHERE pk = 3)
);
-set @show_explain_probe_select_id=2;
+set @show_explain_probe_select_id=1;
set debug_dbug='+d,show_explain_probe_do_select';
send SELECT * FROM t2 WHERE a =
(SELECT MAX(a) FROM t2
diff --git a/mysql-test/t/sp-destruct.test b/mysql-test/t/sp-destruct.test
index 12b0f903c26..e109f88e3f9 100644
--- a/mysql-test/t/sp-destruct.test
+++ b/mysql-test/t/sp-destruct.test
@@ -7,9 +7,6 @@
# In the case of trouble you might want to skip this.
#
-# embedded server returns different paths in error messages
-# in lines like 'call bug14233();'
-# mysqltest should be fixed to allow REPLACE_RESULT in error message
-- source include/not_embedded.inc
# Supress warnings written to the log file
diff --git a/mysql-test/t/subselect4.test b/mysql-test/t/subselect4.test
index 37f660d6682..e427253f65f 100644
--- a/mysql-test/t/subselect4.test
+++ b/mysql-test/t/subselect4.test
@@ -1865,5 +1865,18 @@ ORDER BY alias1.b;
drop table t1, t2, t3;
+--echo #
+--echo # MDEV-4144 simple subquery causes full scan instead of range scan
+--echo #
+
+CREATE TABLE t1 (id int not null auto_increment, x int not null, primary key(id));
+INSERT INTO t1 (x) VALUES (0),(0),(0);
+
+EXPLAIN
+SELECT x FROM t1 WHERE id > (SELECT MAX(id) - 1000 FROM t1) ORDER BY x LIMIT 1;
+SELECT x FROM t1 WHERE id > (SELECT MAX(id) - 1000 FROM t1) ORDER BY x LIMIT 1;
+
+drop table t1;
+
SET optimizer_switch= @@global.optimizer_switch;
set @@tmp_table_size= @@global.tmp_table_size;
diff --git a/mysql-test/t/subselect_exists2in.test b/mysql-test/t/subselect_exists2in.test
new file mode 100644
index 00000000000..94e7109e9d2
--- /dev/null
+++ b/mysql-test/t/subselect_exists2in.test
@@ -0,0 +1,739 @@
+
+--disable_warnings
+drop table if exists t1,t2,t3;
+--enable_warnings
+
+set optimizer_switch='exists_to_in=on';
+--echo #
+--echo # LP BUG#884644 exists2in broke name resolution
+--echo #
+
+CREATE TABLE t1 (f1 integer);
+
+--error ER_BAD_FIELD_ERROR
+SELECT * FROM t1 WHERE EXISTS (SELECT NO_SUCH_TABLE.NO_SUCH_FIELD FROM t1);
+
+drop table t1;
+
+--echo #
+--echo # LP BUG#884657 Wrong result with exists2in , correlated subquery
+--echo #
+
+CREATE TABLE t1 ( a varchar(1)) ;
+INSERT INTO t1 VALUES ('c'),('b');
+
+CREATE TABLE t2 ( b varchar(1)) ;
+INSERT INTO t2 VALUES ('v'),('v'),('c'),(NULL),('x'),('i'),('e'),('p'),('s'),('j'),('z'),('c'),('a'),('q'),('y'),(NULL),('r'),('v'),(NULL),('r');
+
+CREATE TABLE t3 ( a int NOT NULL , b varchar(1)) ;
+INSERT INTO t3 VALUES (29,'c');
+
+SELECT *
+FROM t1, t2
+WHERE EXISTS (
+ SELECT a
+ FROM t3
+ WHERE t3.b = t1.a
+ AND t3.b <> t2.b
+);
+
+
+INSERT INTO t3 VALUES (2,'c');
+alter table t1 add index aa (a);
+alter table t3 add index bb (b);
+--echo -- EXIST to IN then semijoin (has priority over IN to EXISTS)
+set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=on,materialization=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+--echo -- EXIST to IN then IN to EXISTS
+set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+--echo -- EXIST2IN then MATERIALIZATION
+set optimizer_switch='exists_to_in=on,in_to_exists=off,semijoin=off,materialization=on,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+--echo -- NO EXIST2IN
+set optimizer_switch='exists_to_in=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+drop table t1,t2,t3;
+
+--echo #
+--echo # From group_min_max.test
+--echo #
+create table t1 (
+ a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
+);
+
+insert into t1 (a1, a2, b, c, d) values
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
+('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
+('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
+('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
+('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'),
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
+('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
+('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
+('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
+('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4');
+
+create index idx_t1_0 on t1 (a1);
+create index idx_t1_1 on t1 (a1,a2,b,c);
+create index idx_t1_2 on t1 (a1,a2,b);
+analyze table t1;
+
+# t2 is the same as t1, but with some NULLs in the MIN/MAX column, and
+# one more nullable attribute
+
+create table t2 (
+ a1 char(64), a2 char(64) not null, b char(16), c char(16), d char(16), dummy char(64) default ' '
+);
+insert into t2 select * from t1;
+# add few rows with NULL's in the MIN/MAX column
+insert into t2 (a1, a2, b, c, d) values
+('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'),
+('a','a','a',NULL,'xyz'),
+('a','a','b',NULL,'xyz'),
+('a','b','a',NULL,'xyz'),
+('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'),
+('d','b','b',NULL,'xyz'),
+('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),
+('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),
+('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'),
+('a','a','a',NULL,'xyz'),
+('a','a','b',NULL,'xyz'),
+('a','b','a',NULL,'xyz'),
+('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'),
+('d','b','b',NULL,'xyz'),
+('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),
+('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz');
+
+create index idx_t2_0 on t2 (a1);
+create index idx_t2_1 on t2 (a1,a2,b,c);
+create index idx_t2_2 on t2 (a1,a2,b);
+analyze table t2;
+
+# Table t3 is the same as t1, but with smaller column lenghts.
+# This allows to test different branches of the cost computation procedure
+# when the number of keys per block are less than the number of keys in the
+# sub-groups formed by predicates over non-group attributes.
+
+create table t3 (
+ a1 char(1), a2 char(1), b char(1), c char(4) not null, d char(3), dummy char(1) default ' '
+);
+
+insert into t3 (a1, a2, b, c, d) values
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
+insert into t3 (a1, a2, b, c, d) values
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
+insert into t3 (a1, a2, b, c, d) values
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
+insert into t3 (a1, a2, b, c, d) values
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
+
+create index idx_t3_0 on t3 (a1);
+create index idx_t3_1 on t3 (a1,a2,b,c);
+create index idx_t3_2 on t3 (a1,a2,b);
+analyze table t3;
+
+
+explain select a1,a2,b,c,min(c), max(c) from t1
+where exists ( select * from t2
+ where t2.c in (select c from t3 where t3.c > t1.b) and
+ t2.c > 'b1' )
+group by a1,a2,b;
+
+select a1,a2,b,c,min(c), max(c) from t1
+where exists ( select * from t2
+ where t2.c in (select c from t3 where t3.c > t1.b) and
+ t2.c > 'b1' )
+group by a1,a2,b;
+
+explain select a1,a2,b,c,min(c), max(c) from t1
+where exists ( select * from t2
+ where t2.c in (select c from t3 where t3.c > t1.c) and
+ t2.c > 'b1' )
+group by a1,a2,b;
+
+select a1,a2,b,c,min(c), max(c) from t1
+where exists ( select * from t2
+ where t2.c in (select c from t3 where t3.c > t1.c) and
+ t2.c > 'b1' )
+group by a1,a2,b;
+
+drop table t1, t2, t3;
+
+#
+# LP BUG#901835 - incorrect semi-join conversion after exists2in
+#
+CREATE TABLE t1 ( a INT );
+INSERT INTO t1 VALUES (7),(0);
+CREATE TABLE t2 ( b INT );
+INSERT INTO t2 VALUES (0),(8);
+
+SELECT * FROM t1 WHERE
+ EXISTS ( SELECT * FROM t2 WHERE b = a )
+ OR a > 0;
+
+explain extended
+SELECT * FROM t1 WHERE
+ EXISTS ( SELECT * FROM t2 WHERE b = a )
+ OR a > 0;
+
+drop tables t1,t2;
+
+#
+# NOT EXISTS test
+#
+CREATE TABLE t1 ( a INT );
+INSERT INTO t1 VALUES (1),(5);
+CREATE TABLE t2 ( b INT ) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (1);
+
+CREATE TABLE t3 ( c INT );
+INSERT INTO t3 VALUES (4),(5);
+
+SET optimizer_switch='exists_to_in=on,subquery_cache=off,materialization=on,in_to_exists=off,semijoin=off';
+
+explain extended
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+
+SET optimizer_switch='exists_to_in=on,subquery_cache=off';
+
+
+explain extended
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+
+SET optimizer_switch='exists_to_in=off,subquery_cache=off';
+
+explain extended
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+drop table t1,t2,t3;
+
+--echo # multi condition test
+CREATE TABLE t1 ( a varchar(1), a1 varchar(1)) ;
+INSERT INTO t1 VALUES ('c', 'c'), ('b', 'b');
+
+CREATE TABLE t3 ( a int NOT NULL , b varchar(1), b1 varchar(1)) ;
+INSERT INTO t3 VALUES (29,'c','c');
+INSERT INTO t3 VALUES (2,'c','c');
+alter table t1 add index aa (a,a1);
+alter table t3 add index bb (b,b1);
+--echo -- EXIST to IN then semijoin (has priority over IN to EXISTS)
+set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=on,materialization=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+--echo -- EXIST to IN then IN to EXISTS
+set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+--echo -- EXIST2IN then MATERIALIZATION
+set optimizer_switch='exists_to_in=on,in_to_exists=off,semijoin=off,materialization=on,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+--echo -- NO EXIST2IN
+set optimizer_switch='exists_to_in=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+drop table t1,t3;
+
+--echo #
+--echo # MDEV-159 Assertion about not marked for read failed in
+--echo # String* Field_varstring::val_str(String*, String*)
+--echo #
+
+SET optimizer_switch = REPLACE( @@optimizer_switch, '=on', '=off' );
+SET optimizer_switch='in_to_exists=on,exists_to_in=on';
+
+CREATE TABLE t1 ( a VARCHAR(1) );
+INSERT INTO t1 VALUES ('k'),('m');
+
+CREATE TABLE t2 ( b INT,
+ c VARCHAR(1),
+ d VARCHAR(1) NOT NULL );
+
+INSERT INTO t2 VALUES
+ (4,'j','j'),(6,'v','v');
+
+CREATE ALGORITHM=MERGE VIEW v AS SELECT * FROM t2 WHERE b < 1;
+
+SELECT c FROM v
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= v.d AND b = v.b
+);
+
+explain extended
+SELECT c FROM v
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= v.d AND b = v.b
+);
+
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+drop view v;
+drop table t1,t2;
+
+
+--echo #
+--echo # MDEV-160 Exists2In: Crash in in hp_movelink with subquery_cache=ON
+--echo #
+
+SET optimizer_switch = 'in_to_exists=on,subquery_cache=on,exists_to_in=on';
+
+CREATE TABLE t1 (
+ a VARCHAR(3) NOT NULL,
+ b VARCHAR(50)
+);
+INSERT INTO t1 VALUES
+ ('USA','Chinese'),('USA','English'),
+ ('FRA','French'),('ITA','Italian');
+
+CREATE TABLE t2 ( c VARCHAR(3) );
+INSERT INTO t2 VALUES ('USA'),('FRA');
+
+SELECT * FROM t1 AS alias1, t1 AS alias2
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= alias2.a AND c = alias1.b
+) OR alias1 .a = 'foo';
+
+SELECT * FROM t1 AS alias1, t1 AS alias2
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= alias2.a AND c = alias1.a
+) OR alias1 .a = 'foo';
+
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-160 Exists2In: Crash in in hp_movelink with subquery_cache=ON
+--echo #
+SET optimizer_switch = 'in_to_exists=on,subquery_cache=on,exists_to_in=on';
+
+CREATE TABLE t1 (
+ a VARCHAR(3) NOT NULL,
+ b VARCHAR(50)
+);
+INSERT INTO t1 VALUES
+ ('USA','Chinese'),('USA','English'),
+ ('FRA','French'),('ITA','Italian');
+
+CREATE TABLE t2 ( c VARCHAR(3) );
+INSERT INTO t2 VALUES ('USA'),('FRA');
+
+SELECT * FROM t1 AS alias1, t1 AS alias2
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= alias2.a AND c = alias1.b
+) OR alias1 .a = 'foo';
+
+explain extended
+SELECT * FROM t1 AS alias1, t1 AS alias2
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= alias2.a AND c = alias1.b
+) OR alias1 .a = 'foo';
+
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-245 Exists2In: Wrong result (extra rows) with
+--echo # exists_to_in=ON, materialization=OFF, NOT EXISTS subquery
+--echo #
+SET optimizer_switch='materialization=off,exists_to_in=on';
+
+CREATE TABLE t1 ( a INT ) ;
+INSERT INTO t1 VALUES (0),(8),(1);
+
+CREATE TABLE t2 ( b INT ) ;
+INSERT INTO t2 VALUES (1),(2),(3);
+
+SELECT * FROM t1 WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b = a );
+explain extended
+SELECT * FROM t1 WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b = a );
+
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-243 Wrong result (extra or missing rows) with
+--echo # exists_to_in + materialization, EXISTS subquery
+--echo #
+
+SET optimizer_switch='index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=on';
+
+CREATE TABLE t1 ( a VARCHAR(1), b VARCHAR(1) );
+INSERT INTO t1 VALUES ('v','v'),('s','v');
+
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+explain extended
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+
+SET optimizer_switch = REPLACE( @@optimizer_switch, '=on', '=off' );
+SET optimizer_switch = 'exists_to_in=on,materialization=on,semijoin=off';
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+explain extended
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+SET optimizer_switch = 'exists_to_in=on,materialization=on,semijoin=on';
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+explain extended
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+
+drop table t1;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-403 Wrong result (missing rows) with subquery in
+--echo # EXISTS and an OR condition outside
+--echo #
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (2),(3);
+
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1),(3);
+SET optimizer_switch = 'exists_to_in=off,in_to_exists=on';
+SELECT * FROM t1 AS alias1, t2 AS alias2
+WHERE EXISTS (
+ SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
+) OR a = 5;
+
+SET optimizer_switch = 'exists_to_in=on,in_to_exists=on';
+
+SELECT * FROM t1 AS alias1, t2 AS alias2
+WHERE EXISTS (
+ SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
+) OR a = 5;
+
+explain extended
+SELECT * FROM t1 AS alias1, t2 AS alias2
+WHERE EXISTS (
+ SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
+) OR a = 5;
+
+drop table t1, t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-404: Wrong result (extra rows) with STRAIGHT_JOIN,
+--echo # EXISTS subquery, NOT NULL column
+--echo # (same as above)
+--echo #
+SET optimizer_switch = 'exists_to_in=on,in_to_exists=on';
+
+CREATE TABLE t1 (a INT, b VARCHAR(1) NOT NULL);
+INSERT INTO t1 VALUES (1,'s'),(2,'e');
+
+SELECT STRAIGHT_JOIN * FROM t1 AS alias1, t1 AS alias2
+WHERE EXISTS ( SELECT 1 FROM t1 WHERE b < alias2.b AND a = alias1.a );
+
+drop table t1;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+
+--echo #
+--echo # MDEV-3800: ORDER BY doesn't work with exists_to_in=ON on
+--echo # a query with EXISTS subquery and OR condition
+--echo #
+SET optimizer_switch = 'in_to_exists=on,exists_to_in=on';
+CREATE TABLE t1 (a INT, b VARCHAR(1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (4,'j'),(6,'v'),(3,'c');
+
+CREATE TABLE t2 (c VARCHAR(1)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('b'),('y');
+
+SELECT a FROM t1
+WHERE EXISTS (
+ SELECT 1 FROM t2 WHERE c = b
+) OR b NOT IN ('U')
+ORDER BY a;
+
+select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`b` in (select `test`.`t2`.`c` from `test`.`t2` where 1 ) or (`test`.`t1`.`b` <> 'U') order by `test`.`t1`.`a`;
+
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+
+--echo #
+--echo # correct calculation of reserved items (postreview-fix)
+--echo #
+create table t1 (col1 int, col2 int, col3 int);
+insert into t1 values (1,2,3),(2,3,4),(4,5,6);
+create table t2 as select * from t1;
+explain extended
+select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2);
+select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2);
+drop table t1,t2;
+
+--echo #
+--echo # MDEV-3879: Exists2In: Wrong result (extra row) and unexpected
+--echo # warning with exists_to_in=on and a NOT EXISTS subquery
+--echo #
+SET optimizer_switch = 'exists_to_in=on';
+
+CREATE TABLE t1 (a1 INT, b1 CHAR(1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (3,'y'),(6,'w');
+
+CREATE TABLE t2 (a2 INT, b2 CHAR(1)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (3,'y'),(6,'d');
+
+SELECT * FROM t1
+WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b2 = b1 AND a2 = a1 );
+
+drop table t1, t2;
+
+--echo #
+--echo # MDEV-3880: Wrong result (missing rows) with exists_to_in=on,
+--echo # LEFT JOIN and NOT EXISTS subquery.
+--echo # (Duplicate of above MDEV-3879).
+--echo #
+
+SET optimizer_switch = 'exists_to_in=on';
+CREATE TABLE t1 (a1 INT, b1 CHAR(1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (4,'b'),(5,'y');
+
+CREATE TABLE t2 (b2 CHAR(1)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('z'),('b');
+
+CREATE TABLE t3 (a3 INT, b3 CHAR(1)) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (4,'j'),(6,'v');
+
+SELECT * FROM t1 LEFT JOIN t2 ON ( b2 = b1 )
+WHERE NOT EXISTS ( SELECT * FROM t3 WHERE b3 = b2 AND a3 = a1 ) ;
+
+drop table t1, t2, t3;
+
+
+
+--echo #
+--echo # MDEV-3881: Endless loop and crash in Item_ref::real_item with
+--echo # exists_to_in=on, NOT EXISTS subquery, merge view or from subquery,
+--echo # constant table
+--echo #
+SET optimizer_switch = 'exists_to_in=on';
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(7);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (8);
+CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t2;
+
+CREATE TABLE t3 (c INT) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (4),(6);
+
+SELECT * FROM t1, v1 WHERE NOT EXISTS ( SELECT * FROM t3 WHERE c = b ) AND a = b;
+
+drop view v1;
+drop table t1, t2, t3;
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(7);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (8);
+
+CREATE TABLE t3 (c INT) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (4),(6);
+
+SELECT * FROM t1, ( SELECT * FROM t2 ) alias WHERE NOT EXISTS ( SELECT * FROM t3 WHERE c = b ) AND a = b;
+
+drop table t1, t2, t3;
+
+--echo #
+--echo # MDEV-3906: Server crashes in Dependency_marker::visit_field
+--echo # on 2nd execution of PS with exists_to_in and NOT EXISTS subquery
+--echo #
+SET optimizer_switch='exists_to_in=on';
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(7);
+
+PREPARE stmt FROM '
+SELECT * FROM t1 AS alias
+WHERE NOT EXISTS ( SELECT * FROM t1 WHERE t1.a = alias.a )
+';
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-3904: Assertion `in_subs->has_strategy()' failed in
+--echo # JOIN::choose_subquery_plan on 2nd execution of PS with
+--echo # exists_to_in+semijoin, EXISTS subquery, MERGE view or FROM subquery
+--echo #
+SET optimizer_switch='in_to_exists=on,semijoin=on,exists_to_in=on';
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (4),(6);
+
+CREATE ALGORITHM=MERGE VIEW v AS
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t2 WHERE b = a );
+
+PREPARE stmt FROM ' SELECT * FROM v ';
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+drop view v;
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-3903: Server crashes in Item_cond::fix_fields on 2nd execution
+--echo # of a prepared stmt with exists_to_in+materialization+semijoin,
+--echo # EXISTS subquery, STRAIGHT_JOIN
+--echo #
+
+SET optimizer_switch='materialization=on,semijoin=on,exists_to_in=on';
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (3),(4);
+
+PREPARE stmt FROM
+'SELECT STRAIGHT_JOIN * FROM t1
+WHERE EXISTS ( SELECT * FROM t2 WHERE b = a )';
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-4152: Wrong result (missing rows) with exists_to_in=on,
+--echo # inner joins
+--echo #
+SET optimizer_switch='materialization=on,semijoin=on,exists_to_in=on';
+
+CREATE TABLE t1 (i INT, c1 CHAR(5), c2 CHAR(5), t1_field VARCHAR(1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1,'test1','test2','f'), (2,'test3','test4','d');
+
+CREATE TABLE t2 (t2_field VARCHAR(1)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('m'), ('b');
+
+CREATE TABLE t3 (t3_field VARCHAR(1)) ENGINE=MyISAM;
+INSERT INTO t3 VALUES ('b'),('c');
+
+SELECT * FROM t1, t2 outer_t2
+WHERE EXISTS ( SELECT 1 FROM t2, t3 WHERE t3_field = outer_t2.t2_field AND t2_field <= t1_field );
+
+drop table t1,t2,t3;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+#restore defaults
+set optimizer_switch=default;
diff --git a/mysql-test/t/subselect_exists2in_costmat.test b/mysql-test/t/subselect_exists2in_costmat.test
new file mode 100644
index 00000000000..5d5eeaee268
--- /dev/null
+++ b/mysql-test/t/subselect_exists2in_costmat.test
@@ -0,0 +1,83 @@
+#
+# Tests of cost-based choice between the materialization and in-to-exists
+# subquery execution strategies (MWL#89)
+#
+# The test file is divided into two groups of tests:
+# A. Typical cases when either of the two strategies is selected:
+# 1. Subquery in disjunctive WHERE clause of the outer query.
+# 2. NOT IN subqueries
+# 3. Subqueries with GROUP BY, HAVING, and aggregate functions
+# 4. Subqueries in the SELECT and HAVING clauses
+# 5. Subqueries with UNION
+# B. Reasonably exhaustive tests of the various combinations of optimizer
+# switches, data distribution, available indexes, and typical queries.
+#
+
+set @subselect_mat_cost=@@optimizer_switch;
+set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
+#
+# Test logging to slow log (there was some errors in the log files about
+# the slow log when running under valgrind, so better to get this tested)
+#
+set long_query_time=0.1;
+
+
+--disable_warnings
+drop database if exists world;
+--enable_warnings
+
+set names utf8;
+
+create database world;
+use world;
+
+--source include/world_schema.inc
+--disable_query_log
+--disable_result_log
+--disable_warnings
+--source include/world.inc
+--enable_warnings
+--enable_result_log
+--enable_query_log
+
+-- echo Make the schema and data more diverse by adding more indexes, nullable
+-- echo columns, and NULL data.
+create index SurfaceArea on Country(SurfaceArea);
+create index Language on CountryLanguage(Language);
+create index CityName on City(Name);
+alter table City change population population int(11) null default 0;
+
+select max(id) from City into @max_city_id;
+insert into City values (@max_city_id + 1,'Kilifarevo','BGR',NULL);
+
+
+SELECT COUNT(*) FROM Country;
+SELECT COUNT(*) FROM City;
+SELECT COUNT(*) FROM CountryLanguage;
+
+set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on';
+
+-- echo
+-- echo 1. Subquery in a disjunctive WHERE clause of the outer query.
+-- echo
+
+-- echo
+-- echo Q1.1m:
+-- echo MATERIALIZATION: there are too many rows in the outer query
+-- echo to be looked up in the inner table.
+EXPLAIN
+SELECT Name FROM Country
+WHERE (EXISTS (select 1 from City where City.Population > 100000 and
+Code = Country) OR
+ Name LIKE 'L%') AND
+ surfacearea > 1000000;
+
+SELECT Name FROM Country
+WHERE (EXISTS (select 1 from City where City.Population > 100000 and
+Code = Country) OR
+ Name LIKE 'L%') AND
+ surfacearea > 1000000;
+
+drop database world;
+
+set optimizer_switch=@subselect_mat_cost;
diff --git a/mysql-test/t/subselect_exists_to_in.test b/mysql-test/t/subselect_exists_to_in.test
new file mode 100644
index 00000000000..1b97aa13955
--- /dev/null
+++ b/mysql-test/t/subselect_exists_to_in.test
@@ -0,0 +1,11 @@
+#
+# Run subselect.test with exists to in transformation
+#
+select @@optimizer_switch like '%exists_to_in=on%';
+set optimizer_switch='exists_to_in=on';
+
+--source t/subselect.test
+
+set optimizer_switch=default;
+select @@optimizer_switch like '%exists_to_in=on%';
+
diff --git a/mysql-test/t/subselect_sj.test b/mysql-test/t/subselect_sj.test
index efbd2b00f24..e2abb8040b3 100644
--- a/mysql-test/t/subselect_sj.test
+++ b/mysql-test/t/subselect_sj.test
@@ -2482,6 +2482,15 @@ deallocate prepare stmt;
drop table t1,t2;
--echo #
+--echo # MDEV-4335: Unexpected results when selecting on information_schema
+--echo #
+CREATE TABLE t1 (db VARCHAR(64) DEFAULT NULL);
+INSERT INTO t1 VALUES ('mysql'),('information_schema');
+SELECT * FROM t1 WHERE db IN (SELECT `SCHEMA_NAME` FROM information_schema.SCHEMATA);
+DROP TABLE t1;
+
+
+--echo #
--echo # MySQL Bug#13340270: assertion table->sort.record_pointers == __null
--echo #
diff --git a/mysql-test/t/subselect_sj2_mat.test b/mysql-test/t/subselect_sj2_mat.test
index 7c3b37b517a..61d9b09edff 100644
--- a/mysql-test/t/subselect_sj2_mat.test
+++ b/mysql-test/t/subselect_sj2_mat.test
@@ -36,4 +36,230 @@ WHERE a IN
DROP TABLE t1, t2;
set max_join_size= @tmp_906385;
+--echo #
+--echo # mdev-3995: Wrong result for semijoin with materialization
+--echo #
+
+set @save_optimizer_switch=@@optimizer_switch;
+
+CREATE TABLE t1 (
+ cat_id int(10) unsigned NOT NULL,
+ PRIMARY KEY (cat_id)
+) ENGINE=MyISAM;
+
+INSERT INTO t1 VALUES
+(709411),(709412),(709413),(709414),(709416),(709417),(709418),(709419),(709421),(709422),
+(709424),(709425),(709427),(709428),(709429),(709431),(709432),(709433),(709434),(709435),
+(709438),(709439),(709441),(709442),(709443),(709444),(709445),(709446),(709447),(709450),
+(709451),(709454),(709455),(709456),(709457),(709459),(709460),(709461),(709462),(709463),
+(709464),(709465),(709467),(709469),(709470),(709471),(709472),(709473),(709474),(709475),
+(709476),(709477),(709478),(709479),(709480),(709481),(709483),(709484),(709485),(709487),
+(709490),(709491),(709492),(709493),(709494),(709495),(709496),(709497),(709498),(709499),
+(709500),(709501),(709502),(709503),(709504),(709505),(709506),(709507),(709509),(709510),
+(709511),(709512),(709513),(709514),(709515),(709516),(709517),(709518),(709519),(709520),
+(709521),(709522),(709523),(709524),(709525),(709526),(709527),(709528),(709529),(709530),
+(709531),(709532),(709533),(709534),(709535),(709536),(709537),(709538),(709539),(709540),
+(709541),(709542),(709543),(709544),(709545),(709546),(709548),(709549),(709551),(709552),
+(709553),(709555),(709556),(709557),(709558),(709559),(709560),(709561),(709562),(709563),
+(709564),(709565),(709566),(709567),(709568),(709569),(709570),(709571),(709572),(709573),
+(709574),(709575),(709576),(709577),(709578),(709579),(709580),(709581),(709582),(709583),
+(709584),(709585),(709586),(709587),(709588),(709590),(709591),(709592),(709593),(709594),
+(709595),(709596),(709597),(709598),(709600),(709601),(709602),(709603),(709604),(709605),
+(709606),(709608),(709609),(709610),(709611),(709612),(709613),(709614),(709615),(709616),
+(709617),(709618),(709619),(709620),(709621),(709622),(709623),(709624),(709625),(709626),
+(709627),(709628),(709629),(709630),(709631),(709632),(709633),(709634),(709635),(709637),
+(709638),(709639),(709640),(709641),(709642),(709643),(709644),(709645),(709646),(709649),
+(709650),(709651),(709652),(709653),(709654),(709655),(709656),(709657),(709658),(709659);
+
+CREATE TABLE t2 (
+ cat_id int(10) NOT NULL,
+ KEY cat_id (cat_id)
+) ENGINE=MyISAM;
+
+INSERT INTO t2 VALUES
+(708742),(708755),(708759),(708761),(708766),(708769),(708796),(708798),(708824),(708825),
+(708838),(708844),(708861),(708882),(708887),(708889),(708890),(709586),(709626);
+
+CREATE TABLE t3 (
+ sack_id int(10) unsigned NOT NULL,
+ kit_id tinyint(3) unsigned NOT NULL DEFAULT '0',
+ cat_id int(10) unsigned NOT NULL,
+ PRIMARY KEY (sack_id,kit_id,cat_id)
+) ENGINE=MyISAM;
+
+INSERT INTO t3 VALUES
+(33479,6,708523),(33479,6,708632),(33479,6,709085),(33479,6,709586),(33479,6,709626);
+
+CREATE TABLE t4 (
+ cat_id int(10) unsigned NOT NULL,
+ KEY cat_id (cat_id)
+) ENGINE=MyISAM;
+
+INSERT INTO t4 (cat_id) SELECT cat_id from t2;
+
+set optimizer_switch='materialization=off';
+
+EXPLAIN
+SELECT count(*) FROM t1, t3
+ WHERE t1.cat_id = t3.cat_id AND
+ t3.cat_id IN (SELECT cat_id FROM t2) AND
+ t3.sack_id = 33479 AND t3.kit_id = 6;
+
+SELECT count(*) FROM t1, t3
+ WHERE t1.cat_id = t3.cat_id AND
+ t3.cat_id IN (SELECT cat_id FROM t2) AND
+ t3.sack_id = 33479 AND t3.kit_id = 6;
+
+set optimizer_switch='materialization=on';
+
+EXPLAIN
+SELECT count(*) FROM t1, t3
+ WHERE t1.cat_id = t3.cat_id AND
+ t3.cat_id IN (SELECT cat_id FROM t4) AND
+ t3.sack_id = 33479 AND t3.kit_id = 6;
+
+SELECT count(*) FROM t1, t3
+ WHERE t1.cat_id = t3.cat_id AND
+ t3.cat_id IN (SELECT cat_id FROM t4) AND
+ t3.sack_id = 33479 AND t3.kit_id = 6;
+
+EXPLAIN
+SELECT count(*) FROM t1, t3
+ WHERE t1.cat_id = t3.cat_id AND
+ t3.cat_id IN (SELECT cat_id FROM t2) AND
+ t3.sack_id = 33479 AND t3.kit_id = 6;
+
+SELECT count(*) FROM t1, t3
+ WHERE t1.cat_id = t3.cat_id AND
+ t3.cat_id IN (SELECT cat_id FROM t2) AND
+ t3.sack_id = 33479 AND t3.kit_id = 6;
+
+
+DROP TABLE t1,t2,t3,t4;
+
+set optimizer_switch=@save_optimizer_switch;
+
+--echo #
+--echo # mdev-3913: LEFT JOIN with materialized multi-table IN subquery in WHERE
+--echo #
+
+set @save_optimizer_switch=@@optimizer_switch;
+
+CREATE TABLE t1 (a1 char(1), b1 char(1), index idx(b1,a1));
+INSERT INTO t1 VALUES ('f','c'),('d','m'),('g','y');
+INSERT INTO t1 VALUES ('f','c'),('d','m'),('g','y');
+
+CREATE TABLE t2 (a2 char(1), b2 char(1));
+INSERT INTO t2 VALUES ('y','y'),('y','y'),('w','w');
+
+CREATE TABLE t3 (a3 int);
+INSERT INTO t3 VALUES (8),(6);
+
+CREATE TABLE t4 (a4 char(1), b4 char(1));
+INSERT INTO t4 VALUES ('y','y'),('y','y'),('w','w');
+
+set optimizer_switch='materialization=off';
+
+EXPLAIN EXTENDED
+SELECT * FROM t1 LEFT JOIN t2 ON ( b1 = a2 )
+ WHERE ( b1, b1 ) IN ( SELECT a4, b4 FROM t3, t4);
+SELECT * FROM t1 LEFT JOIN t2 ON ( b1 = a2 )
+ WHERE ( b1, b1 ) IN ( SELECT a4, b4 FROM t3, t4);
+
+set optimizer_switch='materialization=on';
+
+EXPLAIN EXTENDED
+SELECT * FROM t1 LEFT JOIN t2 ON ( b1 = a2 )
+ WHERE ( b1, b1 ) IN ( SELECT a4, b4 FROM t3, t4);
+SELECT * FROM t1 LEFT JOIN t2 ON ( b1 = a2 )
+ WHERE ( b1, b1 ) IN ( SELECT a4, b4 FROM t3, t4);
+
+DROP TABLE t1,t2,t3,t4;
+
+set optimizer_switch=@save_optimizer_switch;
+
+--echo #
+--echo # mdev-4172: LEFT JOIN with materialized multi-table IN subquery in WHERE
+--echo # and OR in ON condition
+--echo #
+
+set @save_optimizer_switch=@@optimizer_switch;
+
+CREATE TABLE t1 (a1 int, c1 varchar(1));
+INSERT t1 VALUES (7,'v'), (3,'y');
+
+CREATE TABLE t2 (c2 varchar(1));
+INSERT INTO t2 VALUES ('y'), ('y');
+
+CREATE TABLE t3 (c3 varchar(1));
+INSERT INTO t3 VALUES
+ ('j'), ('v'), ('c'), ('m'), ('d'),
+ ('d'), ('y'), ('t'), ('d'), ('s');
+
+CREATE TABLE t4 (a4 int, c4 varchar(1));
+INSERT INTO t4 SELECT * FROM t1;
+
+set optimizer_switch='materialization=off';
+
+EXPLAIN EXTENDED
+SELECT * FROM t1 LEFT JOIN t2 ON (c2 = c1 OR c1 > 'z')
+ WHERE c1 IN ( SELECT c4 FROM t3,t4 WHERE c3 = c4);
+SELECT * FROM t1 LEFT JOIN t2 ON (c2 = c1 OR c1 > 'z')
+ WHERE c1 IN ( SELECT c4 FROM t3,t4 WHERE c3 = c4);
+
+set optimizer_switch='materialization=on';
+
+EXPLAIN EXTENDED
+SELECT * FROM t1 LEFT JOIN t2 ON (c2 = c1 OR c1 > 'z')
+ WHERE c1 IN ( SELECT c4 FROM t3,t4 WHERE c3 = c4);
+SELECT * FROM t1 LEFT JOIN t2 ON (c2 = c1 OR c1 > 'z')
+ WHERE c1 IN ( SELECT c4 FROM t3,t4 WHERE c3 = c4);
+
+DROP TABLE t1,t2,t3,t4;
+
+set optimizer_switch=@save_optimizer_switch;
+
+--echo #
+--echo # mdev-4177: materialization of a subquery whose WHERE condition is OR
+--echo # formula with two disjucts such that the second one is always false
+--echo #
+
+set @save_optimizer_switch=@@optimizer_switch;
+set @save_join_cache_level=@@join_cache_level;
+
+CREATE TABLE t1 (i1 int) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1), (7), (4), (8), (4);
+
+CREATE TABLE t2 (i2 int) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (7), (5);
+
+CREATE TABLE t3 (i3 int) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (7), (2), (9);
+
+set join_cache_level=3;
+
+set optimizer_switch='materialization=off,semijoin=off';
+
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 = i2 OR 1=2);
+SELECT * FROM t1 WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 = i2 OR 1=2);
+
+set optimizer_switch='materialization=on,semijoin=on';
+
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 = i2 OR 1=2);
+SELECT * FROM t1 WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 = i2 OR 1=2);
+
+EXPLAIN EXTENDED
+SELECT * FROM t1
+ WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 > 0 AND i3 = i2 OR 1=2);
+SELECT * FROM t1
+ WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 > 0 AND i3 = i2 OR 1=2);
+SELECT * FROM t1
+ WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 > 7 AND i3 = i2 OR 1=2);
+
+DROP TABLE t1,t2,t3;
+
+set join_cache_level= @save_join_cache_level;
+set optimizer_switch=@save_optimizer_switch;
diff --git a/mysql-test/t/sum_distinct-big.test b/mysql-test/t/sum_distinct-big.test
index d3710056c9a..fee406ee46d 100644
--- a/mysql-test/t/sum_distinct-big.test
+++ b/mysql-test/t/sum_distinct-big.test
@@ -3,15 +3,23 @@
#
--source include/big_test.inc
+--source include/have_innodb.inc
--disable_warnings
DROP TABLE IF EXISTS t1, t2;
--enable_warnings
+set @save_tmp_table_size=@@tmp_table_size;
+set @save_max_heap_table_size=@@max_heap_table_size;
+
+set @save_storage_engine=@@storage_engine;
+
#
# Test the case when distinct values doesn't fit in memory and
# filesort is used (see uniques.cc:merge_walk)
#
+set storage_engine=MYISAM;
+
CREATE TABLE t1 (id INTEGER);
CREATE TABLE t2 (id INTEGER);
@@ -82,3 +90,64 @@ SELECT SUM(DISTINCT id) sm FROM t2;
DROP TABLE t1;
DROP TABLE t2;
+
+SET @@tmp_table_size=@save_tmp_table_size;
+SET @@max_heap_table_size=@save_max_heap_table_size;
+
+--echo #
+--echo # Bug mdev-4311: COUNT(DISTINCT...) requiring a file for Unique
+--echo # (bug #68749)
+--echo #
+
+set @save_storage_engine=@@storage_engine;
+set storage_engine=INNODB;
+
+CREATE TABLE t1 (id INTEGER) ENGINE=InnoDB;
+CREATE TABLE t2 (id INTEGER) ENGINE=InnoDB;
+
+INSERT INTO t1 (id) VALUES (1), (1), (1),(1);
+INSERT INTO t1 (id) SELECT id FROM t1;
+INSERT INTO t1 (id) SELECT id FROM t1;
+INSERT INTO t1 (id) SELECT id FROM t1;
+INSERT INTO t1 (id) SELECT id FROM t1;
+INSERT INTO t1 (id) SELECT id FROM t1;
+INSERT INTO t1 SELECT id+1 FROM t1;
+INSERT INTO t1 SELECT id+2 FROM t1;
+INSERT INTO t1 SELECT id+4 FROM t1;
+INSERT INTO t1 SELECT id+8 FROM t1;
+INSERT INTO t1 SELECT id+16 FROM t1;
+INSERT INTO t1 SELECT id+32 FROM t1;
+INSERT INTO t1 SELECT id+64 FROM t1;
+INSERT INTO t1 SELECT id+128 FROM t1;
+INSERT INTO t1 SELECT id+256 FROM t1;
+INSERT INTO t1 SELECT id+512 FROM t1;
+INSERT INTO t1 SELECT id+1024 FROM t1;
+INSERT INTO t1 SELECT id+2048 FROM t1;
+INSERT INTO t1 SELECT id+4096 FROM t1;
+INSERT INTO t1 SELECT id+8192 FROM t1;
+
+INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand();
+INSERT INTO t2 VALUE(NULL);
+
+--echo # With default tmp_table_size / max_heap_table_size
+SELECT SQL_NO_CACHE count(DISTINCT id) sm FROM t2;
+
+set @@tmp_table_size=1024*256;
+
+--echo # With reduced tmp_table_size
+SELECT SQL_NO_CACHE count(DISTINCT id) sm FROM t2;
+
+set @@tmp_table_size=@save_tmp_table_size;
+SET @@max_heap_table_size=1024*256;
+
+--echo # With reduced max_heap_table_size
+SELECT SQL_NO_CACHE count(DISTINCT id) sm FROM t2;
+
+SET @@max_heap_table_size=@save_max_heap_table_size;
+
+--echo # Back to default tmp_table_size / max_heap_table_size
+SELECT SQL_NO_CACHE count(DISTINCT id) sm FROM t2;
+
+DROP TABLE t1,t2;
+
+set storage_engine=@save_storage_engine;
diff --git a/mysql-test/t/temporal_scale_4283.test b/mysql-test/t/temporal_scale_4283.test
new file mode 100644
index 00000000000..d79ca7caa54
--- /dev/null
+++ b/mysql-test/t/temporal_scale_4283.test
@@ -0,0 +1,13 @@
+#
+# MDEV-4283 Assertion `scale <= precision' fails in strings/decimal.c
+#
+create table t1 (a int);
+insert into t1 values (4),(8);
+select distinct 100 mod timestampadd( week, a, '2002-05-20' ) from t1;
+drop table t1;
+
+create table t1 (i int);
+insert into t1 values (2),(4);
+select distinct convert_tz( '2001-03-21', 'utc', 'met' ) mod i from t1;
+drop table t1;
+
diff --git a/mysql-test/t/truncate_badse.test b/mysql-test/t/truncate_badse.test
new file mode 100644
index 00000000000..71545cab11a
--- /dev/null
+++ b/mysql-test/t/truncate_badse.test
@@ -0,0 +1,15 @@
+#
+# test what TRUNCATE TABLE does, if the table was created in
+# now-unknown storage engine.
+#
+--source include/have_example_plugin.inc
+install plugin example soname 'ha_example';
+create table t1 (a int) engine=example;
+select 1;
+uninstall plugin example;
+flush tables;
+select count(*) from information_schema.plugins where plugin_name='example';
+--error ER_UNKNOWN_STORAGE_ENGINE
+truncate table t1;
+drop table t1;
+
diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test
index 989e0d29210..d1648254fb2 100644
--- a/mysql-test/t/type_datetime.test
+++ b/mysql-test/t/type_datetime.test
@@ -463,6 +463,16 @@ DROP TABLE t1;
--echo End of 5.1 tests
+#
+# MDEV-4281 Assertion `maybe_null && item->null_value' fails in make_sortkey on CASE with different return types, GROUP_CONCAT, GROUP BY
+#
+create table t1 (d date, t time) engine=myisam;
+insert into t1 values ('2000-12-03','22:55:23'),('2008-05-03','10:19:31');
+select case when d = '2012-12-12' then d else t end as cond, group_concat( d ) from t1 group by cond;
+drop table t1;
+
+--echo End of 5.3 tests
+
--echo #
--echo # Start of 5.5 tests
--echo #
diff --git a/mysql-test/t/type_enum.test b/mysql-test/t/type_enum.test
index 2043342e2c8..5b0b70631a5 100644
--- a/mysql-test/t/type_enum.test
+++ b/mysql-test/t/type_enum.test
@@ -221,3 +221,18 @@ SELECT a FROM t1 WHERE a=0;
DROP TABLE t1;
--echo End of 5.1 tests
+
+--echo #
+--echo # MDEV-4241: Assertion failure: scale >= 0 && precision > 0 &&
+--echo # scale <= precision in decimal_bin_size
+--echo #
+CREATE TABLE t1 (
+ f1 enum('1','2','3','4','5')
+) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+--enable_metadata
+SELECT AVG(f1) FROM t1;
+--disable_metadata
+drop table t1;
+
+--echo End of 5.3 tests
diff --git a/mysql-test/t/upgrade.test b/mysql-test/t/upgrade.test
index a8c875ef764..c6d01a16f49 100644
--- a/mysql-test/t/upgrade.test
+++ b/mysql-test/t/upgrade.test
@@ -33,18 +33,15 @@ drop database `mysqltest-1`;
#
# Bug#17142: Crash if create with encoded name
#
---disable_warnings
-drop table if exists `txu@0023p@0023p1`;
-drop table if exists `txu#p#p1`;
---enable_warnings
create table `txu#p#p1` (s1 int);
insert into `txu#p#p1` values (1);
--error 1146
select * from `txu@0023p@0023p1`;
---error ER_TABLE_EXISTS_ERROR
create table `txu@0023p@0023p1` (s1 int);
+show tables;
select * from `txu#p#p1`;
drop table `txu#p#p1`;
+drop table `txu@0023p@0023p1`;
--echo #
--echo # Bug#37631 Incorrect key file for table after upgrading from 5.0 to 5.1
diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test
index c6930a7e468..2c889c2cc0c 100644
--- a/mysql-test/t/user_var.test
+++ b/mysql-test/t/user_var.test
@@ -364,7 +364,7 @@ SELECT (@v:=a) <> (@v:=1) FROM t1;
DROP TABLE t1;
#
-# LP BUG#1001506 Crash on a query with GROUP BY and user variables
+# lp:1001506 Crash on a query with GROUP BY and user variables
# MySQL Bug #11764372 57197: EVEN MORE USER VARIABLE CRASHING FUN
#
@@ -374,15 +374,49 @@ SELECT DISTINCT @a:=MIN(t1.a) FROM t1, t1 AS t2
GROUP BY @b:=(SELECT COUNT(*) > t2.a);
DROP TABLE t1;
+#
+#
+# Bug #12408412: GROUP_CONCAT + ORDER BY + INPUT/OUTPUT
+# SAME USER VARIABLE = CRASH
+#
+SET @bug12408412=1;
+SELECT GROUP_CONCAT(@bug12408412 ORDER BY 1) INTO @bug12408412;
+
--echo End of 5.1 tests
#
-# Bug#50511: Sometimes wrong handling of user variables containing NULL.
+# MDEV-616 lp:1002126
+# Bug #11764371 57196: MORE FUN WITH ASSERTION: !TABLE->FILE ||
+# TABLE->FILE->INITED == HANDLER::
#
---disable_warnings
-DROP TABLE IF EXISTS t1;
---enable_warnings
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (0);
+SELECT DISTINCT POW(COUNT(*), @a:=(SELECT 1 FROM t1 LEFT JOIN t1 AS t2 ON @a))
+AS b FROM t1 GROUP BY a;
+SELECT @a;
+DROP TABLE t1;
+CREATE TABLE t1(f1 INT, f2 INT);
+INSERT INTO t1 VALUES (1,2),(2,3),(3,1);
+CREATE TABLE t2(a INT);
+INSERT INTO t2 VALUES (1);
+SET @var=NULL;
+SELECT @var:=(SELECT f2 FROM t2 WHERE @var) FROM t1 GROUP BY f1 ORDER BY f2 DESC
+LIMIT 1;
+SELECT @var;
+DROP TABLE t1, t2;
+
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (0),(1),(3);
+SELECT DISTINCT POW(COUNT(distinct a), @a:=(SELECT 1 FROM t1 LEFT JOIN t1 AS t2 ON @a limit 1)) AS b FROM t1 GROUP BY a;
+SELECT @a;
+DROP TABLE t1;
+
+--echo End of 5.2 tests
+
+#
+# Bug#50511: Sometimes wrong handling of user variables containing NULL.
+#
CREATE TABLE t1(f1 INT AUTO_INCREMENT, PRIMARY KEY(f1));
@@ -415,7 +449,6 @@ SELECT f1, f2 FROM t1 ORDER BY f2;
DROP TRIGGER trg1;
DROP TABLE t1;
-
--echo #
--echo # Bug #12408412: GROUP_CONCAT + ORDER BY + INPUT/OUTPUT
--echo # SAME USER VARIABLE = CRASH
@@ -452,6 +485,8 @@ SELECT DISTINCT POW(COUNT(distinct a), @a:=(SELECT 1 FROM t1 LEFT JOIN t1 AS t2
SELECT @a;
DROP TABLE t1;
+--echo End of 5.5 tests
+
--echo #
--echo # Check that used memory extends if we set a variable
--echo #
@@ -466,4 +501,3 @@ eval select $tmp < $tmp2;
--enable_column_names
--enable_query_log
---echo End of 5.5 tests
diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test
index 792859386e9..08e7e68c225 100644
--- a/mysql-test/t/variables.test
+++ b/mysql-test/t/variables.test
@@ -1206,22 +1206,6 @@ SET GLOBAL server_id = -1;
SELECT @@GLOBAL.server_id;
SET GLOBAL server_id = @old_server_id;
-#
-# Bug #42778: delete order by null global variable causes
-# assertion .\filesort.cc, line 797
-#
-
-SELECT @@GLOBAL.INIT_CONNECT, @@GLOBAL.INIT_CONNECT IS NULL;
-
-CREATE TABLE t1 (a INT);
-INSERT INTO t1 VALUES ();
-SET @bug42778= @@sql_safe_updates;
-SET @@sql_safe_updates= 0;
-DELETE FROM t1 ORDER BY (@@GLOBAL.INIT_CONNECT) ASC LIMIT 10;
-SET @@sql_safe_updates= @bug42778;
-
-DROP TABLE t1;
-
--echo #
--echo # BUG#10206 - InnoDB: Transaction requiring Max_BinLog_Cache_size > 4GB always rollsback
--echo #