From 4e9322e2ff25d638013e6e6cf051754084e2f16b Mon Sep 17 00:00:00 2001 From: Monty Date: Wed, 20 Sep 2023 15:46:55 +0300 Subject: [PATCH] MDEV-32203 Raise notes when an index cannot be used on data type mismatch Raise notes if indexes cannot be used: - in case of data type or collation mismatch (diferent error messages). - in case if a table field was replaced to something else (e.g. Item_func_conv_charset) during a condition rewrite. Added option to write warnings and notes to the slow query log for slow queries. New variables added/changed: - note_verbosity, with is a set of the following options: basic - All old notes unusable_keys - Print warnings about keys that cannot be used for select, delete or update. explain - Print unusable_keys warnings for EXPLAIN querys. The default is 'basic,explain'. This means that for old installations the only notable new behavior is that one will get notes about unusable keys when one does an EXPLAIN for a query. One can turn all of all notes by either setting note_verbosity to "" or setting sql_notes=0. - log_slow_verbosity has a new option 'warnings'. If this is set then warnings and notes generated are printed in the slow query log (up to log_slow_max_warnings times per statement). - log_slow_max_warnings - Max number of warnings written to slow query log. Other things: - One can now use =ALL for any 'set' variable to set all options at once. For example using "note_verbosity=ALL" in a config file or "SET @@note_verbosity=ALL' in SQL. - mysqldump will in the future use @@note_verbosity=""' instead of @sql_notes=0 to disable notes. - Added "enum class Data_type_compatibility" and changing the return type of all Field::can_optimize*() methods from "bool" to this new data type. Reviewer & Co-author: Alexander Barkov - The code that prints out the notes comes mainly from Alexander --- client/mysqltest.cc | 40 ++- include/m_ctype.h | 6 + mysql-test/main/compare.result | 2 + mysql-test/main/ctype_collate.result | 2 + mysql-test/main/log_slow.result | 1 + mysql-test/main/log_slow_debug.result | 56 ++++ mysql-test/main/log_slow_debug.test | 66 +++++ mysql-test/main/mrr_icp_extra.result | 2 + .../main/myisam_explain_non_select_all.result | 30 ++ mysql-test/main/mysqld--help.result | 31 ++- mysql-test/main/null_key.result | 3 + mysql-test/main/null_key.test | 6 + mysql-test/main/range.result | 8 + mysql-test/main/range_mrr_icp.result | 8 + mysql-test/main/subselect_sj2.result | 2 + mysql-test/main/subselect_sj2_jcl6.result | 2 + mysql-test/main/subselect_sj2_mat.result | 2 + mysql-test/main/table_elim.result | 8 + mysql-test/main/type_binary.result | 177 ++++++++++++ mysql-test/main/type_binary.test | 19 ++ mysql-test/main/type_bit.result | 154 ++++++++++ mysql-test/main/type_bit.test | 19 ++ mysql-test/main/type_bit_innodb.result | 154 ++++++++++ mysql-test/main/type_bit_innodb.test | 18 ++ mysql-test/main/type_blob.result | 260 +++++++++++++++++ mysql-test/main/type_blob.test | 31 +++ mysql-test/main/type_date.result | 122 ++++++++ mysql-test/main/type_date.test | 23 ++ mysql-test/main/type_datetime.result | 122 ++++++++ mysql-test/main/type_datetime.test | 23 ++ mysql-test/main/type_enum.result | 217 +++++++++++++++ mysql-test/main/type_enum.test | 22 ++ mysql-test/main/type_float.result | 262 ++++++++++++++++++ mysql-test/main/type_float.test | 33 +++ mysql-test/main/type_int.result | 253 +++++++++++++++++ mysql-test/main/type_int.test | 33 +++ mysql-test/main/type_newdecimal.result | 134 +++++++++ mysql-test/main/type_newdecimal.test | 18 ++ mysql-test/main/type_set.result | 217 +++++++++++++++ mysql-test/main/type_set.test | 21 ++ mysql-test/main/type_time.result | 112 ++++++++ mysql-test/main/type_time.test | 18 ++ mysql-test/main/type_timestamp.result | 119 ++++++++ mysql-test/main/type_timestamp.test | 18 ++ mysql-test/main/type_uint.result | 256 +++++++++++++++++ mysql-test/main/type_uint.test | 33 +++ mysql-test/main/type_varchar.result | 185 +++++++++++++ mysql-test/main/type_varchar.test | 19 ++ mysql-test/main/type_year.result | 107 +++++++ mysql-test/main/type_year.test | 19 ++ mysql-test/main/unusable_keys_joins.inc | 66 +++++ mysql-test/main/unusable_keys_literals.inc | 14 + .../r/log_slow_verbosity_basic.result | 20 +- .../sys_vars/r/sysvars_server_embedded.result | 26 +- .../r/sysvars_server_notembedded,32bit.rdiff | 231 +++++++-------- .../r/sysvars_server_notembedded.result | 26 +- .../sys_vars/t/log_slow_verbosity_basic.test | 10 +- mysys/my_getopt.c | 24 +- .../type_inet/type_inet6_myisam.result | 2 + sql/field.cc | 198 ++++++++++--- sql/field.h | 124 +++++---- sql/item_cmpfunc.cc | 67 ++++- sql/item_cmpfunc.h | 7 +- sql/log.cc | 18 +- sql/log_slow.h | 3 +- sql/opt_range.cc | 95 +++++-- sql/opt_range.h | 5 +- sql/opt_table_elimination.cc | 3 +- sql/protocol.cc | 2 + sql/sql_class.cc | 11 +- sql/sql_class.h | 10 + sql/sql_error.h | 13 + sql/sql_select.cc | 45 ++- sql/sql_type.h | 34 +++ sql/sql_type_fixedbin.h | 28 +- sql/sql_type_geom.cc | 11 +- sql/sql_type_geom.h | 6 +- sql/sys_vars.cc | 36 ++- sql/sys_vars.inl | 10 + 79 files changed, 4328 insertions(+), 310 deletions(-) create mode 100644 mysql-test/main/unusable_keys_joins.inc create mode 100644 mysql-test/main/unusable_keys_literals.inc diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 564bcb1dc15..2fbd8c95e9f 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -1037,35 +1037,38 @@ exit_func: static int do_stmt_prepare(struct st_connection *cn, const char *q, int q_len) { /* The cn->stmt is already set. */ + DBUG_ENTER("do_stmt_prepare"); if (!cn->has_thread) - return mysql_stmt_prepare(cn->stmt, q, q_len); + DBUG_RETURN(mysql_stmt_prepare(cn->stmt, q, q_len)); cn->cur_query= q; cn->cur_query_len= q_len; signal_connection_thd(cn, EMB_PREPARE_STMT); wait_query_thread_done(cn); - return cn->result; + DBUG_RETURN(cn->result); } static int do_stmt_execute(struct st_connection *cn) { + DBUG_ENTER("do_stmt_execute"); /* The cn->stmt is already set. */ if (!cn->has_thread) - return mysql_stmt_execute(cn->stmt); + DBUG_RETURN(mysql_stmt_execute(cn->stmt)); signal_connection_thd(cn, EMB_EXECUTE_STMT); wait_query_thread_done(cn); - return cn->result; + DBUG_RETURN(cn->result); } static int do_stmt_close(struct st_connection *cn) { + DBUG_ENTER("do_stmt_close"); /* The cn->stmt is already set. */ if (!cn->has_thread) - return mysql_stmt_close(cn->stmt); + DBUG_RETURN(mysql_stmt_close(cn->stmt)); signal_connection_thd(cn, EMB_CLOSE_STMT); wait_query_thread_done(cn); - return cn->result; + DBUG_RETURN(cn->result); } @@ -7910,6 +7913,7 @@ int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) if (!(count= mysql_warning_count(mysql))) DBUG_RETURN(0); + DBUG_PRINT("info", ("Warnings: %ud", count)); /* If one day we will support execution of multi-statements @@ -8365,6 +8369,7 @@ void run_query_stmt(struct st_connection *cn, struct st_command *command, char *query, size_t query_len, DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_warnings) { + my_bool ignore_second_execution= 0; MYSQL_RES *res= NULL; /* Note that here 'res' is meta data result set */ MYSQL *mysql= cn->mysql; MYSQL_STMT *stmt; @@ -8372,6 +8377,9 @@ void run_query_stmt(struct st_connection *cn, struct st_command *command, DYNAMIC_STRING ds_execute_warnings; DBUG_ENTER("run_query_stmt"); DBUG_PRINT("query", ("'%-.60s'", query)); + DBUG_PRINT("info", + ("disable_warnings: %d prepare_warnings_enabled: %d", + (int) disable_warnings, (int) prepare_warnings_enabled)); if (!mysql) { @@ -8442,12 +8450,18 @@ void run_query_stmt(struct st_connection *cn, struct st_command *command, mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); goto end; } + /* + We cannot run query twice if we get prepare warnings as these will otherwise be + disabled + */ + ignore_second_execution= (prepare_warnings_enabled && + mysql_warning_count(mysql) != 0); } /* Execute the query */ - if (do_stmt_execute(cn)) + if (!ignore_second_execution && do_stmt_execute(cn)) { handle_error(command, mysql_stmt_errno(stmt), mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); @@ -8522,7 +8536,10 @@ void run_query_stmt(struct st_connection *cn, struct st_command *command, that warnings from both the prepare and execute phase are shown. */ if (!disable_warnings && !prepare_warnings_enabled) + { + DBUG_PRINT("info", ("warnings disabled")); dynstr_set(&ds_prepare_warnings, NULL); + } } else { @@ -8624,7 +8641,9 @@ end: error - function will not return */ -void run_prepare_stmt(struct st_connection *cn, struct st_command *command, const char *query, size_t query_len, DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_warnings) +void run_prepare_stmt(struct st_connection *cn, struct st_command *command, + const char *query, size_t query_len, DYNAMIC_STRING *ds, + DYNAMIC_STRING *ds_warnings) { MYSQL *mysql= cn->mysql; @@ -8785,9 +8804,8 @@ void run_bind_stmt(struct st_connection *cn, struct st_command *command, */ void run_execute_stmt(struct st_connection *cn, struct st_command *command, - const char *query, size_t query_len, DYNAMIC_STRING *ds, - DYNAMIC_STRING *ds_warnings - ) + const char *query, size_t query_len, DYNAMIC_STRING *ds, + DYNAMIC_STRING *ds_warnings) { MYSQL_RES *res= NULL; /* Note that here 'res' is meta data result set */ MYSQL *mysql= cn->mysql; diff --git a/include/m_ctype.h b/include/m_ctype.h index 2352de4ec3a..cda43d81b39 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -887,6 +887,12 @@ struct charset_info_st return (coll->strnncollsp)(this, (uchar *) a, alen, (uchar *) b, blen); } + int strnncollsp(const LEX_CSTRING &a, const LEX_CSTRING &b) const + { + return (coll->strnncollsp)(this, (uchar *) a.str, a.length, + (uchar *) b.str, b.length); + } + size_t strnxfrm(char *dst, size_t dstlen, uint nweights, const char *src, size_t srclen, uint flags) const { diff --git a/mysql-test/main/compare.result b/mysql-test/main/compare.result index b8883784d21..70664e2cc18 100644 --- a/mysql-test/main/compare.result +++ b/mysql-test/main/compare.result @@ -4,6 +4,8 @@ insert into t1 values ('000000000001'),('000000000002'); explain select * from t1 where id=000000000001; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index PRIMARY PRIMARY 12 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t1`.`id` of type `char` = "1" of type `bigint` select * from t1 where id=000000000001; id 000000000001 diff --git a/mysql-test/main/ctype_collate.result b/mysql-test/main/ctype_collate.result index 1ae9f295042..120f0759268 100644 --- a/mysql-test/main/ctype_collate.result +++ b/mysql-test/main/ctype_collate.result @@ -606,6 +606,8 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM t1 WHERE s2='a' COLLATE latin1_german1_ci; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL s2 NULL NULL NULL 10 Using where +Warnings: +Note 1105 Cannot use key `s2` part[0] for lookup: `test`.`t1`.`s2` of collation `latin1_swedish_ci` = "'a' collate latin1_german1_ci" of collation `latin1_german1_ci` EXPLAIN SELECT * FROM t1 WHERE s1 BETWEEN 'a' AND 'b' COLLATE latin1_german1_ci; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range s1 s1 11 NULL 2 Using index condition diff --git a/mysql-test/main/log_slow.result b/mysql-test/main/log_slow.result index 6b9fddb7fb6..239aa4a2f34 100644 --- a/mysql-test/main/log_slow.result +++ b/mysql-test/main/log_slow.result @@ -13,6 +13,7 @@ Variable_name Value log_slow_admin_statements ON log_slow_disabled_statements sp log_slow_filter admin,filesort,filesort_on_disk,filesort_priority_queue,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk +log_slow_max_warnings 10 log_slow_rate_limit 1 log_slow_slave_statements ON log_slow_verbosity diff --git a/mysql-test/main/log_slow_debug.result b/mysql-test/main/log_slow_debug.result index 16d67d7fdc7..c1fc91217f5 100644 --- a/mysql-test/main/log_slow_debug.result +++ b/mysql-test/main/log_slow_debug.result @@ -216,6 +216,62 @@ sql_text [slow] DEALLOCATE PREPARE stmt [slow] DROP SEQUENCE s4 # +# Start of 10.6 tests +# +# +# MDEV-32203 Raise notes when an index cannot be used on data type +# mismatch +# +CREATE TABLE t1 (a VARCHAR(10), KEY(a)); +insert into t1 select seq from seq_0_to_31; +SET note_verbosity=all; +SET log_slow_verbosity=all; +SET global log_output='FILE'; +set @org_slow_query_log_file=@@global.slow_query_log_file; +set global slow_query_log_file='MYSQLTEST_VARDIR/tmp/log_slow_debug-1.log'; +FLUSH SLOW LOGS; +SELECT * FROM t1 WHERE a=10; +a +10 +Warnings: +Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of type `varchar` = "10" of type `int` +EXPLAIN SELECT * FROM t1 WHERE a=10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index a a 13 NULL 32 Using where; Using index +Warnings: +Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of type `varchar` = "10" of type `int` +FOUND 2 /# Warnings/ in log_slow_debug-1.log +FOUND 1 /# Note.*Cannot use key.*varchar.*10.*int/ in log_slow_debug-1.log +set global slow_query_log_file='MYSQLTEST_VARDIR/tmp/log_slow_debug-2.log'; +SET note_verbosity="explain"; +FLUSH SLOW LOGS; +EXPLAIN SELECT * FROM t1 WHERE a=10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index a a 13 NULL 32 Using where; Using index +Warnings: +Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of type `varchar` = "10" of type `int` +FOUND 1 /# Warnings/ in log_slow_debug-2.log +FOUND 1 /# Note.*Cannot use key.*varchar.*10.*int/ in log_slow_debug-2.log +set global slow_query_log_file='MYSQLTEST_VARDIR/tmp/log_slow_debug-3.log'; +SET log_slow_verbosity=replace(@@log_slow_verbosity, "warnings", ""); +SET log_slow_verbosity=replace(@@log_slow_verbosity, "full", ""); +SET note_verbosity=all; +FLUSH SLOW LOGS; +SELECT * FROM t1 WHERE a=10; +a +10 +Warnings: +Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of type `varchar` = "10" of type `int` +EXPLAIN SELECT * FROM t1 WHERE a=10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index a a 13 NULL 32 Using where; Using index +Warnings: +Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of type `varchar` = "10" of type `int` +NOT FOUND /# Warnings/ in log_slow_debug-3.log +NOT FOUND /# Note.*Cannot use key.*varchar.*10.*int/ in log_slow_debug-3.log +set @@global.slow_query_log_file= @org_slow_query_log_file; +DROP TABLE t1; +# # Clean up # SET SESSION debug_dbug=@saved_dbug; diff --git a/mysql-test/main/log_slow_debug.test b/mysql-test/main/log_slow_debug.test index aba4cbc8dcb..a1bcb17b324 100644 --- a/mysql-test/main/log_slow_debug.test +++ b/mysql-test/main/log_slow_debug.test @@ -1,4 +1,5 @@ -- source include/have_debug.inc +-- source include/have_sequence.inc SET @org_slow_query_log= @@global.slow_query_log; SET @org_log_output= @@global.log_output; @@ -82,6 +83,71 @@ TRUNCATE TABLE mysql.slow_log; --source include/log_slow_debug_common.inc CALL show_slow_log(); +--echo # +--echo # Start of 10.6 tests +--echo # + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type +--echo # mismatch +--echo # + +CREATE TABLE t1 (a VARCHAR(10), KEY(a)); +insert into t1 select seq from seq_0_to_31; + +SET note_verbosity=all; +SET log_slow_verbosity=all; +SET global log_output='FILE'; +set @org_slow_query_log_file=@@global.slow_query_log_file; + +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval set global slow_query_log_file='$MYSQLTEST_VARDIR/tmp/log_slow_debug-1.log'; +FLUSH SLOW LOGS; +--disable_ps_protocol +SELECT * FROM t1 WHERE a=10; +EXPLAIN SELECT * FROM t1 WHERE a=10; +--enable_ps_protocol + +--let SEARCH_FILE = `SELECT @@slow_query_log_file` +--let SEARCH_PATTERN=# Warnings +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= # Note.*Cannot use key.*varchar.*10.*int +--source include/search_pattern_in_file.inc + +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval set global slow_query_log_file='$MYSQLTEST_VARDIR/tmp/log_slow_debug-2.log'; +SET note_verbosity="explain"; +FLUSH SLOW LOGS; +EXPLAIN SELECT * FROM t1 WHERE a=10; + +--let SEARCH_FILE = `SELECT @@slow_query_log_file` +--let SEARCH_PATTERN=# Warnings +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= # Note.*Cannot use key.*varchar.*10.*int +--source include/search_pattern_in_file.inc + +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval set global slow_query_log_file='$MYSQLTEST_VARDIR/tmp/log_slow_debug-3.log'; +SET log_slow_verbosity=replace(@@log_slow_verbosity, "warnings", ""); +SET log_slow_verbosity=replace(@@log_slow_verbosity, "full", ""); +SET note_verbosity=all; +FLUSH SLOW LOGS; +SELECT * FROM t1 WHERE a=10; +EXPLAIN SELECT * FROM t1 WHERE a=10; + +--let SEARCH_FILE = `SELECT @@slow_query_log_file` +--let SEARCH_PATTERN=# Warnings +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= # Note.*Cannot use key.*varchar.*10.*int +--source include/search_pattern_in_file.inc + +set @@global.slow_query_log_file= @org_slow_query_log_file; + +--remove_file $MYSQLTEST_VARDIR/tmp/log_slow_debug-1.log +--remove_file $MYSQLTEST_VARDIR/tmp/log_slow_debug-2.log +--remove_file $MYSQLTEST_VARDIR/tmp/log_slow_debug-3.log + +DROP TABLE t1; --echo # --echo # Clean up diff --git a/mysql-test/main/mrr_icp_extra.result b/mysql-test/main/mrr_icp_extra.result index 8f6ee88acc6..1b33b008f35 100644 --- a/mysql-test/main/mrr_icp_extra.result +++ b/mysql-test/main/mrr_icp_extra.result @@ -30,6 +30,8 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM t1 WHERE s2='a' COLLATE latin1_german1_ci; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL s2 NULL NULL NULL 10 Using where +Warnings: +Note 1105 Cannot use key `s2` part[0] for lookup: `test`.`t1`.`s2` of collation `latin1_swedish_ci` = "'a' collate latin1_german1_ci" of collation `latin1_german1_ci` EXPLAIN SELECT * FROM t1 WHERE s1 BETWEEN 'a' AND 'b' COLLATE latin1_german1_ci; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range s1 s1 11 NULL 2 Using index condition; Rowid-ordered scan diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result index 61fa42d1596..cc42c16d46b 100644 --- a/mysql-test/main/myisam_explain_non_select_all.result +++ b/mysql-test/main/myisam_explain_non_select_all.result @@ -1505,12 +1505,17 @@ Warning 1287 ' INTO ;' is deprecated and will be EXPLAIN DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +Warnings: +Note 1105 Cannot use key `a` part[1] for lookup: `test`.`t2`.`b` of type `char` = "10" of type `int` FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort Warnings: +Note 1105 Cannot use key `a` part[1] for lookup: `test`.`t2`.`b` of type `char` = "10" of type `int` Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value @@ -1683,6 +1693,7 @@ EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort Warnings: +Note 1105 Cannot use key `a` part[1] for lookup: `test`.`t2`.`b` of type `char` = "10" of type `int` Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution Variable_name Value @@ -1723,12 +1734,15 @@ Warning 1287 ' INTO ;' is deprecated and will be EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +Warnings: +Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` >= "10" of type `int` +Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` <= "18" of type `int` FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort Warnings: +Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` >= "10" of type `int` +Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` <= "18" of type `int` Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value @@ -2057,6 +2077,8 @@ EXPLAIN EXTENDED SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL i NULL NULL NULL 26 100.00 Using where; Using filesort Warnings: +Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` >= "10" of type `int` +Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` <= "18" of type `int` Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5 # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution Variable_name Value @@ -2206,12 +2228,15 @@ Warning 1287 ' INTO ;' is deprecated and will be EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +Warnings: +Note 1105 Cannot use key `a` part[1] for lookup: `test`.`t2`.`b` of type `char` = "10" of type `int` FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort Warnings: +Note 1105 Cannot use key `a` part[1] for lookup: `test`.`t2`.`b` of type `char` = "10" of type `int` Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value @@ -2278,6 +2307,7 @@ EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort Warnings: +Note 1105 Cannot use key `a` part[1] for lookup: `test`.`t2`.`b` of type `char` = "10" of type `int` Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution Variable_name Value diff --git a/mysql-test/main/mysqld--help.result b/mysql-test/main/mysqld--help.result index 764f5037105..94a3e1a4e7d 100644 --- a/mysql-test/main/mysqld--help.result +++ b/mysql-test/main/mysqld--help.result @@ -210,6 +210,7 @@ The following specify which files/extra groups are read (specified before remain Default flags for the regex library. Any combination of: DOTALL, DUPNAMES, EXTENDED, EXTENDED_MORE, EXTRA, MULTILINE, UNGREEDY + Use 'ALL' to set all combinations. --default-storage-engine=name The default storage engine for new tables --default-time-zone=name @@ -484,12 +485,14 @@ The following specify which files/extra groups are read (specified before remain --log-disabled-statements=name Don't log certain types of statements to general log. Any combination of: slave, sp + Use 'ALL' to set all combinations. --log-error[=name] Log errors to file (instead of stdout). If file name is not specified then 'datadir'/'log-basename'.err or the 'pid-file' path with extension .err is used --log-isam[=name] Log all MyISAM changes to file. --log-output=name How logs should be written. Any combination of: NONE, FILE, TABLE + Use 'ALL' to set all combinations. --log-queries-not-using-indexes Log queries that are executed without benefit of any index to the slow log if it is open. Same as @@ -508,15 +511,20 @@ The following specify which files/extra groups are read (specified before remain --log-slow-disabled-statements=name Don't log certain types of statements to slow log. Any combination of: admin, call, slave, sp + Use 'ALL' to set all combinations. --log-slow-filter=name Log only certain types of queries to the slow log. If - variable empty alll kind of queries are logged. All - types are bound by slow_query_time, except - 'not_using_index' which is always logged if enabled. Any - combination of: admin, filesort, filesort_on_disk, + variable empty all kind of queries are logged. All types + are bound by slow_query_time, except 'not_using_index' + which is always logged if enabled. Any combination of: + admin, filesort, filesort_on_disk, filesort_priority_queue, full_join, full_scan, not_using_index, query_cache, query_cache_miss, tmp_table, tmp_table_on_disk + Use 'ALL' to set all combinations. + --log-slow-max-warnings=# + Max numbers of warnings printed to slow query log per + statement --log-slow-rate-limit=# Write to slow log every #th slow query. Set to 1 to log everything. Increase it to reduce the size of the slow or @@ -528,7 +536,8 @@ The following specify which files/extra groups are read (specified before remain (Defaults to on; use --skip-log-slow-slave-statements to disable.) --log-slow-verbosity=name Verbosity level for the slow log. Any combination of: - innodb, query_plan, explain, engine, full + innodb, query_plan, explain, engine, warnings, full + Use 'ALL' to set all combinations. --log-tc=name Path to transaction coordinator log (used for transactions that affect more than one storage engine, when binary log is disabled). @@ -646,6 +655,7 @@ The following specify which files/extra groups are read (specified before remain Specifies how corrupted tables should be automatically repaired. Any combination of: DEFAULT, BACKUP, FORCE, QUICK, BACKUP_ALL, OFF + Use 'ALL' to set all combinations. --myisam-repair-threads=# If larger than 1, when repairing a MyISAM table all indexes will be created in parallel, with one thread per @@ -674,6 +684,11 @@ The following specify which files/extra groups are read (specified before remain --net-write-timeout=# Number of seconds to wait for a block to be written to a connection before aborting the write + --note-verbosity=name + Verbosity level for note-warnings given to the user. See + also @@sql_notes.. Any combination of: basic, + unusable_keys, explain + Use 'ALL' to set all combinations. --old Use compatible behavior from previous MariaDB version. See also --old-mode --old-alter-table[=name] @@ -684,6 +699,7 @@ The following specify which files/extra groups are read (specified before remain MySQL versions. Any combination of: NO_DUP_KEY_WARNINGS_WITH_IGNORE, NO_PROGRESS_INFO, ZERO_DATE_TIME_CAST, UTF8_IS_UTF8MB3 + Use 'ALL' to set all combinations. --old-passwords Use old password encryption method (needed for 4.0 and older clients) --old-style-user-limits @@ -1284,6 +1300,7 @@ The following specify which files/extra groups are read (specified before remain variable is empty, no conversions are allowed and it is expected that the types match exactly. Any combination of: ALL_LOSSY, ALL_NON_LOSSY + Use 'ALL' to set all combinations. --slow-launch-time=# If creating the thread takes longer than this value (in seconds), the Slow_launch_threads counter will be @@ -1314,6 +1331,7 @@ The following specify which files/extra groups are read (specified before remain NO_ENGINE_SUBSTITUTION, PAD_CHAR_TO_FULL_LENGTH, EMPTY_STRING_IS_NULL, SIMULTANEOUS_ASSIGNMENT, TIME_ROUND_FRACTIONAL + Use 'ALL' to set all combinations. --sql-safe-updates If set to 1, UPDATEs and DELETEs need either a key in the WHERE clause, or a LIMIT clause, or else they will aborted. Prevents the common mistake of accidentally @@ -1421,6 +1439,7 @@ The following specify which files/extra groups are read (specified before remain --time-format=name The TIME format (ignored) --tls-version=name TLS protocol version for secure connections.. Any combination of: TLSv1.0, TLSv1.1, TLSv1.2, TLSv1.3 + Use 'ALL' to set all combinations. --tmp-disk-table-size=# Max size for data for an internal temporary on-disk MyISAM or Aria table. @@ -1601,6 +1620,7 @@ log-slave-updates FALSE log-slow-admin-statements TRUE log-slow-disabled-statements sp log-slow-filter admin,filesort,filesort_on_disk,filesort_priority_queue,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk +log-slow-max-warnings 10 log-slow-rate-limit 1 log-slow-slave-statements TRUE log-slow-verbosity @@ -1655,6 +1675,7 @@ net-buffer-length 16384 net-read-timeout 30 net-retry-count 10 net-write-timeout 60 +note-verbosity basic,explain old FALSE old-alter-table DEFAULT old-mode UTF8_IS_UTF8MB3 diff --git a/mysql-test/main/null_key.result b/mysql-test/main/null_key.result index 6b9d59c636a..c48382e7309 100644 --- a/mysql-test/main/null_key.result +++ b/mysql-test/main/null_key.result @@ -1,4 +1,5 @@ drop table if exists t1,t2; +set @@note_verbosity=replace(@@note_verbosity,"explain",""); create table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam; insert ignore into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(null,7),(9,9),(8,8),(7,7),(null,9),(null,9),(6,6); Warnings: @@ -473,3 +474,5 @@ INSERT INTO t1 VALUES ('9','k'),(NULL,'r'); SELECT * FROM t1 WHERE (f3 = 83) OR (f10 = 'z' AND f3 IS NULL); f3 f10 DROP TABLE t1; +## end of 10.6 tests +set @@note_verbosity=default; diff --git a/mysql-test/main/null_key.test b/mysql-test/main/null_key.test index 0759e99b524..e0c318f7d59 100644 --- a/mysql-test/main/null_key.test +++ b/mysql-test/main/null_key.test @@ -5,6 +5,9 @@ drop table if exists t1,t2; --enable_warnings +# Disable wrong key warnings for this test (to test @@note_verbosity usage) +set @@note_verbosity=replace(@@note_verbosity,"explain",""); + create table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam; insert ignore into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(null,7),(9,9),(8,8),(7,7),(null,9),(null,9),(6,6); explain select * from t1 where a is null; @@ -281,3 +284,6 @@ INSERT INTO t1 VALUES ('9','k'),(NULL,'r'); SELECT * FROM t1 WHERE (f3 = 83) OR (f10 = 'z' AND f3 IS NULL); DROP TABLE t1; +--echo ## end of 10.6 tests + +set @@note_verbosity=default; diff --git a/mysql-test/main/range.result b/mysql-test/main/range.result index 8b4eafa3682..4245e054581 100644 --- a/mysql-test/main/range.result +++ b/mysql-test/main/range.result @@ -632,6 +632,8 @@ id select_type table type possible_keys key key_len ref rows Extra explain select * from t1 where a='aaa' collate latin1_german1_ci; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL a NULL NULL NULL 9 Using where +Warnings: +Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of collation `latin1_swedish_ci` = "'aaa' collate latin1_german1_ci" of collation `latin1_german1_ci` drop table t1; CREATE TABLE t1 ( `CLIENT` char(3) character set latin1 collate latin1_bin NOT NULL default '000', @@ -2224,6 +2226,8 @@ INSERT INTO t2 VALUES ('2001-01-01 11:22:33'); EXPLAIN SELECT * FROM t2 WHERE b=CAST('2001-01-01' AS DATE); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 index b b 67 NULL 5 Using where; Using index +Warnings: +Note 1105 Cannot use key `b` part[0] for lookup: `test`.`t2`.`b` of type `varchar` = "cast('2001-01-01' as date)" of type `date` SELECT * FROM t2 WHERE b=CAST('2001-01-01' AS DATE); b 2001#01#01 @@ -2238,6 +2242,8 @@ EXPLAIN SELECT * FROM t1, t2 WHERE a=b ORDER BY BINARY a, BINARY b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 1 SIMPLE t2 ALL b NULL NULL NULL 5 Range checked for each record (index map: 0x1) +Warnings: +Note 1105 Cannot use key `b` part[0] for lookup: `test`.`t2`.`b` of type `varchar` = "`t1`.`a`" of type `datetime` SELECT * FROM t1, t2 WHERE a=b ORDER BY BINARY a, BINARY b; a b 2001-01-01 00:00:00 2001#01#01 @@ -2250,6 +2256,8 @@ EXPLAIN SELECT * FROM t1, t2 WHERE b=a ORDER BY BINARY a, BINARY b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 1 SIMPLE t2 ALL b NULL NULL NULL 5 Range checked for each record (index map: 0x1) +Warnings: +Note 1105 Cannot use key `b` part[0] for lookup: `test`.`t2`.`b` of type `varchar` = "`t1`.`a`" of type `datetime` SELECT * FROM t1, t2 WHERE b=a ORDER BY BINARY a, BINARY b; a b 2001-01-01 00:00:00 2001#01#01 diff --git a/mysql-test/main/range_mrr_icp.result b/mysql-test/main/range_mrr_icp.result index 4fb717b0b51..deb9918dc89 100644 --- a/mysql-test/main/range_mrr_icp.result +++ b/mysql-test/main/range_mrr_icp.result @@ -635,6 +635,8 @@ id select_type table type possible_keys key key_len ref rows Extra explain select * from t1 where a='aaa' collate latin1_german1_ci; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL a NULL NULL NULL 9 Using where +Warnings: +Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of collation `latin1_swedish_ci` = "'aaa' collate latin1_german1_ci" of collation `latin1_german1_ci` drop table t1; CREATE TABLE t1 ( `CLIENT` char(3) character set latin1 collate latin1_bin NOT NULL default '000', @@ -2227,6 +2229,8 @@ INSERT INTO t2 VALUES ('2001-01-01 11:22:33'); EXPLAIN SELECT * FROM t2 WHERE b=CAST('2001-01-01' AS DATE); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 index b b 67 NULL 5 Using where; Using index +Warnings: +Note 1105 Cannot use key `b` part[0] for lookup: `test`.`t2`.`b` of type `varchar` = "cast('2001-01-01' as date)" of type `date` SELECT * FROM t2 WHERE b=CAST('2001-01-01' AS DATE); b 2001#01#01 @@ -2241,6 +2245,8 @@ EXPLAIN SELECT * FROM t1, t2 WHERE a=b ORDER BY BINARY a, BINARY b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 1 SIMPLE t2 ALL b NULL NULL NULL 5 Range checked for each record (index map: 0x1) +Warnings: +Note 1105 Cannot use key `b` part[0] for lookup: `test`.`t2`.`b` of type `varchar` = "`t1`.`a`" of type `datetime` SELECT * FROM t1, t2 WHERE a=b ORDER BY BINARY a, BINARY b; a b 2001-01-01 00:00:00 2001#01#01 @@ -2253,6 +2259,8 @@ EXPLAIN SELECT * FROM t1, t2 WHERE b=a ORDER BY BINARY a, BINARY b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 1 SIMPLE t2 ALL b NULL NULL NULL 5 Range checked for each record (index map: 0x1) +Warnings: +Note 1105 Cannot use key `b` part[0] for lookup: `test`.`t2`.`b` of type `varchar` = "`t1`.`a`" of type `datetime` SELECT * FROM t1, t2 WHERE b=a ORDER BY BINARY a, BINARY b; a b 2001-01-01 00:00:00 2001#01#01 diff --git a/mysql-test/main/subselect_sj2.result b/mysql-test/main/subselect_sj2.result index 727dfcc4c40..966d0f4c254 100644 --- a/mysql-test/main/subselect_sj2.result +++ b/mysql-test/main/subselect_sj2.result @@ -961,6 +961,8 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ref b b 4 test.t2.d 1 2 MATERIALIZED t2 index_merge PRIMARY,d d,PRIMARY 4,4 NULL 2 Using sort_union(d,PRIMARY); Using where 2 MATERIALIZED t1 ref a a 5 test.t2.d 1 Using where; Using index +Warnings: +Note 1105 Cannot use key `d` part[0] for lookup: `test`.`t2`.`d` of type `varchar` = "`t1`.`a`" of type `int` SELECT * FROM t1 WHERE b IN ( SELECT d FROM t2, t1 WHERE a = d AND ( pk < 2 OR d = 'z' ) diff --git a/mysql-test/main/subselect_sj2_jcl6.result b/mysql-test/main/subselect_sj2_jcl6.result index 66882150ebd..f6d127d89be 100644 --- a/mysql-test/main/subselect_sj2_jcl6.result +++ b/mysql-test/main/subselect_sj2_jcl6.result @@ -974,6 +974,8 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ref b b 4 test.t2.d 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 2 MATERIALIZED t2 index_merge PRIMARY,d d,PRIMARY 4,4 NULL 2 Using sort_union(d,PRIMARY); Using where 2 MATERIALIZED t1 ref a a 5 test.t2.d 1 Using where; Using index +Warnings: +Note 1105 Cannot use key `d` part[0] for lookup: `test`.`t2`.`d` of type `varchar` = "`t1`.`a`" of type `int` SELECT * FROM t1 WHERE b IN ( SELECT d FROM t2, t1 WHERE a = d AND ( pk < 2 OR d = 'z' ) diff --git a/mysql-test/main/subselect_sj2_mat.result b/mysql-test/main/subselect_sj2_mat.result index fe6bc0b9cbe..1d654bba72c 100644 --- a/mysql-test/main/subselect_sj2_mat.result +++ b/mysql-test/main/subselect_sj2_mat.result @@ -963,6 +963,8 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ref b b 4 test.t2.d 1 2 MATERIALIZED t2 index_merge PRIMARY,d d,PRIMARY 4,4 NULL 2 Using sort_union(d,PRIMARY); Using where 2 MATERIALIZED t1 ref a a 5 test.t2.d 1 Using where; Using index +Warnings: +Note 1105 Cannot use key `d` part[0] for lookup: `test`.`t2`.`d` of type `varchar` = "`t1`.`a`" of type `int` SELECT * FROM t1 WHERE b IN ( SELECT d FROM t2, t1 WHERE a = d AND ( pk < 2 OR d = 'z' ) diff --git a/mysql-test/main/table_elim.result b/mysql-test/main/table_elim.result index deff0623370..cd2b9dbad69 100644 --- a/mysql-test/main/table_elim.result +++ b/mysql-test/main/table_elim.result @@ -250,11 +250,15 @@ explain select t1.* from t1 left join t2 on t2.a='foo' collate latin1_general_ci id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL PRIMARY 10 NULL 2 Using index 1 SIMPLE t2 index PRIMARY PRIMARY 10 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of collation `latin1_general_cs` = "'foo' collate latin1_general_ci" of collation `latin1_general_ci` this must not use table elimination: explain select t1.* from t1 left join t2 on t2.a=t1.a collate latin1_general_ci; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL PRIMARY 10 NULL 2 Using index 1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 2 Range checked for each record (index map: 0x1) +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of collation `latin1_general_cs` = "`t1`.`a` collate latin1_general_ci" of collation `latin1_general_ci` drop table t1,t2; create table t1 (a int primary key); insert into t1 values (1),(2); @@ -265,11 +269,15 @@ explain select t1.* from t1 left join t2 on t2.a=1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index 1 SIMPLE t2 index PRIMARY PRIMARY 10 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `char` = "1" of type `int` this must not use table elimination: explain select t1.* from t1 left join t2 on t2.a=t1.a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index 1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 2 Range checked for each record (index map: 0x1) +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `char` = "`t1`.`a`" of type `int` drop table t1, t2; create table t1 (a char(10) primary key); insert into t1 values ('foo'),('bar'); diff --git a/mysql-test/main/type_binary.result b/mysql-test/main/type_binary.result index ca0495e3899..d1aa4ada5af 100644 --- a/mysql-test/main/type_binary.result +++ b/mysql-test/main/type_binary.result @@ -220,3 +220,180 @@ def CAST(a AS BINARY(16777215)) 250 16777215 0 Y 128 0 63 def CAST(a AS BINARY(16777216)) 251 16777216 0 Y 128 0 63 CAST(a AS BINARY(0)) CAST(a AS BINARY(1)) CAST(a AS BINARY(16)) CAST(a AS BINARY(255)) CAST(a AS BINARY(256)) CAST(a AS BINARY(512)) CAST(a AS BINARY(513)) CAST(a AS BINARY(65532)) CAST(a AS BINARY(65533)) CAST(a AS BINARY(65534)) CAST(a AS BINARY(65535)) CAST(a AS BINARY(65536)) CAST(a AS BINARY(16777215)) CAST(a AS BINARY(16777216)) DROP TABLE t1; +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col VARBINARY(32), KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (20230100+i); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +20230101 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "20230101" of type `int` +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "20230101102030" of type `bigint` +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "20230101102030.1" of type `decimal` +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "20230101102030.1e0" of type `double` +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "DATE'2001-01-01'" of type `date` +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "TIME'10:20:30'" of type `time` +Warning 1292 Truncated incorrect time value: '20230101' +Warning 1292 Truncated incorrect time value: '20230102' +Warning 1292 Truncated incorrect time value: '20230103' +Warning 1292 Truncated incorrect time value: '20230104' +Warning 1292 Truncated incorrect time value: '20230105' +Warning 1292 Truncated incorrect time value: '20230106' +Warning 1292 Truncated incorrect time value: '20230107' +Warning 1292 Truncated incorrect time value: '20230108' +Warning 1292 Truncated incorrect time value: '20230109' +Warning 1292 Truncated incorrect time value: '20230110' +Warning 1292 Truncated incorrect time value: '20230111' +Warning 1292 Truncated incorrect time value: '20230112' +Warning 1292 Truncated incorrect time value: '20230113' +Warning 1292 Truncated incorrect time value: '20230114' +Warning 1292 Truncated incorrect time value: '20230115' +Warning 1292 Truncated incorrect time value: '20230116' +Warning 1292 Truncated incorrect time value: '20230117' +Warning 1292 Truncated incorrect time value: '20230118' +Warning 1292 Truncated incorrect time value: '20230119' +Warning 1292 Truncated incorrect time value: '20230120' +Warning 1292 Truncated incorrect time value: '20230121' +Warning 1292 Truncated incorrect time value: '20230122' +Warning 1292 Truncated incorrect time value: '20230123' +Warning 1292 Truncated incorrect time value: '20230124' +Warning 1292 Truncated incorrect time value: '20230125' +Warning 1292 Truncated incorrect time value: '20230126' +Warning 1292 Truncated incorrect time value: '20230127' +Warning 1292 Truncated incorrect time value: '20230128' +Warning 1292 Truncated incorrect time value: '20230129' +Warning 1292 Truncated incorrect time value: '20230130' +Warning 1292 Truncated incorrect time value: '20230131' +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +Warnings: +Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten condition: `convert(``t1``.``indexed_col`` using utf8mb3) = _utf8mb3'0' collate utf8mb3_bin` +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `int` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `int unsigned` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `bigint` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `bigint unsigned` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `decimal` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `float` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `double` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 +20230102 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_binary.test b/mysql-test/main/type_binary.test index 04cdc94e6d8..bfc9222762a 100644 --- a/mysql-test/main/type_binary.test +++ b/mysql-test/main/type_binary.test @@ -156,3 +156,22 @@ FROM t1; --disable_metadata --enable_view_protocol DROP TABLE t1; + + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col VARBINARY(32), KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (20230100+i); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_bit.result b/mysql-test/main/type_bit.result index e051a52d56a..d075e883ac2 100644 --- a/mysql-test/main/type_bit.result +++ b/mysql-test/main/type_bit.result @@ -1884,3 +1884,157 @@ DROP TABLE t1; # # End of 10.5 tests # +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col BIT(64), KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (CONCAT(20230100+i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "DATE'2001-01-01'" of type `date` +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "TIME'10:20:30'" of type `time` +Warning 1292 Truncated incorrect time value: '20230101' +Warning 1292 Truncated incorrect time value: '20230102' +Warning 1292 Truncated incorrect time value: '20230103' +Warning 1292 Truncated incorrect time value: '20230104' +Warning 1292 Truncated incorrect time value: '20230105' +Warning 1292 Truncated incorrect time value: '20230106' +Warning 1292 Truncated incorrect time value: '20230107' +Warning 1292 Truncated incorrect time value: '20230108' +Warning 1292 Truncated incorrect time value: '20230109' +Warning 1292 Truncated incorrect time value: '20230110' +Warning 1292 Truncated incorrect time value: '20230111' +Warning 1292 Truncated incorrect time value: '20230112' +Warning 1292 Truncated incorrect time value: '20230113' +Warning 1292 Truncated incorrect time value: '20230114' +Warning 1292 Truncated incorrect time value: '20230115' +Warning 1292 Truncated incorrect time value: '20230116' +Warning 1292 Truncated incorrect time value: '20230117' +Warning 1292 Truncated incorrect time value: '20230118' +Warning 1292 Truncated incorrect time value: '20230119' +Warning 1292 Truncated incorrect time value: '20230120' +Warning 1292 Truncated incorrect time value: '20230121' +Warning 1292 Truncated incorrect time value: '20230122' +Warning 1292 Truncated incorrect time value: '20230123' +Warning 1292 Truncated incorrect time value: '20230124' +Warning 1292 Truncated incorrect time value: '20230125' +Warning 1292 Truncated incorrect time value: '20230126' +Warning 1292 Truncated incorrect time value: '20230127' +Warning 1292 Truncated incorrect time value: '20230128' +Warning 1292 Truncated incorrect time value: '20230129' +Warning 1292 Truncated incorrect time value: '20230130' +Warning 1292 Truncated incorrect time value: '20230131' +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 +20230102 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_bit.test b/mysql-test/main/type_bit.test index 846fc34e2e9..8bab78adeaf 100644 --- a/mysql-test/main/type_bit.test +++ b/mysql-test/main/type_bit.test @@ -571,3 +571,22 @@ DROP TABLE t1; --echo # --echo # End of 10.5 tests --echo # + + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col BIT(64), KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (CONCAT(20230100+i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_bit_innodb.result b/mysql-test/main/type_bit_innodb.result index 67b4ff55674..fc932c8749e 100644 --- a/mysql-test/main/type_bit_innodb.result +++ b/mysql-test/main/type_bit_innodb.result @@ -424,3 +424,157 @@ hex(f1) hex(f2) 0 0 drop table t1; SET GLOBAL innodb_stats_persistent=@save_stats_persistent; +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col BIT(64), KEY(indexed_col)) ENGINE=InnoDB; +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (CONCAT(20230100+i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "DATE'2001-01-01'" of type `date` +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "TIME'10:20:30'" of type `time` +Warning 1292 Truncated incorrect time value: '20230101' +Warning 1292 Truncated incorrect time value: '20230102' +Warning 1292 Truncated incorrect time value: '20230103' +Warning 1292 Truncated incorrect time value: '20230104' +Warning 1292 Truncated incorrect time value: '20230105' +Warning 1292 Truncated incorrect time value: '20230106' +Warning 1292 Truncated incorrect time value: '20230107' +Warning 1292 Truncated incorrect time value: '20230108' +Warning 1292 Truncated incorrect time value: '20230109' +Warning 1292 Truncated incorrect time value: '20230110' +Warning 1292 Truncated incorrect time value: '20230111' +Warning 1292 Truncated incorrect time value: '20230112' +Warning 1292 Truncated incorrect time value: '20230113' +Warning 1292 Truncated incorrect time value: '20230114' +Warning 1292 Truncated incorrect time value: '20230115' +Warning 1292 Truncated incorrect time value: '20230116' +Warning 1292 Truncated incorrect time value: '20230117' +Warning 1292 Truncated incorrect time value: '20230118' +Warning 1292 Truncated incorrect time value: '20230119' +Warning 1292 Truncated incorrect time value: '20230120' +Warning 1292 Truncated incorrect time value: '20230121' +Warning 1292 Truncated incorrect time value: '20230122' +Warning 1292 Truncated incorrect time value: '20230123' +Warning 1292 Truncated incorrect time value: '20230124' +Warning 1292 Truncated incorrect time value: '20230125' +Warning 1292 Truncated incorrect time value: '20230126' +Warning 1292 Truncated incorrect time value: '20230127' +Warning 1292 Truncated incorrect time value: '20230128' +Warning 1292 Truncated incorrect time value: '20230129' +Warning 1292 Truncated incorrect time value: '20230130' +Warning 1292 Truncated incorrect time value: '20230131' +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 +20230102 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bit` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_bit_innodb.test b/mysql-test/main/type_bit_innodb.test index 5fc7c188246..196f28f12ec 100644 --- a/mysql-test/main/type_bit_innodb.test +++ b/mysql-test/main/type_bit_innodb.test @@ -160,3 +160,21 @@ select hex(f1), hex(f2) from t1; drop table t1; SET GLOBAL innodb_stats_persistent=@save_stats_persistent; + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col BIT(64), KEY(indexed_col)) ENGINE=InnoDB; +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (CONCAT(20230100+i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_blob.result b/mysql-test/main/type_blob.result index 80bcab5cbe0..c3211a78a99 100644 --- a/mysql-test/main/type_blob.result +++ b/mysql-test/main/type_blob.result @@ -1155,3 +1155,263 @@ drop table t1; # # End of 10.4 test # +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col BLOB, KEY(indexed_col(64))); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (20230100+i); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +20230101 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "20230101" of type `int` +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "20230101102030" of type `bigint` +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "20230101102030.1" of type `decimal` +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "20230101102030.1e0" of type `double` +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "DATE'2001-01-01'" of type `date` +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "TIME'10:20:30'" of type `time` +Warning 1292 Truncated incorrect time value: '20230101' +Warning 1292 Truncated incorrect time value: '20230102' +Warning 1292 Truncated incorrect time value: '20230103' +Warning 1292 Truncated incorrect time value: '20230104' +Warning 1292 Truncated incorrect time value: '20230105' +Warning 1292 Truncated incorrect time value: '20230106' +Warning 1292 Truncated incorrect time value: '20230107' +Warning 1292 Truncated incorrect time value: '20230108' +Warning 1292 Truncated incorrect time value: '20230109' +Warning 1292 Truncated incorrect time value: '20230110' +Warning 1292 Truncated incorrect time value: '20230111' +Warning 1292 Truncated incorrect time value: '20230112' +Warning 1292 Truncated incorrect time value: '20230113' +Warning 1292 Truncated incorrect time value: '20230114' +Warning 1292 Truncated incorrect time value: '20230115' +Warning 1292 Truncated incorrect time value: '20230116' +Warning 1292 Truncated incorrect time value: '20230117' +Warning 1292 Truncated incorrect time value: '20230118' +Warning 1292 Truncated incorrect time value: '20230119' +Warning 1292 Truncated incorrect time value: '20230120' +Warning 1292 Truncated incorrect time value: '20230121' +Warning 1292 Truncated incorrect time value: '20230122' +Warning 1292 Truncated incorrect time value: '20230123' +Warning 1292 Truncated incorrect time value: '20230124' +Warning 1292 Truncated incorrect time value: '20230125' +Warning 1292 Truncated incorrect time value: '20230126' +Warning 1292 Truncated incorrect time value: '20230127' +Warning 1292 Truncated incorrect time value: '20230128' +Warning 1292 Truncated incorrect time value: '20230129' +Warning 1292 Truncated incorrect time value: '20230130' +Warning 1292 Truncated incorrect time value: '20230131' +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +Warnings: +Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten condition: `convert(``t1``.``indexed_col`` using utf8mb3) = _utf8mb3'0' collate utf8mb3_bin` +DROP TABLE t1; +SET note_verbosity=DEFAULT; +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col TEXT, KEY(indexed_col(64))); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (20230100+i); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +20230101 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "20230101" of type `int` +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "20230101102030" of type `bigint` +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "20230101102030.1" of type `decimal` +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "20230101102030.1e0" of type `double` +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "DATE'2001-01-01'" of type `date` +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "TIME'10:20:30'" of type `time` +Warning 1292 Truncated incorrect time value: '20230101' +Warning 1292 Truncated incorrect time value: '20230102' +Warning 1292 Truncated incorrect time value: '20230103' +Warning 1292 Truncated incorrect time value: '20230104' +Warning 1292 Truncated incorrect time value: '20230105' +Warning 1292 Truncated incorrect time value: '20230106' +Warning 1292 Truncated incorrect time value: '20230107' +Warning 1292 Truncated incorrect time value: '20230108' +Warning 1292 Truncated incorrect time value: '20230109' +Warning 1292 Truncated incorrect time value: '20230110' +Warning 1292 Truncated incorrect time value: '20230111' +Warning 1292 Truncated incorrect time value: '20230112' +Warning 1292 Truncated incorrect time value: '20230113' +Warning 1292 Truncated incorrect time value: '20230114' +Warning 1292 Truncated incorrect time value: '20230115' +Warning 1292 Truncated incorrect time value: '20230116' +Warning 1292 Truncated incorrect time value: '20230117' +Warning 1292 Truncated incorrect time value: '20230118' +Warning 1292 Truncated incorrect time value: '20230119' +Warning 1292 Truncated incorrect time value: '20230120' +Warning 1292 Truncated incorrect time value: '20230121' +Warning 1292 Truncated incorrect time value: '20230122' +Warning 1292 Truncated incorrect time value: '20230123' +Warning 1292 Truncated incorrect time value: '20230124' +Warning 1292 Truncated incorrect time value: '20230125' +Warning 1292 Truncated incorrect time value: '20230126' +Warning 1292 Truncated incorrect time value: '20230127' +Warning 1292 Truncated incorrect time value: '20230128' +Warning 1292 Truncated incorrect time value: '20230129' +Warning 1292 Truncated incorrect time value: '20230130' +Warning 1292 Truncated incorrect time value: '20230131' +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +Warnings: +Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten condition: `convert(``t1``.``indexed_col`` using utf8mb3) = _utf8mb3'0' collate utf8mb3_bin` +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "`t2`.`not_indexed_col`" of type `int` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "`t2`.`not_indexed_col`" of type `int unsigned` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "`t2`.`not_indexed_col`" of type `bigint` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "`t2`.`not_indexed_col`" of type `bigint unsigned` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "`t2`.`not_indexed_col`" of type `decimal` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "`t2`.`not_indexed_col`" of type `float` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "`t2`.`not_indexed_col`" of type `double` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 +20230102 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `blob` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten condition: `convert(``t1``.``indexed_col`` using utf8mb3) = ``t2``.``not_indexed_col``` +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_blob.test b/mysql-test/main/type_blob.test index 7ea6639d167..fda61d2d2b6 100644 --- a/mysql-test/main/type_blob.test +++ b/mysql-test/main/type_blob.test @@ -773,3 +773,34 @@ drop table t1; --echo # --echo # End of 10.4 test --echo # + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col BLOB, KEY(indexed_col(64))); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (20230100+i); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col TEXT, KEY(indexed_col(64))); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (20230100+i); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_date.result b/mysql-test/main/type_date.result index 8af3e224c8a..7cfc30fc2fe 100644 --- a/mysql-test/main/type_date.result +++ b/mysql-test/main/type_date.result @@ -1164,3 +1164,125 @@ set sql_mode=default; # # End of 10.4 tests # +# +# Start of 10.6 tests +# +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col DATE, KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +2023-01-01 +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +Warnings: +Warning 1292 Truncated incorrect datetime value: '10:20:30' +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +Warnings: +Warning 1292 Truncated incorrect datetime value: '\x00' +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +Warnings: +Warning 1292 Truncated incorrect datetime value: '0' +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 20230101 +2023-01-02 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 20230101 +2023-01-02 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 2023-01-01 +2023-01-02 2023-01-02 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 2023-01-01 00:00:00 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 2023-01-01 00:00:00 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Incorrect datetime value: '0' +Warning 1292 Incorrect datetime value: '1' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_date.test b/mysql-test/main/type_date.test index 81cad6b5af5..d4981183c10 100644 --- a/mysql-test/main/type_date.test +++ b/mysql-test/main/type_date.test @@ -806,3 +806,26 @@ set sql_mode=default; --echo # --echo # End of 10.4 tests --echo # + + +--echo # +--echo # Start of 10.6 tests +--echo # + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col DATE, KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_datetime.result b/mysql-test/main/type_datetime.result index 2293050292a..949ae16f12c 100644 --- a/mysql-test/main/type_datetime.result +++ b/mysql-test/main/type_datetime.result @@ -1585,3 +1585,125 @@ DROP TABLE t1; # # End of 10.4 tests # +# +# Start of 10.6 tests +# +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col DATETIME, KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +2023-01-01 00:00:00 +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +Warnings: +Warning 1292 Truncated incorrect datetime value: '10:20:30' +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +Warnings: +Warning 1292 Truncated incorrect datetime value: '\x00' +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +Warnings: +Warning 1292 Truncated incorrect datetime value: '0' +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 00:00:00 20230101 +2023-01-02 00:00:00 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 00:00:00 20230101 +2023-01-02 00:00:00 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 00:00:00 2023-01-01 +2023-01-02 00:00:00 2023-01-02 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 00:00:00 2023-01-01 00:00:00 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 00:00:00 2023-01-01 00:00:00 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Incorrect datetime value: '0' +Warning 1292 Incorrect datetime value: '1' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_datetime.test b/mysql-test/main/type_datetime.test index 4a14bee4319..3c46d10718f 100644 --- a/mysql-test/main/type_datetime.test +++ b/mysql-test/main/type_datetime.test @@ -1055,3 +1055,26 @@ DROP TABLE t1; --echo # --echo # End of 10.4 tests --echo # + + +--echo # +--echo # Start of 10.6 tests +--echo # + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col DATETIME, KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_enum.result b/mysql-test/main/type_enum.result index f9300b81b39..311875d4aa6 100644 --- a/mysql-test/main/type_enum.result +++ b/mysql-test/main/type_enum.result @@ -1903,6 +1903,9 @@ EXPLAIN SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 1 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `enum` = "`t1`.`c1`" of type `date` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `enum` = "'2001-01-01'" of type `date` SELECT t1.* FROM t1 LEFT JOIN t2 USING (c1); c1 2001-01-01 @@ -1912,6 +1915,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING (c1); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 1 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `enum` = "`t1`.`c1`" of type `date` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `enum` = "'2001-01-01'" of type `date` DROP TABLE t1, t2; # # MDEV-6978 Bad results with join comparing case insensitive VARCHAR/ENUM/SET expression to a _bin ENUM column @@ -1942,6 +1948,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 1 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "`t1`.`c1` collate latin1_swedish_ci" of collation `latin1_swedish_ci` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "('a' collate latin1_swedish_ci)" of collation `latin1_swedish_ci` DROP TABLE IF EXISTS t1,t2; CREATE TABLE t1 (c1 SET('a') CHARACTER SET latin1 PRIMARY KEY); INSERT INTO t1 VALUES ('a'); @@ -1969,6 +1978,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 1 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "`t1`.`c1` collate latin1_swedish_ci" of collation `latin1_swedish_ci` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "('a' collate latin1_swedish_ci)" of collation `latin1_swedish_ci` DROP TABLE IF EXISTS t1,t2; CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET latin1 PRIMARY KEY); INSERT INTO t1 VALUES ('a'); @@ -1996,6 +2008,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 1 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "`t1`.`c1` collate latin1_swedish_ci" of collation `latin1_swedish_ci` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "('a' collate latin1_swedish_ci)" of collation `latin1_swedish_ci` DROP TABLE IF EXISTS t1,t2; # # MDEV-6991 GROUP_MIN_MAX optimization is erroneously applied in some cases @@ -2353,3 +2368,205 @@ a FLOOR(a) CEILING(a) TRUNCATE(a,0) ROUND(a) 999999999999999999999999999999999999999999999999999999999999 1 1 1 1 DROP TABLE t2; DROP TABLE t1; +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 ( +indexed_col ENUM('2001','2002','2003','2004','2005','2006','2007','2008','2009','2010'), +KEY(indexed_col) +); +FOR i IN 1..10 +DO +INSERT INTO t1 VALUES (i); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `enum` = "DATE'2001-01-01'" of type `date` +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `enum` = "TIME'10:20:30'" of type `time` +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `enum` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +Warnings: +Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten condition: `convert(``t1``.``indexed_col`` using utf8mb3) = _utf8mb3'0' collate utf8mb3_bin` +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `enum` = "`t2`.`not_indexed_col`" of type `date` +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `enum` = "`t2`.`not_indexed_col`" of type `datetime` +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `enum` = "`t2`.`not_indexed_col`" of type `timestamp` +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of collation `latin1_swedish_ci` = "`t2`.`not_indexed_col`" of collation `binary` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten condition: `convert(``t1``.``indexed_col`` using utf8mb3) = ``t2``.``not_indexed_col``` +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_enum.test b/mysql-test/main/type_enum.test index bcbc4cc520e..56b2313d2b5 100644 --- a/mysql-test/main/type_enum.test +++ b/mysql-test/main/type_enum.test @@ -555,3 +555,25 @@ SHOW CREATE TABLE t2; SELECT * FROM t2; DROP TABLE t2; DROP TABLE t1; + + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 ( + indexed_col ENUM('2001','2002','2003','2004','2005','2006','2007','2008','2009','2010'), + KEY(indexed_col) +); +DELIMITER $$; +FOR i IN 1..10 +DO + INSERT INTO t1 VALUES (i); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_float.result b/mysql-test/main/type_float.result index 500f906642d..609326632cc 100644 --- a/mysql-test/main/type_float.result +++ b/mysql-test/main/type_float.result @@ -538,6 +538,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 8 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `double` = "`t1`.`a`" of type `datetime` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `double` = "'1999-01-01 00:00:00'" of type `datetime` DROP TABLE t1,t2; # # MDEV-6971 Bad results with joins comparing TIME and DOUBLE/DECIMAL columns @@ -568,6 +571,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING(a); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 8 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `double` = "`t1`.`a`" of type `time` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `double` = "'10:20:30.000000'" of type `time` DROP TABLE t1,t2; # # End of 10.0 tests @@ -1169,3 +1175,259 @@ fdec 123.456.789,12345678900000000000000000000000000000 # # End of 10.4 tests # +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col FLOAT, KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `float` = "DATE'2001-01-01'" of type `date` +Warning 1292 Incorrect datetime value: '20230132' for column `test`.`t1`.`indexed_col` at row 31 +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `float` = "TIME'10:20:30'" of type `time` +Warning 1292 Incorrect time value: '20230132' for column `test`.`t1`.`indexed_col` at row 31 +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `float` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +Warning 1292 Incorrect datetime value: '20230132' for column `test`.`t1`.`indexed_col` at row 31 +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230100 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230100 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230100 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `float` = "`t2`.`not_indexed_col`" of type `date` +Warning 1292 Incorrect datetime value: '20230132' for column `test`.`t1`.`indexed_col` at row 31 +Warning 1292 Incorrect datetime value: '20230132' for column `test`.`t1`.`indexed_col` at row 31 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `float` = "`t2`.`not_indexed_col`" of type `datetime` +Warning 1292 Incorrect datetime value: '20230132' for column `test`.`t1`.`indexed_col` at row 31 +Warning 1292 Incorrect datetime value: '20230132' for column `test`.`t1`.`indexed_col` at row 31 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `float` = "`t2`.`not_indexed_col`" of type `timestamp` +Warning 1292 Incorrect datetime value: '20230132' for column `test`.`t1`.`indexed_col` at row 31 +Warning 1292 Incorrect datetime value: '20230132' for column `test`.`t1`.`indexed_col` at row 31 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '2001-01-01' +Warning 1292 Truncated incorrect DOUBLE value: '2001-01-02' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '2001-01-01' +Warning 1292 Truncated incorrect DOUBLE value: '2001-01-02' +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col DOUBLE, KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +20230101 +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `double` = "DATE'2001-01-01'" of type `date` +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `double` = "TIME'10:20:30'" of type `time` +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `double` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 +20230102 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `double` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `double` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `double` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '2001-01-01' +Warning 1292 Truncated incorrect DOUBLE value: '2001-01-02' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '2001-01-01' +Warning 1292 Truncated incorrect DOUBLE value: '2001-01-02' +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_float.test b/mysql-test/main/type_float.test index 7516508ac3c..5a74941ff00 100644 --- a/mysql-test/main/type_float.test +++ b/mysql-test/main/type_float.test @@ -719,3 +719,36 @@ DELIMITER ;$$ --echo # --echo # End of 10.4 tests --echo # + + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col FLOAT, KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col DOUBLE, KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_int.result b/mysql-test/main/type_int.result index c25b213c7c4..9a54c9a5287 100644 --- a/mysql-test/main/type_int.result +++ b/mysql-test/main/type_int.result @@ -1688,3 +1688,256 @@ drop table t1; # # End of 10.5 tests # +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col INT, KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +20230101 +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int` = "DATE'2001-01-01'" of type `date` +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int` = "TIME'10:20:30'" of type `time` +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 +20230102 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col BIGINT, KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +20230101 +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '10:20:30' +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '2001-01-01' +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '2001-01-01 10:20:30' +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 +20230102 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bigint` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bigint` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bigint` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_int.test b/mysql-test/main/type_int.test index c339bfa1834..c47ab501116 100644 --- a/mysql-test/main/type_int.test +++ b/mysql-test/main/type_int.test @@ -567,3 +567,36 @@ drop table t1; --echo # --echo # End of 10.5 tests --echo # + + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col INT, KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col BIGINT, KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_newdecimal.result b/mysql-test/main/type_newdecimal.result index 645178db2ce..152cae4b10e 100644 --- a/mysql-test/main/type_newdecimal.result +++ b/mysql-test/main/type_newdecimal.result @@ -2134,6 +2134,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 14 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `decimal` = "`t1`.`a`" of type `datetime` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `decimal` = "'1999-01-01 00:00:00'" of type `datetime` DROP TABLE t1,t2; # # MDEV-6971 Bad results with joins comparing TIME and DOUBLE/DECIMAL columns @@ -2164,6 +2167,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING(a); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 14 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `decimal` = "`t1`.`a`" of type `time` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `decimal` = "'10:20:30.000000'" of type `time` DROP TABLE t1,t2; # # End of 10.0 tests @@ -2802,3 +2808,131 @@ DROP TABLE t2,t1; # # End of 10.4 tests # +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col DECIMAL(30,6), KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +20230101.000000 +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `decimal` = "DATE'2001-01-01'" of type `date` +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `decimal` = "TIME'10:20:30'" of type `time` +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `decimal` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101.000000 20230101 +20230102.000000 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101.000000 20230101 +20230102.000000 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101.000000 2023-01-01 +20230102.000000 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `decimal` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101.000000 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `decimal` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101.000000 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `decimal` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '2001-01-01' +Warning 1292 Truncated incorrect DECIMAL value: '2001-01-02' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '2001-01-01' +Warning 1292 Truncated incorrect DECIMAL value: '2001-01-02' +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_newdecimal.test b/mysql-test/main/type_newdecimal.test index af5dc43fbd3..af82b7d601c 100644 --- a/mysql-test/main/type_newdecimal.test +++ b/mysql-test/main/type_newdecimal.test @@ -2011,3 +2011,21 @@ DROP TABLE t2,t1; --echo # --echo # End of 10.4 tests --echo # + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col DECIMAL(30,6), KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_set.result b/mysql-test/main/type_set.result index ea057157569..a3f988718b5 100644 --- a/mysql-test/main/type_set.result +++ b/mysql-test/main/type_set.result @@ -133,6 +133,9 @@ EXPLAIN SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 1 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `set` = "`t1`.`c1`" of type `date` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `set` = "'2001-01-01'" of type `date` SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1; c1 2001-01-01 @@ -142,6 +145,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 1 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `set` = "`t1`.`c1`" of type `date` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `set` = "'2001-01-01'" of type `date` DROP TABLE t1, t2; # # MDEV-6978 Bad results with join comparing case insensitive VARCHAR/ENUM/SET expression to a _bin ENUM column @@ -172,6 +178,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 1 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "`t1`.`c1` collate latin1_swedish_ci" of collation `latin1_swedish_ci` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "('a' collate latin1_swedish_ci)" of collation `latin1_swedish_ci` DROP TABLE IF EXISTS t1,t2; CREATE TABLE t1 (c1 SET('a') CHARACTER SET latin1 PRIMARY KEY); INSERT INTO t1 VALUES ('a'); @@ -199,6 +208,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 1 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "`t1`.`c1` collate latin1_swedish_ci" of collation `latin1_swedish_ci` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "('a' collate latin1_swedish_ci)" of collation `latin1_swedish_ci` DROP TABLE IF EXISTS t1,t2; CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET latin1 PRIMARY KEY); INSERT INTO t1 VALUES ('a'); @@ -226,6 +238,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 1 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "`t1`.`c1` collate latin1_swedish_ci" of collation `latin1_swedish_ci` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of collation `latin1_bin` = "('a' collate latin1_swedish_ci)" of collation `latin1_swedish_ci` DROP TABLE IF EXISTS t1,t2; # # MDEV-6993 Bad results with join comparing DECIMAL and ENUM/SET columns @@ -379,3 +394,205 @@ a FLOOR(a) CEILING(a) TRUNCATE(a,0) ROUND(a) 999999999999999999999999999999999999999999999999999999999999 1 1 1 1 DROP TABLE t2; DROP TABLE t1; +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 ( +indexed_col SET('2001','2002','2003','2004','2005','2006','2007','2008','2009','2010'), +KEY(indexed_col) +); +FOR i IN 1..10 +DO +INSERT INTO t1 VALUES (CONCAT(2000+i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `set` = "DATE'2001-01-01'" of type `date` +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `set` = "TIME'10:20:30'" of type `time` +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `set` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +Warnings: +Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten condition: `convert(``t1``.``indexed_col`` using utf8mb3) = _utf8mb3'0' collate utf8mb3_bin` +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `set` = "`t2`.`not_indexed_col`" of type `date` +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `set` = "`t2`.`not_indexed_col`" of type `datetime` +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `set` = "`t2`.`not_indexed_col`" of type `timestamp` +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +Warning 1292 Truncated incorrect datetime value: '2001' +Warning 1292 Truncated incorrect datetime value: '2002' +Warning 1292 Truncated incorrect datetime value: '2003' +Warning 1292 Truncated incorrect datetime value: '2004' +Warning 1292 Truncated incorrect datetime value: '2005' +Warning 1292 Truncated incorrect datetime value: '2006' +Warning 1292 Truncated incorrect datetime value: '2007' +Warning 1292 Truncated incorrect datetime value: '2008' +Warning 1292 Truncated incorrect datetime value: '2009' +Warning 1292 Truncated incorrect datetime value: '2010' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of collation `latin1_swedish_ci` = "`t2`.`not_indexed_col`" of collation `binary` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten condition: `convert(``t1``.``indexed_col`` using utf8mb3) = ``t2``.``not_indexed_col``` +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_set.test b/mysql-test/main/type_set.test index 2d0c81340ae..884d64f3e03 100644 --- a/mysql-test/main/type_set.test +++ b/mysql-test/main/type_set.test @@ -261,3 +261,24 @@ SHOW CREATE TABLE t2; SELECT * FROM t2; DROP TABLE t2; DROP TABLE t1; + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 ( + indexed_col SET('2001','2002','2003','2004','2005','2006','2007','2008','2009','2010'), + KEY(indexed_col) +); +DELIMITER $$; +FOR i IN 1..10 +DO + INSERT INTO t1 VALUES (CONCAT(2000+i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_time.result b/mysql-test/main/type_time.result index 34bf165a3e4..caf0b50714c 100644 --- a/mysql-test/main/type_time.result +++ b/mysql-test/main/type_time.result @@ -2492,3 +2492,115 @@ DROP TABLE t1; # # End of 10.4 tests # +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col TIME, KEY(indexed_col)); +FOR i IN 1..15 +DO +INSERT INTO t1 VALUES (MAKETIME(0,0,i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +Warnings: +Warning 1292 Truncated incorrect time value: '2001-01-01' +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +Warnings: +Warning 1292 Truncated incorrect time value: '\x00' +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +00:00:01 1 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect time value: '2001-01-01' +Warning 1292 Truncated incorrect time value: '2001-01-02' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect time value: '2001-01-01' +Warning 1292 Truncated incorrect time value: '2001-01-02' +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_time.test b/mysql-test/main/type_time.test index a75b278b1de..6d33c96a637 100644 --- a/mysql-test/main/type_time.test +++ b/mysql-test/main/type_time.test @@ -1623,3 +1623,21 @@ DROP TABLE t1; --echo # --echo # End of 10.4 tests --echo # + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col TIME, KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..15 +DO + INSERT INTO t1 VALUES (MAKETIME(0,0,i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_timestamp.result b/mysql-test/main/type_timestamp.result index c78619fe585..4a86d46a81e 100644 --- a/mysql-test/main/type_timestamp.result +++ b/mysql-test/main/type_timestamp.result @@ -1370,3 +1370,122 @@ drop table t1; # # End of 10.10 tests # +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col TIMESTAMP, KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +2023-01-01 00:00:00 +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +Warnings: +Warning 1292 Incorrect datetime value: '10:20:30' +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +Warnings: +Warning 1292 Incorrect datetime value: '\x00' +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +Warnings: +Warning 1292 Incorrect datetime value: '0' +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 00:00:00 20230101 +2023-01-02 00:00:00 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 00:00:00 20230101 +2023-01-02 00:00:00 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 00:00:00 2023-01-01 +2023-01-02 00:00:00 2023-01-02 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 00:00:00 2023-01-01 00:00:00 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +2023-01-01 00:00:00 2023-01-01 00:00:00 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Incorrect datetime value: '0' +Warning 1292 Incorrect datetime value: '1' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_timestamp.test b/mysql-test/main/type_timestamp.test index abff4e69c22..ea0b7dc78b8 100644 --- a/mysql-test/main/type_timestamp.test +++ b/mysql-test/main/type_timestamp.test @@ -923,3 +923,21 @@ drop table t1; --echo # --echo # End of 10.10 tests --echo # + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col TIMESTAMP, KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_uint.result b/mysql-test/main/type_uint.result index 7a90d6f0689..c98a513a3f9 100644 --- a/mysql-test/main/type_uint.result +++ b/mysql-test/main/type_uint.result @@ -66,7 +66,263 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `int unsigned` = "`t1`.`a`" of type `date` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`a` of type `int unsigned` = "'1999-01-01'" of type `date` DROP TABLE t1,t2; # # End of 10.0 tests # +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col INT UNSIGNED, KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +20230101 +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int unsigned` = "DATE'2001-01-01'" of type `date` +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int unsigned` = "TIME'10:20:30'" of type `time` +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int unsigned` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 +20230102 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int unsigned` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int unsigned` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `int unsigned` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col BIGINT UNSIGNED, KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +20230101 +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '10:20:30' +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '2001-01-01' +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '2001-01-01 10:20:30' +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 +20230102 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bigint unsigned` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bigint unsigned` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `bigint unsigned` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '2001-01-01' +Warning 1292 Truncated incorrect INTEGER value: '2001-01-02' +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_uint.test b/mysql-test/main/type_uint.test index ae48b30997a..72f32de848b 100644 --- a/mysql-test/main/type_uint.test +++ b/mysql-test/main/type_uint.test @@ -48,3 +48,36 @@ DROP TABLE t1,t2; --echo # --echo # End of 10.0 tests --echo # + + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col INT UNSIGNED, KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col BIGINT UNSIGNED, KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (MAKEDATE(2023, i)); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_varchar.result b/mysql-test/main/type_varchar.result index d00531018a4..6cce19dec38 100644 --- a/mysql-test/main/type_varchar.result +++ b/mysql-test/main/type_varchar.result @@ -612,6 +612,9 @@ EXPLAIN SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 22 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `varchar` = "`t1`.`c1`" of type `date` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `varchar` = "'2001-01-01'" of type `date` SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1; c1 2001-01-01 @@ -621,6 +624,9 @@ EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 1 SIMPLE t2 index PRIMARY PRIMARY 22 NULL 2 Using where; Using index +Warnings: +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `varchar` = "`t1`.`c1`" of type `date` +Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t2`.`c1` of type `varchar` = "'2001-01-01'" of type `date` DROP TABLE IF EXISTS t1,t2; # # MDEV-6989 BINARY and COLLATE xxx_bin comparisions are not used for optimization in some cases @@ -767,3 +773,182 @@ DROP TABLE vchar; # # End of 10.5 tests # +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col VARCHAR(32), KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (20230100+i); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +20230101 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "20230101" of type `int` +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "20230101102030" of type `bigint` +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "20230101102030.1" of type `decimal` +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "20230101102030.1e0" of type `double` +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "DATE'2001-01-01'" of type `date` +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "TIME'10:20:30'" of type `time` +Warning 1292 Truncated incorrect time value: '20230101' +Warning 1292 Truncated incorrect time value: '20230102' +Warning 1292 Truncated incorrect time value: '20230103' +Warning 1292 Truncated incorrect time value: '20230104' +Warning 1292 Truncated incorrect time value: '20230105' +Warning 1292 Truncated incorrect time value: '20230106' +Warning 1292 Truncated incorrect time value: '20230107' +Warning 1292 Truncated incorrect time value: '20230108' +Warning 1292 Truncated incorrect time value: '20230109' +Warning 1292 Truncated incorrect time value: '20230110' +Warning 1292 Truncated incorrect time value: '20230111' +Warning 1292 Truncated incorrect time value: '20230112' +Warning 1292 Truncated incorrect time value: '20230113' +Warning 1292 Truncated incorrect time value: '20230114' +Warning 1292 Truncated incorrect time value: '20230115' +Warning 1292 Truncated incorrect time value: '20230116' +Warning 1292 Truncated incorrect time value: '20230117' +Warning 1292 Truncated incorrect time value: '20230118' +Warning 1292 Truncated incorrect time value: '20230119' +Warning 1292 Truncated incorrect time value: '20230120' +Warning 1292 Truncated incorrect time value: '20230121' +Warning 1292 Truncated incorrect time value: '20230122' +Warning 1292 Truncated incorrect time value: '20230123' +Warning 1292 Truncated incorrect time value: '20230124' +Warning 1292 Truncated incorrect time value: '20230125' +Warning 1292 Truncated incorrect time value: '20230126' +Warning 1292 Truncated incorrect time value: '20230127' +Warning 1292 Truncated incorrect time value: '20230128' +Warning 1292 Truncated incorrect time value: '20230129' +Warning 1292 Truncated incorrect time value: '20230130' +Warning 1292 Truncated incorrect time value: '20230131' +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "TIMESTAMP'2001-01-01 10:20:30'" of type `datetime` +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +Warnings: +Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten condition: `convert(``t1``.``indexed_col`` using utf8mb3) = _utf8mb3'0' collate utf8mb3_bin` +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `int` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 20230101 +20230102 20230102 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `int unsigned` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `bigint` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `bigint unsigned` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `decimal` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `float` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `double` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 +20230102 2023-01-02 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +20230101 2023-01-01 00:00:00 +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `varchar` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten condition: `convert(``t1``.``indexed_col`` using utf8mb3) = ``t2``.``not_indexed_col``` +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_varchar.test b/mysql-test/main/type_varchar.test index f63523e226b..46b37554575 100644 --- a/mysql-test/main/type_varchar.test +++ b/mysql-test/main/type_varchar.test @@ -396,3 +396,22 @@ DROP TABLE vchar; --echo # --echo # End of 10.5 tests --echo # + + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col VARCHAR(32), KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (20230100+i); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_year.result b/mysql-test/main/type_year.result index aaee5049c63..6e3a7731b38 100644 --- a/mysql-test/main/type_year.result +++ b/mysql-test/main/type_year.result @@ -703,3 +703,110 @@ DROP TABLE t1; # # End of 10.5 tests # +# +# MDEV-32203 Raise notes when an index cannot be used on data type mismatch +# +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col YEAR, KEY(indexed_col)); +FOR i IN 1..31 +DO +INSERT INTO t1 VALUES (2023 + i); +END FOR; +$$ +SELECT * FROM t1 WHERE indexed_col=20230101; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +indexed_col +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +indexed_col +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +indexed_col +SELECT * FROM t1 WHERE indexed_col=0x00; +indexed_col +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +indexed_col +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `year` = "`t2`.`not_indexed_col`" of type `date` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `year` = "`t2`.`not_indexed_col`" of type `datetime` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +Warnings: +Note 1105 Cannot use key `indexed_col` part[0] for lookup: `test`.`t1`.`indexed_col` of type `year` = "`t2`.`not_indexed_col`" of type `timestamp` +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +indexed_col not_indexed_col +DROP TABLE t2; +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/type_year.test b/mysql-test/main/type_year.test index 52783a21b74..2edb67a89eb 100644 --- a/mysql-test/main/type_year.test +++ b/mysql-test/main/type_year.test @@ -386,3 +386,22 @@ DROP TABLE t1; --echo # --echo # End of 10.5 tests --echo # + + +--echo # +--echo # MDEV-32203 Raise notes when an index cannot be used on data type mismatch +--echo # + +SET note_verbosity=unusable_keys; +CREATE TABLE t1 (indexed_col YEAR, KEY(indexed_col)); +DELIMITER $$; +FOR i IN 1..31 +DO + INSERT INTO t1 VALUES (2023 + i); +END FOR; +$$ +DELIMITER ;$$ +--source unusable_keys_literals.inc +--source unusable_keys_joins.inc +DROP TABLE t1; +SET note_verbosity=DEFAULT; diff --git a/mysql-test/main/unusable_keys_joins.inc b/mysql-test/main/unusable_keys_joins.inc new file mode 100644 index 00000000000..14d235fab30 --- /dev/null +++ b/mysql-test/main/unusable_keys_joins.inc @@ -0,0 +1,66 @@ +--enable_prepare_warnings +CREATE TABLE t2 (not_indexed_col INT); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col INT UNSIGNED); +INSERT INTO t2 VALUES (20230101),(20230102); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col BIGINT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col BIGINT UNSIGNED); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col DECIMAL(30,6)); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col FLOAT); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col DOUBLE); +INSERT INTO t2 VALUES (20230101102030),(20230101102031); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col DATE); +INSERT INTO t2 VALUES ('2023-01-01'),('2023-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col DATETIME); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col TIMESTAMP); +INSERT INTO t2 VALUES ('2023-01-01 00:00:00'),('2023-01-01 00:00:01'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col VARBINARY(32)); +INSERT INTO t2 VALUES (0x30),(0x31); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col VARCHAR(32)); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; + +CREATE TABLE t2 (not_indexed_col VARCHAR(32) CHARACTER SET utf8mb3); +INSERT INTO t2 VALUES ('2001-01-01'),('2001-01-02'); +SELECT * FROM t1, t2 WHERE indexed_col=not_indexed_col; +DROP TABLE t2; +--disable_prepare_warnings diff --git a/mysql-test/main/unusable_keys_literals.inc b/mysql-test/main/unusable_keys_literals.inc new file mode 100644 index 00000000000..e19baa16f3c --- /dev/null +++ b/mysql-test/main/unusable_keys_literals.inc @@ -0,0 +1,14 @@ +--enable_prepare_warnings +SELECT * FROM t1 WHERE indexed_col=20230101; +SELECT * FROM t1 WHERE indexed_col=20230101102030; +SELECT * FROM t1 WHERE indexed_col=20230101102030.1; +SELECT * FROM t1 WHERE indexed_col=20230101102030.1e0; +SELECT * FROM t1 WHERE indexed_col='10:20:30'; +SELECT * FROM t1 WHERE indexed_col='2001-01-01'; +SELECT * FROM t1 WHERE indexed_col='2001-01-01 10:20:30'; +SELECT * FROM t1 WHERE indexed_col=DATE'2001-01-01'; +SELECT * FROM t1 WHERE indexed_col=TIME'10:20:30'; +SELECT * FROM t1 WHERE indexed_col=TIMESTAMP'2001-01-01 10:20:30'; +SELECT * FROM t1 WHERE indexed_col=0x00; +SELECT * FROM t1 WHERE indexed_col=_utf8mb3'0' COLLATE utf8mb3_bin; +--disable_prepare_warnings diff --git a/mysql-test/suite/sys_vars/r/log_slow_verbosity_basic.result b/mysql-test/suite/sys_vars/r/log_slow_verbosity_basic.result index 13f8f91ba04..e5dcc8fcafe 100644 --- a/mysql-test/suite/sys_vars/r/log_slow_verbosity_basic.result +++ b/mysql-test/suite/sys_vars/r/log_slow_verbosity_basic.result @@ -51,6 +51,18 @@ set session log_slow_verbosity=7; select @@session.log_slow_verbosity; @@session.log_slow_verbosity innodb,query_plan,explain +set session log_slow_verbosity=8; +select @@session.log_slow_verbosity; +@@session.log_slow_verbosity +engine +set session log_slow_verbosity=16; +select @@session.log_slow_verbosity; +@@session.log_slow_verbosity +warnings +set session log_slow_verbosity=32; +select @@session.log_slow_verbosity; +@@session.log_slow_verbosity +full set session log_slow_verbosity='innodb'; select @@session.log_slow_verbosity; @@session.log_slow_verbosity @@ -67,10 +79,10 @@ set session log_slow_verbosity='explain'; select @@session.log_slow_verbosity; @@session.log_slow_verbosity explain -set session log_slow_verbosity='innodb,query_plan,explain,engine,full'; +set session log_slow_verbosity='innodb,query_plan,explain,engine,warnings,full'; select @@session.log_slow_verbosity; @@session.log_slow_verbosity -innodb,query_plan,explain,engine,full +innodb,query_plan,explain,engine,warnings,full set session log_slow_verbosity=''; select @@session.log_slow_verbosity; @@session.log_slow_verbosity @@ -81,6 +93,6 @@ set session log_slow_verbosity=1e1; ERROR 42000: Incorrect argument type to variable 'log_slow_verbosity' set session log_slow_verbosity="foo"; ERROR 42000: Variable 'log_slow_verbosity' can't be set to the value of 'foo' -set session log_slow_verbosity=32; -ERROR 42000: Variable 'log_slow_verbosity' can't be set to the value of '32' +set session log_slow_verbosity=64; +ERROR 42000: Variable 'log_slow_verbosity' can't be set to the value of '64' SET @@global.log_slow_verbosity = @start_global_value; diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result index 19c5a24a835..2fc0b7dbaf6 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result @@ -1685,13 +1685,23 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME LOG_SLOW_FILTER VARIABLE_SCOPE SESSION VARIABLE_TYPE SET -VARIABLE_COMMENT Log only certain types of queries to the slow log. If variable empty alll kind of queries are logged. All types are bound by slow_query_time, except 'not_using_index' which is always logged if enabled +VARIABLE_COMMENT Log only certain types of queries to the slow log. If variable empty all kind of queries are logged. All types are bound by slow_query_time, except 'not_using_index' which is always logged if enabled NUMERIC_MIN_VALUE NULL NUMERIC_MAX_VALUE NULL NUMERIC_BLOCK_SIZE NULL ENUM_VALUE_LIST admin,filesort,filesort_on_disk,filesort_priority_queue,full_join,full_scan,not_using_index,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME LOG_SLOW_MAX_WARNINGS +VARIABLE_SCOPE SESSION +VARIABLE_TYPE BIGINT UNSIGNED +VARIABLE_COMMENT Max numbers of warnings printed to slow query log per statement +NUMERIC_MIN_VALUE 0 +NUMERIC_MAX_VALUE 1000 +NUMERIC_BLOCK_SIZE 1 +ENUM_VALUE_LIST NULL +READ_ONLY NO +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME LOG_SLOW_RATE_LIMIT VARIABLE_SCOPE SESSION VARIABLE_TYPE BIGINT UNSIGNED @@ -1719,7 +1729,7 @@ VARIABLE_COMMENT Verbosity level for the slow log NUMERIC_MIN_VALUE NULL NUMERIC_MAX_VALUE NULL NUMERIC_BLOCK_SIZE NULL -ENUM_VALUE_LIST innodb,query_plan,explain,engine,full +ENUM_VALUE_LIST innodb,query_plan,explain,engine,warnings,full READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME LOG_WARNINGS @@ -2202,6 +2212,16 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME NOTE_VERBOSITY +VARIABLE_SCOPE SESSION +VARIABLE_TYPE SET +VARIABLE_COMMENT Verbosity level for note-warnings given to the user. See also @@sql_notes. +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST basic,unusable_keys,explain +READ_ONLY NO +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME OLD VARIABLE_SCOPE SESSION VARIABLE_TYPE BOOLEAN @@ -3275,7 +3295,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME SQL_NOTES VARIABLE_SCOPE SESSION VARIABLE_TYPE BOOLEAN -VARIABLE_COMMENT If set to 1, the default, warning_count is incremented each time a Note warning is encountered. If set to 0, Note warnings are not recorded. mysqldump has outputs to set this variable to 0 so that no unnecessary increments occur when data is reloaded. +VARIABLE_COMMENT If set to 1, the default, warning_count is incremented each time a Note warning is encountered. If set to 0, Note warnings are not recorded. mysqldump has outputs to set this variable to 0 so that no unnecessary increments occur when data is reloaded. See also note_verbosity, which allows one to define with notes are sent. NUMERIC_MIN_VALUE NULL NUMERIC_MAX_VALUE NULL NUMERIC_BLOCK_SIZE NULL diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded,32bit.rdiff b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded,32bit.rdiff index 39deee979d0..daef1f58414 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded,32bit.rdiff +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded,32bit.rdiff @@ -1,5 +1,5 @@ ---- sysvars_server_notembedded.result 2023-08-01 16:37:40.350222956 +0200 -+++ sysvars_server_notembedded,32bit.result 2023-08-04 10:09:14.211943206 +0200 +--- suite/sys_vars/r/sysvars_server_notembedded.result 2023-09-26 14:15:14.054742094 +0300 ++++ suite/sys_vars/r/sysvars_server_notembedded,32bit.reject 2023-09-26 14:37:54.831543723 +0300 @@ -34,7 +34,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME ARIA_BLOCK_SIZE @@ -399,6 +399,15 @@ NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 31536000 @@ -1834,7 +1834,7 @@ + COMMAND_LINE_ARGUMENT REQUIRED + VARIABLE_NAME LOG_SLOW_MAX_WARNINGS + VARIABLE_SCOPE SESSION +-VARIABLE_TYPE BIGINT UNSIGNED ++VARIABLE_TYPE INT UNSIGNED + VARIABLE_COMMENT Max numbers of warnings printed to slow query log per statement + NUMERIC_MIN_VALUE 0 + NUMERIC_MAX_VALUE 1000 +@@ -1844,7 +1844,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME LOG_SLOW_RATE_LIMIT VARIABLE_SCOPE SESSION @@ -407,7 +416,7 @@ VARIABLE_COMMENT Write to slow log every #th slow query. Set to 1 to log everything. Increase it to reduce the size of the slow or the performance impact of slow logging NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 4294967295 -@@ -1864,7 +1864,7 @@ +@@ -1874,7 +1874,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME LOG_WARNINGS VARIABLE_SCOPE SESSION @@ -416,7 +425,7 @@ VARIABLE_COMMENT Log some not critical warnings to the general log file.Value can be between 0 and 11. Higher values mean more verbosity NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 4294967295 -@@ -1924,7 +1924,7 @@ +@@ -1934,7 +1934,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME MAX_ALLOWED_PACKET VARIABLE_SCOPE SESSION @@ -425,7 +434,7 @@ VARIABLE_COMMENT Max packet length to send to or receive from the server NUMERIC_MIN_VALUE 1024 NUMERIC_MAX_VALUE 1073741824 -@@ -1937,14 +1937,14 @@ +@@ -1947,14 +1947,14 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Sets the total size of the transactional cache NUMERIC_MIN_VALUE 4096 @@ -442,7 +451,7 @@ VARIABLE_COMMENT Binary log will be rotated automatically when the size exceeds this value. NUMERIC_MIN_VALUE 4096 NUMERIC_MAX_VALUE 1073741824 -@@ -1957,14 +1957,14 @@ +@@ -1967,14 +1967,14 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Sets the total size of the statement cache NUMERIC_MIN_VALUE 4096 @@ -459,7 +468,7 @@ VARIABLE_COMMENT The number of simultaneous clients allowed NUMERIC_MIN_VALUE 10 NUMERIC_MAX_VALUE 100000 -@@ -1974,7 +1974,7 @@ +@@ -1984,7 +1984,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MAX_CONNECT_ERRORS VARIABLE_SCOPE GLOBAL @@ -468,7 +477,7 @@ VARIABLE_COMMENT If there is more than this number of interrupted connections from a host this host will be blocked from further connections NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 4294967295 -@@ -1984,7 +1984,7 @@ +@@ -1994,7 +1994,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MAX_DELAYED_THREADS VARIABLE_SCOPE SESSION @@ -477,7 +486,7 @@ VARIABLE_COMMENT Don't start more than this number of threads to handle INSERT DELAYED statements. If set to zero INSERT DELAYED will be not used NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 16384 -@@ -2004,7 +2004,7 @@ +@@ -2014,7 +2014,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MAX_ERROR_COUNT VARIABLE_SCOPE SESSION @@ -486,7 +495,7 @@ VARIABLE_COMMENT Max number of errors/warnings to store for a statement NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 65535 -@@ -2017,14 +2017,14 @@ +@@ -2027,14 +2027,14 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Don't allow creation of heap tables bigger than this NUMERIC_MIN_VALUE 16384 @@ -503,7 +512,7 @@ VARIABLE_COMMENT Don't start more than this number of threads to handle INSERT DELAYED statements. If set to zero INSERT DELAYED will be not used NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 16384 -@@ -2044,7 +2044,7 @@ +@@ -2054,7 +2054,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MAX_LENGTH_FOR_SORT_DATA VARIABLE_SCOPE SESSION @@ -512,7 +521,7 @@ VARIABLE_COMMENT Max number of bytes in sorted records NUMERIC_MIN_VALUE 4 NUMERIC_MAX_VALUE 8388608 -@@ -2074,7 +2074,7 @@ +@@ -2084,7 +2084,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MAX_RECURSIVE_ITERATIONS VARIABLE_SCOPE SESSION @@ -521,7 +530,7 @@ VARIABLE_COMMENT Maximum number of iterations when executing recursive queries NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 4294967295 -@@ -2097,14 +2097,14 @@ +@@ -2107,14 +2107,14 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT The maximum size of the container of a rowid filter NUMERIC_MIN_VALUE 1024 @@ -538,7 +547,7 @@ VARIABLE_COMMENT Limit assumed max number of seeks when looking up rows based on a key NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 4294967295 -@@ -2124,7 +2124,7 @@ +@@ -2134,7 +2134,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MAX_SORT_LENGTH VARIABLE_SCOPE SESSION @@ -547,7 +556,7 @@ VARIABLE_COMMENT The number of bytes to use when sorting BLOB or TEXT values (only the first max_sort_length bytes of each value are used; the rest are ignored) NUMERIC_MIN_VALUE 64 NUMERIC_MAX_VALUE 8388608 -@@ -2134,7 +2134,7 @@ +@@ -2144,7 +2144,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MAX_SP_RECURSION_DEPTH VARIABLE_SCOPE SESSION @@ -556,7 +565,7 @@ VARIABLE_COMMENT Maximum stored procedure recursion depth NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 255 -@@ -2154,7 +2154,7 @@ +@@ -2164,7 +2164,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MAX_TMP_TABLES VARIABLE_SCOPE SESSION @@ -565,7 +574,7 @@ VARIABLE_COMMENT Unused, will be removed. NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 4294967295 -@@ -2174,7 +2174,7 @@ +@@ -2184,7 +2184,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MAX_WRITE_LOCK_COUNT VARIABLE_SCOPE GLOBAL @@ -574,7 +583,7 @@ VARIABLE_COMMENT After this many write locks, allow some read locks to run in between NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 4294967295 -@@ -2184,7 +2184,7 @@ +@@ -2194,7 +2194,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME METADATA_LOCKS_CACHE_SIZE VARIABLE_SCOPE GLOBAL @@ -583,7 +592,7 @@ VARIABLE_COMMENT Unused NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 1048576 -@@ -2194,7 +2194,7 @@ +@@ -2204,7 +2204,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME METADATA_LOCKS_HASH_INSTANCES VARIABLE_SCOPE GLOBAL @@ -592,7 +601,7 @@ VARIABLE_COMMENT Unused NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 1024 -@@ -2204,7 +2204,7 @@ +@@ -2214,7 +2214,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MIN_EXAMINED_ROW_LIMIT VARIABLE_SCOPE SESSION @@ -601,7 +610,7 @@ VARIABLE_COMMENT Don't write queries to slow log that examine fewer rows than that NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 4294967295 -@@ -2214,7 +2214,7 @@ +@@ -2224,7 +2224,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MRR_BUFFER_SIZE VARIABLE_SCOPE SESSION @@ -610,7 +619,7 @@ VARIABLE_COMMENT Size of buffer to use when using MRR with range access NUMERIC_MIN_VALUE 8192 NUMERIC_MAX_VALUE 2147483647 -@@ -2224,7 +2224,7 @@ +@@ -2234,7 +2234,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MYISAM_BLOCK_SIZE VARIABLE_SCOPE GLOBAL @@ -619,7 +628,7 @@ VARIABLE_COMMENT Block size to be used for MyISAM index pages NUMERIC_MIN_VALUE 1024 NUMERIC_MAX_VALUE 16384 -@@ -2234,7 +2234,7 @@ +@@ -2244,7 +2244,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME MYISAM_DATA_POINTER_SIZE VARIABLE_SCOPE GLOBAL @@ -628,7 +637,7 @@ VARIABLE_COMMENT Default pointer size to be used for MyISAM tables NUMERIC_MIN_VALUE 2 NUMERIC_MAX_VALUE 7 -@@ -2257,7 +2257,7 @@ +@@ -2267,7 +2267,7 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Restricts the total memory used for memory mapping of MySQL tables NUMERIC_MIN_VALUE 7 @@ -637,7 +646,7 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY YES -@@ -2274,10 +2274,10 @@ +@@ -2284,10 +2284,10 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME MYISAM_REPAIR_THREADS VARIABLE_SCOPE SESSION @@ -650,7 +659,7 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO -@@ -2287,7 +2287,7 @@ +@@ -2297,7 +2297,7 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE NUMERIC_MIN_VALUE 4096 @@ -659,7 +668,7 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO -@@ -2324,7 +2324,7 @@ +@@ -2334,7 +2334,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME NET_BUFFER_LENGTH VARIABLE_SCOPE SESSION @@ -668,7 +677,7 @@ VARIABLE_COMMENT Buffer length for TCP/IP and socket communication NUMERIC_MIN_VALUE 1024 NUMERIC_MAX_VALUE 1048576 -@@ -2334,7 +2334,7 @@ +@@ -2344,7 +2344,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME NET_READ_TIMEOUT VARIABLE_SCOPE SESSION @@ -677,7 +686,7 @@ VARIABLE_COMMENT Number of seconds to wait for more data from a connection before aborting the read NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 31536000 -@@ -2344,7 +2344,7 @@ +@@ -2354,7 +2354,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME NET_RETRY_COUNT VARIABLE_SCOPE SESSION @@ -686,7 +695,7 @@ VARIABLE_COMMENT If a read on a communication port is interrupted, retry this many times before giving up NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 4294967295 -@@ -2354,7 +2354,7 @@ +@@ -2364,7 +2364,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME NET_WRITE_TIMEOUT VARIABLE_SCOPE SESSION @@ -695,7 +704,7 @@ VARIABLE_COMMENT Number of seconds to wait for a block to be written to a connection before aborting the write NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 31536000 -@@ -2404,7 +2404,7 @@ +@@ -2424,7 +2424,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME OPEN_FILES_LIMIT VARIABLE_SCOPE GLOBAL @@ -704,7 +713,7 @@ VARIABLE_COMMENT If this is not 0, then mysqld will use this value to reserve file descriptors to use with setrlimit(). If this value is 0 or autoset then mysqld will reserve max_connections*5 or max_connections + table_cache*2 (whichever is larger) number of file descriptors NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 4294967295 -@@ -2414,17 +2414,17 @@ +@@ -2434,17 +2434,17 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME OPTIMIZER_MAX_SEL_ARG_WEIGHT VARIABLE_SCOPE SESSION @@ -725,7 +734,7 @@ VARIABLE_COMMENT Controls the heuristic(s) applied during query optimization to prune less-promising partial plans from the optimizer search space. Meaning: 0 - do not apply any heuristic, thus perform exhaustive search; 1 - prune plans based on number of retrieved rows NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 1 -@@ -2434,7 +2434,7 @@ +@@ -2454,7 +2454,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME OPTIMIZER_SEARCH_DEPTH VARIABLE_SCOPE SESSION @@ -734,7 +743,7 @@ VARIABLE_COMMENT Maximum depth of search performed by the query optimizer. Values larger than the number of relations in a query result in better query plans, but take longer to compile a query. Values smaller than the number of tables in a relation result in faster optimization, but may produce very bad query plans. If set to 0, the system will automatically pick a reasonable value. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 62 -@@ -2444,7 +2444,7 @@ +@@ -2464,7 +2464,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME OPTIMIZER_SELECTIVITY_SAMPLING_LIMIT VARIABLE_SCOPE SESSION @@ -743,7 +752,7 @@ VARIABLE_COMMENT Controls number of record samples to check condition selectivity NUMERIC_MIN_VALUE 10 NUMERIC_MAX_VALUE 4294967295 -@@ -2474,17 +2474,17 @@ +@@ -2494,17 +2494,17 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME OPTIMIZER_TRACE_MAX_MEM_SIZE VARIABLE_SCOPE SESSION @@ -764,7 +773,7 @@ VARIABLE_COMMENT Controls selectivity of which conditions the optimizer takes into account to calculate cardinality of a partial join when it searches for the best execution plan Meaning: 1 - use selectivity of index backed range conditions to calculate the cardinality of a partial join if the last joined table is accessed by full table scan or an index scan, 2 - use selectivity of index backed range conditions to calculate the cardinality of a partial join in any case, 3 - additionally always use selectivity of range conditions that are not backed by any index to calculate the cardinality of a partial join, 4 - use histograms to calculate selectivity of range conditions that are not backed by any index to calculate the cardinality of a partial join.5 - additionally use selectivity of certain non-range predicates calculated on record samples NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 5 -@@ -2504,7 +2504,7 @@ +@@ -2524,7 +2524,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME PERFORMANCE_SCHEMA_ACCOUNTS_SIZE VARIABLE_SCOPE GLOBAL @@ -773,7 +782,7 @@ VARIABLE_COMMENT Maximum number of instrumented user@host accounts. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2514,7 +2514,7 @@ +@@ -2534,7 +2534,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_DIGESTS_SIZE VARIABLE_SCOPE GLOBAL @@ -782,7 +791,7 @@ VARIABLE_COMMENT Size of the statement digest. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2524,7 +2524,7 @@ +@@ -2544,7 +2544,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_EVENTS_STAGES_HISTORY_LONG_SIZE VARIABLE_SCOPE GLOBAL @@ -791,7 +800,7 @@ VARIABLE_COMMENT Number of rows in EVENTS_STAGES_HISTORY_LONG. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2534,7 +2534,7 @@ +@@ -2554,7 +2554,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_EVENTS_STAGES_HISTORY_SIZE VARIABLE_SCOPE GLOBAL @@ -800,7 +809,7 @@ VARIABLE_COMMENT Number of rows per thread in EVENTS_STAGES_HISTORY. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1024 -@@ -2544,7 +2544,7 @@ +@@ -2564,7 +2564,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_EVENTS_STATEMENTS_HISTORY_LONG_SIZE VARIABLE_SCOPE GLOBAL @@ -809,7 +818,7 @@ VARIABLE_COMMENT Number of rows in EVENTS_STATEMENTS_HISTORY_LONG. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2554,7 +2554,7 @@ +@@ -2574,7 +2574,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_EVENTS_STATEMENTS_HISTORY_SIZE VARIABLE_SCOPE GLOBAL @@ -818,7 +827,7 @@ VARIABLE_COMMENT Number of rows per thread in EVENTS_STATEMENTS_HISTORY. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1024 -@@ -2564,7 +2564,7 @@ +@@ -2584,7 +2584,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_EVENTS_TRANSACTIONS_HISTORY_LONG_SIZE VARIABLE_SCOPE GLOBAL @@ -827,7 +836,7 @@ VARIABLE_COMMENT Number of rows in EVENTS_TRANSACTIONS_HISTORY_LONG. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2574,7 +2574,7 @@ +@@ -2594,7 +2594,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_EVENTS_TRANSACTIONS_HISTORY_SIZE VARIABLE_SCOPE GLOBAL @@ -836,7 +845,7 @@ VARIABLE_COMMENT Number of rows per thread in EVENTS_TRANSACTIONS_HISTORY. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1024 -@@ -2584,7 +2584,7 @@ +@@ -2604,7 +2604,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_EVENTS_WAITS_HISTORY_LONG_SIZE VARIABLE_SCOPE GLOBAL @@ -845,7 +854,7 @@ VARIABLE_COMMENT Number of rows in EVENTS_WAITS_HISTORY_LONG. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2594,7 +2594,7 @@ +@@ -2614,7 +2614,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_EVENTS_WAITS_HISTORY_SIZE VARIABLE_SCOPE GLOBAL @@ -854,7 +863,7 @@ VARIABLE_COMMENT Number of rows per thread in EVENTS_WAITS_HISTORY. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1024 -@@ -2604,7 +2604,7 @@ +@@ -2624,7 +2624,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_HOSTS_SIZE VARIABLE_SCOPE GLOBAL @@ -863,7 +872,7 @@ VARIABLE_COMMENT Maximum number of instrumented hosts. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2614,7 +2614,7 @@ +@@ -2634,7 +2634,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_COND_CLASSES VARIABLE_SCOPE GLOBAL @@ -872,7 +881,7 @@ VARIABLE_COMMENT Maximum number of condition instruments. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 256 -@@ -2624,7 +2624,7 @@ +@@ -2644,7 +2644,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_COND_INSTANCES VARIABLE_SCOPE GLOBAL @@ -881,7 +890,7 @@ VARIABLE_COMMENT Maximum number of instrumented condition objects. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2634,7 +2634,7 @@ +@@ -2654,7 +2654,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_DIGEST_LENGTH VARIABLE_SCOPE GLOBAL @@ -890,7 +899,7 @@ VARIABLE_COMMENT Maximum length considered for digest text, when stored in performance_schema tables. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 1048576 -@@ -2644,7 +2644,7 @@ +@@ -2664,7 +2664,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_FILE_CLASSES VARIABLE_SCOPE GLOBAL @@ -899,7 +908,7 @@ VARIABLE_COMMENT Maximum number of file instruments. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 256 -@@ -2654,7 +2654,7 @@ +@@ -2674,7 +2674,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_FILE_HANDLES VARIABLE_SCOPE GLOBAL @@ -908,7 +917,7 @@ VARIABLE_COMMENT Maximum number of opened instrumented files. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 1048576 -@@ -2664,7 +2664,7 @@ +@@ -2684,7 +2684,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_FILE_INSTANCES VARIABLE_SCOPE GLOBAL @@ -917,7 +926,7 @@ VARIABLE_COMMENT Maximum number of instrumented files. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2674,7 +2674,7 @@ +@@ -2694,7 +2694,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_INDEX_STAT VARIABLE_SCOPE GLOBAL @@ -926,7 +935,7 @@ VARIABLE_COMMENT Maximum number of index statistics for instrumented tables. Use 0 to disable, -1 for automated scaling. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2684,7 +2684,7 @@ +@@ -2704,7 +2704,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_MEMORY_CLASSES VARIABLE_SCOPE GLOBAL @@ -935,7 +944,7 @@ VARIABLE_COMMENT Maximum number of memory pool instruments. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 1024 -@@ -2694,7 +2694,7 @@ +@@ -2714,7 +2714,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_METADATA_LOCKS VARIABLE_SCOPE GLOBAL @@ -944,7 +953,7 @@ VARIABLE_COMMENT Maximum number of metadata locks. Use 0 to disable, -1 for automated scaling. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 104857600 -@@ -2704,7 +2704,7 @@ +@@ -2724,7 +2724,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_MUTEX_CLASSES VARIABLE_SCOPE GLOBAL @@ -953,7 +962,7 @@ VARIABLE_COMMENT Maximum number of mutex instruments. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 256 -@@ -2714,7 +2714,7 @@ +@@ -2734,7 +2734,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_MUTEX_INSTANCES VARIABLE_SCOPE GLOBAL @@ -962,7 +971,7 @@ VARIABLE_COMMENT Maximum number of instrumented MUTEX objects. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 104857600 -@@ -2724,7 +2724,7 @@ +@@ -2744,7 +2744,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_PREPARED_STATEMENTS_INSTANCES VARIABLE_SCOPE GLOBAL @@ -971,7 +980,7 @@ VARIABLE_COMMENT Maximum number of instrumented prepared statements. Use 0 to disable, -1 for automated scaling. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2734,7 +2734,7 @@ +@@ -2754,7 +2754,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_PROGRAM_INSTANCES VARIABLE_SCOPE GLOBAL @@ -980,7 +989,7 @@ VARIABLE_COMMENT Maximum number of instrumented programs. Use 0 to disable, -1 for automated scaling. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2744,7 +2744,7 @@ +@@ -2764,7 +2764,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_RWLOCK_CLASSES VARIABLE_SCOPE GLOBAL @@ -989,7 +998,7 @@ VARIABLE_COMMENT Maximum number of rwlock instruments. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 256 -@@ -2754,7 +2754,7 @@ +@@ -2774,7 +2774,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_RWLOCK_INSTANCES VARIABLE_SCOPE GLOBAL @@ -998,7 +1007,7 @@ VARIABLE_COMMENT Maximum number of instrumented RWLOCK objects. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 104857600 -@@ -2764,7 +2764,7 @@ +@@ -2784,7 +2784,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_SOCKET_CLASSES VARIABLE_SCOPE GLOBAL @@ -1007,7 +1016,7 @@ VARIABLE_COMMENT Maximum number of socket instruments. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 256 -@@ -2774,7 +2774,7 @@ +@@ -2794,7 +2794,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_SOCKET_INSTANCES VARIABLE_SCOPE GLOBAL @@ -1016,7 +1025,7 @@ VARIABLE_COMMENT Maximum number of opened instrumented sockets. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2784,7 +2784,7 @@ +@@ -2804,7 +2804,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_SQL_TEXT_LENGTH VARIABLE_SCOPE GLOBAL @@ -1025,7 +1034,7 @@ VARIABLE_COMMENT Maximum length of displayed sql text. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 1048576 -@@ -2794,7 +2794,7 @@ +@@ -2814,7 +2814,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_STAGE_CLASSES VARIABLE_SCOPE GLOBAL @@ -1034,7 +1043,7 @@ VARIABLE_COMMENT Maximum number of stage instruments. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 256 -@@ -2804,7 +2804,7 @@ +@@ -2824,7 +2824,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_STATEMENT_CLASSES VARIABLE_SCOPE GLOBAL @@ -1043,7 +1052,7 @@ VARIABLE_COMMENT Maximum number of statement instruments. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 256 -@@ -2814,7 +2814,7 @@ +@@ -2834,7 +2834,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_STATEMENT_STACK VARIABLE_SCOPE GLOBAL @@ -1052,7 +1061,7 @@ VARIABLE_COMMENT Number of rows per thread in EVENTS_STATEMENTS_CURRENT. NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 256 -@@ -2824,7 +2824,7 @@ +@@ -2844,7 +2844,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_TABLE_HANDLES VARIABLE_SCOPE GLOBAL @@ -1061,7 +1070,7 @@ VARIABLE_COMMENT Maximum number of opened instrumented tables. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2834,7 +2834,7 @@ +@@ -2854,7 +2854,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_TABLE_INSTANCES VARIABLE_SCOPE GLOBAL @@ -1070,7 +1079,7 @@ VARIABLE_COMMENT Maximum number of instrumented tables. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2844,7 +2844,7 @@ +@@ -2864,7 +2864,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_TABLE_LOCK_STAT VARIABLE_SCOPE GLOBAL @@ -1079,7 +1088,7 @@ VARIABLE_COMMENT Maximum number of lock statistics for instrumented tables. Use 0 to disable, -1 for automated scaling. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2854,7 +2854,7 @@ +@@ -2874,7 +2874,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_THREAD_CLASSES VARIABLE_SCOPE GLOBAL @@ -1088,7 +1097,7 @@ VARIABLE_COMMENT Maximum number of thread instruments. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 256 -@@ -2864,7 +2864,7 @@ +@@ -2884,7 +2884,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_THREAD_INSTANCES VARIABLE_SCOPE GLOBAL @@ -1097,7 +1106,7 @@ VARIABLE_COMMENT Maximum number of instrumented threads. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2874,7 +2874,7 @@ +@@ -2894,7 +2894,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_SESSION_CONNECT_ATTRS_SIZE VARIABLE_SCOPE GLOBAL @@ -1106,7 +1115,7 @@ VARIABLE_COMMENT Size of session attribute string buffer per thread. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2884,7 +2884,7 @@ +@@ -2904,7 +2904,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_SETUP_ACTORS_SIZE VARIABLE_SCOPE GLOBAL @@ -1115,7 +1124,7 @@ VARIABLE_COMMENT Maximum number of rows in SETUP_ACTORS. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1024 -@@ -2894,7 +2894,7 @@ +@@ -2914,7 +2914,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_SETUP_OBJECTS_SIZE VARIABLE_SCOPE GLOBAL @@ -1124,7 +1133,7 @@ VARIABLE_COMMENT Maximum number of rows in SETUP_OBJECTS. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2904,7 +2904,7 @@ +@@ -2924,7 +2924,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_USERS_SIZE VARIABLE_SCOPE GLOBAL @@ -1133,7 +1142,7 @@ VARIABLE_COMMENT Maximum number of instrumented users. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 NUMERIC_MAX_VALUE 1048576 -@@ -2954,7 +2954,7 @@ +@@ -2974,7 +2974,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PRELOAD_BUFFER_SIZE VARIABLE_SCOPE SESSION @@ -1142,7 +1151,7 @@ VARIABLE_COMMENT The size of the buffer that is allocated when preloading indexes NUMERIC_MIN_VALUE 1024 NUMERIC_MAX_VALUE 1073741824 -@@ -2974,7 +2974,7 @@ +@@ -2994,7 +2994,7 @@ COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME PROFILING_HISTORY_SIZE VARIABLE_SCOPE SESSION @@ -1151,7 +1160,7 @@ VARIABLE_COMMENT Number of statements about which profiling information is maintained. If set to 0, no profiles are stored. See SHOW PROFILES. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 100 -@@ -2984,7 +2984,7 @@ +@@ -3004,7 +3004,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PROGRESS_REPORT_TIME VARIABLE_SCOPE SESSION @@ -1160,7 +1169,7 @@ VARIABLE_COMMENT Seconds between sending progress reports to the client for time-consuming statements. Set to 0 to disable progress reporting. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 4294967295 -@@ -3044,7 +3044,7 @@ +@@ -3064,7 +3064,7 @@ COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME QUERY_ALLOC_BLOCK_SIZE VARIABLE_SCOPE SESSION @@ -1169,7 +1178,7 @@ VARIABLE_COMMENT Allocation block size for query parsing and execution NUMERIC_MIN_VALUE 1024 NUMERIC_MAX_VALUE 4294967295 -@@ -3054,7 +3054,7 @@ +@@ -3074,7 +3074,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME QUERY_CACHE_LIMIT VARIABLE_SCOPE GLOBAL @@ -1178,7 +1187,7 @@ VARIABLE_COMMENT Don't cache results that are bigger than this NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 4294967295 -@@ -3064,7 +3064,7 @@ +@@ -3084,7 +3084,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME QUERY_CACHE_MIN_RES_UNIT VARIABLE_SCOPE GLOBAL @@ -1187,7 +1196,7 @@ VARIABLE_COMMENT The minimum size for blocks allocated by the query cache NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 4294967295 -@@ -3077,7 +3077,7 @@ +@@ -3097,7 +3097,7 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT The memory allocated to store results from old queries NUMERIC_MIN_VALUE 0 @@ -1196,7 +1205,7 @@ NUMERIC_BLOCK_SIZE 1024 ENUM_VALUE_LIST NULL READ_ONLY NO -@@ -3114,7 +3114,7 @@ +@@ -3134,7 +3134,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME QUERY_PREALLOC_SIZE VARIABLE_SCOPE SESSION @@ -1205,7 +1214,7 @@ VARIABLE_COMMENT Persistent buffer for query parsing and execution NUMERIC_MIN_VALUE 1024 NUMERIC_MAX_VALUE 4294967295 -@@ -3127,7 +3127,7 @@ +@@ -3147,7 +3147,7 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Sets the internal state of the RAND() generator for replication purposes NUMERIC_MIN_VALUE 0 @@ -1214,7 +1223,7 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO -@@ -3137,14 +3137,14 @@ +@@ -3157,14 +3157,14 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Sets the internal state of the RAND() generator for replication purposes NUMERIC_MIN_VALUE 0 @@ -1231,7 +1240,7 @@ VARIABLE_COMMENT Allocation block size for storing ranges during optimization NUMERIC_MIN_VALUE 4096 NUMERIC_MAX_VALUE 4294967295 -@@ -3157,14 +3157,14 @@ +@@ -3177,14 +3177,14 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Maximum speed(KB/s) to read binlog from master (0 = no limit) NUMERIC_MIN_VALUE 0 @@ -1248,7 +1257,7 @@ VARIABLE_COMMENT Each thread that does a sequential scan allocates a buffer of this size for each table it scans. If you do many sequential scans, you may want to increase this value NUMERIC_MIN_VALUE 8192 NUMERIC_MAX_VALUE 2147483647 -@@ -3184,7 +3184,7 @@ +@@ -3204,7 +3204,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME READ_RND_BUFFER_SIZE VARIABLE_SCOPE SESSION @@ -1257,7 +1266,7 @@ VARIABLE_COMMENT When reading rows in sorted order after a sort, the rows are read through this buffer to avoid a disk seeks NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 2147483647 -@@ -3394,10 +3394,10 @@ +@@ -3414,10 +3414,10 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME ROWID_MERGE_BUFF_SIZE VARIABLE_SCOPE SESSION @@ -1270,7 +1279,7 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO -@@ -3414,20 +3414,20 @@ +@@ -3434,20 +3434,20 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME RPL_SEMI_SYNC_MASTER_TIMEOUT VARIABLE_SCOPE GLOBAL @@ -1295,7 +1304,7 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO -@@ -3484,10 +3484,10 @@ +@@ -3504,10 +3504,10 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME RPL_SEMI_SYNC_SLAVE_TRACE_LEVEL VARIABLE_SCOPE GLOBAL @@ -1308,7 +1317,7 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO -@@ -3524,7 +3524,7 @@ +@@ -3544,7 +3544,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME SERVER_ID VARIABLE_SCOPE SESSION @@ -1317,7 +1326,7 @@ VARIABLE_COMMENT Uniquely identifies the server instance in the community of replication partners NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 4294967295 -@@ -3654,7 +3654,7 @@ +@@ -3674,7 +3674,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME SLAVE_DOMAIN_PARALLEL_THREADS VARIABLE_SCOPE GLOBAL @@ -1326,7 +1335,7 @@ VARIABLE_COMMENT Maximum number of parallel threads to use on slave for events in a single replication domain. When using multiple domains, this can be used to limit a single domain from grabbing all threads and thus stalling other domains. The default of 0 means to allow a domain to grab as many threads as it wants, up to the value of slave_parallel_threads. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 16383 -@@ -3684,7 +3684,7 @@ +@@ -3704,7 +3704,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME SLAVE_MAX_ALLOWED_PACKET VARIABLE_SCOPE GLOBAL @@ -1335,7 +1344,7 @@ VARIABLE_COMMENT The maximum packet length to sent successfully from the master to slave. NUMERIC_MIN_VALUE 1024 NUMERIC_MAX_VALUE 1073741824 -@@ -3704,7 +3704,7 @@ +@@ -3724,7 +3724,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME SLAVE_PARALLEL_MAX_QUEUED VARIABLE_SCOPE GLOBAL @@ -1344,7 +1353,7 @@ VARIABLE_COMMENT Limit on how much memory SQL threads should use per parallel replication thread when reading ahead in the relay log looking for opportunities for parallel replication. Only used when --slave-parallel-threads > 0. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 2147483647 -@@ -3724,7 +3724,7 @@ +@@ -3744,7 +3744,7 @@ COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME SLAVE_PARALLEL_THREADS VARIABLE_SCOPE GLOBAL @@ -1353,7 +1362,7 @@ VARIABLE_COMMENT If non-zero, number of threads to spawn to apply in parallel events on the slave that were group-committed on the master or were logged with GTID in different replication domains. Note that these threads are in addition to the IO and SQL threads, which are always created by a replication slave NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 16383 -@@ -3734,7 +3734,7 @@ +@@ -3754,7 +3754,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME SLAVE_PARALLEL_WORKERS VARIABLE_SCOPE GLOBAL @@ -1362,7 +1371,7 @@ VARIABLE_COMMENT Alias for slave_parallel_threads NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 16383 -@@ -3774,7 +3774,7 @@ +@@ -3794,7 +3794,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME SLAVE_TRANSACTION_RETRIES VARIABLE_SCOPE GLOBAL @@ -1371,7 +1380,7 @@ VARIABLE_COMMENT Number of times the slave SQL thread will retry a transaction in case it failed with a deadlock, elapsed lock wait timeout or listed in slave_transaction_retry_errors, before giving up and stopping NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 4294967295 -@@ -3794,7 +3794,7 @@ +@@ -3814,7 +3814,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME SLAVE_TRANSACTION_RETRY_INTERVAL VARIABLE_SCOPE GLOBAL @@ -1380,7 +1389,7 @@ VARIABLE_COMMENT Interval of the slave SQL thread will retry a transaction in case it failed with a deadlock or elapsed lock wait timeout or listed in slave_transaction_retry_errors NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 3600 -@@ -3814,7 +3814,7 @@ +@@ -3834,7 +3834,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME SLOW_LAUNCH_TIME VARIABLE_SCOPE GLOBAL @@ -1389,7 +1398,7 @@ VARIABLE_COMMENT If creating the thread takes longer than this value (in seconds), the Slow_launch_threads counter will be incremented NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 31536000 -@@ -3857,7 +3857,7 @@ +@@ -3877,7 +3877,7 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Each thread that needs to do a sort allocates a buffer of this size NUMERIC_MIN_VALUE 1024 @@ -1398,7 +1407,7 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO -@@ -4084,7 +4084,7 @@ +@@ -4104,7 +4104,7 @@ COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME STORED_PROGRAM_CACHE VARIABLE_SCOPE GLOBAL @@ -1407,7 +1416,7 @@ VARIABLE_COMMENT The soft upper limit for number of cached stored routines for one connection. NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 524288 -@@ -4184,7 +4184,7 @@ +@@ -4204,7 +4204,7 @@ COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME TABLE_DEFINITION_CACHE VARIABLE_SCOPE GLOBAL @@ -1416,7 +1425,7 @@ VARIABLE_COMMENT The number of cached table definitions NUMERIC_MIN_VALUE 400 NUMERIC_MAX_VALUE 2097152 -@@ -4194,7 +4194,7 @@ +@@ -4214,7 +4214,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME TABLE_OPEN_CACHE VARIABLE_SCOPE GLOBAL @@ -1425,7 +1434,7 @@ VARIABLE_COMMENT The number of cached open tables NUMERIC_MIN_VALUE 10 NUMERIC_MAX_VALUE 1048576 -@@ -4254,7 +4254,7 @@ +@@ -4274,7 +4274,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME THREAD_CACHE_SIZE VARIABLE_SCOPE GLOBAL @@ -1434,7 +1443,7 @@ VARIABLE_COMMENT How many threads we should keep in a cache for reuse. These are freed after 5 minutes of idle time NUMERIC_MIN_VALUE 0 NUMERIC_MAX_VALUE 16384 -@@ -4427,7 +4427,7 @@ +@@ -4447,7 +4447,7 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Max size for data for an internal temporary on-disk MyISAM or Aria table. NUMERIC_MIN_VALUE 1024 @@ -1443,7 +1452,7 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO -@@ -4437,7 +4437,7 @@ +@@ -4457,7 +4457,7 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT If an internal in-memory temporary table exceeds this size, MariaDB will automatically convert it to an on-disk MyISAM or Aria table. Same as tmp_table_size. NUMERIC_MIN_VALUE 0 @@ -1452,7 +1461,7 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO -@@ -4447,14 +4447,14 @@ +@@ -4467,14 +4467,14 @@ VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Alias for tmp_memory_table_size. If an internal in-memory temporary table exceeds this size, MariaDB will automatically convert it to an on-disk MyISAM or Aria table. NUMERIC_MIN_VALUE 0 @@ -1469,7 +1478,7 @@ VARIABLE_COMMENT Allocation block size for transactions to be stored in binary log NUMERIC_MIN_VALUE 1024 NUMERIC_MAX_VALUE 134217728 -@@ -4464,7 +4464,7 @@ +@@ -4484,7 +4484,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME TRANSACTION_PREALLOC_SIZE VARIABLE_SCOPE SESSION @@ -1478,7 +1487,7 @@ VARIABLE_COMMENT Persistent buffer for transactions to be stored in binary log NUMERIC_MIN_VALUE 1024 NUMERIC_MAX_VALUE 134217728 -@@ -4604,7 +4604,7 @@ +@@ -4624,7 +4624,7 @@ COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME WAIT_TIMEOUT VARIABLE_SCOPE SESSION @@ -1487,7 +1496,7 @@ VARIABLE_COMMENT The number of seconds the server waits for activity on a connection before closing it NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 31536000 -@@ -4631,7 +4631,7 @@ +@@ -4651,7 +4651,7 @@ VARIABLE_NAME LOG_TC_SIZE GLOBAL_VALUE_ORIGIN AUTO VARIABLE_SCOPE GLOBAL diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index 72c3659f2b6..0def58e186b 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -1825,13 +1825,23 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME LOG_SLOW_FILTER VARIABLE_SCOPE SESSION VARIABLE_TYPE SET -VARIABLE_COMMENT Log only certain types of queries to the slow log. If variable empty alll kind of queries are logged. All types are bound by slow_query_time, except 'not_using_index' which is always logged if enabled +VARIABLE_COMMENT Log only certain types of queries to the slow log. If variable empty all kind of queries are logged. All types are bound by slow_query_time, except 'not_using_index' which is always logged if enabled NUMERIC_MIN_VALUE NULL NUMERIC_MAX_VALUE NULL NUMERIC_BLOCK_SIZE NULL ENUM_VALUE_LIST admin,filesort,filesort_on_disk,filesort_priority_queue,full_join,full_scan,not_using_index,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME LOG_SLOW_MAX_WARNINGS +VARIABLE_SCOPE SESSION +VARIABLE_TYPE BIGINT UNSIGNED +VARIABLE_COMMENT Max numbers of warnings printed to slow query log per statement +NUMERIC_MIN_VALUE 0 +NUMERIC_MAX_VALUE 1000 +NUMERIC_BLOCK_SIZE 1 +ENUM_VALUE_LIST NULL +READ_ONLY NO +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME LOG_SLOW_RATE_LIMIT VARIABLE_SCOPE SESSION VARIABLE_TYPE BIGINT UNSIGNED @@ -1859,7 +1869,7 @@ VARIABLE_COMMENT Verbosity level for the slow log NUMERIC_MIN_VALUE NULL NUMERIC_MAX_VALUE NULL NUMERIC_BLOCK_SIZE NULL -ENUM_VALUE_LIST innodb,query_plan,explain,engine,full +ENUM_VALUE_LIST innodb,query_plan,explain,engine,warnings,full READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME LOG_WARNINGS @@ -2362,6 +2372,16 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME NOTE_VERBOSITY +VARIABLE_SCOPE SESSION +VARIABLE_TYPE SET +VARIABLE_COMMENT Verbosity level for note-warnings given to the user. See also @@sql_notes. +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST basic,unusable_keys,explain +READ_ONLY NO +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME OLD VARIABLE_SCOPE SESSION VARIABLE_TYPE BOOLEAN @@ -3935,7 +3955,7 @@ COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME SQL_NOTES VARIABLE_SCOPE SESSION VARIABLE_TYPE BOOLEAN -VARIABLE_COMMENT If set to 1, the default, warning_count is incremented each time a Note warning is encountered. If set to 0, Note warnings are not recorded. mysqldump has outputs to set this variable to 0 so that no unnecessary increments occur when data is reloaded. +VARIABLE_COMMENT If set to 1, the default, warning_count is incremented each time a Note warning is encountered. If set to 0, Note warnings are not recorded. mysqldump has outputs to set this variable to 0 so that no unnecessary increments occur when data is reloaded. See also note_verbosity, which allows one to define with notes are sent. NUMERIC_MIN_VALUE NULL NUMERIC_MAX_VALUE NULL NUMERIC_BLOCK_SIZE NULL diff --git a/mysql-test/suite/sys_vars/t/log_slow_verbosity_basic.test b/mysql-test/suite/sys_vars/t/log_slow_verbosity_basic.test index d3ed1a9465b..3e27f25b63c 100644 --- a/mysql-test/suite/sys_vars/t/log_slow_verbosity_basic.test +++ b/mysql-test/suite/sys_vars/t/log_slow_verbosity_basic.test @@ -37,6 +37,12 @@ set session log_slow_verbosity=6; select @@session.log_slow_verbosity; set session log_slow_verbosity=7; select @@session.log_slow_verbosity; +set session log_slow_verbosity=8; +select @@session.log_slow_verbosity; +set session log_slow_verbosity=16; +select @@session.log_slow_verbosity; +set session log_slow_verbosity=32; +select @@session.log_slow_verbosity; set session log_slow_verbosity='innodb'; @@ -47,7 +53,7 @@ set session log_slow_verbosity='innodb,query_plan'; select @@session.log_slow_verbosity; set session log_slow_verbosity='explain'; select @@session.log_slow_verbosity; -set session log_slow_verbosity='innodb,query_plan,explain,engine,full'; +set session log_slow_verbosity='innodb,query_plan,explain,engine,warnings,full'; select @@session.log_slow_verbosity; set session log_slow_verbosity=''; select @@session.log_slow_verbosity; @@ -62,6 +68,6 @@ set session log_slow_verbosity=1e1; --error ER_WRONG_VALUE_FOR_VAR set session log_slow_verbosity="foo"; --error ER_WRONG_VALUE_FOR_VAR -set session log_slow_verbosity=32; +set session log_slow_verbosity=64; SET @@global.log_slow_verbosity = @start_global_value; diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 2b3e774f01a..235b8ce48b9 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -798,15 +798,21 @@ static int setval(const struct my_option *opts, void *value, char *argument, *((ulonglong*)value)= find_typeset(argument, opts->typelib, &err); if (err) { - /* Accept an integer representation of the set */ - char *endptr; - ulonglong arg= (ulonglong) strtol(argument, &endptr, 10); - if (*endptr || (arg >> 1) >= (1ULL << (opts->typelib->count-1))) + /* Check if option 'all' is used (to set all bits) */ + if (!my_strcasecmp(&my_charset_latin1, argument, "all")) + *(ulonglong*) value= ((1ULL << opts->typelib->count) - 1); + else { - res= EXIT_ARGUMENT_INVALID; - goto ret; - }; - *(ulonglong*)value= arg; + /* Accept an integer representation of the set */ + char *endptr; + ulonglong arg= (ulonglong) strtol(argument, &endptr, 10); + if (*endptr || (arg >> 1) >= (1ULL << (opts->typelib->count-1))) + { + res= EXIT_ARGUMENT_INVALID; + goto ret; + }; + *(ulonglong*)value= arg; + } err= 0; } break; @@ -1602,6 +1608,8 @@ void my_print_help(const struct my_option *options) printf(" to disable.)\n"); } } + else if ((optp->var_type & GET_TYPE_MASK) == GET_SET) + printf(" Use 'ALL' to set all combinations.\n"); } DBUG_VOID_RETURN; } diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_myisam.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_myisam.result index c2577ef44df..da67e05a163 100644 --- a/plugin/type_inet/mysql-test/type_inet/type_inet6_myisam.result +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_myisam.result @@ -105,6 +105,8 @@ c EXPLAIN SELECT * FROM t1 WHERE c=CAST('::1' AS INET6); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index c c 67 NULL 3 Using where; Using index +Warnings: +Note 1105 Cannot use key `c` part[0] for lookup: `test`.`t1`.`c` of type `varchar` = "cast('::1' as inet6)" of type `inet6` DROP TABLE t1; # # End of 10.5 tests diff --git a/sql/field.cc b/sql/field.cc index 3d11d0b878f..9498b874900 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1294,37 +1294,46 @@ bool Field::cmp_is_done_using_type_handler_of_this(const Item_bool_func *cond, /* This handles all numeric and BIT data types. */ -bool Field::can_optimize_keypart_ref(const Item_bool_func *cond, - const Item *item) const +Data_type_compatibility +Field::can_optimize_keypart_ref(const Item_bool_func *cond, + const Item *item) const { DBUG_ASSERT(cmp_type() != STRING_RESULT); DBUG_ASSERT(cmp_type() != TIME_RESULT); - return item->cmp_type() != TIME_RESULT; + return item->cmp_type() != TIME_RESULT ? + Data_type_compatibility::OK : + Data_type_compatibility::INCOMPATIBLE_DATA_TYPE; } /* This handles all numeric and BIT data types. */ -bool Field::can_optimize_group_min_max(const Item_bool_func *cond, - const Item *const_item) const +Data_type_compatibility +Field::can_optimize_group_min_max(const Item_bool_func *cond, + const Item *const_item) const { DBUG_ASSERT(cmp_type() != STRING_RESULT); DBUG_ASSERT(cmp_type() != TIME_RESULT); - return const_item->cmp_type() != TIME_RESULT; + return const_item->cmp_type() != TIME_RESULT ? + Data_type_compatibility::OK : + Data_type_compatibility::INCOMPATIBLE_DATA_TYPE; } /* This covers all numeric types, BIT */ -bool Field::can_optimize_range(const Item_bool_func *cond, - const Item *item, - bool is_eq_func) const +Data_type_compatibility +Field::can_optimize_range(const Item_bool_func *cond, + const Item *item, + bool is_eq_func) const { DBUG_ASSERT(cmp_type() != TIME_RESULT); // Handled in Field_temporal DBUG_ASSERT(cmp_type() != STRING_RESULT); // Handled in Field_str descendants - return item->cmp_type() != TIME_RESULT; + return item->cmp_type() != TIME_RESULT ? + Data_type_compatibility::OK : + Data_type_compatibility::INCOMPATIBLE_DATA_TYPE; } @@ -5913,17 +5922,21 @@ my_decimal *Field_temporal::val_decimal(my_decimal *d) } -bool Field_temporal::can_optimize_keypart_ref(const Item_bool_func *cond, - const Item *value) const +Data_type_compatibility +Field_temporal::can_optimize_keypart_ref(const Item_bool_func *cond, + const Item *value) const { - return true; // Field is of TIME_RESULT, which supersedes everything else. + // Field is of TIME_RESULT, which supersedes everything else. + return Data_type_compatibility::OK; } -bool Field_temporal::can_optimize_group_min_max(const Item_bool_func *cond, - const Item *const_item) const +Data_type_compatibility +Field_temporal::can_optimize_group_min_max(const Item_bool_func *cond, + const Item *const_item) const { - return true; // Field is of TIME_RESULT, which supersedes everything else. + // Field is of TIME_RESULT, which supersedes everything else. + return Data_type_compatibility::OK; } @@ -7418,43 +7431,52 @@ uint32 Field_longstr::max_data_length() const } -bool +Data_type_compatibility Field_longstr::cmp_to_string_with_same_collation(const Item_bool_func *cond, const Item *item) const { - return cmp_is_done_using_type_handler_of_this(cond, item) && - charset() == cond->compare_collation(); + return !cmp_is_done_using_type_handler_of_this(cond, item) ? + Data_type_compatibility::INCOMPATIBLE_DATA_TYPE : + charset() != cond->compare_collation() ? + Data_type_compatibility::INCOMPATIBLE_COLLATION : + Data_type_compatibility::OK; } -bool +Data_type_compatibility Field_longstr::cmp_to_string_with_stricter_collation(const Item_bool_func *cond, const Item *item) const { - return cmp_is_done_using_type_handler_of_this(cond, item) && - (charset() == cond->compare_collation() || - cond->compare_collation()->state & MY_CS_BINSORT); + return !cmp_is_done_using_type_handler_of_this(cond, item) ? + Data_type_compatibility::INCOMPATIBLE_DATA_TYPE : + (charset() != cond->compare_collation() && + !(cond->compare_collation()->state & MY_CS_BINSORT)) ? + Data_type_compatibility::INCOMPATIBLE_COLLATION : + Data_type_compatibility::OK; } -bool Field_longstr::can_optimize_keypart_ref(const Item_bool_func *cond, - const Item *item) const +Data_type_compatibility +Field_longstr::can_optimize_keypart_ref(const Item_bool_func *cond, + const Item *item) const { DBUG_ASSERT(cmp_type() == STRING_RESULT); return cmp_to_string_with_stricter_collation(cond, item); } -bool Field_longstr::can_optimize_hash_join(const Item_bool_func *cond, - const Item *item) const +Data_type_compatibility +Field_longstr::can_optimize_hash_join(const Item_bool_func *cond, + const Item *item) const { DBUG_ASSERT(cmp_type() == STRING_RESULT); return cmp_to_string_with_same_collation(cond, item); } -bool Field_longstr::can_optimize_group_min_max(const Item_bool_func *cond, - const Item *const_item) const +Data_type_compatibility +Field_longstr::can_optimize_group_min_max(const Item_bool_func *cond, + const Item *const_item) const { /* Can't use indexes when comparing a string to a number or a date @@ -7465,9 +7487,10 @@ bool Field_longstr::can_optimize_group_min_max(const Item_bool_func *cond, } -bool Field_longstr::can_optimize_range(const Item_bool_func *cond, - const Item *item, - bool is_eq_func) const +Data_type_compatibility +Field_longstr::can_optimize_range(const Item_bool_func *cond, + const Item *item, + bool is_eq_func) const { return is_eq_func ? cmp_to_string_with_stricter_collation(cond, item) : @@ -9687,24 +9710,27 @@ bool Field_num::is_equal(const Column_definition &new_field) const } -bool Field_enum::can_optimize_range_or_keypart_ref(const Item_bool_func *cond, - const Item *item) const +Data_type_compatibility +Field_enum::can_optimize_range_or_keypart_ref(const Item_bool_func *cond, + const Item *item) const { switch (item->cmp_type()) { case TIME_RESULT: - return false; + return Data_type_compatibility::INCOMPATIBLE_DATA_TYPE; case INT_RESULT: case DECIMAL_RESULT: case REAL_RESULT: - return true; + return Data_type_compatibility::OK; case STRING_RESULT: - return charset() == cond->compare_collation(); + return charset() == cond->compare_collation() ? + Data_type_compatibility::OK : + Data_type_compatibility::INCOMPATIBLE_COLLATION; case ROW_RESULT: DBUG_ASSERT(0); break; } - return false; + return Data_type_compatibility::INCOMPATIBLE_DATA_TYPE; } @@ -11233,6 +11259,102 @@ void Field::set_warning_truncated_wrong_value(const char *type_arg, } +/* + Give warning for unusable key + + Note that the caller is responsible to call it only under ther + right note_verbosity level +*/ + +void Field::raise_note_cannot_use_key_part(THD *thd, + uint keynr, uint part, + const LEX_CSTRING &op, + Item *value, + Data_type_compatibility reason) + const +{ + StringBuffer<128> value_buffer; + const LEX_CSTRING keyname= table->s->key_info[keynr].name; + size_t value_length; + + value->print(&value_buffer, QT_EXPLAIN); + value_length= Well_formed_prefix(value_buffer.charset(), + value_buffer.ptr(), + MY_MIN(value_buffer.length(), 64)).length(); + /* + We must use c_ptr() here for the 'T' argument as it only works with + zero terminated strings. + */ + switch (reason){ + case Data_type_compatibility::INCOMPATIBLE_COLLATION: + { + const LEX_CSTRING colf(charset()->coll_name); + const LEX_CSTRING colv(value->collation.collation->coll_name); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, + ER_UNKNOWN_ERROR, + "Cannot use key %`.*s part[%u] for lookup: " + "%`.*s.%`.*s.%`.*s of collation %`.*s " + "%.*s \"%.*T\" of collation %`.*s", + (int) keyname.length, keyname.str, + part, + (int) table->s->db.length, table->s->db.str, + (int) table->s->table_name.length, + table->s->table_name.str, + (int) field_name.length, field_name.str, + (int) colf.length, colf.str, + (int) op.length, op.str, + (int) value_length, value_buffer.c_ptr_safe(), + (int) colv.length, colv.str); + } + break; + case Data_type_compatibility::OK: + DBUG_ASSERT(0); + /* fall through */ + case Data_type_compatibility::INCOMPATIBLE_DATA_TYPE: + { + const LEX_CSTRING dtypef(type_handler()->name().lex_cstring()); + const LEX_CSTRING dtypev(value->type_handler()->name().lex_cstring()); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, + ER_UNKNOWN_ERROR, + "Cannot use key %`.*s part[%u] for lookup: " + "%`.*s.%`.*s.%`.*s of type %`.*s " + "%.*s \"%.*T\" of type %`.*s", + (int) keyname.length, keyname.str, + part, + (int) table->s->db.length, table->s->db.str, + (int) table->s->table_name.length, + table->s->table_name.str, + (int) field_name.length, field_name.str, + (int) dtypef.length, dtypef.str, + (int) op.length, op.str, + (int) value_length, value_buffer.c_ptr_safe(), + (int) dtypev.length, dtypev.str); + } + break; + } +} + + +/* + Give warning for unusable key + + Note that the caller is responsible to call it only under ther + right note_verbosity level +*/ + +void Field::raise_note_key_become_unused(THD *thd, const String &expr) const +{ + push_warning_printf(thd, + Sql_condition::WARN_LEVEL_NOTE, ER_UNKNOWN_ERROR, + "Cannot use key parts with %`.*s.%`.*s.%`.*s " + "in the rewritten condition: %`.*s", + (int) table->s->db.length, table->s->db.str, + (int) table->s->table_name.length, table->s->table_name.str, + (int) field_name.length, field_name.str, + (int) expr.length(), expr.ptr()); +} + + /* @brief Return possible keys for a field diff --git a/sql/field.h b/sql/field.h index e4e88408f8a..82d85e12ca4 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1640,6 +1640,12 @@ public: virtual void print_key_value(String *out, uint32 length); void print_key_part_value(String *out, const uchar *key, uint32 length); void print_key_value_binary(String *out, const uchar* key, uint32 length); + void raise_note_cannot_use_key_part(THD *thd, uint keynr, uint part, + const LEX_CSTRING &op, + Item *value, + const Data_type_compatibility reason) + const; + void raise_note_key_become_unused(THD *thd, const String &expr) const; protected: bool set_warning(unsigned int code, int cuted_increment) const { @@ -1668,11 +1674,12 @@ protected: Copy_func *get_identical_copy_func() const; bool cmp_is_done_using_type_handler_of_this(const Item_bool_func *cond, const Item *item) const; - bool can_optimize_scalar_range(const RANGE_OPT_PARAM *param, + Data_type_compatibility can_optimize_scalar_range( + const RANGE_OPT_PARAM *param, const KEY_PART *key_part, const Item_bool_func *cond, scalar_comparison_op op, - const Item *value) const; + Item *value) const; uchar *make_key_image(MEM_ROOT *mem_root, const KEY_PART *key_part); SEL_ARG *get_mm_leaf_int(RANGE_OPT_PARAM *param, KEY_PART *key_part, const Item_bool_func *cond, @@ -1893,29 +1900,33 @@ public: { return const_item; } - virtual bool can_optimize_keypart_ref(const Item_bool_func *cond, + virtual Data_type_compatibility can_optimize_keypart_ref( + const Item_bool_func *cond, const Item *item) const; - virtual bool can_optimize_hash_join(const Item_bool_func *cond, + virtual Data_type_compatibility can_optimize_hash_join( + const Item_bool_func *cond, const Item *item) const { return can_optimize_keypart_ref(cond, item); } - virtual bool can_optimize_group_min_max(const Item_bool_func *cond, + virtual Data_type_compatibility can_optimize_group_min_max( + const Item_bool_func *cond, const Item *const_item) const; /** Test if Field can use range optimizer for a standard comparison operation: <=, <, =, <=>, >, >= Note, this method does not cover spatial operations. */ - virtual bool can_optimize_range(const Item_bool_func *cond, - const Item *item, - bool is_eq_func) const; + virtual Data_type_compatibility can_optimize_range(const Item_bool_func *cond, + const Item *item, + bool is_eq_func) const; virtual SEL_ARG *get_mm_leaf(RANGE_OPT_PARAM *param, KEY_PART *key_part, const Item_bool_func *cond, scalar_comparison_op op, Item *value)= 0; - bool can_optimize_outer_join_table_elimination(const Item_bool_func *cond, + Data_type_compatibility can_optimize_outer_join_table_elimination( + const Item_bool_func *cond, const Item *item) const { // Exactly the same rules with REF access @@ -2199,9 +2210,11 @@ protected: return check_conversion_status(&copier, from + from_length, from_cs, count_spaces); } - bool cmp_to_string_with_same_collation(const Item_bool_func *cond, + Data_type_compatibility cmp_to_string_with_same_collation( + const Item_bool_func *cond, const Item *item) const; - bool cmp_to_string_with_stricter_collation(const Item_bool_func *cond, + Data_type_compatibility cmp_to_string_with_stricter_collation( + const Item_bool_func *cond, const Item *item) const; int compress(char *to, uint to_length, const char *from, uint length, @@ -2233,15 +2246,18 @@ public: } bool match_collation_to_optimize_range() const { return true; } - bool can_optimize_keypart_ref(const Item_bool_func *cond, - const Item *item) const override; - bool can_optimize_hash_join(const Item_bool_func *cond, - const Item *item) const override; - bool can_optimize_group_min_max(const Item_bool_func *cond, - const Item *const_item) const override; - bool can_optimize_range(const Item_bool_func *cond, - const Item *item, - bool is_eq_func) const override; + Data_type_compatibility can_optimize_keypart_ref(const Item_bool_func *cond, + const Item *item) + const override; + Data_type_compatibility can_optimize_hash_join(const Item_bool_func *cond, + const Item *item) + const override; + Data_type_compatibility can_optimize_group_min_max(const Item_bool_func *cond, + const Item *const_item) + const override; + Data_type_compatibility can_optimize_range(const Item_bool_func *cond, + const Item *item, + bool is_eq_func) const override; bool is_packable() const override { return true; } uint make_packed_sort_key_part(uchar *buff, const SORT_FIELD_ATTR *sort_field)override; @@ -2822,21 +2838,24 @@ public: return get_date(ltime, fuzzydate, (ulonglong) val_int()); } bool test_if_equality_guarantees_uniqueness(const Item *item) const override; - bool can_optimize_keypart_ref(const Item_bool_func *, const Item *) + Data_type_compatibility can_optimize_keypart_ref(const Item_bool_func *, + const Item *) const override { - return true; + return Data_type_compatibility::OK; } - bool can_optimize_group_min_max(const Item_bool_func *, const Item *) + Data_type_compatibility can_optimize_group_min_max(const Item_bool_func *, + const Item *) const override { - return true; + return Data_type_compatibility::OK; } - bool can_optimize_range(const Item_bool_func *, const Item *, bool) + Data_type_compatibility can_optimize_range(const Item_bool_func *, + const Item *, bool is_eq_func) const override { - return true; + return Data_type_compatibility::OK; } /* cmp_type() cannot be TIME_RESULT, because we want to compare this field against integers. But in all other cases we treat it as TIME_RESULT! */ @@ -2999,15 +3018,17 @@ public: uint size_of() const override final { return sizeof *this; } uint32 max_display_length() const override final { return 4; } void move_field_offset(my_ptrdiff_t ptr_diff) override final {} - bool can_optimize_keypart_ref(const Item_bool_func *cond, - const Item *item) const override final + Data_type_compatibility can_optimize_keypart_ref(const Item_bool_func *cond, + const Item *item) + const override final { - return false; + return Data_type_compatibility::INCOMPATIBLE_DATA_TYPE; } - bool can_optimize_group_min_max(const Item_bool_func *cond, - const Item *const_item) const override final + Data_type_compatibility can_optimize_group_min_max(const Item_bool_func *cond, + const Item *const_item) + const override final { - return false; + return Data_type_compatibility::INCOMPATIBLE_DATA_TYPE; } }; @@ -3106,15 +3127,17 @@ public: { return pos_in_interval_val_real(min, max); } - bool can_optimize_keypart_ref(const Item_bool_func *cond, - const Item *item) const override; - bool can_optimize_group_min_max(const Item_bool_func *cond, - const Item *const_item) const override; - bool can_optimize_range(const Item_bool_func *cond, - const Item *item, - bool is_eq_func) const override + Data_type_compatibility can_optimize_keypart_ref(const Item_bool_func *cond, + const Item *item) + const override; + Data_type_compatibility can_optimize_group_min_max(const Item_bool_func *cond, + const Item *const_item) + const override; + Data_type_compatibility can_optimize_range(const Item_bool_func *cond, + const Item *item, + bool is_eq_func) const override { - return true; + return Data_type_compatibility::OK; } SEL_ARG *get_mm_leaf(RANGE_OPT_PARAM *param, KEY_PART *key_part, const Item_bool_func *cond, @@ -4721,7 +4744,8 @@ private: class Field_enum :public Field_str { static void do_field_enum(Copy_field *copy_field); longlong val_int(const uchar *) const; - bool can_optimize_range_or_keypart_ref(const Item_bool_func *cond, + Data_type_compatibility can_optimize_range_or_keypart_ref( + const Item_bool_func *cond, const Item *item) const; protected: uint packlength; @@ -4814,13 +4838,15 @@ public: const uchar *unpack(uchar *to, const uchar *from, const uchar *from_end, uint param_data) override; - bool can_optimize_keypart_ref(const Item_bool_func *cond, - const Item *item) const override + Data_type_compatibility can_optimize_keypart_ref(const Item_bool_func *cond, + const Item *item) + const override { return can_optimize_range_or_keypart_ref(cond, item); } - bool can_optimize_group_min_max(const Item_bool_func *cond, - const Item *const_item) const override + Data_type_compatibility can_optimize_group_min_max(const Item_bool_func *cond, + const Item *const_item) + const override { /* Can't use GROUP_MIN_MAX optimization for ENUM and SET, @@ -4829,11 +4855,11 @@ public: It would return the records with min and max enum numeric indexes. "Bug#45300 MAX() and ENUM type" should be fixed first. */ - return false; + return Data_type_compatibility::INCOMPATIBLE_DATA_TYPE; } - bool can_optimize_range(const Item_bool_func *cond, - const Item *item, - bool is_eq_func) const override + Data_type_compatibility can_optimize_range(const Item_bool_func *cond, + const Item *item, + bool is_eq_func) const override { return can_optimize_range_or_keypart_ref(cond, item); } diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 0a9227933c5..0ea012f82b2 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -411,6 +411,51 @@ void Item_func::convert_const_compared_to_int_field(THD *thd) } +/* + Iterate through arguments and compare them to the original arguments + in "old_args". If some argument was replaced: + - from Item_field pointing to an indexed Field + - to something else (for example, Item_func_conv_charset) + then we cannot use Field's indexes for range access any more. + Raise a note in this case. + + Note, the number of arguments in "old_args" can be smaller than arg_count. + For example, for LIKE, BETWEEN, IN we pass only args[0] in old_args. + + For a comparison predicate we pass both args[0] and args[1] to cover both: + - WHERE field=expr + - WHERE expr=field +*/ + +void Item_bool_func::raise_note_if_key_become_unused(THD *thd, const Item_args &old_args) +{ + if (!(thd->variables.note_verbosity & NOTE_VERBOSITY_UNUSABLE_KEYS)) + return; + + DBUG_ASSERT(old_args.argument_count() <= arg_count); + for (uint i= 0; i < old_args.argument_count(); i++) + { + if (args[i] != old_args.arguments()[i]) + { + DBUG_ASSERT(old_args.arguments()[i]->fixed()); + Item *real_item= old_args.arguments()[i]->real_item(); + if (real_item->type() == Item::FIELD_ITEM) + { + Field *field= static_cast(real_item)->field; + if (field->flags & PART_KEY_FLAG) + { + /* + It used to be Item_field (with indexes!) before the condition + rewrite. Now it's something else. Cannot use indexes any more. + */ + field->raise_note_key_become_unused(thd, Print(this, QT_EXPLAIN)); + } + } + } + } +} + + bool Item_func::setup_args_and_comparator(THD *thd, Arg_comparator *cmp) { DBUG_ASSERT(arg_count >= 2); // Item_func_nullif has arg_count == 3 @@ -450,6 +495,7 @@ Item_bool_rowready_func2::value_depends_on_sql_mode() const bool Item_bool_rowready_func2::fix_length_and_dec() { + THD *thd= current_thd; max_length= 1; // Function returns 0 or 1 /* @@ -458,7 +504,11 @@ bool Item_bool_rowready_func2::fix_length_and_dec() */ if (!args[0] || !args[1]) return FALSE; - return setup_args_and_comparator(current_thd, &cmp); + Item_args old_args(args[0], args[1]); + if (setup_args_and_comparator(thd, &cmp)) + return true; + raise_note_if_key_become_unused(thd, old_args); + return false; } @@ -2125,6 +2175,7 @@ void Item_func_between::fix_after_pullout(st_select_lex *new_parent, bool Item_func_between::fix_length_and_dec() { max_length= 1; + THD *thd= current_thd; /* As some compare functions are generated after sql_yacc, @@ -2132,16 +2183,18 @@ bool Item_func_between::fix_length_and_dec() */ if (!args[0] || !args[1] || !args[2]) return TRUE; + Item_args old_predicant(args[0]); if (m_comparator.aggregate_for_comparison(Item_func_between:: func_name_cstring(), args, 3, false)) { - DBUG_ASSERT(current_thd->is_error()); + DBUG_ASSERT(thd->is_error()); return TRUE; } - - return m_comparator.type_handler()-> - Item_func_between_fix_length_and_dec(this); + if (m_comparator.type_handler()->Item_func_between_fix_length_and_dec(this)) + return true; + raise_note_if_key_become_unused(thd, old_predicant); + return false; } @@ -4475,6 +4528,7 @@ bool Item_func_in::prepare_predicant_and_values(THD *thd, uint *found_types) bool Item_func_in::fix_length_and_dec() { + Item_args old_predicant(args[0]); THD *thd= current_thd; uint found_types; m_comparator.set_handler(type_handler_varchar.type_handler_for_comparison()); @@ -4531,7 +4585,7 @@ bool Item_func_in::fix_length_and_dec() else { DBUG_ASSERT(m_comparator.cmp_type() != ROW_RESULT); - if ( fix_for_scalar_comparison_using_cmp_items(thd, found_types)) + if (fix_for_scalar_comparison_using_cmp_items(thd, found_types)) return TRUE; } @@ -4540,6 +4594,7 @@ bool Item_func_in::fix_length_and_dec() ER_UNKNOWN_ERROR, "DBUG: types_compatible=%s bisect=%s", arg_types_compatible ? "yes" : "no", array != NULL ? "yes" : "no");); + raise_note_if_key_become_unused(thd, old_predicant); return FALSE; } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index c2aed9ce9f4..ae0efdd6ae1 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -215,6 +215,7 @@ protected: virtual SEL_ARG *get_mm_leaf(RANGE_OPT_PARAM *param, Field *field, KEY_PART *key_part, Item_func::Functype type, Item *value); + void raise_note_if_key_become_unused(THD *thd, const Item_args &old_args); public: Item_bool_func(THD *thd): Item_int_func(thd) {} Item_bool_func(THD *thd, Item *a): Item_int_func(thd, a) {} @@ -2976,7 +2977,11 @@ public: bool fix_length_and_dec() override { max_length= 1; - return agg_arg_charsets_for_comparison(cmp_collation, args, 2); + Item_args old_predicant(args[0]); + if (agg_arg_charsets_for_comparison(cmp_collation, args, 2)) + return true; + raise_note_if_key_become_unused(current_thd, old_predicant); + return false; } void cleanup() override; diff --git a/sql/log.cc b/sql/log.cc index a49b4b2c0fa..eef8d86e4da 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -3320,6 +3320,23 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time, goto err; thd->free_items(); } + if ((log_slow_verbosity & LOG_SLOW_VERBOSITY_WARNINGS) && + thd->get_stmt_da()->unsafe_statement_warn_count()) + { + Diagnostics_area::Sql_condition_iterator it= + thd->get_stmt_da()->sql_conditions(); + ulong idx, max_warnings= thd->variables.log_slow_max_warnings; + const Sql_condition *err; + my_b_printf(&log_file, "# Warnings\n"); + for (idx= 0; (err= it++) && idx < max_warnings; idx++) + { + my_b_printf(&log_file, "# %-15s %4u %.*s\n", + warning_level_names[err->get_level()].str, + (uint) err->get_sql_errno(), + (int) err->get_message_octet_length(), + err->get_message_text()); + } + } if (thd->db.str && strcmp(thd->db.str, db)) { // Database changed if (my_b_printf(&log_file,"use %s;\n",thd->db.str)) @@ -3344,7 +3361,6 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time, end, -10); } } - /* This info used to show up randomly, depending on whether the query checked the query start time or not. now we always write current diff --git a/sql/log_slow.h b/sql/log_slow.h index 366906d7cb3..eb6895b973d 100644 --- a/sql/log_slow.h +++ b/sql/log_slow.h @@ -23,7 +23,8 @@ #define LOG_SLOW_VERBOSITY_QUERY_PLAN (1U << 1) #define LOG_SLOW_VERBOSITY_EXPLAIN (1U << 2) #define LOG_SLOW_VERBOSITY_STORAGE_ENGINE (1U << 3) /* Replaces InnoDB */ -#define LOG_SLOW_VERBOSITY_FULL (1U << 4) +#define LOG_SLOW_VERBOSITY_WARNINGS (1U << 4) +#define LOG_SLOW_VERBOSITY_FULL (1U << 5) #define LOG_SLOW_VERBOSITY_ENGINE (LOG_SLOW_VERBOSITY_FULL | \ LOG_SLOW_VERBOSITY_INNODB | \ diff --git a/sql/opt_range.cc b/sql/opt_range.cc index cf4dd4988f0..b0caf60d586 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -2680,7 +2680,8 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, ha_rows limit, bool force_quick_range, bool ordered_output, bool remove_false_parts_of_where, - bool only_single_index_range_scan) + bool only_single_index_range_scan, + bool suppress_unusable_key_notes) { uint idx; double scan_time; @@ -2771,6 +2772,9 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, param.max_key_parts= 0; param.remove_false_where_parts= remove_false_parts_of_where; param.force_default_mrr= ordered_output; + param.note_unusable_keys= (!suppress_unusable_key_notes && + thd->give_notes_for_unusable_keys()); + param.possible_keys.clear_all(); thd->no_errors=1; // Don't warn about NULL @@ -8723,14 +8727,21 @@ Item_func_like::get_mm_leaf(RANGE_OPT_PARAM *param, if (key_part->image_type != Field::itRAW) DBUG_RETURN(0); + uint keynr= param->real_keynr[key_part->key]; if (param->using_real_indexes && - !field->optimize_range(param->real_keynr[key_part->key], - key_part->part)) + !field->optimize_range(keynr, key_part->part)) DBUG_RETURN(0); if (field->result_type() == STRING_RESULT && field->charset() != compare_collation()) + { + if (param->note_unusable_keys) + field->raise_note_cannot_use_key_part(param->thd, keynr, key_part->part, + func_name_cstring(), value, + Data_type_compatibility:: + INCOMPATIBLE_COLLATION); DBUG_RETURN(0); + } StringBuffer tmp(value->collation.collation); String *res; @@ -8741,7 +8752,14 @@ Item_func_like::get_mm_leaf(RANGE_OPT_PARAM *param, if (field->cmp_type() != STRING_RESULT || field->type_handler() == &type_handler_enum || field->type_handler() == &type_handler_set) + { + if (param->note_unusable_keys) + field->raise_note_cannot_use_key_part(param->thd, keynr, key_part->part, + func_name_cstring(), value, + Data_type_compatibility:: + INCOMPATIBLE_DATA_TYPE); DBUG_RETURN(0); + } /* TODO: @@ -8821,19 +8839,44 @@ Item_bool_func::get_mm_leaf(RANGE_OPT_PARAM *param, } -bool Field::can_optimize_scalar_range(const RANGE_OPT_PARAM *param, - const KEY_PART *key_part, - const Item_bool_func *cond, - scalar_comparison_op op, - const Item *value) const +Data_type_compatibility +Field::can_optimize_scalar_range(const RANGE_OPT_PARAM *param, + const KEY_PART *key_part, + const Item_bool_func *cond, + scalar_comparison_op op, + Item *value) const { bool is_eq_func= op == SCALAR_CMP_EQ || op == SCALAR_CMP_EQUAL; - if ((param->using_real_indexes && - !optimize_range(param->real_keynr[key_part->key], - key_part->part) && !is_eq_func) || - !can_optimize_range(cond, value, is_eq_func)) - return false; - return true; + uint keynr= param->real_keynr[key_part->key]; + if (param->using_real_indexes && + !optimize_range(keynr, key_part->part) && !is_eq_func) + return Data_type_compatibility::INCOMPATIBLE_DATA_TYPE; + Data_type_compatibility compat= can_optimize_range(cond, value, is_eq_func); + if (compat == Data_type_compatibility::OK) + return compat; + /* + Raise a note that the index part could not be used. + + TODO: Perhaps we also need to raise a similar note when + a partition could not be used (when using_real_indexes==false). + */ + if (param->using_real_indexes && param->note_unusable_keys) + { + DBUG_ASSERT(keynr < table->s->keys); + /* + Here "cond" can be any sargable predicate, e.g.: + 1. field=value (and other scalar comparison predicates: <, <=, <=>, =>, >) + 2. field [NOT] BETWEEN value1 AND value2 + 3. field [NOT] IN (value1, value2...) + Don't print the entire "cond" as in case of BETWEEN and IN + it would list all values. + Let's only print the current field/value pair. + */ + raise_note_cannot_use_key_part(param->thd, keynr, key_part->part, + scalar_comparison_op_to_lex_cstring(op), + value, compat); + } + return compat; } @@ -8873,7 +8916,8 @@ SEL_ARG *Field_num::get_mm_leaf(RANGE_OPT_PARAM *prm, KEY_PART *key_part, scalar_comparison_op op, Item *value) { DBUG_ENTER("Field_num::get_mm_leaf"); - if (!can_optimize_scalar_range(prm, key_part, cond, op, value)) + if (can_optimize_scalar_range(prm, key_part, cond, op, value) != + Data_type_compatibility::OK) DBUG_RETURN(0); int err= value->save_in_field_no_warnings(this, 1); if ((op != SCALAR_CMP_EQUAL && is_real_null()) || err < 0) @@ -8889,7 +8933,8 @@ SEL_ARG *Field_temporal::get_mm_leaf(RANGE_OPT_PARAM *prm, KEY_PART *key_part, scalar_comparison_op op, Item *value) { DBUG_ENTER("Field_temporal::get_mm_leaf"); - if (!can_optimize_scalar_range(prm, key_part, cond, op, value)) + if (can_optimize_scalar_range(prm, key_part, cond, op, value) != + Data_type_compatibility::OK) DBUG_RETURN(0); int err= value->save_in_field_no_warnings(this, 1); if ((op != SCALAR_CMP_EQUAL && is_real_null()) || err < 0) @@ -8907,7 +8952,8 @@ SEL_ARG *Field_date_common::get_mm_leaf(RANGE_OPT_PARAM *prm, Item *value) { DBUG_ENTER("Field_date_common::get_mm_leaf"); - if (!can_optimize_scalar_range(prm, key_part, cond, op, value)) + if (can_optimize_scalar_range(prm, key_part, cond, op, value) != + Data_type_compatibility::OK) DBUG_RETURN(0); int err= value->save_in_field_no_warnings(this, 1); if ((op != SCALAR_CMP_EQUAL && is_real_null()) || err < 0) @@ -8949,7 +8995,8 @@ SEL_ARG *Field_str::get_mm_leaf(RANGE_OPT_PARAM *prm, KEY_PART *key_part, scalar_comparison_op op, Item *value) { DBUG_ENTER("Field_str::get_mm_leaf"); - if (!can_optimize_scalar_range(prm, key_part, cond, op, value)) + if (can_optimize_scalar_range(prm, key_part, cond, op, value) != + Data_type_compatibility::OK) DBUG_RETURN(0); int err= value->save_in_field_no_warnings(this, 1); if ((op != SCALAR_CMP_EQUAL && is_real_null()) || err < 0) @@ -8970,7 +9017,8 @@ SEL_ARG *Field::get_mm_leaf_int(RANGE_OPT_PARAM *prm, KEY_PART *key_part, bool unsigned_field) { DBUG_ENTER("Field::get_mm_leaf_int"); - if (!can_optimize_scalar_range(prm, key_part, cond, op, value)) + if (can_optimize_scalar_range(prm, key_part, cond, op, value) != + Data_type_compatibility::OK) DBUG_RETURN(0); int err= value->save_in_field_no_warnings(this, 1); if ((op != SCALAR_CMP_EQUAL && is_real_null()) || err < 0) @@ -14394,13 +14442,16 @@ check_group_min_max_predicates(Item *cond, Item_field *min_max_arg_item, Field *field= min_max_arg_item->field; if (!args[2]) // this is a binary function { - if (!field->can_optimize_group_min_max(bool_func, args[1])) + if (field->can_optimize_group_min_max(bool_func, args[1]) != + Data_type_compatibility::OK) DBUG_RETURN(FALSE); } else // this is BETWEEN { - if (!field->can_optimize_group_min_max(bool_func, args[1]) || - !field->can_optimize_group_min_max(bool_func, args[2])) + if (field->can_optimize_group_min_max(bool_func, args[1]) != + Data_type_compatibility::OK || + field->can_optimize_group_min_max(bool_func, args[2]) != + Data_type_compatibility::OK) DBUG_RETURN(FALSE); } } diff --git a/sql/opt_range.h b/sql/opt_range.h index 6e1dab84e47..1df034d9524 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -713,6 +713,8 @@ public: */ bool remove_false_where_parts; + bool note_unusable_keys; // Give SQL notes for unusable keys + /* used_key_no -> table_key_no translation table. Only makes sense if using_real_indexes==TRUE @@ -1733,7 +1735,8 @@ class SQL_SELECT :public Sql_alloc { int test_quick_select(THD *thd, key_map keys, table_map prev_tables, ha_rows limit, bool force_quick_range, bool ordered_output, bool remove_false_parts_of_where, - bool only_single_index_range_scan); + bool only_single_index_range_scan, + bool suppress_unusable_key_notes = 0); }; diff --git a/sql/opt_table_elimination.cc b/sql/opt_table_elimination.cc index c3297cb81cd..03a9985708d 100644 --- a/sql/opt_table_elimination.cc +++ b/sql/opt_table_elimination.cc @@ -1518,7 +1518,8 @@ void check_equality(Dep_analysis_context *ctx, Dep_module_expr **eq_mod, left->real_item()->type() == Item::FIELD_ITEM) { Field *field= ((Item_field*)left->real_item())->field; - if (!field->can_optimize_outer_join_table_elimination(cond, right)) + if (field->can_optimize_outer_join_table_elimination(cond, right) != + Data_type_compatibility::OK) return; Dep_value_field *field_val; if ((field_val= ctx->get_field_value(field))) diff --git a/sql/protocol.cc b/sql/protocol.cc index 33d865a3f9f..a8e451137c8 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -324,6 +324,8 @@ Protocol::net_send_eof(THD *thd, uint server_status, uint statement_warn_count) NET *net= &thd->net; bool error= FALSE; DBUG_ENTER("Protocol::net_send_eof"); + DBUG_PRINT("enter", ("status: %u warn_count: %u", + server_status, statement_warn_count)); /* Check if client understand new format packets (OK instead of EOF) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 884d6c81511..d86f79fb5fe 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1020,7 +1020,8 @@ void THD::raise_note(uint sql_errno) { DBUG_ENTER("THD::raise_note"); DBUG_PRINT("enter", ("code: %d", sql_errno)); - if (!(variables.option_bits & OPTION_SQL_NOTES)) + if (!(variables.option_bits & OPTION_SQL_NOTES) || + (variables.note_verbosity == 0)) DBUG_VOID_RETURN; const char* msg= ER_THD(this, sql_errno); (void) raise_condition(sql_errno, @@ -1036,7 +1037,8 @@ void THD::raise_note_printf(uint sql_errno, ...) char ebuff[MYSQL_ERRMSG_SIZE]; DBUG_ENTER("THD::raise_note_printf"); DBUG_PRINT("enter",("code: %u", sql_errno)); - if (!(variables.option_bits & OPTION_SQL_NOTES)) + if (!(variables.option_bits & OPTION_SQL_NOTES) || + (variables.note_verbosity == 0)) DBUG_VOID_RETURN; const char* format= ER_THD(this, sql_errno); va_start(args, sql_errno); @@ -1060,8 +1062,9 @@ Sql_condition* THD::raise_condition(uint sql_errno, DBUG_ENTER("THD::raise_condition"); DBUG_ASSERT(level < Sql_condition::WARN_LEVEL_END); - if (!(variables.option_bits & OPTION_SQL_NOTES) && - (level == Sql_condition::WARN_LEVEL_NOTE)) + if ((level == Sql_condition::WARN_LEVEL_NOTE) && + (!(variables.option_bits & OPTION_SQL_NOTES) || + (variables.note_verbosity == 0))) DBUG_RETURN(NULL); #ifdef WITH_WSREP /* diff --git a/sql/sql_class.h b/sql/sql_class.h index d76cc46d307..e8a42d4d135 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -699,6 +699,7 @@ typedef struct system_variables ulonglong log_slow_verbosity; ulonglong log_slow_disabled_statements; ulonglong log_disabled_statements; + ulonglong note_verbosity; ulonglong bulk_insert_buff_size; ulonglong join_buff_size; ulonglong sortbuff_size; @@ -771,6 +772,7 @@ typedef struct system_variables ulong trans_alloc_block_size; ulong trans_prealloc_size; ulong log_warnings; + ulong log_slow_max_warnings; /* Flags for slow log filtering */ ulong log_slow_rate_limit; ulong binlog_format; ///< binlog format for this thd (see enum_binlog_format) @@ -5661,6 +5663,14 @@ public: return (variables.log_slow_verbosity & LOG_SLOW_VERBOSITY_ENGINE) || lex->analyze_stmt; } + + /* Return true if we should create a note when an unusable key is found */ + bool give_notes_for_unusable_keys() + { + return ((variables.note_verbosity & (NOTE_VERBOSITY_UNUSABLE_KEYS)) || + (lex->describe && // Is EXPLAIN + (variables.note_verbosity & NOTE_VERBOSITY_EXPLAIN))); + } }; diff --git a/sql/sql_error.h b/sql/sql_error.h index 679672e5994..5d6141831a1 100644 --- a/sql/sql_error.h +++ b/sql/sql_error.h @@ -29,6 +29,14 @@ class THD; class my_decimal; class sp_condition_value; +/* Types of LOG warnings, used by note_verbosity */ + +#define NOTE_VERBOSITY_NORMAL (1U << 0) +/* Show warnings about keys parts that cannot be used */ +#define NOTE_VERBOSITY_UNUSABLE_KEYS (1U << 1) +/* Show warnings in explain for key parts that cannot be used */ +#define NOTE_VERBOSITY_EXPLAIN (1U << 2) + /////////////////////////////////////////////////////////////////////////// class Sql_state @@ -1071,6 +1079,11 @@ public: return m_statement_warn_count; } + uint unsafe_statement_warn_count() const + { + return m_statement_warn_count; + } + /** Get the current errno, state and id of the user defined condition and return them as Sql_condition_identity. diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f2f3e23b949..ed3b61a3594 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -5137,7 +5137,7 @@ static ha_rows get_quick_record_count(THD *thd, SQL_SELECT *select, (table_map) 0, limit, 0, FALSE, TRUE, /* remove_where_parts*/ - FALSE)) == + FALSE, TRUE)) == 1)) DBUG_RETURN(select->quick->records); if (unlikely(error == -1)) @@ -6391,7 +6391,7 @@ add_key_field(JOIN *join, { /* Save info to be able check whether this predicate can be - considered as sargable for range analisis after reading const tables. + considered as sargable for range analysis after reading const tables. We do not save info about equalities as update_const_equal_items will take care of updating info on keys from sargable equalities. */ @@ -6897,11 +6897,14 @@ add_keyuse(DYNAMIC_ARRAY *keyuse_array, KEY_FIELD *key_field, 1 - Out of memory. */ +static LEX_CSTRING equal_str= { STRING_WITH_LEN("=") }; + static bool add_key_part(DYNAMIC_ARRAY *keyuse_array, KEY_FIELD *key_field) { Field *field=key_field->field; TABLE *form= field->table; + THD *thd= form->in_use; if (key_field->eq_func && !(key_field->optimize & KEY_OPTIMIZE_EXISTS)) { @@ -6916,19 +6919,31 @@ add_key_part(DYNAMIC_ARRAY *keyuse_array, KEY_FIELD *key_field) uint key_parts= form->actual_n_key_parts(keyinfo); for (uint part=0 ; part < key_parts ; part++) { - if (field->eq(form->key_info[key].key_part[part].field) && - field->can_optimize_keypart_ref(key_field->cond, key_field->val)) - { - if (add_keyuse(keyuse_array, key_field, key, part)) - return TRUE; - } + if (field->eq(form->key_info[key].key_part[part].field)) + { + Data_type_compatibility compat= + field->can_optimize_keypart_ref(key_field->cond, key_field->val); + if (compat == Data_type_compatibility::OK) + { + if (add_keyuse(keyuse_array, key_field, key, part)) + return TRUE; + } + else if (thd->give_notes_for_unusable_keys()) + { + field->raise_note_cannot_use_key_part(thd, key, part, + equal_str, + key_field->val, + compat); + } + } } } if (field->hash_join_is_possible() && (key_field->optimize & KEY_OPTIMIZE_EQ) && key_field->val->used_tables()) { - if (!field->can_optimize_hash_join(key_field->cond, key_field->val)) + if (field->can_optimize_hash_join(key_field->cond, key_field->val) != + Data_type_compatibility::OK) return false; if (form->is_splittable()) form->add_splitting_info_for_key_field(key_field); @@ -11299,7 +11314,7 @@ bool JOIN::get_best_combination() form->reginfo.join_tab=j; DBUG_PRINT("info",("type: %d", j->type)); if (j->type == JT_CONST) - goto loop_end; // Handled in make_join_stat.. + goto loop_end; // Handled in make_join_stat.. j->loosescan_match_tab= NULL; //non-nulls will be set later j->inside_loosescan_range= FALSE; @@ -12631,7 +12646,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) OPTION_FOUND_ROWS ? HA_POS_ERROR : join->unit->lim.get_select_limit()),0, - FALSE, FALSE, FALSE) < 0) + FALSE, FALSE, FALSE, TRUE) < 0) DBUG_RETURN(1); // Impossible WHERE } else @@ -22617,7 +22632,8 @@ test_if_quick_select(JOIN_TAB *tab) int res= tab->select->test_quick_select(tab->join->thd, tab->keys, (table_map) 0, HA_POS_ERROR, 0, FALSE, /*remove where parts*/FALSE, - FALSE); + FALSE, + /* no warnings */ TRUE); if (tab->explain_plan && tab->explain_plan->range_checked_fer) tab->explain_plan->range_checked_fer->collect_data(tab->select->quick); @@ -30341,8 +30357,9 @@ uint get_index_for_order(ORDER *order, TABLE *table, SQL_SELECT *select, { // check if some index scan & LIMIT is more efficient than filesort /* - Update opt_range_condition_rows since single table UPDATE/DELETE procedures - don't call make_join_statistics() and leave this variable uninitialized. + Update opt_range_condition_rows since single table UPDATE/DELETE + procedures don't call make_join_statistics() and leave this + variable uninitialized. */ table->opt_range_condition_rows= table->stat_records(); diff --git a/sql/sql_type.h b/sql/sql_type.h index 471fe519847..e7f02eb6b13 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -124,6 +124,40 @@ enum scalar_comparison_op }; +/* + This enum is intentionally defined as "class" to disallow its implicit + cast as "bool". This is needed to avoid pre-MDEV-32203 constructs like: + if (field->can_optimize_range(...)) + do_optimization(); + to merge automatically as such - that would change the meaning + to the opposite. The pre-MDEV-32203 code must to be changed to: + if (field->can_optimize_range(...) == Data_type_compatibility::OK) + do_optimization(); +*/ +enum class Data_type_compatibility +{ + OK, + INCOMPATIBLE_DATA_TYPE, + INCOMPATIBLE_COLLATION +}; + + +static inline const LEX_CSTRING +scalar_comparison_op_to_lex_cstring(scalar_comparison_op op) +{ + switch (op) { + case SCALAR_CMP_EQ: return LEX_CSTRING{STRING_WITH_LEN("=")}; + case SCALAR_CMP_EQUAL: return LEX_CSTRING{STRING_WITH_LEN("<=>")}; + case SCALAR_CMP_LT: return LEX_CSTRING{STRING_WITH_LEN("<")}; + case SCALAR_CMP_LE: return LEX_CSTRING{STRING_WITH_LEN("<=")}; + case SCALAR_CMP_GE: return LEX_CSTRING{STRING_WITH_LEN(">")}; + case SCALAR_CMP_GT: return LEX_CSTRING{STRING_WITH_LEN(">=")}; + } + DBUG_ASSERT(0); + return LEX_CSTRING{STRING_WITH_LEN("")}; +} + + class Hasher { ulong m_nr1; diff --git a/sql/sql_type_fixedbin.h b/sql/sql_type_fixedbin.h index e971dc08b66..9bd23a949fa 100644 --- a/sql/sql_type_fixedbin.h +++ b/sql/sql_type_fixedbin.h @@ -622,8 +622,9 @@ public: return NULL; return new (thd->mem_root) Item_literal_fbt(thd, tmp); } - bool can_optimize_keypart_ref(const Item_bool_func *cond, - const Item *item) const override + Data_type_compatibility can_optimize_keypart_ref(const Item_bool_func *cond, + const Item *item) + const override { /* Mixing of two different non-traditional types is currently prevented. @@ -632,22 +633,22 @@ public: DBUG_ASSERT(item->type_handler()->type_handler_base_or_self()-> is_traditional_scalar_type() || item->type_handler() == type_handler()); - return true; + return Data_type_compatibility::OK; } /** Test if Field can use range optimizer for a standard comparison operation: <=, <, =, <=>, >, >= Note, this method does not cover spatial operations. */ - bool can_optimize_range(const Item_bool_func *cond, - const Item *item, - bool is_eq_func) const override + Data_type_compatibility can_optimize_range(const Item_bool_func *cond, + const Item *item, + bool is_eq_func) const override { // See the DBUG_ASSERT comment in can_optimize_keypart_ref() DBUG_ASSERT(item->type_handler()->type_handler_base_or_self()-> is_traditional_scalar_type() || item->type_handler() == type_handler()); - return true; + return Data_type_compatibility::OK; } void hash_not_null(Hasher *hasher) override { @@ -658,7 +659,8 @@ public: scalar_comparison_op op, Item *value) override { DBUG_ENTER("Field_fbt::get_mm_leaf"); - if (!can_optimize_scalar_range(prm, key_part, cond, op, value)) + if (can_optimize_scalar_range(prm, key_part, cond, op, value) != + Data_type_compatibility::OK) DBUG_RETURN(0); int err= value->save_in_field_no_warnings(this, 1); if ((op != SCALAR_CMP_EQUAL && is_real_null()) || err < 0) @@ -671,15 +673,17 @@ public: } DBUG_RETURN(stored_field_make_mm_leaf(prm, key_part, op, value)); } - bool can_optimize_hash_join(const Item_bool_func *cond, - const Item *item) const override + Data_type_compatibility can_optimize_hash_join(const Item_bool_func *cond, + const Item *item) + const override { return can_optimize_keypart_ref(cond, item); } - bool can_optimize_group_min_max(const Item_bool_func *cond, + Data_type_compatibility can_optimize_group_min_max( + const Item_bool_func *cond, const Item *const_item) const override { - return true; + return Data_type_compatibility::OK; } uint row_pack_length() const override { return pack_length(); } diff --git a/sql/sql_type_geom.cc b/sql/sql_type_geom.cc index c555022a99d..74d17fd21eb 100644 --- a/sql/sql_type_geom.cc +++ b/sql/sql_type_geom.cc @@ -919,11 +919,14 @@ bool Field_geom::is_equal(const Column_definition &new_field) const } -bool Field_geom::can_optimize_range(const Item_bool_func *cond, - const Item *item, - bool is_eq_func) const +Data_type_compatibility +Field_geom::can_optimize_range(const Item_bool_func *cond, + const Item *item, + bool is_eq_func) const { - return item->cmp_type() == STRING_RESULT; + return item->cmp_type() == STRING_RESULT ? + Data_type_compatibility::OK : + Data_type_compatibility::INCOMPATIBLE_DATA_TYPE; } diff --git a/sql/sql_type_geom.h b/sql/sql_type_geom.h index f3e34526f26..95726aa3bf7 100644 --- a/sql/sql_type_geom.h +++ b/sql/sql_type_geom.h @@ -377,9 +377,9 @@ public: if (tmp.length) to->set_data_type_name(tmp); } - bool can_optimize_range(const Item_bool_func *cond, - const Item *item, - bool is_eq_func) const override; + Data_type_compatibility can_optimize_range(const Item_bool_func *cond, + const Item *item, + bool is_eq_func) const override; void sql_type(String &str) const override; Copy_func *get_copy_func(const Field *from) const override { diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index f97bd36aa85..8053577038f 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -4543,10 +4543,13 @@ static Sys_var_bit Sys_sql_warnings( DEFAULT(FALSE)); static Sys_var_bit Sys_sql_notes( - "sql_notes", "If set to 1, the default, warning_count is incremented each " - "time a Note warning is encountered. If set to 0, Note warnings are not " - "recorded. mysqldump has outputs to set this variable to 0 so that no " - "unnecessary increments occur when data is reloaded.", + "sql_notes", + "If set to 1, the default, warning_count is incremented " + "each time a Note warning is encountered. If set to 0, Note warnings " + "are not recorded. mysqldump has outputs to set this variable to 0 so " + "that no unnecessary increments occur when data is reloaded. " + "See also note_verbosity, which allows one to define with notes are " + "sent.", SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_SQL_NOTES, DEFAULT(TRUE)); @@ -6347,7 +6350,7 @@ static const char *log_slow_filter_names[]= static Sys_var_set Sys_log_slow_filter( "log_slow_filter", - "Log only certain types of queries to the slow log. If variable empty alll kind of queries are logged. All types are bound by slow_query_time, except 'not_using_index' which is always logged if enabled", + "Log only certain types of queries to the slow log. If variable empty all kind of queries are logged. All types are bound by slow_query_time, except 'not_using_index' which is always logged if enabled", SESSION_VAR(log_slow_filter), CMD_LINE(REQUIRED_ARG), log_slow_filter_names, /* by default we log all queries except 'not_using_index' */ @@ -6439,8 +6442,12 @@ static Sys_var_ulong Sys_log_slow_rate_limit( SESSION_VAR(log_slow_rate_limit), CMD_LINE(REQUIRED_ARG), VALID_RANGE(1, UINT_MAX), DEFAULT(1), BLOCK_SIZE(1)); +/* + Full is not needed below anymore as one can set all bits with '= ALL', but + we need it for compatiblity with earlier versions. +*/ static const char *log_slow_verbosity_names[]= -{ "innodb", "query_plan", "explain", "engine", "full", 0}; +{ "innodb", "query_plan", "explain", "engine", "warnings", "full", 0}; static Sys_var_set Sys_log_slow_verbosity( "log_slow_verbosity", @@ -6448,6 +6455,23 @@ static Sys_var_set Sys_log_slow_verbosity( SESSION_VAR(log_slow_verbosity), CMD_LINE(REQUIRED_ARG), log_slow_verbosity_names, DEFAULT(LOG_SLOW_VERBOSITY_INIT)); +static Sys_var_ulong Sys_log_slow_max_warnings( + "log_slow_max_warnings", + "Max numbers of warnings printed to slow query log per statement", + SESSION_VAR(log_slow_max_warnings), CMD_LINE(REQUIRED_ARG), + VALID_RANGE(0, 1000), DEFAULT(10), BLOCK_SIZE(1)); + +static const char *note_verbosity_names[]= +{ "basic", "unusable_keys", "explain", 0}; + +static Sys_var_set Sys_note_verbosity( + "note_verbosity", + "Verbosity level for note-warnings given to the user. " + "See also @@sql_notes.", + SESSION_VAR(note_verbosity), CMD_LINE(REQUIRED_ARG), + note_verbosity_names, DEFAULT(NOTE_VERBOSITY_NORMAL | + NOTE_VERBOSITY_EXPLAIN)); + static Sys_var_ulong Sys_join_cache_level( "join_cache_level", "Controls what join operations can be executed with join buffers. Odd " diff --git a/sql/sys_vars.inl b/sql/sys_vars.inl index fff8998b25a..09191a7236d 100644 --- a/sql/sys_vars.inl +++ b/sql/sys_vars.inl @@ -1390,6 +1390,10 @@ public: Backing store: ulonglong */ + +static const LEX_CSTRING all_clex_str= {STRING_WITH_LEN("all")}; + + class Sys_var_set: public Sys_var_typelib { public: @@ -1449,6 +1453,12 @@ public: var->save_result.ulonglong_value= find_set(&typelib, res->ptr(), res->length(), NULL, &error, &error_len, ¬_used); + if (error_len && + !my_charset_latin1.strnncollsp(res->to_lex_cstring(), all_clex_str)) + { + var->save_result.ulonglong_value= ((1ULL << (typelib.count)) -1); + error_len= 0; + } /* note, we only issue an error if error_len > 0. That is even while empty (zero-length) values are considered