Loading client/mysqldump.c +4 −3 Original line number Diff line number Diff line Loading @@ -2122,8 +2122,7 @@ static void dump_triggers_for_table(char *table, } if (mysql_num_rows(result)) { if (opt_compact) fprintf(sql_file, "\n/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n"); fprintf(sql_file, "\n/*!50003 SET @SAVE_SQL_MODE=@@SQL_MODE*/;\n"); fprintf(sql_file, "\nDELIMITER ;;\n"); } while ((row= mysql_fetch_row(result))) Loading Loading @@ -2167,9 +2166,11 @@ static void dump_triggers_for_table(char *table, row[3] /* Statement */); } if (mysql_num_rows(result)) { fprintf(sql_file, "DELIMITER ;\n" "/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;\n"); "/*!50003 SET SESSION SQL_MODE=@SAVE_SQL_MODE*/;\n"); } mysql_free_result(result); /* make sure to set back opt_compatible mode to Loading mysql-test/r/create.result +29 −0 Original line number Diff line number Diff line Loading @@ -1503,4 +1503,33 @@ t1 CREATE TABLE `t1` ( `c17` int(11) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; Bug #26104 Bug on foreign key class constructor Check that ref_columns is initalized correctly in the constructor and semantic checks in mysql_prepare_table work. We do not need a storage engine that supports foreign keys for this test, as the checks are purely syntax-based, and the syntax is supported for all engines. drop table if exists t1,t2; create table t1(a int not null, b int not null, primary key (a, b)); create table t2(a int not null, b int not null, c int not null, primary key (a), foreign key fk_bug26104 (b,c) references t1(a)); ERROR 42000: Incorrect foreign key definition for 'fk_bug26104': Key reference and table reference don't match drop table t1; create table t1(f1 int,f2 int); insert into t1 value(1,1),(1,2),(1,3),(2,1),(2,2),(2,3); flush status; create table t2 select sql_big_result f1,count(f2) from t1 group by f1; show status like 'handler_read%'; Variable_name Value Handler_read_first 0 Handler_read_key 0 Handler_read_next 0 Handler_read_prev 0 Handler_read_rnd 0 Handler_read_rnd_next 7 drop table t1,t2; End of 5.0 tests mysql-test/r/having.result +19 −0 Original line number Diff line number Diff line Loading @@ -158,6 +158,25 @@ EXPLAIN SELECT 0 AS x, a FROM t1 GROUP BY x,a HAVING x=1 AND a > 1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible HAVING DROP table t1; CREATE TABLE t1 (a int PRIMARY KEY); CREATE TABLE t2 (b int PRIMARY KEY, a int); CREATE TABLE t3 (b int, flag int); INSERT INTO t1 VALUES (1); INSERT INTO t2 VALUES (1,1), (2,1), (3,1); INSERT INTO t3(b,flag) VALUES (2, 1); SELECT t1.a FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0; a SELECT DISTINCT t1.a, MAX(t3.flag) FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0; a MAX(t3.flag) SELECT DISTINCT t1.a FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0; a DROP TABLE t1,t2,t3; create table t1 (col1 int, col2 varchar(5), col_t1 int); create table t2 (col1 int, col2 varchar(5), col_t2 int); create table t3 (col1 int, col2 varchar(5), col_t3 int); Loading mysql-test/r/innodb.result +1 −1 Original line number Diff line number Diff line Loading @@ -1648,7 +1648,7 @@ t2 CREATE TABLE `t2` ( ) ENGINE=InnoDB DEFAULT CHARSET=latin1 drop table t2; create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb; ERROR HY000: Can't create table './test/t2' (errno: 150) ERROR 42000: Incorrect foreign key definition for 't1_id_fk': Key reference and table reference don't match create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb; show create table t2; Table Create Table Loading mysql-test/r/innodb_mysql.result +268 −0 Original line number Diff line number Diff line Loading @@ -739,4 +739,272 @@ drop table if exists t1; create table t1 (a int) engine=innodb; alter table t1 alter a set default 1; drop table t1; CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b)) ENGINE=InnoDB; INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2); INSERT INTO t1 SELECT a + 8, 2 FROM t1; INSERT INTO t1 SELECT a + 16, 1 FROM t1; EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a; id 1 select_type SIMPLE table t1 type ref possible_keys bkey key bkey key_len 5 ref const rows 16 Extra Using where; Using index SELECT * FROM t1 WHERE b=2 ORDER BY a; a b 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a; id 1 select_type SIMPLE table t1 type range possible_keys bkey key bkey key_len 5 ref NULL rows 16 Extra Using where; Using index; Using filesort SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a; a b 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a; id 1 select_type SIMPLE table t1 type range possible_keys bkey key bkey key_len 5 ref NULL rows 16 Extra Using where; Using index SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a; a b 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a), KEY bkey (b,c)) ENGINE=InnoDB; INSERT INTO t2 VALUES (1,1,1),(3,1,1),(2,1,1),(4,1,1); INSERT INTO t2 SELECT a + 4, 1, 1 FROM t2; INSERT INTO t2 SELECT a + 8, 1, 1 FROM t2; EXPLAIN SELECT * FROM t2 WHERE b=1 ORDER BY a; id 1 select_type SIMPLE table t2 type ref possible_keys bkey key bkey key_len 5 ref const rows 8 Extra Using where; Using index; Using filesort SELECT * FROM t2 WHERE b=1 ORDER BY a; a b c 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 1 14 1 1 15 1 1 16 1 1 EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a; id 1 select_type SIMPLE table t2 type ref possible_keys bkey key bkey key_len 10 ref const,const rows 8 Extra Using where; Using index SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a; a b c 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 1 14 1 1 15 1 1 16 1 1 EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a; id 1 select_type SIMPLE table t2 type ref possible_keys bkey key bkey key_len 10 ref const,const rows 8 Extra Using where; Using index SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a; a b c 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 1 14 1 1 15 1 1 16 1 1 EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a; id 1 select_type SIMPLE table t2 type ref possible_keys bkey key bkey key_len 10 ref const,const rows 8 Extra Using where; Using index SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a; a b c 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 1 14 1 1 15 1 1 16 1 1 DROP TABLE t1,t2; CREATE TABLE t1 (a INT, PRIMARY KEY (a)) ENGINE=InnoDB; INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8); INSERT INTO t1 SELECT a + 8 FROM t1; INSERT INTO t1 SELECT a + 16 FROM t1; CREATE PROCEDURE p1 () BEGIN DECLARE i INT DEFAULT 50; DECLARE cnt INT; START TRANSACTION; ALTER TABLE t1 ENGINE=InnoDB; COMMIT; START TRANSACTION; WHILE (i > 0) DO SET i = i - 1; SELECT COUNT(*) INTO cnt FROM t1 LOCK IN SHARE MODE; END WHILE; COMMIT; END;| CALL p1(); CALL p1(); CALL p1(); DROP PROCEDURE p1; DROP TABLE t1; End of 5.0 tests Loading
client/mysqldump.c +4 −3 Original line number Diff line number Diff line Loading @@ -2122,8 +2122,7 @@ static void dump_triggers_for_table(char *table, } if (mysql_num_rows(result)) { if (opt_compact) fprintf(sql_file, "\n/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n"); fprintf(sql_file, "\n/*!50003 SET @SAVE_SQL_MODE=@@SQL_MODE*/;\n"); fprintf(sql_file, "\nDELIMITER ;;\n"); } while ((row= mysql_fetch_row(result))) Loading Loading @@ -2167,9 +2166,11 @@ static void dump_triggers_for_table(char *table, row[3] /* Statement */); } if (mysql_num_rows(result)) { fprintf(sql_file, "DELIMITER ;\n" "/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;\n"); "/*!50003 SET SESSION SQL_MODE=@SAVE_SQL_MODE*/;\n"); } mysql_free_result(result); /* make sure to set back opt_compatible mode to Loading
mysql-test/r/create.result +29 −0 Original line number Diff line number Diff line Loading @@ -1503,4 +1503,33 @@ t1 CREATE TABLE `t1` ( `c17` int(11) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; Bug #26104 Bug on foreign key class constructor Check that ref_columns is initalized correctly in the constructor and semantic checks in mysql_prepare_table work. We do not need a storage engine that supports foreign keys for this test, as the checks are purely syntax-based, and the syntax is supported for all engines. drop table if exists t1,t2; create table t1(a int not null, b int not null, primary key (a, b)); create table t2(a int not null, b int not null, c int not null, primary key (a), foreign key fk_bug26104 (b,c) references t1(a)); ERROR 42000: Incorrect foreign key definition for 'fk_bug26104': Key reference and table reference don't match drop table t1; create table t1(f1 int,f2 int); insert into t1 value(1,1),(1,2),(1,3),(2,1),(2,2),(2,3); flush status; create table t2 select sql_big_result f1,count(f2) from t1 group by f1; show status like 'handler_read%'; Variable_name Value Handler_read_first 0 Handler_read_key 0 Handler_read_next 0 Handler_read_prev 0 Handler_read_rnd 0 Handler_read_rnd_next 7 drop table t1,t2; End of 5.0 tests
mysql-test/r/having.result +19 −0 Original line number Diff line number Diff line Loading @@ -158,6 +158,25 @@ EXPLAIN SELECT 0 AS x, a FROM t1 GROUP BY x,a HAVING x=1 AND a > 1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible HAVING DROP table t1; CREATE TABLE t1 (a int PRIMARY KEY); CREATE TABLE t2 (b int PRIMARY KEY, a int); CREATE TABLE t3 (b int, flag int); INSERT INTO t1 VALUES (1); INSERT INTO t2 VALUES (1,1), (2,1), (3,1); INSERT INTO t3(b,flag) VALUES (2, 1); SELECT t1.a FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0; a SELECT DISTINCT t1.a, MAX(t3.flag) FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0; a MAX(t3.flag) SELECT DISTINCT t1.a FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0; a DROP TABLE t1,t2,t3; create table t1 (col1 int, col2 varchar(5), col_t1 int); create table t2 (col1 int, col2 varchar(5), col_t2 int); create table t3 (col1 int, col2 varchar(5), col_t3 int); Loading
mysql-test/r/innodb.result +1 −1 Original line number Diff line number Diff line Loading @@ -1648,7 +1648,7 @@ t2 CREATE TABLE `t2` ( ) ENGINE=InnoDB DEFAULT CHARSET=latin1 drop table t2; create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb; ERROR HY000: Can't create table './test/t2' (errno: 150) ERROR 42000: Incorrect foreign key definition for 't1_id_fk': Key reference and table reference don't match create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb; show create table t2; Table Create Table Loading
mysql-test/r/innodb_mysql.result +268 −0 Original line number Diff line number Diff line Loading @@ -739,4 +739,272 @@ drop table if exists t1; create table t1 (a int) engine=innodb; alter table t1 alter a set default 1; drop table t1; CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b)) ENGINE=InnoDB; INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2); INSERT INTO t1 SELECT a + 8, 2 FROM t1; INSERT INTO t1 SELECT a + 16, 1 FROM t1; EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a; id 1 select_type SIMPLE table t1 type ref possible_keys bkey key bkey key_len 5 ref const rows 16 Extra Using where; Using index SELECT * FROM t1 WHERE b=2 ORDER BY a; a b 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a; id 1 select_type SIMPLE table t1 type range possible_keys bkey key bkey key_len 5 ref NULL rows 16 Extra Using where; Using index; Using filesort SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a; a b 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a; id 1 select_type SIMPLE table t1 type range possible_keys bkey key bkey key_len 5 ref NULL rows 16 Extra Using where; Using index SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a; a b 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a), KEY bkey (b,c)) ENGINE=InnoDB; INSERT INTO t2 VALUES (1,1,1),(3,1,1),(2,1,1),(4,1,1); INSERT INTO t2 SELECT a + 4, 1, 1 FROM t2; INSERT INTO t2 SELECT a + 8, 1, 1 FROM t2; EXPLAIN SELECT * FROM t2 WHERE b=1 ORDER BY a; id 1 select_type SIMPLE table t2 type ref possible_keys bkey key bkey key_len 5 ref const rows 8 Extra Using where; Using index; Using filesort SELECT * FROM t2 WHERE b=1 ORDER BY a; a b c 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 1 14 1 1 15 1 1 16 1 1 EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a; id 1 select_type SIMPLE table t2 type ref possible_keys bkey key bkey key_len 10 ref const,const rows 8 Extra Using where; Using index SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a; a b c 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 1 14 1 1 15 1 1 16 1 1 EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a; id 1 select_type SIMPLE table t2 type ref possible_keys bkey key bkey key_len 10 ref const,const rows 8 Extra Using where; Using index SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a; a b c 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 1 14 1 1 15 1 1 16 1 1 EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a; id 1 select_type SIMPLE table t2 type ref possible_keys bkey key bkey key_len 10 ref const,const rows 8 Extra Using where; Using index SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a; a b c 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 1 14 1 1 15 1 1 16 1 1 DROP TABLE t1,t2; CREATE TABLE t1 (a INT, PRIMARY KEY (a)) ENGINE=InnoDB; INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8); INSERT INTO t1 SELECT a + 8 FROM t1; INSERT INTO t1 SELECT a + 16 FROM t1; CREATE PROCEDURE p1 () BEGIN DECLARE i INT DEFAULT 50; DECLARE cnt INT; START TRANSACTION; ALTER TABLE t1 ENGINE=InnoDB; COMMIT; START TRANSACTION; WHILE (i > 0) DO SET i = i - 1; SELECT COUNT(*) INTO cnt FROM t1 LOCK IN SHARE MODE; END WHILE; COMMIT; END;| CALL p1(); CALL p1(); CALL p1(); DROP PROCEDURE p1; DROP TABLE t1; End of 5.0 tests