From 9b8fc089bd007d55b0e6b9e587429fe08033a98d Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Fri, 15 Feb 2019 10:16:19 +0100 Subject: [PATCH 01/19] MDEV-18198 Fix MTR test galera_sr.galera_sr_table_contents * Created new binlog-header file * Fixed warning on SELECT INTO DUMPFILE * Re-recorded the test result --- mysql-test/std_data/binlog-header.binlog | Bin 0 -> 256 bytes .../galera/include/galera_dump_sr_table.inc | 6 +- .../r/galera_sr_table_contents.result | 192 ++++++++---------- 3 files changed, 89 insertions(+), 109 deletions(-) create mode 100644 mysql-test/std_data/binlog-header.binlog diff --git a/mysql-test/std_data/binlog-header.binlog b/mysql-test/std_data/binlog-header.binlog new file mode 100644 index 0000000000000000000000000000000000000000..d37fac92f19ee67a2a7d73736d70c57dd8ead643 GIT binary patch literal 256 zcmeyDl$rN#N@@&0BLf4&A0TD`F&J1F3=Q;5^o(_V6N@qvU7U1NQj<#4b#wC5L9*BZ z$QWS@UIq>ZAqEy85Mp3>!oVWM0aVSw!NCNixVX5mYo(tki!ciVFVHzar!aaNB*_2( DhDQ=# literal 0 HcmV?d00001 diff --git a/mysql-test/suite/galera/include/galera_dump_sr_table.inc b/mysql-test/suite/galera/include/galera_dump_sr_table.inc index 48a55006eae..1e6ff5548d2 100644 --- a/mysql-test/suite/galera/include/galera_dump_sr_table.inc +++ b/mysql-test/suite/galera/include/galera_dump_sr_table.inc @@ -11,17 +11,17 @@ while ($seqno <= $sr_max) --let $sr_fragment_file = $MYSQLTEST_VARDIR/tmp/sr_fragment.log --exec rm -rf $sr_fragment_file --disable_query_log - --eval SELECT frag FROM mysql.wsrep_streaming_log WHERE seqno = $seqno INTO DUMPFILE '$sr_fragment_file' + --eval SELECT frag INTO DUMPFILE '$sr_fragment_file' FROM mysql.wsrep_streaming_log WHERE seqno = $seqno --enable_query_log --let $sr_binlog_file = $MYSQLTEST_VARDIR/tmp/sr_binlog.log --exec rm -rf $sr_binlog_file - --exec cp std_data/binlog-header.log $sr_binlog_file + --exec cp std_data/binlog-header.binlog $sr_binlog_file --exec cat $sr_fragment_file >> $sr_binlog_file --replace_regex /SET TIMESTAMP=[0-9]+/SET TIMESTAMP=/ /#[0-9]+ +[0-9]+:[0-9]+:[0-9]+// /pseudo_thread_id=[0-9]+/pseudo_thread_id=/ /thread_id=[0-9]+/thread_id=/ /table id [0-9]+/table id / /mapped to number [0-9]+/mapped to number / /auto_increment_increment=[0-9]+/auto_increment_increment=/ /auto_increment_offset=[0-9]+/auto_increment_offset=/ /exec_time=[0-9]+/exec_time=/ - --exec $MYSQL_BINLOG --skip-gtids $sr_binlog_file --base64-output=decode-rows --start-position=120 | grep -v 'SET @' 2>&1 + --exec $MYSQL_BINLOG $sr_binlog_file --base64-output=decode-rows --start-position=256 --skip-annotate-row-events | grep -v 'SET @' 2>&1 --inc $seqno } diff --git a/mysql-test/suite/galera_sr/r/galera_sr_table_contents.result b/mysql-test/suite/galera_sr/r/galera_sr_table_contents.result index 29bb71704e2..006a1a9da96 100644 --- a/mysql-test/suite/galera_sr/r/galera_sr_table_contents.result +++ b/mysql-test/suite/galera_sr/r/galera_sr_table_contents.result @@ -1,3 +1,5 @@ +connection node_2; +connection node_1; CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1),(2),(3); CREATE TABLE t2 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; @@ -9,16 +11,12 @@ START TRANSACTION; Start of Simple Insert INSERT INTO t1 VALUES (4); DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 73 Query thread_id= exec_time= error_code=0 -SET TIMESTAMP=/*!*/; -/*!\C latin1 *//*!*/; -BEGIN -/*!*/; -# at 193 - server id 1 end_log_pos 114 Table_map: `test`.`t1` mapped to number -# at 234 - server id 1 end_log_pos 150 Write_rows: table id flags: STMT_END_F +# at 256 +# at 300 + server id 1 end_log_pos 85 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 341 + server id 1 end_log_pos 119 CRC32 0x00000004 Write_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; @@ -29,34 +27,34 @@ ROLLBACK; Start of Multi-row Update UPDATE t1 SET f1 = f1 + 10; DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 73 Query thread_id= exec_time= error_code=0 -SET TIMESTAMP=/*!*/; -/*!\C latin1 *//*!*/; -BEGIN -/*!*/; -# at 193 - server id 1 end_log_pos 114 Table_map: `test`.`t1` mapped to number -# at 234 - server id 1 end_log_pos 156 Update_rows: table id flags: STMT_END_F +# at 256 +# at 301 + server id 1 end_log_pos 86 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 342 + server id 1 end_log_pos 126 CRC32 0x0000000b Update_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 197 Table_map: `test`.`t1` mapped to number -# at 161 - server id 1 end_log_pos 239 Update_rows: table id flags: STMT_END_F +# at 256 +# at 301 + server id 1 end_log_pos 212 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 342 + server id 1 end_log_pos 252 CRC32 0x0000000c Update_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 280 Table_map: `test`.`t1` mapped to number -# at 161 - server id 1 end_log_pos 322 Update_rows: table id flags: STMT_END_F +# at 256 +# at 301 + server id 1 end_log_pos 338 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 342 + server id 1 end_log_pos 378 CRC32 0x0000000d Update_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; @@ -67,73 +65,79 @@ ROLLBACK; Start of Multi-table Update UPDATE t1, t2 SET t1.f1 = t1.f1 + 100, t2.f1 = t2.f1 + 100; DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 82 Query thread_id= exec_time= error_code=0 -SET TIMESTAMP=/*!*/; -/*!\C latin1 *//*!*/; -BEGIN -/*!*/; -# at 202 - server id 1 end_log_pos 123 Table_map: `test`.`t1` mapped to number -# at 243 - server id 1 end_log_pos 164 Table_map: `test`.`t2` mapped to number -# at 284 - server id 1 end_log_pos 206 Update_rows: table id flags: STMT_END_F +# at 256 +# at 333 + server id 1 end_log_pos 118 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 374 + server id 1 end_log_pos 159 CRC32 0x00000301 Table_map: `test`.`t2` mapped to number +# at 415 + server id 1 end_log_pos 199 CRC32 0x00000065 Update_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 247 Table_map: `test`.`t1` mapped to number -# at 161 - server id 1 end_log_pos 288 Table_map: `test`.`t2` mapped to number -# at 202 - server id 1 end_log_pos 330 Update_rows: table id flags: STMT_END_F +# at 256 +# at 333 + server id 1 end_log_pos 317 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 374 + server id 1 end_log_pos 358 CRC32 0x00000301 Table_map: `test`.`t2` mapped to number +# at 415 + server id 1 end_log_pos 398 CRC32 0x00000066 Update_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 371 Table_map: `test`.`t1` mapped to number -# at 161 - server id 1 end_log_pos 412 Table_map: `test`.`t2` mapped to number -# at 202 - server id 1 end_log_pos 454 Update_rows: table id flags: STMT_END_F +# at 256 +# at 333 + server id 1 end_log_pos 516 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 374 + server id 1 end_log_pos 557 CRC32 0x00000301 Table_map: `test`.`t2` mapped to number +# at 415 + server id 1 end_log_pos 597 CRC32 0x00000067 Update_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 495 Table_map: `test`.`t1` mapped to number -# at 161 - server id 1 end_log_pos 536 Table_map: `test`.`t2` mapped to number -# at 202 - server id 1 end_log_pos 578 Update_rows: table id flags: STMT_END_F +# at 256 +# at 333 + server id 1 end_log_pos 715 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 374 + server id 1 end_log_pos 756 CRC32 0x00000301 Table_map: `test`.`t2` mapped to number +# at 415 + server id 1 end_log_pos 796 CRC32 0x00000065 Update_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 619 Table_map: `test`.`t1` mapped to number -# at 161 - server id 1 end_log_pos 660 Table_map: `test`.`t2` mapped to number -# at 202 - server id 1 end_log_pos 702 Update_rows: table id flags: STMT_END_F +# at 256 +# at 333 + server id 1 end_log_pos 914 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 374 + server id 1 end_log_pos 955 CRC32 0x00000301 Table_map: `test`.`t2` mapped to number +# at 415 + server id 1 end_log_pos 995 CRC32 0x00000066 Update_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 743 Table_map: `test`.`t1` mapped to number -# at 161 - server id 1 end_log_pos 784 Table_map: `test`.`t2` mapped to number -# at 202 - server id 1 end_log_pos 826 Update_rows: table id flags: STMT_END_F +# at 256 +# at 333 + server id 1 end_log_pos 1113 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 374 + server id 1 end_log_pos 1154 CRC32 0x00000301 Table_map: `test`.`t2` mapped to number +# at 415 + server id 1 end_log_pos 1194 CRC32 0x00000067 Update_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; @@ -147,47 +151,23 @@ SAVEPOINT X; INSERT INTO t1 VALUES (2000); ROLLBACK TO SAVEPOINT X; DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 73 Query thread_id= exec_time= error_code=0 -SET TIMESTAMP=/*!*/; -/*!\C latin1 *//*!*/; -BEGIN -/*!*/; -# at 193 - server id 1 end_log_pos 114 Table_map: `test`.`t1` mapped to number -# at 234 - server id 1 end_log_pos 150 Write_rows: table id flags: STMT_END_F +# at 256 +# at 303 + server id 1 end_log_pos 88 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 344 + server id 1 end_log_pos 122 CRC32 0x000003e8 Write_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 231 Query thread_id= exec_time= error_code=0 -SET TIMESTAMP=/*!*/; -/*!\C latin1 *//*!*/; -SAVEPOINT `X` -/*!*/; -DELIMITER ; -# End of log file -ROLLBACK /* added by mysqlbinlog */; -/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; -DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 272 Table_map: `test`.`t1` mapped to number -# at 161 - server id 1 end_log_pos 308 Write_rows: table id flags: STMT_END_F -DELIMITER ; -# End of log file -ROLLBACK /* added by mysqlbinlog */; -/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; -DELIMITER /*!*/; -# at 120 - server id 1 end_log_pos 391 Query thread_id= exec_time= error_code=0 -SET TIMESTAMP=/*!*/; -/*!\C latin1 *//*!*/; -ROLLBACK TO `X` -/*!*/; +# at 256 +# at 303 + server id 1 end_log_pos 210 CRC32 0x00000301 Table_map: `test`.`t1` mapped to number +# at 344 + server id 1 end_log_pos 244 CRC32 0x000007d0 Write_rows: table id flags: STMT_END_F +# Number of rows: 1 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; From b4c75f685b370c9ef6d91e1537bdec74f2bb69a0 Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Tue, 12 Feb 2019 15:58:06 +0200 Subject: [PATCH 02/19] MDEV-18480 Backwards compatibility in log_view() Galera versions below 4.x do not generate unique sequence number for view events. Take this into account when writing the SE checkpoint to avoid debug assertion in InnoDB. --- sql/wsrep_server_service.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sql/wsrep_server_service.cc b/sql/wsrep_server_service.cc index 7efff35f2b1..14b294c4214 100644 --- a/sql/wsrep_server_service.cc +++ b/sql/wsrep_server_service.cc @@ -176,10 +176,12 @@ void Wsrep_server_service::log_view( { Wsrep_id id; Wsrep_view prev_view= wsrep_schema->restore_view(applier->m_thd, id); + bool checkpoint_was_reset= false; if (prev_view.state_id().id() != view.state_id().id()) { WSREP_DEBUG("New cluster UUID was generated, resetting position info"); wsrep_set_SE_checkpoint(wsrep::gtid::undefined()); + checkpoint_was_reset= true; } if (wsrep_debug) @@ -188,7 +190,7 @@ void Wsrep_server_service::log_view( os << "Storing cluster view:\n" << view; WSREP_INFO("%s", os.str().c_str()); DBUG_ASSERT(prev_view.state_id().id() != view.state_id().id() || - view.state_id().seqno() > prev_view.state_id().seqno()); + view.state_id().seqno().get() >= prev_view.state_id().seqno().get()); } if (trans_begin(applier->m_thd, MYSQL_START_TRANS_OPT_READ_WRITE)) @@ -216,7 +218,21 @@ void Wsrep_server_service::log_view( applier->m_thd->mdl_context.release_transactional_locks(); } - wsrep_set_SE_checkpoint(view.state_id()); + /* + Backwards compatibility: When running in mixed cluster with + Galera 3.x, the provider does not generate unique sequence numbers + for views. This condition can be checked by inspecting last + committed as returned by the provider. If the last_committed + matches to view state_id seqno, the cluster runs in backwards + compatibility mode and we skip setting the checkpoint for + view. + */ + wsrep::seqno last_committed= + Wsrep_server_state::instance().provider().last_committed_gtid().seqno(); + if (checkpoint_was_reset || last_committed != view.state_id().seqno()) + { + wsrep_set_SE_checkpoint(view.state_id()); + } DBUG_ASSERT(wsrep_get_SE_checkpoint().id() == view.state_id().id()); } else From 3be9982f6a9f2bcd2e5ad00f403a4598ba5afb99 Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Thu, 14 Feb 2019 15:30:54 +0200 Subject: [PATCH 03/19] MDEV-18571 Fix wsrep PS protocol crash Calls to wsrep_after_statement() were missing on PS protocol codepath. Added calls after mysqld_stmt_execute() and mysqld_stmt_bulk_execute(). --- sql/sql_parse.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 25dfdbcbc71..57cec6bacff 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1729,11 +1729,23 @@ bool dispatch_command(enum enum_server_command command, THD *thd, case COM_STMT_BULK_EXECUTE: { mysqld_stmt_bulk_execute(thd, packet, packet_length); +#ifdef WITH_WSREP + if (WSREP_ON) + { + (void)wsrep_after_statement(thd); + } +#endif /* WITH_WSREP */ break; } case COM_STMT_EXECUTE: { mysqld_stmt_execute(thd, packet, packet_length); +#ifdef WITH_WSREP + if (WSREP_ON) + { + (void)wsrep_after_statement(thd); + } +#endif /* WITH_WSREP */ break; } case COM_STMT_FETCH: From 3220227794ab9b3f96f0038f72165c6f43242fe6 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sat, 16 Feb 2019 14:03:33 +0100 Subject: [PATCH 04/19] MDEV-18578 build aws sdk for all plugins to use --- CMakeLists.txt | 1 + aws_sdk/CMakeLists.txt | 74 +++++++++ cmake/aws_sdk.cmake | 91 ++++++++++++ plugin/aws_key_management/CMakeLists.txt | 182 ++--------------------- 4 files changed, 176 insertions(+), 172 deletions(-) create mode 100644 aws_sdk/CMakeLists.txt create mode 100644 cmake/aws_sdk.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b40a25e52cc..d1ed3f3e4de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -431,6 +431,7 @@ INCLUDE(cmake/tags.cmake) INCLUDE(for_clients) ADD_SUBDIRECTORY(scripts) ADD_SUBDIRECTORY(support-files) +ADD_SUBDIRECTORY(aws_sdk) IF(NOT CMAKE_CROSSCOMPILING) SET(EXPORTED comp_err comp_sql factorial) diff --git a/aws_sdk/CMakeLists.txt b/aws_sdk/CMakeLists.txt new file mode 100644 index 00000000000..85a196dccce --- /dev/null +++ b/aws_sdk/CMakeLists.txt @@ -0,0 +1,74 @@ +OPTION(AWS_SDK_EXTERNAL_PROJECT "Allow to download and build AWS C++ SDK" OFF) +INCLUDE(aws_sdk) +INCLUDE(ExternalProject) + +GET_PROPERTY(SDK_LIBS GLOBAL PROPERTY AWS_SDK_LIBS) +LIST(LENGTH SDK_LIBS SDK_LIBS_COUNT) +IF(SDK_LIBS_COUNT EQUAL 0) + RETURN() +ENDIF() + +CHECK_AWS_SDK(RETVAL REASON) +IF(NOT RETVAL) + MESSAGE(FATAL_ERROR + "AWS C++ will not be built (${REASON}), but dependency on following components is found ${SDK_LIBS}. + Use CHECK_AWS_SDK() function before trying to build with SDK components") +ENDIF() + + +SET(byproducts) + +FOREACH(lib ${SDK_LIBS} core) + SET(lib aws-cpp-sdk-${lib}) + ADD_LIBRARY(${lib} STATIC IMPORTED GLOBAL) + ADD_DEPENDENCIES(${lib} aws_sdk_cpp) + + SET (loc "${CMAKE_CURRENT_BINARY_DIR}/aws_sdk_cpp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX}") + IF(CMAKE_VERSION VERSION_GREATER "3.1") + SET(byproducts ${byproducts} BUILD_BYPRODUCTS ${loc}) + ENDIF() + SET_TARGET_PROPERTIES(${lib} PROPERTIES IMPORTED_LOCATION ${loc}) +ENDFOREACH() + +# To be compatible with older cmake, we use older version of the SDK +IF(CMAKE_VERSION LESS "3.0") + SET(GIT_TAG "1.0.8") +ELSE() + SET(GIT_TAG "1.2.11") +ENDIF() + +IF(MSVC_CRT_TYPE MATCHES "/MD") + SET(FORCE_SHARED_CRT ON) +ELSE() + SET(FORCE_SHARED_CRT OFF) +ENDIF() + +LIST(REMOVE_DUPLICATES SDK_LIBS) +STRING( REPLACE ";" "!" SDK_LIBS_STR "${SDK_LIBS}") +#MESSAGE("SDK_LIBS_STR=${SDK_LIBS_STR}") + +ExternalProject_Add( + aws_sdk_cpp + GIT_REPOSITORY "https://github.com/awslabs/aws-sdk-cpp.git" + GIT_TAG ${GIT_TAG} + UPDATE_COMMAND "" + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/aws-sdk-cpp" + LIST_SEPARATOR ! + ${byproducts} + CMAKE_ARGS + -DBUILD_ONLY=${SDK_LIBS_STR} + -DBUILD_SHARED_LIBS=OFF + -DFORCE_SHARED_CRT=${FORCE_SHARED_CRT} + -DENABLE_TESTING=OFF + "-DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} ${PIC_FLAG}" + "-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${PIC_FLAG}" + "-DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE} ${PIC_FLAG}" + "-DCMAKE_CXX_FLAGS_MINSIZEREL=${CMAKE_CXX_FLAGS_MINSIZEREL} ${PIC_FLAG}" + "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + ${EXTRA_SDK_CMAKE_FLAGS} + -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/aws_sdk_cpp + -DCMAKE_INSTALL_LIBDIR=lib + TEST_COMMAND "" +) +SET_TARGET_PROPERTIES(aws_sdk_cpp PROPERTIES EXCLUDE_FROM_ALL TRUE) diff --git a/cmake/aws_sdk.cmake b/cmake/aws_sdk.cmake new file mode 100644 index 00000000000..975a3fa6888 --- /dev/null +++ b/cmake/aws_sdk.cmake @@ -0,0 +1,91 @@ +MACRO (SKIP_AWS_SDK MSG) + SET(${RETVAL} OFF PARENT_SCOPE) + SET(${REASON} ${MSG} PARENT_SCOPE) + RETURN() +ENDMACRO() + +FUNCTION (CHECK_AWS_SDK RETVAL REASON) + # AWS_SDK_EXTERNAL_PROJECT must be ON + IF(NOT AWS_SDK_EXTERNAL_PROJECT) + SKIP_AWS_SDK("AWS_SDK_EXTERNAL_PROJECT is not ON") + ENDIF() + # Check compiler support + IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) + IF (GCC_VERSION VERSION_LESS 4.8) + SKIP_AWS_SDK("GCC VERSION too old (${GCC_VERSION}, required is 4.8 or later") + ENDIF() + ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + IF ((CMAKE_CXX_COMPILER_VERSION AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3) OR + (CLANG_VERSION_STRING AND CLANG_VERSION_STRING VERSION_LESS 3.3)) + SKIP_AWS_SDK("Clang version too old, required is 3.3 or later") + ENDIF() + ELSEIF(MSVC) + IF (MSVC_VERSION LESS 1800) + SKIP_AWS_SDK("MSVC version too old, required is VS2015 or later") + ENDIF() + ELSE() + SKIP_AWS_SDK("Unsupported compiler") + ENDIF() + + # Check OS support + IF (NOT(WIN32 OR APPLE OR (CMAKE_SYSTEM_NAME MATCHES "Linux"))) + SKIP_AWS_SDK("OS unsupported by AWS SDK") + ENDIF() + + # Build from source, using ExternalProject_Add + # AWS C++ SDK requires cmake 2.8.12 + IF(CMAKE_VERSION VERSION_LESS "2.8.12") + SKIP_AWS_SDK("CMake is too old") + ENDIF() + + IF(UNIX) + # Check librairies required for building SDK + FIND_PACKAGE(CURL) + IF(NOT CURL_FOUND) + SKIP_AWS_SDK("AWS C++ SDK requires libcurl development package") + ENDIF() + FIND_PATH(UUID_INCLUDE_DIR uuid/uuid.h) + IF(NOT UUID_INCLUDE_DIR) + SKIP_AWS_SDK("AWS C++ SDK requires uuid development package") + ENDIF() + IF(NOT APPLE) + FIND_LIBRARY(UUID_LIBRARIES uuid) + IF(NOT UUID_LIBRARIES) + SKIP_AWS_SDK("AWS C++ SDK requires uuid development package") + ENDIF() + FIND_PACKAGE(OpenSSL) + IF(NOT OPENSSL_FOUND) + SKIP_AWS_SDK("AWS C++ SDK requires openssl development package") + ENDIF() + ENDIF() + ENDIF() + SET(${RETVAL} ON PARENT_SCOPE) +ENDFUNCTION() + + +# USE_AWS_SDK_LIBS(target sdk_component1 ... sdk_component_N) +# Example usage +# USE_AWS_SDK_LIBS(aws_key_management kms s3) +FUNCTION(USE_AWS_SDK_LIBS) + SET(SDK_COMPONENTS ${ARGN}) + LIST(GET SDK_COMPONENTS 0 target) + IF(NOT TARGET ${target}) + MESSAGE(FATAL_ERROR "${target} is not a valid target") + ENDIF() + LIST(REMOVE_AT SDK_COMPONENTS 0) + FOREACH(comp ${SDK_COMPONENTS}) + SET_PROPERTY(GLOBAL PROPERTY AWS_SDK_LIBS ${comp} APPEND) + TARGET_LINK_LIBRARIES(${target} aws-cpp-sdk-${comp}) + ENDFOREACH() + TARGET_LINK_LIBRARIES(${target} aws-cpp-sdk-core) + TARGET_INCLUDE_DIRECTORIES(${target} PRIVATE ${PROJECT_BINARY_DIR}/aws_sdk/aws_sdk_cpp/include) + # Link OS libraries that AWS SDK depends on + IF(WIN32) + TARGET_LINK_LIBRARIES(${target} bcrypt winhttp wininet userenv version) + ELSE() + FIND_PACKAGE(CURL REQUIRED) + FIND_PACKAGE(OpenSSL REQUIRED) + TARGET_LINK_LIBRARIES(${target} ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES} ${UUID_LIBRARIES}) + ENDIF() +ENDFUNCTION() diff --git a/plugin/aws_key_management/CMakeLists.txt b/plugin/aws_key_management/CMakeLists.txt index 4620290000e..b6f48cd18a0 100644 --- a/plugin/aws_key_management/CMakeLists.txt +++ b/plugin/aws_key_management/CMakeLists.txt @@ -1,176 +1,14 @@ -# We build parts of AWS C++ SDK as CMake external project -# The restrictions of the SDK (https://github.com/awslabs/aws-sdk-cpp/blob/master/README.md) -# are - -# - OS : Windows,Linux or OSX -# - C++11 compiler : VS2013+, gcc 4.8+, clang 3.3+ -# - libcurl development package needs to be present on Unixes -# -# If we build SDK outselves, we'll need require GIT to be present on the build machine - - -# Give message why the building this plugin is skipped (only if -DVERBOSE is defined) -# or if plugin is explicitly requested to build. Then bail out. -MACRO(SKIP_AWS_PLUGIN msg) - MESSAGE_ONCE(SKIP_AWS_PLUGIN "Skip aws_key_management - ${msg}") +INCLUDE(aws_sdk) +CHECK_AWS_SDK(HAVE_AWS_SDK REASON) +IF(NOT HAVE_AWS_SDK) + MESSAGE_ONCE(AWS_KEY_MANAGEMENT_NO_AWS_SDK "Can't build aws_key_management - AWS SDK not available (${REASON})") RETURN() -ENDMACRO() -SET(CMAKE_CXX_STANDARD 11) - - - -# This plugin needs recent C++ compilers (AWS C++ SDK header files are using C++11 features) -SET(CXX11_FLAGS) -SET(OLD_COMPILER_MSG "AWS SDK requires c++11 -capable compiler (minimal supported versions are g++ 4.8, clang 3.3, VS2103)") - -IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) - IF (GCC_VERSION VERSION_LESS 4.8) - SKIP_AWS_PLUGIN("${OLD_COMPILER_MSG}") - ENDIF() - SET(CXX11_FLAGS "-std=c++11") -ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - IF ((CMAKE_CXX_COMPILER_VERSION AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3) OR - (CLANG_VERSION_STRING AND CLANG_VERSION_STRING VERSION_LESS 3.3)) - SKIP_AWS_PLUGIN("${OLD_COMPILER_MSG}") - ENDIF() - SET(CXX11_FLAGS "-stdlib=libc++") -ELSEIF(MSVC) - IF (MSVC_VERSION LESS 1800) - SKIP_AWS_PLUGIN("${OLD_COMPILER_MSG}") - ENDIF() -ELSE() - SKIP_AWS_PLUGIN("Compiler not supported by AWS C++ SDK") ENDIF() -IF (NOT(WIN32 OR APPLE OR (CMAKE_SYSTEM_NAME MATCHES "Linux"))) - SKIP_AWS_PLUGIN("OS unsupported by AWS SDK") -ENDIF() - - - -FIND_LIBRARY(AWS_CPP_SDK_CORE NAMES aws-cpp-sdk-core PATH_SUFFIXES "${SDK_INSTALL_BINARY_PREFIX}") -FIND_LIBRARY(AWS_CPP_SDK_KMS NAMES aws-cpp-sdk-kms PATH_SUFFIXES "${SDK_INSTALL_BINARY_PREFIX}") -FIND_PATH(AWS_CPP_SDK_INCLUDE_DIR NAMES aws/kms/KMSClient.h) - -IF(AWS_CPP_SDK_CORE AND AWS_CPP_SDK_KMS AND AWS_CPP_SDK_INCLUDE_DIR) - # AWS C++ SDK installed - INCLUDE_DIRECTORIES(${AWS_CPP_SDK_INCLUDE_DIR}) - SET(AWS_SDK_LIBS ${AWS_CPP_SDK_CORE} ${AWS_CPP_SDK_KMS}) -ELSE() - OPTION(AWS_SDK_EXTERNAL_PROJECT "Allow download and build AWS C++ SDK" OFF) - IF(NOT AWS_SDK_EXTERNAL_PROJECT) - SKIP_AWS_PLUGIN("AWS_SDK_EXTERNAL_PROJECT is not set") - ENDIF() - # Build from source, using ExternalProject_Add - # AWS C++ SDK requires cmake 2.8.12 - IF(CMAKE_VERSION VERSION_LESS "2.8.12") - SKIP_AWS_PLUGIN("CMake is too old") - ENDIF() - FIND_PACKAGE(Git) - IF(NOT GIT_FOUND) - SKIP_AWS_PLUGIN("no GIT") - ENDIF() - INCLUDE(ExternalProject) - IF(UNIX) - FIND_PACKAGE(CURL) - IF(NOT CURL_FOUND) - SKIP_AWS_PLUGIN("AWS C++ SDK requires libcurl development package") - ENDIF() - SET(PIC_FLAG -fPIC) - FIND_PATH(UUID_INCLUDE_DIR uuid/uuid.h) - IF(NOT UUID_INCLUDE_DIR) - SKIP_AWS_PLUGIN("AWS C++ SDK requires uuid development package") - ENDIF() - IF(NOT APPLE) - FIND_LIBRARY(UUID_LIBRARIES uuid) - IF(NOT UUID_LIBRARIES) - SKIP_AWS_PLUGIN("AWS C++ SDK requires uuid development package") - ENDIF() - FIND_PACKAGE(OpenSSL) - IF(NOT OPENSSL_FOUND) - SKIP_AWS_PLUGIN("AWS C++ SDK requires openssl development package") - ENDIF() - ENDIF() - ENDIF() - IF(MSVC) - SET(EXTRA_SDK_CMAKE_FLAGS -DCMAKE_CXX_FLAGS_DEBUGOPT="" -DCMAKE_EXE_LINKER_FLAGS_DEBUGOPT="" "-DCMAKE_CXX_FLAGS=/wd4530 /wd4577 /WX-") - ENDIF() - IF(CMAKE_CXX_COMPILER) - SET(EXTRA_SDK_CMAKE_FLAGS ${EXTRA_SDK_CMAKE_FLAGS} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}) - ENDIF() - - SET(byproducts ) - # We do not need to build the whole SDK , just 2 of its libs - set(AWS_SDK_LIBS aws-cpp-sdk-core aws-cpp-sdk-kms) - FOREACH(lib ${AWS_SDK_LIBS}) - ADD_LIBRARY(${lib} STATIC IMPORTED GLOBAL) - ADD_DEPENDENCIES(${lib} aws_sdk_cpp) - SET(loc "${CMAKE_CURRENT_BINARY_DIR}/aws_sdk_cpp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX}") - IF(CMAKE_VERSION VERSION_GREATER "3.1") - SET(byproducts ${byproducts} BUILD_BYPRODUCTS ${loc}) - ENDIF() - SET_TARGET_PROPERTIES(${lib} PROPERTIES IMPORTED_LOCATION ${loc}) - ENDFOREACH() - - # To be compatible with older cmake, we use older version of the SDK - IF(CMAKE_VERSION LESS "3.0") - SET(GIT_TAG "1.0.8") - ELSE() - SET(GIT_TAG "1.2.11") - ENDIF() - - IF(MSVC_CRT_TYPE MATCHES "/MD") - SET(FORCE_SHARED_CRT ON) - ELSE() - SET(FORCE_SHARED_CRT OFF) - ENDIF() - - SET(AWS_SDK_PATCH_COMMAND ) - ExternalProject_Add( - aws_sdk_cpp - GIT_REPOSITORY "https://github.com/awslabs/aws-sdk-cpp.git" - GIT_TAG ${GIT_TAG} - UPDATE_COMMAND "" - SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/aws-sdk-cpp" - ${byproducts} - CMAKE_ARGS - -DBUILD_ONLY=kms - -DBUILD_SHARED_LIBS=OFF - -DFORCE_SHARED_CRT=${FORCE_SHARED_CRT} - -DENABLE_TESTING=OFF - "-DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} ${PIC_FLAG}" - "-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${PIC_FLAG}" - "-DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE} ${PIC_FLAG}" - "-DCMAKE_CXX_FLAGS_MINSIZEREL=${CMAKE_CXX_FLAGS_MINSIZEREL} ${PIC_FLAG}" - ${EXTRA_SDK_CMAKE_FLAGS} - -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/aws_sdk_cpp - -DCMAKE_INSTALL_LIBDIR=lib - TEST_COMMAND "" - ) - SET_TARGET_PROPERTIES(aws_sdk_cpp PROPERTIES EXCLUDE_FROM_ALL TRUE) - - IF(CMAKE_SYSTEM_NAME MATCHES "Linux") - # Need whole-archive , otherwise static libraries are not linked - SET(AWS_SDK_LIBS -Wl,--whole-archive ${AWS_SDK_LIBS} -Wl,--no-whole-archive) - ENDIF() - SET_TARGET_PROPERTIES(aws_sdk_cpp PROPERTIES EXCLUDE_FROM_ALL TRUE) - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/aws_sdk_cpp/include) -ENDIF() - -ADD_DEFINITIONS(${SSL_DEFINES}) # Need to know whether openssl should be initialized -IF(CMAKE_VERSION GREATER "3.0") - SET(CMAKE_CXX_STANDARD 11) -ELSE() - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS}") -ENDIF() -IF(WIN32) - SET(AWS_CPP_SDK_DEPENDENCIES bcrypt winhttp wininet userenv version) -ELSE() - SET(AWS_CPP_SDK_DEPENDENCIES ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES} ${UUID_LIBRARIES}) -ENDIF() -MYSQL_ADD_PLUGIN(aws_key_management aws_key_management_plugin.cc - LINK_LIBRARIES ${AWS_SDK_LIBS} ${AWS_CPP_SDK_DEPENDENCIES} - COMPONENT aws-key-management) - +MYSQL_ADD_PLUGIN(aws_key_management + aws_key_management_plugin.cc + COMPONENT aws-key-management) +IF(TARGET aws_key_management) + USE_AWS_SDK_LIBS(aws_key_management kms) +ENDIF() \ No newline at end of file From 54ffc4996a6b9ffd400177864c0b33b49b0c4bcf Mon Sep 17 00:00:00 2001 From: mkaruza Date: Fri, 15 Feb 2019 11:31:29 +0100 Subject: [PATCH 05/19] MDEV-18588 Segfault during SST on joiner with bin-log, no bin-log-index When node is JOINER and bin-log is enabled but bin-log-index is not set in configuration, we use NULL pointer which causes segfault. Fixed by checking for NULL pointer before using variable. --- sql/wsrep_sst.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/wsrep_sst.cc b/sql/wsrep_sst.cc index 103afa1c412..d79b7771571 100644 --- a/sql/wsrep_sst.cc +++ b/sql/wsrep_sst.cc @@ -337,7 +337,7 @@ static int generate_binlog_index_opt_val(char** ret) { DBUG_ASSERT(ret); *ret= NULL; - if (opt_bin_log) + if (opt_binlog_index_name) { *ret= strcmp(opt_binlog_index_name, "0") ? my_strdup(opt_binlog_index_name, MYF(0)) : my_strdup("", MYF(0)); From 2bd7f3298089c04a0ad5e7cad06c2a34e239a410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 18 Feb 2019 09:00:02 +0200 Subject: [PATCH 06/19] MDEV-16188: Remove redundant !this || Fix clang warning: 'this' pointer cannot be null in well-defined C++ code; pointer may be assumed to always convert to true The only caller of TABLE::best_range_rowid_filter_for_partial_join() already seems to be assuming that s->table != NULL. --- sql/rowid_filter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/rowid_filter.cc b/sql/rowid_filter.cc index d6ea22c1704..7e7447d4c37 100644 --- a/sql/rowid_filter.cc +++ b/sql/rowid_filter.cc @@ -434,7 +434,7 @@ TABLE::best_range_rowid_filter_for_partial_join(uint access_key_no, double records, double access_cost_factor) { - if (!this || range_rowid_filter_cost_info_elems == 0 || + if (range_rowid_filter_cost_info_elems == 0 || covering_keys.is_set(access_key_no)) return 0; From 869ce67f595879ef9584adbd4067074b98ab0829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 18 Feb 2019 09:33:24 +0200 Subject: [PATCH 07/19] Disable unused function --- sql/wsrep_var.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/wsrep_var.cc b/sql/wsrep_var.cc index 7ba4ed3c14c..d091348f481 100644 --- a/sql/wsrep_var.cc +++ b/sql/wsrep_var.cc @@ -757,7 +757,7 @@ static int show_var_cmp(const void *var1, const void *var2) { return strcasecmp(((SHOW_VAR*)var1)->name, ((SHOW_VAR*)var2)->name); } -#endif /* UNUSED */ + /* * Status variables stuff below */ @@ -780,6 +780,7 @@ wsrep_assign_to_mysql (SHOW_VAR* mysql, wsrep_stats_var* wsrep_var) break; } } +#endif /* UNUSED */ #if DYNAMIC // somehow this mysql status thing works only with statically allocated arrays. From a12d0d5a56ab2a6474170d244e487fab2a224eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 18 Feb 2019 09:48:13 +0200 Subject: [PATCH 08/19] MDEV-18609 Assertion !is_string || (*af)->charset() == cf->charset failed The Create_field::charset can contain garbage for columns that the SQL layer does not consider as being string columns. InnoDB considers BIT a string column for historical reasons (and backward compatibility with old persistent InnoDB metadata), and therefore it checked the charset. The Field::charset() consistently is my_charset_bin for BIT, so we can trust that one. --- .../suite/innodb/r/instant_alter.result | 36 +++++++++++++++++++ mysql-test/suite/innodb/t/instant_alter.test | 9 +++++ storage/innobase/handler/handler0alter.cc | 10 ++---- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/mysql-test/suite/innodb/r/instant_alter.result b/mysql-test/suite/innodb/r/instant_alter.result index 448f5c668e2..d6fd90ec27f 100644 --- a/mysql-test/suite/innodb/r/instant_alter.result +++ b/mysql-test/suite/innodb/r/instant_alter.result @@ -779,10 +779,22 @@ DELETE FROM t1 LIMIT 3; ALTER TABLE t1 MODIFY f BIT(15); affected rows: 1 info: Records: 1 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 MODIFY f BIT(8); +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 SELECT HEX(f) FROM t1; HEX(f) 80 DROP TABLE t1; +CREATE TABLE t1 (b BIT NOT NULL) ENGINE=InnoDB ROW_FORMAT=REDUNDANT DEFAULT CHARSET utf16; +INSERT INTO t1 SET b=b'1'; +ALTER TABLE t1 CHANGE b c BIT NOT NULL; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +SELECT HEX(c) FROM t1; +HEX(c) +1 +DROP TABLE t1; CREATE TABLE t1 (id INT PRIMARY KEY, c2 INT UNIQUE, c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'), @@ -1508,10 +1520,22 @@ DELETE FROM t1 LIMIT 3; ALTER TABLE t1 MODIFY f BIT(15); affected rows: 1 info: Records: 1 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 MODIFY f BIT(8); +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 SELECT HEX(f) FROM t1; HEX(f) 80 DROP TABLE t1; +CREATE TABLE t1 (b BIT NOT NULL) ENGINE=InnoDB ROW_FORMAT=COMPACT DEFAULT CHARSET utf16; +INSERT INTO t1 SET b=b'1'; +ALTER TABLE t1 CHANGE b c BIT NOT NULL; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +SELECT HEX(c) FROM t1; +HEX(c) +1 +DROP TABLE t1; CREATE TABLE t1 (id INT PRIMARY KEY, c2 INT UNIQUE, c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'), @@ -2237,10 +2261,22 @@ DELETE FROM t1 LIMIT 3; ALTER TABLE t1 MODIFY f BIT(15); affected rows: 1 info: Records: 1 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 MODIFY f BIT(8); +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 SELECT HEX(f) FROM t1; HEX(f) 80 DROP TABLE t1; +CREATE TABLE t1 (b BIT NOT NULL) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET utf16; +INSERT INTO t1 SET b=b'1'; +ALTER TABLE t1 CHANGE b c BIT NOT NULL; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +SELECT HEX(c) FROM t1; +HEX(c) +1 +DROP TABLE t1; disconnect analyze; SELECT variable_value-@old_instant instants FROM information_schema.global_status diff --git a/mysql-test/suite/innodb/t/instant_alter.test b/mysql-test/suite/innodb/t/instant_alter.test index d662277b8e3..013b2483f54 100644 --- a/mysql-test/suite/innodb/t/instant_alter.test +++ b/mysql-test/suite/innodb/t/instant_alter.test @@ -668,10 +668,19 @@ ALTER TABLE t1 MODIFY f BIT(15); DELETE FROM t1 LIMIT 3; --enable_info ALTER TABLE t1 MODIFY f BIT(15); +ALTER TABLE t1 MODIFY f BIT(8); --disable_info SELECT HEX(f) FROM t1; DROP TABLE t1; +eval CREATE TABLE t1 (b BIT NOT NULL) $engine DEFAULT CHARSET utf16; +INSERT INTO t1 SET b=b'1'; +--enable_info +ALTER TABLE t1 CHANGE b c BIT NOT NULL; +--disable_info +SELECT HEX(c) FROM t1; +DROP TABLE t1; + dec $format; } disconnect analyze; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index a02163fd986..771d9bd18b5 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -9016,7 +9016,6 @@ static void get_type(const Field& f, ulint& prtype, ulint& mtype, ulint& len) @param table_name Table name in MySQL @param pos 0-based index to user_table->cols[] or user_table->v_cols[] @param f new column -@param cf column modification @param is_v if it's a virtual column @retval true Failure @retval false Success */ @@ -9028,7 +9027,6 @@ innobase_rename_or_enlarge_column_try( const char* table_name, ulint pos, const Field& f, - const Create_field& cf, bool is_v) { dict_col_t* col; @@ -9052,7 +9050,7 @@ innobase_rename_or_enlarge_column_try( ulint prtype, mtype, len; get_type(f, prtype, mtype, len); DBUG_ASSERT(!dtype_is_string_type(col->mtype) - || col->mbminlen == cf.charset->mbminlen); + || col->mbminlen == f.charset()->mbminlen); DBUG_ASSERT(col->len <= len); #ifdef UNIV_DEBUG @@ -9152,7 +9150,7 @@ innobase_rename_or_enlarge_columns_try( if (cf->field == *fp) { if (innobase_rename_or_enlarge_column_try( ctx->old_table, trx, table_name, - idx, **af, *cf, is_v)) { + idx, **af, is_v)) { DBUG_RETURN(true); } break; @@ -9208,8 +9206,6 @@ innobase_rename_or_enlarge_columns_cache( ->m_col : dict_table_get_nth_col(user_table, col_n); const bool is_string= dtype_is_string_type(col->mtype); - DBUG_ASSERT(!is_string - || (*af)->charset() == cf->charset); DBUG_ASSERT(col->mbminlen == (is_string ? (*af)->charset()->mbminlen : 0)); @@ -9227,7 +9223,7 @@ innobase_rename_or_enlarge_columns_cache( dict_mem_table_col_rename( user_table, col_n, cf->field->field_name.str, - cf->field_name.str, is_virtual); + (*af)->field_name.str, is_virtual); } break; From 19c6a7bbd75d8a72716ecba3aa32d4e9f13daebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 18 Feb 2019 09:52:08 +0200 Subject: [PATCH 09/19] MDEV-15564: Fix a memory leak --- storage/innobase/handler/handler0alter.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 771d9bd18b5..b0f87fdae9e 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -8748,7 +8748,6 @@ innobase_rename_column_try( const char* to, bool new_clustered) { - pars_info_t* info; dberr_t error; DBUG_ENTER("innobase_rename_column_try"); @@ -8762,7 +8761,6 @@ innobase_rename_column_try( goto rename_foreign; } - info = pars_info_create(); error = DB_SUCCESS; trx->op_info = "renaming column in SYS_FIELDS"; @@ -8789,8 +8787,7 @@ innobase_rename_column_try( continue; } - info = pars_info_create(); - + pars_info_t* info = pars_info_create(); ulint pos = has_prefixes ? i << 16 | f.prefix_len : i; pars_info_add_ull_literal(info, "indexid", index->id); @@ -8843,7 +8840,7 @@ rename_foreign: continue; } - info = pars_info_create(); + pars_info_t* info = pars_info_create(); pars_info_add_str_literal(info, "id", foreign->id); pars_info_add_int4_literal(info, "nth", i); @@ -8885,7 +8882,7 @@ rename_foreign: continue; } - info = pars_info_create(); + pars_info_t* info = pars_info_create(); pars_info_add_str_literal(info, "id", foreign->id); pars_info_add_int4_literal(info, "nth", i); From 15a77a1a2ce2d9608101e8f440580c23d9508c54 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sun, 17 Feb 2019 22:46:10 +0300 Subject: [PATCH 10/19] MDEV-18608: Defaults for 10.4: histogram size should be set Change the defaults: -histogram_size=0 +histogram_size=254 -histogram_type=SINGLE_PREC_HB +histogram_type=DOUBLE_PREC_HB Adjust the testcases: - Some have ignorable changes in EXPLAIN outputs and more counter increments due to EITS table reads. - Testcases that meaningfully depend on the old defaults are changed to use the old values. --- mysql-test/main/derived_cond_pushdown.result | 8 +-- mysql-test/main/group_min_max.result | 12 ++-- mysql-test/main/join.result | 2 +- mysql-test/main/join_outer.result | 8 +-- mysql-test/main/join_outer_jcl6.result | 8 +-- mysql-test/main/mysqld--help.result | 4 +- mysql-test/main/opt_trace.result | 14 ++--- mysql-test/main/order_by.result | 6 +- mysql-test/main/order_by.test | 6 +- mysql-test/main/partition.result | 4 +- .../main/partition_explicit_prune.result | 2 +- mysql-test/main/selectivity.result | 6 +- mysql-test/main/selectivity.test | 2 + mysql-test/main/selectivity_innodb.result | 6 +- mysql-test/main/stat_tables.result | 3 + mysql-test/main/stat_tables.test | 3 + mysql-test/main/stat_tables_innodb.result | 3 + mysql-test/main/statistics.result | 15 +++-- mysql-test/main/statistics.test | 17 +++--- mysql-test/main/subselect_mat.result | 24 ++++---- mysql-test/main/subselect_sj_mat.result | 60 +++++++++---------- .../sys_vars/r/histogram_size_basic.result | 12 ++-- .../sys_vars/r/histogram_type_basic.result | 10 ++-- .../r/sysvars_server_notembedded.result | 12 ++-- sql/sys_vars.cc | 4 +- 25 files changed, 136 insertions(+), 115 deletions(-) diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index 473415ac099..52143f8e6c1 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -15734,7 +15734,7 @@ explain extended select t2.a,t2.b,t2.c,t.c as t_c,t.max,t.min from t2, t3, (select c, max(b) max, min(b) min from t4 group by c) t where t2.b < 40 and t2.a=t3.a and t3.c=t.c; id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 90 33.33 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 90 63.28 Using where 1 PRIMARY t3 ref idx_a idx_a 5 test.t2.a 1 100.00 Using where 1 PRIMARY ref key0 key0 128 test.t3.c 10 100.00 2 DERIVED t4 ALL idx_c NULL NULL NULL 160 100.00 Using temporary; Using filesort @@ -15751,7 +15751,7 @@ EXPLAIN "table_name": "t2", "access_type": "ALL", "rows": 90, - "filtered": 33.333, + "filtered": 63.281, "attached_condition": "t2.b < 40 and t2.a is not null" }, "table": { @@ -16230,7 +16230,7 @@ explain extended select * from t2, t3, (select c, b, sum(b) over (partition by c) from t4 ) t where t2.b < 40 and t2.a=t3.a and t3.c=t.c; id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 90 33.33 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 90 63.28 Using where 1 PRIMARY t3 ref idx_a idx_a 5 test.t2.a 1 100.00 Using where 1 PRIMARY ref key0 key0 128 test.t3.c 10 100.00 2 DERIVED t4 ALL idx_c NULL NULL NULL 160 100.00 Using temporary @@ -16247,7 +16247,7 @@ EXPLAIN "table_name": "t2", "access_type": "ALL", "rows": 90, - "filtered": 33.333, + "filtered": 63.281, "attached_condition": "t2.b < 40 and t2.a is not null" }, "table": { diff --git a/mysql-test/main/group_min_max.result b/mysql-test/main/group_min_max.result index 7a49dbdf3f8..9f94b7897d7 100644 --- a/mysql-test/main/group_min_max.result +++ b/mysql-test/main/group_min_max.result @@ -1716,7 +1716,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 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 index NULL idx_t1_1 163 NULL 128 0.39 Using where; Using index +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 0.38 Using where; Using index 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'); @@ -1733,7 +1733,7 @@ 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 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 index NULL idx_t2_1 163 NULL 164 0.28 Using where; Using index +1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 0.30 Using where; Using index 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'); @@ -2078,19 +2078,19 @@ id select_type table type possible_keys key key_len ref rows Extra 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 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 77 100.00 Using where; Using index +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 77 99.22 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 ALL idx_t1_0,idx_t1_1,idx_t1_2 NULL NULL NULL 128 40.10 Using where; Using temporary; Using filesort +1 SIMPLE t1 ALL idx_t1_0,idx_t1_1,idx_t1_2 NULL NULL NULL 128 45.12 Using where; Using temporary; Using filesort 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 ALL idx_t1_0,idx_t1_1,idx_t1_2 NULL NULL NULL 128 40.10 Using where; Using temporary; Using filesort +1 SIMPLE t1 ALL idx_t1_0,idx_t1_1,idx_t1_2 NULL NULL NULL 128 45.12 Using where; Using temporary; Using filesort 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; @@ -2098,7 +2098,7 @@ id select_type table type possible_keys key key_len ref rows Extra 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 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 77 100.00 Using where; Using index +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 77 99.22 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; diff --git a/mysql-test/main/join.result b/mysql-test/main/join.result index 54da744e1fd..47c3e78116f 100644 --- a/mysql-test/main/join.result +++ b/mysql-test/main/join.result @@ -1280,7 +1280,7 @@ pk v pk v SHOW STATUS LIKE 'Handler_read_%'; Variable_name Value Handler_read_first 0 -Handler_read_key 11 +Handler_read_key 14 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 diff --git a/mysql-test/main/join_outer.result b/mysql-test/main/join_outer.result index 6e59d8845a8..05991b56aba 100644 --- a/mysql-test/main/join_outer.result +++ b/mysql-test/main/join_outer.result @@ -1803,7 +1803,7 @@ sum(t3.b) show status like "handler_read%"; Variable_name Value Handler_read_first 0 -Handler_read_key 10 +Handler_read_key 13 Handler_read_last 0 Handler_read_next 5 Handler_read_prev 0 @@ -1818,7 +1818,7 @@ sum(t3.b) show status like "handler_read%"; Variable_name Value Handler_read_first 0 -Handler_read_key 6 +Handler_read_key 7 Handler_read_last 0 Handler_read_next 5 Handler_read_prev 0 @@ -2552,7 +2552,7 @@ test.t3 analyze status OK explain extended select * from t1 left join t3 on t1.a=t3.b and t3.a<5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 -1 SIMPLE t3 ALL NULL NULL NULL NULL 1000 0.99 Using where +1 SIMPLE t3 ALL NULL NULL NULL NULL 1000 1.96 Using where Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` left join `test`.`t3` on(`test`.`t3`.`b` = `test`.`t1`.`a` and `test`.`t3`.`a` < 5) where 1 # t3.filtered must less than 100%, too: @@ -2560,7 +2560,7 @@ explain extended select * from t1 left join (t3 join t2) on t1.a=t3.b and t3.a<5 id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 -1 SIMPLE t3 ALL NULL NULL NULL NULL 1000 0.99 Using where +1 SIMPLE t3 ALL NULL NULL NULL NULL 1000 1.96 Using where Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` left join (`test`.`t3` join `test`.`t2`) on(`test`.`t3`.`b` = `test`.`t1`.`a` and `test`.`t3`.`a` < 5) where 1 drop table t1,t2,t3; diff --git a/mysql-test/main/join_outer_jcl6.result b/mysql-test/main/join_outer_jcl6.result index 0b8c9fa93a5..399d6306fa0 100644 --- a/mysql-test/main/join_outer_jcl6.result +++ b/mysql-test/main/join_outer_jcl6.result @@ -1814,7 +1814,7 @@ sum(t3.b) show status like "handler_read%"; Variable_name Value Handler_read_first 0 -Handler_read_key 10 +Handler_read_key 13 Handler_read_last 0 Handler_read_next 5 Handler_read_prev 0 @@ -1829,7 +1829,7 @@ sum(t3.b) show status like "handler_read%"; Variable_name Value Handler_read_first 0 -Handler_read_key 6 +Handler_read_key 7 Handler_read_last 0 Handler_read_next 5 Handler_read_prev 0 @@ -2563,7 +2563,7 @@ test.t3 analyze status OK explain extended select * from t1 left join t3 on t1.a=t3.b and t3.a<5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 -1 SIMPLE t3 hash_ALL NULL #hash#$hj 5 test.t1.a 1000 0.99 Using where; Using join buffer (flat, BNLH join) +1 SIMPLE t3 hash_ALL NULL #hash#$hj 5 test.t1.a 1000 1.96 Using where; Using join buffer (flat, BNLH join) Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` left join `test`.`t3` on(`test`.`t3`.`b` = `test`.`t1`.`a` and `test`.`t3`.`a` < 5 and `test`.`t1`.`a` is not null) where 1 # t3.filtered must less than 100%, too: @@ -2571,7 +2571,7 @@ explain extended select * from t1 left join (t3 join t2) on t1.a=t3.b and t3.a<5 id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where -1 SIMPLE t3 ALL NULL NULL NULL NULL 1000 0.99 Using where +1 SIMPLE t3 ALL NULL NULL NULL NULL 1000 1.96 Using where Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` left join (`test`.`t3` join `test`.`t2`) on(`test`.`t3`.`b` = `test`.`t1`.`a` and `test`.`t3`.`a` < 5 and `test`.`t1`.`a` is not null) where 1 drop table t1,t2,t3; diff --git a/mysql-test/main/mysqld--help.result b/mysql-test/main/mysqld--help.result index f83bf1bf61e..5a6bb51b501 100644 --- a/mysql-test/main/mysqld--help.result +++ b/mysql-test/main/mysqld--help.result @@ -1462,8 +1462,8 @@ gtid-ignore-duplicates FALSE gtid-pos-auto-engines gtid-strict-mode FALSE help TRUE -histogram-size 0 -histogram-type SINGLE_PREC_HB +histogram-size 254 +histogram-type DOUBLE_PREC_HB host-cache-size 279 idle-readonly-transaction-timeout 0 idle-transaction-timeout 0 diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index 57ed163c68b..dab96903f37 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -1324,11 +1324,11 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "selectivity_for_columns": [ { "column_name": "b", - "selectivity_from_histograms": 0.1667 + "selectivity_from_histograms": 0.2891 }, { "column_name": "c", - "selectivity_from_histograms": 0.25 + "selectivity_from_histograms": 0.2891 } ] } @@ -1348,8 +1348,8 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 0.2917, - "cost": 3.3707, + "resulting_rows": 0.5849, + "cost": 3.3121, "chosen": true, "use_tmp_table": true } @@ -1374,7 +1374,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "reconsidering_access_paths_for_index_ordering": { "clause": "GROUP BY", "fanout": 1, - "read_time": 3.3717, + "read_time": 3.3131, "table": "t1", "rows_estimation": 7, "possible_keys": [ @@ -1957,11 +1957,11 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "selectivity_for_columns": [ { "column_name": "a", - "selectivity_from_histograms": 0.0012 + "selectivity_from_histograms": 0.1797 }, { "column_name": "b", - "selectivity_from_histograms": 0.001 + "selectivity_from_histograms": 0.0156 } ] } diff --git a/mysql-test/main/order_by.result b/mysql-test/main/order_by.result index fcc34a24a56..f2065f67585 100644 --- a/mysql-test/main/order_by.result +++ b/mysql-test/main/order_by.result @@ -3347,9 +3347,9 @@ filler2 char(255), key(a) ); insert into t4 select a,a,a, a,a from t3; -set @tmp_h=@@histogram_size, @tmp_u=@@use_stat_tables, +set @tmp_h=@@histogram_size, @tmp_ht=@@histogram_type, @tmp_u=@@use_stat_tables, @tmp_o=@@optimizer_use_condition_selectivity; -set histogram_size=100; +set histogram_size=100, histogram_type='single_prec_hb'; set use_stat_tables=preferably; set optimizer_use_condition_selectivity=4; analyze table t4 persistent for columns(b) indexes (); @@ -3363,6 +3363,6 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t4 index NULL a 5 NULL 1188 100.00 Using where Warnings: Note 1003 select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t4`.`c` AS `c`,`test`.`t4`.`filler1` AS `filler1`,`test`.`t4`.`filler2` AS `filler2` from `test`.`t4` where `test`.`t4`.`b` < 5000 order by `test`.`t4`.`a` limit 600 -set histogram_size=@tmp_h, use_stat_tables=@tmp_u, +set histogram_size=@tmp_h, histogram_type=@tmp_ht, use_stat_tables=@tmp_u, optimizer_use_condition_selectivity=@tmp_o; drop table t1,t2,t3,t4; diff --git a/mysql-test/main/order_by.test b/mysql-test/main/order_by.test index f639f2fdc60..896a8106bae 100644 --- a/mysql-test/main/order_by.test +++ b/mysql-test/main/order_by.test @@ -2209,9 +2209,9 @@ create table t4 ( ); insert into t4 select a,a,a, a,a from t3; -set @tmp_h=@@histogram_size, @tmp_u=@@use_stat_tables, +set @tmp_h=@@histogram_size, @tmp_ht=@@histogram_type, @tmp_u=@@use_stat_tables, @tmp_o=@@optimizer_use_condition_selectivity; -set histogram_size=100; +set histogram_size=100, histogram_type='single_prec_hb'; set use_stat_tables=preferably; set optimizer_use_condition_selectivity=4; analyze table t4 persistent for columns(b) indexes (); @@ -2220,7 +2220,7 @@ analyze table t4 persistent for columns(b) indexes (); explain extended select * from t4 where b < 5000 order by a limit 600; -set histogram_size=@tmp_h, use_stat_tables=@tmp_u, +set histogram_size=@tmp_h, histogram_type=@tmp_ht, use_stat_tables=@tmp_u, optimizer_use_condition_selectivity=@tmp_o; drop table t1,t2,t3,t4; diff --git a/mysql-test/main/partition.result b/mysql-test/main/partition.result index 16a7ff6b564..10480dc0698 100644 --- a/mysql-test/main/partition.result +++ b/mysql-test/main/partition.result @@ -2737,7 +2737,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t2 p1,p2 ALL NULL NULL NULL NULL 400 Using where explain extended select * from t2 where b=5; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 19.80 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1000 19.61 Using where Warnings: Note 1003 select `test`.`t2`.`part_key` AS `part_key`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where `test`.`t2`.`b` = 5 explain partitions select * from t2 where b=5; @@ -2745,7 +2745,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t2 p0,p1,p2,p3,p4 ALL NULL NULL NULL NULL 1000 Using where explain extended select * from t2 partition(p0) where b=1; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 200 19.80 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 200 19.61 Using where Warnings: Note 1003 select `test`.`t2`.`part_key` AS `part_key`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` PARTITION (`p0`) where `test`.`t2`.`b` = 1 set @@use_stat_tables= @save_use_stat_tables; diff --git a/mysql-test/main/partition_explicit_prune.result b/mysql-test/main/partition_explicit_prune.result index 9c1174c5414..650c8d268c7 100644 --- a/mysql-test/main/partition_explicit_prune.result +++ b/mysql-test/main/partition_explicit_prune.result @@ -350,7 +350,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0; VARIABLE_NAME VARIABLE_VALUE HANDLER_COMMIT 1 HANDLER_READ_FIRST 1 -HANDLER_READ_KEY 6 +HANDLER_READ_KEY 8 HANDLER_TMP_WRITE 24 # Should be 1 commit # 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock) diff --git a/mysql-test/main/selectivity.result b/mysql-test/main/selectivity.result index dc349a6008b..087faef284d 100644 --- a/mysql-test/main/selectivity.result +++ b/mysql-test/main/selectivity.result @@ -10,6 +10,8 @@ set use_stat_tables='preferably'; set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; set @save_histogram_size=@@histogram_size; set @save_histogram_type=@@histogram_type; +set histogram_size=0; +set histogram_type='single_prec_hb'; set optimizer_use_condition_selectivity=3; create table t1 (a int); insert into t1 values @@ -1369,14 +1371,14 @@ test.t2 analyze status Table is already up to date explain extended select * from t1 straight_join t2 where t1.a=t2.a and t1.a<10; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 0.99 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 1.96 Using where 1 SIMPLE t2 ref a a 5 test.t1.a 10 100.00 Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` straight_join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`a` < 10 explain extended select * from t1 straight_join t2 where t1.a=t2.a and t2.a<10; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 0.99 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 1.96 Using where 1 SIMPLE t2 ref a a 5 test.t1.a 10 100.00 Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` straight_join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`a` < 10 diff --git a/mysql-test/main/selectivity.test b/mysql-test/main/selectivity.test index 3df49456332..eb3f6e2893a 100644 --- a/mysql-test/main/selectivity.test +++ b/mysql-test/main/selectivity.test @@ -14,6 +14,8 @@ set use_stat_tables='preferably'; set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; set @save_histogram_size=@@histogram_size; set @save_histogram_type=@@histogram_type; +set histogram_size=0; +set histogram_type='single_prec_hb'; # check that statistics on nulls is used diff --git a/mysql-test/main/selectivity_innodb.result b/mysql-test/main/selectivity_innodb.result index 93917065722..b6fed1bb41d 100644 --- a/mysql-test/main/selectivity_innodb.result +++ b/mysql-test/main/selectivity_innodb.result @@ -13,6 +13,8 @@ set use_stat_tables='preferably'; set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; set @save_histogram_size=@@histogram_size; set @save_histogram_type=@@histogram_type; +set histogram_size=0; +set histogram_type='single_prec_hb'; set optimizer_use_condition_selectivity=3; create table t1 (a int); insert into t1 values @@ -1379,14 +1381,14 @@ test.t2 analyze status OK explain extended select * from t1 straight_join t2 where t1.a=t2.a and t1.a<10; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 0.99 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 1.96 Using where 1 SIMPLE t2 ref a a 5 test.t1.a 10 100.00 Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` straight_join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`a` < 10 explain extended select * from t1 straight_join t2 where t1.a=t2.a and t2.a<10; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 0.99 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 1.96 Using where 1 SIMPLE t2 ref a a 5 test.t1.a 10 100.00 Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` straight_join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`a` < 10 diff --git a/mysql-test/main/stat_tables.result b/mysql-test/main/stat_tables.result index efa53344a22..05bae1da085 100644 --- a/mysql-test/main/stat_tables.result +++ b/mysql-test/main/stat_tables.result @@ -6,6 +6,8 @@ select @@session.use_stat_tables; COMPLEMENTARY set @save_use_stat_tables=@@use_stat_tables; set use_stat_tables='preferably'; +set @tmp_stt_hs=@@histogram_size, @tmp_stt_ht=@@histogram_type; +set histogram_size=0, histogram_type='single_prec_hb'; DROP DATABASE IF EXISTS dbt3_s001; CREATE DATABASE dbt3_s001; use dbt3_s001; @@ -680,4 +682,5 @@ select * from t1 where a=1 and b=3; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 2.78 10.00 Using where drop table t1; +set histogram_size=@tmp_stt_hs, histogram_type=@tmp_stt_ht; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/main/stat_tables.test b/mysql-test/main/stat_tables.test index 2c1d53a2583..da17dcf7df8 100644 --- a/mysql-test/main/stat_tables.test +++ b/mysql-test/main/stat_tables.test @@ -6,6 +6,8 @@ select @@session.use_stat_tables; set @save_use_stat_tables=@@use_stat_tables; set use_stat_tables='preferably'; +set @tmp_stt_hs=@@histogram_size, @tmp_stt_ht=@@histogram_type; +set histogram_size=0, histogram_type='single_prec_hb'; --disable_warnings DROP DATABASE IF EXISTS dbt3_s001; @@ -443,4 +445,5 @@ select * from mysql.column_stats; analyze select * from t1 where a=1 and b=3; drop table t1; +set histogram_size=@tmp_stt_hs, histogram_type=@tmp_stt_ht; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/main/stat_tables_innodb.result b/mysql-test/main/stat_tables_innodb.result index c49c9253816..60e04ed20e0 100644 --- a/mysql-test/main/stat_tables_innodb.result +++ b/mysql-test/main/stat_tables_innodb.result @@ -14,6 +14,8 @@ select @@session.use_stat_tables; COMPLEMENTARY set @save_use_stat_tables=@@use_stat_tables; set use_stat_tables='preferably'; +set @tmp_stt_hs=@@histogram_size, @tmp_stt_ht=@@histogram_type; +set histogram_size=0, histogram_type='single_prec_hb'; DROP DATABASE IF EXISTS dbt3_s001; CREATE DATABASE dbt3_s001; use dbt3_s001; @@ -712,6 +714,7 @@ select * from t1 where a=1 and b=3; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 2.78 10.00 Using where drop table t1; +set histogram_size=@tmp_stt_hs, histogram_type=@tmp_stt_ht; set use_stat_tables=@save_use_stat_tables; set global innodb_stats_persistent= @innodb_stats_persistent_save; set global innodb_stats_persistent_sample_pages= diff --git a/mysql-test/main/statistics.result b/mysql-test/main/statistics.result index 34a17cf049c..5f6a7cd7bb3 100644 --- a/mysql-test/main/statistics.result +++ b/mysql-test/main/statistics.result @@ -1,5 +1,7 @@ drop table if exists t1,t2; set @save_use_stat_tables=@@use_stat_tables; +set @save_hist_size=@@histogram_size, @save_hist_type=@@histogram_type; +set histogram_size=0, histogram_type='single_prec_hb'; DELETE FROM mysql.table_stats; DELETE FROM mysql.column_stats; DELETE FROM mysql.index_stats; @@ -246,7 +248,7 @@ test t1 e 0.01 0.112 0.2250 6.2000 8 DOUBLE_PREC_HB 000005056464E1E1 test t1 f 1 5 0.2000 6.4000 8 DOUBLE_PREC_HB FF3FFF7FFFBFFFBF DELETE FROM mysql.column_stats; set histogram_size= 0; -set histogram_type=default; +set histogram_type='single_prec_hb'; ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected @@ -1504,8 +1506,8 @@ hist_size 254 hist_type DOUBLE_PREC_HB hex(histogram) 1F00A1002B023002350238023F02430249024E02520258025D02630268026E02720276027B02800285028C02920297029D02A102A802AC02B402BC02C402CC02D302DA02E302EA02F102F802010305030C03120319031F03290333033D0343034F03590363036D037803840390039A03A603B303C303D103E003F203020412042404330440045304600472047F049104A204B804C804DE04F2040A0526053F0558056F058E05B305D905F4051306380667068406AB06DA06020731075C079407C507F8072E085E08A508DF0824096909CC092E0A760AD50A400BA90B150CAD0C310D240E130F0E103B11B9126B14F0166B192F1CB71FFF240630483FC567 decode_histogram(hist_type,histogram) 0.00047,0.00198,0.00601,0.00008,0.00008,0.00005,0.00011,0.00006,0.00009,0.00008,0.00006,0.00009,0.00008,0.00009,0.00008,0.00009,0.00006,0.00006,0.00008,0.00008,0.00008,0.00011,0.00009,0.00008,0.00009,0.00006,0.00011,0.00006,0.00012,0.00012,0.00012,0.00012,0.00011,0.00011,0.00014,0.00011,0.00011,0.00011,0.00014,0.00006,0.00011,0.00009,0.00011,0.00009,0.00015,0.00015,0.00015,0.00009,0.00018,0.00015,0.00015,0.00015,0.00017,0.00018,0.00018,0.00015,0.00018,0.00020,0.00024,0.00021,0.00023,0.00027,0.00024,0.00024,0.00027,0.00023,0.00020,0.00029,0.00020,0.00027,0.00020,0.00027,0.00026,0.00034,0.00024,0.00034,0.00031,0.00037,0.00043,0.00038,0.00038,0.00035,0.00047,0.00056,0.00058,0.00041,0.00047,0.00056,0.00072,0.00044,0.00060,0.00072,0.00061,0.00072,0.00066,0.00085,0.00075,0.00078,0.00082,0.00073,0.00108,0.00089,0.00105,0.00105,0.00151,0.00150,0.00110,0.00145,0.00163,0.00160,0.00165,0.00232,0.00201,0.00371,0.00365,0.00383,0.00459,0.00583,0.00662,0.00984,0.00969,0.01080,0.01379,0.02063,0.04308,0.05960,0.15816,0.59464 -set histogram_type=default; -set histogram_size=default; +set histogram_type='single_prec_hb'; +set histogram_size=0; use test; DROP DATABASE world; SELECT UPPER(db_name), UPPER(table_name), cardinality @@ -1600,8 +1602,8 @@ hist_size, hist_type, HEX(histogram) FROM mysql.column_stats; db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) test t1 a 1 5 0.0000 1.0000 10 DOUBLE_PREC_HB 0000FF3FFF7FFFBFFFFF -set histogram_size=default; -set histogram_type=default; +set histogram_size=0; +set histogram_type='single_prec_hb'; drop table t1; # # Bug mdev-4369: histogram for a column with many distinct values @@ -1641,7 +1643,7 @@ hist_size, hist_type, HEX(histogram) FROM mysql.column_stats; db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) test t2 id 1 1024 0.0000 8.0000 63 SINGLE_PREC_HB 03070B0F13171B1F23272B2F33373B3F43474B4F53575B5F63676B6F73777B7F83878B8F93979B9FA3A7ABAFB3B7BBBFC3C7CBCFD3D7DBDFE3E7EBEFF3F7FB -set histogram_size=default; +set histogram_size=0; drop table t1, t2; set use_stat_tables=@save_use_stat_tables; # @@ -1757,3 +1759,4 @@ DROP TABLE t1; # # End of 10.2 tests # +set histogram_size=@save_hist_size, histogram_type=@save_hist_type; diff --git a/mysql-test/main/statistics.test b/mysql-test/main/statistics.test index b2e544064b0..78439e3e68a 100644 --- a/mysql-test/main/statistics.test +++ b/mysql-test/main/statistics.test @@ -5,7 +5,8 @@ drop table if exists t1,t2; --enable_warnings set @save_use_stat_tables=@@use_stat_tables; - +set @save_hist_size=@@histogram_size, @save_hist_type=@@histogram_type; +set histogram_size=0, histogram_type='single_prec_hb'; DELETE FROM mysql.table_stats; --sorted_result DELETE FROM mysql.column_stats; @@ -196,7 +197,7 @@ SELECT db_name, table_name, column_name, DELETE FROM mysql.column_stats; set histogram_size= 0; -set histogram_type=default; +set histogram_type='single_prec_hb'; ANALYZE TABLE t1; @@ -657,8 +658,8 @@ FLUSH TABLES; --query_vertical select UPPER(db_name),UPPER(table_name),UPPER(column_name),min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(hist_type,histogram) from mysql.column_stats where UPPER(db_name)='WORLD' and UPPER(table_name)='COUNTRYLANGUAGE' and UPPER(column_name) = 'PERCENTAGE'; --query_vertical select UPPER(db_name),UPPER(table_name),UPPER(column_name),min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(hist_type,histogram) from mysql.column_stats where UPPER(db_name)='WORLD' and UPPER(table_name)='CITY' and UPPER(column_name) = 'POPULATION'; -set histogram_type=default; -set histogram_size=default; +set histogram_type='single_prec_hb'; +set histogram_size=0; use test; DROP DATABASE world; @@ -732,8 +733,8 @@ select db_name, table_name, column_name, hist_size, hist_type, HEX(histogram) FROM mysql.column_stats; -set histogram_size=default; -set histogram_type=default; +set histogram_size=0; +set histogram_type='single_prec_hb'; drop table t1; @@ -776,7 +777,7 @@ select db_name, table_name, column_name, hist_size, hist_type, HEX(histogram) FROM mysql.column_stats; -set histogram_size=default; +set histogram_size=0; drop table t1, t2; @@ -898,3 +899,5 @@ DROP TABLE t1; --echo # --echo # End of 10.2 tests --echo # +set histogram_size=@save_hist_size, histogram_type=@save_hist_type; + diff --git a/mysql-test/main/subselect_mat.result b/mysql-test/main/subselect_mat.result index 3cd45d11a62..907e44c2335 100644 --- a/mysql-test/main/subselect_mat.result +++ b/mysql-test/main/subselect_mat.result @@ -62,7 +62,7 @@ explain extended select * from t1 where a1 in (select b1 from t2 where b1 > '0'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 99.22 Using where Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <`test`.`t1`.`a1`>((`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( (/* select#2 */ select `test`.`t2`.`b1` from `test`.`t2` where `test`.`t2`.`b1` > '0' ), (`test`.`t1`.`a1` in on distinct_key where `test`.`t1`.`a1` = ``.`b1`)))) select * from t1 where a1 in (select b1 from t2 where b1 > '0'); @@ -73,7 +73,7 @@ explain extended select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 99.22 Using where Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <`test`.`t1`.`a1`>((`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( (/* select#2 */ select `test`.`t2`.`b1` from `test`.`t2` where `test`.`t2`.`b1` > '0' ), (`test`.`t1`.`a1` in on distinct_key where `test`.`t1`.`a1` = ``.`b1`)))) select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1); @@ -84,7 +84,7 @@ explain extended select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 99.22 Using where Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <`test`.`t1`.`a1`,`test`.`t1`.`a2`>(((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` > '0' ), (`test`.`t1`.`a1` in on distinct_key where `test`.`t1`.`a1` = ``.`b1` and `test`.`t1`.`a2` = ``.`b2`)))) select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2); @@ -95,7 +95,7 @@ explain extended select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using temporary +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 99.22 Using where; Using temporary Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <`test`.`t1`.`a1`,`test`.`t1`.`a2`>(((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( (/* select#2 */ select `test`.`t2`.`b1`,min(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`b1` > '0' group by `test`.`t2`.`b1` ), (`test`.`t1`.`a1` in on distinct_key where `test`.`t1`.`a1` = ``.`b1` and `test`.`t1`.`a2` = ``.`min(b2)`)))) select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1); @@ -322,7 +322,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where 3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where 4 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 99.22 Using where Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <`test`.`t1`.`a1`,`test`.`t1`.`a2`>(((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` > '0' ), (`test`.`t1`.`a1` in on distinct_key where `test`.`t1`.`a1` = ``.`b1` and `test`.`t1`.`a2` = ``.`b2`)))) and <`test`.`t1`.`a1`,`test`.`t1`.`a2`>(((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( (/* select#3 */ select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <`test`.`t3`.`c1`,`test`.`t3`.`c2`>(((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( (/* select#4 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), (`test`.`t3`.`c1` in on distinct_key where `test`.`t3`.`c1` = ``.`b1` and `test`.`t3`.`c2` = ``.`b2`)))) ), (`test`.`t1`.`a1` in on distinct_key where `test`.`t1`.`a1` = ``.`c1` and `test`.`t1`.`a2` = ``.`c2`)))) select * from t1 @@ -452,8 +452,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where 4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where 5 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 99.22 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 99.22 Using where NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <`test`.`t1`.`a1`,`test`.`t1`.`a2`>(((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(/* select#2 */ select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where `test`.`t1`.`a1` > '0' and (`test`.`t1`.`a1`) = `test`.`t1`.`a1` and (`test`.`t1`.`a2`) = `test`.`t1`.`a2` union /* select#3 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` < '9' and (`test`.`t1`.`a1`) = `test`.`t2`.`b1` and (`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and <`test`.`t1`.`a1`,`test`.`t1`.`a2`>(((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( (/* select#4 */ select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <`test`.`t3`.`c1`,`test`.`t3`.`c2`>(((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( (/* select#5 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), (`test`.`t3`.`c1` in on distinct_key where `test`.`t3`.`c1` = ``.`b1` and `test`.`t3`.`c2` = ``.`b2`)))) ), (`test`.`t1`.`a1` in on distinct_key where `test`.`t1`.`a1` = ``.`c1` and `test`.`t1`.`a2` = ``.`c2`)))) @@ -475,8 +475,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join) 4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where 5 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 99.22 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 99.22 Using where NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`c1` = `test`.`t1`.`a1` and <`test`.`t1`.`a1`,`test`.`t1`.`a2`>(((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(/* select#2 */ select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where `test`.`t1`.`a1` > '0' and (`test`.`t1`.`a1`) = `test`.`t1`.`a1` and (`test`.`t1`.`a2`) = `test`.`t1`.`a2` union /* select#3 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` < '9' and (`test`.`t1`.`a1`) = `test`.`t2`.`b1` and (`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and <`test`.`t3`.`c1`,`test`.`t3`.`c2`>(((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( (/* select#4 */ select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <`test`.`t3`.`c1`,`test`.`t3`.`c2`>(((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( (/* select#5 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), (`test`.`t3`.`c1` in on distinct_key where `test`.`t3`.`c1` = ``.`b1` and `test`.`t3`.`c2` = ``.`b2`)))) ), (`test`.`t3`.`c1` in on distinct_key where `test`.`t3`.`c1` = ``.`c1` and `test`.`t3`.`c2` = ``.`c2`)))) @@ -497,8 +497,8 @@ select * from t3 where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 99.22 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 99.22 Using where NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1003 /* select#1 */ select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <`test`.`t3`.`c1`>((`test`.`t3`.`c1`,(/* select#2 */ select `test`.`t1`.`a1` from `test`.`t1` where `test`.`t1`.`a1` > '0' and (`test`.`t3`.`c1`) = `test`.`t1`.`a1` union /* select#3 */ select `test`.`t2`.`b1` from `test`.`t2` where `test`.`t2`.`b1` < '9' and (`test`.`t3`.`c1`) = `test`.`t2`.`b1`))) @@ -712,7 +712,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where 3 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where 3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join) -4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 99.22 Using where Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where ((concat(`test`.`t1`.`a1`,'x'),(/* select#2 */ select left(`test`.`t1_16`.`a1`,8) from `test`.`t1_16` where <`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`>(((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),(/* select#3 */ select `test`.`t2_16`.`b1`,`test`.`t2_16`.`b2` from `test`.`t2_16` join `test`.`t2` where `test`.`t2`.`b2` = substr(`test`.`t2_16`.`b2`,1,6) and <`test`.`t2`.`b1`>((`test`.`t2`.`b1`,`test`.`t2`.`b1` in ( (/* select#4 */ select `test`.`t3`.`c1` from `test`.`t3` where `test`.`t3`.`c2` > '0' ), (`test`.`t2`.`b1` in on distinct_key where `test`.`t2`.`b1` = ``.`c1`)))) and (`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1` and (`test`.`t1_16`.`a2`) = `test`.`t2_16`.`b2`))) and (concat(`test`.`t1`.`a1`,'x')) = left(`test`.`t1_16`.`a1`,8)))) drop table t1_16, t2_16, t3_16; diff --git a/mysql-test/main/subselect_sj_mat.result b/mysql-test/main/subselect_sj_mat.result index 00f5acc8803..679ad4fddd9 100644 --- a/mysql-test/main/subselect_sj_mat.result +++ b/mysql-test/main/subselect_sj_mat.result @@ -60,9 +60,9 @@ set @@optimizer_switch='materialization=on,in_to_exists=off,firstmatch=off'; explain extended select * from t1 where a1 in (select b1 from t2 where b1 > '0'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 99.22 1 PRIMARY eq_ref distinct_key distinct_key 8 func 1 100.00 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 99.22 Using where Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`b1` > '0' select * from t1 where a1 in (select b1 from t2 where b1 > '0'); @@ -72,9 +72,9 @@ a1 a2 explain extended select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 99.22 1 PRIMARY eq_ref distinct_key distinct_key 8 func 1 100.00 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 99.22 Using where Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`b1` > '0' select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1); @@ -84,9 +84,9 @@ a1 a2 explain extended select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 99.22 1 PRIMARY eq_ref distinct_key distinct_key 16 func,func 1 100.00 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 99.22 Using where Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`b1` > '0' select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2); @@ -98,7 +98,7 @@ select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' gr id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where 1 PRIMARY eq_ref distinct_key distinct_key 16 test.t1.a1,test.t1.a2 1 100.00 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using temporary +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 99.22 Using where; Using temporary Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from (/* select#2 */ select `test`.`t2`.`b1`,min(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`b1` > '0' group by `test`.`t2`.`b1`) join `test`.`t1` where ``.`b1` = `test`.`t1`.`a1` and ``.`min(b2)` = `test`.`t1`.`a2` select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1); @@ -331,12 +331,12 @@ where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and (a1, a2) in (select c1, c2 from t3 where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 98.44 1 PRIMARY eq_ref distinct_key distinct_key 16 func,func 1 100.00 1 PRIMARY eq_ref distinct_key distinct_key 16 func,func 1 100.00 -3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 98.44 Using where 3 MATERIALIZED t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t3.c1,test.t3.c2 1 100.00 Using index -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 98.44 Using where Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and `test`.`t2`.`b1` > '0' and `test`.`t3`.`c2` > '0' select * from t1 @@ -373,12 +373,12 @@ b2 in (select c2 from t3 where c2 LIKE '%03')) and (a1, a2) in (select c1, c2 from t3 where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 99.22 1 PRIMARY eq_ref distinct_key distinct_key 16 func,func 1 100.00 1 PRIMARY eq_ref distinct_key distinct_key 16 func,func 1 100.00 -5 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +5 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 99.22 Using where 5 MATERIALIZED t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t3.c1,test.t3.c2 1 100.00 Using index -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 99.22 Using where 4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where 3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where Warnings: @@ -399,10 +399,10 @@ b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and (a1, a2) in (select c1, c2 from t3 t3c where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 99.22 1 PRIMARY eq_ref distinct_key distinct_key 16 func,func 1 100.00 -1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) -5 MATERIALIZED t3c ALL NULL NULL NULL NULL 4 100.00 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 5 99.22 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +5 MATERIALIZED t3c ALL NULL NULL NULL NULL 4 99.22 Using where 5 MATERIALIZED t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t3c.c1,test.t3c.c2 1 100.00 Using index 4 MATERIALIZED t3b ALL NULL NULL NULL NULL 4 100.00 Using where 3 DEPENDENT SUBQUERY t3a ALL NULL NULL NULL NULL 4 100.00 Using where @@ -432,12 +432,12 @@ where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and (a1, a2) in (select c1, c2 from t3i where (c1, c2) in (select b1, b2 from t2i where b2 > '0'))); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL # # # 3 100.00 # +1 PRIMARY t1 ALL NULL # # # 3 99.22 # 1 PRIMARY eq_ref distinct_key # # # 1 100.00 # 1 PRIMARY eq_ref distinct_key # # # 1 100.00 # -5 MATERIALIZED t3 ALL NULL # # # 4 100.00 # +5 MATERIALIZED t3 ALL NULL # # # 4 99.22 # 5 MATERIALIZED t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 # -2 MATERIALIZED t2 ALL NULL # # # 5 100.00 # +2 MATERIALIZED t2 ALL NULL # # # 5 99.22 # 4 MATERIALIZED t3 ALL NULL # # # 4 100.00 # 3 MATERIALIZED t3 ALL NULL # # # 4 100.00 # 7 UNION t2i index it2i1,it2i2,it2i3 # # # 5 50.00 # @@ -468,12 +468,12 @@ where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where (a1, a2) in (select c1, c2 from t3 where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 99.22 Using where 1 PRIMARY eq_ref distinct_key distinct_key 16 func,func 1 100.00 -4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 99.22 Using where 4 MATERIALIZED t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t3.c1,test.t3.c2 1 100.00 Using index -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 99.22 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 99.22 Using where NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and <`test`.`t1`.`a1`,`test`.`t1`.`a2`>(((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(/* select#2 */ select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where `test`.`t1`.`a1` > '0' and (`test`.`t1`.`a1`) = `test`.`t1`.`a1` and (`test`.`t1`.`a2`) = `test`.`t1`.`a2` union /* select#3 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` < '9' and (`test`.`t1`.`a1`) = `test`.`t2`.`b1` and (`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and `test`.`t3`.`c2` > '0' @@ -493,11 +493,11 @@ a1 = c1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where 1 PRIMARY ALL distinct_key NULL NULL NULL 4 100.00 Using where -1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join) -4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +1 PRIMARY t3 ALL NULL NULL NULL NULL 4 99.22 Using where; Using join buffer (flat, BNL join) +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 99.22 Using where 4 MATERIALIZED t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t3.c1,test.t3.c2 1 100.00 Using index -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 99.22 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 99.22 Using where NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t1` semi join (`test`.`t2i` join `test`.`t3`) join `test`.`t3` where `test`.`t3`.`c1` = `test`.`t1`.`a1` and `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t3`.`c1` = `test`.`t1`.`a1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and `test`.`t3`.`c2` = `test`.`t3`.`c2` and <`test`.`t1`.`a1`,`test`.`t1`.`a2`>(((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(/* select#2 */ select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where `test`.`t1`.`a1` > '0' and (`test`.`t1`.`a1`) = `test`.`t1`.`a1` and (`test`.`t1`.`a2`) = `test`.`t1`.`a2` union /* select#3 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` < '9' and (`test`.`t1`.`a1`) = `test`.`t2`.`b1` and (`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and `test`.`t3`.`c2` > '0' @@ -518,8 +518,8 @@ select * from t3 where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 99.22 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 99.22 Using where NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1003 /* select#1 */ select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <`test`.`t3`.`c1`>((`test`.`t3`.`c1`,(/* select#2 */ select `test`.`t1`.`a1` from `test`.`t1` where `test`.`t1`.`a1` > '0' and (`test`.`t3`.`c1`) = `test`.`t1`.`a1` union /* select#3 */ select `test`.`t2`.`b1` from `test`.`t2` where `test`.`t2`.`b1` < '9' and (`test`.`t3`.`c1`) = `test`.`t2`.`b1`))) @@ -734,7 +734,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; Using join buffer (flat, BNL join) 1 PRIMARY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) -1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t3 ALL NULL NULL NULL NULL 4 99.22 Using where; Using join buffer (flat, BNL join) 1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; End temporary; Using join buffer (flat, BNL join) Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t3` join `test`.`t2_16` join `test`.`t2` join `test`.`t1_16`) where `test`.`t2`.`b1` = `test`.`t3`.`c1` and `test`.`t2_16`.`b1` = `test`.`t1_16`.`a1` and `test`.`t2_16`.`b2` = `test`.`t1_16`.`a2` and `test`.`t2`.`b2` = substr(`test`.`t1_16`.`a2`,1,6) and `test`.`t3`.`c2` > '0' and concat(`test`.`t1`.`a1`,'x') = left(`test`.`t1_16`.`a1`,8) diff --git a/mysql-test/suite/sys_vars/r/histogram_size_basic.result b/mysql-test/suite/sys_vars/r/histogram_size_basic.result index 1f310600d00..05a52309d9f 100644 --- a/mysql-test/suite/sys_vars/r/histogram_size_basic.result +++ b/mysql-test/suite/sys_vars/r/histogram_size_basic.result @@ -1,20 +1,20 @@ SET @start_global_value = @@global.histogram_size; SELECT @start_global_value; @start_global_value -0 +254 SET @start_session_value = @@session.histogram_size; SELECT @start_session_value; @start_session_value -0 +254 '#--------------------FN_DYNVARS_053_01-------------------------#' SET @@global.histogram_size = DEFAULT; SELECT @@global.histogram_size; @@global.histogram_size -0 +254 SET @@session.histogram_size = DEFAULT; SELECT @@session.histogram_size; @@session.histogram_size -0 +254 '#--------------------FN_DYNVARS_053_03-------------------------#' SET @@global.histogram_size = 1; SELECT @@global.histogram_size; @@ -129,8 +129,8 @@ SELECT @@local.histogram_size = @@session.histogram_size; SET @@global.histogram_size = @start_global_value; SELECT @@global.histogram_size; @@global.histogram_size -0 +254 SET @@session.histogram_size = @start_session_value; SELECT @@session.histogram_size; @@session.histogram_size -0 +254 diff --git a/mysql-test/suite/sys_vars/r/histogram_type_basic.result b/mysql-test/suite/sys_vars/r/histogram_type_basic.result index f688a2a15fd..db42204ac1f 100644 --- a/mysql-test/suite/sys_vars/r/histogram_type_basic.result +++ b/mysql-test/suite/sys_vars/r/histogram_type_basic.result @@ -1,16 +1,16 @@ SET @start_global_value = @@global.histogram_type; SELECT @start_global_value; @start_global_value -SINGLE_PREC_HB +DOUBLE_PREC_HB SET @start_session_value = @@session.histogram_type; SELECT @start_session_value; @start_session_value -SINGLE_PREC_HB +DOUBLE_PREC_HB SET @@global.histogram_type = 1; SET @@global.histogram_type = DEFAULT; SELECT @@global.histogram_type; @@global.histogram_type -SINGLE_PREC_HB +DOUBLE_PREC_HB SET @@global.histogram_type = 0; SELECT @@global.histogram_type; @@global.histogram_type @@ -71,9 +71,9 @@ HISTOGRAM_TYPE DOUBLE_PREC_HB SET @@global.histogram_type = @start_global_value; SELECT @@global.histogram_type; @@global.histogram_type -SINGLE_PREC_HB +DOUBLE_PREC_HB SET @@session.histogram_type = @start_session_value; SELECT @@session.histogram_type; @@session.histogram_type -SINGLE_PREC_HB +DOUBLE_PREC_HB set sql_mode=''; diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index da7790f26b7..6cd6c674cbf 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -1427,10 +1427,10 @@ ENUM_VALUE_LIST NULL READ_ONLY YES COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME HISTOGRAM_SIZE -SESSION_VALUE 0 -GLOBAL_VALUE 0 +SESSION_VALUE 254 +GLOBAL_VALUE 254 GLOBAL_VALUE_ORIGIN COMPILE-TIME -DEFAULT_VALUE 0 +DEFAULT_VALUE 254 VARIABLE_SCOPE SESSION VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Number of bytes used for a histogram. If set to 0, no histograms are created by ANALYZE. @@ -1441,10 +1441,10 @@ ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME HISTOGRAM_TYPE -SESSION_VALUE SINGLE_PREC_HB -GLOBAL_VALUE SINGLE_PREC_HB +SESSION_VALUE DOUBLE_PREC_HB +GLOBAL_VALUE DOUBLE_PREC_HB GLOBAL_VALUE_ORIGIN COMPILE-TIME -DEFAULT_VALUE SINGLE_PREC_HB +DEFAULT_VALUE DOUBLE_PREC_HB VARIABLE_SCOPE SESSION VARIABLE_TYPE ENUM VARIABLE_COMMENT Specifies type of the histograms created by ANALYZE. Possible values are: SINGLE_PREC_HB - single precision height-balanced, DOUBLE_PREC_HB - double precision height-balanced. diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 7343c6ea2e7..3375017ce10 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -5936,7 +5936,7 @@ static Sys_var_ulong Sys_histogram_size( "Number of bytes used for a histogram. " "If set to 0, no histograms are created by ANALYZE.", SESSION_VAR(histogram_size), CMD_LINE(REQUIRED_ARG), - VALID_RANGE(0, 255), DEFAULT(0), BLOCK_SIZE(1)); + VALID_RANGE(0, 255), DEFAULT(254), BLOCK_SIZE(1)); extern const char *histogram_types[]; static Sys_var_enum Sys_histogram_type( @@ -5946,7 +5946,7 @@ static Sys_var_enum Sys_histogram_type( "SINGLE_PREC_HB - single precision height-balanced, " "DOUBLE_PREC_HB - double precision height-balanced.", SESSION_VAR(histogram_type), CMD_LINE(REQUIRED_ARG), - histogram_types, DEFAULT(0)); + histogram_types, DEFAULT(1)); static Sys_var_mybool Sys_no_thread_alarm( "debug_no_thread_alarm", From 3f154943db8bc4135fb3c60b8a74f926b65a040b Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Mon, 18 Feb 2019 13:29:01 +0300 Subject: [PATCH 11/19] MDEV-18608: Defaults for 10.4: histogram size should be set Followup: update test results --- mysql-test/suite/gcol/r/gcol_select_innodb.result | 8 ++++---- mysql-test/suite/gcol/r/gcol_select_myisam.result | 8 ++++---- .../suite/sys_vars/r/sysvars_server_embedded.result | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mysql-test/suite/gcol/r/gcol_select_innodb.result b/mysql-test/suite/gcol/r/gcol_select_innodb.result index 8288588f6db..ed0f15d5717 100644 --- a/mysql-test/suite/gcol/r/gcol_select_innodb.result +++ b/mysql-test/suite/gcol/r/gcol_select_innodb.result @@ -698,7 +698,7 @@ WHERE t4.c1 < 'o' ) AND t1.i1 <= t3.i2_key; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY ALL distinct_key NULL NULL NULL 3 +1 PRIMARY ALL distinct_key NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join) 1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.i1 1 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join) @@ -753,7 +753,7 @@ WHERE t4.c1 < 'o' ) AND t1.i1 <= t3.i2_key; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY ALL distinct_key NULL NULL NULL 3 +1 PRIMARY ALL distinct_key NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join) 1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.i1 1 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join) @@ -809,7 +809,7 @@ WHERE t4.c1 < 'o' ) AND t1.i1 <= t3.i2_key; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY ALL distinct_key NULL NULL NULL 3 +1 PRIMARY ALL distinct_key NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join) 1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.i1 1 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join) @@ -873,7 +873,7 @@ WHERE t4.c1 < 'o' ) AND t1.i1 <= t3.i2_key; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY ALL distinct_key NULL NULL NULL 3 +1 PRIMARY ALL distinct_key NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join) 1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.i1 1 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join) diff --git a/mysql-test/suite/gcol/r/gcol_select_myisam.result b/mysql-test/suite/gcol/r/gcol_select_myisam.result index 039484b31a7..ae619f37eb6 100644 --- a/mysql-test/suite/gcol/r/gcol_select_myisam.result +++ b/mysql-test/suite/gcol/r/gcol_select_myisam.result @@ -1324,7 +1324,7 @@ WHERE t4.c1 < 'o' ) AND t1.i1 <= t3.i2_key; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY ALL distinct_key NULL NULL NULL 3 +1 PRIMARY ALL distinct_key NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join) 1 PRIMARY t3 eq_ref PRIMARY,v_idx PRIMARY 4 test.t4.i1 1 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join) @@ -1380,7 +1380,7 @@ WHERE t4.c1 < 'o' ) AND t1.i1 <= t3.i2_key; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY ALL distinct_key NULL NULL NULL 3 +1 PRIMARY ALL distinct_key NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join) 1 PRIMARY t3 eq_ref PRIMARY,v_idx,v_idx2 PRIMARY 4 test.t4.i1 1 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join) @@ -1438,7 +1438,7 @@ WHERE t4.c1 < 'o' ) AND t1.i1 <= t3.i2_key; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY ALL distinct_key NULL NULL NULL 3 +1 PRIMARY ALL distinct_key NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join) 1 PRIMARY t3 eq_ref PRIMARY,v_idx2 PRIMARY 4 test.t4.i1 1 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join) @@ -1505,7 +1505,7 @@ WHERE t4.c1 < 'o' ) AND t1.i1 <= t3.i2_key; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY ALL distinct_key NULL NULL NULL 3 +1 PRIMARY ALL distinct_key NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join) 1 PRIMARY t3 eq_ref PRIMARY,v_idx PRIMARY 4 test.t4.i1 1 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join) diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result index 628ba002550..be5d9a9e670 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result @@ -1287,10 +1287,10 @@ ENUM_VALUE_LIST NULL READ_ONLY YES COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME HISTOGRAM_SIZE -SESSION_VALUE 0 -GLOBAL_VALUE 0 +SESSION_VALUE 254 +GLOBAL_VALUE 254 GLOBAL_VALUE_ORIGIN COMPILE-TIME -DEFAULT_VALUE 0 +DEFAULT_VALUE 254 VARIABLE_SCOPE SESSION VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Number of bytes used for a histogram. If set to 0, no histograms are created by ANALYZE. @@ -1301,10 +1301,10 @@ ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME HISTOGRAM_TYPE -SESSION_VALUE SINGLE_PREC_HB -GLOBAL_VALUE SINGLE_PREC_HB +SESSION_VALUE DOUBLE_PREC_HB +GLOBAL_VALUE DOUBLE_PREC_HB GLOBAL_VALUE_ORIGIN COMPILE-TIME -DEFAULT_VALUE SINGLE_PREC_HB +DEFAULT_VALUE DOUBLE_PREC_HB VARIABLE_SCOPE SESSION VARIABLE_TYPE ENUM VARIABLE_COMMENT Specifies type of the histograms created by ANALYZE. Possible values are: SINGLE_PREC_HB - single precision height-balanced, DOUBLE_PREC_HB - double precision height-balanced. From 7d2138d4a4788b8979c13e995d357097b0372ae2 Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Mon, 18 Feb 2019 10:09:44 +0100 Subject: [PATCH 12/19] MTR tests for galera sync wait up to --- .../galera/r/galera_last_committed_id.result | 38 ++++++ .../galera/r/galera_sync_wait_upto.result | 43 +++++++ .../galera/t/galera_last_committed_id.test | 68 +++++++++++ .../galera/t/galera_sync_wait_upto-master.opt | 1 + .../suite/galera/t/galera_sync_wait_upto.test | 115 ++++++++++++++++++ 5 files changed, 265 insertions(+) create mode 100644 mysql-test/suite/galera/r/galera_last_committed_id.result create mode 100644 mysql-test/suite/galera/r/galera_sync_wait_upto.result create mode 100644 mysql-test/suite/galera/t/galera_last_committed_id.test create mode 100644 mysql-test/suite/galera/t/galera_sync_wait_upto-master.opt create mode 100644 mysql-test/suite/galera/t/galera_sync_wait_upto.test diff --git a/mysql-test/suite/galera/r/galera_last_committed_id.result b/mysql-test/suite/galera/r/galera_last_committed_id.result new file mode 100644 index 00000000000..fabc5337576 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_last_committed_id.result @@ -0,0 +1,38 @@ +connection node_2; +connection node_1; +SELECT WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1'; +WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1' +1 +wsrep_last_committed_id_match +1 +connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; +connection node_1a; +CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +connection node_1; +SELECT WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1'; +WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1' +1 +connection node_1a; +INSERT INTO t1 VALUES (1); +connection node_1; +wsrep_last_committed_id_match +1 +SET AUTOCOMMIT=OFF; +START TRANSACTION; +SELECT WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1'; +WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1' +1 +INSERT INTO t1 VALUES (1); +SELECT WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1'; +WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1' +1 +wsrep_last_committed_id_match +1 +COMMIT; +wsrep_last_committed_id_advanced +1 +wsrep_last_committed_id_advanced +1 +SET AUTOCOMMIT=ON; +DROP TABLE t1; diff --git a/mysql-test/suite/galera/r/galera_sync_wait_upto.result b/mysql-test/suite/galera/r/galera_sync_wait_upto.result new file mode 100644 index 00000000000..7d691e105da --- /dev/null +++ b/mysql-test/suite/galera/r/galera_sync_wait_upto.result @@ -0,0 +1,43 @@ +connection node_2; +connection node_1; +CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +SELECT WSREP_SYNC_WAIT_UPTO_GTID(NULL); +ERROR HY000: Incorrect arguments to wsrep_sync_wait_upto_gtid +SELECT WSREP_SYNC_WAIT_UPTO_GTID('a'); +ERROR HY000: Incorrect arguments to wsrep_sync_wait_upto_gtid +SELECT WSREP_SYNC_WAIT_UPTO_GTID(2); +ERROR HY000: Incorrect arguments to wsrep_sync_wait_upto_gtid +WSREP_SYNC_WAIT_UPTO +1 +WSREP_SYNC_WAIT_UPTO +1 +WSREP_SYNC_WAIT_UPTO +1 +ERROR HY000: Lock wait timeout exceeded; try restarting transaction +connection node_2; +SET GLOBAL DEBUG_DBUG = "d,sync.wsrep_apply_cb"; +connection node_1; +INSERT INTO t1 VALUES (2); +INSERT INTO t1 VALUES (3); +connection node_2; +SET SESSION wsrep_sync_wait = 0; +ERROR HY000: Lock wait timeout exceeded; try restarting transaction +connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2; +connection node_2a; +SET SESSION wsrep_sync_wait = 0; +SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb"; +connection node_2; +WSREP_SYNC_WAIT_UPTO +1 +gtid_current = gtid_first +1 +SET GLOBAL DEBUG_DBUG = ""; +SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb"; +WSREP_SYNC_WAIT_UPTO +1 +seqno_current = seqno_second +1 +SET DEBUG_SYNC = "RESET"; +connection node_1; +DROP TABLE t1; diff --git a/mysql-test/suite/galera/t/galera_last_committed_id.test b/mysql-test/suite/galera/t/galera_last_committed_id.test new file mode 100644 index 00000000000..550838cdcd9 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_last_committed_id.test @@ -0,0 +1,68 @@ +# +# Tests functions WSREP_LAST_WRITTEN_GTID and WSREP_LAST_SEEN_GTID +# + +--source include/galera_cluster.inc + +# Returns -1 if no transactions have been run + +SELECT WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1'; + +--disable_query_log +--let $seqno = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--let $state = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_state_uuid'` +--eval SELECT WSREP_LAST_SEEN_GTID() = '$state:$seqno' AS wsrep_last_committed_id_match; +--enable_query_log + +# WSREP_LAST_WRITTEN_GTID() should not be influenced by transactions committed +# on other connections + +--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 +--connection node_1a +CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); + +--connection node_1 +SELECT WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1'; + +# WSREP_LAST_SEEN_GTID() should be influenced by transactions committed +# on other connections + +--connection node_1a +INSERT INTO t1 VALUES (1); +--disable_query_log +--let $wsrep_last_committed_id_conn_1a = `SELECT WSREP_LAST_SEEN_GTID()` +--enable_query_log + +--connection node_1 +--disable_query_log +--eval SELECT WSREP_LAST_SEEN_GTID() = '$wsrep_last_committed_id_conn_1a' AS wsrep_last_committed_id_match; +--enable_query_log + +# Should not advance while a transaction is in progress + +SET AUTOCOMMIT=OFF; +START TRANSACTION; +SELECT WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1'; + +--disable_query_log +--let $wsrep_last_committed_id_before = `SELECT WSREP_LAST_SEEN_GTID()` +--enable_query_log +INSERT INTO t1 VALUES (1); +SELECT WSREP_LAST_WRITTEN_GTID() = '00000000-0000-0000-0000-000000000000:-1'; +--disable_query_log +--eval SELECT WSREP_LAST_SEEN_GTID() = '$wsrep_last_committed_id_before' AS wsrep_last_committed_id_match; +--enable_query_log + +# Should only advance after the transaction has been committed + +COMMIT; +--disable_query_log +--let $seqno = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--let $state = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_state_uuid'` +--eval SELECT WSREP_LAST_WRITTEN_GTID() = '$state:$seqno' AS wsrep_last_committed_id_advanced; +--eval SELECT WSREP_LAST_SEEN_GTID() = '$state:$seqno' AS wsrep_last_committed_id_advanced; +--enable_query_log +SET AUTOCOMMIT=ON; + +DROP TABLE t1; diff --git a/mysql-test/suite/galera/t/galera_sync_wait_upto-master.opt b/mysql-test/suite/galera/t/galera_sync_wait_upto-master.opt new file mode 100644 index 00000000000..0b35236062b --- /dev/null +++ b/mysql-test/suite/galera/t/galera_sync_wait_upto-master.opt @@ -0,0 +1 @@ +--wsrep-sync-wait=0 --wsrep-causal-reads=OFF \ No newline at end of file diff --git a/mysql-test/suite/galera/t/galera_sync_wait_upto.test b/mysql-test/suite/galera/t/galera_sync_wait_upto.test new file mode 100644 index 00000000000..32c6b590c84 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_sync_wait_upto.test @@ -0,0 +1,115 @@ +# +# Tests the wsrep_sync_wait_upto variable. +# + +--source include/galera_cluster.inc +--source include/have_debug_sync.inc + +CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); + + +# Test with invalid values + +--error ER_WRONG_ARGUMENTS +SELECT WSREP_SYNC_WAIT_UPTO_GTID(NULL); + +--error ER_WRONG_ARGUMENTS +SELECT WSREP_SYNC_WAIT_UPTO_GTID('a'); + +--error ER_WRONG_ARGUMENTS +SELECT WSREP_SYNC_WAIT_UPTO_GTID(2); + + +# If set to low value, expect no waiting + +--disable_query_log +--let $seqno = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--let $state = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_state_uuid'` +--enable_query_log + +--disable_query_log +--eval SELECT WSREP_SYNC_WAIT_UPTO_GTID('00000000-0000-0000-0000-000000000000:-1') AS WSREP_SYNC_WAIT_UPTO; +--enable_query_log + +--disable_query_log +--eval SELECT WSREP_SYNC_WAIT_UPTO_GTID('$state:0') AS WSREP_SYNC_WAIT_UPTO; +--enable_query_log + + +# If set to current last_committed value + +--disable_query_log +--eval SELECT WSREP_SYNC_WAIT_UPTO_GTID('$state:$seqno') AS WSREP_SYNC_WAIT_UPTO; +--enable_query_log + + +# If set to very high value, will wait + +--disable_query_log +--error ER_LOCK_WAIT_TIMEOUT +--eval SELECT WSREP_SYNC_WAIT_UPTO_GTID('$state:9223372036854775807', 1) AS WSREP_SYNC_WAIT_UPTO; +--enable_query_log + + +# If applier is blocked, will wait + +--connection node_2 +SET GLOBAL DEBUG_DBUG = "d,sync.wsrep_apply_cb"; + + +--connection node_1 +# Perform two inserts and record the IDs of each +INSERT INTO t1 VALUES (2); +--let $gtid_first = `SELECT WSREP_LAST_WRITTEN_GTID()` + +INSERT INTO t1 VALUES (3); +--let $gtid_second = `SELECT WSREP_LAST_WRITTEN_GTID()` + +--connection node_2 +SET SESSION wsrep_sync_wait = 0; + +--disable_query_log +--error ER_LOCK_WAIT_TIMEOUT +--eval SELECT WSREP_SYNC_WAIT_UPTO_GTID('$gtid_first', 1) AS WSREP_SYNC_WAIT_UPTO; +--enable_query_log + +--disable_query_log +--send_eval SELECT WSREP_SYNC_WAIT_UPTO_GTID('$gtid_first') AS WSREP_SYNC_WAIT_UPTO; +--enable_query_log + +# Unblock applier +--connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2 +--connection node_2a +SET SESSION wsrep_sync_wait = 0; +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE 'SELECT WSREP_SYNC_WAIT%'; +--source include/wait_condition.inc +SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb"; + +--connection node_2 +--reap + +# Confirm that we were allowed to proceed when the applier reached $seqno_first +--let $gtid_current = `SELECT WSREP_LAST_SEEN_GTID()` +--disable_query_log +--eval SELECT '$gtid_current' = '$gtid_first' AS `gtid_current = gtid_first` +--enable_query_log + +SET GLOBAL DEBUG_DBUG = ""; +SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb"; + +# Move forward some more, to $seqno_second; + +--disable_query_log +--eval SELECT WSREP_SYNC_WAIT_UPTO_GTID('$gtid_second') AS WSREP_SYNC_WAIT_UPTO; +--enable_query_log + +--let $gtid_current = `SELECT WSREP_LAST_SEEN_GTID()` +--disable_query_log +--eval SELECT '$gtid_current' = '$gtid_second' AS `seqno_current = seqno_second` +--enable_query_log + +SET DEBUG_SYNC = "RESET"; + +--connection node_1 +DROP TABLE t1; From 9cb55143ac78c8c0dc4781883bd24ee9284dbbce Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 18 Feb 2019 17:11:20 +0530 Subject: [PATCH 13/19] Minor cleanup in the optimizer trace code. More test coverage added for the optimizer trace. --- mysql-test/main/opt_trace.result | 2893 +++++++++++++++-- mysql-test/main/opt_trace.test | 41 + mysql-test/main/opt_trace_index_merge.result | 10 +- .../main/opt_trace_index_merge_innodb.result | 10 +- mysql-test/main/opt_trace_security.result | 18 +- sql/my_json_writer.cc | 20 +- sql/my_json_writer.h | 20 +- sql/opt_range.cc | 105 +- sql/opt_subselect.cc | 77 +- sql/opt_table_elimination.cc | 23 +- sql/opt_trace.cc | 160 +- sql/opt_trace.h | 15 +- sql/opt_trace_context.h | 15 +- sql/sql_class.cc | 2 +- sql/sql_derived.cc | 43 +- sql/sql_select.cc | 44 +- sql/sql_test.cc | 10 +- 17 files changed, 3037 insertions(+), 469 deletions(-) diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index dab96903f37..4c3e2b33cf2 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -45,7 +45,7 @@ select * from v1 { "view": { "table": "v1", "select_id": 2, - "merged": true + "algorithm": "merged" } }, { @@ -53,13 +53,13 @@ select * from v1 { "select_id": 2, "steps": [ { - "expanded_query": "/* select#2 */ select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` where `t1`.`a` = 1" + "expanded_query": "/* select#2 */ select t1.a AS a,t1.b AS b from t1 where t1.a = 1" } ] } }, { - "expanded_query": "/* select#1 */ select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `v1`" + "expanded_query": "/* select#1 */ select t1.a AS a,t1.b AS b from v1" } ] } @@ -108,9 +108,10 @@ select * from v1 { "selectivity_for_columns": [ { "column_name": "a", - "selectivity_from_histograms": 0.5 + "selectivity_from_histogram": 0.5 } - ] + ], + "cond_selectivity": 0.5 }, { "table": "t1", @@ -121,11 +122,6 @@ select * from v1 { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -182,7 +178,7 @@ select * from (select * from t1 where t1.a=1)q { "derived": { "table": "q", "select_id": 2, - "merged": true + "algorithm": "merged" } }, { @@ -190,13 +186,13 @@ select * from (select * from t1 where t1.a=1)q { "select_id": 2, "steps": [ { - "expanded_query": "/* select#2 */ select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` where `t1`.`a` = 1" + "expanded_query": "/* select#2 */ select t1.a AS a,t1.b AS b from t1 where t1.a = 1" } ] } }, { - "expanded_query": "/* select#1 */ select `t1`.`a` AS `a`,`t1`.`b` AS `b` from (/* select#2 */ select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` where `t1`.`a` = 1) `q`" + "expanded_query": "/* select#1 */ select t1.a AS a,t1.b AS b from (/* select#2 */ select t1.a AS a,t1.b AS b from t1 where t1.a = 1) q" } ] } @@ -245,9 +241,10 @@ select * from (select * from t1 where t1.a=1)q { "selectivity_for_columns": [ { "column_name": "a", - "selectivity_from_histograms": 0.5 + "selectivity_from_histogram": 0.5 } - ] + ], + "cond_selectivity": 0.5 }, { "table": "t1", @@ -258,11 +255,6 @@ select * from (select * from t1 where t1.a=1)q { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -320,7 +312,7 @@ select * from v2 { "view": { "table": "v2", "select_id": 2, - "materialized": true + "algorithm": "materialized" } }, { @@ -328,13 +320,13 @@ select * from v2 { "select_id": 2, "steps": [ { - "expanded_query": "/* select#2 */ select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` where `t1`.`a` = 1 group by `t1`.`b`" + "expanded_query": "/* select#2 */ select t1.a AS a,t1.b AS b from t1 where t1.a = 1 group by t1.b" } ] } }, { - "expanded_query": "/* select#1 */ select `v2`.`a` AS `a`,`v2`.`b` AS `b` from `v2`" + "expanded_query": "/* select#1 */ select v2.a AS a,v2.b AS b from v2" } ] } @@ -387,9 +379,10 @@ select * from v2 { "selectivity_for_columns": [ { "column_name": "a", - "selectivity_from_histograms": 0.5 + "selectivity_from_histogram": 0.5 } - ] + ], + "cond_selectivity": 0.5 }, { "table": "t1", @@ -400,11 +393,6 @@ select * from v2 { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -460,11 +448,6 @@ select * from v2 { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -548,7 +531,7 @@ explain select * from v2 { "view": { "table": "v2", "select_id": 2, - "merged": true + "algorithm": "merged" } }, { @@ -556,13 +539,13 @@ explain select * from v2 { "select_id": 2, "steps": [ { - "expanded_query": "/* select#2 */ select `t2`.`a` AS `a` from `t2`" + "expanded_query": "/* select#2 */ select t2.a AS a from t2" } ] } }, { - "expanded_query": "/* select#1 */ select `t2`.`a` AS `a` from `v2`" + "expanded_query": "/* select#1 */ select t2.a AS a from v2" } ] } @@ -592,11 +575,6 @@ explain select * from v2 { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -655,7 +633,7 @@ explain select * from v1 { "view": { "table": "v1", "select_id": 2, - "materialized": true + "algorithm": "materialized" } }, { @@ -663,13 +641,13 @@ explain select * from v1 { "select_id": 2, "steps": [ { - "expanded_query": "/* select#2 */ select `t1`.`a` AS `a` from `t1` group by `t1`.`b`" + "expanded_query": "/* select#2 */ select t1.a AS a from t1 group by t1.b" } ] } }, { - "expanded_query": "/* select#1 */ select `v1`.`a` AS `a` from `v1`" + "expanded_query": "/* select#1 */ select v1.a AS a from v1" } ] } @@ -703,11 +681,6 @@ explain select * from v1 { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -763,11 +736,6 @@ explain select * from v1 { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -848,7 +816,7 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { "select_id": 1, "steps": [ { - "expanded_query": "select `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c`,`t2`.`a` AS `a`,`t2`.`b` AS `b`,`t2`.`c` AS `c` from `t1` join `t2` where `t1`.`a` = `t2`.`b` + 2 and `t2`.`a` = `t1`.`b`" + "expanded_query": "select t1.a AS a,t1.b AS b,t1.c AS c,t2.a AS a,t2.b AS b,t2.c AS c from t1 join t2 where t1.a = t2.b + 2 and t2.a = t1.b" } ] } @@ -927,11 +895,6 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -1063,7 +1026,7 @@ EXPLAIN SELECT DISTINCT a FROM t1 { "select_id": 1, "steps": [ { - "expanded_query": "select distinct `t1`.`a` AS `a` from `t1`" + "expanded_query": "select distinct t1.a AS a from t1" } ] } @@ -1122,7 +1085,7 @@ EXPLAIN SELECT DISTINCT a FROM t1 { "best_group_range_summary": { "type": "index_group", "index": "a", - "group_attribute": null, + "min_max_arg": null, "min_aggregate": false, "max_aggregate": false, "distinct_aggregate": false, @@ -1136,7 +1099,7 @@ EXPLAIN SELECT DISTINCT a FROM t1 { "range_access_plan": { "type": "index_group", "index": "a", - "group_attribute": null, + "min_max_arg": null, "min_aggregate": false, "max_aggregate": false, "distinct_aggregate": false, @@ -1153,11 +1116,6 @@ EXPLAIN SELECT DISTINCT a FROM t1 { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -1221,7 +1179,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "select_id": 1, "steps": [ { - "expanded_query": "select min(`t1`.`d`) AS `MIN(d)` from `t1` where `t1`.`b` = 2 and `t1`.`c` = 3 group by `t1`.`a`" + "expanded_query": "select min(t1.d) AS `MIN(d)` from t1 where t1.b = 2 and t1.c = 3 group by t1.a" } ] } @@ -1299,7 +1257,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "best_group_range_summary": { "type": "index_group", "index": "a", - "group_attribute": "d", + "min_max_arg": "d", "min_aggregate": true, "max_aggregate": false, "distinct_aggregate": false, @@ -1324,21 +1282,17 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "selectivity_for_columns": [ { "column_name": "b", - "selectivity_from_histograms": 0.2891 + "selectivity_from_histogram": 0.2891 }, { "column_name": "c", - "selectivity_from_histograms": 0.2891 + "selectivity_from_histogram": 0.2891 } - ] + ], + "cond_selectivity": 0.0836 } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -1423,7 +1377,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id { "select_id": 1, "steps": [ { - "expanded_query": "select `t1`.`id` AS `id`,min(`t1`.`a`) AS `MIN(a)`,max(`t1`.`a`) AS `MAX(a)` from `t1` where `t1`.`a` >= 20010104e0 group by `t1`.`id`" + "expanded_query": "select t1.`id` AS `id`,min(t1.a) AS `MIN(a)`,max(t1.a) AS `MAX(a)` from t1 where t1.a >= 20010104e0 group by t1.`id`" } ] } @@ -1501,7 +1455,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id { "best_group_range_summary": { "type": "index_group", "index": "id", - "group_attribute": "a", + "min_max_arg": "a", "min_aggregate": true, "max_aggregate": true, "distinct_aggregate": false, @@ -1523,15 +1477,11 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id { }, { "selectivity_for_indexes": [], - "selectivity_for_columns": [] + "selectivity_for_columns": [], + "cond_selectivity": 1 } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -1605,7 +1555,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id { "select_id": 1, "steps": [ { - "expanded_query": "select `t1`.`id` AS `id`,`t1`.`a` AS `a` from `t1` where `t1`.`a` = 20010104e0 group by `t1`.`id`" + "expanded_query": "select t1.`id` AS `id`,t1.a AS a from t1 where t1.a = 20010104e0 group by t1.`id`" } ] } @@ -1683,7 +1633,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id { "best_group_range_summary": { "type": "index_group", "index": "id", - "group_attribute": null, + "min_max_arg": null, "min_aggregate": false, "max_aggregate": false, "distinct_aggregate": false, @@ -1705,15 +1655,11 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id { }, { "selectivity_for_indexes": [], - "selectivity_for_columns": [] + "selectivity_for_columns": [], + "cond_selectivity": 1 } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -1814,7 +1760,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "select_id": 1, "steps": [ { - "expanded_query": "select `t1`.`pk` AS `pk`,`t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c`,`t1`.`filler` AS `filler` from `t1` where `t1`.`a` = 1 and `t1`.`b` = 2 order by `t1`.`c` limit 1" + "expanded_query": "select t1.pk AS pk,t1.a AS a,t1.b AS b,t1.c AS c,t1.filler AS filler from t1 where t1.a = 1 and t1.b = 2 order by t1.c limit 1" } ] } @@ -1957,21 +1903,17 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "selectivity_for_columns": [ { "column_name": "a", - "selectivity_from_histograms": 0.1797 + "selectivity_from_histogram": 0.1797 }, { "column_name": "b", - "selectivity_from_histograms": 0.0156 + "selectivity_from_histogram": 0.0156 } - ] + ], + "cond_selectivity": 0.021 } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -2160,7 +2102,7 @@ select t1.a from t1 left join t2 on t1.a=t2.a { "select_id": 1, "steps": [ { - "expanded_query": "select `t1`.`a` AS `a` from (`t1` left join `t2` on(`t1`.`a` = `t2`.`a`))" + "expanded_query": "select t1.a AS a from (t1 left join t2 on(t1.a = t2.a))" } ] } @@ -2215,11 +2157,6 @@ select t1.a from t1 left join t2 on t1.a=t2.a { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -2278,7 +2215,7 @@ explain select * from t1 left join t2 on t2.a=t1.a { "select_id": 1, "steps": [ { - "expanded_query": "select `t1`.`a` AS `a`,`t2`.`a` AS `a`,`t2`.`b` AS `b` from (`t1` left join `t2` on(`t2`.`a` = `t1`.`a`))" + "expanded_query": "select t1.a AS a,t2.a AS a,t2.b AS b from (t1 left join t2 on(t2.a = t1.a))" } ] } @@ -2334,11 +2271,6 @@ explain select * from t1 left join t2 on t2.a=t1.a { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -2423,7 +2355,7 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and "select_id": 1, "steps": [ { - "expanded_query": "select `t1`.`a` AS `a` from (`t1` left join (`t2` join `t3` on(`t2`.`b` = `t3`.`b`)) on(`t2`.`a` = `t1`.`a` and `t3`.`a` = `t1`.`a`))" + "expanded_query": "select t1.a AS a from (t1 left join (t2 join t3 on(t2.b = t3.b)) on(t2.a = t1.a and t3.a = t1.a))" } ] } @@ -2508,11 +2440,6 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -2615,13 +2542,13 @@ explain extended select * from t1 where a in (select pk from t10) { } }, { - "expanded_query": "/* select#2 */ select `t10`.`pk` from `t10`" + "expanded_query": "/* select#2 */ select t10.pk from t10" } ] } }, { - "expanded_query": "/* select#1 */ select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` where `t1`.`a` in (/* select#2 */ select `t10`.`pk` from `t10`)" + "expanded_query": "/* select#1 */ select t1.a AS a,t1.b AS b from t1 where t1.a in (/* select#2 */ select t10.pk from t10)" } ] } @@ -2768,6 +2695,18 @@ explain extended select * from t1 where a in (select pk from t10) { } ] }, + { + "fix_semijoin_strategies_for_picked_join_order": [ + { + "semi_join_strategy": "sj_materialize", + "join_order": [ + { + "table": "t10" + } + ] + } + ] + }, { "condition_on_constant_tables": "1" }, @@ -2837,7 +2776,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "select_id": 1, "steps": [ { - "expanded_query": "select `t1`.`pk` AS `pk`,`t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` where `t1`.`pk` = 2 and `t1`.`a` = 5 and `t1`.`b` = 1" + "expanded_query": "select t1.pk AS pk,t1.a AS a,t1.b AS b from t1 where t1.pk = 2 and t1.a = 5 and t1.b = 1" } ] } @@ -3043,21 +2982,17 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "selectivity_for_columns": [ { "column_name": "a", - "selectivity_from_histograms": 0.1 + "selectivity_from_histogram": 0.1 }, { "column_name": "b", - "selectivity_from_histograms": 0.1 + "selectivity_from_histogram": 0.1 } - ] + ], + "cond_selectivity": 0.1 } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -3164,7 +3099,7 @@ select f1(a) from t1 { "select_id": 1, "steps": [ { - "expanded_query": "select `f1`(`t1`.`a`) AS `f1(a)` from `t1`" + "expanded_query": "select f1(t1.a) AS `f1(a)` from t1" } ] } @@ -3194,11 +3129,6 @@ select f1(a) from t1 { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -3255,7 +3185,7 @@ select f2(a) from t1 { "select_id": 1, "steps": [ { - "expanded_query": "select `f2`(`t1`.`a`) AS `f2(a)` from `t1`" + "expanded_query": "select f2(t1.a) AS `f2(a)` from t1" } ] } @@ -3285,11 +3215,6 @@ select f2(a) from t1 { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -3348,7 +3273,7 @@ a 2 select length(trace) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; length(trace) -1889 +1754 set optimizer_trace_max_mem_size=100; select * from t1; a @@ -3362,7 +3287,7 @@ select * from t1 { "join_preparation": { "select_id": 1, "steps": [ - 1789 0 + 1654 0 set optimizer_trace_max_mem_size=0; select * from t1; a @@ -3370,7 +3295,7 @@ a 2 select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES -select * from t1 1889 0 +select * from t1 1754 0 drop table t1; set optimizer_trace='enabled=off'; set @@optimizer_trace_max_mem_size= @save_optimizer_trace_max_mem_size; @@ -3444,6 +3369,7 @@ set optimizer_trace='enabled=off'; # # MDEV-18528: Optimizer trace support for multi-table UPDATE and DELETE # +set optimizer_trace=1; create table ten(a int); insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t0 (a int, b int); @@ -3457,55 +3383,2642 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref a a 5 test.t0.a 1 select * from information_schema.optimizer_trace; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES -explain delete from t0 where t0.a<3 { +explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "steps": [ { - "table": "t0", - "range_analysis": { - "table_scan": { - "rows": 10, - "cost": 6.122 - }, - "potential_range_indexes": [ + "join_preparation": { + "select_id": 1, + "steps": [ { - "index": "a", - "usable": true, - "key_parts": ["a"] + "expanded_query": "select NULL AS `NULL` from t0 join t1 where t0.a = t1.a and t1.a < 3" } - ], - "setup_range_conditions": [], - "group_index_range": { - "chosen": false, - "cause": "no join" - }, - "analyzing_range_alternatives": { - "range_scan_alternatives": [ - { - "index": "a", - "ranges": ["NULL < a < 3"], - "rowid_ordered": false, - "using_mrr": false, - "index_only": false, - "rows": 3, - "cost": 5.007, - "chosen": true + ] + } + }, + { + "join_optimization": { + "select_id": 1, + "steps": [ + { + "condition_processing": { + "condition": "WHERE", + "original_condition": "t0.a = t1.a and t1.a < 3", + "steps": [ + { + "transformation": "equality_propagation", + "resulting_condition": "t1.a < 3 and multiple equal(t0.a, t1.a)" + }, + { + "transformation": "constant_propagation", + "resulting_condition": "t1.a < 3 and multiple equal(t0.a, t1.a)" + }, + { + "transformation": "trivial_condition_removal", + "resulting_condition": "t1.a < 3 and multiple equal(t0.a, t1.a)" + } + ] } - ], - "analyzing_index_merge_union": [] - }, - "chosen_range_access_summary": { - "range_access_plan": { - "type": "range_scan", - "index": "a", - "rows": 3, - "ranges": ["NULL < a < 3"] }, - "rows_for_plan": 3, - "cost_for_plan": 5.007, - "chosen": true - } + { + "table_dependencies": [ + { + "table": "t0", + "row_may_be_null": false, + "map_bit": 0, + "depends_on_map_bits": [] + }, + { + "table": "t1", + "row_may_be_null": false, + "map_bit": 1, + "depends_on_map_bits": [] + } + ] + }, + { + "ref_optimizer_key_uses": [ + { + "table": "t0", + "field": "a", + "equals": "t1.a", + "null_rejecting": true + }, + { + "table": "t1", + "field": "a", + "equals": "t0.a", + "null_rejecting": true + } + ] + }, + { + "rows_estimation": [ + { + "table": "t0", + "range_analysis": { + "table_scan": { + "rows": 10, + "cost": 6.122 + }, + "potential_range_indexes": [ + { + "index": "a", + "usable": true, + "key_parts": ["a"] + } + ], + "best_covering_index_scan": { + "index": "a", + "cost": 1.5234, + "chosen": true + }, + "setup_range_conditions": [], + "group_index_range": { + "chosen": false, + "cause": "not single_table" + }, + "analyzing_range_alternatives": { + "range_scan_alternatives": [ + { + "index": "a", + "ranges": ["NULL < a < 3"], + "rowid_ordered": false, + "using_mrr": false, + "index_only": true, + "rows": 3, + "cost": 1.407, + "chosen": true + } + ], + "analyzing_roworder_intersect": { + "cause": "too few roworder scans" + }, + "analyzing_index_merge_union": [] + }, + "chosen_range_access_summary": { + "range_access_plan": { + "type": "range_scan", + "index": "a", + "rows": 3, + "ranges": ["NULL < a < 3"] + }, + "rows_for_plan": 3, + "cost_for_plan": 1.407, + "chosen": true + } + } + }, + { + "selectivity_for_indexes": [ + { + "index_name": "a", + "selectivity_from_index": 0.3 + } + ], + "selectivity_for_columns": [], + "cond_selectivity": 0.3 + }, + { + "table": "t1", + "range_analysis": { + "table_scan": { + "rows": 10, + "cost": 6.122 + }, + "potential_range_indexes": [ + { + "index": "a", + "usable": true, + "key_parts": ["a"] + } + ], + "best_covering_index_scan": { + "index": "a", + "cost": 1.5234, + "chosen": true + }, + "setup_range_conditions": [], + "group_index_range": { + "chosen": false, + "cause": "not single_table" + }, + "analyzing_range_alternatives": { + "range_scan_alternatives": [ + { + "index": "a", + "ranges": ["NULL < a < 3"], + "rowid_ordered": false, + "using_mrr": false, + "index_only": true, + "rows": 3, + "cost": 1.407, + "chosen": true + } + ], + "analyzing_roworder_intersect": { + "cause": "too few roworder scans" + }, + "analyzing_index_merge_union": [] + }, + "chosen_range_access_summary": { + "range_access_plan": { + "type": "range_scan", + "index": "a", + "rows": 3, + "ranges": ["NULL < a < 3"] + }, + "rows_for_plan": 3, + "cost_for_plan": 1.407, + "chosen": true + } + } + }, + { + "selectivity_for_indexes": [ + { + "index_name": "a", + "selectivity_from_index": 0.3 + } + ], + "selectivity_for_columns": [], + "cond_selectivity": 0.3 + } + ] + }, + { + "considered_execution_plans": [ + { + "plan_prefix": [], + "table": "t0", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "range", + "resulting_rows": 3, + "cost": 1.407, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t0"], + "table": "t1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "ref", + "index": "a", + "used_range_estimates": false, + "cause": "not better than ref estimates", + "rows": 1, + "cost": 3.007, + "chosen": true + }, + { + "type": "scan", + "chosen": false, + "cause": "cost" + } + ] + } + } + ] + }, + { + "plan_prefix": [], + "table": "t1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "range", + "resulting_rows": 3, + "cost": 1.407, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t1"], + "table": "t0", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "ref", + "index": "a", + "used_range_estimates": false, + "cause": "not better than ref estimates", + "rows": 2, + "cost": 3.014, + "chosen": true + }, + { + "type": "scan", + "chosen": false, + "cause": "cost" + } + ] + }, + "pruned_by_cost": true + } + ] + } + ] + }, + { + "attaching_conditions_to_tables": { + "original_condition": "t1.a = t0.a and t0.a < 3", + "attached_conditions_computation": [], + "attached_conditions_summary": [ + { + "table": "t0", + "attached": "t0.a < 3 and t0.a is not null" + }, + { + "table": "t1", + "attached": null + } + ] + } + } + ] + } + }, + { + "join_execution": { + "select_id": 1, + "steps": [] } } ] } 0 0 drop table ten,t0,t1; +set optimizer_trace='enabled=off'; +# +# Merged to Materialized for derived tables +# +set optimizer_trace=1; +create table t1 (a int); +insert into t1 values (1),(2),(3); +explain select * from (select rand() from t1)q; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 3 +2 DERIVED t1 ALL NULL NULL NULL NULL 3 +select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; +QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES +explain select * from (select rand() from t1)q { + "steps": [ + { + "join_preparation": { + "select_id": 1, + "steps": [ + { + "derived": { + "table": "q", + "select_id": 2, + "algorithm": "merged" + } + }, + { + "join_preparation": { + "select_id": 2, + "steps": [ + { + "expanded_query": "/* select#2 */ select rand() AS `rand()` from t1" + } + ] + } + }, + { + "expanded_query": "/* select#1 */ select rand() AS `rand()` from (/* select#2 */ select rand() AS `rand()` from t1) q" + } + ] + } + }, + { + "join_optimization": { + "select_id": 1, + "steps": [ + { + "derived": { + "table": "q", + "select_id": 2, + "algorithm": "materialized", + "cause": "Random function in the select" + } + }, + { + "join_optimization": { + "select_id": 2, + "steps": [ + { + "table_dependencies": [ + { + "table": "t1", + "row_may_be_null": false, + "map_bit": 0, + "depends_on_map_bits": [] + } + ] + }, + { + "rows_estimation": [ + { + "table": "t1", + "table_scan": { + "rows": 3, + "cost": 2.0051 + } + } + ] + }, + { + "considered_execution_plans": [ + { + "plan_prefix": [], + "table": "t1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + } + } + ] + }, + { + "attaching_conditions_to_tables": { + "original_condition": null, + "attached_conditions_computation": [], + "attached_conditions_summary": [ + { + "table": "t1", + "attached": null + } + ] + } + } + ] + } + }, + { + "table_dependencies": [ + { + "table": "", + "row_may_be_null": false, + "map_bit": 0, + "depends_on_map_bits": [] + } + ] + }, + { + "rows_estimation": [ + { + "table": "", + "table_scan": { + "rows": 3, + "cost": 3 + } + } + ] + }, + { + "considered_execution_plans": [ + { + "plan_prefix": [], + "table": "", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 3, + "chosen": true + } + ] + } + } + ] + }, + { + "attaching_conditions_to_tables": { + "original_condition": null, + "attached_conditions_computation": [], + "attached_conditions_summary": [ + { + "table": "", + "attached": null + } + ] + } + } + ] + } + }, + { + "join_execution": { + "select_id": 1, + "steps": [ + { + "join_execution": { + "select_id": 2, + "steps": [] + } + } + ] + } + } + ] +} 0 0 +drop table t1; +set optimizer_trace='enabled=off'; +# +# Semi-join nest +# +set optimizer_trace=1; +create table t1 (a int); +insert into t1 values (1),(2),(3); +create table t2(a int); +insert into t2 values (1),(2),(3),(1),(2),(3),(1),(2),(3); +set @save_optimizer_switch= @@optimizer_switch; +explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_inner_2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED t_inner_1 ALL NULL NULL NULL NULL 3 +2 MATERIALIZED t_inner_2 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; +QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES +explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_inner_2) { + "steps": [ + { + "join_preparation": { + "select_id": 1, + "steps": [ + { + "join_preparation": { + "select_id": 2, + "steps": [ + { + "transformation": { + "select_id": 2, + "from": "IN (SELECT)", + "to": "materialization", + "sjm_scan_allowed": true, + "possible": true + } + }, + { + "transformation": { + "select_id": 2, + "from": "IN (SELECT)", + "to": "semijoin", + "chosen": true + } + }, + { + "expanded_query": "/* select#2 */ select t_inner_1.a from t1 t_inner_1 join t1 t_inner_2" + } + ] + } + }, + { + "expanded_query": "/* select#1 */ select t1.a AS a from t1 where t1.a in (/* select#2 */ select t_inner_1.a from t1 t_inner_1 join t1 t_inner_2)" + } + ] + } + }, + { + "join_optimization": { + "select_id": 1, + "steps": [ + { + "transformation": { + "select_id": 2, + "from": "IN (SELECT)", + "to": "semijoin", + "converted_to_semi_join": true + } + }, + { + "condition_processing": { + "condition": "WHERE", + "original_condition": "1 and t1.a = t_inner_1.a", + "steps": [ + { + "transformation": "equality_propagation", + "resulting_condition": "1 and multiple equal(t1.a, t_inner_1.a)" + }, + { + "transformation": "constant_propagation", + "resulting_condition": "1 and multiple equal(t1.a, t_inner_1.a)" + }, + { + "transformation": "trivial_condition_removal", + "resulting_condition": "multiple equal(t1.a, t_inner_1.a)" + } + ] + } + }, + { + "table_dependencies": [ + { + "table": "t1", + "row_may_be_null": false, + "map_bit": 0, + "depends_on_map_bits": [] + }, + { + "table": "t_inner_1", + "row_may_be_null": false, + "map_bit": 1, + "depends_on_map_bits": [] + }, + { + "table": "t_inner_2", + "row_may_be_null": false, + "map_bit": 2, + "depends_on_map_bits": [] + } + ] + }, + { + "ref_optimizer_key_uses": [] + }, + { + "rows_estimation": [ + { + "table": "t1", + "table_scan": { + "rows": 3, + "cost": 2.0051 + } + }, + { + "table": "t_inner_1", + "table_scan": { + "rows": 3, + "cost": 2.0051 + } + }, + { + "table": "t_inner_2", + "table_scan": { + "rows": 3, + "cost": 2.0051 + } + } + ] + }, + { + "execution_plan_for_potential_materialization": { + "steps": [ + { + "considered_execution_plans": [ + { + "plan_prefix": [], + "table": "t_inner_1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_inner_1"], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + } + } + ] + }, + { + "plan_prefix": [], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + } + ] + } + }, + { + "considered_execution_plans": [ + { + "plan_prefix": [], + "table": "t1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t1"], + "table": "t_inner_1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t1", "t_inner_1"], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + } + } + ] + }, + { + "plan_prefix": ["t1"], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "plan_prefix": [], + "table": "t_inner_1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": [], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "fix_semijoin_strategies_for_picked_join_order": [ + { + "semi_join_strategy": "sj_materialize", + "join_order": [ + { + "table": "t_inner_1" + }, + { + "table": "t_inner_2" + } + ] + } + ] + }, + { + "condition_on_constant_tables": "1" + }, + { + "attaching_conditions_to_tables": { + "original_condition": "1", + "attached_conditions_computation": [], + "attached_conditions_summary": [ + { + "table": "t1", + "attached": null + }, + { + "table": "t_inner_1", + "attached": null + }, + { + "table": "t_inner_2", + "attached": null + }, + { + "table": "", + "attached": null + } + ] + } + } + ] + } + }, + { + "join_execution": { + "select_id": 1, + "steps": [] + } + } + ] +} 0 0 +# with Firstmatch, mostly for tracing fix_semijoin_strategies_for_picked_join_order +set optimizer_switch='materialization=off'; +explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and +t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t_outer_1 ALL NULL NULL NULL NULL 3 +1 PRIMARY t_inner_1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t_inner_2 ALL NULL NULL NULL NULL 9 FirstMatch(t_outer_1); Using join buffer (incremental, BNL join) +1 PRIMARY t_outer_2 ALL NULL NULL NULL NULL 9 Using join buffer (incremental, BNL join) +1 PRIMARY t_inner_4 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +1 PRIMARY t_inner_3 ALL NULL NULL NULL NULL 9 Using where; FirstMatch(t_outer_2); Using join buffer (incremental, BNL join) +select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; +QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES +explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and +t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { + "steps": [ + { + "join_preparation": { + "select_id": 1, + "steps": [ + { + "join_preparation": { + "select_id": 2, + "steps": [ + { + "transformation": { + "select_id": 2, + "from": "IN (SELECT)", + "to": "materialization", + "sjm_scan_allowed": true, + "possible": true + } + }, + { + "transformation": { + "select_id": 2, + "from": "IN (SELECT)", + "to": "semijoin", + "chosen": true + } + }, + { + "expanded_query": "/* select#2 */ select t_inner_1.a from t2 t_inner_2 join t1 t_inner_1" + } + ] + } + }, + { + "join_preparation": { + "select_id": 3, + "steps": [ + { + "transformation": { + "select_id": 3, + "from": "IN (SELECT)", + "to": "materialization", + "sjm_scan_allowed": true, + "possible": true + } + }, + { + "transformation": { + "select_id": 3, + "from": "IN (SELECT)", + "to": "semijoin", + "chosen": true + } + }, + { + "expanded_query": "/* select#3 */ select t_inner_3.a from t2 t_inner_3 join t1 t_inner_4" + } + ] + } + }, + { + "expanded_query": "/* select#1 */ select t_outer_1.a AS a,t_outer_2.a AS a from t1 t_outer_1 join t2 t_outer_2 where t_outer_1.a in (/* select#2 */ select t_inner_1.a from t2 t_inner_2 join t1 t_inner_1) and t_outer_2.a in (/* select#3 */ select t_inner_3.a from t2 t_inner_3 join t1 t_inner_4)" + } + ] + } + }, + { + "join_optimization": { + "select_id": 1, + "steps": [ + { + "transformation": { + "select_id": 2, + "from": "IN (SELECT)", + "to": "semijoin", + "converted_to_semi_join": true + } + }, + { + "transformation": { + "select_id": 3, + "from": "IN (SELECT)", + "to": "semijoin", + "converted_to_semi_join": true + } + }, + { + "condition_processing": { + "condition": "WHERE", + "original_condition": "1 and 1 and t_outer_1.a = t_inner_1.a and t_outer_2.a = t_inner_3.a", + "steps": [ + { + "transformation": "equality_propagation", + "resulting_condition": "1 and 1 and multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" + }, + { + "transformation": "constant_propagation", + "resulting_condition": "1 and 1 and multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" + }, + { + "transformation": "trivial_condition_removal", + "resulting_condition": "multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" + } + ] + } + }, + { + "table_dependencies": [ + { + "table": "t_outer_1", + "row_may_be_null": false, + "map_bit": 0, + "depends_on_map_bits": [] + }, + { + "table": "t_outer_2", + "row_may_be_null": false, + "map_bit": 1, + "depends_on_map_bits": [] + }, + { + "table": "t_inner_2", + "row_may_be_null": false, + "map_bit": 2, + "depends_on_map_bits": [] + }, + { + "table": "t_inner_1", + "row_may_be_null": false, + "map_bit": 3, + "depends_on_map_bits": [] + }, + { + "table": "t_inner_3", + "row_may_be_null": false, + "map_bit": 4, + "depends_on_map_bits": [] + }, + { + "table": "t_inner_4", + "row_may_be_null": false, + "map_bit": 5, + "depends_on_map_bits": [] + } + ] + }, + { + "ref_optimizer_key_uses": [] + }, + { + "rows_estimation": [ + { + "table": "t_outer_1", + "table_scan": { + "rows": 3, + "cost": 2.0051 + } + }, + { + "table": "t_outer_2", + "table_scan": { + "rows": 9, + "cost": 2.0154 + } + }, + { + "table": "t_inner_2", + "table_scan": { + "rows": 9, + "cost": 2.0154 + } + }, + { + "table": "t_inner_1", + "table_scan": { + "rows": 3, + "cost": 2.0051 + } + }, + { + "table": "t_inner_3", + "table_scan": { + "rows": 9, + "cost": 2.0154 + } + }, + { + "table": "t_inner_4", + "table_scan": { + "rows": 3, + "cost": 2.0051 + } + } + ] + }, + { + "execution_plan_for_potential_materialization": { + "steps": [] + } + }, + { + "considered_execution_plans": [ + { + "plan_prefix": [], + "table": "t_outer_1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_outer_1"], + "table": "t_inner_1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_outer_1", "t_inner_1"], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_2", + "t_outer_2" + ], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_2", + "t_outer_2", + "t_inner_4" + ], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + } + } + ] + }, + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_2", + "t_outer_2" + ], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_2", + "t_inner_4" + ], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_2", + "t_inner_4", + "t_outer_2" + ], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + } + ] + }, + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_2", + "t_inner_4" + ], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1"], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_outer_2", + "t_inner_4" + ], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + }, + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_outer_2", + "t_inner_4" + ], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1"], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_4", + "t_outer_2" + ], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + }, + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_4", + "t_outer_2" + ], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1"], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_3"], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_3", + "t_outer_2" + ], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_cost": true + }, + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_3", + "t_outer_2" + ], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_3"], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_3", + "t_inner_4" + ], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + }, + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_3", + "t_inner_4" + ], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_3"], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + } + ] + }, + { + "plan_prefix": ["t_outer_1"], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": ["t_outer_1"], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": ["t_outer_1"], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": ["t_outer_1"], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "plan_prefix": [], + "table": "t_inner_1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": [], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": [], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": [], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": [], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "fix_semijoin_strategies_for_picked_join_order": [ + { + "semi_join_strategy": "firstmatch", + "join_order": [ + { + "table": "t_inner_4" + }, + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 162.42, + "chosen": true + } + ] + }, + { + "table": "t_inner_3" + }, + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 489.74, + "chosen": true + } + ] + } + ] + }, + { + "semi_join_strategy": "firstmatch", + "join_order": [ + { + "table": "t_inner_1" + }, + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 18.046, + "chosen": true + } + ] + }, + { + "table": "t_inner_2" + }, + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 54.415, + "chosen": true + } + ] + } + ] + } + ] + }, + { + "attaching_conditions_to_tables": { + "original_condition": "t_inner_1.a = t_outer_1.a and t_inner_3.a = t_outer_2.a", + "attached_conditions_computation": [], + "attached_conditions_summary": [ + { + "table": "t_outer_1", + "attached": null + }, + { + "table": "t_inner_1", + "attached": "t_inner_1.a = t_outer_1.a" + }, + { + "table": "t_inner_2", + "attached": null + }, + { + "table": "t_outer_2", + "attached": null + }, + { + "table": "t_inner_4", + "attached": null + }, + { + "table": "t_inner_3", + "attached": "t_inner_3.a = t_outer_2.a" + } + ] + } + } + ] + } + }, + { + "join_execution": { + "select_id": 1, + "steps": [] + } + } + ] +} 0 0 +set optimizer_switch='materialization=on'; +explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and +t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t_outer_1 ALL NULL NULL NULL NULL 3 +1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 +1 PRIMARY t_outer_2 ALL NULL NULL NULL NULL 9 Using join buffer (flat, BNL join) +1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED t_inner_1 ALL NULL NULL NULL NULL 3 +2 MATERIALIZED t_inner_2 ALL NULL NULL NULL NULL 9 Using join buffer (flat, BNL join) +3 MATERIALIZED t_inner_4 ALL NULL NULL NULL NULL 3 +3 MATERIALIZED t_inner_3 ALL NULL NULL NULL NULL 9 Using join buffer (flat, BNL join) +select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; +QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES +explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and +t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { + "steps": [ + { + "join_preparation": { + "select_id": 1, + "steps": [ + { + "join_preparation": { + "select_id": 2, + "steps": [ + { + "transformation": { + "select_id": 2, + "from": "IN (SELECT)", + "to": "materialization", + "sjm_scan_allowed": true, + "possible": true + } + }, + { + "transformation": { + "select_id": 2, + "from": "IN (SELECT)", + "to": "semijoin", + "chosen": true + } + }, + { + "expanded_query": "/* select#2 */ select t_inner_1.a from t2 t_inner_2 join t1 t_inner_1" + } + ] + } + }, + { + "join_preparation": { + "select_id": 3, + "steps": [ + { + "transformation": { + "select_id": 3, + "from": "IN (SELECT)", + "to": "materialization", + "sjm_scan_allowed": true, + "possible": true + } + }, + { + "transformation": { + "select_id": 3, + "from": "IN (SELECT)", + "to": "semijoin", + "chosen": true + } + }, + { + "expanded_query": "/* select#3 */ select t_inner_3.a from t2 t_inner_3 join t1 t_inner_4" + } + ] + } + }, + { + "expanded_query": "/* select#1 */ select t_outer_1.a AS a,t_outer_2.a AS a from t1 t_outer_1 join t2 t_outer_2 where t_outer_1.a in (/* select#2 */ select t_inner_1.a from t2 t_inner_2 join t1 t_inner_1) and t_outer_2.a in (/* select#3 */ select t_inner_3.a from t2 t_inner_3 join t1 t_inner_4)" + } + ] + } + }, + { + "join_optimization": { + "select_id": 1, + "steps": [ + { + "transformation": { + "select_id": 2, + "from": "IN (SELECT)", + "to": "semijoin", + "converted_to_semi_join": true + } + }, + { + "transformation": { + "select_id": 3, + "from": "IN (SELECT)", + "to": "semijoin", + "converted_to_semi_join": true + } + }, + { + "condition_processing": { + "condition": "WHERE", + "original_condition": "1 and 1 and t_outer_1.a = t_inner_1.a and t_outer_2.a = t_inner_3.a", + "steps": [ + { + "transformation": "equality_propagation", + "resulting_condition": "1 and 1 and multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" + }, + { + "transformation": "constant_propagation", + "resulting_condition": "1 and 1 and multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" + }, + { + "transformation": "trivial_condition_removal", + "resulting_condition": "multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" + } + ] + } + }, + { + "table_dependencies": [ + { + "table": "t_outer_1", + "row_may_be_null": false, + "map_bit": 0, + "depends_on_map_bits": [] + }, + { + "table": "t_outer_2", + "row_may_be_null": false, + "map_bit": 1, + "depends_on_map_bits": [] + }, + { + "table": "t_inner_2", + "row_may_be_null": false, + "map_bit": 2, + "depends_on_map_bits": [] + }, + { + "table": "t_inner_1", + "row_may_be_null": false, + "map_bit": 3, + "depends_on_map_bits": [] + }, + { + "table": "t_inner_3", + "row_may_be_null": false, + "map_bit": 4, + "depends_on_map_bits": [] + }, + { + "table": "t_inner_4", + "row_may_be_null": false, + "map_bit": 5, + "depends_on_map_bits": [] + } + ] + }, + { + "ref_optimizer_key_uses": [] + }, + { + "rows_estimation": [ + { + "table": "t_outer_1", + "table_scan": { + "rows": 3, + "cost": 2.0051 + } + }, + { + "table": "t_outer_2", + "table_scan": { + "rows": 9, + "cost": 2.0154 + } + }, + { + "table": "t_inner_2", + "table_scan": { + "rows": 9, + "cost": 2.0154 + } + }, + { + "table": "t_inner_1", + "table_scan": { + "rows": 3, + "cost": 2.0051 + } + }, + { + "table": "t_inner_3", + "table_scan": { + "rows": 9, + "cost": 2.0154 + } + }, + { + "table": "t_inner_4", + "table_scan": { + "rows": 3, + "cost": 2.0051 + } + } + ] + }, + { + "execution_plan_for_potential_materialization": { + "steps": [ + { + "considered_execution_plans": [ + { + "plan_prefix": [], + "table": "t_inner_1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_inner_1"], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + } + } + ] + }, + { + "plan_prefix": [], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "considered_execution_plans": [ + { + "plan_prefix": [], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_inner_4"], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + } + } + ] + }, + { + "plan_prefix": [], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + } + ] + } + }, + { + "considered_execution_plans": [ + { + "plan_prefix": [], + "table": "t_outer_1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_outer_1"], + "table": "t_inner_1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_outer_1", "t_inner_1"], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_2", + "t_outer_2" + ], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_2", + "t_outer_2", + "t_inner_4" + ], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + } + } + ] + }, + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_2", + "t_outer_2" + ], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "rest_of_plan": [ + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_2", + "t_inner_4" + ], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + }, + { + "plan_prefix": [ + "t_outer_1", + "t_inner_1", + "t_inner_2", + "t_inner_4" + ], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1"], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1"], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1"], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_cost": true + } + ] + }, + { + "plan_prefix": ["t_outer_1"], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": ["t_outer_1"], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": ["t_outer_1"], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": ["t_outer_1"], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "plan_prefix": [], + "table": "t_inner_1", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": [], + "table": "t_inner_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": [], + "table": "t_outer_2", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": [], + "table": "t_inner_4", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 3, + "cost": 2.0051, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + }, + { + "plan_prefix": [], + "table": "t_inner_3", + "best_access_path": { + "considered_access_paths": [ + { + "access_type": "scan", + "resulting_rows": 9, + "cost": 2.0154, + "chosen": true + } + ] + }, + "pruned_by_heuristic": true + } + ] + }, + { + "fix_semijoin_strategies_for_picked_join_order": [ + { + "semi_join_strategy": "sj_materialize", + "join_order": [ + { + "table": "t_inner_4" + }, + { + "table": "t_inner_3" + } + ] + }, + { + "semi_join_strategy": "sj_materialize", + "join_order": [ + { + "table": "t_inner_1" + }, + { + "table": "t_inner_2" + } + ] + } + ] + }, + { + "condition_on_constant_tables": "1" + }, + { + "attaching_conditions_to_tables": { + "original_condition": "1", + "attached_conditions_computation": [], + "attached_conditions_summary": [ + { + "table": "t_outer_1", + "attached": null + }, + { + "table": "t_inner_1", + "attached": null + }, + { + "table": "t_inner_2", + "attached": null + }, + { + "table": "", + "attached": null + }, + { + "table": "t_outer_2", + "attached": null + }, + { + "table": "t_inner_4", + "attached": null + }, + { + "table": "t_inner_3", + "attached": null + }, + { + "table": "", + "attached": null + } + ] + } + } + ] + } + }, + { + "join_execution": { + "select_id": 1, + "steps": [] + } + } + ] +} 0 0 +set @@optimizer_switch= @save_optimizer_switch; +drop table t1,t2; +set optimizer_trace='enabled=off'; diff --git a/mysql-test/main/opt_trace.test b/mysql-test/main/opt_trace.test index f55cf57b82a..e59a11fbfc3 100644 --- a/mysql-test/main/opt_trace.test +++ b/mysql-test/main/opt_trace.test @@ -323,6 +323,7 @@ set optimizer_trace='enabled=off'; --echo # MDEV-18528: Optimizer trace support for multi-table UPDATE and DELETE --echo # +set optimizer_trace=1; create table ten(a int); insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t0 (a int, b int); @@ -333,3 +334,43 @@ insert into t1 select * from t0; explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3; select * from information_schema.optimizer_trace; drop table ten,t0,t1; +set optimizer_trace='enabled=off'; + +--echo # +--echo # Merged to Materialized for derived tables +--echo # + +set optimizer_trace=1; +create table t1 (a int); +insert into t1 values (1),(2),(3); +explain select * from (select rand() from t1)q; +select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; +drop table t1; +set optimizer_trace='enabled=off'; + +--echo # +--echo # Semi-join nest +--echo # + +set optimizer_trace=1; +create table t1 (a int); +insert into t1 values (1),(2),(3); +create table t2(a int); +insert into t2 values (1),(2),(3),(1),(2),(3),(1),(2),(3); +set @save_optimizer_switch= @@optimizer_switch; +explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_inner_2); +select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; + +--echo # with Firstmatch, mostly for tracing fix_semijoin_strategies_for_picked_join_order + +set optimizer_switch='materialization=off'; +explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and + t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4); +select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; +set optimizer_switch='materialization=on'; +explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and + t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4); +select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; +set @@optimizer_switch= @save_optimizer_switch; +drop table t1,t2; +set optimizer_trace='enabled=off'; diff --git a/mysql-test/main/opt_trace_index_merge.result b/mysql-test/main/opt_trace_index_merge.result index 855a7256f4f..50daef815d6 100644 --- a/mysql-test/main/opt_trace_index_merge.result +++ b/mysql-test/main/opt_trace_index_merge.result @@ -24,7 +24,7 @@ explain select * from t1 where a=1 or b=1 { "select_id": 1, "steps": [ { - "expanded_query": "select `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c`,`t1`.`filler` AS `filler` from `t1` where `t1`.`a` = 1 or `t1`.`b` = 1" + "expanded_query": "select t1.a AS a,t1.b AS b,t1.c AS c,t1.filler AS filler from t1 where t1.a = 1 or t1.b = 1" } ] } @@ -194,15 +194,11 @@ explain select * from t1 where a=1 or b=1 { }, { "selectivity_for_indexes": [], - "selectivity_for_columns": [] + "selectivity_for_columns": [], + "cond_selectivity": 0.002 } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { diff --git a/mysql-test/main/opt_trace_index_merge_innodb.result b/mysql-test/main/opt_trace_index_merge_innodb.result index 43c9462303f..11ab89b1bb6 100644 --- a/mysql-test/main/opt_trace_index_merge_innodb.result +++ b/mysql-test/main/opt_trace_index_merge_innodb.result @@ -32,7 +32,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "select_id": 1, "steps": [ { - "expanded_query": "select `t1`.`pk1` AS `pk1`,`t1`.`pk2` AS `pk2`,`t1`.`key1` AS `key1`,`t1`.`key2` AS `key2` from `t1` where `t1`.`pk1` <> 0 and `t1`.`key1` = 1" + "expanded_query": "select t1.pk1 AS pk1,t1.pk2 AS pk2,t1.key1 AS key1,t1.key2 AS key2 from t1 where t1.pk1 <> 0 and t1.key1 = 1" } ] } @@ -183,15 +183,11 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "selectivity_from_index": 0.001 } ], - "selectivity_for_columns": [] + "selectivity_for_columns": [], + "cond_selectivity": 0.001 } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { diff --git a/mysql-test/main/opt_trace_security.result b/mysql-test/main/opt_trace_security.result index 2d66a0a9576..9f5bacd6aa7 100644 --- a/mysql-test/main/opt_trace_security.result +++ b/mysql-test/main/opt_trace_security.result @@ -55,7 +55,7 @@ select * from db1.t1 { "select_id": 1, "steps": [ { - "expanded_query": "select `db1`.`t1`.`a` AS `a` from `t1`" + "expanded_query": "select db1.t1.a AS a from t1" } ] } @@ -85,11 +85,6 @@ select * from db1.t1 { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { @@ -157,7 +152,7 @@ select * from db1.v1 { "view": { "table": "v1", "select_id": 2, - "merged": true + "algorithm": "merged" } }, { @@ -165,13 +160,13 @@ select * from db1.v1 { "select_id": 2, "steps": [ { - "expanded_query": "/* select#2 */ select `db1`.`t1`.`a` AS `a` from `t1`" + "expanded_query": "/* select#2 */ select db1.t1.a AS a from t1" } ] } }, { - "expanded_query": "/* select#1 */ select `db1`.`t1`.`a` AS `a` from `v1`" + "expanded_query": "/* select#1 */ select db1.t1.a AS a from v1" } ] } @@ -201,11 +196,6 @@ select * from db1.v1 { } ] }, - { - "execution_plan_for_potential_materialization": { - "steps": [] - } - }, { "considered_execution_plans": [ { diff --git a/sql/my_json_writer.cc b/sql/my_json_writer.cc index 7ae0c58bd7d..3755f8d4bcb 100644 --- a/sql/my_json_writer.cc +++ b/sql/my_json_writer.cc @@ -219,15 +219,15 @@ void Json_writer::add_str(const String &str) add_str(str.ptr(), str.length()); } -Json_writer_object::Json_writer_object(THD *thd) : +Json_writer_object::Json_writer_object(THD *thd) : Json_writer_struct(thd) { if (my_writer) my_writer->start_object(); } -Json_writer_object::Json_writer_object(THD* thd, const char *str) - : Json_writer_struct(thd) +Json_writer_object::Json_writer_object(THD* thd, const char *str) : + Json_writer_struct(thd) { if (my_writer) my_writer->add_member(str).start_object(); @@ -247,8 +247,8 @@ Json_writer_array::Json_writer_array(THD *thd) : my_writer->start_array(); } -Json_writer_array::Json_writer_array(THD *thd, const char *str) - :Json_writer_struct(thd) +Json_writer_array::Json_writer_array(THD *thd, const char *str) : + Json_writer_struct(thd) { if (my_writer) my_writer->add_member(str).start_array(); @@ -263,6 +263,16 @@ Json_writer_array::~Json_writer_array() } } +Json_writer_temp_disable::Json_writer_temp_disable(THD *thd_arg) +{ + thd= thd_arg; + thd->opt_trace.disable_tracing_if_required(); +} +Json_writer_temp_disable::~Json_writer_temp_disable() +{ + thd->opt_trace.enable_tracing_if_required(); +} + bool Single_line_formatting_helper::on_add_member(const char *name) { DBUG_ASSERT(state== INACTIVE || state == DISABLED); diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h index 3234c748f5d..dbd7cd133e9 100644 --- a/sql/my_json_writer.h +++ b/sql/my_json_writer.h @@ -215,12 +215,11 @@ public: */ void set_size_limit(size_t mem_size) { output.set_size_limit(mem_size); } - // psergey: return how many bytes would be required to store everything size_t get_truncated_bytes() { return output.get_truncated_bytes(); } Json_writer() : indent_level(0), document_start(true), element_started(false), - first_child(true), allowed_mem_size(0) + first_child(true) { fmt_helper.init(this); } @@ -235,12 +234,6 @@ private: bool element_started; bool first_child; - /* - True when we are using the optimizer trace - FALSE otherwise - */ - size_t allowed_mem_size; - Single_line_formatting_helper fmt_helper; void append_indent(); @@ -566,6 +559,17 @@ public: ~Json_writer_array(); }; +/* + RAII-based class to disable writing into the JSON document +*/ + +class Json_writer_temp_disable +{ +public: + Json_writer_temp_disable(THD *thd_arg); + ~Json_writer_temp_disable(); + THD *thd; +}; /* RAII-based helper class to detect incorrect use of Json_writer. diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 468d16c095e..fcf0d2228a5 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -675,7 +675,7 @@ int SEL_IMERGE::or_sel_tree_with_checks(RANGE_OPT_PARAM *param, { bool was_ored= FALSE; *is_last_check_pass= is_first_check_pass; - SEL_TREE** or_tree = trees; + SEL_TREE** or_tree= trees; for (uint i= 0; i < n_trees; i++, or_tree++) { SEL_TREE *result= 0; @@ -872,7 +872,7 @@ SEL_IMERGE::SEL_IMERGE(SEL_IMERGE *arg, uint cnt, trees_next= trees + (cnt ? cnt : arg->trees_next-arg->trees); trees_end= trees + elements; - for (SEL_TREE **tree = trees, **arg_tree= arg->trees; tree < trees_next; + for (SEL_TREE **tree= trees, **arg_tree= arg->trees; tree < trees_next; tree++, arg_tree++) { if (!(*tree= new SEL_TREE(*arg_tree, TRUE, param))) @@ -2211,7 +2211,7 @@ public: @param trace_object The optimizer trace object the info is appended to */ virtual void trace_basic_info(const PARAM *param, - Json_writer_object *trace_object) const = 0; + Json_writer_object *trace_object) const= 0; }; @@ -2261,10 +2261,10 @@ void TRP_RANGE::trace_basic_info(const PARAM *param, Json_writer_object *trace_object) const { DBUG_ASSERT(param->using_real_indexes); - const uint keynr_in_table = param->real_keynr[key_idx]; + const uint keynr_in_table= param->real_keynr[key_idx]; - const KEY &cur_key = param->table->key_info[keynr_in_table]; - const KEY_PART_INFO *key_part = cur_key.key_part; + const KEY &cur_key= param->table->key_info[keynr_in_table]; + const KEY_PART_INFO *key_part= cur_key.key_part; trace_object->add("type", "range_scan") .add("index", cur_key.name) @@ -2329,7 +2329,7 @@ void TRP_ROR_UNION::trace_basic_info(const PARAM *param, THD *thd= param->thd; trace_object->add("type", "index_roworder_union"); Json_writer_array smth_trace(thd, "union_of"); - for (TABLE_READ_PLAN **current = first_ror; current != last_ror; current++) + for (TABLE_READ_PLAN **current= first_ror; current != last_ror; current++) { Json_writer_object trp_info(thd); (*current)->trace_basic_info(param, &trp_info); @@ -2364,7 +2364,7 @@ void TRP_INDEX_INTERSECT::trace_basic_info(const PARAM *param, THD *thd= param->thd; trace_object->add("type", "index_sort_intersect"); Json_writer_array smth_trace(thd, "index_sort_intersect_of"); - for (TRP_RANGE **current = range_scans; current != range_scans_end; + for (TRP_RANGE **current= range_scans; current != range_scans_end; current++) { Json_writer_object trp_info(thd); @@ -2466,9 +2466,9 @@ void TRP_GROUP_MIN_MAX::trace_basic_info(const PARAM *param, trace_object->add("type", "index_group").add("index", index_info->name); if (min_max_arg_part) - trace_object->add("group_attribute", min_max_arg_part->field->field_name); + trace_object->add("min_max_arg", min_max_arg_part->field->field_name); else - trace_object->add_null("group_attribute"); + trace_object->add_null("min_max_arg"); trace_object->add("min_aggregate", have_min) .add("max_aggregate", have_max) @@ -2476,12 +2476,12 @@ void TRP_GROUP_MIN_MAX::trace_basic_info(const PARAM *param, .add("rows", records) .add("cost", read_cost); - const KEY_PART_INFO *key_part = index_info->key_part; + const KEY_PART_INFO *key_part= index_info->key_part; { Json_writer_array trace_keyparts(thd, "key_parts_used_for_access"); - for (uint partno = 0; partno < used_key_parts; partno++) + for (uint partno= 0; partno < used_key_parts; partno++) { - const KEY_PART_INFO *cur_key_part = key_part + partno; + const KEY_PART_INFO *cur_key_part= key_part + partno; trace_keyparts.add(cur_key_part->field->field_name); } } @@ -3438,7 +3438,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond) { rows= 0; table->reginfo.impossible_range= 1; - selectivity_for_column.add("selectivity_from_histograms", rows); + selectivity_for_column.add("selectivity_from_histogram", rows); selectivity_for_column.add("cause", "impossible range"); goto free_alloc; } @@ -3448,7 +3448,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond) if (rows != DBL_MAX) { key->field->cond_selectivity= rows/table_records; - selectivity_for_column.add("selectivity_from_histograms", + selectivity_for_column.add("selectivity_from_histogram", key->field->cond_selectivity); } } @@ -3472,6 +3472,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond) free_root(&alloc, MYF(0)); } + selectivity_for_columns.end(); if (quick && (quick->get_type() == QUICK_SELECT_I::QS_TYPE_ROR_UNION || quick->get_type() == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE)) @@ -3546,7 +3547,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond) table->cond_selectivity_sampling_explain= &dt->list; } } - + trace_wrapper.add("cond_selectivity", table->cond_selectivity); DBUG_RETURN(FALSE); } @@ -5073,7 +5074,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge, trace_idx.add("chosen", false).add("cause", "cost"); continue; } - const uint keynr_in_table = param->real_keynr[(*cur_child)->key_idx]; + const uint keynr_in_table= param->real_keynr[(*cur_child)->key_idx]; imerge_cost += (*cur_child)->read_cost; all_scans_ror_able &= ((*ptree)->n_ror_scans > 0); all_scans_rors &= (*cur_child)->is_ror; @@ -5134,7 +5135,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge, */ double rid_comp_cost= static_cast(non_cpk_scan_records) / TIME_FOR_COMPARE_ROWID; - imerge_cost += rid_comp_cost; + imerge_cost+= rid_comp_cost; trace_best_disjunct.add("cost_of_mapping_rowid_in_non_clustered_pk_scan", rid_comp_cost); } @@ -5142,7 +5143,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge, /* Calculate cost(rowid_to_row_scan) */ { double sweep_cost= get_sweep_read_cost(param, non_cpk_scan_records); - imerge_cost += sweep_cost; + imerge_cost+= sweep_cost; trace_best_disjunct.add("cost_sort_rowid_and_read_disk", sweep_cost); } DBUG_PRINT("info",("index_merge cost with rowid-to-row scan: %g", @@ -5169,7 +5170,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge, } { - const double dup_removal_cost = Unique::get_use_cost( + const double dup_removal_cost= Unique::get_use_cost( param->imerge_cost_buff, (uint)non_cpk_scan_records, param->table->file->ref_length, (size_t)param->thd->variables.sortbuff_size, @@ -6371,11 +6372,11 @@ void TRP_ROR_INTERSECT::trace_basic_info(const PARAM *param, trace_object->add("clustered_pk_scan", cpk_scan != NULL); Json_writer_array smth_trace(thd, "intersect_of"); - for (ROR_SCAN_INFO **cur_scan = first_scan; cur_scan != last_scan; + for (ROR_SCAN_INFO **cur_scan= first_scan; cur_scan != last_scan; cur_scan++) { - const KEY &cur_key = param->table->key_info[(*cur_scan)->keynr]; - const KEY_PART_INFO *key_part = cur_key.key_part; + const KEY &cur_key= param->table->key_info[(*cur_scan)->keynr]; + const KEY_PART_INFO *key_part= cur_key.key_part; Json_writer_object trace_isect_idx(thd); trace_isect_idx.add("type", "range_scan"); @@ -6383,15 +6384,15 @@ void TRP_ROR_INTERSECT::trace_basic_info(const PARAM *param, trace_isect_idx.add("rows", (*cur_scan)->records); Json_writer_array trace_range(thd, "ranges"); - for (const SEL_ARG *current = (*cur_scan)->sel_arg->first(); current; - current = current->next) + for (const SEL_ARG *current= (*cur_scan)->sel_arg->first(); current; + current= current->next) { String range_info; range_info.set_charset(system_charset_info); - for (const SEL_ARG *part = current; part; - part = part->next_key_part ? part->next_key_part : nullptr) + for (const SEL_ARG *part= current; part; + part= part->next_key_part ? part->next_key_part : nullptr) { - const KEY_PART_INFO *cur_key_part = key_part + part->part; + const KEY_PART_INFO *cur_key_part= key_part + part->part; append_range(&range_info, cur_key_part, part->min_value, part->max_value, part->min_flag | part->max_flag); } @@ -6816,7 +6817,7 @@ static bool ror_intersect_add(ROR_INTERSECT_INFO *info, */ const double idx_cost= rows2double(info->index_records) / TIME_FOR_COMPARE_ROWID; - info->index_scan_costs += idx_cost; + info->index_scan_costs+= idx_cost; trace_costs->add("index_scan_cost", idx_cost); } else @@ -6840,7 +6841,7 @@ static bool ror_intersect_add(ROR_INTERSECT_INFO *info, { double sweep_cost= get_sweep_read_cost(info->param, double2rows(info->out_rows)); - info->total_cost += sweep_cost; + info->total_cost+= sweep_cost; trace_costs->add("disk_sweep_cost", sweep_cost); DBUG_PRINT("info", ("info->total_cost= %g", info->total_cost)); } @@ -7371,8 +7372,8 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree, { Json_writer_array trace_range(thd, "ranges"); - const KEY &cur_key = param->table->key_info[keynr]; - const KEY_PART_INFO *key_part = cur_key.key_part; + const KEY &cur_key= param->table->key_info[keynr]; + const KEY_PART_INFO *key_part= cur_key.key_part; String range_info; range_info.set_charset(system_charset_info); @@ -13384,7 +13385,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time) key_part_nr= get_field_keypart(cur_index_info, min_max_arg_item->field); if (key_part_nr <= cur_group_key_parts) { - cause = "aggregate column not suffix in idx"; + cause= "aggregate column not suffix in idx"; goto next_index; } min_max_arg_part= cur_index_info->key_part + key_part_nr - 1; @@ -13438,7 +13439,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time) &cur_key_infix_len, &first_non_infix_part)) { - cause = "nonconst equality gap attribute"; + cause= "nonconst equality gap attribute"; goto next_index; } } @@ -13449,7 +13450,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time) There is a gap but no range tree, thus no predicates at all for the non-group keyparts. */ - cause = "no nongroup keypart predicate"; + cause= "no nongroup keypart predicate"; goto next_index; } else if (first_non_group_part && join->conds) @@ -13474,7 +13475,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time) if (join->conds->walk(&Item::find_item_in_field_list_processor, 0, key_part_range)) { - cause = "keypart reference from where clause"; + cause= "keypart reference from where clause"; goto next_index; } } @@ -13492,7 +13493,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time) { if (bitmap_is_set(table->read_set, cur_part->field->field_index)) { - cause = "keypart after infix in query"; + cause= "keypart after infix in query"; goto next_index; } } @@ -13511,7 +13512,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time) index_range_tree, &cur_range) || (cur_range && cur_range->type != SEL_ARG::KEY_RANGE)) { - cause = "minmax keypart in disjunctive query"; + cause= "minmax keypart in disjunctive query"; goto next_index; } } @@ -13538,7 +13539,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time) { Json_writer_array trace_range(thd, "ranges"); - const KEY_PART_INFO *key_part = cur_index_info->key_part; + const KEY_PART_INFO *key_part= cur_index_info->key_part; String range_info; range_info.set_charset(system_charset_info); @@ -13578,7 +13579,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time) if (cause) { trace_idx.add("usable", false).add("cause", cause); - cause = NULL; + cause= NULL; } } @@ -15776,9 +15777,9 @@ static void append_range_all_keyparts(Json_writer_array *range_trace, DBUG_ASSERT(keypart && keypart != &null_element); // Navigate to first interval in red-black tree - const KEY_PART_INFO *cur_key_part = key_parts + keypart->part; - const SEL_ARG *keypart_range = keypart->first(); - const size_t save_range_so_far_length = range_so_far->length(); + const KEY_PART_INFO *cur_key_part= key_parts + keypart->part; + const SEL_ARG *keypart_range= keypart->first(); + const size_t save_range_so_far_length= range_so_far->length(); while (keypart_range) @@ -15827,9 +15828,10 @@ static void append_range_all_keyparts(Json_writer_array *range_trace, static void print_key_value(String *out, const KEY_PART_INFO *key_part, const uchar *key) { - Field *field = key_part->field; + Field *field= key_part->field; - if (field->flags & BLOB_FLAG) { + if (field->flags & BLOB_FLAG) + { // Byte 0 of a nullable key is the null-byte. If set, key is NULL. if (field->real_maybe_null() && *key) out->append(STRING_WITH_LEN("NULL")); @@ -15840,7 +15842,7 @@ static void print_key_value(String *out, const KEY_PART_INFO *key_part, return; } - uint store_length = key_part->store_length; + uint store_length= key_part->store_length; if (field->real_maybe_null()) { @@ -15849,7 +15851,8 @@ static void print_key_value(String *out, const KEY_PART_INFO *key_part, Otherwise, print the key value starting immediately after the null-byte */ - if (*key) { + if (*key) + { out->append(STRING_WITH_LEN("NULL")); return; } @@ -15862,9 +15865,11 @@ static void print_key_value(String *out, const KEY_PART_INFO *key_part, optimizer trace expects. If the column is binary, the hex representation is printed to the trace instead. */ - if (field->flags & BINARY_FLAG) { + if (field->flags & BINARY_FLAG) + { out->append("0x"); - for (uint i = 0; i < store_length; i++) { + for (uint i = 0; i < store_length; i++) + { out->append(_dig_vec_lower[*(key + i) >> 4]); out->append(_dig_vec_lower[*(key + i) & 0x0F]); } @@ -15872,7 +15877,7 @@ static void print_key_value(String *out, const KEY_PART_INFO *key_part, } StringBuffer<128> tmp(system_charset_info); - TABLE *table = field->table; + TABLE *table= field->table; my_bitmap_map *old_sets[2]; dbug_tmp_use_all_columns(table, old_sets, table->read_set, table->write_set); diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 228fcd0f7e6..247452cc8f1 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -456,6 +456,7 @@ void best_access_path(JOIN *join, JOIN_TAB *s, table_map remaining_tables, uint idx, bool disable_jbuf, double record_count, POSITION *pos, POSITION *loose_scan_pos); +void trace_plan_prefix(JOIN *join, uint idx, table_map remaining_tables); static Item *create_subq_in_equalities(THD *thd, SJ_MATERIALIZATION_INFO *sjm, Item_in_subselect *subq_pred); @@ -697,9 +698,10 @@ int check_and_do_in_subquery_rewrites(JOIN *join) if (arena) thd->restore_active_arena(arena, &backup); in_subs->is_registered_semijoin= TRUE; - OPT_TRACE_TRANSFORM(thd, oto0, oto1, select_lex->select_number, + OPT_TRACE_TRANSFORM(thd, trace_wrapper, trace_transform, + select_lex->select_number, "IN (SELECT)", "semijoin"); - oto1.add("chosen", true); + trace_transform.add("chosen", true); } } else @@ -840,7 +842,7 @@ bool subquery_types_allow_materialization(THD* thd, Item_in_subselect *in_subs) in_subs->types_allow_materialization= FALSE; // Assign default values in_subs->sjm_scan_allowed= FALSE; - OPT_TRACE_TRANSFORM(thd, oto0, oto1, + OPT_TRACE_TRANSFORM(thd, trace_wrapper, trace_transform, in_subs->get_select_lex()->select_number, "IN (SELECT)", "materialization"); @@ -856,8 +858,8 @@ bool subquery_types_allow_materialization(THD* thd, Item_in_subselect *in_subs) if (!inner->type_handler()->subquery_type_allows_materialization(inner, outer)) { - oto1.add("possible", false); - oto1.add("cause", "types mismatch"); + trace_transform.add("possible", false); + trace_transform.add("cause", "types mismatch"); DBUG_RETURN(FALSE); } } @@ -879,12 +881,12 @@ bool subquery_types_allow_materialization(THD* thd, Item_in_subselect *in_subs) { in_subs->types_allow_materialization= TRUE; in_subs->sjm_scan_allowed= all_are_fields; - oto1.add("sjm_scan_allowed", all_are_fields) - .add("possible", true); + trace_transform.add("sjm_scan_allowed", all_are_fields) + .add("possible", true); DBUG_PRINT("info",("subquery_types_allow_materialization: ok, allowed")); DBUG_RETURN(TRUE); } - oto1.add("possible", false).add("cause", cause); + trace_transform.add("possible", false).add("cause", cause); DBUG_RETURN(FALSE); } @@ -1236,29 +1238,30 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) /* Stop processing if we've reached a subquery that's attached to the ON clause */ if (in_subq->do_not_convert_to_sj) { - OPT_TRACE_TRANSFORM(thd, oto0, oto1, + OPT_TRACE_TRANSFORM(thd, trace_wrapper, trace_transform, in_subq->get_select_lex()->select_number, "IN (SELECT)", "semijoin"); - oto1.add("converted_to_semi_join", false) - .add("cause", "subquery attached to the ON clause"); + trace_transform.add("converted_to_semi_join", false) + .add("cause", "subquery attached to the ON clause"); break; } if (in_subq->is_flattenable_semijoin) { - OPT_TRACE_TRANSFORM(thd, oto0, oto1, + OPT_TRACE_TRANSFORM(thd, trace_wrapper, trace_transform, in_subq->get_select_lex()->select_number, "IN (SELECT)", "semijoin"); if (join->table_count + in_subq->unit->first_select()->join->table_count >= MAX_TABLES) { - oto1.add("converted_to_semi_join", false); - oto1.add("cause", "table in parent join now exceeds MAX_TABLES"); + trace_transform.add("converted_to_semi_join", false); + trace_transform.add("cause", + "table in parent join now exceeds MAX_TABLES"); break; } if (convert_subq_to_sj(join, in_subq)) goto restore_arena_and_fail; - oto1.add("converted_to_semi_join", true); + trace_transform.add("converted_to_semi_join", true); } else { @@ -2380,6 +2383,8 @@ bool optimize_semijoin_nests(JOIN *join, table_map all_table_map) THD *thd= join->thd; List_iterator sj_list_it(join->select_lex->sj_nests); TABLE_LIST *sj_nest; + if (!join->select_lex->sj_nests.elements) + DBUG_RETURN(FALSE); Json_writer_object wrapper(thd); Json_writer_object trace_semijoin_nest(thd, "execution_plan_for_potential_materialization"); @@ -2939,6 +2944,7 @@ bool Sj_materialization_picker::check_qep(JOIN *join, { bool sjm_scan; SJ_MATERIALIZATION_INFO *mat_info; + THD *thd= join->thd; if ((mat_info= at_sjmat_pos(join, remaining_tables, new_join_tab, idx, &sjm_scan))) { @@ -3040,6 +3046,7 @@ bool Sj_materialization_picker::check_qep(JOIN *join, POSITION curpos, dummy; /* Need to re-run best-access-path as we prefix_rec_count has changed */ bool disable_jbuf= (join->thd->variables.join_cache_level == 0); + Json_writer_temp_disable trace_semijoin_mat_scan(thd); for (i= first_tab + mat_info->tables; i <= idx; i++) { best_access_path(join, join->positions[i].table, rem_tables, i, @@ -3590,6 +3597,12 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join) table_map handled_tabs= 0; join->sjm_lookup_tables= 0; join->sjm_scan_tables= 0; + THD *thd= join->thd; + if (!join->select_lex->sj_nests.elements) + return; + Json_writer_object trace_wrapper(thd); + Json_writer_array trace_semijoin_strategies(thd, + "fix_semijoin_strategies_for_picked_join_order"); for (tablenr= table_count - 1 ; tablenr != join->const_tables - 1; tablenr--) { POSITION *pos= join->best_positions + tablenr; @@ -3614,8 +3627,18 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join) first= tablenr - sjm->tables + 1; join->best_positions[first].n_sj_tables= sjm->tables; join->best_positions[first].sj_strategy= SJ_OPT_MATERIALIZE; + Json_writer_object semijoin_strategy(thd); + semijoin_strategy.add("semi_join_strategy","sj_materialize"); + Json_writer_array semijoin_plan(thd, "join_order"); for (uint i= first; i < first+ sjm->tables; i++) + { + if (unlikely(thd->trace_started())) + { + Json_writer_object trace_one_table(thd); + trace_one_table.add_table_name(join->best_positions[i].table); + } join->sjm_lookup_tables |= join->best_positions[i].table->table->map; + } } else if (pos->sj_strategy == SJ_OPT_MATERIALIZE_SCAN) { @@ -3653,8 +3676,16 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join) POSITION dummy; join->cur_sj_inner_tables= 0; + Json_writer_object semijoin_strategy(thd); + semijoin_strategy.add("semi_join_strategy","sj_materialize_scan"); + Json_writer_array semijoin_plan(thd, "join_order"); for (i= first + sjm->tables; i <= tablenr; i++) { + if (unlikely(thd->trace_started())) + { + Json_writer_object trace_one_table(thd); + trace_one_table.add_table_name(join->best_positions[i].table); + } best_access_path(join, join->best_positions[i].table, rem_tables, i, FALSE, prefix_rec_count, join->best_positions + i, &dummy); @@ -3683,8 +3714,16 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join) join buffering */ join->cur_sj_inner_tables= 0; + Json_writer_object semijoin_strategy(thd); + semijoin_strategy.add("semi_join_strategy","firstmatch"); + Json_writer_array semijoin_plan(thd, "join_order"); for (idx= first; idx <= tablenr; idx++) { + if (unlikely(thd->trace_started())) + { + Json_writer_object trace_one_table(thd); + trace_one_table.add_table_name(join->best_positions[idx].table); + } if (join->best_positions[idx].use_join_buffer) { best_access_path(join, join->best_positions[idx].table, @@ -3713,8 +3752,16 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join) join buffering */ join->cur_sj_inner_tables= 0; + Json_writer_object semijoin_strategy(thd); + semijoin_strategy.add("semi_join_strategy","sj_materialize"); + Json_writer_array semijoin_plan(thd, "join_order"); for (idx= first; idx <= tablenr; idx++) { + if (unlikely(thd->trace_started())) + { + Json_writer_object trace_one_table(thd); + trace_one_table.add_table_name(join->best_positions[idx].table); + } if (join->best_positions[idx].use_join_buffer || (idx == first)) { best_access_path(join, join->best_positions[idx].table, diff --git a/sql/opt_table_elimination.cc b/sql/opt_table_elimination.cc index 03516146de2..422b21cb541 100644 --- a/sql/opt_table_elimination.cc +++ b/sql/opt_table_elimination.cc @@ -525,7 +525,7 @@ eliminate_tables_for_list(JOIN *join, table_map tables_in_list, Item *on_expr, table_map tables_used_elsewhere, - Json_writer_array* eliminate_tables); + Json_writer_array* trace_eliminate_tables); static bool check_func_dependency(JOIN *join, table_map dep_tables, @@ -545,7 +545,7 @@ Dep_module_expr *merge_eq_mods(Dep_module_expr *start, Dep_module_expr *new_fields, Dep_module_expr *end, uint and_level); static void mark_as_eliminated(JOIN *join, TABLE_LIST *tbl, - Json_writer_array* eliminate_tables); + Json_writer_array* trace_eliminate_tables); static void add_module_expr(Dep_analysis_context *dac, Dep_module_expr **eq_mod, uint and_level, Dep_value_field *field_val, Item *right, @@ -671,12 +671,12 @@ void eliminate_tables(JOIN *join) } table_map all_tables= join->all_tables_map(); - Json_writer_array eliminated_tables(thd,"eliminated_tables"); + Json_writer_array trace_eliminated_tables(thd,"eliminated_tables"); if (all_tables & ~used_tables) { /* There are some tables that we probably could eliminate. Try it. */ eliminate_tables_for_list(join, join->join_list, all_tables, NULL, - used_tables, &eliminated_tables); + used_tables, &trace_eliminated_tables); } DBUG_VOID_RETURN; } @@ -720,7 +720,7 @@ static bool eliminate_tables_for_list(JOIN *join, List *join_list, table_map list_tables, Item *on_expr, table_map tables_used_elsewhere, - Json_writer_array *eliminate_tables) + Json_writer_array *trace_eliminate_tables) { TABLE_LIST *tbl; List_iterator it(*join_list); @@ -742,9 +742,10 @@ eliminate_tables_for_list(JOIN *join, List *join_list, &tbl->nested_join->join_list, tbl->nested_join->used_tables, tbl->on_expr, - outside_used_tables, eliminate_tables)) + outside_used_tables, + trace_eliminate_tables)) { - mark_as_eliminated(join, tbl, eliminate_tables); + mark_as_eliminated(join, tbl, trace_eliminate_tables); } else all_eliminated= FALSE; @@ -756,7 +757,7 @@ eliminate_tables_for_list(JOIN *join, List *join_list, check_func_dependency(join, tbl->table->map, NULL, tbl, tbl->on_expr)) { - mark_as_eliminated(join, tbl, eliminate_tables); + mark_as_eliminated(join, tbl, trace_eliminate_tables); } else all_eliminated= FALSE; @@ -1797,7 +1798,7 @@ Dep_module* Dep_value_field::get_next_unbound_module(Dep_analysis_context *dac, */ static void mark_as_eliminated(JOIN *join, TABLE_LIST *tbl, - Json_writer_array* eliminate_tables) + Json_writer_array* trace_eliminate_tables) { TABLE *table; /* @@ -1810,7 +1811,7 @@ static void mark_as_eliminated(JOIN *join, TABLE_LIST *tbl, TABLE_LIST *child; List_iterator it(tbl->nested_join->join_list); while ((child= it++)) - mark_as_eliminated(join, child, eliminate_tables); + mark_as_eliminated(join, child, trace_eliminate_tables); } else if ((table= tbl->table)) { @@ -1821,7 +1822,7 @@ static void mark_as_eliminated(JOIN *join, TABLE_LIST *tbl, tab->type= JT_CONST; tab->table->const_table= 1; join->eliminated_tables |= table->map; - eliminate_tables->add(table->alias.c_ptr_safe()); + trace_eliminate_tables->add(table->alias.c_ptr_safe()); join->const_table_map|= table->map; set_position(join, join->const_tables++, tab, (KEYUSE*)0); } diff --git a/sql/opt_trace.cc b/sql/opt_trace.cc index ca05f36579a..befc7934a3a 100644 --- a/sql/opt_trace.cc +++ b/sql/opt_trace.cc @@ -24,7 +24,7 @@ #include "my_json_writer.h" #include "sp_head.h" -const char I_S_table_name[] = "OPTIMIZER_TRACE"; +const char I_S_table_name[]= "OPTIMIZER_TRACE"; /** Whether a list of tables contains information_schema.OPTIMIZER_TRACE. @@ -38,7 +38,7 @@ const char I_S_table_name[] = "OPTIMIZER_TRACE"; */ bool list_has_optimizer_trace_table(const TABLE_LIST *tbl) { - for (; tbl; tbl = tbl->next_global) + for (; tbl; tbl= tbl->next_global) { if (tbl->schema_table && 0 == strcmp(tbl->schema_table->table_name, I_S_table_name)) @@ -59,14 +59,15 @@ bool sets_var_optimizer_trace(enum enum_sql_command sql_command, { List_iterator_fast it(*set_vars); const set_var_base *var; - while ((var = it++)) + while ((var= it++)) if (var->is_var_optimizer_trace()) return true; } return false; } -ST_FIELD_INFO optimizer_trace_info[] = { +ST_FIELD_INFO optimizer_trace_info[]= +{ /* name, length, type, value, maybe_null, old_name, open_method */ {"QUERY", 65535, MYSQL_TYPE_STRING, 0, false, NULL, SKIP_OPEN_TABLE}, {"TRACE", 65535, MYSQL_TYPE_STRING, 0, false, NULL, SKIP_OPEN_TABLE}, @@ -74,12 +75,13 @@ ST_FIELD_INFO optimizer_trace_info[] = { SKIP_OPEN_TABLE}, {"INSUFFICIENT_PRIVILEGES", 1, MYSQL_TYPE_TINY, 0, false, NULL, SKIP_OPEN_TABLE}, - {NULL, 0, MYSQL_TYPE_STRING, 0, true, NULL, 0}}; + {NULL, 0, MYSQL_TYPE_STRING, 0, true, NULL, 0} +}; /* TODO: one-line needs to be implemented seperately */ -const char *Opt_trace_context::flag_names[] = {"enabled", "default", +const char *Opt_trace_context::flag_names[]= {"enabled", "default", NullS}; /* @@ -105,15 +107,15 @@ void opt_trace_print_expanded_query(THD *thd, SELECT_LEX *select_lex, { if (!thd->trace_started()) return; - char buff[1024]; - String str(buff, sizeof(buff), system_charset_info); - str.length(0); + StringBuffer<1024> str(system_charset_info); + ulonglong save_option_bits= thd->variables.option_bits; + thd->variables.option_bits &= ~OPTION_QUOTE_SHOW_CREATE; select_lex->print(thd, &str, enum_query_type(QT_TO_SYSTEM_CHARSET | QT_SHOW_SELECT_NUMBER | QT_ITEM_IDENT_SKIP_DB_NAMES | - QT_VIEW_INTERNAL - )); + QT_VIEW_INTERNAL)); + thd->variables.option_bits= save_option_bits; /* The output is not very pretty lots of back-ticks, the output is as the one in explain extended , lets try to improved it here. @@ -141,7 +143,7 @@ void opt_trace_disable_if_no_security_context_access(THD *thd) */ return; } - Opt_trace_context *const trace = &thd->opt_trace; + Opt_trace_context *const trace= &thd->opt_trace; if (!thd->trace_started()) { /* @@ -187,7 +189,6 @@ void opt_trace_disable_if_no_security_context_access(THD *thd) thd->main_security_ctx.priv_host, thd->security_context()->priv_host))) trace->missing_privilege(); - return; } void opt_trace_disable_if_no_stored_proc_func_access(THD *thd, sp_head *sp) @@ -197,17 +198,16 @@ void opt_trace_disable_if_no_stored_proc_func_access(THD *thd, sp_head *sp) thd->system_thread) return; - Opt_trace_context *const trace = &thd->opt_trace; + Opt_trace_context *const trace= &thd->opt_trace; if (!thd->trace_started()) return; bool full_access; - Security_context *const backup_thd_sctx = thd->security_context(); + Security_context *const backup_thd_sctx= thd->security_context(); thd->set_security_context(&thd->main_security_ctx); - const bool rc = check_show_routine_access(thd, sp, &full_access) || !full_access; + const bool rc= check_show_routine_access(thd, sp, &full_access) || !full_access; thd->set_security_context(backup_thd_sctx); if (rc) trace->missing_privilege(); - return; } /** @@ -231,16 +231,16 @@ void opt_trace_disable_if_no_tables_access(THD *thd, TABLE_LIST *tbl) if (likely(!(thd->variables.optimizer_trace & Opt_trace_context::FLAG_ENABLED)) || thd->system_thread) return; - Opt_trace_context *const trace = &thd->opt_trace; + Opt_trace_context *const trace= &thd->opt_trace; if (!thd->trace_started()) return; - Security_context *const backup_thd_sctx = thd->security_context(); + Security_context *const backup_thd_sctx= thd->security_context(); thd->set_security_context(&thd->main_security_ctx); - const TABLE_LIST *const first_not_own_table = thd->lex->first_not_own_table(); - for (TABLE_LIST *t = tbl; t != NULL && t != first_not_own_table; - t = t->next_global) + const TABLE_LIST *const first_not_own_table= thd->lex->first_not_own_table(); + for (TABLE_LIST *t= tbl; t != NULL && t != first_not_own_table; + t= t->next_global) { /* Anonymous derived tables (as in @@ -248,9 +248,9 @@ void opt_trace_disable_if_no_tables_access(THD *thd, TABLE_LIST *tbl) */ if (!t->is_anonymous_derived_table()) { - const GRANT_INFO backup_grant_info = t->grant; - Security_context *const backup_table_sctx = t->security_ctx; - t->security_ctx = NULL; + const GRANT_INFO backup_grant_info= t->grant; + Security_context *const backup_table_sctx= t->security_ctx; + t->security_ctx= NULL; /* (1) check_table_access() fills t->grant.privilege. (2) Because SELECT privileges can be column-based, @@ -271,8 +271,8 @@ void opt_trace_disable_if_no_tables_access(THD *thd, TABLE_LIST *tbl) */ rc |= check_table_access(thd, SHOW_VIEW_ACL, t, false, 1, true); } - t->security_ctx = backup_table_sctx; - t->grant = backup_grant_info; + t->security_ctx= backup_table_sctx; + t->grant= backup_grant_info; if (rc) { trace->missing_privilege(); @@ -292,22 +292,22 @@ void opt_trace_disable_if_no_view_access(THD *thd, TABLE_LIST *view, Opt_trace_context::FLAG_ENABLED)) || thd->system_thread) return; - Opt_trace_context *const trace = &thd->opt_trace; + Opt_trace_context *const trace= &thd->opt_trace; if (!thd->trace_started()) return; - Security_context *const backup_table_sctx = view->security_ctx; - Security_context *const backup_thd_sctx = thd->security_context(); - const GRANT_INFO backup_grant_info = view->grant; + Security_context *const backup_table_sctx= view->security_ctx; + Security_context *const backup_thd_sctx= thd->security_context(); + const GRANT_INFO backup_grant_info= view->grant; - view->security_ctx = NULL; // no SUID context for view + view->security_ctx= NULL; // no SUID context for view // no SUID context for THD thd->set_security_context(&thd->main_security_ctx); - const int rc = check_table_access(thd, SHOW_VIEW_ACL, view, false, 1, true); + const int rc= check_table_access(thd, SHOW_VIEW_ACL, view, false, 1, true); - view->security_ctx = backup_table_sctx; + view->security_ctx= backup_table_sctx; thd->set_security_context(backup_thd_sctx); - view->grant = backup_grant_info; + view->grant= backup_grant_info; if (rc) { @@ -347,16 +347,13 @@ class Opt_trace_stmt { ~Opt_trace_stmt() { delete current_json; - missing_priv= false; - ctx= NULL; - I_S_disabled= 0; } void set_query(const char *query_ptr, size_t length, const CHARSET_INFO *charset); void open_struct(const char *key, char opening_bracket); void close_struct(const char *saved_key, char closing_bracket); void fill_info(Opt_trace_info* info); void add(const char *key, char *opening_bracket, size_t val_length); - Json_writer* get_current_json(){return current_json;} + Json_writer* get_current_json() {return current_json;} void missing_privilege(); void disable_tracing_for_children(); void enable_tracing_for_children(); @@ -372,6 +369,12 @@ private: String query; // store the query sent by the user Json_writer *current_json; // stores the trace bool missing_priv; ///< whether user lacks privilege to see this trace + /* + 0 <=> this trace should be in information_schema. + !=0 tracing is disabled, this currently happens when we want to trace a + sub-statement. For now traces are only collect for the top statement + not for the sub-statments. + */ uint I_S_disabled; }; @@ -440,28 +443,11 @@ bool Opt_trace_context::is_enabled() Opt_trace_context::Opt_trace_context() { current_trace= NULL; - inited= FALSE; - traces= NULL; max_mem_size= 0; } Opt_trace_context::~Opt_trace_context() { - inited= FALSE; - /* - would be nice to move this to a function - */ - if (traces) - { - while (traces->elements()) - { - Opt_trace_stmt *prev= traces->at(0); - delete prev; - traces->del(0); - } - delete traces; - traces= NULL; - } - max_mem_size= 0; + delete_traces(); } void Opt_trace_context::set_query(const char *query, size_t length, const CHARSET_INFO *charset) @@ -487,26 +473,21 @@ void Opt_trace_context::start(THD *thd, TABLE_LIST *tbl, DBUG_ASSERT(!current_trace); current_trace= new Opt_trace_stmt(this); max_mem_size= max_mem_size_arg; - if (!inited) - { - traces= new Dynamic_array(); - inited= TRUE; - } set_allowed_mem_size(remaining_mem_size()); } void Opt_trace_context::end() { if (current_trace) - traces->push(current_trace); + traces.push(current_trace); - if (!traces->elements()) + if (!traces.elements()) return; - if (traces->elements() > 1) + if (traces.elements() > 1) { - Opt_trace_stmt *prev= traces->at(0); + Opt_trace_stmt *prev= traces.at(0); delete prev; - traces->del(0); + traces.del(0); } current_trace= NULL; } @@ -522,7 +503,7 @@ Opt_trace_start::Opt_trace_start(THD *thd, TABLE_LIST *tbl, if optimizer trace is enabled and the statment we have is traceable, then we start the context. */ - const ulonglong var = thd->variables.optimizer_trace; + const ulonglong var= thd->variables.optimizer_trace; traceable= FALSE; if (unlikely(var & Opt_trace_context::FLAG_ENABLED) && sql_command_can_be_traced(sql_command) && @@ -554,21 +535,21 @@ Opt_trace_start::~Opt_trace_start() void Opt_trace_stmt::fill_info(Opt_trace_info* info) { - if (unlikely(info->missing_priv = get_missing_priv())) + if (unlikely(info->missing_priv= get_missing_priv())) { - info->trace_ptr = info->query_ptr = ""; - info->trace_length = info->query_length = 0; - info->query_charset = &my_charset_bin; - info->missing_bytes = 0; + info->trace_ptr= info->query_ptr= ""; + info->trace_length= info->query_length= 0; + info->query_charset= &my_charset_bin; + info->missing_bytes= 0; } else { - info->trace_ptr = current_json->output.get_string()->ptr(); - info->trace_length = get_length(); - info->query_ptr = query.ptr(); - info->query_length = query.length(); - info->query_charset = query.charset(); - info->missing_bytes = get_truncated_bytes(); + info->trace_ptr= current_json->output.get_string()->ptr(); + info->trace_length= get_length(); + info->query_ptr= query.ptr(); + info->query_length= query.length(); + info->query_charset= query.charset(); + info->missing_bytes= get_truncated_bytes(); info->missing_priv= get_missing_priv(); } } @@ -659,9 +640,7 @@ void Json_writer::add_str(Item *item) if (item) { THD *thd= current_thd; - char buff[256]; - String str(buff, sizeof(buff), system_charset_info); - str.length(0); + StringBuffer<256> str(system_charset_info); ulonglong save_option_bits= thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_QUOTE_SHOW_CREATE; @@ -675,26 +654,23 @@ void Json_writer::add_str(Item *item) add_null(); } -void Opt_trace_context::flush_optimizer_trace() +void Opt_trace_context::delete_traces() { - inited= false; - if (traces) + if (traces.elements()) { - while (traces->elements()) + while (traces.elements()) { - Opt_trace_stmt *prev= traces->at(0); + Opt_trace_stmt *prev= traces.at(0); delete prev; - traces->del(0); + traces.del(0); } - delete traces; - traces= NULL; } } int fill_optimizer_trace_info(THD *thd, TABLE_LIST *tables, Item *) { - TABLE *table = tables->table; + TABLE *table= tables->table; Opt_trace_info info; /* get_values of trace, query , missing bytes and missing_priv @@ -703,7 +679,7 @@ int fill_optimizer_trace_info(THD *thd, TABLE_LIST *tables, Item *) */ Opt_trace_context* ctx= &thd->opt_trace; - if (thd->opt_trace.empty()) + if (!thd->opt_trace.empty()) { Opt_trace_stmt *stmt= ctx->get_top_trace(); stmt->fill_info(&info); diff --git a/sql/opt_trace.h b/sql/opt_trace.h index 0e2d0146a49..52318bc6b7f 100644 --- a/sql/opt_trace.h +++ b/sql/opt_trace.h @@ -193,9 +193,16 @@ void opt_trace_disable_if_no_stored_proc_func_access(THD *thd, sp_head *sp); */ int fill_optimizer_trace_info(THD *thd, TABLE_LIST *tables, Item *); -#define OPT_TRACE_TRANSFORM(writer, object_level0, object_level1, \ +#define OPT_TRACE_TRANSFORM(thd, object_level0, object_level1, \ select_number, from, to) \ - Json_writer_object object_level0(writer); \ - Json_writer_object object_level1(writer, "transformation"); \ + Json_writer_object object_level0(thd); \ + Json_writer_object object_level1(thd, "transformation"); \ object_level1.add_select_number(select_number).add("from", from).add("to", to); -#endif \ No newline at end of file + +#define OPT_TRACE_VIEWS_TRANSFORM(thd, object_level0, object_level1, \ + derived, name, select_number, algorithm) \ + Json_writer_object trace_wrapper(thd); \ + Json_writer_object trace_derived(thd, derived); \ + trace_derived.add("table", name).add_select_number(select_number) \ + .add("algorithm", algorithm); +#endif diff --git a/sql/opt_trace_context.h b/sql/opt_trace_context.h index 87317f67e22..e5df16b1e3b 100644 --- a/sql/opt_trace_context.h +++ b/sql/opt_trace_context.h @@ -19,14 +19,14 @@ public: ulong max_mem_size_arg); void end(); void set_query(const char *query, size_t length, const CHARSET_INFO *charset); - void flush_optimizer_trace(); + void delete_traces(); void set_allowed_mem_size(size_t mem_size); size_t remaining_mem_size(); private: Opt_trace_stmt* top_trace() { - return *(traces->front()); + return *(traces.front()); } public: @@ -39,7 +39,7 @@ public: Opt_trace_stmt* get_top_trace() { - if (!traces || !traces->elements()) + if (!traces.elements()) return NULL; return top_trace(); } @@ -52,7 +52,7 @@ public: bool empty() { - return traces && (static_cast(traces->elements()) != 0); + return static_cast(traces.elements()) == 0; } bool is_started() @@ -79,13 +79,8 @@ private: /* List of traces (currently it stores only 1 trace) */ - Dynamic_array *traces; + Dynamic_array traces; Opt_trace_stmt *current_trace; - /* - TRUE: if we allocate memory for list of traces - FALSE: otherwise - */ - bool inited; size_t max_mem_size; }; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 891a64a5748..bb0227df212 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1411,7 +1411,7 @@ void THD::change_user(void) sp_cache_clear(&sp_func_cache); sp_cache_clear(&sp_package_spec_cache); sp_cache_clear(&sp_package_body_cache); - opt_trace.flush_optimizer_trace(); + opt_trace.delete_traces(); } /** diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index a3a53320ac0..6bfcd40f411 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -34,6 +34,7 @@ #include "sql_class.h" #include "sql_cte.h" #include "my_json_writer.h" +#include "opt_trace.h" typedef bool (*dt_processor)(THD *thd, LEX *lex, TABLE_LIST *derived); @@ -384,6 +385,15 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived) { /* There is random function => fall back to materialization. */ cause= "Random function in the select"; + if (unlikely(thd->trace_started())) + { + OPT_TRACE_VIEWS_TRANSFORM(thd, trace_wrapper, trace_derived, + derived->is_derived() ? "derived" : "view", + derived->alias.str ? derived->alias.str : "", + derived->get_unit()->first_select()->select_number, + "materialized"); + trace_derived.add("cause", cause); + } derived->change_refs_to_fields(); derived->set_materialized_derived(); DBUG_RETURN(FALSE); @@ -497,19 +507,12 @@ unconditional_materialization: if (unlikely(thd->trace_started())) { - /* - Add to the optimizer trace the change in choice for merged - derived tables/views to materialised ones. - */ - Json_writer_object trace_wrapper(thd); - Json_writer_object trace_derived(thd, derived->is_derived() ? - "derived" : "view"); - trace_derived.add("table", derived->alias.str ? derived->alias.str : "") - .add_select_number(derived->get_unit()-> - first_select()->select_number) - .add("initial_choice", "merged") - .add("final_choice", "materialized") - .add("cause", cause); + OPT_TRACE_VIEWS_TRANSFORM(thd,trace_wrapper, trace_derived, + derived->is_derived() ? "derived" : "view", + derived->alias.str ? derived->alias.str : "", + derived->get_unit()->first_select()->select_number, + "materialized"); + trace_derived.add("cause", cause); } derived->change_refs_to_fields(); @@ -778,15 +781,11 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) Add to optimizer trace whether a derived table/view is merged into the parent select or not. */ - Json_writer_object trace_wrapper(thd); - Json_writer_object trace_derived(thd, derived->is_derived() ? - "derived" : "view"); - trace_derived.add("table", derived->alias.str ? derived->alias.str : "") - .add_select_number(derived->get_unit()->first_select()->select_number); - if (derived->is_materialized_derived()) - trace_derived.add("materialized", true); - if (derived->is_merged_derived()) - trace_derived.add("merged", true); + OPT_TRACE_VIEWS_TRANSFORM(thd, trace_wrapper, trace_derived, + derived->is_derived() ? "derived" : "view", + derived->alias.str ? derived->alias.str : "", + derived->get_unit()->first_select()->select_number, + derived->is_merged_derived() ? "merged" : "materialized"); } /* Above cascade call of prepare is important for PS protocol, but after it diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 3670eff574e..d08f8fe4b29 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -121,6 +121,7 @@ static bool best_extension_by_limited_search(JOIN *join, double read_time, uint depth, uint prune_level, uint use_cond_selectivity); +void trace_plan_prefix(JOIN *join, uint idx, table_map remaining_tables); static uint determine_search_depth(JOIN* join); C_MODE_START static int join_tab_cmp(const void *dummy, const void* ptr1, const void* ptr2); @@ -302,8 +303,6 @@ void set_postjoin_aggr_write_func(JOIN_TAB *tab); static Item **get_sargable_cond(JOIN *join, TABLE *table); -static void trace_plan_prefix(JOIN *join, uint idx, table_map remaining_tables); - #ifndef DBUG_OFF /* @@ -359,16 +358,16 @@ static void trace_table_dependencies(THD *thd, { Json_writer_object trace_wrapper(thd); Json_writer_array trace_dep(thd, "table_dependencies"); - for (uint i = 0; i < table_count; i++) + for (uint i= 0; i < table_count; i++) { - TABLE_LIST *table_ref = join_tabs[i].tab_list; + TABLE_LIST *table_ref= join_tabs[i].tab_list; Json_writer_object trace_one_table(thd); trace_one_table.add_table_name(&join_tabs[i]); trace_one_table.add("row_may_be_null", (bool)table_ref->table->maybe_null); - const table_map map = table_ref->get_map(); + const table_map map= table_ref->get_map(); DBUG_ASSERT(map < (1ULL << table_count)); - for (uint j = 0; j < table_count; j++) + for (uint j= 0; j < table_count; j++) { if (map & (1ULL << j)) { @@ -377,14 +376,10 @@ static void trace_table_dependencies(THD *thd, } } Json_writer_array depends_on(thd, "depends_on_map_bits"); - static_assert(sizeof(table_ref->get_map()) <= 64, - "RAND_TABLE_BIT may be in join_tabs[i].dependent, so we test " - "all 64 bits."); - for (uint j = 0; j < 64; j++) - { - if (join_tabs[i].dependent & (1ULL << j)) - depends_on.add(static_cast(j)); - } + Table_map_iterator it(join_tabs[i].dependent); + uint dep_bit; + while ((dep_bit= it++) != Table_map_iterator::BITMAP_END) + depends_on.add(static_cast(dep_bit)); } } @@ -9045,13 +9040,13 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, } -static void trace_plan_prefix(JOIN *join, uint idx, table_map remaining_tables) +void trace_plan_prefix(JOIN *join, uint idx, table_map remaining_tables) { - THD *const thd = join->thd; + THD *const thd= join->thd; Json_writer_array plan_prefix(thd, "plan_prefix"); - for (uint i = 0; i < idx; i++) + for (uint i= 0; i < idx; i++) { - TABLE_LIST *const tr = join->positions[i].table->tab_list; + TABLE_LIST *const tr= join->positions[i].table->tab_list; if (!(tr->map & remaining_tables)) plan_prefix.add_table_name(join->positions[i].table); } @@ -9261,9 +9256,6 @@ best_extension_by_limited_search(JOIN *join, current_record_count / (double) TIME_FOR_COMPARE - filter_cmp_gain; - /* - TODO add filtering estimates here - */ advance_sj_state(join, remaining_tables, idx, ¤t_record_count, ¤t_read_time, &loose_scan_pos); @@ -11070,12 +11062,6 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) tab->table->intersect_keys.is_set(tab->ref.key)))) { /* Range uses longer key; Use this instead of ref on key */ - - /* - We can trace here, changing ref access to range access here - have a range that uses longer key. - Lets take @spetrunia's opinion - */ Json_writer_object ref_to_range(thd); ref_to_range.add("ref_to_range", true); ref_to_range.add("cause", "range uses longer key"); @@ -16413,6 +16399,8 @@ void optimize_wo_join_buffering(JOIN *join, uint first_tab, uint last_tab, double cost, rec_count; table_map reopt_remaining_tables= last_remaining_tables; uint i; + THD *thd= join->thd; + Json_writer_temp_disable trace_wo_join_buffering(thd); if (first_tab > join->const_tables) { @@ -16447,7 +16435,7 @@ void optimize_wo_join_buffering(JOIN *join, uint first_tab, uint last_tab, { JOIN_TAB *rs= join->positions[i].table; POSITION pos, loose_scan_pos; - + if ((i == first_tab && first_alt) || join->positions[i].use_join_buffer) { /* Find the best access method that would not use join buffering */ diff --git a/sql/sql_test.cc b/sql/sql_test.cc index f247fb10f89..93085251711 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -665,11 +665,11 @@ void print_keyuse_array_for_trace(THD *thd, DYNAMIC_ARRAY *keyuse_array) KEYUSE *keyuse= (KEYUSE*)dynamic_array_ptr(keyuse_array, i); Json_writer_object keyuse_elem(thd); keyuse_elem.add_table_name(keyuse->table->reginfo.join_tab); - keyuse_elem.add("field", (keyuse->keypart == FT_KEYPART) ? "" - : (keyuse->is_for_hash_join() - ? keyuse->table->field[keyuse->keypart] - ->field_name.str - : keyuse->table->key_info[keyuse->key] + keyuse_elem.add("field", (keyuse->keypart == FT_KEYPART) ? "": + (keyuse->is_for_hash_join() ? + keyuse->table->field[keyuse->keypart] + ->field_name.str : + keyuse->table->key_info[keyuse->key] .key_part[keyuse->keypart] .field->field_name.str)); keyuse_elem.add("equals",keyuse->val); From 33fd3998d253aad13913cef00a5f0d3629e423ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 18 Feb 2019 14:21:46 +0200 Subject: [PATCH 14/19] MDEV-18596 Crash in row_mysql_store_col_in_innobase_format() on MODIFY/ADD column innobase_build_col_map_add(): Do not assume that old_field->pack_length() equals to field->pack_length(). Fix submitted by Aleksey Midenkov. innobase_instant_try(): Assert that the column length of fixed-length NOT NULL columns is only changing for ROW_FORMAT=REDUNDANT. --- .../suite/innodb/r/instant_alter.result | 158 +++++++++++++++++- mysql-test/suite/innodb/t/instant_alter.test | 34 ++++ storage/innobase/handler/handler0alter.cc | 22 +-- 3 files changed, 203 insertions(+), 11 deletions(-) diff --git a/mysql-test/suite/innodb/r/instant_alter.result b/mysql-test/suite/innodb/r/instant_alter.result index d6fd90ec27f..14b7aeece25 100644 --- a/mysql-test/suite/innodb/r/instant_alter.result +++ b/mysql-test/suite/innodb/r/instant_alter.result @@ -795,6 +795,58 @@ SELECT HEX(c) FROM t1; HEX(c) 1 DROP TABLE t1; +CREATE TABLE t1 (c VARCHAR(10) NOT NULL DEFAULT 'scary') ENGINE=InnoDB ROW_FORMAT=REDUNDANT; +INSERT INTO t1() VALUES(); +ALTER TABLE t1 ADD f TINYINT NOT NULL DEFAULT -42; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 MODIFY f MEDIUMINT NOT NULL DEFAULT 64802, +MODIFY c VARCHAR(20) NOT NULL DEFAULT 'gory', +ADD d DATETIME; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +INSERT INTO t1() VALUES(); +INSERT INTO t1 (c,f,d) VALUES ('fury', -8388608, now()); +SELECT * FROM t1; +c f d +scary -42 NULL +gory 64802 NULL +fury -8388608 1970-01-01 03:00:42 +DROP TABLE t1; +CREATE TABLE t1 (t TINYINT PRIMARY KEY, m MEDIUMINT UNIQUE) ENGINE=InnoDB ROW_FORMAT=REDUNDANT; +SELECT table_id INTO @table_id1 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +INSERT INTO t1 VALUES (-42, -123456); +ALTER TABLE t1 CHANGE t s SMALLINT; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +SELECT table_id INTO @table_id2 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +affected rows: 1 +ALTER TABLE t1 CHANGE m i INT, ALGORITHM=INSTANT; +ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: ADD INDEX. Try ALGORITHM=NOCOPY +ALTER TABLE t1 CHANGE m i INT; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +SELECT table_id INTO @table_id3 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +affected rows: 1 +SELECT @table_id1 = @table_id2, @table_id2 = @table_id3; +@table_id1 = @table_id2 @table_id2 = @table_id3 +0 1 +INSERT IGNORE INTO t1 VALUES (0, -123456); +REPLACE INTO t1 VALUES(-42, 123456); +INSERT IGNORE INTO t1 VALUES(32768, 2147483648); +Warnings: +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 'i' at row 1 +SELECT * FROM t1; +s i +-42 -123456 +0 -123456 +-42 123456 +32767 2147483647 +DROP TABLE t1; CREATE TABLE t1 (id INT PRIMARY KEY, c2 INT UNIQUE, c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'), @@ -1536,6 +1588,58 @@ SELECT HEX(c) FROM t1; HEX(c) 1 DROP TABLE t1; +CREATE TABLE t1 (c VARCHAR(10) NOT NULL DEFAULT 'scary') ENGINE=InnoDB ROW_FORMAT=COMPACT; +INSERT INTO t1() VALUES(); +ALTER TABLE t1 ADD f TINYINT NOT NULL DEFAULT -42; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 MODIFY f MEDIUMINT NOT NULL DEFAULT 64802, +MODIFY c VARCHAR(20) NOT NULL DEFAULT 'gory', +ADD d DATETIME; +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 +INSERT INTO t1() VALUES(); +INSERT INTO t1 (c,f,d) VALUES ('fury', -8388608, now()); +SELECT * FROM t1; +c f d +scary -42 NULL +gory 64802 NULL +fury -8388608 1970-01-01 03:00:42 +DROP TABLE t1; +CREATE TABLE t1 (t TINYINT PRIMARY KEY, m MEDIUMINT UNIQUE) ENGINE=InnoDB ROW_FORMAT=COMPACT; +SELECT table_id INTO @table_id1 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +INSERT INTO t1 VALUES (-42, -123456); +ALTER TABLE t1 CHANGE t s SMALLINT; +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 +SELECT table_id INTO @table_id2 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +affected rows: 1 +ALTER TABLE t1 CHANGE m i INT, ALGORITHM=INSTANT; +ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY +ALTER TABLE t1 CHANGE m i INT; +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 +SELECT table_id INTO @table_id3 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +affected rows: 1 +SELECT @table_id1 = @table_id2, @table_id2 = @table_id3; +@table_id1 = @table_id2 @table_id2 = @table_id3 +0 0 +INSERT IGNORE INTO t1 VALUES (0, -123456); +Warnings: +Warning 1062 Duplicate entry '-123456' for key 'm' +REPLACE INTO t1 VALUES(-42, 123456); +INSERT IGNORE INTO t1 VALUES(32768, 2147483648); +Warnings: +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 'i' at row 1 +SELECT * FROM t1; +s i +-42 123456 +32767 2147483647 +DROP TABLE t1; CREATE TABLE t1 (id INT PRIMARY KEY, c2 INT UNIQUE, c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'), @@ -2277,10 +2381,62 @@ SELECT HEX(c) FROM t1; HEX(c) 1 DROP TABLE t1; +CREATE TABLE t1 (c VARCHAR(10) NOT NULL DEFAULT 'scary') ENGINE=InnoDB ROW_FORMAT=DYNAMIC; +INSERT INTO t1() VALUES(); +ALTER TABLE t1 ADD f TINYINT NOT NULL DEFAULT -42; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 MODIFY f MEDIUMINT NOT NULL DEFAULT 64802, +MODIFY c VARCHAR(20) NOT NULL DEFAULT 'gory', +ADD d DATETIME; +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 +INSERT INTO t1() VALUES(); +INSERT INTO t1 (c,f,d) VALUES ('fury', -8388608, now()); +SELECT * FROM t1; +c f d +scary -42 NULL +gory 64802 NULL +fury -8388608 1970-01-01 03:00:42 +DROP TABLE t1; +CREATE TABLE t1 (t TINYINT PRIMARY KEY, m MEDIUMINT UNIQUE) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; +SELECT table_id INTO @table_id1 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +INSERT INTO t1 VALUES (-42, -123456); +ALTER TABLE t1 CHANGE t s SMALLINT; +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 +SELECT table_id INTO @table_id2 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +affected rows: 1 +ALTER TABLE t1 CHANGE m i INT, ALGORITHM=INSTANT; +ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY +ALTER TABLE t1 CHANGE m i INT; +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 +SELECT table_id INTO @table_id3 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +affected rows: 1 +SELECT @table_id1 = @table_id2, @table_id2 = @table_id3; +@table_id1 = @table_id2 @table_id2 = @table_id3 +0 0 +INSERT IGNORE INTO t1 VALUES (0, -123456); +Warnings: +Warning 1062 Duplicate entry '-123456' for key 'm' +REPLACE INTO t1 VALUES(-42, 123456); +INSERT IGNORE INTO t1 VALUES(32768, 2147483648); +Warnings: +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 'i' at row 1 +SELECT * FROM t1; +s i +-42 123456 +32767 2147483647 +DROP TABLE t1; disconnect analyze; SELECT variable_value-@old_instant instants FROM information_schema.global_status WHERE variable_name = 'innodb_instant_alter_column'; instants -171 +175 SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency; diff --git a/mysql-test/suite/innodb/t/instant_alter.test b/mysql-test/suite/innodb/t/instant_alter.test index 013b2483f54..c36b5801b1e 100644 --- a/mysql-test/suite/innodb/t/instant_alter.test +++ b/mysql-test/suite/innodb/t/instant_alter.test @@ -681,6 +681,40 @@ ALTER TABLE t1 CHANGE b c BIT NOT NULL; SELECT HEX(c) FROM t1; DROP TABLE t1; +eval CREATE TABLE t1 (c VARCHAR(10) NOT NULL DEFAULT 'scary') $engine; +INSERT INTO t1() VALUES(); +--enable_info +ALTER TABLE t1 ADD f TINYINT NOT NULL DEFAULT -42; +ALTER TABLE t1 MODIFY f MEDIUMINT NOT NULL DEFAULT 64802, +MODIFY c VARCHAR(20) NOT NULL DEFAULT 'gory', +ADD d DATETIME; +--disable_info +INSERT INTO t1() VALUES(); +INSERT INTO t1 (c,f,d) VALUES ('fury', -8388608, now()); +SELECT * FROM t1; +DROP TABLE t1; + +eval CREATE TABLE t1 (t TINYINT PRIMARY KEY, m MEDIUMINT UNIQUE) $engine; +SELECT table_id INTO @table_id1 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +INSERT INTO t1 VALUES (-42, -123456); +--enable_info +ALTER TABLE t1 CHANGE t s SMALLINT; +SELECT table_id INTO @table_id2 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON +ALTER TABLE t1 CHANGE m i INT, ALGORITHM=INSTANT; +ALTER TABLE t1 CHANGE m i INT; +SELECT table_id INTO @table_id3 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name = 'test/t1'; +--disable_info +SELECT @table_id1 = @table_id2, @table_id2 = @table_id3; +INSERT IGNORE INTO t1 VALUES (0, -123456); +REPLACE INTO t1 VALUES(-42, 123456); +INSERT IGNORE INTO t1 VALUES(32768, 2147483648); +SELECT * FROM t1; +DROP TABLE t1; + dec $format; } disconnect analyze; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index b0f87fdae9e..8612aa9404b 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -4122,7 +4122,7 @@ innobase_check_foreigns( @param[in,out] heap Memory heap where allocated @param[out] dfield InnoDB data field to copy to @param[in] field MySQL value for the column -@param[in] old_field Old field or NULL if new col is added +@param[in] old_field Old column if altering; NULL for ADD COLUMN @param[in] comp nonzero if in compact format. */ static void innobase_build_col_map_add( mem_heap_t* heap, @@ -4141,14 +4141,13 @@ static void innobase_build_col_map_add( return; } - ulint size = field->pack_length(); + const Field& from = old_field ? *old_field : *field; + ulint size = from.pack_length(); byte* buf = static_cast(mem_heap_alloc(heap, size)); - const byte* mysql_data = old_field ? old_field->ptr : field->ptr; - row_mysql_store_col_in_innobase_format( - dfield, buf, true, mysql_data, size, comp); + dfield, buf, true, from.ptr, size, comp); } /** Construct the translation table for reordering, dropping or @@ -5547,6 +5546,11 @@ static bool innobase_instant_try( dict_table_get_col_name(user_table, i))); DBUG_ASSERT(old || col->is_added()); + ut_d(const Create_field* new_field = cf_it++); + /* new_field->field would point to an existing column. + If it is NULL, the column was added by this ALTER TABLE. */ + ut_ad(!new_field->field == !old); + if (col->is_added()) { dfield_set_data(d, col->def_val.data, col->def_val.len); @@ -5580,14 +5584,12 @@ static bool innobase_instant_try( mem_heap_alloc(ctx->heap, len)) : NULL, true, (*af)->ptr, len, dict_table_is_comp(user_table)); + ut_ad(new_field->field->pack_length() == len + || !user_table->not_redundant()); + } } - ut_d(const Create_field* new_field = cf_it++); - /* new_field->field would point to an existing column. - If it is NULL, the column was added by this ALTER TABLE. */ - ut_ad(!new_field->field == !old); - bool update = old && (!ctx->first_alter_pos || i < ctx->first_alter_pos - 1); ut_ad(!old || col->same_format( From f0b65102b23f006f596eef35e6e5f4f8b6d8146d Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Thu, 14 Feb 2019 23:49:07 +0200 Subject: [PATCH 15/19] MDEV-18585 Avoid excessive Annotate_rows_log_events in binlog Make sure that the Annotate_rows_log_events is written into binlog only for the first fragment of the current statement. Also avoid flusing pending rows event when calculating bytes generated by the transaction. Added and recorded a test which verifies that the binlog contains only one Annotate_rows_log_event per statement with various SR settings. Recrded mysql-wsrep-features#136 which produced different output with excession log events suppressed. --- .../suite/galera_sr/r/MDEV-18585.result | 36 ++++++++++++++++ .../r/mysql-wsrep-features#136.result | 2 - mysql-test/suite/galera_sr/t/MDEV-18585.cnf | 5 +++ mysql-test/suite/galera_sr/t/MDEV-18585.test | 42 +++++++++++++++++++ sql/handler.cc | 4 +- sql/wsrep_client_service.cc | 8 +++- sql/wsrep_trans_observer.h | 8 ++++ wsrep-lib | 2 +- 8 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 mysql-test/suite/galera_sr/r/MDEV-18585.result create mode 100644 mysql-test/suite/galera_sr/t/MDEV-18585.cnf create mode 100644 mysql-test/suite/galera_sr/t/MDEV-18585.test diff --git a/mysql-test/suite/galera_sr/r/MDEV-18585.result b/mysql-test/suite/galera_sr/r/MDEV-18585.result new file mode 100644 index 00000000000..d30def1ea63 --- /dev/null +++ b/mysql-test/suite/galera_sr/r/MDEV-18585.result @@ -0,0 +1,36 @@ +connection node_2; +connection node_1; +CREATE TABLE t1 (f1 INT PRIMARY KEY); +SET SESSION wsrep_trx_fragment_unit='ROWS'; +SET SESSION wsrep_trx_fragment_size=1; +INSERT INTO t1 VALUES (1), (2); +SET SESSION wsrep_trx_fragment_unit='BYTES'; +SET SESSION wsrep_trx_fragment_size=1; +INSERT INTO t1 VALUES (3), (4); +SET SESSION wsrep_trx_fragment_unit='STATEMENTS'; +SET SESSION wsrep_trx_fragment_size=1; +INSERT INTO t1 VALUES (5), (6); +SET SESSION wsrep_trx_fragment_unit=default; +SET SESSION wsrep_trx_fragment_size=default; +SHOW BINLOG EVENTS IN 'mysqld-bin.000002' FROM 518; +Log_name Pos Event_type Server_id End_log_pos Info +mysqld-bin.000002 518 Gtid 1 560 BEGIN GTID 0-1-2 +mysqld-bin.000002 560 Annotate_rows 1 613 INSERT INTO t1 VALUES (1), (2) +mysqld-bin.000002 613 Table_map 1 658 table_id: # (test.t1) +mysqld-bin.000002 658 Write_rows_v1 1 696 table_id: # flags: STMT_END_F +mysqld-bin.000002 696 Table_map 1 741 table_id: # (test.t1) +mysqld-bin.000002 741 Write_rows_v1 1 779 table_id: # flags: STMT_END_F +mysqld-bin.000002 779 Xid 1 810 COMMIT /* xid=# */ +mysqld-bin.000002 810 Gtid 1 852 BEGIN GTID 0-1-3 +mysqld-bin.000002 852 Annotate_rows 1 905 INSERT INTO t1 VALUES (3), (4) +mysqld-bin.000002 905 Table_map 1 950 table_id: # (test.t1) +mysqld-bin.000002 950 Write_rows_v1 1 988 table_id: # flags: STMT_END_F +mysqld-bin.000002 988 Table_map 1 1033 table_id: # (test.t1) +mysqld-bin.000002 1033 Write_rows_v1 1 1071 table_id: # flags: STMT_END_F +mysqld-bin.000002 1071 Xid 1 1102 COMMIT /* xid=# */ +mysqld-bin.000002 1102 Gtid 1 1144 BEGIN GTID 0-1-4 +mysqld-bin.000002 1144 Annotate_rows 1 1197 INSERT INTO t1 VALUES (5), (6) +mysqld-bin.000002 1197 Table_map 1 1242 table_id: # (test.t1) +mysqld-bin.000002 1242 Write_rows_v1 1 1285 table_id: # flags: STMT_END_F +mysqld-bin.000002 1285 Xid 1 1316 COMMIT /* xid=# */ +DROP TABLE t1; diff --git a/mysql-test/suite/galera_sr/r/mysql-wsrep-features#136.result b/mysql-test/suite/galera_sr/r/mysql-wsrep-features#136.result index 25bc2e11a3e..84246a8eed2 100644 --- a/mysql-test/suite/galera_sr/r/mysql-wsrep-features#136.result +++ b/mysql-test/suite/galera_sr/r/mysql-wsrep-features#136.result @@ -29,7 +29,6 @@ mysqld-bin.000001 Gtid 1 BEGIN GTID 0-1-2 mysqld-bin.000001 Annotate_rows 1 INSERT INTO t1 VALUES (1),(2) mysqld-bin.000001 Table_map 1 table_id: ### (test.t1) mysqld-bin.000001 Write_rows_v1 1 table_id: ### flags: STMT_END_F -mysqld-bin.000001 Annotate_rows 1 INSERT INTO t1 VALUES (1),(2) mysqld-bin.000001 Table_map 1 table_id: ### (test.t1) mysqld-bin.000001 Write_rows_v1 1 table_id: ### flags: STMT_END_F mysqld-bin.000001 Xid 1 COMMIT /* xid=### */ @@ -52,7 +51,6 @@ mysqld-bin.000001 Gtid 1 BEGIN GTID 0-1-2 mysqld-bin.000001 Annotate_rows 1 INSERT INTO t1 VALUES (1),(2) mysqld-bin.000001 Table_map 1 table_id: ### (test.t1) mysqld-bin.000001 Write_rows_v1 1 table_id: ### flags: STMT_END_F -mysqld-bin.000001 Annotate_rows 1 INSERT INTO t1 VALUES (1),(2) mysqld-bin.000001 Table_map 1 table_id: ### (test.t1) mysqld-bin.000001 Write_rows_v1 1 table_id: ### flags: STMT_END_F mysqld-bin.000001 Xid 1 COMMIT /* xid=### */ diff --git a/mysql-test/suite/galera_sr/t/MDEV-18585.cnf b/mysql-test/suite/galera_sr/t/MDEV-18585.cnf new file mode 100644 index 00000000000..00801511d76 --- /dev/null +++ b/mysql-test/suite/galera_sr/t/MDEV-18585.cnf @@ -0,0 +1,5 @@ +!include ../galera_2nodes.cnf + +[mysqld.1] +log-bin +log-slave-updates diff --git a/mysql-test/suite/galera_sr/t/MDEV-18585.test b/mysql-test/suite/galera_sr/t/MDEV-18585.test new file mode 100644 index 00000000000..18bbbe8f7e0 --- /dev/null +++ b/mysql-test/suite/galera_sr/t/MDEV-18585.test @@ -0,0 +1,42 @@ +# +# MDEV-18686 Verify that the Annotate_rows_log_event is written only +# once per statement into binlog. +# +--source include/galera_cluster.inc + +CREATE TABLE t1 (f1 INT PRIMARY KEY); + +# +# Unit ROW +# +SET SESSION wsrep_trx_fragment_unit='ROWS'; +SET SESSION wsrep_trx_fragment_size=1; + +INSERT INTO t1 VALUES (1), (2); + +# +# Unit BYTE +# +SET SESSION wsrep_trx_fragment_unit='BYTES'; +SET SESSION wsrep_trx_fragment_size=1; + +INSERT INTO t1 VALUES (3), (4); + +# +# Unit STATEMENT +# +SET SESSION wsrep_trx_fragment_unit='STATEMENTS'; +SET SESSION wsrep_trx_fragment_size=1; + +INSERT INTO t1 VALUES (5), (6); + +# +# Reset to default settings +# +SET SESSION wsrep_trx_fragment_unit=default; +SET SESSION wsrep_trx_fragment_size=default; + +--replace_regex /table_id: [0-9]+/table_id: #/ /xid=[0-9]+/xid=#/ +SHOW BINLOG EVENTS IN 'mysqld-bin.000002' FROM 518; + +DROP TABLE t1; diff --git a/sql/handler.cc b/sql/handler.cc index 9f656806b5d..bc183837903 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -6256,7 +6256,9 @@ static int write_locked_table_maps(THD *thd) MYSQL_LOCK *locks[2]; locks[0]= thd->extra_lock; locks[1]= thd->lock; - my_bool with_annotate= thd->variables.binlog_annotate_row_events && + my_bool with_annotate= IF_WSREP(!wsrep_fragments_certified_for_stmt(thd), + true) && + thd->variables.binlog_annotate_row_events && thd->query() && thd->query_length(); for (uint i= 0 ; i < sizeof(locks)/sizeof(*locks) ; ++i ) diff --git a/sql/wsrep_client_service.cc b/sql/wsrep_client_service.cc index 994fa97db60..62b90cc032f 100644 --- a/sql/wsrep_client_service.cc +++ b/sql/wsrep_client_service.cc @@ -229,8 +229,12 @@ size_t Wsrep_client_service::bytes_generated() const IO_CACHE* cache= wsrep_get_trans_cache(m_thd); if (cache) { - m_thd->binlog_flush_pending_rows_event(true); - return my_b_tell(cache); + size_t pending_rows_event_length= 0; + if (Rows_log_event* ev= m_thd->binlog_get_pending_rows_event(true)) + { + pending_rows_event_length= ev->get_data_size(); + } + return my_b_tell(cache) + pending_rows_event_length; } return 0; } diff --git a/sql/wsrep_trans_observer.h b/sql/wsrep_trans_observer.h index a3acc9e78fb..04a1224701e 100644 --- a/sql/wsrep_trans_observer.h +++ b/sql/wsrep_trans_observer.h @@ -83,6 +83,14 @@ static inline bool wsrep_streaming_enabled(THD* thd) return (thd->wsrep_sr().fragment_size() > 0); } +/* + Return number of fragments succesfully certified for the + current statement. + */ +static inline size_t wsrep_fragments_certified_for_stmt(THD* thd) +{ + return thd->wsrep_trx().fragments_certified_for_statement(); +} static inline int wsrep_start_transaction(THD* thd, wsrep_trx_id_t trx_id) { diff --git a/wsrep-lib b/wsrep-lib index af8383daf03..92024c7d502 160000 --- a/wsrep-lib +++ b/wsrep-lib @@ -1 +1 @@ -Subproject commit af8383daf03bee80b8e54ce207fa9ef1f9d83f94 +Subproject commit 92024c7d502b716c8c0ca5e2b9524b43d3a5378c From 2c74799d6496f9dbc17bb2cbe764ac81e60e7734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 18 Feb 2019 18:30:01 +0200 Subject: [PATCH 16/19] MDEV-18627 Wrong result after instant size change of integer If we instantly change the size of a fixed-length field and treat it as kind-of variable-length, then we will need conversions between old column values and new ones. I tried adding such a conversion to row_build(), but then I noticed that more conversions would be needed, because old values still appeared in a freshly rebuilt secondary index, causing a mismatch when trying to search with the correct longer value that was converted in my provisional fix to row_build(). So, we will revert the essential part of MDEV-15563: Instant ROW_FORMAT=REDUNDANT column extension (commit 22feb179ae166500ec91feec6246c8154e33f9a2), but not remove any tests. --- .../suite/innodb/r/instant_alter.result | 74 ++++++++++--- .../r/instant_alter_charset,redundant.rdiff | 18 --- .../innodb/r/instant_alter_extend.result | Bin 7781 -> 8753 bytes mysql-test/suite/innodb/t/instant_alter.test | 13 +++ .../suite/innodb/t/instant_alter_extend.test | 103 ++++++++++++------ sql/field.cc | 24 ---- sql/handler.h | 8 -- sql/sql_priv.h | 5 - sql/sql_table.cc | 3 - storage/innobase/btr/btr0btr.cc | 4 +- storage/innobase/btr/btr0cur.cc | 10 +- storage/innobase/data/data0type.cc | 16 --- storage/innobase/dict/dict0dict.cc | 8 -- storage/innobase/handler/ha_innodb.cc | 2 +- storage/innobase/handler/handler0alter.cc | 38 ++----- storage/innobase/include/data0type.ic | 20 +--- storage/innobase/include/dict0mem.h | 48 ++------ storage/innobase/row/row0merge.cc | 7 +- storage/innobase/row/row0mysql.cc | 13 +-- storage/innobase/row/row0sel.cc | 18 +-- 20 files changed, 186 insertions(+), 246 deletions(-) diff --git a/mysql-test/suite/innodb/r/instant_alter.result b/mysql-test/suite/innodb/r/instant_alter.result index 14b7aeece25..8753977c0b8 100644 --- a/mysql-test/suite/innodb/r/instant_alter.result +++ b/mysql-test/suite/innodb/r/instant_alter.result @@ -741,8 +741,8 @@ CREATE TABLE t1 (f TINYINT, g SMALLINT UNSIGNED) ENGINE=InnoDB ROW_FORMAT=REDUND INSERT INTO t1 VALUES(127,6502),(-128,33101); ALTER TABLE t1 MODIFY f SMALLINT DEFAULT 12345, MODIFY g BIGINT UNSIGNED DEFAULT 1234567; -affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 SELECT * FROM t1; f g 127 6502 @@ -803,8 +803,8 @@ info: Records: 0 Duplicates: 0 Warnings: 0 ALTER TABLE t1 MODIFY f MEDIUMINT NOT NULL DEFAULT 64802, MODIFY c VARCHAR(20) NOT NULL DEFAULT 'gory', ADD d DATETIME; -affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 INSERT INTO t1() VALUES(); INSERT INTO t1 (c,f,d) VALUES ('fury', -8388608, now()); SELECT * FROM t1; @@ -818,23 +818,25 @@ SELECT table_id INTO @table_id1 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE name = 'test/t1'; INSERT INTO t1 VALUES (-42, -123456); ALTER TABLE t1 CHANGE t s SMALLINT; -affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 SELECT table_id INTO @table_id2 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE name = 'test/t1'; affected rows: 1 ALTER TABLE t1 CHANGE m i INT, ALGORITHM=INSTANT; -ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: ADD INDEX. Try ALGORITHM=NOCOPY +ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY ALTER TABLE t1 CHANGE m i INT; -affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 SELECT table_id INTO @table_id3 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE name = 'test/t1'; affected rows: 1 SELECT @table_id1 = @table_id2, @table_id2 = @table_id3; @table_id1 = @table_id2 @table_id2 = @table_id3 -0 1 +0 0 INSERT IGNORE INTO t1 VALUES (0, -123456); +Warnings: +Warning 1062 Duplicate entry '-123456' for key 'm' REPLACE INTO t1 VALUES(-42, 123456); INSERT IGNORE INTO t1 VALUES(32768, 2147483648); Warnings: @@ -842,11 +844,25 @@ Warning 1264 Out of range value for column 's' at row 1 Warning 1264 Out of range value for column 'i' at row 1 SELECT * FROM t1; s i --42 -123456 -0 -123456 -42 123456 32767 2147483647 DROP TABLE t1; +CREATE TABLE t1 (a SERIAL, b INT, c TINYINT UNIQUE) ENGINE=InnoDB ROW_FORMAT=REDUNDANT; +INSERT INTO t1 (c) VALUES(1),(2),(3); +ALTER TABLE t1 MODIFY c BIGINT; +affected rows: 3 +info: Records: 3 Duplicates: 0 Warnings: 0 +UPDATE t1 SET b=1 WHERE c=2; +UPDATE t1 SET c=4 WHERE a=3; +UPDATE t1 SET b=2 WHERE c>3; +UPDATE t1 SET c=c+1; +ERROR 23000: Duplicate entry '2' for key 'c' +SELECT * FROM t1; +a b c +1 NULL 1 +2 1 2 +3 2 4 +DROP TABLE t1; CREATE TABLE t1 (id INT PRIMARY KEY, c2 INT UNIQUE, c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'), @@ -1640,6 +1656,22 @@ s i -42 123456 32767 2147483647 DROP TABLE t1; +CREATE TABLE t1 (a SERIAL, b INT, c TINYINT UNIQUE) ENGINE=InnoDB ROW_FORMAT=COMPACT; +INSERT INTO t1 (c) VALUES(1),(2),(3); +ALTER TABLE t1 MODIFY c BIGINT; +affected rows: 3 +info: Records: 3 Duplicates: 0 Warnings: 0 +UPDATE t1 SET b=1 WHERE c=2; +UPDATE t1 SET c=4 WHERE a=3; +UPDATE t1 SET b=2 WHERE c>3; +UPDATE t1 SET c=c+1; +ERROR 23000: Duplicate entry '2' for key 'c' +SELECT * FROM t1; +a b c +1 NULL 1 +2 1 2 +3 2 4 +DROP TABLE t1; CREATE TABLE t1 (id INT PRIMARY KEY, c2 INT UNIQUE, c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'), @@ -2433,10 +2465,26 @@ s i -42 123456 32767 2147483647 DROP TABLE t1; +CREATE TABLE t1 (a SERIAL, b INT, c TINYINT UNIQUE) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; +INSERT INTO t1 (c) VALUES(1),(2),(3); +ALTER TABLE t1 MODIFY c BIGINT; +affected rows: 3 +info: Records: 3 Duplicates: 0 Warnings: 0 +UPDATE t1 SET b=1 WHERE c=2; +UPDATE t1 SET c=4 WHERE a=3; +UPDATE t1 SET b=2 WHERE c>3; +UPDATE t1 SET c=c+1; +ERROR 23000: Duplicate entry '2' for key 'c' +SELECT * FROM t1; +a b c +1 NULL 1 +2 1 2 +3 2 4 +DROP TABLE t1; disconnect analyze; SELECT variable_value-@old_instant instants FROM information_schema.global_status WHERE variable_name = 'innodb_instant_alter_column'; instants -175 +174 SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency; diff --git a/mysql-test/suite/innodb/r/instant_alter_charset,redundant.rdiff b/mysql-test/suite/innodb/r/instant_alter_charset,redundant.rdiff index 9a8dcd45e36..82a5ca95986 100644 --- a/mysql-test/suite/innodb/r/instant_alter_charset,redundant.rdiff +++ b/mysql-test/suite/innodb/r/instant_alter_charset,redundant.rdiff @@ -1,23 +1,5 @@ --- instant_alter_charset.result +++ instant_alter_charset,redundant.result -@@ -143,7 +143,7 @@ - drop index ab, - add unique key ab(a,c), - algorithm=instant; --ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY -+ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: ADD INDEX. Try ALGORITHM=NOCOPY - drop table key_part_change; - create table key_part_change_and_rename ( - a char(100) charset ascii, -@@ -156,7 +156,7 @@ - drop index ab, - add unique key ab(a,b), - algorithm=instant; --ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY -+ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: ADD INDEX. Try ALGORITHM=NOCOPY - drop table key_part_change_and_rename; - create table enum_and_set ( - a enum('one', 'two') charset utf8mb3, @@ -254,7 +254,6 @@ alter table boundary_255 modify b varchar(200) charset utf8mb3, diff --git a/mysql-test/suite/innodb/r/instant_alter_extend.result b/mysql-test/suite/innodb/r/instant_alter_extend.result index d353e5f97f4440b1054af45964ab18662c2b389e..ca8e566f19ce2e5ac7f5f2cf79da79754b5fe62f 100644 GIT binary patch literal 8753 zcmeHNZFAZ<5WcVWuh?m44!EJIUwCVBxhYN3E7K%oC~c>o7zGRBsV#H1XiYx!x8F*# z4F;Pe4Y{ z$M4UNyXQj~2j1Lgz!x(L<150Z^miI_$|5&lI8QaCUuejw11?J@?X;|RO@FG7LrOS> zAcT<4JTj)>5Kb;hM1j+YAL#S!DWV)4Iw5n9k0Ks~WJ*VrO zFT^_(6XM*}ieXxIquFYAUR3H}8?}RiMQ33!rp`PR=F{=#5t`u9s{B1-#Ha9ugt)P= zYBig+ntn-fSzOJdV-9MRD>laic$xmGPr|^*&n7|W6ON7;ML4%l_LQ-sXc4JpBK_+X z#g*kchv-W-7G{g>KSzs~Mxf=%l458beBtjpT+z5X3&nE{NCfJ!4jyH74pg#bkYZ%5pbWi{8 z4|>BlXNSG>cSC_*Hv$%Lh~~3dAW*so14^QR?ZXj4VDSXfIh6O#FHXBhCwnjq7b{a9 z^)Ei%$;NRoTNDAZzyp@@0PYI8q`=0}J>Hx~P)$&e9xDF6a$UK}dpJG%cQQdtBU8iR zYqSp*PB#hm(IMj?bi@Y$$Mc!zB19?vX#jjAA#>SO{E@aEwHl#cYo;!_nt?%P9EUmw`cSY}>(8{aXgU(aP!Bjj z7p&UjntW43c<_0o_224a;(0mhSGe$(;F%_ArYTwp1JDdh>lnuC6AeRxw2+*j%p>8H z`jqkQ0FaRX-^~)>nB{KeW=pzRCKj$hm8K%hxC9VXQ_Kn?4rRX2^7jrJTN$o4j?A7!4r>Eta zJ()n9S~gH=uIF}hYi{2>sTJD#a8)YZ%MKWvKt3%(cdAoa3Ch3a(FvBkI+!&qbFx}x z19ed*9<5f{n*G{nWW_2urQM=jrT*SQ!TJFBGNwm zfh;@4-SI&73zw1KzVAoB{=WBqmA8I`oF|KKk8vsvh|8;Kw5{~Uz+JY$+dS6HqM8d; z6U7Uxr$u+s7$P4p6ZrOh3+@J?Vjb6gET_g=OKTXGX6f@8N;D|XfVkerhhSUnR=d<2 zK6Tu=|1j>5D?hG7UTF4)LppY+(=y6k@-WUwR()J|*ji)59hTW>H#&B!QSK4Ez&(sp zmTNz*UpiVx2n9l0gx=Xje=vk$_tojiy9*SN%5#wg)mSJ!>&eCf$Bo7$bd>lJ%}_Yq zq9U1Mnv$GmrZjF?YaBLHc}<#dpijJcbd@X!+yoRhfyP2ILzR|!0d7s+2%@!lEO31> zDrf6ja>KP_yrREn)uP3pO9?s>JeV;~h`g34wn@jmC1j(^!$tMALW zRLJERdkvLZT{JILA0e*Paq5hU?vw?n+9#Lbj4Ug5G?#X4oCWT5jyLs8WKEwm(`q%f zW9*dx59gv|fSRpfWYUVMkO~kkR9w_>*T`m~HM-iM9+&-Ok-;ex^kvgUvB71dj2)`K zQLSx>j!I&yctM#yQ}*$Gxyb^=Q;sC*p+luBf>-QG5L6OnImRnDW{{_7vuas&OsfGG zZ$ZLIww0bG7hcSmqDeI&t``-ypR#x=qw64^h4Klu_w3RTBuygo{z}+QK_J40d>`fBK_D1}yF2SXN67&FTrV}q2Y}$CpSH&Ytrsqt5t{g#+5Nw&}DVKFK*V5>4d>7 zEeP0U+%+a+?OJcOG@(HMCoUIv_*)bX9J0*IZMzOw3pW{Q=CAK67A_t(5%^AQW9xbI tojbC4EgEah>Vj_T9ToY_vL0(hZ`=6mK^TzxpBeH%B@_S;&t?os_Aj*tjk^E< delta 846 zcmdn!^3-O6_hdsU;fa-w@x_T{sqty~MY)M3wh9go?mqrbjy`&sd3pIMN%1MEX^Evd zCGkc1kCytpp->qHA)TILBmPc?}n&@Ps>yD>0`ewMd~PF)1fip~O%jr6|8ZAvr&% zG&fJ75{rh(8$}f+Pf(DY{76B0vY@o^3; +--error ER_DUP_ENTRY +UPDATE t1 SET c=c+1; +SELECT * FROM t1; +DROP TABLE t1; + dec $format; } disconnect analyze; diff --git a/mysql-test/suite/innodb/t/instant_alter_extend.test b/mysql-test/suite/innodb/t/instant_alter_extend.test index 80f82820afe..6b528c1d30c 100644 --- a/mysql-test/suite/innodb/t/instant_alter_extend.test +++ b/mysql-test/suite/innodb/t/instant_alter_extend.test @@ -1,8 +1,10 @@ --source include/have_innodb.inc +--source include/innodb_row_format.inc --source include/maybe_debug.inc -- echo # -- echo # MDEV-15563: Instant ROW_FORMAT=REDUNDANT column type change&extension +-- echo # (reverted in MDEV-18627) -- echo # # Use character-set-server in test db @@ -10,8 +12,6 @@ create or replace database test; use test; set default_storage_engine=innodb; -set @save_format= @@GLOBAL.innodb_default_row_format; -SET GLOBAL innodb_default_row_format=redundant; set @bigval= repeat('0123456789', 30); delimiter ~~; @@ -45,7 +45,9 @@ set @save_debug= @@SESSION.debug_dbug; set debug_dbug= '+d,ib_instant_error'; --enable_query_log } -alter table t modify a char(200), algorithm=instant; +--enable_info +alter table t modify a char(200); +--disable_info select count(a) from t where a = @bigval; select a, length(a) from t where a = 'z'; @@ -53,7 +55,9 @@ check table t extended; call check_table('t'); --echo # CHAR enlargement -alter table t modify a char(220), algorithm=instant; +--enable_info +alter table t modify a char(220); +--disable_info select count(a) from t where a = @bigval; select a, length(a) from t where a = 'z'; @@ -61,10 +65,10 @@ check table t extended; call check_table('t'); --echo # Convert from VARCHAR to a bigger CHAR ---error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON -alter table t modify a varchar(200), algorithm=instant; -alter table t modify a varchar(200), algorithm=copy; -alter table t modify a char(255), algorithm=instant; +--enable_info +alter table t modify a varchar(200); +alter table t modify a char(255); +--disable_info select count(a) from t where a = @bigval; select a, length(a) from t where a = 'z'; @@ -74,14 +78,17 @@ call check_table('t'); --echo # BINARY/VARBINARY test create or replace table t (a varbinary(300)); ---error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON -alter table t modify a binary(255), algorithm=instant; -alter table t modify a binary(255), algorithm=copy; +insert into t values(NULL); +--enable_info +alter table t modify a binary(255); +--disable_info create or replace table t (a varbinary(200)); insert into t values (@bigval); insert into t values ('z'); -alter table t modify a binary(200), algorithm=instant; +--enable_info +alter table t modify a binary(200); +--disable_info select count(a) from t where a = @bigval; select length(a) from t where left(a, 1) = 'z'; @@ -89,16 +96,18 @@ check table t extended; call check_table('t'); --echo # BINARY enlargement -alter table t modify a binary(220), algorithm=instant; +--enable_info +alter table t modify a binary(220); +--disable_info check table t extended; call check_table('t'); --echo # Convert from VARBINARY to a bigger BINARY ---error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON -alter table t modify a varbinary(220), algorithm=instant; -alter table t modify a varbinary(220), algorithm=copy; -alter table t modify a binary(255), algorithm=instant; +--enable_info +alter table t modify a varbinary(220); +alter table t modify a binary(255); +--disable_info select count(a) from t where a = @bigval; select a, length(a) from t where a = 'z'; @@ -110,25 +119,33 @@ call check_table('t'); --echo # Integer conversions create or replace table t (x tinyint); insert into t values (127); -alter table t modify x smallint, algorithm=instant; +--enable_info +alter table t modify x smallint; +--disable_info select * from t; check table t extended; call check_table('t'); update t set x= 32767; -alter table t modify x mediumint, algorithm=instant; +--enable_info +alter table t modify x mediumint; +--disable_info select * from t; check table t extended; call check_table('t'); update t set x= 8388607; -alter table t modify x int, algorithm=instant; +--enable_info +alter table t modify x int; +--disable_info select * from t; check table t extended; call check_table('t'); update t set x= 2147483647; -alter table t modify x bigint, algorithm=instant; +--enable_info +alter table t modify x bigint; +--disable_info select * from t; check table t extended; call check_table('t'); @@ -163,13 +180,19 @@ call check_table('t2'); create or replace table t1 (x mediumint); insert into t1 values (1); insert into t1 values (1); -alter table t1 add column y int first, modify x int, algorithm instant; +--enable_info +alter table t1 add column y int first, modify x int; --error ER_DUP_ENTRY alter table t1 add column z int first, add primary key (x); +--disable_info --echo # Check assertion in wrong instant operation create or replace table t1 (a varchar(26) not null) default character set utf8mb4; -alter table t1 modify a varchar(25) not null; +insert into t1 values ('abcdef'), (repeat('x',26)); +--enable_info +alter ignore table t1 modify a varchar(25) not null; +--disable_info +select * from t1; --echo # Check row_mysql_store_col_in_innobase_format() create or replace table t1(x int primary key, a varchar(20)); @@ -181,30 +204,46 @@ update t1 set a= 'foo' where x = 2; --echo # create or replace table t1 (x int, y int); insert into t1 (x, y) values (11, 22); -alter table t1 modify x bigint, algorithm instant; -alter table t1 add primary key (x), algorithm inplace; +--enable_info +alter table t1 modify x bigint; +alter table t1 add primary key (x); +--disable_info +select * from t1; check table t1; create or replace table t1 (a varchar(10), y int); insert into t1 (a, y) values ("0123456789", 33); -alter table t1 modify a char(15), algorithm instant; -alter table t1 add primary key (a), algorithm inplace; +--enable_info +alter table t1 modify a char(15); +alter table t1 add primary key (a); +--disable_info +select * from t1; check table t1; create or replace table t1 (x int primary key, y int); insert into t1 (x, y) values (44, 55); -alter table t1 modify x bigint, algorithm inplace; +--enable_info +alter table t1 modify x bigint; +--disable_info +select * from t1; check table t1; create or replace table t1 (x int primary key, y int); insert into t1 values (66, 77); -alter table t1 add column z int, algorithm instant; -alter table t1 drop column y, algorithm instant; +--enable_info +alter table t1 add column z int; +alter table t1 drop column y; +--disable_info +select * from t1; +check table t1; create or replace table t1 (x integer, a varchar(20)); -alter table t1 add index idx3 (a); +--enable_info insert into t1 (x, a) values (73, 'a'); +alter table t1 add index idx3 (a); alter table t1 modify a char(20); +--disable_info +select * from t1; +check table t1; create or replace database test charset latin1; -SET GLOBAL innodb_default_row_format=@save_format; diff --git a/sql/field.cc b/sql/field.cc index 6cef622bf1e..bb4a0f06fc4 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -7084,9 +7084,6 @@ uint Field_str::is_equal(Create_field *new_field) return new_field->charset == field_charset ? IS_EQUAL_YES : IS_EQUAL_PACK_LENGTH; - if (table->file->ha_table_flags() & HA_EXTENDED_TYPES_CONVERSION) - return IS_EQUAL_PACK_LENGTH_EXT; - return IS_EQUAL_NO; } @@ -7947,11 +7944,6 @@ uint Field_varstring::is_equal(Create_field *new_field) (table->file->ha_table_flags() & HA_EXTENDED_TYPES_CONVERSION)) return IS_EQUAL_PACK_LENGTH; // VARCHAR, longer length } - else if (new_type_handler == &type_handler_string) // converting to CHAR - { - if (table->file->ha_table_flags() & HA_EXTENDED_TYPES_CONVERSION) - return IS_EQUAL_PACK_LENGTH_EXT; - } return IS_EQUAL_NO; } @@ -9568,22 +9560,6 @@ uint Field_num::is_equal(Create_field *new_field) format for integers, we can only return IS_EQUAL_YES for the TINYINT conversion. */ - if (table->file->ha_table_flags() & HA_EXTENDED_TYPES_CONVERSION) - { - /* For now, prohibit instant conversion between BIT and integers. - Note: pack_length(), which is compared below, is measured in - bytes, and for BIT the last byte may be partially occupied. We - must not allow instant conversion to BIT such that the last byte - is partially occupied. - We could allow converting TINYINT UNSIGNED to BIT(8) or wider. */ - if (th != new_th && - (th == &type_handler_bit || new_th == &type_handler_bit)) - return IS_EQUAL_NO; - if (th->result_type() == new_th->result_type() && - new_field->pack_length >= pack_length()) - return IS_EQUAL_PACK_LENGTH_EXT; - } - return IS_EQUAL_NO; } diff --git a/sql/handler.h b/sql/handler.h index afe45f2b8d6..09c9c9a6849 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -751,14 +751,6 @@ typedef ulonglong alter_table_operations; */ #define ALTER_COLUMN_INDEX_LENGTH (1ULL << 60) -/** - Change the column length or type such that no rebuild is needed. - Only set if ALTER_COLUMN_EQUAL_PACK_LENGTH does not apply, and - if HA_EXTENDED_TYPES_CONVERSION holds. - @see IS_EQUAL_PACK_LENGTH_EXT -*/ -#define ALTER_COLUMN_EQUAL_PACK_LENGTH_EXT (1ULL << 61) - /* Flags set in partition_flags when altering partitions */ diff --git a/sql/sql_priv.h b/sql/sql_priv.h index 00d1616df1e..dab7a3161be 100644 --- a/sql/sql_priv.h +++ b/sql/sql_priv.h @@ -358,11 +358,6 @@ data dictionary without changing table rows */ #define IS_EQUAL_PACK_LENGTH 2 -/** - new_field has a representation that is compatible with the old type - when the storage engine advertises HA_EXTENDED_TYPES_CONVERSION -*/ -#define IS_EQUAL_PACK_LENGTH_EXT 3 enum enum_parsing_place { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index a40febf58f4..4dd9d43a7b9 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -6605,9 +6605,6 @@ static bool fill_alter_inplace_info(THD *thd, */ ha_alter_info->handler_flags|= ALTER_COLUMN_EQUAL_PACK_LENGTH; break; - case IS_EQUAL_PACK_LENGTH_EXT: - ha_alter_info->handler_flags|= ALTER_COLUMN_EQUAL_PACK_LENGTH_EXT; - break; default: DBUG_ASSERT(0); /* Safety. */ diff --git a/storage/innobase/btr/btr0btr.cc b/storage/innobase/btr/btr0btr.cc index 2db08b1a537..29696f96aa0 100644 --- a/storage/innobase/btr/btr0btr.cc +++ b/storage/innobase/btr/btr0btr.cc @@ -4839,9 +4839,7 @@ n_field_mismatch: if (len_is_stored(len) && (field->prefix_len ? len > field->prefix_len - : (fixed_size && (page_is_comp(page) - ? len != fixed_size - : len > fixed_size)))) { + : (fixed_size && len != fixed_size))) { len_mismatch: btr_index_rec_validate_report(page, rec, index); ib::error error; diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index ed9fd219d91..59704201c4e 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -486,14 +486,8 @@ incompatible: For the metadata record, variable-length columns are always written with zero length. The DB_TRX_ID will start right after any fixed-length columns. */ - if (index->table->not_redundant()) { - for (uint i = index->n_uniq; i--; ) { - trx_id_offset += index->fields[i] - .fixed_len; - } - } else { - trx_id_offset = rec_get_field_start_offs( - rec, index->n_uniq); + for (uint i = index->n_uniq; i--; ) { + trx_id_offset += index->fields[i].fixed_len; } } diff --git a/storage/innobase/data/data0type.cc b/storage/innobase/data/data0type.cc index 53d019a4664..a154dc6b490 100644 --- a/storage/innobase/data/data0type.cc +++ b/storage/innobase/data/data0type.cc @@ -100,22 +100,6 @@ dtype_validate( return(TRUE); } -bool dict_col_t::same_charset(const dict_col_t& other) const -{ - if (dtype_is_non_binary_string_type(mtype, prtype) - && dtype_is_non_binary_string_type(other.mtype, other.prtype)) { - uint csn1 = (uint) dtype_get_charset_coll(prtype); - uint csn2 = (uint) dtype_get_charset_coll(other.prtype); - CHARSET_INFO* cs1 = get_charset(csn1, MYF(MY_WME)); - CHARSET_INFO* cs2 = get_charset(csn2, MYF(MY_WME)); - if (!my_charset_same(cs1, cs2)) { - return false; - } - } - - return true; -} - #ifdef UNIV_DEBUG /** Print a data type structure. @param[in] type data type */ diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 232a21b99d2..7664bc2064d 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -2203,14 +2203,6 @@ dict_index_too_big_for_tree( } field_max_size = dict_col_get_max_size(col); - if (!comp && (col->mtype == DATA_INT - || col->mtype == DATA_CHAR - || col->mtype == DATA_FIXBINARY)) { - /* DATA_INT, DATA_FIXBINARY and DATA_CHAR are variable- - length (enlarged instantly), but are stored locally. */ - field_ext_max_size = 0; - goto add_field_size; - } field_ext_max_size = field_max_size < 256 ? 1 : 2; if (field->prefix_len) { diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 3eee1730972..b0e58872ad8 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -9977,7 +9977,7 @@ innobase_fts_create_doc_id_key( /* The unique Doc ID field should be an eight-bytes integer */ dict_field_t* field = dict_index_get_nth_field(index, 0); ut_a(field->col->mtype == DATA_INT); - ut_ad(sizeof(*doc_id) == field->col->len); + ut_ad(sizeof(*doc_id) == field->fixed_len); ut_ad(!strcmp(index->name, FTS_DOC_ID_INDEX_NAME)); #endif /* UNIV_DEBUG */ diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 8612aa9404b..3606088d037 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -135,7 +135,6 @@ static const alter_table_operations INNOBASE_ALTER_INSTANT | ALTER_ADD_VIRTUAL_COLUMN | INNOBASE_FOREIGN_OPERATIONS | ALTER_COLUMN_EQUAL_PACK_LENGTH - | ALTER_COLUMN_EQUAL_PACK_LENGTH_EXT | ALTER_COLUMN_UNVERSIONED | ALTER_DROP_VIRTUAL_COLUMN; @@ -270,7 +269,7 @@ inline void dict_table_t::prepare_instant(const dict_table_t& old, ut_ad(!not_redundant()); for (unsigned i = index.n_fields; i--; ) { ut_ad(index.fields[i].col->same_format( - *oindex.fields[i].col, true)); + *oindex.fields[i].col)); } } #endif @@ -458,13 +457,9 @@ inline void dict_index_t::instant_add_field(const dict_index_t& instant) as this index. Fields for any added columns are appended at the end. */ #ifndef DBUG_OFF for (unsigned i = 0; i < n_fields; i++) { - DBUG_ASSERT(fields[i].prefix_len - == instant.fields[i].prefix_len); - DBUG_ASSERT(fields[i].fixed_len - == instant.fields[i].fixed_len - || !table->not_redundant()); - DBUG_ASSERT(instant.fields[i].col->same_format( - *fields[i].col, !table->not_redundant())); + DBUG_ASSERT(fields[i].same(instant.fields[i])); + DBUG_ASSERT(instant.fields[i].col->same_format(*fields[i] + .col)); /* Instant conversion from NULL to NOT NULL is not allowed. */ DBUG_ASSERT(!fields[i].col->is_nullable() || instant.fields[i].col->is_nullable()); @@ -540,7 +535,10 @@ inline bool dict_table_t::instant_column(const dict_table_t& table, if (const dict_col_t* o = find(old_cols, col_map, n_cols, i)) { c.def_val = o->def_val; - ut_ad(c.same_format(*o, !not_redundant())); + DBUG_ASSERT(!((c.prtype ^ o->prtype) + & ~(DATA_NOT_NULL | DATA_VERSIONED))); + DBUG_ASSERT(c.mtype == o->mtype); + DBUG_ASSERT(c.len >= o->len); if (o->vers_sys_start()) { ut_ad(o->ind == vers_start); @@ -1752,10 +1750,6 @@ ha_innobase::check_if_supported_inplace_alter( { DBUG_ENTER("check_if_supported_inplace_alter"); - DBUG_ASSERT(!(ALTER_COLUMN_EQUAL_PACK_LENGTH_EXT - & ha_alter_info->handler_flags) - || !m_prebuilt->table->not_redundant()); - if ((ha_alter_info->handler_flags & INNOBASE_ALTER_VERSIONED_REBUILD) && altered_table->versioned(VERS_TIMESTAMP)) { @@ -2951,7 +2945,7 @@ innobase_col_to_mysql( switch (col->mtype) { case DATA_INT: - ut_ad(len <= flen); + ut_ad(len == flen); /* Convert integer data from Innobase to little-endian format, sign bit restored to normal */ @@ -5592,8 +5586,7 @@ static bool innobase_instant_try( bool update = old && (!ctx->first_alter_pos || i < ctx->first_alter_pos - 1); - ut_ad(!old || col->same_format( - *old, !user_table->not_redundant())); + DBUG_ASSERT(!old || col->same_format(*old)); if (update && old->prtype == d->type.prtype) { /* The record is already present in SYS_COLUMNS. */ @@ -5682,8 +5675,6 @@ add_all_virtual: NULL, trx, ctx->heap, NULL); dberr_t err = DB_SUCCESS; - DBUG_EXECUTE_IF("ib_instant_error", - err = DB_OUT_OF_FILE_SPACE; goto func_exit;); if (rec_is_metadata(rec, *index)) { ut_ad(page_rec_is_user_rec(rec)); if (!page_has_next(block->frame) @@ -9061,7 +9052,7 @@ innobase_rename_or_enlarge_column_try( and ROW_FORMAT is not REDUNDANT and mbminlennot_redundant() || col->len == len); + ut_ad(col->len == len); break; case DATA_BINARY: case DATA_VARCHAR: @@ -9069,11 +9060,6 @@ innobase_rename_or_enlarge_column_try( case DATA_DECIMAL: case DATA_BLOB: break; - case DATA_INT: - if (!user_table->not_redundant()) { - break; - } - /* fall through */ default: ut_ad(col->prtype == prtype); ut_ad(col->mtype == mtype); @@ -9129,7 +9115,6 @@ innobase_rename_or_enlarge_columns_try( if (!(ha_alter_info->handler_flags & (ALTER_COLUMN_EQUAL_PACK_LENGTH - | ALTER_COLUMN_EQUAL_PACK_LENGTH_EXT | ALTER_COLUMN_NAME))) { DBUG_RETURN(false); } @@ -9178,7 +9163,6 @@ innobase_rename_or_enlarge_columns_cache( { if (!(ha_alter_info->handler_flags & (ALTER_COLUMN_EQUAL_PACK_LENGTH - | ALTER_COLUMN_EQUAL_PACK_LENGTH_EXT | ALTER_COLUMN_NAME))) { return; } diff --git a/storage/innobase/include/data0type.ic b/storage/innobase/include/data0type.ic index 39f00364ea2..9e88ee53559 100644 --- a/storage/innobase/include/data0type.ic +++ b/storage/innobase/include/data0type.ic @@ -472,18 +472,12 @@ dtype_get_fixed_size_low( } #endif /* UNIV_DEBUG */ /* fall through */ + case DATA_CHAR: + case DATA_FIXBINARY: + case DATA_INT: case DATA_FLOAT: case DATA_DOUBLE: return(len); - case DATA_FIXBINARY: - case DATA_CHAR: - case DATA_INT: - /* Treat these types as variable length for redundant - row format. We can't rely on fixed_len anymore because record - can have shorter length from before instant enlargement - [MDEV-15563]. Note, that importing such tablespace to - earlier MariaDB versions produces ER_TABLE_SCHEMA_MISMATCH. */ - return comp ? len : 0; case DATA_MYSQL: if (prtype & DATA_BINARY_TYPE) { return(len); @@ -631,14 +625,6 @@ dtype_get_sql_null_size( const dtype_t* type, /*!< in: type */ ulint comp) /*!< in: nonzero=ROW_FORMAT=COMPACT */ { - switch (type->mtype) { - case DATA_INT: - case DATA_CHAR: - case DATA_FIXBINARY: - return(type->len); - default: - break; - } return(dtype_get_fixed_size_low(type->mtype, type->prtype, type->len, type->mbminlen, type->mbmaxlen, comp)); } diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index e9ffa660354..11e150c4f78 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -682,52 +682,18 @@ public: def_val.data = NULL; } -private: - /** Determine if the columns have the same character set - @param[in] other column to compare to - @return whether the columns have the same character set */ - bool same_charset(const dict_col_t& other) const; -public: /** Determine if the columns have the same format except for is_nullable() and is_versioned(). @param[in] other column to compare to - @param[in] redundant table is redundant row format @return whether the columns have the same format */ - bool same_format(const dict_col_t& other, bool redundant = false) const + bool same_format(const dict_col_t& other) const { - if (len < other.len - || mbminlen != other.mbminlen - || mbmaxlen != other.mbmaxlen) { - return false; - } - - if (!((prtype ^ other.prtype) - & ~(DATA_NOT_NULL | DATA_VERSIONED))) { - return mtype == other.mtype; - } - - if (redundant) { - switch (other.mtype) { - case DATA_CHAR: - case DATA_MYSQL: - case DATA_VARCHAR: - case DATA_VARMYSQL: - return (mtype == DATA_CHAR - || mtype == DATA_MYSQL - || mtype == DATA_VARCHAR - || mtype == DATA_VARMYSQL) - && same_charset(other); - case DATA_FIXBINARY: - case DATA_BINARY: - return (mtype == DATA_FIXBINARY - || mtype == DATA_BINARY) - && same_charset(other); - case DATA_INT: - return mtype == DATA_INT; - } - } - - return false; + return mtype == other.mtype + && len >= other.len + && mbminlen == other.mbminlen + && mbmaxlen == other.mbmaxlen + && !((prtype ^ other.prtype) + & ~(DATA_NOT_NULL | DATA_VERSIONED)); } }; diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index 6de4dda93b1..0913f2d7574 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2005, 2017, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2014, 2018, MariaDB Corporation. +Copyright (c) 2014, 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 @@ -706,6 +706,11 @@ row_merge_buf_add( row_field, field, col->len, old_table->space->zip_size(), conv_heap); + } else { + /* Field length mismatch should not + happen when rebuilding redundant row + format table. */ + ut_ad(index->table->not_redundant()); } } } diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 1e82c6b6551..071ef9ffd92 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -887,15 +887,10 @@ row_create_prebuilt( == MAX_REF_PARTS);); uint temp_len = 0; for (uint i = 0; i < temp_index->n_uniq; i++) { - const dict_field_t& f = temp_index->fields[i]; - if (f.col->mtype == DATA_INT) { - ut_ad(f.col->len >= f.fixed_len); - /* dtype_get_fixed_size_low() returns 0 - for ROW_FORMAT=REDUNDANT */ - ut_ad(table->not_redundant() - ? f.col->len == f.fixed_len - : f.fixed_len == 0); - temp_len += f.col->len; + ulint type = temp_index->fields[i].col->mtype; + if (type == DATA_INT) { + temp_len += + temp_index->fields[i].fixed_len; } } srch_key_len = std::max(srch_key_len,temp_len); diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index e0b7cdb7145..73ed5f06825 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -2723,8 +2723,6 @@ row_sel_field_store_in_mysql_format_func( switch (templ->type) { const byte* field_end; - case DATA_CHAR: - case DATA_FIXBINARY: case DATA_VARCHAR: case DATA_VARMYSQL: case DATA_BINARY: @@ -2822,8 +2820,7 @@ row_sel_field_store_in_mysql_format_func( ut_ad(len * templ->mbmaxlen >= templ->mysql_col_len || (field_no == templ->icp_rec_field_no && field->prefix_len > 0) - || templ->rec_field_is_prefix - || !index->table->not_redundant()); + || templ->rec_field_is_prefix); ut_ad(templ->is_virtual || !(field->prefix_len % templ->mbmaxlen)); @@ -2845,6 +2842,8 @@ row_sel_field_store_in_mysql_format_func( ut_ad(0); /* fall through */ + case DATA_CHAR: + case DATA_FIXBINARY: case DATA_FLOAT: case DATA_DOUBLE: case DATA_DECIMAL: @@ -2859,18 +2858,13 @@ row_sel_field_store_in_mysql_format_func( case DATA_INT: /* Convert InnoDB big-endian integer to little-endian format, sign bit restored to 2's complement form */ - DBUG_ASSERT(templ->mysql_col_len >= len); + DBUG_ASSERT(templ->mysql_col_len == len); byte* ptr = pad; do *--ptr = *data++; while (ptr != dest); - byte b = templ->is_unsigned || !((pad[-1] ^= 0x80) & 0x80) - ? 0 : 0xff; - - if (ulint l = templ->mysql_col_len - len) { - DBUG_ASSERT(!index->table->not_redundant()); - memset(pad, b, l); + if (!templ->is_unsigned) { + pad[-1] ^= 0x80; } - break; } } From 75c6fce5a35a6ce38882e8228dd1a2b6020831b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 18 Feb 2019 18:49:34 +0200 Subject: [PATCH 17/19] MDEV-18627: Tighten an assertion added in MDEV-18596 innobase_instant_try(): Assert that the column length of fixed-length columns is not changing. --- storage/innobase/handler/handler0alter.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 3606088d037..c4bb4936e3a 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -5578,8 +5578,7 @@ static bool innobase_instant_try( mem_heap_alloc(ctx->heap, len)) : NULL, true, (*af)->ptr, len, dict_table_is_comp(user_table)); - ut_ad(new_field->field->pack_length() == len - || !user_table->not_redundant()); + ut_ad(new_field->field->pack_length() == len); } } From 4baab8697ac398e461d2a07988d9ad1739ce9019 Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Fri, 15 Feb 2019 14:51:39 +0200 Subject: [PATCH 18/19] MDEV-18587 Don't reject DDLs if streaming replication is on The check for streaming replication logging format in THD::decide_logging_format() did the check also for DDLs running in TOI mode. This caused DROP DATABASE to fail if streaming replication was enabled. Added check for THD wsrep execution mode and perform the check only if the THD is in local processing mode (i.e. not TOI). Added galera_sr_create_drop test to verify that CREATE/DROP statements pass even if streaming replication is on. --- .../galera_sr/r/galera_sr_create_drop.result | 28 ++++++++++++++++ .../galera_sr/t/galera_sr_create_drop.test | 33 +++++++++++++++++++ sql/sql_class.cc | 3 +- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/galera_sr/r/galera_sr_create_drop.result create mode 100644 mysql-test/suite/galera_sr/t/galera_sr_create_drop.test diff --git a/mysql-test/suite/galera_sr/r/galera_sr_create_drop.result b/mysql-test/suite/galera_sr/r/galera_sr_create_drop.result new file mode 100644 index 00000000000..c8658f09ff0 --- /dev/null +++ b/mysql-test/suite/galera_sr/r/galera_sr_create_drop.result @@ -0,0 +1,28 @@ +connection node_2; +connection node_1; +SET SESSION wsrep_trx_fragment_size=1; +CREATE TABLE t1 (f1 INT PRIMARY KEY) ENGINE=InnoDB; +connection node_2; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f1` int(11) NOT NULL, + PRIMARY KEY (`f1`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +connection node_1; +DROP TABLE t1; +connection node_2; +SHOW CREATE TABLE t1; +ERROR 42S02: Table 'test.t1' doesn't exist +CREATE DATABASE mdev_18587; +connection node_2; +SHOW DATABASES LIKE 'mdev_18587'; +Database (mdev_18587) +mdev_18587 +connection node_1; +DROP DATABASE mdev_18587; +connection node_2; +SHOW DATABASES LIKE 'mdev_18587'; +Database (mdev_18587) +connection node_1; +SET SESSION wsrep_trx_fragment_size=DEFAULT; diff --git a/mysql-test/suite/galera_sr/t/galera_sr_create_drop.test b/mysql-test/suite/galera_sr/t/galera_sr_create_drop.test new file mode 100644 index 00000000000..b7987d26191 --- /dev/null +++ b/mysql-test/suite/galera_sr/t/galera_sr_create_drop.test @@ -0,0 +1,33 @@ +# +# Verify that CREATE/DROP DDLs work when streaming replication is on. +# + +--source include/galera_cluster.inc + +SET SESSION wsrep_trx_fragment_size=1; + +# +# CREATE/DROP TABLE succeeds and the change is propagated to node_2. +# +CREATE TABLE t1 (f1 INT PRIMARY KEY) ENGINE=InnoDB; +--connection node_2 +SHOW CREATE TABLE t1; +--connection node_1 +DROP TABLE t1; +--connection node_2 +--error ER_NO_SUCH_TABLE +SHOW CREATE TABLE t1; + +# +# CREATE/DROP DATABASE succeeds and the change is propagated to node_2. +# +CREATE DATABASE mdev_18587; +--connection node_2 +SHOW DATABASES LIKE 'mdev_18587'; +--connection node_1 +DROP DATABASE mdev_18587; +--connection node_2 +SHOW DATABASES LIKE 'mdev_18587'; +--connection node_1 + +SET SESSION wsrep_trx_fragment_size=DEFAULT; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index bb0227df212..029da77761e 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -5987,7 +5987,8 @@ int THD::decide_logging_format(TABLE_LIST *tables) binlog by filtering rules. */ #ifdef WITH_WSREP - if (WSREP_CLIENT_NNULL(this) && variables.wsrep_trx_fragment_size > 0) + if (WSREP_CLIENT_NNULL(this) && wsrep_thd_is_local(this) && + variables.wsrep_trx_fragment_size > 0) { if (!is_current_stmt_binlog_format_row()) { From f2f0c2004408a38a428d6c6346a8f2d2d69cd599 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 18 Feb 2019 11:13:19 +0100 Subject: [PATCH 19/19] MDEV-18439 Windows builds should have core_file=1 by default --- sql/sys_vars.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 3375017ce10..a14bfefa752 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -474,7 +474,7 @@ bool check_has_super(sys_var *self, THD *thd, set_var *var) static Sys_var_bit Sys_core_file("core_file", "write a core-file on crashes", READ_ONLY GLOBAL_VAR(test_flags), NO_CMD_LINE, - TEST_CORE_ON_SIGNAL, DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, + TEST_CORE_ON_SIGNAL, DEFAULT(IF_WIN(TRUE,FALSE)), NO_MUTEX_GUARD, NOT_IN_BINLOG, 0,0,0); static bool binlog_format_check(sys_var *self, THD *thd, set_var *var)