[Commits] d77e498: MDEV-18689 Simple query with extra brackets stopped working
by IgorBabaev 06 May '19
by IgorBabaev 06 May '19
06 May '19
revision-id: d77e49853c6a051252ae085f0aa92dd1ab5b924f (mariadb-10.4.4-66-gd77e498)
parent(s): d18ef804bb5d9d473055a2fdc04f74e175a8e9cd
author: Igor Babaev
committer: Igor Babaev
timestamp: 2019-05-05 20:00:49 -0700
message:
MDEV-18689 Simple query with extra brackets stopped working
Parenthesis around table names and derived tables should be allowed
in FROM clauses and some other context as it was in earlier versions.
Returned test queries that used such parenthesis in 10.3 to their
original form. Adjusted test results accordingly.
---
mysql-test/main/brackets.result | 42 +++++++++++++++++++++
mysql-test/main/brackets.test | 22 +++++++++++
mysql-test/main/subselect.result | 24 +++++++++---
mysql-test/main/subselect.test | 4 --
mysql-test/main/subselect_no_exists_to_in.result | 24 +++++++++---
mysql-test/main/subselect_no_mat.result | 24 +++++++++---
mysql-test/main/subselect_no_opts.result | 24 +++++++++---
mysql-test/main/subselect_no_scache.result | 24 +++++++++---
mysql-test/main/subselect_no_semijoin.result | 24 +++++++++---
mysql-test/main/subselect_sj.test | 2 +-
mysql-test/main/subselect_sj_mat.test | 4 +-
mysql-test/main/union.test | 6 +--
mysql-test/main/view.test | 48 ++++++++++++------------
mysql-test/suite/innodb/t/innodb.test | 2 +-
sql/sql_yacc.yy | 17 +++++++--
15 files changed, 217 insertions(+), 74 deletions(-)
diff --git a/mysql-test/main/brackets.result b/mysql-test/main/brackets.result
index 869afe5..e14bef9 100644
--- a/mysql-test/main/brackets.result
+++ b/mysql-test/main/brackets.result
@@ -452,4 +452,46 @@ EXPLAIN
}
}
drop table t1;
+#
+# MDEV-18689: parenthesis around table names and derived tables
+#
+select * from ( mysql.db );
+Host Db User Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Grant_priv References_priv Index_priv Alter_priv Create_tmp_table_priv Lock_tables_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv Execute_priv Event_priv Trigger_priv Delete_history_priv
+% test Y Y Y Y Y Y N Y Y Y Y Y Y Y Y N N Y Y Y
+% test\_% Y Y Y Y Y Y N Y Y Y Y Y Y Y Y N N Y Y Y
+create table t1 (a int);
+insert into t1 values (7), (2), (7);
+select * from (t1);
+a
+7
+2
+7
+select * from ((t1));
+a
+7
+2
+7
+select * from (t1 t) where t.a > 5;
+a
+7
+7
+select * from ((t1 t)) where t.a > 5;
+a
+7
+7
+select * from ((select a, sum(a) from t1 group by a) t);
+a sum(a)
+2 2
+7 14
+select * from (((select a, sum(a) from t1 group by a) t));
+a sum(a)
+2 2
+7 14
+update (t1 t) set t.a=t.a+1;
+select * from t1;
+a
+8
+3
+8
+drop table t1;
# End of 10.4 tests
diff --git a/mysql-test/main/brackets.test b/mysql-test/main/brackets.test
index cf1dcc5..9ca86b8 100644
--- a/mysql-test/main/brackets.test
+++ b/mysql-test/main/brackets.test
@@ -154,5 +154,27 @@ eval explain format=json $q;
drop table t1;
+--echo #
+--echo # MDEV-18689: parenthesis around table names and derived tables
+--echo #
+
+select * from ( mysql.db );
+
+create table t1 (a int);
+insert into t1 values (7), (2), (7);
+
+select * from (t1);
+select * from ((t1));
+select * from (t1 t) where t.a > 5;
+select * from ((t1 t)) where t.a > 5;
+
+select * from ((select a, sum(a) from t1 group by a) t);
+select * from (((select a, sum(a) from t1 group by a) t));
+
+update (t1 t) set t.a=t.a+1;
+select * from t1;
+
+drop table t1;
+
--echo # End of 10.4 tests
diff --git a/mysql-test/main/subselect.result b/mysql-test/main/subselect.result
index 3bd23a4..8c8c034 100644
--- a/mysql-test/main/subselect.result
+++ b/mysql-test/main/subselect.result
@@ -5198,17 +5198,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/main/subselect.test b/mysql-test/main/subselect.test
index dd80b78..82823b4 100644
--- a/mysql-test/main/subselect.test
+++ b/mysql-test/main/subselect.test
@@ -4325,14 +4325,10 @@ SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
--error ER_PARSE_ERROR
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
---error ER_PARSE_ERROR
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
---error ER_PARSE_ERROR
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
---error ER_PARSE_ERROR
SELECT * FROM (t1 t1a);
---error ER_PARSE_ERROR
SELECT * FROM ((t1 t1a));
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
diff --git a/mysql-test/main/subselect_no_exists_to_in.result b/mysql-test/main/subselect_no_exists_to_in.result
index bacba84..1bcc1a5 100644
--- a/mysql-test/main/subselect_no_exists_to_in.result
+++ b/mysql-test/main/subselect_no_exists_to_in.result
@@ -5200,17 +5200,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/main/subselect_no_mat.result b/mysql-test/main/subselect_no_mat.result
index a5b1d95..2876e19 100644
--- a/mysql-test/main/subselect_no_mat.result
+++ b/mysql-test/main/subselect_no_mat.result
@@ -5198,17 +5198,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/main/subselect_no_opts.result b/mysql-test/main/subselect_no_opts.result
index 0ea16d8..47f554a 100644
--- a/mysql-test/main/subselect_no_opts.result
+++ b/mysql-test/main/subselect_no_opts.result
@@ -5194,17 +5194,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/main/subselect_no_scache.result b/mysql-test/main/subselect_no_scache.result
index 196af2d..7096878 100644
--- a/mysql-test/main/subselect_no_scache.result
+++ b/mysql-test/main/subselect_no_scache.result
@@ -5204,17 +5204,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/main/subselect_no_semijoin.result b/mysql-test/main/subselect_no_semijoin.result
index c590a5d..3265a4f 100644
--- a/mysql-test/main/subselect_no_semijoin.result
+++ b/mysql-test/main/subselect_no_semijoin.result
@@ -5194,17 +5194,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/main/subselect_sj.test b/mysql-test/main/subselect_sj.test
index 22c9b2b..d735d85 100644
--- a/mysql-test/main/subselect_sj.test
+++ b/mysql-test/main/subselect_sj.test
@@ -1462,7 +1462,7 @@ INSERT IGNORE INTO t3 VALUES (0);
SELECT alias1.f11 AS field2
FROM ( t3 AS alias2 JOIN t1 AS alias3 ON alias3.f10 = 1)
-LEFT JOIN t2 AS alias1 ON alias3.f11 = 1
+LEFT JOIN ( t2 AS alias1 ) ON alias3.f11 = 1
WHERE alias2.f11 IN ( SELECT f11 FROM t2 )
GROUP BY field2 ;
diff --git a/mysql-test/main/subselect_sj_mat.test b/mysql-test/main/subselect_sj_mat.test
index ac0baee..c66ca57 100644
--- a/mysql-test/main/subselect_sj_mat.test
+++ b/mysql-test/main/subselect_sj_mat.test
@@ -1859,9 +1859,9 @@ drop database mysqltest4;
CREATE TABLE t1 (a INT NOT NULL) ENGINE=MyISAM;
INSERT INTO t1 VALUES (0),(8);
-SELECT a FROM (SELECT DISTINCT * FROM t1) AS sq WHERE a IN (SELECT MIN(t2.a) FROM t1 AS t2);
+SELECT a FROM (SELECT DISTINCT * FROM t1) AS sq WHERE a IN (SELECT MIN(t2.a) FROM (t1 AS t2));
PREPARE stmt FROM "
-SELECT a FROM (SELECT DISTINCT * FROM t1) AS sq WHERE a IN (SELECT MIN(t2.a) FROM t1 AS t2)
+SELECT a FROM (SELECT DISTINCT * FROM t1) AS sq WHERE a IN (SELECT MIN(t2.a) FROM (t1 AS t2))
";
execute stmt;
execute stmt;
diff --git a/mysql-test/main/union.test b/mysql-test/main/union.test
index 9d25708..ce52eba 100644
--- a/mysql-test/main/union.test
+++ b/mysql-test/main/union.test
@@ -1371,15 +1371,15 @@ SET @@global.slow_query_log= @old_slow_query_log;
CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int);
CREATE TABLE t3 (c int);
-SELECT a FROM t1 UNION SELECT b FROM t2 JOIN t3 ON ( t2.b = t3.c );
+SELECT a FROM t1 UNION SELECT b FROM t2 JOIN (t3) ON ( t2.b = t3.c );
DROP TABLE t1, t2, t3;
CREATE TABLE t1 (pk int NOT NULL);
CREATE TABLE t2 (pk int NOT NULL, fk int NOT NULL);
-SELECT t1.pk FROM t1 LEFT JOIN t2 ON (t1.pk = t2.fk)
+SELECT t1.pk FROM t1 LEFT JOIN (t2) ON (t1.pk = t2.fk)
UNION
-SELECT t1.pk FROM t1 LEFT JOIN t2 ON (t1.pk = t2.fk);
+SELECT t1.pk FROM t1 LEFT JOIN (t2) ON (t1.pk = t2.fk);
DROP TABLE t1,t2;
diff --git a/mysql-test/main/view.test b/mysql-test/main/view.test
index 2b7b9d1..ce8ac8d 100644
--- a/mysql-test/main/view.test
+++ b/mysql-test/main/view.test
@@ -4050,7 +4050,7 @@ CREATE OR REPLACE view v1 AS
;
SELECT 1
-FROM ( SELECT 1
+FROM (( SELECT 1
FROM t1 a_alias_1
LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1
LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1
@@ -4058,8 +4058,8 @@ FROM ( SELECT 1
LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1
LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1
LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1
-) t1
-LEFT OUTER JOIN ( SELECT 1
+) t1)
+LEFT OUTER JOIN (( SELECT 1
FROM t1 a_alias_1
LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1
LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1
@@ -4067,8 +4067,8 @@ LEFT OUTER JOIN ( SELECT 1
LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1
LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1
LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1
-) t2 ON 1=1
-LEFT OUTER JOIN ( SELECT 1
+) t2) ON 1=1
+LEFT OUTER JOIN (( SELECT 1
FROM t1 a_alias_1
LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1
LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1
@@ -4076,8 +4076,8 @@ LEFT OUTER JOIN ( SELECT 1
LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1
LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1
LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1
-) t3 ON 1=1
-LEFT OUTER JOIN ( SELECT 1
+) t3) ON 1=1
+LEFT OUTER JOIN (( SELECT 1
FROM t1 a_alias_1
LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1
LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1
@@ -4085,8 +4085,8 @@ LEFT OUTER JOIN ( SELECT 1
LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1
LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1
LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1
-) t4 ON 1=1
-LEFT OUTER JOIN ( SELECT 1
+) t4) ON 1=1
+LEFT OUTER JOIN (( SELECT 1
FROM t1 a_alias_1
LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1
LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1
@@ -4094,8 +4094,8 @@ LEFT OUTER JOIN ( SELECT 1
LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1
LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1
LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1
-) t5 ON 1=1
-LEFT OUTER JOIN ( SELECT 1
+) t5) ON 1=1
+LEFT OUTER JOIN (( SELECT 1
FROM t1 a_alias_1
LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1
LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1
@@ -4103,8 +4103,8 @@ LEFT OUTER JOIN ( SELECT 1
LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1
LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1
LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1
-) t6 ON 1=1
-LEFT OUTER JOIN ( SELECT 1
+) t6) ON 1=1
+LEFT OUTER JOIN (( SELECT 1
FROM t1 a_alias_1
LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1
LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1
@@ -4112,8 +4112,8 @@ LEFT OUTER JOIN ( SELECT 1
LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1
LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1
LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1
-) t7 ON 1=1
-LEFT OUTER JOIN ( SELECT 1
+) t7) ON 1=1
+LEFT OUTER JOIN (( SELECT 1
FROM t1 a_alias_1
LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1
LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1
@@ -4121,18 +4121,18 @@ LEFT OUTER JOIN ( SELECT 1
LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1
LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1
LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1
-) t8 ON 1=1
+) t8) ON 1=1
;
SELECT 1
-FROM v1 t1
-LEFT OUTER JOIN v1 t2 ON 1=1
-LEFT OUTER JOIN v1 t3 ON 1=1
-LEFT OUTER JOIN v1 t4 ON 1=1
-LEFT OUTER JOIN v1 t5 ON 1=1
-LEFT OUTER JOIN v1 t6 ON 1=1
-LEFT OUTER JOIN v1 t7 ON 1=1
-LEFT OUTER JOIN v1 t8 ON 1=1
+FROM (v1 t1)
+LEFT OUTER JOIN (v1 t2) ON 1=1
+LEFT OUTER JOIN (v1 t3) ON 1=1
+LEFT OUTER JOIN (v1 t4) ON 1=1
+LEFT OUTER JOIN (v1 t5) ON 1=1
+LEFT OUTER JOIN (v1 t6) ON 1=1
+LEFT OUTER JOIN (v1 t7) ON 1=1
+LEFT OUTER JOIN (v1 t8) ON 1=1
;
drop view v1;
diff --git a/mysql-test/suite/innodb/t/innodb.test b/mysql-test/suite/innodb/t/innodb.test
index 0062ba7..ab12cac 100644
--- a/mysql-test/suite/innodb/t/innodb.test
+++ b/mysql-test/suite/innodb/t/innodb.test
@@ -1253,7 +1253,7 @@ CREATE TABLE t2 (b_id tinyint(4) NOT NULL default '0',b_a tinyint(4) NOT NULL de
CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--enable_warnings
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
-SELECT * FROM (SELECT t1.*,GROUP_CONCAT(t2.b_id SEPARATOR ',') as b_list FROM (t1 LEFT JOIN t2 on t1.a_id = t2.b_a) GROUP BY t1.a_id ) AS xyz;
+SELECT * FROM (SELECT t1.*,GROUP_CONCAT(t2.b_id SEPARATOR ',') as b_list FROM (t1 LEFT JOIN (t2) on t1.a_id = t2.b_a) GROUP BY t1.a_id ) AS xyz;
DROP TABLE t2;
DROP TABLE t1;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index d09aa85..8057eeb 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1932,7 +1932,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
%type <table_list>
join_table_list join_table
table_factor table_ref esc_table_ref
- table_primary_ident table_primary_derived
+ table_primary_ident table_primary_ident_opt_parens
+ table_primary_derived table_primary_derived_opt_parens
derived_table_list table_reference_list_parens
nested_table_reference_list join_table_parens
update_table_list
@@ -12059,12 +12060,22 @@ use_partition:
;
table_factor:
- table_primary_ident { $$= $1; }
- | table_primary_derived { $$= $1; }
+ table_primary_ident_opt_parens { $$= $1; }
+ | table_primary_derived_opt_parens { $$= $1; }
| join_table_parens { $$= $1; }
| table_reference_list_parens { $$= $1; }
;
+table_primary_ident_opt_parens:
+ table_primary_ident { $$= $1; }
+ | '(' table_primary_ident_opt_parens ')' { $$= $2; }
+ ;
+
+table_primary_derived_opt_parens:
+ table_primary_derived { $$= $1; }
+ | '(' table_primary_derived_opt_parens ')' { $$= $2; }
+
+
table_reference_list_parens:
'(' table_reference_list_parens ')' { $$= $2; }
| '(' nested_table_reference_list ')'
1
0
[Commits] 6b39cab: MDEV-18689 Simple query with extra brackets stopped working
by IgorBabaev 06 May '19
by IgorBabaev 06 May '19
06 May '19
revision-id: 6b39cab178892a429128be4701b49c78b7b0fdab (mariadb-10.4.4-66-g6b39cab)
parent(s): d18ef804bb5d9d473055a2fdc04f74e175a8e9cd
author: Igor Babaev
committer: Igor Babaev
timestamp: 2019-05-05 19:59:21 -0700
message:
MDEV-18689 Simple query with extra brackets stopped working
Parenthesis around table names and derived tables should be allowed
in FROM clauses and some other context as it was in earlier versions.
Returned test queries that used such parenthesis in 10.3 to their
original form. Adjusted test results accordingly.
---
mysql-test/main/brackets.result | 42 ++++++++++++++++++++++++
mysql-test/main/brackets.test | 22 +++++++++++++
mysql-test/main/subselect.result | 24 ++++++++++----
mysql-test/main/subselect.test | 4 ---
mysql-test/main/subselect_no_exists_to_in.result | 24 ++++++++++----
mysql-test/main/subselect_no_mat.result | 24 ++++++++++----
mysql-test/main/subselect_no_opts.result | 24 ++++++++++----
mysql-test/main/subselect_no_scache.result | 24 ++++++++++----
mysql-test/main/subselect_no_semijoin.result | 24 ++++++++++----
mysql-test/suite/innodb/t/innodb.test | 2 +-
sql/sql_yacc.yy | 17 ++++++++--
11 files changed, 187 insertions(+), 44 deletions(-)
diff --git a/mysql-test/main/brackets.result b/mysql-test/main/brackets.result
index 869afe5..e14bef9 100644
--- a/mysql-test/main/brackets.result
+++ b/mysql-test/main/brackets.result
@@ -452,4 +452,46 @@ EXPLAIN
}
}
drop table t1;
+#
+# MDEV-18689: parenthesis around table names and derived tables
+#
+select * from ( mysql.db );
+Host Db User Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Grant_priv References_priv Index_priv Alter_priv Create_tmp_table_priv Lock_tables_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv Execute_priv Event_priv Trigger_priv Delete_history_priv
+% test Y Y Y Y Y Y N Y Y Y Y Y Y Y Y N N Y Y Y
+% test\_% Y Y Y Y Y Y N Y Y Y Y Y Y Y Y N N Y Y Y
+create table t1 (a int);
+insert into t1 values (7), (2), (7);
+select * from (t1);
+a
+7
+2
+7
+select * from ((t1));
+a
+7
+2
+7
+select * from (t1 t) where t.a > 5;
+a
+7
+7
+select * from ((t1 t)) where t.a > 5;
+a
+7
+7
+select * from ((select a, sum(a) from t1 group by a) t);
+a sum(a)
+2 2
+7 14
+select * from (((select a, sum(a) from t1 group by a) t));
+a sum(a)
+2 2
+7 14
+update (t1 t) set t.a=t.a+1;
+select * from t1;
+a
+8
+3
+8
+drop table t1;
# End of 10.4 tests
diff --git a/mysql-test/main/brackets.test b/mysql-test/main/brackets.test
index cf1dcc5..9ca86b8 100644
--- a/mysql-test/main/brackets.test
+++ b/mysql-test/main/brackets.test
@@ -154,5 +154,27 @@ eval explain format=json $q;
drop table t1;
+--echo #
+--echo # MDEV-18689: parenthesis around table names and derived tables
+--echo #
+
+select * from ( mysql.db );
+
+create table t1 (a int);
+insert into t1 values (7), (2), (7);
+
+select * from (t1);
+select * from ((t1));
+select * from (t1 t) where t.a > 5;
+select * from ((t1 t)) where t.a > 5;
+
+select * from ((select a, sum(a) from t1 group by a) t);
+select * from (((select a, sum(a) from t1 group by a) t));
+
+update (t1 t) set t.a=t.a+1;
+select * from t1;
+
+drop table t1;
+
--echo # End of 10.4 tests
diff --git a/mysql-test/main/subselect.result b/mysql-test/main/subselect.result
index 3bd23a4..8c8c034 100644
--- a/mysql-test/main/subselect.result
+++ b/mysql-test/main/subselect.result
@@ -5198,17 +5198,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/main/subselect.test b/mysql-test/main/subselect.test
index dd80b78..82823b4 100644
--- a/mysql-test/main/subselect.test
+++ b/mysql-test/main/subselect.test
@@ -4325,14 +4325,10 @@ SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
--error ER_PARSE_ERROR
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
---error ER_PARSE_ERROR
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
---error ER_PARSE_ERROR
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
---error ER_PARSE_ERROR
SELECT * FROM (t1 t1a);
---error ER_PARSE_ERROR
SELECT * FROM ((t1 t1a));
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
diff --git a/mysql-test/main/subselect_no_exists_to_in.result b/mysql-test/main/subselect_no_exists_to_in.result
index bacba84..1bcc1a5 100644
--- a/mysql-test/main/subselect_no_exists_to_in.result
+++ b/mysql-test/main/subselect_no_exists_to_in.result
@@ -5200,17 +5200,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/main/subselect_no_mat.result b/mysql-test/main/subselect_no_mat.result
index a5b1d95..2876e19 100644
--- a/mysql-test/main/subselect_no_mat.result
+++ b/mysql-test/main/subselect_no_mat.result
@@ -5198,17 +5198,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/main/subselect_no_opts.result b/mysql-test/main/subselect_no_opts.result
index 0ea16d8..47f554a 100644
--- a/mysql-test/main/subselect_no_opts.result
+++ b/mysql-test/main/subselect_no_opts.result
@@ -5194,17 +5194,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/main/subselect_no_scache.result b/mysql-test/main/subselect_no_scache.result
index 196af2d..7096878 100644
--- a/mysql-test/main/subselect_no_scache.result
+++ b/mysql-test/main/subselect_no_scache.result
@@ -5204,17 +5204,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/main/subselect_no_semijoin.result b/mysql-test/main/subselect_no_semijoin.result
index c590a5d..3265a4f 100644
--- a/mysql-test/main/subselect_no_semijoin.result
+++ b/mysql-test/main/subselect_no_semijoin.result
@@ -5194,17 +5194,29 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT 1)) ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) t1a ON 1' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1a ON 1' at line 1
SELECT * FROM t1 JOIN (t1 t1a) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ON 1' at line 1
+a a
+1 1
+2 1
+1 2
+2 2
SELECT * FROM (t1 t1a);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+a
+1
+2
SELECT * FROM ((t1 t1a));
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
+a
+1
+2
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1;
a t1a
1 1
diff --git a/mysql-test/suite/innodb/t/innodb.test b/mysql-test/suite/innodb/t/innodb.test
index 0062ba7..ab12cac 100644
--- a/mysql-test/suite/innodb/t/innodb.test
+++ b/mysql-test/suite/innodb/t/innodb.test
@@ -1253,7 +1253,7 @@ CREATE TABLE t2 (b_id tinyint(4) NOT NULL default '0',b_a tinyint(4) NOT NULL de
CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--enable_warnings
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
-SELECT * FROM (SELECT t1.*,GROUP_CONCAT(t2.b_id SEPARATOR ',') as b_list FROM (t1 LEFT JOIN t2 on t1.a_id = t2.b_a) GROUP BY t1.a_id ) AS xyz;
+SELECT * FROM (SELECT t1.*,GROUP_CONCAT(t2.b_id SEPARATOR ',') as b_list FROM (t1 LEFT JOIN (t2) on t1.a_id = t2.b_a) GROUP BY t1.a_id ) AS xyz;
DROP TABLE t2;
DROP TABLE t1;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index d09aa85..8057eeb 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1932,7 +1932,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
%type <table_list>
join_table_list join_table
table_factor table_ref esc_table_ref
- table_primary_ident table_primary_derived
+ table_primary_ident table_primary_ident_opt_parens
+ table_primary_derived table_primary_derived_opt_parens
derived_table_list table_reference_list_parens
nested_table_reference_list join_table_parens
update_table_list
@@ -12059,12 +12060,22 @@ use_partition:
;
table_factor:
- table_primary_ident { $$= $1; }
- | table_primary_derived { $$= $1; }
+ table_primary_ident_opt_parens { $$= $1; }
+ | table_primary_derived_opt_parens { $$= $1; }
| join_table_parens { $$= $1; }
| table_reference_list_parens { $$= $1; }
;
+table_primary_ident_opt_parens:
+ table_primary_ident { $$= $1; }
+ | '(' table_primary_ident_opt_parens ')' { $$= $2; }
+ ;
+
+table_primary_derived_opt_parens:
+ table_primary_derived { $$= $1; }
+ | '(' table_primary_derived_opt_parens ')' { $$= $2; }
+
+
table_reference_list_parens:
'(' table_reference_list_parens ')' { $$= $2; }
| '(' nested_table_reference_list ')'
1
0
revision-id: 54d0a55adf6fbfc92c5473bbcad2b459f14ef038 (mariadb-10.2.23-116-g54d0a55adf6)
parent(s): ad53218a9d173131f1ea941a2686c7f78e345c92
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2019-05-05 20:06:29 +0200
message:
fix of results
---
storage/connect/mysql-test/connect/r/xml.result | 98 ++++++++++++-------------
1 file changed, 49 insertions(+), 49 deletions(-)
diff --git a/storage/connect/mysql-test/connect/r/xml.result b/storage/connect/mysql-test/connect/r/xml.result
index c4635ba053e..6a0c9db27b3 100644
--- a/storage/connect/mysql-test/connect/r/xml.result
+++ b/storage/connect/mysql-test/connect/r/xml.result
@@ -158,47 +158,47 @@ TRANSLATOR NULL
PUBLISHER Eyrolles Paris
DATEPUB 1998
SELECT LOAD_FILE('MYSQLD_DATADIR/test/xsample2.xml') AS xml;
-xml <?xml version="1.0" encoding="UTF-8"?>
-<BIBLIO SUBJECT="XML">
- <BOOK ISBN="9782212090819" LANG="fr" SUBJECT="applications">
- <AUTHOR>
- <FIRSTNAME>Jean-Christophe</FIRSTNAME>
- <LASTNAME>Bernadac</LASTNAME>
- </AUTHOR>
- <AUTHOR>
- <FIRSTNAME>François</FIRSTNAME>
- <LASTNAME>Knab</LASTNAME>
- </AUTHOR>
- <TITLE>Construire une application XML</TITLE>
- <PUBLISHER>
- <NAME>Eyrolles</NAME>
- <PLACE>Paris</PLACE>
- </PUBLISHER>
- <DATEPUB>1999</DATEPUB>
- </BOOK>
- <BOOK ISBN="9782840825685" LANG="fr" SUBJECT="applications">
- <AUTHOR>
- <FIRSTNAME>William J.</FIRSTNAME>
- <LASTNAME>Pardi</LASTNAME>
- </AUTHOR>
- <TRANSLATOR PREFIX="adapté de l'anglais par">
- <FIRSTNAME>James</FIRSTNAME>
- <LASTNAME>Guerin</LASTNAME>
- </TRANSLATOR>
- <TITLE>XML en Action</TITLE>
- <PUBLISHER>
- <NAME>Microsoft Press</NAME>
- <PLACE>Paris</PLACE>
- </PUBLISHER>
- <DATEPUB>1999</DATEPUB>
- </BOOK>
- <BOOK ISBN="9782212090529" LANG="fr" SUBJECT="général">
- <AUTHOR>Alain Michard</AUTHOR>
- <TITLE>XML, Langage et Applications</TITLE>
- <PUBLISHER>Eyrolles Paris</PUBLISHER>
- <DATEPUB>1998</DATEPUB>
- </BOOK>
-</BIBLIO>
+xml <?xml version="1.0" encoding="UTF-8"?>
+<BIBLIO SUBJECT="XML">
+ <BOOK ISBN="9782212090819" LANG="fr" SUBJECT="applications">
+ <AUTHOR>
+ <FIRSTNAME>Jean-Christophe</FIRSTNAME>
+ <LASTNAME>Bernadac</LASTNAME>
+ </AUTHOR>
+ <AUTHOR>
+ <FIRSTNAME>François</FIRSTNAME>
+ <LASTNAME>Knab</LASTNAME>
+ </AUTHOR>
+ <TITLE>Construire une application XML</TITLE>
+ <PUBLISHER>
+ <NAME>Eyrolles</NAME>
+ <PLACE>Paris</PLACE>
+ </PUBLISHER>
+ <DATEPUB>1999</DATEPUB>
+ </BOOK>
+ <BOOK ISBN="9782840825685" LANG="fr" SUBJECT="applications">
+ <AUTHOR>
+ <FIRSTNAME>William J.</FIRSTNAME>
+ <LASTNAME>Pardi</LASTNAME>
+ </AUTHOR>
+ <TRANSLATOR PREFIX="adapté de l'anglais par">
+ <FIRSTNAME>James</FIRSTNAME>
+ <LASTNAME>Guerin</LASTNAME>
+ </TRANSLATOR>
+ <TITLE>XML en Action</TITLE>
+ <PUBLISHER>
+ <NAME>Microsoft Press</NAME>
+ <PLACE>Paris</PLACE>
+ </PUBLISHER>
+ <DATEPUB>1999</DATEPUB>
+ </BOOK>
+ <BOOK ISBN="9782212090529" LANG="fr" SUBJECT="général">
+ <AUTHOR>Alain Michard</AUTHOR>
+ <TITLE>XML, Langage et Applications</TITLE>
+ <PUBLISHER>Eyrolles Paris</PUBLISHER>
+ <DATEPUB>1998</DATEPUB>
+ </BOOK>
+</BIBLIO>
DROP TABLE t1;
#
@@ -374,7 +374,7 @@ INSERT INTO t1 VALUES (_cp1251 0xC0C1C2C3);
Warnings:
Level Warning
Code 1105
-Message Com error: Unable to save character to 'iso-8859-1' encoding.
+Message Com error: Unable to save character to 'iso-8859-1' encoding.
INSERT INTO t1 VALUES ('&<>"\'');
SELECT node, hex(node) FROM t1;
@@ -383,11 +383,11 @@ hex(node) 263C3E2227
DROP TABLE t1;
SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml');
SELECT CAST(@a AS CHAR CHARACTER SET latin1);
-CAST(@a AS CHAR CHARACTER SET latin1) <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- Created by the MariaDB CONNECT Storage Engine-->
-<t1>
- <line>
- <node>&<>"'</node>
- </line>
-</t1>
+CAST(@a AS CHAR CHARACTER SET latin1) <?xml version="1.0" encoding="iso-8859-1"?>
+<!-- Created by the MariaDB CONNECT Storage Engine-->
+<t1>
+ <line>
+ <node>&<>"'</node>
+ </line>
+</t1>
1
0
[Commits] ad53218a9d1: Merge remote-tracking branch 'connect/10.2' into 10.2
by Oleksandr Byelkin 05 May '19
by Oleksandr Byelkin 05 May '19
05 May '19
revision-id: ad53218a9d173131f1ea941a2686c7f78e345c92 (mariadb-10.2.23-115-gad53218a9d1)
parent(s): 409aba76ee98027010c7178daa6aa6f66c9f58ab 4e583a276fa0efe67f0185604b062668db707af0
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2019-05-05 09:15:47 +0200
message:
Merge remote-tracking branch 'connect/10.2' into 10.2
storage/connect/ha_connect.cc | 3 -
storage/connect/mysql-test/connect/r/xml.result | 98 ++++++++++++-------------
2 files changed, 49 insertions(+), 52 deletions(-)
1
0
[Commits] 2482867f844: MDEV-19134: EXISTS() slower if ORDER BY is defined
by Sergei Petrunia 04 May '19
by Sergei Petrunia 04 May '19
04 May '19
revision-id: 2482867f844eef0648533089181d678a3f157b2f (mariadb-10.4.4-37-g2482867f844)
parent(s): baadbe96019b205164167928d80e836ebbb6bcfe
author: Sergei Petrunia
committer: Sergei Petrunia
timestamp: 2019-05-04 21:49:50 +0300
message:
MDEV-19134: EXISTS() slower if ORDER BY is defined
Step 1: Removal of ORDER BY [LIMIT] from the subquery should be done
earlier and for broader class of subqueries.
The rewrite was done in Item_in_subselect::select_in_like_transformer(),
but this had problems:
- It didn't cover EXISTS subqueries
- It covered IN-subqueries, but was done after the semi-join transformation
was considered inapplicable, because ORDER BY was present.
Remaining issue:
- EXISTS->IN transformation happens before
check_and_do_in_subquery_rewrites() is called, so it is still prevented
by the present ORDER BY.
---
mysql-test/main/subselect4.result | 25 ++++++++++++++++++++++++-
mysql-test/main/subselect4.test | 24 ++++++++++++++++++++++++
mysql-test/main/subselect_innodb.result | 4 ++--
mysql-test/main/subselect_mat_cost_bugs.result | 2 +-
mysql-test/main/subselect_sj_mat.result | 18 +++++++-----------
mysql-test/main/subselect_sj_mat.test | 1 +
mysql-test/main/union.result | 2 +-
sql/item_subselect.cc | 15 ---------------
sql/opt_subselect.cc | 23 ++++++++++++++++++++++-
9 files changed, 82 insertions(+), 32 deletions(-)
diff --git a/mysql-test/main/subselect4.result b/mysql-test/main/subselect4.result
index bd9ecdc642b..05f65b4f550 100644
--- a/mysql-test/main/subselect4.result
+++ b/mysql-test/main/subselect4.result
@@ -2256,7 +2256,7 @@ SELECT a3 FROM t3 WHERE b2 = b1 AND b2 <= b1 ORDER BY b3
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
-3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT * FROM t1 WHERE a1 IN (
SELECT a2 FROM t2 WHERE a2 IN (
SELECT a3 FROM t3 WHERE b2 = b1 AND b2 <= b1 ORDER BY b3
@@ -2534,3 +2534,26 @@ x
c1
1
drop table t1;
+#
+# MDEV-19134: EXISTS() slower if ORDER BY is defined
+#
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1(a int, b int);
+insert into t1 select
+A.a + B.a*10, A.a + B.a*10 from t0 A, t0 B;
+create table t2 as select * from t1;
+# This will not be able to convert to semi-join but will not require filesort:
+explain
+select * from t1 where exists (select * from t2 where t2.a=t1.a order by t2.b);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL # Using where
+# This will be merged and converted into a semi-join:
+explain
+select * from t1 where t1.a in (select t2.a from t2 order by t2.b);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 100
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 100
+drop table t0, t1, t2;
diff --git a/mysql-test/main/subselect4.test b/mysql-test/main/subselect4.test
index d5a40419185..5c5dd797353 100644
--- a/mysql-test/main/subselect4.test
+++ b/mysql-test/main/subselect4.test
@@ -2075,3 +2075,27 @@ insert into t1 values(2,1),(1,2);
select (select c1 from t1 group by c1,c2 order by c1 limit 1) as x;
(select c1 from t1 group by c1,c2 order by c1 limit 1);
drop table t1;
+
+--echo #
+--echo # MDEV-19134: EXISTS() slower if ORDER BY is defined
+--echo #
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t1(a int, b int);
+insert into t1 select
+ A.a + B.a*10, A.a + B.a*10 from t0 A, t0 B;
+
+create table t2 as select * from t1;
+
+--echo # This will not be able to convert to semi-join but will not require filesort:
+--replace_column 9 #
+explain
+select * from t1 where exists (select * from t2 where t2.a=t1.a order by t2.b);
+
+--echo # This will be merged and converted into a semi-join:
+explain
+select * from t1 where t1.a in (select t2.a from t2 order by t2.b);
+
+drop table t0, t1, t2;
+
diff --git a/mysql-test/main/subselect_innodb.result b/mysql-test/main/subselect_innodb.result
index 8e09be9b705..c0181451f66 100644
--- a/mysql-test/main/subselect_innodb.result
+++ b/mysql-test/main/subselect_innodb.result
@@ -458,7 +458,7 @@ EXPLAIN
SELECT * FROM t1 WHERE EXISTS ( SELECT b FROM t2, t3 GROUP BY b HAVING b != 3 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
-2 SUBQUERY t2 index PRIMARY PRIMARY 4 NULL 1 Using where; Using index; Using temporary; Using filesort
+2 SUBQUERY t2 index PRIMARY PRIMARY 4 NULL 1 Using where; Using index; Using temporary
2 SUBQUERY t3 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join)
SELECT * FROM t1 WHERE EXISTS ( SELECT b FROM t2, t3 GROUP BY b HAVING b != 3 );
a
@@ -480,7 +480,7 @@ HAVING SQ2_alias1 . col_int_key >= 7
);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
-2 SUBQUERY SQ2_alias2 index NULL col_int_key 5 NULL 1 Using index; Using temporary; Using filesort
+2 SUBQUERY SQ2_alias2 index NULL col_int_key 5 NULL 1 Using index; Using temporary
2 SUBQUERY SQ2_alias1 ref col_int_key col_int_key 5 test.SQ2_alias2.col_int_key 1 Using where; Using index
SELECT 1 FROM t1 AS alias1
WHERE EXISTS ( SELECT SQ2_alias1 . col_int_key AS SQ2_field1
diff --git a/mysql-test/main/subselect_mat_cost_bugs.result b/mysql-test/main/subselect_mat_cost_bugs.result
index 2c696ed36fd..a18c5e608f1 100644
--- a/mysql-test/main/subselect_mat_cost_bugs.result
+++ b/mysql-test/main/subselect_mat_cost_bugs.result
@@ -148,7 +148,7 @@ FROM t2 GROUP BY f1
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 SUBQUERY t1 system NULL NULL NULL NULL 1
-3 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
+3 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using temporary
drop table t1, t2, t3;
#
# LP BUG#715034 Item_sum_distinct::clear(): Assertion `tree != 0' failed
diff --git a/mysql-test/main/subselect_sj_mat.result b/mysql-test/main/subselect_sj_mat.result
index 3fc8f9afd3e..53afa90ca73 100644
--- a/mysql-test/main/subselect_sj_mat.result
+++ b/mysql-test/main/subselect_sj_mat.result
@@ -265,11 +265,11 @@ set @@optimizer_switch=@save_optimizer_switch;
explain extended
select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 16 test.t1.a1,test.t1.a2 1 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 16 func,func 1 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` order by `test`.`t2`.`b1`,`test`.`t2`.`b2`) join `test`.`t1` where `<subquery2>`.`b1` = `test`.`t1`.`a1` and `<subquery2>`.`b2` = `test`.`t1`.`a2`
+Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) where 1
select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
a1 a2
1 - 01 2 - 01
@@ -277,11 +277,10 @@ a1 a2
explain extended
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1i index it1i1,it1i2,it1i3 it1i3 18 NULL 3 100.00 Using where; Using index
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 16 test.t1i.a1,test.t1i.a2 1 100.00
-2 MATERIALIZED t2i index NULL it2i3 18 NULL 5 100.00 Using index
+1 PRIMARY t2i index it2i1,it2i2,it2i3 it2i3 18 NULL 5 50.00 Using where; Using index; LooseScan
+1 PRIMARY t1i ref it1i1,it1i2,it1i3 it1i3 18 test.t2i.b1,test.t2i.b2 1 100.00 Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` order by `test`.`t2i`.`b1`,`test`.`t2i`.`b2`) join `test`.`t1i` where `<subquery2>`.`b1` = `test`.`t1i`.`a1` and `<subquery2>`.`b2` = `test`.`t1i`.`a2`
+Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2`
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
a1 a2
1 - 01 2 - 01
@@ -1472,10 +1471,7 @@ INSERT INTO t2 VALUES (10,0),(11,0);
explain SELECT * FROM t1 JOIN t2 USING (f1)
WHERE t1.f1 IN (SELECT t1.pk FROM t1 ORDER BY t1.f1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 system NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 const 1
-1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
-2 MATERIALIZED t1 system NULL NULL NULL NULL 1
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
SELECT * FROM t1 JOIN t2 USING (f1)
WHERE t1.f1 IN (SELECT t1.pk FROM t1 ORDER BY t1.f1);
f1 pk pk
diff --git a/mysql-test/main/subselect_sj_mat.test b/mysql-test/main/subselect_sj_mat.test
index ac0baee3728..74d670bcf61 100644
--- a/mysql-test/main/subselect_sj_mat.test
+++ b/mysql-test/main/subselect_sj_mat.test
@@ -161,6 +161,7 @@ execute st1;
set @@optimizer_switch=@save_optimizer_switch;
# materialize the result of ORDER BY
+# No longer really happens as the optimizer is now smart enough not to sort in this case
# non-indexed fields
explain extended
select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
diff --git a/mysql-test/main/union.result b/mysql-test/main/union.result
index a0421bae922..00df8e9533d 100644
--- a/mysql-test/main/union.result
+++ b/mysql-test/main/union.result
@@ -2049,7 +2049,7 @@ insert t1 values (1),(2),(3),(1);
explain select 1 from dual where exists (select max(a) from t1 group by a union select a+2 from t1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
-2 SUBQUERY t1 ALL NULL NULL NULL NULL 4 Using temporary; Using filesort
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 4 Using temporary
3 UNION t1 ALL NULL NULL NULL NULL 4
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
drop table t1;
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 2b1c4c174c7..531ce763d86 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -3204,21 +3204,6 @@ Item_in_subselect::select_in_like_transformer(JOIN *join)
DBUG_ENTER("Item_in_subselect::select_in_like_transformer");
DBUG_ASSERT(thd == join->thd);
-
- /*
- IN/SOME/ALL/ANY subqueries aren't support LIMIT clause. Without it
- ORDER BY clause becomes meaningless thus we drop it here.
- */
- for (SELECT_LEX *sl= current->master_unit()->first_select();
- sl; sl= sl->next_select())
- {
- if (sl->join)
- {
- sl->join->order= 0;
- sl->join->skip_sort_order= 1;
- }
- }
-
thd->where= "IN/ALL/ANY subquery";
/*
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index 2fedd8a4ed3..809c9378569 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -594,7 +594,8 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
{
Item_in_subselect *in_subs= NULL;
Item_allany_subselect *allany_subs= NULL;
- switch (subselect->substype()) {
+ Item_subselect::subs_type substype= subselect->substype();
+ switch (substype) {
case Item_subselect::IN_SUBS:
in_subs= (Item_in_subselect *)subselect;
break;
@@ -606,6 +607,26 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
break;
}
+ /*
+ Try removing "ORDER BY" or even "ORDER BY ... LIMIT" from certain kinds
+ of subqueries. The removal might enable further transformations.
+ */
+ if (substype == Item_subselect::IN_SUBS ||
+ substype == Item_subselect::EXISTS_SUBS ||
+ substype == Item_subselect::ANY_SUBS ||
+ substype == Item_subselect::ALL_SUBS)
+ {
+ // (1) - ORDER BY without LIMIT can be removed from IN/EXISTS subqueries
+ // (2) - for EXISTS, can also remove "ORDER BY ... LIMIT n",
+ // but cannot remove "ORDER BY ... LIMIT n OFFSET m"
+ if (!select_lex->select_limit || // (1)
+ (substype == Item_subselect::EXISTS_SUBS && // (2)
+ !select_lex->offset_limit)) // (2)
+ {
+ select_lex->join->order= 0;
+ select_lex->join->skip_sort_order= 1;
+ }
+ }
/* Resolve expressions and perform semantic analysis for IN query */
if (in_subs != NULL)
1
0
revision-id: 409aba76ee98027010c7178daa6aa6f66c9f58ab (mariadb-10.2.23-114-g409aba76ee9)
parent(s): 8cbb14ef5d180687f131bc44a4e8fc84083d033c
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2019-05-04 17:06:19 +0200
message:
update Connector C
---
libmariadb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libmariadb b/libmariadb
index b5087161176..bce6c801380 160000
--- a/libmariadb
+++ b/libmariadb
@@ -1 +1 @@
-Subproject commit b50871611764d282874ad095d6c021163d1fe354
+Subproject commit bce6c8013805f203b38e52c979b22b3141334f3c
1
0
revision-id: 8cbb14ef5d180687f131bc44a4e8fc84083d033c (mariadb-10.2.23-113-g8cbb14ef5d1)
parent(s): 4345868382ca3525de5eb432302b6b9b957b47c1 b85aa20065504bdda4bc03c2bd7eb7de38865c5d
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2019-05-04 17:04:55 +0200
message:
Merge branch '10.1' into 10.2
client/mysql_plugin.c | 8 +-
client/mysqldump.c | 63 +++++-----
debian/autobake-deb.sh | 3 +-
...41_scripts__mysql_install_db.sh__no_test.dpatch | 21 ++--
include/my_tree.h | 2 +-
mysql-test/include/ctype_like_escape.inc | 6 +
mysql-test/lib/generate-ssl-certs.sh | 2 +-
mysql-test/mysql-test-run.pl | 4 +
mysql-test/r/create_drop_binlog.result | 4 +
mysql-test/r/create_drop_event.result | 5 +
mysql-test/r/ctype_big5.result | 12 ++
mysql-test/r/ctype_euckr.result | 12 ++
mysql-test/r/ctype_gb2312.result | 12 ++
mysql-test/r/ctype_gbk.result | 12 ++
mysql-test/r/ctype_latin1.result | 12 ++
mysql-test/r/ctype_sjis.result | 12 ++
mysql-test/r/ctype_tis620.result | 12 ++
mysql-test/r/ctype_uca.result | 6 +
mysql-test/r/ctype_ucs.result | 12 ++
mysql-test/r/ctype_ujis.result | 12 ++
mysql-test/r/ctype_utf16.result | 12 ++
mysql-test/r/ctype_utf16_uca.result | 6 +
mysql-test/r/ctype_utf16le.result | 12 ++
mysql-test/r/ctype_utf32.result | 12 ++
mysql-test/r/ctype_utf32_uca.result | 6 +
mysql-test/r/ctype_utf8.result | 12 ++
mysql-test/r/ctype_utf8mb4.result | 12 ++
mysql-test/r/ctype_utf8mb4_heap.result | 12 ++
mysql-test/r/ctype_utf8mb4_innodb.result | 12 ++
mysql-test/r/ctype_utf8mb4_myisam.result | 12 ++
mysql-test/r/ddl_i18n_koi8r.result | 8 ++
mysql-test/r/ddl_i18n_utf8.result | 8 ++
mysql-test/r/events_1.result | 68 +++++++++++
mysql-test/r/events_2.result | 30 +++++
mysql-test/r/events_bugs.result | 54 ++++++++
mysql-test/r/events_grant.result | 10 ++
mysql-test/r/events_restart.result | 26 ++--
mysql-test/r/events_trans.result | 9 ++
mysql-test/r/flush_read_lock.result | 2 +
mysql-test/r/func_gconcat.result | 30 ++++-
mysql-test/r/func_hybrid_type.result | 40 +++++-
mysql-test/r/func_str.result | 38 ++++++
mysql-test/r/gis.result | 38 ++++++
mysql-test/r/gis2.result | 38 ------
mysql-test/r/gis_notembedded.result | 45 +++++++
mysql-test/r/grant4.result | 21 ++++
mysql-test/r/information_schema_prepare.result | 4 +
mysql-test/r/lock_sync.result | 4 +
mysql-test/r/mdev_19276.result | 11 ++
mysql-test/r/multi_update.result | 23 ++++
...ulti_update2.result => multi_update_big.result} | 0
mysql-test/r/mysqldump-compat.result | 4 +
mysql-test/r/mysqldump.result | 16 +++
mysql-test/r/partition_innodb.result | 42 +++++++
mysql-test/r/ps.result | 23 ++++
mysql-test/r/show_check.result | 4 +
mysql-test/r/sp_notembedded.result | 2 +
mysql-test/r/ssl_verify_ip.result | 4 +
mysql-test/r/stat_tables.result | 18 +++
mysql-test/r/stat_tables_innodb.result | 18 +++
mysql-test/r/statistics.result | 14 +++
mysql-test/r/status2.result | 4 +-
mysql-test/r/timezone2.result | 33 +++++
mysql-test/r/type_bit.result | 7 ++
mysql-test/r/view_grant.result | 4 +
mysql-test/std_data/serversan-cert.pem | 110 ++++++++---------
mysql-test/std_data/serversan-key.pem | 52 ++++----
mysql-test/suite.pm | 5 +
mysql-test/suite/binlog/r/binlog_mdev717.result | 2 +
mysql-test/suite/binlog/r/binlog_sql_mode.result | 2 +
.../suite/funcs_1/r/is_routines_embedded.result | 12 ++
mysql-test/suite/galera/r/galera_events.result | 2 +
mysql-test/suite/innodb/r/innodb-index.result | 27 ++++
mysql-test/suite/innodb/r/innodb-truncate.result | 13 ++
mysql-test/suite/innodb/r/xa_debug.result | 1 +
mysql-test/suite/innodb/t/innodb-index.test | 20 +++
mysql-test/suite/innodb/t/innodb-truncate.test | 19 +++
mysql-test/suite/innodb/t/xa_debug.test | 1 +
.../suite/perfschema/r/pfs_upgrade_event.result | 2 +
mysql-test/suite/plugins/r/pam.result | 20 +++
mysql-test/suite/plugins/t/pam.test | 24 +++-
mysql-test/suite/rpl/r/kill_race_condition.result | 18 +++
.../suite/rpl/r/rpl_create_drop_event.result | 4 +
mysql-test/suite/rpl/r/rpl_current_user.result | 2 +
mysql-test/suite/rpl/r/rpl_events.result | 6 +
mysql-test/suite/rpl/r/rpl_heartbeat_basic.result | 2 +
mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result | 2 +
mysql-test/suite/rpl/r/rpl_invoked_features.result | 4 +
mysql-test/suite/rpl/r/rpl_killed_ddl.result | 2 +
.../rpl/r/rpl_mixed_implicit_commit_binlog.result | 2 +
.../rpl/r/rpl_row_implicit_commit_binlog.result | 2 +
.../rpl/r/rpl_stm_implicit_commit_binlog.result | 2 +
.../suite/rpl/r/rpl_tmp_table_and_DDL.result | 4 +
mysql-test/suite/rpl/t/kill_race_condition.test | 28 +++++
.../r/sysvars_innodb,32bit,xtradb.rdiff-disabled | 4 +-
.../r/sysvars_innodb,xtradb.rdiff-disabled | 4 +-
.../t/transaction_prealloc_size_bug27322.test | 9 +-
mysql-test/t/bootstrap.test | 9 ++
mysql-test/t/events_stress.test | 1 +
mysql-test/t/func_gconcat.test | 33 ++++-
mysql-test/t/func_hybrid_type.test | 20 +++
mysql-test/t/func_str.test | 36 ++++++
mysql-test/t/gis.test | 47 +++++++
mysql-test/t/gis2.test | 45 -------
mysql-test/t/gis_notembedded.test | 24 ++++
mysql-test/t/grant4.test | 31 ++++-
mysql-test/t/information_schema_prepare.test | 7 ++
mysql-test/t/mdev_19276.test | 17 +++
mysql-test/t/multi_update.test | 31 +++++
...lti_update2-master.opt => multi_update_big.opt} | 0
.../{multi_update2.test => multi_update_big.test} | 0
mysql-test/t/mysqldump-compat.test | 13 ++
mysql-test/t/partition_innodb.test | 25 ++++
mysql-test/t/ps.test | 16 +++
mysql-test/t/ssl_verify_ip.opt | 3 +
mysql-test/t/ssl_verify_ip.test | 3 +
mysql-test/t/stat_tables.test | 21 ++++
mysql-test/t/statistics.test | 15 +++
mysql-test/t/status2.test | 4 +-
mysql-test/t/timezone2.test | 31 +++++
mysql-test/t/type_bit.test | 9 ++
mysql-test/t/view_grant.test | 5 +
mysys/tree.c | 48 ++++----
pcre/AUTHORS | 6 +-
pcre/ChangeLog | 43 +++++++
pcre/LICENCE | 10 +-
pcre/NEWS | 10 ++
pcre/configure.ac | 10 +-
pcre/pcre_compile.c | 18 ++-
pcre/pcre_jit_compile.c | 2 +-
pcre/pcrecpp.cc | 64 +++++++++-
pcre/pcrecpp_unittest.cc | 34 +++++-
pcre/pcregrep.c | 4 +-
pcre/testdata/testinput1 | 15 +++
pcre/testdata/testinput2 | 3 +
pcre/testdata/testinput4 | 3 +
pcre/testdata/testoutput1 | 24 ++++
pcre/testdata/testoutput2 | 4 +
pcre/testdata/testoutput4 | 4 +
plugin/auth_pam/auth_pam.c | 10 +-
scripts/maria_add_gis_sp.sql.in | 4 +-
scripts/mysql_install_db.sh | 8 +-
sql-common/client.c | 6 +-
sql/events.cc | 6 +
sql/field.cc | 2 +-
sql/gen_win_tzname_data.ps1 | 11 ++
sql/ha_partition.cc | 11 +-
sql/handler.h | 5 +-
sql/item_func.cc | 6 +-
sql/item_sum.cc | 93 +++++++++++++-
sql/item_sum.h | 9 +-
sql/log_event.cc | 23 ++--
sql/log_event_old.cc | 19 ++-
sql/mysqld.cc | 48 ++++++--
sql/share/errmsg-utf8.txt | 4 +-
sql/sql_acl.cc | 33 ++++-
sql/sql_base.cc | 95 +++++++-------
sql/sql_base.h | 17 ++-
sql/sql_class.cc | 1 +
sql/sql_class.h | 1 +
sql/sql_db.cc | 20 +--
sql/sql_db.h | 2 +-
sql/sql_lex.h | 4 +-
sql/sql_parse.cc | 16 ++-
sql/sql_select.cc | 18 +--
sql/sql_show.cc | 10 +-
sql/sql_statistics.cc | 20 ++-
sql/sql_string.cc | 21 ++++
sql/sql_truncate.cc | 14 +--
sql/sql_update.cc | 36 +++++-
sql/sql_view.cc | 3 +-
sql/sql_yacc.yy | 37 +++---
sql/table.cc | 3 +-
sql/table.h | 1 +
sql/win_tzname_data.h | 136 +++++++++++++++++++++
storage/connect/filter.h | 1 +
storage/connect/ha_connect.cc | 81 ++++++------
storage/connect/ha_connect.h | 3 +-
storage/connect/jmgoconn.cpp | 4 +-
storage/connect/tabdos.cpp | 42 ++++---
storage/connect/tabfmt.cpp | 13 +-
storage/connect/user_connect.cc | 3 +-
storage/connect/value.cpp | 97 +++++++--------
storage/connect/value.h | 16 +--
storage/innobase/dict/dict0stats.cc | 4 +-
storage/innobase/handler/handler0alter.cc | 21 +++-
storage/innobase/include/handler0alter.h | 11 +-
storage/tokudb/.clang-format | 40 ++++++
storage/tokudb/ha_tokudb.cc | 28 +++--
storage/tokudb/ha_tokudb.h | 2 +-
storage/tokudb/ha_tokudb_mrr_mysql.cc | 1 +
.../mysql-test/rpl/r/rpl_tokudb_mixed_dml.result | 2 +
.../tokudb/mysql-test/tokudb_bugs/r/PS-5158.result | 6 +
.../tokudb/mysql-test/tokudb_bugs/r/PS-5163.result | 5 +
.../mysql-test/tokudb_bugs/t/PS-5158-master.opt | 2 +
.../tokudb/mysql-test/tokudb_bugs/t/PS-5158.test | 27 ++++
.../tokudb/mysql-test/tokudb_bugs/t/PS-5163.test | 11 ++
storage/xtradb/dict/dict0stats.cc | 5 +-
storage/xtradb/handler/ha_innodb.cc | 4 +-
storage/xtradb/handler/handler0alter.cc | 21 +++-
storage/xtradb/include/handler0alter.h | 11 +-
storage/xtradb/include/univ.i | 4 +-
support-files/rpm/server-postin.sh | 7 +-
support-files/rpm/server-posttrans.sh | 7 +-
support-files/rpm/server-preun.sh | 18 +--
205 files changed, 2788 insertions(+), 657 deletions(-)
diff --cc debian/autobake-deb.sh
index 1a43c064468,98071ba6d03..687f2356153
--- a/debian/autobake-deb.sh
+++ b/debian/autobake-deb.sh
@@@ -6,137 -7,71 +6,138 @@@
# Exit immediately on any error
set -e
-# Debug script and command lines
-#set -x
-
-# Don't run the mysql-test-run test suite as part of build.
+# On Buildbot, don't run the mysql-test-run test suite as part of build.
# It takes a lot of time, and we will do a better test anyway in
# Buildbot, running the test suite from installed .debs on a clean VM.
-export DEB_BUILD_OPTIONS="nocheck"
+# On Travis-CI we want to simulate the full build, including tests.
+# Also on Travis-CI it is useful not to override the DEB_BUILD_OPTIONS
+# at this stage at all.
+if [[ ! $TRAVIS ]]
+then
+ export DEB_BUILD_OPTIONS="nocheck"
+fi
-export MARIADB_OPTIONAL_DEBS=""
+# Travis-CI optimizations
+if [[ $TRAVIS ]]
+then
+ # On Travis-CI, the log must stay under 4MB so make the build less verbose
+ sed -i -e '/Add support for verbose builds/,+2d' debian/rules
+
+ # Don't include test suite package on Travis-CI to make the build time shorter
+ sed '/Package: mariadb-test-data/,/^$/d' -i debian/control
+ sed '/Package: mariadb-test/,/^$/d' -i debian/control
+fi
-# Find major.minor version.
+
+# Look up distro-version specific stuff
#
-source ./VERSION
-UPSTREAM="${MYSQL_VERSION_MAJOR}.${MYSQL_VERSION_MINOR}.${MYSQL_VERSION_PATCH}${MYSQL_VERSION_EXTRA}"
-RELEASE_EXTRA=""
+# Always keep the actual packaging as up-to-date as possible following the latest
+# Debian policy and targetting Debian Sid. Then case-by-case run in autobake-deb.sh
+# tests for backwards compatibility and strip away parts on older builders.
-RELEASE_NAME=""
-PATCHLEVEL="+maria"
-LOGSTRING="MariaDB build"
+# If iproute2 is not available (before Debian Jessie and Ubuntu Trusty)
+# fall back to the old iproute package.
+if ! apt-cache madison iproute2 | grep 'iproute2 *|' >/dev/null 2>&1
+then
+ sed 's/iproute2/iproute/' -i debian/control
+fi
-# Look up distro-version specific stuff.
+# If libcrack2 (>= 2.9.0) is not available (before Debian Jessie and Ubuntu Trusty)
+# clean away the cracklib stanzas so the package can build without them.
+if ! apt-cache madison libcrack2-dev | grep 'libcrack2-dev *| *2\.9' >/dev/null 2>&1
+then
+ sed '/libcrack2-dev/d' -i debian/control
+ sed '/Package: mariadb-plugin-cracklib/,/^$/d' -i debian/control
+fi
-CODENAME="$(lsb_release -sc)"
-VERNUM="$(lsb_release -sr)"
+# If libpcre3-dev (>= 2:8.35-3.2~) is not available (before Debian Jessie or Ubuntu Wily)
+# clean away the PCRE3 stanzas so the package can build without them.
+# Update check when version 2:8.40 or newer is available.
+if ! apt-cache madison libpcre3-dev | grep 'libpcre3-dev *| *2:8\.3[2-9]' >/dev/null 2>&1
+then
+ sed '/libpcre3-dev/d' -i debian/control
+fi
-# add libcrack2 (>= 2.9.0) as a build dependency
-# but only where the distribution can possibly satisfy it
-if apt-cache madison cracklib2|grep 'cracklib2 *| *2\.[0-8]\.' >/dev/null 2>&1
+# If libsystemd-dev is not available (before Debian Jessie or Ubuntu Wily)
+# clean away the systemd stanzas so the package can build without them.
+if ! apt-cache madison libsystemd-dev | grep 'libsystemd-dev' >/dev/null 2>&1
then
- # Anything in MARIADB_OPTIONAL_DEBS is omitted from the resulting
- # packages by snipped in rules file
- MARIADB_OPTIONAL_DEBS="${MARIADB_OPTIONAL_DEBS} cracklib-password-check-10.1"
- sed -i -e "/\\\${MAYBE_LIBCRACK}/d" debian/control
-else
- MAYBE_LIBCRACK='libcrack2-dev (>= 2.9.0),'
- sed -i -e "s/\\\${MAYBE_LIBCRACK}/${MAYBE_LIBCRACK}/g" debian/control
+ sed '/dh-systemd/d' -i debian/control
+ sed '/libsystemd-dev/d' -i debian/control
+ sed 's/ --with systemd//' -i debian/rules
+ sed '/systemd/d' -i debian/rules
+ sed '/\.service/d' -i debian/rules
+ sed '/galera_new_cluster/d' -i debian/mariadb-server-10.2.install
+ sed '/galera_recovery/d' -i debian/mariadb-server-10.2.install
+ sed '/mariadb-service-convert/d' -i debian/mariadb-server-10.2.install
fi
-# same for OpenSSL. Use the correct dependency
-if apt-cache madison libssl-dev|grep 'libssl-dev *| *1\.1\.' >/dev/null 2>&1
+# Convert gcc version to numberical value. Format is Mmmpp where M is Major
+# version, mm is minor version and p is patch.
+# -dumpfullversion & -dumpversion to make it uniform across old and new (>=7)
+GCCVERSION=$(gcc -dumpfullversion -dumpversion | sed -e 's/\.\([0-9][0-9]\)/\1/g' \
+ -e 's/\.\([0-9]\)/0\1/g' \
+ -e 's/^[0-9]\{3,4\}$/&00/')
+# Don't build rocksdb package if gcc version is less than 4.8 or we are running on
+# x86 32 bit.
+if [[ $GCCVERSION -lt 40800 ]] || [[ $(arch) =~ i[346]86 ]]
then
- LIBSSL='libssl1.0-dev'
-else
- LIBSSL='libssl-dev'
+ sed '/Package: mariadb-plugin-rocksdb/,/^$/d' -i debian/control
fi
-sed -i -e "s/\\\${LIBSSL}/${LIBSSL}/g" debian/control
-# Adjust changelog, add new version.
-#
+# Always remove aws plugin, see -DNOT_FOR_DISTRIBUTION in CMakeLists.txt
+sed '/Package: mariadb-plugin-aws-key-management-10.2/,/^$/d' -i debian/control
+
+# Don't build cassandra package if thrift is not installed
+if [[ ! -f /usr/local/include/thrift/Thrift.h && ! -f /usr/include/thrift/Thrift.h ]]
+then
+ sed '/Package: mariadb-plugin-cassandra/,/^$/d' -i debian/control
+fi
+
+# Adjust changelog, add new version
echo "Incrementing changelog and starting build scripts"
+# Find major.minor version
+source ./VERSION
+UPSTREAM="${MYSQL_VERSION_MAJOR}.${MYSQL_VERSION_MINOR}.${MYSQL_VERSION_PATCH}${MYSQL_VERSION_EXTRA}"
+PATCHLEVEL="+maria"
+LOGSTRING="MariaDB build"
+CODENAME="$(lsb_release -sc)"
- if [[ "$CODENAME" == bionic ]]; then
++VERNUM="$(lsb_release -sr)"
+ if [[ "${VERNUM%.*}" -ge 18 ]]; then
EPOCH="1:"
fi
-dch -b -D ${CODENAME} -v "${EPOCH}${UPSTREAM}${PATCHLEVEL}-${RELEASE_NAME}${RELEASE_EXTRA:+-${RELEASE_EXTRA}}1~${CODENAME}" "Automatic build with ${LOGSTRING}."
-echo "Creating package version ${EPOCH}${UPSTREAM}${PATCHLEVEL}-${RELEASE_NAME}${RELEASE_EXTRA:+-${RELEASE_EXTRA}}1~${CODENAME} ... "
+dch -b -D ${CODENAME} -v "${EPOCH}${UPSTREAM}${PATCHLEVEL}~${CODENAME}" "Automatic build with ${LOGSTRING}."
+
+echo "Creating package version ${EPOCH}${UPSTREAM}${PATCHLEVEL}~${CODENAME} ... "
+
+# On Travis CI, use -b to build binary only packages as there is no need to
+# waste time on generating the source package.
+if [[ $TRAVIS ]]
+then
+ BUILDPACKAGE_FLAGS="-b"
+fi
-# Build the package.
+# Build the package
# Pass -I so that .git and other unnecessary temporary and source control files
-# will be ignored by dpkg-source when createing the tar.gz source package
-fakeroot dpkg-buildpackage -us -uc -I
+# will be ignored by dpkg-source when creating the tar.gz source package.
+fakeroot dpkg-buildpackage -us -uc -I $BUILDPACKAGE_FLAGS
-[ -e debian/autorm-file ] && rm -vf `cat debian/autorm-file`
+# If the step above fails due to missing dependencies, you can manually run
+# sudo mk-build-deps debian/control -r -i
-echo "Build complete"
+# Don't log package contents on Travis-CI to save time and log size
+if [[ ! $TRAVIS ]]
+then
+ echo "List package contents ..."
+ cd ..
+ for package in `ls *.deb`
+ do
+ echo $package | cut -d '_' -f 1
+ dpkg-deb -c $package | awk '{print $1 " " $2 " " $6}' | sort -k 3
+ echo "------------------------------------------------"
+ done
+fi
-# end of autobake script
+echo "Build complete"
diff --cc mysql-test/lib/generate-ssl-certs.sh
index 0894be3a299,4b333854c08..7df1c2d8279
--- a/mysql-test/lib/generate-ssl-certs.sh
+++ b/mysql-test/lib/generate-ssl-certs.sh
@@@ -34,25 -31,9 +34,25 @@@ openssl ca -keyfile cakey.pem -days 730
# with SubjectAltName, only for OpenSSL 1.0.2+
cat > demoCA/sanext.conf <<EOF
- subjectAltName=DNS:localhost
+ subjectAltName=IP:127.0.0.1, DNS:localhost
EOF
-openssl req -newkey rsa:1024 -keyout serversan-key.pem -out demoCA/serversan-req.pem -days 7300 -nodes -subj '/CN=server/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB'
-openssl ca -keyfile cakey.pem -extfile demoCA/sanext.conf -days 7300 -batch -cert cacert.pem -policy policy_anything -out serversan-cert.pem -infiles demoCA/serversan-req.pem
+openssl req -newkey rsa:2048 -keyout serversan-key.pem -out demoCA/serversan-req.pem -days 7300 -nodes -subj '/CN=server/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB'
+openssl ca -keyfile cakey.pem -extfile demoCA/sanext.conf -days 7300 -batch -cert cacert.pem -policy policy_anything -out serversan-cert.pem -in demoCA/serversan-req.pem
+
+# client cert
+openssl req -newkey rsa:2048 -keyout client-key.pem -out demoCA/client-req.pem -days 7300 -nodes -subj '/CN=client/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB'
+openssl rsa -in client-key.pem -out client-key.pem
+openssl ca -keyfile cakey.pem -days 7300 -batch -cert cacert.pem -policy policy_anything -out client-cert.pem -in demoCA/client-req.pem
+
+# generate crls
+openssl ca -revoke server-cert.pem -keyfile cakey.pem -batch -cert cacert.pem
+openssl ca -gencrl -keyfile cakey.pem -crldays 7300 -batch -cert cacert.pem -out server-cert.crl
+# we only want to have one certificate per CRL. Un-revoke server-cert.crl
+cp demoCA/index.txt.old demoCA/index.txt
+openssl ca -revoke client-cert.pem -keyfile cakey.pem -batch -cert cacert.pem
+openssl ca -gencrl -keyfile cakey.pem -crldays 7300 -batch -cert cacert.pem -out client-cert.crl
+
+rm -fv crldir/*
+cp -v client-cert.crl crldir/`openssl x509 -in client-cert.pem -noout -issuer_hash`.r0
rm -rf demoCA
diff --cc mysql-test/r/ctype_latin1.result
index db4054401d2,db9ce63fb78..d17323fb827
--- a/mysql-test/r/ctype_latin1.result
+++ b/mysql-test/r/ctype_latin1.result
@@@ -636,21 -627,12 +642,27 @@@ select c1 as c2h from t1 where c1 like
c2h
ab_def
drop table t1;
+ SELECT @@collation_connection;
+ @@collation_connection
+ latin1_bin
+ SELECT '\%b' LIKE '%\%';
+ '\%b' LIKE '%\%'
+ 0
+SELECT strcmp('a','a '), strcmp('a ','a');
+strcmp('a','a ') strcmp('a ','a')
+0 0
+SELECT strcmp('a\0','a' ), strcmp('a','a\0');
+strcmp('a\0','a' ) strcmp('a','a\0')
+-1 1
+SELECT strcmp('a\0','a '), strcmp('a ','a\0');
+strcmp('a\0','a ') strcmp('a ','a\0')
+-1 1
+SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
+strcmp('a\t','a' ) strcmp('a', 'a\t')
+-1 1
+SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');
+strcmp('a\t','a ') strcmp('a ', 'a\t')
+-1 1
CREATE TABLE �a (a int);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '�a (a int)' at line 1
SELECT '�a' as str;
diff --cc mysql-test/r/events_1.result
index 6f3ad654810,8ea45fa8f2b..26611abb880
--- a/mysql-test/r/events_1.result
+++ b/mysql-test/r/events_1.result
@@@ -11,10 -11,12 +11,14 @@@ CREATE DATABASE db_x
GRANT EVENT ON db_x.* TO pauline@localhost;
USE db_x;
CREATE TABLE x_table(a int);
+connect priv_conn,localhost,pauline,,db_x;
CREATE EVENT e_x1 ON SCHEDULE EVERY 1 SECOND DO DROP DATABASE db_x;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
CREATE EVENT e_x2 ON SCHEDULE EVERY 1 SECOND DO DROP TABLE x_table;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
+connection default;
SHOW DATABASES LIKE 'db_x';
Database (db_x)
db_x
diff --cc mysql-test/r/events_2.result
index 6d2ebda03d0,280ca6c8d98..6dd1a9e5dc6
--- a/mysql-test/r/events_2.result
+++ b/mysql-test/r/events_2.result
@@@ -377,9 -401,11 +401,11 @@@ create event event_35981 on schedule ev
on completion not preserve
do
select 1;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
alter event event_35981 on schedule every 1 hour starts '1999-01-01 00:00:00'
ends '1999-01-02 00:00:00';
-ERROR HY000: Event execution time is in the past and ON COMPLETION NOT PRESERVE is set. The event was not changed. Specify a time in the future.
+ERROR HY000: Event execution time is in the past and ON COMPLETION NOT PRESERVE is set. The event was not changed. Specify a time in the future
drop event event_35981;
create event event_35981 on schedule every 1 hour starts current_timestamp
on completion not preserve
diff --cc mysql-test/r/events_bugs.result
index 3e770451735,a873a28faed..008d4db7dae
--- a/mysql-test/r/events_bugs.result
+++ b/mysql-test/r/events_bugs.result
@@@ -203,8 -209,9 +209,10 @@@ drop database if exists mysqltest_db1
create user mysqltest_user1@localhost;
create database mysqltest_db1;
grant event on events_test.* to mysqltest_user1@localhost;
+connect conn2,localhost,mysqltest_user1,,events_test;
create event mysqltest_user1 on schedule every 10 second do select 42;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
alter event mysqltest_user1 rename to mysqltest_db1.mysqltest_user1;
ERROR 42000: Access denied for user 'mysqltest_user1'@'localhost' to database 'mysqltest_db1'
"Let's test now rename when there is no select DB"
@@@ -371,8 -384,9 +389,10 @@@ SELECT event_name, definer FROM INFORMA
event_name definer
e1 mysqltest_u1@localhost
DROP EVENT e1;
+connect conn1, localhost, mysqltest_u1, , events_test;
CREATE EVENT e1 ON SCHEDULE EVERY 1 DAY DO SELECT 1;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
SELECT event_name, definer FROM INFORMATION_SCHEMA.EVENTS;
event_name definer
e1 mysqltest_u1@localhost
@@@ -660,9 -693,13 +700,11 @@@ ERROR HY000: The MariaDB server is runn
DROP EVENT e1;
ERROR HY000: The MariaDB server is running with the --read-only option so it cannot execute this statement
-#
-# Connection: root_con (root@localhost/events_test).
-#
+connect root_con,localhost,root,,events_test;
CREATE EVENT e1 ON SCHEDULE AT '2020-01-01 00:00:00' DO SET @a = 1;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
ALTER EVENT e1 COMMENT 'comment';
@@@ -670,10 -707,16 +712,14 @@@ DROP EVENT e1
SET GLOBAL READ_ONLY = 0;
-#
-# Connection: u1_con (mysqltest_u1@localhost/test).
-#
+connection u1_con;
CREATE EVENT e1 ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 SECOND DO SET @a = 1;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
CREATE EVENT e2 ON SCHEDULE EVERY 1 SECOND DO SET @a = 1;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
SELECT
event_name,
diff --cc mysql-test/r/events_grant.result
index a054e58494b,446ede09b5a..c691f44aa2e
--- a/mysql-test/r/events_grant.result
+++ b/mysql-test/r/events_grant.result
@@@ -53,12 -58,11 +59,14 @@@ events_test two_event ev_test@localhos
"This should show us no events:";
SHOW EVENTS FROM test LIKE '%';
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
+connection default;
GRANT EVENT ON events_test2.* TO ev_test@localhost;
+connection ev_con1;
USE events_test2;
CREATE EVENT four_event ON SCHEDULE EVERY 20 SECOND DO SELECT 42;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
+connection default;
USE events_test;
"We should see 4 events : one_event, two_event, three_event & four_event"
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME;
@@@ -78,7 -81,8 +86,9 @@@ connection default
CREATE DATABASE events_test2;
USE events_test2;
CREATE EVENT five_event ON SCHEDULE EVERY 20 SECOND DO SELECT 42;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
+connection ev_con1;
"Should see 4 events - one, two, three & five"
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME;
EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_DEFINITION EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT
diff --cc mysql-test/r/flush_read_lock.result
index 55c31ae8d12,da53d2f6d2e..47c46da05f1
--- a/mysql-test/r/flush_read_lock.result
+++ b/mysql-test/r/flush_read_lock.result
@@@ -85,10 -85,8 +85,12 @@@ insert into t1_temp values (1)
return 0;
end|
create event e1 on schedule every 1 minute do begin end;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
+connect con1,localhost,root,,;
+connect con2,localhost,root,,;
+connect con3,localhost,root,,;
+connection default;
#
# Test compatibility of FLUSH TABLES WITH READ LOCK
# with various statements.
diff --cc mysql-test/r/func_gconcat.result
index 0c3d649a6bb,2147040ddb5..992f935b14e
--- a/mysql-test/r/func_gconcat.result
+++ b/mysql-test/r/func_gconcat.result
@@@ -1200,57 -1199,30 +1199,86 @@@ Warning 1260 Row 3 was cut by GROUP_CON
Warning 1260 Row 5 was cut by GROUP_CONCAT()
DROP TABLE t1;
SET group_concat_max_len= DEFAULT;
++set session group_concat_max_len=1024;
+ set max_session_mem_used=16*1024*1024;
+ SELECT GROUP_CONCAT(concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1) ORDER BY 2,1,3,4,6,5,8,7) AS c
+ FROM seq_1_to_200000;
+ c
+ 0.90910.90910.90910.90910.90910.90910.90910.9091,1.81821.81821.81821.81821.81821.81821.81821.8182,10.000010.000010.000010.000010.000010.000010.000010.0000,10.909110.909110.909110.909110.909110.909110.909110.9091,100.0000100.0000100.0000100.0000100.0000100.0000100.0000100.0000,100.9091100.9091100.9091100.9091100.9091100.9091100.9091100.9091,1000.00001000.00001000.00001000.00001000.00001000.00001000.00001000.0000,1000.90911000.90911000.90911000.90911000.90911000.90911000.90911000.9091,10000.000010000.000010000.000010000.000010000.000010000.000010000.000010000.0000,10000.909110000.909110000.909110000.909110000.909110000.909110000.909110000.9091,100000.0000100000.0000100000.0000100000.0000100000.0000100000.0000100000.0000100000.0000,100000.9091100000.9091100000.9091100000.9091100000.9091100000.9091100000.9091100000.9091,100001.8182100001.8182100001.8182100001.8182100001.8182100001.8182100001.8182100001.8182,100002.7273100002.7273100002.7273100002.7273100002.7273100002.727310000
2.7273100002.7273,100003.6364100003.
+ Warnings:
+ Warning 1260 Row 15 was cut by GROUP_CONCAT()
+ set max_session_mem_used=default;
++set session group_concat_max_len=default;
+ SET group_concat_max_len= 8;
+ CREATE TABLE t1 (a INT);
+ INSERT t1 VALUES (1),(2);
+ CREATE TABLE t2 (b DATE, c INT);
+ INSERT t2 VALUES ('2019-12-04',1),('2020-03-28',2);
+ CREATE TABLE t3 (d INT);
+ INSERT t3 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14);
+ CREATE TABLE t4 (e INT);
+ INSERT t4 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15);
+ SELECT (SELECT MAX(a) FROM t1 WHERE t2_sq.c > 0) AS f,
+ GROUP_CONCAT(t2_sq.b ORDER BY 1) AS gc
+ FROM (SELECT t2_a.* FROM t2 AS t2_a, t2 AS t2_b) AS t2_sq, t3, t4
+ GROUP BY f;
+ f gc
+ 2 2019-12-
+ Warnings:
+ Warning 1260 Row 1 was cut by GROUP_CONCAT()
+ DROP TABLE t1, t2, t3, t4;
+ SET group_concat_max_len= default;
+#
+# Start of 10.2 tests
+#
+#
+# MDEV-10124 Incorrect usage of CUBE/ROLLUP and ORDER BY with GROUP_CONCAT(a ORDER BY a)
+#
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (10),(20),(30);
+SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP;
+a GROUP_CONCAT(a ORDER BY a)
+10 10
+20 20
+30 30
+NULL 10,20,30
+CREATE VIEW v1 AS
+SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP;
+SELECT * FROM v1;
+a GROUP_CONCAT(a ORDER BY a)
+10 10
+20 20
+30 30
+NULL 10,20,30
+DROP VIEW v1;
+SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30';
+a GROUP_CONCAT(a ORDER BY a)
+NULL 10,20,30
+CREATE VIEW v1 AS
+SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30';
+SELECT * FROM v1;
+a GROUP_CONCAT(a ORDER BY a)
+NULL 10,20,30
+DROP VIEW v1;
+SELECT * FROM (SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30') t1;
+a GROUP_CONCAT(a ORDER BY a)
+NULL 10,20,30
+CREATE VIEW v1 AS
+SELECT * FROM (SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30') t1;
+SELECT * FROM v1;
+a GROUP_CONCAT(a ORDER BY a)
+NULL 10,20,30
+DROP VIEW v1;
+SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30');
+(SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30')
+10,20,30
+CREATE VIEW v1 AS
+SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30');
+SELECT * FROM v1;
+Name_exp_1
+10,20,30
+DROP VIEW v1;
+DROP TABLE t1;
+#
+# End of 10.2 tests
+#
diff --cc mysql-test/r/gis.result
index f97f588d888,76524311f01..828fbd9d0e7
--- a/mysql-test/r/gis.result
+++ b/mysql-test/r/gis.result
@@@ -1875,375 -1877,17 +1875,413 @@@ t2 CREATE TABLE `t2`
`w2` int(1) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1,t2;
+ CREATE TABLE t1 (
+ id INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ point_data POINT NOT NULL,
+ PRIMARY KEY (id),
+ KEY idx_point_data(point_data)
+ ) ENGINE=MyISAM;
+ INSERT t1 (point_data) VALUES
+ (GeomFromText('Point(37.0248492 23.8512726)')),
+ (GeomFromText('Point(38.0248492 23.8512726)'));
+ SELECT id FROM t1
+ WHERE ST_Contains(point_data, GeomFromText('Point(38.0248492 23.8512726)'));
+ id
+ 2
+ DROP TABLE t1;
+#
+# Start of 10.2 tests
+#
+create view v1 as select AsWKT(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9))));
+show create view v1;
+View Create View character_set_client collation_connection
+v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select st_astext(geometrycollection(point(44,6),geometrycollection(point(3,6),point(7,9)))) AS `Name_exp_1` latin1 latin1_swedish_ci
+select * from v1;
+Name_exp_1
+GEOMETRYCOLLECTION(POINT(44 6),GEOMETRYCOLLECTION(POINT(3 6),POINT(7 9)))
+drop view v1;
+#
+# MDEV-10134 Add full support for DEFAULT
+#
+CREATE TABLE t1 (a POINT, x DOUBLE DEFAULT x(a), y DOUBLE DEFAULT y(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` point DEFAULT NULL,
+ `x` double DEFAULT st_x(`a`),
+ `y` double DEFAULT st_y(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (Point(1,2));
+SELECT x,y FROM t1;
+x y
+1 2
+DROP TABLE t1;
+CREATE TABLE t1 (g GEOMETRY, area DOUBLE DEFAULT ST_AREA(g));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `g` geometry DEFAULT NULL,
+ `area` double DEFAULT st_area(`g`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (g) VALUES (GeomFromText('POLYGON((0 0,20 0,20 20,0 20,0 0))'));
+SELECT area FROM t1;
+area
+400
+DROP TABLE t1;
+CREATE TABLE t1 (g GEOMETRY, length DOUBLE DEFAULT ST_LENGTH(g));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `g` geometry DEFAULT NULL,
+ `length` double DEFAULT st_length(`g`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (g) VALUES (GeomFromText('LINESTRING(0 0,20 0,20 20,0 20,0 0)'));
+SELECT length FROM t1;
+length
+80
+DROP TABLE t1;
+CREATE TABLE t1 (g POINT, distance DOUBLE DEFAULT ST_DISTANCE(g, POINT(0,0)));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `g` point DEFAULT NULL,
+ `distance` double DEFAULT st_distance(`g`,point(0,0))
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (g) VALUES (Point(1,0));
+SELECT distance FROM t1;
+distance
+1
+DROP TABLE t1;
+CREATE TABLE t1 (a TEXT, g GEOMETRY DEFAULT GeomFromText(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` text DEFAULT NULL,
+ `g` geometry DEFAULT st_geometryfromtext(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES ('point(1 1)');
+SELECT AsText(g) FROM t1;
+AsText(g)
+POINT(1 1)
+DROP TABLE t1;
+CREATE TABLE t1 (x INT, y INT, g GEOMETRY DEFAULT POINT(x,y));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `x` int(11) DEFAULT NULL,
+ `y` int(11) DEFAULT NULL,
+ `g` geometry DEFAULT point(`x`,`y`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (x,y) VALUES (10,20);
+SELECT AsText(g) FROM t1;
+AsText(g)
+POINT(10 20)
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT PointN(a,2));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT st_pointn(`a`,2)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,2 2,3 3)'));
+SELECT AsText(b) FROM t1;
+AsText(b)
+POINT(2 2)
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT StartPoint(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT st_startpoint(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,2 2,3 3)'));
+SELECT AsText(b) FROM t1;
+AsText(b)
+POINT(1 1)
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c GEOMETRY DEFAULT GeometryCollection(a,b));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT NULL,
+ `c` geometry DEFAULT geometrycollection(`a`,`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a,b) VALUES (Point(1,1), Point(2,2));
+SELECT AsText(c) FROM t1;
+AsText(c)
+GEOMETRYCOLLECTION(POINT(1 1),POINT(2 2))
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT GeomFromWKB(AsBinary(a),20));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT st_geometryfromwkb(st_aswkb(`a`),20)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('POINT(1 1)', 10));
+SELECT AsText(a), SRID(a), AsText(b), SRID(b) FROM t1;
+AsText(a) SRID(a) AsText(b) SRID(b)
+POINT(1 1) 10 POINT(1 1) 20
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT BOUNDARY(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT st_boundary(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))'));
+SELECT AsText(b) FROM t1;
+AsText(b)
+LINESTRING(10 10,10 20,20 20,20 10,10 10)
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT BUFFER(a,10));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT st_buffer(`a`,10)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))'));
+SELECT GeometryType(b) FROM t1;
+GeometryType(b)
+POLYGON
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT CENTROID(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT st_centroid(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))'));
+SELECT AsText(b) FROM t1;
+AsText(b)
+POINT(15 15)
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT ENVELOPE(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT st_envelope(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,4 4)'));
+SELECT AsText(b) FROM t1;
+AsText(b)
+POLYGON((1 1,4 1,4 4,1 4,1 1))
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT PointOnSurface(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT st_pointonsurface(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))'));
+SELECT GeometryType(b) FROM t1;
+GeometryType(b)
+POINT
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT Point(1,1), c GEOMETRY DEFAULT ST_UNION(a,b));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT point(1,1),
+ `c` geometry DEFAULT st_union(`a`,`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (Point(0,0));
+SELECT AsText(c) FROM t1;
+AsText(c)
+MULTIPOINT(0 0,1 1)
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b VARCHAR(20) DEFAULT GeometryType(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` varchar(20) DEFAULT st_geometrytype(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (Point(0, 0));
+SELECT b FROM t1;
+b
+POINT
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsSimple(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` int(11) DEFAULT st_issimple(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (Point(0, 0));
+SELECT b FROM t1;
+b
+1
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsEmpty(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` int(11) DEFAULT st_isempty(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (Point(0, 0));
+SELECT b FROM t1;
+b
+0
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsRing(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` int(11) DEFAULT st_isring(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('LineString(0 0,0 1,1 1,1 0,0 0)'));
+SELECT b FROM t1;
+b
+1
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsClosed(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` int(11) DEFAULT st_isclosed(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('LineString(0 0,0 1,1 1,1 0,0 0)'));
+SELECT b FROM t1;
+b
+1
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT Dimension(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` int(11) DEFAULT st_dimension(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (Buffer(Point(1,1),1));
+SELECT b FROM t1;
+b
+2
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumGeometries(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` int(11) DEFAULT st_numgeometries(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (ST_UNION(Point(1,1),Point(0,0)));
+SELECT b FROM t1;
+b
+2
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumInteriorRings(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` int(11) DEFAULT st_numinteriorrings(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))'));
+SELECT b FROM t1;
+b
+1
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumPoints(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` int(11) DEFAULT st_numpoints(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (LineString(Point(1,1),Point(0,0)));
+SELECT b FROM t1;
+b
+2
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT SRID(a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` int(11) DEFAULT srid(`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (GeomFromText('Point(1 1)', 100));
+SELECT b FROM t1;
+b
+100
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT MBRDisjoint(a,b));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT NULL,
+ `c` int(11) DEFAULT mbrdisjoint(`a`,`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1));
+SELECT c FROM t1;
+c
+0
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT ST_Disjoint(a,b));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT NULL,
+ `c` int(11) DEFAULT st_disjoint(`a`,`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1));
+SELECT c FROM t1;
+c
+0
+DROP TABLE t1;
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT ST_Relate(a,b,'T*F**FFF*'));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` geometry DEFAULT NULL,
+ `b` geometry DEFAULT NULL,
+ `c` int(11) DEFAULT st_relate(`a`,`b`,'T*F**FFF*')
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1));
+SELECT c FROM t1;
+c
+1
+DROP TABLE t1;
++create table t1 (p point default "qwer");
++ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
++create table t1 (p point default 0);
++ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
++create table t1 (p point not null default st_geometryfromtext('point 0)'));
++ERROR 42000: Invalid default value for 'p'
++create table t1 (p point not null default st_geometryfromtext('point(0 0)'));
++insert into t1 values(default);
++select st_astext(p) from t1;
++st_astext(p)
++POINT(0 0)
++drop table t1;
++create table t1 (p point not null default if(unix_timestamp()>10,POINT(1,1),0));
++set timestamp=10;
++insert into t1 values(default);
++ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
++drop table t1;
++SET timestamp=default;
++create table t1 (p point not null default if(unix_timestamp()>10,POINT(1,1),0));
++set timestamp=10;
++alter table t1 add column i int;
++ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
++drop table t1;
++SET timestamp=default;
+#
+# End of 10.2 tests
+#
diff --cc mysql-test/r/gis_notembedded.result
index 00000000000,eb1e2b98917..64e90572bf0
mode 000000,100644..100644
--- a/mysql-test/r/gis_notembedded.result
+++ b/mysql-test/r/gis_notembedded.result
@@@ -1,0 -1,42 +1,45 @@@
+ show create procedure mysql.AddGeometryColumn;
+ Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation
+ AddGeometryColumn CREATE DEFINER=`root`@`localhost` PROCEDURE `AddGeometryColumn`(catalog varchar(64), t_schema varchar(64),
+ t_name varchar(64), geometry_column varchar(64), t_srid int)
+ SQL SECURITY INVOKER
+ begin
+ set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' ADD ', geometry_column,' GEOMETRY REF_SYSTEM_ID=', t_srid); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end latin1 latin1_swedish_ci latin1_swedish_ci
+ show create procedure mysql.DropGeometryColumn;
+ Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation
+ DropGeometryColumn CREATE DEFINER=`root`@`localhost` PROCEDURE `DropGeometryColumn`(catalog varchar(64), t_schema varchar(64),
+ t_name varchar(64), geometry_column varchar(64))
+ SQL SECURITY INVOKER
+ begin
+ set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' DROP ', geometry_column); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end latin1 latin1_swedish_ci latin1_swedish_ci
+ create table t1 (a int, b int);
+ call mysql.AddGeometryColumn('', 'test', 't1', 'c', 10);
+ show create table t1;
+ Table Create Table
+ t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` geometry DEFAULT NULL
+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1
+ call mysql.DropGeometryColumn('', 'test', 't1', 'c');
+ show create table t1;
+ Table Create Table
+ t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL
+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1
+ call mysql.DropGeometryColumn('', 'test', 't1', 'b');
+ show create table t1;
+ Table Create Table
+ t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL
+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1
+ drop table t1;
+ create user foo@localhost;
+ grant execute on mysql.* to foo@localhost;
++connect foo, localhost, foo;
+ call mysql.AddGeometryColumn('', 'mysql', 'proc', 'c', 10);
+ ERROR 42000: ALTER command denied to user 'foo'@'localhost' for table 'proc'
++disconnect foo;
++connection default;
+ drop user foo@localhost;
diff --cc mysql-test/r/grant4.result
index c3db2e03e3e,88fad6edf49..cb26148dbd1
--- a/mysql-test/r/grant4.result
+++ b/mysql-test/r/grant4.result
@@@ -125,10 -121,28 +125,30 @@@ ERROR 42000: SELECT command denied to u
SHOW CREATE VIEW v3;
View Create View character_set_client collation_connection
v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t_select_priv`.`a` AS `a`,`t_select_priv`.`b` AS `b` from `t_select_priv` latin1 latin1_swedish_ci
+connection default;
+disconnect con1;
drop database mysqltest_db1;
drop user mysqltest_u1@localhost;
+ call mtr.add_suppression("Table 'mysql.user' doesn't exist");
+ call mtr.add_suppression("'mysql.user' is not TABLE");
+ rename table mysql.user to mysql.user1;
+ create view mysql.user as select * from mysql.user1;
+ flush privileges;
+ ERROR HY000: 'mysql.user' is not TABLE
+ drop view mysql.user;
+ create temporary table mysql.user select * from mysql.user1 limit 0;
+ flush privileges;
+ ERROR 42S02: Table 'mysql.user' doesn't exist
+ drop temporary table mysql.user;
+ rename table mysql.user1 to mysql.user;
+ call mtr.add_suppression('mysql.user table is damaged');
+ rename table mysql.user to mysql.user1;
+ create table mysql.user (Host char(100), User char(100));
+ flush privileges;
+ ERROR HY000: Unknown error
+ drop table mysql.user;
+ rename table mysql.user1 to mysql.user;
+ End of 5.5 tests
#
# Additional coverage for refactoring which is made as part
# of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege
diff --cc mysql-test/r/lock_sync.result
index 7b61c5994b6,f8f511b3e3d..d017cf90cb8
--- a/mysql-test/r/lock_sync.result
+++ b/mysql-test/r/lock_sync.result
@@@ -729,8 -725,12 +729,12 @@@ disconnect con2
# Bug#51391 Deadlock involving events during rqg_info_schema test
#
CREATE EVENT e1 ON SCHEDULE EVERY 5 HOUR DO SELECT 1;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
CREATE EVENT e2 ON SCHEDULE EVERY 5 HOUR DO SELECT 2;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
-# Connection con1
+connect con1, localhost, root;
SET DEBUG_SYNC="before_lock_tables_takes_lock SIGNAL drop WAIT_FOR query";
# Sending:
DROP EVENT e1;;
diff --cc mysql-test/r/mdev_19276.result
index 00000000000,09d51561427..c1b822de6bf
mode 000000,100644..100644
--- a/mysql-test/r/mdev_19276.result
+++ b/mysql-test/r/mdev_19276.result
@@@ -1,0 -1,9 +1,11 @@@
+ CREATE DATABASE db1;
+ CREATE USER u@localhost IDENTIFIED BY 'pw';
+ set global log_warnings=2;
+ connect(localhost,u,pw,db1,MASTER_PORT,MASTER_SOCKET);
++connect con1,localhost,u,pw,db1;
+ ERROR 42000: Access denied for user 'u'@'localhost' to database 'db1'
-FOUND /Access denied for user 'u'@'localhost' to database 'db1'/ in mysqld.1.err
++connection default;
++FOUND 1 /Access denied for user 'u'@'localhost' to database 'db1'/ in mysqld.1.err
+ set global log_warnings=@@log_warnings;
+ DROP DATABASE db1;
+ DROP USER u@localhost;
diff --cc mysql-test/r/multi_update.result
index 634b3897ba0,f614ea1e497..11823941e56
--- a/mysql-test/r/multi_update.result
+++ b/mysql-test/r/multi_update.result
@@@ -1001,4 -1018,79 +1001,27 @@@ execute stmt1
deallocate prepare stmt1;
drop view v3,v2,v1;
drop table t1,t2,t3;
+ create table t1 (id int not null, v1 varchar(10) not null);
+ insert into t1 values (1,1),(2,2);
+ create table t2 (log varchar(10) not null);
+ create trigger t1_after_update after update on t1
+ for each row insert into t2 values ('triggered');
+ create user foo;
+ grant select, insert, update, delete, create, drop, reload, index, alter, show databases, create temporary tables, lock tables, execute, create view, show view, create routine, alter routine, trigger on *.* to 'foo'@'%';
+ set global read_only=1;
++connect a, localhost, foo;
+ create temporary table temp_t1 (id int not null, update_me varchar(10));
+ insert into temp_t1 values (1,1),(2,2),(3,3);
+ update temp_t1 left join t1 on temp_t1.id = t1.id set temp_t1.update_me = 'hello';
++connection default;
+ set global read_only = 0;
+ create table t3 (id int not null);
+ insert t3 values (2);
+ update t1 left join t3 on t1.id = t3.id set t1.v1 = 'hello';
+ select * from t2;
+ log
+ triggered
+ triggered
+ drop table t1,t2, t3;
+ drop user foo;
end of 5.5 tests
-
-# Bug mdev-5970
-# Bug#13256831 - ERROR 1032 (HY000): CAN'T FIND RECORD
-
-CREATE TABLE t1 (f1 INT PRIMARY KEY, f2 INT) ENGINE=InnoDB;
-CREATE TABLE t2 (f1 INT PRIMARY KEY, f2 INT) ENGINE=InnoDB;
-INSERT INTO t1 VALUES (5, 7);
-INSERT INTO t2 VALUES (6, 97);
-CREATE ALGORITHM = MERGE VIEW v1 AS
-SELECT a2.f1 AS f1, a2.f2 AS f2
-FROM t1 AS a1 JOIN t2 AS a2 ON a1.f2 > a2.f1
-WITH LOCAL CHECK OPTION;
-SELECT * FROM v1;
-f1 f2
-6 97
-UPDATE v1 SET f1 = 1;
-SELECT * FROM v1;
-f1 f2
-1 97
-DROP TABLE t1, t2;
-DROP VIEW v1;
-#
-# MDEV-5973: MySQL Bug#11757486:49539: NON-DESCRIPTIVE ERR (ERROR 0
-# FROM STORAGE ENGINE) WITH MULTI-TABLE UPDATE
-#
-CREATE TABLE table_11757486 (field1 tinyint) ENGINE=INNODB;
-INSERT INTO table_11757486 VALUES (0),(0);
-SET SESSION SQL_MODE='STRICT_ALL_TABLES';
-UPDATE IGNORE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1;
-Warnings:
-Warning 1264 Out of range value for column 'field1' at row 1
-Warning 1264 Out of range value for column 'field1' at row 2
-UPDATE IGNORE table_11757486 SET field1=128;
-Warnings:
-Warning 1264 Out of range value for column 'field1' at row 1
-Warning 1264 Out of range value for column 'field1' at row 2
-Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. UPDATE IGNORE is unsafe because the order in which rows are updated determines which (if any) rows are ignored. This order cannot be predicted and may differ on master and the slave.
-UPDATE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1;
-ERROR 22003: Out of range value for column 'field1' at row 1
-UPDATE table_11757486 SET field1=128;
-ERROR 22003: Out of range value for column 'field1' at row 1
-SET SESSION SQL_MODE='';
-UPDATE IGNORE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1;
-Warnings:
-Warning 1264 Out of range value for column 'field1' at row 1
-Warning 1264 Out of range value for column 'field1' at row 2
-UPDATE IGNORE table_11757486 SET field1=128;
-Warnings:
-Warning 1264 Out of range value for column 'field1' at row 1
-Warning 1264 Out of range value for column 'field1' at row 2
-Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. UPDATE IGNORE is unsafe because the order in which rows are updated determines which (if any) rows are ignored. This order cannot be predicted and may differ on master and the slave.
-DROP TABLE table_11757486;
-SET SESSION SQL_MODE=default;
-end of 10.0 tests
diff --cc mysql-test/r/partition_innodb.result
index 0a58883bb34,5deab4d84fc..8c0950e3643
--- a/mysql-test/r/partition_innodb.result
+++ b/mysql-test/r/partition_innodb.result
@@@ -928,48 -918,45 +928,90 @@@ ERROR 44000: CHECK OPTION failed `test`
SET GLOBAL innodb_stats_persistent= @save_isp;
DROP view v;
DROP TABLE t;
+set sql_mode= @save_sql_mode;
#
+ # Bug#28573894 ALTER PARTITIONED TABLE ADD AUTO_INCREMENT DIFF RESULT
+ #
+ CREATE TABLE t (a VARCHAR(10) NOT NULL,b INT,PRIMARY KEY (b)) ENGINE=INNODB
+ PARTITION BY RANGE (b)
+ (PARTITION pa VALUES LESS THAN (2),
+ PARTITION pb VALUES LESS THAN (20),
+ PARTITION pc VALUES LESS THAN (30),
+ PARTITION pd VALUES LESS THAN (40));
+ INSERT INTO t
+ VALUES('A',0),('B',1),('C',2),('D',3),('E',4),('F',5),('G',25),('H',35);
+ CREATE TABLE t_copy LIKE t;
+ INSERT INTO t_copy SELECT * FROM t;
+ ALTER TABLE t ADD COLUMN r INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ ADD UNIQUE KEY (r,b);
+ affected rows: 0
+ info: Records: 0 Duplicates: 0 Warnings: 0
+ ALTER TABLE t_copy ADD COLUMN r INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ ADD UNIQUE KEY (r,b), ALGORITHM=COPY;
+ affected rows: 8
+ info: Records: 8 Duplicates: 0 Warnings: 0
+ SELECT * FROM t;
+ a b r
+ A 0 1
+ B 1 2
+ C 2 3
+ D 3 4
+ E 4 5
+ F 5 6
+ G 25 7
+ H 35 8
+ SELECT * FROM t_copy;
+ a b r
+ A 0 1
+ B 1 2
+ C 2 3
+ D 3 4
+ E 4 5
+ F 5 6
+ G 25 7
+ H 35 8
+ DROP TABLE t,t_copy;
++#
+# Bug#26390658 RENAMING A PARTITIONED TABLE DOES NOT UPDATE
+# MYSQL.INNODB_TABLE_STATS
+#
+CREATE DATABASE test_jfg;
+CREATE TABLE test_jfg.test_jfg1 (id int(10) unsigned NOT NULL,PRIMARY
+KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1 STATS_PERSISTENT=1;
+CREATE TABLE test_jfg.test_jfg2 (id int(10) unsigned NOT NULL,PRIMARY
+KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1 STATS_PERSISTENT=1
+PARTITION BY RANGE ( id ) (PARTITION p1000 VALUES LESS THAN (1000)
+ENGINE = InnoDB,PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE =
+InnoDB);
+SELECT database_name, table_name FROM mysql.innodb_table_stats WHERE
+database_name = 'test_jfg';
+database_name table_name
+test_jfg test_jfg1
+test_jfg test_jfg2#P#p1000
+test_jfg test_jfg2#P#pmax
+RENAME TABLE test_jfg.test_jfg1 TO test_jfg.test_jfg11;
+RENAME TABLE test_jfg.test_jfg2 TO test_jfg.test_jfg12;
+SELECT database_name, table_name FROM mysql.innodb_table_stats WHERE
+database_name = 'test_jfg';
+database_name table_name
+test_jfg test_jfg11
+test_jfg test_jfg12#P#p1000
+test_jfg test_jfg12#P#pmax
+DROP DATABASE test_jfg;
+create table t1 (a int) engine=innodb;
+create table t2 (
+b int,
+c int,
+d bit not null default 0,
+v bit as (d) virtual,
+key (b,v)
+) engine=innodb partition by hash (b);
+insert into t1 values (1),(2);
+insert into t2 (b,c,d) values (1,1,0),(2,2,0);
+explain select t1.* from t1 join t2 on (v = a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2
+1 SIMPLE t2 index NULL b 7 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
+select t1.* from t1 join t2 on (v = a);
+a
+drop table t1, t2;
diff --cc mysql-test/r/ps.result
index e4d2ce83db1,0d305b37bd3..e8bea47e28c
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@@ -4404,888 -4397,22 +4410,905 @@@ END
1
1
#
+ # MDEV-14572: Assertion `! is_set()' failed in
+ # Diagnostics_area::set_eof_status upon EXPLAIN UPDATE in PS
+ #
+ CREATE TABLE t1 (a INT);
+ CREATE TABLE t2 (b INT);
+ PREPARE stmt FROM 'EXPLAIN UPDATE t1, t2 SET a = 1';
+ EXECUTE stmt;
+ id select_type table type possible_keys key key_len ref rows Extra
+ 1 SIMPLE t1 system NULL NULL NULL NULL 0 const row not found
+ 1 SIMPLE t2 system NULL NULL NULL NULL 0 const row not found
+ EXECUTE stmt;
+ id select_type table type possible_keys key key_len ref rows Extra
+ 1 SIMPLE t1 system NULL NULL NULL NULL 0 const row not found
+ 1 SIMPLE t2 system NULL NULL NULL NULL 0 const row not found
+ deallocate prepare stmt;
+ DROP TABLE t1, t2;
+ #
# End of 10.1 tests
#
+#
+# MDEV-10709 Expressions as parameters to Dynamic SQL
+#
+#
+# Using a simple expressions as an EXECUTE parameter
+#
+PREPARE stmt FROM 'SELECT ? FROM DUAL';
+EXECUTE stmt USING 10;
+?
+10
+DEALLOCATE PREPARE stmt;
+PREPARE stmt FROM 'SELECT ? FROM DUAL';
+EXECUTE stmt USING TO_BASE64('xxx');
+?
+eHh4
+DEALLOCATE PREPARE stmt;
+PREPARE stmt FROM 'SELECT ?+? FROM DUAL';
+EXECUTE stmt USING 10, 10 + 10;
+?+?
+30
+DEALLOCATE PREPARE stmt;
+PREPARE stmt FROM 'SELECT CONCAT(?,?) FROM DUAL';
+EXECUTE stmt USING 'xxx', CONCAT('yyy','zzz');
+CONCAT(?,?)
+xxxyyyzzz
+DEALLOCATE PREPARE stmt;
+#
+# Testing disallowed expressions in USING
+#
+PREPARE stmt FROM 'SELECT ? FROM DUAL';
+EXECUTE stmt USING (SELECT 1);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT 1)' at line 1
+DEALLOCATE PREPARE stmt;
+CREATE FUNCTION f1() RETURNS VARCHAR(10) RETURN 'test';
+PREPARE stmt FROM 'SELECT ? FROM DUAL';
+EXECUTE stmt USING f1();
+ERROR 42000: EXECUTE..USING does not support subqueries or stored functions
+DEALLOCATE PREPARE stmt;
+DROP FUNCTION f1;
+#
+# Testing erroneous expressions in USING
+#
+PREPARE stmt FROM 'SELECT ?';
+EXECUTE stmt USING _latin1'a'=_latin2'a';
+ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin2_general_ci,COERCIBLE) for operation '='
+DEALLOCATE PREPARE stmt;
+PREPARE stmt FROM 'SELECT ?';
+EXECUTE stmt USING ROW(1,2);
+ERROR 21000: Operand should contain 1 column(s)
+DEALLOCATE PREPARE stmt;
+#
+# Creating tables from EXECUTE parameters
+#
+PREPARE stmt FROM 'CREATE TABLE t1 AS SELECT ? AS c1 FROM DUAL';
+EXECUTE stmt USING 10;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` bigint(21) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+EXECUTE stmt USING 10.123;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` decimal(5,3) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+EXECUTE stmt USING 10.123e0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` double NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+EXECUTE stmt USING CURRENT_DATE;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` date NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+EXECUTE stmt USING CURRENT_TIMESTAMP;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` datetime NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+EXECUTE stmt USING CURRENT_TIMESTAMP(3);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` datetime(3) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+EXECUTE stmt USING CURRENT_TIMESTAMP(6);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` datetime(6) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+EXECUTE stmt USING CURRENT_TIME;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` time NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+EXECUTE stmt USING CURRENT_TIME(3);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` time(3) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+EXECUTE stmt USING CURRENT_TIME(6);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` time(6) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+DEALLOCATE PREPARE stmt;
+#
+# Using a user variable as an EXECUTE..USING out parameter
+#
+CREATE PROCEDURE p1(OUT a INT)
+BEGIN
+SET a:= 10;
+END;
+/
+SET @a=1;
+CALL p1(@a);
+SELECT @a;
+@a
+10
+SET @a=2;
+PREPARE stmt FROM 'CALL p1(?)';
+EXECUTE stmt USING @a;
+SELECT @a;
+@a
+10
+DROP PROCEDURE p1;
+#
+# Using an SP variable as an EXECUTE..USING out parameter
+#
+CREATE PROCEDURE p1 (OUT a INT)
+BEGIN
+SET a=10;
+END;
+/
+CREATE PROCEDURE p2 (OUT a INT)
+BEGIN
+PREPARE stmt FROM 'CALL p1(?)';
+EXECUTE stmt USING a;
+END;
+/
+SET @a= 1;
+CALL p2(@a);
+SELECT @a;
+@a
+10
+DROP PROCEDURE p2;
+DROP PROCEDURE p1;
+#
+# Testing re-prepare on a table metadata update between PREPARE and EXECUTE
+#
+CREATE TABLE t1 (a INT);
+CREATE PROCEDURE p1(a INT)
+BEGIN
+INSERT INTO t1 VALUES (a);
+END;
+/
+PREPARE stmt FROM 'CALL p1(?)';
+EXECUTE stmt USING 10;
+SELECT * FROM t1;
+a
+10
+CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a=NEW.a+1;
+EXECUTE stmt USING 20;
+SELECT * FROM t1;
+a
+10
+21
+DEALLOCATE PREPARE stmt;
+DROP PROCEDURE p1;
+DROP TABLE t1;
+#
+# End of MDEV-10709 Expressions as parameters to Dynamic SQL
+#
+#
+# MDEV-10585 EXECUTE IMMEDIATE statement
+#
+EXECUTE IMMEDIATE 'SELECT 1 AS a';
+a
+1
+SET @a=10;
+EXECUTE IMMEDIATE 'SELECT ? AS a' USING @a;
+a
+10
+EXECUTE IMMEDIATE 'SELECT ? AS a' USING 20;
+a
+20
+#
+# Erroneous queries
+#
+EXECUTE IMMEDIATE 'xxx';
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'xxx' at line 1
+EXECUTE IMMEDIATE 'SELECT 1' USING @a;
+ERROR HY000: Incorrect arguments to EXECUTE
+EXECUTE IMMEDIATE 'SELECT ?';
+ERROR HY000: Incorrect arguments to EXECUTE
+EXECUTE IMMEDIATE 'EXECUTE IMMEDIATE "SELECT 1"';
+ERROR HY000: This command is not supported in the prepared statement protocol yet
+EXECUTE IMMEDIATE 'PREPARE stmt FROM "SELECT 1"';
+ERROR HY000: This command is not supported in the prepared statement protocol yet
+EXECUTE IMMEDIATE 'EXECUTE stmt';
+ERROR HY000: This command is not supported in the prepared statement protocol yet
+EXECUTE IMMEDIATE 'DEALLOCATE PREPARE stmt';
+ERROR HY000: This command is not supported in the prepared statement protocol yet
+EXECUTE IMMEDIATE 'SELECT ?' USING _latin1'a'=_latin2'a';
+ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin2_general_ci,COERCIBLE) for operation '='
+EXECUTE IMMEDIATE 'SELECT ?' USING ROW(1,2);
+ERROR 21000: Operand should contain 1 column(s)
+#
+# Testing disallowed expressions in USING
+#
+EXECUTE IMMEDIATE 'SELECT ? FROM DUAL' USING (SELECT 1);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT 1)' at line 1
+CREATE FUNCTION f1() RETURNS VARCHAR(10) RETURN 'test';
+EXECUTE IMMEDIATE 'SELECT ? FROM DUAL' USING f1();
+ERROR 42000: EXECUTE..USING does not support subqueries or stored functions
+DROP FUNCTION f1;
+#
+# DDL
+#
+EXECUTE IMMEDIATE 'CREATE TABLE t1 (a INT)';
+EXECUTE IMMEDIATE 'SHOW CREATE TABLE t1';
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+EXECUTE IMMEDIATE 'DROP TABLE t1';
+SET @stmt= 'CREATE TABLE t1 (a INT)';
+EXECUTE IMMEDIATE @stmt;
+SET @stmt= 'SHOW CREATE TABLE t1';
+EXECUTE IMMEDIATE @stmt;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SET @stmt= 'DROP TABLE t1';
+EXECUTE IMMEDIATE @stmt;
+#
+# DDL with parameters
+#
+SET @a= 10, @b= 10.1, @c= 10e0, @d='str';
+EXECUTE IMMEDIATE
+'CREATE TABLE t1 AS SELECT ? AS a,? AS b,? AS c,? AS d'
+ USING @a,@b,@c,@d;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` bigint(21) NOT NULL,
+ `b` decimal(3,1) NOT NULL,
+ `c` double NOT NULL,
+ `d` varchar(3) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+EXECUTE IMMEDIATE
+'CREATE TABLE t1 AS SELECT ? AS a,? AS b,? AS c,? AS d'
+ USING 10, 10.1, 10e0, 'str';
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` bigint(21) NOT NULL,
+ `b` decimal(3,1) NOT NULL,
+ `c` double NOT NULL,
+ `d` varchar(3) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+EXECUTE IMMEDIATE
+'CREATE TABLE t1 AS SELECT ? AS t1,? AS t2, ? AS d1,? AS dt1, ? AS dt2'
+ USING TIME'10:20:30',
+TIME'10:20:30.123',
+DATE'2001-01-01',
+TIMESTAMP'2001-01-01 10:20:30',
+TIMESTAMP'2001-01-01 10:20:30.123';
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `t1` time NOT NULL,
+ `t2` time(3) NOT NULL,
+ `d1` date NOT NULL,
+ `dt1` datetime NOT NULL,
+ `dt2` datetime(3) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+#
+# Using a user variable as an EXECUTE IMMEDIATE..USING out parameter
+#
+CREATE PROCEDURE p1(OUT a INT)
+BEGIN
+SET a:= 10;
+END;
+/
+SET @a=1;
+CALL p1(@a);
+SELECT @a;
+@a
+10
+SET @a=2;
+EXECUTE IMMEDIATE 'CALL p1(?)' USING @a;
+SELECT @a;
+@a
+10
+DROP PROCEDURE p1;
+#
+# Using an SP variable as an EXECUTE IMMEDIATE..USING out parameter
+#
+CREATE PROCEDURE p1 (OUT a INT)
+BEGIN
+SET a=10;
+END;
+/
+CREATE PROCEDURE p2 (OUT a INT)
+BEGIN
+EXECUTE IMMEDIATE 'CALL p1(?)' USING a;
+END;
+/
+SET @a= 1;
+CALL p2(@a);
+SELECT @a;
+@a
+10
+DROP PROCEDURE p2;
+DROP PROCEDURE p1;
+#
+# Changing user variables
+#
+SET @a=10;
+EXECUTE IMMEDIATE 'SET @a=@a+1';
+SELECT @a;
+@a
+11
+#
+# SET STATEMENT
+#
+SET @@max_sort_length=1024;
+EXECUTE IMMEDIATE 'SET STATEMENT max_sort_length=1025 FOR SELECT @@max_sort_length';
+@@max_sort_length
+1025
+SELECT @@max_sort_length;
+@@max_sort_length
+1024
+SET @@max_sort_length=DEFAULT;
+#
+# Similar to prepared EXECUTE, IMMEDIATE is not allowed in stored functions
+#
+CREATE FUNCTION f1() RETURNS INT
+BEGIN
+EXECUTE IMMEDIATE 'DO 1';
+RETURN 1;
+END;
+$$
+ERROR 0A000: Dynamic SQL is not allowed in stored function or trigger
+#
+# Status variables
+#
+CREATE FUNCTION get_status_var(name TEXT) RETURNS INT
+RETURN (SELECT CAST(VARIABLE_VALUE AS INT)
+FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME=name);
+CREATE PROCEDURE test_status_var(name TEXT)
+BEGIN
+SET @cnt0=get_status_var(name);
+EXECUTE IMMEDIATE 'DO 1';
+SET @cnt1=get_status_var(name);
+SELECT @cnt1-@cnt0 AS increment;
+END;
+$$
+# Note, EXECUTE IMMEDIATE does not increment COM_EXECUTE_SQL
+# It increments COM_EXECUTE_IMMEDIATE instead.
+CALL test_status_var('COM_EXECUTE_SQL');
+increment
+0
+CALL test_status_var('COM_EXECUTE_IMMEDIATE');
+increment
+1
+CALL test_status_var('COM_STMT_PREPARE');
+increment
+1
+CALL test_status_var('COM_STMT_EXECUTE');
+increment
+1
+CALL test_status_var('COM_STMT_CLOSE');
+increment
+1
+DROP PROCEDURE test_status_var;
+DROP FUNCTION get_status_var;
+#
+# End of MDEV-10585 EXECUTE IMMEDIATE statement
+#
+#
+# MDEV-10866 Extend PREPARE and EXECUTE IMMEDIATE to understand expressions
+#
+#
+# Testing erroneous and diallowed prepare source
+#
+EXECUTE IMMEDIATE CONCAT(_latin1'SELECT 1 AS c FROM ', _latin2 'DUAL');
+ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin2_general_ci,COERCIBLE) for operation 'concat'
+PREPARE stmt FROM CONCAT(_latin1'SELECT 1 AS c FROM ', _latin2 'DUAL');
+ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin2_general_ci,COERCIBLE) for operation 'concat'
+EXECUTE IMMEDIATE (SELECT 'SELECT 1');
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT 'SELECT 1')' at line 1
+PREPARE stmt FROM (SELECT 'SELECT 1');
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT 'SELECT 1')' at line 1
+EXECUTE IMMEDIATE a;
+ERROR 42S22: Unknown column 'a' in 'field list'
+PREPARE stmt FROM a;
+ERROR 42S22: Unknown column 'a' in 'field list'
+EXECUTE IMMEDIATE NULL;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1
+PREPARE stmt FROM NULL;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1
+EXECUTE IMMEDIATE CONCAT(NULL);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1
+PREPARE stmt FROM CONCAT(NULL);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1
+EXECUTE IMMEDIATE ? USING 'SELECT 1';
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? USING 'SELECT 1'' at line 1
+EXECUTE IMMEDIATE 10;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '10' at line 1
+EXECUTE IMMEDIATE TIME'10:20:30';
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '10:20:30' at line 1
+EXECUTE IMMEDIATE ROW('SELECT 1','SELECT 2');
+ERROR 21000: Operand should contain 1 column(s)
+EXECUTE IMMEDIATE MAX('SELECT 1 AS c');
+ERROR HY000: Invalid use of group function
+EXECUTE IMMEDIATE DEFAULT(a);
+ERROR 42S22: Unknown column 'a' in 'field list'
+EXECUTE IMMEDIATE VALUES(a);
+ERROR 42S22: Unknown column 'a' in 'field list'
+CREATE FUNCTION f1() RETURNS VARCHAR(64) RETURN 't1';
+EXECUTE IMMEDIATE f1();
+ERROR 42000: EXECUTE IMMEDIATE does not support subqueries or stored functions
+PREPARE stmt FROM f1();
+ERROR 42000: PREPARE..FROM does not support subqueries or stored functions
+DROP FUNCTION f1;
+EXECUTE IMMEDIATE non_existent();
+ERROR 42000: EXECUTE IMMEDIATE does not support subqueries or stored functions
+#
+# Testing literals in prepare source
+#
+EXECUTE IMMEDIATE N'SELECT 1 AS c';
+c
+1
+EXECUTE IMMEDIATE _latin1'SELECT 1 AS c';
+c
+1
+EXECUTE IMMEDIATE 'SELECT ' '1' ' AS c' ' FROM ' 'DUAL';
+c
+1
+EXECUTE IMMEDIATE 0x53454C4543542031 /*This is 'SELECT 1'*/;
+1
+1
+#
+# Testing user variables in prepare source
+#
+SET @stmt='SELECT 1 AS c FROM DUAL';
+EXECUTE IMMEDIATE @stmt;
+c
+1
+PREPARE stmt FROM @stmt;
+EXECUTE stmt;
+c
+1
+DEALLOCATE PREPARE stmt;
+SET @table_name='DUAL';
+EXECUTE IMMEDIATE CONCAT('SELECT 1 AS a FROM ', @table_name);
+a
+1
+PREPARE stmt FROM CONCAT('SELECT 1 AS a FROM ', @table_name);
+EXECUTE stmt;
+a
+1
+DEALLOCATE PREPARE stmt;
+#
+# Testing SP parameters and variables in prepare source
+#
+CREATE PROCEDURE p1(table_name VARCHAR(64))
+BEGIN
+EXECUTE IMMEDIATE CONCAT('SELECT 1 AS c FROM ', table_name);
+END;
+$$
+CALL p1('DUAL');
+c
+1
+DROP PROCEDURE p1;
+CREATE PROCEDURE p1()
+BEGIN
+DECLARE table_name VARCHAR(64) DEFAULT 'DUAL';
+EXECUTE IMMEDIATE CONCAT('SELECT 1 AS c FROM ', table_name);
+END;
+$$
+CALL p1();
+c
+1
+DROP PROCEDURE p1;
+#
+# Testing complex expressions
+#
+EXECUTE IMMEDIATE CONVERT('SELECT 1 AS c' USING utf8);
+c
+1
+EXECUTE IMMEDIATE CAST('SELECT 1 AS c' AS CHAR);
+c
+1
+EXECUTE IMMEDIATE _latin1'SELECT 1 AS c' COLLATE latin1_bin;
+c
+1
+EXECUTE IMMEDIATE (((('SELECT 1 AS c'))));
+c
+1
+EXECUTE IMMEDIATE CASE WHEN 1>2 THEN 'SELECT 1 AS c' ELSE 'SELECT 2 AS c' END;
+c
+2
+EXECUTE IMMEDIATE TRIM('SELECT 1 AS c');
+c
+1
+EXECUTE IMMEDIATE SUBSTRING('SELECT 1 AS c' FROM 1);
+c
+1
+EXECUTE IMMEDIATE COALESCE(NULL, 'SELECT 1 AS c');
+c
+1
+#
+# Testing SET STATEMENT and system variables
+#
+CREATE TABLE t1 (a INT);
+SET STATEMENT max_sort_length=1025 FOR EXECUTE IMMEDIATE CONCAT('INSERT INTO t1 VALUES (', @@max_sort_length, ')');
+SELECT * FROM t1;
+a
+1025
+DROP TABLE t1;
+#
+# End of MDEV-10866 Extend PREPARE and EXECUTE IMMEDIATE to understand expressions
+#
+#
+# MDEV-11360 Dynamic SQL: DEFAULT as a bind parameter
+#
+CREATE TABLE t1 (a INT DEFAULT 10, b INT DEFAULT NULL);
+EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?,?)' USING DEFAULT, DEFAULT;
+SELECT * FROM t1;
+a b
+10 NULL
+UPDATE t1 SET a=20, b=30;
+SELECT * FROM t1;
+a b
+20 30
+EXECUTE IMMEDIATE 'UPDATE t1 SET a=?,b=?' USING DEFAULT, DEFAULT;
+SELECT * FROM t1;
+a b
+10 NULL
+DROP TABLE t1;
+CREATE TABLE t1 (a INT DEFAULT 10);
+EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?+1)' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (CONCAT(?,?))' USING DEFAULT, 'test';
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+DROP TABLE t1;
+CREATE TABLE t1 (a INT DEFAULT 10);
+INSERT INTO t1 VALUES (20);
+EXECUTE IMMEDIATE 'UPDATE t1 SET a=?+1' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+EXECUTE IMMEDIATE 'UPDATE t1 SET a=CONCAT(?,?)' USING DEFAULT, 'test';
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+DROP TABLE t1;
+EXECUTE IMMEDIATE 'SELECT CAST(? AS SIGNED)' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+EXECUTE IMMEDIATE 'SELECT CAST(? AS DOUBLE)' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+EXECUTE IMMEDIATE 'SELECT CAST(? AS CHAR)' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+EXECUTE IMMEDIATE 'SELECT CAST(? AS DECIMAL(10,1))' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+EXECUTE IMMEDIATE 'SELECT CAST(? AS TIME)' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+EXECUTE IMMEDIATE 'SELECT CAST(? AS DATE)' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+EXECUTE IMMEDIATE 'SELECT CAST(? AS DATETIME)' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+EXECUTE IMMEDIATE 'SELECT ?+1' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+EXECUTE IMMEDIATE 'SELECT CONCAT(?,?)' USING DEFAULT,'test';
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+EXECUTE IMMEDIATE 'SELECT 1 LIMIT ?' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+CREATE TABLE t1 (a INT DEFAULT 10);
+INSERT INTO t1 VALUES (1),(2),(3);
+EXECUTE IMMEDIATE 'SELECT * FROM t1 LIMIT ?' USING DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+DROP TABLE t1;
+# The output of this query in 'Note' is a syntactically incorrect query.
+# But as it's never logged, it's ok. It should be human readable only.
+EXECUTE IMMEDIATE 'EXPLAIN EXTENDED SELECT ?' USING DEFAULT;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select default AS `?`
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+EXECUTE IMMEDIATE 'EXPLAIN EXTENDED SELECT * FROM t1 WHERE ?+a<=>?+a' USING DEFAULT,DEFAULT;
+ERROR HY000: Default/ignore value is not supported for such parameter usage
+DROP TABLE t1;
+#
+# MDEV-11780 Crash with PREPARE + SP out parameter + literal
+#
+CREATE OR REPLACE PROCEDURE p1(OUT a INT)
+BEGIN
+SET a=10;
+END;
+$$
+PREPARE stmt FROM 'CALL p1(?)';
+EXECUTE stmt USING 10;
+ERROR 42000: OUT or INOUT argument 1 for routine test.p1 is not a variable or NEW pseudo-variable in BEFORE trigger
+EXECUTE stmt USING DEFAULT;
+ERROR 42000: OUT or INOUT argument 1 for routine test.p1 is not a variable or NEW pseudo-variable in BEFORE trigger
+EXECUTE stmt USING IGNORE;
+ERROR 42000: OUT or INOUT argument 1 for routine test.p1 is not a variable or NEW pseudo-variable in BEFORE trigger
+DEALLOCATE PREPARE stmt;
+EXECUTE IMMEDIATE 'CALL p1(?)' USING 10;
+ERROR 42000: OUT or INOUT argument 1 for routine test.p1 is not a variable or NEW pseudo-variable in BEFORE trigger
+EXECUTE IMMEDIATE 'CALL p1(?)' USING DEFAULT;
+ERROR 42000: OUT or INOUT argument 1 for routine test.p1 is not a variable or NEW pseudo-variable in BEFORE trigger
+EXECUTE IMMEDIATE 'CALL p1(?)' USING IGNORE;
+ERROR 42000: OUT or INOUT argument 1 for routine test.p1 is not a variable or NEW pseudo-variable in BEFORE trigger
+DROP PROCEDURE p1;
+#
+# MDEV-14434 Wrong result for CHARSET(CONCAT(?,const))
+#
+SET NAMES utf8;
+EXECUTE IMMEDIATE "SELECT CHARSET(CONCAT(5,_latin1'a'))";
+CHARSET(CONCAT(5,_latin1'a'))
+latin1
+EXECUTE IMMEDIATE "SELECT CHARSET(CONCAT(?,_latin1'a'))" USING 5;
+CHARSET(CONCAT(?,_latin1'a'))
+latin1
+EXECUTE IMMEDIATE "SELECT CHARSET(CONCAT(?,_latin1'a'))" USING 5.5;
+CHARSET(CONCAT(?,_latin1'a'))
+latin1
+EXECUTE IMMEDIATE "SELECT CHARSET(CONCAT(?,_latin1'a'))" USING 5.5e0;
+CHARSET(CONCAT(?,_latin1'a'))
+latin1
+EXECUTE IMMEDIATE "SELECT CHARSET(CONCAT(?,_latin1'a'))" USING TIME'10:20:30';
+CHARSET(CONCAT(?,_latin1'a'))
+latin1
+EXECUTE IMMEDIATE "SELECT CHARSET(CONCAT(?,_latin1'a'))" USING TIMESTAMP'2001-01-01 10:20:30';
+CHARSET(CONCAT(?,_latin1'a'))
+latin1
+EXECUTE IMMEDIATE "SELECT COERCIBILITY(?)" USING 5;
+COERCIBILITY(?)
+5
+EXECUTE IMMEDIATE "SELECT COERCIBILITY(?)" USING 5.5;
+COERCIBILITY(?)
+5
+EXECUTE IMMEDIATE "SELECT COERCIBILITY(?)" USING 5.5e0;
+COERCIBILITY(?)
+5
+EXECUTE IMMEDIATE "SELECT COERCIBILITY(?)" USING TIME'10:20:30';
+COERCIBILITY(?)
+5
+EXECUTE IMMEDIATE "SELECT COERCIBILITY(?)" USING TIMESTAMP'2001-01-01 10:20:30';
+COERCIBILITY(?)
+5
+#
+# MDEV-14435 Different UNSIGNED flag of out user variable for YEAR parameter for direct vs prepared CALL
+#
+CREATE PROCEDURE p1(OUT v INT UNSIGNED) SET v = 2010;
+CALL p1(@a);
+PREPARE stmt FROM 'CALL p1(?)';
+EXECUTE stmt USING @b;
+DEALLOCATE PREPARE stmt;
+CREATE TABLE t1 AS SELECT @a AS a, @b AS b;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` bigint(20) unsigned DEFAULT NULL,
+ `b` bigint(20) unsigned DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+DROP PROCEDURE p1;
+CREATE PROCEDURE p1(OUT v YEAR) SET v = 2010;
+CALL p1(@a);
+PREPARE stmt FROM 'CALL p1(?)';
+EXECUTE stmt USING @b;
+DEALLOCATE PREPARE stmt;
+CREATE TABLE t1 AS SELECT @a AS a, @b AS b;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` bigint(20) unsigned DEFAULT NULL,
+ `b` bigint(20) unsigned DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+DROP PROCEDURE p1;
+CREATE PROCEDURE p1(OUT v BIT(16)) SET v = 2010;
+CALL p1(@a);
+PREPARE stmt FROM 'CALL p1(?)';
+EXECUTE stmt USING @b;
+DEALLOCATE PREPARE stmt;
+CREATE TABLE t1 AS SELECT @a AS a, @b AS b;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` bigint(20) unsigned DEFAULT NULL,
+ `b` bigint(20) unsigned DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+DROP PROCEDURE p1;
+#
+# MDEV-14426 Assertion in Diagnostics_area::set_error_status when using a bad datetime with PS and SP
+#
+CREATE PROCEDURE p1(OUT a VARCHAR(20))
+BEGIN
+SET a=10;
+END;
+$$
+BEGIN NOT ATOMIC
+DECLARE a DATETIME;
+CALL p1(a);
+END;
+$$
+ERROR 22007: Incorrect datetime value: '10' for column ``.``.`a` at row 1
+BEGIN NOT ATOMIC
+DECLARE a DATETIME;
+EXECUTE IMMEDIATE 'CALL p1(?)' USING a;
+END;
+$$
+ERROR 22007: Incorrect datetime value: '10' for column ``.``.`a` at row 1
+BEGIN NOT ATOMIC
+DECLARE a DATETIME;
+PREPARE stmt FROM 'CALL p1(?)';
+EXECUTE stmt USING a;
+DEALLOCATE PREPARE stmt;
+END;
+$$
+ERROR 22007: Incorrect datetime value: '10' for column ``.``.`a` at row 1
+DROP PROCEDURE p1;
+#
+# MDEV-14603 signal 11 with short stacktrace
+#
+SET NAMES utf8;
+CREATE TABLE t1(i INT);
+CREATE PROCEDURE p1(tn VARCHAR(32))
+EXECUTE IMMEDIATE CONCAT('ANALYZE TABLE ',tn);
+CALL p1('t1');
+Table Op Msg_type Msg_text
+test.t1 analyze status Table is already up to date
+DROP PROCEDURE p1;
+DROP TABLE t1;
+SET NAMES utf8;
+CREATE PROCEDURE p1()
+EXECUTE IMMEDIATE CONCAT('SELECT ',CONVERT(RAND() USING latin1));
+CALL p1();
+DROP PROCEDURE p1;
+SET NAMES utf8;
+CREATE PROCEDURE p1()
+BEGIN
+PREPARE stmt FROM CONCAT('SELECT ',CONVERT(RAND() USING latin1));
+EXECUTE stmt;
+DEALLOCATE PREPARE stmt;
+END;
+$$
+CALL p1();
+DROP PROCEDURE p1;
+SET NAMES utf8;
+CREATE PROCEDURE p1(a VARCHAR(10) CHARACTER SET utf8)
+EXECUTE IMMEDIATE 'SELECT ?' USING CONCAT(a, CONVERT(RAND() USING latin1));
+CALL p1('x');
+DROP PROCEDURE p1;
+SET NAMES utf8;
+CREATE PROCEDURE p1(a VARCHAR(10) CHARACTER SET utf8)
+BEGIN
+PREPARE stmt FROM 'SELECT ?';
+EXECUTE stmt USING CONCAT(a, CONVERT(RAND() USING latin1));
+DEALLOCATE PREPARE stmt;
+END;
+$$
+CALL p1('x');
+DROP PROCEDURE p1;
+create table t1 (b blob default '');
+prepare stmt from "alter table t1 force";
+execute stmt;
+execute stmt;
+execute stmt;
+set names latin1;
+prepare stmt from "alter table t1 modify b text character set utf8 default 'a'";
+execute stmt;
+execute stmt;
+execute stmt;
+drop table t1;
+#
+# MDEV-12060 Crash in EXECUTE IMMEDIATE with an expression returning a GRANT command
+#
+CREATE ROLE testrole;
+CREATE OR REPLACE PROCEDURE p1()
+BEGIN
+END;
+/
+CREATE PROCEDURE p2 (wgrp VARCHAR(10))
+BEGIN
+EXECUTE IMMEDIATE concat('GRANT EXECUTE ON PROCEDURE p1 TO ',wgrp);
+END;
+/
+CALL p2('testrole');
+DROP PROCEDURE p2;
+CREATE PROCEDURE p2 ()
+BEGIN
+EXECUTE IMMEDIATE concat(_utf8'GRANT EXECUTE ON PROCEDURE p1 TO ',_latin1'testrole');
+END;
+/
+CALL p2();
+DROP PROCEDURE p2;
+CREATE PROCEDURE p2 ()
+BEGIN
+PREPARE stmt FROM concat(_utf8'GRANT EXECUTE ON PROCEDURE p1 TO ',_latin1' testrole');
+EXECUTE stmt;
+DEALLOCATE PREPARE stmt;
+END;
+/
+CALL p2();
+DROP PROCEDURE p2;
+DROP PROCEDURE p1;
+DROP ROLE testrole;
+#
+# MDEV-16992: prepare of CREATE TABLE, CREATE VIEW, DO, SET, CALL
+# statements with CTE containing materialized derived
+# (the bug is reproducible on 10.4)
+#
+prepare stmt from
+"CREATE TABLE t1 AS
+ WITH cte(a) AS (SELECT * FROM (SELECT 1) AS t) SELECT * FROM cte;";
+execute stmt;
+select * from t1;
+a
+1
+prepare stmt from
+"CREATE VIEW v1 AS
+ WITH cte(a) AS (SELECT * FROM (SELECT 1) AS t) SELECT * FROM cte;";
+execute stmt;
+select * from v1;
+a
+1
+prepare stmt from
+"DO (SELECT 1
+ FROM (WITH cte AS (SELECT * FROM (SELECT 1) AS t)
+ SELECT * FROM cte) AS tt);";
+execute stmt;
+prepare stmt from
+"SET @a = (SELECT 1
+ FROM (WITH cte AS (SELECT * FROM (SELECT 1) AS t)
+ SELECT * FROM cte) AS t);";
+execute stmt;
+create procedure p (i int) insert into t1 values(i);
+prepare stmt from
+"CALL p
+ ((SELECT 1
+ FROM (WITH cte AS (SELECT * FROM (SELECT 1) AS t)
+ SELECT * FROM cte) AS tt));";
+execute stmt;
+select * from t1;
+a
+1
+1
+drop procedure p;
+drop view v1;
+drop table t1;
+#
+# End of 10.2 tests
+#
diff --cc mysql-test/r/stat_tables.result
index 7fd0b5902ec,0a53a5ae99d..f001c78bc11
--- a/mysql-test/r/stat_tables.result
+++ b/mysql-test/r/stat_tables.result
@@@ -692,63 -692,23 +692,81 @@@ USE test
delete from mysql.table_stats;
delete from mysql.column_stats;
delete from mysql.index_stats;
+ #
+ # MDEV-19352: Server crash in alloc_histograms_for_table_share upon query from information schema
+ #
+ use test;
+ set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
+ set @@optimizer_use_condition_selectivity= 4;
+ set use_stat_tables='preferably';
+ CREATE TABLE t1 (a INT);
+ CREATE TABLE t2 (b INT);
+ CREATE VIEW v AS SELECT * FROM t1 JOIN t2;
+ INSERT INTO t2 SELECT * FROM x;
+ ERROR 42S02: Table 'test.x' doesn't exist
+ select * from information_schema.tables where table_name='v';
+ TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT
+ def test v VIEW NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL VIEW
+ drop table t1,t2;
+ drop view v;
+ set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @save_optimizer_switch=@@optimizer_switch;
set use_stat_tables=@save_use_stat_tables;
+#
+# MDEV-18899: Server crashes in Field::set_warning_truncated_wrong_value
+#
+set names utf8;
+set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
+set optimizer_use_condition_selectivity=4;
+set use_stat_tables=preferably;
+set @save_histogram_size= @@histogram_size;
+set histogram_size=255;
+create table t1 ( a varchar(255) character set utf8);
+insert into t1 values (REPEAT('ӥ',255)), (REPEAT('ç',255));
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+select HEX(RIGHT(min_value, 1)), length(min_value) from mysql.column_stats where db_name='test' and table_name='t1';
+HEX(RIGHT(min_value, 1)) length(min_value)
+A7 254
+select HEX(RIGHT(max_value, 1)), length(max_value) from mysql.column_stats where db_name='test' and table_name='t1';
+HEX(RIGHT(max_value, 1)) length(max_value)
+A5 254
+analyze select * from t1 where a >= 'Ó¥';
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 2.00 50.00 50.00 Using where
+set @save_sql_mode= @@sql_mode;
+set sql_mode='ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+update mysql.column_stats set min_value= REPEAT('Ó¥',255) where db_name='test' and table_name='t1';
+Warnings:
+Warning 1265 Data truncated for column 'min_value' at row 1
+select HEX(RIGHT(min_value, 1)), length(min_value) from mysql.column_stats where db_name='test' and table_name='t1';
+HEX(RIGHT(min_value, 1)) length(min_value)
+D3 255
+analyze select * from t1 where a >= 'Ó¥';
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 2.00 50.00 50.00 Using where
+set names latin1;
+drop table t1;
+CREATE TABLE t1 (col1 date);
+INSERT INTO t1 VALUES('2004-01-01'),('2004-02-29');
+INSERT INTO t1 VALUES('0000-10-31');
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+update mysql.column_stats set min_value='2004-0-31123' where db_name='test' and table_name='t1';
+select min_value from mysql.column_stats where db_name='test' and table_name='t1';
+min_value
+2004-0-31123
+select * from t1;
+col1
+2004-01-01
+2004-02-29
+0000-10-31
+drop table t1;
+set @@sql_mode= @save_sql_mode;
+set use_stat_tables=@save_use_stat_tables;
+set @@histogram_size= @save_histogram_size;
+set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
diff --cc mysql-test/r/stat_tables_innodb.result
index 2bc69c24104,9a93b479664..1107e349582
--- a/mysql-test/r/stat_tables_innodb.result
+++ b/mysql-test/r/stat_tables_innodb.result
@@@ -719,65 -719,25 +719,83 @@@ USE test
delete from mysql.table_stats;
delete from mysql.column_stats;
delete from mysql.index_stats;
+ #
+ # MDEV-19352: Server crash in alloc_histograms_for_table_share upon query from information schema
+ #
+ use test;
+ set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
+ set @@optimizer_use_condition_selectivity= 4;
+ set use_stat_tables='preferably';
+ CREATE TABLE t1 (a INT);
+ CREATE TABLE t2 (b INT);
+ CREATE VIEW v AS SELECT * FROM t1 JOIN t2;
+ INSERT INTO t2 SELECT * FROM x;
+ ERROR 42S02: Table 'test.x' doesn't exist
+ select * from information_schema.tables where table_name='v';
+ TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT
+ def test v VIEW NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL VIEW
+ drop table t1,t2;
+ drop view v;
+ set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @save_optimizer_switch=@@optimizer_switch;
set use_stat_tables=@save_use_stat_tables;
+#
+# MDEV-18899: Server crashes in Field::set_warning_truncated_wrong_value
+#
+set names utf8;
+set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
+set optimizer_use_condition_selectivity=4;
+set use_stat_tables=preferably;
+set @save_histogram_size= @@histogram_size;
+set histogram_size=255;
+create table t1 ( a varchar(255) character set utf8);
+insert into t1 values (REPEAT('ӥ',255)), (REPEAT('ç',255));
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+select HEX(RIGHT(min_value, 1)), length(min_value) from mysql.column_stats where db_name='test' and table_name='t1';
+HEX(RIGHT(min_value, 1)) length(min_value)
+A7 254
+select HEX(RIGHT(max_value, 1)), length(max_value) from mysql.column_stats where db_name='test' and table_name='t1';
+HEX(RIGHT(max_value, 1)) length(max_value)
+A5 254
+analyze select * from t1 where a >= 'Ó¥';
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 2.00 50.00 50.00 Using where
+set @save_sql_mode= @@sql_mode;
+set sql_mode='ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+update mysql.column_stats set min_value= REPEAT('Ó¥',255) where db_name='test' and table_name='t1';
+Warnings:
+Warning 1265 Data truncated for column 'min_value' at row 1
+select HEX(RIGHT(min_value, 1)), length(min_value) from mysql.column_stats where db_name='test' and table_name='t1';
+HEX(RIGHT(min_value, 1)) length(min_value)
+D3 255
+analyze select * from t1 where a >= 'Ó¥';
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 2.00 50.00 50.00 Using where
+set names latin1;
+drop table t1;
+CREATE TABLE t1 (col1 date);
+INSERT INTO t1 VALUES('2004-01-01'),('2004-02-29');
+INSERT INTO t1 VALUES('0000-10-31');
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+update mysql.column_stats set min_value='2004-0-31123' where db_name='test' and table_name='t1';
+select min_value from mysql.column_stats where db_name='test' and table_name='t1';
+min_value
+2004-0-31123
+select * from t1;
+col1
+2004-01-01
+2004-02-29
+0000-10-31
+drop table t1;
+set @@sql_mode= @save_sql_mode;
+set use_stat_tables=@save_use_stat_tables;
+set @@histogram_size= @save_histogram_size;
+set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
SET SESSION STORAGE_ENGINE=DEFAULT;
diff --cc mysql-test/r/statistics.result
index 34a17cf049c,135a0806bc3..267d9da965e
--- a/mysql-test/r/statistics.result
+++ b/mysql-test/r/statistics.result
@@@ -1735,25 -1735,18 +1735,39 @@@ rename table t1 to t2, t3 to t4
ERROR 42S02: Table 'test.t3' doesn't exist
drop table t1, mysql.table_stats;
rename table test.table_stats to mysql.table_stats;
+ #
+ # MDEV-19334: bool is_eits_usable(Field*): Assertion `field->table->stats_is_read' failed.
+ #
+ create temporary table t1(a int);
+ insert into t1 values (1),(2),(3);
+ set use_stat_tables=preferably;
+ set @optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
+ set optimizer_use_condition_selectivity=4;
+ select * from t1 where a >= 2;
+ a
+ 2
+ 3
+ drop table t1;
+ set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set use_stat_tables=@save_use_stat_tables;
+#
+# Start of 10.2 tests
+#
+#
+# MDEV-10134 Add full support for DEFAULT
+#
+CREATE TABLE t1 (a BLOB, b TEXT DEFAULT DECODE_HISTOGRAM('SINGLE_PREC_HB',a));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` blob DEFAULT NULL,
+ `b` text DEFAULT decode_histogram('SINGLE_PREC_HB',`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (a) VALUES (0x0000000000000000000000000101010101010101010202020303030304040404050505050606070707080809090A0A0B0C0D0D0E0E0F10111213131415161718191B1C1E202224292A2E33373B4850575F6A76818C9AA7B9C4CFDADFE5EBF0F4F8FAFCFF);
+SELECT b FROM t1;
+b
+0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.004,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.004,0.000,0.000,0.004,0.000,0.000,0.000,0.004,0.000,0.000,0.000,0.004,0.000,0.000,0.000,0.004,0.000,0.004,0.000,0.000,0.004,0.000,0.004,0.000,0.004,0.000,0.004,0.004,0.004,0.000,0.004,0.000,0.004,0.004,0.004,0.004,0.004,0.000,0.004,0.004,0.004,0.004,0.004,0.004,0.008,0.004,0.008,0.008,0.008,0.008,0.020,0.004,0.016,0.020,0.016,0.016,0.051,0.031,0.027,0.031,0.043,0.047,0.043,0.043,0.055,0.051,0.071,0.043,0.043,0.043,0.020,0.024,0.024,0.020,0.016,0.016,0.008,0.008,0.012,0.000
+DROP TABLE t1;
+#
+# End of 10.2 tests
+#
diff --cc mysql-test/r/type_bit.result
index eeedc501dc4,f460d05e2a9..7eaba70d7fa
--- a/mysql-test/r/type_bit.result
+++ b/mysql-test/r/type_bit.result
@@@ -831,21 -831,9 +831,28 @@@ COALESCE(val, 1
0
DROP TABLE t1;
#
+ # MDEV-18452 ASAN unknown-crash in Field::set_default upon SET bit_column = DEFAULT
+ #
+ CREATE TABLE t1 (b BIT(20)) ENGINE=MyISAM;
+ INSERT INTO t1 VALUES (0);
+ UPDATE t1 SET b = DEFAULT;
+ DROP TABLE t1;
++#
+# End of 10.1 tests
+#
+#
+# Start of 10.2 tests
+#
+#
+# MDEV-9334 ALTER from DECIMAL to BIGINT UNSIGNED returns a wrong result
+#
+CREATE TABLE t1 (a DECIMAL(30,0));
+INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
+ALTER TABLE t1 MODIFY a BIT(64);
+SELECT a+0 FROM t1;
+a+0
+18446744073709551615
+DROP TABLE IF EXISTS t1;
+#
+# End of 10.2 tests
+#
diff --cc mysql-test/r/view_grant.result
index 04ad19c5ddc,a1eb6e8bdb6..838ed7d5fd2
--- a/mysql-test/r/view_grant.result
+++ b/mysql-test/r/view_grant.result
@@@ -204,8 -185,8 +206,9 @@@ create view mysqltest.v3 (a,c) as selec
create user mysqltest_1@localhost;
grant update (a) on mysqltest.v2 to mysqltest_1@localhost;
grant update on mysqltest.v1 to mysqltest_1@localhost;
+ grant update on mysqltest.t3 to mysqltest_1@localhost;
grant select on mysqltest.* to mysqltest_1@localhost;
+connection user1;
use mysqltest;
update t2,v1 set v1.a=v1.a+v1.c where t2.x=v1.c;
select * from t1;
diff --cc mysql-test/std_data/serversan-cert.pem
index d40127365ca,b6494c29b00..41d5241a389
--- a/mysql-test/std_data/serversan-cert.pem
+++ b/mysql-test/std_data/serversan-cert.pem
@@@ -1,72 -1,60 +1,72 @@@
Certificate:
Data:
Version: 3 (0x2)
-- Serial Number: 4 (0x4)
-- Signature Algorithm: sha256WithRSAEncryption
++ Serial Number: 1 (0x1)
++ Signature Algorithm: sha256WithRSAEncryption
Issuer: CN=cacert, C=FI, ST=Helsinki, L=Helsinki, O=MariaDB
Validity
- Not Before: Jan 27 10:11:15 2019 GMT
- Not After : Jan 22 10:11:15 2039 GMT
- Not Before: Apr 24 14:29:50 2019 GMT
- Not After : Apr 19 14:29:50 2039 GMT
++ Not Before: May 2 14:29:07 2019 GMT
++ Not After : Apr 27 14:29:07 2039 GMT
Subject: C=FI, ST=Helsinki, L=Helsinki, O=MariaDB, CN=server
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
- Public-Key: (2048 bit)
- Public-Key: (1024 bit)
++ RSA Public-Key: (2048 bit)
Modulus:
- 00:be:e7:9b:da:e1:bf:fe:e6:a4:6d:c2:20:8a:1f:
- ea:8e:1a:a6:3f:57:93:75:d8:3b:80:55:bd:f3:fe:
- c3:1e:50:0f:e9:66:0e:bf:98:98:5f:06:95:fc:4a:
- 9a:b2:fc:7f:b1:e0:d9:ef:df:6c:28:d0:12:98:bf:
- 78:b6:f4:1a:94:83:a0:3e:bc:d3:b3:02:4f:4a:96:
- d9:30:b5:7c:5a:82:dd:ff:96:72:1c:f5:ad:80:bd:
- ec:f7:fa:9c:40:e2:37:f5:86:b7:c6:b0:bb:6a:69:
- 77:77:e1:2a:b1:03:bb:1e:bb:e8:b3:7a:2c:bf:a6:
- c5:6b:4d:99:fb:f3:84:ec:ac:a9:2a:f3:f5:09:4e:
- 5b:75:18:9c:68:f7:c9:2b:59:0b:41:33:60:23:fa:
- d4:f8:64:e2:51:59:37:29:f2:bb:68:f5:6a:47:69:
- 58:ed:a8:bb:11:9d:6b:d1:77:75:01:da:57:5d:3e:
- 8e:bf:f7:b1:7b:69:df:53:22:5f:7d:c5:ac:b0:80:
- 0c:20:ea:9d:f7:c4:52:d8:31:03:07:b8:84:a9:74:
- e3:2e:4a:68:bf:a1:84:c6:38:32:c1:11:ef:f9:4b:
- e6:79:f4:7b:7f:52:f3:36:4b:a6:d8:a5:ad:d2:02:
- 40:89:42:ed:ba:d6:ea:74:d0:6e:c1:bc:02:33:9f:
- 0b:ab
- 00:c4:ca:f5:53:66:e9:f7:48:39:dc:8c:d7:06:f4:
- 03:3b:87:11:8e:8f:4d:a1:2b:b7:2a:38:37:6c:a2:
- 34:2f:d4:9d:84:78:99:7f:6b:ec:c3:63:ea:e8:9c:
- 57:af:a4:78:cf:59:5f:79:6b:29:11:2c:be:16:56:
- 8f:7b:76:57:c9:36:d5:7f:58:10:f3:d1:c2:dc:09:
- 17:f2:7b:fa:2d:71:c2:50:15:92:af:a0:58:32:f0:
- 64:60:d3:9a:c6:3c:8a:31:e0:b6:b2:9f:29:7d:97:
- 87:3c:62:bf:e6:8e:e7:2f:4a:ac:f7:fe:93:38:bc:
- 86:d4:87:91:38:2d:ed:e2:0d
++ 00:b1:17:08:8f:43:a3:00:01:98:3b:52:8f:0b:b0:
++ 13:4c:eb:df:37:0d:a3:2c:5b:38:8d:28:88:94:33:
++ f3:04:0a:b2:1c:98:27:ec:76:9f:a2:f7:35:79:48:
++ cc:55:1e:68:b4:a7:4d:40:0e:bd:d5:86:c0:e5:cc:
++ cc:fa:41:5a:55:3f:79:59:28:6b:a2:ca:55:77:c9:
++ 3f:5e:c4:96:e1:8c:64:cc:c7:95:29:48:81:bf:a8:
++ c0:d2:3a:6f:6d:a7:14:b5:ec:d8:b6:c1:d8:86:7f:
++ 7a:e9:83:c0:83:c3:e1:5a:30:dd:29:ec:85:68:d9:
++ 09:9a:75:eb:ab:5f:3d:b1:a3:4f:e2:de:54:35:56:
++ 9c:7d:8f:2a:4a:18:8d:34:05:05:b4:3b:5b:9e:df:
++ 40:20:ad:87:a3:6b:c1:f2:da:a3:65:ef:c4:cb:3c:
++ 24:68:43:23:e8:14:a7:c0:11:b7:5f:e9:e3:09:24:
++ af:dd:ac:97:75:22:9e:15:b7:20:b0:82:b0:e1:0f:
++ 0f:41:fc:da:3b:76:0c:6b:f8:42:06:e2:9e:70:9a:
++ ed:a1:73:23:58:5c:f1:98:18:42:42:d4:0f:2e:35:
++ 41:00:50:1d:15:e7:65:30:b5:db:72:7d:88:da:be:
++ 93:72:e3:65:14:fa:0d:23:98:d6:5c:a5:fc:bb:8a:
++ 8f:f9
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Alternative Name:
- DNS:localhost
+ IP Address:127.0.0.1, DNS:localhost
Signature Algorithm: sha256WithRSAEncryption
- 73:fa:07:e9:05:65:28:2e:72:91:29:f8:6b:a6:11:2e:e3:e2:
- 14:6c:4d:7e:69:16:01:47:55:df:88:8d:be:82:37:bd:95:4e:
- cc:9c:71:98:fa:3b:0d:ad:13:53:e7:04:e7:6f:38:97:ce:12:
- c1:f1:c2:48:bc:3f:a9:61:b5:22:48:e1:8c:64:1f:58:14:e9:
- dd:5d:9f:e3:e7:78:5f:7d:43:6a:89:21:38:9d:65:e8:71:c1:
- 62:d9:62:c7:e6:b3:bd:cb:de:f1:7c:46:10:53:28:8c:47:02:
- 22:91:ad:78:c0:21:10:28:a8:2c:23:a3:f2:c0:2c:c9:71:0d:
- b4:a0:ca:37:ac:36:b3:1c:75:6a:74:85:a5:ba:c2:19:de:e4:
- 3e:c2:3c:a4:cc:dc:8e:a7:08:36:f4:e9:81:32:ac:49:f4:34:
- 89:84:e7:61:54:29:7b:c0:54:53:b9:73:37:58:21:32:56:01:
- 7f:97:d3:a1:06:5b:06:14:19:6a:42:5d:45:5a:ba:8e:14:d7:
- df:49:46:f2:83:7a:f0:d6:25:52:37:39:ae:37:ea:67:5f:7f:
- 7b:6d:f1:42:c9:0f:44:4d:f7:39:2d:39:78:12:93:42:1b:4a:
- 6d:f8:76:48:78:41:e9:a1:0b:78:fd:ad:29:f1:28:62:b8:9f:
- f7:22:39:3b
- c5:83:b2:bb:a3:3b:a9:42:df:de:30:db:09:90:e1:3e:7a:19:
- 09:4b:82:a3:1d:e8:23:3f:61:46:b7:98:b3:2e:90:61:7f:c5:
- a1:36:a6:3e:b0:5b:3f:a1:23:70:7d:0f:71:5b:13:0f:be:73:
- 1b:31:1a:b3:ce:f7:59:aa:b4:18:8d:37:e1:8c:07:af:10:18:
- 4e:37:16:b2:67:73:5b:79:c6:30:16:ab:62:c5:c2:3e:72:06:
- fd:b2:2a:f5:92:99:32:7e:ed:65:7e:bd:b2:74:9d:38:d4:d5:
- 35:f8:06:dd:ac:85:75:e7:c2:6b:16:e8:2f:0f:c4:d3:b7:e7:
- be:b6:cd:61:7b:29:e6:3a:c2:7c:38:46:fb:2c:a3:da:fe:84:
- 5f:79:99:2f:80:3e:ec:09:88:f4:31:cd:5c:d1:32:a1:9f:1f:
- 55:f2:9b:c6:4e:b2:26:04:9b:ee:04:42:d2:40:88:0e:c8:cf:
- e0:6e:06:a1:6a:c8:1a:62:d0:7a:a4:19:4d:9c:e4:b6:57:e2:
- 1d:19:57:54:58:1b:cc:bf:b8:29:e2:15:1e:f1:96:be:30:9e:
- 4c:05:f9:90:e3:a1:7b:d7:e0:63:a6:d1:25:b1:80:81:f3:1b:
- 55:4f:c1:64:9f:a1:06:01:8c:9a:15:64:b9:12:96:a8:22:4b:
- 4a:d9:e3:04
++ 7e:97:8a:e9:81:e7:c9:44:0d:a6:45:7c:f6:ae:12:f9:c3:3c:
++ 2c:1f:de:aa:6b:1b:1a:09:ce:9d:d2:d7:5c:ab:32:98:91:1e:
++ f8:7d:63:7a:c0:d3:34:eb:3a:55:b2:cd:f5:99:5f:95:bb:3e:
++ 52:1d:05:2d:06:26:08:d1:e8:59:09:61:64:67:70:6d:5b:94:
++ 2b:b4:0c:59:88:bf:56:c8:fe:73:7f:47:e9:b0:e5:46:71:26:
++ 73:5f:d2:a0:81:4a:67:43:7a:18:2a:81:5b:2a:90:a9:3e:7b:
++ 73:6e:83:b5:55:06:75:d1:8c:d1:d8:ad:7c:6a:ce:48:00:dd:
++ c2:1d:b9:40:cd:91:2f:43:c4:d6:f4:79:5e:5c:83:23:87:a7:
++ 38:3c:d8:49:81:d2:eb:49:c7:f0:5f:3d:6e:a0:38:75:ca:92:
++ ce:d5:a7:54:fc:0e:7e:f4:14:66:77:79:93:bb:92:56:ab:f3:
++ 1b:3c:75:57:4f:2d:12:6d:99:5b:d0:b5:62:b7:1d:e3:5b:a9:
++ 70:cd:58:41:77:a6:2c:6d:34:bd:11:13:7d:ca:51:3e:06:f5:
++ cb:d4:d5:11:64:b0:cc:30:2f:a5:62:d0:dd:2c:8c:66:3f:df:
++ 2a:df:4d:56:99:5c:12:af:ee:92:e1:02:f6:ce:12:be:99:fa:
++ cc:0c:5c:af
-----BEGIN CERTIFICATE-----
- MIIDPzCCAiegAwIBAgIBBDANBgkqhkiG9w0BAQsFADBWMQ8wDQYDVQQDDAZjYWNl
-MIICwTCCAamgAwIBAgIBBDANBgkqhkiG9w0BAQsFADBWMQ8wDQYDVQQDDAZjYWNl
++MIIDRTCCAi2gAwIBAgIBATANBgkqhkiG9w0BAQsFADBWMQ8wDQYDVQQDDAZjYWNl
cnQxCzAJBgNVBAYTAkZJMREwDwYDVQQIDAhIZWxzaW5raTERMA8GA1UEBwwISGVs
- c2lua2kxEDAOBgNVBAoMB01hcmlhREIwHhcNMTkwMTI3MTAxMTE1WhcNMzkwMTIy
- MTAxMTE1WjBWMQswCQYDVQQGEwJGSTERMA8GA1UECAwISGVsc2lua2kxETAPBgNV
-c2lua2kxEDAOBgNVBAoMB01hcmlhREIwHhcNMTkwNDI0MTQyOTUwWhcNMzkwNDE5
-MTQyOTUwWjBWMQswCQYDVQQGEwJGSTERMA8GA1UECAwISGVsc2lua2kxETAPBgNV
++c2lua2kxEDAOBgNVBAoMB01hcmlhREIwHhcNMTkwNTAyMTQyOTA3WhcNMzkwNDI3
++MTQyOTA3WjBWMQswCQYDVQQGEwJGSTERMA8GA1UECAwISGVsc2lua2kxETAPBgNV
BAcMCEhlbHNpbmtpMRAwDgYDVQQKDAdNYXJpYURCMQ8wDQYDVQQDDAZzZXJ2ZXIw
- ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC+55va4b/+5qRtwiCKH+qO
- GqY/V5N12DuAVb3z/sMeUA/pZg6/mJhfBpX8Spqy/H+x4Nnv32wo0BKYv3i29BqU
- g6A+vNOzAk9KltkwtXxagt3/lnIc9a2Avez3+pxA4jf1hrfGsLtqaXd34SqxA7se
- u+izeiy/psVrTZn784TsrKkq8/UJTlt1GJxo98krWQtBM2Aj+tT4ZOJRWTcp8rto
- 9WpHaVjtqLsRnWvRd3UB2lddPo6/97F7ad9TIl99xaywgAwg6p33xFLYMQMHuISp
- dOMuSmi/oYTGODLBEe/5S+Z59Ht/UvM2S6bYpa3SAkCJQu261up00G7BvAIznwur
- AgMBAAGjGDAWMBQGA1UdEQQNMAuCCWxvY2FsaG9zdDANBgkqhkiG9w0BAQsFAAOC
- AQEAc/oH6QVlKC5ykSn4a6YRLuPiFGxNfmkWAUdV34iNvoI3vZVOzJxxmPo7Da0T
- U+cE5284l84SwfHCSLw/qWG1IkjhjGQfWBTp3V2f4+d4X31DaokhOJ1l6HHBYtli
- x+azvcve8XxGEFMojEcCIpGteMAhECioLCOj8sAsyXENtKDKN6w2sxx1anSFpbrC
- Gd7kPsI8pMzcjqcINvTpgTKsSfQ0iYTnYVQpe8BUU7lzN1ghMlYBf5fToQZbBhQZ
- akJdRVq6jhTX30lG8oN68NYlUjc5rjfqZ19/e23xQskPRE33OS05eBKTQhtKbfh2
- SHhB6aELeP2tKfEoYrif9yI5Ow==
-gZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMTK9VNm6fdIOdyM1wb0AzuHEY6P
-TaErtyo4N2yiNC/UnYR4mX9r7MNj6uicV6+keM9ZX3lrKREsvhZWj3t2V8k21X9Y
-EPPRwtwJF/J7+i1xwlAVkq+gWDLwZGDTmsY8ijHgtrKfKX2Xhzxiv+aO5y9KrPf+
-kzi8htSHkTgt7eINAgMBAAGjHjAcMBoGA1UdEQQTMBGHBH8AAAGCCWxvY2FsaG9z
-dDANBgkqhkiG9w0BAQsFAAOCAQEAxYOyu6M7qULf3jDbCZDhPnoZCUuCox3oIz9h
-RreYsy6QYX/FoTamPrBbP6EjcH0PcVsTD75zGzEas873Waq0GI034YwHrxAYTjcW
-smdzW3nGMBarYsXCPnIG/bIq9ZKZMn7tZX69snSdONTVNfgG3ayFdefCaxboLw/E
-07fnvrbNYXsp5jrCfDhG+yyj2v6EX3mZL4A+7AmI9DHNXNEyoZ8fVfKbxk6yJgSb
-7gRC0kCIDsjP4G4GoWrIGmLQeqQZTZzktlfiHRlXVFgbzL+4KeIVHvGWvjCeTAX5
-kOOhe9fgY6bRJbGAgfMbVU/BZJ+hBgGMmhVkuRKWqCJLStnjBA==
++ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCxFwiPQ6MAAZg7Uo8LsBNM
++6983DaMsWziNKIiUM/MECrIcmCfsdp+i9zV5SMxVHmi0p01ADr3VhsDlzMz6QVpV
++P3lZKGuiylV3yT9exJbhjGTMx5UpSIG/qMDSOm9tpxS17Ni2wdiGf3rpg8CDw+Fa
++MN0p7IVo2QmadeurXz2xo0/i3lQ1Vpx9jypKGI00BQW0O1ue30AgrYeja8Hy2qNl
++78TLPCRoQyPoFKfAEbdf6eMJJK/drJd1Ip4VtyCwgrDhDw9B/No7dgxr+EIG4p5w
++mu2hcyNYXPGYGEJC1A8uNUEAUB0V52UwtdtyfYjavpNy42UU+g0jmNZcpfy7io/5
++AgMBAAGjHjAcMBoGA1UdEQQTMBGHBH8AAAGCCWxvY2FsaG9zdDANBgkqhkiG9w0B
++AQsFAAOCAQEAfpeK6YHnyUQNpkV89q4S+cM8LB/eqmsbGgnOndLXXKsymJEe+H1j
++esDTNOs6VbLN9Zlflbs+Uh0FLQYmCNHoWQlhZGdwbVuUK7QMWYi/Vsj+c39H6bDl
++RnEmc1/SoIFKZ0N6GCqBWyqQqT57c26DtVUGddGM0ditfGrOSADdwh25QM2RL0PE
++1vR5XlyDI4enODzYSYHS60nH8F89bqA4dcqSztWnVPwOfvQUZnd5k7uSVqvzGzx1
++V08tEm2ZW9C1Yrcd41upcM1YQXemLG00vRETfcpRPgb1y9TVEWSwzDAvpWLQ3SyM
++Zj/fKt9NVplcEq/ukuEC9s4Svpn6zAxcrw==
-----END CERTIFICATE-----
diff --cc mysql-test/std_data/serversan-key.pem
index 84c34d63b0f,0fcb42b4f63..22387b3af7d
--- a/mysql-test/std_data/serversan-key.pem
+++ b/mysql-test/std_data/serversan-key.pem
@@@ -1,28 -1,16 +1,28 @@@
-----BEGIN PRIVATE KEY-----
- MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC+55va4b/+5qRt
- wiCKH+qOGqY/V5N12DuAVb3z/sMeUA/pZg6/mJhfBpX8Spqy/H+x4Nnv32wo0BKY
- v3i29BqUg6A+vNOzAk9KltkwtXxagt3/lnIc9a2Avez3+pxA4jf1hrfGsLtqaXd3
- 4SqxA7seu+izeiy/psVrTZn784TsrKkq8/UJTlt1GJxo98krWQtBM2Aj+tT4ZOJR
- WTcp8rto9WpHaVjtqLsRnWvRd3UB2lddPo6/97F7ad9TIl99xaywgAwg6p33xFLY
- MQMHuISpdOMuSmi/oYTGODLBEe/5S+Z59Ht/UvM2S6bYpa3SAkCJQu261up00G7B
- vAIznwurAgMBAAECggEATXOwMuyWNbejjHhPNVrfkcnUGyzPweb5tQaUa5K33OuE
- mR/z6d3iK+ODJHmsK+Pvdt6P7RcLTb+lW92K/0coJYsFj46SoTTVsKBk+7MWAa7I
- nLKQF5nBS9NCehVuIZDmPTHsC6uWTgT+GF/9LxYha8W3EmIGF7d0ryUrzSGuk0qA
- yVj4V2JbEbox5jjRUvRvCfbQnZYhT1Aa1/kN4fxYp00sQTkCQ1QZiC+SbN245nrv
- UHumVBy0dPL+vmYxKc+L9qwYhHKsspx6+RUTgW+7YbHs6LEd8HmXb0hIp1Xb4yUS
- ADVI7TgTGEGGRt1gQYkfcwl1YoVQeyBK8Yvfz88tgQKBgQD9PeBEXM+y7z8jcXAB
- f/JpmMmm+S8JhPyKOMDZRL5jPKgm93Xm0pAReo8xM/quKH2jAoMxmburnYTTskyo
- HBATcWDTBUiNkjCJORdWKwP6kvtYt8ZZsC9vrWkx4pPqTXQaXUNmrfZ1cuh5U/BK
- 5aAzN5Drx0tKie+/+2gvevoZawKBgQDA++qDlRAiNft7fEZhjA3ovOSq9kIf1hnE
- psh4SRB21QZ443gifQKRRFIhMWRX0QkTyw2PbeVJvPjab08NmcumJWK5NCxPy3C0
- /ihQV2Ip49GVYA2qlgVzOMuxJJlG6SyKvCiBmadHY/ex4Ya1YPcfhjKsNr4ObIV8
- OCvQruQmwQKBgB+jp21jGyAD/CN1fMTzM1o2GJuf7lyGHPc3+AAtMow7e9bCfByG
- mjFU2qcPE3bG4EuJeNKtnmDmoT3BvQoT135WX/59Xn8xkJbUZzIA1dJsorKG42U5
- OfP9+nKdGFXhr2vL0yv0+CHcZWcjMZZp8gX0H0sV7zY03Zti0bV869pZAoGBALDg
- c+IkJoRkm9ljXxKbDkiJkMBNMvABCN8fyk/ND8UKnIMCYaKil07Tor7/iSuf0MUO
- b6BNJkE+bYuvR3J8ypW+YEzFT/PWz7dj10lDvhoMz5QsVHpMRDSGEtOKat3+ay/B
- IxMd5J7fNjAYN6JYfEetdRY4mluYBYSD60y6byxBAoGBALDoRoub5TUMdgr66fNp
- p7tc9ERH8/htPEq5g2SrzQex7lUIp8+wmvprx0i4a2SgDYCkj6gmjG8rP2O65tsn
- dkrKXnUOjIgjHGesbZoKgE+7Gl4c+eyoDsNVHH+ZFKN26fcO9i6wrbeGKjTTMcfu
- nEXqAq0CccdZ0lXxQTS/ttbU
-MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMTK9VNm6fdIOdyM
-1wb0AzuHEY6PTaErtyo4N2yiNC/UnYR4mX9r7MNj6uicV6+keM9ZX3lrKREsvhZW
-j3t2V8k21X9YEPPRwtwJF/J7+i1xwlAVkq+gWDLwZGDTmsY8ijHgtrKfKX2Xhzxi
-v+aO5y9KrPf+kzi8htSHkTgt7eINAgMBAAECgYAKFt29COm1494TkKT1lk0UIDim
-NnKkcLlTUM6Go0pJqXzp7cTw43egDN9eTaWxO512A/8BGp1gZAra2lVA3zBg6Yqb
-QYJwT2s/DsCwFU0msw1sUr5ynJ4A/jQCwR6RzaP2xoJTPaczpoE+RiOmgvQ14GF4
-sJEfAIJCw5OglICTgQJBAOK3yeiMSF6ic8OORkOHy8LdQAFGOsKwliQltxzvRXYZ
-dWlHHAX+9l6rVC+o0rbooO4QEfJHn9ojjROr5+iIn2cCQQDeNbljgN+6K36r9Qmh
-fuBy2Ot+wRO30T4ASFelgJ0aHYEngSGSRneMmbbgDFx7v7Y9k6yY9RPiSqYX+vCQ
-425rAkAjfkpp0axyxFQDRX7Si6vmseSXTntch3C57/2e1ga12n57INrORYAkigYA
-ABoc8IZhPrrQh04LRI2Nitgfm2P5AkBmqEFGk/JIKvHxdVoGrvv4cviQ7ZgzcsqH
-DOTZBAsQVpMlcgXVcxKl9RnEdlF/pjkGR6QUYhzWjZAgQgFDnp6TAkBqIXYMvyp7
-JRfbnhze+UBgjeCoE/wTv/DiXL1yi4uVVVm8luToFv9DPAyvms/guJ7Ade5HDHye
-M/LZbE37/NYP
++MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCxFwiPQ6MAAZg7
++Uo8LsBNM6983DaMsWziNKIiUM/MECrIcmCfsdp+i9zV5SMxVHmi0p01ADr3VhsDl
++zMz6QVpVP3lZKGuiylV3yT9exJbhjGTMx5UpSIG/qMDSOm9tpxS17Ni2wdiGf3rp
++g8CDw+FaMN0p7IVo2QmadeurXz2xo0/i3lQ1Vpx9jypKGI00BQW0O1ue30AgrYej
++a8Hy2qNl78TLPCRoQyPoFKfAEbdf6eMJJK/drJd1Ip4VtyCwgrDhDw9B/No7dgxr
+++EIG4p5wmu2hcyNYXPGYGEJC1A8uNUEAUB0V52UwtdtyfYjavpNy42UU+g0jmNZc
++pfy7io/5AgMBAAECggEAP6QHb3TfHyFzk94Xihu80+fwT9iWy1n8+L2YV6pTqyAs
++4hnMPy5iMC6nCO8gf3ZuKn31RRAHKLVEnVD8WPMjg39MHL5p8BbGoEWygFwl3OiX
++UQBomm10M2xx3xsg8EcbKkXzm7oOFke55DF0/eVnFwJ4eJiHWSamTNwT1YJkqXFt
++kbYxxcpvjzFKuIOFXMTbS6OHGLHjuuyWffxEkbvM/bU13IFmDOzahLFPihcz7rFu
++CaFN9JSSj4jENPkYOiw+zTtJhgOMCoclAcNc4c5Gs95wk6pTxoj9kHJaaYqinVgI
++owUTgIXRhuixjWJd1dylgY3YvrRFENZlMe39cVKwAQKBgQDppB7Qf2FmejMYtJkA
++WmlDSy+LZnYAAYjTqIeSAlRXI91iDa9HqrdPucQkv6nPvL6yndZYIrq50BLNGiL+
++v/3Ok/9v3H8jAiCzwIuqAYoA2gHh4d4ZV9Vxoqu6CcX/2xOUL7CSOV5NkK+3Yrs7
++n47X4ILGihIKzz5GoSTHyb6zRwKBgQDCCX1jwSEnIDhPCuid4+6g1vjTvVtgVIf9
++87sds02duE8K5Uwjio7g3BlV1YzLv0jKNkUK+HuG/c7n9r0IVrs4of6t/bJjl7vJ
++RLl6ZkSybzzS2x2nYk23VZlInYWUdJS9kHlic+mXfJvJvBBwyz8WX7t2wQaTqlDu
++QCpuV+HCvwKBgDz4/q2swG9s7o7A+rjT32qXYXYArES+IcYS0iZxgy8mhezD431R
++ePtOYHiyqA81k5KrjDd+ALrjKTTrYDyZQBQ8HUpFAczSDlS6p/ga5LfqLNmVB1AX
++0vUP3b70M/7cXlSqyWqvnAOkAadbFb+umSmPRrGncKPvh7II9b9J0AGbAoGAMyD3
++BnMcfkfSLpnMQ9aMyZr7xCeQTWjY0MUJmEDoAdhQE6nqDy9yiLPWhTSZPhLwZkA4
++nzRssFxuydbNZsYb3UdqaYSBHhccZ2ORkDwke/Qtzc3pGXMg0V9f3a+MRFsX2n+Y
++TKYIdl9iWZ0Ro/cab5XYOumQBxcI7k7AH4VOutcCgYEA3JgQiYoiPohS9A49bPiF
++eDX1Ck3lgaEF72us6BfvLHTrbA/qYhVUlrbrU2P/gAy1uKDRYq5RAoNGDLdwatvE
++0hPYj1hc1DuPAAGG83/tSh2jfFVbZBw5xEDjLerkpQyop59dfTS0E/oSu6ebxIIg
++dHEwqlmDrrJv7WwUJUzuUJU=
-----END PRIVATE KEY-----
diff --cc mysql-test/suite.pm
index 3849e4ef886,f90679e6f1f..fe68295340c
--- a/mysql-test/suite.pm
+++ b/mysql-test/suite.pm
@@@ -70,10 -68,11 +70,11 @@@ sub skip_combinations
}
$skip{'include/check_ipv6.inc'} = 'No IPv6' unless ipv6_ok();
- $skip{'t/openssl_6975.test'} = 'no or too old openssl'
+ $skip{'t/openssl_6975.test'} = 'no or wrong openssl version'
unless $::mysqld_variables{'version-ssl-library'} =~ /OpenSSL (\S+)/
- and $1 ge "1.0.1d";
+ and $1 ge "1.0.1d" and $1 lt "1.1.1";
+
$skip{'t/ssl_7937.combinations'} = [ 'x509v3' ]
unless $::mysqld_variables{'version-ssl-library'} =~ /OpenSSL (\S+)/
and $1 ge "1.0.2";
diff --cc mysql-test/suite/binlog/r/binlog_mdev717.result
index 5fe80be651a,594032e7dd4..f9ec3a32845
--- a/mysql-test/suite/binlog/r/binlog_mdev717.result
+++ b/mysql-test/suite/binlog/r/binlog_mdev717.result
@@@ -18,12 -13,12 +18,14 @@@ SET DEBUG_SYNC= "now WAIT_FOR locked"
SET DEBUG_SYNC= "before_wait_locked_pname SIGNAL release";
CREATE EVENT mysqltest.e1 ON SCHEDULE EVERY 15 MINUTE DO BEGIN END;
ERROR 42000: Unknown database 'mysqltest'
+connection default;
CREATE DATABASE mysqltest;
CREATE EVENT mysqltest.e1 ON SCHEDULE EVERY 15 MINUTE DO BEGIN END;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
SET DEBUG_SYNC= "after_wait_locked_schema_name SIGNAL locked WAIT_FOR release";
DROP DATABASE mysqltest;;
+connection con1;
SET DEBUG_SYNC= "now WAIT_FOR locked";
SET DEBUG_SYNC= "before_wait_locked_pname SIGNAL release";
ALTER EVENT mysqltest.e1 ON SCHEDULE EVERY 20 MINUTE DO BEGIN END;
diff --cc mysql-test/suite/funcs_1/r/is_routines_embedded.result
index 1fc9f90ae49,e5f476367e2..193265433aa
--- a/mysql-test/suite/funcs_1/r/is_routines_embedded.result
+++ b/mysql-test/suite/funcs_1/r/is_routines_embedded.result
@@@ -187,46 -159,34 +187,58 @@@ GRANT EXECUTE ON PROCEDURE db_datadict_
TO 'testuser2'@'localhost';
GRANT EXECUTE ON db_datadict_2.* TO 'testuser2'@'localhost';
FLUSH PRIVILEGES;
-# Establish connection testuser1 (user=testuser1)
+connect testuser1, localhost, testuser1, , db_datadict;
SELECT * FROM information_schema.routines;
-SPECIFIC_NAME ROUTINE_CATALOG ROUTINE_SCHEMA ROUTINE_NAME ROUTINE_TYPE DTD_IDENTIFIER ROUTINE_BODY ROUTINE_DEFINITION EXTERNAL_NAME EXTERNAL_LANGUAGE PARAMETER_STYLE IS_DETERMINISTIC SQL_DATA_ACCESS SQL_PATH SECURITY_TYPE CREATED LAST_ALTERED SQL_MODE ROUTINE_COMMENT DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION
-sp_6_408002_1 NULL db_datadict sp_6_408002_1 PROCEDURE NULL SQL BEGIN
+SPECIFIC_NAME ROUTINE_CATALOG ROUTINE_SCHEMA ROUTINE_NAME ROUTINE_TYPE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME DTD_IDENTIFIER ROUTINE_BODY ROUTINE_DEFINITION EXTERNAL_NAME EXTERNAL_LANGUAGE PARAMETER_STYLE IS_DETERMINISTIC SQL_DATA_ACCESS SQL_PATH SECURITY_TYPE CREATED LAST_ALTERED SQL_MODE ROUTINE_COMMENT DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION
+sp_6_408002_1 def db_datadict sp_6_408002_1 PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN
SELECT * FROM db_datadict.res_6_408002_1;
END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
-sp_6_408002_2 NULL db_datadict_2 sp_6_408002_2 PROCEDURE NULL SQL BEGIN
+sp_6_408002_2 def db_datadict_2 sp_6_408002_2 PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN
SELECT * FROM db_datadict_2.res_6_408002_2;
END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
-# Establish connection testuser2 (user=testuser2)
+add_suppression def mtr add_suppression PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN INSERT INTO test_suppressions (pattern) VALUES (pattern); FLUSH NO_WRITE_TO_BINLOG TABLE test_suppressions; END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost utf8 utf8_general_ci latin1_swedish_ci
+check_testcase def mtr check_testcase PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE variable_name NOT IN ('timestamp', 'innodb_file_format_max') AND variable_name not like "Last_IO_Err*" AND variable_name != 'INNODB_IBUF_MAX_SIZE' AND variable_name != 'INNODB_USE_NATIVE_AIO' AND variable_name != 'INNODB_BUFFER_POOL_LOAD_AT_STARTUP' AND variable_name not like 'GTID%POS' AND variable_name != 'GTID_BINLOG_STATE' ORDER BY variable_name; SELECT * FROM INFORMATION_SCHEMA.SCHEMATA; SELECT * FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME NOT IN ('mtr_wsrep_notify', 'wsrep_schema'); SELECT table_name AS tables_in_test FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='test'; SELECT CONCAT(table_schema, '.', table_name) AS tables_in_mysql FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='mysql' ORDER BY tables_in_mysql; SELECT CONCAT(
table_schema, '.', table_name) AS columns_in_mysql, column_name, ordinal_position, column_default, is_nullable, data_type, character_maximum_length, character_octet_length, numeric_precision, numeric_scale, character_set_name, collation_name, column_type, column_key, extra, column_comment FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema='mysql' ORDER BY columns_in_mysql; SELECT * FROM INFORMATION_SCHEMA.EVENTS; SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME NOT IN ('gs_insert', 'ts_insert'); SELECT * FROM INFORMATION_SCHEMA.ROUTINES; SHOW STATUS LIKE 'slave_open_temp_tables'; checksum table mysql.columns_priv, mysql.db, mysql.func, mysql.help_category, mysql.help_keyword, mysql.help_relation, mysql.host, mysql.plugin, mysql.proc, mysql.procs_priv, mysql.roles_mapping, mysql.tables_priv, mysql.time_zone, mysql.time_zone_leap_second,
mysql.time_zone_name, mysql.time_zone_transition, mysql.time_zone_transition_type, mysql.user; SELECT * FROM INFORMATION_SCHEMA.PLUGINS; select * from information_schema.session_variables where variable_name = 'debug_sync'; END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost utf8 utf8_general_ci latin1_swedish_ci
+check_warnings def mtr check_warnings PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN DECLARE `pos` bigint unsigned; SET SQL_LOG_BIN=0; UPDATE error_log el, global_suppressions gs SET suspicious=0 WHERE el.suspicious=1 AND el.line REGEXP gs.pattern; UPDATE error_log el, test_suppressions ts SET suspicious=0 WHERE el.suspicious=1 AND el.line REGEXP ts.pattern; SELECT COUNT(*) INTO @num_warnings FROM error_log WHERE suspicious=1; IF @num_warnings > 0 THEN SELECT line FROM error_log WHERE suspicious=1; SELECT 2 INTO result; ELSE SELECT 0 INTO RESULT; END IF; TRUNCATE test_suppressions; DROP TABLE error_log; END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost utf8 utf8_general_ci latin1_swedish_ci
++AddGeometryColumn def mysql AddGeometryColumn PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL begin
++ set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' ADD ', geometry_column,' GEOMETRY REF_SYSTEM_ID=', t_srid); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end NULL NULL SQL NO CONTAINS SQL NULL INVOKER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
++DropGeometryColumn def mysql DropGeometryColumn PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL begin
++ set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' DROP ', geometry_column); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end NULL NULL SQL NO CONTAINS SQL NULL INVOKER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
+connect testuser2, localhost, testuser2, , db_datadict;
SELECT * FROM information_schema.routines;
-SPECIFIC_NAME ROUTINE_CATALOG ROUTINE_SCHEMA ROUTINE_NAME ROUTINE_TYPE DTD_IDENTIFIER ROUTINE_BODY ROUTINE_DEFINITION EXTERNAL_NAME EXTERNAL_LANGUAGE PARAMETER_STYLE IS_DETERMINISTIC SQL_DATA_ACCESS SQL_PATH SECURITY_TYPE CREATED LAST_ALTERED SQL_MODE ROUTINE_COMMENT DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION
-sp_6_408002_1 NULL db_datadict sp_6_408002_1 PROCEDURE NULL SQL BEGIN
+SPECIFIC_NAME ROUTINE_CATALOG ROUTINE_SCHEMA ROUTINE_NAME ROUTINE_TYPE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME DTD_IDENTIFIER ROUTINE_BODY ROUTINE_DEFINITION EXTERNAL_NAME EXTERNAL_LANGUAGE PARAMETER_STYLE IS_DETERMINISTIC SQL_DATA_ACCESS SQL_PATH SECURITY_TYPE CREATED LAST_ALTERED SQL_MODE ROUTINE_COMMENT DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION
+sp_6_408002_1 def db_datadict sp_6_408002_1 PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN
SELECT * FROM db_datadict.res_6_408002_1;
END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
-sp_6_408002_2 NULL db_datadict_2 sp_6_408002_2 PROCEDURE NULL SQL BEGIN
+sp_6_408002_2 def db_datadict_2 sp_6_408002_2 PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN
SELECT * FROM db_datadict_2.res_6_408002_2;
END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
-# Establish connection testuser3 (user=testuser3)
+add_suppression def mtr add_suppression PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN INSERT INTO test_suppressions (pattern) VALUES (pattern); FLUSH NO_WRITE_TO_BINLOG TABLE test_suppressions; END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost utf8 utf8_general_ci latin1_swedish_ci
+check_testcase def mtr check_testcase PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE variable_name NOT IN ('timestamp', 'innodb_file_format_max') AND variable_name not like "Last_IO_Err*" AND variable_name != 'INNODB_IBUF_MAX_SIZE' AND variable_name != 'INNODB_USE_NATIVE_AIO' AND variable_name != 'INNODB_BUFFER_POOL_LOAD_AT_STARTUP' AND variable_name not like 'GTID%POS' AND variable_name != 'GTID_BINLOG_STATE' ORDER BY variable_name; SELECT * FROM INFORMATION_SCHEMA.SCHEMATA; SELECT * FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME NOT IN ('mtr_wsrep_notify', 'wsrep_schema'); SELECT table_name AS tables_in_test FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='test'; SELECT CONCAT(table_schema, '.', table_name) AS tables_in_mysql FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='mysql' ORDER BY tables_in_mysql; SELECT CONCAT(
table_schema, '.', table_name) AS columns_in_mysql, column_name, ordinal_position, column_default, is_nullable, data_type, character_maximum_length, character_octet_length, numeric_precision, numeric_scale, character_set_name, collation_name, column_type, column_key, extra, column_comment FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema='mysql' ORDER BY columns_in_mysql; SELECT * FROM INFORMATION_SCHEMA.EVENTS; SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME NOT IN ('gs_insert', 'ts_insert'); SELECT * FROM INFORMATION_SCHEMA.ROUTINES; SHOW STATUS LIKE 'slave_open_temp_tables'; checksum table mysql.columns_priv, mysql.db, mysql.func, mysql.help_category, mysql.help_keyword, mysql.help_relation, mysql.host, mysql.plugin, mysql.proc, mysql.procs_priv, mysql.roles_mapping, mysql.tables_priv, mysql.time_zone, mysql.time_zone_leap_second,
mysql.time_zone_name, mysql.time_zone_transition, mysql.time_zone_transition_type, mysql.user; SELECT * FROM INFORMATION_SCHEMA.PLUGINS; select * from information_schema.session_variables where variable_name = 'debug_sync'; END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost utf8 utf8_general_ci latin1_swedish_ci
+check_warnings def mtr check_warnings PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN DECLARE `pos` bigint unsigned; SET SQL_LOG_BIN=0; UPDATE error_log el, global_suppressions gs SET suspicious=0 WHERE el.suspicious=1 AND el.line REGEXP gs.pattern; UPDATE error_log el, test_suppressions ts SET suspicious=0 WHERE el.suspicious=1 AND el.line REGEXP ts.pattern; SELECT COUNT(*) INTO @num_warnings FROM error_log WHERE suspicious=1; IF @num_warnings > 0 THEN SELECT line FROM error_log WHERE suspicious=1; SELECT 2 INTO result; ELSE SELECT 0 INTO RESULT; END IF; TRUNCATE test_suppressions; DROP TABLE error_log; END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost utf8 utf8_general_ci latin1_swedish_ci
++AddGeometryColumn def mysql AddGeometryColumn PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL begin
++ set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' ADD ', geometry_column,' GEOMETRY REF_SYSTEM_ID=', t_srid); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end NULL NULL SQL NO CONTAINS SQL NULL INVOKER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
++DropGeometryColumn def mysql DropGeometryColumn PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL begin
++ set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' DROP ', geometry_column); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end NULL NULL SQL NO CONTAINS SQL NULL INVOKER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
+connect testuser3, localhost, testuser3, , test;
SELECT * FROM information_schema.routines;
-SPECIFIC_NAME ROUTINE_CATALOG ROUTINE_SCHEMA ROUTINE_NAME ROUTINE_TYPE DTD_IDENTIFIER ROUTINE_BODY ROUTINE_DEFINITION EXTERNAL_NAME EXTERNAL_LANGUAGE PARAMETER_STYLE IS_DETERMINISTIC SQL_DATA_ACCESS SQL_PATH SECURITY_TYPE CREATED LAST_ALTERED SQL_MODE ROUTINE_COMMENT DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION
-sp_6_408002_1 NULL db_datadict sp_6_408002_1 PROCEDURE NULL SQL BEGIN
+SPECIFIC_NAME ROUTINE_CATALOG ROUTINE_SCHEMA ROUTINE_NAME ROUTINE_TYPE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME DTD_IDENTIFIER ROUTINE_BODY ROUTINE_DEFINITION EXTERNAL_NAME EXTERNAL_LANGUAGE PARAMETER_STYLE IS_DETERMINISTIC SQL_DATA_ACCESS SQL_PATH SECURITY_TYPE CREATED LAST_ALTERED SQL_MODE ROUTINE_COMMENT DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION
+sp_6_408002_1 def db_datadict sp_6_408002_1 PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN
SELECT * FROM db_datadict.res_6_408002_1;
END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
-sp_6_408002_2 NULL db_datadict_2 sp_6_408002_2 PROCEDURE NULL SQL BEGIN
+sp_6_408002_2 def db_datadict_2 sp_6_408002_2 PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN
SELECT * FROM db_datadict_2.res_6_408002_2;
END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
-# Switch to connection default and close connections testuser1,testuser2,testuser3
+add_suppression def mtr add_suppression PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN INSERT INTO test_suppressions (pattern) VALUES (pattern); FLUSH NO_WRITE_TO_BINLOG TABLE test_suppressions; END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost utf8 utf8_general_ci latin1_swedish_ci
+check_testcase def mtr check_testcase PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE variable_name NOT IN ('timestamp', 'innodb_file_format_max') AND variable_name not like "Last_IO_Err*" AND variable_name != 'INNODB_IBUF_MAX_SIZE' AND variable_name != 'INNODB_USE_NATIVE_AIO' AND variable_name != 'INNODB_BUFFER_POOL_LOAD_AT_STARTUP' AND variable_name not like 'GTID%POS' AND variable_name != 'GTID_BINLOG_STATE' ORDER BY variable_name; SELECT * FROM INFORMATION_SCHEMA.SCHEMATA; SELECT * FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME NOT IN ('mtr_wsrep_notify', 'wsrep_schema'); SELECT table_name AS tables_in_test FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='test'; SELECT CONCAT(table_schema, '.', table_name) AS tables_in_mysql FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='mysql' ORDER BY tables_in_mysql; SELECT CONCAT(
table_schema, '.', table_name) AS columns_in_mysql, column_name, ordinal_position, column_default, is_nullable, data_type, character_maximum_length, character_octet_length, numeric_precision, numeric_scale, character_set_name, collation_name, column_type, column_key, extra, column_comment FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema='mysql' ORDER BY columns_in_mysql; SELECT * FROM INFORMATION_SCHEMA.EVENTS; SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME NOT IN ('gs_insert', 'ts_insert'); SELECT * FROM INFORMATION_SCHEMA.ROUTINES; SHOW STATUS LIKE 'slave_open_temp_tables'; checksum table mysql.columns_priv, mysql.db, mysql.func, mysql.help_category, mysql.help_keyword, mysql.help_relation, mysql.host, mysql.plugin, mysql.proc, mysql.procs_priv, mysql.roles_mapping, mysql.tables_priv, mysql.time_zone, mysql.time_zone_leap_second,
mysql.time_zone_name, mysql.time_zone_transition, mysql.time_zone_transition_type, mysql.user; SELECT * FROM INFORMATION_SCHEMA.PLUGINS; select * from information_schema.session_variables where variable_name = 'debug_sync'; END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost utf8 utf8_general_ci latin1_swedish_ci
+check_warnings def mtr check_warnings PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL BEGIN DECLARE `pos` bigint unsigned; SET SQL_LOG_BIN=0; UPDATE error_log el, global_suppressions gs SET suspicious=0 WHERE el.suspicious=1 AND el.line REGEXP gs.pattern; UPDATE error_log el, test_suppressions ts SET suspicious=0 WHERE el.suspicious=1 AND el.line REGEXP ts.pattern; SELECT COUNT(*) INTO @num_warnings FROM error_log WHERE suspicious=1; IF @num_warnings > 0 THEN SELECT line FROM error_log WHERE suspicious=1; SELECT 2 INTO result; ELSE SELECT 0 INTO RESULT; END IF; TRUNCATE test_suppressions; DROP TABLE error_log; END NULL NULL SQL NO CONTAINS SQL NULL DEFINER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost utf8 utf8_general_ci latin1_swedish_ci
++AddGeometryColumn def mysql AddGeometryColumn PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL begin
++ set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' ADD ', geometry_column,' GEOMETRY REF_SYSTEM_ID=', t_srid); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end NULL NULL SQL NO CONTAINS SQL NULL INVOKER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
++DropGeometryColumn def mysql DropGeometryColumn PROCEDURE NULL NULL NULL NULL NULL NULL NULL NULL SQL begin
++ set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' DROP ', geometry_column); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end NULL NULL SQL NO CONTAINS SQL NULL INVOKER YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
+connection default;
+disconnect testuser1;
+disconnect testuser2;
+disconnect testuser3;
DROP USER 'testuser1'@'localhost';
DROP USER 'testuser2'@'localhost';
DROP USER 'testuser3'@'localhost';
diff --cc mysql-test/suite/galera/r/galera_events.result
index f01627aba70,80631442e08..e925e62cb91
--- a/mysql-test/suite/galera/r/galera_events.result
+++ b/mysql-test/suite/galera/r/galera_events.result
@@@ -1,6 -1,6 +1,8 @@@
+connection node_1;
CREATE EVENT event1 ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO SELECT 1;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
+connection node_2;
SELECT DEFINER= 'root@localhost', ORIGINATOR = 1, STATUS = 'SLAVESIDE_DISABLED', EVENT_TYPE = 'ONE TIME', ON_COMPLETION = 'NOT PRESERVE' FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME = 'event1';
DEFINER= 'root@localhost' ORIGINATOR = 1 STATUS = 'SLAVESIDE_DISABLED' EVENT_TYPE = 'ONE TIME' ON_COMPLETION = 'NOT PRESERVE'
1 1 1 1 1
diff --cc mysql-test/suite/innodb/r/innodb-index.result
index b64fd27fb35,64c5586173e..bdc16ad7692
--- a/mysql-test/suite/innodb/r/innodb-index.result
+++ b/mysql-test/suite/innodb/r/innodb-index.result
@@@ -1211,701 -1211,32 +1211,728 @@@ CHECK TABLE t1
Table Op Msg_type Msg_text
test.t1 check status OK
DROP TABLE t1;
-SET GLOBAL innodb_file_format=@save_format;
-SET GLOBAL innodb_large_prefix=@save_prefix;
#
+ # Bug#19811005 ALTER TABLE ADD INDEX DOES NOT UPDATE INDEX_LENGTH
+ # IN I_S TABLES
+ #
+ CREATE TABLE t1(a INT, b INT) ENGINE=INNODB, STATS_PERSISTENT=1;
+ SELECT cast(DATA_LENGTH/@@innodb_page_size as int) D,
+ cast(INDEX_LENGTH/@@innodb_page_size as int) I
+ FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test';
+ D I
+ 1 0
+ ALTER TABLE t1 ADD INDEX (a);
+ affected rows: 0
+ info: Records: 0 Duplicates: 0 Warnings: 0
+ SELECT cast(DATA_LENGTH/@@innodb_page_size as int) D,
+ cast(INDEX_LENGTH/@@innodb_page_size as int) I
+ FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test';
+ D I
+ 1 1
+ ALTER TABLE t1 ADD INDEX (b);
+ affected rows: 0
+ info: Records: 0 Duplicates: 0 Warnings: 0
+ SELECT cast(DATA_LENGTH/@@innodb_page_size as int) D,
+ cast(INDEX_LENGTH/@@innodb_page_size as int) I
+ FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test';
+ D I
+ 1 2
+ DROP TABLE t1;
++#
+# Bug #17657223 EXCESSIVE TEMPORARY FILE USAGE IN ALTER TABLE
+#
+SET GLOBAL innodb_monitor_enable = module_ddl;
+create table t1(f1 int not null, f2 blob)engine=innodb;
+insert into t1 values(1, repeat('a',20000));
+# Skip sort
+# Reusing the same pk
+alter table t1 force;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+drop table t1;
+create table t1(f1 int not null, f2 int not null,
+primary key(f1))engine=innodb;
+insert into t1 values(1,2), (3,4);
+# Add Secondary index.
+# Skip temp file usage due to small table size
+alter table t1 add key(f2);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+drop table t1;
+create table t480(a serial)engine=innodb;
+insert into t480
+values(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),
+(),(),(),(),(),(),(),();
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+create table t1(f1 int auto_increment not null,
+f2 char(200) not null, f3 char(200) not null,
+f4 char(200) not null,primary key(f1))engine=innodb;
+insert into t1 select NULL,'aaa','bbb','ccc' from t480;
+insert into t1 select NULL,'aaaa','bbbb','cccc' from t480;
+insert into t1 select NULL,'aaaaa','bbbbb','ccccc' from t480;
+insert into t1 select NULL,'aaaaaa','bbbbbb','cccccc' from t480;
+insert into t1 select NULL,'aaaaaaa','bbbbbbb','ccccccc' from t480;
+insert into t1 select NULL,'aaaaaaaa','bbbbbbbb','cccccccc' from t480;
+select count(*) from t1;
+count(*)
+2880
+# Skip sort
+# Change PK from (f1) to (f1,f2,f3,f4)
+alter table t1 drop primary key, add primary key(f1,f2,f3,f4);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Change PK from (f1,f2,f3,f4) to (f1,f2,added_columns)
+alter table t1 drop primary key,add column f5 int not null,
+add column f6 int not null,add primary key(f1,f2,f5,f6);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Change PK from (f1,f2,f5,f6) to (f1,f2,f5)
+alter table t1 drop column f6;
+ERROR 42000: Key column 'f6' doesn't exist in table
+alter table t1 drop column f6, drop primary key, add primary key(f1,f2,f5);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Reusing the same PK
+alter table t1 add column f6 int;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Reusing the same pk
+alter table t1 drop column f6;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Must sort
+# Change PK from (f1,f2,f5) to (f1,f5)
+alter table t1 drop column f2;
+ERROR 42000: Key column 'f2' doesn't exist in table
+alter table t1 drop column f2, drop primary key, add primary key(f1,f5);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+ddl_sort_file_alter_table 2
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Reusing the same pk
+alter table t1 add column f2n int after f1, drop primary key, add
+primary key (f1,f5,f2n);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Reusing the same pk
+alter table t1 change f5 f2n int not null,change f2n f5 int not null,
+add column f8 int not null;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Change PK from (f1,f4,f2n) to (f1,f4,added_column,f2n)
+alter table t1 add column f7 int, drop primary key,
+add primary key (f1,f5,f7,f2n);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+ddl_sort_file_alter_table 2
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Reusing the same pk
+alter table t1 force;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Reusing the same pk
+alter table t1 row_format=compact;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Reusing the same pk
+alter table t1 engine=innodb;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Optimize table
+optimize table t1;
+Table Op Msg_type Msg_text
+test.t1 optimize note Table does not support optimize, doing recreate + analyze instead
+test.t1 optimize status OK
+affected rows: 2
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Sort files used for adding secondary index
+alter table t1 drop primary key, add primary key(f1,f5,f7), add index
+i(f3);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# No sort files used for dropping secondary index
+alter table t1 drop primary key, add primary key(f1,f5),drop index i;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Change PK(f1,f5) to (f1,added_columns) and drop f5
+alter table t1 drop primary key, add primary key(f1,f12),
+drop column f5, add column f12 int not null;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Must sort
+# Change PK(f1,f12) to (f1,existing_columns)
+alter table t1 drop primary key, add primary key(f1,f3);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+ddl_sort_file_alter_table 2
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort
+# Change PK(f1,f3) to (f1,added_column,f3,added_column)
+alter table t1 drop primary key, add column f3n int,
+add column f4n int, add primary key(f1,f3n,f3,f4n);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Adding Secondary index alone.
+alter table t1 add key(f1);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Must sort
+# Change PK(f1,f3) to (existing_column,f1)
+alter table t1 drop primary key, add primary key(f4,f1);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+ddl_sort_file_alter_table 3
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort for PK.
+# Change PK(f4,f1) to (added_columns,f4,f1)
+# Secondary index rebuild happens
+alter table t1 drop primary key, add column f5n int,
+add column f6n int, add primary key(f5n,f6n,f4,f1);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+# Skip sort for PK.
+# Change PK(f5n,f6n,f4,f1) to
+# (added_columns,f5n,added_column,f6n,f4,f1)
+# Secondary index rebuild happens
+alter table t1 drop primary key, add column f7n int,
+add column f8n int, add primary key(f7n,f5n,f8n,f6n,f4,f1);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+name count_reset
+SET GLOBAL innodb_monitor_reset = module_ddl;
+SET GLOBAL innodb_monitor_disable = module_ddl;
+select count(*) from t1;
+count(*)
+2880
+drop table t1;
+SET GLOBAL innodb_monitor_reset = default;
+SET GLOBAL innodb_monitor_enable = default;
+SET GLOBAL innodb_monitor_disable = default;
+# Bug#19163915 INNODB: DUPLICATE RECORDS COULD EXIST
+# WHEN SKIPPING SORT FOR CLUSTER INDEX
+SELECT @@innodb_sort_buffer_size;
+@@innodb_sort_buffer_size
+1048576
+create table t1(f1 int auto_increment not null,
+f2 char(200) not null, f3 char(200) not null,
+f4 char(200) not null,primary key(f1,f2,f3,f4));
+insert into t1 select NULL,'aaa','bbb','ccc' from t480;
+insert into t1 values(106, 'aaa','bbb','cccc');
+select count(*) from t1;
+count(*)
+481
+# Skip sort
+# Change PK from (f1,f2,f3,f4) to (f1,f2,f3)
+alter table t1 drop primary key, add primary key(f1,f2,f3);
+ERROR 23000: ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '106-aaa-bbb' for key 'PRIMARY'
+select count(*) from t1;
+count(*)
+481
+drop table t1;
+create table t1(f1 int auto_increment not null,
+f2 char(200) not null, f3 char(200) not null,
+f4 char(200) not null,primary key(f1,f2,f3,f4));
+insert into t1 select NULL,'aaa','bbb','ccc' from t480;
+insert into t1 values(108,'aaa','bbb','cccc');
+select count(*) from t1;
+count(*)
+481
+alter table t1 drop primary key, add primary key(f1,f2,f3);
+ERROR 23000: ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '108-aaa-bbb' for key 'PRIMARY'
+select count(*) from t1;
+count(*)
+481
+drop table t1, t480;
+#
+# Bug #19896922 SORTING SKIPPED WHEN PREFIX LENGTH OF THE PK
+# FIELD IS CHANGED
+#
+create table t1(a int not null, b varchar(30) not null,
+primary key (b(10), a)) engine = innodb;
+insert into t1 values(0,'khdHps6UxW8Lwaoxa604oK6zkb'),(1,'khdHps6UxW8L');
+select * from t1;
+a b
+0 khdHps6UxW8Lwaoxa604oK6zkb
+1 khdHps6UxW8L
+alter table t1 drop primary key, add primary key (b(18),a);
+select * from t1;
+a b
+1 khdHps6UxW8L
+0 khdHps6UxW8Lwaoxa604oK6zkb
+drop table t1;
+create table t1(a int not null, b varchar(30) not null,
+primary key (b(10), a)) engine = innodb;
+insert into t1 values(0,'khdHps6UxW8Lwaoxa604oK6zkb'),(1,'khdHps6UtW8L');
+select * from t1;
+a b
+1 khdHps6UtW8L
+0 khdHps6UxW8Lwaoxa604oK6zkb
+alter table t1 drop primary key, add primary key (b(8),a);
+select * from t1;
+a b
+0 khdHps6UxW8Lwaoxa604oK6zkb
+1 khdHps6UtW8L
+drop table t1;
+#
+# Bug #21103101 SORTING SKIPPED WHEN DROPPING THE SINGLE
+# COLUMN PRIMARY KEY
+#
+create table t1(f1 int not null, f2 int not null,
+primary key (f1), unique key(f1, f2))engine=innodb;
+insert into t1 values(1,3), (2,2);
+alter table t1 drop column f1;
+ERROR 42000: Key column 'f1' doesn't exist in table
+alter table t1 drop column f1, drop primary key;
+ERROR 42000: Key column 'f1' doesn't exist in table
+alter table t1 drop column f1, drop key f1;
+drop table t1;
+create table t1(f1 int not null, f2 int not null,
+primary key (f1), unique key(f1, f2))engine=innodb;
+insert into t1 values(1,3), (2,2);
+alter table t1 drop primary key, lock=none;
+alter table t1 drop index f1, lock=none;
+ERROR 0A000: LOCK=NONE is not supported. Reason: Dropping a primary key is not allowed without also adding a new primary key. Try LOCK=SHARED
+drop table t1;
+#
+# BUG#21612714 ALTER TABLE SORTING SKIPPED WHEN CHANGE PK AND DROP
+# LAST COLUMN OF OLD PK
+#
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3), drop o2, lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop o1, drop o2, add primary key(o3), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o3), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 add column n1 int not null, drop primary key, add primary key(n1,o3), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(2,2,1);
+alter table t1 add column n1 int not null, drop primary key, add primary key(o3,n1), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2, o1), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2,o3), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int not null, primary key(o2,o1)) engine = innodb;
+insert into t1 values(1,1,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2,o3), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3,o2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o3,o1,o2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop o1, lock=none;
+ERROR 42000: Key column 'o1' doesn't exist in table
+alter table t1 drop o1, drop primary key, add primary key(o2,o3), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop o2, lock=none;
+ERROR 42000: Key column 'o2' doesn't exist in table
+alter table t1 drop o2, drop primary key, add primary key(o1,o3), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop o1, drop o2, lock=none;
+ERROR 42000: Key column 'o2' doesn't exist in table
+alter table t1 drop o1, drop o2,drop primary key,add primary key(o3),lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1(3), o2), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1, o2), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1(3), o3), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1, o3), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(3), o2)) engine = innodb;
+insert into t1 values('abc', 2, 1), ('abd', 1, 2);
+alter table t1 drop primary key, add primary key(o1(2), o2), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1, o2)) engine = innodb;
+insert into t1 values('abc', 2, 1), ('abd', 1, 2);
+alter table t1 drop primary key, add primary key(o1(2), o2), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(3), o2)) engine = innodb;
+insert into t1 values('abc', 2, 2), ('abd', 1, 1);
+alter table t1 drop primary key, add primary key(o1(2), o3), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1, o2)) engine = innodb;
+insert into t1 values('abc', 2, 2), ('abd', 1, 1);
+alter table t1 drop primary key, add primary key(o1(2), o3), lock=none;
+drop table t1;
+create table t1(o1 int, o2 varchar(10), o3 int, primary key(o1,o2(2),o3)) engine = innodb;
+insert into t1 values(1, 'abd', 1), (1, 'abc', 2);
+alter table t1 drop primary key, add primary key(o1,o2(3)), lock=none;
+drop table t1;
+create table t1(o1 int, o2 varchar(10), o3 int, primary key(o1,o2(2),o3)) engine = innodb;
+insert into t1 values(1, 'abd', 1), (1, 'abc', 2);
+alter table t1 drop primary key, add primary key(o1,o2), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1(3),o2(3))) engine = innodb;
+insert into t1 values('abc', 'acd'), ('abd', 'abd');
+alter table t1 drop primary key, add primary key(o1(2),o2(3)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1,o2)) engine = innodb;
+insert into t1 values('abc', 'acd'), ('abd', 'abd');
+alter table t1 drop primary key, add primary key(o1(2),o2), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1(3),o2(3))) engine = innodb;
+insert into t1 values('abd', 'acd'), ('acd', 'abd');
+alter table t1 drop primary key, add primary key(o2(3),o1(3)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1,o2)) engine = innodb;
+insert into t1 values('abd', 'acd'), ('acd', 'abd');
+alter table t1 drop primary key, add primary key(o2,o1), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), primary key(o1(2))) engine = innodb;
+insert into t1 values('abd'), ('acd');
+alter table t1 drop primary key, add primary key(o1(3)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), primary key(o1(2))) engine = innodb;
+insert into t1 values('abd'), ('acd');
+alter table t1 drop primary key, add primary key(o1), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), primary key(o1(2))) engine = innodb;
+insert into t1 values('abd'), ('acd');
+alter table t1 add n1 int not null, drop primary key, add primary key(o1(3), n1), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), primary key(o1(2))) engine = innodb;
+insert into t1 values('abd'), ('acd');
+alter table t1 add n1 int not null, drop primary key, add primary key(o1, n1), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int not null, primary key(o1(2))) engine = innodb;
+insert into t1 values('abd', 1), ('acd', 2);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1(3), o2), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int not null, primary key(o1(2))) engine = innodb;
+insert into t1 values('abd', 1), ('acd', 2);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1, o2), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), primary key(o1(3))) engine = innodb;
+insert into t1 values('abd'), ('acd');
+alter table t1 drop primary key, add primary key(o1(2)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), primary key(o1)) engine = innodb;
+insert into t1 values('abd'), ('acd');
+alter table t1 drop primary key, add primary key(o1(2)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, primary key(o1(3), o2)) engine = innodb;
+insert into t1 values('abd', 1), ('acd', 2);
+alter table t1 drop primary key, add primary key(o1(2)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, primary key(o1, o2)) engine = innodb;
+insert into t1 values('abd', 1), ('acd', 2);
+alter table t1 drop primary key, add primary key(o1(2)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, primary key(o1(3), o2)) engine = innodb;
+insert into t1 values('abd', 1), ('acd', 2);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1(2),n1), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, primary key(o1, o2)) engine = innodb;
+insert into t1 values('abd', 1), ('acd', 2);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1(2),n1), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, primary key(o1(3), o2)) engine = innodb;
+insert into t1 values('abd', 1), ('acd', 2);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1(3),n1), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, primary key(o1, o2)) engine = innodb;
+insert into t1 values('abd', 1), ('acd', 2);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1,n1), lock=none;
+drop table t1;
+create table t1(o1 int, o2 varchar(10), primary key(o1,o2(3))) engine = innodb;
+insert into t1 values(1,'abd'), (2,'acd');
+alter table t1 drop primary key, add primary key(o1,o2(2)), lock=none;
+drop table t1;
+create table t1(o1 int, o2 varchar(10), primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,'abd'), (2,'acd');
+alter table t1 drop primary key, add primary key(o1,o2(2)), lock=none;
+drop table t1;
+create table t1(o1 int, o2 varchar(10), primary key(o1,o2(2))) engine = innodb;
+insert into t1 values(1, 'abd'), (2, 'acd');
+alter table t1 drop primary key, add primary key(o1,o2(3)), lock=none;
+drop table t1;
+create table t1(o1 int, o2 varchar(10), primary key(o1,o2(2))) engine = innodb;
+insert into t1 values(1, 'abd'), (2, 'acd');
+alter table t1 drop primary key, add primary key(o1,o2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 varchar(10), o3 int, primary key(o1,o2(3),o3)) engine = innodb;
+insert into t1 values(1, 'abd', 1), (2, 'acd', 2);
+alter table t1 drop primary key, add primary key(o1,o2(2)), lock=none;
+drop table t1;
+create table t1(o1 int, o2 varchar(10), o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1, 'abd', 1), (2, 'acd', 2);
+alter table t1 drop primary key, add primary key(o1,o2(2)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1(3),o2(3))) engine = innodb;
+insert into t1 values('abd', 'acd'), ('acd', 'abd');
+alter table t1 drop primary key, add primary key(o1(3),o2(2)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1,o2)) engine = innodb;
+insert into t1 values('abd', 'acd'), ('acd', 'abd');
+alter table t1 drop primary key, add primary key(o1,o2(2)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1(3),o2(2))) engine = innodb;
+insert into t1 values('abd', 'acd'), ('acd', 'abd');
+alter table t1 drop primary key, add primary key(o1(3),o2(3)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1,o2(2))) engine = innodb;
+insert into t1 values('abd', 'acd'), ('acd', 'abd');
+alter table t1 drop primary key, add primary key(o1,o2), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 varchar(10), primary key(o1(3),o2,o3(2))) engine = innodb;
+insert into t1 values('abd', 1, 'acd'), ('acd', 2, 'abd');
+alter table t1 drop primary key, add primary key(o1(3),o2,o3(3)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 varchar(10), primary key(o1,o2,o3(2))) engine = innodb;
+insert into t1 values('abd', 1, 'acd'), ('acd', 2, 'abd');
+alter table t1 drop primary key, add primary key(o1,o2,o3), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 varchar(10), primary key(o1(3),o2,o3(3))) engine = innodb;
+insert into t1 values('abd', 1, 'acd'), ('acd', 2, 'abd');
+alter table t1 drop primary key, add primary key(o1(3),o2,o3(2)), lock=none;
+drop table t1;
+create table t1(o1 varchar(10), o2 int, o3 varchar(10), primary key(o1,o2,o3(3))) engine = innodb;
+insert into t1 values('abd', 1, 'acd'), ('acd', 2, 'abd');
+alter table t1 drop primary key, add primary key(o1,o2,o3(2)), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int not null, primary key(o1)) engine = innodb;
+insert into t1 values(1,1),(2,2);
+alter table t1 drop primary key, add primary key(o1,o2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int not null, primary key(o1)) engine = innodb;
+insert into t1 values(1,1),(2,2);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1,n1), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int not null, primary key(o1)) engine = innodb;
+insert into t1 values(1,1),(2,2);
+alter table t1 add n1 int not null, drop primary key, add primary key(n1,o1), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int not null, primary key(o1)) engine = innodb;
+insert into t1 values(1,1),(2,2);
+alter table t1 add n1 int not null, add n2 int not null, drop primary key, add primary key(n1,o1,n2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int not null, primary key(o1)) engine = innodb;
+insert into t1 values(1,1),(2,2);
+alter table t1 add n1 int not null, add n2 int not null, drop primary key, add primary key(n1,n2,o1), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int not null, primary key(o1)) engine = innodb;
+insert into t1 values(1,1),(2,2);
+alter table t1 add n1 int not null, add n2 int not null, drop primary key, add primary key(o1,n1,n2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int not null, primary key(o1)) engine = innodb;
+insert into t1 values(1,1),(2,2);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1,o2,n1), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int not null, primary key(o1)) engine = innodb;
+insert into t1 values(1,1),(2,2);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1,n1,o2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int not null, primary key(o1)) engine = innodb;
+insert into t1 values(1,1),(2,2);
+alter table t1 add n1 int not null, drop primary key, add primary key(n1,o1,o2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int not null, o3 int not null, primary key(o1)) engine = innodb;
+insert into t1 values(1,1,2),(2,2,1);
+alter table t1 drop primary key, add primary key(o1,o2,o3), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int not null, o3 int not null, primary key(o1)) engine = innodb;
+insert into t1 values(1,1,2),(2,2,1);
+alter table t1 drop primary key, add primary key(o1,o3,o2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,1,2),(2,2,1);
+alter table t1 drop primary key, add primary key(o1,o2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int, o4 int not null, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,1,2,2),(2,2,1,1);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1,o2,o3,o4), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,1,2),(2,2,1);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1,o2,n1), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,1,2),(2,2,1);
+alter table t1 add n1 int not null, drop primary key, add primary key(o1,n1,o2), lock=none;
+drop table t1;
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,1,2),(2,2,1);
+alter table t1 drop primary key, add primary key(o1), lock=none;
+drop table t1;
+#
+# MDEV-15325 Incomplete validation of missing tablespace during recovery
+#
+CREATE TABLE t1(f1 INT PRIMARY KEY)ENGINE=InnoDB;
+CREATE TABLE t2(f1 INT PRIMARY KEY)ENGINE=InnoDB;
+# Kill the server
+# Wrong space_id in a dirty file and a missing file
+SELECT * FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS
+# Restore t1 and t2
+SELECT * FROM t1;
+f1
+SELECT * FROM t2;
+f1
+DROP TABLE t1, t2;
+#
+# MDEV-18186 assertion failure on missing InnoDB index
+#
+CREATE TABLE t (a INT, INDEX i1 (a)) ENGINE=INNODB;
+DROP TABLE t;
+CREATE TABLE t (a INT) ENGINE=INNODB;
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ KEY `i1` (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+Warnings:
+Warning 1082 InnoDB: Table test/t contains 0 indexes inside InnoDB, which is different from the number of indexes 1 defined in the MariaDB
+Warning 1082 InnoDB: Table test/t contains 0 indexes inside InnoDB, which is different from the number of indexes 1 defined in the MariaDB
+DROP TABLE t;
diff --cc mysql-test/suite/innodb/r/innodb-truncate.result
index a606868ae52,37ed19fa3fc..8610a892cc6
--- a/mysql-test/suite/innodb/r/innodb-truncate.result
+++ b/mysql-test/suite/innodb/r/innodb-truncate.result
@@@ -78,3 -66,16 +78,16 @@@
1
2
DROP TABLE t1;
-call mtr.add_suppression('InnoDB: Error: in RENAME TABLE table `test`.`t3`');
++call mtr.add_suppression('InnoDB: in RENAME TABLE table `test`.`t3`');
+ SET FOREIGN_KEY_CHECKS= OFF;
+ CREATE TABLE t1 (f2 INT, f4 INT, KEY(f2), FOREIGN KEY (f4) REFERENCES t3 (f4)) ENGINE=InnoDB;
+ SET FOREIGN_KEY_CHECKS= ON;
+ CREATE TABLE t2 (f2 INT, FOREIGN KEY(f2) REFERENCES t1 (f2)) ENGINE=InnoDB;
+ CREATE TABLE t3 (a INT) ENGINE=InnoDB;
+ ERROR HY000: Can't create table `test`.`t3` (errno: 150 "Foreign key constraint is incorrectly formed")
+ ALTER TABLE t1 RENAME TO t3;
+ ERROR HY000: Error on rename of './test/t1' to './test/t3' (errno: 150 "Foreign key constraint is incorrectly formed")
+ ALTER TABLE t1 FORCE;
+ TRUNCATE TABLE t1;
+ ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `test`.`t3` (`f2`))
+ DROP TABLE t2, t1;
diff --cc mysql-test/suite/innodb/r/xa_debug.result
index 902166f51c8,f1fd3f14220..7c2bd9f92c2
--- a/mysql-test/suite/innodb/r/xa_debug.result
+++ b/mysql-test/suite/innodb/r/xa_debug.result
@@@ -251,7 -201,7 +251,8 @@@ xa start 'test1'
insert into t1 values(1);
xa end 'test1';
xa prepare 'test1';
+connection default;
+ FLUSH TABLES;
xa recover;
formatID gtrid_length bqual_length data
1 5 0 test1
diff --cc mysql-test/suite/innodb/t/innodb-index.test
index 8bd3919af91,86ac1a8123e..474b0e08935
--- a/mysql-test/suite/innodb/t/innodb-index.test
+++ b/mysql-test/suite/innodb/t/innodb-index.test
@@@ -568,615 -591,25 +568,635 @@@ ALTER TABLE t1 ROW_FORMAT=REDUNDANT, al
SELECT COUNT(*) FROM t1;
CHECK TABLE t1;
DROP TABLE t1;
-SET GLOBAL innodb_file_format=@save_format;
-SET GLOBAL innodb_large_prefix=@save_prefix;
+ --echo #
+ --echo # Bug#19811005 ALTER TABLE ADD INDEX DOES NOT UPDATE INDEX_LENGTH
+ --echo # IN I_S TABLES
+ --echo #
+ let $i_s_query=SELECT cast(DATA_LENGTH/@@innodb_page_size as int) D,
+ cast(INDEX_LENGTH/@@innodb_page_size as int) I
+ FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test';
+
+ CREATE TABLE t1(a INT, b INT) ENGINE=INNODB, STATS_PERSISTENT=1;
+ eval $i_s_query;
+ --enable_info
+ ALTER TABLE t1 ADD INDEX (a);
+ --disable_info
+ eval $i_s_query;
+ --enable_info
+ ALTER TABLE t1 ADD INDEX (b);
+ --disable_info
+ eval $i_s_query;
+ DROP TABLE t1;
++
+--echo #
+--echo # Bug #17657223 EXCESSIVE TEMPORARY FILE USAGE IN ALTER TABLE
+--echo #
+
+SET GLOBAL innodb_monitor_enable = module_ddl;
+let $innodb_metrics_select=
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+
+# Table with Blob data.
+create table t1(f1 int not null, f2 blob)engine=innodb;
+insert into t1 values(1, repeat('a',20000));
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 force;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+drop table t1;
+
+# Table with small data.
+create table t1(f1 int not null, f2 int not null,
+primary key(f1))engine=innodb;
+insert into t1 values(1,2), (3,4);
+--echo # Add Secondary index.
+--echo # Skip temp file usage due to small table size
+--enable_info
+alter table t1 add key(f2);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+drop table t1;
+
+# Table with large data which is greater than sort buffer
+create table t480(a serial)engine=innodb;
+insert into t480
+values(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),
+(),(),(),(),(),(),(),();
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+create table t1(f1 int auto_increment not null,
+ f2 char(200) not null, f3 char(200) not null,
+ f4 char(200) not null,primary key(f1))engine=innodb;
+insert into t1 select NULL,'aaa','bbb','ccc' from t480;
+insert into t1 select NULL,'aaaa','bbbb','cccc' from t480;
+insert into t1 select NULL,'aaaaa','bbbbb','ccccc' from t480;
+insert into t1 select NULL,'aaaaaa','bbbbbb','cccccc' from t480;
+insert into t1 select NULL,'aaaaaaa','bbbbbbb','ccccccc' from t480;
+insert into t1 select NULL,'aaaaaaaa','bbbbbbbb','cccccccc' from t480;
+select count(*) from t1;
+
+--echo # Skip sort
+--echo # Change PK from (f1) to (f1,f2,f3,f4)
+--enable_info
+alter table t1 drop primary key, add primary key(f1,f2,f3,f4);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+
+# Temp file not used during clustered index rebuild
+# for the following alter table commands.
+
+--echo # Skip sort
+--echo # Change PK from (f1,f2,f3,f4) to (f1,f2,added_columns)
+--enable_info
+alter table t1 drop primary key,add column f5 int not null,
+add column f6 int not null,add primary key(f1,f2,f5,f6);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Change PK from (f1,f2,f5,f6) to (f1,f2,f5)
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 drop column f6;
+--enable_info
+alter table t1 drop column f6, drop primary key, add primary key(f1,f2,f5);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same PK
+--enable_info
+alter table t1 add column f6 int;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 drop column f6;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Must sort
+--echo # Change PK from (f1,f2,f5) to (f1,f5)
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 drop column f2;
+--enable_info
+alter table t1 drop column f2, drop primary key, add primary key(f1,f5);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 add column f2n int after f1, drop primary key, add
+primary key (f1,f5,f2n);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 change f5 f2n int not null,change f2n f5 int not null,
+add column f8 int not null;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Change PK from (f1,f4,f2n) to (f1,f4,added_column,f2n)
+--enable_info
+alter table t1 add column f7 int, drop primary key,
+add primary key (f1,f5,f7,f2n);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 force;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 row_format=compact;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 engine=innodb;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Optimize table
+--enable_info
+optimize table t1;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Sort files used for adding secondary index
+--enable_info
+alter table t1 drop primary key, add primary key(f1,f5,f7), add index
+i(f3);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # No sort files used for dropping secondary index
+--enable_info
+alter table t1 drop primary key, add primary key(f1,f5),drop index i;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Change PK(f1,f5) to (f1,added_columns) and drop f5
+--enable_info
+alter table t1 drop primary key, add primary key(f1,f12),
+drop column f5, add column f12 int not null;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Must sort
+--echo # Change PK(f1,f12) to (f1,existing_columns)
+--enable_info
+alter table t1 drop primary key, add primary key(f1,f3);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Change PK(f1,f3) to (f1,added_column,f3,added_column)
+--enable_info
+alter table t1 drop primary key, add column f3n int,
+add column f4n int, add primary key(f1,f3n,f3,f4n);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Adding Secondary index alone.
+--enable_info
+alter table t1 add key(f1);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Must sort
+--echo # Change PK(f1,f3) to (existing_column,f1)
+--enable_info
+alter table t1 drop primary key, add primary key(f4,f1);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort for PK.
+--echo # Change PK(f4,f1) to (added_columns,f4,f1)
+--echo # Secondary index rebuild happens
+--enable_info
+alter table t1 drop primary key, add column f5n int,
+add column f6n int, add primary key(f5n,f6n,f4,f1);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort for PK.
+--echo # Change PK(f5n,f6n,f4,f1) to
+--echo # (added_columns,f5n,added_column,f6n,f4,f1)
+--echo # Secondary index rebuild happens
+--enable_info
+alter table t1 drop primary key, add column f7n int,
+add column f8n int, add primary key(f7n,f5n,f8n,f6n,f4,f1);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+SET GLOBAL innodb_monitor_disable = module_ddl;
+select count(*) from t1;
+drop table t1;
+--disable_warnings
+SET GLOBAL innodb_monitor_reset = default;
+SET GLOBAL innodb_monitor_enable = default;
+SET GLOBAL innodb_monitor_disable = default;
+--enable_warnings
+
+--echo # Bug#19163915 INNODB: DUPLICATE RECORDS COULD EXIST
+--echo # WHEN SKIPPING SORT FOR CLUSTER INDEX
+
+# last mtuple in previous buffer and first mtuple in next buffer
+# are equal.
+SELECT @@innodb_sort_buffer_size;
+create table t1(f1 int auto_increment not null,
+ f2 char(200) not null, f3 char(200) not null,
+ f4 char(200) not null,primary key(f1,f2,f3,f4));
+insert into t1 select NULL,'aaa','bbb','ccc' from t480;
+insert into t1 values(106, 'aaa','bbb','cccc');
+select count(*) from t1;
+--echo # Skip sort
+--echo # Change PK from (f1,f2,f3,f4) to (f1,f2,f3)
+--error ER_DUP_ENTRY
+alter table t1 drop primary key, add primary key(f1,f2,f3);
+select count(*) from t1;
+drop table t1;
+
+# Duplicates exist with in the buffer
+create table t1(f1 int auto_increment not null,
+ f2 char(200) not null, f3 char(200) not null,
+ f4 char(200) not null,primary key(f1,f2,f3,f4));
+insert into t1 select NULL,'aaa','bbb','ccc' from t480;
+insert into t1 values(108,'aaa','bbb','cccc');
+select count(*) from t1;
+--error ER_DUP_ENTRY
+alter table t1 drop primary key, add primary key(f1,f2,f3);
+select count(*) from t1;
+drop table t1, t480;
+
+--echo #
+--echo # Bug #19896922 SORTING SKIPPED WHEN PREFIX LENGTH OF THE PK
+--echo # FIELD IS CHANGED
+--echo #
+
+# Prefix length changes for the varchar column.
+create table t1(a int not null, b varchar(30) not null,
+ primary key (b(10), a)) engine = innodb;
+insert into t1 values(0,'khdHps6UxW8Lwaoxa604oK6zkb'),(1,'khdHps6UxW8L');
+select * from t1;
+alter table t1 drop primary key, add primary key (b(18),a);
+select * from t1;
+drop table t1;
+
+create table t1(a int not null, b varchar(30) not null,
+ primary key (b(10), a)) engine = innodb;
+insert into t1 values(0,'khdHps6UxW8Lwaoxa604oK6zkb'),(1,'khdHps6UtW8L');
+select * from t1;
+alter table t1 drop primary key, add primary key (b(8),a);
+select * from t1;
+drop table t1;
+
+
+--echo #
+--echo # Bug #21103101 SORTING SKIPPED WHEN DROPPING THE SINGLE
+--echo # COLUMN PRIMARY KEY
+--echo #
+
+# Drop primary key column.
+create table t1(f1 int not null, f2 int not null,
+ primary key (f1), unique key(f1, f2))engine=innodb;
+insert into t1 values(1,3), (2,2);
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 drop column f1;
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 drop column f1, drop primary key;
+# DROP PRIMARY KEY is implied for a single-column PRIMARY KEY
+alter table t1 drop column f1, drop key f1;
+drop table t1;
+
+# Drop Primary key when lock is none.
+create table t1(f1 int not null, f2 int not null,
+ primary key (f1), unique key(f1, f2))engine=innodb;
+insert into t1 values(1,3), (2,2);
+alter table t1 drop primary key, lock=none;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t1 drop index f1, lock=none;
+drop table t1;
+
+--echo #
+--echo # BUG#21612714 ALTER TABLE SORTING SKIPPED WHEN CHANGE PK AND DROP
+--echo # LAST COLUMN OF OLD PK
+--echo #
+
+# no skip sort cases
+# pk(o1,o2) to pk(o1,o3), drop o2
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3), drop o2, lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o3), drop o1, o2
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop o1, drop o2, add primary key(o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o1,o3)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o3)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(n1,o3)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 add column n1 int not null, drop primary key, add primary key(n1,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o3,n1)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(2,2,1);
+alter table t1 add column n1 int not null, drop primary key, add primary key(o3,n1), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o2,o1)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2, o1), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o2)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o2,o3)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2,o3), lock=none;
+drop table t1;
+
+# pk(o2,o1) to pk(o2,o3)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o2,o1)) engine = innodb;
+insert into t1 values(1,1,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o1,o3,o2)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3,o2), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o3,o1,o2)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o3,o1,o2), lock=none;
+drop table t1;
+
+# pk(o1,o2,o3) to pk(o1,o3)
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2,o3) to pk(o2,o3) by drop o1
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 drop o1, lock=none;
+alter table t1 drop o1, drop primary key, add primary key(o2,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2,o3) to pk(o1,o3) by drop o2
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 drop o2, lock=none;
+alter table t1 drop o2, drop primary key, add primary key(o1,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2,o3) to pk(o3) by drop o1,o2
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 drop o1, drop o2, lock=none;
+alter table t1 drop o1, drop o2,drop primary key,add primary key(o3),lock=none;
+drop table t1;
+
+# no skip sort for prefix change
+# pk(o1(2),o2) to pk(o1(3),o2)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1(3), o2), lock=none;
+drop table t1;
+
+# pk(o1(2),o2) to pk(o1,o2)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1, o2), lock=none;
+drop table t1;
+
+# pk(o1(2),o2) to pk(o1(3),o3)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1(3), o3), lock=none;
+drop table t1;
+
+# pk(o1(2),o2) to pk(o1,o3)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1, o3), lock=none;
+drop table t1;
+
+# pk(o1(3),o2) to pk(o1(2),o2)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(3), o2)) engine = innodb;
+insert into t1 values('abc', 2, 1), ('abd', 1, 2);
+alter table t1 drop primary key, add primary key(o1(2), o2), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o1(2),o2)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1, o2)) engine = innodb;
+insert into t1 values('abc', 2, 1), ('abd', 1, 2);
+alter table t1 drop primary key, add primary key(o1(2), o2), lock=none;
+drop table t1;
+
+# pk(o1(3),o2) to pk(o1(2),o3)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(3), o2)) engine = innodb;
+insert into t1 values('abc', 2, 2), ('abd', 1, 1);
+alter table t1 drop primary key, add primary key(o1(2), o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o1(2),o3)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1, o2)) engine = innodb;
+insert into t1 values('abc', 2, 2), ('abd', 1, 1);
+alter table t1 drop primary key, add primary key(o1(2), o3), lock=none;
+drop table t1;
+
+# pk(o1,o2(2),o3) to pk(o1,o2(3))
+create table t1(o1 int, o2 varchar(10), o3 int, primary key(o1,o2(2),o3)) engine = innodb;
+insert into t1 values(1, 'abd', 1), (1, 'abc', 2);
+alter table t1 drop primary key, add primary key(o1,o2(3)), lock=none;
+drop table t1;
+
+# pk(o1,o2(2),o3) to pk(o1,o2)
+create table t1(o1 int, o2 varchar(10), o3 int, primary key(o1,o2(2),o3)) engine = innodb;
+insert into t1 values(1, 'abd', 1), (1, 'abc', 2);
+alter table t1 drop primary key, add primary key(o1,o2), lock=none;
+drop table t1;
+
+# pk(o1(3),o2(3)) to pk(o1(2),o2(3))
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1(3),o2(3))) engine = innodb;
+insert into t1 values('abc', 'acd'), ('abd', 'abd');
+alter table t1 drop primary key, add primary key(o1(2),o2(3)), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o1(2),o2)
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1,o2)) engine = innodb;
+insert into t1 values('abc', 'acd'), ('abd', 'abd');
+alter table t1 drop primary key, add primary key(o1(2),o2), lock=none;
+drop table t1;
+
+# pk(o1(3),o2(3)) to pk(o2(3),o1(3))
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1(3),o2(3))) engine = innodb;
+insert into t1 values('abd', 'acd'), ('acd', 'abd');
+alter table t1 drop primary key, add primary key(o2(3),o1(3)), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o2,o1)
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1,o2)) engine = innodb;
+insert into t1 values('abd', 'acd'), ('acd', 'abd');
+alter table t1 drop primary key, add primary key(o2,o1), lock=none;
+drop table t1;
+
+# no skip sort cases
+--source suite/innodb/include/alter_table_pk_no_sort.inc
+
+--echo #
+--echo # MDEV-15325 Incomplete validation of missing tablespace during recovery
+--echo #
+
+--source include/no_checkpoint_start.inc
+if ($have_debug) {
+SET GLOBAL DEBUG_DBUG='+d,fil_names_write_bogus';
+}
+CREATE TABLE t1(f1 INT PRIMARY KEY)ENGINE=InnoDB;
+
+CREATE TABLE t2(f1 INT PRIMARY KEY)ENGINE=InnoDB;
+
+--let CLEANUP_IF_CHECKPOINT=DROP TABLE t1, t2;
+--source include/no_checkpoint_end.inc
+
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+let $check_no_innodb=SELECT * FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+
+--echo # Wrong space_id in a dirty file and a missing file
+
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t0.ibd
+--move_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t1.ibd
+
+--source include/start_mysqld.inc
+--eval $check_no_innodb
+--source include/shutdown_mysqld.inc
+
+--echo # Restore t1 and t2
+
+--move_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+--move_file $MYSQLD_DATADIR/test/t0.ibd $MYSQLD_DATADIR/test/t1.ibd
+
+--source include/start_mysqld.inc
+if ($have_debug) {
+# Initiate shutdown in order to issue a redo log checkpoint and to discard
+# the redo log record that was emitted due to '+d,fil_names_write_bogus'.
+--source include/restart_mysqld.inc
+}
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-18186 assertion failure on missing InnoDB index
+--echo #
+
+--disable_query_log
+call mtr.add_suppression("Cannot find index i1 in InnoDB index dictionary");
+call mtr.add_suppression("InnoDB indexes are inconsistent with what defined");
+call mtr.add_suppression("Table test/t contains 0 indexes");
+call mtr.add_suppression("InnoDB could not find key no");
+--enable_query_log
+
+# Test an attempt to rename a nonexistent index inside InnoDB
+-- let $MYSQL_DATA_DIR = `SELECT @@datadir`
+CREATE TABLE t (a INT, INDEX i1 (a)) ENGINE=INNODB;
+-- copy_file $MYSQL_DATA_DIR/test/t.frm $MYSQL_DATA_DIR/test/t.fr_
+DROP TABLE t;
+CREATE TABLE t (a INT) ENGINE=INNODB;
+-- remove_file $MYSQL_DATA_DIR/test/t.frm
+-- move_file $MYSQL_DATA_DIR/test/t.fr_ $MYSQL_DATA_DIR/test/t.frm
+--enable_prepare_warnings
+SHOW CREATE TABLE t;
+--disable_prepare_warnings
+DROP TABLE t;
+
+--disable_query_log
+
+call mtr.add_suppression("InnoDB: Tablespace .* was not found at .*t[12].ibd.");
+call mtr.add_suppression("InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
+
+--enable_query_log
diff --cc mysql-test/suite/innodb/t/innodb-truncate.test
index 8f9b1f1f0e9,a5b500a4ea5..71c0fcfea8b
--- a/mysql-test/suite/innodb/t/innodb-truncate.test
+++ b/mysql-test/suite/innodb/t/innodb-truncate.test
@@@ -52,24 -53,30 +53,42 @@@ SET @@SESSION.foreign_key_checks = @old
--echo # Test that TRUNCATE resets auto-increment.
--echo #
-CREATE TABLE t1 (a INT PRIMARY KEY NOT NULL AUTO_INCREMENT);
-INSERT INTO t1 VALUES (NULL), (NULL);
+CREATE TABLE t1 (a INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
+ b INT, c INT, d INT, e INT, f INT, g INT, h INT, i INT, j INT, k INT,
+ l INT, m INT, n INT, o INT, p INT, q INT, r INT, s INT, t INT, u INT,
+ KEY(b),KEY(c),KEY(d),KEY(e),KEY(f),KEY(g),KEY(h),KEY(i),KEY(j),KEY(k),
+ KEY(l),KEY(m),KEY(n),KEY(o),KEY(p),KEY(q),KEY(r),KEY(s),KEY(t),KEY(u),
+ KEY(c,b),KEY(d,b),KEY(e,b),KEY(f,b),KEY(g,b),KEY(h,b),KEY(i,b),KEY(j,b),
+ KEY(k,b),KEY(l,b),KEY(m,b),KEY(n,b),KEY(o,b),KEY(p,b),KEY(q,b),KEY(r,b),
+ KEY(s,b),KEY(t,b),KEY(u,b),
+ KEY(d,c),KEY(e,c),KEY(f,c),KEY(g,c),KEY(h,c),KEY(i,c),KEY(j,c),
+ KEY(k,c),KEY(l,c),KEY(m,c),KEY(n,c),KEY(o,c),KEY(p,c),KEY(q,c),KEY(r,c),
+ KEY(s,c),KEY(t,c),KEY(u,c),
+ KEY(e,d),KEY(f,d),KEY(g,d),KEY(h,d),KEY(i,d),KEY(j,d)
+) ENGINE=InnoDB;
+INSERT INTO t1 () VALUES (), ();
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1';
-SELECT * FROM t1 ORDER BY a;
+SELECT a FROM t1 ORDER BY a;
TRUNCATE TABLE t1;
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1';
-INSERT INTO t1 VALUES (NULL), (NULL);
-SELECT * FROM t1 ORDER BY a;
+INSERT INTO t1 () VALUES (), ();
+SELECT a FROM t1 ORDER BY a;
DROP TABLE t1;
+
+ #
+ # MDEV-18923 Assertion `!lex_string_cmp(system_charset_info, fk_info->referenced_table, &table->s->table_name)' failed in fk_truncate_illegal_if_parent
+ #
-call mtr.add_suppression('InnoDB: Error: in RENAME TABLE table `test`.`t3`');
++call mtr.add_suppression('InnoDB: in RENAME TABLE table `test`.`t3`');
+ SET FOREIGN_KEY_CHECKS= OFF;
+ CREATE TABLE t1 (f2 INT, f4 INT, KEY(f2), FOREIGN KEY (f4) REFERENCES t3 (f4)) ENGINE=InnoDB;
+ SET FOREIGN_KEY_CHECKS= ON;
+ CREATE TABLE t2 (f2 INT, FOREIGN KEY(f2) REFERENCES t1 (f2)) ENGINE=InnoDB;
+ --error ER_CANT_CREATE_TABLE
+ CREATE TABLE t3 (a INT) ENGINE=InnoDB;
+ --replace_result $datadir ./
+ --error ER_ERROR_ON_RENAME
+ ALTER TABLE t1 RENAME TO t3;
+ ALTER TABLE t1 FORCE;
+ --error ER_TRUNCATE_ILLEGAL_FK
+ TRUNCATE TABLE t1;
+ DROP TABLE t2, t1;
diff --cc mysql-test/suite/rpl/r/kill_race_condition.result
index 00000000000,e4e347dc786..87ee3214b8e
mode 000000,100644..100644
--- a/mysql-test/suite/rpl/r/kill_race_condition.result
+++ b/mysql-test/suite/rpl/r/kill_race_condition.result
@@@ -1,0 -1,13 +1,18 @@@
+ include/master-slave.inc
+ [connection master]
++connection slave;
+ set global debug_dbug='d,rows_log_event_before_open_table';
+ set debug_sync='now WAIT_FOR before_open_table';
++connection master;
+ create table t1 (a int);
+ insert t1 values (1),(2),(3);
++connection slave;
+ kill slave_sql_thread;
+ set debug_sync='now SIGNAL go_ahead_sql';
+ set global debug_dbug='';
+ set debug_sync='RESET';
++connection master;
+ drop table t1;
++connection slave;
+ start slave;
+ include/rpl_end.inc
diff --cc mysql-test/suite/rpl/r/rpl_current_user.result
index ba5269bef22,3e8d6883c0b..efb036023e9
--- a/mysql-test/suite/rpl/r/rpl_current_user.result
+++ b/mysql-test/suite/rpl/r/rpl_current_user.result
@@@ -88,8 -82,9 +88,10 @@@ include/rpl_sync.in
include/diff_tables.inc [server_1:v_user, server_2:v_user, server_3:v_user]
# Verify 'ALTER EVENT...' statement
+connection master;
CREATE EVENT e1 ON SCHEDULE EVERY 1 DAY DO SELECT * FROM t1;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
# Explicitly assign CURRENT_USER() to definer
ALTER DEFINER=CURRENT_USER() EVENT e1 ENABLE;
include/rpl_sync.inc
diff --cc mysql-test/suite/rpl/r/rpl_heartbeat_basic.result
index 4ffa8fc9883,d7638942f85..1db69ea4b83
--- a/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result
+++ b/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result
@@@ -237,7 -216,8 +237,9 @@@ D
BEGIN
UPDATE test.t1 SET a = a + 1 WHERE a < 10;
END|
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
+connection slave;
RESET SLAVE;
CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_CONNECT_RETRY=20, MASTER_HEARTBEAT_PERIOD=5;
include/start_slave.inc
diff --cc mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result
index 00b50df4a68,3726760f498..dce79837700
--- a/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result
+++ b/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result
@@@ -679,6 -678,9 +679,8 @@@ DROP TRIGGER tr1
GRANT EVENT ON *.* TO 'root'@'localhost';
INSERT INTO t1 VALUES(1, 'test1');
CREATE EVENT e1 ON SCHEDULE EVERY '1' SECOND COMMENT 'e_second_comment' DO DELETE FROM t1;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
-==========MASTER==========
SHOW EVENTS;
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
test_rpl e1 root@localhost SYSTEM RECURRING NULL 1 # # NULL ENABLED 1 latin1 latin1_swedish_ci latin1_swedish_ci
diff --cc mysql-test/suite/rpl/r/rpl_killed_ddl.result
index 66309432efe,a0520783168..2c0f27a3218
--- a/mysql-test/suite/rpl/r/rpl_killed_ddl.result
+++ b/mysql-test/suite/rpl/r/rpl_killed_ddl.result
@@@ -32,11 -32,13 +32,13 @@@ CREATE DATABASE d1
CREATE EVENT e1
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 DAY
DO INSERT INTO test.t1 VALUES (1);
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
CREATE FUNCTION f1 () RETURNS INT DETERMINISTIC
RETURN 1;
-CREATE PROCEDURE p1 (OUT rows INT)
+CREATE PROCEDURE p1 (OUT rows_cnt INT)
BEGIN
-SELECT COUNT(*) INTO rows FROM t1;
+SELECT COUNT(*) INTO rows_cnt FROM t1;
END;
//
CREATE SERVER s1
diff --cc mysql-test/t/func_gconcat.test
index abc86476a6b,57da0f3c6fc..e752d9fcd50
--- a/mysql-test/t/func_gconcat.test
+++ b/mysql-test/t/func_gconcat.test
@@@ -874,44 -872,29 +872,73 @@@ SELECT LENGTH(GROUP_CONCAT(f1 ORDER BY
DROP TABLE t1;
SET group_concat_max_len= DEFAULT;
+ #
+ # MDEV-9531 GROUP_CONCAT with ORDER BY inside takes a lot of memory while it's executed
+ #
++set session group_concat_max_len=1024;
+ set max_session_mem_used=16*1024*1024; # 8M..32M
+ SELECT GROUP_CONCAT(concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1) ORDER BY 2,1,3,4,6,5,8,7) AS c
+ FROM seq_1_to_200000;
+ set max_session_mem_used=default;
++set session group_concat_max_len=default;
+
+ #
+ # MDEV-19350 Server crashes in delete_tree_element / ... / Item_func_group_concat::repack_tree
+ #
+ SET group_concat_max_len= 8;
+ CREATE TABLE t1 (a INT);
+ INSERT t1 VALUES (1),(2);
+ CREATE TABLE t2 (b DATE, c INT);
+ INSERT t2 VALUES ('2019-12-04',1),('2020-03-28',2);
+ CREATE TABLE t3 (d INT);
+ INSERT t3 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14);
+ CREATE TABLE t4 (e INT);
+ INSERT t4 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15);
+ SELECT (SELECT MAX(a) FROM t1 WHERE t2_sq.c > 0) AS f,
+ GROUP_CONCAT(t2_sq.b ORDER BY 1) AS gc
+ FROM (SELECT t2_a.* FROM t2 AS t2_a, t2 AS t2_b) AS t2_sq, t3, t4
+ GROUP BY f;
+ DROP TABLE t1, t2, t3, t4;
+ SET group_concat_max_len= default;
++
+
+--echo #
+--echo # Start of 10.2 tests
+--echo #
+
+--echo #
+--echo # MDEV-10124 Incorrect usage of CUBE/ROLLUP and ORDER BY with GROUP_CONCAT(a ORDER BY a)
+--echo #
+
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (10),(20),(30);
+
+SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP;
+CREATE VIEW v1 AS
+SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP;
+SELECT * FROM v1;
+DROP VIEW v1;
+
+SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30';
+CREATE VIEW v1 AS
+SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30';
+SELECT * FROM v1;
+DROP VIEW v1;
+
+SELECT * FROM (SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30') t1;
+CREATE VIEW v1 AS
+SELECT * FROM (SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30') t1;
+SELECT * FROM v1;
+DROP VIEW v1;
+
+SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30');
+CREATE VIEW v1 AS
+SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30');
+SELECT * FROM v1;
+DROP VIEW v1;
+
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.2 tests
+--echo #
diff --cc mysql-test/t/gis.test
index ebcea63b083,db3ab00fb03..f630a6dc8bf
--- a/mysql-test/t/gis.test
+++ b/mysql-test/t/gis.test
@@@ -1568,196 -1569,19 +1568,243 @@@ CREATE TABLE t2 AS SELECT WITHIN(g1,g1
SHOW CREATE TABLE t2;
DROP TABLE t1,t2;
++
+ #
+ # MDEV-3934 Assertion `((keypart_map+1) & keypart_map) == 0' failed in _mi_pack_key with an index on a POINT column
+ #
+
+ CREATE TABLE t1 (
+ id INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ point_data POINT NOT NULL,
+ PRIMARY KEY (id),
+ KEY idx_point_data(point_data)
+ ) ENGINE=MyISAM;
+ INSERT t1 (point_data) VALUES
+ (GeomFromText('Point(37.0248492 23.8512726)')),
+ (GeomFromText('Point(38.0248492 23.8512726)'));
+ SELECT id FROM t1
+ WHERE ST_Contains(point_data, GeomFromText('Point(38.0248492 23.8512726)'));
+ DROP TABLE t1;
++
++
+--echo #
+--echo # Start of 10.2 tests
+--echo #
+
+#
+# Item_func_spatial_collection::print()
+#
+create view v1 as select AsWKT(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9))));
+show create view v1;
+select * from v1;
+drop view v1;
+
+--echo #
+--echo # MDEV-10134 Add full support for DEFAULT
+--echo #
+
+CREATE TABLE t1 (a POINT, x DOUBLE DEFAULT x(a), y DOUBLE DEFAULT y(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (Point(1,2));
+SELECT x,y FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (g GEOMETRY, area DOUBLE DEFAULT ST_AREA(g));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (g) VALUES (GeomFromText('POLYGON((0 0,20 0,20 20,0 20,0 0))'));
+SELECT area FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (g GEOMETRY, length DOUBLE DEFAULT ST_LENGTH(g));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (g) VALUES (GeomFromText('LINESTRING(0 0,20 0,20 20,0 20,0 0)'));
+SELECT length FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (g POINT, distance DOUBLE DEFAULT ST_DISTANCE(g, POINT(0,0)));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (g) VALUES (Point(1,0));
+SELECT distance FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a TEXT, g GEOMETRY DEFAULT GeomFromText(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES ('point(1 1)');
+SELECT AsText(g) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (x INT, y INT, g GEOMETRY DEFAULT POINT(x,y));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (x,y) VALUES (10,20);
+SELECT AsText(g) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT PointN(a,2));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,2 2,3 3)'));
+SELECT AsText(b) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT StartPoint(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,2 2,3 3)'));
+SELECT AsText(b) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c GEOMETRY DEFAULT GeometryCollection(a,b));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a,b) VALUES (Point(1,1), Point(2,2));
+SELECT AsText(c) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT GeomFromWKB(AsBinary(a),20));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('POINT(1 1)', 10));
+SELECT AsText(a), SRID(a), AsText(b), SRID(b) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT BOUNDARY(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))'));
+SELECT AsText(b) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT BUFFER(a,10));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))'));
+SELECT GeometryType(b) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT CENTROID(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))'));
+SELECT AsText(b) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT ENVELOPE(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,4 4)'));
+SELECT AsText(b) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT PointOnSurface(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))'));
+SELECT GeometryType(b) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT Point(1,1), c GEOMETRY DEFAULT ST_UNION(a,b));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (Point(0,0));
+SELECT AsText(c) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b VARCHAR(20) DEFAULT GeometryType(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (Point(0, 0));
+SELECT b FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsSimple(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (Point(0, 0));
+SELECT b FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsEmpty(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (Point(0, 0));
+SELECT b FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsRing(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('LineString(0 0,0 1,1 1,1 0,0 0)'));
+SELECT b FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsClosed(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('LineString(0 0,0 1,1 1,1 0,0 0)'));
+SELECT b FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT Dimension(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (Buffer(Point(1,1),1));
+SELECT b FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumGeometries(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (ST_UNION(Point(1,1),Point(0,0)));
+SELECT b FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumInteriorRings(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))'));
+SELECT b FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumPoints(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (LineString(Point(1,1),Point(0,0)));
+SELECT b FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT SRID(a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (GeomFromText('Point(1 1)', 100));
+SELECT b FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT MBRDisjoint(a,b));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1));
+SELECT c FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT ST_Disjoint(a,b));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1));
+SELECT c FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT ST_Relate(a,b,'T*F**FFF*'));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1));
+SELECT c FROM t1;
+DROP TABLE t1;
+
++#
++# MDEV-13923 Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' failed upon altering table with geometry field
++#
++--error ER_CANT_CREATE_GEOMETRY_OBJECT
++create table t1 (p point default "qwer");
++--error ER_CANT_CREATE_GEOMETRY_OBJECT
++create table t1 (p point default 0);
++--error ER_INVALID_DEFAULT
++create table t1 (p point not null default st_geometryfromtext('point 0)'));
++create table t1 (p point not null default st_geometryfromtext('point(0 0)'));
++insert into t1 values(default);
++select st_astext(p) from t1;
++drop table t1;
++
++create table t1 (p point not null default if(unix_timestamp()>10,POINT(1,1),0));
++set timestamp=10;
++--error ER_CANT_CREATE_GEOMETRY_OBJECT
++insert into t1 values(default);
++drop table t1;
++SET timestamp=default;
++
++create table t1 (p point not null default if(unix_timestamp()>10,POINT(1,1),0));
++set timestamp=10;
++--error ER_CANT_CREATE_GEOMETRY_OBJECT
++alter table t1 add column i int;
++drop table t1;
++SET timestamp=default;
++
+--echo #
+--echo # End of 10.2 tests
+--echo #
diff --cc mysql-test/t/multi_update.test
index 64e61f7c0b5,8399c465562..900d0bd4283
--- a/mysql-test/t/multi_update.test
+++ b/mysql-test/t/multi_update.test
@@@ -983,4 -1056,86 +983,35 @@@ deallocate prepare stmt1
drop view v3,v2,v1;
drop table t1,t2,t3;
+
+ #
+ # MDEV-18507 can't update temporary table when joined with table with triggers on read-only
+ #
+ create table t1 (id int not null, v1 varchar(10) not null);
+ insert into t1 values (1,1),(2,2);
+ create table t2 (log varchar(10) not null);
+ create trigger t1_after_update after update on t1
+ for each row insert into t2 values ('triggered');
+
+ create user foo;
+ grant select, insert, update, delete, create, drop, reload, index, alter, show databases, create temporary tables, lock tables, execute, create view, show view, create routine, alter routine, trigger on *.* to 'foo'@'%';
+
+ set global read_only=1;
+ connect a, localhost, foo;
+
+ create temporary table temp_t1 (id int not null, update_me varchar(10));
+ insert into temp_t1 values (1,1),(2,2),(3,3);
+ update temp_t1 left join t1 on temp_t1.id = t1.id set temp_t1.update_me = 'hello';
+
+ connection default;
+ set global read_only = 0;
+
+ create table t3 (id int not null);
+ insert t3 values (2);
+ update t1 left join t3 on t1.id = t3.id set t1.v1 = 'hello';
+ select * from t2;
+
+ drop table t1,t2, t3;
+ drop user foo;
+
--echo end of 5.5 tests
-
-
---source include/have_xtradb.inc
-
---echo
---echo # Bug mdev-5970
---echo # Bug#13256831 - ERROR 1032 (HY000): CAN'T FIND RECORD
---echo
-
-CREATE TABLE t1 (f1 INT PRIMARY KEY, f2 INT) ENGINE=InnoDB;
-CREATE TABLE t2 (f1 INT PRIMARY KEY, f2 INT) ENGINE=InnoDB;
-INSERT INTO t1 VALUES (5, 7);
-INSERT INTO t2 VALUES (6, 97);
-
-CREATE ALGORITHM = MERGE VIEW v1 AS
-SELECT a2.f1 AS f1, a2.f2 AS f2
-FROM t1 AS a1 JOIN t2 AS a2 ON a1.f2 > a2.f1
-WITH LOCAL CHECK OPTION;
-
-SELECT * FROM v1;
-UPDATE v1 SET f1 = 1;
-SELECT * FROM v1;
-
-DROP TABLE t1, t2;
-DROP VIEW v1;
-
---echo #
---echo # MDEV-5973: MySQL Bug#11757486:49539: NON-DESCRIPTIVE ERR (ERROR 0
---echo # FROM STORAGE ENGINE) WITH MULTI-TABLE UPDATE
---echo #
-
-CREATE TABLE table_11757486 (field1 tinyint) ENGINE=INNODB;
-INSERT INTO table_11757486 VALUES (0),(0);
-SET SESSION SQL_MODE='STRICT_ALL_TABLES';
-UPDATE IGNORE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1;
-UPDATE IGNORE table_11757486 SET field1=128;
-
---error ER_WARN_DATA_OUT_OF_RANGE
-UPDATE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1;
---error ER_WARN_DATA_OUT_OF_RANGE
-UPDATE table_11757486 SET field1=128;
-
-SET SESSION SQL_MODE='';
-UPDATE IGNORE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1;
-UPDATE IGNORE table_11757486 SET field1=128;
-
-DROP TABLE table_11757486;
-
-SET SESSION SQL_MODE=default;
-
---echo end of 10.0 tests
diff --cc mysql-test/t/partition_innodb.test
index 590e2fc7f07,15c9625770b..8c644103046
--- a/mysql-test/t/partition_innodb.test
+++ b/mysql-test/t/partition_innodb.test
@@@ -1022,49 -1027,28 +1022,74 @@@ UPDATE v SET f2 = NULL
SET GLOBAL innodb_stats_persistent= @save_isp;
DROP view v;
DROP TABLE t;
+set sql_mode= @save_sql_mode;
+ --echo #
+ --echo # Bug#28573894 ALTER PARTITIONED TABLE ADD AUTO_INCREMENT DIFF RESULT
+ --echo #
+ CREATE TABLE t (a VARCHAR(10) NOT NULL,b INT,PRIMARY KEY (b)) ENGINE=INNODB
+ PARTITION BY RANGE (b)
+ (PARTITION pa VALUES LESS THAN (2),
+ PARTITION pb VALUES LESS THAN (20),
+ PARTITION pc VALUES LESS THAN (30),
+ PARTITION pd VALUES LESS THAN (40));
+
+ INSERT INTO t
+ VALUES('A',0),('B',1),('C',2),('D',3),('E',4),('F',5),('G',25),('H',35);
+ CREATE TABLE t_copy LIKE t;
+ INSERT INTO t_copy SELECT * FROM t;
+
+ --enable_info
+ ALTER TABLE t ADD COLUMN r INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ ADD UNIQUE KEY (r,b);
+ ALTER TABLE t_copy ADD COLUMN r INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ ADD UNIQUE KEY (r,b), ALGORITHM=COPY;
+ --disable_info
+ SELECT * FROM t;
+ SELECT * FROM t_copy;
+ DROP TABLE t,t_copy;
++
+--echo #
+--echo # Bug#26390658 RENAMING A PARTITIONED TABLE DOES NOT UPDATE
+--echo # MYSQL.INNODB_TABLE_STATS
+--echo #
+
+CREATE DATABASE test_jfg;
+
+CREATE TABLE test_jfg.test_jfg1 (id int(10) unsigned NOT NULL,PRIMARY
+KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1 STATS_PERSISTENT=1;
+CREATE TABLE test_jfg.test_jfg2 (id int(10) unsigned NOT NULL,PRIMARY
+KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1 STATS_PERSISTENT=1
+PARTITION BY RANGE ( id ) (PARTITION p1000 VALUES LESS THAN (1000)
+ENGINE = InnoDB,PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE =
+InnoDB);
+
+--replace_result #p# #P#
+SELECT database_name, table_name FROM mysql.innodb_table_stats WHERE
+database_name = 'test_jfg';
+
+RENAME TABLE test_jfg.test_jfg1 TO test_jfg.test_jfg11;
+RENAME TABLE test_jfg.test_jfg2 TO test_jfg.test_jfg12;
+
+--replace_result #p# #P#
+SELECT database_name, table_name FROM mysql.innodb_table_stats WHERE
+database_name = 'test_jfg';
+
+DROP DATABASE test_jfg;
+
+#
+# MDEV-17755 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index) || (!(ptr >= table->record[0] && ptr < table->record[0] + table->s->reclength)))' failed in Field_bit::val_int upon SELECT with JOIN, partitions, indexed virtual column
+#
+create table t1 (a int) engine=innodb;
+create table t2 (
+ b int,
+ c int,
+ d bit not null default 0,
+ v bit as (d) virtual,
+ key (b,v)
+) engine=innodb partition by hash (b);
+insert into t1 values (1),(2);
+insert into t2 (b,c,d) values (1,1,0),(2,2,0);
+explain select t1.* from t1 join t2 on (v = a);
+select t1.* from t1 join t2 on (v = a);
+drop table t1, t2;
diff --cc mysql-test/t/stat_tables.test
index 93caa47ce79,2727f8d8bb1..ddf881c69ae
--- a/mysql-test/t/stat_tables.test
+++ b/mysql-test/t/stat_tables.test
@@@ -453,47 -453,27 +453,68 @@@ delete from mysql.table_stats
delete from mysql.column_stats;
delete from mysql.index_stats;
+ --echo #
+ --echo # MDEV-19352: Server crash in alloc_histograms_for_table_share upon query from information schema
+ --echo #
+
+ use test;
+ set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
+ set @@optimizer_use_condition_selectivity= 4;
+ set use_stat_tables='preferably';
+
+ CREATE TABLE t1 (a INT);
+ CREATE TABLE t2 (b INT);
+ CREATE VIEW v AS SELECT * FROM t1 JOIN t2;
+ --error ER_NO_SUCH_TABLE
+ INSERT INTO t2 SELECT * FROM x;
+
+ select * from information_schema.tables where table_name='v';
+
+ drop table t1,t2;
+ drop view v;
+ set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
+
set @save_optimizer_switch=@@optimizer_switch;
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # MDEV-18899: Server crashes in Field::set_warning_truncated_wrong_value
+--echo #
+set names utf8;
+set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
+set optimizer_use_condition_selectivity=4;
+set use_stat_tables=preferably;
+set @save_histogram_size= @@histogram_size;
+set histogram_size=255;
+
+create table t1 ( a varchar(255) character set utf8);
+insert into t1 values (REPEAT('ӥ',255)), (REPEAT('ç',255));
+
+analyze table t1;
+select HEX(RIGHT(min_value, 1)), length(min_value) from mysql.column_stats where db_name='test' and table_name='t1';
+select HEX(RIGHT(max_value, 1)), length(max_value) from mysql.column_stats where db_name='test' and table_name='t1';
+analyze select * from t1 where a >= 'Ó¥';
+
+set @save_sql_mode= @@sql_mode;
+set sql_mode='ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+update mysql.column_stats set min_value= REPEAT('Ó¥',255) where db_name='test' and table_name='t1';
+select HEX(RIGHT(min_value, 1)), length(min_value) from mysql.column_stats where db_name='test' and table_name='t1';
+analyze select * from t1 where a >= 'Ó¥';
+
+set names latin1;
+drop table t1;
+
+CREATE TABLE t1 (col1 date);
+INSERT INTO t1 VALUES('2004-01-01'),('2004-02-29');
+INSERT INTO t1 VALUES('0000-10-31');
+analyze table t1;
+update mysql.column_stats set min_value='2004-0-31123' where db_name='test' and table_name='t1';
+select min_value from mysql.column_stats where db_name='test' and table_name='t1';
+select * from t1;
+drop table t1;
+
+set @@sql_mode= @save_sql_mode;
set use_stat_tables=@save_use_stat_tables;
+set @@histogram_size= @save_histogram_size;
+set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
diff --cc mysql-test/t/statistics.test
index b2e544064b0,7d2e7e898d3..4c45b4f38b8
--- a/mysql-test/t/statistics.test
+++ b/mysql-test/t/statistics.test
@@@ -879,22 -809,19 +879,37 @@@ rename table t1 to t2, t3 to t4
drop table t1, mysql.table_stats;
rename table test.table_stats to mysql.table_stats;
+ --echo #
+ --echo # MDEV-19334: bool is_eits_usable(Field*): Assertion `field->table->stats_is_read' failed.
+ --echo #
+
+ create temporary table t1(a int);
+ insert into t1 values (1),(2),(3);
+
+ set use_stat_tables=preferably;
+ set @optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
+ set optimizer_use_condition_selectivity=4;
+
+ select * from t1 where a >= 2;
+ drop table t1;
+ set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
+
set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Start of 10.2 tests
+--echo #
+
+--echo #
+--echo # MDEV-10134 Add full support for DEFAULT
+--echo #
+
+CREATE TABLE t1 (a BLOB, b TEXT DEFAULT DECODE_HISTOGRAM('SINGLE_PREC_HB',a));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a) VALUES (0x0000000000000000000000000101010101010101010202020303030304040404050505050606070707080809090A0A0B0C0D0D0E0E0F10111213131415161718191B1C1E202224292A2E33373B4850575F6A76818C9AA7B9C4CFDADFE5EBF0F4F8FAFCFF);
+SELECT b FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.2 tests
+--echo #
diff --cc mysql-test/t/type_bit.test
index 04db1511833,4df6d72ce9a..012fa2236d7
--- a/mysql-test/t/type_bit.test
+++ b/mysql-test/t/type_bit.test
@@@ -459,27 -459,12 +459,36 @@@ SELECT COALESCE(val, 1) FROM t1
--disable_metadata
DROP TABLE t1;
-
+ --echo #
+ --echo # MDEV-18452 ASAN unknown-crash in Field::set_default upon SET bit_column = DEFAULT
+ --echo #
+
+ CREATE TABLE t1 (b BIT(20)) ENGINE=MyISAM;
+ INSERT INTO t1 VALUES (0);
+ UPDATE t1 SET b = DEFAULT;
+ DROP TABLE t1;
++
+--echo #
+--echo # End of 10.1 tests
+--echo #
+
+
+--echo #
+--echo # Start of 10.2 tests
+--echo #
+
+--echo #
+--echo # MDEV-9334 ALTER from DECIMAL to BIGINT UNSIGNED returns a wrong result
+--echo #
+
+CREATE TABLE t1 (a DECIMAL(30,0));
+INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
+ALTER TABLE t1 MODIFY a BIT(64);
+SELECT a+0 FROM t1;
+DROP TABLE IF EXISTS t1;
+
+
+--echo #
+--echo # End of 10.2 tests
+--echo #
+
diff --cc pcre/pcregrep.c
index 79d9e286c75,5982406862b..1f3b12f2a03
--- a/pcre/pcregrep.c
+++ b/pcre/pcregrep.c
@@@ -2249,10 -2249,10 +2249,10 @@@ if (isdirectory(pathname)
while ((nextfile = readdirectory(dir)) != NULL)
{
int frc;
- int fnlength = strlen(pathname) + strlen(nextfile) + 2;
+ size_t fnlength = strlen(pathname) + strlen(nextfile) + 2;
if (fnlength > 2048)
{
- fprintf(stderr, "pcre2grep: recursive filename is too long\n");
+ fprintf(stderr, "pcregrep: recursive filename is too long\n");
rc = 2;
break;
}
diff --cc scripts/mysql_install_db.sh
index 8bad8c4000b,43b7d7a52f6..2c132cccf2a
--- a/scripts/mysql_install_db.sh
+++ b/scripts/mysql_install_db.sh
@@@ -499,7 -495,7 +501,7 @@@ SET @auth_root_socket=NULL;" ;
SET @skip_auth_root_nopasswd=1;
SET @auth_root_socket='$auth_root_socket_user';" ;;
esac
- if { echo "use mysql;$install_params"; cat "$create_system_tables" "$create_system_tables2" "$fill_system_tables" "$fill_help_tables" "$maria_add_gis_sp"; } | eval "$filter_cmd_line" | mysqld_install_cmd_line > /dev/null
-if { echo "$install_params"; cat "$create_system_tables" "$create_system_tables2" "$fill_system_tables"; } | eval "$filter_cmd_line" | mysqld_install_cmd_line > /dev/null
++if { echo "$install_params"; cat "$create_system_tables" "$create_system_tables2" "$fill_system_tables" "$fill_help_tables" "$maria_add_gis_sp"; } | eval "$filter_cmd_line" | mysqld_install_cmd_line > /dev/null
then
s_echo "OK"
else
diff --cc sql/field.cc
index 0621015c0e4,a4308a378b3..30eed286512
--- a/sql/field.cc
+++ b/sql/field.cc
@@@ -2415,26 -2283,6 +2415,26 @@@ Field *Field::clone(MEM_ROOT *root, my_
return tmp;
}
+int Field::set_default()
+{
+ if (default_value)
+ {
+ Query_arena backup_arena;
+ table->in_use->set_n_backup_active_arena(table->expr_arena, &backup_arena);
+ int rc= default_value->expr->save_in_field(this, 0);
+ table->in_use->restore_active_arena(table->expr_arena, &backup_arena);
+ return rc;
+ }
+ /* Copy constant value stored in s->default_values */
+ my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values -
+ table->record[0]);
- memcpy(ptr, ptr + l_offset, pack_length());
++ memcpy(ptr, ptr + l_offset, pack_length_in_rec());
+ if (maybe_null_in_table())
+ *null_ptr= ((*null_ptr & (uchar) ~null_bit) |
+ (null_ptr[l_offset] & null_bit));
+ return 0;
+}
+
/****************************************************************************
Field_null, a field that always return NULL
diff --cc sql/item_sum.cc
index 4405477b6a1,71f07706d22..b1b22d0877f
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@@ -3451,6 -3304,62 +3455,62 @@@ void Item_func_group_concat::clear(
/* No need to reset the table as we never call write_row */
}
+ struct st_repack_tree {
+ TREE tree;
+ TABLE *table;
+ size_t len, maxlen;
+ };
+
+ extern "C"
+ int copy_to_tree(void* key, element_count count __attribute__((unused)),
+ void* arg)
+ {
+ struct st_repack_tree *st= (struct st_repack_tree*)arg;
+ TABLE *table= st->table;
+ Field* field= table->field[0];
+ const uchar *ptr= field->ptr_in_record((uchar*)key - table->s->null_bytes);
- size_t len= field->val_int(ptr);
++ size_t len= (size_t)field->val_int(ptr);
+
+ DBUG_ASSERT(count == 1);
+ if (!tree_insert(&st->tree, key, 0, st->tree.custom_arg))
+ return 1;
+
+ st->len += len;
+ return st->len > st->maxlen;
+ }
+
+ bool Item_func_group_concat::repack_tree(THD *thd)
+ {
+ struct st_repack_tree st;
+
- init_tree(&st.tree, MY_MIN(thd->variables.max_heap_table_size,
- thd->variables.sortbuff_size/16), 0,
++ init_tree(&st.tree, (size_t) MY_MIN(thd->variables.max_heap_table_size,
++ thd->variables.sortbuff_size/16), 0,
+ tree->size_of_element, group_concat_key_cmp_with_order, NULL,
+ (void*) this, MYF(MY_THREAD_SPECIFIC));
+ st.table= table;
+ st.len= 0;
- st.maxlen= thd->variables.group_concat_max_len;
++ st.maxlen= (size_t)thd->variables.group_concat_max_len;
+ tree_walk(tree, ©_to_tree, &st, left_root_right);
+ if (st.len <= st.maxlen) // Copying aborted. Must be OOM
+ {
+ delete_tree(&st.tree);
+ return 1;
+ }
+ delete_tree(tree);
+ *tree= st.tree;
+ tree_len= st.len;
+ return 0;
+ }
+
+ /*
+ Repacking the tree is expensive. But it keeps the tree small, and
+ inserting into an unnecessary large tree is also waste of time.
+
+ The following number is best-by-test. Test execution time slowly
+ decreases up to N=10 (that is, factor=1024) and then starts to increase,
+ again, very slowly.
+ */
+ #define GCONCAT_REPACK_FACTOR (1 << 10)
bool Item_func_group_concat::add()
{
@@@ -3486,6 -3403,12 +3554,12 @@@
TREE_ELEMENT *el= 0; // Only for safety
if (row_eligible && tree)
{
+ THD *thd= table->in_use;
- table->field[0]->store(row_str_len);
++ table->field[0]->store(row_str_len, FALSE);
+ if (tree_len > thd->variables.group_concat_max_len * GCONCAT_REPACK_FACTOR
+ && tree->elements_in_tree > 1)
+ if (repack_tree(thd))
+ return 1;
el= tree_insert(tree, table->record[0] + table->s->null_bytes, 0,
tree->custom_arg);
/* check if there was enough memory to insert the row */
@@@ -3620,9 -3543,17 +3695,17 @@@ bool Item_func_group_concat::setup(THD
if (!ref_pointer_array)
DBUG_RETURN(TRUE);
memcpy(ref_pointer_array, args, arg_count * sizeof(Item*));
- if (setup_order(thd, ref_pointer_array, context->table_list, list,
- all_fields, *order))
+ if (setup_order(thd, Ref_ptr_array(ref_pointer_array, n_elems),
+ context->table_list, list, all_fields, *order))
DBUG_RETURN(TRUE);
+ /*
+ Prepend the field to store the length of the string representation
+ of this row. Used to detect when the tree goes over group_concat_max_len
+ */
+ Item *item= new (thd->mem_root)
- Item_int(thd, thd->variables.group_concat_max_len);
++ Item_uint(thd, thd->variables.group_concat_max_len);
+ if (!item || all_fields.push_front(item, thd->mem_root))
+ DBUG_RETURN(TRUE);
}
count_field_types(select_lex, tmp_table_param, all_fields, 0);
@@@ -3685,11 -3617,12 +3769,12 @@@
syntax of this function). If there is no ORDER BY clause, we don't
create this tree.
*/
- init_tree(tree, MY_MIN(thd->variables.max_heap_table_size,
- thd->variables.sortbuff_size/16), 0,
- tree_key_length,
+ init_tree(tree, (size_t)MY_MIN(thd->variables.max_heap_table_size,
- thd->variables.sortbuff_size/16), 0,
- tree_key_length,
++ thd->variables.sortbuff_size/16), 0,
++ tree_key_length,
group_concat_key_cmp_with_order, NULL, (void*) this,
MYF(MY_THREAD_SPECIFIC));
+ tree_len= 0;
}
if (distinct)
diff --cc sql/item_sum.h
index 5c8ff520259,001d1d13fe4..c1373f6c1fc
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@@ -1629,8 -1468,8 +1630,10 @@@ class Item_func_group_concat : public I
friend int dump_leaf_key(void* key_arg,
element_count count __attribute__((unused)),
void* item_arg);
+protected:
- virtual Field *make_string_field(TABLE *table);
++ Field *make_string_field(TABLE *table);
+
+ bool repack_tree(THD *thd);
public:
Item_func_group_concat(THD *thd, Name_resolution_context *context_arg,
@@@ -1686,11 -1525,9 +1689,11 @@@
String* val_str(String* str);
Item *copy_or_same(THD* thd);
void no_rows_in_result() {}
- virtual void print(String *str, enum_query_type query_type);
- virtual bool change_context_processor(void *cntx)
+ void print(String *str, enum_query_type query_type);
- bool change_context_processor(uchar *cntx)
++ bool change_context_processor(void *cntx)
{ context= (Name_resolution_context *)cntx; return FALSE; }
+ Item *get_copy(THD *thd, MEM_ROOT *mem_root)
+ { return get_item_copy<Item_func_group_concat>(thd, mem_root, this); }
};
#endif /* ITEM_SUM_INCLUDED */
diff --cc sql/mysqld.cc
index 2d872afaeb8,cf76a6a4c5c..cf96318f34c
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@@ -4146,24 -4077,18 +4179,26 @@@ static int init_common_variables(
if (!global_rpl_filter || !binlog_filter)
{
sql_perror("Could not allocate replication and binlog filters");
- return 1;
+ exit(1);
}
- if (init_thread_environment() ||
- mysql_init_variables())
- return 1;
+#ifdef HAVE_OPENSSL
+ if (check_openssl_compatibility())
+ {
+ sql_print_error("Incompatible OpenSSL version. Cannot continue...");
+ exit(1);
+ }
+#endif
+
+ if (init_thread_environment() || mysql_init_variables())
+ exit(1);
if (ignore_db_dirs_init())
- return 1;
+ exit(1);
+
- #ifdef HAVE_TZNAME
+ #ifdef _WIN32
+ get_win_tzname(system_time_zone, sizeof(system_time_zone));
+ #elif defined(HAVE_TZNAME)
struct tm tm_tmp;
localtime_r(&server_start_time,&tm_tmp);
const char *tz_name= tzname[tm_tmp.tm_isdst != 0 ? 1 : 0];
diff --cc sql/sql_acl.cc
index 871744c6b36,6448f65a2cd..d5ef3c38b7b
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@@ -782,641 -786,30 +782,640 @@@ static const int Table_procs_priv= 1 <
static const int Table_proxies_priv= 1 << PROXIES_PRIV_TABLE;
static const int Table_roles_mapping= 1 << ROLES_MAPPING_TABLE;
-static int open_grant_tables(THD *, TABLE_LIST *, enum thr_lock_type, int);
+/**
+ Base class representing a generic grant table from the mysql database.
+
+ The potential tables that this class can represent are:
+ user, db, columns_priv, tables_priv, host, procs_priv, proxies_priv,
+ roles_mapping
+
+ Objects belonging to this parent class can only be constructed by the
+ Grants_table class. This ensures the correct initialization of the objects.
+*/
+class Grant_table_base
+{
+ public:
+ /* Number of fields for this Grant Table. */
+ uint num_fields() const { return tl.table->s->fields; }
+ /* Check if the table exists after an attempt to open it was made.
+ Some tables, such as the host table in MySQL 5.6.7+ are missing. */
+ bool table_exists() const { return tl.table; };
+ /* Initializes the READ_RECORD structure provided as a parameter
+ to read through the whole table, with all columns available. Cleaning up
+ is the caller's job. */
+ bool init_read_record(READ_RECORD* info, THD* thd) const
+ {
+ DBUG_ASSERT(tl.table);
+ bool result= ::init_read_record(info, thd, tl.table, NULL, NULL, 1,
+ true, false);
+ if (!result)
+ tl.table->use_all_columns();
+ return result;
+ }
+
+ /* Return the number of privilege columns for this table. */
+ uint num_privileges() const { return num_privilege_cols; }
+ /* Return a privilege column by index. */
+ Field* priv_field(uint privilege_idx) const
+ {
+ DBUG_ASSERT(privilege_idx < num_privileges());
+ return tl.table->field[start_privilege_column + privilege_idx];
+ }
+
+ /* Fetch the privileges from the table as a set of bits. The first column
+ is represented by the first bit in the result, the second column by the
+ second bit, etc. */
+ ulong get_access() const
+ {
+ return get_access(start_privilege_column,
+ start_privilege_column + num_privileges() - 1);
+ }
+
+ /* Return the underlying TABLE handle. */
+ TABLE* table() const
+ {
+ return tl.table;
+ }
+
+ /** Check if the table was opened, issue an error otherwise. */
+ int no_such_table() const
+ {
+ if (table_exists())
+ return 0;
+
+ my_error(ER_NO_SUCH_TABLE, MYF(0), tl.db, tl.alias);
+ return 1;
+ }
+
+
+ protected:
+ friend class Grant_tables;
+
+ Grant_table_base() : start_privilege_column(0), num_privilege_cols(0)
+ {
+ tl.reset();
+ };
+
+ /* Initialization sequence common for all grant tables. This should be called
+ after all table-specific initialization is performed. */
+ void init(enum thr_lock_type lock_type, bool is_optional)
+ {
+ tl.open_type= OT_BASE_ONLY;
- if (lock_type >= TL_WRITE_ALLOW_WRITE)
- tl.updating= 1;
++ tl.i_s_requested_object= OPEN_TABLE_ONLY;
+ if (is_optional)
+ tl.open_strategy= TABLE_LIST::OPEN_IF_EXISTS;
+ }
+
+ /*
+ Get all access bits from table between start_field and end_field indices.
+
+ IMPLEMENTATION
+ The record should be already read in table->record[0]. All privileges
+ are specified as an ENUM(Y,N).
+
+ SYNOPSIS
+ get_access()
+ start_field_idx The field index at which the first privilege
+ specification begins.
+ end_field_idx The field index at which the last privilege
+ specification is located.
+
+ RETURN VALUE
+ privilege mask
+ */
+ ulong get_access(uint start_field_idx, uint end_field_idx) const
+ {
+ ulong access_bits= 0, bit= 1;
+ for (uint i = start_field_idx; i <= end_field_idx; i++, bit<<=1)
+ {
+ if (get_YN_as_bool(tl.table->field[i]))
+ access_bits|= bit;
+ }
+ return access_bits;
+ }
+
+ /* Compute how many privilege columns this table has. This method
+ can only be called after the table has been opened.
+
+ IMPLEMENTATION
+ A privilege column is of type enum('Y', 'N'). Privilege columns are
+ expected to be one after another.
+ */
+ void compute_num_privilege_cols()
+ {
+ if (!table_exists()) // Table does not exist or not opened.
+ return;
+
+ num_privilege_cols= 0;
+ for (uint i= 0; i < num_fields(); i++)
+ {
+ Field *field= tl.table->field[i];
+ if (num_privilege_cols > 0 && field->real_type() != MYSQL_TYPE_ENUM)
+ return;
+ if (field->real_type() == MYSQL_TYPE_ENUM &&
+ static_cast<Field_enum*>(field)->typelib->count == 2)
+ {
+ num_privilege_cols++;
+ if (num_privilege_cols == 1)
+ start_privilege_column= i;
+ }
+ }
+ }
+
+ /* The index at which privilege columns start. */
+ uint start_privilege_column;
+ /* The number of privilege columns in the table. */
+ uint num_privilege_cols;
+
+ TABLE_LIST tl;
+};
+
+class User_table: public Grant_table_base
+{
+ public:
+ /* Field getters return NULL if the column is not present in the table.
+ This is consistent only if the table is in a supported version. We do
+ not guard against corrupt tables. (yet) */
+ Field* host() const
+ { return get_field(0); }
+ Field* user() const
+ { return get_field(1); }
+ Field* password() const
+ { return have_password() ? NULL : tl.table->field[2]; }
+ /* Columns after privilege columns. */
+ Field* ssl_type() const
+ { return get_field(start_privilege_column + num_privileges()); }
+ Field* ssl_cipher() const
+ { return get_field(start_privilege_column + num_privileges() + 1); }
+ Field* x509_issuer() const
+ { return get_field(start_privilege_column + num_privileges() + 2); }
+ Field* x509_subject() const
+ { return get_field(start_privilege_column + num_privileges() + 3); }
+ Field* max_questions() const
+ { return get_field(start_privilege_column + num_privileges() + 4); }
+ Field* max_updates() const
+ { return get_field(start_privilege_column + num_privileges() + 5); }
+ Field* max_connections() const
+ { return get_field(start_privilege_column + num_privileges() + 6); }
+ Field* max_user_connections() const
+ { return get_field(start_privilege_column + num_privileges() + 7); }
+ Field* plugin() const
+ { return get_field(start_privilege_column + num_privileges() + 8); }
+ Field* authentication_string() const
+ { return get_field(start_privilege_column + num_privileges() + 9); }
+ Field* password_expired() const
+ { return get_field(start_privilege_column + num_privileges() + 10); }
+ Field* is_role() const
+ { return get_field(start_privilege_column + num_privileges() + 11); }
+ Field* default_role() const
+ { return get_field(start_privilege_column + num_privileges() + 12); }
+ Field* max_statement_time() const
+ { return get_field(start_privilege_column + num_privileges() + 13); }
+
+ /*
+ Check if a user entry in the user table is marked as being a role entry
+
+ IMPLEMENTATION
+ Access the coresponding column and check the coresponding ENUM of the form
+ ENUM('N', 'Y')
+
+ SYNOPSIS
+ check_is_role()
+ form an open table to read the entry from.
+ The record should be already read in table->record[0]
+
+ RETURN VALUE
+ TRUE if the user is marked as a role
+ FALSE otherwise
+ */
+ bool check_is_role() const
+ {
+ /* Table version does not support roles */
+ if (!is_role())
+ return false;
+
+ return get_YN_as_bool(is_role());
+ }
+
-const LEX_STRING acl_table_names[]= // matches enum_acl_tables
+ private:
+ friend class Grant_tables;
+
+ /* Only Grant_tables can instantiate this class. */
+ User_table() {};
+
+ void init(enum thr_lock_type lock_type)
+ {
+ /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */
+ tl.init_one_table(C_STRING_WITH_LEN("mysql"),
+ C_STRING_WITH_LEN("user"),
+ NULL, lock_type);
+ Grant_table_base::init(lock_type, false);
+ }
+
+ /* The user table is a bit different compared to the other Grant tables.
+ Usually, we only add columns to the grant tables when adding functionality.
+ This makes it easy to test which version of the table we are using, by
+ just looking at the number of fields present in the table.
+
+ In MySQL 5.7.6 the Password column was removed. We need to guard for that.
+ The field-fetching methods for the User table return NULL if the field
+ doesn't exist. This simplifies checking of table "version", as we don't
+ have to make use of num_fields() any more.
+ */
+ inline Field* get_field(uint field_num) const
+ {
+ if (field_num >= num_fields())
+ return NULL;
+
+ return tl.table->field[field_num];
+ }
+
+ /* Normally password column is the third column in the table. If privileges
+ start on the third column instead, we are missing the password column.
+ This means we are using a MySQL 5.7.6+ data directory. */
+ bool have_password() const { return start_privilege_column == 2; }
+
+};
+
+class Db_table: public Grant_table_base
{
- { C_STRING_WITH_LEN("user") },
- { C_STRING_WITH_LEN("db") },
- { C_STRING_WITH_LEN("tables_priv") },
- { C_STRING_WITH_LEN("columns_priv") },
- { C_STRING_WITH_LEN("host") },
- { C_STRING_WITH_LEN("procs_priv") },
- { C_STRING_WITH_LEN("proxies_priv") },
- { C_STRING_WITH_LEN("roles_mapping") }
+ public:
+ Field* host() const { return tl.table->field[0]; }
+ Field* db() const { return tl.table->field[1]; }
+ Field* user() const { return tl.table->field[2]; }
+
+ private:
+ friend class Grant_tables;
+
+ Db_table() {};
+
+ void init(enum thr_lock_type lock_type)
+ {
+ /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */
+ tl.init_one_table(C_STRING_WITH_LEN("mysql"),
+ C_STRING_WITH_LEN("db"),
+ NULL, lock_type);
+ Grant_table_base::init(lock_type, false);
+ }
};
-/** check if the table was opened, issue an error otherwise */
-static int no_such_table(TABLE_LIST *tl)
+class Tables_priv_table: public Grant_table_base
{
- if (tl->table)
- return 0;
+ public:
+ Field* host() const { return tl.table->field[0]; }
+ Field* db() const { return tl.table->field[1]; }
+ Field* user() const { return tl.table->field[2]; }
+ Field* table_name() const { return tl.table->field[3]; }
+ Field* grantor() const { return tl.table->field[4]; }
+ Field* timestamp() const { return tl.table->field[5]; }
+ Field* table_priv() const { return tl.table->field[6]; }
+ Field* column_priv() const { return tl.table->field[7]; }
- my_error(ER_NO_SUCH_TABLE, MYF(0), tl->db, tl->alias);
- return 1;
+ private:
+ friend class Grant_tables;
+
+ Tables_priv_table() {};
+
+ void init(enum thr_lock_type lock_type, Grant_table_base *next_table= NULL)
+ {
+ /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */
+ tl.init_one_table(C_STRING_WITH_LEN("mysql"),
+ C_STRING_WITH_LEN("tables_priv"),
+ NULL, lock_type);
+ Grant_table_base::init(lock_type, false);
+ }
+};
+
+class Columns_priv_table: public Grant_table_base
+{
+ public:
+ Field* host() const { return tl.table->field[0]; }
+ Field* db() const { return tl.table->field[1]; }
+ Field* user() const { return tl.table->field[2]; }
+ Field* table_name() const { return tl.table->field[3]; }
+ Field* column_name() const { return tl.table->field[4]; }
+ Field* timestamp() const { return tl.table->field[5]; }
+ Field* column_priv() const { return tl.table->field[6]; }
+
+ private:
+ friend class Grant_tables;
+
+ Columns_priv_table() {};
+
+ void init(enum thr_lock_type lock_type)
+ {
+ /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */
+ tl.init_one_table(C_STRING_WITH_LEN("mysql"),
+ C_STRING_WITH_LEN("columns_priv"),
+ NULL, lock_type);
+ Grant_table_base::init(lock_type, false);
+ }
+};
+
+class Host_table: public Grant_table_base
+{
+ public:
+ Field* host() const { return tl.table->field[0]; }
+ Field* db() const { return tl.table->field[1]; }
+
+ private:
+ friend class Grant_tables;
+
+ Host_table() {}
+
+ void init(enum thr_lock_type lock_type)
+ {
+ /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */
+ tl.init_one_table(C_STRING_WITH_LEN("mysql"),
+ C_STRING_WITH_LEN("host"),
+ NULL, lock_type);
+ Grant_table_base::init(lock_type, true);
+ }
+};
+
+class Procs_priv_table: public Grant_table_base
+{
+ public:
+ Field* host() const { return tl.table->field[0]; }
+ Field* db() const { return tl.table->field[1]; }
+ Field* user() const { return tl.table->field[2]; }
+ Field* routine_name() const { return tl.table->field[3]; }
+ Field* routine_type() const { return tl.table->field[4]; }
+ Field* grantor() const { return tl.table->field[5]; }
+ Field* proc_priv() const { return tl.table->field[6]; }
+ Field* timestamp() const { return tl.table->field[7]; }
+
+ private:
+ friend class Grant_tables;
+
+ Procs_priv_table() {}
+
+ void init(enum thr_lock_type lock_type)
+ {
+ /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */
+ tl.init_one_table(C_STRING_WITH_LEN("mysql"),
+ C_STRING_WITH_LEN("procs_priv"),
+ NULL, lock_type);
+ Grant_table_base::init(lock_type, true);
+ }
+};
+
+class Proxies_priv_table: public Grant_table_base
+{
+ public:
+ Field* host() const { return tl.table->field[0]; }
+ Field* user() const { return tl.table->field[1]; }
+ Field* proxied_host() const { return tl.table->field[2]; }
+ Field* proxied_user() const { return tl.table->field[3]; }
+ Field* with_grant() const { return tl.table->field[4]; }
+ Field* grantor() const { return tl.table->field[5]; }
+ Field* timestamp() const { return tl.table->field[6]; }
+
+ private:
+ friend class Grant_tables;
+
+ Proxies_priv_table() {}
+
+ void init(enum thr_lock_type lock_type)
+ {
+ /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */
+ tl.init_one_table(C_STRING_WITH_LEN("mysql"),
+ C_STRING_WITH_LEN("proxies_priv"),
+ NULL, lock_type);
+ Grant_table_base::init(lock_type, true);
+ }
+};
+
+class Roles_mapping_table: public Grant_table_base
+{
+ public:
+ Field* host() const { return tl.table->field[0]; }
+ Field* user() const { return tl.table->field[1]; }
+ Field* role() const { return tl.table->field[2]; }
+ Field* admin_option() const { return tl.table->field[3]; }
+
+ private:
+ friend class Grant_tables;
+
+ Roles_mapping_table() {}
+
+ void init(enum thr_lock_type lock_type)
+ {
+ /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */
+ tl.init_one_table(C_STRING_WITH_LEN("mysql"),
+ C_STRING_WITH_LEN("roles_mapping"),
+ NULL, lock_type);
+ Grant_table_base::init(lock_type, true);
+ }
+};
+
+/**
+ Class that represents a collection of grant tables.
+*/
+class Grant_tables
+{
+ public:
+ /* When constructing the Grant_tables object, we initialize only
+ the tables which are going to be opened.
+ @param which_tables Bitmap of which tables to open.
+ @param lock_type Lock type to use when opening tables.
+ */
+ Grant_tables(int which_tables, enum thr_lock_type lock_type)
+ {
+ DBUG_ENTER("Grant_tables::Grant_tables");
+ DBUG_PRINT("info", ("which_tables: %x, lock_type: %u",
+ which_tables, lock_type));
+ DBUG_ASSERT(which_tables); /* At least one table must be opened. */
+ Grant_table_base* prev= NULL;
+ /* We start from the last table, Table_roles_mapping, such that
+ the first one in the linked list is Table_user. */
+ if (which_tables & Table_roles_mapping)
+ {
+ m_roles_mapping_table.init(lock_type);
+ prev= &m_roles_mapping_table;
+ }
+ if (which_tables & Table_proxies_priv)
+ {
+ m_proxies_priv_table.init(lock_type);
+ link_tables(&m_proxies_priv_table, prev);
+ prev= &m_proxies_priv_table;
+ }
+ if (which_tables & Table_procs_priv)
+ {
+ m_procs_priv_table.init(lock_type);
+ link_tables(&m_procs_priv_table, prev);
+ prev= &m_procs_priv_table;
+ }
+ if (which_tables & Table_host)
+ {
+ m_host_table.init(lock_type);
+ link_tables(&m_host_table, prev);
+ prev= &m_host_table;
+ }
+ if (which_tables & Table_columns_priv)
+ {
+ m_columns_priv_table.init(lock_type);
+ link_tables(&m_columns_priv_table, prev);
+ prev= &m_columns_priv_table;
+ }
+ if (which_tables & Table_tables_priv)
+ {
+ m_tables_priv_table.init(lock_type);
+ link_tables(&m_tables_priv_table, prev);
+ prev= &m_tables_priv_table;
+ }
+ if (which_tables & Table_db)
+ {
+ m_db_table.init(lock_type);
+ link_tables(&m_db_table, prev);
+ prev= &m_db_table;
+ }
+ if (which_tables & Table_user)
+ {
+ m_user_table.init(lock_type);
+ link_tables(&m_user_table, prev);
+ prev= &m_user_table;
+ }
+
+ first_table_in_list= prev;
+ DBUG_VOID_RETURN;
+ }
+
+ /* Before any operation is possible on grant tables, they must be opened.
+ This opens the tables according to the lock type specified during
+ construction.
+
+ @retval 1 replication filters matched. Abort the operation,
+ but return OK (!)
+ @retval 0 tables were opened successfully
+ @retval -1 error, tables could not be opened
+ */
+ int open_and_lock(THD *thd)
+ {
+ DBUG_ENTER("Grant_tables::open_and_lock");
+ DBUG_ASSERT(first_table_in_list);
+#ifdef HAVE_REPLICATION
+ if (first_table_in_list->tl.lock_type >= TL_WRITE_ALLOW_WRITE &&
+ thd->slave_thread && !thd->spcont)
+ {
+ /*
+ GRANT and REVOKE are applied the slave in/exclusion rules as they are
+ some kind of updates to the mysql.% tables.
+ */
+ Rpl_filter *rpl_filter= thd->system_thread_info.rpl_sql_info->rpl_filter;
+ if (rpl_filter->is_on() &&
+ !rpl_filter->tables_ok(0, &first_table_in_list->tl))
+ DBUG_RETURN(1);
+ }
+#endif
+ if (open_and_lock_tables(thd, &first_table_in_list->tl, FALSE,
+ MYSQL_LOCK_IGNORE_TIMEOUT))
+ DBUG_RETURN(-1);
+
+ /*
+ We can read privilege tables even when !initialized.
+ This can be acl_load() - server startup or FLUSH PRIVILEGES
+ */
+ if (first_table_in_list->tl.lock_type >= TL_WRITE_ALLOW_WRITE &&
+ !initialized)
+ {
+ my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables");
+ DBUG_RETURN(-1);
+ }
+
+ /* The privilge columns vary based on MariaDB version. Figure out
+ how many we have after we've opened the table. */
+ m_user_table.compute_num_privilege_cols();
+ m_db_table.compute_num_privilege_cols();
+ m_tables_priv_table.compute_num_privilege_cols();
+ m_columns_priv_table.compute_num_privilege_cols();
+ m_host_table.compute_num_privilege_cols();
+ m_procs_priv_table.compute_num_privilege_cols();
+ m_proxies_priv_table.compute_num_privilege_cols();
+ m_roles_mapping_table.compute_num_privilege_cols();
+ DBUG_RETURN(0);
+ }
+
+ inline const User_table& user_table() const
+ {
+ return m_user_table;
+ }
+
+ inline const Db_table& db_table() const
+ {
+ return m_db_table;
+ }
+
+
+ inline const Tables_priv_table& tables_priv_table() const
+ {
+ return m_tables_priv_table;
+ }
+
+ inline const Columns_priv_table& columns_priv_table() const
+ {
+ return m_columns_priv_table;
+ }
+
+ inline const Host_table& host_table() const
+ {
+ return m_host_table;
+ }
+
+ inline const Procs_priv_table& procs_priv_table() const
+ {
+ return m_procs_priv_table;
+ }
+
+ inline const Proxies_priv_table& proxies_priv_table() const
+ {
+ return m_proxies_priv_table;
+ }
+
+ inline const Roles_mapping_table& roles_mapping_table() const
+ {
+ return m_roles_mapping_table;
+ }
+
+ private:
+ User_table m_user_table;
+ Db_table m_db_table;
+ Tables_priv_table m_tables_priv_table;
+ Columns_priv_table m_columns_priv_table;
+ Host_table m_host_table;
+ Procs_priv_table m_procs_priv_table;
+ Proxies_priv_table m_proxies_priv_table;
+ Roles_mapping_table m_roles_mapping_table;
+
+ /* The grant tables are set-up in a linked list. We keep the head of it. */
+ Grant_table_base *first_table_in_list;
+ /**
+ Chain two grant tables' TABLE_LIST members.
+ */
+ static void link_tables(Grant_table_base *from, Grant_table_base *to)
+ {
+ DBUG_ASSERT(from);
+ if (to)
+ from->tl.next_local= from->tl.next_global= &to->tl;
+ else
+ from->tl.next_local= from->tl.next_global= NULL;
+ }
+};
+
+
+void ACL_PROXY_USER::init(const Proxies_priv_table& proxies_priv_table,
+ MEM_ROOT *mem)
+{
+ init(get_field(mem, proxies_priv_table.host()),
+ get_field(mem, proxies_priv_table.user()),
+ get_field(mem, proxies_priv_table.proxied_host()),
+ get_field(mem, proxies_priv_table.proxied_user()),
+ proxies_priv_table.with_grant()->val_int() != 0);
}
+
+
/*
Enumeration of various ACL's and Hashes used in handle_grant_struct()
*/
@@@ -1871,56 -1266,61 +1870,62 @@@ static bool acl_load(THD *thd, const Gr
}
freeze_size(&acl_hosts);
- if (init_read_record(&read_record_info, thd, table=tables[USER_TABLE].table,
- NULL, 1, 1, FALSE))
- goto end;
- table->use_all_columns();
+ const User_table& user_table= tables.user_table();
+ if (user_table.init_read_record(&read_record_info, thd))
+ DBUG_RETURN(true);
- if (table->s->fields < 13) // number of columns in 3.21
++ if (user_table.num_fields() < 13) // number of columns in 3.21
+ {
+ sql_print_error("Fatal error: mysql.user table is damaged or in "
+ "unsupported 3.20 format.");
- goto end;
++ DBUG_RETURN(true);
+ }
-
- username_char_length= MY_MIN(table->field[1]->char_length(),
+ username_char_length= MY_MIN(user_table.user()->char_length(),
USERNAME_CHAR_LENGTH);
- password_length= table->field[2]->field_length /
- table->field[2]->charset()->mbmaxlen;
- if (password_length < SCRAMBLED_PASSWORD_CHAR_LENGTH_323)
+ if (user_table.password()) // Password column might be missing. (MySQL 5.7.6+)
{
- sql_print_error("Fatal error: mysql.user table is damaged or in "
- "unsupported 3.20 format.");
- goto end;
- }
+ password_length= user_table.password()->field_length /
+ user_table.password()->charset()->mbmaxlen;
+ if (password_length < SCRAMBLED_PASSWORD_CHAR_LENGTH_323)
+ {
+ sql_print_error("Fatal error: mysql.user table is damaged or in "
+ "unsupported 3.20 format.");
+ DBUG_RETURN(TRUE);
+ }
- DBUG_PRINT("info",("user table fields: %d, password length: %d",
- table->s->fields, password_length));
+ DBUG_PRINT("info",("user table fields: %d, password length: %d",
+ user_table.num_fields(), password_length));
- mysql_mutex_lock(&LOCK_global_system_variables);
- if (password_length < SCRAMBLED_PASSWORD_CHAR_LENGTH)
- {
- if (opt_secure_auth)
+ mysql_mutex_lock(&LOCK_global_system_variables);
+ if (password_length < SCRAMBLED_PASSWORD_CHAR_LENGTH)
{
- mysql_mutex_unlock(&LOCK_global_system_variables);
- sql_print_error("Fatal error: mysql.user table is in old format, "
- "but server started with --secure-auth option.");
- goto end;
+ if (opt_secure_auth)
+ {
+ mysql_mutex_unlock(&LOCK_global_system_variables);
+ sql_print_error("Fatal error: mysql.user table is in old format, "
+ "but server started with --secure-auth option.");
+ DBUG_RETURN(TRUE);
+ }
+ mysql_user_table_is_in_short_password_format= true;
+ if (global_system_variables.old_passwords)
+ mysql_mutex_unlock(&LOCK_global_system_variables);
+ else
+ {
+ extern sys_var *Sys_old_passwords_ptr;
+ Sys_old_passwords_ptr->value_origin= sys_var::AUTO;
+ global_system_variables.old_passwords= 1;
+ mysql_mutex_unlock(&LOCK_global_system_variables);
+ sql_print_warning("mysql.user table is not updated to new password format; "
+ "Disabling new password usage until "
+ "mysql_fix_privilege_tables is run");
+ }
+ thd->variables.old_passwords= 1;
}
- mysql_user_table_is_in_short_password_format= true;
- if (global_system_variables.old_passwords)
- mysql_mutex_unlock(&LOCK_global_system_variables);
else
{
- extern sys_var *Sys_old_passwords_ptr;
- Sys_old_passwords_ptr->value_origin= sys_var::AUTO;
- global_system_variables.old_passwords= 1;
+ mysql_user_table_is_in_short_password_format= false;
mysql_mutex_unlock(&LOCK_global_system_variables);
- sql_print_warning("mysql.user table is not updated to new password format; "
- "Disabling new password usage until "
- "mysql_fix_privilege_tables is run");
}
- thd->variables.old_passwords= 1;
- }
- else
- {
- mysql_user_table_is_in_short_password_format= false;
- mysql_mutex_unlock(&LOCK_global_system_variables);
}
allow_all_hosts=0;
diff --cc sql/sql_class.cc
index 1c29e3d18a7,6fa8c100894..142088faea4
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@@ -840,11 -983,10 +840,12 @@@ THD::THD(my_thread_id id, bool is_wsrep
memset(&invoker_host, 0, sizeof(invoker_host));
prepare_derived_at_open= FALSE;
create_tmp_table_for_derived= FALSE;
+ force_read_stats= FALSE;
save_prep_leaf_list= FALSE;
+ org_charset= 0;
/* Restore THR_THD */
set_current_thd(old_THR_THD);
+ inc_thread_count();
}
diff --cc sql/sql_class.h
index 38e55f9c4a9,c0dc42deefe..9c968abf25c
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@@ -37,7 -36,7 +37,8 @@@
#include "violite.h" /* vio_is_connected */
#include "thr_lock.h" /* thr_lock_type, THR_LOCK_DATA, THR_LOCK_INFO */
#include "thr_timer.h"
+#include "thr_malloc.h"
+ #include <my_tree.h>
#include "sql_digest_stream.h" // sql_digest_state
diff --cc sql/sql_db.cc
index 0e554e29380,7b83332ea62..ebc04decbb3
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@@ -1616,10 -1610,7 +1616,10 @@@ uint mysql_change_db(THD *thd, const LE
mysql_change_db_impl(thd, &new_db_file_name, db_access, db_default_cl);
+done:
+ SESSION_TRACKER_CHANGED(thd, CURRENT_SCHEMA_TRACKER, NULL);
+ SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL);
- DBUG_RETURN(FALSE);
+ DBUG_RETURN(0);
}
diff --cc sql/sql_lex.h
index 2af1d527cd3,845e1242eb7..a880b6e4283
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@@ -547,21 -543,8 +547,21 @@@ public
List<Index_hint> *hints= 0,
List<String> *partition_names= 0,
LEX_STRING *option= 0);
- virtual void set_lock_for_tables(thr_lock_type lock_type) {}
+ virtual void set_lock_for_tables(thr_lock_type lock_type, bool for_update) {}
-
+ void set_slave(st_select_lex_node *slave_arg) { slave= slave_arg; }
+ void move_node(st_select_lex_node *where_to_move)
+ {
+ if (where_to_move == this)
+ return;
+ if (next)
+ next->prev= prev;
+ *prev= next;
+ *where_to_move->prev= this;
+ next= where_to_move;
+ }
+ st_select_lex_node *insert_chain_before(st_select_lex_node **ptr_pos_to_insert,
+ st_select_lex_node *end_chain_node);
+ void move_as_slave(st_select_lex_node *new_master);
friend class st_select_lex_unit;
friend bool mysql_new_select(LEX *lex, bool move_down);
friend bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
diff --cc sql/sql_select.cc
index bcbe4597aff,eb9e0492dc7..5e0472b4224
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@@ -16486,15 -16301,7 +16493,8 @@@ Field *create_tmp_field(THD *thd, TABL
case Item::NULL_ITEM:
case Item::VARBIN_ITEM:
case Item::CACHE_ITEM:
+ case Item::WINDOW_FUNC_ITEM: // psergey-winfunc:
- case Item::EXPR_CACHE_ITEM:
case Item::PARAM_ITEM:
- if (make_copy_field)
- {
- DBUG_ASSERT(((Item_result_field*)item)->result_field);
- *from_field= ((Item_result_field*)item)->result_field;
- }
return create_tmp_field_from_item(thd, item, table,
(make_copy_field ? 0 : copy_func),
modify_item);
diff --cc sql/sql_show.cc
index c84ac5f4977,d8b35eda089..56103d8b654
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@@ -4398,19 -4272,15 +4398,16 @@@ fill_schema_table_by_open(THD *thd, boo
SQLCOM_SHOW_FIELDS is used because it satisfies
'only_view_structure()'.
*/
- lex->sql_command= SQLCOM_SHOW_FIELDS;
thd->force_read_stats= get_schema_table_idx(schema_table) == SCH_STATISTICS;
+ lex->sql_command= SQLCOM_SHOW_FIELDS;
- result= (open_temporary_tables(thd, table_list) ||
+ result= (thd->open_temporary_tables(table_list) ||
open_normal_and_derived_tables(thd, table_list,
(MYSQL_OPEN_IGNORE_FLUSH |
MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL |
(can_deadlock ?
MYSQL_OPEN_FAIL_ON_MDL_CONFLICT : 0)),
- DT_PREPARE | DT_CREATE));
+ DT_INIT | DT_PREPARE | DT_CREATE));
+
- (void) read_statistics_for_tables_if_needed(thd, table_list);
- thd->force_read_stats= false;
-
/*
Restore old value of sql_command back as it is being looked at in
process_table() function.
diff --cc storage/innobase/dict/dict0stats.cc
index d6d7845b2c3,06364689173..6dd3c9c930f
--- a/storage/innobase/dict/dict0stats.cc
+++ b/storage/innobase/dict/dict0stats.cc
@@@ -1,7 -1,7 +1,7 @@@
/*****************************************************************************
- Copyright (c) 2009, 2018, Oracle and/or its affiliates. All Rights Reserved.
+ Copyright (c) 2009, 2019, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2015, 2017, MariaDB Corporation.
+Copyright (c) 2015, 2018, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
diff --cc storage/innobase/handler/handler0alter.cc
index 005c0fd5adf,0d0982fa498..f470ac3ca4c
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@@ -104,170 -98,10 +104,187 @@@ static const Alter_inplace_info::HA_ALT
| INNOBASE_FOREIGN_OPERATIONS
| Alter_inplace_info::DROP_INDEX
| Alter_inplace_info::DROP_UNIQUE_INDEX
- | Alter_inplace_info::ALTER_COLUMN_NAME;
+ | Alter_inplace_info::ALTER_COLUMN_NAME
+ | Alter_inplace_info::ALTER_COLUMN_EQUAL_PACK_LENGTH
+ //| Alter_inplace_info::ALTER_INDEX_COMMENT
+ | Alter_inplace_info::ADD_VIRTUAL_COLUMN
+ | Alter_inplace_info::DROP_VIRTUAL_COLUMN
+ | Alter_inplace_info::ALTER_VIRTUAL_COLUMN_ORDER;
+
+struct ha_innobase_inplace_ctx : public inplace_alter_handler_ctx
+{
+ /** Dummy query graph */
+ que_thr_t* thr;
+ /** The prebuilt struct of the creating instance */
+ row_prebuilt_t*& prebuilt;
+ /** InnoDB indexes being created */
+ dict_index_t** add_index;
+ /** MySQL key numbers for the InnoDB indexes that are being created */
+ const ulint* add_key_numbers;
+ /** number of InnoDB indexes being created */
+ ulint num_to_add_index;
+ /** InnoDB indexes being dropped */
+ dict_index_t** drop_index;
+ /** number of InnoDB indexes being dropped */
+ const ulint num_to_drop_index;
+ /** InnoDB indexes being renamed */
+ dict_index_t** rename;
+ /** number of InnoDB indexes being renamed */
+ const ulint num_to_rename;
+ /** InnoDB foreign key constraints being dropped */
+ dict_foreign_t** drop_fk;
+ /** number of InnoDB foreign key constraints being dropped */
+ const ulint num_to_drop_fk;
+ /** InnoDB foreign key constraints being added */
+ dict_foreign_t** add_fk;
+ /** number of InnoDB foreign key constraints being dropped */
+ const ulint num_to_add_fk;
+ /** whether to create the indexes online */
+ bool online;
+ /** memory heap */
+ mem_heap_t* heap;
+ /** dictionary transaction */
+ trx_t* trx;
+ /** original table (if rebuilt, differs from indexed_table) */
+ dict_table_t* old_table;
+ /** table where the indexes are being created or dropped */
+ dict_table_t* new_table;
+ /** mapping of old column numbers to new ones, or NULL */
+ const ulint* col_map;
+ /** new column names, or NULL if nothing was renamed */
+ const char** col_names;
+ /** added AUTO_INCREMENT column position, or ULINT_UNDEFINED */
+ const ulint add_autoinc;
+ /** default values of ADD COLUMN, or NULL */
+ const dtuple_t* add_cols;
+ /** autoinc sequence to use */
+ ib_sequence_t sequence;
+ /** temporary table name to use for old table when renaming tables */
+ const char* tmp_name;
+ /** whether the order of the clustered index is unchanged */
+ bool skip_pk_sort;
+ /** number of virtual columns to be added */
+ ulint num_to_add_vcol;
+ /** virtual columns to be added */
+ dict_v_col_t* add_vcol;
+ const char** add_vcol_name;
+ /** number of virtual columns to be dropped */
+ ulint num_to_drop_vcol;
+ /** virtual columns to be dropped */
+ dict_v_col_t* drop_vcol;
+ const char** drop_vcol_name;
+ /** ALTER TABLE stage progress recorder */
+ ut_stage_alter_t* m_stage;
+
+ ha_innobase_inplace_ctx(row_prebuilt_t*& prebuilt_arg,
+ dict_index_t** drop_arg,
+ ulint num_to_drop_arg,
+ dict_index_t** rename_arg,
+ ulint num_to_rename_arg,
+ dict_foreign_t** drop_fk_arg,
+ ulint num_to_drop_fk_arg,
+ dict_foreign_t** add_fk_arg,
+ ulint num_to_add_fk_arg,
+ bool online_arg,
+ mem_heap_t* heap_arg,
+ dict_table_t* new_table_arg,
+ const char** col_names_arg,
+ ulint add_autoinc_arg,
+ ulonglong autoinc_col_min_value_arg,
+ ulonglong autoinc_col_max_value_arg,
+ ulint num_to_drop_vcol_arg) :
+ inplace_alter_handler_ctx(),
+ prebuilt (prebuilt_arg),
+ add_index (0), add_key_numbers (0), num_to_add_index (0),
+ drop_index (drop_arg), num_to_drop_index (num_to_drop_arg),
+ rename (rename_arg), num_to_rename (num_to_rename_arg),
+ drop_fk (drop_fk_arg), num_to_drop_fk (num_to_drop_fk_arg),
+ add_fk (add_fk_arg), num_to_add_fk (num_to_add_fk_arg),
+ online (online_arg), heap (heap_arg), trx (0),
+ old_table (prebuilt_arg->table),
+ new_table (new_table_arg),
+ col_map (0), col_names (col_names_arg),
+ add_autoinc (add_autoinc_arg),
+ add_cols (0),
+ sequence(prebuilt->trx->mysql_thd,
+ autoinc_col_min_value_arg, autoinc_col_max_value_arg),
+ tmp_name (0),
+ skip_pk_sort(false),
+ num_to_add_vcol(0),
+ add_vcol(0),
+ add_vcol_name(0),
+ num_to_drop_vcol(0),
+ drop_vcol(0),
+ drop_vcol_name(0),
+ m_stage(NULL)
+ {
+#ifdef UNIV_DEBUG
+ for (ulint i = 0; i < num_to_add_index; i++) {
+ ut_ad(!add_index[i]->to_be_dropped);
+ }
+ for (ulint i = 0; i < num_to_drop_index; i++) {
+ ut_ad(drop_index[i]->to_be_dropped);
+ }
+#endif /* UNIV_DEBUG */
+
+ thr = pars_complete_graph_for_exec(NULL, prebuilt->trx, heap,
+ prebuilt);
+ }
+
+ ~ha_innobase_inplace_ctx()
+ {
+ UT_DELETE(m_stage);
+ mem_heap_free(heap);
+ }
+
+ /** Determine if the table will be rebuilt.
+ @return whether the table will be rebuilt */
+ bool need_rebuild () const { return(old_table != new_table); }
+
+ /** Clear uncommmitted added indexes after a failed operation. */
+ void clear_added_indexes()
+ {
+ for (ulint i = 0; i < num_to_add_index; i++) {
+ if (!add_index[i]->is_committed()) {
+ add_index[i]->detach_columns();
+ }
+ }
+ }
+
++ /** Share context between partitions.
++ @param[in] ctx context from another partition of the table */
++ void set_shared_data(const inplace_alter_handler_ctx& ctx)
++ {
++ if (add_autoinc != ULINT_UNDEFINED) {
++ const ha_innobase_inplace_ctx& ha_ctx =
++ static_cast<const ha_innobase_inplace_ctx&>
++ (ctx);
++ /* When adding an AUTO_INCREMENT column to a
++ partitioned InnoDB table, we must share the
++ sequence for all partitions. */
++ ut_ad(ha_ctx.add_autoinc == add_autoinc);
++ ut_ad(ha_ctx.sequence.last());
++ sequence = ha_ctx.sequence;
++ }
++ }
++
+private:
+ // Disable copying
+ ha_innobase_inplace_ctx(const ha_innobase_inplace_ctx&);
+ ha_innobase_inplace_ctx& operator=(const ha_innobase_inplace_ctx&);
+};
+
+/********************************************************************//**
+Get the upper limit of the MySQL integral and floating-point type.
+@return maximum allowed value for the field */
+UNIV_INTERN
+ulonglong
+innobase_get_int_col_max_value(
+/*===========================*/
+ const Field* field); /*!< in: MySQL field */
/* Report an InnoDB error to the client by invoking my_error(). */
-static UNIV_COLD MY_ATTRIBUTE((nonnull))
+static ATTRIBUTE_COLD __attribute__((nonnull))
void
my_error_innodb(
/*============*/
diff --cc storage/tokudb/mysql-test/rpl/r/rpl_tokudb_mixed_dml.result
index 65057791b48,c71dcadc32f..5f41fd328c9
--- a/storage/tokudb/mysql-test/rpl/r/rpl_tokudb_mixed_dml.result
+++ b/storage/tokudb/mysql-test/rpl/r/rpl_tokudb_mixed_dml.result
@@@ -682,6 -681,9 +682,8 @@@ DROP TRIGGER tr1
GRANT EVENT ON *.* TO 'root'@'localhost';
INSERT INTO t1 VALUES(1, 'test1');
CREATE EVENT e1 ON SCHEDULE EVERY '1' SECOND COMMENT 'e_second_comment' DO DELETE FROM t1;
+ Warnings:
+ Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
-==========MASTER==========
SHOW EVENTS;
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
test_rpl e1 root@localhost SYSTEM RECURRING NULL 1 # # NULL ENABLED 1 latin1 latin1_swedish_ci latin1_swedish_ci
diff --cc storage/tokudb/mysql-test/tokudb_bugs/r/PS-5163.result
index 00000000000,a203787f11d..27e19150945
mode 000000,100644..100644
--- a/storage/tokudb/mysql-test/tokudb_bugs/r/PS-5163.result
+++ b/storage/tokudb/mysql-test/tokudb_bugs/r/PS-5163.result
@@@ -1,0 -1,5 +1,5 @@@
-CREATE TABLE t1(c1 INT,c2 INT,c3 CHAR(10),c4 CHAR(10),c5 CHAR(10),PRIMARY KEY(c1),INDEX(c3,c4(1),c5(1)),INDEX(c2)) ENGINE=TokuDB;
++CREATE TABLE t1(c1 INT default 0,c2 INT,c3 CHAR(10),c4 CHAR(10),c5 CHAR(10),PRIMARY KEY(c1),INDEX(c3,c4(1),c5(1)),INDEX(c2)) ENGINE=TokuDB;
+ INSERT INTO t1 VALUES(),(),(),(),();
+ ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
+ UPDATE t1 SET c1=1 WHERE c1=1 OR c2=1;
+ DROP TABLE t1;
diff --cc storage/tokudb/mysql-test/tokudb_bugs/t/PS-5163.test
index 00000000000,5fc01bb5f0e..d370bab6517
mode 000000,100644..100644
--- a/storage/tokudb/mysql-test/tokudb_bugs/t/PS-5163.test
+++ b/storage/tokudb/mysql-test/tokudb_bugs/t/PS-5163.test
@@@ -1,0 -1,11 +1,11 @@@
+ --source include/have_tokudb.inc
+
-CREATE TABLE t1(c1 INT,c2 INT,c3 CHAR(10),c4 CHAR(10),c5 CHAR(10),PRIMARY KEY(c1),INDEX(c3,c4(1),c5(1)),INDEX(c2)) ENGINE=TokuDB;
++CREATE TABLE t1(c1 INT default 0,c2 INT,c3 CHAR(10),c4 CHAR(10),c5 CHAR(10),PRIMARY KEY(c1),INDEX(c3,c4(1),c5(1)),INDEX(c2)) ENGINE=TokuDB;
+ --error ER_DUP_ENTRY
+ INSERT INTO t1 VALUES(),(),(),(),();
+
+ # 8.0 asserts here down in data dictionary because ha_tokudb::ds_mrr did not
+ # properly call ds_mrr.init(this, table)
+ UPDATE t1 SET c1=1 WHERE c1=1 OR c2=1;
+
+ DROP TABLE t1;
diff --cc support-files/rpm/server-posttrans.sh
index 0d242596185,00000000000..1406c78a5f5
mode 100644,000000..100644
--- a/support-files/rpm/server-posttrans.sh
+++ b/support-files/rpm/server-posttrans.sh
@@@ -1,11 -1,0 +1,10 @@@
+if [ -r %{restart_flag} ] ; then
+ rm %{restart_flag}
+ if [ -x /usr/bin/systemctl ] ; then
+ /usr/bin/systemctl daemon-reload > /dev/null 2>&1
- fi
-
- # only restart the server if it was alredy running
- if %{_sysconfdir}/init.d/mysql status > /dev/null 2>&1; then
++ /usr/bin/systemctl try-restart mariadb.service > /dev/null 2>&1
++ elif %{_sysconfdir}/init.d/mysql status > /dev/null 2>&1; then
++ # only restart the server if it was alredy running
+ %{_sysconfdir}/init.d/mysql restart
+ fi
+fi
1
0
[Commits] 386a759efe5: MDEV-13275:Query optimizer not picking optimal ORDER BY PRIMARY in case of INNER JOIN
by Varun 03 May '19
by Varun 03 May '19
03 May '19
revision-id: 386a759efe552519fb6a4f9acc6f630b2872316e (mariadb-10.2.23-109-g386a759efe5)
parent(s): d61d88a34f6c1444a9d472c4d1aa83cce93e69fc
author: Varun Gupta
committer: Varun Gupta
timestamp: 2019-05-04 03:17:09 +0530
message:
MDEV-13275:Query optimizer not picking optimal ORDER BY PRIMARY in case of INNER JOIN
on PRIMARY like it does for similar WHERE condition
Currently the code for the optimization orderby_uses_equalities takes into account full substitution so this
blocks cases where we have [VAR]char with insensitive comparisions('A'='a') and padding('A'='A ')
The solutuion would be to allow substitution for the purpose of comparison for order by
because order by only needs the sorting columns for comparision.
---
mysql-test/r/order_by.result | 97 ++++++++++++++++++++++++++++++++++++++++++++
mysql-test/t/order_by.test | 20 +++++++++
sql/item.cc | 7 ++++
sql/item.h | 1 +
sql/sql_select.cc | 20 ++++++---
5 files changed, 139 insertions(+), 6 deletions(-)
diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result
index 28b63dab22e..1a4e1b094bf 100644
--- a/mysql-test/r/order_by.result
+++ b/mysql-test/r/order_by.result
@@ -3266,3 +3266,100 @@ NULLIF(GROUP_CONCAT(v1), null)
C
B
DROP TABLE t1;
+#
+# MDEV-13275:Query optimizer not picking optimal ORDER BY PRIMARY in case of INNER JOIN on PRIMARY
+# like it does for similar WHERE condition
+#
+create table t1 (id char(32) NOT NULL primary key);
+insert into t1 values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9);
+create table t2 (id char(32) NOT NULL primary key);
+insert into t2 values (0), (1), (2), (3);
+explain select t1.id from t1 INNER JOIN t2 on t1.id=t2.id order by t1.id;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index PRIMARY PRIMARY 32 NULL 4 Using index
+1 SIMPLE t1 eq_ref PRIMARY PRIMARY 32 test.t2.id 1 Using index
+analyze format=json select t1.id from t1 INNER JOIN t2 on t1.id=t2.id order by t1.id;
+ANALYZE
+{
+ "query_block": {
+ "select_id": 1,
+ "r_loops": 1,
+ "r_total_time_ms": "REPLACED",
+ "table": {
+ "table_name": "t2",
+ "access_type": "index",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "32",
+ "used_key_parts": ["id"],
+ "r_loops": 1,
+ "rows": 4,
+ "r_rows": 4,
+ "r_total_time_ms": "REPLACED",
+ "filtered": 100,
+ "r_filtered": 100,
+ "using_index": true
+ },
+ "table": {
+ "table_name": "t1",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "32",
+ "used_key_parts": ["id"],
+ "ref": ["test.t2.id"],
+ "r_loops": 4,
+ "rows": 1,
+ "r_rows": 1,
+ "r_total_time_ms": "REPLACED",
+ "filtered": 100,
+ "r_filtered": 100,
+ "using_index": true
+ }
+ }
+}
+explain select t1.id from t1 INNER JOIN t2 on t1.id=t2.id order by t2.id;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index PRIMARY PRIMARY 32 NULL 4 Using index
+1 SIMPLE t1 eq_ref PRIMARY PRIMARY 32 test.t2.id 1 Using index
+analyze format=json select t1.id from t1 INNER JOIN t2 on t1.id=t2.id order by t2.id;
+ANALYZE
+{
+ "query_block": {
+ "select_id": 1,
+ "r_loops": 1,
+ "r_total_time_ms": "REPLACED",
+ "table": {
+ "table_name": "t2",
+ "access_type": "index",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "32",
+ "used_key_parts": ["id"],
+ "r_loops": 1,
+ "rows": 4,
+ "r_rows": 4,
+ "r_total_time_ms": "REPLACED",
+ "filtered": 100,
+ "r_filtered": 100,
+ "using_index": true
+ },
+ "table": {
+ "table_name": "t1",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "32",
+ "used_key_parts": ["id"],
+ "ref": ["test.t2.id"],
+ "r_loops": 4,
+ "rows": 1,
+ "r_rows": 1,
+ "r_total_time_ms": "REPLACED",
+ "filtered": 100,
+ "r_filtered": 100,
+ "using_index": true
+ }
+ }
+}
+drop table t1,t2;
diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test
index d67c67de89c..07dc540c121 100644
--- a/mysql-test/t/order_by.test
+++ b/mysql-test/t/order_by.test
@@ -2201,3 +2201,23 @@ GROUP BY id
ORDER BY id+1 DESC;
DROP TABLE t1;
+
+--echo #
+--echo # MDEV-13275:Query optimizer not picking optimal ORDER BY PRIMARY in case of INNER JOIN on PRIMARY
+--echo # like it does for similar WHERE condition
+--echo #
+
+create table t1 (id char(32) NOT NULL primary key);
+insert into t1 values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9);
+create table t2 (id char(32) NOT NULL primary key);
+insert into t2 values (0), (1), (2), (3);
+
+explain select t1.id from t1 INNER JOIN t2 on t1.id=t2.id order by t1.id;
+--source include/analyze-format.inc
+analyze format=json select t1.id from t1 INNER JOIN t2 on t1.id=t2.id order by t1.id;
+
+explain select t1.id from t1 INNER JOIN t2 on t1.id=t2.id order by t2.id;
+--source include/analyze-format.inc
+analyze format=json select t1.id from t1 INNER JOIN t2 on t1.id=t2.id order by t2.id;
+
+drop table t1,t2;
diff --git a/sql/item.cc b/sql/item.cc
index f7092eb6c86..817d4db0660 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -5822,6 +5822,13 @@ Item *Item_field::propagate_equal_fields(THD *thd,
return item;
}
+Item *Item_field::propagate_equal_fields_helper(THD *thd,
+ COND_EQUAL *arg)
+{
+ return propagate_equal_fields(thd,Context(ANY_SUBST,
+ result_type(),
+ collation.collation), arg);
+}
/**
Replace an Item_field for an equal Item_field that evaluated earlier
diff --git a/sql/item.h b/sql/item.h
index bd72fed5300..cbbf5a12115 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -2775,6 +2775,7 @@ class Item_field :public Item_ident,
void set_item_equal(Item_equal *item_eq) { item_equal= item_eq; }
Item_equal *find_item_equal(COND_EQUAL *cond_equal);
Item* propagate_equal_fields(THD *, const Context &, COND_EQUAL *);
+ Item* propagate_equal_fields_helper(THD *, COND_EQUAL *);
Item *replace_equal_field(THD *thd, uchar *arg);
inline uint32 max_disp_length() { return field->max_display_length(); }
Item_field *field_for_view_update() { return this; }
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 6eb4ecbb4cf..7665fedd0cf 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -12682,20 +12682,28 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond,
table_map first_table_bit=
join->join_tab[join->const_tables].table->map;
- Item *item= order->item[0];
+ Item_field* item= (Item_field *)order->item[0]->real_item();
/*
- TODO: equality substitution in the context of ORDER BY is
+ Equality substitution in the context of ORDER BY is
sometimes allowed when it is not allowed in the general case.
+ An example of this would be when we are using a collation that
+ is case insensitive so 'a' and 'A' would be the same but HEX(a)
+ and HEX('A') are different, so we don't make this substitution in
+ general case but the sustitutions works well with comparision, so
+ if we have 'a' < 'das' then we can substitute this with
+ 'A' < 'das'.
+ For equality propagation the fields after substituion would be
+ used for comparision so we can do these substitutions in the
+ order by clause.
+
We make the below call for its side effect: it will locate the
multiple equality the item belongs to and set item->item_equal
accordingly.
*/
- Item *res= item->propagate_equal_fields(join->thd,
- Value_source::
- Context_identity(),
- join->cond_equal);
+ Item *res= item->propagate_equal_fields_helper(join->thd,
+ join->cond_equal);
Item_equal *item_eq;
if ((item_eq= res->get_item_equal()))
{
1
0
03 May '19
revision-id: e793e4e260b6faa4666d4ff439a6a7023daedceb (mariadb-10.2.23-110-ge793e4e260b)
parent(s): 386a759efe552519fb6a4f9acc6f630b2872316e
author: Varun Gupta
committer: Varun Gupta
timestamp: 2019-05-04 03:21:42 +0530
message:
MDEV-18373: DENSE_RANK is not calculated correctly
Need to call split_sum_func if an aggregate function is part of order by
or partition by clause so that we have the required fields inside the temporary
table, as all the fields inside the partition by and order by clause of the
window function needs to be there in the temp table used for window function
computation.
---
mysql-test/r/win.result | 26 ++++++++++++++++++++++++++
mysql-test/t/win.test | 15 +++++++++++++++
sql/sql_select.cc | 8 ++++++++
3 files changed, 49 insertions(+)
diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result
index 849da8668f1..5da8a7f8a3c 100644
--- a/mysql-test/r/win.result
+++ b/mysql-test/r/win.result
@@ -3581,5 +3581,31 @@ x b c
8 64 248
drop table t1;
#
+# MDEV-18373: DENSE_RANK is not calculated correctly
+#
+create table t1 (a int, b int);
+insert into t1 values (60, 1515),(60, 2000),(70, 2000),(55, 1600);
+select b, dense_rank() over (order by sum(a)) from t1 group by b;
+b dense_rank() over (order by sum(a))
+1515 2
+1600 1
+2000 3
+select b, dense_rank() over (order by sum(a)+1) from t1 group by b;
+b dense_rank() over (order by sum(a)+1)
+1515 2
+1600 1
+2000 3
+select b, row_number() over (partition by sum(a)) from t1 group by b;
+b row_number() over (partition by sum(a))
+1515 1
+1600 1
+2000 1
+select b, row_number() over (partition by sum(a)+1) from t1 group by b;
+b row_number() over (partition by sum(a)+1)
+1515 1
+1600 1
+2000 1
+drop table t1;
+#
# End of 10.2 tests
#
diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test
index 270af3833c9..40da44c0426 100644
--- a/mysql-test/t/win.test
+++ b/mysql-test/t/win.test
@@ -2310,6 +2310,21 @@ SELECT max(t1.a) over (partition by c) as x, b, c from t1 order by max(t1.a) ove
drop table t1;
+--echo #
+--echo # MDEV-18373: DENSE_RANK is not calculated correctly
+--echo #
+
+create table t1 (a int, b int);
+insert into t1 values (60, 1515),(60, 2000),(70, 2000),(55, 1600);
+
+select b, dense_rank() over (order by sum(a)) from t1 group by b;
+select b, dense_rank() over (order by sum(a)+1) from t1 group by b;
+
+select b, row_number() over (partition by sum(a)) from t1 group by b;
+select b, row_number() over (partition by sum(a)+1) from t1 group by b;
+
+drop table t1;
+
--echo #
--echo # End of 10.2 tests
--echo #
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 7665fedd0cf..521cd863cfc 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -22584,6 +22584,10 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
my_error(ER_WINDOW_FUNCTION_IN_WINDOW_SPEC, MYF(0));
return 1;
}
+ if (from_window_spec && (*order->item)->with_sum_func &&
+ (*order->item)->type() != Item::SUM_FUNC_ITEM)
+ (*order->item)->split_sum_func(thd, ref_pointer_array,
+ all_fields, SPLIT_SUM_SELECT);
}
return 0;
}
@@ -22651,6 +22655,10 @@ setup_group(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
my_error(ER_WINDOW_FUNCTION_IN_WINDOW_SPEC, MYF(0));
return 1;
}
+ if (from_window_spec && (*ord->item)->with_sum_func &&
+ (*ord->item)->type() != Item::SUM_FUNC_ITEM)
+ (*ord->item)->split_sum_func(thd, ref_pointer_array,
+ all_fields, SPLIT_SUM_SELECT);
}
if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
context_analysis_place == IN_GROUP_BY)
1
0
[Commits] 5e23f561984: MDEV-18741: Optimizer trace: multi-part key ranges are printed incorrectly
by Varun 03 May '19
by Varun 03 May '19
03 May '19
revision-id: 5e23f56198493ed19ac270759963f615324b2c49 (mariadb-10.4.3-162-g5e23f561984)
parent(s): 02d9b048a2ab549a3227a81e15ff2f8c45562a65
author: Varun Gupta
committer: Varun Gupta
timestamp: 2019-04-05 14:58:39 +0530
message:
MDEV-18741: Optimizer trace: multi-part key ranges are printed incorrectly
Changed the function append_range_all_keyparts to use sel_arg_range_seq_init / sel_arg_range_seq_next to produce ranges.
Also adjusted to print format for the ranges, now the ranges are printed as:
(keypart1_min, keypart2_min,..) OP (keypart1_name,keypart2_name, ..) OP (keypart1_max,keypart2_max, ..)
Also added more tests for range and index merge access for optimizer trace
---
mysql-test/main/opt_trace.result | 276 ++++++++++-
mysql-test/main/opt_trace.test | 57 +++
mysql-test/main/opt_trace_index_merge.result | 509 ++++++++++++++++++++-
mysql-test/main/opt_trace_index_merge.test | 112 +++++
.../main/opt_trace_index_merge_innodb.result | 6 +-
sql/opt_range.cc | 281 ++++++------
sql/opt_range.h | 7 +-
7 files changed, 1079 insertions(+), 169 deletions(-)
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index 12d4c713886..ed5881e08fd 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -1248,7 +1248,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
{
"index": "a",
"covering": true,
- "ranges": ["2 <= b <= 2 AND 3 <= c <= 3"],
+ "ranges": ["(2,3) <= (b,c) <= (2,3)"],
"rows": 8,
"cost": 2.2
}
@@ -1264,7 +1264,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
"rows": 8,
"cost": 2.2,
"key_parts_used_for_access": ["a", "b", "c"],
- "ranges": ["2 <= b <= 2 AND 3 <= c <= 3"],
+ "ranges": ["(2,3) <= (b,c) <= (2,3)"],
"chosen": false,
"cause": "cost"
},
@@ -1446,7 +1446,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
{
"index": "id",
"covering": true,
- "ranges": ["0x24a20f <= a"],
+ "ranges": ["(0x24a20f) <= (a)"],
"rows": 9,
"cost": 2.35
}
@@ -1462,7 +1462,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
"rows": 9,
"cost": 2.35,
"key_parts_used_for_access": ["id"],
- "ranges": ["0x24a20f <= a"],
+ "ranges": ["(0x24a20f) <= (a)"],
"chosen": false,
"cause": "cost"
},
@@ -1624,7 +1624,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
{
"index": "id",
"covering": true,
- "ranges": ["0x24a20f <= a <= 0x24a20f"],
+ "ranges": ["(0x24a20f) <= (a) <= (0x24a20f)"],
"rows": 9,
"cost": 2.35
}
@@ -1640,7 +1640,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
"rows": 9,
"cost": 2.35,
"key_parts_used_for_access": ["id", "a"],
- "ranges": ["0x24a20f <= a <= 0x24a20f"],
+ "ranges": ["(0x24a20f) <= (a) <= (0x24a20f)"],
"chosen": false,
"cause": "cost"
},
@@ -1856,7 +1856,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"range_scan_alternatives": [
{
"index": "a_c",
- "ranges": ["1 <= a <= 1"],
+ "ranges": ["(1) <= (a) <= (1)"],
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
@@ -1866,7 +1866,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
},
{
"index": "a_b",
- "ranges": ["1 <= a <= 1 AND 2 <= b <= 2"],
+ "ranges": ["(1,2) <= (a,b) <= (1,2)"],
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
@@ -1885,7 +1885,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"type": "range_scan",
"index": "a_b",
"rows": 21,
- "ranges": ["1 <= a <= 1 AND 2 <= b <= 2"]
+ "ranges": ["(1,2) <= (a,b) <= (1,2)"]
},
"rows_for_plan": 21,
"cost_for_plan": 27.445,
@@ -2025,7 +2025,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"range_scan_alternatives": [
{
"index": "a_c",
- "ranges": ["1 <= a <= 1"],
+ "ranges": ["(1) <= (a) <= (1)"],
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
@@ -2044,7 +2044,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"type": "range_scan",
"index": "a_c",
"rows": 180,
- "ranges": ["1 <= a <= 1"]
+ "ranges": ["(1) <= (a) <= (1)"]
},
"rows_for_plan": 180,
"cost_for_plan": 231.72,
@@ -2895,7 +2895,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"range_scan_alternatives": [
{
"index": "pk",
- "ranges": ["2 <= pk <= 2"],
+ "ranges": ["(2) <= (pk) <= (2)"],
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
@@ -2906,7 +2906,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
},
{
"index": "pk_a",
- "ranges": ["2 <= pk <= 2 AND 5 <= a <= 5"],
+ "ranges": ["(2,5) <= (pk,a) <= (2,5)"],
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
@@ -2917,7 +2917,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
},
{
"index": "pk_a_b",
- "ranges": ["2 <= pk <= 2 AND 5 <= a <= 5 AND 1 <= b <= 1"],
+ "ranges": ["(2,5,1) <= (pk,a,b) <= (2,5,1)"],
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
@@ -2964,7 +2964,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"type": "range_scan",
"index": "pk_a_b",
"rows": 1,
- "ranges": ["2 <= pk <= 2 AND 5 <= a <= 5 AND 1 <= b <= 1"]
+ "ranges": ["(2,5,1) <= (pk,a,b) <= (2,5,1)"]
},
"rows_for_plan": 1,
"cost_for_plan": 1.1793,
@@ -3338,7 +3338,7 @@ explain delete from t0 where t0.a<3 {
"range_scan_alternatives": [
{
"index": "a",
- "ranges": ["NULL < a < 3"],
+ "ranges": ["(NULL) < (a) < (3)"],
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
@@ -3354,7 +3354,7 @@ explain delete from t0 where t0.a<3 {
"type": "range_scan",
"index": "a",
"rows": 3,
- "ranges": ["NULL < a < 3"]
+ "ranges": ["(NULL) < (a) < (3)"]
},
"rows_for_plan": 3,
"cost_for_plan": 5.007,
@@ -3481,7 +3481,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"range_scan_alternatives": [
{
"index": "a",
- "ranges": ["NULL < a < 3"],
+ "ranges": ["(NULL) < (a) < (3)"],
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
@@ -3500,7 +3500,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"type": "range_scan",
"index": "a",
"rows": 3,
- "ranges": ["NULL < a < 3"]
+ "ranges": ["(NULL) < (a) < (3)"]
},
"rows_for_plan": 3,
"cost_for_plan": 1.407,
@@ -3546,7 +3546,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"range_scan_alternatives": [
{
"index": "a",
- "ranges": ["NULL < a < 3"],
+ "ranges": ["(NULL) < (a) < (3)"],
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
@@ -3565,7 +3565,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"type": "range_scan",
"index": "a",
"rows": 3,
- "ranges": ["NULL < a < 3"]
+ "ranges": ["(NULL) < (a) < (3)"]
},
"rows_for_plan": 3,
"cost_for_plan": 1.407,
@@ -6034,4 +6034,238 @@ COUNT(*)
1
DROP VIEW v1;
DROP TABLE t1;
+#
+# MDEV-18741: Optimizer trace: multi-part key ranges are printed incorrectly.
+#
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table one_k (a int);
+insert into one_k select A.a + B.a*10 + C.a*100 from t0 A, t0 B, t0 C;
+create table t1 ( a int, b int, key a_b(a,b));
+insert into t1 select a,a from one_k;
+set optimizer_trace='enabled=on';
+explain select * from t1 force index (a_b) where a=2 and b=4;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref a_b a_b 10 const,const 1 Using index
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
+[
+
+ {
+ "range_scan_alternatives":
+ [
+
+ {
+ "index": "a_b",
+ "ranges":
+ [
+ "(2,4) <= (a,b) <= (2,4)"
+ ],
+ "rowid_ordered": true,
+ "using_mrr": false,
+ "index_only": true,
+ "rows": 1,
+ "cost": 1.1783,
+ "chosen": true
+ }
+ ],
+ "analyzing_roworder_intersect":
+ {
+ "cause": "too few roworder scans"
+ },
+ "analyzing_index_merge_union":
+ [
+ ]
+ }
+]
+explain select * from t1 where a >= 900 and b between 10 and 20;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range a_b a_b 10 NULL 107 Using where; Using index
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
+[
+
+ {
+ "range_scan_alternatives":
+ [
+
+ {
+ "index": "a_b",
+ "ranges":
+ [
+ "(900,10) <= (a,b)"
+ ],
+ "rowid_ordered": false,
+ "using_mrr": false,
+ "index_only": true,
+ "rows": 107,
+ "cost": 10.955,
+ "chosen": true
+ }
+ ],
+ "analyzing_roworder_intersect":
+ {
+ "cause": "too few roworder scans"
+ },
+ "analyzing_index_merge_union":
+ [
+ ]
+ }
+]
+drop table t0,t1;
+create table t1 (start_date date, end_date date, filler char(100), key(start_date, end_date)) ;
+insert into t1 select date_add(now(), interval a day), date_add(now(), interval (a+7) day), 'data' from one_k;
+explain select * from t1 force index(start_date) where start_date >= '2019-02-10' and end_date <'2019-04-01';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range start_date start_date 8 NULL 1000 Using index condition
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
+[
+
+ {
+ "range_scan_alternatives":
+ [
+
+ {
+ "index": "start_date",
+ "ranges":
+ [
+ "(0x4ac60f,NULL) < (start_date,end_date)"
+ ],
+ "rowid_ordered": false,
+ "using_mrr": false,
+ "index_only": false,
+ "rows": 1000,
+ "cost": 1282.2,
+ "chosen": true
+ }
+ ],
+ "analyzing_roworder_intersect":
+ {
+ "cause": "too few roworder scans"
+ },
+ "analyzing_index_merge_union":
+ [
+ ]
+ }
+]
+drop table t1,one_k;
+create table ten(a int);
+insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (
+a int not null,
+b int not null,
+c int not null,
+d int not null,
+key a_b_c(a,b,c)
+);
+insert into t1 select a,a, a,a from ten;
+explain select * from t1 force index(a_b_c) where a between 1 and 4 and b < 50;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range a_b_c a_b_c 8 NULL 4 Using index condition
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
+[
+
+ {
+ "range_scan_alternatives":
+ [
+
+ {
+ "index": "a_b_c",
+ "ranges":
+ [
+ "(1) <= (a) < (4,50)"
+ ],
+ "rowid_ordered": false,
+ "using_mrr": false,
+ "index_only": false,
+ "rows": 4,
+ "cost": 6.2648,
+ "chosen": true
+ }
+ ],
+ "analyzing_roworder_intersect":
+ {
+ "cause": "too few roworder scans"
+ },
+ "analyzing_index_merge_union":
+ [
+ ]
+ }
+]
+drop table ten,t1;
+# Ported test from MYSQL for ranges involving Binary column
+CREATE TABLE t1(i INT PRIMARY KEY, b BINARY(16), INDEX i_b(b));
+INSERT INTO t1 VALUES (1, x'D95B94336A9946A39CF5B58CFE772D8C');
+INSERT INTO t1 VALUES (2, NULL);
+EXPLAIN SELECT * FROM t1 WHERE b IN (0xD95B94336A9946A39CF5B58CFE772D8C);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref i_b i_b 17 const 1 Using index condition
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
+[
+
+ {
+ "range_scan_alternatives":
+ [
+
+ {
+ "index": "i_b",
+ "ranges":
+ [
+ "(0xd95b94336a9946a39cf5b58cfe772d8c) <= (b) <= (0xd95b94336a9946a39cf5b58cfe772d8c)"
+ ],
+ "rowid_ordered": true,
+ "using_mrr": false,
+ "index_only": false,
+ "rows": 1,
+ "cost": 2.3797,
+ "chosen": true
+ }
+ ],
+ "analyzing_roworder_intersect":
+ {
+ "cause": "too few roworder scans"
+ },
+ "analyzing_index_merge_union":
+ [
+ ]
+ }
+]
+EXPLAIN SELECT * FROM t1 WHERE b IS NULL;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref i_b i_b 17 const 1 Using index condition
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
+[
+
+ {
+ "range_scan_alternatives":
+ [
+
+ {
+ "index": "i_b",
+ "ranges":
+ [
+ "(NULL) <= (b) <= (NULL)"
+ ],
+ "rowid_ordered": true,
+ "using_mrr": false,
+ "index_only": false,
+ "rows": 1,
+ "cost": 2.3797,
+ "chosen": true
+ }
+ ],
+ "analyzing_roworder_intersect":
+ {
+ "cause": "too few roworder scans"
+ },
+ "analyzing_index_merge_union":
+ [
+ ]
+ }
+]
+drop table t1;
set optimizer_trace='enabled=off';
diff --git a/mysql-test/main/opt_trace.test b/mysql-test/main/opt_trace.test
index 4ec7c338acd..981a53ac1ad 100644
--- a/mysql-test/main/opt_trace.test
+++ b/mysql-test/main/opt_trace.test
@@ -387,4 +387,61 @@ SELECT COUNT(*) FROM v1 WHERE MATCH (f) AGAINST ('fooba');
DROP VIEW v1;
DROP TABLE t1;
+--echo #
+--echo # MDEV-18741: Optimizer trace: multi-part key ranges are printed incorrectly.
+--echo #
+
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table one_k (a int);
+insert into one_k select A.a + B.a*10 + C.a*100 from t0 A, t0 B, t0 C;
+create table t1 ( a int, b int, key a_b(a,b));
+insert into t1 select a,a from one_k;
+set optimizer_trace='enabled=on';
+
+explain select * from t1 force index (a_b) where a=2 and b=4;
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+
+explain select * from t1 where a >= 900 and b between 10 and 20;
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+
+drop table t0,t1;
+
+create table t1 (start_date date, end_date date, filler char(100), key(start_date, end_date)) ;
+--disable_warnings
+insert into t1 select date_add(now(), interval a day), date_add(now(), interval (a+7) day), 'data' from one_k;
+--enable_warnings
+explain select * from t1 force index(start_date) where start_date >= '2019-02-10' and end_date <'2019-04-01';
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+drop table t1,one_k;
+
+create table ten(a int);
+insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (
+ a int not null,
+ b int not null,
+ c int not null,
+ d int not null,
+ key a_b_c(a,b,c)
+);
+
+insert into t1 select a,a, a,a from ten;
+explain select * from t1 force index(a_b_c) where a between 1 and 4 and b < 50;
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+drop table ten,t1;
+
+--echo # Ported test from MYSQL for ranges involving Binary column
+
+CREATE TABLE t1(i INT PRIMARY KEY, b BINARY(16), INDEX i_b(b));
+INSERT INTO t1 VALUES (1, x'D95B94336A9946A39CF5B58CFE772D8C');
+INSERT INTO t1 VALUES (2, NULL);
+
+EXPLAIN SELECT * FROM t1 WHERE b IN (0xD95B94336A9946A39CF5B58CFE772D8C);
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+
+EXPLAIN SELECT * FROM t1 WHERE b IS NULL;
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+
+drop table t1;
+
set optimizer_trace='enabled=off';
diff --git a/mysql-test/main/opt_trace_index_merge.result b/mysql-test/main/opt_trace_index_merge.result
index 50daef815d6..b5e68d04615 100644
--- a/mysql-test/main/opt_trace_index_merge.result
+++ b/mysql-test/main/opt_trace_index_merge.result
@@ -110,7 +110,7 @@ explain select * from t1 where a=1 or b=1 {
"range_scan_alternatives": [
{
"index": "a",
- "ranges": ["1 <= a <= 1"],
+ "ranges": ["(1) <= (a) <= (1)"],
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
@@ -126,7 +126,7 @@ explain select * from t1 where a=1 or b=1 {
"range_scan_alternatives": [
{
"index": "b",
- "ranges": ["1 <= b <= 1"],
+ "ranges": ["(1) <= (b) <= (1)"],
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
@@ -147,7 +147,7 @@ explain select * from t1 where a=1 or b=1 {
"type": "range_scan",
"index": "a",
"rows": 1,
- "ranges": ["1 <= a <= 1"],
+ "ranges": ["(1) <= (a) <= (1)"],
"analyzing_roworder_intersect": {
"cause": "too few roworder scans"
}
@@ -156,7 +156,7 @@ explain select * from t1 where a=1 or b=1 {
"type": "range_scan",
"index": "b",
"rows": 1,
- "ranges": ["1 <= b <= 1"],
+ "ranges": ["(1) <= (b) <= (1)"],
"analyzing_roworder_intersect": {
"cause": "too few roworder scans"
}
@@ -176,13 +176,13 @@ explain select * from t1 where a=1 or b=1 {
"type": "range_scan",
"index": "a",
"rows": 1,
- "ranges": ["1 <= a <= 1"]
+ "ranges": ["(1) <= (a) <= (1)"]
},
{
"type": "range_scan",
"index": "b",
"rows": 1,
- "ranges": ["1 <= b <= 1"]
+ "ranges": ["(1) <= (b) <= (1)"]
}
]
},
@@ -243,3 +243,500 @@ explain select * from t1 where a=1 or b=1 {
drop table t0,t1;
set optimizer_trace="enabled=off";
set @@optimizer_switch= @tmp_opt_switch;
+# More tests added index_merge access
+create table t1
+(
+/* Field names reflect value(rowid) distribution, st=STairs, swt= SaWTooth */
+st_a int not null default 0,
+swt1a int not null default 0,
+swt2a int not null default 0,
+st_b int not null default 0,
+swt1b int not null default 0,
+swt2b int not null default 0,
+/* fields/keys for row retrieval tests */
+key1 int,
+key2 int,
+key3 int,
+key4 int,
+/* make rows much bigger then keys */
+filler1 char (200),
+filler2 char (200),
+filler3 char (200),
+filler4 char (200),
+filler5 char (200),
+filler6 char (200),
+/* order of keys is important */
+key sta_swt12a(st_a,swt1a,swt2a),
+key sta_swt1a(st_a,swt1a),
+key sta_swt2a(st_a,swt2a),
+key sta_swt21a(st_a,swt2a,swt1a),
+key st_a(st_a),
+key stb_swt1a_2b(st_b,swt1b,swt2a),
+key stb_swt1b(st_b,swt1b),
+key st_b(st_b),
+key(key1),
+key(key2),
+key(key3),
+key(key4)
+) ;
+create table t0 as select * from t1;
+# Printing of many insert into t0 values (....) disabled.
+alter table t1 disable keys;
+# Printing of many insert into t1 select .... from t0 disabled.
+# Printing of many insert into t1 (...) values (....) disabled.
+alter table t1 enable keys;
+insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, -1, -1, 'key1-key2');
+insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 100, 100, 'key4-key3');
+set optimizer_trace='enabled=on';
+# 3-way ROR-intersection
+explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge key1,key2,key3 key1,key2,key3 5,5,5 NULL 2 Using intersect(key1,key2,key3); Using where; Using index
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
+[
+
+ {
+ "range_scan_alternatives":
+ [
+
+ {
+ "index": "key1",
+ "ranges":
+ [
+ "(100) <= (key1) <= (100)"
+ ],
+ "rowid_ordered": true,
+ "using_mrr": false,
+ "index_only": false,
+ "rows": 2243,
+ "cost": 2862.1,
+ "chosen": true
+ },
+
+ {
+ "index": "key2",
+ "ranges":
+ [
+ "(100) <= (key2) <= (100)"
+ ],
+ "rowid_ordered": true,
+ "using_mrr": false,
+ "index_only": false,
+ "rows": 2243,
+ "cost": 2862.1,
+ "chosen": false,
+ "cause": "cost"
+ },
+
+ {
+ "index": "key3",
+ "ranges":
+ [
+ "(100) <= (key3) <= (100)"
+ ],
+ "rowid_ordered": true,
+ "using_mrr": false,
+ "index_only": false,
+ "rows": 2243,
+ "cost": 2862.1,
+ "chosen": false,
+ "cause": "cost"
+ }
+ ],
+ "analyzing_roworder_intersect":
+ {
+ "intersecting_indexes":
+ [
+
+ {
+ "index": "key1",
+ "index_scan_cost": 58.252,
+ "cumulated_index_scan_cost": 58.252,
+ "disk_sweep_cost": 1923.1,
+ "cumulative_total_cost": 1981.4,
+ "usable": true,
+ "matching_rows_now": 2243,
+ "intersect_covering_with_this_index": false,
+ "chosen": true
+ },
+
+ {
+ "index": "key2",
+ "index_scan_cost": 58.252,
+ "cumulated_index_scan_cost": 116.5,
+ "disk_sweep_cost": 84.518,
+ "cumulative_total_cost": 201.02,
+ "usable": true,
+ "matching_rows_now": 77.636,
+ "intersect_covering_with_this_index": false,
+ "chosen": true
+ },
+
+ {
+ "index": "key3",
+ "index_scan_cost": 58.252,
+ "cumulated_index_scan_cost": 174.76,
+ "disk_sweep_cost": 0,
+ "cumulative_total_cost": 174.76,
+ "usable": true,
+ "matching_rows_now": 2.6872,
+ "intersect_covering_with_this_index": true,
+ "chosen": true
+ }
+ ],
+ "clustered_pk":
+ {
+ "clustered_pk_added_to_intersect": false,
+ "cause": "no clustered pk index"
+ },
+ "rows": 2,
+ "cost": 174.76,
+ "covering": true,
+ "chosen": true
+ },
+ "analyzing_index_merge_union":
+ [
+ ]
+ }
+]
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
+[
+
+ {
+ "range_access_plan":
+ {
+ "type": "index_roworder_intersect",
+ "rows": 2,
+ "cost": 174.76,
+ "covering": true,
+ "clustered_pk_scan": false,
+ "intersect_of":
+ [
+
+ {
+ "type": "range_scan",
+ "index": "key1",
+ "rows": 2243,
+ "ranges":
+ [
+ "(100) <= (key1) <= (100)"
+ ]
+ },
+
+ {
+ "type": "range_scan",
+ "index": "key2",
+ "rows": 2243,
+ "ranges":
+ [
+ "(100) <= (key2) <= (100)"
+ ]
+ },
+
+ {
+ "type": "range_scan",
+ "index": "key3",
+ "rows": 2243,
+ "ranges":
+ [
+ "(100) <= (key3) <= (100)"
+ ]
+ }
+ ]
+ },
+ "rows_for_plan": 2,
+ "cost_for_plan": 174.76,
+ "chosen": true
+ }
+]
+# ROR-union(ROR-intersection, ROR-range)
+explain select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge key1,key2,key3,key4 key1,key2,key3,key4 5,5,5,5 NULL 154 Using union(intersect(key1,key2),intersect(key3,key4)); Using where
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
+[
+
+ {
+ "range_scan_alternatives":
+ [
+ ],
+ "analyzing_roworder_intersect":
+ {
+ "cause": "too few roworder scans"
+ },
+ "analyzing_index_merge_union":
+ [
+
+ {
+ "indexes_to_merge":
+ [
+
+ {
+ "range_scan_alternatives":
+ [
+
+ {
+ "index": "key1",
+ "ranges":
+ [
+ "(100) <= (key1) <= (100)"
+ ],
+ "rowid_ordered": true,
+ "using_mrr": false,
+ "index_only": true,
+ "rows": 2243,
+ "cost": 170.53,
+ "chosen": true
+ },
+
+ {
+ "index": "key2",
+ "ranges":
+ [
+ "(100) <= (key2) <= (100)"
+ ],
+ "rowid_ordered": true,
+ "using_mrr": false,
+ "index_only": true,
+ "rows": 2243,
+ "cost": 170.53,
+ "chosen": false,
+ "cause": "cost"
+ }
+ ],
+ "index_to_merge": "key1",
+ "cumulated_cost": 170.53
+ },
+
+ {
+ "range_scan_alternatives":
+ [
+
+ {
+ "index": "key3",
+ "ranges":
+ [
+ "(100) <= (key3) <= (100)"
+ ],
+ "rowid_ordered": true,
+ "using_mrr": false,
+ "index_only": true,
+ "rows": 2243,
+ "cost": 170.53,
+ "chosen": true
+ },
+
+ {
+ "index": "key4",
+ "ranges":
+ [
+ "(100) <= (key4) <= (100)"
+ ],
+ "rowid_ordered": true,
+ "using_mrr": false,
+ "index_only": true,
+ "rows": 2243,
+ "cost": 170.53,
+ "chosen": false,
+ "cause": "cost"
+ }
+ ],
+ "index_to_merge": "key3",
+ "cumulated_cost": 341.05
+ }
+ ],
+ "cost_of_reading_ranges": 341.05,
+ "use_roworder_union": true,
+ "cause": "always cheaper than non roworder retrieval",
+ "analyzing_roworder_scans":
+ [
+
+ {
+ "type": "range_scan",
+ "index": "key1",
+ "rows": 2243,
+ "ranges":
+ [
+ "(100) <= (key1) <= (100)"
+ ],
+ "analyzing_roworder_intersect":
+ {
+ "intersecting_indexes":
+ [
+
+ {
+ "index": "key1",
+ "index_scan_cost": 58.252,
+ "cumulated_index_scan_cost": 58.252,
+ "disk_sweep_cost": 1923.1,
+ "cumulative_total_cost": 1981.4,
+ "usable": true,
+ "matching_rows_now": 2243,
+ "intersect_covering_with_this_index": false,
+ "chosen": true
+ },
+
+ {
+ "index": "key2",
+ "index_scan_cost": 58.252,
+ "cumulated_index_scan_cost": 116.5,
+ "disk_sweep_cost": 84.518,
+ "cumulative_total_cost": 201.02,
+ "usable": true,
+ "matching_rows_now": 77.636,
+ "intersect_covering_with_this_index": false,
+ "chosen": true
+ }
+ ],
+ "clustered_pk":
+ {
+ "clustered_pk_added_to_intersect": false,
+ "cause": "no clustered pk index"
+ },
+ "rows": 77,
+ "cost": 201.02,
+ "covering": false,
+ "chosen": true
+ }
+ },
+
+ {
+ "type": "range_scan",
+ "index": "key3",
+ "rows": 2243,
+ "ranges":
+ [
+ "(100) <= (key3) <= (100)"
+ ],
+ "analyzing_roworder_intersect":
+ {
+ "intersecting_indexes":
+ [
+
+ {
+ "index": "key3",
+ "index_scan_cost": 58.252,
+ "cumulated_index_scan_cost": 58.252,
+ "disk_sweep_cost": 1923.1,
+ "cumulative_total_cost": 1981.4,
+ "usable": true,
+ "matching_rows_now": 2243,
+ "intersect_covering_with_this_index": false,
+ "chosen": true
+ },
+
+ {
+ "index": "key4",
+ "index_scan_cost": 58.252,
+ "cumulated_index_scan_cost": 116.5,
+ "disk_sweep_cost": 84.518,
+ "cumulative_total_cost": 201.02,
+ "usable": true,
+ "matching_rows_now": 77.636,
+ "intersect_covering_with_this_index": false,
+ "chosen": true
+ }
+ ],
+ "clustered_pk":
+ {
+ "clustered_pk_added_to_intersect": false,
+ "cause": "no clustered pk index"
+ },
+ "rows": 77,
+ "cost": 201.02,
+ "covering": false,
+ "chosen": true
+ }
+ }
+ ],
+ "index_roworder_union_cost": 386.73,
+ "members": 2,
+ "chosen": true
+ }
+ ]
+ }
+]
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
+[
+
+ {
+ "range_access_plan":
+ {
+ "type": "index_roworder_union",
+ "union_of":
+ [
+
+ {
+ "type": "index_roworder_intersect",
+ "rows": 77,
+ "cost": 201.02,
+ "covering": false,
+ "clustered_pk_scan": false,
+ "intersect_of":
+ [
+
+ {
+ "type": "range_scan",
+ "index": "key1",
+ "rows": 2243,
+ "ranges":
+ [
+ "(100) <= (key1) <= (100)"
+ ]
+ },
+
+ {
+ "type": "range_scan",
+ "index": "key2",
+ "rows": 2243,
+ "ranges":
+ [
+ "(100) <= (key2) <= (100)"
+ ]
+ }
+ ]
+ },
+
+ {
+ "type": "index_roworder_intersect",
+ "rows": 77,
+ "cost": 201.02,
+ "covering": false,
+ "clustered_pk_scan": false,
+ "intersect_of":
+ [
+
+ {
+ "type": "range_scan",
+ "index": "key3",
+ "rows": 2243,
+ "ranges":
+ [
+ "(100) <= (key3) <= (100)"
+ ]
+ },
+
+ {
+ "type": "range_scan",
+ "index": "key4",
+ "rows": 2243,
+ "ranges":
+ [
+ "(100) <= (key4) <= (100)"
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "rows_for_plan": 154,
+ "cost_for_plan": 386.73,
+ "chosen": true
+ }
+]
+drop table t0,t1;
+set optimizer_trace="enabled=off";
diff --git a/mysql-test/main/opt_trace_index_merge.test b/mysql-test/main/opt_trace_index_merge.test
index d5efaf81db5..73240b6a9e2 100644
--- a/mysql-test/main/opt_trace_index_merge.test
+++ b/mysql-test/main/opt_trace_index_merge.test
@@ -19,3 +19,115 @@ select * from information_schema.OPTIMIZER_TRACE;
drop table t0,t1;
set optimizer_trace="enabled=off";
set @@optimizer_switch= @tmp_opt_switch;
+
+--echo # More tests added index_merge access
+
+--enable_warnings
+create table t1
+(
+ /* Field names reflect value(rowid) distribution, st=STairs, swt= SaWTooth */
+ st_a int not null default 0,
+ swt1a int not null default 0,
+ swt2a int not null default 0,
+
+ st_b int not null default 0,
+ swt1b int not null default 0,
+ swt2b int not null default 0,
+
+ /* fields/keys for row retrieval tests */
+ key1 int,
+ key2 int,
+ key3 int,
+ key4 int,
+
+ /* make rows much bigger then keys */
+ filler1 char (200),
+ filler2 char (200),
+ filler3 char (200),
+ filler4 char (200),
+ filler5 char (200),
+ filler6 char (200),
+
+ /* order of keys is important */
+ key sta_swt12a(st_a,swt1a,swt2a),
+ key sta_swt1a(st_a,swt1a),
+ key sta_swt2a(st_a,swt2a),
+ key sta_swt21a(st_a,swt2a,swt1a),
+ key st_a(st_a),
+ key stb_swt1a_2b(st_b,swt1b,swt2a),
+ key stb_swt1b(st_b,swt1b),
+ key st_b(st_b),
+
+ key(key1),
+ key(key2),
+ key(key3),
+ key(key4)
+) ;
+# Fill table
+create table t0 as select * from t1;
+--disable_query_log
+--echo # Printing of many insert into t0 values (....) disabled.
+let $cnt=1000;
+while ($cnt)
+{
+ eval insert into t0 values (1, 2, 3, 1, 2, 3, 0, 0, 0, 0, 'data1', 'data2', 'data3', 'data4', 'data5', 'data6');
+ dec $cnt;
+}
+--enable_query_log
+
+alter table t1 disable keys;
+--disable_query_log
+--echo # Printing of many insert into t1 select .... from t0 disabled.
+let $1=4;
+while ($1)
+{
+ let $2=4;
+ while ($2)
+ {
+ let $3=4;
+ while ($3)
+ {
+ eval insert into t1 select $1, $2, $3, $1 ,$2, $3, key1, key2, key3, key4, filler1, filler2, filler3, filler4, filler5, filler6 from t0;
+ dec $3;
+ }
+ dec $2;
+ }
+ dec $1;
+}
+
+--echo # Printing of many insert into t1 (...) values (....) disabled.
+# Row retrieval tests
+# -1 is used for values 'out of any range we are using'
+# insert enough rows for index intersection to be used for (key1,key2)
+insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 100, 100,'key1-key2-key3-key4');
+let $cnt=400;
+while ($cnt)
+{
+ eval insert into t1 (key1, key2, key3, key4, filler1) values (100, -1, 100, -1,'key1-key3');
+ dec $cnt;
+}
+let $cnt=400;
+while ($cnt)
+{
+ eval insert into t1 (key1, key2, key3, key4, filler1) values (-1, 100, -1, 100,'key2-key4');
+ dec $cnt;
+}
+--enable_query_log
+alter table t1 enable keys;
+
+insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, -1, -1, 'key1-key2');
+insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 100, 100, 'key4-key3');
+set optimizer_trace='enabled=on';
+
+--echo # 3-way ROR-intersection
+explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+
+--echo # ROR-union(ROR-intersection, ROR-range)
+explain select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+select JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+
+drop table t0,t1;
+set optimizer_trace="enabled=off";
diff --git a/mysql-test/main/opt_trace_index_merge_innodb.result b/mysql-test/main/opt_trace_index_merge_innodb.result
index 94e9d4f58cc..6a245cc83da 100644
--- a/mysql-test/main/opt_trace_index_merge_innodb.result
+++ b/mysql-test/main/opt_trace_index_merge_innodb.result
@@ -116,7 +116,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"range_scan_alternatives": [
{
"index": "PRIMARY",
- "ranges": ["pk1 < 0", "0 < pk1"],
+ "ranges": ["(pk1) < (0)", "(0) < (pk1)"],
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
@@ -127,7 +127,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
},
{
"index": "key1",
- "ranges": ["1 <= key1 <= 1"],
+ "ranges": ["(1) <= (key1) <= (1)"],
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
@@ -164,7 +164,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"type": "range_scan",
"index": "key1",
"rows": 1,
- "ranges": ["1 <= key1 <= 1"]
+ "ranges": ["(1) <= (key1) <= (1)"]
},
"rows_for_plan": 1,
"cost_for_plan": 2.3751,
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 5ab3d70214d..1827e2fcaf2 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -431,16 +431,18 @@ static int and_range_trees(RANGE_OPT_PARAM *param,
static bool remove_nonrange_trees(RANGE_OPT_PARAM *param, SEL_TREE *tree);
static void print_key_value(String *out, const KEY_PART_INFO *key_part,
- const uchar *key);
+ const uchar* key, uint length);
+static void print_keyparts_name(String *out, const KEY_PART_INFO *key_part,
+ uint n_keypart, key_part_map keypart_map);
static void append_range_all_keyparts(Json_writer_array *range_trace,
- String *range_string,
- String *range_so_far, const SEL_ARG *keypart,
+ PARAM param, uint idx,
+ SEL_ARG *keypart,
const KEY_PART_INFO *key_parts);
static
-void append_range(String *out, const KEY_PART_INFO *key_parts,
- const uchar *min_key, const uchar *max_key, const uint flag);
+void append_range(String *out, const KEY_PART_INFO *key_part,
+ KEY_MULTI_RANGE *range, uint n_key_parts);
/*
@@ -2273,10 +2275,7 @@ void TRP_RANGE::trace_basic_info(const PARAM *param,
// TRP_RANGE should not be created if there are no range intervals
DBUG_ASSERT(key);
- String range_info;
- range_info.length(0);
- range_info.set_charset(system_charset_info);
- append_range_all_keyparts(&trace_range, NULL, &range_info, key, key_part);
+ append_range_all_keyparts(&trace_range, *param, key_idx, key, key_part);
}
@@ -2489,10 +2488,8 @@ void TRP_GROUP_MIN_MAX::trace_basic_info(const PARAM *param,
// can have group quick without ranges
if (index_tree)
{
- String range_info;
- range_info.set_charset(system_charset_info);
- append_range_all_keyparts(&trace_range, NULL, &range_info, index_tree,
- key_part);
+ append_range_all_keyparts(&trace_range, *param, param_idx,
+ index_tree, key_part);
}
}
@@ -6398,20 +6395,9 @@ void TRP_ROR_INTERSECT::trace_basic_info(const PARAM *param,
trace_isect_idx.add("rows", (*cur_scan)->records);
Json_writer_array trace_range(thd, "ranges");
- for (const SEL_ARG *current= (*cur_scan)->sel_arg->first(); current;
- current= current->next)
- {
- String range_info;
- range_info.set_charset(system_charset_info);
- for (const SEL_ARG *part= current; part;
- part= part->next_key_part ? part->next_key_part : nullptr)
- {
- const KEY_PART_INFO *cur_key_part= key_part + part->part;
- append_range(&range_info, cur_key_part, part->min_value,
- part->max_value, part->min_flag | part->max_flag);
- }
- trace_range.add(range_info.ptr(), range_info.length());
- }
+
+ append_range_all_keyparts(&trace_range, *param, (*cur_scan)->idx,
+ (*cur_scan)->sel_arg->first(), key_part);
}
}
@@ -7389,9 +7375,6 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
const KEY &cur_key= param->table->key_info[keynr];
const KEY_PART_INFO *key_part= cur_key.key_part;
- String range_info;
- range_info.set_charset(system_charset_info);
-
index_scan->idx= idx;
index_scan->keynr= keynr;
index_scan->key_info= ¶m->table->key_info[keynr];
@@ -7402,8 +7385,8 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
*tree->index_scans_end++= index_scan;
if (unlikely(thd->trace_started()))
- append_range_all_keyparts(&trace_range, NULL, &range_info, key,
- key_part);
+ append_range_all_keyparts(&trace_range, (*param), idx,
+ key, key_part);
trace_range.end();
trace_idx.add("rowid_ordered", param->is_ror_scan)
@@ -13554,10 +13537,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
Json_writer_array trace_range(thd, "ranges");
const KEY_PART_INFO *key_part= cur_index_info->key_part;
-
- String range_info;
- range_info.set_charset(system_charset_info);
- append_range_all_keyparts(&trace_range, NULL, &range_info,
+ append_range_all_keyparts(&trace_range, *param, cur_param_idx,
cur_index_tree, key_part);
}
}
@@ -15730,12 +15710,17 @@ void QUICK_GROUP_MIN_MAX_SELECT::dbug_dump(int indent, bool verbose)
}
#endif /* !DBUG_OFF */
+
static
void append_range(String *out, const KEY_PART_INFO *key_part,
- const uchar *min_key, const uchar *max_key, const uint flag)
+ KEY_MULTI_RANGE *range, uint n_key_parts)
{
- if (out->length() > 0)
- out->append(STRING_WITH_LEN(" AND "));
+ uint flag= range->range_flag;
+ String key_name;
+ key_name.set_charset(system_charset_info);
+ key_part_map keypart_map= range->start_key.length ?
+ range->start_key.keypart_map :
+ range->end_key.keypart_map;
if (flag & GEOM_FLAG)
{
@@ -15744,22 +15729,24 @@ void append_range(String *out, const KEY_PART_INFO *key_part,
range types, so printing "col < some_geom" doesn't make sense.
Just print the column name, not operator.
*/
- out->append(key_part->field->field_name);
+ print_keyparts_name(out, key_part, n_key_parts, keypart_map);
out->append(STRING_WITH_LEN(" "));
- print_key_value(out, key_part, min_key);
+ print_key_value(out, key_part, range->start_key.key,
+ range->start_key.length);
return;
}
if (!(flag & NO_MIN_RANGE))
{
- print_key_value(out, key_part, min_key);
+ print_key_value(out, key_part, range->start_key.key,
+ range->start_key.length);
if (flag & NEAR_MIN)
out->append(STRING_WITH_LEN(" < "));
else
out->append(STRING_WITH_LEN(" <= "));
}
- out->append(key_part->field->field_name);
+ print_keyparts_name(out, key_part, n_key_parts, keypart_map);
if (!(flag & NO_MAX_RANGE))
{
@@ -15767,7 +15754,8 @@ void append_range(String *out, const KEY_PART_INFO *key_part,
out->append(STRING_WITH_LEN(" < "));
else
out->append(STRING_WITH_LEN(" <= "));
- print_key_value(out, key_part, max_key);
+ print_key_value(out, key_part, range->end_key.key,
+ range->end_key.length);
}
}
@@ -15775,60 +15763,39 @@ void append_range(String *out, const KEY_PART_INFO *key_part,
Add ranges to the trace
For ex:
- query: select * from t1 where a=2 ;
- and we have an index on a , so we create a range
- 2 <= a <= 2
+ lets say we have an index a_b(a,b)
+ query: select * from t1 where a=2 and b=4 ;
+ so we create a range:
+ (2,4) <= (a,b) <= (2,4)
this is added to the trace
*/
static void append_range_all_keyparts(Json_writer_array *range_trace,
- String *range_string,
- String *range_so_far, const SEL_ARG *keypart,
+ PARAM param, uint idx,
+ SEL_ARG *keypart,
const KEY_PART_INFO *key_parts)
{
-
- DBUG_ASSERT(keypart);
- DBUG_ASSERT(keypart && keypart != &null_element);
-
- // Navigate to first interval in red-black tree
+ SEL_ARG_RANGE_SEQ seq;
+ KEY_MULTI_RANGE range;
+ range_seq_t seq_it;
+ uint flags= 0;
+ RANGE_SEQ_IF seq_if = {NULL, sel_arg_range_seq_init,
+ sel_arg_range_seq_next, 0, 0};
+ KEY *keyinfo= param.table->key_info + param.real_keynr[idx];
+ uint n_key_parts= param.table->actual_n_key_parts(keyinfo);
+ seq.keyno= idx;
+ seq.real_keyno= param.real_keynr[idx];
+ seq.param= ¶m;
+ seq.start= keypart;
const KEY_PART_INFO *cur_key_part= key_parts + keypart->part;
- const SEL_ARG *keypart_range= keypart->first();
- const size_t save_range_so_far_length= range_so_far->length();
-
+ seq_it= seq_if.init((void *) &seq, 0, flags);
- while (keypart_range)
+ while (!seq_if.next(seq_it, &range))
{
- // Append the current range predicate to the range String
- switch (keypart->type)
- {
- case SEL_ARG::Type::KEY_RANGE:
- append_range(range_so_far, cur_key_part, keypart_range->min_value,
- keypart_range->max_value,
- keypart_range->min_flag | keypart_range->max_flag);
- break;
- case SEL_ARG::Type::MAYBE_KEY:
- range_so_far->append("MAYBE_KEY");
- break;
- case SEL_ARG::Type::IMPOSSIBLE:
- range_so_far->append("IMPOSSIBLE");
- break;
- default:
- DBUG_ASSERT(false);
- break;
- }
-
- if (keypart_range->next_key_part &&
- keypart_range->next_key_part->part ==
- keypart_range->part + 1 &&
- keypart_range->is_singlepoint())
- {
- append_range_all_keyparts(range_trace, range_string, range_so_far,
- keypart_range->next_key_part, key_parts);
- }
- else
- range_trace->add(range_so_far->c_ptr_safe(), range_so_far->length());
- keypart_range= keypart_range->next;
- range_so_far->length(save_range_so_far_length);
+ String range_info;
+ range_info.set_charset(system_charset_info);
+ append_range(&range_info, cur_key_part, &range, n_key_parts);
+ range_trace->add(range_info.c_ptr_safe(), range_info.length());
}
}
@@ -15838,70 +15805,110 @@ static void append_range_all_keyparts(Json_writer_array *range_trace,
@param[out] out String the key is appended to
@param[in] key_part Index components description
@param[in] key Key tuple
+ @param[in] used_length length of the key tuple
*/
+
static void print_key_value(String *out, const KEY_PART_INFO *key_part,
- const uchar *key)
+ const uchar* key, uint used_length)
{
+ out->append(STRING_WITH_LEN("("));
Field *field= key_part->field;
+ StringBuffer<128> tmp(system_charset_info);
+ TABLE *table= field->table;
+ uint store_length;
+ my_bitmap_map *old_sets[2];
+ dbug_tmp_use_all_columns(table, old_sets, table->read_set, table->write_set);
+ const uchar *key_end= key+used_length;
- if (field->flags & BLOB_FLAG)
+ for (; key < key_end; key+=store_length, key_part++)
{
- // Byte 0 of a nullable key is the null-byte. If set, key is NULL.
- if (field->real_maybe_null() && *key)
- out->append(STRING_WITH_LEN("NULL"));
- else
- (field->type() == MYSQL_TYPE_GEOMETRY)
- ? out->append(STRING_WITH_LEN("unprintable_geometry_value"))
- : out->append(STRING_WITH_LEN("unprintable_blob_value"));
- return;
- }
+ field= key_part->field;
+ store_length= key_part->store_length;
+ if (field->flags & BLOB_FLAG)
+ {
+ // Byte 0 of a nullable key is the null-byte. If set, key is NULL.
+ if (field->real_maybe_null() && *key)
+ out->append(STRING_WITH_LEN("NULL"));
+ else
+ (field->type() == MYSQL_TYPE_GEOMETRY)
+ ? out->append(STRING_WITH_LEN("unprintable_geometry_value"))
+ : out->append(STRING_WITH_LEN("unprintable_blob_value"));
+ goto next;
+ }
- uint store_length= key_part->store_length;
+ if (field->real_maybe_null())
+ {
+ /*
+ Byte 0 of key is the null-byte. If set, key is NULL.
+ Otherwise, print the key value starting immediately after the
+ null-byte
+ */
+ if (*key)
+ {
+ out->append(STRING_WITH_LEN("NULL"));
+ goto next;
+ }
+ key++; // Skip null byte
+ store_length--;
+ }
- if (field->real_maybe_null())
- {
/*
- Byte 0 of key is the null-byte. If set, key is NULL.
- Otherwise, print the key value starting immediately after the
- null-byte
+ Binary data cannot be converted to UTF8 which is what the
+ optimizer trace expects. If the column is binary, the hex
+ representation is printed to the trace instead.
*/
- if (*key)
+ if (field->flags & BINARY_FLAG)
{
- out->append(STRING_WITH_LEN("NULL"));
- return;
+ out->append("0x");
+ for (uint i = 0; i < store_length; i++)
+ {
+ out->append(_dig_vec_lower[*(key + i) >> 4]);
+ out->append(_dig_vec_lower[*(key + i) & 0x0F]);
+ }
+ goto next;
}
- key++; // Skip null byte
- store_length--;
+
+ field->set_key_image(key, key_part->length);
+ if (field->type() == MYSQL_TYPE_BIT)
+ (void)field->val_int_as_str(&tmp, 1); // may change tmp's charset
+ else
+ field->val_str(&tmp); // may change tmp's charset
+ out->append(tmp.ptr(), tmp.length(), tmp.charset());
+
+ next:
+ if (key + store_length < key_end)
+ out->append(STRING_WITH_LEN(","));
}
+ dbug_tmp_restore_column_maps(table->read_set, table->write_set, old_sets);
+ out->append(STRING_WITH_LEN(")"));
+}
- /*
- Binary data cannot be converted to UTF8 which is what the
- optimizer trace expects. If the column is binary, the hex
- representation is printed to the trace instead.
- */
- if (field->flags & BINARY_FLAG)
+/**
+ Print key parts involed in a range
+ @param[out] out String the key is appended to
+ @param[in] key_part Index components description
+ @param[in] n_keypart Number of keyparts in index
+ @param[in] keypart_map map for keyparts involved in the range
+*/
+
+void print_keyparts_name(String *out, const KEY_PART_INFO *key_part,
+ uint n_keypart, key_part_map keypart_map)
+{
+ uint i;
+ out->append(STRING_WITH_LEN("("));
+ bool first_keypart= TRUE;
+ for (i=0; i < n_keypart; key_part++, i++)
{
- out->append("0x");
- for (uint i = 0; i < store_length; i++)
+ if (keypart_map & (1 << i))
{
- out->append(_dig_vec_lower[*(key + i) >> 4]);
- out->append(_dig_vec_lower[*(key + i) & 0x0F]);
+ if (first_keypart)
+ first_keypart= FALSE;
+ else
+ out->append(STRING_WITH_LEN(","));
+ out->append(key_part->field->field_name);
}
- return;
+ else
+ break;
}
-
- StringBuffer<128> tmp(system_charset_info);
- TABLE *table= field->table;
- my_bitmap_map *old_sets[2];
-
- dbug_tmp_use_all_columns(table, old_sets, table->read_set, table->write_set);
-
- field->set_key_image(key, key_part->length);
- if (field->type() == MYSQL_TYPE_BIT)
- (void)field->val_int_as_str(&tmp, 1); // may change tmp's charset
- else
- field->val_str(&tmp); // may change tmp's charset
- out->append(tmp.ptr(), tmp.length(), tmp.charset());
-
- dbug_tmp_restore_column_maps(table->read_set, table->write_set, old_sets);
+ out->append(STRING_WITH_LEN(")"));
}
diff --git a/sql/opt_range.h b/sql/opt_range.h
index 2dab90b9f69..5c2a2e39137 100644
--- a/sql/opt_range.h
+++ b/sql/opt_range.h
@@ -458,7 +458,9 @@ class SEL_ARG :public Sql_alloc
SEL_ARG *key_tree= first();
uint res= key_tree->store_min(key[key_tree->part].store_length,
range_key, *range_key_flag);
- *range_key_flag|= key_tree->min_flag;
+ // add flags only if a key_part is written to the buffer
+ if (res)
+ *range_key_flag|= key_tree->min_flag;
if (key_tree->next_key_part &&
key_tree->next_key_part->type == SEL_ARG::KEY_RANGE &&
key_tree->part != last_part &&
@@ -480,7 +482,8 @@ class SEL_ARG :public Sql_alloc
SEL_ARG *key_tree= last();
uint res=key_tree->store_max(key[key_tree->part].store_length,
range_key, *range_key_flag);
- (*range_key_flag)|= key_tree->max_flag;
+ if (res)
+ (*range_key_flag)|= key_tree->max_flag;
if (key_tree->next_key_part &&
key_tree->next_key_part->type == SEL_ARG::KEY_RANGE &&
key_tree->part != last_part &&
2
1