diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2021-04-21 07:25:48 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2021-04-21 07:25:48 +0300 |
commit | 75c01f39b1b4a6d27d36d075f8baab9bdda7cc7e (patch) | |
tree | dff54cd8894bf7f9b46847fb1d3e03690179cf11 | |
parent | 562bbf5212412437273a469fc59138a939f123cd (diff) | |
parent | 922e676b43c7b5cb0f20ca67c6d2222e2fc5ec03 (diff) | |
download | mariadb-git-75c01f39b1b4a6d27d36d075f8baab9bdda7cc7e.tar.gz |
Merge 10.2 into 10.3
30 files changed, 621 insertions, 123 deletions
diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c index 5992af3bb78..d75c3f51319 100644 --- a/extra/my_print_defaults.c +++ b/extra/my_print_defaults.c @@ -116,7 +116,7 @@ static void usage() { version(); puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); - puts("Prints all arguments that is give to some program using the default files"); + puts("Displays the options from option groups of option files, which is useful to see which options a particular tool will use"); printf("Usage: %s [OPTIONS] [groups]\n", my_progname); my_print_help(my_long_options); my_print_default_files(config_file); diff --git a/libmariadb b/libmariadb -Subproject fc431a035a21ac1d4ef25d9d3cd8c4d7e64a8ee +Subproject d19c7c69269fdf4e2af8943dd86c12e4e1664af diff --git a/man/mysqlbinlog.1 b/man/mysqlbinlog.1 index 879d3304122..6a382818ac6 100644 --- a/man/mysqlbinlog.1 +++ b/man/mysqlbinlog.1 @@ -1,6 +1,6 @@ '\" t .\" -.TH "\FBMYSQLBINLOG\FR" "1" "9 May 2017" "MariaDB 10\&.3" "MariaDB Database System" +.TH "\FBMYSQLBINLOG\FR" "1" "14 April 2021" "MariaDB 10\&.3" "MariaDB Database System" .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- @@ -1091,6 +1091,23 @@ This option is useful for point\-in\-time recovery\&. .sp -1 .IP \(bu 2.3 .\} +.\" mysqlbinlog: table option +.\" table option: mysqlbinlog +\fB\-\-table\fR, +\fB\-T\fR +.sp +List entries for just this table (local log only)\&. +.RE +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} + .\" mysqlbinlog: to-last-log option .\" to-last-log option: mysqlbinlog \fB\-\-to\-last\-log\fR, @@ -2107,7 +2124,7 @@ option can be used to prevent this header from being written\&. .SH "COPYRIGHT" .br .PP -Copyright 2007-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc., 2010-2015 MariaDB Foundation +Copyright 2007-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc., 2010-2021 MariaDB Foundation .PP This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. .PP diff --git a/mysql-test/main/alter_table.result b/mysql-test/main/alter_table.result index 2f3ac342aed..8a3fc640301 100644 --- a/mysql-test/main/alter_table.result +++ b/mysql-test/main/alter_table.result @@ -2528,6 +2528,23 @@ ALTER TABLE t1 ALTER COLUMN k1 SET DEFAULT (SELECT 1 FROM t2 limit 1); ERROR HY000: Function or expression 'select ...' cannot be used in the DEFAULT clause of `k1` DROP TABLE t1,t2; # +# MDEV-25403 ALTER TABLE wrongly checks for field's default value if AFTER is used +# +create table t1(t int, d date not null); +insert into t1 values (1,'2001-1-1'); +set sql_mode = "no_zero_date"; +alter table t1 change d d date not null after t, add i int; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `t` int(11) DEFAULT NULL, + `d` date NOT NULL, + `i` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +alter table t1 add x date not null; +ERROR 22007: Incorrect date value: '0000-00-00' for column `test`.`t1`.`x` at row 1 +drop table t1; +# # End of 10.2 tests # # diff --git a/mysql-test/main/alter_table.test b/mysql-test/main/alter_table.test index 36146195b67..fab57a49f5b 100644 --- a/mysql-test/main/alter_table.test +++ b/mysql-test/main/alter_table.test @@ -2051,6 +2051,18 @@ ALTER TABLE t1 ALTER COLUMN k1 SET DEFAULT (SELECT 1 FROM t2 limit 1); DROP TABLE t1,t2; --echo # +--echo # MDEV-25403 ALTER TABLE wrongly checks for field's default value if AFTER is used +--echo # +create table t1(t int, d date not null); +insert into t1 values (1,'2001-1-1'); +set sql_mode = "no_zero_date"; +alter table t1 change d d date not null after t, add i int; +show create table t1; +--error ER_TRUNCATED_WRONG_VALUE +alter table t1 add x date not null; +drop table t1; + +--echo # --echo # End of 10.2 tests --echo # diff --git a/mysql-test/main/join_outer.result b/mysql-test/main/join_outer.result index 796d01a0996..758d1eda7ae 100644 --- a/mysql-test/main/join_outer.result +++ b/mysql-test/main/join_outer.result @@ -2684,6 +2684,77 @@ id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV DROP TABLE t1,t2,t3,t4; # end of 10.1 tests # +# MDEV-25362: name resolution for subqueries in ON expressions +# +create table t1 (a int, b int); +create table t2 (c int, d int); +create table t3 (e int, f int); +create table t4 (g int, h int); +explain +select * +from +t1 left join +(t2 +join +t3 on +(t3.f=t1.a) +) on (t2.c=t1.a ); +ERROR 42S22: Unknown column 't1.a' in 'on clause' +explain +select * +from +t1 left join +(t2 +join +t3 on +(t3.f=(select max(g) from t4 where t4.h=t1.a)) +) on (t2.c=t1.a ); +ERROR 42S22: Unknown column 't1.a' in 'where clause' +drop table t1,t2,t3,t4; +create table t1 (a int); +insert into t1 values (1),(2); +create table t2 (b int); +insert into t2 values (1),(2); +create table t3 (c int); +insert into t3 values (1),(2); +select * from ( select * from t1 left join t2 +on b in (select x from t3 as sq1) +) as sq2; +ERROR 42S22: Unknown column 'x' in 'field list' +drop table t1,t2,t3; +# end of 10.2 tests +# +# MDEV-22866: Crash in join optimizer with constant outer join nest +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3),(4); +CREATE TABLE t3 (c INT, KEY(c)) ENGINE=MyISAM; +CREATE TABLE t4 (d INT, KEY(d)) ENGINE=MyISAM; +INSERT INTO t4 VALUES (5),(6); +CREATE TABLE t5 (e INT) ENGINE=MyISAM; +INSERT INTO t5 VALUES (7),(8); +CREATE TABLE t6 (f INT) ENGINE=MyISAM; +INSERT INTO t6 VALUES (9),(10); +SELECT * +FROM +t1 +LEFT JOIN ( +t2 LEFT JOIN ( +t3 JOIN +t4 ON t3.c = t4.d and t3.c >2 and t3.c<0 +) ON t2.b >= t4.d +) ON t1.a <= t2.b +LEFT JOIN t5 ON t2.b = t5.e +LEFT JOIN t6 ON t3.c = t6.f; +a b c d e f +1 3 NULL NULL NULL NULL +1 4 NULL NULL NULL NULL +2 3 NULL NULL NULL NULL +2 4 NULL NULL NULL NULL +drop table t1,t2,t3,t4,t5,t6; +# # MDEV-17518: Range optimization doesn't use ON expressions from nested outer joins # create table t1(a int); @@ -2751,35 +2822,5 @@ WHERE t3.pk IN (2); 1 drop view v4; drop table t1,t2,t3,t4; +# end of 10.3 tests SET optimizer_switch=@org_optimizer_switch; -# -# MDEV-22866: Crash in join optimizer with constant outer join nest -# -CREATE TABLE t1 (a INT) ENGINE=MyISAM; -INSERT INTO t1 VALUES (1),(2); -CREATE TABLE t2 (b INT) ENGINE=MyISAM; -INSERT INTO t2 VALUES (3),(4); -CREATE TABLE t3 (c INT, KEY(c)) ENGINE=MyISAM; -CREATE TABLE t4 (d INT, KEY(d)) ENGINE=MyISAM; -INSERT INTO t4 VALUES (5),(6); -CREATE TABLE t5 (e INT) ENGINE=MyISAM; -INSERT INTO t5 VALUES (7),(8); -CREATE TABLE t6 (f INT) ENGINE=MyISAM; -INSERT INTO t6 VALUES (9),(10); -SELECT * -FROM -t1 -LEFT JOIN ( -t2 LEFT JOIN ( -t3 JOIN -t4 ON t3.c = t4.d and t3.c >2 and t3.c<0 -) ON t2.b >= t4.d -) ON t1.a <= t2.b -LEFT JOIN t5 ON t2.b = t5.e -LEFT JOIN t6 ON t3.c = t6.f; -a b c d e f -1 3 NULL NULL NULL NULL -2 3 NULL NULL NULL NULL -1 4 NULL NULL NULL NULL -2 4 NULL NULL NULL NULL -drop table t1,t2,t3,t4,t5,t6; diff --git a/mysql-test/main/join_outer.test b/mysql-test/main/join_outer.test index f835d8af5a8..82c7b265b56 100644 --- a/mysql-test/main/join_outer.test +++ b/mysql-test/main/join_outer.test @@ -2192,6 +2192,91 @@ DROP TABLE t1,t2,t3,t4; --echo # end of 10.1 tests --echo # +--echo # MDEV-25362: name resolution for subqueries in ON expressions +--echo # + +create table t1 (a int, b int); +create table t2 (c int, d int); +create table t3 (e int, f int); +create table t4 (g int, h int); + +--error ER_BAD_FIELD_ERROR +explain +select * +from + t1 left join + (t2 + join + t3 on + (t3.f=t1.a) + ) on (t2.c=t1.a ); + +# This must produce an error: +--error ER_BAD_FIELD_ERROR +explain +select * +from + t1 left join + (t2 + join + t3 on + (t3.f=(select max(g) from t4 where t4.h=t1.a)) + ) on (t2.c=t1.a ); + +drop table t1,t2,t3,t4; + +create table t1 (a int); +insert into t1 values (1),(2); +create table t2 (b int); +insert into t2 values (1),(2); +create table t3 (c int); +insert into t3 values (1),(2); + +--error ER_BAD_FIELD_ERROR +select * from ( select * from t1 left join t2 + on b in (select x from t3 as sq1) + ) as sq2; + +drop table t1,t2,t3; + +--echo # end of 10.2 tests + +--echo # +--echo # MDEV-22866: Crash in join optimizer with constant outer join nest +--echo # + +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); + +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3),(4); + +CREATE TABLE t3 (c INT, KEY(c)) ENGINE=MyISAM; + +CREATE TABLE t4 (d INT, KEY(d)) ENGINE=MyISAM; +INSERT INTO t4 VALUES (5),(6); + +CREATE TABLE t5 (e INT) ENGINE=MyISAM; +INSERT INTO t5 VALUES (7),(8); + +CREATE TABLE t6 (f INT) ENGINE=MyISAM; +INSERT INTO t6 VALUES (9),(10); + +SELECT * +FROM + t1 + LEFT JOIN ( + t2 LEFT JOIN ( + t3 JOIN + t4 ON t3.c = t4.d and t3.c >2 and t3.c<0 + ) ON t2.b >= t4.d + ) ON t1.a <= t2.b + LEFT JOIN t5 ON t2.b = t5.e + LEFT JOIN t6 ON t3.c = t6.f; + +drop table t1,t2,t3,t4,t5,t6; + +--echo # --echo # MDEV-17518: Range optimization doesn't use ON expressions from nested outer joins --echo # create table t1(a int); @@ -2251,39 +2336,6 @@ WHERE t3.pk IN (2); drop view v4; drop table t1,t2,t3,t4; -SET optimizer_switch=@org_optimizer_switch; - ---echo # ---echo # MDEV-22866: Crash in join optimizer with constant outer join nest ---echo # - -CREATE TABLE t1 (a INT) ENGINE=MyISAM; -INSERT INTO t1 VALUES (1),(2); +--echo # end of 10.3 tests -CREATE TABLE t2 (b INT) ENGINE=MyISAM; -INSERT INTO t2 VALUES (3),(4); - -CREATE TABLE t3 (c INT, KEY(c)) ENGINE=MyISAM; - -CREATE TABLE t4 (d INT, KEY(d)) ENGINE=MyISAM; -INSERT INTO t4 VALUES (5),(6); - -CREATE TABLE t5 (e INT) ENGINE=MyISAM; -INSERT INTO t5 VALUES (7),(8); - -CREATE TABLE t6 (f INT) ENGINE=MyISAM; -INSERT INTO t6 VALUES (9),(10); - -SELECT * -FROM - t1 - LEFT JOIN ( - t2 LEFT JOIN ( - t3 JOIN - t4 ON t3.c = t4.d and t3.c >2 and t3.c<0 - ) ON t2.b >= t4.d - ) ON t1.a <= t2.b - LEFT JOIN t5 ON t2.b = t5.e - LEFT JOIN t6 ON t3.c = t6.f; - -drop table t1,t2,t3,t4,t5,t6; +SET optimizer_switch=@org_optimizer_switch; diff --git a/mysql-test/main/join_outer_jcl6.result b/mysql-test/main/join_outer_jcl6.result index 4f66b004cfc..71579ae7b38 100644 --- a/mysql-test/main/join_outer_jcl6.result +++ b/mysql-test/main/join_outer_jcl6.result @@ -2691,6 +2691,77 @@ id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV DROP TABLE t1,t2,t3,t4; # end of 10.1 tests # +# MDEV-25362: name resolution for subqueries in ON expressions +# +create table t1 (a int, b int); +create table t2 (c int, d int); +create table t3 (e int, f int); +create table t4 (g int, h int); +explain +select * +from +t1 left join +(t2 +join +t3 on +(t3.f=t1.a) +) on (t2.c=t1.a ); +ERROR 42S22: Unknown column 't1.a' in 'on clause' +explain +select * +from +t1 left join +(t2 +join +t3 on +(t3.f=(select max(g) from t4 where t4.h=t1.a)) +) on (t2.c=t1.a ); +ERROR 42S22: Unknown column 't1.a' in 'where clause' +drop table t1,t2,t3,t4; +create table t1 (a int); +insert into t1 values (1),(2); +create table t2 (b int); +insert into t2 values (1),(2); +create table t3 (c int); +insert into t3 values (1),(2); +select * from ( select * from t1 left join t2 +on b in (select x from t3 as sq1) +) as sq2; +ERROR 42S22: Unknown column 'x' in 'field list' +drop table t1,t2,t3; +# end of 10.2 tests +# +# MDEV-22866: Crash in join optimizer with constant outer join nest +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3),(4); +CREATE TABLE t3 (c INT, KEY(c)) ENGINE=MyISAM; +CREATE TABLE t4 (d INT, KEY(d)) ENGINE=MyISAM; +INSERT INTO t4 VALUES (5),(6); +CREATE TABLE t5 (e INT) ENGINE=MyISAM; +INSERT INTO t5 VALUES (7),(8); +CREATE TABLE t6 (f INT) ENGINE=MyISAM; +INSERT INTO t6 VALUES (9),(10); +SELECT * +FROM +t1 +LEFT JOIN ( +t2 LEFT JOIN ( +t3 JOIN +t4 ON t3.c = t4.d and t3.c >2 and t3.c<0 +) ON t2.b >= t4.d +) ON t1.a <= t2.b +LEFT JOIN t5 ON t2.b = t5.e +LEFT JOIN t6 ON t3.c = t6.f; +a b c d e f +1 3 NULL NULL NULL NULL +2 3 NULL NULL NULL NULL +1 4 NULL NULL NULL NULL +2 4 NULL NULL NULL NULL +drop table t1,t2,t3,t4,t5,t6; +# # MDEV-17518: Range optimization doesn't use ON expressions from nested outer joins # create table t1(a int); @@ -2758,35 +2829,5 @@ WHERE t3.pk IN (2); 1 drop view v4; drop table t1,t2,t3,t4; +# end of 10.3 tests SET optimizer_switch=@org_optimizer_switch; -# -# MDEV-22866: Crash in join optimizer with constant outer join nest -# -CREATE TABLE t1 (a INT) ENGINE=MyISAM; -INSERT INTO t1 VALUES (1),(2); -CREATE TABLE t2 (b INT) ENGINE=MyISAM; -INSERT INTO t2 VALUES (3),(4); -CREATE TABLE t3 (c INT, KEY(c)) ENGINE=MyISAM; -CREATE TABLE t4 (d INT, KEY(d)) ENGINE=MyISAM; -INSERT INTO t4 VALUES (5),(6); -CREATE TABLE t5 (e INT) ENGINE=MyISAM; -INSERT INTO t5 VALUES (7),(8); -CREATE TABLE t6 (f INT) ENGINE=MyISAM; -INSERT INTO t6 VALUES (9),(10); -SELECT * -FROM -t1 -LEFT JOIN ( -t2 LEFT JOIN ( -t3 JOIN -t4 ON t3.c = t4.d and t3.c >2 and t3.c<0 -) ON t2.b >= t4.d -) ON t1.a <= t2.b -LEFT JOIN t5 ON t2.b = t5.e -LEFT JOIN t6 ON t3.c = t6.f; -a b c d e f -1 3 NULL NULL NULL NULL -2 3 NULL NULL NULL NULL -1 4 NULL NULL NULL NULL -2 4 NULL NULL NULL NULL -drop table t1,t2,t3,t4,t5,t6; diff --git a/mysql-test/main/subselect_exists2in.result b/mysql-test/main/subselect_exists2in.result index a06988a7f9c..16136fcb5ae 100644 --- a/mysql-test/main/subselect_exists2in.result +++ b/mysql-test/main/subselect_exists2in.result @@ -1099,4 +1099,22 @@ U5.`storage_target_id` = V0.`id` ); id drop table t1,t2,t3; +# +# MDEV-25407: EXISTS subquery with correlation in ON expression crashes +# +create table t10(a int primary key); +insert into t10 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t11(a int primary key); +insert into t11 select a.a + b.a* 10 + c.a * 100 from t10 a, t10 b, t10 c; +create table t1 (a int, b int); +insert into t1 select a,a from t10; +create table t2 (a int, b int); +insert into t2 select a,a from t11; +create table t3 as select * from t2; +explain select * from t1 where exists (select t2.a from t2 left join t3 on (t3.b=t1.b) where t2.a=t1.a); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 10 +1 PRIMARY t2 ALL NULL NULL NULL NULL 1000 Using where; Start temporary; Using join buffer (flat, BNL join) +1 PRIMARY t3 ALL NULL NULL NULL NULL 1000 Using where; End temporary; Using join buffer (incremental, BNL join) +drop table t1, t2, t3, t10, t11; set optimizer_switch=default; diff --git a/mysql-test/main/subselect_exists2in.test b/mysql-test/main/subselect_exists2in.test index e27ce57038b..e70d643138b 100644 --- a/mysql-test/main/subselect_exists2in.test +++ b/mysql-test/main/subselect_exists2in.test @@ -941,5 +941,28 @@ WHERE ( drop table t1,t2,t3; +--echo # +--echo # MDEV-25407: EXISTS subquery with correlation in ON expression crashes +--echo # +create table t10(a int primary key); +insert into t10 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t11(a int primary key); +insert into t11 select a.a + b.a* 10 + c.a * 100 from t10 a, t10 b, t10 c; + +create table t1 (a int, b int); +insert into t1 select a,a from t10; + +create table t2 (a int, b int); +insert into t2 select a,a from t11; + +create table t3 as select * from t2; + + +explain select * from t1 where exists (select t2.a from t2 left join t3 on (t3.b=t1.b) where t2.a=t1.a); + +drop table t1, t2, t3, t10, t11; + + #restore defaults set optimizer_switch=default; diff --git a/mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result b/mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result index d6875ab60e0..a4cd5b4080d 100644 --- a/mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result +++ b/mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result @@ -50,3 +50,4 @@ a 400 401 drop table t1; +reset master; diff --git a/mysql-test/suite/binlog/t/binlog_statement_insert_delayed.test b/mysql-test/suite/binlog/t/binlog_statement_insert_delayed.test index b2af560fa50..9145afc047f 100644 --- a/mysql-test/suite/binlog/t/binlog_statement_insert_delayed.test +++ b/mysql-test/suite/binlog/t/binlog_statement_insert_delayed.test @@ -10,3 +10,4 @@ disable_query_log; call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); enable_query_log; -- source include/binlog_insert_delayed.test +reset master; diff --git a/mysql-test/suite/innodb/r/temporary_table.result b/mysql-test/suite/innodb/r/temporary_table.result index 94c2cfc63b1..0211fce72b2 100644 --- a/mysql-test/suite/innodb/r/temporary_table.result +++ b/mysql-test/suite/innodb/r/temporary_table.result @@ -671,3 +671,99 @@ SET FOREIGN_KEY_CHECKS = 0; CREATE TEMPORARY TABLE t1(f1 INT NOT NULL, FOREIGN KEY(f1) REFERENCES t0(f1))ENGINE=InnoDB; ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") +CREATE TABLE t (c INT) ENGINE=InnoDB; +INSERT INTO t VALUES(0); +CREATE TEMPORARY TABLE t2 (c INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +INSERT INTO t2 SELECT * FROM t; +COMMIT; +DROP TABLE t, t2; +CREATE TEMPORARY TABLE t (c INT,c2 INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +INSERT INTO t VALUES(0); +ERROR 21S01: Column count doesn't match value count at row 1 +SAVEPOINT s; +INSERT INTO t VALUES(0,0); +COMMIT; +DROP TABLE t; +CREATE TEMPORARY TABLE t (c INT,c2 INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +INSERT INTO t VALUES(0); +ERROR 21S01: Column count doesn't match value count at row 1 +SAVEPOINT s; +INSERT INTO t VALUES(0,0); +ROLLBACK; +DROP TABLE t; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +COMMIT; +DROP TABLE t1; +CREATE TEMPORARY TABLE t(c INT) ENGINE=InnoDB; +SET SESSION tx_read_only=TRUE; +LOCK TABLE test.t READ; +SELECT * FROM t; +c +INSERT INTO t VALUES(0xADC3); +SET SESSION tx_read_only=FALSE; +DROP TABLE t; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +COMMIT; +DROP TABLE t1; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY, b int) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 1); +START TRANSACTION READ ONLY; +UPDATE t1 SET b= 2; +COMMIT; +DROP TABLE t1; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY, b int, c varchar(255)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 1, repeat('a', 200)); +START TRANSACTION READ ONLY; +UPDATE t1 SET b= 2, c=repeat('a', 250); +COMMIT; +DROP TABLE t1; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +ROLLBACK; +DROP TABLE t1; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +DELETE FROM t1 WHERE a= 2; +COMMIT; +DROP TABLE t1; +CREATE TEMPORARY TABLE tmp (a INT) ENGINE=InnoDB; +INSERT INTO tmp () VALUES (),(); +SET TX_READ_ONLY= 1; +INSERT INTO tmp SELECT * FROM tmp; +SET TX_READ_ONLY= 0; +DROP TABLE tmp; +SET sql_mode=''; +SET GLOBAL tx_read_only=TRUE; +CREATE TEMPORARY TABLE t (c INT); +SET SESSION tx_read_only=DEFAULT; +INSERT INTO t VALUES(1); +INSERT INTO t SELECT * FROM t; +SET SESSION tx_read_only=FALSE; +SET GLOBAL tx_read_only=OFF; +DROP TABLE t; +CREATE TEMPORARY TABLE t(a INT); +SET SESSION tx_read_only=ON; +LOCK TABLE t READ; +SELECT COUNT(*)FROM t; +COUNT(*) +0 +INSERT INTO t VALUES (0); +SET SESSION tx_read_only=OFF; +DROP TABLE t; +CREATE TEMPORARY TABLE t (a INT) ENGINE=InnoDB; +INSERT INTO t VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t SET a = NULL; +ROLLBACK; diff --git a/mysql-test/suite/innodb/t/temporary_table.test b/mysql-test/suite/innodb/t/temporary_table.test index 8e3ddf95634..13c203b587b 100644 --- a/mysql-test/suite/innodb/t/temporary_table.test +++ b/mysql-test/suite/innodb/t/temporary_table.test @@ -502,3 +502,110 @@ SET FOREIGN_KEY_CHECKS = 0; --error ER_CANT_CREATE_TABLE CREATE TEMPORARY TABLE t1(f1 INT NOT NULL, FOREIGN KEY(f1) REFERENCES t0(f1))ENGINE=InnoDB; + +CREATE TABLE t (c INT) ENGINE=InnoDB; +INSERT INTO t VALUES(0); +CREATE TEMPORARY TABLE t2 (c INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +INSERT INTO t2 SELECT * FROM t; +COMMIT; +DROP TABLE t, t2; + +CREATE TEMPORARY TABLE t (c INT,c2 INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +--error ER_WRONG_VALUE_COUNT_ON_ROW +INSERT INTO t VALUES(0); +SAVEPOINT s; +INSERT INTO t VALUES(0,0); +COMMIT; +DROP TABLE t; + +CREATE TEMPORARY TABLE t (c INT,c2 INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +--error ER_WRONG_VALUE_COUNT_ON_ROW +INSERT INTO t VALUES(0); +SAVEPOINT s; +INSERT INTO t VALUES(0,0); +ROLLBACK; +DROP TABLE t; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +COMMIT; +DROP TABLE t1; + +CREATE TEMPORARY TABLE t(c INT) ENGINE=InnoDB; +SET SESSION tx_read_only=TRUE; +LOCK TABLE test.t READ; +SELECT * FROM t; +INSERT INTO t VALUES(0xADC3); +SET SESSION tx_read_only=FALSE; +DROP TABLE t; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +COMMIT; +DROP TABLE t1; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY, b int) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 1); +START TRANSACTION READ ONLY; +UPDATE t1 SET b= 2; +COMMIT; +DROP TABLE t1; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY, b int, c varchar(255)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 1, repeat('a', 200)); +START TRANSACTION READ ONLY; +UPDATE t1 SET b= 2, c=repeat('a', 250); +COMMIT; +DROP TABLE t1; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +ROLLBACK; +DROP TABLE t1; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +DELETE FROM t1 WHERE a= 2; +COMMIT; +DROP TABLE t1; + +CREATE TEMPORARY TABLE tmp (a INT) ENGINE=InnoDB; +INSERT INTO tmp () VALUES (),(); +SET TX_READ_ONLY= 1; +INSERT INTO tmp SELECT * FROM tmp; +SET TX_READ_ONLY= 0; +DROP TABLE tmp; + +SET sql_mode=''; +SET GLOBAL tx_read_only=TRUE; +CREATE TEMPORARY TABLE t (c INT); +SET SESSION tx_read_only=DEFAULT; +INSERT INTO t VALUES(1); +INSERT INTO t SELECT * FROM t; +SET SESSION tx_read_only=FALSE; +SET GLOBAL tx_read_only=OFF; +DROP TABLE t; + +CREATE TEMPORARY TABLE t(a INT); +SET SESSION tx_read_only=ON; +LOCK TABLE t READ; +SELECT COUNT(*)FROM t; +INSERT INTO t VALUES (0); +SET SESSION tx_read_only=OFF; +DROP TABLE t; + +CREATE TEMPORARY TABLE t (a INT) ENGINE=InnoDB; +INSERT INTO t VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t SET a = NULL; +ROLLBACK; diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c index 917ccd160ee..41b586f44ab 100644 --- a/mysys/mf_iocache.c +++ b/mysys/mf_iocache.c @@ -1603,7 +1603,7 @@ int _my_b_async_read(IO_CACHE *info, uchar *Buffer, size_t Count) Buffer+=length; Count-=length; left_length+=length; - info->read_end=info->rc_pos+read_length; + info->read_end=info->read_pos+read_length; info->read_pos+=length; } else diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 8a00c12722c..bedf85e3699 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -673,6 +673,31 @@ bool Item_subselect::is_expensive() } +static +int walk_items_for_table_list(Item_processor processor, + bool walk_subquery, void *argument, + List<TABLE_LIST>& join_list) +{ + List_iterator<TABLE_LIST> li(join_list); + int res; + while (TABLE_LIST *table= li++) + { + if (table->on_expr) + { + if ((res= table->on_expr->walk(processor, walk_subquery, argument))) + return res; + } + if (table->nested_join) + { + if ((res= walk_items_for_table_list(processor, walk_subquery, argument, + table->nested_join->join_list))) + return res; + } + } + return 0; +} + + bool Item_subselect::walk(Item_processor processor, bool walk_subquery, void *argument) { @@ -704,7 +729,10 @@ bool Item_subselect::walk(Item_processor processor, bool walk_subquery, if (lex->having && (lex->having)->walk(processor, walk_subquery, argument)) return 1; - /* TODO: why does this walk WHERE/HAVING but not ON expressions of outer joins? */ + + if (walk_items_for_table_list(processor, walk_subquery, argument, + *lex->join_list)) + return 1; while ((item=li++)) { diff --git a/sql/mf_iocache.cc b/sql/mf_iocache.cc index c9cff6ad930..877a49edbec 100644 --- a/sql/mf_iocache.cc +++ b/sql/mf_iocache.cc @@ -26,7 +26,7 @@ Used instead of FILE when reading or writing whole files. This will make mf_rec_cache obsolete. One can change info->pos_in_file to a higher value to skip bytes in file if - also info->rc_pos is set to info->rc_end. + also info->read_pos is set to info->read_end. If called through open_cached_file(), then the temporary file will only be created if a write exeeds the file buffer or if one calls flush_io_cache(). diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index 79fb77e38d2..c0f31077e4d 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -31,7 +31,7 @@ #endif -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__FreeBSD__) #include <sys/sysctl.h> #endif @@ -56,7 +56,7 @@ extern const char *optimizer_switch_names[]; static inline void output_core_info() { /* proc is optional on some BSDs so it can't hurt to look */ -#if defined(HAVE_READLINK) && !defined(__APPLE__) +#if defined(HAVE_READLINK) && !defined(__APPLE__) && !defined(__FreeBSD__) char buff[PATH_MAX]; ssize_t len; int fd; @@ -82,7 +82,7 @@ static inline void output_core_info() my_close(fd, MYF(0)); } #endif -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__FreeBSD__) char buff[PATH_MAX]; size_t len = sizeof(buff); if (sysctlbyname("kern.corefile", buff, &len, NULL, 0) == 0) diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 8a76a5372cc..50b0178c6c9 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -562,6 +562,32 @@ bool mysql_derived_init(THD *thd, LEX *lex, TABLE_LIST *derived) /* + @brief + Prevent name resolution out of context of ON expressions in derived tables + + @param + join_list list of tables used in from list of a derived + + @details + The function sets the Name_resolution_context::outer_context to NULL + for all ON expressions contexts in the given join list. It does this + recursively for all nested joins the list contains. +*/ + +static void nullify_outer_context_for_on_clauses(List<TABLE_LIST>& join_list) +{ + List_iterator<TABLE_LIST> li(join_list); + while (TABLE_LIST *table= li++) + { + if (table->on_context) + table->on_context->outer_context= NULL; + if (table->nested_join) + nullify_outer_context_for_on_clauses(table->nested_join->join_list); + } +} + + +/* Create temporary table structure (but do not fill it) @param thd Thread handle @@ -726,7 +752,12 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) /* prevent name resolving out of derived table */ for (SELECT_LEX *sl= first_select; sl; sl= sl->next_select()) { + // Prevent it for the WHERE clause sl->context.outer_context= 0; + + // And for ON clauses, if there are any + nullify_outer_context_for_on_clauses(*sl->join_list); + if (!derived->is_with_table_recursive_reference() || (!derived->with->with_anchor && !derived->with->is_with_prepared_anchor())) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 1208ed536e1..b16091dbab4 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7492,6 +7492,7 @@ mysql_new_select(LEX *lex, bool move_down, SELECT_LEX *select_lex) { THD *thd= lex->thd; bool new_select= select_lex == NULL; + Name_resolution_context *curr_context= lex->context_stack.head(); DBUG_ENTER("mysql_new_select"); if (new_select) @@ -7529,7 +7530,8 @@ mysql_new_select(LEX *lex, bool move_down, SELECT_LEX *select_lex) By default we assume that it is usual subselect and we have outer name resolution context, if no we will assign it to 0 later */ - select_lex->context.outer_context= &select_lex->outer_select()->context; + + select_lex->context.outer_context= curr_context; } else { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 64336ed02af..a6347c58c21 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1,6 +1,6 @@ /* Copyright (c) 2000, 2019, Oracle and/or its affiliates. - Copyright (c) 2010, 2020, MariaDB + Copyright (c) 2010, 2021, MariaDB 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 @@ -8247,7 +8247,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, def->real_field_type() == MYSQL_TYPE_NEWDATE || def->real_field_type() == MYSQL_TYPE_DATETIME || def->real_field_type() == MYSQL_TYPE_DATETIME2) && - !alter_ctx->datetime_field && + !alter_ctx->datetime_field && !def->field && !(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) && thd->variables.sql_mode & MODE_NO_ZERO_DATE) { diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 45ba84e319c..66e680ae494 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -3461,7 +3461,8 @@ fail_err: ut_ad(thr->graph->trx->id == trx_read_trx_id( static_cast<const byte*>( - trx_id->data))); + trx_id->data)) + || index->table->is_temporary()); } } #endif @@ -4075,7 +4076,8 @@ btr_cur_update_in_place( index = cursor->index; ut_ad(rec_offs_validate(rec, index, offsets)); ut_ad(!!page_rec_is_comp(rec) == dict_table_is_comp(index->table)); - ut_ad(trx_id > 0 || (flags & BTR_KEEP_SYS_FLAG)); + ut_ad(trx_id > 0 || (flags & BTR_KEEP_SYS_FLAG) + || index->table->is_temporary()); /* The insert buffer tree should never be updated in place. */ ut_ad(!dict_index_is_ibuf(index)); ut_ad(dict_index_is_online_ddl(index) == !!(flags & BTR_CREATE_FLAG) @@ -4304,7 +4306,8 @@ btr_cur_optimistic_update( page = buf_block_get_frame(block); rec = btr_cur_get_rec(cursor); index = cursor->index; - ut_ad(trx_id > 0 || (flags & BTR_KEEP_SYS_FLAG)); + ut_ad(trx_id > 0 || (flags & BTR_KEEP_SYS_FLAG) + || index->table->is_temporary()); ut_ad(!!page_rec_is_comp(rec) == dict_table_is_comp(index->table)); ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX)); /* This is intended only for leaf page updates */ @@ -4661,8 +4664,8 @@ btr_cur_pessimistic_update( ut_ad(!page_zip || !index->table->is_temporary()); /* The insert buffer tree should never be updated in place. */ ut_ad(!dict_index_is_ibuf(index)); - ut_ad(trx_id > 0 - || (flags & BTR_KEEP_SYS_FLAG)); + ut_ad(trx_id > 0 || (flags & BTR_KEEP_SYS_FLAG) + || index->table->is_temporary()); ut_ad(dict_index_is_online_ddl(index) == !!(flags & BTR_CREATE_FLAG) || dict_index_is_clust(index)); ut_ad(thr_get_trx(thr)->id == trx_id diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index d943610e2b2..862ed7e41a4 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -6193,8 +6193,10 @@ no_such_table: innobase_copy_frm_flags_from_table_share(ib_table, table->s); - /* No point to init any statistics if tablespace is still encrypted. */ - if (ib_table->is_readable()) { + /* No point to init any statistics if tablespace is still encrypted + or if table is being opened by background thread */ + if (THDVAR(thd, background_thread)) { + } else if (ib_table->is_readable()) { dict_stats_init(ib_table); } else { ib_table->stat_initialized = 1; diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h index 30ee5f5833d..35ac8e12001 100644 --- a/storage/innobase/include/trx0sys.h +++ b/storage/innobase/include/trx0sys.h @@ -94,7 +94,6 @@ void trx_write_trx_id(byte* db_trx_id, trx_id_t id) { compile_time_assert(DATA_TRX_ID_LEN == 6); - ut_ad(id); mach_write_to_6(db_trx_id, id); } diff --git a/storage/innobase/pars/pars0pars.cc b/storage/innobase/pars/pars0pars.cc index 43f089e3bf7..6a187787c12 100644 --- a/storage/innobase/pars/pars0pars.cc +++ b/storage/innobase/pars/pars0pars.cc @@ -1219,6 +1219,7 @@ pars_update_statement( sel_node->row_lock_mode = LOCK_X; } else { node->has_clust_rec_x_lock = sel_node->set_x_locks; + ut_ad(node->has_clust_rec_x_lock); } ut_a(sel_node->n_tables == 1); diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 9247c7680bc..512d373bbfa 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -3327,7 +3327,8 @@ row_ins_index_entry( dtuple_t* entry, /*!< in/out: index entry to insert */ que_thr_t* thr) /*!< in: query thread */ { - ut_ad(thr_get_trx(thr)->id || index->table->no_rollback()); + ut_ad(thr_get_trx(thr)->id || index->table->no_rollback() + || index->table->is_temporary()); DBUG_EXECUTE_IF("row_ins_index_entry_timeout", { DBUG_SET("-d,row_ins_index_entry_timeout"); @@ -3737,13 +3738,17 @@ row_ins_step( } if (UNIV_LIKELY(!node->table->skip_alter_undo)) { - trx_write_trx_id(&node->sys_buf[DATA_ROW_ID_LEN], trx->id); + trx_write_trx_id(&node->sys_buf[DATA_TRX_ID_LEN], trx->id); } if (node->state == INS_NODE_SET_IX_LOCK) { node->state = INS_NODE_ALLOC_ROW_ID; + if (node->table->is_temporary()) { + node->trx_id = trx->id; + } + /* It may be that the current session has not yet started its transaction, or it has been committed: */ diff --git a/storage/innobase/row/row0uins.cc b/storage/innobase/row/row0uins.cc index 756d6d54024..304ec71a63a 100644 --- a/storage/innobase/row/row0uins.cc +++ b/storage/innobase/row/row0uins.cc @@ -108,7 +108,7 @@ row_undo_ins_remove_clust_rec( btr_cur = btr_pcur_get_btr_cur(&node->pcur); ut_ad(rec_get_trx_id(btr_cur_get_rec(btr_cur), btr_cur->index) - == node->trx->id); + == node->trx->id || node->table->is_temporary()); ut_ad(!rec_get_deleted_flag( btr_cur_get_rec(btr_cur), dict_table_is_comp(btr_cur->index->table))); diff --git a/storage/innobase/row/row0umod.cc b/storage/innobase/row/row0umod.cc index c7c19eaadb2..88e87e2f9bc 100644 --- a/storage/innobase/row/row0umod.cc +++ b/storage/innobase/row/row0umod.cc @@ -110,7 +110,8 @@ row_undo_mod_clust_low( ut_ad(success); ut_ad(rec_get_trx_id(btr_cur_get_rec(btr_cur), btr_cur_get_index(btr_cur)) - == thr_get_trx(thr)->id); + == thr_get_trx(thr)->id + || btr_cur_get_index(btr_cur)->table->is_temporary()); if (mode != BTR_MODIFY_LEAF && dict_index_is_online_ddl(btr_cur_get_index(btr_cur))) { diff --git a/storage/innobase/row/row0undo.cc b/storage/innobase/row/row0undo.cc index a8c35186a7d..b8be086e875 100644 --- a/storage/innobase/row/row0undo.cc +++ b/storage/innobase/row/row0undo.cc @@ -196,7 +196,7 @@ row_undo_search_clust_to_pcur( if (found) { ut_ad(row_get_rec_trx_id(rec, clust_index, offsets) - == node->trx->id); + == node->trx->id || node->table->is_temporary()); if (dict_table_has_atomic_blobs(node->table)) { /* There is no prefix of externally stored diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index c85caa30fe6..600034c8ba3 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -515,7 +515,7 @@ row_upd_index_entry_sys_field( field = static_cast<byte*>(dfield_get_data(dfield)); if (type == DATA_TRX_ID) { - ut_ad(val > 0); + ut_ad(val > 0 || index->table->is_temporary()); trx_write_trx_id(field, val); } else { ut_ad(type == DATA_ROLL_PTR); |