From 403e6615fdd3f5f4de6d159457b2bd2fe566e0ad Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Fri, 26 Jul 2019 18:17:55 +0300 Subject: [PATCH 01/63] List of unstable tests for 10.1.41 release (updated) --- mysql-test/unstable-tests | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/mysql-test/unstable-tests b/mysql-test/unstable-tests index 0c7756d70ae..f09647523af 100644 --- a/mysql-test/unstable-tests +++ b/mysql-test/unstable-tests @@ -23,13 +23,14 @@ # ############################################################################## # -# Based on 10.1 1f498f901b394e869c430b777fdc233ab98d428f +# Based on 10.1 2382cd14a8c96cf8b4375d7338abfa6e1b333a86 main.alter_table_trans : MDEV-12084 - timeout main.analyze_stmt : Modified in 10.1.39 main.analyze_stmt_slow_query_log : MDEV-12237 - Wrong result main.auth_named_pipe : MDEV-14724 - System error 2 main.bootstrap : Modified in 10.1.41 +main.connect_debug : Modified in 10.1.41 main.count_distinct2 : MDEV-11768 - timeout main.create_delayed : MDEV-10605 - failed with timeout main.create_drop_event : MDEV-16271 - Wrong result @@ -81,11 +82,14 @@ main.host_cache_size_functionality : MDEV-10606 - sporadic failure on shutdown main.index_intersect_innodb : MDEV-10643 - failed with timeout main.index_merge_innodb : MDEV-7142 - Wrong execution plan, timeout with valgrind; modified in 10.1.39 main.index_merge_myisam : Include files modified in 10.1.39 +main.information_schema_parameters : Modified in 10.1.41 main.information_schema_prepare : Added in 10.1.39 main.innodb_mysql_lock : MDEV-7861 - sporadic lock detection failure +main.join : Modified in 10.1.41 main.join_cache : Modified in 10.1.41 main.join_nested : Modified in 10.1.41 main.join_outer : Modified in 10.1.41 +main.join_outer_innodb : Modified in 10.1.41 main.kill_processlist-6619 : MDEV-10793 - wrong result in processlist; modified in 10.1.39 main.loaddata : MDEV-19368 - mysqltest failed but provided no output; modified in 10.1.39 main.log_slow : MDEV-13263 - Wrong result; modified in 10.1.39 @@ -117,7 +121,10 @@ main.partition : Modified in 10.1.39 main.partition_debug_sync : MDEV-15669 - Deadlock found when trying to get lock main.partition_innodb : Modified in 10.1.39 main.partition_innodb_plugin : MDEV-12901 - Valgrind warnings -main.ps : MDEV-11017 - sporadic wrong Prepared_stmt_count; modified in 10.1.39 +main.plugin : Modified in 10.1.41 +main.plugin_not_embedded : Modified in 10.1.41 +main.ps : MDEV-11017 - sporadic wrong Prepared_stmt_count; modified in 10.1.41 +main.ps_innodb : Added in 10.1.41 main.query_cache : MDEV-12895 - Wrong result main.query_cache_debug : MDEV-15281 - Resize or similar command in progress main.range_vs_index_merge_innodb : MDEV-15283 - Server has gone away @@ -135,6 +142,7 @@ main.stat_tables_par_innodb : MDEV-14155 - wrong rounding main.statistics : Modified in 10.1.39 main.status : MDEV-8510 - sporadic wrong result main.status2 : Modified in 10.1.39 +main.subselect : Modified in 10.1.41 main.subselect_innodb : MDEV-10614 - sporadic wrong results main.subselect_sj : Modified in 10.1.41 main.subselect_sj_mat : Modified in 10.1.41 @@ -150,7 +158,7 @@ main.type_decimal : Modified in 10.1.39 main.type_year : Modified in 10.1.39 main.update_innodb : Modified in 10.1.39 main.userstat : Modified in 10.1.39 -main.view : Modified in 10.1.39 +main.view : Modified in 10.1.41 main.view_grant : Modified in 10.1.39 main.wait_timeout : Lost connection to MySQL server during query main.xa : MDEV-11769 - lock wait timeout @@ -169,13 +177,17 @@ archive-test_sql_discovery.discover : MDEV-16817 - Table marked as crashed #----------------------------------------------------------------------- -binlog.binlog_commit_wait : MDEV-10150 - Error: too much time elapsed -binlog.binlog_innodb_stm : Added in 10.1.39 -binlog.binlog_killed : MDEV-12925 - Wrong result -binlog.binlog_mysqlbinlog2 : Modified in 10.1.39 -binlog.binlog_mysqlbinlog_stop_never : Added in 10.1.41 -binlog.binlog_xa_recover : MDEV-8517 - Extra checkpoint -binlog.load_data_stm_view : MDEV-16948 - Wrong result +binlog.binlog_commit_wait : MDEV-10150 - Error: too much time elapsed +binlog.binlog_innodb_stm : Added in 10.1.39 +binlog.binlog_killed : MDEV-12925 - Wrong result +binlog.binlog_mysqlbinlog2 : Modified in 10.1.39 +binlog.binlog_mysqlbinlog_stop_never : Added in 10.1.41 +binlog.binlog_parallel_replication_marks_row : Include file modified in 10.1.41 +binlog.binlog_parallel_replication_marks_stm_mix : Include file modified in 10.1.41 +binlog.binlog_row_drop_tmp_tbl : Include file modified in 10.1.41 +binlog.binlog_stm_drop_tmp_tbl : MDEV-20188 - Unknown table on exec; include file modified in 10.1.41 +binlog.binlog_xa_recover : MDEV-8517 - Extra checkpoint +binlog.load_data_stm_view : MDEV-16948 - Wrong result #----------------------------------------------------------------------- @@ -279,6 +291,7 @@ innodb.innodb-64k-crash : MDEV-13872 - Failure and crash on innodb.innodb-alter-debug : MDEV-13182 - InnoDB: adjusting FSP_SPACE_FLAGS innodb.innodb-alter-nullable : Modified in 10.1.39 innodb.innodb-alter-table : MDEV-10619 - Testcase timeout +innodb.innodb-autoinc : Modified in 10.1.41 innodb.innodb-blob : MDEV-12053 - Client crash innodb.innodb-corrupted-table : Modified in 10.1.39 innodb.innodb-fk : MDEV-13832 - Assertion failure on shutdown @@ -309,7 +322,6 @@ innodb.xa_recovery : MDEV-15279 - mysqld got exception #----------------------------------------------------------------------- -innodb_fts.innodb-fts-fic : MDEV-14154 - Assertion failure innodb_fts.innodb_ft_aux_table : Added in 10.1.41 innodb_fts.innodb_fts_misc_debug : MDEV-14156 - Unexpected warning @@ -397,6 +409,9 @@ roles.flush_roles-17898 : Modified in 10.1.39 #----------------------------------------------------------------------- rpl.circular_serverid0 : MDEV-19372 - ASAN heap-use-after-free +rpl.create_or_replace_mix : Include file modified in 10.1.41 +rpl.create_or_replace_row : Include file modified in 10.1.41 +rpl.create_or_replace_statement : Include file modified in 10.1.41 rpl.create_select : MDEV-14121 - Assertion failure rpl.kill_race_condition : Modified in 10.1.41 rpl.last_insert_id : MDEV-10625 - warnings in error log @@ -447,6 +462,7 @@ rpl.rpl_rewrt_db : Modified in 10.1.39 rpl.rpl_row_basic_11bugs : MDEV-12171 - Server failed to start rpl.rpl_row_basic_2myisam : MDEV-13875 - command "diff_files" failed rpl.rpl_row_drop_create_temp_table : MDEV-14487 - Wrong result +rpl.rpl_row_drop_temp_table : Added in 10.1.41 rpl.rpl_row_img_blobs : MDEV-13875 - command "diff_files" failed rpl.rpl_row_img_eng_min : MDEV-13875 - command "diff_files" failed rpl.rpl_row_img_eng_noblob : MDEV-13875 - command "diff_files" failed From d6886b95d0d48d80deffa7f2190b8abd5ee8236b Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Sat, 27 Jul 2019 00:19:28 +0300 Subject: [PATCH 02/63] List of unstable tests for 10.2.26 release (updated) --- mysql-test/unstable-tests | 43 +++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/mysql-test/unstable-tests b/mysql-test/unstable-tests index 8d6019eca9a..6d71041785e 100644 --- a/mysql-test/unstable-tests +++ b/mysql-test/unstable-tests @@ -23,7 +23,7 @@ # ############################################################################## # -# Based on 10.2 97055e6b11508b53203aaadfe4618f543891c575 +# Based on 10.2 32c6f40a6319d493e5270c72ac5d27dc99d1b242 main.alter_table_trans : MDEV-12084 - timeout main.analyze_stmt_slow_query_log : MDEV-12237 - Wrong result @@ -31,6 +31,7 @@ main.auth_named_pipe : MDEV-14724 - System error 2 main.charset_client_win : Added in 10.2.26 main.connect : MDEV-17282 - Wrong result main.connect2 : MDEV-13885 - Server crash +main.connect_debug : Modified in 10.2.26 main.count_distinct2 : MDEV-11768 - timeout main.create_delayed : MDEV-10605 - failed with timeout main.create_drop_event : MDEV-16271 - Wrong result @@ -39,10 +40,10 @@ main.ctype_upgrade : MDEV-16945 - Error upon mysql_upgrade main.ctype_utf16 : MDEV-10675: timeout or extra warnings main.ctype_utf8_def_upgrade : Added in 10.2.25 main.debug_sync : MDEV-10607 - internal error -main.derived : Modified in 10.2.25 +main.derived : Modified in 10.2.26 main.derived_cond_pushdown : Modified in 10.2.25 main.derived_opt : MDEV-11768 - timeout -main.derived_view : Modified in 10.2.25 +main.derived_view : Modified in 10.2.26 main.dirty_close : MDEV-19368 - mysqltest failed but provided no output main.distinct : MDEV-14194 - Crash main.drop_bad_db_type : MDEV-15676 - Wrong result @@ -56,10 +57,13 @@ main.gis : MDEV-13411 - wrong result on P8 main.host_cache_size_functionality : MDEV-10606 - sporadic failure on shutdown main.index_intersect_innodb : MDEV-10643 - failed with timeout main.index_merge_innodb : MDEV-7142 - Plan mismatch +main.information_schema_parameters : Modified in 10.2.26 main.innodb_mysql_lock : MDEV-7861 - Wrong result +main.join : Modified in 10.2.26 main.join_cache : Modified in 10.2.25 main.join_nested : Modified in 10.2.25 main.join_outer : Modified in 10.2.26 +main.join_outer_innodb : Modified in 10.2.26 main.kill-2 : MDEV-13257 - Wrong result main.kill_processlist-6619 : MDEV-10793 - Wrong result main.loaddata : MDEV-19368 - mysqltest failed but provided no output @@ -88,8 +92,11 @@ main.order_by_optimizer_innodb : MDEV-10683 - Wrong result main.partition_debug_sync : MDEV-15669 - Deadlock found when trying to get lock main.partition_innodb_plugin : MDEV-12901 - Valgrind warnings main.partition_innodb_semi_consistent : MDEV-19411 - Failed to start mysqld.1 +main.plugin : Modified in 10.2.26 main.plugin_auth : Modified in 10.2.26 -main.ps : MDEV-11017 - Wrong result +main.plugin_not_embedded : Modified in 10.2.26 +main.ps : MDEV-11017 - Wrong result; modified in 10.2.26 +main.ps_innodb : Added in 10.2.26 main.query_cache : MDEV-16180 - Wrong result main.query_cache_debug : MDEV-15281 - Query cache is disabled main.range_vs_index_merge_innodb : MDEV-15283 - Server has gone away @@ -111,6 +118,7 @@ main.stat_tables : Modified in 10.2.25 main.stat_tables_par : MDEV-13266 - Wrong result main.stat_tables_par_innodb : MDEV-14155 - Wrong rounding main.status : MDEV-13255 - Wrong result +main.subselect : Modified in 10.2.26 main.subselect_innodb : MDEV-10614 - Sporadic wrong results main.subselect_no_semijoin : Modified in 10.2.25 main.subselect_sj : Modified in 10.2.25 @@ -122,6 +130,7 @@ main.type_blob : MDEV-15195 - Wrong result main.type_datetime : Modified in 10.2.26 main.type_datetime_hires : MDEV-10687 - Timeout main.userstat : MDEV-12904 - SSL errors +main.view : Modified in 10.2.26 main.wait_timeout : MDEV-19023 - Lost connection to MySQL server during query main.win : Modified in 10.2.25 main.xa : MDEV-11769 - lock wait timeout @@ -139,13 +148,17 @@ archive-test_sql_discovery.discover : MDEV-16817 - Table marked as crashed #----------------------------------------------------------------------- -binlog.binlog_commit_wait : MDEV-10150 - Mismatch -binlog.binlog_killed : MDEV-12925 - Wrong result -binlog.binlog_max_extension : MDEV-19762 - Crash on shutdown -binlog.binlog_mysqlbinlog_stop_never : Added in 10.2.26 -binlog.binlog_xa_recover : MDEV-8517 - Extra checkpoint -binlog.flashback-largebinlog : MDEV-19764 - Out of memory; added in 10.2.25 -binlog.load_data_stm_view : MDEV-16948 - Wrong result +binlog.binlog_commit_wait : MDEV-10150 - Mismatch +binlog.binlog_killed : MDEV-12925 - Wrong result +binlog.binlog_max_extension : MDEV-19762 - Crash on shutdown +binlog.binlog_mysqlbinlog_stop_never : Added in 10.2.26 +binlog.binlog_parallel_replication_marks_row : Include file modified in 10.2.26 +binlog.binlog_parallel_replication_marks_stm_mix : Include file modified in 10.2.26 +binlog.binlog_row_drop_tmp_tbl : Include file modified in 10.2.26 +binlog.binlog_stm_drop_tmp_tbl : MDEV-20188 - Unknown table on exec; include file modified in 10.2.26 +binlog.binlog_xa_recover : MDEV-8517 - Extra checkpoint +binlog.flashback-largebinlog : MDEV-19764 - Out of memory; added in 10.2.25 +binlog.load_data_stm_view : MDEV-16948 - Wrong result #----------------------------------------------------------------------- @@ -285,6 +298,7 @@ innodb.innodb-64k-crash : MDEV-13872 - Failure and crash on innodb.innodb-alter-debug : MDEV-13182 - InnoDB: adjusting FSP_SPACE_FLAGS innodb.innodb-alter-table : MDEV-10619 - Testcase timeout innodb.innodb-alter-tempfile : MDEV-15285 - Table already exists +innodb.innodb-autoinc : Modified in 10.2.26 innodb.innodb-blob : MDEV-12053 - Client crash innodb.innodb-change-buffer-recovery : MDEV-19115 - Lost connection to MySQL server during query innodb.innodb-fk : MDEV-13832 - Assertion failure on shutdown @@ -348,7 +362,6 @@ innodb.xa_recovery : MDEV-15279 - mysqld got exception #----------------------------------------------------------------------- innodb_fts.fulltext2 : Modified in 10.2.26 -innodb_fts.innodb-fts-fic : MDEV-14154 - Assertion failure innodb_fts.innodb_ft_aux_table : Added in 10.2.25 innodb_fts.innodb_fts_misc_debug : MDEV-14156 - Unexpected warning innodb_fts.innodb_fts_plugin : MDEV-13888 - Errors in server log @@ -539,6 +552,9 @@ roles.create_and_grant_role : MDEV-11772 - wrong result rpl.circular_serverid0 : MDEV-19372 - ASAN heap-use-after-free rpl.create_or_replace2 : MDEV-19412 - Lost connection to MySQL server +rpl.create_or_replace_mix : Include file modified in 10.2.26 +rpl.create_or_replace_row : Include file modified in 10.2.26 +rpl.create_or_replace_statement : Include file modified in 10.2.26 rpl.create_select : MDEV-14121 - Assertion failure rpl.kill_race_condition : Modified in 10.2.26 rpl.last_insert_id : MDEV-10625 - warnings in error log @@ -598,6 +614,7 @@ rpl.rpl_row_001 : MDEV-16653 - Internal check fails rpl.rpl_row_basic_11bugs : MDEV-12171 - Server failed to start rpl.rpl_row_basic_2myisam : MDEV-13875 - command "diff_files" failed rpl.rpl_row_drop_create_temp_table : MDEV-14487 - Wrong result +rpl.rpl_row_drop_temp_table : Added in 10.2.26 rpl.rpl_row_img_blobs : MDEV-13875 - command "diff_files" failed rpl.rpl_row_img_eng_min : MDEV-13875 - diff_files failed rpl.rpl_row_img_eng_noblob : MDEV-13875 - command "diff_files" failed @@ -678,7 +695,7 @@ stress.ddl_innodb : MDEV-10635 - Testcase timeout sys_vars.autocommit_func2 : MDEV-9329 - Fails on Ubuntu/s390x sys_vars.delayed_insert_limit_func : MDEV-17683 - Wrong result sys_vars.innodb_buffer_pool_dump_at_shutdown_basic : MDEV-14280 - Unexpected error -sys_vars.innodb_ft_result_cache_limit : Modified in 10.2.25 +sys_vars.innodb_ft_result_cache_limit : Modified in 10.2.26 sys_vars.keep_files_on_create_basic : MDEV-10676 - timeout sys_vars.log_slow_admin_statements_func : MDEV-12235 - Server crash sys_vars.rpl_init_slave_func : MDEV-10149 - Test assertion From f79212f96d2b9ad23037201f6896ba303a222b5d Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Wed, 31 Jul 2019 02:49:15 -0700 Subject: [PATCH 03/63] Fix extra space in mysql-test README --- mysql-test/README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/README b/mysql-test/README index c4ded4e8e79..08a8200e27f 100644 --- a/mysql-test/README +++ b/mysql-test/README @@ -60,7 +60,7 @@ In the file, put a set of SQL statements that create some tables, load test data, and run some queries to manipulate it. Your test should begin by dropping the tables you are going to create and -end by dropping them again. This ensures that you can run the test over +end by dropping them again. This ensures that you can run the test over and over again. If you are using mysqltest commands in your test case, you should create @@ -81,7 +81,7 @@ comments, you can create the result file in one of the following ways: # mysqltest --record --database test --result-file=r/test_case_name.result < t/test_case_name.test -When this is done, take a look at r/test_case_name.result . +When this is done, take a look at r/test_case_name.result. If the result is incorrect, you have found a bug. In this case, you should edit the test result to the correct results so that we can verify that the bug is corrected in future releases. From cabf10b640980fae6051a2a0f20b9b2b0c4143ce Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Wed, 31 Jul 2019 09:53:58 -0400 Subject: [PATCH 04/63] bump the VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index b9002ef5c4d..df06ca3b38a 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=5 MYSQL_VERSION_MINOR=5 -MYSQL_VERSION_PATCH=65 +MYSQL_VERSION_PATCH=66 MYSQL_VERSION_EXTRA= From 0bb8f33b55cc016d0ede86b97990a3ee30dcb069 Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Wed, 31 Jul 2019 09:55:57 -0400 Subject: [PATCH 05/63] bump the VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 3e7ee013177..93f88d1e9c0 100644 --- a/VERSION +++ b/VERSION @@ -1,3 +1,3 @@ MYSQL_VERSION_MAJOR=10 MYSQL_VERSION_MINOR=1 -MYSQL_VERSION_PATCH=41 +MYSQL_VERSION_PATCH=42 From 05b35cf4c1cc11f2078ebf0a16a1aa82cfe04b25 Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Wed, 31 Jul 2019 09:57:31 -0400 Subject: [PATCH 06/63] bump the VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 748fcaa7c2b..5bceb99bb75 100644 --- a/VERSION +++ b/VERSION @@ -1,3 +1,3 @@ MYSQL_VERSION_MAJOR=10 MYSQL_VERSION_MINOR=2 -MYSQL_VERSION_PATCH=26 +MYSQL_VERSION_PATCH=27 From 319cec959c6295da3c2a1d003d12421a7d8ba343 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Thu, 1 Aug 2019 15:24:48 +0300 Subject: [PATCH 07/63] MDEV-17638 Improve error message about corruption of encrypted page Help user distinguish between space ID and page number. --- extra/innochecksum.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extra/innochecksum.cc b/extra/innochecksum.cc index d7c5cd7495b..00ca3e20339 100644 --- a/extra/innochecksum.cc +++ b/extra/innochecksum.cc @@ -525,7 +525,8 @@ is_page_corrupted( page_size.is_compressed() ? page_size.physical() : 0); if (is_corrupted && log_file) { fprintf(log_file, - "Page " ULINTPF ":%llu may be corrupted;" + "[page id: space=" ULINTPF + ", page_number=%llu] may be corrupted;" " key_version=" ULINTPF "\n", space_id, cur_page_num, mach_read_from_4( From 09a85692a65634cda40214b6693f34bec2f5b73b Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sat, 3 Aug 2019 23:15:44 +0300 Subject: [PATCH 08/63] Post-merge fixes for rocksdb.group_min_max test - Fix the LooseScan code to support storage engines that return HA_ERR_END_OF_FILE if the index scan goes out of provided range bounds - Add a DBUG_EXECUTE_IF("force_group_by",...) to allow a test to force a LooseScan - Adjust rocksdb.group_min_max test not to use features not present in MariaDB 10.2 (e.g. optimizer_trace. In MariaDB 10.4 it's present but it doesn't meet the assumptions that the test makes about it - Adjust the test result file: = MariaDB doesn't support "Enhanced Loose Scan" that FB/MySQL has = MariaDB has different cost calculations. --- sql/opt_range.cc | 38 +- .../rocksdb/include/group_min_max.inc | 49 +- .../mysql-test/rocksdb/r/group_min_max.result | 663 +++++++++--------- .../mysql-test/rocksdb/t/group_min_max.test | 5 +- 4 files changed, 395 insertions(+), 360 deletions(-) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 3ba8c44d790..3f6c18dca5c 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -2428,6 +2428,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, KEY_PART *key_parts; KEY *key_info; PARAM param; + bool force_group_by = false; if (check_stack_overrun(thd, 2*STACK_MIN_SIZE + sizeof(PARAM), buff)) DBUG_RETURN(0); // Fatal error flag is set @@ -2555,15 +2556,20 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, Try to construct a QUICK_GROUP_MIN_MAX_SELECT. Notice that it can be constructed no matter if there is a range tree. */ + DBUG_EXECUTE_IF("force_group_by", force_group_by = true; ); group_trp= get_best_group_min_max(¶m, tree, best_read_time); if (group_trp) { param.table->quick_condition_rows= MY_MIN(group_trp->records, head->stat_records()); - if (group_trp->read_cost < best_read_time) + if (group_trp->read_cost < best_read_time || force_group_by) { best_trp= group_trp; best_read_time= best_trp->read_cost; + if (force_group_by) + { + goto force_plan; + } } } @@ -2663,6 +2669,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, } } +force_plan: thd->mem_root= param.old_root; /* If we got a read plan, create a quick select from it. */ @@ -11509,13 +11516,28 @@ int QUICK_RANGE_SELECT::get_next_prefix(uint prefix_length, DBUG_ASSERT(cur_prefix != NULL); result= file->ha_index_read_map(record, cur_prefix, keypart_map, HA_READ_AFTER_KEY); - if (result || last_range->max_keypart_map == 0) - DBUG_RETURN(result); - - key_range previous_endpoint; - last_range->make_max_endpoint(&previous_endpoint, prefix_length, keypart_map); - if (file->compare_key(&previous_endpoint) <= 0) - DBUG_RETURN(0); + if (result || last_range->max_keypart_map == 0) { + /* + Only return if actual failure occurred. For HA_ERR_KEY_NOT_FOUND + or HA_ERR_END_OF_FILE, we just want to continue to reach the next + set of ranges. It is possible for the storage engine to return + HA_ERR_KEY_NOT_FOUND/HA_ERR_END_OF_FILE even when there are more + keys if it respects the end range set by the read_range_first call + below. + */ + if (result != HA_ERR_KEY_NOT_FOUND && result != HA_ERR_END_OF_FILE) + DBUG_RETURN(result); + } else { + /* + For storage engines that don't respect end range, check if we've + moved past the current range. + */ + key_range previous_endpoint; + last_range->make_max_endpoint(&previous_endpoint, prefix_length, + keypart_map); + if (file->compare_key(&previous_endpoint) <= 0) + DBUG_RETURN(0); + } } uint count= ranges.elements - (uint)(cur_range - (QUICK_RANGE**) ranges.buffer); diff --git a/storage/rocksdb/mysql-test/rocksdb/include/group_min_max.inc b/storage/rocksdb/mysql-test/rocksdb/include/group_min_max.inc index 79ac367a73b..6c3e29537b1 100644 --- a/storage/rocksdb/mysql-test/rocksdb/include/group_min_max.inc +++ b/storage/rocksdb/mysql-test/rocksdb/include/group_min_max.inc @@ -266,6 +266,17 @@ select a1, max(c) from t2 where a1 in ('a','b','d') group by a1,a2,b; # B) Equalities only over the non-group 'B' attributes # plans +--echo # +--echo # MariaDB: we dont have the following patch: +--echo # +--echo # commit 60a92a79a3b7fde3c6efe91799e344b977c8e5c3 +--echo # Author: Manuel Ung +--echo # Date: Thu Apr 19 23:06:27 2018 -0700 +--echo # +--echo # Enhance group-by loose index scan +--echo # +--echo # So the following results are not very meaningful, but are still kept here + explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; @@ -730,9 +741,9 @@ explain extended select a1,a2,count(a2) from t1 where (a1 > 'a') group by a1,a2, explain extended select sum(ord(a1)) from t1 where (a1 > 'a') group by a1,a2,b; # test multi_range_groupby flag -set optimizer_switch = 'multi_range_groupby=off'; +#MariaDB: no support: set optimizer_switch = 'multi_range_groupby=off'; explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'a' or b = 'b') group by a1; -set optimizer_switch = 'default'; +#set optimizer_switch = 'default'; explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'a' or b = 'b') group by a1; @@ -1361,41 +1372,41 @@ drop table t1; eval CREATE TABLE t (a INT, b INT, KEY(a,b)) engine=$engine; INSERT INTO t VALUES (1,1), (2,2), (3,3), (4,4), (1,0), (3,2), (4,5); ANALYZE TABLE t; -let $DEFAULT_TRACE_MEM_SIZE=1048576; # 1MB -eval set optimizer_trace_max_mem_size=$DEFAULT_TRACE_MEM_SIZE; -set @@session.optimizer_trace='enabled=on'; -set end_markers_in_json=on; +# MariaDB: 10.2 doesn't have trace, yet: let $DEFAULT_TRACE_MEM_SIZE=1048576; # 1MB +# eval set optimizer_trace_max_mem_size=$DEFAULT_TRACE_MEM_SIZE; +# set @@session.optimizer_trace='enabled=on'; +# set end_markers_in_json=on; ANALYZE TABLE t; SELECT a, SUM(DISTINCT a), MIN(b) FROM t GROUP BY a; EXPLAIN SELECT a, SUM(DISTINCT a), MIN(b) FROM t GROUP BY a; -SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK - FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; +#SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK +# FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; SELECT a, SUM(DISTINCT a), MAX(b) FROM t GROUP BY a; EXPLAIN SELECT a, SUM(DISTINCT a), MAX(b) FROM t GROUP BY a; -SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK - FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; +#SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK +# FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; SELECT a, MAX(b) FROM t GROUP BY a HAVING SUM(DISTINCT a); EXPLAIN SELECT a, MAX(b) FROM t GROUP BY a HAVING SUM(DISTINCT a); -SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK - FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; +#SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK +# FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; SELECT SUM(DISTINCT a), MIN(b), MAX(b) FROM t; EXPLAIN SELECT SUM(DISTINCT a), MIN(b), MAX(b) FROM t; -SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK - FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; +#SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK +# FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; SELECT a, SUM(DISTINCT a), MIN(b), MAX(b) FROM t GROUP BY a; EXPLAIN SELECT a, SUM(DISTINCT a), MIN(b), MAX(b) FROM t GROUP BY a; -SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK - FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; +#SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK +# FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; -SET optimizer_trace_max_mem_size=DEFAULT; -SET optimizer_trace=DEFAULT; -SET end_markers_in_json=DEFAULT; +#SET optimizer_trace_max_mem_size=DEFAULT; +#SET optimizer_trace=DEFAULT; +#SET end_markers_in_json=DEFAULT; DROP TABLE t; diff --git a/storage/rocksdb/mysql-test/rocksdb/r/group_min_max.result b/storage/rocksdb/mysql-test/rocksdb/r/group_min_max.result index 7fede0ac603..a1031f518e0 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/group_min_max.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/group_min_max.result @@ -1,4 +1,5 @@ -set global debug="+d,force_group_by"; +set @debug_tmp= @@debug_dbug; +set global debug_dbug="+d,force_group_by"; drop table if exists t1; create table t1 ( a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(248) default ' ' @@ -134,34 +135,34 @@ Table Op Msg_type Msg_text test.t3 analyze status OK explain select a1, min(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using index for group-by explain select a1, max(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 65 NULL 126 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 65 NULL 63 Using index for group-by explain select a1, min(a2), max(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using index for group-by explain select a1, a2, b, min(c), max(c) from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by explain select a1,a2,b,max(c),min(c) from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by explain select a1,a2,b,max(c),min(c) from t2 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 # NULL # Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 # NULL # Using index for group-by explain select min(a2), a1, max(a2), min(a2), a1 from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using index for group-by explain select a1, b, min(c), a1, max(c), b, a2, max(c), max(c) from t1 group by a1, a2, b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by explain select min(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using index for group-by explain select a2, min(c), max(c) from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by select a1, min(a2) from t1 group by a1; a1 min(a2) a a @@ -288,37 +289,37 @@ b i421 l421 b m422 p422 explain select a1,a2,b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where a1 >= 'b' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 1002 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 502 Using where; Using index for group-by explain select a1, max(c) from t1 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 1002 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 502 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where a1 >= 'c' or a2 < 'b' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 1503 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 753 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 1503 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 753 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 2004 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 1004 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 2004 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 1004 Using where; Using index for group-by explain select a1,min(c),max(c) from t1 where a1 >= 'b' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1, max(c) from t1 where a1 in ('a','b','d') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 1503 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 753 Using where; Using index for group-by explain select a1,a2,b, max(c) from t2 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by @@ -668,99 +669,109 @@ d d411 d h412 d l421 d p422 +# +# MariaDB: we dont have the following patch: +# +# commit 60a92a79a3b7fde3c6efe91799e344b977c8e5c3 +# Author: Manuel Ung +# Date: Thu Apr 19 23:06:27 2018 -0700 +# +# Enhance group-by loose index scan +# +# So the following results are not very meaningful, but are still kept here explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 63 Using where; Using index for group-by explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a' or a2 = 'b') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index explain select a1,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 63 Using where; Using index for group-by explain select a1,max(c),min(c) from t1 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index explain select a1,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index explain select a1,a2,b, max(c) from t1 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 126 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,min(c),max(c) from t1 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 126 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index explain select a1,a2, max(c) from t1 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 126 Using where; Using index for group-by explain select a1,a2, max(c) from t1 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 63 Using where; Using index for group-by explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 63 Using where; Using index for group-by explain select a1,max(c),min(c) from t2 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b, max(c) from t2 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL 251 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL 126 Using where; Using index for group-by explain select a1,a2,b, max(c) from t2 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL 251 Using where; Using index for group-by +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,min(c),max(c) from t2 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 126 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2, max(c) from t2 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL 251 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL 126 Using where; Using index for group-by explain select a1,a2, max(c) from t2 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL 251 Using where; Using index for group-by +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 range idx_t3_0,idx_t3_1,idx_t3_2 idx_t3_1 6 NULL 126 Using where; Using index for group-by +1 SIMPLE t3 range NULL idx_t3_1 6 NULL 63 Using where; Using index for group-by explain select a1,a2,b,max(c),min(c) from t3 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 range idx_t3_0,idx_t3_1,idx_t3_2 idx_t3_1 6 NULL 126 Using where; Using index for group-by +1 SIMPLE t3 index NULL idx_t3_1 10 NULL 1000 Using where; Using index explain select a1,a2,b,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 range idx_t3_0,idx_t3_1,idx_t3_2 idx_t3_1 6 NULL 126 Using where; Using index for group-by +1 SIMPLE t3 index NULL idx_t3_1 10 NULL 1000 Using where; Using index explain select a1,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 range idx_t3_0,idx_t3_1,idx_t3_2 idx_t3_1 6 NULL 126 Using where; Using index for group-by +1 SIMPLE t3 range NULL idx_t3_1 6 NULL 63 Using where; Using index for group-by explain select a1,max(c),min(c) from t3 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 range idx_t3_0,idx_t3_1,idx_t3_2 idx_t3_1 6 NULL 126 Using where; Using index for group-by +1 SIMPLE t3 index NULL idx_t3_1 10 NULL 1000 Using where; Using index explain select a1,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 range idx_t3_0,idx_t3_1,idx_t3_2 idx_t3_1 6 NULL 126 Using where; Using index for group-by +1 SIMPLE t3 index NULL idx_t3_1 10 NULL 1000 Using where; Using index select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; a1 a2 b max(c) min(c) a a b h112 e112 @@ -769,22 +780,22 @@ c a b h312 e312 d a b h412 e412 select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; a1 a2 b max(c) min(c) -a b b p122 e112 -b b b p222 e212 -c b b p322 e312 -d b b p422 e412 +a a b p122 e112 +b a b p222 e212 +c a b p322 e312 +d a b p422 e412 select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; a1 a2 b max(c) min(c) -a a b h112 a111 -b a b h212 a211 -c a b h312 a311 -d a b h412 a411 +a a a h112 a111 +b a a h212 a211 +c a a h312 a311 +d a a h412 a411 select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a' or a2 = 'b') and (b = 'b' or b = 'a') group by a1; a1 a2 b max(c) min(c) -a b b p122 a111 -b b b p222 a211 -c b b p322 a311 -d b b p422 a411 +a a a p122 a111 +b a a p222 a211 +c a a p322 a311 +d a a p422 a411 select a1,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; a1 max(c) min(c) a h112 e112 @@ -815,14 +826,14 @@ d a b h412 d b b p422 select a1,a2,b, max(c) from t1 where (b = 'b' or b = 'a') group by a1,a2; a1 a2 b max(c) -a a b h112 -a b b p122 -b a b h212 -b b b p222 -c a b h312 -c b b p322 -d a b h412 -d b b p422 +a a a h112 +a b a p122 +b a a h212 +b b a p222 +c a a h312 +c b a p322 +d a a h412 +d b a p422 select a1,a2,b,min(c),max(c) from t1 where (b = 'b') group by a1,a2; a1 a2 b min(c) max(c) a a b e112 h112 @@ -835,14 +846,14 @@ d a b e412 h412 d b b m422 p422 select a1,a2,b,min(c),max(c) from t1 where (b = 'b' or b = 'a') group by a1,a2; a1 a2 b min(c) max(c) -a a b a111 h112 -a b b i121 p122 -b a b a211 h212 -b b b i221 p222 -c a b a311 h312 -c b b i321 p322 -d a b a411 h412 -d b b i421 p422 +a a a a111 h112 +a b a i121 p122 +b a a a211 h212 +b b a i221 p222 +c a a a311 h312 +c b a i321 p322 +d a a a411 h412 +d b a i421 p422 select a1,a2, max(c) from t1 where (b = 'b') group by a1,a2; a1 a2 max(c) a a h112 @@ -872,17 +883,18 @@ d a b h412 e412 e a b NULL NULL select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; a1 a2 b max(c) min(c) -a b b p122 e112 -b b b p222 e212 -c b b p322 e312 -d b b p422 e412 +a a b p122 e112 +b a b p222 e212 +c a b p322 e312 +d a b p422 e412 +e a b NULL NULL select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; a1 a2 b max(c) min(c) -a a b h112 a111 -b a b h212 a211 -c a b h312 a311 -d a b h412 a411 -e a b NULL NULL +a a a h112 a111 +b a a h212 a211 +c a a h312 a311 +d a a h412 a411 +e a a NULL NULL select a1,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') group by a1; a1 max(c) min(c) a h112 e112 @@ -896,6 +908,7 @@ a p122 e112 b p222 e212 c p322 e312 d p422 e412 +e NULL NULL select a1,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; a1 max(c) min(c) a h112 a111 @@ -916,15 +929,15 @@ d b b p422 e a b NULL select a1,a2,b, max(c) from t2 where (b = 'b' or b = 'a') group by a1,a2; a1 a2 b max(c) -a a b h112 -a b b p122 -b a b h212 -b b b p222 -c a b h312 -c b b p322 -d a b h412 -d b b p422 -e a b NULL +a a a h112 +a b a p122 +b a a h212 +b b a p222 +c a a h312 +c b a p322 +d a a h412 +d b a p422 +e a a NULL select a1,a2,b,min(c),max(c) from t2 where (b = 'b') group by a1,a2; a1 a2 b min(c) max(c) a a b e112 h112 @@ -938,15 +951,15 @@ d b b m422 p422 e a b NULL NULL select a1,a2,b,min(c),max(c) from t2 where (b = 'b' or b = 'a') group by a1,a2; a1 a2 b min(c) max(c) -a a b a111 h112 -a b b i121 p122 -b a b a211 h212 -b b b i221 p222 -c a b a311 h312 -c b b i321 p322 -d a b a411 h412 -d b b i421 p422 -e a b NULL NULL +a a a a111 h112 +a b a i121 p122 +b a a a211 h212 +b b a i221 p222 +c a a a311 h312 +c b a i321 p322 +d a a a411 h412 +d b a i421 p422 +e a a NULL NULL select a1,a2, max(c) from t2 where (b = 'b') group by a1,a2; a1 a2 max(c) a a h112 @@ -976,14 +989,14 @@ b a b h212 e212 c a b h312 e312 select a1,a2,b,max(c),min(c) from t3 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; a1 a2 b max(c) min(c) -a b b p122 e112 -b b b p222 e212 -c b b p322 e312 +a a b p122 e112 +b a b p222 e212 +c a b p322 e312 select a1,a2,b,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; a1 a2 b max(c) min(c) -a a b h112 a111 -b a b h212 a211 -c a b h312 a311 +a a a h112 a111 +b a a h212 a211 +c a a h312 a311 select a1,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b') group by a1; a1 max(c) min(c) a h112 e112 @@ -1001,37 +1014,41 @@ b h212 a211 c h312 a311 explain select a1,a2,b,min(c) from t2 where (a2 = 'a') and b is NULL group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 63 Using where; Using index for group-by explain select a1,a2,b,min(c) from t2 where (a2 = 'a' or a2 = 'b') and b is NULL group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,max(c) from t2 where (a2 = 'a') and b is NULL group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL 63 Using where; Using index for group-by explain select a1,a2,b,max(c) from t2 where (a2 = 'a' or a2 = 'b') and b is NULL group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,min(c) from t2 where b is NULL group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 126 Using where; Using index for group-by explain select a1,a2,b,max(c) from t2 where b is NULL group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL 251 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL 126 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where b is NULL group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 126 Using where; Using index for group-by select a1,a2,b,min(c) from t2 where (a2 = 'a') and b is NULL group by a1; a1 a2 b min(c) a a NULL a777 c a NULL c777 select a1,a2,b,min(c) from t2 where (a2 = 'a' or a2 = 'b') and b is NULL group by a1; a1 a2 b min(c) +a a NULL a777 +c a NULL c777 select a1,a2,b,max(c) from t2 where (a2 = 'a') and b is NULL group by a1; a1 a2 b max(c) a a NULL a999 c a NULL c999 select a1,a2,b,max(c) from t2 where (a2 = 'a' or a2 = 'b') and b is NULL group by a1; a1 a2 b max(c) +a a NULL a999 +c a NULL c999 select a1,a2,b,min(c) from t2 where b is NULL group by a1,a2; a1 a2 b min(c) a a NULL a777 @@ -1050,97 +1067,97 @@ a a NULL a777 a999 c a NULL c777 c999 explain select a1,a2,b, max(c) from t1 where (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL # Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (c > 'f123') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c > 'f123') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (c < 'a0') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (c < 'k321') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c < 'k321') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b111') and (c <= 'g112') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c < 'c5') or (c = 'g412') or (c = 'k421') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where ((c > 'b111') and (c <= 'g112')) or ((c > 'd000') and (c <= 'i110')) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c between 'b111' and 'g112') or (c between 'd000' and 'i110') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b, max(c) from t2 where (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b, max(c) from t2 where (c > 'f123') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (c > 'f123') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b, max(c) from t2 where (c < 'a0') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (c < 'a0') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b, max(c) from t2 where (c < 'k321') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (c < 'k321') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b, max(c) from t2 where (c < 'a0') or (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (c < 'a0') or (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b, max(c) from t2 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (c > 'b111') and (c <= 'g112') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (c < 'c5') or (c = 'g412') or (c = 'k421') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where ((c > 'b111') and (c <= 'g112')) or ((c > 'd000') and (c <= 'i110')) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by select a1,a2,b, max(c) from t1 where (c > 'b1') group by a1,a2,b; a1 a2 b max(c) a a a d111 @@ -1562,35 +1579,36 @@ explain select a1,a2,b,min(c),max(c) from t1 where exists ( select * from t2 where t2.c = t1.c ) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 index idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 1000 Using where; Using index -2 DEPENDENT SUBQUERY t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 PRIMARY t1 index NULL idx_t1_1 163 NULL 1000 Using index +1 PRIMARY eq_ref distinct_key distinct_key 16 func 1 +2 MATERIALIZED t2 index NULL idx_t2_1 163 NULL 1000 Using index explain select a1,a2,b,min(c),max(c) from t1 where exists ( select * from t2 where t2.c > 'b1' ) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using index for group-by +1 PRIMARY t1 index NULL idx_t1_1 163 NULL 1000 Using index 2 SUBQUERY t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (c > 'b111') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c) from t1 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c < 'h112') or (c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122')) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 1002 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 502 Using where; Using index for group-by explain select a1,a2,b,min(c) from t1 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122') or (c < 'h112') or (c = 'c111')) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 1002 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 502 Using where; Using index for group-by explain select a1,a2,b,min(c) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c) from t1 where (ord(a1) > 97) and (ord(a2) + ord(a1) > 194) and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by @@ -1599,7 +1617,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c) from t2 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c < 'h112') or (c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122')) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by @@ -1695,31 +1713,31 @@ select a1,a2,b,min(c) from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') grou a1 a2 b min(c) explain select a1,a2,b from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121' or c = 'i121') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select a1,a2,b from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by explain select a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by explain select a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121' or c = 'i121') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by @@ -1770,50 +1788,50 @@ select a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1 a1 a2 b explain select distinct a1,a2,b from t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by explain select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by explain extended select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range idx_t1_1 idx_t1_1 163 NULL 1001 99.90 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 501 100.00 Using where; Using index for group-by Warnings: -Note 1003 /* select#1 */ select distinct `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where ((`test`.`t1`.`c` = 'i121') and (`test`.`t1`.`b` = 'a') and (`test`.`t1`.`a2` >= 'b')) +Note 1003 select distinct `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`b` = 'a' and `test`.`t1`.`c` = 'i121' and `test`.`t1`.`a2` >= 'b' explain select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select distinct b from t1 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 Using where; Using index explain select distinct a1 from t1 where a1 in ('a', 'd') and a2 = 'b'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 252 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using where; Using index for group-by explain select distinct a1 from t1 where a1 in ('a', 'd') and a2 = 'e'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 252 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using where; Using index for group-by explain select distinct a1,a2,b from t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using index for group-by explain select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by explain extended select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 range idx_t2_1 idx_t2_1 163 NULL 1001 99.90 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 501 100.00 Using where; Using index for group-by Warnings: -Note 1003 /* select#1 */ select distinct `test`.`t2`.`a1` AS `a1`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where ((`test`.`t2`.`c` = 'i121') and (`test`.`t2`.`b` = 'a') and (`test`.`t2`.`a2` >= 'b')) +Note 1003 select distinct `test`.`t2`.`a1` AS `a1`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where `test`.`t2`.`b` = 'a' and `test`.`t2`.`c` = 'i121' and `test`.`t2`.`a2` >= 'b' explain select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by explain select distinct b from t2 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx_t2_1,idx_t2_2 idx_t2_2 146 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_2 146 NULL 1000 Using where; Using index explain select distinct a1 from t2 where a1 in ('a', 'd') and a2 = 'b'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 129 NULL 252 Using where; Using index for group-by +1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 129 NULL 126 Using where; Using index for group-by explain select distinct a1 from t2 where a1 in ('a', 'd') and a2 = 'e'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 129 NULL 252 Using where; Using index for group-by +1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 129 NULL 126 Using where; Using index for group-by select distinct a1,a2,b from t1; a1 a2 b a a a @@ -1942,40 +1960,40 @@ c e d e explain select distinct a1,a2,b from t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by explain select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by explain select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select distinct b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by; Using temporary; Using filesort +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by; Using temporary; Using filesort explain select distinct a1 from t1 where a1 in ('a', 'd') and a2 = 'b' group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 252 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using where; Using index for group-by explain select distinct a1 from t1 where a1 in ('a', 'd') and a2 = 'e' group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 252 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using where; Using index for group-by explain select distinct a1,a2,b from t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using index for group-by explain select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by explain select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by explain select distinct b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by; Using temporary; Using filesort +1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by; Using temporary; Using filesort explain select distinct a1 from t2 where a1 in ('a', 'd') and a2 = 'b' group by a1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 129 NULL # Using where; Using index for group-by @@ -2064,23 +2082,23 @@ select distinct a1 from t2 where a1 in ('a', 'd') and a2 = 'e' group by a1; a1 explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by (scanning) +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1 idx_t1_1 163 NULL 1001 Using where; Using index for group-by (scanning) +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 501 Using where; Using index for group-by (scanning) explain extended select count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 100.00 Using where; Using index for group-by (scanning) +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 100.00 Using where; Using index for group-by Warnings: -Note 1003 /* select#1 */ select count(distinct `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`) AS `count(distinct a1,a2,b)` from `test`.`t1` where ((`test`.`t1`.`b` = 'c') and (`test`.`t1`.`a1` > 'a') and (`test`.`t1`.`a2` > 'a')) +Note 1003 select count(distinct `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`) AS `count(distinct a1,a2,b)` from `test`.`t1` where `test`.`t1`.`b` = 'c' and `test`.`t1`.`a1` > 'a' and `test`.`t1`.`a2` > 'a' explain select count(distinct b) from t1 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 Using where; Using index explain extended select 98 + count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 100.00 Using where; Using index for group-by (scanning) +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 100.00 Using where; Using index for group-by Warnings: -Note 1003 /* select#1 */ select (98 + count(distinct `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`)) AS `98 + count(distinct a1,a2,b)` from `test`.`t1` where ((`test`.`t1`.`a1` > 'a') and (`test`.`t1`.`a2` > 'a')) +Note 1003 select 98 + count(distinct `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`) AS `98 + count(distinct a1,a2,b)` from `test`.`t1` where `test`.`t1`.`a1` > 'a' and `test`.`t1`.`a2` > 'a' select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); count(distinct a1,a2,b) 4 @@ -2098,19 +2116,19 @@ select 98 + count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a'); 104 explain select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select concat(a1,min(c)),b from t1 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select concat(a1,min(c)),b,max(c) from t1 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select concat(a1,a2),b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by explain select concat(ord(min(b)),ord(max(b))),min(b),max(b) from t1 group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 126 Using index for group-by select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b; a1 a2 b concat(min(c), max(c)) a a a a111d111 @@ -2179,85 +2197,83 @@ concat(ord(min(b)),ord(max(b))) min(b) max(b) 9798 a b explain select a1,a2,b,d,min(c),max(c) from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 1000 NULL +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 explain select a1,a2,b,d from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 1000 NULL +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 explain extended select a1,a2,min(b),max(b) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 1000 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,min(`test`.`t1`.`b`) AS `min(b)`,max(`test`.`t1`.`b`) AS `max(b)` from `test`.`t1` where (((`test`.`t1`.`a1` = 'b') or (`test`.`t1`.`a1` = 'd') or (`test`.`t1`.`a1` = 'a') or (`test`.`t1`.`a1` = 'c')) and (`test`.`t1`.`a2` > 'a') and (`test`.`t1`.`c` > 'a111')) group by `test`.`t1`.`a1`,`test`.`t1`.`a2` +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,min(`test`.`t1`.`b`) AS `min(b)`,max(`test`.`t1`.`b`) AS `max(b)` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2` explain extended select a1,a2,b,min(c),max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 1000 100.00 Using where Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,min(`test`.`t1`.`c`) AS `min(c)`,max(`test`.`t1`.`c`) AS `max(c)` from `test`.`t1` where (((`test`.`t1`.`a1` = 'b') or (`test`.`t1`.`a1` = 'd') or (`test`.`t1`.`a1` = 'a') or (`test`.`t1`.`a1` = 'c')) and (`test`.`t1`.`a2` > 'a') and (`test`.`t1`.`d` > 'xy2')) group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,min(`test`.`t1`.`c`) AS `min(c)`,max(`test`.`t1`.`c`) AS `max(c)` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`d` > 'xy2' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` explain extended select a1,a2,b,c from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b,c; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 1000 100.00 Using where Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (((`test`.`t1`.`a1` = 'b') or (`test`.`t1`.`a1` = 'd') or (`test`.`t1`.`a1` = 'a') or (`test`.`t1`.`a1` = 'c')) and (`test`.`t1`.`a2` > 'a') and (`test`.`t1`.`d` > 'xy2')) group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`,`test`.`t1`.`c` +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`d` > 'xy2' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`,`test`.`t1`.`c` explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') or (b < 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_0 65 NULL 1000 Using where +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b < 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_0 65 NULL 1000 Using where +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b <= 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_0 65 NULL 1000 Using where +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b <= 'b' and b >= 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_0 65 NULL 1000 Using where +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain extended select a1,a2,b from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 1000 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (((`test`.`t1`.`a1` = 'b') or (`test`.`t1`.`a1` = 'd') or (`test`.`t1`.`a1` = 'a') or (`test`.`t1`.`a1` = 'c')) and (`test`.`t1`.`a2` > 'a') and (`test`.`t1`.`c` > 'a111')) group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` explain select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_0 65 NULL 1000 Using where +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1; a1 a2 min(b) c a a a a111 explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') or (b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_0 65 NULL 1000 Using where +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,min(c),max(c) from t2 where (c > 'a000') and (c <= 'd999') and (c like '_8__') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1, a2, b, c, min(d), max(d) from t1 group by a1,a2,b,c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index idx_t1_1 idx_t1_1 163 NULL 1000 NULL +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 explain select a1,a2,count(a2) from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 1000 Using index +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 Using index explain extended select a1,a2,count(a2) from t1 where (a1 > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 1000 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,count(`test`.`t1`.`a2`) AS `count(a2)` from `test`.`t1` where (`test`.`t1`.`a1` > 'a') group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,count(`test`.`t1`.`a2`) AS `count(a2)` from `test`.`t1` where `test`.`t1`.`a1` > 'a' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` explain extended select sum(ord(a1)) from t1 where (a1 > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 1000 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select sum(ord(`test`.`t1`.`a1`)) AS `sum(ord(a1))` from `test`.`t1` where (`test`.`t1`.`a1` > 'a') group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` -set optimizer_switch = 'multi_range_groupby=off'; +Note 1003 select sum(ord(`test`.`t1`.`a1`)) AS `sum(ord(a1))` from `test`.`t1` where `test`.`t1`.`a1` > 'a' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'a' or b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_0 65 NULL 1000 Using where -set optimizer_switch = 'default'; +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'a' or b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index explain select distinct(a1) from t1 where ord(a2) = 98; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_0 65 NULL 1000 Using where +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 Using where; Using index select distinct(a1) from t1 where ord(a2) = 98; a1 a @@ -2266,7 +2282,7 @@ c d explain select a1 from t1 where a2 = 'b' group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using where; Using index for group-by select a1 from t1 where a2 = 'b' group by a1; a1 a @@ -2275,7 +2291,7 @@ c d explain select distinct a1 from t1 where a2 = 'b'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using where; Using index for group-by select distinct a1 from t1 where a2 = 'b'; a1 a @@ -2385,7 +2401,7 @@ INSERT INTO t1 (a) VALUES ('SOUTH EAST'), ('SOUTH WEST'), ('WESTERN'); EXPLAIN SELECT DISTINCT a,a FROM t1 ORDER BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 66 NULL 1001 Using index for group-by +1 SIMPLE t1 index NULL PRIMARY 66 NULL 1000 Using index SELECT DISTINCT a,a FROM t1 ORDER BY a; a a @@ -2477,7 +2493,7 @@ Table Op Msg_type Msg_text test.t1 analyze status OK EXPLAIN SELECT max(b), a FROM t1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 5 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by FLUSH STATUS; SELECT max(b), a FROM t1 GROUP BY a; max(b) a @@ -2489,15 +2505,17 @@ SHOW STATUS LIKE 'handler_read__e%'; Variable_name Value Handler_read_key 8 Handler_read_next 0 +Handler_read_retry 0 EXPLAIN SELECT max(b), a FROM t1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 5 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by FLUSH STATUS; CREATE TABLE t2 engine=RocksDB SELECT max(b), a FROM t1 GROUP BY a; SHOW STATUS LIKE 'handler_read__e%'; Variable_name Value Handler_read_key 8 Handler_read_next 0 +Handler_read_retry 0 FLUSH STATUS; SELECT * FROM (SELECT max(b), a FROM t1 GROUP BY a) b; max(b) a @@ -2509,6 +2527,7 @@ SHOW STATUS LIKE 'handler_read__e%'; Variable_name Value Handler_read_key 8 Handler_read_next 0 +Handler_read_retry 0 FLUSH STATUS; (SELECT max(b), a FROM t1 GROUP BY a) UNION (SELECT max(b), a FROM t1 GROUP BY a); @@ -2521,50 +2540,52 @@ SHOW STATUS LIKE 'handler_read__e%'; Variable_name Value Handler_read_key 16 Handler_read_next 0 +Handler_read_retry 0 EXPLAIN (SELECT max(b), a FROM t1 GROUP BY a) UNION (SELECT max(b), a FROM t1 GROUP BY a); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 range a a 5 NULL 501 Using index for group-by -2 UNION t1 range a a 5 NULL 501 Using index for group-by -NULL UNION RESULT ALL NULL NULL NULL NULL NULL Using temporary +1 PRIMARY t1 range NULL a 5 NULL 251 Using index for group-by +2 UNION t1 range NULL a 5 NULL 251 Using index for group-by +NULL UNION RESULT ALL NULL NULL NULL NULL NULL EXPLAIN SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x FROM t1 AS t1_outer; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1_outer index NULL a 10 NULL 1000 Using index -2 SUBQUERY t1 range a a 5 NULL 501 Using index for group-by +2 SUBQUERY t1 range NULL a 5 NULL 251 Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE EXISTS (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1_outer index NULL a 10 NULL 1000 Using index -2 SUBQUERY t1 range a a 5 NULL 501 Using index for group-by +2 SUBQUERY t1 index NULL a 10 NULL 1000 Using index EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE -2 SUBQUERY t1 range a a 5 NULL 501 Using index for group-by +1 PRIMARY t1_outer index NULL a 10 NULL 1000 Using index +2 SUBQUERY t1 range NULL a 5 NULL 251 Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE a IN (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer index NULL a 10 NULL 1000 Using where; Using index -2 SUBQUERY t1 range a a 5 NULL 501 Using index for group-by +1 PRIMARY ALL distinct_key NULL NULL NULL 251 +1 PRIMARY t1_outer ref a a 5 .max(b) 4 Using index +2 MATERIALIZED t1 range NULL a 5 NULL 251 Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer GROUP BY a HAVING a > (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer range a a 5 NULL 501 Using index for group-by -2 SUBQUERY t1 range a a 5 NULL 501 Using index for group-by +1 PRIMARY t1_outer range NULL a 5 NULL 251 Using index for group-by +2 SUBQUERY t1 range NULL a 5 NULL 251 Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer1 JOIN t1 AS t1_outer2 ON t1_outer1.a = (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) AND t1_outer1.b = t1_outer2.b; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer2 index NULL a 10 NULL 1000 Using where; Using index -1 PRIMARY t1_outer1 ref a a 10 const,test.t1_outer2.b 1 Using where; Using index -2 SUBQUERY t1 range a a 5 NULL 501 Using index for group-by +1 PRIMARY t1_outer1 ref a a 5 const 4 Using where; Using index +1 PRIMARY t1_outer2 index NULL a 10 NULL 1000 Using where; Using index; Using join buffer (flat, BNL join) +2 SUBQUERY t1 range NULL a 5 NULL 251 Using index for group-by EXPLAIN SELECT (SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x FROM t1 AS t1_outer) x2 FROM t1 AS t1_outer2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1_outer2 index NULL a 10 NULL 1000 Using index 2 SUBQUERY t1_outer index NULL a 10 NULL 1000 Using index -3 SUBQUERY t1 range a a 5 NULL 501 Using index for group-by +3 SUBQUERY t1 range NULL a 5 NULL 251 Using index for group-by CREATE TABLE t3 LIKE t1; FLUSH STATUS; INSERT INTO t3 SELECT a,MAX(b) FROM t1 GROUP BY a; @@ -2572,6 +2593,7 @@ SHOW STATUS LIKE 'handler_read__e%'; Variable_name Value Handler_read_key 8 Handler_read_next 0 +Handler_read_retry 0 DELETE FROM t3; FLUSH STATUS; INSERT INTO t3 SELECT 1, (SELECT MAX(b) FROM t1 GROUP BY a HAVING a < 2) @@ -2580,12 +2602,14 @@ SHOW STATUS LIKE 'handler_read__e%'; Variable_name Value Handler_read_key 8 Handler_read_next 0 +Handler_read_retry 0 FLUSH STATUS; DELETE FROM t3 WHERE (SELECT MAX(b) FROM t1 GROUP BY a HAVING a < 2) > 10000; SHOW STATUS LIKE 'handler_read__e%'; Variable_name Value Handler_read_key 8 Handler_read_next 0 +Handler_read_retry 0 FLUSH STATUS; DELETE FROM t3 WHERE (SELECT (SELECT MAX(b) FROM t1 GROUP BY a HAVING a < 2) x FROM t1) > 10000; @@ -2594,6 +2618,7 @@ SHOW STATUS LIKE 'handler_read__e%'; Variable_name Value Handler_read_key 8 Handler_read_next 1 +Handler_read_retry 0 DROP TABLE t1,t2,t3; CREATE TABLE t1 (a int, INDEX idx(a)) engine=RocksDB; INSERT INTO t1 VALUES @@ -2604,7 +2629,7 @@ Table Op Msg_type Msg_text test.t1 analyze status OK EXPLAIN SELECT DISTINCT(a) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx idx 5 NULL 1001 Using index for group-by +1 SIMPLE t1 range NULL idx 5 NULL 501 Using index for group-by SELECT DISTINCT(a) FROM t1; a 1 @@ -2612,7 +2637,7 @@ a 4 EXPLAIN SELECT SQL_BIG_RESULT DISTINCT(a) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx idx 5 NULL 1001 Using index for group-by +1 SIMPLE t1 range NULL idx 5 NULL 501 Using index for group-by SELECT SQL_BIG_RESULT DISTINCT(a) FROM t1; a 1 @@ -2640,7 +2665,7 @@ CREATE INDEX break_it ON t1 (a, b); EXPLAIN SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range break_it break_it 10 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL break_it 10 NULL 251 Using index for group-by SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a; a MIN(b) MAX(b) 1 1 3 @@ -2650,7 +2675,7 @@ a MIN(b) MAX(b) EXPLAIN SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a DESC; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range break_it break_it 10 NULL 501 Using index for group-by; Using temporary; Using filesort +1 SIMPLE t1 range NULL break_it 10 NULL 251 Using index for group-by; Using temporary; Using filesort SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a DESC; a MIN(b) MAX(b) 4 1 3 @@ -2660,7 +2685,7 @@ a MIN(b) MAX(b) EXPLAIN SELECT a, MIN(b), MAX(b), AVG(b) FROM t1 GROUP BY a ORDER BY a DESC; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index break_it break_it 10 NULL 1000 Using index +1 SIMPLE t1 index NULL break_it 10 NULL 1000 Using index SELECT a, MIN(b), MAX(b), AVG(b) FROM t1 GROUP BY a ORDER BY a DESC; a MIN(b) MAX(b) AVG(b) 4 1 3 2.0000 @@ -2743,9 +2768,9 @@ a b 3 13 explain extended select sql_buffer_result a, max(b)+1 from t1 where a = 0 group by a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range PRIMARY,index PRIMARY 4 NULL 1 100.00 Using where; Using index for group-by; Using temporary +1 SIMPLE t1 ref PRIMARY,index PRIMARY 4 const 15 100.00 Using index; Using temporary Warnings: -Note 1003 /* select#1 */ select sql_buffer_result `test`.`t1`.`a` AS `a`,(max(`test`.`t1`.`b`) + 1) AS `max(b)+1` from `test`.`t1` where (`test`.`t1`.`a` = 0) group by `test`.`t1`.`a` +Note 1003 select sql_buffer_result `test`.`t1`.`a` AS `a`,max(`test`.`t1`.`b`) + 1 AS `max(b)+1` from `test`.`t1` where `test`.`t1`.`a` = 0 group by `test`.`t1`.`a` drop table t1; CREATE TABLE t1 (a int, b int, c int, d int, KEY foo (c,d,a,b), KEY bar (c,a,b,d)) engine=RocksDB; @@ -2758,7 +2783,7 @@ Table Op Msg_type Msg_text test.t1 analyze status OK EXPLAIN SELECT DISTINCT c FROM t1 WHERE d=4; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range foo,bar foo 10 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range NULL foo 10 NULL 63 Using where; Using index for group-by SELECT DISTINCT c FROM t1 WHERE d=4; c 1 @@ -2780,7 +2805,7 @@ test.t analyze status OK EXPLAIN SELECT a, MIN(b) FROM t WHERE b <> 0 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t range a a 10 NULL 501 Using where; Using index for group-by +1 SIMPLE t range NULL a 10 NULL 251 Using where; Using index for group-by #should return 1 row SELECT a, MIN(b) FROM t WHERE b <> 0 GROUP BY a; a MIN(b) @@ -2790,7 +2815,7 @@ a MIN(b) EXPLAIN SELECT a, MAX(b) FROM t WHERE b <> 1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t range a a 10 NULL 501 Using where; Using index for group-by +1 SIMPLE t range NULL a 10 NULL 251 Using where; Using index for group-by #should return 1 row SELECT a, MAX(b) FROM t WHERE b <> 1 GROUP BY a; a MAX(b) @@ -2801,7 +2826,7 @@ INSERT INTO t SELECT a, 2 FROM t; EXPLAIN SELECT a, MAX(b) FROM t WHERE b > 0 AND b < 2 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t range a a 10 NULL 501 Using where; Using index for group-by +1 SIMPLE t range NULL a 10 NULL 251 Using where; Using index for group-by #should return 1 row SELECT a, MAX(b) FROM t WHERE b > 0 AND b < 2 GROUP BY a; a MAX(b) @@ -2915,7 +2940,7 @@ NULL EXPLAIN SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); id select_type table type possible_keys key key_len ref rows Extra -x x x x x x x x x Impossible WHERE noticed after reading const tables +x x x x x x x x x Using where; Using index x x x x x x x x x Using where; Using index SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); MIN( a ) @@ -2990,7 +3015,7 @@ NULL EXPLAIN SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); id select_type table type possible_keys key key_len ref rows Extra -x x x x x x x x x Impossible WHERE noticed after reading const tables +x x x x x x x x x Using where; Using index x x x x x x x x x Using where; Using index SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); MIN( a ) @@ -3072,7 +3097,7 @@ NULL EXPLAIN SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); id select_type table type possible_keys key key_len ref rows Extra -x x x x x x x x x Impossible WHERE noticed after reading const tables +x x x x x x x x x Using where; Using index x x x x x x x x x Using where; Using index SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); MIN( a ) @@ -3119,45 +3144,45 @@ Table Op Msg_type Msg_text test.t2 analyze status OK EXPLAIN SELECT COUNT(DISTINCT a) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 5 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by SELECT COUNT(DISTINCT a) FROM t1; COUNT(DISTINCT a) 2 EXPLAIN SELECT COUNT(DISTINCT a,b) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 10 NULL 1001 Using index for group-by (scanning) +1 SIMPLE t1 range NULL a 10 NULL 501 Using index for group-by SELECT COUNT(DISTINCT a,b) FROM t1; COUNT(DISTINCT a,b) 16 EXPLAIN SELECT COUNT(DISTINCT b,a) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 10 NULL 1001 Using index for group-by (scanning) +1 SIMPLE t1 range NULL a 10 NULL 501 Using index for group-by SELECT COUNT(DISTINCT b,a) FROM t1; COUNT(DISTINCT b,a) 16 EXPLAIN SELECT COUNT(DISTINCT b) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index a a 10 NULL 1000 Using index +1 SIMPLE t1 index NULL a 10 NULL 1000 Using index SELECT COUNT(DISTINCT b) FROM t1; COUNT(DISTINCT b) 8 EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 5 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by SELECT COUNT(DISTINCT a) FROM t1 GROUP BY a; COUNT(DISTINCT a) 1 1 EXPLAIN SELECT COUNT(DISTINCT b) FROM t1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 10 NULL 1001 Using index for group-by (scanning) +1 SIMPLE t1 range NULL a 10 NULL 501 Using index for group-by SELECT COUNT(DISTINCT b) FROM t1 GROUP BY a; COUNT(DISTINCT b) 8 8 EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 GROUP BY b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index a a 10 NULL 1000 Using index; Using filesort +1 SIMPLE t1 index NULL a 10 NULL 1000 Using index; Using filesort SELECT COUNT(DISTINCT a) FROM t1 GROUP BY b; COUNT(DISTINCT a) 2 @@ -3170,7 +3195,7 @@ COUNT(DISTINCT a) 2 EXPLAIN SELECT DISTINCT COUNT(DISTINCT a) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index a a 10 NULL 1000 Using index +1 SIMPLE t1 index NULL a 10 NULL 1000 Using index SELECT DISTINCT COUNT(DISTINCT a) FROM t1; COUNT(DISTINCT a) 2 @@ -3188,76 +3213,76 @@ COUNT(DISTINCT a) 2 EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 HAVING COUNT(DISTINCT c) < 10; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 NULL +1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 SELECT COUNT(DISTINCT a) FROM t1 HAVING COUNT(DISTINCT c) < 10; COUNT(DISTINCT a) 2 EXPLAIN SELECT 1 FROM t1 HAVING COUNT(DISTINCT a) < 10; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 5 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by SELECT 1 FROM t1 HAVING COUNT(DISTINCT a) < 10; 1 1 EXPLAIN SELECT 1 FROM t1 GROUP BY a HAVING COUNT(DISTINCT b) > 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 10 NULL 1001 Using index for group-by (scanning) +1 SIMPLE t1 range NULL a 10 NULL 501 Using index for group-by SELECT 1 FROM t1 GROUP BY a HAVING COUNT(DISTINCT b) > 1; 1 1 1 EXPLAIN SELECT COUNT(DISTINCT t1_1.a) FROM t1 t1_1, t1 t1_2 GROUP BY t1_1.a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1_1 index a a 10 NULL 1000 Using index; Using temporary; Using filesort -1 SIMPLE t1_2 index NULL a 10 NULL 1000 Using index; Using join buffer (Block Nested Loop) +1 SIMPLE t1_1 index NULL a 10 NULL 1000 Using index; Using temporary; Using filesort +1 SIMPLE t1_2 index NULL a 10 NULL 1000 Using index; Using join buffer (flat, BNL join) SELECT COUNT(DISTINCT t1_1.a) FROM t1 t1_1, t1 t1_2 GROUP BY t1_1.a; COUNT(DISTINCT t1_1.a) 1 1 EXPLAIN SELECT COUNT(DISTINCT a), 12 FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 5 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by SELECT COUNT(DISTINCT a), 12 FROM t1; COUNT(DISTINCT a) 12 2 12 EXPLAIN SELECT COUNT(DISTINCT a, b, c) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a a 15 NULL 1001 Using index for group-by (scanning) +1 SIMPLE t2 range NULL a 15 NULL 501 Using index for group-by SELECT COUNT(DISTINCT a, b, c) FROM t2; COUNT(DISTINCT a, b, c) 16 EXPLAIN SELECT COUNT(DISTINCT a), SUM(DISTINCT a), AVG(DISTINCT a) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a a 5 NULL 251 Using index for group-by +1 SIMPLE t2 range NULL a 5 NULL 126 Using index for group-by SELECT COUNT(DISTINCT a), SUM(DISTINCT a), AVG(DISTINCT a) FROM t2; COUNT(DISTINCT a) SUM(DISTINCT a) AVG(DISTINCT a) 2 3 1.5000 EXPLAIN SELECT COUNT(DISTINCT a), SUM(DISTINCT a), AVG(DISTINCT f) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 NULL +1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 SELECT COUNT(DISTINCT a), SUM(DISTINCT a), AVG(DISTINCT f) FROM t2; COUNT(DISTINCT a) SUM(DISTINCT a) AVG(DISTINCT f) 2 3 1.0000 EXPLAIN SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, a) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a a 10 NULL 501 Using index for group-by (scanning) +1 SIMPLE t2 range NULL a 10 NULL 251 Using index for group-by SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, a) FROM t2; COUNT(DISTINCT a, b) COUNT(DISTINCT b, a) 16 16 EXPLAIN SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, f) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 NULL +1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, f) FROM t2; COUNT(DISTINCT a, b) COUNT(DISTINCT b, f) 16 8 EXPLAIN SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, d) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 NULL +1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, d) FROM t2; COUNT(DISTINCT a, b) COUNT(DISTINCT b, d) 16 8 EXPLAIN SELECT a, c, COUNT(DISTINCT c, a, b) FROM t2 GROUP BY a, b, c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a a 15 NULL 1001 Using index for group-by (scanning) +1 SIMPLE t2 range NULL a 15 NULL 501 Using index for group-by SELECT a, c, COUNT(DISTINCT c, a, b) FROM t2 GROUP BY a, b, c; a c COUNT(DISTINCT c, a, b) 1 1 1 @@ -3279,7 +3304,7 @@ a c COUNT(DISTINCT c, a, b) EXPLAIN SELECT COUNT(DISTINCT c, a, b) FROM t2 WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a a 15 NULL 1001 Using where; Using index for group-by (scanning) +1 SIMPLE t2 range a a 15 NULL 501 Using where; Using index for group-by SELECT COUNT(DISTINCT c, a, b) FROM t2 WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; COUNT(DISTINCT c, a, b) @@ -3292,28 +3317,28 @@ GROUP BY b; COUNT(DISTINCT b) SUM(DISTINCT b) EXPLAIN SELECT a, COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a a 10 NULL 501 Using index for group-by (scanning) +1 SIMPLE t2 range NULL a 10 NULL 251 Using index for group-by SELECT a, COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a; a COUNT(DISTINCT b) SUM(DISTINCT b) 1 8 36 2 8 36 EXPLAIN SELECT COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a a 10 NULL 501 Using index for group-by (scanning) +1 SIMPLE t2 range NULL a 10 NULL 251 Using index for group-by SELECT COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a; COUNT(DISTINCT b) SUM(DISTINCT b) 8 36 8 36 EXPLAIN SELECT COUNT(DISTINCT a, b) FROM t2 WHERE c = 13 AND d = 42; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL a NULL NULL NULL 1000 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 Using where SELECT COUNT(DISTINCT a, b) FROM t2 WHERE c = 13 AND d = 42; COUNT(DISTINCT a, b) 0 EXPLAIN SELECT a, COUNT(DISTINCT a), SUM(DISTINCT a) FROM t2 WHERE b = 13 AND c = 42 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a a 15 NULL 251 Using where; Using index for group-by +1 SIMPLE t2 range NULL a 15 NULL 126 Using where; Using index for group-by SELECT a, COUNT(DISTINCT a), SUM(DISTINCT a) FROM t2 WHERE b = 13 AND c = 42 GROUP BY a; a COUNT(DISTINCT a) SUM(DISTINCT a) @@ -3327,14 +3352,14 @@ COUNT(DISTINCT a, b) SUM(DISTINCT a) 0 NULL EXPLAIN SELECT SUM(DISTINCT a), MAX(b) FROM t2 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index a a 15 NULL 1000 Using index +1 SIMPLE t2 index NULL a 15 NULL 1000 Using index SELECT SUM(DISTINCT a), MAX(b) FROM t2 GROUP BY a; SUM(DISTINCT a) MAX(b) 1 8 2 8 EXPLAIN SELECT 42 * (a + c + COUNT(DISTINCT c, a, b)) FROM t2 GROUP BY a, b, c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a a 15 NULL 1001 Using index for group-by (scanning) +1 SIMPLE t2 range NULL a 15 NULL 501 Using index for group-by SELECT 42 * (a + c + COUNT(DISTINCT c, a, b)) FROM t2 GROUP BY a, b, c; 42 * (a + c + COUNT(DISTINCT c, a, b)) 126 @@ -3355,7 +3380,7 @@ SELECT 42 * (a + c + COUNT(DISTINCT c, a, b)) FROM t2 GROUP BY a, b, c; 168 EXPLAIN SELECT (SUM(DISTINCT a) + MAX(b)) FROM t2 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index a a 15 NULL 1000 Using index +1 SIMPLE t2 index NULL a 15 NULL 1000 Using index SELECT (SUM(DISTINCT a) + MAX(b)) FROM t2 GROUP BY a; (SUM(DISTINCT a) + MAX(b)) 9 @@ -3383,7 +3408,7 @@ f1 COUNT(DISTINCT f2) 3 4 explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index PRIMARY PRIMARY 5 NULL 1000 Using index +1 SIMPLE t1 index NULL PRIMARY 5 NULL 1000 Using index drop table t1; # End of test#50539. # @@ -3395,9 +3420,6 @@ INSERT INTO t VALUES (1,1), (2,2), (3,3), (4,4), (1,0), (3,2), (4,5); ANALYZE TABLE t; Table Op Msg_type Msg_text test.t analyze status OK -set optimizer_trace_max_mem_size=1048576; -set @@session.optimizer_trace='enabled=on'; -set end_markers_in_json=on; ANALYZE TABLE t; Table Op Msg_type Msg_text test.t analyze status OK @@ -3409,11 +3431,7 @@ a SUM(DISTINCT a) MIN(b) 4 4 4 EXPLAIN SELECT a, SUM(DISTINCT a), MIN(b) FROM t GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t index a a 10 NULL 1000 Using index -SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK -FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; -OK -1 +1 SIMPLE t index NULL a 10 NULL 1000 Using index SELECT a, SUM(DISTINCT a), MAX(b) FROM t GROUP BY a; a SUM(DISTINCT a) MAX(b) 1 1 1 @@ -3422,11 +3440,7 @@ a SUM(DISTINCT a) MAX(b) 4 4 5 EXPLAIN SELECT a, SUM(DISTINCT a), MAX(b) FROM t GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t index a a 10 NULL 1000 Using index -SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK -FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; -OK -1 +1 SIMPLE t index NULL a 10 NULL 1000 Using index SELECT a, MAX(b) FROM t GROUP BY a HAVING SUM(DISTINCT a); a MAX(b) 1 1 @@ -3435,21 +3449,13 @@ a MAX(b) 4 5 EXPLAIN SELECT a, MAX(b) FROM t GROUP BY a HAVING SUM(DISTINCT a); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t index a a 10 NULL 1000 Using index -SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK -FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; -OK -1 +1 SIMPLE t index NULL a 10 NULL 1000 Using index SELECT SUM(DISTINCT a), MIN(b), MAX(b) FROM t; SUM(DISTINCT a) MIN(b) MAX(b) 10 0 5 EXPLAIN SELECT SUM(DISTINCT a), MIN(b), MAX(b) FROM t; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t index a a 10 NULL 1000 Using index -SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK -FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; -OK -1 +1 SIMPLE t index NULL a 10 NULL 1000 Using index SELECT a, SUM(DISTINCT a), MIN(b), MAX(b) FROM t GROUP BY a; a SUM(DISTINCT a) MIN(b) MAX(b) 1 1 0 1 @@ -3458,14 +3464,7 @@ a SUM(DISTINCT a) MIN(b) MAX(b) 4 4 4 5 EXPLAIN SELECT a, SUM(DISTINCT a), MIN(b), MAX(b) FROM t GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t index a a 10 NULL 1000 Using index -SELECT TRACE RLIKE 'have_both_agg_distinct_and_min_max' AS OK -FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; -OK -1 -SET optimizer_trace_max_mem_size=DEFAULT; -SET optimizer_trace=DEFAULT; -SET end_markers_in_json=DEFAULT; +1 SIMPLE t index NULL a 10 NULL 1000 Using index DROP TABLE t; # # Bug#18109609: LOOSE INDEX SCAN IS NOT USED WHEN IT SHOULD @@ -3484,7 +3483,7 @@ Table Op Msg_type Msg_text test.t1 analyze status OK EXPLAIN SELECT MAX(c2), c1 FROM t1 WHERE c1 = 4 GROUP BY c1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range c1 c1 5 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 ref c1 c1 5 const 1000 Using index FLUSH STATUS; SELECT MAX(c2), c1 FROM t1 WHERE c1 = 4 GROUP BY c1; MAX(c2) c1 @@ -3492,12 +3491,14 @@ MAX(c2) c1 SHOW SESSION STATUS LIKE 'Handler_read%'; Variable_name Value Handler_read_first 0 -Handler_read_key 3 -Handler_read_last 1 -Handler_read_next 0 +Handler_read_key 1 +Handler_read_last 0 +Handler_read_next 20 Handler_read_prev 0 +Handler_read_retry 0 Handler_read_rnd 0 +Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 DROP TABLE t1; # End of test for Bug#18109609 -set global debug="-d,force_group_by"; +set global debug_dbug=@debug_tmp; diff --git a/storage/rocksdb/mysql-test/rocksdb/t/group_min_max.test b/storage/rocksdb/mysql-test/rocksdb/t/group_min_max.test index a9c44a71edd..eb66bd0e972 100644 --- a/storage/rocksdb/mysql-test/rocksdb/t/group_min_max.test +++ b/storage/rocksdb/mysql-test/rocksdb/t/group_min_max.test @@ -1,8 +1,9 @@ --source include/have_debug.inc -set global debug="+d,force_group_by"; +set @debug_tmp= @@debug_dbug; +set global debug_dbug="+d,force_group_by"; let $engine=RocksDB; --source include/group_min_max.inc -set global debug="-d,force_group_by"; +set global debug_dbug=@debug_tmp; From 988ff90256d2aacbcb6aaf57fc8984dc60ae74ff Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sun, 4 Aug 2019 23:37:47 +0300 Subject: [PATCH 09/63] MDEV-20227: rocksdb.rocksdb_concurrent_delete fails on windows A combination of: * lots of include'd test files where each has "--source include/have_rocksdb.inc" * for each such occurrence, MTR adds testsuite's arguments into server arguments * which hits some limit on the length of argv array on Windows, causing the server to get garbage data in the last argument. Work around this by commenting out one of the totally redundant "source include/have_rocksdb.inc" lines. --- .../mysql-test/rocksdb/t/rocksdb_concurrent_delete.inc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/storage/rocksdb/mysql-test/rocksdb/t/rocksdb_concurrent_delete.inc b/storage/rocksdb/mysql-test/rocksdb/t/rocksdb_concurrent_delete.inc index 55f466a4d31..5336c77ee83 100644 --- a/storage/rocksdb/mysql-test/rocksdb/t/rocksdb_concurrent_delete.inc +++ b/storage/rocksdb/mysql-test/rocksdb/t/rocksdb_concurrent_delete.inc @@ -1,4 +1,7 @@ ---source include/have_rocksdb.inc +# MariaDB: including the below too many times causes really long argv list +# in win_main()'s argument which blows up some limit on Windows. +# Comment it out: +#--source include/have_rocksdb.inc --source include/have_debug_sync.inc --source include/count_sessions.inc From eef7540405849287abf94c0332adfc50cf4f13c5 Mon Sep 17 00:00:00 2001 From: Sujatha Date: Mon, 5 Aug 2019 14:34:13 +0530 Subject: [PATCH 10/63] MDEV-18930: Failed CREATE OR REPLACE TEMPORARY not written into binary log makes data on master and slave diverge Problem: ======= Failed CREATE OR REPLACE TEMPORARY TABLE statement which dropped the table but failed at a later stage of creation of temporary table is not written to binarylog in row based replication. This causes the slave to diverge. Analysis: ======== CREATE OR REPLACE statements work as shown below. CREATE OR REPLACE TABLE table_name (a int); is basically the same as: DROP TABLE IF EXISTS table_name; CREATE TABLE table_name (a int); Hence every CREATE OR REPLACE TABLE command which dropped the table should be written to binary log, even when following CREATE TABLE part fails. In order to achieve this, during the execution of CREATE OR REPLACE command, when a table is dropped 'thd->log_current_statement' flag is set. When table creation results in an error within 'mysql_create_table' code, the error handling part looks for this flag. If it is set the failed CREATE OR REPLACE statement is written into the binary log inspite of error. This ensure that slave doesn't diverge from the master. In case of row based replication the error handling code returns very early, if the table is of type temporary. This is done based on the assumption that temporary tables are not replicated in row based replication. It fails to handle the cases where a temporary table was created as part of statement based replication at an earlier stage and the binary log format was changed to row because of an unsafe statement. In this case when a CREATE OR REPLACE statement is executed on this temporary table it will dropped but the query will not be written to binary log. Hence slave diverges. Fix: === In error handling code check the return status of create table operation. If it is successful and replication mode is row based and table is of type temporary then return. Other wise proceed further to the code which checks for thd->log_current_statement flag and does appropriate logging. --- .../rpl/r/rpl_create_or_replace_fail.result | 18 ++++++ .../rpl/t/rpl_create_or_replace_fail.test | 56 +++++++++++++++++++ sql/sql_table.cc | 2 +- 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/rpl/r/rpl_create_or_replace_fail.result create mode 100644 mysql-test/suite/rpl/t/rpl_create_or_replace_fail.test diff --git a/mysql-test/suite/rpl/r/rpl_create_or_replace_fail.result b/mysql-test/suite/rpl/r/rpl_create_or_replace_fail.result new file mode 100644 index 00000000000..57178f0efbe --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_create_or_replace_fail.result @@ -0,0 +1,18 @@ +include/master-slave.inc +[connection master] +CREATE TEMPORARY TABLE t1 (a INT NOT NULL); +LOAD DATA INFILE 'x' INTO TABLE x; +ERROR 42S02: Table 'test.x' doesn't exist +CREATE OR REPLACE TEMPORARY TABLE t1 (x INT) PARTITION BY HASH(x); +ERROR HY000: Cannot create temporary table with partitions +"************** DROP TEMPORARY TABLE Should be present in Binary log **************" +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE TEMPORARY TABLE t1 (a INT NOT NULL) +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE OR REPLACE TEMPORARY TABLE t1 (x INT) PARTITION BY HASH(x) +CREATE TABLE t1 (b INT); +INSERT INTO t1 VALUES (NULL); +DROP TABLE t1; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_create_or_replace_fail.test b/mysql-test/suite/rpl/t/rpl_create_or_replace_fail.test new file mode 100644 index 00000000000..e75f34b0b56 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_create_or_replace_fail.test @@ -0,0 +1,56 @@ +# ==== Purpose ==== +# +# Test verifies that failed CREATE OR REPLACE TEMPORARY TABLE statement which +# dropped the table but failed at a later stage of creation of temporary table +# is written to binarylog in row based replication. +# +# ==== Implementation ==== +# +# Steps: +# 0 - Have mixed based replication mode. +# 1 - Create a temporary table. It will be replicated as mixed replication +# mode is in use. +# 2 - Execute an unsafe statement which will switch current statement +# binlog format to 'ROW'. i.e If binlog_format=MIXED, there are open +# temporary tables, and an unsafe statement is executed, then subsequent +# statements are logged in row format. +# 3 - Execute a CREATE OR REPLACE TEMPORARY TABLE statement which tries to +# create partitions on temporary table. Since it is not supported it will +# fail. +# 4 - Check the binary log output to ensure that the failed statement is +# written to the binary log. +# 5 - Slave should be up and running and in sync with master. +# +# ==== References ==== +# +# MDEV-18930: Failed CREATE OR REPLACE TEMPORARY not written into binary log +# makes data on master and slave diverge +# + +--source include/have_partition.inc +--source include/have_binlog_format_mixed.inc +--source include/master-slave.inc + +CREATE TEMPORARY TABLE t1 (a INT NOT NULL); + +# Execute an unsafe statement which switches replication mode internally from +# "STATEMENT" to "ROW". +--error ER_NO_SUCH_TABLE +LOAD DATA INFILE 'x' INTO TABLE x; + +--error ER_PARTITION_NO_TEMPORARY +CREATE OR REPLACE TEMPORARY TABLE t1 (x INT) PARTITION BY HASH(x); + +--echo "************** DROP TEMPORARY TABLE Should be present in Binary log **************" +--source include/show_binlog_events.inc + +CREATE TABLE t1 (b INT); +INSERT INTO t1 VALUES (NULL); +--sync_slave_with_master + +# Cleanup +--connection master +DROP TABLE t1; + +--source include/rpl_end.inc + diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 656834c7852..fe923d73200 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5092,7 +5092,7 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table, err: /* In RBR we don't need to log CREATE TEMPORARY TABLE */ - if (thd->is_current_stmt_binlog_format_row() && create_info->tmp_table()) + if (!result && thd->is_current_stmt_binlog_format_row() && create_info->tmp_table()) DBUG_RETURN(result); if (create_info->tmp_table()) From da7d82b8ea9e7ad35e261f1452eabd242269de5d Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Fri, 19 Jul 2019 18:22:22 +0300 Subject: [PATCH 11/63] MDEV-20103 add a class similar to std::span Non-owning reference to elements. Use it as function argument instead of pointer+size pair or instead of const std::vector. Do not use it for strings! More info is here http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines Or just google about it. --- storage/innobase/include/span.h | 157 ++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 storage/innobase/include/span.h diff --git a/storage/innobase/include/span.h b/storage/innobase/include/span.h new file mode 100644 index 00000000000..8d24289740a --- /dev/null +++ b/storage/innobase/include/span.h @@ -0,0 +1,157 @@ +/***************************************************************************** + +Copyright (c) 2019, MariaDB Corporation. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA + +*****************************************************************************/ + +#pragma once + +#include +#include + +namespace st_ { + +template class span { +public: + typedef ElementType element_type; + typedef ElementType value_type; + typedef size_t index_type; + typedef ptrdiff_t difference_type; + typedef element_type* pointer; + typedef const element_type* const_pointer; + typedef element_type& reference; + typedef const element_type& const_reference; + typedef pointer iterator; + typedef const pointer const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + span() : data_(NULL), size_(0) {} + + span(pointer ptr, index_type count) : data_(ptr), size_(count) {} + + span(pointer first, pointer last) : data_(first), size_(last - first) {} + + template span(element_type (&arr)[N]) : data_(arr), size_(N) + { + } + + template + span(Container& cont) : data_(cont.begin()), size_(cont.size()) + { + } + + template + span(const Container& cont) : data_(cont.begin()), size_(cont.size()) + { + } + + span(const span& other) : data_(other.data_), size_(other.size_) {} + + ~span(){}; + + span& operator=(const span& other) + { + data_ = other.data_; + size_ = other.size_; + return *this; + } + + template span first() const + { + assert(!empty()); + return span(data_, 1); + } + template span last() const + { + assert(!empty()); + return span(data_ + size() - 1, 1); + } + + span first(index_type count) const + { + assert(!empty()); + return span(data_, 1); + } + span last(index_type count) const + { + assert(!empty()); + return span(data_ + size() - 1, 1); + } + span subspan(index_type offset, index_type count) const + { + assert(!empty()); + assert(size() >= offset + count); + return span(data_ + offset, count); + } + + index_type size() const { return size_; } + index_type size_bytes() const { return size_ * sizeof(ElementType); } + bool empty() const __attribute__((warn_unused_result)) + { + return size_ == 0; + } + + reference operator[](index_type idx) const + { + assert(size() > idx); + return data_[idx]; + } + reference front() const + { + assert(!empty()); + return data_[0]; + } + reference back() const + { + assert(!empty()); + return data_[size() - 1]; + } + pointer data() const + { + assert(!empty()); + return data_; + } + + iterator begin() const { return data_; } + iterator end() const { return data_ + size_; } + const_iterator cbegin() const { return data_; } + const_iterator cend() const { return data_ + size_; } + reverse_iterator rbegin() const + { + return std::reverse_iterator(std::advance(end(), -1)); + } + reverse_iterator rend() const + { + return std::reverse_iterator( + std::advance(begin(), -1)); + } + const_reverse_iterator crbegin() const + { + return std::reverse_iterator( + std::advance(end(), -1)); + } + const_reverse_iterator crend() const + { + return std::reverse_iterator( + std::advance(begin(), -1)); + } + +private: + pointer data_; + index_type size_; +}; + +} // namespace st_ From a5a7ab1957ed2189e1e9c5b35268e14043ac68ed Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Fri, 19 Jul 2019 18:23:10 +0300 Subject: [PATCH 12/63] Cleanup: this is how to use span --- storage/innobase/handler/handler0alter.cc | 60 +++++++++++------------ 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 4168b91a4d9..c0c34103f1d 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -52,6 +52,9 @@ Smart ALTER TABLE #include "row0sel.h" #include "ha_innodb.h" #include "ut0stage.h" +#include "span.h" + +using st_::span; static const char *MSG_UNSUPPORTED_ALTER_ONLINE_ON_VIRTUAL_COLUMN= "INPLACE ADD or DROP of virtual columns cannot be " @@ -1272,20 +1275,22 @@ innobase_set_foreign_key_option( /*******************************************************************//** Check if a foreign key constraint can make use of an index that is being created. +@param[in] col_names column names +@param[in] n_cols number of columns +@param[in] keys index information +@param[in] add indexes being created @return useable index, or NULL if none found */ static MY_ATTRIBUTE((nonnull, warn_unused_result)) const KEY* innobase_find_equiv_index( -/*======================*/ const char*const* col_names, - /*!< in: column names */ - uint n_cols, /*!< in: number of columns */ - const KEY* keys, /*!< in: index information */ - const uint* add, /*!< in: indexes being created */ - uint n_add) /*!< in: number of indexes to create */ + uint n_cols, + const KEY* keys, + span add) { - for (uint i = 0; i < n_add; i++) { - const KEY* key = &keys[add[i]]; + for (span::iterator it = add.begin(), end = add.end(); it != end; + ++it) { + const KEY* key = &keys[*it]; if (key->user_defined_key_parts < n_cols || key->flags & HA_SPATIAL) { @@ -1336,7 +1341,7 @@ no_match: Find an index whose first fields are the columns in the array in the same order and is not marked for deletion @return matching index, NULL if not found */ -static MY_ATTRIBUTE((nonnull(1,2,6), warn_unused_result)) +static MY_ATTRIBUTE((nonnull(1,2,5), warn_unused_result)) dict_index_t* innobase_find_fk_index( /*===================*/ @@ -1346,10 +1351,8 @@ innobase_find_fk_index( const char** col_names, /*!< in: column names, or NULL to use table->col_names */ - dict_index_t** drop_index, + span drop_index, /*!< in: indexes to be dropped */ - ulint n_drop_index, - /*!< in: size of drop_index[] */ const char** columns,/*!< in: array of column names */ ulint n_cols) /*!< in: number of columns */ { @@ -1358,21 +1361,14 @@ innobase_find_fk_index( index = dict_table_get_first_index(table); while (index != NULL) { - if (dict_foreign_qualify_index( - table, col_names, columns, n_cols, - index, NULL, true, 0, - NULL, NULL, NULL)) { - for (ulint i = 0; i < n_drop_index; i++) { - if (index == drop_index[i]) { - /* Skip to-be-dropped indexes. */ - goto next_rec; - } - } - - return(index); + if (dict_foreign_qualify_index(table, col_names, columns, + n_cols, index, NULL, true, 0, + NULL, NULL, NULL) + && std::find(drop_index.begin(), drop_index.end(), index) + == drop_index.end()) { + return index; } -next_rec: index = dict_table_get_next_index(index); } @@ -1519,7 +1515,7 @@ innobase_get_foreign_key_info( index = innobase_find_fk_index( ha_alter_info, table, col_names, - drop_index, n_drop_index, + span(drop_index, n_drop_index), column_names, i); /* MySQL would add a index in the creation @@ -1534,8 +1530,8 @@ innobase_get_foreign_key_info( if (!index && !innobase_find_equiv_index( column_names, static_cast(i), ha_alter_info->key_info_buffer, - ha_alter_info->index_add_buffer, - ha_alter_info->index_add_count)) { + span(ha_alter_info->index_add_buffer, + ha_alter_info->index_add_count))) { my_error( ER_FK_NO_INDEX_CHILD, MYF(0), @@ -5180,8 +5176,8 @@ innobase_check_foreign_key_index( foreign->referenced_col_names, foreign->n_fields, ha_alter_info->key_info_buffer, - ha_alter_info->index_add_buffer, - ha_alter_info->index_add_count)) { + span(ha_alter_info->index_add_buffer, + ha_alter_info->index_add_count))) { /* Index cannot be dropped. */ trx->error_info = index; @@ -5215,8 +5211,8 @@ innobase_check_foreign_key_index( foreign->foreign_col_names, foreign->n_fields, ha_alter_info->key_info_buffer, - ha_alter_info->index_add_buffer, - ha_alter_info->index_add_count)) { + span(ha_alter_info->index_add_buffer, + ha_alter_info->index_add_count))) { /* Index cannot be dropped. */ trx->error_info = index; From 88abca55f9ddd3297e44cd649d4bf5d6578001a0 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Tue, 6 Aug 2019 12:56:16 +0300 Subject: [PATCH 13/63] fix build (-Werror + -Wignored-qualifiers) --- libmariadb | 2 +- storage/innobase/include/span.h | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/libmariadb b/libmariadb index ed3a91c1391..5fa9c4615e7 160000 --- a/libmariadb +++ b/libmariadb @@ -1 +1 @@ -Subproject commit ed3a91c139175746c5d6903d67ca902d91228f65 +Subproject commit 5fa9c4615e71b696b84b4c77aefa197466526a13 diff --git a/storage/innobase/include/span.h b/storage/innobase/include/span.h index 8d24289740a..faeb41029b8 100644 --- a/storage/innobase/include/span.h +++ b/storage/innobase/include/span.h @@ -127,8 +127,6 @@ public: iterator begin() const { return data_; } iterator end() const { return data_ + size_; } - const_iterator cbegin() const { return data_; } - const_iterator cend() const { return data_ + size_; } reverse_iterator rbegin() const { return std::reverse_iterator(std::advance(end(), -1)); @@ -138,16 +136,6 @@ public: return std::reverse_iterator( std::advance(begin(), -1)); } - const_reverse_iterator crbegin() const - { - return std::reverse_iterator( - std::advance(end(), -1)); - } - const_reverse_iterator crend() const - { - return std::reverse_iterator( - std::advance(begin(), -1)); - } private: pointer data_; From 47f8a18fec604983e47fdf7c822d94b26d85cade Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Wed, 7 Aug 2019 12:35:04 +0530 Subject: [PATCH 14/63] MDEV-20247 Replication hangs with "preparing" and never starts - The commit ab6dd774082c57f48d998e03655c06b672799b2d wrongly sets the condition inside innobase_srv_conc_enter_innodb(). Problem is that InnoDB makes the thread to sleep indefinitely if it is a replication slave thread. Thanks to Sujatha Sivakumar for contributing the replication test case. --- .../r/rpl_sync_with_innodb_thd_conc.result | 13 ++++++ .../rpl/t/rpl_sync_with_innodb_thd_conc.test | 41 +++++++++++++++++++ storage/innobase/handler/ha_innodb.cc | 6 +-- storage/xtradb/handler/ha_innodb.cc | 6 +-- 4 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_sync_with_innodb_thd_conc.result create mode 100644 mysql-test/suite/rpl/t/rpl_sync_with_innodb_thd_conc.test diff --git a/mysql-test/suite/rpl/r/rpl_sync_with_innodb_thd_conc.result b/mysql-test/suite/rpl/r/rpl_sync_with_innodb_thd_conc.result new file mode 100644 index 00000000000..0ed894336a1 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_sync_with_innodb_thd_conc.result @@ -0,0 +1,13 @@ +include/master-slave.inc +[connection master] +SET @old_innodb_thread_concurrency := @@innodb_thread_concurrency; +SET @old_innodb_thread_sleep_delay := @@innodb_thread_sleep_delay; +SET GLOBAL innodb_thread_concurrency = 100; +CREATE TABLE t(f INT) ENGINE=INNODB; +INSERT INTO t VALUES (10); +include/diff_tables.inc [master:t, slave:t] +"===== Clean up=======" +DROP TABLE t; +SET GLOBAL innodb_thread_concurrency = @old_innodb_thread_concurrency; +SET GLOBAL innodb_thread_sleep_delay = @old_innodb_thread_sleep_delay; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_sync_with_innodb_thd_conc.test b/mysql-test/suite/rpl/t/rpl_sync_with_innodb_thd_conc.test new file mode 100644 index 00000000000..b4c2971d2fb --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_sync_with_innodb_thd_conc.test @@ -0,0 +1,41 @@ +# ==== Purpose ==== +# +# Test verifies that replication shouldn't hang when number of active threads +# on the slave server are less than the allowed innodb_thread_concurrency value. +# +# ==== Implementation ==== +# +# Steps: +# 0 - Have master slave replication setup with engine being Innodb. +# 1 - Configure innodb_thread_concurrency = 100. +# 2 - Do some DML on master and sync the slave with master. +# 3 - Ensure replication doesn't hang. +# +# ==== References ==== +# +# MDEV-20247: Replication hangs with "preparing" and never starts +# + +--source include/master-slave.inc +--source include/have_innodb.inc + +--connection slave +SET @old_innodb_thread_concurrency := @@innodb_thread_concurrency; +SET @old_innodb_thread_sleep_delay := @@innodb_thread_sleep_delay; +SET GLOBAL innodb_thread_concurrency = 100; + +--connection master +CREATE TABLE t(f INT) ENGINE=INNODB; +INSERT INTO t VALUES (10); +--sync_slave_with_master + +--let $diff_tables=master:t, slave:t +--source include/diff_tables.inc + +--echo "===== Clean up=======" +--connection master +DROP TABLE t; +--sync_slave_with_master +SET GLOBAL innodb_thread_concurrency = @old_innodb_thread_concurrency; +SET GLOBAL innodb_thread_sleep_delay = @old_innodb_thread_sleep_delay; +--source include/rpl_end.inc diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 081fcbd9c51..5dfe240631b 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -1686,9 +1686,9 @@ innobase_srv_conc_enter_innodb( && thd_is_replication_slave_thread(trx->mysql_thd)) { const ulonglong end = my_interval_timer() + ulonglong(srv_replication_delay) * 1000000; - while (srv_conc_get_active_threads() - >= srv_thread_concurrency - || my_interval_timer() >= end) { + while ((srv_conc_get_active_threads() + >= srv_thread_concurrency) + && my_interval_timer() < end) { os_thread_sleep(2000 /* 2 ms */); } } else { diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index 5e7482ff6bf..b5002187e3b 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -1949,9 +1949,9 @@ innobase_srv_conc_enter_innodb( && thd_is_replication_slave_thread(trx->mysql_thd)) { const ulonglong end = my_interval_timer() + ulonglong(srv_replication_delay) * 1000000; - while (srv_conc_get_active_threads() - >= srv_thread_concurrency - || my_interval_timer() >= end) { + while ((srv_conc_get_active_threads() + >= srv_thread_concurrency) + && my_interval_timer() < end) { os_thread_sleep(2000 /* 2 ms */); } } else { From d39d5dd2bc4aecd31adaa20e428425b75c972af3 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Mon, 29 Jul 2019 14:12:19 +0300 Subject: [PATCH 15/63] MDEV-20060: Failing assertion: srv_log_file_size <= 512ULL << 30 while preparing backup The general reason why innodb redo log file is limited by 512G is that log_block_convert_lsn_to_no() returns value limited by 1G. But there is no need to have unique log block numbers in log group. The fix removes 512G limit and limits log group size by (uint32_t maximum value) * (minimum page size), which, in turns, can be removed if fil_io() is no longer used for innodb redo log io. --- extra/mariabackup/xtrabackup.cc | 2 +- mysql-test/mysql-test-run.pl | 1 + .../suite/mariabackup/big_innodb_log.result | 30 +++++++ .../suite/mariabackup/big_innodb_log.test | 87 +++++++++++++++++++ .../suite/sys_vars/r/sysvars_innodb.result | 2 +- storage/innobase/handler/ha_innodb.cc | 2 +- storage/innobase/include/log0log.h | 10 +++ storage/innobase/include/log0log.ic | 4 +- storage/innobase/log/log0log.cc | 11 ++- storage/innobase/srv/srv0start.cc | 14 ++- 10 files changed, 147 insertions(+), 16 deletions(-) create mode 100644 mysql-test/suite/mariabackup/big_innodb_log.result create mode 100644 mysql-test/suite/mariabackup/big_innodb_log.test diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index 524aed6cd5a..bc7149a87fd 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -1298,7 +1298,7 @@ struct my_option xb_server_options[] = {"innodb_log_file_size", OPT_INNODB_LOG_FILE_SIZE, "Ignored for mysqld option compatibility", (G_PTR*) &srv_log_file_size, (G_PTR*) &srv_log_file_size, 0, - GET_ULL, REQUIRED_ARG, 48 << 20, 1 << 20, 512ULL << 30, 0, + GET_ULL, REQUIRED_ARG, 48 << 20, 1 << 20, log_group_max_size, 0, UNIV_PAGE_SIZE_MAX, 0}, {"innodb_log_files_in_group", OPT_INNODB_LOG_FILES_IN_GROUP, "Ignored for mysqld option compatibility", diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index a29ae0b67ae..47f697ae0de 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -3333,6 +3333,7 @@ sub mysql_install_db { # Create the bootstrap.sql file # ---------------------------------------------------------------------- my $bootstrap_sql_file= "$opt_vardir/log/bootstrap.sql"; + $ENV{'MYSQL_BOOTSTRAP_SQL_FILE'}= $bootstrap_sql_file; if (! -e $bootstrap_sql_file) { diff --git a/mysql-test/suite/mariabackup/big_innodb_log.result b/mysql-test/suite/mariabackup/big_innodb_log.result new file mode 100644 index 00000000000..6577c0c9aae --- /dev/null +++ b/mysql-test/suite/mariabackup/big_innodb_log.result @@ -0,0 +1,30 @@ +# Kill the server +CREATE TABLE t(i INT) ENGINE InnoDB; +INSERT INTO t VALUES +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9); +# xtrabackup backup, execute the following query after test.t is copied: +# BEGIN NOT ATOMIC INSERT INTO test.t SELECT * FROM test.t; UPDATE test.t SET i = 10 WHERE i = 0; DELETE FROM test.t WHERE i = 1; END +SELECT count(*) FROM t WHERE i = 0; +count(*) +0 +# xtrabackup prepare +# shutdown server +# remove datadir +# xtrabackup move back +# restart server +SELECT count(*) FROM t WHERE i = 0; +count(*) +0 +Ok +Ok +DROP TABLE t; +# Kill the server diff --git a/mysql-test/suite/mariabackup/big_innodb_log.test b/mysql-test/suite/mariabackup/big_innodb_log.test new file mode 100644 index 00000000000..05dc3aa39c5 --- /dev/null +++ b/mysql-test/suite/mariabackup/big_innodb_log.test @@ -0,0 +1,87 @@ +# The general reason why innodb redo log file is limited by 512G is that +# log_block_convert_lsn_to_no() returns value limited by 1G. But there is no +# need to have unique log block numbers in log group. This test forces innodb +# to generate redo log files with non-unique log block numbers and tests +# recovery process with such numbers. +--source include/have_innodb.inc +--source include/have_debug.inc + +--let MYSQLD_DATADIR= `select @@datadir` +let $MYSQLD_BOOTSTRAP_CMD= $MYSQLD_BOOTSTRAP_CMD --datadir=$MYSQLD_DATADIR --debug-dbug=+d,innodb_small_log_block_no_limit; + +--source include/kill_mysqld.inc +--rmdir $MYSQLD_DATADIR +--mkdir $MYSQLD_DATADIR +--mkdir $MYSQLD_DATADIR/mysql +--mkdir $MYSQLD_DATADIR/test +--exec $MYSQLD_BOOTSTRAP_CMD < $MYSQL_BOOTSTRAP_SQL_FILE >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1 +let $old_restart_parameters=$restart_parameters; +let $restart_parameters= $old_restart_parameters --debug-dbug=+d,innodb_small_log_block_no_limit; +--source include/start_mysqld.inc + +CREATE TABLE t(i INT) ENGINE InnoDB; +INSERT INTO t VALUES + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9); + +--let after_copy_test_t=BEGIN NOT ATOMIC INSERT INTO test.t SELECT * FROM test.t; UPDATE test.t SET i = 10 WHERE i = 0; DELETE FROM test.t WHERE i = 1; END + +--echo # xtrabackup backup, execute the following query after test.t is copied: +--echo # $after_copy_test_t +let $targetdir=$MYSQLTEST_VARDIR/tmp/backup; + +--disable_result_log +exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --parallel=10 --target-dir=$targetdir --dbug=+d,mariabackup_events,innodb_small_log_block_no_limit; +--enable_result_log + +--let $total_before=`SELECT count(*) FROM t` +SELECT count(*) FROM t WHERE i = 0; +--let $updated_before=`SELECT count(*) FROM t WHERE i = 10` + +echo # xtrabackup prepare; +--disable_result_log +exec $XTRABACKUP --prepare --target-dir=$targetdir --dbug=+d,innodb_small_log_block_no_limit; +--source include/restart_and_restore.inc +--enable_result_log + +--let $total_after=`SELECT count(*) FROM t` +SELECT count(*) FROM t WHERE i = 0; +--let $updated_after=`SELECT count(*) FROM t WHERE i = 10` + +if ($total_before == $total_after) { +--echo Ok +} +if ($total_before != $total_after) { +--echo Failed +} +if ($updated_before == $updated_after) { +--echo Ok +} +if ($updated_before != $updated_after) { +--echo Failed +} + +DROP TABLE t; +rmdir $targetdir; +--source include/kill_mysqld.inc +--rmdir $MYSQLD_DATADIR + +perl; +use lib "lib"; +use My::File::Path; +my $install_db_dir = ($ENV{MTR_PARALLEL} == 1) ? + "$ENV{'MYSQLTEST_VARDIR'}/install.db" : + "$ENV{'MYSQLTEST_VARDIR'}/../install.db"; +copytree($install_db_dir, $ENV{'MYSQLD_DATADIR'}); +EOF + +--let $restart_parameters= $old_restart_parameters +--source include/start_mysqld.inc diff --git a/mysql-test/suite/sys_vars/r/sysvars_innodb.result b/mysql-test/suite/sys_vars/r/sysvars_innodb.result index 497366ebf3d..20f2db8ba70 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_innodb.result +++ b/mysql-test/suite/sys_vars/r/sysvars_innodb.result @@ -1793,7 +1793,7 @@ VARIABLE_SCOPE GLOBAL VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Size of each log file in a log group. NUMERIC_MIN_VALUE 1048576 -NUMERIC_MAX_VALUE 549755813888 +NUMERIC_MAX_VALUE 17592186044415 NUMERIC_BLOCK_SIZE 65536 ENUM_VALUE_LIST NULL READ_ONLY YES diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 3a3688e35df..db0fa4001c6 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -20453,7 +20453,7 @@ static MYSQL_SYSVAR_LONG(log_buffer_size, innobase_log_buffer_size, static MYSQL_SYSVAR_ULONGLONG(log_file_size, srv_log_file_size, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, "Size of each log file in a log group.", - NULL, NULL, 48 << 20, 1 << 20, 512ULL << 30, UNIV_PAGE_SIZE_MAX); + NULL, NULL, 48 << 20, 1 << 20, log_group_max_size, UNIV_PAGE_SIZE_MAX); /* OS_FILE_LOG_BLOCK_SIZE would be more appropriate than UNIV_PAGE_SIZE_MAX, but fil_space_t is being used for the redo log, and it uses data pages. */ diff --git a/storage/innobase/include/log0log.h b/storage/innobase/include/log0log.h index 4864041ef51..8a6705359db 100644 --- a/storage/innobase/include/log0log.h +++ b/storage/innobase/include/log0log.h @@ -40,6 +40,10 @@ Created 12/9/1995 Heikki Tuuri #include "os0event.h" #include "os0file.h" +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + /** Redo log group */ struct log_group_t; @@ -527,6 +531,12 @@ MariaDB 10.2.18 and later will use the 10.3 format, but LOG_HEADER_SUBFORMAT header */ #define LOG_FILE_HDR_SIZE (4 * OS_FILE_LOG_BLOCK_SIZE) +/* As long as fil_io() is used to handle log io, log group max size is limited +by (maximum page number) * (minimum page size). Page number type is uint32_t. +Remove this limitation if page number is no longer used for log file io. */ +static const ulonglong log_group_max_size = + ((ulonglong(UINT32_MAX) + 1) * UNIV_PAGE_SIZE_MIN - 1); + /** The state of a log group */ enum log_group_state_t { /** No corruption detected */ diff --git a/storage/innobase/include/log0log.ic b/storage/innobase/include/log0log.ic index c6bfc9560a2..36caaedfaa2 100644 --- a/storage/innobase/include/log0log.ic +++ b/storage/innobase/include/log0log.ic @@ -185,7 +185,9 @@ log_block_convert_lsn_to_no( /*========================*/ lsn_t lsn) /*!< in: lsn of a byte within the block */ { - return(((ulint) (lsn / OS_FILE_LOG_BLOCK_SIZE) & 0x3FFFFFFFUL) + 1); + return(((ulint) (lsn / OS_FILE_LOG_BLOCK_SIZE) & + DBUG_EVALUATE_IF("innodb_small_log_block_no_limit", + 0xFUL, 0x3FFFFFFFUL)) + 1); } /************************************************************//** diff --git a/storage/innobase/log/log0log.cc b/storage/innobase/log/log0log.cc index 1d98f92bff0..682a79409f9 100644 --- a/storage/innobase/log/log0log.cc +++ b/storage/innobase/log/log0log.cc @@ -942,11 +942,14 @@ loop: the trailer fields of the log blocks */ for (i = 0; i < write_len / OS_FILE_LOG_BLOCK_SIZE; i++) { +#ifdef UNIV_DEBUG + ulint hdr_no_2 = log_block_get_hdr_no(buf) + i; + DBUG_EXECUTE_IF("innodb_small_log_block_no_limit", + hdr_no_2 = ((hdr_no_2 - 1) & 0xFUL) + 1;); +#endif ut_ad(pad_len >= len - || i * OS_FILE_LOG_BLOCK_SIZE >= len - pad_len - || log_block_get_hdr_no( - buf + i * OS_FILE_LOG_BLOCK_SIZE) - == log_block_get_hdr_no(buf) + i); + || i * OS_FILE_LOG_BLOCK_SIZE >= len - pad_len + || log_block_get_hdr_no(buf + i * OS_FILE_LOG_BLOCK_SIZE) == hdr_no_2); log_block_store_checksum(buf + i * OS_FILE_LOG_BLOCK_SIZE); } diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 3cd5f289991..1b4a478639c 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1852,13 +1852,11 @@ innobase_start_or_create_for_mysql() srv_start_state_set(SRV_START_STATE_IO); } - if (srv_n_log_files * srv_log_file_size >= 512ULL << 30) { - /* log_block_convert_lsn_to_no() limits the returned block - number to 1G and given that OS_FILE_LOG_BLOCK_SIZE is 512 - bytes, then we have a limit of 512 GB. If that limit is to - be raised, then log_block_convert_lsn_to_no() must be - modified. */ - ib::error() << "Combined size of log files must be < 512 GB"; + if (srv_n_log_files * srv_log_file_size >= log_group_max_size) { + /* Log group size is limited by the size of page number. Remove this + limitation when fil_io() is not used for recovery log io. */ + ib::error() << "Combined size of log files must be < " + << log_group_max_size << " GB"; return(srv_init_abort(DB_ERROR)); } @@ -2070,7 +2068,7 @@ innobase_start_or_create_for_mysql() ut_a(fil_validate()); ut_a(log_space); - ut_a(srv_log_file_size <= 512ULL << 30); + ut_a(srv_log_file_size <= log_group_max_size); const ulint size = 1 + ulint((srv_log_file_size - 1) >> srv_page_size_shift); From 6dca5f6726c043f2bf154f16163b438e4c640283 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Thu, 8 Aug 2019 22:55:35 +0300 Subject: [PATCH 16/63] revert accidental libmariadb change --- libmariadb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmariadb b/libmariadb index 5fa9c4615e7..ed3a91c1391 160000 --- a/libmariadb +++ b/libmariadb @@ -1 +1 @@ -Subproject commit 5fa9c4615e71b696b84b4c77aefa197466526a13 +Subproject commit ed3a91c139175746c5d6903d67ca902d91228f65 From 6168f414017d491464b68445048f5c79c95abbbd Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 8 Aug 2019 20:02:40 +0300 Subject: [PATCH 17/63] Updated BUILD/compile-pentium64-asan-max --- BUILD/compile-pentium64-asan-max | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD/compile-pentium64-asan-max b/BUILD/compile-pentium64-asan-max index 9a4de53162e..37acc9f74f3 100755 --- a/BUILD/compile-pentium64-asan-max +++ b/BUILD/compile-pentium64-asan-max @@ -17,7 +17,7 @@ path=`dirname $0` . "$path/SETUP.sh" -extra_flags="$pentium64_cflags $debug_cflags -lasan -O -g -fsanitize=address" +extra_flags="$pentium64_cflags $debug_cflags -lasan -O -g -fsanitize=address -USAFEMALLOC -UFORCE_INIT_OF_VARS -Wno-uninitialized -Wno-maybe-uninitialized" extra_configs="$pentium_configs $debug_configs $valgrind_configs $max_configs $disable_asan_plugins" export LDFLAGS="-ldl" From 5fa2eb6f3d8210ce73d18e518108f32c29b11d63 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 8 Aug 2019 20:03:21 +0300 Subject: [PATCH 18/63] Fixed connect_debug.test to not depend on system error message --- mysql-test/t/connect_debug.test | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/t/connect_debug.test b/mysql-test/t/connect_debug.test index 7a2f2872b79..300a2de0fbd 100644 --- a/mysql-test/t/connect_debug.test +++ b/mysql-test/t/connect_debug.test @@ -17,6 +17,7 @@ drop user bad; # set global debug_dbug='+d,auth_invalid_plugin'; create user 'bad' identified by 'worse'; +--replace_regex /loaded: [^\n]*/loaded: invalid plugin name/ --error 1 --exec $MYSQL --default-auth=mysql_old_password --user=bad --password=worse 2>&1 set global debug_dbug=@old_dbug; From dbac2039e81f6d371acdacfb65eba10e395bb9a2 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 8 Aug 2019 20:05:40 +0300 Subject: [PATCH 19/63] Fixed some errors & warnings found by clang - pcretest.c could use macro with side effect - maria_chk could access freed memory - Initialized some variables that could be accessed uninitalized - Fixed compiler warning in my_atomic-t.c --- pcre/pcretest.c | 3 ++- storage/maria/maria_chk.c | 4 +++- storage/mroonga/vendor/groonga/lib/ts.c | 2 +- storage/mroonga/vendor/groonga/lib/ts/ts_expr_node.c | 2 +- unittest/mysys/my_atomic-t.c | 4 ++-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pcre/pcretest.c b/pcre/pcretest.c index a0e65ed9808..dcf1e2c6760 100644 --- a/pcre/pcretest.c +++ b/pcre/pcretest.c @@ -2864,7 +2864,8 @@ strncmpic(pcre_uint8 *s, pcre_uint8 *t, int n) { while (n--) { - int c = tolower(*s++) - tolower(*t++); + int c = tolower(*s) - tolower(*t); + s++; t++; if (c) return c; } return 0; diff --git a/storage/maria/maria_chk.c b/storage/maria/maria_chk.c index 7cac0a0c718..defbe79e32a 100644 --- a/storage/maria/maria_chk.c +++ b/storage/maria/maria_chk.c @@ -974,6 +974,7 @@ static int maria_chk(HA_CHECK *param, char *filename) int error,lock_type,recreate; uint warning_printed_by_chk_status; my_bool rep_quick= MY_TEST(param->testflag & (T_QUICK | T_FORCE_UNIQUENESS)); + my_bool born_transactional; MARIA_HA *info; File datafile; char llbuff[22],llbuff2[22]; @@ -1416,6 +1417,7 @@ static int maria_chk(HA_CHECK *param, char *filename) maria_lock_database(info, F_UNLCK); end2: + born_transactional= share->base.born_transactional; if (maria_close(info)) { _ma_check_print_error(param, default_close_errmsg, my_errno, filename); @@ -1431,7 +1433,7 @@ end2: MYF(MY_REDEL_MAKE_BACKUP) : MYF(0))); } if (opt_transaction_logging && - share->base.born_transactional && !error && + born_transactional && !error && (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX | T_ZEROFILL))) error= write_log_record(param); diff --git a/storage/mroonga/vendor/groonga/lib/ts.c b/storage/mroonga/vendor/groonga/lib/ts.c index 68e363a27d7..909f4864786 100644 --- a/storage/mroonga/vendor/groonga/lib/ts.c +++ b/storage/mroonga/vendor/groonga/lib/ts.c @@ -683,7 +683,7 @@ static grn_rc grn_ts_select_output(grn_ctx *ctx, grn_obj *table, grn_ts_str str, const grn_ts_record *in, size_t n_in, size_t n_hits) { - grn_ts_writer *writer; + grn_ts_writer *writer= 0; grn_rc rc = grn_ts_writer_open(ctx, table, str, &writer); if (rc != GRN_SUCCESS) { return rc; diff --git a/storage/mroonga/vendor/groonga/lib/ts/ts_expr_node.c b/storage/mroonga/vendor/groonga/lib/ts/ts_expr_node.c index ddd69714b1e..4ae900034bb 100644 --- a/storage/mroonga/vendor/groonga/lib/ts/ts_expr_node.c +++ b/storage/mroonga/vendor/groonga/lib/ts/ts_expr_node.c @@ -5173,7 +5173,7 @@ grn_ts_expr_node_deref(grn_ctx *ctx, grn_ts_expr_node **node_ptr) { grn_ts_expr_node *node = *node_ptr, **in_ptr = NULL; while ((node->data_kind & ~GRN_TS_VECTOR_FLAG) == GRN_TS_REF) { - grn_ts_expr_node *new_node; + grn_ts_expr_node *new_node= 0; grn_rc rc = grn_ts_expr_node_deref_once(ctx, node, &new_node); if (rc != GRN_SUCCESS) { if (in_ptr) { diff --git a/unittest/mysys/my_atomic-t.c b/unittest/mysys/my_atomic-t.c index 83c46c24d3f..d358b939b4d 100644 --- a/unittest/mysys/my_atomic-t.c +++ b/unittest/mysys/my_atomic-t.c @@ -90,10 +90,10 @@ pthread_handler_t test_atomic_cas(void *arg) y= my_atomic_load32(&bad); x= (x*m+0x87654321) & INT_MAX32; do { - ok= my_atomic_cas32(&bad, &y, (uint32)y+x); + ok= my_atomic_cas32((int32*) &bad, &y, y+x); } while (!ok) ; do { - ok= my_atomic_cas32(&bad, &y, y-x); + ok= my_atomic_cas32((int32*) &bad, &y, y-x); } while (!ok) ; } return 0; From 6765cc607764c920bc5fbf4128bb526b73f15c2e Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 8 Aug 2019 20:10:00 +0300 Subject: [PATCH 20/63] Fixed assertion Assertion `!table->pos_in_locked_tables' failed MDEV-17717 Assertion `!table->pos_in_locked_tables' failed in tc_release_table on flushing RocksDB table under SERIALIZABLE MDEV-17998 Deadlock and eventual Assertion `!table->pos_in_locked_tables' failed in tc_release_table on KILL_TIMEOUT MDEV-19591 Assertion `!table->pos_in_locked_tables' failed in tc_release_table upon altering table into S3 under lock. The problem was that thd->open_tables->pos_in_locked_tables was not reset when alter table failed to reopen a locked table. --- mysql-test/r/kill.result | 17 +++++++++++++++ mysql-test/t/kill.test | 21 +++++++++++++++++++ sql/sql_base.cc | 1 + .../rocksdb/mysql-test/rocksdb/r/kill.result | 6 ++++++ .../rocksdb/mysql-test/rocksdb/t/kill.test | 9 ++++++++ 5 files changed, 54 insertions(+) create mode 100644 storage/rocksdb/mysql-test/rocksdb/r/kill.result create mode 100644 storage/rocksdb/mysql-test/rocksdb/t/kill.test diff --git a/mysql-test/r/kill.result b/mysql-test/r/kill.result index dc1cb9252da..c2ad72e4240 100644 --- a/mysql-test/r/kill.result +++ b/mysql-test/r/kill.result @@ -399,3 +399,20 @@ DROP USER u1@localhost; SET DEBUG_SYNC = 'RESET'; DROP FUNCTION MY_KILL; set global sql_mode=default; +# +# MDEV-17998 +# Deadlock and eventual Assertion `!table->pos_in_locked_tables' failed +# in tc_release_table on KILL_TIMEOUT +# +SET max_statement_time= 2; +CREATE TABLE t1 (a INT); +CREATE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (b INT, c INT); +LOCK TABLES v1 READ, t2 WRITE, t1 WRITE; +ALTER TABLE t1 CHANGE f1 f2 DOUBLE; +Got one of the listed errors +ALTER TABLE t2 DROP c; +ERROR 70100: Query execution was interrupted (max_statement_time exceeded) +UNLOCK TABLES; +DROP VIEW v1; +DROP TABLE t1, t2; diff --git a/mysql-test/t/kill.test b/mysql-test/t/kill.test index b6000ffced1..a188cee52f2 100644 --- a/mysql-test/t/kill.test +++ b/mysql-test/t/kill.test @@ -642,3 +642,24 @@ SET DEBUG_SYNC = 'RESET'; DROP FUNCTION MY_KILL; set global sql_mode=default; + +--echo # +--echo # MDEV-17998 +--echo # Deadlock and eventual Assertion `!table->pos_in_locked_tables' failed +--echo # in tc_release_table on KILL_TIMEOUT +--echo # + +SET max_statement_time= 2; + +CREATE TABLE t1 (a INT); +CREATE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (b INT, c INT); + +LOCK TABLES v1 READ, t2 WRITE, t1 WRITE; +--error ER_BAD_FIELD_ERROR,ER_STATEMENT_TIMEOUT +ALTER TABLE t1 CHANGE f1 f2 DOUBLE; +--error ER_STATEMENT_TIMEOUT +ALTER TABLE t2 DROP c; +UNLOCK TABLES; +DROP VIEW v1; +DROP TABLE t1, t2; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 25f3ed6e9ad..662ba3f6b30 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2371,6 +2371,7 @@ unlink_all_closed_tables(THD *thd, MYSQL_LOCK *lock, size_t reopen_count) DBUG_ASSERT(thd->open_tables == m_reopen_array[reopen_count]); thd->open_tables->pos_in_locked_tables->table= NULL; + thd->open_tables->pos_in_locked_tables= 0; close_thread_table(thd, &thd->open_tables); } diff --git a/storage/rocksdb/mysql-test/rocksdb/r/kill.result b/storage/rocksdb/mysql-test/rocksdb/r/kill.result new file mode 100644 index 00000000000..19614e1fd95 --- /dev/null +++ b/storage/rocksdb/mysql-test/rocksdb/r/kill.result @@ -0,0 +1,6 @@ +CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=RocksDB; +LOCK TABLE t1 WRITE; +SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE; +FLUSH TABLES; +ERROR HY000: MyRocks supports only READ COMMITTED and REPEATABLE READ isolation levels. Please change from current isolation level SERIALIZABLE +DROP TABLE t1; diff --git a/storage/rocksdb/mysql-test/rocksdb/t/kill.test b/storage/rocksdb/mysql-test/rocksdb/t/kill.test new file mode 100644 index 00000000000..a2809d969d5 --- /dev/null +++ b/storage/rocksdb/mysql-test/rocksdb/t/kill.test @@ -0,0 +1,9 @@ +--source include/have_binlog_format_row.inc +--source include/have_rocksdb.inc + +CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=RocksDB; +LOCK TABLE t1 WRITE; +SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE; +--error ER_ISOLATION_MODE_NOT_SUPPORTED +FLUSH TABLES; +DROP TABLE t1; From 284c72eacf2074bf50c1930d5e8eb333367eba2f Mon Sep 17 00:00:00 2001 From: Sachin Date: Wed, 17 Jul 2019 15:56:29 +0530 Subject: [PATCH 21/63] MDEV-17614 INSERT on dup key update is replication unsafe Problem:- When mysql executes INSERT ON DUPLICATE KEY INSERT, the storage engine checks if the inserted row would generate a duplicate key error. If yes, it returns the existing row to mysql, mysql updates it and sends it back to the storage engine.When the table has more than one unique or primary key, this statement is sensitive to the order in which the storage engines checks the keys. Depending on this order, the storage engine may determine different rows to mysql, and hence mysql can update different rows.The order that the storage engine checks keys is not deterministic. For example, InnoDB checks keys in an order that depends on the order in which indexes were added to the table. The first added index is checked first. So if master and slave have added indexes in different orders, then slave may go out of sync. Solution:- Make INSERT...ON DUPLICATE KEY UPDATE unsafe while using stmt or mixed format When there is more then one unique key. Although there is two exception. 1. Auto Increment key is not counted because Innodb will get gap lock for failed Insert and concurrent insert will get a next increment value. But if user supplies auto inc value it can be unsafe. 2. Count only unique keys for which insertion is performed. So this patch also addresses the bug id #72921 --- .../rpl/r/rpl_known_bugs_detection.result | 20 --- mysql-test/suite/rpl/r/rpl_mdev_17614.result | 98 ++++++++++++++ .../suite/rpl/r/rpl_unsafe_statements.result | 5 + .../suite/rpl/t/rpl_known_bugs_detection.test | 39 ------ mysql-test/suite/rpl/t/rpl_mdev_17614.test | 121 ++++++++++++++++++ .../suite/rpl/t/rpl_unsafe_statements.test | 2 +- sql/sql_class.cc | 42 ++++++ sql/sql_class.h | 40 ++++-- sql/sql_insert.cc | 1 + 9 files changed, 294 insertions(+), 74 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_mdev_17614.result create mode 100644 mysql-test/suite/rpl/t/rpl_mdev_17614.test diff --git a/mysql-test/suite/rpl/r/rpl_known_bugs_detection.result b/mysql-test/suite/rpl/r/rpl_known_bugs_detection.result index ea738b710fd..adef091ea3e 100644 --- a/mysql-test/suite/rpl/r/rpl_known_bugs_detection.result +++ b/mysql-test/suite/rpl/r/rpl_known_bugs_detection.result @@ -1,26 +1,6 @@ call mtr.add_suppression("Unsafe statement written to the binary log using statement format"); include/master-slave.inc [connection master] -call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT."); -CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b INT, -UNIQUE(b)); -INSERT INTO t1(b) VALUES(1),(1),(2) ON DUPLICATE KEY UPDATE t1.b=10; -SELECT * FROM t1; -a b -1 10 -2 2 -call mtr.add_suppression("Slave SQL.*suffer.*http:..bugs.mysql.com.bug.php.id=24432"); -include/wait_for_slave_sql_error.inc [errno=1105] -Last_SQL_Error = 'Error 'master may suffer from http://bugs.mysql.com/bug.php?id=24432 so slave stops; check error log on slave for more info' on query. Default database: 'test'. Query: 'INSERT INTO t1(b) VALUES(1),(1),(2) ON DUPLICATE KEY UPDATE t1.b=10'' -SELECT * FROM t1; -a b -stop slave; -include/wait_for_slave_to_stop.inc -reset slave; -reset master; -drop table t1; -start slave; -include/wait_for_slave_to_start.inc CREATE TABLE t1 ( id bigint(20) unsigned NOT NULL auto_increment, field_1 int(10) unsigned NOT NULL, diff --git a/mysql-test/suite/rpl/r/rpl_mdev_17614.result b/mysql-test/suite/rpl/r/rpl_mdev_17614.result new file mode 100644 index 00000000000..28de23e28c9 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_mdev_17614.result @@ -0,0 +1,98 @@ +include/master-slave.inc +[connection master] +call mtr.add_suppression("Unsafe statement written to the binary log using statement format"); +CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY , b INT, +UNIQUE(b), c int) engine=innodb; +INSERT INTO t1 VALUES (1, 1, 1); +BEGIN; +INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe +INSERT INTO t1 VALUES(2, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe +COMMIT; +SELECT * FROM t1; +a b c +1 1 2 +2 2 3 +include/wait_for_slave_sql_error.inc [errno=1062] +Last_SQL_Error = 'Error 'Duplicate entry '1' for key 'b'' on query. Default database: 'test'. Query: 'INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c)'' +#Different value from server +SELECT * FROM t1; +a b c +1 1 1 +2 2 3 +stop slave; +include/wait_for_slave_to_stop.inc +reset slave; +reset master; +drop table t1; +start slave; +include/wait_for_slave_to_start.inc +CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY auto_increment, b INT, +UNIQUE(b), c int) engine=innodb; +INSERT INTO t1 VALUES (default, 1, 1); +BEGIN; +INSERT INTO t1 VALUES (default, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +INSERT INTO t1 VALUES(default, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +COMMIT; +SELECT * FROM t1; +a b c +1 1 2 +3 2 3 +#same data as master +SELECT * FROM t1; +a b c +1 1 2 +3 2 3 +drop table t1; +CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT, +UNIQUE(b), c int, d int ) engine=innodb; +INSERT INTO t1 VALUES (1, 1, 1, 1); +BEGIN; +INSERT INTO t1 VALUES (2, NULL, 2, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe +INSERT INTO t1 VALUES(3, NULL, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe +COMMIT; +SELECT * FROM t1; +a b c d +1 1 1 1 +2 NULL 2 2 +3 NULL 2 3 +#same data as master +SELECT * FROM t1; +a b c d +1 1 1 1 +2 NULL 2 2 +3 NULL 2 3 +drop table t1; +CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY auto_increment, b INT, +UNIQUE(b), c int) engine=innodb; +INSERT INTO t1 VALUES (1, 1, 1); +BEGIN; +INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +INSERT INTO t1 VALUES(2, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +COMMIT; +SELECT * FROM t1; +a b c +1 1 2 +2 2 3 +include/wait_for_slave_sql_error.inc [errno=1062] +Last_SQL_Error = 'Error 'Duplicate entry '1' for key 'b'' on query. Default database: 'test'. Query: 'INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c)'' +#Different value from server +SELECT * FROM t1; +a b c +1 1 1 +2 2 3 +stop slave; +include/wait_for_slave_to_stop.inc +reset slave; +reset master; +drop table t1; +start slave; +include/wait_for_slave_to_start.inc +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_unsafe_statements.result b/mysql-test/suite/rpl/r/rpl_unsafe_statements.result index 2efb3eba2b1..55ff09f6fad 100644 --- a/mysql-test/suite/rpl/r/rpl_unsafe_statements.result +++ b/mysql-test/suite/rpl/r/rpl_unsafe_statements.result @@ -1,5 +1,6 @@ include/master-slave.inc [connection master] +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); CREATE TABLE t1(id INT AUTO_INCREMENT, i INT, PRIMARY KEY (id)) ENGINE=INNODB; CREATE TABLE t2(id INT AUTO_INCREMENT, i INT, PRIMARY KEY (id)) ENGINE=INNODB; CREATE TRIGGER trig1 AFTER INSERT ON t1 @@ -43,9 +44,13 @@ include/diff_tables.inc [master:t1, slave:t1] DROP TABLE t1; CREATE TABLE t1(i INT, j INT, UNIQUE KEY(i), UNIQUE KEY(j)) ENGINE=INNODB; INSERT INTO t1 (i,j) VALUES (1,2) ON DUPLICATE KEY UPDATE j=j+1; +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe START TRANSACTION; LOCK TABLES t1 WRITE; INSERT INTO t1 (i,j) VALUES (1,2) ON DUPLICATE KEY UPDATE j=j+1; +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe UNLOCK TABLES; COMMIT; include/diff_tables.inc [master:t1, slave:t1] diff --git a/mysql-test/suite/rpl/t/rpl_known_bugs_detection.test b/mysql-test/suite/rpl/t/rpl_known_bugs_detection.test index ab263ece407..5ea056d5f14 100644 --- a/mysql-test/suite/rpl/t/rpl_known_bugs_detection.test +++ b/mysql-test/suite/rpl/t/rpl_known_bugs_detection.test @@ -14,45 +14,6 @@ source include/have_binlog_checksum_off.inc; source include/master-slave.inc; -call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT."); - -# -# This is to test that slave properly detects if -# master may suffer from: -# BUG#24432 "INSERT... ON DUPLICATE KEY UPDATE skips auto_increment values" -# (i.e. on master, INSERT ON DUPLICATE KEY UPDATE is used and manipulates -# an auto_increment column, and is binlogged statement-based). -# - -# testcase with INSERT VALUES -CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b INT, -UNIQUE(b)); -sync_slave_with_master; -connection master; -INSERT INTO t1(b) VALUES(1),(1),(2) ON DUPLICATE KEY UPDATE t1.b=10; -SELECT * FROM t1; -connection slave; - -# show the error message -#1105 = ER_UNKNOWN_ERROR ---let $slave_sql_errno= 1105 ---let $show_slave_sql_error= 1 -call mtr.add_suppression("Slave SQL.*suffer.*http:..bugs.mysql.com.bug.php.id=24432"); ---source include/wait_for_slave_sql_error.inc -# show that it was not replicated -SELECT * FROM t1; - -# restart replication for the next testcase -stop slave; ---source include/wait_for_slave_to_stop.inc -reset slave; -connection master; -reset master; -drop table t1; -connection slave; -start slave; ---source include/wait_for_slave_to_start.inc - # testcase with INSERT SELECT connection master; CREATE TABLE t1 ( diff --git a/mysql-test/suite/rpl/t/rpl_mdev_17614.test b/mysql-test/suite/rpl/t/rpl_mdev_17614.test new file mode 100644 index 00000000000..9b86c8c15b5 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_mdev_17614.test @@ -0,0 +1,121 @@ +source include/have_debug.inc; +source include/have_innodb.inc; +-- source include/have_binlog_format_statement.inc +source include/master-slave.inc; +# MDEV-17614 +# INSERT on dup key update is replication unsafe +# There can be three case +# 1. 2 unique key, Replication is unsafe. +# 2. 2 unique key , with one auto increment key, Safe to replicate because Innodb will acquire gap lock +# 3. n no of unique keys (n>1) but insert is only in 1 unique key +# 4. 2 unique key , with one auto increment key(but user gives auto inc value), unsafe to replicate + +# Case 1 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format"); +CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY , b INT, +UNIQUE(b), c int) engine=innodb; +sync_slave_with_master; +connection master; +INSERT INTO t1 VALUES (1, 1, 1); +BEGIN; +INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); + --connection master1 + INSERT INTO t1 VALUES(2, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +--connection master +COMMIT; +SELECT * FROM t1; +--connection slave +# show the error message +--let $slave_sql_errno= 1062 +--let $show_slave_sql_error= 1 +--source include/wait_for_slave_sql_error.inc +--echo #Different value from server +SELECT * FROM t1; + +# restart replication for the next testcase +stop slave; +--source include/wait_for_slave_to_stop.inc +reset slave; +connection master; +reset master; +drop table t1; +connection slave; +start slave; +--source include/wait_for_slave_to_start.inc +# Case 2 +--connection master +CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY auto_increment, b INT, +UNIQUE(b), c int) engine=innodb; +sync_slave_with_master; +connection master; +INSERT INTO t1 VALUES (default, 1, 1); +BEGIN; +INSERT INTO t1 VALUES (default, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); + --connection master1 + INSERT INTO t1 VALUES(default, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +--connection master +COMMIT; +SELECT * FROM t1; +--sync_slave_with_master +--echo #same data as master +SELECT * FROM t1; + +connection master; +drop table t1; +--sync_slave_with_master + +# Case 3 +--connection master +CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT, +UNIQUE(b), c int, d int ) engine=innodb; +sync_slave_with_master; +connection master; +INSERT INTO t1 VALUES (1, 1, 1, 1); +BEGIN; +INSERT INTO t1 VALUES (2, NULL, 2, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); + --connection master1 + INSERT INTO t1 VALUES(3, NULL, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +--connection master +COMMIT; +SELECT * FROM t1; +--sync_slave_with_master +--echo #same data as master +SELECT * FROM t1; +connection master; +drop table t1; +--sync_slave_with_master + +# Case 4 +--connection master +CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY auto_increment, b INT, +UNIQUE(b), c int) engine=innodb; +sync_slave_with_master; +connection master; +INSERT INTO t1 VALUES (1, 1, 1); +BEGIN; +INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); + --connection master1 + INSERT INTO t1 VALUES(2, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +--connection master +COMMIT; +SELECT * FROM t1; +--connection slave +# show the error message +--let $slave_sql_errno= 1062 +--let $show_slave_sql_error= 1 +--source include/wait_for_slave_sql_error.inc +--echo #Different value from server +SELECT * FROM t1; + +# restart replication for the next testcase +stop slave; +--source include/wait_for_slave_to_stop.inc +reset slave; +connection master; +reset master; +drop table t1; +connection slave; +start slave; +--source include/wait_for_slave_to_start.inc + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_unsafe_statements.test b/mysql-test/suite/rpl/t/rpl_unsafe_statements.test index cbb4b54a220..aa0bd076398 100644 --- a/mysql-test/suite/rpl/t/rpl_unsafe_statements.test +++ b/mysql-test/suite/rpl/t/rpl_unsafe_statements.test @@ -24,7 +24,7 @@ --source include/have_innodb.inc --source include/have_binlog_format_mixed.inc --source include/master-slave.inc - +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); # Case-1: BINLOG_STMT_UNSAFE_AUTOINC_COLUMNS # Statement is unsafe because it invokes a trigger or a # stored function that inserts into an AUTO_INCREMENT column. diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 6bcff6d1fca..1a3ca54abf8 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -6144,6 +6144,48 @@ int THD::decide_logging_format(TABLE_LIST *tables) DBUG_RETURN(0); } +int THD::decide_logging_format_low(TABLE *table) +{ + /* + INSERT...ON DUPLICATE KEY UPDATE on a table with more than one unique keys + can be unsafe. + */ + if(wsrep_binlog_format() <= BINLOG_FORMAT_STMT && + !is_current_stmt_binlog_format_row() && + !lex->is_stmt_unsafe() && + lex->sql_command == SQLCOM_INSERT && + lex->duplicates == DUP_UPDATE) + { + uint unique_keys= 0; + uint keys= table->s->keys, i= 0; + Field *field; + for (KEY* keyinfo= table->s->key_info; + i < keys && unique_keys <= 1; i++, keyinfo++) + if (keyinfo->flags & HA_NOSAME && + !(keyinfo->key_part->field->flags & AUTO_INCREMENT_FLAG && + //User given auto inc can be unsafe + !keyinfo->key_part->field->val_int())) + { + for (uint j= 0; j < keyinfo->user_defined_key_parts; j++) + { + field= keyinfo->key_part[j].field; + if(!bitmap_is_set(table->write_set,field->field_index)) + goto exit; + } + unique_keys++; +exit:; + } + + if (unique_keys > 1) + { + lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_INSERT_TWO_KEYS); + binlog_unsafe_warning_flags|= lex->get_stmt_unsafe_flags(); + set_current_stmt_binlog_format_row_if_mixed(); + return 1; + } + } + return 0; +} /* Implementation of interface to write rows to the binary log through the diff --git a/sql/sql_class.h b/sql/sql_class.h index e3bc572ed0c..8a4d8ff06a3 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2208,6 +2208,20 @@ public: /* container for handler's private per-connection data */ Ha_data ha_data[MAX_HA]; + /** + Bit field for the state of binlog warnings. + + The first Lex::BINLOG_STMT_UNSAFE_COUNT bits list all types of + unsafeness that the current statement has. + + This must be a member of THD and not of LEX, because warnings are + detected and issued in different places (@c + decide_logging_format() and @c binlog_query(), respectively). + Between these calls, the THD->lex object may change; e.g., if a + stored routine is invoked. Only THD persists between the calls. + */ + uint32 binlog_unsafe_warning_flags; + #ifndef MYSQL_CLIENT binlog_cache_mngr * binlog_setup_trx_data(); @@ -2317,20 +2331,6 @@ private: */ enum_binlog_format current_stmt_binlog_format; - /** - Bit field for the state of binlog warnings. - - The first Lex::BINLOG_STMT_UNSAFE_COUNT bits list all types of - unsafeness that the current statement has. - - This must be a member of THD and not of LEX, because warnings are - detected and issued in different places (@c - decide_logging_format() and @c binlog_query(), respectively). - Between these calls, the THD->lex object may change; e.g., if a - stored routine is invoked. Only THD persists between the calls. - */ - uint32 binlog_unsafe_warning_flags; - /* Number of outstanding table maps, i.e., table maps in the transaction cache. @@ -3939,6 +3939,18 @@ public: } void leave_locked_tables_mode(); int decide_logging_format(TABLE_LIST *tables); + /* + In Some cases when decide_logging_format is called it does not have all + information to decide the logging format. So that cases we call decide_logging_format_2 + at later stages in execution. + One example would be binlog format for IODKU but column with unique key is not inserted. + We dont have inserted columns info when we call decide_logging_format so on later stage we call + decide_logging_format_low + + @returns 0 if no format is changed + 1 if there is change in binlog format + */ + int decide_logging_format_low(TABLE *table); enum need_invoker { INVOKER_NONE=0, INVOKER_USER, INVOKER_ROLE}; void binlog_invoker(bool role) { m_binlog_invoker= role ? INVOKER_ROLE : INVOKER_USER; } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 1ad74bd0f5a..f67897bb9c5 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1025,6 +1025,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, error= 1; break; } + thd->decide_logging_format_low(table); #ifndef EMBEDDED_LIBRARY if (lock_type == TL_WRITE_DELAYED) { From 3b234104ae227556f06c2c3d227e5fc51692c8fa Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sat, 10 Aug 2019 01:46:50 +0300 Subject: [PATCH 22/63] MDEV-16955: rocksdb_sys_vars.rocksdb_update_cf_options_basic ... produces "bytes lost" warnings When rocksdb_validate_update_cf_options() returns an error, the update won't happen. Free the copy of the string in this case. --- storage/rocksdb/ha_rocksdb.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 4f256b10abc..613ac0884a7 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -14314,6 +14314,8 @@ static int rocksdb_validate_update_cf_options( // then there's no point to proceed. if (!Rdb_cf_options::parse_cf_options(str, &option_map)) { my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "rocksdb_update_cf_options", str); + // Free what we've copied with my_strdup above. + my_free((void*)(*(const char **)save)); return HA_EXIT_FAILURE; } // Loop through option_map and create missing column families From cdbac54df0bd857a053decd66b6067abf15a6801 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Wed, 26 Dec 2018 13:24:45 +0300 Subject: [PATCH 23/63] MDEV-17613 MIN/MAX Optimization (Select tables optimized away) does not work Prune to now-partition when there is no FOR SYSTEM_TIME clause. --- .../suite/versioning/r/partition.result | 11 ++++++ .../versioning/r/partition_rotation.result | 2 +- mysql-test/suite/versioning/t/partition.test | 21 +++++++++++ sql/sql_select.cc | 35 ++++++++++++++++--- 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result index c0a163ed027..588e6432c4a 100644 --- a/mysql-test/suite/versioning/r/partition.result +++ b/mysql-test/suite/versioning/r/partition.result @@ -546,6 +546,17 @@ t1 CREATE TABLE `t1` ( # create or replace table t1 (f int) with system versioning partition by hash(f); insert delayed into t1 values (1); +# +# MDEV-17613 MIN/MAX Optimization (Select tables optimized away) does not work +# +create or replace table t1 (pk int primary key) with system versioning +partition by system_time ( +partition p1 history, +partition pn current); +insert into t1 values (1), (2); +explain select max(pk) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away # Test cleanup drop database test; create database test; diff --git a/mysql-test/suite/versioning/r/partition_rotation.result b/mysql-test/suite/versioning/r/partition_rotation.result index 7e25f122238..69b30a56bd6 100644 --- a/mysql-test/suite/versioning/r/partition_rotation.result +++ b/mysql-test/suite/versioning/r/partition_rotation.result @@ -44,7 +44,7 @@ i 6 explain partitions select * from t1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t1 pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL 2 explain partitions select * from t1 for system_time as of '2001-02-04 10:20:30'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1_p1sp0,p1_p1sp1,p0_p0sp0,p0_p0sp1,p2_p2sp0,p2_p2sp1,pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL # Using where diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test index cd16ab7c466..29e4c413f77 100644 --- a/mysql-test/suite/versioning/t/partition.test +++ b/mysql-test/suite/versioning/t/partition.test @@ -497,6 +497,27 @@ create or replace table t1 (f int) with system versioning partition by hash(f); --error 0,ER_DELAYED_NOT_SUPPORTED insert delayed into t1 values (1); +--echo # +--echo # MDEV-17613 MIN/MAX Optimization (Select tables optimized away) does not work +--echo # +--disable_query_log +set @saved_storage_engine= @@default_storage_engine; +if ($MTR_COMBINATION_HEAP) +{ + # This case does not work with HEAP + set default_storage_engine= myisam; +} +--enable_query_log +create or replace table t1 (pk int primary key) with system versioning +partition by system_time ( + partition p1 history, + partition pn current); +insert into t1 values (1), (2); +explain select max(pk) from t1; +--disable_query_log +set default_storage_engine= @saved_storage_engine; +--enable_query_log + --echo # Test cleanup drop database test; create database test; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index cc3ff1037ad..33ff0bc70cc 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -721,6 +721,19 @@ void vers_select_conds_t::print(String *str, enum_query_type query_type) const } } +/** + Setup System Versioning conditions + + Add WHERE condition according to FOR SYSTEM_TIME clause. + + If the table is partitioned by SYSTEM_TIME and there is no FOR SYSTEM_TIME + clause, then select now-partition instead of modifying WHERE condition. + + @retval + -1 on error + @retval + 0 on success +*/ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) { DBUG_ENTER("SELECT_LEX::vers_setup_cond"); @@ -788,12 +801,13 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) vers_select_conds_t &vers_conditions= table->vers_conditions; #ifdef WITH_PARTITION_STORAGE_ENGINE - /* - if the history is stored in partitions, then partitions - themselves are not versioned - */ - if (table->partition_names && table->table->part_info->vers_info) + Vers_part_info *vers_info; + if (table->table->part_info && (vers_info= table->table->part_info->vers_info)) + { + if (table->partition_names) { + /* If the history is stored in partitions, then partitions + themselves are not versioned. */ if (vers_conditions.is_set()) { my_error(ER_VERS_QUERY_IN_PARTITION, MYF(0), table->alias.str); @@ -802,6 +816,16 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) else vers_conditions.init(SYSTEM_TIME_ALL); } + else if (!vers_conditions.is_set()) + { + table->partition_names= newx List; + String *s= newx String(vers_info->now_part->partition_name, + system_charset_info); + table->partition_names->push_back(s); + table->table->file->change_partitions_to_open(table->partition_names); + vers_conditions.init(SYSTEM_TIME_ALL); + } + } #endif if (outer_table && !vers_conditions.is_set()) @@ -951,6 +975,7 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) DBUG_RETURN(0); #undef newx } +#undef newx /***************************************************************************** Check fields, find best join, do the select and output fields. From 98758b52b3a3b0ede3cb8f93bcada5e5af51254b Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Tue, 16 Jul 2019 19:40:38 +0300 Subject: [PATCH 24/63] MDEV-20068 History partition rotation is not done under LOCK TABLES Wrong value F_WRLCK for thr_lock_type. --- mysql-test/suite/versioning/r/partition.result | 12 ++++++++++++ mysql-test/suite/versioning/t/partition.test | 11 +++++++++++ sql/ha_partition.cc | 17 +++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result index 588e6432c4a..da851791640 100644 --- a/mysql-test/suite/versioning/r/partition.result +++ b/mysql-test/suite/versioning/r/partition.result @@ -557,6 +557,18 @@ insert into t1 values (1), (2); explain select max(pk) from t1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +# +# MDEV-20068 History partition rotation is not done under LOCK TABLES +# +create or replace table t1 (x int) with system versioning partition by system_time limit 1 +(partition p1 history, partition pn current); +lock tables t1 write; +insert into t1 values (0), (1), (2), (3); +delete from t1 where x < 3; +delete from t1; +Warnings: +Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions +unlock tables; # Test cleanup drop database test; create database test; diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test index 29e4c413f77..f602c49d7c1 100644 --- a/mysql-test/suite/versioning/t/partition.test +++ b/mysql-test/suite/versioning/t/partition.test @@ -518,6 +518,17 @@ explain select max(pk) from t1; set default_storage_engine= @saved_storage_engine; --enable_query_log +--echo # +--echo # MDEV-20068 History partition rotation is not done under LOCK TABLES +--echo # +create or replace table t1 (x int) with system versioning partition by system_time limit 1 +(partition p1 history, partition pn current); +lock tables t1 write; +insert into t1 values (0), (1), (2), (3); +delete from t1 where x < 3; +delete from t1; +unlock tables; + --echo # Test cleanup drop database test; create database test; diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index ce0f430147a..125669a403d 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -4093,8 +4093,21 @@ int ha_partition::start_stmt(THD *thd, thr_lock_type lock_type) /* Add partition to be called in reset(). */ bitmap_set_bit(&m_partitions_to_reset, i); } - if (lock_type == F_WRLCK && m_part_info->part_expr) - m_part_info->part_expr->walk(&Item::register_field_in_read_map, 1, 0); + switch (lock_type) + { + case TL_WRITE_ALLOW_WRITE: + case TL_WRITE_CONCURRENT_INSERT: + case TL_WRITE_DELAYED: + case TL_WRITE_DEFAULT: + case TL_WRITE_LOW_PRIORITY: + case TL_WRITE: + case TL_WRITE_ONLY: + if (m_part_info->part_expr) + m_part_info->part_expr->walk(&Item::register_field_in_read_map, 1, 0); + if (m_part_info->part_type == VERSIONING_PARTITION) + m_part_info->vers_set_hist_part(thd); + default:; + } DBUG_RETURN(error); } From 5851e668d7a0d51034c7d74779c39ef0f7b8d002 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Mon, 27 May 2019 15:03:15 +0300 Subject: [PATCH 25/63] MDEV-19304 Segfault in ALTER TABLE after UPDATE for SIMULTANEOUS_ASSIGNMENT For MODE_SIMULTANEOUS_ASSIGNMENT it is required to return back field offsets from record[1] to record[0]. 'continue' in warning branch did skip of rfield->move_field_offset() call. --- mysql-test/suite/versioning/r/alter.result | 13 +++++++++++++ mysql-test/suite/versioning/t/alter.test | 11 +++++++++++ sql/sql_base.cc | 9 ++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/mysql-test/suite/versioning/r/alter.result b/mysql-test/suite/versioning/r/alter.result index 528c6ca7c2f..d272d53f407 100644 --- a/mysql-test/suite/versioning/r/alter.result +++ b/mysql-test/suite/versioning/r/alter.result @@ -603,5 +603,18 @@ select * from t1; a b 1 0 affected rows: 1 +# +# MDEV-19304 Segfault in ALTER TABLE after UPDATE for SIMULTANEOUS_ASSIGNMENT +# +create or replace table t1 (a int, s timestamp(6) as row start, e timestamp(6) as row end, period for system_time(s,e)) engine=myisam with system versioning; +insert into t1 values (null, null, null); +insert into t1 values (null, null, null); +set sql_mode= 'simultaneous_assignment'; +update t1 set e= 1; +Warnings: +Warning 1906 The value specified for generated column 'e' in table 't1' has been ignored +Warning 1906 The value specified for generated column 'e' in table 't1' has been ignored +alter table t1 force; +set sql_mode= default; drop database test; create database test; diff --git a/mysql-test/suite/versioning/t/alter.test b/mysql-test/suite/versioning/t/alter.test index 4af937b96e7..f11eee59641 100644 --- a/mysql-test/suite/versioning/t/alter.test +++ b/mysql-test/suite/versioning/t/alter.test @@ -503,5 +503,16 @@ alter table t1 modify a int with system versioning; select * from t1; --disable_info +--echo # +--echo # MDEV-19304 Segfault in ALTER TABLE after UPDATE for SIMULTANEOUS_ASSIGNMENT +--echo # +create or replace table t1 (a int, s timestamp(6) as row start, e timestamp(6) as row end, period for system_time(s,e)) engine=myisam with system versioning; +insert into t1 values (null, null, null); +insert into t1 values (null, null, null); +set sql_mode= 'simultaneous_assignment'; +update t1 set e= 1; +alter table t1 force; +set sql_mode= default; + drop database test; create database test; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index b7294fbc304..287d5771155 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -8304,8 +8304,8 @@ fill_record(THD *thd, TABLE *table_arg, List &fields, List &values, rfield->field_index == table->next_number_field->field_index) table->auto_increment_field_not_null= TRUE; Item::Type type= value->type(); - bool vers_sys_field= table->versioned() && rfield->vers_sys_field(); - if ((rfield->vcol_info || vers_sys_field) && + const bool skip_sys_field= rfield->vers_sys_field(); // TODO: && !thd->vers_modify_history() [MDEV-16546] + if ((rfield->vcol_info || skip_sys_field) && type != Item::DEFAULT_VALUE_ITEM && type != Item::NULL_ITEM && table->s->table_category != TABLE_CATEGORY_TEMPORARY) @@ -8314,15 +8314,14 @@ fill_record(THD *thd, TABLE *table_arg, List &fields, List &values, ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN, ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN), rfield->field_name.str, table->s->table_name.str); - if (vers_sys_field) - continue; } if (only_unvers_fields && !rfield->vers_update_unversioned()) only_unvers_fields= false; if (rfield->stored_in_db()) { - if (unlikely(value->save_in_field(rfield, 0) < 0) && !ignore_errors) + if (!skip_sys_field && + unlikely(value->save_in_field(rfield, 0) < 0) && !ignore_errors) { my_message(ER_UNKNOWN_ERROR, ER_THD(thd, ER_UNKNOWN_ERROR), MYF(0)); goto err; From 638e78853f8d7c0e2c1cf580f3847c5789f165e1 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Wed, 20 Mar 2019 20:45:54 +0300 Subject: [PATCH 26/63] MDEV-18862 Unfortunate error message upon attempt to drop system versioning Special case for DROP PERIOD when system fields are implicit. --- mysql-test/suite/versioning/r/alter.result | 13 +++++++++++++ mysql-test/suite/versioning/t/alter.test | 14 ++++++++++++++ sql/share/errmsg-utf8.txt | 2 ++ sql/sql_table.cc | 15 +++++++++++++-- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/versioning/r/alter.result b/mysql-test/suite/versioning/r/alter.result index d272d53f407..0c79e6d4a39 100644 --- a/mysql-test/suite/versioning/r/alter.result +++ b/mysql-test/suite/versioning/r/alter.result @@ -616,5 +616,18 @@ Warning 1906 The value specified for generated column 'e' in table 't1' has been Warning 1906 The value specified for generated column 'e' in table 't1' has been ignored alter table t1 force; set sql_mode= default; +# +# MDEV-18862 Unfortunate error message upon attempt to drop system versioning +# +set system_versioning_alter_history= keep; +create or replace table t1 (x int) with system versioning; +alter table t1 drop column `row_start`, drop column `row_end`, drop period for system_time, drop system versioning; +ERROR HY000: No 'PERIOD FOR SYSTEM_TIME' in system-versioned `t1` +alter table t1 drop period for system_time; +ERROR HY000: No 'PERIOD FOR SYSTEM_TIME' in system-versioned `t1` +alter table t1 drop column `row_start`, drop column `row_end`, drop system versioning; +ERROR 42000: Can't DROP COLUMN `row_start`; check that it exists +alter table t1 drop column `row_end`; +ERROR 42000: Can't DROP COLUMN `row_end`; check that it exists drop database test; create database test; diff --git a/mysql-test/suite/versioning/t/alter.test b/mysql-test/suite/versioning/t/alter.test index f11eee59641..ea699104eac 100644 --- a/mysql-test/suite/versioning/t/alter.test +++ b/mysql-test/suite/versioning/t/alter.test @@ -514,5 +514,19 @@ update t1 set e= 1; alter table t1 force; set sql_mode= default; +--echo # +--echo # MDEV-18862 Unfortunate error message upon attempt to drop system versioning +--echo # +set system_versioning_alter_history= keep; +create or replace table t1 (x int) with system versioning; +--error ER_VERS_NO_PERIOD +alter table t1 drop column `row_start`, drop column `row_end`, drop period for system_time, drop system versioning; +--error ER_VERS_NO_PERIOD +alter table t1 drop period for system_time; +--error ER_CANT_DROP_FIELD_OR_KEY +alter table t1 drop column `row_start`, drop column `row_end`, drop system versioning; +--error ER_CANT_DROP_FIELD_OR_KEY +alter table t1 drop column `row_end`; + drop database test; create database test; diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 99af1c60287..39198912fbe 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7898,3 +7898,5 @@ ER_KEY_DOESNT_SUPPORT eng "%s index %`s does not support this operation" ER_ALTER_OPERATION_TABLE_OPTIONS_NEED_REBUILD eng "Changing table options requires the table to be rebuilt" +ER_VERS_NO_PERIOD + eng "No 'PERIOD FOR SYSTEM_TIME' in system-versioned %`s" diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 62f7a7c4952..a615dd9f1ed 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7833,6 +7833,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, KEY *key_info=table->key_info; bool rc= TRUE; bool modified_primary_key= FALSE; + bool vers_system_invisible= false; Create_field *def; Field **f_ptr,*field; MY_BITMAP *dropped_fields= NULL; // if it's NULL - no dropped fields @@ -7941,7 +7942,11 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, bitmap_set_bit(dropped_fields, field->field_index); continue; } - + if (field->invisible == INVISIBLE_SYSTEM && + field->flags & VERS_SYSTEM_FIELD) + { + vers_system_invisible= true; + } /* invisible versioning column is dropped automatically on DROP SYSTEM VERSIONING */ if (!drop && field->invisible >= INVISIBLE_SYSTEM && field->flags & VERS_SYSTEM_FIELD && @@ -8059,7 +8064,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, dropped_sys_vers_fields &= VERS_SYSTEM_FIELD; if ((dropped_sys_vers_fields || alter_info->flags & ALTER_DROP_PERIOD) && - dropped_sys_vers_fields != VERS_SYSTEM_FIELD) + dropped_sys_vers_fields != VERS_SYSTEM_FIELD && + !vers_system_invisible) { StringBuffer tmp; append_drop_column(thd, dropped_sys_vers_fields & VERS_SYS_START_FLAG, @@ -8069,6 +8075,11 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, my_error(ER_MISSING, MYF(0), table->s->table_name.str, tmp.c_ptr()); goto err; } + else if (alter_info->flags & ALTER_DROP_PERIOD && vers_system_invisible) + { + my_error(ER_VERS_NO_PERIOD, MYF(0), table->s->table_name.str); + goto err; + } alter_info->flags &= ~(ALTER_DROP_PERIOD | ALTER_ADD_PERIOD); def_it.rewind(); while ((def=def_it++)) // Add new columns From 0b74c8832d45340a455f27c3b4aa20db5d8313db Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Thu, 11 Apr 2019 10:04:34 +0300 Subject: [PATCH 27/63] MDEV-19127 Assertion `row_start_field' failed in vers_prepare_keys upon ALTER TABLE Prevent conflicting clauses at parser level. Clear HA_VERSIONED_TABLE flag for DROP SYSTEM VERSIONING (for the sake of strictness). --- mysql-test/suite/versioning/r/alter.result | 9 +++++++++ mysql-test/suite/versioning/t/alter.test | 10 ++++++++++ sql/sql_yacc.yy | 6 ++++++ sql/sql_yacc_ora.yy | 6 ++++++ 4 files changed, 31 insertions(+) diff --git a/mysql-test/suite/versioning/r/alter.result b/mysql-test/suite/versioning/r/alter.result index 0c79e6d4a39..2afd3921154 100644 --- a/mysql-test/suite/versioning/r/alter.result +++ b/mysql-test/suite/versioning/r/alter.result @@ -629,5 +629,14 @@ alter table t1 drop column `row_start`, drop column `row_end`, drop system versi ERROR 42000: Can't DROP COLUMN `row_start`; check that it exists alter table t1 drop column `row_end`; ERROR 42000: Can't DROP COLUMN `row_end`; check that it exists +# +# MDEV-19127 Assertion `row_start_field' failed in vers_prepare_keys upon ALTER TABLE +# +set system_versioning_alter_history=keep; +create or replace table t1 (f1 int) with system versioning; +alter table t1 add f2 int with system versioning, drop system versioning; +create or replace table t1 (f1 int) with system versioning; +alter table t1 drop system versioning, add f2 int with system versioning; +ERROR HY000: Table `t1` is not system-versioned drop database test; create database test; diff --git a/mysql-test/suite/versioning/t/alter.test b/mysql-test/suite/versioning/t/alter.test index ea699104eac..c04c2020460 100644 --- a/mysql-test/suite/versioning/t/alter.test +++ b/mysql-test/suite/versioning/t/alter.test @@ -528,5 +528,15 @@ alter table t1 drop column `row_start`, drop column `row_end`, drop system versi --error ER_CANT_DROP_FIELD_OR_KEY alter table t1 drop column `row_end`; +--echo # +--echo # MDEV-19127 Assertion `row_start_field' failed in vers_prepare_keys upon ALTER TABLE +--echo # +set system_versioning_alter_history=keep; +create or replace table t1 (f1 int) with system versioning; +alter table t1 add f2 int with system versioning, drop system versioning; +create or replace table t1 (f1 int) with system versioning; +--error ER_VERS_NOT_VERSIONED +alter table t1 drop system versioning, add f2 int with system versioning; + drop database test; create database test; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index d5e579e9df5..c1b2fd2294b 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -7368,6 +7368,11 @@ serial_attribute: { Lex->last_field->versioning= $1; Lex->create_info.options|= HA_VERSIONED_TABLE; + if (Lex->alter_info.flags & ALTER_DROP_SYSTEM_VERSIONING) + { + my_yyabort_error((ER_VERS_NOT_VERSIONED, MYF(0), + Lex->create_last_non_select_table->table_name.str)); + } } ; @@ -8498,6 +8503,7 @@ alter_list_item: | DROP SYSTEM VERSIONING_SYM { Lex->alter_info.flags|= ALTER_DROP_SYSTEM_VERSIONING; + Lex->create_info.options&= ~HA_VERSIONED_TABLE; } | DROP PERIOD_SYM FOR_SYSTEM_TIME_SYM { diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index 45f770b0c88..28d3d1bf90b 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -7292,6 +7292,11 @@ serial_attribute: { Lex->last_field->versioning= $1; Lex->create_info.options|= HA_VERSIONED_TABLE; + if (Lex->alter_info.flags & ALTER_DROP_SYSTEM_VERSIONING) + { + my_yyabort_error((ER_VERS_NOT_VERSIONED, MYF(0), + Lex->create_last_non_select_table->table_name.str)); + } } ; @@ -8435,6 +8440,7 @@ alter_list_item: | DROP SYSTEM VERSIONING_SYM { Lex->alter_info.flags|= ALTER_DROP_SYSTEM_VERSIONING; + Lex->create_info.options&= ~HA_VERSIONED_TABLE; } | DROP PERIOD_SYM FOR_SYSTEM_TIME_SYM { From 22914ec793b850438c77acf070f8441cf307ebf6 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Tue, 5 Feb 2019 00:57:31 +0300 Subject: [PATCH 28/63] MDEV-18154 Deadlock and assertion upon no-op ALTER under LOCK TABLES 1. Fix DBUG_ASSERT(!table->pos_in_locked_tables) in tc_release_table(); 2. Fix access of prematurely freed MDL_ticket: don't close ticket if table was not closed; 3. Fix deadlock after erroneous ALTER. mysql_alter_table() leaves dirty table->m_needs_reopen in case of error exit which then incorrectly treated by mysql_lock_tables(). --- mysql-test/main/alter_table.result | 18 ++++++++++++++++++ mysql-test/main/alter_table.test | 18 ++++++++++++++++++ sql/sql_base.cc | 1 + sql/sql_table.cc | 6 +++++- 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/alter_table.result b/mysql-test/main/alter_table.result index 7a88f9165da..c5d974f4469 100644 --- a/mysql-test/main/alter_table.result +++ b/mysql-test/main/alter_table.result @@ -2539,3 +2539,21 @@ test.t1 analyze status OK set @@use_stat_tables= @save_use_stat_tables; set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; drop table t1; +# +# MDEV-18154 Deadlock and assertion upon no-op ALTER under LOCK TABLES +# +create or replace table t1 (pk int, i int, primary key (pk)) engine myisam; +create or replace view v1 as select * from t1; +lock table v1 read, t1 write; +alter table t1 change f1 f2 int; +ERROR 42S22: Unknown column 'f1' in 't1' +set max_statement_time= 1; +alter table t1 add column if not exists i int after pk; +Warnings: +Note 1060 Duplicate column name 'i' +set max_statement_time= 0; +drop table t1; +drop view v1; +# +# End of 10.3 tests +# diff --git a/mysql-test/main/alter_table.test b/mysql-test/main/alter_table.test index 0fab5575f13..5c29dfae6b3 100644 --- a/mysql-test/main/alter_table.test +++ b/mysql-test/main/alter_table.test @@ -2057,3 +2057,21 @@ analyze table t1; set @@use_stat_tables= @save_use_stat_tables; set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; drop table t1; + +--echo # +--echo # MDEV-18154 Deadlock and assertion upon no-op ALTER under LOCK TABLES +--echo # +create or replace table t1 (pk int, i int, primary key (pk)) engine myisam; +create or replace view v1 as select * from t1; +lock table v1 read, t1 write; +--error ER_BAD_FIELD_ERROR +alter table t1 change f1 f2 int; +set max_statement_time= 1; +alter table t1 add column if not exists i int after pk; +set max_statement_time= 0; +drop table t1; +drop view v1; + +--echo # +--echo # End of 10.3 tests +--echo # diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 287d5771155..99c8a227861 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2433,6 +2433,7 @@ unlink_all_closed_tables(THD *thd, MYSQL_LOCK *lock, size_t reopen_count) DBUG_ASSERT(thd->open_tables == m_reopen_array[reopen_count]); thd->open_tables->pos_in_locked_tables->table= NULL; + thd->open_tables->pos_in_locked_tables= NULL; close_thread_table(thd, &thd->open_tables); } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index a615dd9f1ed..eb623e14912 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7837,6 +7837,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, Create_field *def; Field **f_ptr,*field; MY_BITMAP *dropped_fields= NULL; // if it's NULL - no dropped fields + bool save_reopen= table->m_needs_reopen; DBUG_ENTER("mysql_prepare_alter_table"); /* @@ -8516,7 +8517,9 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, alter_info->create_list.swap(new_create_list); alter_info->key_list.swap(new_key_list); alter_info->check_constraint_list.swap(new_constraint_list); + DBUG_RETURN(rc); err: + table->m_needs_reopen= save_reopen; DBUG_RETURN(rc); } @@ -10195,7 +10198,8 @@ err_with_mdl: tables and release the exclusive metadata lock. */ thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0); - thd->mdl_context.release_all_locks_for_name(mdl_ticket); + if (!table_list->table) + thd->mdl_context.release_all_locks_for_name(mdl_ticket); DBUG_RETURN(true); } From 98b24da03808d562bf37e0ae00ba2c6e0c5cc5c3 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Sat, 3 Nov 2018 18:00:22 +0300 Subject: [PATCH 29/63] MDEV-17609 mysql client sets wrong application name for Readline library initialize_readline() is called with full pathname of executable which sets rl_readline_name to that value. It is expected that rl_readline_name is initialized with static name not depending on the file name at all. Needed for setting custom hotkeys in .inputrc --- client/mysql.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/mysql.cc b/client/mysql.cc index 0fba75cfa32..6c8485a5143 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -1060,7 +1060,7 @@ extern "C" int write_history(const char *command); extern "C" HIST_ENTRY *history_get(int num); extern "C" int history_length; static int not_in_history(const char *line); -static void initialize_readline (char *name); +static void initialize_readline (); static void fix_history(String *final_command); #endif @@ -1241,7 +1241,7 @@ int main(int argc,char *argv[]) } #ifdef HAVE_READLINE - initialize_readline((char*) my_progname); + initialize_readline(); if (!status.batch && !quick && !opt_html && !opt_xml) { /* read-history from file, default ~/.mysql_history*/ @@ -2668,10 +2668,11 @@ static int fake_magic_space(const char *, int) } -static void initialize_readline (char *name) +static void initialize_readline () { /* Allow conditional parsing of the ~/.inputrc file. */ - rl_readline_name = name; + rl_readline_name= "mysql"; + rl_terminal_name= getenv("TERM"); /* Tell the completer that we want a crack first. */ #if defined(USE_NEW_READLINE_INTERFACE) From b2a387a3f1a0603482d184241979f0172cba45cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 12 Aug 2019 14:05:26 +0300 Subject: [PATCH 30/63] Document TRASH_FILL, TRASH_ALLOC, TRASH_FREE --- include/my_valgrind.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/my_valgrind.h b/include/my_valgrind.h index ad22f0cad40..7a56b28c0f0 100644 --- a/include/my_valgrind.h +++ b/include/my_valgrind.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 Monty Program Ab +/* Copyright (C) 2010, 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -55,11 +55,19 @@ https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */ #endif /* HAVE_VALGRIND */ #ifndef DBUG_OFF +/* NOTE: Do not invoke TRASH_FILL directly! Use TRASH_ALLOC or TRASH_FREE. + +The MEM_UNDEFINED() call before memset() is for canceling the effect +of any previous MEM_NOACCESS(). We must invoke MEM_UNDEFINED() after +writing the dummy pattern, unless MEM_NOACCESS() is going to be invoked. +On AddressSanitizer, the MEM_UNDEFINED() in TRASH_ALLOC() has no effect. */ #define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_UNDEFINED(A, trash_tmp); memset(A, C, trash_tmp); } while (0) #else #define TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0) #endif +/** Note that some memory became allocated or uninitialized. */ #define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0) +/** Note that some memory became freed. (Prohibit further access to it.) */ #define TRASH_FREE(A,B) do { TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0) #endif /* MY_VALGRIND_INCLUDED */ From 1217e4a0c05eff7a394e46e64dffc849c9edda22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 12 Aug 2019 14:12:32 +0300 Subject: [PATCH 31/63] Fix -Wimplicit-fallthrough --- storage/innobase/include/data0type.ic | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/storage/innobase/include/data0type.ic b/storage/innobase/include/data0type.ic index 2bf21513c1c..d31debef24a 100644 --- a/storage/innobase/include/data0type.ic +++ b/storage/innobase/include/data0type.ic @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2012, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2018, MariaDB Corporation. +Copyright (c) 2018, 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -427,6 +427,7 @@ dtype_get_fixed_size_low( return(0); } #endif /* UNIV_DEBUG */ + /* fall through */ case DATA_CHAR: case DATA_FIXBINARY: case DATA_INT: @@ -503,6 +504,7 @@ dtype_get_min_size_low( return(0); } #endif /* UNIV_DEBUG */ + /* fall through */ case DATA_CHAR: case DATA_FIXBINARY: case DATA_INT: From 7a9e1fcd455bfa8e3d71fabb6b76769433567508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 12 Aug 2019 14:45:28 +0300 Subject: [PATCH 32/63] MDEV-17614: Re-record a result --- mysql-test/suite/binlog/r/binlog_unsafe.result | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql-test/suite/binlog/r/binlog_unsafe.result b/mysql-test/suite/binlog/r/binlog_unsafe.result index 48d9db44b05..e8de90d3422 100644 --- a/mysql-test/suite/binlog/r/binlog_unsafe.result +++ b/mysql-test/suite/binlog/r/binlog_unsafe.result @@ -2706,6 +2706,8 @@ Warnings: Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. CREATE... REPLACE SELECT is unsafe because the order in which rows are retrieved by the SELECT determines which (if any) rows are replaced. This order cannot be predicted and may differ on master and the slave. INSERT INTO insert_2_keys VALUES (1, 2) ON DUPLICATE KEY UPDATE a=VALUES(a)+10, b=VALUES(b)+10; +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe DROP TABLE filler_table; DROP TABLE insert_table; DROP TABLE update_table; From fe8181aca13cf7ba1835fa6c89f297a1d0e79856 Mon Sep 17 00:00:00 2001 From: Monty Date: Mon, 12 Aug 2019 15:40:57 +0300 Subject: [PATCH 33/63] Fixed issues found by valgrind - mysqltest didn't free read_command_buf - wait_for_slave_param did write different things to the log if valgrind was used. - Table open cache should not write the initial variable value as it can depend on the configuration or if valgrind is used - A variable in GetResult was used uninitalized --- client/mysqltest.cc | 3 ++- mysql-test/include/wait_for_slave_param.inc | 2 +- .../suite/rpl/r/rpl_gtid_delete_domain.result | 4 ++-- .../sys_vars/r/table_open_cache_basic.result | 20 +++------------- .../sys_vars/t/table_open_cache_basic.test | 23 +++---------------- storage/connect/myconn.cpp | 2 +- 6 files changed, 12 insertions(+), 42 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 7c46bd194c5..ad868722dfb 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -193,6 +193,7 @@ static char TMPDIR[FN_REFLEN]; static char global_subst_from[200]; static char global_subst_to[200]; static char *global_subst= NULL; +static char *read_command_buf= NULL; static MEM_ROOT require_file_root; static const my_bool my_true= 1; static const my_bool my_false= 0; @@ -1531,6 +1532,7 @@ void free_used_memory() free_defaults(default_argv); free_root(&require_file_root, MYF(0)); free_re(); + my_free(read_command_buf); #ifdef _WIN32 free_tmp_sh_file(); free_win_path_patterns(); @@ -6563,7 +6565,6 @@ static inline bool is_escape_char(char c, char in_string) */ -static char *read_command_buf= NULL; static size_t read_command_buflen= 0; static const size_t max_multibyte_length= 6; diff --git a/mysql-test/include/wait_for_slave_param.inc b/mysql-test/include/wait_for_slave_param.inc index 25020d46ed9..b06dee3c640 100644 --- a/mysql-test/include/wait_for_slave_param.inc +++ b/mysql-test/include/wait_for_slave_param.inc @@ -69,7 +69,7 @@ if (!$_slave_param_comparison) if ($rpl_debug) { - --echo Waiting until '$slave_param' $_slave_param_comparison '$slave_param_value' [timeout='$_slave_timeout', \$slave_error_param='$slave_error_param'] + --echo Waiting until '$slave_param' $_slave_param_comparison '$slave_param_value' [\$slave_error_param='$slave_error_param'] } --let $_slave_check_configured= query_get_value("SHOW SLAVE STATUS", Slave_IO_Running, 1) diff --git a/mysql-test/suite/rpl/r/rpl_gtid_delete_domain.result b/mysql-test/suite/rpl/r/rpl_gtid_delete_domain.result index 75a22b78a32..74648501fbe 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_delete_domain.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_delete_domain.result @@ -41,7 +41,7 @@ START SLAVE; .. con='slave' warn='1' qlog='1' rlog='1' aborterr='1' ...==== BEGIN include/wait_for_slave_param.inc [Slave_IO_Running] ==== ... con='slave' warn='1' qlog='1' rlog='1' aborterr='1' -Waiting until 'Slave_IO_Running' = 'Yes' [timeout='300', $slave_error_param='Last_IO_Errno'] +Waiting until 'Slave_IO_Running' = 'Yes' [$slave_error_param='Last_IO_Errno'] [connection slave] ...==== END include/wait_for_slave_param.inc [Slave_IO_Running] ==== ... con='slave' warn='1' qlog='1' rlog='1' aborterr='1' @@ -52,7 +52,7 @@ Waiting until 'Slave_IO_Running' = 'Yes' [timeout='300', $slave_error_param='Las .. con='slave' warn='1' qlog='1' rlog='1' aborterr='1' ...==== BEGIN include/wait_for_slave_param.inc [Slave_SQL_Running] ==== ... con='slave' warn='1' qlog='1' rlog='1' aborterr='1' -Waiting until 'Slave_SQL_Running' = 'Yes' [timeout='300', $slave_error_param='1'] +Waiting until 'Slave_SQL_Running' = 'Yes' [$slave_error_param='1'] [connection slave] ...==== END include/wait_for_slave_param.inc [Slave_SQL_Running] ==== ... con='slave' warn='1' qlog='1' rlog='1' aborterr='1' diff --git a/mysql-test/suite/sys_vars/r/table_open_cache_basic.result b/mysql-test/suite/sys_vars/r/table_open_cache_basic.result index bc373003e1d..2d8e9005f81 100644 --- a/mysql-test/suite/sys_vars/r/table_open_cache_basic.result +++ b/mysql-test/suite/sys_vars/r/table_open_cache_basic.result @@ -1,18 +1,9 @@ SET @start_value = @@global.table_open_cache ; -SELECT @start_value; -@start_value -421 -'#--------------------FN_DYNVARS_001_01------------------------#' -SET @@global.table_open_cache = 99; -SET @@global.table_open_cache = DeFAULT; -SELECT @@global.table_open_cache; -@@global.table_open_cache -2000 '#---------------------FN_DYNVARS_001_02-------------------------#' SET @@global.table_open_cache = Default; -SELECT @@global.table_open_cache = 400; -@@global.table_open_cache = 400 -0 +SELECT @@global.table_open_cache > 0; +@@global.table_open_cache > 0 +1 '#--------------------FN_DYNVARS_001_03------------------------#' SET @@global.table_open_cache = 8; Warnings: @@ -101,13 +92,8 @@ SELECT @@table_open_cache = @@global.table_open_cache ; '#---------------------FN_DYNVARS_001_11----------------------#' SET table_open_cache = 8; ERROR HY000: Variable 'table_open_cache' is a GLOBAL variable and should be set with SET GLOBAL -SET global.table_open_cache = 10; -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'table_open_cache = 10' at line 1 SELECT global.table_open_cache ; ERROR 42S02: Unknown table 'global' in field list SELECT table_open_cache = @@session.table_open_cache ; ERROR 42S22: Unknown column 'table_open_cache' in 'field list' SET @@global.table_open_cache = @start_value; -SELECT @@global.table_open_cache ; -@@global.table_open_cache -421 diff --git a/mysql-test/suite/sys_vars/t/table_open_cache_basic.test b/mysql-test/suite/sys_vars/t/table_open_cache_basic.test index 7d2549cd87f..fc838d1a28b 100644 --- a/mysql-test/suite/sys_vars/t/table_open_cache_basic.test +++ b/mysql-test/suite/sys_vars/t/table_open_cache_basic.test @@ -4,8 +4,8 @@ # Scope: GLOBAL # # Access Type: Dynamic # # Data Type: numeric # -# Default Value: 400 # -# Range: 64-524288 # +# Default Value: 400 # +# Range: 64-524288 # # # # # # Creation Date: 2008-02-13 # @@ -35,18 +35,6 @@ ########################################################################## SET @start_value = @@global.table_open_cache ; -SELECT @start_value; - - ---echo '#--------------------FN_DYNVARS_001_01------------------------#' -######################################################################## -# Display the DEFAULT value of table_open_cache # -######################################################################## - -SET @@global.table_open_cache = 99; -SET @@global.table_open_cache = DeFAULT; -SELECT @@global.table_open_cache; - --echo '#---------------------FN_DYNVARS_001_02-------------------------#' ############################################### @@ -54,7 +42,7 @@ SELECT @@global.table_open_cache; ############################################### SET @@global.table_open_cache = Default; -SELECT @@global.table_open_cache = 400; +SELECT @@global.table_open_cache > 0; --echo '#--------------------FN_DYNVARS_001_03------------------------#' ######################################################################## @@ -152,8 +140,6 @@ SELECT @@table_open_cache = @@global.table_open_cache ; --Error ER_GLOBAL_VARIABLE SET table_open_cache = 8; ---Error ER_PARSE_ERROR -SET global.table_open_cache = 10; --Error ER_UNKNOWN_TABLE SELECT global.table_open_cache ; --Error ER_BAD_FIELD_ERROR @@ -165,10 +151,7 @@ SELECT table_open_cache = @@session.table_open_cache ; ############################## SET @@global.table_open_cache = @start_value; -SELECT @@global.table_open_cache ; - ################################################################## # END OF table_open_cache TESTS # ################################################################## - diff --git a/storage/connect/myconn.cpp b/storage/connect/myconn.cpp index 253c42bb002..6de5a73875c 100644 --- a/storage/connect/myconn.cpp +++ b/storage/connect/myconn.cpp @@ -879,7 +879,7 @@ MYSQL_FIELD *MYSQLC::GetNextField(void) PQRYRES MYSQLC::GetResult(PGLOBAL g, bool pdb) { PCSZ fmt; - char *name, v; + char *name, v= 0; int n; bool uns; PCOLRES *pcrp, crp; From 609ea2f37b8169a7c282fe2d607c2412467ccbbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 12 Aug 2019 18:50:54 +0300 Subject: [PATCH 34/63] MDEV-17614: After-merge fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MDEV-17614 flags INSERT…ON DUPLICATE KEY UPDATE unsafe for statement-based replication when there are multiple unique indexes. This correctly fixes something whose attempted fix in MySQL 5.7 in mysql/mysql-server@c93b0d9a972cb6f98fd445f2b69d924350f9128a caused lock conflicts. That change was reverted in MySQL 5.7.26 in mysql/mysql-server@066b6fdd433aa6673622341f1a2f0a3a20018043 (with a substantial amount of other changes). In MDEV-17073 we already disabled the unfortunate MySQL change when statement-based replication was not being used. Now, thanks to MDEV-17614, we can actually remove the change altogether. This reverts commit 8a346f31b913daa011085afec2b2d38450c73e00 (MDEV-17073) and mysql/mysql-server@c93b0d9a972cb6f98fd445f2b69d924350f9128a while keeping the test cases. --- .../r/auto_increment_dup,skip-log-bin.rdiff | 51 ----- .../suite/innodb/r/auto_increment_dup.result | 27 +-- .../suite/innodb/t/auto_increment_dup.test | 8 - mysql-test/suite/rpl/disabled.def | 1 - mysql-test/suite/rpl/r/rpl_mdev_17614.result | 31 ++++ sql/sql_class.cc | 6 - storage/innobase/include/ha_prototypes.h | 3 - storage/innobase/include/row0ins.h | 4 - storage/innobase/que/que0que.cc | 5 - storage/innobase/row/row0ins.cc | 175 +----------------- storage/innobase/row/row0mysql.cc | 3 - 11 files changed, 55 insertions(+), 259 deletions(-) delete mode 100644 mysql-test/suite/innodb/r/auto_increment_dup,skip-log-bin.rdiff diff --git a/mysql-test/suite/innodb/r/auto_increment_dup,skip-log-bin.rdiff b/mysql-test/suite/innodb/r/auto_increment_dup,skip-log-bin.rdiff deleted file mode 100644 index 7b4ec54eed8..00000000000 --- a/mysql-test/suite/innodb/r/auto_increment_dup,skip-log-bin.rdiff +++ /dev/null @@ -1,51 +0,0 @@ ---- auto_increment_dup.result -+++ auto_increment_dup,skip-log-bin.reject -@@ -89,13 +89,14 @@ - SET DEBUG_SYNC='execute_command_after_close_tables SIGNAL continue'; - affected rows: 0 - INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2'; --ERROR HY000: Lock wait timeout exceeded; try restarting transaction -+affected rows: 3 -+info: Records: 3 Duplicates: 0 Warnings: 0 - connection con1; - # - # 2 duplicates - # --affected rows: 3 --info: Records: 3 Duplicates: 0 Warnings: 0 -+affected rows: 4 -+info: Records: 3 Duplicates: 1 Warnings: 0 - connection default; - # - # 3 rows -@@ -103,19 +104,21 @@ - SELECT * FROM t1 order by k; - id k c - 1 1 NULL --2 2 NULL --3 3 NULL --affected rows: 3 -+4 2 1 -+2 3 NULL -+5 4 NULL -+6 5 NULL -+affected rows: 5 - INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2'; --affected rows: 4 --info: Records: 3 Duplicates: 1 Warnings: 0 -+affected rows: 6 -+info: Records: 3 Duplicates: 3 Warnings: 0 - SELECT * FROM t1 order by k; - id k c - 1 1 NULL --2 2 2 --3 3 NULL --7 4 NULL --8 5 NULL -+4 2 2 -+2 3 NULL -+5 4 2 -+6 5 2 - affected rows: 5 - disconnect con1; - disconnect con2; diff --git a/mysql-test/suite/innodb/r/auto_increment_dup.result b/mysql-test/suite/innodb/r/auto_increment_dup.result index 1467a459fc1..9926047b665 100644 --- a/mysql-test/suite/innodb/r/auto_increment_dup.result +++ b/mysql-test/suite/innodb/r/auto_increment_dup.result @@ -89,13 +89,14 @@ affected rows: 0 SET DEBUG_SYNC='execute_command_after_close_tables SIGNAL continue'; affected rows: 0 INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2'; -ERROR HY000: Lock wait timeout exceeded; try restarting transaction +affected rows: 3 +info: Records: 3 Duplicates: 0 Warnings: 0 connection con1; # # 2 duplicates # -affected rows: 3 -info: Records: 3 Duplicates: 0 Warnings: 0 +affected rows: 4 +info: Records: 3 Duplicates: 1 Warnings: 0 connection default; # # 3 rows @@ -103,19 +104,21 @@ connection default; SELECT * FROM t1 order by k; id k c 1 1 NULL -2 2 NULL -3 3 NULL -affected rows: 3 +4 2 1 +2 3 NULL +5 4 NULL +6 5 NULL +affected rows: 5 INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2'; -affected rows: 4 -info: Records: 3 Duplicates: 1 Warnings: 0 +affected rows: 6 +info: Records: 3 Duplicates: 3 Warnings: 0 SELECT * FROM t1 order by k; id k c 1 1 NULL -2 2 2 -3 3 NULL -7 4 NULL -8 5 NULL +4 2 2 +2 3 NULL +5 4 2 +6 5 2 affected rows: 5 disconnect con1; disconnect con2; diff --git a/mysql-test/suite/innodb/t/auto_increment_dup.test b/mysql-test/suite/innodb/t/auto_increment_dup.test index aa399e5966d..9e54a6a8a66 100644 --- a/mysql-test/suite/innodb/t/auto_increment_dup.test +++ b/mysql-test/suite/innodb/t/auto_increment_dup.test @@ -8,8 +8,6 @@ --source include/have_debug_sync.inc --source include/innodb_binlog.inc -let $stmt= `SELECT @@GLOBAL.log_bin`; - set global transaction isolation level repeatable read; CREATE TABLE t1( @@ -84,13 +82,7 @@ SET DEBUG_SYNC='ha_write_row_end SIGNAL write_row_done WAIT_FOR continue'; --reap SET DEBUG_SYNC='execute_command_after_close_tables SIGNAL continue'; -if ($stmt) { ---error ER_LOCK_WAIT_TIMEOUT INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2'; -} -if (!$stmt) { -INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2'; -} --connection con1 --echo # diff --git a/mysql-test/suite/rpl/disabled.def b/mysql-test/suite/rpl/disabled.def index cfebf0f6ff1..59ca2958e80 100644 --- a/mysql-test/suite/rpl/disabled.def +++ b/mysql-test/suite/rpl/disabled.def @@ -15,4 +15,3 @@ rpl_get_master_version_and_clock : Bug#11766137 Jan 05 2011 joro Valgrind warnin rpl_partition_archive : MDEV-5077 2013-09-27 svoj Cannot exchange partition with archive table rpl_row_binlog_max_cache_size : MDEV-11092 rpl_row_index_choice : MDEV-11666 -rpl_mdev_17614 : MDEV-17614/MDEV-17073 Unexpected lock conflict diff --git a/mysql-test/suite/rpl/r/rpl_mdev_17614.result b/mysql-test/suite/rpl/r/rpl_mdev_17614.result index 28de23e28c9..39057334926 100644 --- a/mysql-test/suite/rpl/r/rpl_mdev_17614.result +++ b/mysql-test/suite/rpl/r/rpl_mdev_17614.result @@ -3,19 +3,24 @@ include/master-slave.inc call mtr.add_suppression("Unsafe statement written to the binary log using statement format"); CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY , b INT, UNIQUE(b), c int) engine=innodb; +connection slave; +connection master; INSERT INTO t1 VALUES (1, 1, 1); BEGIN; INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); Warnings: Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe +connection master1; INSERT INTO t1 VALUES(2, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); Warnings: Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe +connection master; COMMIT; SELECT * FROM t1; a b c 1 1 2 2 2 3 +connection slave; include/wait_for_slave_sql_error.inc [errno=1062] Last_SQL_Error = 'Error 'Duplicate entry '1' for key 'b'' on query. Default database: 'test'. Query: 'INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c)'' #Different value from server @@ -26,61 +31,85 @@ a b c stop slave; include/wait_for_slave_to_stop.inc reset slave; +connection master; reset master; drop table t1; +connection slave; start slave; include/wait_for_slave_to_start.inc +connection master; CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY auto_increment, b INT, UNIQUE(b), c int) engine=innodb; +connection slave; +connection master; INSERT INTO t1 VALUES (default, 1, 1); BEGIN; INSERT INTO t1 VALUES (default, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +connection master1; INSERT INTO t1 VALUES(default, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +connection master; COMMIT; SELECT * FROM t1; a b c 1 1 2 3 2 3 +connection slave; #same data as master SELECT * FROM t1; a b c 1 1 2 3 2 3 +connection master; drop table t1; +connection slave; +connection master; CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT, UNIQUE(b), c int, d int ) engine=innodb; +connection slave; +connection master; INSERT INTO t1 VALUES (1, 1, 1, 1); BEGIN; INSERT INTO t1 VALUES (2, NULL, 2, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); Warnings: Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe +connection master1; INSERT INTO t1 VALUES(3, NULL, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); Warnings: Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe +connection master; COMMIT; SELECT * FROM t1; a b c d 1 1 1 1 2 NULL 2 2 3 NULL 2 3 +connection slave; #same data as master SELECT * FROM t1; a b c d 1 1 1 1 2 NULL 2 2 3 NULL 2 3 +connection master; drop table t1; +connection slave; +connection master; CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY auto_increment, b INT, UNIQUE(b), c int) engine=innodb; +connection slave; +connection master; INSERT INTO t1 VALUES (1, 1, 1); BEGIN; INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +connection master1; INSERT INTO t1 VALUES(2, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c); +connection master; COMMIT; SELECT * FROM t1; a b c 1 1 2 2 2 3 +connection slave; include/wait_for_slave_sql_error.inc [errno=1062] Last_SQL_Error = 'Error 'Duplicate entry '1' for key 'b'' on query. Default database: 'test'. Query: 'INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c)'' #Different value from server @@ -91,8 +120,10 @@ a b c stop slave; include/wait_for_slave_to_stop.inc reset slave; +connection master; reset master; drop table t1; +connection slave; start slave; include/wait_for_slave_to_start.inc include/rpl_end.inc diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 0f6003264b6..20366742084 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -4553,12 +4553,6 @@ extern "C" int thd_rpl_is_parallel(const MYSQL_THD thd) return thd->rgi_slave && thd->rgi_slave->is_parallel_exec; } -extern "C" int thd_rpl_stmt_based(const MYSQL_THD thd) -{ - return thd && - !thd->is_current_stmt_binlog_format_row() && - !thd->is_current_stmt_binlog_disabled(); -} /* Returns high resolution timestamp for the start of the current query. */ diff --git a/storage/innobase/include/ha_prototypes.h b/storage/innobase/include/ha_prototypes.h index 7fd0de92562..693dcd15163 100644 --- a/storage/innobase/include/ha_prototypes.h +++ b/storage/innobase/include/ha_prototypes.h @@ -121,9 +121,6 @@ thd_is_replication_slave_thread( /*============================*/ THD* thd); /*!< in: thread handle */ -/** @return whether statement-based replication is active */ -extern "C" int thd_rpl_stmt_based(const THD* thd); - /******************************************************************//** Returns true if the transaction this thread is processing has edited non-transactional tables. Used by the deadlock detector when deciding diff --git a/storage/innobase/include/row0ins.h b/storage/innobase/include/row0ins.h index 2d4e9f67562..3a85d7a21c4 100644 --- a/storage/innobase/include/row0ins.h +++ b/storage/innobase/include/row0ins.h @@ -196,10 +196,6 @@ struct ins_node_t{ entry_list and sys fields are stored here; if this is NULL, entry list should be created and buffers for sys fields in row allocated */ - dict_index_t* duplicate; - /* This is the first index that reported - DB_DUPLICATE_KEY. Used in the case of REPLACE - or INSERT ... ON DUPLICATE UPDATE. */ ulint magic_n; }; diff --git a/storage/innobase/que/que0que.cc b/storage/innobase/que/que0que.cc index 9b98cdbcdcb..1d3d1573299 100644 --- a/storage/innobase/que/que0que.cc +++ b/storage/innobase/que/que0que.cc @@ -684,11 +684,6 @@ que_thr_stop( trx->lock.wait_thr = thr; thr->state = QUE_THR_LOCK_WAIT; - } else if (trx->duplicates && trx->error_state == DB_DUPLICATE_KEY - && thd_rpl_stmt_based(trx->mysql_thd)) { - - return(FALSE); - } else if (trx->error_state != DB_SUCCESS && trx->error_state != DB_LOCK_WAIT) { diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index ce394390679..ece291378b6 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -88,7 +88,6 @@ ins_node_create( node->select = NULL; node->trx_id = 0; - node->duplicate = NULL; node->entry_sys_heap = mem_heap_create(128); @@ -191,7 +190,6 @@ ins_node_set_new_row( node->state = INS_NODE_SET_IX_LOCK; node->index = NULL; node->entry = NULL; - node->duplicate = NULL; node->row = row; @@ -2320,12 +2318,6 @@ row_ins_duplicate_error_in_clust( true, ULINT_UNDEFINED, &heap); - ulint lock_type = - trx->isolation_level <= TRX_ISO_READ_COMMITTED - || (trx->mysql_thd - && !thd_rpl_stmt_based(trx->mysql_thd)) - ? LOCK_REC_NOT_GAP : LOCK_ORDINARY; - /* We set a lock on the possible duplicate: this is needed in logical logging of MySQL to make sure that in roll-forward we get the same duplicate @@ -2342,13 +2334,13 @@ row_ins_duplicate_error_in_clust( INSERT ON DUPLICATE KEY UPDATE). */ err = row_ins_set_exclusive_rec_lock( - lock_type, + LOCK_REC_NOT_GAP, btr_cur_get_block(cursor), rec, cursor->index, offsets, thr); } else { err = row_ins_set_shared_rec_lock( - lock_type, + LOCK_REC_NOT_GAP, btr_cur_get_block(cursor), rec, cursor->index, offsets, thr); } @@ -2363,7 +2355,10 @@ row_ins_duplicate_error_in_clust( if (row_ins_dupl_error_with_rec( rec, entry, cursor->index, offsets)) { - goto duplicate; +duplicate: + trx->error_info = cursor->index; + err = DB_DUPLICATE_KEY; + goto func_exit; } } } @@ -2406,10 +2401,7 @@ row_ins_duplicate_error_in_clust( if (row_ins_dupl_error_with_rec( rec, entry, cursor->index, offsets)) { -duplicate: - trx->error_info = cursor->index; - err = DB_DUPLICATE_KEY; - goto func_exit; + goto duplicate; } } @@ -3023,46 +3015,6 @@ row_ins_sec_index_entry_low( &cursor, 0, __FILE__, __LINE__, &mtr); } - if (!(flags & BTR_NO_LOCKING_FLAG) - && dict_index_is_unique(index) - && thr_get_trx(thr)->duplicates - && thr_get_trx(thr)->isolation_level >= TRX_ISO_REPEATABLE_READ - && thd_rpl_stmt_based(thr_get_trx(thr)->mysql_thd)) { - - /* In statement-based replication, when replicating a - REPLACE statement or ON DUPLICATE KEY UPDATE clause, a - gap lock is taken on the position of the to-be-inserted record, - to avoid other concurrent transactions from inserting the same - record. */ - - dberr_t err; - const rec_t* rec = page_rec_get_next_const( - btr_cur_get_rec(&cursor)); - - ut_ad(!page_rec_is_infimum(rec)); - - offsets = rec_get_offsets(rec, index, offsets, true, - ULINT_UNDEFINED, &offsets_heap); - - err = row_ins_set_exclusive_rec_lock( - LOCK_GAP, btr_cur_get_block(&cursor), rec, - index, offsets, thr); - - switch (err) { - case DB_SUCCESS: - case DB_SUCCESS_LOCKED_REC: - if (thr_get_trx(thr)->error_state != DB_DUPLICATE_KEY) { - break; - } - /* Fall through (skip actual insert) after we have - successfully acquired the gap lock. */ - default: - goto func_exit; - } - } - - ut_ad(thr_get_trx(thr)->error_state == DB_SUCCESS); - if (dup_chk_only) { goto func_exit; } @@ -3578,13 +3530,6 @@ row_ins( DBUG_PRINT("row_ins", ("table: %s", node->table->name.m_name)); - trx_t* trx = thr_get_trx(thr); - - if (node->duplicate) { - ut_ad(thd_rpl_stmt_based(trx->mysql_thd)); - trx->error_state = DB_DUPLICATE_KEY; - } - if (node->state == INS_NODE_ALLOC_ROW_ID) { row_ins_alloc_row_id_step(node); @@ -3610,91 +3555,7 @@ row_ins( if (node->index->type != DICT_FTS) { dberr_t err = row_ins_index_entry_step(node, thr); - switch (err) { - case DB_SUCCESS: - break; - case DB_NO_REFERENCED_ROW: - if (!dict_index_is_unique(node->index)) { - DBUG_RETURN(err); - } - /* fall through */ - case DB_DUPLICATE_KEY: - ut_ad(dict_index_is_unique(node->index)); - - if (trx->isolation_level - >= TRX_ISO_REPEATABLE_READ - && trx->duplicates - && !node->table->is_temporary() - && thd_rpl_stmt_based(trx->mysql_thd)) { - - /* When we are in REPLACE statement or - INSERT .. ON DUPLICATE UPDATE - statement, we process all the - unique secondary indexes, even after we - encounter a duplicate error. This is - done to take necessary gap locks in - secondary indexes to block concurrent - transactions from inserting the - searched records. */ - if (err == DB_NO_REFERENCED_ROW - && node->duplicate) { - /* A foreign key check on a - unique index may fail to - find the record. - - Consider as a example - following: - create table child(a int not null - primary key, b int not null, - c int, - unique key (b), - foreign key (b) references - parent (id)) engine=innodb; - - insert into child values - (1,1,2); - - insert into child(a) values - (1) on duplicate key update - c = 3; - - Now primary key value 1 - naturally causes duplicate - key error that will be - stored on node->duplicate. - If there was no duplicate - key error, we should return - the actual no referenced - row error. - - As value for - column b used in both unique - key and foreign key is not - provided, server uses 0 as a - search value. This is - naturally, not found leading - to DB_NO_REFERENCED_ROW. - But, we should update the - row with primay key value 1 - anyway. - - Return the - original DB_DUPLICATE_KEY - error after - placing all gaplocks. */ - err = DB_DUPLICATE_KEY; - break; - } else if (!node->duplicate) { - /* Save 1st dup error. Ignore - subsequent dup errors. */ - node->duplicate = node->index; - trx->error_state - = DB_DUPLICATE_KEY; - } - break; - } - // fall through - default: + if (err != DB_SUCCESS) { DBUG_RETURN(err); } } @@ -3711,31 +3572,13 @@ row_ins( node->index = dict_table_get_next_index(node->index); node->entry = UT_LIST_GET_NEXT(tuple_list, node->entry); } - - /* After encountering a duplicate key error, we process - remaining indexes just to place gap locks and no actual - insertion will take place. These gap locks are needed - only for unique indexes. So skipping non-unique indexes. */ - if (node->duplicate) { - ut_ad(thd_rpl_stmt_based(trx->mysql_thd)); - while (node->index - && !dict_index_is_unique(node->index)) { - - node->index = dict_table_get_next_index( - node->index); - node->entry = UT_LIST_GET_NEXT(tuple_list, - node->entry); - } - trx->error_state = DB_DUPLICATE_KEY; - } } ut_ad(node->entry == NULL); - trx->error_info = node->duplicate; node->state = INS_NODE_ALLOC_ROW_ID; - DBUG_RETURN(node->duplicate ? DB_DUPLICATE_KEY : DB_SUCCESS); + DBUG_RETURN(DB_SUCCESS); } /***********************************************************//** diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index fd87f8d03bc..f3d48edfb80 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -1435,7 +1435,6 @@ error_exit: goto run_again; } - node->duplicate = NULL; trx->op_info = ""; if (blob_heap != NULL) { @@ -1445,8 +1444,6 @@ error_exit: return(err); } - node->duplicate = NULL; - if (dict_table_has_fts_index(table)) { doc_id_t doc_id; From eff898f2a0d9888815ec3fb7e7aae93b319f6796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Tue, 13 Aug 2019 12:30:36 +0300 Subject: [PATCH 35/63] MDEV-20335: Extra trans_commit_stmt after rollback caused by incorrect fix of MDEV-14401 Fix incorrect else that should have been else if. --- sql/sql_parse.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 385319d80ad..adead650029 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5487,7 +5487,7 @@ finish: if (thd->is_error() || (thd->variables.option_bits & OPTION_MASTER_SQL_ERROR)) trans_rollback_stmt(thd); #ifdef WITH_WSREP - if (thd->spcont && + else if (thd->spcont && (thd->wsrep_conflict_state == MUST_ABORT || thd->wsrep_conflict_state == ABORTED || thd->wsrep_conflict_state == CERT_FAILURE)) From c738aa240e5bea8292e099affd988a6f95268e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 13 Aug 2019 12:39:08 +0300 Subject: [PATCH 36/63] MDEV-20138 innodb.trx_id_future fails on big-endian Skip the test on big-endian systems. In MariaDB Server 10.0 and 10.1 (as well as MySQL 5.6), the implementation of innodb_checksum_algorithm=crc32 wrongly assumes little-endian byte order. --- mysql-test/suite/innodb/t/trx_id_future.test | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mysql-test/suite/innodb/t/trx_id_future.test b/mysql-test/suite/innodb/t/trx_id_future.test index deba753caca..5560ba22005 100644 --- a/mysql-test/suite/innodb/t/trx_id_future.test +++ b/mysql-test/suite/innodb/t/trx_id_future.test @@ -7,6 +7,16 @@ --source include/have_innodb.inc --source include/not_embedded.inc +perl; +open(OUT, ">$ENV{MYSQLTEST_VARDIR}/log/check.txt") || die; +print OUT "--skip innodb_checksum_algorithm=crc32 needs little-endian\n" +unless unpack("L","macs")==unpack("N","scam"); +close(OUT); +EOF + +--source $MYSQLTEST_VARDIR/log/check.txt +--remove_file $MYSQLTEST_VARDIR/log/check.txt + let PAGE_SIZE=`select @@innodb_page_size`; CREATE TABLE t1(a INT) row_format=redundant engine=innoDB; From 3cee665a0444bd2d0bd881e0e2196d680eb58e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 12 Aug 2019 13:01:33 +0300 Subject: [PATCH 37/63] MDEV-17847 Galera test failure on MW-328[A|B|C] Test changes only. --- mysql-test/suite/galera/disabled.def | 3 -- mysql-test/suite/galera/r/MW-328A.result | 25 ++++++++--- mysql-test/suite/galera/r/MW-328B.result | 2 +- mysql-test/suite/galera/r/MW-328C.result | 2 +- mysql-test/suite/galera/t/MW-328-footer.inc | 2 +- mysql-test/suite/galera/t/MW-328A.test | 48 +++++++++++++++------ mysql-test/suite/galera/t/MW-328B.test | 2 - mysql-test/suite/galera/t/MW-328C.test | 3 +- mysql-test/suite/galera/t/MW-328D.test | 1 - mysql-test/suite/galera/t/MW-328E.test | 1 - 10 files changed, 58 insertions(+), 31 deletions(-) diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index fcb4985ebc9..90b13bd7aa4 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -11,9 +11,6 @@ ############################################################################## MW-286 : MDEV-19992 Galera test failure on MW-286 -MW-328A : MDEV-17847 Galera test failure on MW-328[A|B|C] -MW-328B : MDEV-17847 Galera test failure on MW-328[A|B|C] -MW-328C : MDEV-17847 Galera test failure on MW-328[A|B|C] MW-329 : MDEV-19962 Galera test failure on MW-329 MW-388: MDEV-19803 Long semaphore wait error on galera.MW-388 galera_account_management : MariaDB 10.0 does not support ALTER USER diff --git a/mysql-test/suite/galera/r/MW-328A.result b/mysql-test/suite/galera/r/MW-328A.result index db0301b6bf2..535f04bfbab 100644 --- a/mysql-test/suite/galera/r/MW-328A.result +++ b/mysql-test/suite/galera/r/MW-328A.result @@ -14,14 +14,29 @@ connection node_1X; CALL proc_update();; connection node_2; SET SESSION wsrep_retry_autocommit = 0; -have_successes -1 -have_deadlocks -1 connection node_1; connection node_1X; Got one of the listed errors connection node_1; DROP PROCEDURE proc_update; DROP TABLE t1, t2; -CALL mtr.add_suppression("conflict state 3 after post commit"); +CALL mtr.add_suppression("conflict state ABORTED after post commit"); +connection node_1; +CREATE TABLE t1 (i int primary key, j int) engine=innodb; +INSERT INTO t1 values (1,0); +BEGIN; +UPDATE t1 SET j=1 WHERE i=1; +connection node_2; +UPDATE t1 SET j=2 WHERE i=1; +connection node_1; +COMMIT; +ERROR 40001: Deadlock: wsrep aborted transaction +SELECT * FROM t1; +i j +1 2 +connection node_2; +SELECT * FROM t1; +i j +1 2 +connection node_1; +DROP TABLE t1; diff --git a/mysql-test/suite/galera/r/MW-328B.result b/mysql-test/suite/galera/r/MW-328B.result index e898e315ca8..531c5de8029 100644 --- a/mysql-test/suite/galera/r/MW-328B.result +++ b/mysql-test/suite/galera/r/MW-328B.result @@ -20,4 +20,4 @@ Got one of the listed errors connection node_1; DROP PROCEDURE proc_update; DROP TABLE t1, t2; -CALL mtr.add_suppression("conflict state 3 after post commit"); +CALL mtr.add_suppression("conflict state ABORTED after post commit"); diff --git a/mysql-test/suite/galera/r/MW-328C.result b/mysql-test/suite/galera/r/MW-328C.result index d8e164e7b4a..f8d747c5df1 100644 --- a/mysql-test/suite/galera/r/MW-328C.result +++ b/mysql-test/suite/galera/r/MW-328C.result @@ -20,4 +20,4 @@ Got one of the listed errors connection node_1; DROP PROCEDURE proc_update; DROP TABLE t1, t2; -CALL mtr.add_suppression("conflict state 3 after post commit"); +CALL mtr.add_suppression("conflict state ABORTED after post commit"); diff --git a/mysql-test/suite/galera/t/MW-328-footer.inc b/mysql-test/suite/galera/t/MW-328-footer.inc index 5b736df220f..12a4bf12590 100644 --- a/mysql-test/suite/galera/t/MW-328-footer.inc +++ b/mysql-test/suite/galera/t/MW-328-footer.inc @@ -15,4 +15,4 @@ DROP PROCEDURE proc_update; DROP TABLE t1, t2; -CALL mtr.add_suppression("conflict state 3 after post commit"); +CALL mtr.add_suppression("conflict state ABORTED after post commit"); diff --git a/mysql-test/suite/galera/t/MW-328A.test b/mysql-test/suite/galera/t/MW-328A.test index 09aad1bcf60..da1040b3e5d 100644 --- a/mysql-test/suite/galera/t/MW-328A.test +++ b/mysql-test/suite/galera/t/MW-328A.test @@ -3,13 +3,16 @@ # # -# Attempt to insert into t2 and check if insert actually inserted rows if -# a success was reported. +# test phase 1 is not deterministic +# +# Here we attempt to insert into t2 and check if insert actually +# inserted rows if a success was reported. +# +# However, deadlocks may or may not happen in this test execution +# it all depends on timing. # ---source include/big_test.inc --source include/galera_cluster.inc ---source include/have_innodb.inc --source suite/galera/t/MW-328-header.inc --connection node_2 @@ -25,7 +28,7 @@ while ($count) { TRUNCATE TABLE t2; - --error 0,1213 + --error 0,ER_LOCK_DEADLOCK INSERT IGNORE INTO t2 SELECT f2 FROM t1; if ($mysql_errno != 1213) { --inc $successes @@ -44,14 +47,31 @@ while ($count) --enable_query_log -# -# Check that the test produced both deadlocks and successes -# - ---disable_query_log ---eval SELECT $successes > 0 AS have_successes ---eval SELECT $deadlocks > 0 AS have_deadlocks ---enable_query_log - --source suite/galera/t/MW-328-footer.inc + +# +# Test phase 2 is deterministic +# Here we generate a sure conflict in node 1 and verify that +# insert failed in both nodes +# +--connection node_1 +CREATE TABLE t1 (i int primary key, j int) engine=innodb; +INSERT INTO t1 values (1,0); + +BEGIN; +UPDATE t1 SET j=1 WHERE i=1; + +--connection node_2 +UPDATE t1 SET j=2 WHERE i=1; + +--connection node_1 +--error ER_LOCK_DEADLOCK +COMMIT; + +SELECT * FROM t1; +--connection node_2 +SELECT * FROM t1; +--connection node_1 + +DROP TABLE t1; diff --git a/mysql-test/suite/galera/t/MW-328B.test b/mysql-test/suite/galera/t/MW-328B.test index 000b0d8a9ab..11969dd0b47 100644 --- a/mysql-test/suite/galera/t/MW-328B.test +++ b/mysql-test/suite/galera/t/MW-328B.test @@ -7,9 +7,7 @@ # gets the deadlock error # ---source include/big_test.inc --source include/galera_cluster.inc ---source include/have_innodb.inc --source suite/galera/t/MW-328-header.inc --connection node_2 diff --git a/mysql-test/suite/galera/t/MW-328C.test b/mysql-test/suite/galera/t/MW-328C.test index 72a8480923c..1594547d0de 100644 --- a/mysql-test/suite/galera/t/MW-328C.test +++ b/mysql-test/suite/galera/t/MW-328C.test @@ -7,9 +7,8 @@ # masks all deadlock errors # ---source include/big_test.inc --source include/galera_cluster.inc ---source include/have_innodb.inc +--source include/big_test.inc --source suite/galera/t/MW-328-header.inc --connection node_2 diff --git a/mysql-test/suite/galera/t/MW-328D.test b/mysql-test/suite/galera/t/MW-328D.test index d5cffdb8f47..e8a22f22a99 100644 --- a/mysql-test/suite/galera/t/MW-328D.test +++ b/mysql-test/suite/galera/t/MW-328D.test @@ -7,7 +7,6 @@ # --source include/galera_cluster.inc ---source include/have_innodb.inc CREATE TABLE t1 (i INT) ENGINE = InnoDB; INSERT INTO t1 (i) VALUES(1); diff --git a/mysql-test/suite/galera/t/MW-328E.test b/mysql-test/suite/galera/t/MW-328E.test index fd4b0bf9039..34b17be7b08 100644 --- a/mysql-test/suite/galera/t/MW-328E.test +++ b/mysql-test/suite/galera/t/MW-328E.test @@ -7,7 +7,6 @@ # --source include/galera_cluster.inc ---source include/have_innodb.inc create table t1 (i int primary key, j int) engine=innodb; create table t2 (i int primary key, j int) engine=innodb; From 5edc4ea4d968e81408ab9e343a0b3940797f98fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Tue, 13 Aug 2019 09:24:31 +0300 Subject: [PATCH 38/63] MDEV-20324: Galera threads are not registered to performance schema Galera threads were not registered to performance schema and used pthread_create when mysql_thread_create should have been used. Added test case to verify current galera performance schema instrumentation does work. --- .../galera/r/galera_performance_schema.result | 44 ++++++++++++++ mysql-test/suite/galera/t/MW-328A.test | 1 + .../galera/t/galera_performance_schema.test | 58 +++++++++++++++++++ sql/wsrep_mysqld.cc | 16 ++++- sql/wsrep_mysqld.h | 7 +++ sql/wsrep_sst.cc | 8 +-- sql/wsrep_thd.cc | 21 ++++++- 7 files changed, 148 insertions(+), 7 deletions(-) create mode 100644 mysql-test/suite/galera/r/galera_performance_schema.result create mode 100644 mysql-test/suite/galera/t/galera_performance_schema.test diff --git a/mysql-test/suite/galera/r/galera_performance_schema.result b/mysql-test/suite/galera/r/galera_performance_schema.result new file mode 100644 index 00000000000..5b4994556d6 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_performance_schema.result @@ -0,0 +1,44 @@ +use performance_schema; +SELECT name +FROM threads +WHERE name LIKE 'thread/sql/wsrep%' +ORDER BY name; +name thread/sql/wsrep_applier_thread +name thread/sql/wsrep_rollbacker_thread +use test; +create table t1 (a int not null primary key) engine=innodb; +insert into t1 values (1),(2); +use performance_schema; +select name from mutex_instances where name like 'wait/synch/mutex/sql/LOCK_wsrep%' order by name; +name wait/synch/mutex/sql/LOCK_wsrep_config_state +name wait/synch/mutex/sql/LOCK_wsrep_desync +name wait/synch/mutex/sql/LOCK_wsrep_ready +name wait/synch/mutex/sql/LOCK_wsrep_replaying +name wait/synch/mutex/sql/LOCK_wsrep_rollback +name wait/synch/mutex/sql/LOCK_wsrep_slave_threads +name wait/synch/mutex/sql/LOCK_wsrep_sst +name wait/synch/mutex/sql/LOCK_wsrep_sst_init +select name from cond_instances where name like 'wait/synch/cond/sql/COND_wsrep%' order by name; +name wait/synch/cond/sql/COND_wsrep_ready +name wait/synch/cond/sql/COND_wsrep_replaying +name wait/synch/cond/sql/COND_wsrep_rollback +name wait/synch/cond/sql/COND_wsrep_sst +name wait/synch/cond/sql/COND_wsrep_sst_init +connection node_2; +use test; +SET SESSION wsrep_on=OFF; +CREATE TABLE t2 (f1 INTEGER) engine=innodb; +connection node_1; +use test; +CREATE TABLE t2 (f1 INTEGER) engine=innodb; +connection node_2; +SET SESSION wsrep_on=ON; +SELECT COUNT(*) FROM t1; +COUNT(*) 2 +use performance_schema; +select count(*)>=1 from file_instances where file_name like '%GRA_%.log'; +count(*)>=1 1 +CALL mtr.add_suppression("Slave SQL: Error 'Table 't2' already exists' on query"); +use test; +drop table t1; +drop table t2; diff --git a/mysql-test/suite/galera/t/MW-328A.test b/mysql-test/suite/galera/t/MW-328A.test index da1040b3e5d..dd692a292b8 100644 --- a/mysql-test/suite/galera/t/MW-328A.test +++ b/mysql-test/suite/galera/t/MW-328A.test @@ -13,6 +13,7 @@ # --source include/galera_cluster.inc +--source include/big_test.inc --source suite/galera/t/MW-328-header.inc --connection node_2 diff --git a/mysql-test/suite/galera/t/galera_performance_schema.test b/mysql-test/suite/galera/t/galera_performance_schema.test new file mode 100644 index 00000000000..d54555ea301 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_performance_schema.test @@ -0,0 +1,58 @@ +# +# Test that wsrep mutexes, condition variables, files and +# threads are shown in performance schema +# +--source include/galera_cluster.inc +--source include/have_perfschema.inc + +use performance_schema; + +--vertical_results +--disable_ps_protocol +SELECT name +FROM threads +WHERE name LIKE 'thread/sql/wsrep%' +ORDER BY name; +--enable_ps_protocol + +use test; +create table t1 (a int not null primary key) engine=innodb; +insert into t1 values (1),(2); + +use performance_schema; +select name from mutex_instances where name like 'wait/synch/mutex/sql/LOCK_wsrep%' order by name; +select name from cond_instances where name like 'wait/synch/cond/sql/COND_wsrep%' order by name; +# Whenever a node fails to apply an event on a slave node, the database server creates a +# special binary log file of the event in the data directory. The naming convention the +# node uses for the filename is GRA_*.log. +# Thus, we need to produce a applier failure + +--connection node_2 +--exec rm -rf $MYSQLTEST_VARDIR/mysqld.2/data/GRA_*.log + +# Create applier failure + +use test; +SET SESSION wsrep_on=OFF; +CREATE TABLE t2 (f1 INTEGER) engine=innodb; + +--connection node_1 +use test; +CREATE TABLE t2 (f1 INTEGER) engine=innodb; + +--connection node_2 +SET SESSION wsrep_on=ON; +SELECT COUNT(*) FROM t1; + +use performance_schema; +# +# Below we can't just count number of files as if you run this test more +# than once, test will create more files +# +select count(*)>=1 from file_instances where file_name like '%GRA_%.log'; +CALL mtr.add_suppression("Slave SQL: Error 'Table 't2' already exists' on query"); + +use test; +drop table t1; +drop table t2; + diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 8c3be114c19..12a9dc35a6a 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -184,7 +184,19 @@ static PSI_file_info wsrep_files[]= { { &key_file_wsrep_gra_log, "wsrep_gra_log", 0} }; -#endif + +PSI_thread_key key_wsrep_sst_joiner, key_wsrep_sst_donor, + key_wsrep_rollbacker, key_wsrep_applier; + +static PSI_thread_info wsrep_threads[]= +{ + {&key_wsrep_sst_joiner, "wsrep_sst_joiner_thread", PSI_FLAG_GLOBAL}, + {&key_wsrep_sst_donor, "wsrep_sst_donor_thread", PSI_FLAG_GLOBAL}, + {&key_wsrep_rollbacker, "wsrep_rollbacker_thread", PSI_FLAG_GLOBAL}, + {&key_wsrep_applier, "wsrep_applier_thread", PSI_FLAG_GLOBAL} +}; + +#endif /* HAVE_PSI_INTERFACE */ my_bool wsrep_inited = 0; // initialized ? @@ -789,6 +801,7 @@ void wsrep_thr_init() mysql_mutex_register("sql", wsrep_mutexes, array_elements(wsrep_mutexes)); mysql_cond_register("sql", wsrep_conds, array_elements(wsrep_conds)); mysql_file_register("sql", wsrep_files, array_elements(wsrep_files)); + mysql_thread_register("sql", wsrep_threads, array_elements(wsrep_threads)); #endif mysql_mutex_init(key_LOCK_wsrep_ready, &LOCK_wsrep_ready, MY_MUTEX_INIT_FAST); @@ -804,6 +817,7 @@ void wsrep_thr_init() mysql_mutex_init(key_LOCK_wsrep_slave_threads, &LOCK_wsrep_slave_threads, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_wsrep_desync, &LOCK_wsrep_desync, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_wsrep_config_state, &LOCK_wsrep_config_state, MY_MUTEX_INIT_FAST); + DBUG_VOID_RETURN; } diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index 718e188cdc4..96b3e63914b 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -291,7 +291,14 @@ extern PSI_mutex_key key_LOCK_wsrep_slave_threads; extern PSI_mutex_key key_LOCK_wsrep_desync; extern PSI_file_key key_file_wsrep_gra_log; + +extern PSI_thread_key key_wsrep_sst_joiner; +extern PSI_thread_key key_wsrep_sst_donor; +extern PSI_thread_key key_wsrep_rollbacker; +extern PSI_thread_key key_wsrep_applier; #endif /* HAVE_PSI_INTERFACE */ + + struct TABLE_LIST; class Alter_info; int wsrep_to_isolation_begin(THD *thd, char *db_, char *table_, diff --git a/sql/wsrep_sst.cc b/sql/wsrep_sst.cc index 560db0b6c43..cb8b1cab225 100644 --- a/sql/wsrep_sst.cc +++ b/sql/wsrep_sst.cc @@ -735,10 +735,10 @@ static ssize_t sst_prepare_other (const char* method, pthread_t tmp; sst_thread_arg arg(cmd_str(), env()); mysql_mutex_lock (&arg.lock); - ret = pthread_create (&tmp, NULL, sst_joiner_thread, &arg); + ret = mysql_thread_create (key_wsrep_sst_joiner, &tmp, NULL, sst_joiner_thread, &arg); if (ret) { - WSREP_ERROR("sst_prepare_other(): pthread_create() failed: %d (%s)", + WSREP_ERROR("sst_prepare_other(): mysql_thread_create() failed: %d (%s)", ret, strerror(ret)); return -ret; } @@ -1378,10 +1378,10 @@ static int sst_donate_other (const char* method, pthread_t tmp; sst_thread_arg arg(cmd_str(), env); mysql_mutex_lock (&arg.lock); - ret = pthread_create (&tmp, NULL, sst_donor_thread, &arg); + ret = mysql_thread_create (key_wsrep_sst_donor, &tmp, NULL, sst_donor_thread, &arg); if (ret) { - WSREP_ERROR("sst_donate_other(): pthread_create() failed: %d (%s)", + WSREP_ERROR("sst_donate_other(): mysql_thread_create() failed: %d (%s)", ret, strerror(ret)); return ret; } diff --git a/sql/wsrep_thd.cc b/sql/wsrep_thd.cc index 31b6622d30c..da90faa74cf 100644 --- a/sql/wsrep_thd.cc +++ b/sql/wsrep_thd.cc @@ -418,9 +418,26 @@ static void wsrep_replication_process(THD *thd) static bool create_wsrep_THD(wsrep_thread_args* args) { - ulong old_wsrep_running_threads= wsrep_running_threads; mysql_mutex_lock(&LOCK_thread_count); - bool res= pthread_create(&args->thread_id, &connection_attrib, start_wsrep_THD, + ulong old_wsrep_running_threads= wsrep_running_threads; +#ifdef HAVE_PSI_THREAD_INTERFACE + PSI_thread_key key; + + switch (args->thread_type) + { + case WSREP_APPLIER_THREAD: + key= key_wsrep_applier; + break; + case WSREP_ROLLBACKER_THREAD: + key= key_wsrep_rollbacker; + break; + default: + assert(0); + break; + } +#endif + + bool res= mysql_thread_create(key, &args->thread_id, &connection_attrib, start_wsrep_THD, (void*)args); /* if starting a thread on server startup, wait until the this thread's THD From 20c78a6d3e209c20a08c4f9be546d8e3f1a7636d Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 13 Aug 2019 13:54:59 +0400 Subject: [PATCH 39/63] Fixing `MDEV-20303 SPACE(-1) returns a wrong data type` compilation problem in Windows --- sql/item_strfunc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index b170634d864..74bed5d70ed 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -3180,7 +3180,7 @@ bool Item_func_pad::fix_length_and_dec() DBUG_ASSERT(collation.collation->mbmaxlen > 0); if (args[1]->const_item() && !args[1]->is_expensive()) { - fix_char_length(Repeat_count(args[1]).count()); + fix_char_length_ulonglong(Repeat_count(args[1]).count()); return false; } max_length= MAX_BLOB_WIDTH; From f25e9aa4ba9c7d3a4fbeaa280d2bb39abe023e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 13 Aug 2019 11:37:01 +0300 Subject: [PATCH 40/63] MDEV-20310: Make InnoDB crash tests Valgrind-friendly Use DEBUG_SYNC to hang the execution at the interesting point, and then kill and restart the server externally. This will work also with Valgrind. DBUG_SUICIDE() causes Valgrind to hang, and it could also cause uninteresting reports about memory leaks. While we are at it, let us clean up innodb.innodb_bulk_create_index_debug so that it will actually test the desired functionality also in future versions (with instant ADD COLUMN and DROP COLUMN) and avoid some unnecessary restarts. We are adding two DEBUG_SYNC points for ALTER TABLE, because there were none that would be executed right before ha_commit_trans(). --- .../innodb_bulk_create_index_debug.inc | 89 +++---- mysql-test/suite/innodb/r/alter_copy.result | 8 +- .../r/innodb_bulk_create_index_debug.result | 229 +++++++++++------- mysql-test/suite/innodb/t/alter_copy.test | 15 +- sql/sql_table.cc | 7 +- 5 files changed, 200 insertions(+), 148 deletions(-) diff --git a/mysql-test/suite/innodb/include/innodb_bulk_create_index_debug.inc b/mysql-test/suite/innodb/include/innodb_bulk_create_index_debug.inc index 48de3a1962d..85466e5e4ae 100644 --- a/mysql-test/suite/innodb/include/innodb_bulk_create_index_debug.inc +++ b/mysql-test/suite/innodb/include/innodb_bulk_create_index_debug.inc @@ -4,17 +4,8 @@ # Not supported in embedded -- source include/not_embedded.inc - -# This test case needs to crash the server. Needs a debug server. -- source include/have_debug.inc - -# Don't test this under valgrind, memory leaks will occur. --- source include/not_valgrind.inc - -# Avoid CrashReporter popup on Mac --- source include/not_crashrep.inc - --- source include/have_innodb.inc +-- source include/have_debug_sync.inc # Create Insert Procedure DELIMITER |; @@ -62,21 +53,11 @@ CALL populate_t1(); SELECT COUNT(*) FROM t1; +--enable_info CREATE INDEX idx_title ON t1(title); +--disable_info ---source include/restart_mysqld.inc - -CHECK TABLE t1; - -SELECT * FROM t1 WHERE title = 'a10'; - -SELECT * FROM t1 WHERE title = 'a5000'; - -SELECT * FROM t1 WHERE title = 'a10000'; - -SELECT * FROM t1 WHERE title = 'a10010'; - -DROP TABLE t1; +RENAME TABLE t1 TO t0; -- echo # Test Blob @@ -104,16 +85,32 @@ INSERT INTO t1 VALUES SELECT CHAR_LENGTH(b) FROM t1; -ALTER TABLE t1 DROP COLUMN c; +--enable_info +ALTER TABLE t1 DROP COLUMN c, FORCE; +--disable_info --source include/restart_mysqld.inc -CHECK TABLE t1; +CHECK TABLE t0,t1; SELECT CHAR_LENGTH(b) FROM t1; DROP TABLE t1; +RENAME TABLE t0 to t1; + +CHECK TABLE t1; + +SELECT * FROM t1 WHERE title = 'a10'; + +SELECT * FROM t1 WHERE title = 'a5000'; + +SELECT * FROM t1 WHERE title = 'a10000'; + +SELECT * FROM t1 WHERE title = 'a10010'; + +DROP TABLE t1; + # Test Crash Recovery if ($row_format != 'COMPRESSED') @@ -140,17 +137,16 @@ if ($row_format == 'COMPRESSED') CALL populate_t1(); -- enable_query_log -SET debug_dbug='+d,crash_commit_before'; - -# Write file to make mysql-test-run.pl start up the server again ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect - ---error 2013 +connect (hang,localhost,root); +SET DEBUG_SYNC='alter_table_inplace_trans_commit SIGNAL hung WAIT_FOR ever'; +send CREATE INDEX idx_title ON t1(title); ---enable_reconnect ---source include/wait_until_connected_again.inc ---disable_reconnect +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +let $shutdown_timeout=0; +--source include/restart_mysqld.inc +disconnect hang; SELECT COUNT(*) FROM t1; @@ -194,17 +190,16 @@ INSERT INTO t1 VALUES SELECT CHAR_LENGTH(b) FROM t1; -SET debug_dbug='+d,crash_commit_before'; +connect (hang,localhost,root); +SET DEBUG_SYNC='alter_table_inplace_trans_commit SIGNAL hung WAIT_FOR ever'; +send +ALTER TABLE t1 DROP COLUMN c, FORCE; -# Write file to make mysql-test-run.pl start up the server again ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect - ---error 2013 -ALTER TABLE t1 DROP COLUMN c; - ---enable_reconnect ---source include/wait_until_connected_again.inc ---disable_reconnect +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +--source include/restart_mysqld.inc +disconnect hang; +let $shutdown_timeout=60; CHECK TABLE t1; @@ -212,10 +207,4 @@ SELECT CHAR_LENGTH(b) FROM t1; DROP TABLE t1; -# Restore global variables -if ($row_format == 'COMPRESSED') -{ - SET GLOBAL innodb_file_per_table=default; -} - DROP PROCEDURE populate_t1; diff --git a/mysql-test/suite/innodb/r/alter_copy.result b/mysql-test/suite/innodb/r/alter_copy.result index 286c5152ded..659b8ae03b0 100644 --- a/mysql-test/suite/innodb/r/alter_copy.result +++ b/mysql-test/suite/innodb/r/alter_copy.result @@ -37,7 +37,9 @@ t1 CREATE TABLE `t1` ( FULLTEXT KEY `b_2` (`b`,`c`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ALTER TABLE t1 FORCE, ALGORITHM=COPY; -SET DEBUG_DBUG='+d,crash_commit_before'; +connect hang,localhost,root; +SET DEBUG_SYNC='alter_table_copy_trans_commit SIGNAL hung WAIT_FOR ever'; +# create 32 secondary indexes ALTER TABLE t ADD INDEX(b,c,d,a),ADD INDEX(b,c,a,d),ADD INDEX(b,a,c,d),ADD INDEX(b,a,d,c), ADD INDEX(b,d,a,c),ADD INDEX(b,d,c,a),ADD INDEX(a,b,c,d),ADD INDEX(a,b,d,c), ADD INDEX(a,c,b,d),ADD INDEX(a,c,d,b),ADD INDEX(a,d,b,c),ADD INDEX(a,d,c,b), @@ -47,7 +49,9 @@ ADD INDEX(d,b,a,c),ADD INDEX(d,b,c,a),ADD INDEX(d,c,a,b),ADD INDEX(d,c,b,a), ADD INDEX(a,b,c), ADD INDEX(a,c,b), ADD INDEX(a,c,d), ADD INDEX(a,d,c), ADD INDEX(a,b,d), ADD INDEX(a,d,b), ADD INDEX(b,c,d), ADD INDEX(b,d,c), ALGORITHM=COPY; -ERROR HY000: Lost connection to MySQL server during query +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +disconnect hang; #sql-temporary.frm #sql-temporary.ibd FTS_INDEX_1.ibd diff --git a/mysql-test/suite/innodb/r/innodb_bulk_create_index_debug.result b/mysql-test/suite/innodb/r/innodb_bulk_create_index_debug.result index cd5a3c340da..295a9f1bed8 100644 --- a/mysql-test/suite/innodb/r/innodb_bulk_create_index_debug.result +++ b/mysql-test/suite/innodb/r/innodb_bulk_create_index_debug.result @@ -17,21 +17,9 @@ SELECT COUNT(*) FROM t1; COUNT(*) 10000 CREATE INDEX idx_title ON t1(title); -CHECK TABLE t1; -Table Op Msg_type Msg_text -test.t1 check status OK -SELECT * FROM t1 WHERE title = 'a10'; -class id title -10 10 a10 -SELECT * FROM t1 WHERE title = 'a5000'; -class id title -5000 5000 a5000 -SELECT * FROM t1 WHERE title = 'a10000'; -class id title -10000 10000 a10000 -SELECT * FROM t1 WHERE title = 'a10010'; -class id title -DROP TABLE t1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +RENAME TABLE t1 TO t0; # Test Blob CREATE TABLE t1( a INT PRIMARY KEY, @@ -48,9 +36,12 @@ CHAR_LENGTH(b) 20000 40000 60000 -ALTER TABLE t1 DROP COLUMN c; -CHECK TABLE t1; +ALTER TABLE t1 DROP COLUMN c, FORCE; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +CHECK TABLE t0,t1; Table Op Msg_type Msg_text +test.t0 check status OK test.t1 check status OK SELECT CHAR_LENGTH(b) FROM t1; CHAR_LENGTH(b) @@ -59,14 +50,33 @@ CHAR_LENGTH(b) 40000 60000 DROP TABLE t1; +RENAME TABLE t0 to t1; +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +SELECT * FROM t1 WHERE title = 'a10'; +class id title +10 10 a10 +SELECT * FROM t1 WHERE title = 'a5000'; +class id title +5000 5000 a5000 +SELECT * FROM t1 WHERE title = 'a10000'; +class id title +10000 10000 a10000 +SELECT * FROM t1 WHERE title = 'a10010'; +class id title +DROP TABLE t1; CREATE TABLE t1( class INT, id INT, title VARCHAR(100) ) ENGINE=InnoDB ROW_FORMAT=REDUNDANT; -SET debug_dbug='+d,crash_commit_before'; +connect hang,localhost,root; +SET DEBUG_SYNC='alter_table_inplace_trans_commit SIGNAL hung WAIT_FOR ever'; CREATE INDEX idx_title ON t1(title); -ERROR HY000: Lost connection to MySQL server during query +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +disconnect hang; SELECT COUNT(*) FROM t1; COUNT(*) 10000 @@ -104,9 +114,12 @@ CHAR_LENGTH(b) 20000 40000 60000 -SET debug_dbug='+d,crash_commit_before'; -ALTER TABLE t1 DROP COLUMN c; -ERROR HY000: Lost connection to MySQL server during query +connect hang,localhost,root; +SET DEBUG_SYNC='alter_table_inplace_trans_commit SIGNAL hung WAIT_FOR ever'; +ALTER TABLE t1 DROP COLUMN c, FORCE; +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +disconnect hang; CHECK TABLE t1; Table Op Msg_type Msg_text test.t1 check status OK @@ -137,21 +150,9 @@ SELECT COUNT(*) FROM t1; COUNT(*) 10000 CREATE INDEX idx_title ON t1(title); -CHECK TABLE t1; -Table Op Msg_type Msg_text -test.t1 check status OK -SELECT * FROM t1 WHERE title = 'a10'; -class id title -10 10 a10 -SELECT * FROM t1 WHERE title = 'a5000'; -class id title -5000 5000 a5000 -SELECT * FROM t1 WHERE title = 'a10000'; -class id title -10000 10000 a10000 -SELECT * FROM t1 WHERE title = 'a10010'; -class id title -DROP TABLE t1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +RENAME TABLE t1 TO t0; # Test Blob CREATE TABLE t1( a INT PRIMARY KEY, @@ -168,9 +169,12 @@ CHAR_LENGTH(b) 20000 40000 60000 -ALTER TABLE t1 DROP COLUMN c; -CHECK TABLE t1; +ALTER TABLE t1 DROP COLUMN c, FORCE; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +CHECK TABLE t0,t1; Table Op Msg_type Msg_text +test.t0 check status OK test.t1 check status OK SELECT CHAR_LENGTH(b) FROM t1; CHAR_LENGTH(b) @@ -179,14 +183,33 @@ CHAR_LENGTH(b) 40000 60000 DROP TABLE t1; +RENAME TABLE t0 to t1; +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +SELECT * FROM t1 WHERE title = 'a10'; +class id title +10 10 a10 +SELECT * FROM t1 WHERE title = 'a5000'; +class id title +5000 5000 a5000 +SELECT * FROM t1 WHERE title = 'a10000'; +class id title +10000 10000 a10000 +SELECT * FROM t1 WHERE title = 'a10010'; +class id title +DROP TABLE t1; CREATE TABLE t1( class INT, id INT, title VARCHAR(100) ) ENGINE=InnoDB ROW_FORMAT=COMPACT; -SET debug_dbug='+d,crash_commit_before'; +connect hang,localhost,root; +SET DEBUG_SYNC='alter_table_inplace_trans_commit SIGNAL hung WAIT_FOR ever'; CREATE INDEX idx_title ON t1(title); -ERROR HY000: Lost connection to MySQL server during query +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +disconnect hang; SELECT COUNT(*) FROM t1; COUNT(*) 10000 @@ -224,9 +247,12 @@ CHAR_LENGTH(b) 20000 40000 60000 -SET debug_dbug='+d,crash_commit_before'; -ALTER TABLE t1 DROP COLUMN c; -ERROR HY000: Lost connection to MySQL server during query +connect hang,localhost,root; +SET DEBUG_SYNC='alter_table_inplace_trans_commit SIGNAL hung WAIT_FOR ever'; +ALTER TABLE t1 DROP COLUMN c, FORCE; +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +disconnect hang; CHECK TABLE t1; Table Op Msg_type Msg_text test.t1 check status OK @@ -257,21 +283,9 @@ SELECT COUNT(*) FROM t1; COUNT(*) 10000 CREATE INDEX idx_title ON t1(title); -CHECK TABLE t1; -Table Op Msg_type Msg_text -test.t1 check status OK -SELECT * FROM t1 WHERE title = 'a10'; -class id title -10 10 a10 -SELECT * FROM t1 WHERE title = 'a5000'; -class id title -5000 5000 a5000 -SELECT * FROM t1 WHERE title = 'a10000'; -class id title -10000 10000 a10000 -SELECT * FROM t1 WHERE title = 'a10010'; -class id title -DROP TABLE t1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +RENAME TABLE t1 TO t0; # Test Blob CREATE TABLE t1( a INT PRIMARY KEY, @@ -288,9 +302,12 @@ CHAR_LENGTH(b) 20000 40000 60000 -ALTER TABLE t1 DROP COLUMN c; -CHECK TABLE t1; +ALTER TABLE t1 DROP COLUMN c, FORCE; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +CHECK TABLE t0,t1; Table Op Msg_type Msg_text +test.t0 check status OK test.t1 check status OK SELECT CHAR_LENGTH(b) FROM t1; CHAR_LENGTH(b) @@ -299,14 +316,33 @@ CHAR_LENGTH(b) 40000 60000 DROP TABLE t1; +RENAME TABLE t0 to t1; +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +SELECT * FROM t1 WHERE title = 'a10'; +class id title +10 10 a10 +SELECT * FROM t1 WHERE title = 'a5000'; +class id title +5000 5000 a5000 +SELECT * FROM t1 WHERE title = 'a10000'; +class id title +10000 10000 a10000 +SELECT * FROM t1 WHERE title = 'a10010'; +class id title +DROP TABLE t1; CREATE TABLE t1( class INT, id INT, title VARCHAR(100) ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; -SET debug_dbug='+d,crash_commit_before'; +connect hang,localhost,root; +SET DEBUG_SYNC='alter_table_inplace_trans_commit SIGNAL hung WAIT_FOR ever'; CREATE INDEX idx_title ON t1(title); -ERROR HY000: Lost connection to MySQL server during query +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +disconnect hang; SELECT COUNT(*) FROM t1; COUNT(*) 10000 @@ -344,9 +380,12 @@ CHAR_LENGTH(b) 20000 40000 60000 -SET debug_dbug='+d,crash_commit_before'; -ALTER TABLE t1 DROP COLUMN c; -ERROR HY000: Lost connection to MySQL server during query +connect hang,localhost,root; +SET DEBUG_SYNC='alter_table_inplace_trans_commit SIGNAL hung WAIT_FOR ever'; +ALTER TABLE t1 DROP COLUMN c, FORCE; +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +disconnect hang; CHECK TABLE t1; Table Op Msg_type Msg_text test.t1 check status OK @@ -378,21 +417,9 @@ SELECT COUNT(*) FROM t1; COUNT(*) 10000 CREATE INDEX idx_title ON t1(title); -CHECK TABLE t1; -Table Op Msg_type Msg_text -test.t1 check status OK -SELECT * FROM t1 WHERE title = 'a10'; -class id title -10 10 a10 -SELECT * FROM t1 WHERE title = 'a5000'; -class id title -5000 5000 a5000 -SELECT * FROM t1 WHERE title = 'a10000'; -class id title -10000 10000 a10000 -SELECT * FROM t1 WHERE title = 'a10010'; -class id title -DROP TABLE t1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +RENAME TABLE t1 TO t0; # Test Blob SET GLOBAL innodb_file_per_table=1; CREATE TABLE t1( @@ -410,9 +437,12 @@ CHAR_LENGTH(b) 20000 40000 60000 -ALTER TABLE t1 DROP COLUMN c; -CHECK TABLE t1; +ALTER TABLE t1 DROP COLUMN c, FORCE; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +CHECK TABLE t0,t1; Table Op Msg_type Msg_text +test.t0 check status OK test.t1 check status OK SELECT CHAR_LENGTH(b) FROM t1; CHAR_LENGTH(b) @@ -421,15 +451,34 @@ CHAR_LENGTH(b) 40000 60000 DROP TABLE t1; +RENAME TABLE t0 to t1; +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +SELECT * FROM t1 WHERE title = 'a10'; +class id title +10 10 a10 +SELECT * FROM t1 WHERE title = 'a5000'; +class id title +5000 5000 a5000 +SELECT * FROM t1 WHERE title = 'a10000'; +class id title +10000 10000 a10000 +SELECT * FROM t1 WHERE title = 'a10010'; +class id title +DROP TABLE t1; SET GLOBAL innodb_file_per_table=1; CREATE TABLE t1( class INT, id INT, title VARCHAR(100) ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4; -SET debug_dbug='+d,crash_commit_before'; +connect hang,localhost,root; +SET DEBUG_SYNC='alter_table_inplace_trans_commit SIGNAL hung WAIT_FOR ever'; CREATE INDEX idx_title ON t1(title); -ERROR HY000: Lost connection to MySQL server during query +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +disconnect hang; SELECT COUNT(*) FROM t1; COUNT(*) 10000 @@ -468,9 +517,12 @@ CHAR_LENGTH(b) 20000 40000 60000 -SET debug_dbug='+d,crash_commit_before'; -ALTER TABLE t1 DROP COLUMN c; -ERROR HY000: Lost connection to MySQL server during query +connect hang,localhost,root; +SET DEBUG_SYNC='alter_table_inplace_trans_commit SIGNAL hung WAIT_FOR ever'; +ALTER TABLE t1 DROP COLUMN c, FORCE; +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +disconnect hang; CHECK TABLE t1; Table Op Msg_type Msg_text test.t1 check status OK @@ -481,5 +533,4 @@ CHAR_LENGTH(b) 40000 60000 DROP TABLE t1; -SET GLOBAL innodb_file_per_table=default; DROP PROCEDURE populate_t1; diff --git a/mysql-test/suite/innodb/t/alter_copy.test b/mysql-test/suite/innodb/t/alter_copy.test index 0dce61994b5..b7ab05a061a 100644 --- a/mysql-test/suite/innodb/t/alter_copy.test +++ b/mysql-test/suite/innodb/t/alter_copy.test @@ -37,11 +37,11 @@ SELECT * FROM t1 WHERE MATCH(b,c) AGAINST ('column'); SHOW CREATE TABLE t1; ALTER TABLE t1 FORCE, ALGORITHM=COPY; -# crash right after the last write_row(), before the first commit of ALTER TABLE ---source include/expect_crash.inc +# kill right after the last write_row(), before the first commit of ALTER TABLE +connect (hang,localhost,root); -SET DEBUG_DBUG='+d,crash_commit_before'; ---error 2013 +SET DEBUG_SYNC='alter_table_copy_trans_commit SIGNAL hung WAIT_FOR ever'; +send # create 32 secondary indexes ALTER TABLE t ADD INDEX(b,c,d,a),ADD INDEX(b,c,a,d),ADD INDEX(b,a,c,d),ADD INDEX(b,a,d,c), ADD INDEX(b,d,a,c),ADD INDEX(b,d,c,a),ADD INDEX(a,b,c,d),ADD INDEX(a,b,d,c), @@ -53,8 +53,13 @@ ALTER TABLE t ADD INDEX(b,c,d,a),ADD INDEX(b,c,a,d),ADD INDEX(b,a,c,d),ADD INDEX ADD INDEX(a,b,d), ADD INDEX(a,d,b), ADD INDEX(b,c,d), ADD INDEX(b,d,c), ALGORITHM=COPY; +connection default; +SET DEBUG_SYNC='now WAIT_FOR hung'; +let $shutdown_timeout=0; --let $restart_parameters= --innodb-force-recovery=3 ---source include/start_mysqld.inc +--source include/restart_mysqld.inc +disconnect hang; +let $shutdown_timeout=; let $datadir=`select @@datadir`; --replace_regex /#sql-[0-9a-f_]*/#sql-temporary/ /FTS_[0-9a-f]*_[0-9a-f]*/FTS/ --list_files $datadir/test diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 41f62de2a70..9d7e03727d3 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -9788,6 +9788,7 @@ end_temporary: (ulong) (copied + deleted), (ulong) deleted, (ulong) thd->get_stmt_da()->current_statement_warn_count()); my_ok(thd, copied + deleted, 0L, alter_ctx.tmp_name); + DEBUG_SYNC(thd, "alter_table_inplace_trans_commit"); DBUG_RETURN(false); err_new_table_cleanup: @@ -9889,12 +9890,14 @@ bool mysql_trans_commit_alter_copy_data(THD *thd) uint save_unsafe_rollback_flags; DBUG_ENTER("mysql_trans_commit_alter_copy_data"); - /* Save flags as transcommit_implicit_are_deleting_them */ + /* Save flags as trans_commit_implicit are deleting them */ save_unsafe_rollback_flags= thd->transaction.stmt.m_unsafe_rollback_flags; + DEBUG_SYNC(thd, "alter_table_copy_trans_commit"); + if (ha_enable_transaction(thd, TRUE)) DBUG_RETURN(TRUE); - + /* Ensure that the new table is saved properly to disk before installing the new .frm. From f13471c9fefc17e0f097af32e5ee8767d206d693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 13 Aug 2019 13:14:23 +0300 Subject: [PATCH 41/63] MDEV-20060: Remove bogus unit from error message --- storage/innobase/srv/srv0start.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 1b4a478639c..46a2b7b7c09 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1856,7 +1856,7 @@ innobase_start_or_create_for_mysql() /* Log group size is limited by the size of page number. Remove this limitation when fil_io() is not used for recovery log io. */ ib::error() << "Combined size of log files must be < " - << log_group_max_size << " GB"; + << log_group_max_size; return(srv_init_abort(DB_ERROR)); } From eedd6179c1e5e8651270b353a693887179ad7bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 13 Aug 2019 14:54:24 +0300 Subject: [PATCH 42/63] MDEV-20138 innodb.trx_id_future fails on 10.3+ Starting with MDEV-12288 in MariaDB Server 10.3, the transaction identifiers on records will be reset on purge. Because purge might or might not run to completion before shutdown, it could happen that the bogus transaction identifier that our test is writing will be reset by purge after restart, and the expected warning message on SELECT will fail to appear. We resolve the race condition by ensuring that purge runs to completion before the shutdown. --- mysql-test/suite/innodb/r/trx_id_future.result | 2 ++ mysql-test/suite/innodb/t/trx_id_future.test | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/r/trx_id_future.result b/mysql-test/suite/innodb/r/trx_id_future.result index 887d11ddcc2..17b76b4b1c1 100644 --- a/mysql-test/suite/innodb/r/trx_id_future.result +++ b/mysql-test/suite/innodb/r/trx_id_future.result @@ -2,8 +2,10 @@ # Bug #20445525 ADD A CONSISTENCY CHECK AGAINST DB_TRX_ID BEING # IN THE FUTURE # +SET GLOBAL innodb_purge_rseg_truncate_frequency=1; CREATE TABLE t1(a INT) row_format=redundant engine=innoDB; INSERT INTO t1 VALUES(1); +InnoDB 0 transactions not purged NOT FOUND /\[Warning\] InnoDB: A transaction id in a record of table `test`\.`t1` is newer than the system-wide maximum/ in mysqld.1.err call mtr.add_suppression("\\[Warning\\] InnoDB: A transaction id in a record of table `test`\\.`t1` is newer than the system-wide maximum"); SELECT * FROM t1; diff --git a/mysql-test/suite/innodb/t/trx_id_future.test b/mysql-test/suite/innodb/t/trx_id_future.test index deba753caca..5ae0d0093ba 100644 --- a/mysql-test/suite/innodb/t/trx_id_future.test +++ b/mysql-test/suite/innodb/t/trx_id_future.test @@ -7,13 +7,14 @@ --source include/have_innodb.inc --source include/not_embedded.inc +SET GLOBAL innodb_purge_rseg_truncate_frequency=1; let PAGE_SIZE=`select @@innodb_page_size`; CREATE TABLE t1(a INT) row_format=redundant engine=innoDB; INSERT INTO t1 VALUES(1); let MYSQLD_DATADIR=`select @@datadir`; - +--source include/wait_all_purged.inc --source include/shutdown_mysqld.inc perl; From a18d1cc7778633a9d05f46082e7ddeb8e40130ba Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Tue, 13 Aug 2019 16:26:17 +0300 Subject: [PATCH 43/63] MDEV-20315: MyRocks tests produce valgrind failures (Backport to 10.2) - Include the valgrind suppressions from the FB upstream - Use HAVE_Valgrind, not HAVE_Purify (like the rest of MariaDB code does) The call to DisownData() is now actually disabled under Valgrind --- mysql-test/valgrind.supp | 94 +++++++++++++++++++++++++++++++++++ storage/rocksdb/ha_rocksdb.cc | 4 +- 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/mysql-test/valgrind.supp b/mysql-test/valgrind.supp index a8ca80e203a..c113447b229 100644 --- a/mysql-test/valgrind.supp +++ b/mysql-test/valgrind.supp @@ -1771,3 +1771,97 @@ obj:/usr/lib64/libcrypto.so* } + + +## +## The following is a copy of facebook/mysql-5.6 suppressions: +## + +# +# RocksDB Storage Engine suppressions start +# + +{ + Still reachable for once-per-process initializations + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:_ZN7rocksdb16ThreadStatusUtil19NewColumnFamilyInfoEPKNS_2DBEPKNS_16ColumnFamilyDataERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPKNS_3EnvE + fun:_ZNK7rocksdb6DBImpl21NewThreadStatusCfInfoEPNS_16ColumnFamilyDataE + fun:_ZN7rocksdb2DB4OpenERKNS_9DBOptionsERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22ColumnFamilyDescriptorESaISD_EEPSC_IPNS_18ColumnFamilyHandleESaISJ_EEPPS0_ + fun:_ZN7rocksdb13TransactionDB4OpenERKNS_9DBOptionsERKNS_20TransactionDBOptionsERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22ColumnFamilyDescriptorESaISG_EEPSF_IPNS_18ColumnFamilyHandleESaISM_EEPPS0_ + fun:_ZN7myrocksL17rocksdb_init_funcEPv +} + + +{ + Still reachable for once-per-process initializations + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:_ZN7rocksdb19ThreadStatusUpdater14RegisterThreadENS_12ThreadStatus10ThreadTypeEm + fun:_ZN7rocksdb16ThreadStatusUtil14RegisterThreadEPKNS_3EnvENS_12ThreadStatus10ThreadTypeE + fun:_ZN7rocksdb14ThreadPoolImpl4Impl15BGThreadWrapperEPv + fun:_ZNSt12_Bind_simpleIFPFPvS0_EPN7rocksdb16BGThreadMetadataEEE9_M_invokeIILm0EEEES0_St12_Index_tupleIIXspT_EEE + ... +} + +{ + Still reachable for once-per-process initializations + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:_ZN7rocksdb14ThreadLocalPtr14InitSingletonsEv + fun:_ZN7rocksdb3Env7DefaultEv + fun:_ZN7rocksdb9DBOptionsC1Ev + ... + fun:_ZN7myrocksL27rdb_init_rocksdb_db_optionsEv +} + +{ + Still reachable for once-per-process initializations + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:_ZN7rocksdb12_GLOBAL__N_18PosixEnv* + fun:_ZN7rocksdb3Env7DefaultEv + fun:_ZN7rocksdb9DBOptionsC1Ev + ... + fun:_ZN7myrocksL27rdb_init_rocksdb_db_optionsEv +} + +{ + Still reachable for thread local storage initialization (SetHandle) + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:_ZNSt13unordered_mapIjPFvPvESt4hashIjESt8equal_toIjESaISt4pairIKjS2_EEEixERS8_ + fun:_ZN7rocksdb14ThreadLocalPtr10StaticMeta10SetHandlerEjPFvPvE + fun:_ZN7rocksdb14ThreadLocalPtrC1EPFvPvE + ... +} + +{ + Still reachable for thread local storage initialization (ReclaimId) + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:_ZN7rocksdb10autovectorIjLm8EE9push_backERKj + fun:_ZN7rocksdb14ThreadLocalPtr10StaticMeta9ReclaimIdEj + fun:_ZN7rocksdb14ThreadLocalPtrD1Ev + ... +} + +{ + Static initialization + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:_Z41__static_initialization_and_destruction_0ii + ... +} + +## +## RocksDB Storage Engine suppressions end +## + diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 613ac0884a7..bf9183d7dea 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -5836,11 +5836,11 @@ static int rocksdb_done_func(void *const p) { // Disown the cache data since we're shutting down. // This results in memory leaks but it improved the shutdown time. // Don't disown when running under valgrind -#ifndef HAVE_purify +#ifndef HAVE_valgrind if (rocksdb_tbl_options->block_cache) { rocksdb_tbl_options->block_cache->DisownData(); } -#endif /* HAVE_purify */ +#endif /* HAVE_valgrind */ /* MariaDB: don't clear rocksdb_db_options and rocksdb_tbl_options. From c5b4697b2432d1692227ddf4abb46eb625d94d61 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Tue, 13 Aug 2019 16:27:51 +0300 Subject: [PATCH 44/63] MDEV-20315: Backport to 10.2: Myrocks: Get the upstream's valgrind suppressions to work --- mysql-test/valgrind.supp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/mysql-test/valgrind.supp b/mysql-test/valgrind.supp index c113447b229..43f22db69c6 100644 --- a/mysql-test/valgrind.supp +++ b/mysql-test/valgrind.supp @@ -1794,6 +1794,30 @@ } +{ + Still reachable for once-per-process initializations 2 + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:_ZN7rocksdb16ThreadStatusUtil19NewColumnFamilyInfoEPKNS_2DBEPKNS_16ColumnFamilyDataERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPKNS_3EnvE + fun:_ZNK7rocksdb6DBImpl21NewThreadStatusCfInfoEPNS_16ColumnFamilyDataE + fun:_ZN7rocksdb6DBImpl4OpenERKNS_9DBOptionsERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22ColumnFamilyDescriptorESaISD_EEPSC_IPNS_18ColumnFamilyHandleESaISJ_EEPPNS_2DBEbb + fun:_ZN7rocksdb13TransactionDB4OpenERKNS_9DBOptionsERKNS_20TransactionDBOptionsERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22ColumnFamilyDescriptorESaISG_EEPSF_IPNS_18ColumnFamilyHandleESaISM_EEPPS0_ +# fun:_ZN7myrocksL17rocksdb_init_funcEPv +# ^ commenting the above out because we are hitting the --num-callers=16 +# limitation that MTR sets for valgrind +} + +{ + Still reachable for once-per-process initializations 3 + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:_ZN7rocksdb16ThreadStatusUtil19NewColumnFamilyInfoEPKNS_2DBEPKNS_16ColumnFamilyDataERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPKNS_3EnvE + fun:_ZNK7rocksdb6DBImpl21NewThreadStatusCfInfoEPNS_16ColumnFamilyDataE + fun:_ZN7rocksdb6DBImpl22CreateColumnFamilyImplERKNS_19ColumnFamilyOptionsERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPPNS_18ColumnFamilyHandleE +} + { Still reachable for once-per-process initializations Memcheck:Leak @@ -1802,7 +1826,6 @@ fun:_ZN7rocksdb19ThreadStatusUpdater14RegisterThreadENS_12ThreadStatus10ThreadTypeEm fun:_ZN7rocksdb16ThreadStatusUtil14RegisterThreadEPKNS_3EnvENS_12ThreadStatus10ThreadTypeE fun:_ZN7rocksdb14ThreadPoolImpl4Impl15BGThreadWrapperEPv - fun:_ZNSt12_Bind_simpleIFPFPvS0_EPN7rocksdb16BGThreadMetadataEEE9_M_invokeIILm0EEEES0_St12_Index_tupleIIXspT_EEE ... } From 65296123d0fcaeb122bc3b9d9e387468052c06b6 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Tue, 13 Aug 2019 16:37:21 +0300 Subject: [PATCH 45/63] MDEV-12439: MariaRocks produces numerous (spurious?) valgrind failures Enable the rocksdb test suite. It now passes the valgrind tests. --- storage/rocksdb/mysql-test/rocksdb/suite.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/rocksdb/mysql-test/rocksdb/suite.pm b/storage/rocksdb/mysql-test/rocksdb/suite.pm index 3423d34ded5..e4f074df471 100644 --- a/storage/rocksdb/mysql-test/rocksdb/suite.pm +++ b/storage/rocksdb/mysql-test/rocksdb/suite.pm @@ -20,8 +20,8 @@ my $sst_dump= return "RocksDB is not compiled, no sst_dump" unless $sst_dump; $ENV{MARIAROCKS_SST_DUMP}="$sst_dump"; -# Temporarily disable testing under valgrind, due to MDEV-12439 -return "RocksDB tests disabled under valgrind" if ($::opt_valgrind); +## Temporarily disable testing under valgrind, due to MDEV-12439 +#return "RocksDB tests disabled under valgrind" if ($::opt_valgrind); bless { }; From 39db116562f7e5bdd4b8c5dbbdc21a06c7ae09ad Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Tue, 13 Aug 2019 14:31:34 +0300 Subject: [PATCH 46/63] MDEV-18862 Unfortunate error message upon attempt to drop system versioning Fix error code. --- mysql-test/suite/versioning/r/alter.result | 4 ++-- mysql-test/suite/versioning/t/alter.test | 4 ++-- sql/share/errmsg-utf8.txt | 2 -- sql/sql_table.cc | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/mysql-test/suite/versioning/r/alter.result b/mysql-test/suite/versioning/r/alter.result index 2afd3921154..8cc63403bb0 100644 --- a/mysql-test/suite/versioning/r/alter.result +++ b/mysql-test/suite/versioning/r/alter.result @@ -622,9 +622,9 @@ set sql_mode= default; set system_versioning_alter_history= keep; create or replace table t1 (x int) with system versioning; alter table t1 drop column `row_start`, drop column `row_end`, drop period for system_time, drop system versioning; -ERROR HY000: No 'PERIOD FOR SYSTEM_TIME' in system-versioned `t1` +ERROR 42000: Can't DROP PERIOD FOR SYSTEM_TIME on `t1`; check that it exists alter table t1 drop period for system_time; -ERROR HY000: No 'PERIOD FOR SYSTEM_TIME' in system-versioned `t1` +ERROR 42000: Can't DROP PERIOD FOR SYSTEM_TIME on `t1`; check that it exists alter table t1 drop column `row_start`, drop column `row_end`, drop system versioning; ERROR 42000: Can't DROP COLUMN `row_start`; check that it exists alter table t1 drop column `row_end`; diff --git a/mysql-test/suite/versioning/t/alter.test b/mysql-test/suite/versioning/t/alter.test index c04c2020460..7ad3c97e399 100644 --- a/mysql-test/suite/versioning/t/alter.test +++ b/mysql-test/suite/versioning/t/alter.test @@ -519,9 +519,9 @@ set sql_mode= default; --echo # set system_versioning_alter_history= keep; create or replace table t1 (x int) with system versioning; ---error ER_VERS_NO_PERIOD +--error ER_CANT_DROP_FIELD_OR_KEY alter table t1 drop column `row_start`, drop column `row_end`, drop period for system_time, drop system versioning; ---error ER_VERS_NO_PERIOD +--error ER_CANT_DROP_FIELD_OR_KEY alter table t1 drop period for system_time; --error ER_CANT_DROP_FIELD_OR_KEY alter table t1 drop column `row_start`, drop column `row_end`, drop system versioning; diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 39198912fbe..99af1c60287 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7898,5 +7898,3 @@ ER_KEY_DOESNT_SUPPORT eng "%s index %`s does not support this operation" ER_ALTER_OPERATION_TABLE_OPTIONS_NEED_REBUILD eng "Changing table options requires the table to be rebuilt" -ER_VERS_NO_PERIOD - eng "No 'PERIOD FOR SYSTEM_TIME' in system-versioned %`s" diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 182254cfe60..9e302fb762d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -8078,7 +8078,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, } else if (alter_info->flags & ALTER_DROP_PERIOD && vers_system_invisible) { - my_error(ER_VERS_NO_PERIOD, MYF(0), table->s->table_name.str); + my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0), "PERIOD FOR SYSTEM_TIME on", table->s->table_name.str); goto err; } alter_info->flags &= ~(ALTER_DROP_PERIOD | ALTER_ADD_PERIOD); From a20f6f9853e522ad388f5b968ce11af3c5d1fc10 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Wed, 14 Aug 2019 15:52:08 +0300 Subject: [PATCH 47/63] MDEV-20336 Assertion bitmap_is_set(read_partitions) upon SELECT FOR UPDATE from versioned table Exclude SELECT and INSERT SELECT from vers_set_hist_part(). We cannot likewise exclude REPLACE SELECT because it may REPLACE into itself (and REPLACE generates history). INSERT also does not generate history, but we have history modification setting which might be interfered. --- mysql-test/suite/versioning/r/partition.result | 7 +++++++ mysql-test/suite/versioning/t/partition.test | 7 +++++++ sql/ha_partition.cc | 12 ++++++++++-- sql/sql_select.cc | 5 ++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result index da851791640..b029efa7479 100644 --- a/mysql-test/suite/versioning/r/partition.result +++ b/mysql-test/suite/versioning/r/partition.result @@ -569,6 +569,13 @@ delete from t1; Warnings: Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions unlock tables; +# +# MDEV-20336 Assertion bitmap_is_set(read_partitions) upon SELECT FOR UPDATE from versioned table +# +create or replace table t1 (pk int primary key) with system versioning partition by system_time limit 100 (partition p1 history, partition pn current); +execute immediate 'select * from t1 for update'; +pk +drop table t1; # Test cleanup drop database test; create database test; diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test index f602c49d7c1..a3feadee1b5 100644 --- a/mysql-test/suite/versioning/t/partition.test +++ b/mysql-test/suite/versioning/t/partition.test @@ -529,6 +529,13 @@ delete from t1 where x < 3; delete from t1; unlock tables; +--echo # +--echo # MDEV-20336 Assertion bitmap_is_set(read_partitions) upon SELECT FOR UPDATE from versioned table +--echo # +create or replace table t1 (pk int primary key) with system versioning partition by system_time limit 100 (partition p1 history, partition pn current); +execute immediate 'select * from t1 for update'; +drop table t1; + --echo # Test cleanup drop database test; create database test; diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 125669a403d..aa630e83ba0 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -3951,7 +3951,12 @@ int ha_partition::external_lock(THD *thd, int lock_type) { if (m_part_info->part_expr) m_part_info->part_expr->walk(&Item::register_field_in_read_map, 1, 0); - if (m_part_info->part_type == VERSIONING_PARTITION) + if (m_part_info->part_type == VERSIONING_PARTITION && + /* TODO: MDEV-20345 exclude more inapproriate commands like INSERT + These commands may be excluded because working history partition is needed + only for versioned DML. */ + thd->lex->sql_command != SQLCOM_SELECT && + thd->lex->sql_command != SQLCOM_INSERT_SELECT) m_part_info->vers_set_hist_part(thd); } DBUG_RETURN(0); @@ -4104,7 +4109,10 @@ int ha_partition::start_stmt(THD *thd, thr_lock_type lock_type) case TL_WRITE_ONLY: if (m_part_info->part_expr) m_part_info->part_expr->walk(&Item::register_field_in_read_map, 1, 0); - if (m_part_info->part_type == VERSIONING_PARTITION) + if (m_part_info->part_type == VERSIONING_PARTITION && + // TODO: MDEV-20345 (see above) + thd->lex->sql_command != SQLCOM_SELECT && + thd->lex->sql_command != SQLCOM_INSERT_SELECT) m_part_info->vers_set_hist_part(thd); default:; } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 33ff0bc70cc..2d6a843f7ad 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -816,7 +816,10 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) else vers_conditions.init(SYSTEM_TIME_ALL); } - else if (!vers_conditions.is_set()) + else if (!vers_conditions.is_set() && + /* We cannot optimize REPLACE .. SELECT because it may need + to call vers_set_hist_part() to update history. */ + thd->lex->sql_command != SQLCOM_REPLACE_SELECT) { table->partition_names= newx List; String *s= newx String(vers_info->now_part->partition_name, From 2347ffd843b8e4ee9d8eaafab05368435db59ece Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Fri, 9 Aug 2019 00:31:35 +0300 Subject: [PATCH 48/63] MDEV-20301 InnoDB's MVCC has O(N^2) behaviors If there're multiple row versions in InnoDB, reading one row from PK may have O(N) complexity and reading from secondary keys may have O(N^2) complexity. The problem occurs when there are many pending versions of the same row, meaning that the primary key is the same, but a secondary key is different. The slowdown occurs when the secondary index is traversed. This patch creates a helper class for the function row_sel_get_clust_rec_for_mysql() which can remember and re-use cached_clust_rec & cached_old_vers so that rec_get_offsets() does not need to be called over and over for the clustered record. Corrections by Kevin Lewis MDEV-20341 Unstable innodb.innodb_bug14704286 Removed test that tested the ability of interrupting long query which is not long anymore. --- .../suite/innodb/r/innodb_bug14704286.result | 65 ------------- .../suite/innodb/r/innodb_bug84958.result | 81 ++++++++++++++++ .../suite/innodb/t/innodb_bug14704286.test | 95 ------------------- .../suite/innodb/t/innodb_bug84958.test | 86 +++++++++++++++++ storage/innobase/row/row0sel.cc | 55 +++++++++-- 5 files changed, 213 insertions(+), 169 deletions(-) delete mode 100644 mysql-test/suite/innodb/r/innodb_bug14704286.result create mode 100644 mysql-test/suite/innodb/r/innodb_bug84958.result delete mode 100644 mysql-test/suite/innodb/t/innodb_bug14704286.test create mode 100644 mysql-test/suite/innodb/t/innodb_bug84958.test diff --git a/mysql-test/suite/innodb/r/innodb_bug14704286.result b/mysql-test/suite/innodb/r/innodb_bug14704286.result deleted file mode 100644 index f84d5206e07..00000000000 --- a/mysql-test/suite/innodb/r/innodb_bug14704286.result +++ /dev/null @@ -1,65 +0,0 @@ -use test; -drop table if exists t1; -create table t1 (id int primary key, value int, value2 int, -value3 int, index(value,value2)) engine=innodb; -insert into t1 values -(10,10,10,10),(11,11,11,11),(12,12,12,12),(13,13,13,13),(14,14,14,14), -(15,15,15,15),(16,16,16,16),(17,17,17,17),(18,18,18,18),(19,19,19,19), -(20,20,20,20); -connect conn1, localhost, root,,; -connect conn2, localhost, root,,; -connect conn3, localhost, root,,; -connection conn1; -use test; -start transaction with consistent snapshot; -connection conn2; -use test; -CREATE PROCEDURE update_t1() -BEGIN -DECLARE i INT DEFAULT 1; -while (i <= 5000) DO -update test.t1 set value2=value2+1, value3=value3+1 where id=12; -SET i = i + 1; -END WHILE; -END| -set autocommit=0; -CALL update_t1(); -select * from t1; -id value value2 value3 -10 10 10 10 -11 11 11 11 -12 12 5012 5012 -13 13 13 13 -14 14 14 14 -15 15 15 15 -16 16 16 16 -17 17 17 17 -18 18 18 18 -19 19 19 19 -20 20 20 20 -set autocommit=1; -select * from t1; -id value value2 value3 -10 10 10 10 -11 11 11 11 -12 12 5012 5012 -13 13 13 13 -14 14 14 14 -15 15 15 15 -16 16 16 16 -17 17 17 17 -18 18 18 18 -19 19 19 19 -20 20 20 20 -connection conn1; -select * from t1 force index(value) where value=12; -connection conn3; -kill query @id; -connection conn1; -ERROR 70100: Query execution was interrupted -connection default; -disconnect conn1; -disconnect conn2; -disconnect conn3; -drop procedure if exists update_t1; -drop table if exists t1; diff --git a/mysql-test/suite/innodb/r/innodb_bug84958.result b/mysql-test/suite/innodb/r/innodb_bug84958.result new file mode 100644 index 00000000000..1a59a10eb2f --- /dev/null +++ b/mysql-test/suite/innodb/r/innodb_bug84958.result @@ -0,0 +1,81 @@ +# +# Bug #84958 InnoDB's MVCC has O(N^2) behaviors +# https://bugs.mysql.com/bug.php?id=84958 +# +# Set up the test with a procedure and a function. +# +CREATE PROCEDURE insert_n(start int, end int) +BEGIN +DECLARE i INT DEFAULT start; +WHILE i <= end do +INSERT INTO t1 VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE c = i; +SET i = i + 1; +END WHILE; +END~~ +CREATE FUNCTION num_pages_get() +RETURNS INT +BEGIN +DECLARE ret INT; +SELECT variable_value INTO ret +FROM information_schema.global_status +WHERE variable_name = 'innodb_buffer_pool_read_requests'; +RETURN ret; +END~~ +# +# Create a table with one record in it and start an RR transaction +# +CREATE TABLE t1 (a INT, b INT, c INT, PRIMARY KEY(a,b), KEY (b,c)) +ENGINE=InnoDB; +BEGIN; +SELECT * FROM t1; +a b c +# +# Create 100 newer record versions in con2 and con3 +# +connect con2, localhost, root,,; +connection con2; +INSERT INTO t1 VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE c = NULL; +CALL insert_n(1, 50);; +connect con3, localhost, root,,; +connection con3; +CALL insert_n(51, 100);; +connection con2; +connection con3; +INSERT INTO t1 VALUES (1, 2, 1) ON DUPLICATE KEY UPDATE c = NULL; +connection default; +# +# Connect to default and record how many pages were accessed +# when selecting the record using the secondary key. +# +SET @num_pages_1 = num_pages_get(); +SELECT * FROM t1 force index (b); +a b c +SET @num_pages_2= num_pages_get(); +SELECT @num_pages_2 - @num_pages_1 < 500; +@num_pages_2 - @num_pages_1 < 500 +1 +# +# Commit and show the final record. +# +SELECT * FROM t1; +a b c +SELECT * FROM t1 force index (b); +a b c +COMMIT; +SELECT * FROM t1 force index (b); +a b c +1 2 NULL +SELECT * FROM t1; +a b c +1 2 NULL +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +# +# Cleanup +# +disconnect con2; +disconnect con3; +DROP TABLE t1; +DROP PROCEDURE insert_n; +DROP FUNCTION num_pages_get; diff --git a/mysql-test/suite/innodb/t/innodb_bug14704286.test b/mysql-test/suite/innodb/t/innodb_bug14704286.test deleted file mode 100644 index fb5e6b829a1..00000000000 --- a/mysql-test/suite/innodb/t/innodb_bug14704286.test +++ /dev/null @@ -1,95 +0,0 @@ ---source include/have_innodb.inc - -# -# create test-bed to run test -# -use test; ---disable_warnings -drop table if exists t1; ---enable_warnings -create table t1 (id int primary key, value int, value2 int, -value3 int, index(value,value2)) engine=innodb; - -insert into t1 values -(10,10,10,10),(11,11,11,11),(12,12,12,12),(13,13,13,13),(14,14,14,14), -(15,15,15,15),(16,16,16,16),(17,17,17,17),(18,18,18,18),(19,19,19,19), -(20,20,20,20); -let $ID= `SELECT @id := CONNECTION_ID()`; - -# -# we need multiple connections as we need to keep one connection -# active with trx requesting consistent read. -# -connect (conn1, localhost, root,,); -connect (conn2, localhost, root,,); -connect (conn3, localhost, root,,); - -# -# start trx with consistent read -# -connection conn1; -use test; - -start transaction with consistent snapshot; - -# -# update table such that secondary index is updated. -# -connection conn2; -use test; -delimiter |; -CREATE PROCEDURE update_t1() -BEGIN - DECLARE i INT DEFAULT 1; - while (i <= 5000) DO - update test.t1 set value2=value2+1, value3=value3+1 where id=12; - SET i = i + 1; - END WHILE; -END| - -delimiter ;| -set autocommit=0; -CALL update_t1(); -select * from t1; -set autocommit=1; -select * from t1; - -# -# Now try to fire select query from connection-1 enforcing -# use of secondary index. -# -connection conn1; -let $ID= `SELECT @id := CONNECTION_ID()`; -#--error ER_QUERY_INTERRUPTED ---send -select * from t1 force index(value) where value=12; - -# -# select is going to take good time so let's kill query. -# -connection conn3; -let $wait_condition= - select * from information_schema.processlist where state = 'Sending data' and - info = 'select * from t1 force index(value) where value=12'; ---source include/wait_condition.inc -let $ignore= `SELECT @id := $ID`; -kill query @id; - -# -# reap the value of connection-1 -# -connection conn1; ---error ER_QUERY_INTERRUPTED -reap; - -# -# clean test-bed. -# -connection default; -disconnect conn1; -disconnect conn2; -disconnect conn3; -drop procedure if exists update_t1; -drop table if exists t1; - - diff --git a/mysql-test/suite/innodb/t/innodb_bug84958.test b/mysql-test/suite/innodb/t/innodb_bug84958.test new file mode 100644 index 00000000000..4456df21cb9 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb_bug84958.test @@ -0,0 +1,86 @@ +--echo # +--echo # Bug #84958 InnoDB's MVCC has O(N^2) behaviors +--echo # https://bugs.mysql.com/bug.php?id=84958 +--echo # +--echo # Set up the test with a procedure and a function. +--echo # + +--source include/have_innodb.inc + +DELIMITER ~~; +CREATE PROCEDURE insert_n(start int, end int) +BEGIN + DECLARE i INT DEFAULT start; + WHILE i <= end do + INSERT INTO t1 VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE c = i; + SET i = i + 1; + END WHILE; +END~~ + +CREATE FUNCTION num_pages_get() +RETURNS INT +BEGIN + DECLARE ret INT; + SELECT variable_value INTO ret + FROM information_schema.global_status + WHERE variable_name = 'innodb_buffer_pool_read_requests'; + RETURN ret; +END~~ +DELIMITER ;~~ + +--echo # +--echo # Create a table with one record in it and start an RR transaction +--echo # +CREATE TABLE t1 (a INT, b INT, c INT, PRIMARY KEY(a,b), KEY (b,c)) +ENGINE=InnoDB; +BEGIN; +SELECT * FROM t1; + +--echo # +--echo # Create 100 newer record versions in con2 and con3 +--echo # +connect (con2, localhost, root,,); +connection con2; +INSERT INTO t1 VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE c = NULL; +--send CALL insert_n(1, 50); + +connect (con3, localhost, root,,); +connection con3; +--send CALL insert_n(51, 100); + +connection con2; +reap; +connection con3; +reap; +INSERT INTO t1 VALUES (1, 2, 1) ON DUPLICATE KEY UPDATE c = NULL; + +connection default; + +--echo # +--echo # Connect to default and record how many pages were accessed +--echo # when selecting the record using the secondary key. +--echo # +SET @num_pages_1 = num_pages_get(); +SELECT * FROM t1 force index (b); +SET @num_pages_2= num_pages_get(); + +SELECT @num_pages_2 - @num_pages_1 < 500; + +--echo # +--echo # Commit and show the final record. +--echo # +SELECT * FROM t1; +SELECT * FROM t1 force index (b); +COMMIT; +SELECT * FROM t1 force index (b); +SELECT * FROM t1; +CHECK TABLE t1; + +--echo # +--echo # Cleanup +--echo # +disconnect con2; +disconnect con3; +DROP TABLE t1; +DROP PROCEDURE insert_n; +DROP FUNCTION num_pages_get; diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 877d9c3ef78..d5b1a596f01 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -3309,14 +3309,29 @@ row_sel_build_prev_vers_for_mysql( return(err); } +/** Helper class to cache clust_rec and old_ver */ +class Row_sel_get_clust_rec_for_mysql +{ + const rec_t *cached_clust_rec; + rec_t *cached_old_vers; + +public: + Row_sel_get_clust_rec_for_mysql() : + cached_clust_rec(NULL), cached_old_vers(NULL) {} + + dberr_t operator()(row_prebuilt_t *prebuilt, dict_index_t *sec_index, + const rec_t *rec, que_thr_t *thr, const rec_t **out_rec, + ulint **offsets, mem_heap_t **offset_heap, + dtuple_t **vrow, mtr_t *mtr); +}; + /*********************************************************************//** Retrieves the clustered index record corresponding to a record in a non-clustered index. Does the necessary locking. Used in the MySQL interface. @return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, or error code */ -static MY_ATTRIBUTE((warn_unused_result)) dberr_t -row_sel_get_clust_rec_for_mysql( +Row_sel_get_clust_rec_for_mysql::operator()( /*============================*/ row_prebuilt_t* prebuilt,/*!< in: prebuilt struct in the handle */ dict_index_t* sec_index,/*!< in: secondary index where rec resides */ @@ -3508,15 +3523,36 @@ row_sel_get_clust_rec_for_mysql( clust_rec, clust_index, *offsets, trx_get_read_view(trx))) { - /* The following call returns 'offsets' associated with - 'old_vers' */ - err = row_sel_build_prev_vers_for_mysql( - trx->read_view, clust_index, prebuilt, - clust_rec, offsets, offset_heap, &old_vers, - vrow, mtr); + if (clust_rec != cached_clust_rec) { + /* The following call returns 'offsets' associated with + 'old_vers' */ + err = row_sel_build_prev_vers_for_mysql( + trx->read_view, clust_index, prebuilt, + clust_rec, offsets, offset_heap, &old_vers, + vrow, mtr); - if (err != DB_SUCCESS || old_vers == NULL) { + if (err != DB_SUCCESS) { + goto err_exit; + } + cached_clust_rec = clust_rec; + cached_old_vers = old_vers; + } else { + err = DB_SUCCESS; + old_vers = cached_old_vers; + + /* The offsets need not be same for the latest + version of clust_rec and its old version + old_vers. Re-calculate the offsets for old_vers. */ + + if (old_vers != NULL) { + *offsets = rec_get_offsets( + old_vers, clust_index, *offsets, + true, ULINT_UNDEFINED, offset_heap); + } + } + + if (old_vers == NULL) { goto err_exit; } @@ -4233,6 +4269,7 @@ row_search_mvcc( dtuple_t* vrow = NULL; const rec_t* result_rec = NULL; const rec_t* clust_rec; + Row_sel_get_clust_rec_for_mysql row_sel_get_clust_rec_for_mysql; dberr_t err = DB_SUCCESS; ibool unique_search = FALSE; ibool mtr_has_extra_clust_latch = FALSE; From 29e560cdf32a2c6aa10298c2404bbeb54e628d6e Mon Sep 17 00:00:00 2001 From: Sujatha Date: Wed, 14 Aug 2019 22:53:16 +0530 Subject: [PATCH 49/63] MDEV-20348: DROP TABLE IF EXISTS killed on master but was replicated Problem: ======= DROP TABLE IF EXISTS was killed. The table still exists on the master but the DDL was still logged. Analysis: ========= During the execution of DROP TABLE command "ha_delete_table" call is invoked to delete the table. If the query is killed at this point, the kill command is not handled within the code. This results in two issues. 1) The table which is not dropped also gets written into the binary log. 2) The code continues further upon receiving 'KILL QUERY'. Fix: === Upon receiving the KILL command the query should stop its current execution. Tables which were successfully dropped prior to KILL command should be included in the binary log. --- .../rpl/r/rpl_failed_drop_tbl_binlog.result | 32 +++++++++ .../rpl/t/rpl_failed_drop_tbl_binlog.test | 64 ++++++++++++++++++ sql/sql_table.cc | 67 +++++++++---------- 3 files changed, 127 insertions(+), 36 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_failed_drop_tbl_binlog.result create mode 100644 mysql-test/suite/rpl/t/rpl_failed_drop_tbl_binlog.test diff --git a/mysql-test/suite/rpl/r/rpl_failed_drop_tbl_binlog.result b/mysql-test/suite/rpl/r/rpl_failed_drop_tbl_binlog.result new file mode 100644 index 00000000000..df36fa82e0f --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_failed_drop_tbl_binlog.result @@ -0,0 +1,32 @@ +include/master-slave.inc +[connection master] +create table t1 (a int) engine=innodb; +create table t2 (b longblob) engine=innodb; +create table t3 (c int) engine=innodb; +insert into t2 values (repeat('b',1024*1024)); +insert into t2 select * from t2; +insert into t2 select * from t2; +insert into t2 select * from t2; +insert into t2 select * from t2; +set debug_sync='rm_table_no_locks_before_delete_table SIGNAL nogo WAIT_FOR go EXECUTE 2'; +drop table t1, t2, t3; +connect foo,localhost,root; +set debug_sync='now SIGNAL go'; +kill query CONNECTION_ID; +connection master; +ERROR 70100: Query execution was interrupted +"Tables t2 and t3 should be listed" +SHOW TABLES; +Tables_in_test +t2 +t3 +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP TABLE `t1` /* generated by server */ +connection slave; +drop table t2, t3; +connection master; +set debug_sync='RESET'; +drop table t2, t3; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_failed_drop_tbl_binlog.test b/mysql-test/suite/rpl/t/rpl_failed_drop_tbl_binlog.test new file mode 100644 index 00000000000..281e2a2ab47 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_failed_drop_tbl_binlog.test @@ -0,0 +1,64 @@ +# ==== Purpose ==== +# +# Check that when the execution of a DROP TABLE command with single table +# fails it should not be written to the binary log. Also test that when the +# execution of DROP TABLE command with multiple tables fails the command +# should be written into the binary log. +# +# ==== Implementation ==== +# +# Steps: +# 0 - Create tables named t1, t2, t3 +# 1 - Execute DROP TABLE t1,t2,t3 command. +# 2 - Kill the DROP TABLE command while it is trying to drop table 't2'. +# 3 - Verify that tables t2,t3 are present after the DROP command execution +# was interrupted. +# 4 - Check that table 't1' is present in binary log as part of DROP +# command. +# +# ==== References ==== +# +# MDEV-20348: DROP TABLE IF EXISTS killed on master but was replicated. +# + +--source include/have_innodb.inc +--source include/have_debug_sync.inc +--source include/have_binlog_format_statement.inc +--source include/master-slave.inc + +create table t1 (a int) engine=innodb; +create table t2 (b longblob) engine=innodb; +create table t3 (c int) engine=innodb; +insert into t2 values (repeat('b',1024*1024)); +insert into t2 select * from t2; +insert into t2 select * from t2; +insert into t2 select * from t2; +insert into t2 select * from t2; +let $binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1); + +let $id=`select connection_id()`; +set debug_sync='rm_table_no_locks_before_delete_table SIGNAL nogo WAIT_FOR go EXECUTE 2'; +send drop table t1, t2, t3; + +connect foo,localhost,root; +set debug_sync='now SIGNAL go'; +let $wait_condition=select 1 from information_schema.processlist where state like 'debug sync point:%'; +source include/wait_condition.inc; +--replace_result $id CONNECTION_ID +eval kill query $id; + +connection master; +error ER_QUERY_INTERRUPTED; +reap; + +--echo "Tables t2 and t3 should be listed" +SHOW TABLES; +--source include/show_binlog_events.inc +--sync_slave_with_master +drop table t2, t3; + +connection master; +set debug_sync='RESET'; +drop table t2, t3; + +source include/rpl_end.inc; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 9d7e03727d3..cc58dc4a7e8 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2362,35 +2362,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, path_length= build_table_filename(path, sizeof(path) - 1, db, alias, reg_ext, 0); - /* - This handles the case where a "DROP" was executed and a regular - table "may be" dropped as drop_temporary is FALSE and error is - TRUE. If the error was FALSE a temporary table was dropped and - regardless of the status of drop_temporary a "DROP TEMPORARY" - must be used. - */ - if (!dont_log_query) - { - /* - Note that unless if_exists is TRUE or a temporary table was deleted, - there is no means to know if the statement should be written to the - binary log. See further information on this variable in what follows. - */ - non_tmp_table_deleted= (if_exists ? TRUE : non_tmp_table_deleted); - /* - Don't write the database name if it is the current one (or if - thd->db is NULL). - */ - if (thd->db == NULL || strcmp(db,thd->db) != 0) - { - append_identifier(thd, &built_query, db, db_length); - built_query.append("."); - } - - append_identifier(thd, &built_query, table->table_name, - table->table_name_length); - built_query.append(","); - } } DEBUG_SYNC(thd, "rm_table_no_locks_before_delete_table"); error= 0; @@ -2464,14 +2435,20 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, // Remove extension for delete *(end= path + path_length - reg_ext_length)= '\0'; - error= ha_delete_table(thd, table_type, path, db, table->table_name, - !dont_log_query); - - if (!error) + if ((error= ha_delete_table(thd, table_type, path, db, table->table_name, + !dont_log_query))) + { + if (thd->is_killed()) + { + error= -1; + goto err; + } + } + else { int frm_delete_error, trigger_drop_error= 0; - /* Delete the table definition file */ - strmov(end,reg_ext); + /* Delete the table definition file */ + strmov(end,reg_ext); if (table_type && table_type != view_pseudo_hton && table_type->discover_table) { @@ -2505,7 +2482,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, if (error) { if (wrong_tables.length()) - wrong_tables.append(','); + wrong_tables.append(','); wrong_tables.append(db); wrong_tables.append('.'); wrong_tables.append(table->table_name); @@ -2518,6 +2495,24 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, mysql_audit_drop_table(thd, table); } + if (!dont_log_query && !drop_temporary) + { + non_tmp_table_deleted= (if_exists ? TRUE : non_tmp_table_deleted); + /* + Don't write the database name if it is the current one (or if + thd->db is NULL). + */ + if (thd->db == NULL || strcmp(db,thd->db) != 0) + { + append_identifier(thd, &built_query, db, db_length); + built_query.append("."); + } + + append_identifier(thd, &built_query, table->table_name, + table->table_name_length); + built_query.append(","); + } + DBUG_PRINT("table", ("table: %p s: %p", table->table, table->table ? table->table->s : NULL)); } From 870acdf5340b5cec5b70d2d6d255f06087b8862c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 15 Aug 2019 09:00:01 +0300 Subject: [PATCH 50/63] After-merge fix: Re-record results --- .../galera/r/galera_performance_schema.result | 10 +- .../mysql-test/rocksdb/r/group_min_max.result | 476 +++++++++--------- 2 files changed, 257 insertions(+), 229 deletions(-) diff --git a/mysql-test/suite/galera/r/galera_performance_schema.result b/mysql-test/suite/galera/r/galera_performance_schema.result index 5b4994556d6..86d773bb1ef 100644 --- a/mysql-test/suite/galera/r/galera_performance_schema.result +++ b/mysql-test/suite/galera/r/galera_performance_schema.result @@ -1,3 +1,5 @@ +connection node_2; +connection node_1; use performance_schema; SELECT name FROM threads @@ -5,25 +7,29 @@ WHERE name LIKE 'thread/sql/wsrep%' ORDER BY name; name thread/sql/wsrep_applier_thread name thread/sql/wsrep_rollbacker_thread +name thread/sql/wsrep_rollbacker_thread use test; create table t1 (a int not null primary key) engine=innodb; insert into t1 values (1),(2); use performance_schema; select name from mutex_instances where name like 'wait/synch/mutex/sql/LOCK_wsrep%' order by name; +name wait/synch/mutex/sql/LOCK_wsrep_cluster_config name wait/synch/mutex/sql/LOCK_wsrep_config_state name wait/synch/mutex/sql/LOCK_wsrep_desync +name wait/synch/mutex/sql/LOCK_wsrep_group_commit name wait/synch/mutex/sql/LOCK_wsrep_ready name wait/synch/mutex/sql/LOCK_wsrep_replaying -name wait/synch/mutex/sql/LOCK_wsrep_rollback name wait/synch/mutex/sql/LOCK_wsrep_slave_threads +name wait/synch/mutex/sql/LOCK_wsrep_SR_pool +name wait/synch/mutex/sql/LOCK_wsrep_SR_store name wait/synch/mutex/sql/LOCK_wsrep_sst name wait/synch/mutex/sql/LOCK_wsrep_sst_init select name from cond_instances where name like 'wait/synch/cond/sql/COND_wsrep%' order by name; name wait/synch/cond/sql/COND_wsrep_ready name wait/synch/cond/sql/COND_wsrep_replaying -name wait/synch/cond/sql/COND_wsrep_rollback name wait/synch/cond/sql/COND_wsrep_sst name wait/synch/cond/sql/COND_wsrep_sst_init +name wait/synch/cond/sql/COND_wsrep_wsrep_slave_threads connection node_2; use test; SET SESSION wsrep_on=OFF; diff --git a/storage/rocksdb/mysql-test/rocksdb/r/group_min_max.result b/storage/rocksdb/mysql-test/rocksdb/r/group_min_max.result index a1031f518e0..8a2e193a083 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/group_min_max.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/group_min_max.result @@ -42,6 +42,7 @@ create index idx_t1_1 on t1 (a1,a2,b,c); create index idx_t1_2 on t1 (a1,a2,b); analyze table t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK drop table if exists t2; create table t2 ( @@ -70,6 +71,7 @@ create index idx_t2_1 on t2 (a1,a2,b,c); create index idx_t2_2 on t2 (a1,a2,b); analyze table t2; Table Op Msg_type Msg_text +test.t2 analyze status Engine-independent statistics collected test.t2 analyze status OK drop table if exists t3; create table t3 ( @@ -132,37 +134,38 @@ create index idx_t3_1 on t3 (a1,a2,b,c); create index idx_t3_2 on t3 (a1,a2,b); analyze table t3; Table Op Msg_type Msg_text +test.t3 analyze status Engine-independent statistics collected test.t3 analyze status OK explain select a1, min(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a1, max(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 65 NULL 63 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 65 NULL 5 Using index for group-by explain select a1, min(a2), max(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a1, a2, b, min(c), max(c) from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 17 Using index for group-by explain select a1,a2,b,max(c),min(c) from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 17 Using index for group-by explain select a1,a2,b,max(c),min(c) from t2 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range NULL idx_t2_1 # NULL # Using index for group-by explain select min(a2), a1, max(a2), min(a2), a1 from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a1, b, min(c), a1, max(c), b, a2, max(c), max(c) from t1 group by a1, a2, b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 17 Using index for group-by explain select min(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a2, min(c), max(c) from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 17 Using index for group-by select a1, min(a2) from t1 group by a1; a1 min(a2) a a @@ -289,37 +292,37 @@ b i421 l421 b m422 p422 explain select a1,a2,b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where a1 >= 'b' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 502 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select a1, max(c) from t1 where a1 >= 'c' or a1 < 'b' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 502 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where a1 >= 'c' or a2 < 'b' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 17 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 753 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 753 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 1004 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 1004 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select a1,min(c),max(c) from t1 where a1 >= 'b' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select a1, max(c) from t1 where a1 in ('a','b','d') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 753 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select a1,a2,b, max(c) from t2 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by @@ -681,97 +684,97 @@ d p422 # So the following results are not very meaningful, but are still kept here explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 63 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 5 Using where; Using index for group-by explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a' or a2 = 'b') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index explain select a1,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 63 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 5 Using where; Using index for group-by explain select a1,max(c),min(c) from t1 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index explain select a1,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index explain select a1,a2,b, max(c) from t1 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 9 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index explain select a1,a2,b,min(c),max(c) from t1 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 9 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index explain select a1,a2, max(c) from t1 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 9 Using where; Using index for group-by explain select a1,a2, max(c) from t1 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 163 NULL 63 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 6 Using where; Using index for group-by explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 163 NULL 63 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 6 Using where; Using index for group-by explain select a1,max(c),min(c) from t2 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b, max(c) from t2 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 146 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL 10 Using where; Using index for group-by explain select a1,a2,b, max(c) from t2 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b,min(c),max(c) from t2 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 10 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2, max(c) from t2 where (b = 'b') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 146 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL 10 Using where; Using index for group-by explain select a1,a2, max(c) from t2 where (b = 'b' or b = 'a') group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 range NULL idx_t3_1 6 NULL 63 Using where; Using index for group-by +1 SIMPLE t3 range NULL idx_t3_1 6 NULL 4 Using where; Using index for group-by explain select a1,a2,b,max(c),min(c) from t3 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 index NULL idx_t3_1 10 NULL 1000 Using where; Using index +1 SIMPLE t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index explain select a1,a2,b,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 index NULL idx_t3_1 10 NULL 1000 Using where; Using index +1 SIMPLE t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index explain select a1,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 range NULL idx_t3_1 6 NULL 63 Using where; Using index for group-by +1 SIMPLE t3 range NULL idx_t3_1 6 NULL 4 Using where; Using index for group-by explain select a1,max(c),min(c) from t3 where (a2 = 'a' or a2 = 'b') and (b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 index NULL idx_t3_1 10 NULL 1000 Using where; Using index +1 SIMPLE t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index explain select a1,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b' or b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 index NULL idx_t3_1 10 NULL 1000 Using where; Using index +1 SIMPLE t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1; a1 a2 b max(c) min(c) a a b h112 e112 @@ -1014,25 +1017,25 @@ b h212 a211 c h312 a311 explain select a1,a2,b,min(c) from t2 where (a2 = 'a') and b is NULL group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 163 NULL 63 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 6 Using where; Using index for group-by explain select a1,a2,b,min(c) from t2 where (a2 = 'a' or a2 = 'b') and b is NULL group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b,max(c) from t2 where (a2 = 'a') and b is NULL group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 146 NULL 63 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL 6 Using where; Using index for group-by explain select a1,a2,b,max(c) from t2 where (a2 = 'a' or a2 = 'b') and b is NULL group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b,min(c) from t2 where b is NULL group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 10 Using where; Using index for group-by explain select a1,a2,b,max(c) from t2 where b is NULL group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 146 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 146 NULL 10 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where b is NULL group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 163 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 10 Using where; Using index for group-by select a1,a2,b,min(c) from t2 where (a2 = 'a') and b is NULL group by a1; a1 a2 b min(c) a a NULL a777 @@ -1070,49 +1073,49 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 147 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (c > 'f123') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c > 'f123') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (c < 'a0') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (c < 'k321') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c < 'k321') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b, max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b111') and (c <= 'g112') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c < 'c5') or (c = 'g412') or (c = 'k421') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where ((c > 'b111') and (c <= 'g112')) or ((c > 'd000') and (c <= 'i110')) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (c between 'b111' and 'g112') or (c between 'd000' and 'i110') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b, max(c) from t2 where (c > 'b1') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by @@ -1579,36 +1582,36 @@ explain select a1,a2,b,min(c),max(c) from t1 where exists ( select * from t2 where t2.c = t1.c ) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 index NULL idx_t1_1 163 NULL 1000 Using index +1 PRIMARY t1 index NULL idx_t1_1 163 NULL 128 Using index 1 PRIMARY eq_ref distinct_key distinct_key 16 func 1 -2 MATERIALIZED t2 index NULL idx_t2_1 163 NULL 1000 Using index +2 MATERIALIZED t2 index NULL idx_t2_1 163 NULL 164 Using index explain select a1,a2,b,min(c),max(c) from t1 where exists ( select * from t2 where t2.c > 'b1' ) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 index NULL idx_t1_1 163 NULL 1000 Using index -2 SUBQUERY t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 PRIMARY t1 index NULL idx_t1_1 163 NULL 128 Using index +2 SUBQUERY t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (c > 'b111') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t1 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c) from t1 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c < 'h112') or (c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122')) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 502 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 133 Using where; Using index for group-by explain select a1,a2,b,min(c) from t1 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122') or (c < 'h112') or (c = 'c111')) group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 502 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 133 Using where; Using index for group-by explain select a1,a2,b,min(c) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select a1,a2,b,min(c) from t1 where (ord(a1) > 97) and (ord(a2) + ord(a1) > 194) and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 17 Using where; Using index for group-by explain select a1,a2,b,min(c),max(c) from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by @@ -1713,25 +1716,25 @@ select a1,a2,b,min(c) from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') grou a1 a2 b min(c) explain select a1,a2,b from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 17 Using where; Using index for group-by explain select a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_2 147 NULL 17 Using where; Using index for group-by explain select a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121' or c = 'i121') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 133 Using where; Using index for group-by explain select a1,a2,b from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_2 146 NULL # Using where; Using index for group-by explain select a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_2 146 NULL # Using where; Using index for group-by explain select a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by @@ -1740,7 +1743,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_2 146 NULL # Using where; Using index for group-by select a1,a2,b from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; a1 a2 b a a b @@ -1788,50 +1791,50 @@ select a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1 a1 a2 b explain select distinct a1,a2,b from t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_2 147 NULL 17 Using index for group-by explain select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_2 147 NULL 17 Using where; Using index for group-by explain extended select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 501 100.00 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 65 100.00 Using where; Using index for group-by Warnings: Note 1003 select distinct `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`b` = 'a' and `test`.`t1`.`c` = 'i121' and `test`.`t1`.`a2` >= 'b' explain select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 133 Using where; Using index for group-by explain select distinct b from t1 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 128 Using where; Using index explain select distinct a1 from t1 where a1 in ('a', 'd') and a2 = 'b'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 130 NULL 39 Using where; Using index for group-by explain select distinct a1 from t1 where a1 in ('a', 'd') and a2 = 'e'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 130 NULL 39 Using where; Using index for group-by explain select distinct a1,a2,b from t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using index for group-by +1 SIMPLE t2 range NULL idx_t2_2 146 NULL # Using index for group-by explain select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_2 146 NULL # Using where; Using index for group-by explain extended select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 range NULL idx_t2_1 163 NULL 501 100.00 Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_1 163 NULL 83 100.00 Using where; Using index for group-by Warnings: Note 1003 select distinct `test`.`t2`.`a1` AS `a1`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where `test`.`t2`.`b` = 'a' and `test`.`t2`.`c` = 'i121' and `test`.`t2`.`a2` >= 'b' explain select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_2 146 NULL # Using where; Using index for group-by explain select distinct b from t2 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_2 146 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_2 146 NULL 164 Using where; Using index explain select distinct a1 from t2 where a1 in ('a', 'd') and a2 = 'b'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 129 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_2 129 NULL 37 Using where; Using index for group-by explain select distinct a1 from t2 where a1 in ('a', 'd') and a2 = 'e'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 129 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_2 129 NULL 37 Using where; Using index for group-by select distinct a1,a2,b from t1; a1 a2 b a a a @@ -1960,46 +1963,46 @@ c e d e explain select distinct a1,a2,b from t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_2 147 NULL 17 Using index for group-by explain select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_2 147 NULL 17 Using where; Using index for group-by explain select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by explain select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 133 Using where; Using index for group-by explain select distinct b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by; Using temporary; Using filesort +1 SIMPLE t1 range NULL idx_t1_2 147 NULL 17 Using where; Using index for group-by; Using temporary; Using filesort explain select distinct a1 from t1 where a1 in ('a', 'd') and a2 = 'b' group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 130 NULL 39 Using where; Using index for group-by explain select distinct a1 from t1 where a1 in ('a', 'd') and a2 = 'e' group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 126 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 130 NULL 39 Using where; Using index for group-by explain select distinct a1,a2,b from t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using index for group-by +1 SIMPLE t2 range NULL idx_t2_2 146 NULL # Using index for group-by explain select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range NULL idx_t2_2 146 NULL # Using where; Using index for group-by explain select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range NULL idx_t2_1 163 NULL # Using where; Using index for group-by explain select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by +1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_2 146 NULL # Using where; Using index for group-by explain select distinct b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL idx_t2_1 146 NULL # Using where; Using index for group-by; Using temporary; Using filesort +1 SIMPLE t2 range NULL idx_t2_2 146 NULL # Using where; Using index for group-by; Using temporary; Using filesort explain select distinct a1 from t2 where a1 in ('a', 'd') and a2 = 'b' group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 129 NULL # Using where; Using index for group-by +1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_2 129 NULL # Using where; Using index for group-by explain select distinct a1 from t2 where a1 in ('a', 'd') and a2 = 'e' group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 129 NULL # Using where; Using index for group-by +1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_2 129 NULL # Using where; Using index for group-by select distinct a1,a2,b from t1; a1 a2 b a a a @@ -2082,21 +2085,21 @@ select distinct a1 from t2 where a1 in ('a', 'd') and a2 = 'e' group by a1; a1 explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_2 147 NULL 17 Using where; Using index for group-by explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 501 Using where; Using index for group-by (scanning) +1 SIMPLE t1 range NULL idx_t1_1 163 NULL 65 Using where; Using index for group-by explain extended select count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 100.00 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 133 100.00 Using where; Using index for group-by Warnings: Note 1003 select count(distinct `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`) AS `count(distinct a1,a2,b)` from `test`.`t1` where `test`.`t1`.`b` = 'c' and `test`.`t1`.`a1` > 'a' and `test`.`t1`.`a2` > 'a' explain select count(distinct b) from t1 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 128 Using where; Using index explain extended select 98 + count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 100.00 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 133 100.00 Using where; Using index for group-by Warnings: Note 1003 select 98 + count(distinct `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`) AS `98 + count(distinct a1,a2,b)` from `test`.`t1` where `test`.`t1`.`a1` > 'a' and `test`.`t1`.`a2` > 'a' select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); @@ -2116,19 +2119,19 @@ select 98 + count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a'); 104 explain select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select concat(a1,min(c)),b from t1 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select concat(a1,min(c)),b,max(c) from t1 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select concat(a1,a2),b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 251 Using where; Using index for group-by +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 133 Using where; Using index for group-by explain select concat(ord(min(b)),ord(max(b))),min(b),max(b) from t1 group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 126 Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 147 NULL 9 Using index for group-by select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b; a1 a2 b concat(min(c), max(c)) a a a a111d111 @@ -2197,83 +2200,83 @@ concat(ord(min(b)),ord(max(b))) min(b) max(b) 9798 a b explain select a1,a2,b,d,min(c),max(c) from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 128 explain select a1,a2,b,d from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 128 explain extended select a1,a2,min(b),max(b) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 1000 100.00 Using where; Using index +1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 128 100.00 Using where; Using index Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,min(`test`.`t1`.`b`) AS `min(b)`,max(`test`.`t1`.`b`) AS `max(b)` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2` explain extended select a1,a2,b,min(c),max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 1000 100.00 Using where +1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 128 100.00 Using where Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,min(`test`.`t1`.`c`) AS `min(c)`,max(`test`.`t1`.`c`) AS `max(c)` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`d` > 'xy2' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` explain extended select a1,a2,b,c from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b,c; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 1000 100.00 Using where +1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 128 100.00 Using where Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`d` > 'xy2' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`,`test`.`t1`.`c` explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') or (b < 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b < 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b <= 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b <= 'b' and b >= 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain extended select a1,a2,b from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 1000 100.00 Using where; Using index +1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 163 NULL 128 100.00 Using where; Using index Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` explain select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1; a1 a2 min(b) c a a a a111 explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') or (b = 'a') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b,min(c),max(c) from t2 where (c > 'a000') and (c <= 'd999') and (c like '_8__') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1, a2, b, c, min(d), max(d) from t1 group by a1,a2,b,c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_1 163 NULL 1000 +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 explain select a1,a2,count(a2) from t1 group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 Using index +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 128 Using index explain extended select a1,a2,count(a2) from t1 where (a1 > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 1000 100.00 Using where; Using index +1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 128 100.00 Using where; Using index Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,count(`test`.`t1`.`a2`) AS `count(a2)` from `test`.`t1` where `test`.`t1`.`a1` > 'a' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` explain extended select sum(ord(a1)) from t1 where (a1 > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 1000 100.00 Using where; Using index +1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 128 100.00 Using where; Using index Warnings: Note 1003 select sum(ord(`test`.`t1`.`a1`)) AS `sum(ord(a1))` from `test`.`t1` where `test`.`t1`.`a1` > 'a' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'a' or b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'a' or b = 'b') group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx_t2_1 163 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index explain select distinct(a1) from t1 where ord(a2) = 98; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL idx_t1_2 147 NULL 1000 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_2 147 NULL 128 Using where; Using index select distinct(a1) from t1 where ord(a2) = 98; a1 a @@ -2282,7 +2285,7 @@ c d explain select a1 from t1 where a2 = 'b' group by a1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using where; Using index for group-by select a1 from t1 where a2 = 'b' group by a1; a1 a @@ -2291,7 +2294,7 @@ c d explain select distinct a1 from t1 where a2 = 'b'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 130 NULL 63 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using where; Using index for group-by select distinct a1 from t1 where a2 = 'b'; a1 a @@ -2463,10 +2466,11 @@ CREATE TABLE t1 (a int, b int, PRIMARY KEY (a,b), KEY b (b)) engine=RocksDB; INSERT INTO t1 VALUES (1,1),(1,2),(1,0),(1,3); ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY,b PRIMARY 8 NULL 501 Using where; Using index for group-by +1 SIMPLE t1 range PRIMARY,b PRIMARY 8 NULL 500 Using where; Using index for group-by SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; MAX(b) a 1 1 @@ -2477,10 +2481,11 @@ CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a,b,c)) engine=RocksDB; INSERT INTO t2 SELECT a,b,b FROM t1; ANALYZE TABLE t2; Table Op Msg_type Msg_text +test.t2 analyze status Engine-independent statistics collected test.t2 analyze status OK explain SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range PRIMARY PRIMARY 12 NULL 251 Using where; Using index for group-by +1 SIMPLE t2 range PRIMARY PRIMARY 12 NULL 500 Using where; Using index for group-by SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a; MIN(c) 2 @@ -2490,10 +2495,11 @@ INSERT INTO t1 (a, b) VALUES (1,1), (1,2), (1,3), (1,4), (1,5), (2,2), (2,3), (2,1), (3,1), (4,1), (4,2), (4,3), (4,4), (4,5), (4,6); ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK EXPLAIN SELECT max(b), a FROM t1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 6 Using index for group-by FLUSH STATUS; SELECT max(b), a FROM t1 GROUP BY a; max(b) a @@ -2508,7 +2514,7 @@ Handler_read_next 0 Handler_read_retry 0 EXPLAIN SELECT max(b), a FROM t1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 6 Using index for group-by FLUSH STATUS; CREATE TABLE t2 engine=RocksDB SELECT max(b), a FROM t1 GROUP BY a; SHOW STATUS LIKE 'handler_read__e%'; @@ -2544,54 +2550,54 @@ Handler_read_retry 0 EXPLAIN (SELECT max(b), a FROM t1 GROUP BY a) UNION (SELECT max(b), a FROM t1 GROUP BY a); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 range NULL a 5 NULL 251 Using index for group-by -2 UNION t1 range NULL a 5 NULL 251 Using index for group-by +1 PRIMARY t1 range NULL a 5 NULL 6 Using index for group-by +2 UNION t1 range NULL a 5 NULL 6 Using index for group-by NULL UNION RESULT ALL NULL NULL NULL NULL NULL EXPLAIN SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x FROM t1 AS t1_outer; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer index NULL a 10 NULL 1000 Using index -2 SUBQUERY t1 range NULL a 5 NULL 251 Using index for group-by +1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index +2 SUBQUERY t1 range a a 5 NULL 400 Using where; Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE EXISTS (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer index NULL a 10 NULL 1000 Using index -2 SUBQUERY t1 index NULL a 10 NULL 1000 Using index +1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index +2 SUBQUERY t1 index NULL a 10 NULL 15 Using index EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer index NULL a 10 NULL 1000 Using index -2 SUBQUERY t1 range NULL a 5 NULL 251 Using index for group-by +1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index +2 SUBQUERY t1 range a a 5 NULL 400 Using where; Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE a IN (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY ALL distinct_key NULL NULL NULL 251 -1 PRIMARY t1_outer ref a a 5 .max(b) 4 Using index -2 MATERIALIZED t1 range NULL a 5 NULL 251 Using index for group-by +1 PRIMARY t1_outer index a a 10 NULL 15 Using where; Using index +1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1_outer.a 1 +2 MATERIALIZED t1 range a a 5 NULL 400 Using where; Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer GROUP BY a HAVING a > (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer range NULL a 5 NULL 251 Using index for group-by -2 SUBQUERY t1 range NULL a 5 NULL 251 Using index for group-by +1 PRIMARY t1_outer range NULL a 5 NULL 6 Using index for group-by +2 SUBQUERY t1 range a a 5 NULL 400 Using where; Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer1 JOIN t1 AS t1_outer2 ON t1_outer1.a = (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) AND t1_outer1.b = t1_outer2.b; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer1 ref a a 5 const 4 Using where; Using index -1 PRIMARY t1_outer2 index NULL a 10 NULL 1000 Using where; Using index; Using join buffer (flat, BNL join) -2 SUBQUERY t1 range NULL a 5 NULL 251 Using index for group-by +1 PRIMARY t1_outer1 ref a a 5 const 3 Using where; Using index +1 PRIMARY t1_outer2 index NULL a 10 NULL 15 Using where; Using index; Using join buffer (flat, BNL join) +2 SUBQUERY t1 range a a 5 NULL 400 Using where; Using index for group-by EXPLAIN SELECT (SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x FROM t1 AS t1_outer) x2 FROM t1 AS t1_outer2; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer2 index NULL a 10 NULL 1000 Using index -2 SUBQUERY t1_outer index NULL a 10 NULL 1000 Using index -3 SUBQUERY t1 range NULL a 5 NULL 251 Using index for group-by +1 PRIMARY t1_outer2 index NULL a 10 NULL 15 Using index +2 SUBQUERY t1_outer index NULL a 10 NULL 15 Using index +3 SUBQUERY t1 range a a 5 NULL 400 Using where; Using index for group-by CREATE TABLE t3 LIKE t1; FLUSH STATUS; INSERT INTO t3 SELECT a,MAX(b) FROM t1 GROUP BY a; SHOW STATUS LIKE 'handler_read__e%'; Variable_name Value -Handler_read_key 8 +Handler_read_key 13 Handler_read_next 0 Handler_read_retry 0 DELETE FROM t3; @@ -2626,10 +2632,11 @@ INSERT INTO t1 VALUES (4), (2), (1), (2), (2), (4), (1), (4); ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK EXPLAIN SELECT DISTINCT(a) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx 5 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL idx 5 NULL 4 Using index for group-by SELECT DISTINCT(a) FROM t1; a 1 @@ -2637,7 +2644,7 @@ a 4 EXPLAIN SELECT SQL_BIG_RESULT DISTINCT(a) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx 5 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL idx 5 NULL 4 Using index for group-by SELECT SQL_BIG_RESULT DISTINCT(a) FROM t1; a 1 @@ -2650,11 +2657,12 @@ INSERT INTO t1 SELECT a + 1, b FROM t1; INSERT INTO t1 SELECT a + 2, b FROM t1; ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK EXPLAIN SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a DESC; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 Using temporary; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 Using temporary; Using filesort SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a DESC; a MIN(b) MAX(b) 4 1 3 @@ -2665,7 +2673,7 @@ CREATE INDEX break_it ON t1 (a, b); EXPLAIN SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL break_it 10 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL break_it 10 NULL 4 Using index for group-by SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a; a MIN(b) MAX(b) 1 1 3 @@ -2675,7 +2683,7 @@ a MIN(b) MAX(b) EXPLAIN SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a DESC; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL break_it 10 NULL 251 Using index for group-by; Using temporary; Using filesort +1 SIMPLE t1 range NULL break_it 10 NULL 4 Using index for group-by; Using temporary; Using filesort SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a DESC; a MIN(b) MAX(b) 4 1 3 @@ -2685,7 +2693,7 @@ a MIN(b) MAX(b) EXPLAIN SELECT a, MIN(b), MAX(b), AVG(b) FROM t1 GROUP BY a ORDER BY a DESC; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL break_it 10 NULL 1000 Using index +1 SIMPLE t1 index NULL break_it 10 NULL 12 Using index SELECT a, MIN(b), MAX(b), AVG(b) FROM t1 GROUP BY a ORDER BY a DESC; a MIN(b) MAX(b) AVG(b) 4 1 3 2.0000 @@ -2706,6 +2714,7 @@ insert into t1 (a,b) values insert into t1 (a,b) select a, max(b)+1 from t1 where a = 0 group by a; ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK select * from t1; a b @@ -2768,7 +2777,7 @@ a b 3 13 explain extended select sql_buffer_result a, max(b)+1 from t1 where a = 0 group by a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ref PRIMARY,index PRIMARY 4 const 15 100.00 Using index; Using temporary +1 SIMPLE t1 ref PRIMARY,index PRIMARY 4 const 15 6.67 Using index; Using temporary Warnings: Note 1003 select sql_buffer_result `test`.`t1`.`a` AS `a`,max(`test`.`t1`.`b`) + 1 AS `max(b)+1` from `test`.`t1` where `test`.`t1`.`a` = 0 group by `test`.`t1`.`a` drop table t1; @@ -2780,10 +2789,11 @@ INSERT INTO t1 SELECT * FROM t1; INSERT INTO t1 SELECT a,b,c+1,d FROM t1; ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK EXPLAIN SELECT DISTINCT c FROM t1 WHERE d=4; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL foo 10 NULL 63 Using where; Using index for group-by +1 SIMPLE t1 range NULL foo 10 NULL 3 Using where; Using index for group-by SELECT DISTINCT c FROM t1 WHERE d=4; c 1 @@ -2799,13 +2809,14 @@ INSERT INTO t SELECT * FROM t; INSERT INTO t SELECT * FROM t; ANALYZE TABLE t; Table Op Msg_type Msg_text +test.t analyze status Engine-independent statistics collected test.t analyze status OK # test MIN #should use range with index for group by EXPLAIN SELECT a, MIN(b) FROM t WHERE b <> 0 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t range NULL a 10 NULL 251 Using where; Using index for group-by +1 SIMPLE t range NULL a 10 NULL 2 Using where; Using index for group-by #should return 1 row SELECT a, MIN(b) FROM t WHERE b <> 0 GROUP BY a; a MIN(b) @@ -2815,7 +2826,7 @@ a MIN(b) EXPLAIN SELECT a, MAX(b) FROM t WHERE b <> 1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t range NULL a 10 NULL 251 Using where; Using index for group-by +1 SIMPLE t range NULL a 10 NULL 2 Using where; Using index for group-by #should return 1 row SELECT a, MAX(b) FROM t WHERE b <> 1 GROUP BY a; a MAX(b) @@ -2826,7 +2837,7 @@ INSERT INTO t SELECT a, 2 FROM t; EXPLAIN SELECT a, MAX(b) FROM t WHERE b > 0 AND b < 2 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t range NULL a 10 NULL 251 Using where; Using index for group-by +1 SIMPLE t range NULL a 10 NULL 2 Using where; Using index for group-by #should return 1 row SELECT a, MAX(b) FROM t WHERE b > 0 AND b < 2 GROUP BY a; a MAX(b) @@ -2841,6 +2852,7 @@ INSERT INTO t VALUES (2,0), (2,0), (2,1), (2,1); INSERT INTO t SELECT * FROM t; ANALYZE TABLE t; Table Op Msg_type Msg_text +test.t analyze status Engine-independent statistics collected test.t analyze status OK SELECT a, MAX(b) FROM t WHERE 0=b+0 GROUP BY a; a MAX(b) @@ -2862,6 +2874,7 @@ CREATE TABLE t1(a INT NOT NULL, b INT NOT NULL, KEY (b)) engine=RocksDB; INSERT INTO t1 VALUES(1,1),(2,1); ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK SELECT 1 AS c, b FROM t1 WHERE b IN (1,2) GROUP BY c, b; c b @@ -2880,6 +2893,7 @@ CREATE TABLE t1 ( a INT, KEY (a) ) engine=RocksDB; INSERT INTO t1 VALUES (1), (2), (3); ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK EXPLAIN SELECT MIN( a ) FROM t1 WHERE a = NULL; @@ -2940,7 +2954,7 @@ NULL EXPLAIN SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); id select_type table type possible_keys key key_len ref rows Extra -x x x x x x x x x Using where; Using index +x x x x x x x x x Impossible WHERE noticed after reading const tables x x x x x x x x x Using where; Using index SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); MIN( a ) @@ -2955,6 +2969,7 @@ NULL INSERT INTO t1 VALUES (NULL), (NULL); ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK EXPLAIN SELECT MIN( a ) FROM t1 WHERE a = NULL; @@ -3015,7 +3030,7 @@ NULL EXPLAIN SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); id select_type table type possible_keys key key_len ref rows Extra -x x x x x x x x x Using where; Using index +x x x x x x x x x Impossible WHERE noticed after reading const tables x x x x x x x x x Using where; Using index SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); MIN( a ) @@ -3033,6 +3048,7 @@ CREATE TABLE t1 ( a INT NOT NULL PRIMARY KEY) engine=RocksDB; INSERT INTO t1 VALUES (1), (2), (3); ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK # # NULL-safe operator test disabled for non-NULL indexed columns. @@ -3097,7 +3113,7 @@ NULL EXPLAIN SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); id select_type table type possible_keys key key_len ref rows Extra -x x x x x x x x x Using where; Using index +x x x x x x x x x Impossible WHERE noticed after reading const tables x x x x x x x x x Using where; Using index SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); MIN( a ) @@ -3133,6 +3149,7 @@ INSERT INTO t1 SELECT a, b + 4, 1 FROM t1; INSERT INTO t1 SELECT a + 1, b, 1 FROM t1; ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK CREATE TABLE t2 (a INT, b INT, c INT, d INT, e INT, f INT, KEY (a,b,c)) engine=RocksDB; INSERT INTO t2 VALUES (1,1,1,1,1,1), (1,2,1,1,1,1), (1,3,1,1,1,1), @@ -3141,48 +3158,49 @@ INSERT INTO t2 SELECT a, b + 4, c,d,e,f FROM t2; INSERT INTO t2 SELECT a + 1, b, c,d,e,f FROM t2; ANALYZE TABLE t2; Table Op Msg_type Msg_text +test.t2 analyze status Engine-independent statistics collected test.t2 analyze status OK EXPLAIN SELECT COUNT(DISTINCT a) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 3 Using index for group-by SELECT COUNT(DISTINCT a) FROM t1; COUNT(DISTINCT a) 2 EXPLAIN SELECT COUNT(DISTINCT a,b) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL a 10 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL a 10 NULL 17 Using index for group-by SELECT COUNT(DISTINCT a,b) FROM t1; COUNT(DISTINCT a,b) 16 EXPLAIN SELECT COUNT(DISTINCT b,a) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL a 10 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL a 10 NULL 17 Using index for group-by SELECT COUNT(DISTINCT b,a) FROM t1; COUNT(DISTINCT b,a) 16 EXPLAIN SELECT COUNT(DISTINCT b) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL a 10 NULL 1000 Using index +1 SIMPLE t1 index NULL a 10 NULL 16 Using index SELECT COUNT(DISTINCT b) FROM t1; COUNT(DISTINCT b) 8 EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 3 Using index for group-by SELECT COUNT(DISTINCT a) FROM t1 GROUP BY a; COUNT(DISTINCT a) 1 1 EXPLAIN SELECT COUNT(DISTINCT b) FROM t1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL a 10 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL a 10 NULL 17 Using index for group-by SELECT COUNT(DISTINCT b) FROM t1 GROUP BY a; COUNT(DISTINCT b) 8 8 EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 GROUP BY b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL a 10 NULL 1000 Using index; Using filesort +1 SIMPLE t1 index NULL a 10 NULL 16 Using index; Using filesort SELECT COUNT(DISTINCT a) FROM t1 GROUP BY b; COUNT(DISTINCT a) 2 @@ -3195,94 +3213,94 @@ COUNT(DISTINCT a) 2 EXPLAIN SELECT DISTINCT COUNT(DISTINCT a) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL a 10 NULL 1000 Using index +1 SIMPLE t1 index NULL a 10 NULL 16 Using index SELECT DISTINCT COUNT(DISTINCT a) FROM t1; COUNT(DISTINCT a) 2 EXPLAIN SELECT COUNT(DISTINCT a, b + 0) FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL a 10 NULL 1000 Using index +1 SIMPLE t1 index NULL a 10 NULL 16 Using index SELECT COUNT(DISTINCT a, b + 0) FROM t1; COUNT(DISTINCT a, b + 0) 16 EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 HAVING COUNT(DISTINCT b) < 10; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL a 10 NULL 1000 Using index +1 SIMPLE t1 index NULL a 10 NULL 16 Using index SELECT COUNT(DISTINCT a) FROM t1 HAVING COUNT(DISTINCT b) < 10; COUNT(DISTINCT a) 2 EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 HAVING COUNT(DISTINCT c) < 10; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 SELECT COUNT(DISTINCT a) FROM t1 HAVING COUNT(DISTINCT c) < 10; COUNT(DISTINCT a) 2 EXPLAIN SELECT 1 FROM t1 HAVING COUNT(DISTINCT a) < 10; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 3 Using index for group-by SELECT 1 FROM t1 HAVING COUNT(DISTINCT a) < 10; 1 1 EXPLAIN SELECT 1 FROM t1 GROUP BY a HAVING COUNT(DISTINCT b) > 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL a 10 NULL 501 Using index for group-by +1 SIMPLE t1 range NULL a 10 NULL 17 Using index for group-by SELECT 1 FROM t1 GROUP BY a HAVING COUNT(DISTINCT b) > 1; 1 1 1 EXPLAIN SELECT COUNT(DISTINCT t1_1.a) FROM t1 t1_1, t1 t1_2 GROUP BY t1_1.a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1_1 index NULL a 10 NULL 1000 Using index; Using temporary; Using filesort -1 SIMPLE t1_2 index NULL a 10 NULL 1000 Using index; Using join buffer (flat, BNL join) +1 SIMPLE t1_1 index NULL a 10 NULL 16 Using index; Using temporary; Using filesort +1 SIMPLE t1_2 index NULL a 10 NULL 16 Using index; Using join buffer (flat, BNL join) SELECT COUNT(DISTINCT t1_1.a) FROM t1 t1_1, t1 t1_2 GROUP BY t1_1.a; COUNT(DISTINCT t1_1.a) 1 1 EXPLAIN SELECT COUNT(DISTINCT a), 12 FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL a 5 NULL 251 Using index for group-by +1 SIMPLE t1 range NULL a 5 NULL 3 Using index for group-by SELECT COUNT(DISTINCT a), 12 FROM t1; COUNT(DISTINCT a) 12 2 12 EXPLAIN SELECT COUNT(DISTINCT a, b, c) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL a 15 NULL 501 Using index for group-by +1 SIMPLE t2 range NULL a 15 NULL 17 Using index for group-by SELECT COUNT(DISTINCT a, b, c) FROM t2; COUNT(DISTINCT a, b, c) 16 EXPLAIN SELECT COUNT(DISTINCT a), SUM(DISTINCT a), AVG(DISTINCT a) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL a 5 NULL 126 Using index for group-by +1 SIMPLE t2 range NULL a 5 NULL 3 Using index for group-by SELECT COUNT(DISTINCT a), SUM(DISTINCT a), AVG(DISTINCT a) FROM t2; COUNT(DISTINCT a) SUM(DISTINCT a) AVG(DISTINCT a) 2 3 1.5000 EXPLAIN SELECT COUNT(DISTINCT a), SUM(DISTINCT a), AVG(DISTINCT f) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 +1 SIMPLE t2 ALL NULL NULL NULL NULL 16 SELECT COUNT(DISTINCT a), SUM(DISTINCT a), AVG(DISTINCT f) FROM t2; COUNT(DISTINCT a) SUM(DISTINCT a) AVG(DISTINCT f) 2 3 1.0000 EXPLAIN SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, a) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL a 10 NULL 251 Using index for group-by +1 SIMPLE t2 range NULL a 10 NULL 17 Using index for group-by SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, a) FROM t2; COUNT(DISTINCT a, b) COUNT(DISTINCT b, a) 16 16 EXPLAIN SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, f) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 +1 SIMPLE t2 ALL NULL NULL NULL NULL 16 SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, f) FROM t2; COUNT(DISTINCT a, b) COUNT(DISTINCT b, f) 16 8 EXPLAIN SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, d) FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 +1 SIMPLE t2 ALL NULL NULL NULL NULL 16 SELECT COUNT(DISTINCT a, b), COUNT(DISTINCT b, d) FROM t2; COUNT(DISTINCT a, b) COUNT(DISTINCT b, d) 16 8 EXPLAIN SELECT a, c, COUNT(DISTINCT c, a, b) FROM t2 GROUP BY a, b, c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL a 15 NULL 501 Using index for group-by +1 SIMPLE t2 range NULL a 15 NULL 17 Using index for group-by SELECT a, c, COUNT(DISTINCT c, a, b) FROM t2 GROUP BY a, b, c; a c COUNT(DISTINCT c, a, b) 1 1 1 @@ -3304,7 +3322,7 @@ a c COUNT(DISTINCT c, a, b) EXPLAIN SELECT COUNT(DISTINCT c, a, b) FROM t2 WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a a 15 NULL 501 Using where; Using index for group-by +1 SIMPLE t2 range a a 15 NULL 1062 Using where; Using index for group-by (scanning) SELECT COUNT(DISTINCT c, a, b) FROM t2 WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; COUNT(DISTINCT c, a, b) @@ -3317,28 +3335,28 @@ GROUP BY b; COUNT(DISTINCT b) SUM(DISTINCT b) EXPLAIN SELECT a, COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL a 10 NULL 251 Using index for group-by +1 SIMPLE t2 range NULL a 10 NULL 17 Using index for group-by SELECT a, COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a; a COUNT(DISTINCT b) SUM(DISTINCT b) 1 8 36 2 8 36 EXPLAIN SELECT COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL a 10 NULL 251 Using index for group-by +1 SIMPLE t2 range NULL a 10 NULL 17 Using index for group-by SELECT COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a; COUNT(DISTINCT b) SUM(DISTINCT b) 8 36 8 36 EXPLAIN SELECT COUNT(DISTINCT a, b) FROM t2 WHERE c = 13 AND d = 42; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 16 Using where SELECT COUNT(DISTINCT a, b) FROM t2 WHERE c = 13 AND d = 42; COUNT(DISTINCT a, b) 0 EXPLAIN SELECT a, COUNT(DISTINCT a), SUM(DISTINCT a) FROM t2 WHERE b = 13 AND c = 42 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL a 15 NULL 126 Using where; Using index for group-by +1 SIMPLE t2 range NULL a 15 NULL 3 Using where; Using index for group-by SELECT a, COUNT(DISTINCT a), SUM(DISTINCT a) FROM t2 WHERE b = 13 AND c = 42 GROUP BY a; a COUNT(DISTINCT a) SUM(DISTINCT a) @@ -3346,20 +3364,20 @@ a COUNT(DISTINCT a) SUM(DISTINCT a) # the second part of count(..) is defined by a constant predicate EXPLAIN SELECT COUNT(DISTINCT a, b), SUM(DISTINCT a) FROM t2 WHERE b = 42; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL a 15 NULL 1000 Using where; Using index +1 SIMPLE t2 index NULL a 15 NULL 16 Using where; Using index SELECT COUNT(DISTINCT a, b), SUM(DISTINCT a) FROM t2 WHERE b = 42; COUNT(DISTINCT a, b) SUM(DISTINCT a) 0 NULL EXPLAIN SELECT SUM(DISTINCT a), MAX(b) FROM t2 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL a 15 NULL 1000 Using index +1 SIMPLE t2 index NULL a 15 NULL 16 Using index SELECT SUM(DISTINCT a), MAX(b) FROM t2 GROUP BY a; SUM(DISTINCT a) MAX(b) 1 8 2 8 EXPLAIN SELECT 42 * (a + c + COUNT(DISTINCT c, a, b)) FROM t2 GROUP BY a, b, c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range NULL a 15 NULL 501 Using index for group-by +1 SIMPLE t2 range NULL a 15 NULL 17 Using index for group-by SELECT 42 * (a + c + COUNT(DISTINCT c, a, b)) FROM t2 GROUP BY a, b, c; 42 * (a + c + COUNT(DISTINCT c, a, b)) 126 @@ -3380,7 +3398,7 @@ SELECT 42 * (a + c + COUNT(DISTINCT c, a, b)) FROM t2 GROUP BY a, b, c; 168 EXPLAIN SELECT (SUM(DISTINCT a) + MAX(b)) FROM t2 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL a 15 NULL 1000 Using index +1 SIMPLE t2 index NULL a 15 NULL 16 Using index SELECT (SUM(DISTINCT a) + MAX(b)) FROM t2 GROUP BY a; (SUM(DISTINCT a) + MAX(b)) 9 @@ -3400,6 +3418,7 @@ insert into t1 values(1,'A'),(1 , 'B'), (1, 'C'), (2, 'A'), (3, 'A'), (3, 'B'), (3, 'C'), (3, 'D'); ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1; f1 COUNT(DISTINCT f2) @@ -3408,7 +3427,7 @@ f1 COUNT(DISTINCT f2) 3 4 explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL PRIMARY 5 NULL 1000 Using index +1 SIMPLE t1 index NULL PRIMARY 5 NULL 8 Using index drop table t1; # End of test#50539. # @@ -3419,9 +3438,11 @@ CREATE TABLE t (a INT, b INT, KEY(a,b)) engine=RocksDB; INSERT INTO t VALUES (1,1), (2,2), (3,3), (4,4), (1,0), (3,2), (4,5); ANALYZE TABLE t; Table Op Msg_type Msg_text +test.t analyze status Engine-independent statistics collected test.t analyze status OK ANALYZE TABLE t; Table Op Msg_type Msg_text +test.t analyze status Engine-independent statistics collected test.t analyze status OK SELECT a, SUM(DISTINCT a), MIN(b) FROM t GROUP BY a; a SUM(DISTINCT a) MIN(b) @@ -3431,7 +3452,7 @@ a SUM(DISTINCT a) MIN(b) 4 4 4 EXPLAIN SELECT a, SUM(DISTINCT a), MIN(b) FROM t GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t index NULL a 10 NULL 1000 Using index +1 SIMPLE t index NULL a 10 NULL 7 Using index SELECT a, SUM(DISTINCT a), MAX(b) FROM t GROUP BY a; a SUM(DISTINCT a) MAX(b) 1 1 1 @@ -3440,7 +3461,7 @@ a SUM(DISTINCT a) MAX(b) 4 4 5 EXPLAIN SELECT a, SUM(DISTINCT a), MAX(b) FROM t GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t index NULL a 10 NULL 1000 Using index +1 SIMPLE t index NULL a 10 NULL 7 Using index SELECT a, MAX(b) FROM t GROUP BY a HAVING SUM(DISTINCT a); a MAX(b) 1 1 @@ -3449,13 +3470,13 @@ a MAX(b) 4 5 EXPLAIN SELECT a, MAX(b) FROM t GROUP BY a HAVING SUM(DISTINCT a); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t index NULL a 10 NULL 1000 Using index +1 SIMPLE t index NULL a 10 NULL 7 Using index SELECT SUM(DISTINCT a), MIN(b), MAX(b) FROM t; SUM(DISTINCT a) MIN(b) MAX(b) 10 0 5 EXPLAIN SELECT SUM(DISTINCT a), MIN(b), MAX(b) FROM t; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t index NULL a 10 NULL 1000 Using index +1 SIMPLE t index NULL a 10 NULL 7 Using index SELECT a, SUM(DISTINCT a), MIN(b), MAX(b) FROM t GROUP BY a; a SUM(DISTINCT a) MIN(b) MAX(b) 1 1 0 1 @@ -3464,7 +3485,7 @@ a SUM(DISTINCT a) MIN(b) MAX(b) 4 4 4 5 EXPLAIN SELECT a, SUM(DISTINCT a), MIN(b), MAX(b) FROM t GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t index NULL a 10 NULL 1000 Using index +1 SIMPLE t index NULL a 10 NULL 7 Using index DROP TABLE t; # # Bug#18109609: LOOSE INDEX SCAN IS NOT USED WHEN IT SHOULD @@ -3480,6 +3501,7 @@ INSERT INTO t1(c1,c2) VALUES (4,14), (4,15), (4,16), (4,17), (4,18), (4,19), (4,20),(5,5); ANALYZE TABLE t1; Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK EXPLAIN SELECT MAX(c2), c1 FROM t1 WHERE c1 = 4 GROUP BY c1; id select_type table type possible_keys key key_len ref rows Extra From 841294cfaa0e9591de446a4f083477b61e05e3cc Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 15 Aug 2019 10:32:42 +0400 Subject: [PATCH 51/63] MDEV-20351 Window function BIT_OR() OVER (..) return a wrong data type --- mysql-test/main/win.result | 35 +++++++++++++++++++++++++++++++++++ mysql-test/main/win.test | 23 +++++++++++++++++++++++ sql/item_windowfunc.h | 2 +- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/win.result b/mysql-test/main/win.result index 412bfca4bf2..80c4109fe27 100644 --- a/mysql-test/main/win.result +++ b/mysql-test/main/win.result @@ -3654,5 +3654,40 @@ d x 00:00:02 NULL DROP TABLE t1; # +# MDEV-20351 Window function BIT_OR() OVER (..) return a wrong data type +# +CREATE TABLE t1 (pk INT, a INT, b BIGINT UNSIGNED); +INSERT INTO t1 VALUES (1, 0, 1), (2, 0, 18446744073709551615); +CREATE TABLE t2 AS +SELECT pk, a, bit_or(b) AS bit_or FROM t1 GROUP BY pk; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `pk` int(11) DEFAULT NULL, + `a` int(11) DEFAULT NULL, + `bit_or` bigint(21) unsigned NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t1; +pk a b +1 0 1 +2 0 18446744073709551615 +DROP TABLE t2; +CREATE OR REPLACE TABLE t2 AS +SELECT pk, a, BIT_OR(b) OVER (PARTITION BY a ORDER BY pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS bit_or +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `pk` int(11) DEFAULT NULL, + `a` int(11) DEFAULT NULL, + `bit_or` bigint(21) unsigned NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +pk a bit_or +1 0 18446744073709551615 +2 0 18446744073709551615 +DROP TABLE t2; +DROP TABLE t1; +# # End of 10.3 tests # diff --git a/mysql-test/main/win.test b/mysql-test/main/win.test index d49be4a0433..e71a4376392 100644 --- a/mysql-test/main/win.test +++ b/mysql-test/main/win.test @@ -2359,6 +2359,29 @@ INSERT INTO t1 VALUES ('00:00:01'),('00:00:02'); SELECT *, LEAD(d) OVER (ORDER BY d) AS x FROM t1; DROP TABLE t1; + +--echo # +--echo # MDEV-20351 Window function BIT_OR() OVER (..) return a wrong data type +--echo # +CREATE TABLE t1 (pk INT, a INT, b BIGINT UNSIGNED); +INSERT INTO t1 VALUES (1, 0, 1), (2, 0, 18446744073709551615); + +CREATE TABLE t2 AS +SELECT pk, a, bit_or(b) AS bit_or FROM t1 GROUP BY pk; +SHOW CREATE TABLE t2; +SELECT * FROM t1; +DROP TABLE t2; + +CREATE OR REPLACE TABLE t2 AS +SELECT pk, a, BIT_OR(b) OVER (PARTITION BY a ORDER BY pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS bit_or + FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2; +DROP TABLE t2; + +DROP TABLE t1; + + --echo # --echo # End of 10.3 tests --echo # diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h index e6389c01832..cc67c02f1ee 100644 --- a/sql/item_windowfunc.h +++ b/sql/item_windowfunc.h @@ -1282,7 +1282,7 @@ public: bool fix_length_and_dec() { - decimals = window_func()->decimals; + Type_std_attributes::set(window_func()); return FALSE; } From ae34d85beb1780c6a20ba1e57cfb9f25e85a270b Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Mon, 12 Aug 2019 15:16:33 +0300 Subject: [PATCH 52/63] MDEV-20311 row_ins_step accesses unitialized memory ins_node_create() does not initialize all members of que_common_t, so zero-init them with mem_heap_zalloc(). Handle out-of-memory correctly. Init insert_node->common.parent to fulfill the contract of thr usage. Free insert_node subtree at row_update_vers_insert() exit. --- storage/innobase/row/row0ins.cc | 12 +++++------- storage/innobase/row/row0mysql.cc | 14 +++++++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 26e46aedeb5..12bd2001495 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -74,7 +74,11 @@ ins_node_create( ins_node_t* node; node = static_cast( - mem_heap_alloc(heap, sizeof(ins_node_t))); + mem_heap_zalloc(heap, sizeof(ins_node_t))); + + if (!node) { + return(NULL); + } node->common.type = QUE_NODE_INSERT; @@ -82,12 +86,6 @@ ins_node_create( node->state = INS_NODE_SET_IX_LOCK; node->table = table; - node->index = NULL; - node->entry = NULL; - - node->select = NULL; - - node->trx_id = 0; node->entry_sys_heap = mem_heap_create(128); diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index fe6214adefe..aed2f87349d 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -2150,7 +2150,9 @@ This is used in UPDATE CASCADE/SET NULL of a system versioning table. @return DB_SUCCESS or some error */ static dberr_t row_update_vers_insert(que_thr_t* thr, upd_node_t* node) { - const trx_t* trx = thr_get_trx(thr); + trx_t* trx = thr_get_trx(thr); + dfield_t* row_end; + char row_end_data[8]; dict_table_t* table = node->table; ut_ad(table->versioned()); @@ -2161,10 +2163,15 @@ static dberr_t row_update_vers_insert(que_thr_t* thr, upd_node_t* node) ins_node_t* insert_node = ins_node_create(INS_DIRECT, table, node->historical_heap); + if (!insert_node) { + trx->error_state = DB_OUT_OF_MEMORY; + goto exit; + } + + insert_node->common.parent = thr; ins_node_set_new_row(insert_node, row); - dfield_t* row_end = dtuple_get_nth_field(row, table->vers_end); - char row_end_data[8]; + row_end = dtuple_get_nth_field(row, table->vers_end); if (dict_table_get_nth_col(table, table->vers_end)->vers_native()) { mach_write_to_8(row_end_data, trx->id); dfield_set_data(row_end, row_end_data, 8); @@ -2202,6 +2209,7 @@ static dberr_t row_update_vers_insert(que_thr_t* thr, upd_node_t* node) } } exit: + que_graph_free_recursive(insert_node); mem_heap_free(node->historical_heap); node->historical_heap = NULL; return trx->error_state; From 5a2012d2b3d3798f19f0b9502915f51c057338f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 15 Aug 2019 12:36:28 +0300 Subject: [PATCH 53/63] Fix test failure on galera-features#56 We need to use wsrep_sync_wait=15 before selects to make sure that node has applied all inserts from other node. --- mysql-test/suite/galera_sr/r/galera-features#56.result | 1 + mysql-test/suite/galera_sr/t/galera-features#56.test | 1 + 2 files changed, 2 insertions(+) diff --git a/mysql-test/suite/galera_sr/r/galera-features#56.result b/mysql-test/suite/galera_sr/r/galera-features#56.result index b56f955217b..a4264739cbf 100644 --- a/mysql-test/suite/galera_sr/r/galera-features#56.result +++ b/mysql-test/suite/galera_sr/r/galera-features#56.result @@ -26,6 +26,7 @@ INSERT INTO t1 (f2) SELECT 1 FROM ten AS a1, ten AS a2, ten AS a3, ten AS a4;; connection node_1; connection node_1a; connection node_2; +set session wsrep_sync_wait=15; SELECT COUNT(*) FROM t1; COUNT(*) 30000 diff --git a/mysql-test/suite/galera_sr/t/galera-features#56.test b/mysql-test/suite/galera_sr/t/galera-features#56.test index d3fe6363749..4d46a3bf853 100644 --- a/mysql-test/suite/galera_sr/t/galera-features#56.test +++ b/mysql-test/suite/galera_sr/t/galera-features#56.test @@ -52,6 +52,7 @@ SET SESSION wsrep_trx_fragment_size = 1; --connection node_2 --reap +set session wsrep_sync_wait=15; SELECT COUNT(*) FROM t1; SELECT COUNT(DISTINCT f1) FROM t1; From 0b20b9e91173141edda2cd5649b91bd63b61c127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 15 Aug 2019 12:53:08 +0300 Subject: [PATCH 54/63] Disable galera.query_cache as it still fails on bb and azure. --- mysql-test/suite/galera/disabled.def | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index 90b13bd7aa4..017d8ec1380 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -30,3 +30,4 @@ galera_ssl_upgrade : MDEV-19950 Galera test failure on galera_ssl_upgrade galera_sst_mariabackup_encrypt_with_key : MDEV-19926 Galera SST tests fail galera_wan : MDEV-17259: Test failure on galera.galera_wan partition : MDEV-19958 Galera test failure on galera.partition +query_cache: MDEV-15805 Test failure on galera.query_cache \ No newline at end of file From 136cf0400fedebf1b8521e77b016a0962663af2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 15 Aug 2019 13:48:55 +0300 Subject: [PATCH 55/63] Fix result error. --- mysql-test/suite/galera/r/MW-328A.result | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/galera/r/MW-328A.result b/mysql-test/suite/galera/r/MW-328A.result index aab548bdc3c..448e927f09d 100644 --- a/mysql-test/suite/galera/r/MW-328A.result +++ b/mysql-test/suite/galera/r/MW-328A.result @@ -32,7 +32,7 @@ connection node_2; UPDATE t1 SET j=2 WHERE i=1; connection node_1; COMMIT; -ERROR 40001: Deadlock: wsrep aborted transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction SELECT * FROM t1; i j 1 2 From ec28f9532e92820f59fc7298465407069e289a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 15 Aug 2019 15:06:27 +0300 Subject: [PATCH 56/63] MDEV-19740: Fix C++11 violations caught by GCC 9.2.1 --- sql/item.h | 3 +-- sql/sql_list.h | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/sql/item.h b/sql/item.h index 49762d3326f..1229f271790 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2,7 +2,7 @@ #define SQL_ITEM_INCLUDED /* Copyright (c) 2000, 2017, Oracle and/or its affiliates. - Copyright (c) 2009, 2018, MariaDB Corporation + Copyright (c) 2009, 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -651,7 +651,6 @@ class Item: public Value_source, public Type_std_attributes, public Type_handler { - void operator=(Item &); /** The index in the JOIN::join_tab array of the JOIN_TAB this Item is attached to. Items are attached (or 'pushed') to JOIN_TABs during optimization by the diff --git a/sql/sql_list.h b/sql/sql_list.h index c14ebfc00f7..a7ece69acb6 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -1,6 +1,7 @@ #ifndef INCLUDES_MYSQL_SQL_LIST_H #define INCLUDES_MYSQL_SQL_LIST_H /* Copyright (c) 2000, 2012, Oracle and/or its affiliates. + Copyright (c) 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -86,6 +87,14 @@ public: next= elements ? tmp.next : &first; } + SQL_I_List& operator=(const SQL_I_List &tmp) + { + elements= tmp.elements; + first= tmp.first; + next= tmp.next; + return *this; + } + inline void empty() { elements= 0; @@ -176,6 +185,13 @@ public: first == rhs.first && last == rhs.last; } + base_list& operator=(const base_list &rhs) + { + elements= rhs.elements; + first= rhs.first; + last= elements ? rhs.last : &first; + return *this; + } inline void empty() { elements=0; first= &end_of_list; last=&first;} inline base_list() { empty(); } @@ -190,9 +206,7 @@ public: */ inline base_list(const base_list &tmp) :Sql_alloc() { - elements= tmp.elements; - first= tmp.first; - last= elements ? tmp.last : &first; + *this= tmp; } /** Construct a deep copy of the argument in memory root mem_root. @@ -202,7 +216,7 @@ public: */ bool copy(const base_list *rhs, MEM_ROOT *mem_root); base_list(const base_list &rhs, MEM_ROOT *mem_root) { copy(&rhs, mem_root); } - inline base_list(bool error) { } + inline base_list(bool) {} inline bool push_back(void *info) { if (((*last)=new list_node(info, &end_of_list))) @@ -523,7 +537,6 @@ template class List :public base_list { public: inline List() :base_list() {} - inline List(const List &tmp) :base_list(tmp) {} inline List(const List &tmp, MEM_ROOT *mem_root) : base_list(tmp, mem_root) {} inline bool push_back(T *a) { return base_list::push_back(a); } From d07936aabadc99be885d6fed24d309e4611887c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 15 Aug 2019 15:29:03 +0300 Subject: [PATCH 57/63] MDEV-19740: Silence a bogus "may be uninitialized" warning --- extra/innochecksum.cc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/extra/innochecksum.cc b/extra/innochecksum.cc index a1ec663ee1a..4dca6572434 100644 --- a/extra/innochecksum.cc +++ b/extra/innochecksum.cc @@ -1590,10 +1590,8 @@ int main( byte* xdes = NULL; /* bytes read count */ ulint bytes; - /* current time */ - time_t now; /* last time */ - time_t lastt; + time_t lastt = 0; /* stat, to get file size. */ #ifdef _WIN32 struct _stat64 st; @@ -1946,7 +1944,6 @@ int main( /* main checksumming loop */ cur_page_num = start_page ? start_page : cur_page_num + 1; - lastt = 0; while (!feof(fil_in)) { bytes = read_file(buf, partial_page_read, @@ -2026,12 +2023,10 @@ first_non_zero: if (verbose && !read_from_stdin) { if ((cur_page_num % 64) == 0) { - now = time(0); + time_t now = time(0); if (!lastt) { lastt= now; - } - if (now - lastt >= 1 - && is_log_enabled) { + } else if (now - lastt >= 1 && is_log_enabled) { fprintf(log_file, "page::%llu " "okay: %.3f%% done\n", (cur_page_num - 1), From 112589cdeda90b20e015e495912fe7d4dd85c0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 15 Aug 2019 15:29:32 +0300 Subject: [PATCH 58/63] MDEV-19740: Remove a bogus condition This triggered a "may be uninitialized" warning from GCC 9.2.1. The bogus-looking condition was added in 7e916bb86f512ff79f30d809b813608a625ec5ba --- storage/innobase/row/row0sel.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index d5b1a596f01..6b3542e7aa3 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -5726,9 +5726,7 @@ lock_wait_or_error: /*-------------------------------------------------------------*/ if (!dict_index_is_spatial(index)) { - if (rec) { - btr_pcur_store_position(pcur, &mtr); - } + btr_pcur_store_position(pcur, &mtr); } lock_table_wait: From e6b505fd3cfb03567f0c0f5664f30de1b1c0f9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 16 Aug 2019 07:07:31 +0300 Subject: [PATCH 59/63] MDEV-18778: mysql_tzinfo_to_sql does not work correctly in MariaDB Galera There were two problems: (1) If user wanted same time zone information on all nodes in the Galera cluster all updates were not replicated as time zone information was stored on MyISAM tables. This is fixed on Galera by altering time zone tables to InnoDB while they are modified. (2) If user wanted different time zone information to nodes in the Galera cluster TRUNCATE TABLE for time zone tables was replicated by Galera destroying time zone information from other nodes. This is fixed on Galera by introducing new option for mysql_tzinfo_to_sql_symlink tool --skip-write-binlog to disable Galera replication while time zone tables are modified. Changes to be committed: modified: mysql-test/r/mysql_tzinfo_to_sql_symlink.result modified: mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink.result new file: mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink_skip.result new file: mysql-test/suite/wsrep/t/mysql_tzinfo_to_sql_symlink_skip.test modified: sql/tztime.cc This is 10.4 version of commit fa74088838c12210d782aa6c69faa5acebc1d3bc --- .../main/mysql_tzinfo_to_sql_symlink.result | 104 ++++++++++++++---- mysql-test/suite/galera/#disabled.def# | 50 +++++++++ .../r/mysql_tzinfo_to_sql_symlink.result | 82 +++++++++++--- .../r/mysql_tzinfo_to_sql_symlink_skip.result | 74 +++++++++++++ .../t/mysql_tzinfo_to_sql_symlink_skip.test | 40 +++++++ sql/tztime.cc | 64 +++++++++-- 6 files changed, 369 insertions(+), 45 deletions(-) create mode 100644 mysql-test/suite/galera/#disabled.def# create mode 100644 mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink_skip.result create mode 100644 mysql-test/suite/wsrep/t/mysql_tzinfo_to_sql_symlink_skip.test diff --git a/mysql-test/main/mysql_tzinfo_to_sql_symlink.result b/mysql-test/main/mysql_tzinfo_to_sql_symlink.result index 03543244105..966cc1d123a 100644 --- a/mysql-test/main/mysql_tzinfo_to_sql_symlink.result +++ b/mysql-test/main/mysql_tzinfo_to_sql_symlink.result @@ -2,9 +2,15 @@ # MDEV-5226 mysql_tzinfo_to_sql errors with tzdata 2013f and above # # Verbose run -set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?'); -prepare set_wsrep_myisam from @prep; -set @toggle=1; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=InnoDB; +ALTER TABLE time_zone_name ENGINE=InnoDB; +ALTER TABLE time_zone_transition ENGINE=InnoDB; +ALTER TABLE time_zone_transition_type ENGINE=InnoDB; +END IF| +\d ; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; @@ -28,11 +34,25 @@ Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/ignored.tab' as time zo Warning: Skipping directory 'MYSQLTEST_VARDIR/zoneinfo/posix/posix': to avoid infinite symlink recursion. ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; -set @toggle=0; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=Aria; +ALTER TABLE time_zone_name ENGINE=Aria; +ALTER TABLE time_zone_transition ENGINE=Aria; +ALTER TABLE time_zone_transition_type ENGINE=Aria; +END IF| +\d ; # Silent run -set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?'); -prepare set_wsrep_myisam from @prep; -set @toggle=1; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=InnoDB; +ALTER TABLE time_zone_name ENGINE=InnoDB; +ALTER TABLE time_zone_transition ENGINE=InnoDB; +ALTER TABLE time_zone_transition_type ENGINE=InnoDB; +END IF| +\d ; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; @@ -53,39 +73,83 @@ INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/garbage' as time zone. Skipping it. ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; -set @toggle=0; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=Aria; +ALTER TABLE time_zone_name ENGINE=Aria; +ALTER TABLE time_zone_transition ENGINE=Aria; +ALTER TABLE time_zone_transition_type ENGINE=Aria; +END IF| +\d ; # # Testing with explicit timezonefile # -set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?'); -prepare set_wsrep_myisam from @prep; -set @toggle=1; execute set_wsrep_myisam using @toggle; INSERT INTO time_zone (Use_leap_seconds) VALUES ('N'); SET @time_zone_id= LAST_INSERT_ID(); INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('XXX', @time_zone_id); INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES (@time_zone_id, 0, 0, 0, 'GMT') ; -set @toggle=0; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=Aria; +ALTER TABLE time_zone_name ENGINE=Aria; +ALTER TABLE time_zone_transition ENGINE=Aria; +ALTER TABLE time_zone_transition_type ENGINE=Aria; +END IF| +\d ; # # Testing --leap # -set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?'); -prepare set_wsrep_myisam from @prep; -set @toggle=1; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone_leap_second ENGINE=InnoDB; +END IF| +\d ; TRUNCATE TABLE time_zone_leap_second; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone_leap_second ENGINE=Aria; +END IF| +\d ; ALTER TABLE time_zone_leap_second ORDER BY Transition_time; -set @toggle=0; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=Aria; +ALTER TABLE time_zone_name ENGINE=Aria; +ALTER TABLE time_zone_transition ENGINE=Aria; +ALTER TABLE time_zone_transition_type ENGINE=Aria; +END IF| +\d ; # # MDEV-6236 - [PATCH] mysql_tzinfo_to_sql may produce invalid SQL # -set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?'); -prepare set_wsrep_myisam from @prep; -set @toggle=1; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=InnoDB; +ALTER TABLE time_zone_name ENGINE=InnoDB; +ALTER TABLE time_zone_transition ENGINE=InnoDB; +ALTER TABLE time_zone_transition_type ENGINE=InnoDB; +END IF| +\d ; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; TRUNCATE TABLE time_zone_transition_type; ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; -set @toggle=0; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=Aria; +ALTER TABLE time_zone_name ENGINE=Aria; +ALTER TABLE time_zone_transition ENGINE=Aria; +ALTER TABLE time_zone_transition_type ENGINE=Aria; +END IF| +\d ; diff --git a/mysql-test/suite/galera/#disabled.def# b/mysql-test/suite/galera/#disabled.def# new file mode 100644 index 00000000000..0bd39954f30 --- /dev/null +++ b/mysql-test/suite/galera/#disabled.def# @@ -0,0 +1,50 @@ +############################################################################## +# +# List the test cases that are to be disabled temporarily. +# +# Separate the test case name and the comment with ':'. +# +# : MDEV- +# +# Do not use any TAB characters for whitespace. +# +############################################################################## + +MW-286 : MDEV-19992 Galera test failure on MW-286 +GCF-1081 : MDEV-18283 Galera test failure on galera.GCF-1081 +MW-329 : MDEV-19962 Galera test failure on MW-329 +MW-360 : needs rewrite to be MariaDB gtid compatible +MW-388: MDEV-19803 Long semaphore wait error on galera.MW-388 +galera_account_management : MariaDB 10.0 does not support ALTER USER +galera_as_master_gtid : Requires MySQL GTID +galera_as_master_gtid_change_master : Requires MySQL GTID +galera_as_slave_gtid_replicate_do_db_cc : Requires MySQL GTID +galera_as_slave_preordered : wsrep-preordered feature not merged to MariaDB +galera_as_slave_replication_bundle : MDEV-15785 OPTION_GTID_BEGIN is set in Gtid_log_event::do_apply_event() +galera_autoinc_sst_mariabackup : MDEV-19926 Galera SST tests fail +galera_bf_abort_group_commit : MDEV-18282 Galera test failure on galera.galera_bf_abort_group_commit +galera_binlog_rows_query_log_events: MariaDB does not support binlog_rows_query_log_events +galera_binlog_stmt_autoinc: MDEV-19959 Galera test failure on galera_binlog_stmt_autoinc +galera_concurrent_ctas : MDEV-18180 Galera test failure on galera.galera_concurrent_ctas +galera_encrypt_tmp_files : Get error failed to enable encryption of temporary files +galera_flush : MariaDB does not have global.thread_statistics +galera_gcache_recover_manytrx : MDEV-18834 Galera test failure +galera_ist_mariabackup : MDEV-18829 test leaves port open +galera_ist_progress : MDEV-15236 fails when trying to read transfer status +galera_kill_largechanges : MDEV-18179 Galera test failure on galera.galera_kill_largechanges +galera_kill_nochanges : MDEV-18280 Galera test failure on galera_split_brain and galera_kill_nochanges +galera_many_tables_nopk : MDEV-18182 Galera test failure on galera.galera_many_tables_nopk +galera_migrate : MariaDB does not support START SLAVE USER +galera_pc_ignore_sb : MDEV-15811/MDEV-17357 Test failure +galera_split_brain : MDEV-18280 Galera test failure on galera_split_brain and galera_kill_nochanges +galera_ssl_upgrade : MDEV-13549 Galera test failures +galera_sst_mysqldump_with_key : MDEV-16890 Galera test failure +galera_var_node_address : MDEV-17151 Galera test failure +galera_var_notify_cmd : MDEV-13549 Galera test failures +galera_var_reject_queries : assertion in inline_mysql_socket_send +galera_var_retry_autocommit: MDEV-18181 Galera test failure on galera.galera_var_retry_autocommit +galera_sst_mariabackup_encrypt_with_key : MDEV-19926 Galera SST tests fail +galera_wan : MDEV-17259: Test failure on galera.galera_wan +mysql-wsrep#198 : MDEV-18935 Galera test mysql-wsrep#198 sporaric assertion transaction.cpp:362: int wsrep::transaction::before_commit(): Assertion `state() == s_executing || state() == s_committing || state() == s_must_abort || state() == s_replaying' failed. +partition : MDEV-19958 Galera test failure on galera.partition + diff --git a/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink.result b/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink.result index c00a0c73ce3..28fc332bb0a 100644 --- a/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink.result +++ b/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink.result @@ -2,9 +2,15 @@ # MDEV-5226 mysql_tzinfo_to_sql errors with tzdata 2013f and above # # Verbose run -set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?'); -prepare set_wsrep_myisam from @prep; -set @toggle=1; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=InnoDB; +ALTER TABLE time_zone_name ENGINE=InnoDB; +ALTER TABLE time_zone_transition ENGINE=InnoDB; +ALTER TABLE time_zone_transition_type ENGINE=InnoDB; +END IF| +\d ; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; @@ -28,11 +34,25 @@ Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/ignored.tab' as time zo Warning: Skipping directory 'MYSQLTEST_VARDIR/zoneinfo/posix/posix': to avoid infinite symlink recursion. ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; -set @toggle=0; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=Aria; +ALTER TABLE time_zone_name ENGINE=Aria; +ALTER TABLE time_zone_transition ENGINE=Aria; +ALTER TABLE time_zone_transition_type ENGINE=Aria; +END IF| +\d ; # Silent run -set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?'); -prepare set_wsrep_myisam from @prep; -set @toggle=1; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=InnoDB; +ALTER TABLE time_zone_name ENGINE=InnoDB; +ALTER TABLE time_zone_transition ENGINE=InnoDB; +ALTER TABLE time_zone_transition_type ENGINE=InnoDB; +END IF| +\d ; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; @@ -53,26 +73,56 @@ INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/garbage' as time zone. Skipping it. ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; -set @toggle=0; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=Aria; +ALTER TABLE time_zone_name ENGINE=Aria; +ALTER TABLE time_zone_transition ENGINE=Aria; +ALTER TABLE time_zone_transition_type ENGINE=Aria; +END IF| +\d ; # # Testing with explicit timezonefile # -set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?'); -prepare set_wsrep_myisam from @prep; -set @toggle=1; execute set_wsrep_myisam using @toggle; INSERT INTO time_zone (Use_leap_seconds) VALUES ('N'); SET @time_zone_id= LAST_INSERT_ID(); INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('XXX', @time_zone_id); INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES (@time_zone_id, 0, 0, 0, 'GMT') ; -set @toggle=0; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=Aria; +ALTER TABLE time_zone_name ENGINE=Aria; +ALTER TABLE time_zone_transition ENGINE=Aria; +ALTER TABLE time_zone_transition_type ENGINE=Aria; +END IF| +\d ; # # Testing --leap # -set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?'); -prepare set_wsrep_myisam from @prep; -set @toggle=1; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone_leap_second ENGINE=InnoDB; +END IF| +\d ; TRUNCATE TABLE time_zone_leap_second; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone_leap_second ENGINE=Aria; +END IF| +\d ; ALTER TABLE time_zone_leap_second ORDER BY Transition_time; -set @toggle=0; execute set_wsrep_myisam using @toggle; +\d | +IF (select count(*) from information_schema.global_variables where +variable_name='wsrep_on') = 1 THEN +ALTER TABLE time_zone ENGINE=Aria; +ALTER TABLE time_zone_name ENGINE=Aria; +ALTER TABLE time_zone_transition ENGINE=Aria; +ALTER TABLE time_zone_transition_type ENGINE=Aria; +END IF| +\d ; diff --git a/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink_skip.result b/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink_skip.result new file mode 100644 index 00000000000..4ce57c641b3 --- /dev/null +++ b/mysql-test/suite/wsrep/r/mysql_tzinfo_to_sql_symlink_skip.result @@ -0,0 +1,74 @@ +# +# MDEV-5226 mysql_tzinfo_to_sql errors with tzdata 2013f and above +# +# Verbose run +set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); +prepare set_wsrep_write_binlog from @prep1; +set @toggle=0; execute set_wsrep_write_binlog using @toggle; +TRUNCATE TABLE time_zone; +TRUNCATE TABLE time_zone_name; +TRUNCATE TABLE time_zone_transition; +TRUNCATE TABLE time_zone_transition_type; +INSERT INTO time_zone (Use_leap_seconds) VALUES ('N'); +SET @time_zone_id= LAST_INSERT_ID(); +INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('GMT', @time_zone_id); +INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES + (@time_zone_id, 0, 0, 0, 'GMT') +; +Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/garbage' as time zone. Skipping it. +Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/ignored.tab' as time zone. Skipping it. +INSERT INTO time_zone (Use_leap_seconds) VALUES ('N'); +SET @time_zone_id= LAST_INSERT_ID(); +INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('posix/GMT', @time_zone_id); +INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES + (@time_zone_id, 0, 0, 0, 'GMT') +; +Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/garbage' as time zone. Skipping it. +Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/ignored.tab' as time zone. Skipping it. +Warning: Skipping directory 'MYSQLTEST_VARDIR/zoneinfo/posix/posix': to avoid infinite symlink recursion. +ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; +ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; +# Silent run +set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); +prepare set_wsrep_write_binlog from @prep1; +set @toggle=0; execute set_wsrep_write_binlog using @toggle; +TRUNCATE TABLE time_zone; +TRUNCATE TABLE time_zone_name; +TRUNCATE TABLE time_zone_transition; +TRUNCATE TABLE time_zone_transition_type; +INSERT INTO time_zone (Use_leap_seconds) VALUES ('N'); +SET @time_zone_id= LAST_INSERT_ID(); +INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('GMT', @time_zone_id); +INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES + (@time_zone_id, 0, 0, 0, 'GMT') +; +Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/garbage' as time zone. Skipping it. +INSERT INTO time_zone (Use_leap_seconds) VALUES ('N'); +SET @time_zone_id= LAST_INSERT_ID(); +INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('posix/GMT', @time_zone_id); +INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES + (@time_zone_id, 0, 0, 0, 'GMT') +; +Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/garbage' as time zone. Skipping it. +ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; +ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; +# +# Testing with explicit timezonefile +# +set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); +prepare set_wsrep_write_binlog from @prep1; +set @toggle=0; execute set_wsrep_write_binlog using @toggle; +INSERT INTO time_zone (Use_leap_seconds) VALUES ('N'); +SET @time_zone_id= LAST_INSERT_ID(); +INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('XXX', @time_zone_id); +INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES + (@time_zone_id, 0, 0, 0, 'GMT') +; +# +# Testing --leap +# +set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?'); +prepare set_wsrep_write_binlog from @prep1; +set @toggle=0; execute set_wsrep_write_binlog using @toggle; +TRUNCATE TABLE time_zone_leap_second; +ALTER TABLE time_zone_leap_second ORDER BY Transition_time; diff --git a/mysql-test/suite/wsrep/t/mysql_tzinfo_to_sql_symlink_skip.test b/mysql-test/suite/wsrep/t/mysql_tzinfo_to_sql_symlink_skip.test new file mode 100644 index 00000000000..bb3009bd432 --- /dev/null +++ b/mysql-test/suite/wsrep/t/mysql_tzinfo_to_sql_symlink_skip.test @@ -0,0 +1,40 @@ +--source include/have_wsrep.inc +--source include/have_symlink.inc +--source include/not_windows.inc + +--echo # +--echo # MDEV-5226 mysql_tzinfo_to_sql errors with tzdata 2013f and above +--echo # + +--exec mkdir $MYSQLTEST_VARDIR/zoneinfo +--exec ln -s $MYSQLTEST_VARDIR/zoneinfo $MYSQLTEST_VARDIR/zoneinfo/posix +--copy_file std_data/zoneinfo/GMT $MYSQLTEST_VARDIR/zoneinfo/GMT +--copy_file std_data/words.dat $MYSQLTEST_VARDIR/zoneinfo/garbage +--copy_file std_data/words.dat $MYSQLTEST_VARDIR/zoneinfo/ignored.tab + +--echo # Verbose run +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_TZINFO_TO_SQL --verbose --skip-write-binlog $MYSQLTEST_VARDIR/zoneinfo 2>&1 + +--echo # Silent run +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_TZINFO_TO_SQL --skip-write-binlog $MYSQLTEST_VARDIR/zoneinfo 2>&1 + +--echo # +--echo # Testing with explicit timezonefile +--echo # + +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_TZINFO_TO_SQL --skip-write-binlog $MYSQLTEST_VARDIR/zoneinfo/GMT XXX 2>&1 + +--echo # +--echo # Testing --leap +--echo # + +--exec $MYSQL_TZINFO_TO_SQL --leap --skip-write-binlog $MYSQLTEST_VARDIR/zoneinfo/GMT 2>&1 + +# +# Cleanup +# + +--exec rm -rf $MYSQLTEST_VARDIR/zoneinfo diff --git a/sql/tztime.cc b/sql/tztime.cc index 09d775e7e51..c45a6598d69 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -147,6 +147,7 @@ typedef struct st_time_zone_info static my_bool prepare_tz_info(TIME_ZONE_INFO *sp, MEM_ROOT *storage); +my_bool opt_leap, opt_verbose, opt_skip_write_binlog; #if defined(TZINFO2SQL) || defined(TESTTIME) @@ -2428,6 +2429,14 @@ print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp) We are assuming that there are only one list of leap seconds For all timezones. */ + if (!opt_skip_write_binlog) + printf("\\d |\n" + "IF (select count(*) from information_schema.global_variables where\n" + "variable_name='wsrep_on') = 1 THEN\n" + "ALTER TABLE time_zone_leap_second ENGINE=InnoDB;\n" + "END IF|\n" + "\\d ;\n"); + printf("TRUNCATE TABLE time_zone_leap_second;\n"); if (sp->leapcnt) @@ -2440,6 +2449,14 @@ print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp) printf(";\n"); } + if (!opt_skip_write_binlog) + printf("\\d |\n" + "IF (select count(*) from information_schema.global_variables where\n" + "variable_name='wsrep_on') = 1 THEN\n" + "ALTER TABLE time_zone_leap_second ENGINE=Aria;\n" + "END IF|\n" + "\\d ;\n"); + printf("ALTER TABLE time_zone_leap_second ORDER BY Transition_time;\n"); } @@ -2597,8 +2614,6 @@ scan_tz_dir(char * name_end, uint symlink_recursion_level, uint verbose) } -my_bool opt_leap, opt_verbose; - static const char *load_default_groups[]= { "mysql_tzinfo_to_sql", 0}; @@ -2619,6 +2634,8 @@ static struct my_option my_long_options[] = &opt_verbose, &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"skip-write-binlog", 'S', "Do not replicate changes to time zone tables to other nodes in a Galera cluster", + &opt_skip_write_binlog,&opt_skip_write_binlog, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -2687,11 +2704,14 @@ main(int argc, char **argv) return 1; } - // Replicate MyISAM DDL for this session, cf. lp:1161432 - // timezone info unfixable in XtraDB Cluster - printf("set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?');\n" - "prepare set_wsrep_myisam from @prep;\n" - "set @toggle=1; execute set_wsrep_myisam using @toggle;\n"); + if (opt_skip_write_binlog) + /* If skip_write_binlog is set and wsrep is compiled in we disable + sql_log_bin and wsrep_on to avoid Galera replicating below + truncate table clauses. This will allow user to set different + time zones to nodes in Galera cluster. */ + printf("set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?');\n" + "prepare set_wsrep_write_binlog from @prep1;\n" + "set @toggle=0; execute set_wsrep_write_binlog using @toggle;\n"); if (argc == 1 && !opt_leap) { @@ -2699,6 +2719,21 @@ main(int argc, char **argv) root_name_end= strmake_buf(fullname, argv[0]); + if(!opt_skip_write_binlog) + { + // Alter time zone tables to InnoDB if wsrep_on is enabled + // to allow changes to them to replicate with Galera + printf("\\d |\n" + "IF (select count(*) from information_schema.global_variables where\n" + "variable_name='wsrep_on') = 1 THEN\n" + "ALTER TABLE time_zone ENGINE=InnoDB;\n" + "ALTER TABLE time_zone_name ENGINE=InnoDB;\n" + "ALTER TABLE time_zone_transition ENGINE=InnoDB;\n" + "ALTER TABLE time_zone_transition_type ENGINE=InnoDB;\n" + "END IF|\n" + "\\d ;\n"); + } + printf("TRUNCATE TABLE time_zone;\n"); printf("TRUNCATE TABLE time_zone_name;\n"); printf("TRUNCATE TABLE time_zone_transition;\n"); @@ -2740,8 +2775,19 @@ main(int argc, char **argv) free_root(&tz_storage, MYF(0)); } - // Reset wsrep_replicate_myisam. lp:1161432 - printf("set @toggle=0; execute set_wsrep_myisam using @toggle;\n"); + if(!opt_skip_write_binlog) + { + // Fall back to Aria + printf("\\d |\n" + "IF (select count(*) from information_schema.global_variables where\n" + "variable_name='wsrep_on') = 1 THEN\n" + "ALTER TABLE time_zone ENGINE=Aria;\n" + "ALTER TABLE time_zone_name ENGINE=Aria;\n" + "ALTER TABLE time_zone_transition ENGINE=Aria;\n" + "ALTER TABLE time_zone_transition_type ENGINE=Aria;\n" + "END IF|\n" + "\\d ;\n"); + } free_defaults(default_argv); my_end(0); From 130d9490c844d82a7a8613c343a1969c0bec4c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 16 Aug 2019 08:29:41 +0300 Subject: [PATCH 60/63] Silence GCC 9.2.1 -Warray-bounds No memory access violated the bounds of fake_extra_buf[], but GCC does not like the fact that the pointer fake_extra ends up pointing before the array. Allocate a dummy element at the start of fake_extra_buf[] in order to silence the warning. --- storage/innobase/row/row0log.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/storage/innobase/row/row0log.cc b/storage/innobase/row/row0log.cc index 78f283a3fc8..71fb7fc5f7f 100644 --- a/storage/innobase/row/row0log.cc +++ b/storage/innobase/row/row0log.cc @@ -1003,7 +1003,7 @@ row_log_table_low( extra_size = rec_extra_size + is_instant; unsigned fake_extra_size = 0; - byte fake_extra_buf[2]; + byte fake_extra_buf[3]; if (is_instant && UNIV_UNLIKELY(!index->is_instant())) { /* The source table was emptied after ALTER TABLE started, and it was converted to non-instant format. @@ -1015,9 +1015,9 @@ row_log_table_low( fake_extra_size = rec_get_n_add_field_len(n_add); ut_ad(fake_extra_size == 1 || fake_extra_size == 2); extra_size += fake_extra_size; - byte* fake_extra = fake_extra_buf + fake_extra_size - 1; + byte* fake_extra = fake_extra_buf + fake_extra_size; rec_set_n_add_field(fake_extra, n_add); - ut_ad(fake_extra + 1 == fake_extra_buf); + ut_ad(fake_extra == fake_extra_buf); } mrec_size = ROW_LOG_HEADER_SIZE @@ -1076,7 +1076,7 @@ row_log_table_low( memcpy(b, rec - rec_extra_size - omit_size, rec_extra_size); b += rec_extra_size; - memcpy(b, fake_extra_buf, fake_extra_size); + memcpy(b, fake_extra_buf + 1, fake_extra_size); b += fake_extra_size; ulint len; ulint trx_id_offs = rec_get_nth_field_offs( From 3bbf008096fc997556459442bc2503c504248345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 16 Aug 2019 08:33:01 +0300 Subject: [PATCH 61/63] Remove file accidentally pushed. --- mysql-test/suite/galera/#disabled.def# | 50 -------------------------- 1 file changed, 50 deletions(-) delete mode 100644 mysql-test/suite/galera/#disabled.def# diff --git a/mysql-test/suite/galera/#disabled.def# b/mysql-test/suite/galera/#disabled.def# deleted file mode 100644 index 0bd39954f30..00000000000 --- a/mysql-test/suite/galera/#disabled.def# +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################## -# -# List the test cases that are to be disabled temporarily. -# -# Separate the test case name and the comment with ':'. -# -# : MDEV- -# -# Do not use any TAB characters for whitespace. -# -############################################################################## - -MW-286 : MDEV-19992 Galera test failure on MW-286 -GCF-1081 : MDEV-18283 Galera test failure on galera.GCF-1081 -MW-329 : MDEV-19962 Galera test failure on MW-329 -MW-360 : needs rewrite to be MariaDB gtid compatible -MW-388: MDEV-19803 Long semaphore wait error on galera.MW-388 -galera_account_management : MariaDB 10.0 does not support ALTER USER -galera_as_master_gtid : Requires MySQL GTID -galera_as_master_gtid_change_master : Requires MySQL GTID -galera_as_slave_gtid_replicate_do_db_cc : Requires MySQL GTID -galera_as_slave_preordered : wsrep-preordered feature not merged to MariaDB -galera_as_slave_replication_bundle : MDEV-15785 OPTION_GTID_BEGIN is set in Gtid_log_event::do_apply_event() -galera_autoinc_sst_mariabackup : MDEV-19926 Galera SST tests fail -galera_bf_abort_group_commit : MDEV-18282 Galera test failure on galera.galera_bf_abort_group_commit -galera_binlog_rows_query_log_events: MariaDB does not support binlog_rows_query_log_events -galera_binlog_stmt_autoinc: MDEV-19959 Galera test failure on galera_binlog_stmt_autoinc -galera_concurrent_ctas : MDEV-18180 Galera test failure on galera.galera_concurrent_ctas -galera_encrypt_tmp_files : Get error failed to enable encryption of temporary files -galera_flush : MariaDB does not have global.thread_statistics -galera_gcache_recover_manytrx : MDEV-18834 Galera test failure -galera_ist_mariabackup : MDEV-18829 test leaves port open -galera_ist_progress : MDEV-15236 fails when trying to read transfer status -galera_kill_largechanges : MDEV-18179 Galera test failure on galera.galera_kill_largechanges -galera_kill_nochanges : MDEV-18280 Galera test failure on galera_split_brain and galera_kill_nochanges -galera_many_tables_nopk : MDEV-18182 Galera test failure on galera.galera_many_tables_nopk -galera_migrate : MariaDB does not support START SLAVE USER -galera_pc_ignore_sb : MDEV-15811/MDEV-17357 Test failure -galera_split_brain : MDEV-18280 Galera test failure on galera_split_brain and galera_kill_nochanges -galera_ssl_upgrade : MDEV-13549 Galera test failures -galera_sst_mysqldump_with_key : MDEV-16890 Galera test failure -galera_var_node_address : MDEV-17151 Galera test failure -galera_var_notify_cmd : MDEV-13549 Galera test failures -galera_var_reject_queries : assertion in inline_mysql_socket_send -galera_var_retry_autocommit: MDEV-18181 Galera test failure on galera.galera_var_retry_autocommit -galera_sst_mariabackup_encrypt_with_key : MDEV-19926 Galera SST tests fail -galera_wan : MDEV-17259: Test failure on galera.galera_wan -mysql-wsrep#198 : MDEV-18935 Galera test mysql-wsrep#198 sporaric assertion transaction.cpp:362: int wsrep::transaction::before_commit(): Assertion `state() == s_executing || state() == s_committing || state() == s_must_abort || state() == s_replaying' failed. -partition : MDEV-19958 Galera test failure on galera.partition - From 555af003e4291dc41e21fe143ca19649972e2ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 16 Aug 2019 09:54:33 +0300 Subject: [PATCH 62/63] MDEV-8588/MDEV-19740: Restore a condition It looks like the merge of MySQL 5.7.9 to MariaDB 10.2.2 conflicted with earlier changes that were made in MDEV-8588. row_search_mvcc(): If the page is corrupted, avoid invoking btr_cur_store_position(). The caller should not try to fetch the next record after a hard error. --- storage/innobase/row/row0sel.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 6b3542e7aa3..19130576425 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -4725,7 +4725,7 @@ wait_table_again: if (err != DB_SUCCESS) { rec = NULL; - goto lock_wait_or_error; + goto page_read_error; } pcur->trx_if_known = trx; @@ -4779,7 +4779,7 @@ wait_table_again: index->table->file_unreadable = true; } rec = NULL; - goto lock_wait_or_error; + goto page_read_error; } } @@ -4800,7 +4800,7 @@ rec_loop: if (!index->table->is_readable()) { err = DB_DECRYPTION_FAILED; - goto lock_wait_or_error; + goto page_read_error; } ut_ad(!!page_rec_is_comp(rec) == comp); @@ -4895,7 +4895,7 @@ wrong_offs: ut_ad(0); err = DB_CORRUPTION; - goto lock_wait_or_error; + goto page_read_error; } else { /* The user may be dumping a corrupt table. Jump over the corruption to recover as much as possible. */ @@ -5717,6 +5717,10 @@ not_moved: goto normal_return; lock_wait_or_error: + if (!dict_index_is_spatial(index)) { + btr_pcur_store_position(pcur, &mtr); + } +page_read_error: /* Reset the old and new "did semi-consistent read" flags. */ if (UNIV_UNLIKELY(prebuilt->row_read_type == ROW_READ_DID_SEMI_CONSISTENT)) { @@ -5724,11 +5728,6 @@ lock_wait_or_error: } did_semi_consistent_read = FALSE; - /*-------------------------------------------------------------*/ - if (!dict_index_is_spatial(index)) { - btr_pcur_store_position(pcur, &mtr); - } - lock_table_wait: mtr.commit(); mtr_has_extra_clust_latch = FALSE; From fe6eac0cf7ecf1b38e8cf243104e185b8c67eae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 16 Aug 2019 09:50:54 +0300 Subject: [PATCH 63/63] MDEV-19200: shutdown timeout on innodb.undo_truncate_recover Optimize the test by dropping the table early and by using only one undo log thread, so that purge will be doing more useful work and less busy work of suspending and resuming the worker threads. The test used to cause shutdown timeout on 10.4 on buildbot, and for me locally when using --mysqld=--innodb-sync-debug. With these tweaks, it passes for me with --mysqld=--innodb-sync-debug. --- mysql-test/suite/innodb/r/undo_truncate_recover.result | 2 +- mysql-test/suite/innodb/t/undo_truncate_recover.opt | 1 + mysql-test/suite/innodb/t/undo_truncate_recover.test | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 mysql-test/suite/innodb/t/undo_truncate_recover.opt diff --git a/mysql-test/suite/innodb/r/undo_truncate_recover.result b/mysql-test/suite/innodb/r/undo_truncate_recover.result index e1b6a67368b..03393f38aed 100644 --- a/mysql-test/suite/innodb/r/undo_truncate_recover.result +++ b/mysql-test/suite/innodb/r/undo_truncate_recover.result @@ -9,8 +9,8 @@ update t1 set c = 'MariaDB'; update t1 set c = 'InnoDB'; set global debug_dbug = '+d,ib_undo_trunc'; commit; +drop table t1; call mtr.add_suppression("InnoDB: innodb_undo_tablespaces=0 disables dedicated undo log tablespaces"); call mtr.add_suppression("InnoDB: The transaction log size is too large"); SET GLOBAL innodb_fast_shutdown=0; FOUND 1 /ib_undo_trunc/ in mysqld.1.err -drop table t1; diff --git a/mysql-test/suite/innodb/t/undo_truncate_recover.opt b/mysql-test/suite/innodb/t/undo_truncate_recover.opt new file mode 100644 index 00000000000..a1207721427 --- /dev/null +++ b/mysql-test/suite/innodb/t/undo_truncate_recover.opt @@ -0,0 +1 @@ +--innodb-purge-threads=1 diff --git a/mysql-test/suite/innodb/t/undo_truncate_recover.test b/mysql-test/suite/innodb/t/undo_truncate_recover.test index c28a2154f92..94e09ed0e64 100644 --- a/mysql-test/suite/innodb/t/undo_truncate_recover.test +++ b/mysql-test/suite/innodb/t/undo_truncate_recover.test @@ -34,6 +34,7 @@ update t1 set c = 'MariaDB'; update t1 set c = 'InnoDB'; eval set global debug_dbug = '+d,$SEARCH_PATTERN'; commit; +drop table t1; call mtr.add_suppression("InnoDB: innodb_undo_tablespaces=0 disables dedicated undo log tablespaces"); # FIXME: remove this work-around, and generate less log! call mtr.add_suppression("InnoDB: The transaction log size is too large"); @@ -43,5 +44,3 @@ SET GLOBAL innodb_fast_shutdown=0; # FIXME: remove this work-around, and generate less log! --let $restart_parameters= --innodb-buffer-pool-size=16m --innodb-undo-tablespaces=1 --source include/start_mysqld.inc - -drop table t1;