From fefd6d55593f7f29b5d4a074ecaceb22c6907e39 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Wed, 8 Nov 2023 12:06:34 +0100 Subject: [PATCH] MDEV-32656: ASAN errors in base_list_iterator::next / setup_table_map upon 2nd execution of PS Correctly supress error issuing when saving value in field for comporison --- mysql-test/main/subselect.result | 21 +++++++++++++++ mysql-test/main/subselect.test | 27 +++++++++++++++++++ mysql-test/main/subselect_mat.result | 2 +- .../main/subselect_no_exists_to_in.result | 21 +++++++++++++++ mysql-test/main/subselect_no_mat.result | 21 +++++++++++++++ mysql-test/main/subselect_no_opts.result | 21 +++++++++++++++ mysql-test/main/subselect_no_scache.result | 21 +++++++++++++++ mysql-test/main/subselect_no_semijoin.result | 21 +++++++++++++++ mysql-test/main/subselect_sj_mat.result | 2 +- sql/item_cmpfunc.cc | 3 ++- sql/sql_class.h | 6 +++-- 11 files changed, 161 insertions(+), 5 deletions(-) diff --git a/mysql-test/main/subselect.result b/mysql-test/main/subselect.result index 0c877b03b97..32652244353 100644 --- a/mysql-test/main/subselect.result +++ b/mysql-test/main/subselect.result @@ -7497,3 +7497,24 @@ ERROR HY000: Illegal parameter data types row and boolean for operation '=' # # End of 10.4 tests # +# +# MDEV-32656: ASAN errors in base_list_iterator::next / +# setup_table_map upon 2nd execution of PS +# (10.6 part) +# +CREATE TABLE t1 (id BIGINT); +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES (2),(3); +CREATE TABLE t3 (b INT); +INSERT INTO t3 VALUES (3),(4); +insert into t2 select (('e','e') IN (SELECT v1.id, v1.id FROM v1 JOIN t3)); +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: 'e' +Warning 1292 Truncated incorrect DECIMAL value: 'e' +drop view v1; +drop table t1, t2, t3; +# +# End of 10.6 tests +# diff --git a/mysql-test/main/subselect.test b/mysql-test/main/subselect.test index 18ae20c44da..b301d4f584b 100644 --- a/mysql-test/main/subselect.test +++ b/mysql-test/main/subselect.test @@ -6351,3 +6351,30 @@ SELECT ROW(1,2) = (1 = ANY (SELECT 1 UNION SELECT 2)); --echo # --echo # End of 10.4 tests --echo # + + + +--echo # +--echo # MDEV-32656: ASAN errors in base_list_iterator::next / +--echo # setup_table_map upon 2nd execution of PS +--echo # (10.6 part) +--echo # + +CREATE TABLE t1 (id BIGINT); +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW v1 AS SELECT * FROM t1; + +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES (2),(3); + +CREATE TABLE t3 (b INT); +INSERT INTO t3 VALUES (3),(4); + +insert into t2 select (('e','e') IN (SELECT v1.id, v1.id FROM v1 JOIN t3)); + +drop view v1; +drop table t1, t2, t3; + +--echo # +--echo # End of 10.6 tests +--echo # diff --git a/mysql-test/main/subselect_mat.result b/mysql-test/main/subselect_mat.result index 8054dbbd21d..cf3d1671532 100644 --- a/mysql-test/main/subselect_mat.result +++ b/mysql-test/main/subselect_mat.result @@ -2697,7 +2697,7 @@ INSERT INTO t2 VALUES (3),(4); CREATE TABLE t3 (c DATETIME, d INT, KEY(c)); INSERT INTO t3 VALUES ('2012-11-11',5),('2012-12-12',6); UPDATE t1, t2 SET t1.a = 26 WHERE t2.b IN (SELECT MIN(d) FROM t3 WHERE c >= '2012-01'); -ERROR 22007: Incorrect datetime value: '2012-01' for column `test`.`t3`.`c` at row 1 +ERROR 22007: Truncated incorrect datetime value: '2012-01' DROP TABLE t1, t2, t3; # # a followup fix: diff --git a/mysql-test/main/subselect_no_exists_to_in.result b/mysql-test/main/subselect_no_exists_to_in.result index c7fc78ce28e..2f9b36d19f6 100644 --- a/mysql-test/main/subselect_no_exists_to_in.result +++ b/mysql-test/main/subselect_no_exists_to_in.result @@ -7497,6 +7497,27 @@ ERROR HY000: Illegal parameter data types row and boolean for operation '=' # # End of 10.4 tests # +# +# MDEV-32656: ASAN errors in base_list_iterator::next / +# setup_table_map upon 2nd execution of PS +# (10.6 part) +# +CREATE TABLE t1 (id BIGINT); +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES (2),(3); +CREATE TABLE t3 (b INT); +INSERT INTO t3 VALUES (3),(4); +insert into t2 select (('e','e') IN (SELECT v1.id, v1.id FROM v1 JOIN t3)); +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: 'e' +Warning 1292 Truncated incorrect DECIMAL value: 'e' +drop view v1; +drop table t1, t2, t3; +# +# End of 10.6 tests +# set optimizer_switch=default; select @@optimizer_switch like '%exists_to_in=off%'; @@optimizer_switch like '%exists_to_in=off%' diff --git a/mysql-test/main/subselect_no_mat.result b/mysql-test/main/subselect_no_mat.result index 5998be62535..7e692c1a5e1 100644 --- a/mysql-test/main/subselect_no_mat.result +++ b/mysql-test/main/subselect_no_mat.result @@ -7490,6 +7490,27 @@ ERROR HY000: Illegal parameter data types row and boolean for operation '=' # # End of 10.4 tests # +# +# MDEV-32656: ASAN errors in base_list_iterator::next / +# setup_table_map upon 2nd execution of PS +# (10.6 part) +# +CREATE TABLE t1 (id BIGINT); +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES (2),(3); +CREATE TABLE t3 (b INT); +INSERT INTO t3 VALUES (3),(4); +insert into t2 select (('e','e') IN (SELECT v1.id, v1.id FROM v1 JOIN t3)); +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: 'e' +Warning 1292 Truncated incorrect DECIMAL value: 'e' +drop view v1; +drop table t1, t2, t3; +# +# End of 10.6 tests +# set optimizer_switch=default; select @@optimizer_switch like '%materialization=on%'; @@optimizer_switch like '%materialization=on%' diff --git a/mysql-test/main/subselect_no_opts.result b/mysql-test/main/subselect_no_opts.result index 4d3ecfd70e1..790e0f847ee 100644 --- a/mysql-test/main/subselect_no_opts.result +++ b/mysql-test/main/subselect_no_opts.result @@ -7488,4 +7488,25 @@ ERROR HY000: Illegal parameter data types row and boolean for operation '=' # # End of 10.4 tests # +# +# MDEV-32656: ASAN errors in base_list_iterator::next / +# setup_table_map upon 2nd execution of PS +# (10.6 part) +# +CREATE TABLE t1 (id BIGINT); +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES (2),(3); +CREATE TABLE t3 (b INT); +INSERT INTO t3 VALUES (3),(4); +insert into t2 select (('e','e') IN (SELECT v1.id, v1.id FROM v1 JOIN t3)); +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: 'e' +Warning 1292 Truncated incorrect DECIMAL value: 'e' +drop view v1; +drop table t1, t2, t3; +# +# End of 10.6 tests +# set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/main/subselect_no_scache.result b/mysql-test/main/subselect_no_scache.result index 7991829cd49..96d68a94a14 100644 --- a/mysql-test/main/subselect_no_scache.result +++ b/mysql-test/main/subselect_no_scache.result @@ -7503,6 +7503,27 @@ ERROR HY000: Illegal parameter data types row and boolean for operation '=' # # End of 10.4 tests # +# +# MDEV-32656: ASAN errors in base_list_iterator::next / +# setup_table_map upon 2nd execution of PS +# (10.6 part) +# +CREATE TABLE t1 (id BIGINT); +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES (2),(3); +CREATE TABLE t3 (b INT); +INSERT INTO t3 VALUES (3),(4); +insert into t2 select (('e','e') IN (SELECT v1.id, v1.id FROM v1 JOIN t3)); +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: 'e' +Warning 1292 Truncated incorrect DECIMAL value: 'e' +drop view v1; +drop table t1, t2, t3; +# +# End of 10.6 tests +# set optimizer_switch=default; select @@optimizer_switch like '%subquery_cache=on%'; @@optimizer_switch like '%subquery_cache=on%' diff --git a/mysql-test/main/subselect_no_semijoin.result b/mysql-test/main/subselect_no_semijoin.result index aeac9d4c1ed..5a460281e44 100644 --- a/mysql-test/main/subselect_no_semijoin.result +++ b/mysql-test/main/subselect_no_semijoin.result @@ -7489,6 +7489,27 @@ ERROR HY000: Illegal parameter data types row and boolean for operation '=' # End of 10.4 tests # # +# MDEV-32656: ASAN errors in base_list_iterator::next / +# setup_table_map upon 2nd execution of PS +# (10.6 part) +# +CREATE TABLE t1 (id BIGINT); +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES (2),(3); +CREATE TABLE t3 (b INT); +INSERT INTO t3 VALUES (3),(4); +insert into t2 select (('e','e') IN (SELECT v1.id, v1.id FROM v1 JOIN t3)); +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: 'e' +Warning 1292 Truncated incorrect DECIMAL value: 'e' +drop view v1; +drop table t1, t2, t3; +# +# End of 10.6 tests +# +# # MDEV-19714: JOIN::pseudo_bits_cond is not visible in EXPLAIN FORMAT=JSON # CREATE TABLE t1 ( a INT ); diff --git a/mysql-test/main/subselect_sj_mat.result b/mysql-test/main/subselect_sj_mat.result index 9a3b69da6fa..5275a39d018 100644 --- a/mysql-test/main/subselect_sj_mat.result +++ b/mysql-test/main/subselect_sj_mat.result @@ -2739,7 +2739,7 @@ INSERT INTO t2 VALUES (3),(4); CREATE TABLE t3 (c DATETIME, d INT, KEY(c)); INSERT INTO t3 VALUES ('2012-11-11',5),('2012-12-12',6); UPDATE t1, t2 SET t1.a = 26 WHERE t2.b IN (SELECT MIN(d) FROM t3 WHERE c >= '2012-01'); -ERROR 22007: Incorrect datetime value: '2012-01' for column `test`.`t3`.`c` at row 1 +ERROR 22007: Truncated incorrect datetime value: '2012-01' DROP TABLE t1, t2, t3; # # a followup fix: diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index ed6417a4747..d63db33edb3 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -333,6 +333,7 @@ static bool convert_const_to_int(THD *thd, Item_field *field_item, !(*item)->with_sum_func()) { TABLE *table= field->table; + Use_relaxed_field_copy urfc(thd); MY_BITMAP *old_maps[2] = { NULL, NULL }; ulonglong UNINIT_VAR(orig_field_val); /* original field value if valid */ bool save_field_value; @@ -351,7 +352,7 @@ static bool convert_const_to_int(THD *thd, Item_field *field_item, !(field->table->status & STATUS_NO_RECORD)); if (save_field_value) orig_field_val= field->val_int(); - if (!(*item)->save_in_field_no_warnings(field, 1) && !field->is_null()) + if (!(*item)->save_in_field(field, 1) && !field->is_null()) { int field_cmp= 0; // If item is a decimal value, we must reject it if it was truncated. diff --git a/sql/sql_class.h b/sql/sql_class.h index e6580d2432c..1c7839fc266 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -7723,11 +7723,13 @@ public: class Use_relaxed_field_copy: public Sql_mode_save, - public Check_level_instant_set + public Check_level_instant_set, + public Abort_on_warning_instant_set { public: Use_relaxed_field_copy(THD *thd) : - Sql_mode_save(thd), Check_level_instant_set(thd, CHECK_FIELD_IGNORE) + Sql_mode_save(thd), Check_level_instant_set(thd, CHECK_FIELD_IGNORE), + Abort_on_warning_instant_set(thd, 0) { thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE); thd->variables.sql_mode|= MODE_INVALID_DATES;