From 1f1ee085fb65ed98c7adecd61f4e7bd9abb6ae26 Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Fri, 29 Oct 2021 01:32:21 +0300 Subject: MDEV-23766: Fix fix_semijoin_strategies_for_picked_join_order by assert --- sql/opt_subselect.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 7bd778e339f..cef6cd9c160 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -3819,9 +3819,9 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join) Json_writer_array semijoin_plan(thd, "join_order"); for (i= first + sjm->tables; i <= tablenr; i++) { + Json_writer_object trace_one_table(thd); 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, @@ -3858,9 +3858,9 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join) Json_writer_array semijoin_plan(thd, "join_order"); for (idx= first; idx <= tablenr; idx++) { + Json_writer_object trace_one_table(thd); 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) @@ -3897,9 +3897,9 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join) Json_writer_array semijoin_plan(thd, "join_order"); for (idx= first; idx <= tablenr; idx++) { + Json_writer_object trace_one_table(thd); 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)) -- cgit v1.2.1 From cf047efd42ab64d730e2b84c7482e56b695678ef Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Tue, 2 Nov 2021 14:01:54 +0200 Subject: MDEV-23766: Fix get_best_disjunct_quick by assert: in test main.range_vs_index_merge one path requires named JSON object: assert.c:0(.annobin_assert.c_end)[0x7fe9d2270a76] sql/my_json_writer.cc:43(Json_writer::on_start_object())[0x555e284f048a] sql/my_json_writer.cc:59(Json_writer::start_object())[0x555e284ee6e8] sql/my_json_writer.h:377(Json_writer_object::Json_writer_object(THD*))[0x555e281dce11] sql/opt_range.cc:5137(get_best_disjunct_quick(PARAM*, SEL_IMERGE*, double))[0x555e287c576b] sql/opt_range.cc:5492(merge_same_index_scans(PARAM*, SEL_IMERGE*, TRP_INDEX_MERGE*, double))[0x555e287c6cf6] sql/opt_range.cc:5287(get_best_disjunct_quick(PARAM*, SEL_IMERGE*, double))[0x555e287c607a] sql/opt_range.cc:3000(SQL_SELECT::test_quick_select another one requires unnamed JSON: mariadbd: /home/name/server/sql/my_json_writer.cc:379: bool Single_line_formatting_helper::on_add_member(const char*, size_t): Assertion `state== INACTIVE || state == assert.c:0(.annobin_assert.c_end)[0x7f33d8df8a76] sql/my_json_writer.cc:380(Single_line_formatting_helper::on_add_member(char const*, unsigned long))[0x558362f6a717] sql/my_json_writer.cc:150(Json_writer::add_member(char const*, unsigned long))[0x558362f69a91] sql/my_json_writer.cc:146(Json_writer::add_member(char const*))[0x558362f69a5f] sql/my_json_writer.h:383(Json_writer_object::Json_writer_object(THD*, char const*))[0x558362ceccaa] sql/opt_range.cc:5139(get_best_disjunct_quick(PARAM*, SEL_IMERGE*, double))[0x5583632407d0] sql/opt_range.cc:3000(SQL_SELECT::test_quick_select --- sql/opt_range.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index d47aa1ee41e..122b00f4d57 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -371,7 +371,7 @@ TRP_ROR_INTERSECT *get_best_covering_ror_intersect(PARAM *param, double read_time); static TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge, - double read_time); + double read_time, bool named_trace= false); static TABLE_READ_PLAN *merge_same_index_scans(PARAM *param, SEL_IMERGE *imerge, TRP_INDEX_MERGE *imerge_trp, @@ -5052,7 +5052,7 @@ double get_sweep_read_cost(const PARAM *param, ha_rows records) static TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge, - double read_time) + double read_time, bool named_trace) { SEL_TREE **ptree; TRP_INDEX_MERGE *imerge_trp= NULL; @@ -5101,7 +5101,9 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge, n_child_scans))) DBUG_RETURN(NULL); - Json_writer_object trace_best_disjunct(thd); + Json_writer_object trace_best_disjunct = named_trace + ? Json_writer_object(thd, "best_disjunct_quick") + : Json_writer_object(thd); Json_writer_array to_merge(thd, "indexes_to_merge"); /* Collect best 'range' scan for each of disjuncts, and, while doing so, @@ -5459,7 +5461,7 @@ TABLE_READ_PLAN *merge_same_index_scans(PARAM *param, SEL_IMERGE *imerge, DBUG_ASSERT(imerge->trees_next>imerge->trees); if (imerge->trees_next-imerge->trees > 1) - trp= get_best_disjunct_quick(param, imerge, read_time); + trp= get_best_disjunct_quick(param, imerge, read_time, true); else { /* -- cgit v1.2.1 From b17576322b600f53c7a0b74cf14830ad5bbad98e Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Mon, 25 Oct 2021 00:19:37 +0300 Subject: MDEV-23766: add Json_writer consistency asserts to check array/object sequence --- sql/my_json_writer.cc | 138 +++++++++++++++++++++++++++++++++++--------------- sql/my_json_writer.h | 20 ++++++++ 2 files changed, 116 insertions(+), 42 deletions(-) diff --git a/sql/my_json_writer.cc b/sql/my_json_writer.cc index f4cf8204d61..ea20854eb1e 100644 --- a/sql/my_json_writer.cc +++ b/sql/my_json_writer.cc @@ -18,6 +18,14 @@ #include "sql_string.h" #include "my_json_writer.h" +#ifndef NDEBUG +bool Json_writer::named_item_expected() const +{ + return named_items_expectation.size() + && named_items_expectation.back(); +} +#endif + void Json_writer::append_indent() { if (!document_start) @@ -26,9 +34,27 @@ void Json_writer::append_indent() output.append(' '); } -void Json_writer::start_object() +inline void Json_writer::on_start_object() { +#ifndef NDEBUG + if(!is_on_fmt_helper_call) + { + DBUG_ASSERT(got_name == named_item_expected()); + named_items_expectation.push_back(true); + } + + bool was_on_fmt_helper_call= is_on_fmt_helper_call; + is_on_fmt_helper_call= true; +#endif fmt_helper.on_start_object(); +#ifndef NDEBUG + is_on_fmt_helper_call= was_on_fmt_helper_call; +#endif +} + +void Json_writer::start_object() +{ + on_start_object(); if (!element_started) start_element(); @@ -38,11 +64,36 @@ void Json_writer::start_object() first_child=true; element_started= false; document_start= false; +#ifndef NDEBUG + got_name= false; +#endif +} + +bool Json_writer::on_start_array() +{ +#ifndef NDEBUG + bool was_on_fmt_helper_call= is_on_fmt_helper_call; + is_on_fmt_helper_call= true; +#endif + bool helped= fmt_helper.on_start_array(); +#ifndef NDEBUG + is_on_fmt_helper_call= was_on_fmt_helper_call; +#endif + return helped; } void Json_writer::start_array() { - if (fmt_helper.on_start_array()) +#ifndef NDEBUG + if(!is_on_fmt_helper_call) + { + DBUG_ASSERT(got_name == named_item_expected()); + named_items_expectation.push_back(false); + got_name= false; + } +#endif + + if (on_start_array()) return; if (!element_started) @@ -58,6 +109,11 @@ void Json_writer::start_array() void Json_writer::end_object() { +#ifndef NDEBUG + named_items_expectation.pop_back(); + DBUG_ASSERT(!got_name); + got_name= false; +#endif indent_level-=INDENT_SIZE; if (!first_child) append_indent(); @@ -68,6 +124,10 @@ void Json_writer::end_object() void Json_writer::end_array() { +#ifndef NDEBUG + named_items_expectation.pop_back(); + got_name= false; +#endif if (fmt_helper.on_end_array()) return; indent_level-=INDENT_SIZE; @@ -80,31 +140,25 @@ void Json_writer::end_array() Json_writer& Json_writer::add_member(const char *name) { size_t len= strlen(name); - if (fmt_helper.on_add_member(name, len)) - return *this; // handled - - // assert that we are in an object - DBUG_ASSERT(!element_started); - start_element(); - - output.append('"'); - output.append(name, len); - output.append("\": ", 3); - return *this; + return add_member(name, len); } Json_writer& Json_writer::add_member(const char *name, size_t len) { - if (fmt_helper.on_add_member(name, len)) - return *this; // handled - - // assert that we are in an object - DBUG_ASSERT(!element_started); - start_element(); + if (!fmt_helper.on_add_member(name, len)) + { + // assert that we are in an object + DBUG_ASSERT(!element_started); + start_element(); - output.append('"'); - output.append(name, len); - output.append("\": "); + output.append('"'); + output.append(name, len); + output.append("\": ", 3); + } +#ifndef NDEBUG + if (!is_on_fmt_helper_call) + got_name= true; +#endif return *this; } @@ -200,19 +254,13 @@ void Json_writer::add_null() void Json_writer::add_unquoted_str(const char* str) { size_t len= strlen(str); - if (fmt_helper.on_add_str(str, len)) - return; - - if (!element_started) - start_element(); - - output.append(str, len); - element_started= false; + add_unquoted_str(str, len); } void Json_writer::add_unquoted_str(const char* str, size_t len) { - if (fmt_helper.on_add_str(str, len)) + DBUG_ASSERT(is_on_fmt_helper_call || got_name == named_item_expected()); + if (on_add_str(str, len)) return; if (!element_started) @@ -222,19 +270,24 @@ void Json_writer::add_unquoted_str(const char* str, size_t len) element_started= false; } +inline bool Json_writer::on_add_str(const char *str, size_t num_bytes) +{ +#ifndef NDEBUG + got_name= false; + bool was_on_fmt_helper_call= is_on_fmt_helper_call; + is_on_fmt_helper_call= true; +#endif + bool helped= fmt_helper.on_add_str(str, num_bytes); +#ifndef NDEBUG + is_on_fmt_helper_call= was_on_fmt_helper_call; +#endif + return helped; +} + void Json_writer::add_str(const char *str) { size_t len= strlen(str); - if (fmt_helper.on_add_str(str, len)) - return; - - if (!element_started) - start_element(); - - output.append('"'); - output.append(str, len); - output.append('"'); - element_started= false; + add_str(str, len); } /* @@ -243,7 +296,8 @@ void Json_writer::add_str(const char *str) void Json_writer::add_str(const char* str, size_t num_bytes) { - if (fmt_helper.on_add_str(str, num_bytes)) + DBUG_ASSERT(is_on_fmt_helper_call || got_name == named_item_expected()); + if (on_add_str(str, num_bytes)) return; if (!element_started) diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h index bc8002de529..94cd438bbb0 100644 --- a/sql/my_json_writer.h +++ b/sql/my_json_writer.h @@ -181,6 +181,17 @@ private: class Json_writer { +#ifndef NDEBUG + + std::vector named_items_expectation; + + bool named_item_expected() const; + + bool got_name; + bool is_on_fmt_helper_call; + +#endif + public: /* Add a member. We must be in an object. */ Json_writer& add_member(const char *name); @@ -204,6 +215,11 @@ public: private: void add_unquoted_str(const char* val); void add_unquoted_str(const char* val, size_t len); + + bool on_add_str(const char *str, size_t num_bytes); + bool on_start_array(); + void on_start_object(); + public: /* Start a child object */ void start_object(); @@ -221,6 +237,10 @@ public: size_t get_truncated_bytes() { return output.get_truncated_bytes(); } Json_writer() : +#ifndef NDEBUG + got_name(false), + is_on_fmt_helper_call(false), +#endif indent_level(0), document_start(true), element_started(false), first_child(true) { -- cgit v1.2.1 From 1a3570dec35733e725cc6000a06ec666facf4235 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Fri, 28 Jun 2019 13:21:39 +0200 Subject: improve build, allow sql library to be built in parallel with builtins --- extra/mariabackup/CMakeLists.txt | 6 ++++-- sql/CMakeLists.txt | 17 ++++++++++++++--- unittest/sql/CMakeLists.txt | 8 +++++--- unittest/sql/dummy_builtins.cc | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 unittest/sql/dummy_builtins.cc diff --git a/extra/mariabackup/CMakeLists.txt b/extra/mariabackup/CMakeLists.txt index 75c942c8a7b..3179e1550c9 100644 --- a/extra/mariabackup/CMakeLists.txt +++ b/extra/mariabackup/CMakeLists.txt @@ -75,6 +75,7 @@ MYSQL_ADD_EXECUTABLE(mariabackup backup_mysql.cc backup_copy.cc encryption_plugin.cc + ${PROJECT_BINARY_DIR}/sql/sql_builtin.cc ${PROJECT_SOURCE_DIR}/sql/net_serv.cc ${NT_SERVICE_SOURCE} ${PROJECT_SOURCE_DIR}/libmysqld/libmysql.c @@ -82,13 +83,14 @@ MYSQL_ADD_EXECUTABLE(mariabackup ) + + # Export all symbols on Unix, for better crash callstacks SET_TARGET_PROPERTIES(mariabackup PROPERTIES ENABLE_EXPORTS TRUE) ADD_SUBDIRECTORY(crc) -TARGET_LINK_LIBRARIES(mariabackup sql crc) - +TARGET_LINK_LIBRARIES(mariabackup sql sql_builtins crc) IF(NOT HAVE_SYSTEM_REGEX) TARGET_LINK_LIBRARIES(mariabackup pcreposix) ENDIF() diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 7154e3dbe44..4dd34e80f2d 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -145,11 +145,11 @@ SET (SQL_SOURCE ${WSREP_SOURCES} table_cache.cc encryption.cc temporary_tables.cc proxy_protocol.cc backup.cc xa.cc - ${CMAKE_CURRENT_BINARY_DIR}/sql_builtin.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.cc ${CMAKE_CURRENT_BINARY_DIR}/lex_hash.h ${CMAKE_CURRENT_BINARY_DIR}/lex_token.h + ${GEN_SOURCES} ${MYSYS_LIBWRAP_SOURCE} ) @@ -177,13 +177,20 @@ RECOMPILE_FOR_EMBEDDED) ADD_LIBRARY(sql STATIC ${SQL_SOURCE}) DTRACE_INSTRUMENT(sql) -TARGET_LINK_LIBRARIES(sql ${MYSQLD_STATIC_PLUGIN_LIBS} +TARGET_LINK_LIBRARIES(sql mysys mysys_ssl dbug strings vio pcre ${LIBWRAP} ${LIBCRYPT} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${WSREP_LIB} ${SSL_LIBRARIES} ${LIBSYSTEMD}) +FOREACH(se aria partition perfschema sql_sequence) + # These engines are used directly in sql sources. + IF(TARGET ${se}) + TARGET_LINK_LIBRARIES(sql ${se}) + ENDIF() +ENDFOREACH() + IF(WIN32) SET(MYSQLD_SOURCE main.cc nt_servc.cc message.rc) TARGET_LINK_LIBRARIES(sql psapi) @@ -267,6 +274,9 @@ IF(MSVC AND NOT WITHOUT_DYNAMIC_PLUGINS) SET_TARGET_PROPERTIES(mysqld_import_lib PROPERTIES IMPORTED_LOCATION ${MYSQLD_LIB}) ENDIF() +ADD_LIBRARY( sql_builtins ${CMAKE_CURRENT_BINARY_DIR}/sql_builtin.cc) +TARGET_LINK_LIBRARIES(sql_builtins ${MYSQLD_STATIC_PLUGIN_LIBS}) + MYSQL_ADD_EXECUTABLE(mysqld ${MYSQLD_SOURCE} DESTINATION ${INSTALL_SBINDIR} COMPONENT Server) IF(APPLE) @@ -294,7 +304,8 @@ IF(NOT WITHOUT_DYNAMIC_PLUGINS) ENDIF() ENDIF(NOT WITHOUT_DYNAMIC_PLUGINS) -TARGET_LINK_LIBRARIES(mysqld LINK_PRIVATE sql) +TARGET_LINK_LIBRARIES(mysqld LINK_PRIVATE sql sql_builtins) + # Provide plugins with minimal set of libraries SET(INTERFACE_LIBS ${LIBRT}) diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index a4ba1019e49..987e78433a4 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -21,10 +21,12 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql ${CMAKE_SOURCE_DIR}/extra/yassl/include) IF(WIN32) - ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc - ../../sql/nt_servc.cc) + ADD_EXECUTABLE(explain_filename-t + explain_filename-t.cc + dummy_builtins.cc + ../../sql/nt_servc.cc) ELSE() - ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc) + ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc dummy_builtins.cc) ENDIF() TARGET_LINK_LIBRARIES(explain_filename-t sql mytap) diff --git a/unittest/sql/dummy_builtins.cc b/unittest/sql/dummy_builtins.cc new file mode 100644 index 00000000000..31d043d19ec --- /dev/null +++ b/unittest/sql/dummy_builtins.cc @@ -0,0 +1,26 @@ +/* 2018 MariaDB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ + +#include +#include +struct st_maria_plugin *mysql_optional_plugins[]= +{ + 0 +}; + +struct st_maria_plugin *mysql_mandatory_plugins[]= +{ + 0 +}; -- cgit v1.2.1 From e45f7f485a4c8133962a4082636412745ed07093 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sat, 29 Jun 2019 15:28:20 +0300 Subject: =?UTF-8?q?In=20case=20WITH=5FWSREP=20is=20enabled,=20build=20wsre?= =?UTF-8?q?p=20as=20plugin=20If=20it=20is=20not=20enabled,=20build=20wsrep?= =?UTF-8?q?=20as=20static=20"stub"=20library=20from=20wsrep=5Fdummy.cc=20?= =?UTF-8?q?=C2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow static plugins to export symbols (on Unix) wsrep_info relies on wsrep defined symbols (e.g LOCK_wsrep_config_state) exported from mysqld --- cmake/plugin.cmake | 6 ++++-- sql/CMakeLists.txt | 9 ++++----- sql/sql_builtin.cc.in | 6 ------ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/cmake/plugin.cmake b/cmake/plugin.cmake index e7e9d2a3642..5d94e2607f8 100644 --- a/cmake/plugin.cmake +++ b/cmake/plugin.cmake @@ -30,7 +30,7 @@ INCLUDE(CMakeParseArguments) MACRO(MYSQL_ADD_PLUGIN) CMAKE_PARSE_ARGUMENTS(ARG - "STORAGE_ENGINE;STATIC_ONLY;MODULE_ONLY;MANDATORY;DEFAULT;DISABLED;RECOMPILE_FOR_EMBEDDED;CLIENT" + "STORAGE_ENGINE;STATIC_ONLY;MODULE_ONLY;MANDATORY;DEFAULT;DISABLED;RECOMPILE_FOR_EMBEDDED;CLIENT;EXPORT_SYMBOLS" "MODULE_OUTPUT_NAME;STATIC_OUTPUT_NAME;COMPONENT;CONFIG" "LINK_LIBRARIES;DEPENDS" ${ARGN} @@ -139,7 +139,9 @@ MACRO(MYSQL_ADD_PLUGIN) ADD_LIBRARY(${target} STATIC ${SOURCES}) DTRACE_INSTRUMENT(${target}) ADD_DEPENDENCIES(${target} GenError ${ARG_DEPENDS}) - RESTRICT_SYMBOL_EXPORTS(${target}) + IF(NOT ARG_EXPORT_SYMBOLS) + RESTRICT_SYMBOL_EXPORTS(${target}) + ENDIF() IF(WITH_EMBEDDED_SERVER) # Embedded library should contain PIC code and be linkable # to shared libraries (on systems that need PIC) diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 4dd34e80f2d..ec3b0c528bb 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -36,9 +36,10 @@ IF(WITH_WSREP AND NOT EMBEDDED_LIBRARY) wsrep_plugin.cc service_wsrep.cc ) - SET(WSREP_LIB wsrep-lib wsrep_api_v26) + MYSQL_ADD_PLUGIN(wsrep ${WSREP_SOURCES} MANDATORY EXPORT_SYMBOLS LINK_LIBRARIES wsrep-lib wsrep_api_v26) ELSE() - SET(WSREP_SOURCES wsrep_dummy.cc) + ADD_LIBRARY(wsrep STATIC wsrep_dummy.cc) + ADD_DEPENDENCIES(wsrep GenError) ENDIF() INCLUDE_DIRECTORIES( @@ -142,7 +143,6 @@ SET (SQL_SOURCE opt_split.cc rowid_filter.cc rowid_filter.h opt_trace.cc - ${WSREP_SOURCES} table_cache.cc encryption.cc temporary_tables.cc proxy_protocol.cc backup.cc xa.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc @@ -180,11 +180,10 @@ DTRACE_INSTRUMENT(sql) TARGET_LINK_LIBRARIES(sql mysys mysys_ssl dbug strings vio pcre ${LIBWRAP} ${LIBCRYPT} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} - ${WSREP_LIB} ${SSL_LIBRARIES} ${LIBSYSTEMD}) -FOREACH(se aria partition perfschema sql_sequence) +FOREACH(se aria partition perfschema sql_sequence wsrep) # These engines are used directly in sql sources. IF(TARGET ${se}) TARGET_LINK_LIBRARIES(sql ${se}) diff --git a/sql/sql_builtin.cc.in b/sql/sql_builtin.cc.in index 5ac044afd5d..810f98a876c 100644 --- a/sql/sql_builtin.cc.in +++ b/sql/sql_builtin.cc.in @@ -32,9 +32,6 @@ extern builtin_maria_plugin @mysql_mandatory_plugins@ @mysql_optional_plugins@ builtin_maria_binlog_plugin, -#ifdef WITH_WSREP - builtin_maria_wsrep_plugin, -#endif /* WITH_WSREP */ builtin_maria_mysql_password_plugin; struct st_maria_plugin *mysql_optional_plugins[]= @@ -45,8 +42,5 @@ struct st_maria_plugin *mysql_optional_plugins[]= struct st_maria_plugin *mysql_mandatory_plugins[]= { builtin_maria_binlog_plugin, builtin_maria_mysql_password_plugin, -#ifdef WITH_WSREP - builtin_maria_wsrep_plugin, -#endif /* WITH_WSREP */ @mysql_mandatory_plugins@ 0 }; -- cgit v1.2.1 From c9b5b9321f383ff05536466e6aaad7cab7c7ccd0 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 5 Nov 2021 14:36:59 +0300 Subject: MDEV-23766: Make Json_writer assert when one tries to author invalid JSON Code cleanup: Remove Json_writer::is_on_fmt_helper_call. We already maintain this state in fmt_helper. --- sql/my_json_writer.cc | 30 +++++++----------------------- sql/my_json_writer.h | 14 ++++++++++---- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/sql/my_json_writer.cc b/sql/my_json_writer.cc index ea20854eb1e..1c02ca39e22 100644 --- a/sql/my_json_writer.cc +++ b/sql/my_json_writer.cc @@ -37,19 +37,13 @@ void Json_writer::append_indent() inline void Json_writer::on_start_object() { #ifndef NDEBUG - if(!is_on_fmt_helper_call) + if(!fmt_helper.is_making_writer_calls()) { DBUG_ASSERT(got_name == named_item_expected()); named_items_expectation.push_back(true); } - - bool was_on_fmt_helper_call= is_on_fmt_helper_call; - is_on_fmt_helper_call= true; #endif fmt_helper.on_start_object(); -#ifndef NDEBUG - is_on_fmt_helper_call= was_on_fmt_helper_call; -#endif } void Json_writer::start_object() @@ -71,21 +65,14 @@ void Json_writer::start_object() bool Json_writer::on_start_array() { -#ifndef NDEBUG - bool was_on_fmt_helper_call= is_on_fmt_helper_call; - is_on_fmt_helper_call= true; -#endif bool helped= fmt_helper.on_start_array(); -#ifndef NDEBUG - is_on_fmt_helper_call= was_on_fmt_helper_call; -#endif return helped; } void Json_writer::start_array() { #ifndef NDEBUG - if(!is_on_fmt_helper_call) + if(!fmt_helper.is_making_writer_calls()) { DBUG_ASSERT(got_name == named_item_expected()); named_items_expectation.push_back(false); @@ -156,7 +143,7 @@ Json_writer& Json_writer::add_member(const char *name, size_t len) output.append("\": ", 3); } #ifndef NDEBUG - if (!is_on_fmt_helper_call) + if (!fmt_helper.is_making_writer_calls()) got_name= true; #endif return *this; @@ -259,7 +246,8 @@ void Json_writer::add_unquoted_str(const char* str) void Json_writer::add_unquoted_str(const char* str, size_t len) { - DBUG_ASSERT(is_on_fmt_helper_call || got_name == named_item_expected()); + DBUG_ASSERT(fmt_helper.is_making_writer_calls() || + got_name == named_item_expected()); if (on_add_str(str, len)) return; @@ -274,13 +262,8 @@ inline bool Json_writer::on_add_str(const char *str, size_t num_bytes) { #ifndef NDEBUG got_name= false; - bool was_on_fmt_helper_call= is_on_fmt_helper_call; - is_on_fmt_helper_call= true; #endif bool helped= fmt_helper.on_add_str(str, num_bytes); -#ifndef NDEBUG - is_on_fmt_helper_call= was_on_fmt_helper_call; -#endif return helped; } @@ -296,7 +279,8 @@ void Json_writer::add_str(const char *str) void Json_writer::add_str(const char* str, size_t num_bytes) { - DBUG_ASSERT(is_on_fmt_helper_call || got_name == named_item_expected()); + DBUG_ASSERT(fmt_helper.is_making_writer_calls() || + got_name == named_item_expected()); if (on_add_str(str, num_bytes)) return; diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h index 94cd438bbb0..50b277a5052 100644 --- a/sql/my_json_writer.h +++ b/sql/my_json_writer.h @@ -92,9 +92,18 @@ public: bool on_end_array(); void on_start_object(); // on_end_object() is not needed. - + bool on_add_str(const char *str, size_t num_bytes); + /* + Returns true if the helper is flushing its buffer and is probably + making calls back to its Json_writer. (The Json_writer uses this + function to avoid re-doing the processing that it has already done + before making a call to fmt_helper) + */ + bool is_making_writer_calls() const { return state == DISABLED; } + +private: void flush_on_one_line(); void disable_and_flush(); }; @@ -188,8 +197,6 @@ class Json_writer bool named_item_expected() const; bool got_name; - bool is_on_fmt_helper_call; - #endif public: @@ -239,7 +246,6 @@ public: Json_writer() : #ifndef NDEBUG got_name(false), - is_on_fmt_helper_call(false), #endif indent_level(0), document_start(true), element_started(false), first_child(true) -- cgit v1.2.1 From 5e988ff80f51e80f4d74477c4a22a065472317d4 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 5 Nov 2021 20:01:43 +0300 Subject: MDEV-23766: Make Json_writer assert when one tries to author invalid JSON - Add unit test. --- sql/my_json_writer.cc | 14 ++--- sql/my_json_writer.h | 22 ++++++- unittest/sql/CMakeLists.txt | 5 ++ unittest/sql/my_json_writer-t.cc | 130 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+), 8 deletions(-) create mode 100644 unittest/sql/my_json_writer-t.cc diff --git a/sql/my_json_writer.cc b/sql/my_json_writer.cc index 1c02ca39e22..81f7593c23f 100644 --- a/sql/my_json_writer.cc +++ b/sql/my_json_writer.cc @@ -39,7 +39,7 @@ inline void Json_writer::on_start_object() #ifndef NDEBUG if(!fmt_helper.is_making_writer_calls()) { - DBUG_ASSERT(got_name == named_item_expected()); + VALIDITY_ASSERT(got_name == named_item_expected()); named_items_expectation.push_back(true); } #endif @@ -74,7 +74,7 @@ void Json_writer::start_array() #ifndef NDEBUG if(!fmt_helper.is_making_writer_calls()) { - DBUG_ASSERT(got_name == named_item_expected()); + VALIDITY_ASSERT(got_name == named_item_expected()); named_items_expectation.push_back(false); got_name= false; } @@ -98,7 +98,7 @@ void Json_writer::end_object() { #ifndef NDEBUG named_items_expectation.pop_back(); - DBUG_ASSERT(!got_name); + VALIDITY_ASSERT(!got_name); got_name= false; #endif indent_level-=INDENT_SIZE; @@ -246,8 +246,8 @@ void Json_writer::add_unquoted_str(const char* str) void Json_writer::add_unquoted_str(const char* str, size_t len) { - DBUG_ASSERT(fmt_helper.is_making_writer_calls() || - got_name == named_item_expected()); + VALIDITY_ASSERT(fmt_helper.is_making_writer_calls() || + got_name == named_item_expected()); if (on_add_str(str, len)) return; @@ -279,8 +279,8 @@ void Json_writer::add_str(const char *str) void Json_writer::add_str(const char* str, size_t num_bytes) { - DBUG_ASSERT(fmt_helper.is_making_writer_calls() || - got_name == named_item_expected()); + VALIDITY_ASSERT(fmt_helper.is_making_writer_calls() || + got_name == named_item_expected()); if (on_add_str(str, num_bytes)) return; diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h index 50b277a5052..6f9ae73c5ee 100644 --- a/sql/my_json_writer.h +++ b/sql/my_json_writer.h @@ -16,7 +16,17 @@ #ifndef JSON_WRITER_INCLUDED #define JSON_WRITER_INCLUDED #include "my_base.h" + +#ifdef JSON_WRITER_UNIT_TEST +#include "sql_string.h" +#include +// Also, mock objects are defined in my_json_writer-t.cc +#define VALIDITY_ASSERT(x) if ((!x)) this->invalid_json= true; +#else #include "sql_select.h" +#define VALIDITY_ASSERT(x) DBUG_ASSERT(x) +#endif + class Opt_trace_stmt; class Opt_trace_context; class Json_writer; @@ -191,12 +201,22 @@ private: class Json_writer { #ifndef NDEBUG - + /* + In debug mode, Json_writer will fail and assertion if one attempts to + produce an invalid JSON document (e.g. JSON array having named elements). + */ std::vector named_items_expectation; bool named_item_expected() const; bool got_name; + +#ifdef JSON_WRITER_UNIT_TEST +public: + // When compiled for unit test, creating invalid JSON will set this to true + // instead of an assertion. + bool invalid_json= false; +#endif #endif public: diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index 987e78433a4..ab174680fab 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -36,3 +36,8 @@ ADD_EXECUTABLE(mf_iocache-t mf_iocache-t.cc ../../sql/mf_iocache_encr.cc) TARGET_LINK_LIBRARIES(mf_iocache-t mysys mytap mysys_ssl) ADD_DEPENDENCIES(mf_iocache-t GenError) MY_ADD_TEST(mf_iocache) + +# Json writer needs String which needs sql library +ADD_EXECUTABLE(my_json_writer-t my_json_writer-t.cc dummy_builtins.cc) +TARGET_LINK_LIBRARIES(my_json_writer-t sql mytap) +MY_ADD_TEST(my_json_writer) diff --git a/unittest/sql/my_json_writer-t.cc b/unittest/sql/my_json_writer-t.cc new file mode 100644 index 00000000000..46c3f4dc967 --- /dev/null +++ b/unittest/sql/my_json_writer-t.cc @@ -0,0 +1,130 @@ +/* + Copyright (c) 2021, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#include +#include +#include +#include +#include + +/* + Unit tests for class Json_writer. At the moment there are only tests for the + "Fail an assertion if one attempts to produce invalid JSON" feature. +*/ + +struct TABLE; +struct JOIN_TAB; +class Json_writer; + + +/* Several fake objects */ +class Opt_trace +{ +public: + void enable_tracing_if_required() {} + void disable_tracing_if_required() {} + Json_writer *get_current_json() { return nullptr; } +}; + +class THD +{ +public: + Opt_trace opt_trace; +}; + +#define JSON_WRITER_UNIT_TEST +#include "../sql/my_json_writer.h" +#include "../sql/my_json_writer.cc" + +int main(int args, char **argv) +{ + plan(NO_PLAN); + diag("Testing Json_writer checks"); + + { + Json_writer w; + w.start_object(); + w.add_member("foo"); + w.end_object(); + ok(w.invalid_json, "Started a name but didn't add a value"); + } + + { + Json_writer w; + w.start_object(); + w.add_ull(123); + ok(w.invalid_json, "Unnamed value in an object"); + } + + { + Json_writer w; + w.start_array(); + w.add_member("bebebe").add_ull(345); + ok(w.invalid_json, "Named member in array"); + } + + { + Json_writer w; + w.start_object(); + w.start_array(); + ok(w.invalid_json, "Unnamed array in an object"); + } + + { + Json_writer w; + w.start_object(); + w.start_object(); + ok(w.invalid_json, "Unnamed object in an object"); + } + + { + Json_writer w; + w.start_array(); + w.add_member("zzz"); + w.start_object(); + ok(w.invalid_json, "Named object in an array"); + } + { + Json_writer w; + w.start_array(); + w.add_member("zzz"); + w.start_array(); + ok(w.invalid_json, "Named array in an array"); + } + + // BAD: + { + Json_writer w; + w.start_array(); + w.end_object(); + ok(!w.invalid_json, "BAD: not checked!"); + } + + // BAD: + { + Json_writer w; + w.start_object(); + w.end_array(); + ok(!w.invalid_json, "BAD: not checked!"); + } + + + + diag("Done"); + + return exit_status(); +} + -- cgit v1.2.1 From e9b76b896a5cec9804e653f7df117c49284cabba Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Mon, 8 Nov 2021 21:11:05 +0200 Subject: MDEV-23766: fix by my_json_writer test --- sql/my_json_writer.cc | 26 +++++++++++--------------- sql/my_json_writer.h | 10 ++++++---- unittest/sql/my_json_writer-t.cc | 4 ++-- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/sql/my_json_writer.cc b/sql/my_json_writer.cc index 81f7593c23f..8e35b25b822 100644 --- a/sql/my_json_writer.cc +++ b/sql/my_json_writer.cc @@ -18,7 +18,7 @@ #include "sql_string.h" #include "my_json_writer.h" -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) bool Json_writer::named_item_expected() const { return named_items_expectation.size() @@ -36,7 +36,7 @@ void Json_writer::append_indent() inline void Json_writer::on_start_object() { -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) if(!fmt_helper.is_making_writer_calls()) { VALIDITY_ASSERT(got_name == named_item_expected()); @@ -58,20 +58,14 @@ void Json_writer::start_object() first_child=true; element_started= false; document_start= false; -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) got_name= false; #endif } -bool Json_writer::on_start_array() -{ - bool helped= fmt_helper.on_start_array(); - return helped; -} - void Json_writer::start_array() { -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) if(!fmt_helper.is_making_writer_calls()) { VALIDITY_ASSERT(got_name == named_item_expected()); @@ -80,7 +74,7 @@ void Json_writer::start_array() } #endif - if (on_start_array()) + if (fmt_helper.on_start_array()) return; if (!element_started) @@ -96,7 +90,8 @@ void Json_writer::start_array() void Json_writer::end_object() { -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) + VALIDITY_ASSERT(named_item_expected()); named_items_expectation.pop_back(); VALIDITY_ASSERT(!got_name); got_name= false; @@ -111,7 +106,8 @@ void Json_writer::end_object() void Json_writer::end_array() { -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) + VALIDITY_ASSERT(!named_item_expected()); named_items_expectation.pop_back(); got_name= false; #endif @@ -142,7 +138,7 @@ Json_writer& Json_writer::add_member(const char *name, size_t len) output.append(name, len); output.append("\": ", 3); } -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) if (!fmt_helper.is_making_writer_calls()) got_name= true; #endif @@ -260,7 +256,7 @@ void Json_writer::add_unquoted_str(const char* str, size_t len) inline bool Json_writer::on_add_str(const char *str, size_t num_bytes) { -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) got_name= false; #endif bool helped= fmt_helper.on_add_str(str, num_bytes); diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h index 6f9ae73c5ee..c8bd7f5b8fa 100644 --- a/sql/my_json_writer.h +++ b/sql/my_json_writer.h @@ -17,9 +17,12 @@ #define JSON_WRITER_INCLUDED #include "my_base.h" +#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) +#include +#endif + #ifdef JSON_WRITER_UNIT_TEST #include "sql_string.h" -#include // Also, mock objects are defined in my_json_writer-t.cc #define VALIDITY_ASSERT(x) if ((!x)) this->invalid_json= true; #else @@ -200,7 +203,7 @@ private: class Json_writer { -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) /* In debug mode, Json_writer will fail and assertion if one attempts to produce an invalid JSON document (e.g. JSON array having named elements). @@ -244,7 +247,6 @@ private: void add_unquoted_str(const char* val, size_t len); bool on_add_str(const char *str, size_t num_bytes); - bool on_start_array(); void on_start_object(); public: @@ -264,7 +266,7 @@ public: size_t get_truncated_bytes() { return output.get_truncated_bytes(); } Json_writer() : -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) got_name(false), #endif indent_level(0), document_start(true), element_started(false), diff --git a/unittest/sql/my_json_writer-t.cc b/unittest/sql/my_json_writer-t.cc index 46c3f4dc967..3d23c2f021e 100644 --- a/unittest/sql/my_json_writer-t.cc +++ b/unittest/sql/my_json_writer-t.cc @@ -110,7 +110,7 @@ int main(int args, char **argv) Json_writer w; w.start_array(); w.end_object(); - ok(!w.invalid_json, "BAD: not checked!"); + ok(w.invalid_json, "JSON object end of array"); } // BAD: @@ -118,7 +118,7 @@ int main(int args, char **argv) Json_writer w; w.start_object(); w.end_array(); - ok(!w.invalid_json, "BAD: not checked!"); + ok(w.invalid_json, "JSON array end of object"); } -- cgit v1.2.1 From 9960b98267d3952e30c09c9816364304deb3a242 Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Tue, 9 Nov 2021 15:42:57 +0200 Subject: MDEV-23766: buildfix: postpone new unittest until its dependency resolution --- unittest/sql/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index ab174680fab..caeac841a5c 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -37,7 +37,3 @@ TARGET_LINK_LIBRARIES(mf_iocache-t mysys mytap mysys_ssl) ADD_DEPENDENCIES(mf_iocache-t GenError) MY_ADD_TEST(mf_iocache) -# Json writer needs String which needs sql library -ADD_EXECUTABLE(my_json_writer-t my_json_writer-t.cc dummy_builtins.cc) -TARGET_LINK_LIBRARIES(my_json_writer-t sql mytap) -MY_ADD_TEST(my_json_writer) -- cgit v1.2.1 From ff08e948d3708a3e9ab40bb492d6d18b8914ecff Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Tue, 9 Nov 2021 15:40:50 +0200 Subject: Revert "In case WITH_WSREP is enabled, build wsrep as plugin" This reverts commit e45f7f485a4c8133962a4082636412745ed07093. --- cmake/plugin.cmake | 6 ++---- sql/CMakeLists.txt | 9 +++++---- sql/sql_builtin.cc.in | 6 ++++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmake/plugin.cmake b/cmake/plugin.cmake index 5d94e2607f8..e7e9d2a3642 100644 --- a/cmake/plugin.cmake +++ b/cmake/plugin.cmake @@ -30,7 +30,7 @@ INCLUDE(CMakeParseArguments) MACRO(MYSQL_ADD_PLUGIN) CMAKE_PARSE_ARGUMENTS(ARG - "STORAGE_ENGINE;STATIC_ONLY;MODULE_ONLY;MANDATORY;DEFAULT;DISABLED;RECOMPILE_FOR_EMBEDDED;CLIENT;EXPORT_SYMBOLS" + "STORAGE_ENGINE;STATIC_ONLY;MODULE_ONLY;MANDATORY;DEFAULT;DISABLED;RECOMPILE_FOR_EMBEDDED;CLIENT" "MODULE_OUTPUT_NAME;STATIC_OUTPUT_NAME;COMPONENT;CONFIG" "LINK_LIBRARIES;DEPENDS" ${ARGN} @@ -139,9 +139,7 @@ MACRO(MYSQL_ADD_PLUGIN) ADD_LIBRARY(${target} STATIC ${SOURCES}) DTRACE_INSTRUMENT(${target}) ADD_DEPENDENCIES(${target} GenError ${ARG_DEPENDS}) - IF(NOT ARG_EXPORT_SYMBOLS) - RESTRICT_SYMBOL_EXPORTS(${target}) - ENDIF() + RESTRICT_SYMBOL_EXPORTS(${target}) IF(WITH_EMBEDDED_SERVER) # Embedded library should contain PIC code and be linkable # to shared libraries (on systems that need PIC) diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index ec3b0c528bb..4dd34e80f2d 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -36,10 +36,9 @@ IF(WITH_WSREP AND NOT EMBEDDED_LIBRARY) wsrep_plugin.cc service_wsrep.cc ) - MYSQL_ADD_PLUGIN(wsrep ${WSREP_SOURCES} MANDATORY EXPORT_SYMBOLS LINK_LIBRARIES wsrep-lib wsrep_api_v26) + SET(WSREP_LIB wsrep-lib wsrep_api_v26) ELSE() - ADD_LIBRARY(wsrep STATIC wsrep_dummy.cc) - ADD_DEPENDENCIES(wsrep GenError) + SET(WSREP_SOURCES wsrep_dummy.cc) ENDIF() INCLUDE_DIRECTORIES( @@ -143,6 +142,7 @@ SET (SQL_SOURCE opt_split.cc rowid_filter.cc rowid_filter.h opt_trace.cc + ${WSREP_SOURCES} table_cache.cc encryption.cc temporary_tables.cc proxy_protocol.cc backup.cc xa.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc @@ -180,10 +180,11 @@ DTRACE_INSTRUMENT(sql) TARGET_LINK_LIBRARIES(sql mysys mysys_ssl dbug strings vio pcre ${LIBWRAP} ${LIBCRYPT} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} + ${WSREP_LIB} ${SSL_LIBRARIES} ${LIBSYSTEMD}) -FOREACH(se aria partition perfschema sql_sequence wsrep) +FOREACH(se aria partition perfschema sql_sequence) # These engines are used directly in sql sources. IF(TARGET ${se}) TARGET_LINK_LIBRARIES(sql ${se}) diff --git a/sql/sql_builtin.cc.in b/sql/sql_builtin.cc.in index 810f98a876c..5ac044afd5d 100644 --- a/sql/sql_builtin.cc.in +++ b/sql/sql_builtin.cc.in @@ -32,6 +32,9 @@ extern builtin_maria_plugin @mysql_mandatory_plugins@ @mysql_optional_plugins@ builtin_maria_binlog_plugin, +#ifdef WITH_WSREP + builtin_maria_wsrep_plugin, +#endif /* WITH_WSREP */ builtin_maria_mysql_password_plugin; struct st_maria_plugin *mysql_optional_plugins[]= @@ -42,5 +45,8 @@ struct st_maria_plugin *mysql_optional_plugins[]= struct st_maria_plugin *mysql_mandatory_plugins[]= { builtin_maria_binlog_plugin, builtin_maria_mysql_password_plugin, +#ifdef WITH_WSREP + builtin_maria_wsrep_plugin, +#endif /* WITH_WSREP */ @mysql_mandatory_plugins@ 0 }; -- cgit v1.2.1 From f7c6c02a06149aa4f41dd01173f2020a0756f8db Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Tue, 9 Nov 2021 15:43:10 +0200 Subject: Revert "improve build, allow sql library to be built in parallel with builtins" This reverts commit 1a3570dec35733e725cc6000a06ec666facf4235. --- extra/mariabackup/CMakeLists.txt | 6 ++---- sql/CMakeLists.txt | 17 +++-------------- unittest/sql/CMakeLists.txt | 8 +++----- unittest/sql/dummy_builtins.cc | 26 -------------------------- 4 files changed, 8 insertions(+), 49 deletions(-) delete mode 100644 unittest/sql/dummy_builtins.cc diff --git a/extra/mariabackup/CMakeLists.txt b/extra/mariabackup/CMakeLists.txt index 3179e1550c9..75c942c8a7b 100644 --- a/extra/mariabackup/CMakeLists.txt +++ b/extra/mariabackup/CMakeLists.txt @@ -75,7 +75,6 @@ MYSQL_ADD_EXECUTABLE(mariabackup backup_mysql.cc backup_copy.cc encryption_plugin.cc - ${PROJECT_BINARY_DIR}/sql/sql_builtin.cc ${PROJECT_SOURCE_DIR}/sql/net_serv.cc ${NT_SERVICE_SOURCE} ${PROJECT_SOURCE_DIR}/libmysqld/libmysql.c @@ -83,14 +82,13 @@ MYSQL_ADD_EXECUTABLE(mariabackup ) - - # Export all symbols on Unix, for better crash callstacks SET_TARGET_PROPERTIES(mariabackup PROPERTIES ENABLE_EXPORTS TRUE) ADD_SUBDIRECTORY(crc) -TARGET_LINK_LIBRARIES(mariabackup sql sql_builtins crc) +TARGET_LINK_LIBRARIES(mariabackup sql crc) + IF(NOT HAVE_SYSTEM_REGEX) TARGET_LINK_LIBRARIES(mariabackup pcreposix) ENDIF() diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 4dd34e80f2d..7154e3dbe44 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -145,11 +145,11 @@ SET (SQL_SOURCE ${WSREP_SOURCES} table_cache.cc encryption.cc temporary_tables.cc proxy_protocol.cc backup.cc xa.cc + ${CMAKE_CURRENT_BINARY_DIR}/sql_builtin.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.cc ${CMAKE_CURRENT_BINARY_DIR}/lex_hash.h ${CMAKE_CURRENT_BINARY_DIR}/lex_token.h - ${GEN_SOURCES} ${MYSYS_LIBWRAP_SOURCE} ) @@ -177,20 +177,13 @@ RECOMPILE_FOR_EMBEDDED) ADD_LIBRARY(sql STATIC ${SQL_SOURCE}) DTRACE_INSTRUMENT(sql) -TARGET_LINK_LIBRARIES(sql +TARGET_LINK_LIBRARIES(sql ${MYSQLD_STATIC_PLUGIN_LIBS} mysys mysys_ssl dbug strings vio pcre ${LIBWRAP} ${LIBCRYPT} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${WSREP_LIB} ${SSL_LIBRARIES} ${LIBSYSTEMD}) -FOREACH(se aria partition perfschema sql_sequence) - # These engines are used directly in sql sources. - IF(TARGET ${se}) - TARGET_LINK_LIBRARIES(sql ${se}) - ENDIF() -ENDFOREACH() - IF(WIN32) SET(MYSQLD_SOURCE main.cc nt_servc.cc message.rc) TARGET_LINK_LIBRARIES(sql psapi) @@ -274,9 +267,6 @@ IF(MSVC AND NOT WITHOUT_DYNAMIC_PLUGINS) SET_TARGET_PROPERTIES(mysqld_import_lib PROPERTIES IMPORTED_LOCATION ${MYSQLD_LIB}) ENDIF() -ADD_LIBRARY( sql_builtins ${CMAKE_CURRENT_BINARY_DIR}/sql_builtin.cc) -TARGET_LINK_LIBRARIES(sql_builtins ${MYSQLD_STATIC_PLUGIN_LIBS}) - MYSQL_ADD_EXECUTABLE(mysqld ${MYSQLD_SOURCE} DESTINATION ${INSTALL_SBINDIR} COMPONENT Server) IF(APPLE) @@ -304,8 +294,7 @@ IF(NOT WITHOUT_DYNAMIC_PLUGINS) ENDIF() ENDIF(NOT WITHOUT_DYNAMIC_PLUGINS) -TARGET_LINK_LIBRARIES(mysqld LINK_PRIVATE sql sql_builtins) - +TARGET_LINK_LIBRARIES(mysqld LINK_PRIVATE sql) # Provide plugins with minimal set of libraries SET(INTERFACE_LIBS ${LIBRT}) diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index caeac841a5c..2a765c44cb1 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -21,12 +21,10 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql ${CMAKE_SOURCE_DIR}/extra/yassl/include) IF(WIN32) - ADD_EXECUTABLE(explain_filename-t - explain_filename-t.cc - dummy_builtins.cc - ../../sql/nt_servc.cc) + ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc + ../../sql/nt_servc.cc) ELSE() - ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc dummy_builtins.cc) + ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc) ENDIF() TARGET_LINK_LIBRARIES(explain_filename-t sql mytap) diff --git a/unittest/sql/dummy_builtins.cc b/unittest/sql/dummy_builtins.cc deleted file mode 100644 index 31d043d19ec..00000000000 --- a/unittest/sql/dummy_builtins.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* 2018 MariaDB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ - -#include -#include -struct st_maria_plugin *mysql_optional_plugins[]= -{ - 0 -}; - -struct st_maria_plugin *mysql_mandatory_plugins[]= -{ - 0 -}; -- cgit v1.2.1 From 7acf31783c93b54e04d42c9ecec7c7426f5ca31f Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sun, 26 May 2019 12:54:46 +0200 Subject: Add new option NOT_EMBEDDED, for plugins Means, plugin will not be available in embedded, even if compiled-in --- CMakeLists.txt | 2 +- cmake/plugin.cmake | 22 +++++++++++++++++----- libmysqld/CMakeLists.txt | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f81ab458e6d..4153b73b572 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -402,7 +402,7 @@ IF(WITH_UNIT_TESTS) ENDIF() ENDIF() -SET (MYSQLD_STATIC_PLUGIN_LIBS "" CACHE INTERNAL "") +UNSET (MYSQLD_STATIC_PLUGIN_LIBS CACHE) INCLUDE(mariadb_connector_c) # this does ADD_SUBDIRECTORY(libmariadb) diff --git a/cmake/plugin.cmake b/cmake/plugin.cmake index e7e9d2a3642..e63d7ae7b00 100644 --- a/cmake/plugin.cmake +++ b/cmake/plugin.cmake @@ -25,12 +25,13 @@ INCLUDE(CMakeParseArguments) # [MODULE_OUTPUT_NAME module_name] # [STATIC_OUTPUT_NAME static_name] # [RECOMPILE_FOR_EMBEDDED] +# [NOT_EMBEDDED] # [LINK_LIBRARIES lib1...libN] # [DEPENDS target1...targetN] MACRO(MYSQL_ADD_PLUGIN) CMAKE_PARSE_ARGUMENTS(ARG - "STORAGE_ENGINE;STATIC_ONLY;MODULE_ONLY;MANDATORY;DEFAULT;DISABLED;RECOMPILE_FOR_EMBEDDED;CLIENT" + "STORAGE_ENGINE;STATIC_ONLY;MODULE_ONLY;MANDATORY;DEFAULT;DISABLED;NOT_EMBEDDED;RECOMPILE_FOR_EMBEDDED;CLIENT" "MODULE_OUTPUT_NAME;STATIC_OUTPUT_NAME;COMPONENT;CONFIG" "LINK_LIBRARIES;DEPENDS" ${ARGN} @@ -140,7 +141,7 @@ MACRO(MYSQL_ADD_PLUGIN) DTRACE_INSTRUMENT(${target}) ADD_DEPENDENCIES(${target} GenError ${ARG_DEPENDS}) RESTRICT_SYMBOL_EXPORTS(${target}) - IF(WITH_EMBEDDED_SERVER) + IF(WITH_EMBEDDED_SERVER AND (NOT ARG_NOT_EMBEDDED)) # Embedded library should contain PIC code and be linkable # to shared libraries (on systems that need PIC) IF(ARG_RECOMPILE_FOR_EMBEDDED OR NOT _SKIP_PIC) @@ -165,19 +166,30 @@ MACRO(MYSQL_ADD_PLUGIN) TARGET_LINK_LIBRARIES (${target} ${ARG_LINK_LIBRARIES}) ENDIF() + SET(${with_var} ON CACHE INTERNAL "Link ${plugin} statically to the server" FORCE) + # Update mysqld dependencies SET (MYSQLD_STATIC_PLUGIN_LIBS ${MYSQLD_STATIC_PLUGIN_LIBS} ${target} ${ARG_LINK_LIBRARIES} CACHE INTERNAL "" FORCE) - SET(${with_var} ON CACHE INTERNAL "Link ${plugin} statically to the server" FORCE) + IF(WITH_EMBEDDED_SERVER AND (NOT ARG_NOT_EMBEDDED)) + SET (EMBEDDED_PLUGIN_LIBS ${EMBEDDED_PLUGIN_LIBS} + ${target} ${ARG_LINK_LIBRARIES} CACHE INTERNAL "" FORCE) + ENDIF() + + IF(ARG_NOT_EMBEDDED) + SET(builtin_entry "#ifndef EMBEDDED_LIBRARY\n builtin_maria_${target}_plugin,\n#endif") + ELSE() + SET(builtin_entry " builtin_maria_${target}_plugin,") + ENDIF() IF(ARG_MANDATORY) SET (mysql_mandatory_plugins - "${mysql_mandatory_plugins} builtin_maria_${target}_plugin,") + "${mysql_mandatory_plugins}${builtin_entry}\n") SET (mysql_mandatory_plugins ${mysql_mandatory_plugins} PARENT_SCOPE) ELSE() SET (mysql_optional_plugins - "${mysql_optional_plugins} builtin_maria_${target}_plugin,") + "${mysql_optional_plugins}${builtin_entry}\n") SET (mysql_optional_plugins ${mysql_optional_plugins} PARENT_SCOPE) ENDIF() ELSEIF(PLUGIN_${plugin} MATCHES "(DYNAMIC|AUTO|YES)" diff --git a/libmysqld/CMakeLists.txt b/libmysqld/CMakeLists.txt index 0266569eff6..e3d170fa47d 100644 --- a/libmysqld/CMakeLists.txt +++ b/libmysqld/CMakeLists.txt @@ -55,7 +55,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc ../sql/item_subselect.cc ../sql/item_sum.cc ../sql/item_timefunc.cc ../sql/item_xmlfunc.cc ../sql/item_jsonfunc.cc ../sql/key.cc ../sql/lock.cc ../sql/log.cc - ../sql/log_event.cc ../sql/mf_iocache.cc ../sql/my_decimal.cc + ../sql/log_event.cc ../sql/mf_iocache.cc ../sql/my_decimal.cc ../sql/net_serv.cc ../sql/opt_range.cc ../sql/opt_sum.cc ../sql/parse_file.cc ../sql/procedure.cc ../sql/protocol.cc ../sql/records.cc ../sql/repl_failsafe.cc ../sql/rpl_filter.cc @@ -154,7 +154,7 @@ SET(LIBS dbug strings mysys mysys_ssl pcre vio ${ZLIB_LIBRARY} ${SSL_LIBRARIES} ${LIBWRAP} ${LIBCRYPT} ${CMAKE_DL_LIBS} - ${MYSQLD_STATIC_PLUGIN_LIBS} + ${EMBEDDED_PLUGIN_LIBS} sql_embedded ) -- cgit v1.2.1 From 009f3e06f3e74303559df59db404b300a12241d3 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Fri, 28 Jun 2019 13:21:39 +0200 Subject: improve build, allow sql library to be built in parallel with builtins --- extra/mariabackup/CMakeLists.txt | 6 ++++-- sql/CMakeLists.txt | 17 ++++++++++++++--- unittest/sql/CMakeLists.txt | 8 +++++--- unittest/sql/dummy_builtins.cc | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 unittest/sql/dummy_builtins.cc diff --git a/extra/mariabackup/CMakeLists.txt b/extra/mariabackup/CMakeLists.txt index 75c942c8a7b..3179e1550c9 100644 --- a/extra/mariabackup/CMakeLists.txt +++ b/extra/mariabackup/CMakeLists.txt @@ -75,6 +75,7 @@ MYSQL_ADD_EXECUTABLE(mariabackup backup_mysql.cc backup_copy.cc encryption_plugin.cc + ${PROJECT_BINARY_DIR}/sql/sql_builtin.cc ${PROJECT_SOURCE_DIR}/sql/net_serv.cc ${NT_SERVICE_SOURCE} ${PROJECT_SOURCE_DIR}/libmysqld/libmysql.c @@ -82,13 +83,14 @@ MYSQL_ADD_EXECUTABLE(mariabackup ) + + # Export all symbols on Unix, for better crash callstacks SET_TARGET_PROPERTIES(mariabackup PROPERTIES ENABLE_EXPORTS TRUE) ADD_SUBDIRECTORY(crc) -TARGET_LINK_LIBRARIES(mariabackup sql crc) - +TARGET_LINK_LIBRARIES(mariabackup sql sql_builtins crc) IF(NOT HAVE_SYSTEM_REGEX) TARGET_LINK_LIBRARIES(mariabackup pcreposix) ENDIF() diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 7154e3dbe44..4dd34e80f2d 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -145,11 +145,11 @@ SET (SQL_SOURCE ${WSREP_SOURCES} table_cache.cc encryption.cc temporary_tables.cc proxy_protocol.cc backup.cc xa.cc - ${CMAKE_CURRENT_BINARY_DIR}/sql_builtin.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.cc ${CMAKE_CURRENT_BINARY_DIR}/lex_hash.h ${CMAKE_CURRENT_BINARY_DIR}/lex_token.h + ${GEN_SOURCES} ${MYSYS_LIBWRAP_SOURCE} ) @@ -177,13 +177,20 @@ RECOMPILE_FOR_EMBEDDED) ADD_LIBRARY(sql STATIC ${SQL_SOURCE}) DTRACE_INSTRUMENT(sql) -TARGET_LINK_LIBRARIES(sql ${MYSQLD_STATIC_PLUGIN_LIBS} +TARGET_LINK_LIBRARIES(sql mysys mysys_ssl dbug strings vio pcre ${LIBWRAP} ${LIBCRYPT} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${WSREP_LIB} ${SSL_LIBRARIES} ${LIBSYSTEMD}) +FOREACH(se aria partition perfschema sql_sequence) + # These engines are used directly in sql sources. + IF(TARGET ${se}) + TARGET_LINK_LIBRARIES(sql ${se}) + ENDIF() +ENDFOREACH() + IF(WIN32) SET(MYSQLD_SOURCE main.cc nt_servc.cc message.rc) TARGET_LINK_LIBRARIES(sql psapi) @@ -267,6 +274,9 @@ IF(MSVC AND NOT WITHOUT_DYNAMIC_PLUGINS) SET_TARGET_PROPERTIES(mysqld_import_lib PROPERTIES IMPORTED_LOCATION ${MYSQLD_LIB}) ENDIF() +ADD_LIBRARY( sql_builtins ${CMAKE_CURRENT_BINARY_DIR}/sql_builtin.cc) +TARGET_LINK_LIBRARIES(sql_builtins ${MYSQLD_STATIC_PLUGIN_LIBS}) + MYSQL_ADD_EXECUTABLE(mysqld ${MYSQLD_SOURCE} DESTINATION ${INSTALL_SBINDIR} COMPONENT Server) IF(APPLE) @@ -294,7 +304,8 @@ IF(NOT WITHOUT_DYNAMIC_PLUGINS) ENDIF() ENDIF(NOT WITHOUT_DYNAMIC_PLUGINS) -TARGET_LINK_LIBRARIES(mysqld LINK_PRIVATE sql) +TARGET_LINK_LIBRARIES(mysqld LINK_PRIVATE sql sql_builtins) + # Provide plugins with minimal set of libraries SET(INTERFACE_LIBS ${LIBRT}) diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index 2a765c44cb1..caeac841a5c 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -21,10 +21,12 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql ${CMAKE_SOURCE_DIR}/extra/yassl/include) IF(WIN32) - ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc - ../../sql/nt_servc.cc) + ADD_EXECUTABLE(explain_filename-t + explain_filename-t.cc + dummy_builtins.cc + ../../sql/nt_servc.cc) ELSE() - ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc) + ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc dummy_builtins.cc) ENDIF() TARGET_LINK_LIBRARIES(explain_filename-t sql mytap) diff --git a/unittest/sql/dummy_builtins.cc b/unittest/sql/dummy_builtins.cc new file mode 100644 index 00000000000..31d043d19ec --- /dev/null +++ b/unittest/sql/dummy_builtins.cc @@ -0,0 +1,26 @@ +/* 2018 MariaDB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ + +#include +#include +struct st_maria_plugin *mysql_optional_plugins[]= +{ + 0 +}; + +struct st_maria_plugin *mysql_mandatory_plugins[]= +{ + 0 +}; -- cgit v1.2.1 From c1e1ca20f48b30c8a754bd42274385065d89060e Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sat, 29 Jun 2019 15:28:20 +0300 Subject: =?UTF-8?q?In=20case=20WITH=5FWSREP=20is=20enabled,=20build=20wsre?= =?UTF-8?q?p=20as=20plugin=20If=20it=20is=20not=20enabled,=20build=20wsrep?= =?UTF-8?q?=20as=20static=20"stub"=20library=20from=20wsrep=5Fdummy.cc=20?= =?UTF-8?q?=C2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow static plugins to export symbols (on Unix) wsrep_info relies on wsrep defined symbols (e.g LOCK_wsrep_config_state) exported from mysqld --- cmake/plugin.cmake | 6 ++++-- sql/CMakeLists.txt | 9 ++++----- sql/sql_builtin.cc.in | 6 ------ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/cmake/plugin.cmake b/cmake/plugin.cmake index e63d7ae7b00..008ac9e9471 100644 --- a/cmake/plugin.cmake +++ b/cmake/plugin.cmake @@ -31,7 +31,7 @@ INCLUDE(CMakeParseArguments) MACRO(MYSQL_ADD_PLUGIN) CMAKE_PARSE_ARGUMENTS(ARG - "STORAGE_ENGINE;STATIC_ONLY;MODULE_ONLY;MANDATORY;DEFAULT;DISABLED;NOT_EMBEDDED;RECOMPILE_FOR_EMBEDDED;CLIENT" + "STORAGE_ENGINE;STATIC_ONLY;MODULE_ONLY;MANDATORY;DEFAULT;DISABLED;NOT_EMBEDDED;RECOMPILE_FOR_EMBEDDED;CLIENT;EXPORT_SYMBOLS" "MODULE_OUTPUT_NAME;STATIC_OUTPUT_NAME;COMPONENT;CONFIG" "LINK_LIBRARIES;DEPENDS" ${ARGN} @@ -140,7 +140,9 @@ MACRO(MYSQL_ADD_PLUGIN) ADD_LIBRARY(${target} STATIC ${SOURCES}) DTRACE_INSTRUMENT(${target}) ADD_DEPENDENCIES(${target} GenError ${ARG_DEPENDS}) - RESTRICT_SYMBOL_EXPORTS(${target}) + IF(NOT ARG_EXPORT_SYMBOLS) + RESTRICT_SYMBOL_EXPORTS(${target}) + ENDIF() IF(WITH_EMBEDDED_SERVER AND (NOT ARG_NOT_EMBEDDED)) # Embedded library should contain PIC code and be linkable # to shared libraries (on systems that need PIC) diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 4dd34e80f2d..5f6ccddfe16 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -36,9 +36,10 @@ IF(WITH_WSREP AND NOT EMBEDDED_LIBRARY) wsrep_plugin.cc service_wsrep.cc ) - SET(WSREP_LIB wsrep-lib wsrep_api_v26) + MYSQL_ADD_PLUGIN(wsrep ${WSREP_SOURCES} MANDATORY NOT_EMBEDDED EXPORT_SYMBOLS LINK_LIBRARIES wsrep-lib wsrep_api_v26) ELSE() - SET(WSREP_SOURCES wsrep_dummy.cc) + ADD_LIBRARY(wsrep STATIC wsrep_dummy.cc) + ADD_DEPENDENCIES(wsrep GenError) ENDIF() INCLUDE_DIRECTORIES( @@ -142,7 +143,6 @@ SET (SQL_SOURCE opt_split.cc rowid_filter.cc rowid_filter.h opt_trace.cc - ${WSREP_SOURCES} table_cache.cc encryption.cc temporary_tables.cc proxy_protocol.cc backup.cc xa.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc @@ -180,11 +180,10 @@ DTRACE_INSTRUMENT(sql) TARGET_LINK_LIBRARIES(sql mysys mysys_ssl dbug strings vio pcre ${LIBWRAP} ${LIBCRYPT} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} - ${WSREP_LIB} ${SSL_LIBRARIES} ${LIBSYSTEMD}) -FOREACH(se aria partition perfschema sql_sequence) +FOREACH(se aria partition perfschema sql_sequence wsrep) # These engines are used directly in sql sources. IF(TARGET ${se}) TARGET_LINK_LIBRARIES(sql ${se}) diff --git a/sql/sql_builtin.cc.in b/sql/sql_builtin.cc.in index 5ac044afd5d..810f98a876c 100644 --- a/sql/sql_builtin.cc.in +++ b/sql/sql_builtin.cc.in @@ -32,9 +32,6 @@ extern builtin_maria_plugin @mysql_mandatory_plugins@ @mysql_optional_plugins@ builtin_maria_binlog_plugin, -#ifdef WITH_WSREP - builtin_maria_wsrep_plugin, -#endif /* WITH_WSREP */ builtin_maria_mysql_password_plugin; struct st_maria_plugin *mysql_optional_plugins[]= @@ -45,8 +42,5 @@ struct st_maria_plugin *mysql_optional_plugins[]= struct st_maria_plugin *mysql_mandatory_plugins[]= { builtin_maria_binlog_plugin, builtin_maria_mysql_password_plugin, -#ifdef WITH_WSREP - builtin_maria_wsrep_plugin, -#endif /* WITH_WSREP */ @mysql_mandatory_plugins@ 0 }; -- cgit v1.2.1 From 04ad98b5001eafea537d3c655d0021ffb2f5ef06 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 5 Nov 2021 19:01:43 +0200 Subject: MDEV-23766: Re-add Json_writer unit test. --- unittest/sql/CMakeLists.txt | 4 ++++ unittest/sql/my_json_writer-t.cc | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index caeac841a5c..ab174680fab 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -37,3 +37,7 @@ TARGET_LINK_LIBRARIES(mf_iocache-t mysys mytap mysys_ssl) ADD_DEPENDENCIES(mf_iocache-t GenError) MY_ADD_TEST(mf_iocache) +# Json writer needs String which needs sql library +ADD_EXECUTABLE(my_json_writer-t my_json_writer-t.cc dummy_builtins.cc) +TARGET_LINK_LIBRARIES(my_json_writer-t sql mytap) +MY_ADD_TEST(my_json_writer) diff --git a/unittest/sql/my_json_writer-t.cc b/unittest/sql/my_json_writer-t.cc index 3d23c2f021e..6398a589c33 100644 --- a/unittest/sql/my_json_writer-t.cc +++ b/unittest/sql/my_json_writer-t.cc @@ -105,7 +105,6 @@ int main(int args, char **argv) ok(w.invalid_json, "Named array in an array"); } - // BAD: { Json_writer w; w.start_array(); @@ -113,7 +112,6 @@ int main(int args, char **argv) ok(w.invalid_json, "JSON object end of array"); } - // BAD: { Json_writer w; w.start_object(); -- cgit v1.2.1 From 94ef277b5b98afb25400fdb1b3b4917ef16172da Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Tue, 9 Nov 2021 20:06:22 +0200 Subject: MDEV-23766: fix by assert (Windows) --- sql/my_json_writer.h | 20 ++++++++++---------- sql/opt_range.cc | 7 +++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h index c8bd7f5b8fa..7d209501a87 100644 --- a/sql/my_json_writer.h +++ b/sql/my_json_writer.h @@ -24,7 +24,7 @@ #ifdef JSON_WRITER_UNIT_TEST #include "sql_string.h" // Also, mock objects are defined in my_json_writer-t.cc -#define VALIDITY_ASSERT(x) if ((!x)) this->invalid_json= true; +#define VALIDITY_ASSERT(x) if (!(x)) this->invalid_json= true; #else #include "sql_select.h" #define VALIDITY_ASSERT(x) DBUG_ASSERT(x) @@ -356,6 +356,9 @@ public: /* A common base for Json_writer_object and Json_writer_array */ class Json_writer_struct { + Json_writer_struct(const Json_writer_struct&)= delete; + Json_writer_struct& operator=(const Json_writer_struct&)= delete; + protected: Json_writer* my_writer; Json_value_helper context; @@ -394,18 +397,15 @@ private: my_writer->add_member(name); } public: - explicit Json_writer_object(THD *thd) - : Json_writer_struct(thd) - { - if (unlikely(my_writer)) - my_writer->start_object(); - } - - explicit Json_writer_object(THD* thd, const char *str) + explicit Json_writer_object(THD* thd, const char *str= nullptr) : Json_writer_struct(thd) { if (unlikely(my_writer)) - my_writer->add_member(str).start_object(); + { + if (str) + my_writer->add_member(str); + my_writer->start_object(); + } } ~Json_writer_object() diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 122b00f4d57..47bf8f1682f 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -5101,9 +5101,8 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge, n_child_scans))) DBUG_RETURN(NULL); - Json_writer_object trace_best_disjunct = named_trace - ? Json_writer_object(thd, "best_disjunct_quick") - : Json_writer_object(thd); + const char* trace_best_disjunct_obj_name= named_trace ? "best_disjunct_quick" : nullptr; + Json_writer_object trace_best_disjunct(thd, trace_best_disjunct_obj_name); Json_writer_array to_merge(thd, "indexes_to_merge"); /* Collect best 'range' scan for each of disjuncts, and, while doing so, @@ -5649,7 +5648,7 @@ void print_keyparts(THD *thd, KEY *key, uint key_parts) DBUG_ASSERT(thd->trace_started()); KEY_PART_INFO *part= key->key_part; - Json_writer_array keyparts= Json_writer_array(thd, "keyparts"); + Json_writer_array keyparts(thd, "keyparts"); for(uint i= 0; i < key_parts; i++, part++) keyparts.add(part->field->field_name); } -- cgit v1.2.1 From 3163d9e60c0e7d16e1481fb3e0f6fc0baf9e1339 Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Thu, 11 Nov 2021 06:19:19 -0700 Subject: MDEV-26991: CURRENT_TEST: main.mysql_binary_zero_insert 'grep' is not recognized as an internal or external command, operable program or batch file. Removed grep from mysqldump command stream and instead, extend the search_file pattern to search for rows containing binary zeros instead of any occurance of '00' in the input --- mysql-test/r/mysql_binary_zero_insert.result | 4 ++-- mysql-test/t/mysql_binary_zero_insert.test | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/mysql_binary_zero_insert.result b/mysql-test/r/mysql_binary_zero_insert.result index 0bed7487b3e..3e43c070f07 100644 --- a/mysql-test/r/mysql_binary_zero_insert.result +++ b/mysql-test/r/mysql_binary_zero_insert.result @@ -32,8 +32,8 @@ COUNT(*)=8 # Note: We only look for 00 because the 5c only served as an escape # in parsing. # -# MYSQL_DUMP test tb --hex-blob | grep INSERT > MYSQL_TMP_DIR/dump.sql -FOUND 10 /00/ in dump.sql +# MYSQL_DUMP test tb --hex-blob > MYSQL_TMP_DIR/dump.sql +FOUND 8 /\([0-9]+,0x([1-9][0-9])*00([1-9][0-9])*\)/ in dump.sql # # Ensure data consistency on mysqlbinlog replay # diff --git a/mysql-test/t/mysql_binary_zero_insert.test b/mysql-test/t/mysql_binary_zero_insert.test index b327c8a4d1e..37a1f1f79ff 100644 --- a/mysql-test/t/mysql_binary_zero_insert.test +++ b/mysql-test/t/mysql_binary_zero_insert.test @@ -114,9 +114,9 @@ SELECT COUNT(*)=8 from tb; --echo # Note: We only look for 00 because the 5c only served as an escape --echo # in parsing. --echo # ---echo # MYSQL_DUMP test tb --hex-blob | grep INSERT > MYSQL_TMP_DIR/dump.sql ---exec $MYSQL_DUMP test tb --hex-blob | grep INSERT > $MYSQL_TMP_DIR/dump.sql ---let SEARCH_PATTERN= 00 +--echo # MYSQL_DUMP test tb --hex-blob > MYSQL_TMP_DIR/dump.sql +--exec $MYSQL_DUMP test tb --hex-blob > $MYSQL_TMP_DIR/dump.sql +--let SEARCH_PATTERN= \([0-9]+,0x([1-9][0-9])*00([1-9][0-9])*\) --let SEARCH_FILE= $MYSQL_TMP_DIR/dump.sql --source include/search_pattern_in_file.inc -- cgit v1.2.1 From 628c281db6fd0cf68f5fbae34dec6f7143a48f27 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 11 Nov 2021 22:12:12 +0100 Subject: MDEV-27030 vcol.vcol_keys_myisam fails on Windows x64, with Visual Studio 2022 Upon investigation, decided this to be a compiler bug (happens with new compiler, on code that did not change for the last 15 years) Fixed by de-optimizing single function remove_key(), using MSVC pragma --- storage/myisam/mi_delete.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/storage/myisam/mi_delete.c b/storage/myisam/mi_delete.c index 2c829fa9860..62409a15a46 100644 --- a/storage/myisam/mi_delete.c +++ b/storage/myisam/mi_delete.c @@ -767,6 +767,10 @@ err: returns how many chars was removed or 0 on error */ +#if defined(_MSC_VER) && defined(_M_X64) && _MSC_VER >= 1930 +#pragma optimize("g", off) +#endif + static uint remove_key(MI_KEYDEF *keyinfo, uint nod_flag, uchar *keypos, /* Where key starts */ uchar *lastkey, /* key to be removed */ @@ -891,3 +895,7 @@ static uint remove_key(MI_KEYDEF *keyinfo, uint nod_flag, (uint) (page_end-start-s_length)); DBUG_RETURN((uint) s_length); } /* remove_key */ + +#if defined(_MSC_VER) && defined(_M_X64) && _MSC_VER >= 1930 +#pragma optimize("",on) +#endif -- cgit v1.2.1 From d270525dfde86bcb92a2327234a0954083e14a94 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Fri, 12 Nov 2021 17:46:35 +0530 Subject: MDEV-23805 Make Online DDL to Instant DDL when table is empty - In ha_innobase::prepare_inplace_alter_table(), InnoDB should check whether the table is empty. If the table is empty then server should avoid downgrading the MDL after prepare phase. It is more like instant alter, does change only in dicationary and metadata. - Changed few debug test case to make non-empty DDL table --- mysql-test/suite/gcol/r/virtual_index_drop.result | 3 ++ mysql-test/suite/gcol/t/virtual_index_drop.test | 2 ++ .../suite/innodb/r/alter_candidate_key.result | 2 ++ .../suite/innodb/r/alter_not_null_debug.result | 2 ++ mysql-test/suite/innodb/r/alter_primary_key.result | 2 ++ mysql-test/suite/innodb/r/ddl_purge.result | 1 + .../suite/innodb/r/innodb-alter-tempfile.result | 2 +- .../suite/innodb/r/innodb-index-debug.result | 5 ++- .../suite/innodb/r/innodb-index-online.result | 1 + .../suite/innodb/r/instant_alter_debug.result | 3 ++ mysql-test/suite/innodb/t/alter_candidate_key.test | 2 ++ .../suite/innodb/t/alter_not_null_debug.test | 2 +- mysql-test/suite/innodb/t/alter_primary_key.test | 1 + mysql-test/suite/innodb/t/ddl_purge.test | 1 + .../suite/innodb/t/innodb-alter-tempfile.test | 2 +- mysql-test/suite/innodb/t/innodb-index-debug.test | 2 ++ mysql-test/suite/innodb/t/innodb-index-online.test | 1 + mysql-test/suite/innodb/t/instant_alter_debug.test | 3 +- mysql-test/suite/innodb_fts/r/misc_debug.result | 2 ++ mysql-test/suite/innodb_fts/t/misc_debug.test | 1 + sql/handler.h | 3 ++ sql/sql_table.cc | 7 +++-- storage/innobase/handler/handler0alter.cc | 36 +++++++++++++++++++--- 23 files changed, 73 insertions(+), 13 deletions(-) diff --git a/mysql-test/suite/gcol/r/virtual_index_drop.result b/mysql-test/suite/gcol/r/virtual_index_drop.result index 012e61be459..45ee4843b7c 100644 --- a/mysql-test/suite/gcol/r/virtual_index_drop.result +++ b/mysql-test/suite/gcol/r/virtual_index_drop.result @@ -25,6 +25,7 @@ t1 CREATE TABLE `t1` ( ) ENGINE=InnoDB DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB; +INSERT INTO t1(f1) VALUES(1); SET DEBUG_DBUG="+d,create_index_fail"; SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal"; ALTER TABLE t1 ADD COLUMN f3 INT AS (f1) VIRTUAL, ADD INDEX(f2, f3); @@ -33,6 +34,7 @@ SET DEBUG_SYNC="now WAIT_FOR con1_go"; BEGIN; SELECT * FROM t1; f1 f2 +1 1 SET DEBUG_SYNC="now SIGNAL alter_signal"; connection default; ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' @@ -47,6 +49,7 @@ t1 CREATE TABLE `t1` ( ) ENGINE=InnoDB DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB; +INSERT INTO t1(f1) VALUES(1); SET DEBUG_DBUG="+d,create_index_fail"; SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal"; ALTER TABLE t1 ADD INDEX(f2); diff --git a/mysql-test/suite/gcol/t/virtual_index_drop.test b/mysql-test/suite/gcol/t/virtual_index_drop.test index 016832b9e6d..e1ec43f75e5 100644 --- a/mysql-test/suite/gcol/t/virtual_index_drop.test +++ b/mysql-test/suite/gcol/t/virtual_index_drop.test @@ -29,6 +29,7 @@ DROP TABLE t1; # new_vcol_info in index when rollback of alter happens CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB; +INSERT INTO t1(f1) VALUES(1); SET DEBUG_DBUG="+d,create_index_fail"; SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal"; SEND ALTER TABLE t1 ADD COLUMN f3 INT AS (f1) VIRTUAL, ADD INDEX(f2, f3); @@ -47,6 +48,7 @@ SHOW CREATE TABLE t1; DROP TABLE t1; CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB; +INSERT INTO t1(f1) VALUES(1); SET DEBUG_DBUG="+d,create_index_fail"; SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal"; send ALTER TABLE t1 ADD INDEX(f2); diff --git a/mysql-test/suite/innodb/r/alter_candidate_key.result b/mysql-test/suite/innodb/r/alter_candidate_key.result index 23989e0da5f..79cb225e3b5 100644 --- a/mysql-test/suite/innodb/r/alter_candidate_key.result +++ b/mysql-test/suite/innodb/r/alter_candidate_key.result @@ -34,6 +34,7 @@ CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1, f2), UNIQUE INDEX uidx2 (f1, f2), UNIQUE INDEX uidx1 (f2))ENGINE=InnoDB; +INSERT INTO t1 VALUES(2, 2); ALTER TABLE t1 DROP PRIMARY KEY; SHOW CREATE TABLE t1; Table Create Table @@ -66,6 +67,7 @@ test.t1 check status OK DROP TABLE t1; SET SQL_MODE= strict_trans_tables; CREATE TABLE t1(a INT UNIQUE) ENGINE=InnoDB; +INSERT INTO t1 VALUES(1); SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL dml WAIT_FOR dml_done'; ALTER TABLE t1 MODIFY COLUMN a INT NOT NULL; connection con1; diff --git a/mysql-test/suite/innodb/r/alter_not_null_debug.result b/mysql-test/suite/innodb/r/alter_not_null_debug.result index 0c1af03159d..ff77eaf54c5 100644 --- a/mysql-test/suite/innodb/r/alter_not_null_debug.result +++ b/mysql-test/suite/innodb/r/alter_not_null_debug.result @@ -80,6 +80,7 @@ SET DEBUG_SYNC='RESET'; # CREATE TABLE t1 (f VARCHAR(8) CHARACTER SET latin1 COLLATE latin1_swedish_ci) ENGINE=InnoDB; +INSERT INTO t1 VALUES('ZERO'); connection con1; SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL scanned WAIT_FOR insert_done'; ALTER TABLE t1 MODIFY f VARCHAR(256) COLLATE latin1_german2_ci NOT NULL; @@ -96,5 +97,6 @@ ALTER TABLE t1 CHANGE f eins VARCHAR(257) COLLATE latin1_german1_ci NOT NULL, ALGORITHM=INSTANT; SELECT * FROM t1; eins +ZERO one DROP TABLE t1; diff --git a/mysql-test/suite/innodb/r/alter_primary_key.result b/mysql-test/suite/innodb/r/alter_primary_key.result index afe687871f3..b478691af1f 100644 --- a/mysql-test/suite/innodb/r/alter_primary_key.result +++ b/mysql-test/suite/innodb/r/alter_primary_key.result @@ -4,6 +4,7 @@ # CREATE TABLE t0 (pk INT PRIMARY KEY) ENGINE=InnoDB; CREATE TABLE t1 (c CHAR(2) NOT NULL) ENGINE=InnoDB; +INSERT INTO t1 VALUES('cd'); connect con1,localhost,root,,; BEGIN; INSERT INTO t0 VALUES(1); @@ -21,6 +22,7 @@ ERROR 23000: Duplicate entry 'a' for key 'PRIMARY' SET DEBUG_SYNC='RESET'; SELECT * FROM t1; c +cd ab ac DROP TABLE t0,t1; diff --git a/mysql-test/suite/innodb/r/ddl_purge.result b/mysql-test/suite/innodb/r/ddl_purge.result index 45f4c99e97b..275be16b2d7 100644 --- a/mysql-test/suite/innodb/r/ddl_purge.result +++ b/mysql-test/suite/innodb/r/ddl_purge.result @@ -1,5 +1,6 @@ CREATE TABLE t0 (pk INT PRIMARY KEY) ENGINE=InnoDB; CREATE TABLE t1 (pk INT PRIMARY KEY, b INT) ENGINE=InnoDB; +INSERT INTO t1 VALUES(100, 100); connect con1,localhost,root,,test; BEGIN; INSERT INTO t0 SET pk=1; diff --git a/mysql-test/suite/innodb/r/innodb-alter-tempfile.result b/mysql-test/suite/innodb/r/innodb-alter-tempfile.result index 0716f3da23c..57229d05133 100644 --- a/mysql-test/suite/innodb/r/innodb-alter-tempfile.result +++ b/mysql-test/suite/innodb/r/innodb-alter-tempfile.result @@ -61,7 +61,7 @@ connect con1,localhost,root,,; BEGIN; DELETE FROM mysql.innodb_table_stats; connect con2,localhost,root,,; -SET DEBUG_SYNC='inplace_after_index_build SIGNAL blocked WAIT_FOR ever'; +SET DEBUG_SYNC='innodb_inplace_alter_table_enter SIGNAL blocked WAIT_FOR ever'; ALTER TABLE t1 FORCE; connection default; SET DEBUG_SYNC='now WAIT_FOR blocked'; diff --git a/mysql-test/suite/innodb/r/innodb-index-debug.result b/mysql-test/suite/innodb/r/innodb-index-debug.result index daef31d2caa..2eba29e6c28 100644 --- a/mysql-test/suite/innodb/r/innodb-index-debug.result +++ b/mysql-test/suite/innodb/r/innodb-index-debug.result @@ -81,6 +81,7 @@ COUNT(k1) k2 k3 drop table t1; create table t1(k1 int auto_increment primary key, k2 char(200),k3 char(200))engine=innodb; +INSERT INTO t1 VALUES(1, "test", "test"); SET DEBUG_SYNC= 'row_merge_after_scan SIGNAL opened WAIT_FOR flushed'; ALTER TABLE t1 FORCE, ADD COLUMN k4 int; @@ -100,6 +101,7 @@ SELECT COUNT(k1),k2,k3 FROM t1 GROUP BY k2,k3; COUNT(k1) k2 k3 480 aaa bbb 480 aaaa bbbb +1 test test disconnect con1; connection default; show create table t1; @@ -109,7 +111,7 @@ t1 CREATE TABLE `t1` ( `k2` char(200) DEFAULT NULL, `k3` char(200) DEFAULT NULL, PRIMARY KEY (`k1`) -) ENGINE=InnoDB AUTO_INCREMENT=1023 DEFAULT CHARSET=latin1 +) ENGINE=InnoDB AUTO_INCREMENT=1024 DEFAULT CHARSET=latin1 drop table t1; drop table t480; # @@ -117,6 +119,7 @@ drop table t480; # in online table rebuild # CREATE TABLE t1 (j INT UNIQUE, i INT UNIQUE) ENGINE=InnoDB; +INSERT INTO t1 VALUES(2, 2); connect con1,localhost,root,,test; SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL built WAIT_FOR log'; ALTER TABLE t1 DROP j, FORCE; diff --git a/mysql-test/suite/innodb/r/innodb-index-online.result b/mysql-test/suite/innodb/r/innodb-index-online.result index 8eebece46b5..f101a63a6ed 100644 --- a/mysql-test/suite/innodb/r/innodb-index-online.result +++ b/mysql-test/suite/innodb/r/innodb-index-online.result @@ -509,6 +509,7 @@ DROP TABLE t1; # MDEV-13205 assertion !dict_index_is_online_ddl(index) upon ALTER TABLE # CREATE TABLE t1 (c VARCHAR(64)) ENGINE=InnoDB; +INSERT INTO t1 VALUES('foo'); SET DEBUG_SYNC = 'row_log_apply_before SIGNAL t1u_created WAIT_FOR dup_done'; ALTER TABLE t1 ADD UNIQUE(c); connection con1; diff --git a/mysql-test/suite/innodb/r/instant_alter_debug.result b/mysql-test/suite/innodb/r/instant_alter_debug.result index 359eb1fc384..26db222ca82 100644 --- a/mysql-test/suite/innodb/r/instant_alter_debug.result +++ b/mysql-test/suite/innodb/r/instant_alter_debug.result @@ -171,6 +171,7 @@ connect stop_purge,localhost,root; START TRANSACTION WITH CONSISTENT SNAPSHOT; connect ddl,localhost,root,,test; DELETE FROM t1; +INSERT INTO t1 VALUES(1, 2); SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL copied WAIT_FOR logged'; ALTER TABLE t1 FORCE; connection default; @@ -449,6 +450,7 @@ DROP TABLE t1; CREATE TABLE t1 (a INT NOT NULL, b INT, c INT, d INT, e INT, f INT, g INT, h INT, i TEXT) ENGINE=InnoDB; +INSERT INTO t1 VALUES(1, 2, 3, 4, 5, 6, 7, 8, "test"); ALTER TABLE t1 MODIFY a INT NULL; SET DEBUG_SYNC='innodb_inplace_alter_table_enter SIGNAL alter WAIT_FOR go'; ALTER TABLE t1 ADD PRIMARY KEY (a); @@ -462,6 +464,7 @@ connection default; disconnect con1; SELECT * FROM t1; a b c d e f g h i +1 2 3 4 5 6 7 8 test DROP TABLE t1; SET DEBUG_SYNC=RESET; # End of 10.4 tests diff --git a/mysql-test/suite/innodb/t/alter_candidate_key.test b/mysql-test/suite/innodb/t/alter_candidate_key.test index 7429cd89a1a..7c8f5e30993 100644 --- a/mysql-test/suite/innodb/t/alter_candidate_key.test +++ b/mysql-test/suite/innodb/t/alter_candidate_key.test @@ -24,6 +24,7 @@ CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1, f2), UNIQUE INDEX uidx2 (f1, f2), UNIQUE INDEX uidx1 (f2))ENGINE=InnoDB; +INSERT INTO t1 VALUES(2, 2); ALTER TABLE t1 DROP PRIMARY KEY; SHOW CREATE TABLE t1; SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter @@ -42,6 +43,7 @@ DROP TABLE t1; SET SQL_MODE= strict_trans_tables; CREATE TABLE t1(a INT UNIQUE) ENGINE=InnoDB; +INSERT INTO t1 VALUES(1); SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL dml WAIT_FOR dml_done'; --send ALTER TABLE t1 MODIFY COLUMN a INT NOT NULL connection con1; diff --git a/mysql-test/suite/innodb/t/alter_not_null_debug.test b/mysql-test/suite/innodb/t/alter_not_null_debug.test index 7a965fd413a..9c5ba0faff0 100644 --- a/mysql-test/suite/innodb/t/alter_not_null_debug.test +++ b/mysql-test/suite/innodb/t/alter_not_null_debug.test @@ -75,7 +75,7 @@ SET DEBUG_SYNC='RESET'; --echo # CREATE TABLE t1 (f VARCHAR(8) CHARACTER SET latin1 COLLATE latin1_swedish_ci) ENGINE=InnoDB; - +INSERT INTO t1 VALUES('ZERO'); connection con1; SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL scanned WAIT_FOR insert_done'; send ALTER TABLE t1 MODIFY f VARCHAR(256) COLLATE latin1_german2_ci NOT NULL; diff --git a/mysql-test/suite/innodb/t/alter_primary_key.test b/mysql-test/suite/innodb/t/alter_primary_key.test index 4edc0cc023e..bf961c14b43 100644 --- a/mysql-test/suite/innodb/t/alter_primary_key.test +++ b/mysql-test/suite/innodb/t/alter_primary_key.test @@ -9,6 +9,7 @@ CREATE TABLE t0 (pk INT PRIMARY KEY) ENGINE=InnoDB; CREATE TABLE t1 (c CHAR(2) NOT NULL) ENGINE=InnoDB; +INSERT INTO t1 VALUES('cd'); connect (con1,localhost,root,,); BEGIN; diff --git a/mysql-test/suite/innodb/t/ddl_purge.test b/mysql-test/suite/innodb/t/ddl_purge.test index 60d17acead8..e38b68c7bc9 100644 --- a/mysql-test/suite/innodb/t/ddl_purge.test +++ b/mysql-test/suite/innodb/t/ddl_purge.test @@ -4,6 +4,7 @@ CREATE TABLE t0 (pk INT PRIMARY KEY) ENGINE=InnoDB; CREATE TABLE t1 (pk INT PRIMARY KEY, b INT) ENGINE=InnoDB; +INSERT INTO t1 VALUES(100, 100); --connect (con1,localhost,root,,test) BEGIN; diff --git a/mysql-test/suite/innodb/t/innodb-alter-tempfile.test b/mysql-test/suite/innodb/t/innodb-alter-tempfile.test index cbf8ff9e87f..dac176f3b77 100644 --- a/mysql-test/suite/innodb/t/innodb-alter-tempfile.test +++ b/mysql-test/suite/innodb/t/innodb-alter-tempfile.test @@ -80,7 +80,7 @@ BEGIN; DELETE FROM mysql.innodb_table_stats; connect (con2,localhost,root,,); -SET DEBUG_SYNC='inplace_after_index_build SIGNAL blocked WAIT_FOR ever'; +SET DEBUG_SYNC='innodb_inplace_alter_table_enter SIGNAL blocked WAIT_FOR ever'; send ALTER TABLE t1 FORCE; connection default; diff --git a/mysql-test/suite/innodb/t/innodb-index-debug.test b/mysql-test/suite/innodb/t/innodb-index-debug.test index 2988a89c651..6e31200570b 100644 --- a/mysql-test/suite/innodb/t/innodb-index-debug.test +++ b/mysql-test/suite/innodb/t/innodb-index-debug.test @@ -96,6 +96,7 @@ drop table t1; # Log file creation failure. create table t1(k1 int auto_increment primary key, k2 char(200),k3 char(200))engine=innodb; +INSERT INTO t1 VALUES(1, "test", "test"); SET DEBUG_SYNC= 'row_merge_after_scan SIGNAL opened WAIT_FOR flushed'; send ALTER TABLE t1 FORCE, ADD COLUMN k4 int; @@ -122,6 +123,7 @@ drop table t480; --echo # CREATE TABLE t1 (j INT UNIQUE, i INT UNIQUE) ENGINE=InnoDB; +INSERT INTO t1 VALUES(2, 2); --connect (con1,localhost,root,,test) SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL built WAIT_FOR log'; --send diff --git a/mysql-test/suite/innodb/t/innodb-index-online.test b/mysql-test/suite/innodb/t/innodb-index-online.test index 5e21fa896a4..781ff8ee681 100644 --- a/mysql-test/suite/innodb/t/innodb-index-online.test +++ b/mysql-test/suite/innodb/t/innodb-index-online.test @@ -477,6 +477,7 @@ DROP TABLE t1; --echo # MDEV-13205 assertion !dict_index_is_online_ddl(index) upon ALTER TABLE --echo # CREATE TABLE t1 (c VARCHAR(64)) ENGINE=InnoDB; +INSERT INTO t1 VALUES('foo'); SET DEBUG_SYNC = 'row_log_apply_before SIGNAL t1u_created WAIT_FOR dup_done'; send ALTER TABLE t1 ADD UNIQUE(c); diff --git a/mysql-test/suite/innodb/t/instant_alter_debug.test b/mysql-test/suite/innodb/t/instant_alter_debug.test index 10f7546cc36..8cf2610bbfb 100644 --- a/mysql-test/suite/innodb/t/instant_alter_debug.test +++ b/mysql-test/suite/innodb/t/instant_alter_debug.test @@ -186,6 +186,7 @@ connect stop_purge,localhost,root; START TRANSACTION WITH CONSISTENT SNAPSHOT; connect ddl,localhost,root,,test; DELETE FROM t1; +INSERT INTO t1 VALUES(1, 2); SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL copied WAIT_FOR logged'; send ALTER TABLE t1 FORCE; connection default; @@ -519,7 +520,7 @@ DROP TABLE t1; CREATE TABLE t1 (a INT NOT NULL, b INT, c INT, d INT, e INT, f INT, g INT, h INT, i TEXT) ENGINE=InnoDB; - +INSERT INTO t1 VALUES(1, 2, 3, 4, 5, 6, 7, 8, "test"); ALTER TABLE t1 MODIFY a INT NULL; SET DEBUG_SYNC='innodb_inplace_alter_table_enter SIGNAL alter WAIT_FOR go'; diff --git a/mysql-test/suite/innodb_fts/r/misc_debug.result b/mysql-test/suite/innodb_fts/r/misc_debug.result index 9f13822ecda..e252d7f6b11 100644 --- a/mysql-test/suite/innodb_fts/r/misc_debug.result +++ b/mysql-test/suite/innodb_fts/r/misc_debug.result @@ -30,6 +30,7 @@ DROP TABLE t2, t1; # MDEV-25200 Index count mismatch due to aborted FULLTEXT INDEX # CREATE TABLE t1(a INT, b TEXT, c TEXT, FULLTEXT INDEX(b)) ENGINE=InnoDB; +INSERT INTO t1 VALUES(1, "test", "test_1"); connect con1,localhost,root,,test; SET DEBUG_DBUG="+d,innodb_OOM_inplace_alter"; SET DEBUG_SYNC='innodb_commit_inplace_alter_table_enter SIGNAL s2 WAIT_FOR g2'; @@ -39,6 +40,7 @@ SET DEBUG_SYNC='now WAIT_FOR s2'; START TRANSACTION; SELECT * FROM t1; a b c +1 test test_1 SET DEBUG_SYNC='now SIGNAL g2'; connection con1; ERROR HY000: Out of memory. diff --git a/mysql-test/suite/innodb_fts/t/misc_debug.test b/mysql-test/suite/innodb_fts/t/misc_debug.test index c8542152d4d..4a0edf4ef88 100644 --- a/mysql-test/suite/innodb_fts/t/misc_debug.test +++ b/mysql-test/suite/innodb_fts/t/misc_debug.test @@ -59,6 +59,7 @@ DROP TABLE t2, t1; --echo # MDEV-25200 Index count mismatch due to aborted FULLTEXT INDEX --echo # CREATE TABLE t1(a INT, b TEXT, c TEXT, FULLTEXT INDEX(b)) ENGINE=InnoDB; +INSERT INTO t1 VALUES(1, "test", "test_1"); connect(con1,localhost,root,,test); SET DEBUG_DBUG="+d,innodb_OOM_inplace_alter"; SET DEBUG_SYNC='innodb_commit_inplace_alter_table_enter SIGNAL s2 WAIT_FOR g2'; diff --git a/sql/handler.h b/sql/handler.h index 94ac56c3073..9b44b3fd297 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -2493,6 +2493,9 @@ public: /** true when InnoDB should abort the alter when table is not empty */ bool error_if_not_empty; + /** True when DDL should avoid downgrading the MDL */ + bool mdl_exclusive_after_prepare= false; + Alter_inplace_info(HA_CREATE_INFO *create_info_arg, Alter_info *alter_info_arg, KEY *key_info_arg, uint key_count_arg, diff --git a/sql/sql_table.cc b/sql/sql_table.cc index e46a13ce7a9..4409360cd8f 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7709,15 +7709,16 @@ static bool mysql_inplace_alter_table(THD *thd, lock for prepare phase under LOCK TABLES in the same way as when exclusive lock is required for duration of the whole statement. */ - if (inplace_supported == HA_ALTER_INPLACE_EXCLUSIVE_LOCK || - ((inplace_supported == HA_ALTER_INPLACE_COPY_NO_LOCK || + if (!ha_alter_info->mdl_exclusive_after_prepare && + (inplace_supported == HA_ALTER_INPLACE_EXCLUSIVE_LOCK || + ((inplace_supported == HA_ALTER_INPLACE_COPY_NO_LOCK || inplace_supported == HA_ALTER_INPLACE_COPY_LOCK || inplace_supported == HA_ALTER_INPLACE_NOCOPY_NO_LOCK || inplace_supported == HA_ALTER_INPLACE_NOCOPY_LOCK || inplace_supported == HA_ALTER_INPLACE_INSTANT) && (thd->locked_tables_mode == LTM_LOCK_TABLES || thd->locked_tables_mode == LTM_PRELOCKED_UNDER_LOCK_TABLES)) || - alter_info->requested_lock == Alter_info::ALTER_TABLE_LOCK_EXCLUSIVE) + alter_info->requested_lock == Alter_info::ALTER_TABLE_LOCK_EXCLUSIVE)) { if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN)) goto cleanup; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 7ee07f4160e..41871cedfe2 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -1949,10 +1949,15 @@ innobase_fts_check_doc_id_col( } /** Check whether the table is empty. -@param[in] table table to be checked +@param[in] table table to be checked +@param[in] ignore_delete_marked Ignore the delete marked + flag record @return true if table is empty */ -static bool innobase_table_is_empty(const dict_table_t *table) +static bool innobase_table_is_empty(const dict_table_t *table, + bool ignore_delete_marked=true) { + if (!table->space) + return false; dict_index_t *clust_index= dict_table_get_first_index(table); mtr_t mtr; btr_pcur_t pcur; @@ -1991,12 +1996,16 @@ next_page: } rec= page_cur_get_rec(cur); - if (rec_get_deleted_flag(rec, dict_table_is_comp(table))); - else if (!page_rec_is_supremum(rec)) + if (rec_get_deleted_flag(rec, dict_table_is_comp(table))) { + if (ignore_delete_marked) + goto scan_leaf; +non_empty: mtr.commit(); return false; } + else if (!page_rec_is_supremum(rec)) + goto non_empty; else { next_page= true; @@ -6853,6 +6862,7 @@ wrong_column_name: DBUG_ASSERT(num_fts_index <= 1); DBUG_ASSERT(!ctx->online || num_fts_index == 0); DBUG_ASSERT(!ctx->online + || !ha_alter_info->mdl_exclusive_after_prepare || ctx->add_autoinc == ULINT_UNDEFINED); DBUG_ASSERT(!ctx->online || !innobase_need_rebuild(ha_alter_info, old_table) @@ -7666,6 +7676,20 @@ ha_innobase::prepare_inplace_alter_table( DBUG_RETURN(false); } +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (table->part_info == NULL) { +#endif + /* Ignore the MDL downgrade when table is empty. + This optimization is disabled for partition table. */ + ha_alter_info->mdl_exclusive_after_prepare = + innobase_table_is_empty(m_prebuilt->table, false); + if (ha_alter_info->online + && ha_alter_info->mdl_exclusive_after_prepare) { + ha_alter_info->online = false; + } +#ifdef WITH_PARTITION_STORAGE_ENGINE + } +#endif indexed_table = m_prebuilt->table; /* ALTER TABLE will not implicitly move a table from a single-table @@ -8450,7 +8474,9 @@ ha_innobase::inplace_alter_table( DEBUG_SYNC(m_user_thd, "innodb_inplace_alter_table_enter"); - if (!(ha_alter_info->handler_flags & INNOBASE_ALTER_DATA)) { + /* Ignore the inplace alter phase when table is empty */ + if (!(ha_alter_info->handler_flags & INNOBASE_ALTER_DATA) + || ha_alter_info->mdl_exclusive_after_prepare) { ok_exit: DEBUG_SYNC(m_user_thd, "innodb_after_inplace_alter_table"); DBUG_RETURN(false); -- cgit v1.2.1