diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2019-12-27 18:20:28 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2019-12-27 18:20:28 +0200 |
commit | 4c25e75ce766440694553e0baf03cc5c6e803fc3 (patch) | |
tree | f75cea6e472054b7a15466ea5e31c862ae9e77cc | |
parent | 4c57ab34d4852387da4ef8eac862045d1458de1e (diff) | |
parent | 808bc919eb94ac888f2014275b443ebdaf733ae5 (diff) | |
download | mariadb-git-4c25e75ce766440694553e0baf03cc5c6e803fc3.tar.gz |
Merge 10.3 into 10.4
52 files changed, 812 insertions, 288 deletions
diff --git a/.clang-format b/.clang-format index 1ad93ead80a..5fc6ab23622 100644 --- a/.clang-format +++ b/.clang-format @@ -90,7 +90,7 @@ PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Right ReflowComments: true -SortIncludes: true +SortIncludes: false SortUsingDeclarations: true SpaceAfterCStyleCast: true SpaceAfterLogicalNot: false diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index 3cdb116c593..869539dd96c 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -2689,7 +2689,9 @@ static lsn_t xtrabackup_copy_log(lsn_t start_lsn, lsn_t end_lsn, bool last) } } - if (more_data && recv_parse_log_recs(0, STORE_NO, false)) { + store_t store = STORE_NO; + + if (more_data && recv_parse_log_recs(0, &store, 0, false)) { msg("Error: copying the log failed"); diff --git a/mysql-test/include/binlog_parallel_replication_marks.test b/mysql-test/include/binlog_parallel_replication_marks.test index 82fa997822d..3976088ca43 100644 --- a/mysql-test/include/binlog_parallel_replication_marks.test +++ b/mysql-test/include/binlog_parallel_replication_marks.test @@ -80,7 +80,7 @@ while (<F>) { s/table id \d+/table id #/; s/mapped to number \d+/mapped to number #/; s/CRC32 0x[0-9a-f]+/CRC32 0x########/; - print if /GTID|BEGIN|COMMIT|Table_map|Write_rows|Update_rows|Delete_rows|generated by server|40005 TEMPORARY/; + print if /\b(GTID|BEGIN|COMMIT|Table_map|Write_rows|Update_rows|Delete_rows|generated by server|40005 TEMPORARY)\b/; } close F; EOF diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index c044b79d953..9203a3ddf1b 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -10548,6 +10548,36 @@ EXPLAIN } DROP TABLE t1; DROP VIEW v1; +# +# MDEV-21388 Wrong result of DAYNAME()=xxx in combination with condition_pushdown_for_derived=on +# +CREATE TABLE t1 (a INT, b DATE, c INT); +INSERT INTO t1 VALUES +(1,'2001-01-21',345), +(6,'2001-01-20',315), +(6,'2001-01-20',214); +CREATE TABLE t2 (a INT, b INT); +INSERT INTO t2 VALUES (2,19), (7,20); +CREATE VIEW v1 AS SELECT a, b, max(c) AS max_c FROM t1 +GROUP BY a,b HAVING max_c < 707; +SELECT *, dayname(v1.b) FROM v1,t2 WHERE (v1.max_c>214) AND (t2.a>v1.a); +a b max_c a b dayname(v1.b) +1 2001-01-21 345 2 19 Sunday +1 2001-01-21 345 7 20 Sunday +6 2001-01-20 315 7 20 Saturday +SET optimizer_switch='condition_pushdown_for_derived=off'; +SELECT *, dayname(v1.b) FROM v1,t2 WHERE (v1.max_c>214) AND (t2.a>v1.a) AND dayname(v1.b)='Sunday'; +a b max_c a b dayname(v1.b) +1 2001-01-21 345 2 19 Sunday +1 2001-01-21 345 7 20 Sunday +SET optimizer_switch='condition_pushdown_for_derived=on'; +SELECT *, dayname(v1.b) FROM v1,t2 WHERE (v1.max_c>214) AND (t2.a>v1.a) AND dayname(v1.b)='Sunday'; +a b max_c a b dayname(v1.b) +1 2001-01-21 345 2 19 Sunday +1 2001-01-21 345 7 20 Sunday +DROP VIEW v1; +DROP TABLE t1, t2; +SET optimizer_switch=DEFAULT; # End of 10.2 tests # # MDEV-14579: pushdown conditions into materialized views/derived tables diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test index 6d81d2ad80b..1441989e2cc 100644 --- a/mysql-test/main/derived_cond_pushdown.test +++ b/mysql-test/main/derived_cond_pushdown.test @@ -2140,6 +2140,34 @@ SELECT * FROM (SELECT 1 FROM v1 UNION (SELECT 1 FROM v1 WHERE @a := uuid())) dt; DROP TABLE t1; DROP VIEW v1; +--echo # +--echo # MDEV-21388 Wrong result of DAYNAME()=xxx in combination with condition_pushdown_for_derived=on +--echo # + +CREATE TABLE t1 (a INT, b DATE, c INT); +INSERT INTO t1 VALUES + (1,'2001-01-21',345), + (6,'2001-01-20',315), + (6,'2001-01-20',214); + +CREATE TABLE t2 (a INT, b INT); +INSERT INTO t2 VALUES (2,19), (7,20); +CREATE VIEW v1 AS SELECT a, b, max(c) AS max_c FROM t1 + GROUP BY a,b HAVING max_c < 707; + +SELECT *, dayname(v1.b) FROM v1,t2 WHERE (v1.max_c>214) AND (t2.a>v1.a); + +SET optimizer_switch='condition_pushdown_for_derived=off'; +SELECT *, dayname(v1.b) FROM v1,t2 WHERE (v1.max_c>214) AND (t2.a>v1.a) AND dayname(v1.b)='Sunday'; + +SET optimizer_switch='condition_pushdown_for_derived=on'; +SELECT *, dayname(v1.b) FROM v1,t2 WHERE (v1.max_c>214) AND (t2.a>v1.a) AND dayname(v1.b)='Sunday'; + +DROP VIEW v1; +DROP TABLE t1, t2; + +SET optimizer_switch=DEFAULT; + --echo # End of 10.2 tests --echo # diff --git a/mysql-test/main/func_time.result b/mysql-test/main/func_time.result index 791920fca8d..725e156ddd4 100644 --- a/mysql-test/main/func_time.result +++ b/mysql-test/main/func_time.result @@ -159,7 +159,9 @@ date_format('1999-12-31','%x-%v') date_format('2000-01-01','%x-%v') 1999-52 1999-52 select dayname("1962-03-03"),dayname("1962-03-03")+0; dayname("1962-03-03") dayname("1962-03-03")+0 -Saturday 5 +Saturday 0 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'Saturday' select monthname("1972-03-04"),monthname("1972-03-04")+0; monthname("1972-03-04") monthname("1972-03-04")+0 March 0 @@ -3512,6 +3514,19 @@ v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VI DROP VIEW v1,v2,v3; DROP TABLE t1,t2; # +# MDEV-21388 Wrong result of DAYNAME()=xxx in combination with condition_pushdown_for_derived=on +# +SELECT DAYNAME('2019-01-05')+0; +DAYNAME('2019-01-05')+0 +0 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'Saturday' +SELECT CAST(DAYNAME('2019-01-05') AS SIGNED); +CAST(DAYNAME('2019-01-05') AS SIGNED) +0 +Warnings: +Warning 1292 Truncated incorrect INTEGER value: 'Saturday' +# # End of 10.2 tests # # diff --git a/mysql-test/main/func_time.test b/mysql-test/main/func_time.test index 2e44df5a0d0..71f82ddba7b 100644 --- a/mysql-test/main/func_time.test +++ b/mysql-test/main/func_time.test @@ -1973,6 +1973,14 @@ DROP VIEW v1,v2,v3; DROP TABLE t1,t2; --echo # +--echo # MDEV-21388 Wrong result of DAYNAME()=xxx in combination with condition_pushdown_for_derived=on +--echo # + +SELECT DAYNAME('2019-01-05')+0; +SELECT CAST(DAYNAME('2019-01-05') AS SIGNED); + + +--echo # --echo # End of 10.2 tests --echo # diff --git a/mysql-test/main/mysql_tzinfo_to_sql_symlink.result b/mysql-test/main/mysql_tzinfo_to_sql_symlink.result index 966cc1d123a..8997c404079 100644 --- a/mysql-test/main/mysql_tzinfo_to_sql_symlink.result +++ b/mysql-test/main/mysql_tzinfo_to_sql_symlink.result @@ -4,7 +4,7 @@ # Verbose run \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=InnoDB; ALTER TABLE time_zone_name ENGINE=InnoDB; ALTER TABLE time_zone_transition ENGINE=InnoDB; @@ -36,7 +36,7 @@ ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=Aria; ALTER TABLE time_zone_name ENGINE=Aria; ALTER TABLE time_zone_transition ENGINE=Aria; @@ -46,7 +46,7 @@ END IF| # Silent run \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=InnoDB; ALTER TABLE time_zone_name ENGINE=InnoDB; ALTER TABLE time_zone_transition ENGINE=InnoDB; @@ -75,7 +75,7 @@ ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=Aria; ALTER TABLE time_zone_name ENGINE=Aria; ALTER TABLE time_zone_transition ENGINE=Aria; @@ -93,7 +93,7 @@ INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, ; \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=Aria; ALTER TABLE time_zone_name ENGINE=Aria; ALTER TABLE time_zone_transition ENGINE=Aria; @@ -105,21 +105,21 @@ END IF| # \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone_leap_second ENGINE=InnoDB; END IF| \d ; TRUNCATE TABLE time_zone_leap_second; \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone_leap_second ENGINE=Aria; END IF| \d ; ALTER TABLE time_zone_leap_second ORDER BY Transition_time; \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=Aria; ALTER TABLE time_zone_name ENGINE=Aria; ALTER TABLE time_zone_transition ENGINE=Aria; @@ -131,7 +131,7 @@ END IF| # \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=InnoDB; ALTER TABLE time_zone_name ENGINE=InnoDB; ALTER TABLE time_zone_transition ENGINE=InnoDB; @@ -146,7 +146,7 @@ ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=Aria; ALTER TABLE time_zone_name ENGINE=Aria; ALTER TABLE time_zone_transition ENGINE=Aria; diff --git a/mysql-test/main/type_datetime.result b/mysql-test/main/type_datetime.result index 5afb0257757..b23fa762c73 100644 --- a/mysql-test/main/type_datetime.result +++ b/mysql-test/main/type_datetime.result @@ -1198,6 +1198,87 @@ Warning 1292 Incorrect datetime value: '2' for column `test`.`t1`.`pk` at row 2 DROP VIEW v1; DROP TABLE t1; # +# MDEV-21319 COUNT(*) returns 1, actual SELECT returns no result in 10.3.21, but 1 result in 10.1.41 +# +CREATE TABLE t1 +( +id INT NOT NULL PRIMARY KEY, +id2 INT, +k TINYINT, +j INT, +t DATETIME, +KEY k1 (id2,k,j,t) +); +INSERT INTO t1 VALUES +(53,54,1,0,'2019-12-13 10:09:59'), +(54,54,1,0,'2019-12-13 16:28:41'), +(55,54,1,0,'2019-12-13 16:29:10'), +(56,54,1,0,'2019-12-13 16:29:43'), +(57,54,1,0,'2019-12-13 16:30:16'), +(58,54,1,0,'2019-12-13 16:30:49'), +(59,54,1,0,'2019-12-13 16:31:23'), +(60,54,1,0,'2019-12-13 16:31:55'), +(61,54,1,0,'2019-12-13 16:32:28'), +(62,54,1,0,'2019-12-13 16:33:01'), +(63,54,1,0,'2019-12-13 16:33:34'), +(64,54,1,0,'2019-12-13 16:34:07'), +(65,54,1,0,'2019-12-13 16:34:40'), +(66,54,1,0,'2019-12-13 16:35:13'), +(67,54,1,0,'2019-12-13 16:35:46'), +(68,54,1,0,'2019-12-13 16:36:19'); +SELECT t FROM t1 GROUP BY t HAVING t=max(t); +t +2019-12-13 10:09:59 +2019-12-13 16:28:41 +2019-12-13 16:29:10 +2019-12-13 16:29:43 +2019-12-13 16:30:16 +2019-12-13 16:30:49 +2019-12-13 16:31:23 +2019-12-13 16:31:55 +2019-12-13 16:32:28 +2019-12-13 16:33:01 +2019-12-13 16:33:34 +2019-12-13 16:34:07 +2019-12-13 16:34:40 +2019-12-13 16:35:13 +2019-12-13 16:35:46 +2019-12-13 16:36:19 +SELECT t FROM t1 WHERE id2=54 and j=0 and k=1 GROUP BY t HAVING t=max(t); +t +2019-12-13 10:09:59 +2019-12-13 16:28:41 +2019-12-13 16:29:10 +2019-12-13 16:29:43 +2019-12-13 16:30:16 +2019-12-13 16:30:49 +2019-12-13 16:31:23 +2019-12-13 16:31:55 +2019-12-13 16:32:28 +2019-12-13 16:33:01 +2019-12-13 16:33:34 +2019-12-13 16:34:07 +2019-12-13 16:34:40 +2019-12-13 16:35:13 +2019-12-13 16:35:46 +2019-12-13 16:36:19 +DROP TABLE t1; +CREATE TABLE t1 (pk INT); +CREATE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1); +SELECT pk<DATE'2001-01-01' FROM t1 GROUP BY pk; +pk<DATE'2001-01-01' +1 +Warnings: +Warning 1292 Incorrect datetime value: '1' for column `test`.`t1`.`pk` at row 1 +SELECT pk<DATE'2001-01-01' FROM v1 GROUP BY pk; +pk<DATE'2001-01-01' +1 +Warnings: +Warning 1292 Incorrect datetime value: '1' for column `test`.`t1`.`pk` at row 1 +DROP VIEW v1; +DROP TABLE t1; +# # End of 10.1 tests # # diff --git a/mysql-test/main/type_datetime.test b/mysql-test/main/type_datetime.test index b4b5fe95bbf..e4b18a245f0 100644 --- a/mysql-test/main/type_datetime.test +++ b/mysql-test/main/type_datetime.test @@ -748,6 +748,49 @@ DROP TABLE t1; --echo # +--echo # MDEV-21319 COUNT(*) returns 1, actual SELECT returns no result in 10.3.21, but 1 result in 10.1.41 +--echo # + +CREATE TABLE t1 +( + id INT NOT NULL PRIMARY KEY, + id2 INT, + k TINYINT, + j INT, + t DATETIME, + KEY k1 (id2,k,j,t) +); +INSERT INTO t1 VALUES +(53,54,1,0,'2019-12-13 10:09:59'), +(54,54,1,0,'2019-12-13 16:28:41'), +(55,54,1,0,'2019-12-13 16:29:10'), +(56,54,1,0,'2019-12-13 16:29:43'), +(57,54,1,0,'2019-12-13 16:30:16'), +(58,54,1,0,'2019-12-13 16:30:49'), +(59,54,1,0,'2019-12-13 16:31:23'), +(60,54,1,0,'2019-12-13 16:31:55'), +(61,54,1,0,'2019-12-13 16:32:28'), +(62,54,1,0,'2019-12-13 16:33:01'), +(63,54,1,0,'2019-12-13 16:33:34'), +(64,54,1,0,'2019-12-13 16:34:07'), +(65,54,1,0,'2019-12-13 16:34:40'), +(66,54,1,0,'2019-12-13 16:35:13'), +(67,54,1,0,'2019-12-13 16:35:46'), +(68,54,1,0,'2019-12-13 16:36:19'); +SELECT t FROM t1 GROUP BY t HAVING t=max(t); +SELECT t FROM t1 WHERE id2=54 and j=0 and k=1 GROUP BY t HAVING t=max(t); +DROP TABLE t1; + +CREATE TABLE t1 (pk INT); +CREATE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1); +SELECT pk<DATE'2001-01-01' FROM t1 GROUP BY pk; +SELECT pk<DATE'2001-01-01' FROM v1 GROUP BY pk; +DROP VIEW v1; +DROP TABLE t1; + + +--echo # --echo # End of 10.1 tests --echo # diff --git a/mysql-test/main/type_int.result b/mysql-test/main/type_int.result index db08563a191..0d744f6a97b 100644 --- a/mysql-test/main/type_int.result +++ b/mysql-test/main/type_int.result @@ -20,6 +20,19 @@ COALESCE(@a) 1 DROP TABLE t1; # +# MDEV-21065 UNIQUE constraint causes a query with string comparison to omit a row in the result set +# +CREATE TABLE t1 (c0 INT UNIQUE); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL), (NULL), (1), (0); +SELECT * FROM t1 WHERE c0 < '\n2'; +c0 +0 +1 +DROP TABLE t1; +SELECT CAST('\n2' AS INT); +CAST('\n2' AS INT) +2 +# # End of 5.5 tests # # diff --git a/mysql-test/main/type_int.test b/mysql-test/main/type_int.test index 748ba3c3c52..662be57abd3 100644 --- a/mysql-test/main/type_int.test +++ b/mysql-test/main/type_int.test @@ -15,6 +15,18 @@ SELECT COALESCE(@a) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar'); DROP TABLE t1; --echo # +--echo # MDEV-21065 UNIQUE constraint causes a query with string comparison to omit a row in the result set +--echo # + +CREATE TABLE t1 (c0 INT UNIQUE); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL), (NULL), (1), (0); +SELECT * FROM t1 WHERE c0 < '\n2'; +DROP TABLE t1; + +SELECT CAST('\n2' AS INT); + + +--echo # --echo # End of 5.5 tests --echo # diff --git a/mysql-test/main/type_time.result b/mysql-test/main/type_time.result index 673bed990a1..360746bb856 100644 --- a/mysql-test/main/type_time.result +++ b/mysql-test/main/type_time.result @@ -1258,6 +1258,72 @@ drop table t1; SET @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set @@old_mode= @save_old_mode; # +# MDEV-21319 COUNT(*) returns 1, actual SELECT returns no result in 10.3.21, but 1 result in 10.1.41 +# +CREATE OR REPLACE TABLE t1 +( +id INT NOT NULL PRIMARY KEY, +id2 INT, +k TINYINT, +j INT, +t TIME, +KEY k1 (id2,k,j,t) +); +INSERT INTO t1 VALUES +(53,54,1,0,'10:09:59'), +(54,54,1,0,'16:28:41'), +(55,54,1,0,'16:29:10'), +(56,54,1,0,'16:29:43'), +(57,54,1,0,'16:30:16'), +(58,54,1,0,'16:30:49'), +(59,54,1,0,'16:31:23'), +(60,54,1,0,'16:31:55'), +(61,54,1,0,'16:32:28'), +(62,54,1,0,'16:33:01'), +(63,54,1,0,'16:33:34'), +(64,54,1,0,'16:34:07'), +(65,54,1,0,'16:34:40'), +(66,54,1,0,'16:35:13'), +(67,54,1,0,'16:35:46'), +(68,54,1,0,'16:36:19'); +SELECT t FROM t1 GROUP BY t HAVING t=MAX(t); +t +10:09:59 +16:28:41 +16:29:10 +16:29:43 +16:30:16 +16:30:49 +16:31:23 +16:31:55 +16:32:28 +16:33:01 +16:33:34 +16:34:07 +16:34:40 +16:35:13 +16:35:46 +16:36:19 +SELECT t FROM t1 WHERE id2=54 AND j=0 AND k=1 GROUP BY t HAVING t=MAX(t); +t +10:09:59 +16:28:41 +16:29:10 +16:29:43 +16:30:16 +16:30:49 +16:31:23 +16:31:55 +16:32:28 +16:33:01 +16:33:34 +16:34:07 +16:34:40 +16:35:13 +16:35:46 +16:36:19 +DROP TABLE t1; +# # End of 10.1 tests # # diff --git a/mysql-test/main/type_time.test b/mysql-test/main/type_time.test index 08e43041c76..13101f0e29d 100644 --- a/mysql-test/main/type_time.test +++ b/mysql-test/main/type_time.test @@ -752,6 +752,40 @@ SET @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selecti set @@old_mode= @save_old_mode; --echo # +--echo # MDEV-21319 COUNT(*) returns 1, actual SELECT returns no result in 10.3.21, but 1 result in 10.1.41 +--echo # + +CREATE OR REPLACE TABLE t1 +( + id INT NOT NULL PRIMARY KEY, + id2 INT, + k TINYINT, + j INT, + t TIME, + KEY k1 (id2,k,j,t) +); +INSERT INTO t1 VALUES +(53,54,1,0,'10:09:59'), +(54,54,1,0,'16:28:41'), +(55,54,1,0,'16:29:10'), +(56,54,1,0,'16:29:43'), +(57,54,1,0,'16:30:16'), +(58,54,1,0,'16:30:49'), +(59,54,1,0,'16:31:23'), +(60,54,1,0,'16:31:55'), +(61,54,1,0,'16:32:28'), +(62,54,1,0,'16:33:01'), +(63,54,1,0,'16:33:34'), +(64,54,1,0,'16:34:07'), +(65,54,1,0,'16:34:40'), +(66,54,1,0,'16:35:13'), +(67,54,1,0,'16:35:46'), +(68,54,1,0,'16:36:19'); +SELECT t FROM t1 GROUP BY t HAVING t=MAX(t); +SELECT t FROM t1 WHERE id2=54 AND j=0 AND k=1 GROUP BY t HAVING t=MAX(t); +DROP TABLE t1; + +--echo # --echo # End of 10.1 tests --echo # diff --git a/mysql-test/main/win.result b/mysql-test/main/win.result index fff859cfa44..a7b215b5052 100644 --- a/mysql-test/main/win.result +++ b/mysql-test/main/win.result @@ -3643,6 +3643,87 @@ x foo drop table t1; # +# MDEV-16579: Wrong result of query using DISTINCT COUNT(*) OVER (*) +# +CREATE TABLE t1 (i int) ; +INSERT INTO t1 VALUES (1),(0),(1),(2),(0),(1),(2),(1),(2); +SELECT DISTINCT COUNT(*) OVER (), MOD(MIN(i),2) FROM t1 GROUP BY i ; +COUNT(*) OVER () MOD(MIN(i),2) +3 0 +3 1 +drop table t1; +# +# MDEV-21318: Wrong results with window functions and implicit grouping +# +CREATE TABLE t1 (a INT); +# +# With empty const table +# The expected result here is 1, NULL +# +explain +SELECT row_number() over(), sum(1) FROM t1; +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; Using temporary +SELECT row_number() over(), sum(1) FROM t1; +row_number() over() sum(1) +1 NULL +insert into t1 values (2); +# +# Const table has 1 row, but still impossible where +# The expected result here is 1, NULL +# +EXPLAIN SELECT row_number() over(), sum(1) FROM t1 where 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 WHERE noticed after reading const tables +SELECT row_number() over(), sum(1) FROM t1 where a=1; +row_number() over() sum(1) +1 NULL +# +# Impossible HAVING +# Empty result is expected +# +EXPLAIN SELECT row_number() over(), sum(1) FROM t1 where a=1 having 1=0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible HAVING +SELECT row_number() over(), sum(1) FROM t1 where a=1 having 1=0; +row_number() over() sum(1) +# +# const table has 1 row, no impossible where +# The expected result here is 1, 2 +# +EXPLAIN SELECT row_number() over(), sum(a) FROM t1 where a=2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 1 Using temporary +SELECT row_number() over(), sum(a) FROM t1 where a=2; +row_number() over() sum(a) +1 2 +drop table t1; +# +# Impossible Where +# +create table t1(a int); +insert into t1 values (1); +# +# Expected result is NULL, 0, NULL +# +EXPLAIN SELECT MAX(a) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +SELECT MAX(a) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; +MAX(a) OVER () COUNT(a) abs(a) +NULL 0 NULL +# +# Expected result is 1, 0, NULL +# +EXPLAIN +SELECT MAX(1) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +SELECT MAX(1) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; +MAX(1) OVER () COUNT(a) abs(a) +1 0 NULL +drop table t1; +# # End of 10.2 tests # # diff --git a/mysql-test/main/win.test b/mysql-test/main/win.test index c6ddef94d80..32de28511c1 100644 --- a/mysql-test/main/win.test +++ b/mysql-test/main/win.test @@ -2352,6 +2352,81 @@ SELECT (SELECT MIN('foo') OVER() FROM t1 LIMIT 1) as x; drop table t1; --echo # +--echo # MDEV-16579: Wrong result of query using DISTINCT COUNT(*) OVER (*) +--echo # + +CREATE TABLE t1 (i int) ; +INSERT INTO t1 VALUES (1),(0),(1),(2),(0),(1),(2),(1),(2); + +SELECT DISTINCT COUNT(*) OVER (), MOD(MIN(i),2) FROM t1 GROUP BY i ; +drop table t1; + +--echo # +--echo # MDEV-21318: Wrong results with window functions and implicit grouping +--echo # + +CREATE TABLE t1 (a INT); + +--echo # +--echo # With empty const table +--echo # The expected result here is 1, NULL +--echo # + +explain +SELECT row_number() over(), sum(1) FROM t1; +SELECT row_number() over(), sum(1) FROM t1; + +insert into t1 values (2); + +--echo # +--echo # Const table has 1 row, but still impossible where +--echo # The expected result here is 1, NULL +--echo # + +EXPLAIN SELECT row_number() over(), sum(1) FROM t1 where a=1; +SELECT row_number() over(), sum(1) FROM t1 where a=1; + +--echo # +--echo # Impossible HAVING +--echo # Empty result is expected +--echo # + +EXPLAIN SELECT row_number() over(), sum(1) FROM t1 where a=1 having 1=0; +SELECT row_number() over(), sum(1) FROM t1 where a=1 having 1=0; + +--echo # +--echo # const table has 1 row, no impossible where +--echo # The expected result here is 1, 2 +--echo # + +EXPLAIN SELECT row_number() over(), sum(a) FROM t1 where a=2; +SELECT row_number() over(), sum(a) FROM t1 where a=2; +drop table t1; + +--echo # +--echo # Impossible Where +--echo # + +create table t1(a int); +insert into t1 values (1); + +--echo # +--echo # Expected result is NULL, 0, NULL +--echo # +EXPLAIN SELECT MAX(a) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; +SELECT MAX(a) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; + +--echo # +--echo # Expected result is 1, 0, NULL +--echo # + +EXPLAIN +SELECT MAX(1) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; +SELECT MAX(1) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; + +drop table t1; + +--echo # --echo # End of 10.2 tests --echo # diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 58871f7aee1..0315456df57 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -4653,6 +4653,8 @@ sub extract_warning_lines ($$) { qr/missing DBUG_RETURN/, qr/Attempting backtrace/, qr/Assertion .* failed/, + qr/Sanitizer/, + qr/runtime error:/, ); # These are taken from the include/mtr_warnings.sql global suppression # list. They occur delayed, so they can be parsed during shutdown rather diff --git a/mysql-test/suite/galera/r/galera_partition.result b/mysql-test/suite/galera/r/galera_partition.result index ea35eeab96e..f09a0272eda 100644 --- a/mysql-test/suite/galera/r/galera_partition.result +++ b/mysql-test/suite/galera/r/galera_partition.result @@ -397,11 +397,14 @@ SELECT COUNT(*) FROM t1; COUNT(*) 350 connection node_2; -call p1(10);; +call mtr.add_suppression("WSREP: Sending JOIN failed:"); +call p1(10); connection node_3; -call p1(10);; +call mtr.add_suppression("WSREP: Sending JOIN failed:"); +call p1(10); connection node_4; -call p1(10);; +call mtr.add_suppression("WSREP: Sending JOIN failed:"); +call p1(10); connection node_1; SET SESSION wsrep_OSU_method='RSU'; SELECT @@wsrep_OSU_method; diff --git a/mysql-test/suite/galera/t/galera_partition.test b/mysql-test/suite/galera/t/galera_partition.test index af725836f53..bf3f02eaa92 100644 --- a/mysql-test/suite/galera/t/galera_partition.test +++ b/mysql-test/suite/galera/t/galera_partition.test @@ -407,13 +407,16 @@ insert into t1 (id, dt) values (350, '2010-12-17 00:00:00'); SELECT COUNT(*) FROM t1; --connection node_2 ---send call p1(10); +call mtr.add_suppression("WSREP: Sending JOIN failed:"); +send call p1(10); --connection node_3 ---send call p1(10); +call mtr.add_suppression("WSREP: Sending JOIN failed:"); +send call p1(10); --connection node_4 ---send call p1(10); +call mtr.add_suppression("WSREP: Sending JOIN failed:"); +send call p1(10); --connection node_1 SET SESSION wsrep_OSU_method='RSU'; diff --git a/mysql-test/suite/wsrep/disabled.def b/mysql-test/suite/wsrep/disabled.def index 122c7b4b37f..bd8d4ecf33b 100644 --- a/mysql-test/suite/wsrep/disabled.def +++ b/mysql-test/suite/wsrep/disabled.def @@ -11,5 +11,3 @@ ############################################################################## variables : MDEV-20581 Crash on wsrep.variables test case - - diff --git a/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink.result b/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink.result index 28fc332bb0a..ffd6c3cab1f 100644 --- a/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink.result +++ b/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink.result @@ -4,7 +4,7 @@ # Verbose run \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=InnoDB; ALTER TABLE time_zone_name ENGINE=InnoDB; ALTER TABLE time_zone_transition ENGINE=InnoDB; @@ -36,7 +36,7 @@ ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=Aria; ALTER TABLE time_zone_name ENGINE=Aria; ALTER TABLE time_zone_transition ENGINE=Aria; @@ -46,7 +46,7 @@ END IF| # Silent run \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=InnoDB; ALTER TABLE time_zone_name ENGINE=InnoDB; ALTER TABLE time_zone_transition ENGINE=InnoDB; @@ -75,7 +75,7 @@ ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=Aria; ALTER TABLE time_zone_name ENGINE=Aria; ALTER TABLE time_zone_transition ENGINE=Aria; @@ -93,7 +93,7 @@ INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, ; \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=Aria; ALTER TABLE time_zone_name ENGINE=Aria; ALTER TABLE time_zone_transition ENGINE=Aria; @@ -105,21 +105,21 @@ END IF| # \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone_leap_second ENGINE=InnoDB; END IF| \d ; TRUNCATE TABLE time_zone_leap_second; \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone_leap_second ENGINE=Aria; END IF| \d ; ALTER TABLE time_zone_leap_second ORDER BY Transition_time; \d | IF (select count(*) from information_schema.global_variables where -variable_name='wsrep_on') = 1 THEN +variable_name='wsrep_on' and variable_value='ON') = 1 THEN ALTER TABLE time_zone ENGINE=Aria; ALTER TABLE time_zone_name ENGINE=Aria; ALTER TABLE time_zone_transition ENGINE=Aria; diff --git a/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink_skip.result b/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink_skip.result index 4ce57c641b3..85c4d858be2 100644 --- a/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink_skip.result +++ b/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink_skip.result @@ -2,7 +2,7 @@ # MDEV-5226 mysql_tzinfo_to_sql errors with tzdata 2013f and above # # Verbose run -set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); +set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on' and variable_value='ON'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); prepare set_wsrep_write_binlog from @prep1; set @toggle=0; execute set_wsrep_write_binlog using @toggle; TRUNCATE TABLE time_zone; @@ -29,7 +29,7 @@ Warning: Skipping directory 'MYSQLTEST_VARDIR/zoneinfo/posix/posix': to avoid in ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; # Silent run -set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); +set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on' and variable_value='ON'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); prepare set_wsrep_write_binlog from @prep1; set @toggle=0; execute set_wsrep_write_binlog using @toggle; TRUNCATE TABLE time_zone; @@ -55,7 +55,7 @@ ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; # # Testing with explicit timezonefile # -set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); +set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on' and variable_value='ON'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); prepare set_wsrep_write_binlog from @prep1; set @toggle=0; execute set_wsrep_write_binlog using @toggle; INSERT INTO time_zone (Use_leap_seconds) VALUES ('N'); @@ -67,7 +67,7 @@ INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, # # Testing --leap # -set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); +set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on' and variable_value='ON'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); prepare set_wsrep_write_binlog from @prep1; set @toggle=0; execute set_wsrep_write_binlog using @toggle; TRUNCATE TABLE time_zone_leap_second; diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 52fab2a029f..bab8e67fdac 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -418,15 +418,18 @@ IF(WIN32 AND TARGET mysqld AND NOT CMAKE_CROSSCOMPILING) ENDIF() MAKE_DIRECTORY(${CMAKE_CURRENT_BINARY_DIR}/data) ADD_CUSTOM_COMMAND( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/initdb.dep - COMMAND ${CMAKE_COMMAND} ${CONFIG_PARAM} - -DTOP_SRCDIR="${CMAKE_SOURCE_DIR}" - -DBINDIR="${CMAKE_CURRENT_BINARY_DIR}" - -DMYSQLD_EXECUTABLE="$<TARGET_FILE:mysqld>" - -DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}" - -P ${CMAKE_SOURCE_DIR}/cmake/create_initial_db.cmake + OUTPUT initdb.dep + COMMAND ${CMAKE_COMMAND} -E remove_directory data + COMMAND ${CMAKE_COMMAND} -E make_directory data + COMMAND ${CMAKE_COMMAND} -E chdir data ${CMAKE_COMMAND} + ${CONFIG_PARAM} + -DTOP_SRCDIR="${CMAKE_SOURCE_DIR}" + -DBINDIR="${CMAKE_CURRENT_BINARY_DIR}" + -DMYSQLD_EXECUTABLE="$<TARGET_FILE:mysqld>" + -DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}" + -P ${CMAKE_SOURCE_DIR}/cmake/create_initial_db.cmake COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/initdb.dep - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/data + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ DEPENDS mysqld ) ADD_CUSTOM_TARGET(initial_database diff --git a/sql/item.cc b/sql/item.cc index dc39755f63d..7d7d50da2cf 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -3225,12 +3225,13 @@ bool Item_field::get_date(THD *thd, MYSQL_TIME *ltime,date_mode_t fuzzydate) bool Item_field::get_date_result(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - if (result_field->is_null() || result_field->get_date(ltime,fuzzydate)) + if ((null_value= result_field->is_null()) || + result_field->get_date(ltime, fuzzydate)) { bzero((char*) ltime,sizeof(*ltime)); - return (null_value= 1); + return true; } - return (null_value= 0); + return false; } @@ -8229,7 +8230,7 @@ bool Item_ref::val_native(THD *thd, Native *to) longlong Item_ref::val_datetime_packed(THD *thd) { DBUG_ASSERT(fixed); - longlong tmp= (*ref)->val_datetime_packed(thd); + longlong tmp= (*ref)->val_datetime_packed_result(thd); null_value= (*ref)->null_value; return tmp; } @@ -8238,7 +8239,7 @@ longlong Item_ref::val_datetime_packed(THD *thd) longlong Item_ref::val_time_packed(THD *thd) { DBUG_ASSERT(fixed); - longlong tmp= (*ref)->val_time_packed(thd); + longlong tmp= (*ref)->val_time_packed_result(thd); null_value= (*ref)->null_value; return tmp; } diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 3b2ac55c59d..924fdecffa9 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1101,9 +1101,10 @@ longlong Item_func_weekday::val_int() { DBUG_ASSERT(fixed == 1); THD *thd= current_thd; - Datetime d(thd, args[0], Datetime::Options(TIME_NO_ZEROS, thd)); - return ((null_value= !d.is_valid_datetime())) ? 0 : - calc_weekday(d.daynr(), odbc_type) + MY_TEST(odbc_type); + Datetime dt(thd, args[0], Datetime::Options(TIME_NO_ZEROS, thd)); + if ((null_value= !dt.is_valid_datetime())) + return 0; + return dt.weekday(odbc_type) + MY_TEST(odbc_type); } bool Item_func_dayname::fix_length_and_dec() @@ -1122,14 +1123,15 @@ bool Item_func_dayname::fix_length_and_dec() String* Item_func_dayname::val_str(String* str) { DBUG_ASSERT(fixed == 1); - uint weekday=(uint) val_int(); // Always Item_func_weekday() const char *day_name; uint err; + THD *thd= current_thd; + Datetime dt(thd, args[0], Datetime::Options(TIME_NO_ZEROS, thd)); - if (null_value) + if ((null_value= !dt.is_valid_datetime())) return (String*) 0; - - day_name= locale->day_names->type_names[weekday]; + + day_name= locale->day_names->type_names[dt.weekday(false)]; str->copy(day_name, (uint) strlen(day_name), &my_charset_utf8_bin, collation.collation, &err); return str; diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index fe9dc8b43e2..8a69a0a3d5a 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -422,20 +422,13 @@ public: }; -class Item_func_weekday :public Item_func +class Item_func_weekday :public Item_long_func { bool odbc_type; public: Item_func_weekday(THD *thd, Item *a, bool type_arg): - Item_func(thd, a), odbc_type(type_arg) { collation.set_numeric(); } + Item_long_func(thd, a), odbc_type(type_arg) { } longlong val_int(); - double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); } - String *val_str(String *str) - { - DBUG_ASSERT(fixed == 1); - str->set(val_int(), &my_charset_bin); - return null_value ? 0 : str; - } const char *func_name() const { return (odbc_type ? "dayofweek" : "weekday"); @@ -444,7 +437,6 @@ public: { return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); } - const Type_handler *type_handler() const { return &type_handler_long; } bool fix_length_and_dec() { decimals= 0; @@ -462,11 +454,11 @@ public: { return get_item_copy<Item_func_weekday>(thd, this); } }; -class Item_func_dayname :public Item_func_weekday +class Item_func_dayname :public Item_str_func { MY_LOCALE *locale; public: - Item_func_dayname(THD *thd, Item *a): Item_func_weekday(thd, a, 0) {} + Item_func_dayname(THD *thd, Item *a): Item_str_func(thd, a) {} const char *func_name() const { return "dayname"; } String *val_str(String *str); const Type_handler *type_handler() const { return &type_handler_varchar; } @@ -476,6 +468,12 @@ class Item_func_dayname :public Item_func_weekday { return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC); } + bool check_valid_arguments_processor(void *int_arg) + { + return !has_date_args(); + } + Item *get_copy(THD *thd) + { return get_item_copy<Item_func_dayname>(thd, this); } }; diff --git a/sql/sql_audit.h b/sql/sql_audit.h index 59cced13b0a..97317203e34 100644 --- a/sql/sql_audit.h +++ b/sql/sql_audit.h @@ -284,7 +284,9 @@ void mysql_audit_notify_connection_change_user(THD *thd) } static inline -void mysql_audit_external_lock(THD *thd, TABLE_SHARE *share, int lock) +void mysql_audit_external_lock_ex(THD *thd, my_thread_id thread_id, + const char *user, const char *host, const char *ip, query_id_t query_id, + TABLE_SHARE *share, int lock) { if (lock != F_UNLCK && mysql_audit_table_enabled()) { @@ -293,25 +295,33 @@ void mysql_audit_external_lock(THD *thd, TABLE_SHARE *share, int lock) event.event_subclass= MYSQL_AUDIT_TABLE_LOCK; event.read_only= lock == F_RDLCK; - event.thread_id= (unsigned long)thd->thread_id; - event.user= sctx->user; + event.thread_id= (unsigned long)thread_id; + event.user= user; event.priv_user= sctx->priv_user; event.priv_host= sctx->priv_host; event.external_user= sctx->external_user; event.proxy_user= sctx->proxy_user; - event.host= sctx->host; - event.ip= sctx->ip; + event.host= host; + event.ip= ip; event.database= share->db; event.table= share->table_name; event.new_database= null_clex_str; event.new_table= null_clex_str; - event.query_id= thd->query_id; + event.query_id= query_id; mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, &event); } } static inline +void mysql_audit_external_lock(THD *thd, TABLE_SHARE *share, int lock) +{ + mysql_audit_external_lock_ex(thd, thd->thread_id, thd->security_ctx->user, + thd->security_ctx->host, thd->security_ctx->ip, thd->query_id, + share, lock); +} + +static inline void mysql_audit_create_table(TABLE *table) { if (mysql_audit_table_enabled()) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index c8f4ac05efc..807dd94c6f0 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2193,36 +2193,16 @@ public: passed from connection thread to the handler thread. */ MDL_request grl_protection; - my_thread_id orig_thread_id; - void set_default_user() - { - thd.security_ctx->user=(char*) delayed_user; - thd.security_ctx->host=(char*) my_localhost; - thd.security_ctx->ip= NULL; - thd.query_id= 0; - thd.thread_id= orig_thread_id; - } - - void set_user_from_row(const delayed_row *r) - { - if (r) - { - thd.security_ctx->user= r->user; - thd.security_ctx->host= r->host; - thd.security_ctx->ip= r->ip; - thd.query_id= r->query_id; - thd.thread_id= r->thread_id; - } - } - Delayed_insert(SELECT_LEX *current_select) :locks_in_memory(0), thd(next_thread_id()), table(0),tables_in_use(0), stacked_inserts(0), status(0), retry(0), handler_thread_initialized(FALSE), group_count(0) { DBUG_ENTER("Delayed_insert constructor"); - orig_thread_id= thd.thread_id; - set_default_user(); + thd.security_ctx->user=(char*) delayed_user; + thd.security_ctx->host=(char*) my_localhost; + thd.security_ctx->ip= NULL; + thd.query_id= 0; strmake_buf(thd.security_ctx->priv_user, thd.security_ctx->user); thd.current_tablenr=0; thd.set_command(COM_DELAYED_INSERT); @@ -3208,7 +3188,6 @@ pthread_handler_t handle_delayed_insert(void *arg) if (di->tables_in_use && ! thd->lock && (!thd->killed || di->stacked_inserts)) { - di->set_user_from_row(di->rows.head()); /* Request for new delayed insert. Lock the table, but avoid to be blocked by a global read lock. @@ -3230,16 +3209,18 @@ pthread_handler_t handle_delayed_insert(void *arg) { delayed_row *row; I_List_iterator<delayed_row> it(di->rows); + my_thread_id cur_thd= di->thd.thread_id; + while ((row= it++)) { - if (di->thd.thread_id != row->thread_id) + if (cur_thd != row->thread_id) { - di->set_user_from_row(row); - mysql_audit_external_lock(&di->thd, di->table->s, F_WRLCK); + mysql_audit_external_lock_ex(&di->thd, row->thread_id, + row->user, row->host, row->ip, row->query_id, + di->table->s, F_WRLCK); + cur_thd= row->thread_id; } } - di->set_default_user(); - if (di->handle_inserts()) { /* Some fatal error */ diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 9d22eb1a8cc..0983cea44d0 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1679,28 +1679,6 @@ public: uint sroutines_list_own_elements; /** - Locking state of tables in this particular statement. - - If we under LOCK TABLES or in prelocked mode we consider tables - for the statement to be "locked" if there was a call to lock_tables() - (which called handler::start_stmt()) for tables of this statement - and there was no matching close_thread_tables() call. - - As result this state may differ significantly from one represented - by Open_tables_state::lock/locked_tables_mode more, which are always - "on" under LOCK TABLES or in prelocked mode. - */ - enum enum_lock_tables_state { - LTS_NOT_LOCKED = 0, - LTS_LOCKED - }; - enum_lock_tables_state lock_tables_state; - bool is_query_tables_locked() - { - return (lock_tables_state == LTS_LOCKED); - } - - /** Number of tables which were open by open_tables() and to be locked by lock_tables(). Note that we set this member only in some cases, when this value diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a685c948a3d..d9d9c229c2f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2121,6 +2121,7 @@ JOIN::optimize_inner() zero_result_cause= "Zero limit"; } table_count= top_join_tab_count= 0; + handle_implicit_grouping_with_window_funcs(); error= 0; subq_exit_fl= true; goto setup_subq_exit; @@ -2168,6 +2169,7 @@ JOIN::optimize_inner() table_count= top_join_tab_count= 0; error=0; subq_exit_fl= true; + handle_implicit_grouping_with_window_funcs(); goto setup_subq_exit; } if (res > 1) @@ -2183,6 +2185,7 @@ JOIN::optimize_inner() tables_list= 0; // All tables resolved select_lex->min_max_opt_list.empty(); const_tables= top_join_tab_count= table_count; + handle_implicit_grouping_with_window_funcs(); /* Extract all table-independent conditions and replace the WHERE clause with them. All other conditions were computed by opt_sum_query @@ -2331,6 +2334,7 @@ int JOIN::optimize_stage2() zero_result_cause= "no matching row in const table"; DBUG_PRINT("error",("Error: %s", zero_result_cause)); error= 0; + handle_implicit_grouping_with_window_funcs(); goto setup_subq_exit; } if (!(thd->variables.option_bits & OPTION_BIG_SELECTS) && @@ -2362,6 +2366,7 @@ int JOIN::optimize_stage2() zero_result_cause= "Impossible WHERE noticed after reading const tables"; select_lex->mark_const_derived(zero_result_cause); + handle_implicit_grouping_with_window_funcs(); goto setup_subq_exit; } @@ -2524,6 +2529,7 @@ int JOIN::optimize_stage2() zero_result_cause= "Impossible WHERE noticed after reading const tables"; select_lex->mark_const_derived(zero_result_cause); + handle_implicit_grouping_with_window_funcs(); goto setup_subq_exit; } @@ -15741,7 +15747,7 @@ static COND* substitute_for_best_equal_field(THD *thd, JOIN_TAB *context_tab, } } else if (cond->type() == Item::FUNC_ITEM && - ((Item_cond*) cond)->functype() == Item_func::MULT_EQUAL_FUNC) + ((Item_func*) cond)->functype() == Item_func::MULT_EQUAL_FUNC) { item_equal= (Item_equal *) cond; item_equal->sort(&compare_fields_by_table_order, table_join_idx); @@ -19614,7 +19620,8 @@ void set_postjoin_aggr_write_func(JOIN_TAB *tab) } } else if (join->sort_and_group && !tmp_tbl->precomputed_group_by && - !join->sort_and_group_aggr_tab && join->tables_list) + !join->sort_and_group_aggr_tab && join->tables_list && + join->top_join_tab_count) { DBUG_PRINT("info",("Using end_write_group")); aggr->set_write_func(end_write_group); @@ -25041,7 +25048,8 @@ change_to_use_tmp_fields(THD *thd, Ref_ptr_array ref_pointer_array, for (uint i= 0; (item= it++); i++) { Field *field; - if (item->with_sum_func() && item->type() != Item::SUM_FUNC_ITEM) + if ((item->with_sum_func() && item->type() != Item::SUM_FUNC_ITEM) || + item->with_window_func) item_field= item; else if (item->type() == Item::FIELD_ITEM) { @@ -28607,6 +28615,28 @@ Item *remove_pushed_top_conjuncts(THD *thd, Item *cond) } +/* + There are 5 cases in which we shortcut the join optimization process as we + conclude that the join would be a degenerate one + 1) IMPOSSIBLE WHERE + 2) MIN/MAX optimization (@see opt_sum_query) + 3) EMPTY CONST TABLE + If a window function is present in any of the above cases then to get the + result of the window function, we need to execute it. So we need to + create a temporary table for its execution. Here we need to take in mind + that aggregate functions and non-aggregate function need not be executed. + +*/ + +void JOIN::handle_implicit_grouping_with_window_funcs() +{ + if (select_lex->have_window_funcs() && send_row_on_empty_set()) + { + const_tables= top_join_tab_count= table_count= 0; + } +} + + /** @brief Look for provision of the select_handler interface by a foreign engine diff --git a/sql/sql_select.h b/sql/sql_select.h index dcb8326ed8c..b9043a851e7 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1127,6 +1127,7 @@ protected: Join_plan_state *save_to); /* Choose a subquery plan for a table-less subquery. */ bool choose_tableless_subquery_plan(); + void handle_implicit_grouping_with_window_funcs(); public: void save_query_plan(Join_plan_state *save_to); diff --git a/sql/sql_type.h b/sql/sql_type.h index 0dd82f3dfaf..04eb5a25891 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -1785,6 +1785,10 @@ protected: { return (ulong) ::calc_daynr((uint) year, (uint) month, (uint) day); } + int weekday(bool sunday_first_day_of_week) const + { + return ::calc_weekday(daynr(), sunday_first_day_of_week); + } ulong dayofyear() const { return (ulong) (daynr() - ::calc_daynr(year, 1, 1) + 1); @@ -2165,6 +2169,11 @@ public: DBUG_ASSERT(is_valid_datetime_slow()); return Temporal_with_date::daynr(); } + int weekday(bool sunday_first_day_of_week) const + { + DBUG_ASSERT(is_valid_datetime_slow()); + return Temporal_with_date::weekday(sunday_first_day_of_week); + } ulong dayofyear() const { DBUG_ASSERT(is_valid_datetime_slow()); diff --git a/sql/threadpool_generic.cc b/sql/threadpool_generic.cc index eb92846ed07..6f8e1982836 100644 --- a/sql/threadpool_generic.cc +++ b/sql/threadpool_generic.cc @@ -1322,7 +1322,7 @@ void wait_begin(thread_group_t *thread_group) DBUG_ASSERT(thread_group->connection_count > 0); if ((thread_group->active_thread_count == 0) && - (is_queue_empty(thread_group) || !thread_group->listener)) + (!is_queue_empty(thread_group) || !thread_group->listener)) { /* Group might stall while this thread waits, thus wake diff --git a/sql/tztime.cc b/sql/tztime.cc index c45a6598d69..46a24a137e5 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -2432,7 +2432,7 @@ print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp) if (!opt_skip_write_binlog) printf("\\d |\n" "IF (select count(*) from information_schema.global_variables where\n" - "variable_name='wsrep_on') = 1 THEN\n" + "variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n" "ALTER TABLE time_zone_leap_second ENGINE=InnoDB;\n" "END IF|\n" "\\d ;\n"); @@ -2452,7 +2452,7 @@ print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp) if (!opt_skip_write_binlog) printf("\\d |\n" "IF (select count(*) from information_schema.global_variables where\n" - "variable_name='wsrep_on') = 1 THEN\n" + "variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n" "ALTER TABLE time_zone_leap_second ENGINE=Aria;\n" "END IF|\n" "\\d ;\n"); @@ -2709,7 +2709,7 @@ main(int argc, char **argv) sql_log_bin and wsrep_on to avoid Galera replicating below truncate table clauses. This will allow user to set different time zones to nodes in Galera cluster. */ - printf("set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?');\n" + printf("set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on' and variable_value='ON'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?');\n" "prepare set_wsrep_write_binlog from @prep1;\n" "set @toggle=0; execute set_wsrep_write_binlog using @toggle;\n"); @@ -2725,7 +2725,7 @@ main(int argc, char **argv) // to allow changes to them to replicate with Galera printf("\\d |\n" "IF (select count(*) from information_schema.global_variables where\n" - "variable_name='wsrep_on') = 1 THEN\n" + "variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n" "ALTER TABLE time_zone ENGINE=InnoDB;\n" "ALTER TABLE time_zone_name ENGINE=InnoDB;\n" "ALTER TABLE time_zone_transition ENGINE=InnoDB;\n" @@ -2780,7 +2780,7 @@ main(int argc, char **argv) // Fall back to Aria printf("\\d |\n" "IF (select count(*) from information_schema.global_variables where\n" - "variable_name='wsrep_on') = 1 THEN\n" + "variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n" "ALTER TABLE time_zone ENGINE=Aria;\n" "ALTER TABLE time_zone_name ENGINE=Aria;\n" "ALTER TABLE time_zone_transition ENGINE=Aria;\n" diff --git a/sql/unireg.cc b/sql/unireg.cc index d019b5f8a75..a1605dac2e6 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -432,7 +432,8 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING &table, pos+= reclength; int2store(pos, create_info->connect_string.length); pos+= 2; - memcpy(pos, create_info->connect_string.str, create_info->connect_string.length); + if (create_info->connect_string.length) + memcpy(pos, create_info->connect_string.str, create_info->connect_string.length); pos+= create_info->connect_string.length; int2store(pos, str_db_type.length); pos+= 2; diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt index 199a8a3fa8b..17b9d9664c7 100644 --- a/storage/connect/CMakeLists.txt +++ b/storage/connect/CMakeLists.txt @@ -318,9 +318,6 @@ ENDIF(CONNECT_WITH_MONGO) OPTION(CONNECT_WITH_REST "Compile CONNECT storage engine with REST support" ON) IF(CONNECT_WITH_REST) - MESSAGE(STATUS "=====> REST support is ON") - SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp tabrest.h) - add_definitions(-DREST_SUPPORT) FIND_PACKAGE(cpprestsdk QUIET) IF (cpprestsdk_FOUND) IF(UNIX) @@ -334,12 +331,8 @@ IF(CONNECT_WITH_REST) # Comment it out if not needed depending on your cpprestsdk installation. SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") ENDIF(UNIX) -# IF(REST_LIBRARY) why this? how about Windows - SET(CONNECT_SOURCES ${CONNECT_SOURCES} restget.cpp) - add_definitions(-DREST_SOURCE) -# ENDIF() - ELSE(NOT cpprestsdk_FOUND) -# MESSAGE(STATUS "=====> cpprestsdk package not found") + SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h) + add_definitions(-DREST_SUPPORT) ENDIF (cpprestsdk_FOUND) ENDIF(CONNECT_WITH_REST) diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 7f00b27df0e..4c5046ed763 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -95,6 +95,7 @@ struct set_numa_interleave_t " policy to MPOL_INTERLEAVE: " << strerror(errno); } + numa_bitmask_free(numa_mems_allowed); } } @@ -123,29 +124,6 @@ struct set_numa_interleave_t #endif #ifndef UNIV_INNOCHECKSUM -inline void* aligned_malloc(size_t size, size_t align) { - void *result; -#ifdef _MSC_VER - result = _aligned_malloc(size, align); -#elif defined (HAVE_POSIX_MEMALIGN) - if(posix_memalign(&result, align, size)) { - result = 0; - } -#else - /* Use unaligned malloc as fallback */ - result = malloc(size); -#endif - return result; -} - -inline void aligned_free(void *ptr) { -#ifdef _MSC_VER - _aligned_free(ptr); -#else - free(ptr); -#endif -} - buf_pool_t::io_buf_t::~io_buf_t() { for (buf_tmp_buffer_t* s = slots, *e = slots + n_slots; s != e; s++) { @@ -1665,6 +1643,7 @@ buf_chunk_init( " buffer pool page frames to MPOL_INTERLEAVE" " (error: " << strerror(errno) << ")."; } + numa_bitmask_free(numa_mems_allowed); } #endif /* HAVE_LIBNUMA */ diff --git a/storage/innobase/dict/dict0crea.cc b/storage/innobase/dict/dict0crea.cc index a07c89f3059..aa7913b3cbe 100644 --- a/storage/innobase/dict/dict0crea.cc +++ b/storage/innobase/dict/dict0crea.cc @@ -2233,45 +2233,3 @@ dict_replace_tablespace_in_dictionary( return(error); } - -/** Delete records from SYS_TABLESPACES and SYS_DATAFILES associated -with a particular tablespace ID. -@param[in] space Tablespace ID -@param[in,out] trx Current transaction -@return DB_SUCCESS if OK, dberr_t if the operation failed */ - -dberr_t -dict_delete_tablespace_and_datafiles( - ulint space, - trx_t* trx) -{ - dberr_t err = DB_SUCCESS; - - ut_d(dict_sys.assert_locked()); - ut_ad(srv_sys_tablespaces_open); - - trx->op_info = "delete tablespace and datafiles from dictionary"; - - pars_info_t* info = pars_info_create(); - ut_a(!is_system_tablespace(space)); - pars_info_add_int4_literal(info, "space", space); - - err = que_eval_sql(info, - "PROCEDURE P () IS\n" - "BEGIN\n" - "DELETE FROM SYS_TABLESPACES\n" - "WHERE SPACE = :space;\n" - "DELETE FROM SYS_DATAFILES\n" - "WHERE SPACE = :space;\n" - "END;\n", - FALSE, trx); - - if (err != DB_SUCCESS) { - ib::warn() << "Could not delete space_id " - << space << " from data dictionary"; - } - - trx->op_info = ""; - - return(err); -} diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 93a27028ec4..dbccff263a5 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -670,6 +670,27 @@ buf_page_is_corrupted( ulint fsp_flags) MY_ATTRIBUTE((warn_unused_result)); +inline void *aligned_malloc(size_t size, size_t align) +{ +#ifdef _MSC_VER + return _aligned_malloc(size, align); +#else + void *result; + if (posix_memalign(&result, align, size)) + result= NULL; + return result; +#endif +} + +inline void aligned_free(void *ptr) +{ +#ifdef _MSC_VER + _aligned_free(ptr); +#else + free(ptr); +#endif +} + /** Read the key version from the page. In full crc32 format, key version is stored at {0-3th} bytes. In other format, it is stored in 26th position. diff --git a/storage/innobase/include/buf0buf.ic b/storage/innobase/include/buf0buf.ic index 970119edd6e..31137ebf124 100644 --- a/storage/innobase/include/buf0buf.ic +++ b/storage/innobase/include/buf0buf.ic @@ -113,7 +113,17 @@ ulint buf_pool_get_n_pages(void) /*======================*/ { - return buf_pool_get_curr_size() >> srv_page_size_shift; + if (!buf_pool_ptr) + return buf_pool_get_curr_size() >> srv_page_size_shift; + + ulint chunk_size= 0; + for (uint i= 0; i < srv_buf_pool_instances; i++) + { + buf_pool_t* buf_pool = buf_pool_from_array(i); + for (uint j= 0; j < buf_pool->n_chunks; j++) + chunk_size+= buf_pool->chunks[j].size; + } + return chunk_size; } /********************************************************************//** diff --git a/storage/innobase/include/dict0crea.h b/storage/innobase/include/dict0crea.h index 6775154b73a..92f55ce4a14 100644 --- a/storage/innobase/include/dict0crea.h +++ b/storage/innobase/include/dict0crea.h @@ -199,16 +199,6 @@ dict_replace_tablespace_in_dictionary( const char* path, trx_t* trx); -/** Delete records from SYS_TABLESPACES and SYS_DATAFILES associated -with a particular tablespace ID. -@param[in] space Tablespace ID -@param[in,out] trx Current transaction -@return DB_SUCCESS if OK, dberr_t if the operation failed */ -dberr_t -dict_delete_tablespace_and_datafiles( - ulint space, - trx_t* trx); - /********************************************************************//** Add a foreign key definition to the data dictionary tables. @return error code or DB_SUCCESS */ diff --git a/storage/innobase/include/log0recv.h b/storage/innobase/include/log0recv.h index 85a4388b8a7..af97a472e78 100644 --- a/storage/innobase/include/log0recv.h +++ b/storage/innobase/include/log0recv.h @@ -107,14 +107,19 @@ bool recv_sys_add_to_parsing_buf(const byte* log_block, lsn_t scanned_lsn); /** Parse log records from a buffer and optionally store them to a hash table to wait merging to file pages. -@param[in] checkpoint_lsn the LSN of the latest checkpoint -@param[in] store whether to store page operations -@param[in] apply whether to apply the records +@param[in] checkpoint_lsn the LSN of the latest checkpoint +@param[in] store whether to store page operations +@param[in] available_memory memory to read the redo logs +@param[in] apply whether to apply the records @return whether MLOG_CHECKPOINT record was seen the first time, or corruption was noticed */ -bool recv_parse_log_recs(lsn_t checkpoint_lsn, store_t store, bool apply); +bool recv_parse_log_recs( + lsn_t checkpoint_lsn, + store_t* store, + ulint available_memory, + bool apply); -/** Moves the parsing buffer data left to the buffer start. */ +/** Moves the parsing buffer data left to the buffer start */ void recv_sys_justify_left_parsing_buf(); /** Report optimized DDL operation (without redo log), diff --git a/storage/innobase/include/page0page.ic b/storage/innobase/include/page0page.ic index 461efd9147d..21ab45427ff 100644 --- a/storage/innobase/include/page0page.ic +++ b/storage/innobase/include/page0page.ic @@ -652,6 +652,7 @@ page_rec_get_next_low( } ut_ad(page_rec_is_infimum(rec) + || (!page_is_leaf(page) && !page_has_prev(page)) || !(rec_get_info_bits(page + offs, comp) & REC_INFO_MIN_REC_FLAG)); diff --git a/storage/innobase/innodb.cmake b/storage/innobase/innodb.cmake index 964f1edb598..07ed7ed67ab 100644 --- a/storage/innobase/innodb.cmake +++ b/storage/innobase/innodb.cmake @@ -95,7 +95,8 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU") #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion") IF (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR - CMAKE_SYSTEM_PROCESSOR MATCHES "i386") + CMAKE_SYSTEM_PROCESSOR MATCHES "i386" AND + CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6) INCLUDE(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-fno-builtin-memcmp" HAVE_NO_BUILTIN_MEMCMP) IF (HAVE_NO_BUILTIN_MEMCMP) @@ -146,11 +147,6 @@ IF(NOT MSVC) SET_SOURCE_FILES_PROPERTIES(trx/trx0rec.cc PROPERTIES COMPILE_FLAGS -O1) ENDIF() - CHECK_FUNCTION_EXISTS(posix_memalign HAVE_POSIX_MEMALIGN) - IF(HAVE_POSIX_MEMALIGN) - ADD_DEFINITIONS(-DHAVE_POSIX_MEMALIGN) - ENDIF() - # Only use futexes on Linux if GCC atomics are available IF(NOT MSVC AND NOT CMAKE_CROSSCOMPILING) CHECK_C_SOURCE_RUNS( diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 9aecee0c217..510cef0fd32 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -758,7 +758,6 @@ recv_sys_var_init(void) recv_previous_parsed_rec_type = MLOG_SINGLE_REC_FLAG; recv_previous_parsed_rec_offset = 0; recv_previous_parsed_rec_is_multi = 0; - recv_n_pool_free_frames = 384; recv_max_page_lsn = 0; } @@ -841,12 +840,7 @@ void recv_sys_t::create() apply_log_recs = false; apply_batch_on = false; - ulint size = buf_pool_get_curr_size(); - /* Set appropriate value of recv_n_pool_free_frames. */ - if (size >= 10 << 20) { - /* Buffer pool of size greater than 10 MB. */ - recv_n_pool_free_frames = 512; - } + recv_n_pool_free_frames = buf_pool_get_n_pages() / 3; buf = static_cast<byte*>(ut_malloc_dontdump(RECV_PARSING_BUF_SIZE)); buf_size = RECV_PARSING_BUF_SIZE; @@ -860,7 +854,7 @@ void recv_sys_t::create() found_corrupt_fs = false; mlog_checkpoint_lsn = 0; - addr_hash = hash_create(size / 512); + addr_hash = hash_create(buf_pool_get_curr_size() / 512); n_addrs = 0; progress_time = time(NULL); recv_max_page_lsn = 0; @@ -2645,14 +2639,39 @@ recv_mlog_index_load(ulint space_id, ulint page_no, lsn_t lsn) } } +/** Check whether read redo log memory exceeds the available memory +of buffer pool. Store last_stored_lsn if it is not in last phase +@param[in] store whether to store page operations +@param[in] available_mem Available memory in buffer pool to + read redo logs. */ +static bool recv_sys_heap_check(store_t* store, ulint available_mem) +{ + if (*store != STORE_NO && mem_heap_get_size(recv_sys.heap) >= available_mem) + { + if (*store == STORE_YES) + recv_sys.last_stored_lsn= recv_sys.recovered_lsn; + + *store= STORE_NO; + DBUG_PRINT("ib_log",("Ran out of memory and last " + "stored lsn " LSN_PF " last stored offset " + ULINTPF "\n", + recv_sys.recovered_lsn, recv_sys.recovered_offset)); + return true; + } + + return false; +} + /** Parse log records from a buffer and optionally store them to a hash table to wait merging to file pages. -@param[in] checkpoint_lsn the LSN of the latest checkpoint -@param[in] store whether to store page operations -@param[in] apply whether to apply the records +@param[in] checkpoint_lsn the LSN of the latest checkpoint +@param[in] store whether to store page operations +@param[in] available_mem memory to read the redo logs +@param[in] apply whether to apply the records @return whether MLOG_CHECKPOINT record was seen the first time, or corruption was noticed */ -bool recv_parse_log_recs(lsn_t checkpoint_lsn, store_t store, bool apply) +bool recv_parse_log_recs(lsn_t checkpoint_lsn, store_t* store, + ulint available_mem, bool apply) { byte* ptr; byte* end_ptr; @@ -2664,6 +2683,7 @@ bool recv_parse_log_recs(lsn_t checkpoint_lsn, store_t store, bool apply) ulint space; ulint page_no; byte* body; + const bool last_phase = (*store == STORE_IF_EXISTS); ut_ad(log_mutex_own()); ut_ad(mutex_own(&recv_sys.mutex)); @@ -2678,6 +2698,12 @@ loop: return(false); } + /* Check for memory overflow and ignore the parsing of remaining + redo log records if InnoDB ran out of memory */ + if (recv_sys_heap_check(store, available_mem) && last_phase) { + return false; + } + switch (*ptr) { case MLOG_CHECKPOINT: #ifdef UNIV_LOG_LSN_DEBUG @@ -2778,7 +2804,7 @@ loop: break; #endif /* UNIV_LOG_LSN_DEBUG */ default: - switch (store) { + switch (*store) { case STORE_NO: break; case STORE_IF_EXISTS: @@ -2962,7 +2988,7 @@ corrupted_log: recv_parse_or_apply_log_rec_body(). */ break; default: - switch (store) { + switch (*store) { case STORE_NO: break; case STORE_IF_EXISTS: @@ -3005,7 +3031,6 @@ bool recv_sys_add_to_parsing_buf(const byte* log_block, lsn_t scanned_lsn) if (!recv_sys.parse_start_lsn) { /* Cannot start parsing yet because no start point for it found */ - return(false); } @@ -3026,7 +3051,6 @@ bool recv_sys_add_to_parsing_buf(const byte* log_block, lsn_t scanned_lsn) } if (more_len == 0) { - return(false); } @@ -3057,8 +3081,8 @@ bool recv_sys_add_to_parsing_buf(const byte* log_block, lsn_t scanned_lsn) /** Moves the parsing buffer data left to the buffer start. */ void recv_sys_justify_left_parsing_buf() { - ut_memmove(recv_sys.buf, recv_sys.buf + recv_sys.recovered_offset, - recv_sys.len - recv_sys.recovered_offset); + memmove(recv_sys.buf, recv_sys.buf + recv_sys.recovered_offset, + recv_sys.len - recv_sys.recovered_offset); recv_sys.len -= recv_sys.recovered_offset; @@ -3068,26 +3092,30 @@ void recv_sys_justify_left_parsing_buf() /** Scan redo log from a buffer and stores new log data to the parsing buffer. Parse and hash the log records if new data found. Apply log records automatically when the hash table becomes full. +@param[in] available_mem we let the hash table of recs to + grow to this size, at the maximum +@param[in,out] store_to_hash whether the records should be + stored to the hash table; this is + reset if just debug checking is + needed, or when the available_mem + runs out +@param[in] log_block log segment +@param[in] checkpoint_lsn latest checkpoint LSN +@param[in] start_lsn buffer start LSN +@param[in] end_lsn buffer end LSN +@param[in,out] contiguous_lsn it is known that all groups contain + contiguous log data upto this lsn +@param[out] group_scanned_lsn scanning succeeded upto this lsn @return true if not able to scan any more in this log group */ -static -bool -recv_scan_log_recs( -/*===============*/ - ulint available_memory,/*!< in: we let the hash table of recs - to grow to this size, at the maximum */ - store_t* store_to_hash, /*!< in,out: whether the records should be - stored to the hash table; this is reset - if just debug checking is needed, or - when the available_memory runs out */ - const byte* log_block, /*!< in: log segment */ - lsn_t checkpoint_lsn, /*!< in: latest checkpoint LSN */ - lsn_t start_lsn, /*!< in: buffer start LSN */ - lsn_t end_lsn, /*!< in: buffer end LSN */ - lsn_t* contiguous_lsn, /*!< in/out: it is known that all log - groups contain contiguous log data up - to this lsn */ - lsn_t* group_scanned_lsn)/*!< out: scanning succeeded up to - this lsn */ +static bool recv_scan_log_recs( + ulint available_mem, + store_t* store_to_hash, + const byte* log_block, + lsn_t checkpoint_lsn, + lsn_t start_lsn, + lsn_t end_lsn, + lsn_t* contiguous_lsn, + lsn_t* group_scanned_lsn) { lsn_t scanned_lsn = start_lsn; bool finished = false; @@ -3095,14 +3123,13 @@ recv_scan_log_recs( bool more_data = false; bool apply = recv_sys.mlog_checkpoint_lsn != 0; ulint recv_parsing_buf_size = RECV_PARSING_BUF_SIZE; - + const bool last_phase = (*store_to_hash == STORE_IF_EXISTS); ut_ad(start_lsn % OS_FILE_LOG_BLOCK_SIZE == 0); ut_ad(end_lsn % OS_FILE_LOG_BLOCK_SIZE == 0); ut_ad(end_lsn >= start_lsn + OS_FILE_LOG_BLOCK_SIZE); const byte* const log_end = log_block + ulint(end_lsn - start_lsn); - do { ut_ad(!finished); @@ -3213,6 +3240,13 @@ recv_scan_log_recs( = log_block_get_checkpoint_no(log_block); } + /* During last phase of scanning, there can be redo logs + left in recv_sys.buf to parse & store it in recv_sys.heap */ + if (last_phase + && recv_sys.recovered_lsn < recv_sys.scanned_lsn) { + more_data = true; + } + if (data_len < OS_FILE_LOG_BLOCK_SIZE) { /* Log data for this group ends here */ finished = true; @@ -3230,7 +3264,8 @@ recv_scan_log_recs( /* Try to parse more log records */ if (recv_parse_log_recs(checkpoint_lsn, - *store_to_hash, apply)) { + store_to_hash, available_mem, + apply)) { ut_ad(recv_sys.found_corrupt_log || recv_sys.found_corrupt_fs || recv_sys.mlog_checkpoint_lsn @@ -3239,22 +3274,18 @@ recv_scan_log_recs( goto func_exit; } - if (*store_to_hash != STORE_NO - && mem_heap_get_size(recv_sys.heap) > available_memory) { - - DBUG_PRINT("ib_log", ("Ran out of memory and last " - "stored lsn " LSN_PF, - recv_sys.recovered_lsn)); - - recv_sys.last_stored_lsn = recv_sys.recovered_lsn; - *store_to_hash = STORE_NO; - } + recv_sys_heap_check(store_to_hash, available_mem); if (recv_sys.recovered_offset > recv_parsing_buf_size / 4) { /* Move parsing buffer data to the buffer start */ - recv_sys_justify_left_parsing_buf(); } + + /* Need to re-parse the redo log which're stored + in recv_sys.buf */ + if (last_phase && *store_to_hash == STORE_NO) { + finished = false; + } } func_exit: @@ -3316,6 +3347,8 @@ recv_group_scan_log_recs( redo log records before we have finished the redo log scan. */ recv_apply_hashed_log_recs(false); + /* Rescan the redo logs from last stored lsn */ + end_lsn = recv_sys.recovered_lsn; } start_lsn = ut_uint64_align_down(end_lsn, diff --git a/storage/innobase/os/os0proc.cc b/storage/innobase/os/os0proc.cc index c4ecbcd5db9..32067297a24 100644 --- a/storage/innobase/os/os0proc.cc +++ b/storage/innobase/os/os0proc.cc @@ -153,6 +153,12 @@ os_mem_free_large( { ut_a(os_total_large_mem_allocated >= size); + // We could have manually poisoned that memory for ASAN. + // And we must unpoison it by ourself as specified in documentation + // for __asan_poison_memory_region() in sanitizer/asan_interface.h + // munmap() doesn't do it for us automatically. + UNIV_MEM_ALLOC(ptr, size); + #ifdef HAVE_LINUX_LARGE_PAGES if (my_use_large_pages && opt_large_page_size && !shmdt(ptr)) { os_total_large_mem_allocated -= size; diff --git a/storage/rocksdb/CMakeLists.txt b/storage/rocksdb/CMakeLists.txt index a285cd78d3b..f4f23ff08c6 100644 --- a/storage/rocksdb/CMakeLists.txt +++ b/storage/rocksdb/CMakeLists.txt @@ -248,6 +248,8 @@ IF(MSVC) IF(CMAKE_SIZEOF_VOID_P EQUAL 8) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267") ENDIF() +ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + SET_TARGET_PROPERTIES(rocksdb_tools sst_dump mysql_ldb PROPERTIES COMPILE_FLAGS "-Wno-error") ENDIF() # Enable ZSTD if available. Upstream rocksdb cmake will use WITH_ZSTD and set diff --git a/storage/rocksdb/build_rocksdb.cmake b/storage/rocksdb/build_rocksdb.cmake index 96da9737dbc..d7895b095ba 100644 --- a/storage/rocksdb/build_rocksdb.cmake +++ b/storage/rocksdb/build_rocksdb.cmake @@ -471,5 +471,5 @@ list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/build_version.cc) ADD_CONVENIENCE_LIBRARY(rocksdblib ${SOURCES}) target_link_libraries(rocksdblib ${THIRDPARTY_LIBS} ${SYSTEM_LIBS}) IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set_target_properties(rocksdblib PROPERTIES COMPILE_FLAGS "-fPIC -fno-builtin-memcmp") + set_target_properties(rocksdblib PROPERTIES COMPILE_FLAGS "-fPIC -fno-builtin-memcmp -Wno-error") endif() diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c index 91232a1e31f..17cb51ff8cb 100644 --- a/strings/ctype-simple.c +++ b/strings/ctype-simple.c @@ -1598,7 +1598,8 @@ my_strntoull10rnd_8bit(CHARSET_INFO *cs __attribute__((unused)), int shift= 0, digits= 0, negative, addon; /* Skip leading spaces and tabs */ - for ( ; str < end && (*str == ' ' || *str == '\t') ; str++); + for ( ; str < end && my_isspace(&my_charset_latin1, *str) ; ) + str++; if (str >= end) goto ret_edom; diff --git a/strings/my_strtoll10.c b/strings/my_strtoll10.c index 2311b4e5079..183829d7074 100644 --- a/strings/my_strtoll10.c +++ b/strings/my_strtoll10.c @@ -98,18 +98,25 @@ longlong my_strtoll10(const char *nptr, char **endptr, int *error) if (endptr) { end= *endptr; - while (s != end && (*s == ' ' || *s == '\t')) + /* Skip leading spaces */ + for ( ; s < end && my_isspace(&my_charset_latin1, *s) ; ) s++; + if (s == end) goto no_conv; } else { endptr= &dummy; /* Easier end test */ - while (*s == ' ' || *s == '\t') - s++; - if (!*s) - goto no_conv; + /* Skip leading spaces */ + for ( ; ; s++) + { + if (!*s) + goto no_conv; + if (!my_isspace(&my_charset_latin1, *s)) + break; + } + /* This number must be big to guard against a lot of pre-zeros */ end= s+65535; /* Can't be longer than this */ } diff --git a/support-files/mariadb.service.in b/support-files/mariadb.service.in index 8d2e57b8290..e7665ed1219 100644 --- a/support-files/mariadb.service.in +++ b/support-files/mariadb.service.in @@ -131,6 +131,13 @@ UMask=007 # LOAD DATA INFILE you can enable PrivateTmp=true for a little more security. PrivateTmp=false +# Set an explicit Start and Stop timeout of 900 seconds (15 minutes!) +# this is the same value as used in SysV init scripts in the past +# Galera might need a longer timeout, check the KB if you want to change this: +# https://mariadb.com/kb/en/library/systemd/#configuring-the-systemd-service-timeout +TimeoutStartSec=900 +TimeoutStopSec=900 + ## ## Options previously available to be set via [mysqld_safe] ## that now needs to be set by systemd config files as mysqld_safe diff --git a/support-files/mariadb@.service.in b/support-files/mariadb@.service.in index 4a49bd48766..ffefc2f22d8 100644 --- a/support-files/mariadb@.service.in +++ b/support-files/mariadb@.service.in @@ -243,6 +243,13 @@ UMask=007 # LOAD DATA INFILE you can enable PrivateTmp=true for a little more security. PrivateTmp=false +# Set an explicit Start and Stop timeout of 900 seconds (15 minutes!) +# this is the same value as used in SysV init scripts in the past +# if you need a longer timeout, check the KB: +# https://mariadb.com/kb/en/library/systemd/#configuring-the-systemd-service-timeout +TimeoutStartSec=900 +TimeoutStopSec=900 + # Controlling how multiple instances are separated. See top of this file. # Note: This service isn't User=mysql by default so we need to be explicit. # It is as an option here as a user may want to use the MYSQLD_MULTI_INSTANCE |