diff options
-rw-r--r-- | extra/my_print_defaults.c | 2 | ||||
m--------- | libmariadb | 0 | ||||
-rw-r--r-- | man/mysqlbinlog.1 | 21 | ||||
-rw-r--r-- | mysql-test/main/alter_table.result | 17 | ||||
-rw-r--r-- | mysql-test/main/alter_table.test | 12 | ||||
-rw-r--r-- | mysql-test/main/join_outer.result | 103 | ||||
-rw-r--r-- | mysql-test/main/join_outer.test | 122 | ||||
-rw-r--r-- | mysql-test/main/join_outer_jcl6.result | 103 | ||||
-rw-r--r-- | mysql-test/main/subselect_exists2in.result | 18 | ||||
-rw-r--r-- | mysql-test/main/subselect_exists2in.test | 23 | ||||
-rw-r--r-- | mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result | 1 | ||||
-rw-r--r-- | mysql-test/suite/binlog/t/binlog_statement_insert_delayed.test | 1 | ||||
-rw-r--r-- | mysys/mf_iocache.c | 2 | ||||
-rw-r--r-- | sql/item_subselect.cc | 30 | ||||
-rw-r--r-- | sql/mf_iocache.cc | 2 | ||||
-rw-r--r-- | sql/signal_handler.cc | 6 | ||||
-rw-r--r-- | sql/sql_derived.cc | 31 | ||||
-rw-r--r-- | sql/sql_parse.cc | 8 | ||||
-rw-r--r-- | sql/sql_table.cc | 4 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 6 |
20 files changed, 401 insertions, 111 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/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..079874f2f5d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7493,6 +7493,7 @@ mysql_new_select(LEX *lex, bool move_down, SELECT_LEX *select_lex) THD *thd= lex->thd; bool new_select= select_lex == NULL; DBUG_ENTER("mysql_new_select"); + Name_resolution_context *curr_context; if (new_select) { @@ -7500,9 +7501,13 @@ mysql_new_select(LEX *lex, bool move_down, SELECT_LEX *select_lex) DBUG_RETURN(1); select_lex->select_number= ++thd->lex->stmt_lex->current_select_number; select_lex->parent_lex= lex; /* Used in init_query. */ + curr_context= lex->context_stack.head(); select_lex->init_query(); select_lex->init_select(); } + else + curr_context= select_lex->parent_lex->context_stack.head(); + lex->nest_level++; if (lex->nest_level > (int) MAX_SELECT_NESTING) { @@ -7529,7 +7534,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/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; |