diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index 879e8132e8c..3858861113c 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -18559,3 +18559,498 @@ valdouble valint1 5 3289988 DROP TABLE t1,t2; # End of 10.4 tests +# MDEV-34506 2nd execution name resolution problem with pushdown into +# unions +# +# Statements affected by this bug need all the following to be true +# 1) a derived table table or view whose specification contains a set +# operation at the top level. +# 2) a grouping operator (group by/having) operating on a column alias +# other than in the first select of the union/intersect +# 3) an outer condition that will be pushed into all selects in this +# union/intersect, either into the where or having clause +# +# When pushing a condition into all selects of a unit with more than one +# select, pushdown_cond_for_derived() renames items so we can re-use the +# condition being pushed. +# These names need to be saved and reset for correct name resolution on +# second execution of prepared statements. +create table t1 (c1 int, c2 int, c3 int); +insert into t1 values (1,2,3),(1,2,2),(4,5,6); +insert into t1 values (17,8,9),(11,11,12); +create table t2 (c4 int, c5 int, c6 int); +insert into t2 values (7,8,9),(10,11,12); +prepare stmt from 'select * from +( +select c1, sum(c3) as s from t1 group by c1 +union +select c4 as c, sum(c6) as u from t2 group by c +) dt +where c1 > 6'; +execute stmt; +c1 s +11 12 +17 9 +7 9 +10 12 +execute stmt; +c1 s +11 12 +17 9 +7 9 +10 12 +prepare stmt from 'explain format=json select * from +( +select c1, sum(c3) as s from t1 group by c1 +union +select c4 as c, sum(c6) as u from t2 group by c +) dt +where c1 > 6'; +execute stmt; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 7, + "filtered": 100, + "attached_condition": "dt.c1 > 6", + "materialized": { + "query_block": { + "union_result": { + "table_name": "", + "access_type": "ALL", + "query_specifications": [ + { + "query_block": { + "select_id": 2, + "filesort": { + "sort_key": "t1.c1", + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 5, + "filtered": 100, + "attached_condition": "t1.c1 > 6" + } + } + } + } + }, + { + "query_block": { + "select_id": 3, + "operation": "UNION", + "filesort": { + "sort_key": "t2.c4", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 2, + "filtered": 100, + "attached_condition": "t2.c4 > 6" + } + } + } + } + } + ] + } + } + } + } + } +} +execute stmt; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 7, + "filtered": 100, + "attached_condition": "dt.c1 > 6", + "materialized": { + "query_block": { + "union_result": { + "table_name": "", + "access_type": "ALL", + "query_specifications": [ + { + "query_block": { + "select_id": 2, + "filesort": { + "sort_key": "t1.c1", + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 5, + "filtered": 100, + "attached_condition": "t1.c1 > 6" + } + } + } + } + }, + { + "query_block": { + "select_id": 3, + "operation": "UNION", + "filesort": { + "sort_key": "t2.c4", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 2, + "filtered": 100, + "attached_condition": "t2.c4 > 6" + } + } + } + } + } + ] + } + } + } + } + } +} +prepare stmt from 'select * from +( +select c1, c2, sum(c3) as s from t1 group by c1, c2 having s > 2 +union +select c4, c5, sum(c6) as u from t2 group by c4, c5 having u > 3 +) dt +where c2 > 5'; +execute stmt; +c1 c2 s +11 11 12 +17 8 9 +7 8 9 +10 11 12 +execute stmt; +c1 c2 s +11 11 12 +17 8 9 +7 8 9 +10 11 12 +prepare stmt from 'explain format=json select * from +( +select c1, c2, sum(c3) as s from t1 group by c1, c2 having s > 2 +union +select c4, c5, sum(c6) as u from t2 group by c4, c5 having u > 3 +) dt +where c2 > 5'; +execute stmt; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 7, + "filtered": 100, + "attached_condition": "dt.c2 > 5", + "materialized": { + "query_block": { + "union_result": { + "table_name": "", + "access_type": "ALL", + "query_specifications": [ + { + "query_block": { + "select_id": 2, + "having_condition": "s > 2", + "filesort": { + "sort_key": "t1.c1, t1.c2", + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 5, + "filtered": 100, + "attached_condition": "t1.c2 > 5" + } + } + } + } + }, + { + "query_block": { + "select_id": 3, + "operation": "UNION", + "having_condition": "s > 3", + "filesort": { + "sort_key": "t2.c4, t2.c5", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 2, + "filtered": 100, + "attached_condition": "t2.c5 > 5" + } + } + } + } + } + ] + } + } + } + } + } +} +execute stmt; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 7, + "filtered": 100, + "attached_condition": "dt.c2 > 5", + "materialized": { + "query_block": { + "union_result": { + "table_name": "", + "access_type": "ALL", + "query_specifications": [ + { + "query_block": { + "select_id": 2, + "having_condition": "s > 2", + "filesort": { + "sort_key": "t1.c1, t1.c2", + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 5, + "filtered": 100, + "attached_condition": "t1.c2 > 5" + } + } + } + } + }, + { + "query_block": { + "select_id": 3, + "operation": "UNION", + "having_condition": "s > 3", + "filesort": { + "sort_key": "t2.c4, t2.c5", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 2, + "filtered": 100, + "attached_condition": "t2.c5 > 5" + } + } + } + } + } + ] + } + } + } + } + } +} +prepare stmt from 'select * +from +( +select c1, c2, max(c3) as max_c, avg(c3) as avg_c +from t1 +group by c1,c2 +having max_c < 7 +union +select c4, c5, max(c6) as u, avg(c6) as w +from t2 +group by c4, c5 +having u < 10 +) dt, +t2 +where dt.max_c > 6 and t2.c6 > dt.c1'; +execute stmt; +c1 c2 max_c avg_c c4 c5 c6 +7 8 9 9.0000 7 8 9 +7 8 9 9.0000 10 11 12 +execute stmt; +c1 c2 max_c avg_c c4 c5 c6 +7 8 9 9.0000 7 8 9 +7 8 9 9.0000 10 11 12 +prepare stmt from 'explain format=json select * +from +( +select c1, c2, max(c3) as max_c, avg(c3) as avg_c +from t1 +group by c1,c2 +having max_c < 7 +union +select c4, c5, max(c6) as u, avg(c6) as w +from t2 +group by c4, c5 +having u < 10 +) dt, +t2 +where dt.max_c > 6 and t2.c6 > dt.c1'; +execute stmt; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 2, + "filtered": 100 + }, + "block-nl-join": { + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 7, + "filtered": 100, + "attached_condition": "dt.max_c > 6" + }, + "buffer_type": "flat", + "buffer_size": "173", + "join_type": "BNL", + "attached_condition": "t2.c6 > dt.c1", + "materialized": { + "query_block": { + "union_result": { + "table_name": "", + "access_type": "ALL", + "query_specifications": [ + { + "query_block": { + "select_id": 2, + "having_condition": "max_c < 7 and max_c > 6", + "filesort": { + "sort_key": "t1.c1, t1.c2", + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 5, + "filtered": 100 + } + } + } + } + }, + { + "query_block": { + "select_id": 3, + "operation": "UNION", + "having_condition": "max_c < 10 and max_c > 6", + "filesort": { + "sort_key": "t2.c4, t2.c5", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 2, + "filtered": 100 + } + } + } + } + } + ] + } + } + } + } + } +} +execute stmt; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 2, + "filtered": 100 + }, + "block-nl-join": { + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 7, + "filtered": 100, + "attached_condition": "dt.max_c > 6" + }, + "buffer_type": "flat", + "buffer_size": "173", + "join_type": "BNL", + "attached_condition": "t2.c6 > dt.c1", + "materialized": { + "query_block": { + "union_result": { + "table_name": "", + "access_type": "ALL", + "query_specifications": [ + { + "query_block": { + "select_id": 2, + "having_condition": "max_c < 7 and max_c > 6", + "filesort": { + "sort_key": "t1.c1, t1.c2", + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 5, + "filtered": 100 + } + } + } + } + }, + { + "query_block": { + "select_id": 3, + "operation": "UNION", + "having_condition": "max_c < 10 and max_c > 6", + "filesort": { + "sort_key": "t2.c4, t2.c5", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 2, + "filtered": 100 + } + } + } + } + } + ] + } + } + } + } + } +} +drop table t1, t2; +# End of 10.5 tests diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test index 9d8e18af956..0f23f0f747f 100644 --- a/mysql-test/main/derived_cond_pushdown.test +++ b/mysql-test/main/derived_cond_pushdown.test @@ -4103,3 +4103,90 @@ eval $q; DROP TABLE t1,t2; --echo # End of 10.4 tests + +--echo # MDEV-34506 2nd execution name resolution problem with pushdown into +--echo # unions +--echo # +--echo # Statements affected by this bug need all the following to be true +--echo # 1) a derived table table or view whose specification contains a set +--echo # operation at the top level. +--echo # 2) a grouping operator (group by/having) operating on a column alias +--echo # other than in the first select of the union/intersect +--echo # 3) an outer condition that will be pushed into all selects in this +--echo # union/intersect, either into the where or having clause +--echo # +--echo # When pushing a condition into all selects of a unit with more than one +--echo # select, pushdown_cond_for_derived() renames items so we can re-use the +--echo # condition being pushed. +--echo # These names need to be saved and reset for correct name resolution on +--echo # second execution of prepared statements. + +create table t1 (c1 int, c2 int, c3 int); +insert into t1 values (1,2,3),(1,2,2),(4,5,6); +insert into t1 values (17,8,9),(11,11,12); +create table t2 (c4 int, c5 int, c6 int); +insert into t2 values (7,8,9),(10,11,12); +let $q=select * from + ( + select c1, sum(c3) as s from t1 group by c1 + union + select c4 as c, sum(c6) as u from t2 group by c + ) dt + where c1 > 6; +eval prepare stmt from '$q'; +execute stmt; +execute stmt; + +eval prepare stmt from 'explain format=json $q'; +--source include/analyze-format.inc +execute stmt; +--source include/analyze-format.inc +execute stmt; + +let $q=select * from + ( + select c1, c2, sum(c3) as s from t1 group by c1, c2 having s > 2 + union + select c4, c5, sum(c6) as u from t2 group by c4, c5 having u > 3 + ) dt + where c2 > 5; + +eval prepare stmt from '$q'; +execute stmt; +execute stmt; + +eval prepare stmt from 'explain format=json $q'; +--source include/analyze-format.inc +execute stmt; +--source include/analyze-format.inc +execute stmt; + +let $q=select * + from + ( + select c1, c2, max(c3) as max_c, avg(c3) as avg_c + from t1 + group by c1,c2 + having max_c < 7 + union + select c4, c5, max(c6) as u, avg(c6) as w + from t2 + group by c4, c5 + having u < 10 + ) dt, + t2 + where dt.max_c > 6 and t2.c6 > dt.c1; + +eval prepare stmt from '$q'; +execute stmt; +execute stmt; + +eval prepare stmt from 'explain format=json $q'; +--source include/analyze-format.inc +execute stmt; +--source include/analyze-format.inc +execute stmt; + +drop table t1, t2; + +--echo # End of 10.5 tests diff --git a/mysql-test/main/item_types.result b/mysql-test/main/item_types.result new file mode 100644 index 00000000000..865b4f612ae --- /dev/null +++ b/mysql-test/main/item_types.result @@ -0,0 +1,16 @@ +# +# MDEV-34634 Types mismatch when cloning items causes debug assertion +# +CREATE TABLE t1 (a DATETIME); +SET optimizer_switch='derived_merge=off'; +SELECT * FROM (SELECT * FROM t1) AS t1 WHERE a=''; +a +Warnings: +Warning 1292 Truncated incorrect datetime value: '' +DROP TABLE t1; +CREATE TABLE t1 (c YEAR); +CREATE TABLE t2 (c INT); +SELECT * FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.c<=>5; +c c +DROP TABLE t1, t2; +SET optimizer_switch=default; diff --git a/mysql-test/main/item_types.test b/mysql-test/main/item_types.test new file mode 100644 index 00000000000..f43bfe1a8ac --- /dev/null +++ b/mysql-test/main/item_types.test @@ -0,0 +1,15 @@ +--echo # +--echo # MDEV-34634 Types mismatch when cloning items causes debug assertion +--echo # + +CREATE TABLE t1 (a DATETIME); +SET optimizer_switch='derived_merge=off'; +SELECT * FROM (SELECT * FROM t1) AS t1 WHERE a=''; +DROP TABLE t1; + +CREATE TABLE t1 (c YEAR); +CREATE TABLE t2 (c INT); +SELECT * FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.c<=>5; +DROP TABLE t1, t2; + +SET optimizer_switch=default; diff --git a/mysql-test/main/join_cache.result b/mysql-test/main/join_cache.result index e59e4d39cfd..9f58abaeb64 100644 --- a/mysql-test/main/join_cache.result +++ b/mysql-test/main/join_cache.result @@ -6420,3 +6420,23 @@ DROP TABLE t1,t2,t3; # # End of 10.4 tests # +# +# MDEV-34580: Assertion `(key_part->key_part_flag & 4) == 0' failed key_hashnr +# +SET join_cache_level=3; +CREATE TABLE t1 ( a TIMESTAMP , b varchar(100), c varchar(10) ) ; +INSERT INTO t1 (b,c) VALUES ('GHOBS','EMLCG'),('t','p'); +CREATE TABLE t2 (a varchar(100), b varchar(100), c varchar(10) , KEY b (b(66))) ; +insert into t2 select seq, seq, seq from seq_1_to_20; +explain +SELECT t1.a FROM t1 JOIN t2 ON t1.b = t2.b ; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t2 hash_ALL b #hash#b 69 test.t1.b 20 Using where; Using join buffer (flat, BNLH join) +SELECT t1.a FROM t1 JOIN t2 ON t1.b = t2.b ; +a +set join_cache_level=default; +DROP TABLE t1, t2; +# +# End of 10.5 tests +# diff --git a/mysql-test/main/join_cache.test b/mysql-test/main/join_cache.test index 382fbfda80a..623abb8116a 100644 --- a/mysql-test/main/join_cache.test +++ b/mysql-test/main/join_cache.test @@ -4299,3 +4299,25 @@ DROP TABLE t1,t2,t3; --echo # --echo # End of 10.4 tests --echo # + +--echo # +--echo # MDEV-34580: Assertion `(key_part->key_part_flag & 4) == 0' failed key_hashnr +--echo # +--source include/have_sequence.inc +SET join_cache_level=3; + +CREATE TABLE t1 ( a TIMESTAMP , b varchar(100), c varchar(10) ) ; +INSERT INTO t1 (b,c) VALUES ('GHOBS','EMLCG'),('t','p'); + +CREATE TABLE t2 (a varchar(100), b varchar(100), c varchar(10) , KEY b (b(66))) ; +insert into t2 select seq, seq, seq from seq_1_to_20; + +explain +SELECT t1.a FROM t1 JOIN t2 ON t1.b = t2.b ; +SELECT t1.a FROM t1 JOIN t2 ON t1.b = t2.b ; + +set join_cache_level=default; +DROP TABLE t1, t2; +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/mysql-test/main/json_debug_nonembedded.result b/mysql-test/main/json_debug_nonembedded_noasan.result similarity index 100% rename from mysql-test/main/json_debug_nonembedded.result rename to mysql-test/main/json_debug_nonembedded_noasan.result diff --git a/mysql-test/main/json_debug_nonembedded.test b/mysql-test/main/json_debug_nonembedded_noasan.test similarity index 95% rename from mysql-test/main/json_debug_nonembedded.test rename to mysql-test/main/json_debug_nonembedded_noasan.test index cecb9f1f6ed..e68a2ac956a 100644 --- a/mysql-test/main/json_debug_nonembedded.test +++ b/mysql-test/main/json_debug_nonembedded_noasan.test @@ -1,5 +1,6 @@ -- source include/not_embedded.inc --source include/have_debug.inc +--source include/not_asan.inc --echo # --echo # Beginning of 10.6 test diff --git a/mysql-test/main/win.result b/mysql-test/main/win.result index e98f34b79d2..520fc104c91 100644 --- a/mysql-test/main/win.result +++ b/mysql-test/main/win.result @@ -1247,15 +1247,10 @@ insert into t1 values (1,1,'foo'); insert into t1 values (2,2,'bar'); select count(*) over (order by a,b -range between unbounded preceding and current row) as count +range between 1 preceding and current row) as count from t1; ERROR HY000: RANGE-type frame requires ORDER BY clause with single sort key select -count(*) over (order by c -range between unbounded preceding and current row) as count -from t1; -ERROR HY000: Numeric datatype is required for RANGE-type frame -select count(*) over (order by a range between 'abcd' preceding and current row) as count from t1; @@ -1277,6 +1272,56 @@ rows between current row and 3.14 following) as count from t1; ERROR HY000: Integer is required for ROWS-type frame # +# MDEV-19052 Range-type window frame supports only numeric datatype +# +select +count(*) over (order by c +range between unbounded preceding and current row) as r +from t1; +r +1 +2 +select +count(*) over (order by c +range between current row and unbounded following) as r +from t1; +r +2 +1 +select +count(*) over (order by c +range between unbounded preceding and unbounded following) as r +from t1; +r +2 +2 +create table t2 (a int, b varchar(5)); +insert into t2 values (1,'a'), (2, 'b'), (3, 'c'); +select sum(a) over (order by b range between unbounded preceding and current row) as r from t2; +r +1 +3 +6 +insert into t1 values (3,3,'goo'); +insert into t1 values (3,1,'har'); +insert into t1 values (1,4,'har'); +select a, b, sum(b) over (order by a, b desc range between unbounded preceding and current row) as r from t1; +a b r +1 4 4 +1 1 5 +2 2 7 +3 3 10 +3 1 11 +select a, b, sum(b) over (order by a desc, b range between unbounded preceding and current row) as r from t1; +a b r +3 1 1 +3 3 4 +2 2 6 +1 1 7 +1 4 11 +drop table t2; +delete from t1 where a >= 3 or b = 4; +# # EXCLUDE clause is parsed but not supported # select diff --git a/mysql-test/main/win.test b/mysql-test/main/win.test index d599221b68e..99efc4e8672 100644 --- a/mysql-test/main/win.test +++ b/mysql-test/main/win.test @@ -784,13 +784,7 @@ insert into t1 values (2,2,'bar'); --error ER_RANGE_FRAME_NEEDS_SIMPLE_ORDERBY select count(*) over (order by a,b - range between unbounded preceding and current row) as count -from t1; - ---error ER_WRONG_TYPE_FOR_RANGE_FRAME -select - count(*) over (order by c - range between unbounded preceding and current row) as count + range between 1 preceding and current row) as count from t1; --error ER_WRONG_TYPE_FOR_RANGE_FRAME @@ -818,6 +812,41 @@ select rows between current row and 3.14 following) as count from t1; +--echo # +--echo # MDEV-19052 Range-type window frame supports only numeric datatype +--echo # + +select + count(*) over (order by c + range between unbounded preceding and current row) as r +from t1; + +select + count(*) over (order by c + range between current row and unbounded following) as r +from t1; + +select + count(*) over (order by c + range between unbounded preceding and unbounded following) as r +from t1; + +create table t2 (a int, b varchar(5)); +insert into t2 values (1,'a'), (2, 'b'), (3, 'c'); + +select sum(a) over (order by b range between unbounded preceding and current row) as r from t2; + +insert into t1 values (3,3,'goo'); +insert into t1 values (3,1,'har'); +insert into t1 values (1,4,'har'); + +select a, b, sum(b) over (order by a, b desc range between unbounded preceding and current row) as r from t1; + +select a, b, sum(b) over (order by a desc, b range between unbounded preceding and current row) as r from t1; + +drop table t2; +delete from t1 where a >= 3 or b = 4; + --echo # --echo # EXCLUDE clause is parsed but not supported --echo # @@ -843,6 +872,9 @@ select exclude group) as count from t1; + + + # EXCLUDE NO OTHERS means 'don't exclude anything' select count(*) over (order by a diff --git a/mysql-test/suite/encryption/r/innodb_encryption_discard_import.result b/mysql-test/suite/encryption/r/innodb_encryption_discard_import.result index 18082027660..95797da2e15 100644 --- a/mysql-test/suite/encryption/r/innodb_encryption_discard_import.result +++ b/mysql-test/suite/encryption/r/innodb_encryption_discard_import.result @@ -1,3 +1,5 @@ +SET @start_encr_threads = @@global.innodb_encryption_threads; +SET @start_encrypt_tables = @@global.innodb_encrypt_tables; CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB encrypted=yes; CREATE TABLE t2 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB; CREATE TABLE t3 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB row_format=compressed encrypted=yes; @@ -116,3 +118,42 @@ NOT FOUND /temp/ in t2.ibd # t3 ... on expecting NOT FOUND UNLOCK TABLES; DROP TABLE t1, t2, t3; +# +# MDEV-34670 IMPORT TABLESPACE unnecessary traverses +# tablespace list +# +SET GLOBAL innodb_encrypt_tables= OFF; +SET GLOBAL innodb_encryption_threads= 0; +CREATE TABLE t1(f1 int,f2 text)ENGINE=InnoDB; +INSERT INTO t1 VALUES(1, "InnoDB"); +CREATE TABLE t2 LIKE t1; +ALTER TABLE t2 DISCARD TABLESPACE; +FLUSH TABLES t1 FOR EXPORT; +UNLOCK TABLES; +ALTER TABLE t2 IMPORT TABLESPACE; +SET GLOBAL innodb_encryption_threads=2; +SET GLOBAL innodb_encrypt_tables = ON; +# Wait max 10 min for key encryption threads to encrypt all spaces +SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 +AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; +NAME +SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 +AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; +NAME +innodb_system +test/t1 +test/t2 +SET GLOBAL innodb_encrypt_tables = OFF; +# Wait max 10 min for key encryption threads to decrypt all spaces +SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 +AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; +NAME +innodb_system +test/t1 +test/t2 +SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 +AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; +NAME +DROP TABLE t1, t2; +SET GLOBAL innodb_encryption_threads=@start_encr_threads; +SET GLOBAL innodb_encrypt_tables=@start_encrypt_tables; diff --git a/mysql-test/suite/encryption/r/tempfiles_encrypted.result b/mysql-test/suite/encryption/r/tempfiles_encrypted.result index 0f12546995c..029e5b49738 100644 --- a/mysql-test/suite/encryption/r/tempfiles_encrypted.result +++ b/mysql-test/suite/encryption/r/tempfiles_encrypted.result @@ -1253,15 +1253,10 @@ insert into t1 values (1,1,'foo'); insert into t1 values (2,2,'bar'); select count(*) over (order by a,b -range between unbounded preceding and current row) as count +range between 1 preceding and current row) as count from t1; ERROR HY000: RANGE-type frame requires ORDER BY clause with single sort key select -count(*) over (order by c -range between unbounded preceding and current row) as count -from t1; -ERROR HY000: Numeric datatype is required for RANGE-type frame -select count(*) over (order by a range between 'abcd' preceding and current row) as count from t1; @@ -1283,6 +1278,56 @@ rows between current row and 3.14 following) as count from t1; ERROR HY000: Integer is required for ROWS-type frame # +# MDEV-19052 Range-type window frame supports only numeric datatype +# +select +count(*) over (order by c +range between unbounded preceding and current row) as r +from t1; +r +1 +2 +select +count(*) over (order by c +range between current row and unbounded following) as r +from t1; +r +2 +1 +select +count(*) over (order by c +range between unbounded preceding and unbounded following) as r +from t1; +r +2 +2 +create table t2 (a int, b varchar(5)); +insert into t2 values (1,'a'), (2, 'b'), (3, 'c'); +select sum(a) over (order by b range between unbounded preceding and current row) as r from t2; +r +1 +3 +6 +insert into t1 values (3,3,'goo'); +insert into t1 values (3,1,'har'); +insert into t1 values (1,4,'har'); +select a, b, sum(b) over (order by a, b desc range between unbounded preceding and current row) as r from t1; +a b r +1 4 4 +1 1 5 +2 2 7 +3 3 10 +3 1 11 +select a, b, sum(b) over (order by a desc, b range between unbounded preceding and current row) as r from t1; +a b r +3 1 1 +3 3 4 +2 2 6 +1 1 7 +1 4 11 +drop table t2; +delete from t1 where a >= 3 or b = 4; +# # EXCLUDE clause is parsed but not supported # select diff --git a/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test b/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test index 5f02d966e7e..e33aaec3e21 100644 --- a/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test +++ b/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test @@ -2,7 +2,8 @@ -- source include/have_example_key_management_plugin.inc -- source include/not_valgrind.inc -- source include/not_embedded.inc - +SET @start_encr_threads = @@global.innodb_encryption_threads; +SET @start_encrypt_tables = @@global.innodb_encrypt_tables; let MYSQLD_DATADIR = `SELECT @@datadir`; --let SEARCH_RANGE = 10000000 @@ -124,3 +125,56 @@ FLUSH TABLES t1, t2, t3 FOR EXPORT; UNLOCK TABLES; DROP TABLE t1, t2, t3; + +--echo # +--echo # MDEV-34670 IMPORT TABLESPACE unnecessary traverses +--echo # tablespace list +--echo # +SET GLOBAL innodb_encrypt_tables= OFF; +SET GLOBAL innodb_encryption_threads= 0; + +CREATE TABLE t1(f1 int,f2 text)ENGINE=InnoDB; +INSERT INTO t1 VALUES(1, "InnoDB"); +CREATE TABLE t2 LIKE t1; +ALTER TABLE t2 DISCARD TABLESPACE; +FLUSH TABLES t1 FOR EXPORT; +--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg +--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd +UNLOCK TABLES; +ALTER TABLE t2 IMPORT TABLESPACE; + +SET GLOBAL innodb_encryption_threads=2; +SET GLOBAL innodb_encrypt_tables = ON; + +--let $tables_count= `select count(*) + @@global.innodb_undo_tablespaces + 1 from information_schema.tables where engine = 'InnoDB'` + +--echo # Wait max 10 min for key encryption threads to encrypt all spaces +--let $wait_timeout= 600 +--let $wait_condition=SELECT COUNT(*) >= $tables_count FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0; +--source include/wait_condition.inc + +--sorted_result +SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 +AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; +--sorted_result +SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 +AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; + +SET GLOBAL innodb_encrypt_tables = OFF; + +--echo # Wait max 10 min for key encryption threads to decrypt all spaces +--let $wait_timeout= 600 +--let $wait_condition=SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0; +--source include/wait_condition.inc + +--sorted_result +SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 +AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; + +--sorted_result +SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 +AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; + +DROP TABLE t1, t2; +SET GLOBAL innodb_encryption_threads=@start_encr_threads; +SET GLOBAL innodb_encrypt_tables=@start_encrypt_tables; diff --git a/mysql-test/suite/innodb/r/import_bugs.result b/mysql-test/suite/innodb/r/import_bugs.result index 26845e55567..20e70f03fdf 100644 --- a/mysql-test/suite/innodb/r/import_bugs.result +++ b/mysql-test/suite/innodb/r/import_bugs.result @@ -65,6 +65,32 @@ id 4 5 DROP TABLE t2; +# +# MDEV-34181 Instant table aborts after discard tablespace +# +CREATE TABLE t1(c3 INT, c2 INT, c1 INT KEY)ENGINE=InnoDB; +INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2); +CREATE TABLE t2 (c1 INT KEY) ENGINE=InnoDB; +INSERT INTO t2 VALUES(1); +ALTER TABLE t2 ADD c2 INT; +FLUSH TABLES t1 FOR EXPORT; +UNLOCK TABLES; +ALTER TABLE t2 DISCARD TABLESPACE; +ALTER TABLE t2 ADD c3 INT FIRST; +Warnings: +Warning 1814 Tablespace has been discarded for table `t2` +ALTER TABLE t2 IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t2.cfg', will attempt to import without schema verification +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c3` int(11) DEFAULT NULL, + `c1` int(11) NOT NULL, + `c2` int(11) DEFAULT NULL, + PRIMARY KEY (`c1`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2, t1; # End of 10.5 tests # # MDEV-27006 Assertion `!lock_trx_has_sys_table_locks(trx)' diff --git a/mysql-test/suite/innodb/t/import_bugs.test b/mysql-test/suite/innodb/t/import_bugs.test index d22b4b67272..bab4a37e22a 100644 --- a/mysql-test/suite/innodb/t/import_bugs.test +++ b/mysql-test/suite/innodb/t/import_bugs.test @@ -82,6 +82,26 @@ INSERT INTO t2() VALUES(); SELECT * FROM t2 ORDER BY id; DROP TABLE t2; +--echo # +--echo # MDEV-34181 Instant table aborts after discard tablespace +--echo # +CREATE TABLE t1(c3 INT, c2 INT, c1 INT KEY)ENGINE=InnoDB; +INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2); +CREATE TABLE t2 (c1 INT KEY) ENGINE=InnoDB; +INSERT INTO t2 VALUES(1); +ALTER TABLE t2 ADD c2 INT; +FLUSH TABLES t1 FOR EXPORT; +let $datadir=`select @@datadir`; +--copy_file $datadir/test/t1.ibd $datadir/test/imp_t1.ibd +UNLOCK TABLES; +ALTER TABLE t2 DISCARD TABLESPACE; +ALTER TABLE t2 ADD c3 INT FIRST; +--copy_file $datadir/test/imp_t1.ibd $datadir/test/t2.ibd + +--replace_regex /opening '.*\/test\//opening '.\/test\// +ALTER TABLE t2 IMPORT TABLESPACE; +SHOW CREATE TABLE t2; +DROP TABLE t2, t1; --echo # End of 10.5 tests --echo # diff --git a/mysql-test/suite/rpl/r/rpl_mysqldump_gtid_slave_pos.result b/mysql-test/suite/rpl/r/rpl_mysqldump_gtid_slave_pos.result index 301605d5d8d..1849f896758 100644 --- a/mysql-test/suite/rpl/r/rpl_mysqldump_gtid_slave_pos.result +++ b/mysql-test/suite/rpl/r/rpl_mysqldump_gtid_slave_pos.result @@ -30,6 +30,7 @@ insert into t1 set a = 4; insert into t1 set a = 3; insert into t1 set a = 2; insert into t1 set a = 1; +include/save_master_gtid.inc connection slave; include/start_slave.inc include/sync_with_master_gtid.inc diff --git a/mysql-test/suite/rpl/t/rpl_mysqldump_gtid_slave_pos.test b/mysql-test/suite/rpl/t/rpl_mysqldump_gtid_slave_pos.test index 74d231731c7..e66a92a6153 100644 --- a/mysql-test/suite/rpl/t/rpl_mysqldump_gtid_slave_pos.test +++ b/mysql-test/suite/rpl/t/rpl_mysqldump_gtid_slave_pos.test @@ -44,6 +44,7 @@ while ($i) eval insert into t1 set a = $i; --dec $i } +--source include/save_master_gtid.inc --connection slave --source include/start_slave.inc diff --git a/mysys/crc32/crc32c_x86.cc b/mysys/crc32/crc32c_x86.cc index 0a4fd9db812..3ddddf1303c 100644 --- a/mysys/crc32/crc32c_x86.cc +++ b/mysys/crc32/crc32c_x86.cc @@ -28,7 +28,8 @@ # elif __GNUC__ >= 14 || (defined __clang_major__ && __clang_major__ >= 18) # define TARGET "pclmul,evex512,avx512f,avx512dq,avx512bw,avx512vl,vpclmulqdq" # define USE_VPCLMULQDQ __attribute__((target(TARGET))) -# elif __GNUC__ >= 11 || (defined __clang_major__ && __clang_major__ >= 8) +# elif __GNUC__ >= 11 || (defined __clang_major__ && __clang_major__ >= 9) +/* clang 8 does not support _xgetbv(), which we also need */ # define TARGET "pclmul,avx512f,avx512dq,avx512bw,avx512vl,vpclmulqdq" # define USE_VPCLMULQDQ __attribute__((target(TARGET))) # endif @@ -38,6 +39,7 @@ extern "C" unsigned crc32c_sse42(unsigned crc, const void* buf, size_t size); constexpr uint32_t cpuid_ecx_SSE42= 1U << 20; constexpr uint32_t cpuid_ecx_SSE42_AND_PCLMUL= cpuid_ecx_SSE42 | 1U << 1; +constexpr uint32_t cpuid_ecx_XSAVE= 1U << 26; static uint32_t cpuid_ecx() { @@ -382,8 +384,19 @@ static unsigned crc32_avx512(unsigned crc, const char *buf, size_t size, } } -static ATTRIBUTE_NOINLINE int have_vpclmulqdq() +#ifdef __GNUC__ +__attribute__((target("xsave"))) +#endif +static bool os_have_avx512() { + // The following flags must be set: SSE, AVX, OPMASK, ZMM_HI256, HI16_ZMM + return !(~_xgetbv(0 /*_XCR_XFEATURE_ENABLED_MASK*/) & 0xe6); +} + +static ATTRIBUTE_NOINLINE bool have_vpclmulqdq(uint32_t cpuid_ecx) +{ + if (!(cpuid_ecx & cpuid_ecx_XSAVE) || !os_have_avx512()) + return false; # ifdef _MSC_VER int regs[4]; __cpuidex(regs, 7, 0); @@ -410,10 +423,11 @@ static unsigned crc32c_vpclmulqdq(unsigned crc, const void *buf, size_t size) extern "C" my_crc32_t crc32_pclmul_enabled(void) { - if (~cpuid_ecx() & cpuid_ecx_SSE42_AND_PCLMUL) + const uint32_t ecx= cpuid_ecx(); + if (~ecx & cpuid_ecx_SSE42_AND_PCLMUL) return nullptr; #ifdef USE_VPCLMULQDQ - if (have_vpclmulqdq()) + if (have_vpclmulqdq(ecx)) return crc32_vpclmulqdq; #endif return crc32_pclmul; @@ -421,19 +435,20 @@ extern "C" my_crc32_t crc32_pclmul_enabled(void) extern "C" my_crc32_t crc32c_x86_available(void) { + const uint32_t ecx= cpuid_ecx(); #ifdef USE_VPCLMULQDQ - if (have_vpclmulqdq()) + if (have_vpclmulqdq(ecx)) return crc32c_vpclmulqdq; #endif #if SIZEOF_SIZE_T == 8 - switch (cpuid_ecx() & cpuid_ecx_SSE42_AND_PCLMUL) { + switch (ecx & cpuid_ecx_SSE42_AND_PCLMUL) { case cpuid_ecx_SSE42_AND_PCLMUL: return crc32c_3way; case cpuid_ecx_SSE42: return crc32c_sse42; } #else - if (cpuid_ecx() & cpuid_ecx_SSE42) + if (ecx & cpuid_ecx_SSE42) return crc32c_sse42; #endif return nullptr; diff --git a/sql/item.cc b/sql/item.cc index 06d64b420db..41fec9096f8 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -3906,7 +3906,7 @@ void Item_decimal::set_decimal_value(my_decimal *value_par) } -Item *Item_decimal::do_clone_const_item(THD *thd) const +Item *Item_decimal::clone_item(THD *thd) const { return new (thd->mem_root) Item_decimal(thd, name.str, &decimal_value, decimals, max_length); @@ -3927,7 +3927,7 @@ my_decimal *Item_float::val_decimal(my_decimal *decimal_value) } -Item *Item_float::do_clone_const_item(THD *thd) const +Item *Item_float::clone_item(THD *thd) const { return new (thd->mem_root) Item_float(thd, name.str, value, decimals, max_length); @@ -4091,7 +4091,7 @@ Item *Item_null::safe_charset_converter(THD *thd, CHARSET_INFO *tocs) return this; } -Item *Item_null::do_clone_const_item(THD *thd) const +Item *Item_null::clone_item(THD *thd) const { return new (thd->mem_root) Item_null(thd, name.str); } @@ -4933,7 +4933,7 @@ Item *Item_param::value_clone_item(THD *thd) const /* see comments in the header file */ Item * -Item_param::do_clone_const_item(THD *thd) const +Item_param::clone_item(THD *thd) const { // There's no "default". See comments in Item_param::save_in_field(). switch (state) { @@ -7023,7 +7023,7 @@ int Item_string::save_in_field(Field *field, bool no_conversions) } -Item *Item_string::do_clone_const_item(THD *thd) const +Item *Item_string::clone_item(THD *thd) const { LEX_CSTRING val; str_value.get_value(&val); @@ -7087,7 +7087,7 @@ int Item_int::save_in_field(Field *field, bool no_conversions) } -Item *Item_int::do_clone_const_item(THD *thd) const +Item *Item_int::clone_item(THD *thd) const { return new (thd->mem_root) Item_int(thd, name.str, value, max_length, unsigned_flag); } @@ -7116,7 +7116,7 @@ int Item_decimal::save_in_field(Field *field, bool no_conversions) } -Item *Item_int_with_ref::do_clone_const_item(THD *thd) const +Item *Item_int_with_ref::clone_item(THD *thd) const { DBUG_ASSERT(ref->const_item()); /* @@ -7212,7 +7212,7 @@ Item *Item_uint::neg(THD *thd) } -Item *Item_uint::do_clone_const_item(THD *thd) const +Item *Item_uint::clone_item(THD *thd) const { return new (thd->mem_root) Item_uint(thd, name.str, value, max_length); } @@ -7450,7 +7450,7 @@ void Item_date_literal::print(String *str, enum_query_type query_type) } -Item *Item_date_literal::do_clone_const_item(THD *thd) const +Item *Item_date_literal::clone_item(THD *thd) const { return new (thd->mem_root) Item_date_literal(thd, &cached_time); } @@ -7475,7 +7475,7 @@ void Item_datetime_literal::print(String *str, enum_query_type query_type) } -Item *Item_datetime_literal::do_clone_const_item(THD *thd) const +Item *Item_datetime_literal::clone_item(THD *thd) const { return new (thd->mem_root) Item_datetime_literal(thd, &cached_time, decimals); } @@ -7500,7 +7500,7 @@ void Item_time_literal::print(String *str, enum_query_type query_type) } -Item *Item_time_literal::do_clone_const_item(THD *thd) const +Item *Item_time_literal::clone_item(THD *thd) const { return new (thd->mem_root) Item_time_literal(thd, &cached_time, decimals); } @@ -10456,7 +10456,7 @@ void Item_cache_temporal::store_packed(longlong val_arg, Item *example_arg) } -Item *Item_cache_temporal::do_clone_const_item(THD *thd) const +Item *Item_cache_temporal::clone_item(THD *thd) const { Item_cache *tmp= type_handler()->Item_get_cache(thd, this); Item_cache_temporal *item= static_cast(tmp); diff --git a/sql/item.h b/sql/item.h index f88f91fef71..e9ee62b7cb7 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1906,21 +1906,17 @@ public: } /* - Clones the constant item + Clones the constant item (not necessary returning the same item type) Return value: - pointer to a clone of the Item - - nullptr if the item is not clonable */ - Item *clone_const_item(THD *thd) const - { - Item *clone= do_clone_const_item(thd); - if (clone) - { - // Make sure the clone is of same type as this item - DBUG_ASSERT(typeid(*clone) == typeid(*this)); - } - return clone; - } + - nullptr if the item is not clonable + + Note: the clone may have item type different from this + (i.e., instance of another basic constant class may be returned). + For real clones look at build_clone()/get_copy() methods + */ + virtual Item *clone_item(THD *thd) const { return nullptr; } virtual cond_result eq_cmp_result() const { return COND_OK; } inline uint float_length(uint decimals_par) const @@ -2789,12 +2785,6 @@ protected: deep copies (clones) of the item where possible */ virtual Item* do_build_clone(THD *thd) const = 0; - - /* - Service function for public method clone_const_item(). See comments for - clone_const_item() above - */ - virtual Item *do_clone_const_item(THD *thd) const { return nullptr; } }; MEM_ROOT *get_thd_memroot(THD *thd); @@ -3975,7 +3965,7 @@ public: const Type_handler *type_handler() const override { return &type_handler_null; } bool basic_const_item() const override { return true; } - Item *do_clone_const_item(THD *thd) const override; + Item *clone_item(THD *thd) const override; bool const_is_null() const override { return true; } bool is_null() override { return true; } @@ -4426,7 +4416,7 @@ public: basic_const_item returned TRUE. */ Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs) override; - Item *do_clone_const_item(THD *thd) const override; + Item *clone_item(THD *thd) const override; void set_param_type_and_swap_value(Item_param *from); Rewritable_query_parameter *get_rewritable_query_parameter() override @@ -4528,7 +4518,7 @@ public: String *val_str(String*) override; int save_in_field(Field *field, bool no_conversions) override; bool is_order_clause_position() const override { return true; } - Item *do_clone_const_item(THD *thd) const override; + Item *clone_item(THD *thd) const override; void print(String *str, enum_query_type query_type) override; Item *neg(THD *thd) override; decimal_digits_t decimal_precision() const override @@ -4591,8 +4581,8 @@ public: Item_uint(THD *thd, const char *str_arg, size_t length); Item_uint(THD *thd, ulonglong i): Item_int(thd, i, 10) {} Item_uint(THD *thd, const char *str_arg, longlong i, uint length); - double val_real() override { return ulonglong2double((ulonglong)value); } - Item *do_clone_const_item(THD *thd) const override; + double val_real() override { return ulonglong2double((ulonglong)value); } + Item *clone_item(THD *thd) const override; Item *neg(THD *thd) override; decimal_digits_t decimal_precision() const override { return decimal_digits_t(max_length); } @@ -4647,7 +4637,7 @@ public: const my_decimal *const_ptr_my_decimal() const override { return &decimal_value; } int save_in_field(Field *field, bool no_conversions) override; - Item *do_clone_const_item(THD *thd) const override; + Item *clone_item(THD *thd) const override; void print(String *str, enum_query_type query_type) override { decimal_value.to_string(&str_value); @@ -4701,7 +4691,7 @@ public: } String *val_str(String*) override; my_decimal *val_decimal(my_decimal *) override; - Item *do_clone_const_item(THD *thd) const override; + Item *clone_item(THD *thd) const override; Item *neg(THD *thd) override; void print(String *str, enum_query_type query_type) override; Item *do_get_copy(THD *thd) const override @@ -4822,7 +4812,7 @@ public: int save_in_field(Field *field, bool no_conversions) override; const Type_handler *type_handler() const override { return &type_handler_varchar; } - Item *do_clone_const_item(THD *thd) const override; + Item *clone_item(THD *thd) const override; Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs) override { return const_charset_converter(thd, tocs, true); @@ -5246,7 +5236,7 @@ public: { return cached_time.get_mysql_time(); } - Item *do_clone_const_item(THD *thd) const override; + Item *clone_item(THD *thd) const override; longlong val_int() override { return update_null() ? 0 : cached_time.to_longlong(); @@ -5296,7 +5286,7 @@ public: { return cached_time.get_mysql_time(); } - Item *do_clone_const_item(THD *thd) const override; + Item *clone_item(THD *thd) const override; longlong val_int() override { return cached_time.to_longlong(); } double val_real() override { return cached_time.to_double(); } String *val_str(String *to) override @@ -5350,7 +5340,7 @@ public: { return cached_time.get_mysql_time(); } - Item *do_clone_const_item(THD *thd) const override; + Item *clone_item(THD *thd) const override; longlong val_int() override { return update_null() ? 0 : cached_time.to_longlong(); @@ -5439,6 +5429,9 @@ public: cached_time.copy_to_mysql_time(ltime); return (null_value= false); } + Item *do_get_copy(THD *thd) const override + { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -6507,8 +6500,11 @@ public: { return ref->save_in_field(field, no_conversions); } - Item *do_clone_const_item(THD *thd) const override; + Item *clone_item(THD *thd) const override; Item *real_item() override { return ref; } + Item *do_get_copy(THD *thd) const override + { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; #ifdef MYSQL_SERVER @@ -7422,7 +7418,7 @@ public: is a constant and need not be optimized further. Important when storing packed datetime values. */ - Item *do_clone_const_item(THD *thd) const override; + Item *clone_item(THD *thd) const override; Item *convert_to_basic_const_item(THD *thd) override; virtual Item *make_literal(THD *) =0; }; diff --git a/sql/key.cc b/sql/key.cc index d58fd5ea1ea..dc4b7d80347 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -755,10 +755,12 @@ ulong key_hashnr(KEY *key_info, uint used_key_parts, const uchar *key) if (is_string) { /* - Prefix keys are not possible in BNLH joins. - Use the whole string to calculate the hash. + Surprisingly, BNL-H joins may use prefix keys. This may happen + when there is a real index on the column used in equi-join. + + In this case, the passed key tuple is already a prefix, no + special handling is required. */ - DBUG_ASSERT((key_part->key_part_flag & HA_PART_KEY_SEG) == 0); cs->hash_sort(pos+pack_length, length, &nr, &nr2); key+= pack_length; } @@ -862,10 +864,10 @@ bool key_buf_cmp(KEY *key_info, uint used_key_parts, if (is_string) { /* - Prefix keys are not possible in BNLH joins. - Compare whole strings. + Surprisingly, BNL-H joins may use prefix keys. This may happen + when there is a real index on the column used in equi-join. + In this case, we get properly truncated prefixes here. */ - DBUG_ASSERT((key_part->key_part_flag & HA_PART_KEY_SEG) == 0); if (cs->strnncollsp(pos1 + pack_length, length1, pos2 + pack_length, length2)) return true; diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 78ec80ccad6..2eceba1d5b9 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -1574,6 +1574,7 @@ bool pushdown_cond_for_derived(THD *thd, Item *cond, TABLE_LIST *derived) if (sl != first_sl) { DBUG_ASSERT(sl->item_list.elements == first_sl->item_list.elements); + sl->save_item_list_names(thd); List_iterator_fast it(sl->item_list); List_iterator_fast nm_it(unit->types); while (Item *item= it++) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a492f567920..379cec84b1c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -17317,7 +17317,7 @@ change_cond_ref_to_const(THD *thd, I_List *save_list, if (can_change_cond_ref_to_const(func, right_item, left_item, field_value_owner, field, value)) { - Item *tmp=value->clone_const_item(thd); + Item *tmp=value->clone_item(thd); if (tmp) { tmp->collation.set(right_item->collation); @@ -17347,7 +17347,7 @@ change_cond_ref_to_const(THD *thd, I_List *save_list, else if (can_change_cond_ref_to_const(func, left_item, right_item, field_value_owner, field, value)) { - Item *tmp= value->clone_const_item(thd); + Item *tmp= value->clone_item(thd); if (tmp) { tmp->collation.set(left_item->collation); diff --git a/sql/sql_window.cc b/sql/sql_window.cc index 5991c027e64..5f2c4f60437 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -262,9 +262,12 @@ setup_windows(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables, For "win_func() OVER (ORDER BY order_list RANGE BETWEEN ...)", - ORDER BY order_list must not be ommitted - the list must have a single element. + But it really only matters if the frame is bounded. */ if (win_spec->window_frame && - win_spec->window_frame->units == Window_frame::UNITS_RANGE) + win_spec->window_frame->units == Window_frame::UNITS_RANGE && + !(win_spec->window_frame->top_bound->is_unbounded() && + win_spec->window_frame->bottom_bound->is_unbounded())) { if (win_spec->order_list->elements != 1) { diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index 12de62ac2be..ddfa6440680 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -1347,6 +1347,8 @@ inline bool fil_space_t::acquire_if_not_stopped() bool fil_crypt_must_default_encrypt() { + /* prevents a race condition with fil_crypt_set_rotate_key_age() */ + mysql_mutex_assert_owner(&fil_system.mutex); return !srv_fil_crypt_rotate_key_age || !srv_encrypt_rotate; } @@ -2200,6 +2202,27 @@ void fil_crypt_set_rotation_iops(uint val) mysql_mutex_unlock(&fil_crypt_threads_mutex); } +/** Add the import tablespace to default_encrypt list +if necessary and signal fil_crypt_threads +@param space imported tablespace */ +void fil_crypt_add_imported_space(fil_space_t *space) +{ + mysql_mutex_lock(&fil_crypt_threads_mutex); + + mysql_mutex_lock(&fil_system.mutex); + + if (fil_crypt_must_default_encrypt()) + { + fil_system.default_encrypt_tables.push_back(*space); + space->is_in_default_encrypt= true; + } + + mysql_mutex_unlock(&fil_system.mutex); + + pthread_cond_broadcast(&fil_crypt_threads_cond); + mysql_mutex_unlock(&fil_crypt_threads_mutex); +} + /********************************************************************* Adjust encrypt tables @param[in] val New setting for innodb-encrypt-tables */ diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index b99d5873bf5..c90a8db1133 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -13399,7 +13399,7 @@ ha_innobase::discard_or_import_tablespace( | HA_STATUS_VARIABLE | HA_STATUS_AUTO); - fil_crypt_set_encrypt_tables(srv_encrypt_tables); + fil_crypt_add_imported_space(m_prebuilt->table->space); } } diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 09f541a75d9..a944e7515d3 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -374,10 +374,12 @@ found_j: } } - /* In case of discarded tablespace, InnoDB can't - read the root page. So assign the null bytes based - on nullabled fields */ - if (!oindex.table->space) { + /* Discard tablespace doesn't remove the instantness + from the table definition. if n_core_null_bytes wasn't + initialized then assign it based on nullable fields */ + if (!oindex.table->space + && oindex.n_core_null_bytes + == dict_index_t::NO_CORE_NULL_BYTES) { oindex.n_core_null_bytes = static_cast( UT_BITS_IN_BYTES(unsigned(oindex.n_nullable))); } diff --git a/storage/innobase/include/fil0crypt.h b/storage/innobase/include/fil0crypt.h index 26272761f43..ab1b668dde6 100644 --- a/storage/innobase/include/fil0crypt.h +++ b/storage/innobase/include/fil0crypt.h @@ -337,6 +337,11 @@ Adjust rotation iops @param[in] val New max roation iops */ void fil_crypt_set_rotation_iops(uint val); +/** Add the import tablespace to default_encrypt list +if necessary and signal fil_crypt_threads +@param space imported tablespace */ +void fil_crypt_add_imported_space(fil_space_t *space); + /********************************************************************* Adjust encrypt tables @param[in] val New setting for innodb-encrypt-tables */ diff --git a/storage/innobase/include/mach0data.inl b/storage/innobase/include/mach0data.inl index 8fdeaffedf5..968f0ed2639 100644 --- a/storage/innobase/include/mach0data.inl +++ b/storage/innobase/include/mach0data.inl @@ -25,6 +25,7 @@ to the machine format. Created 11/28/1995 Heikki Tuuri ***********************************************************************/ +#include "my_valgrind.h" #ifndef UNIV_INNOCHECKSUM #include "mtr0types.h" @@ -39,7 +40,7 @@ mach_write_to_1( byte* b, /*!< in: pointer to byte where to store */ ulint n) /*!< in: ulint integer to be stored, >= 0, < 256 */ { -#ifndef HAVE_valgrind +#if !defined HAVE_valgrind || __has_feature(memory_sanitizer) ut_ad((n & ~0xFFUL) == 0); #endif @@ -58,7 +59,7 @@ mach_write_to_2( byte* b, /*!< in: pointer to two bytes where to store */ ulint n) /*!< in: ulint integer to be stored */ { -#ifndef HAVE_valgrind +#if !defined HAVE_valgrind || __has_feature(memory_sanitizer) ut_ad((n & ~0xFFFFUL) == 0); #endif