From 9d34939c6e9f8fe138717e66633809d0f2370f49 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Tue, 20 Feb 2024 11:20:21 +1100 Subject: [PATCH 01/25] MDEV-33494 fix spider init with no_zero_date global sql mode Like the fix for MDEV-32753 and MDEV-33242, spider init queries creates new connections that use the global sql_mode of the existing connection. --- .../mysql-test/spider/bugfix/r/mdev_33494.result | 4 ++++ .../spider/mysql-test/spider/bugfix/t/mdev_33494.test | 11 +++++++++++ storage/spider/spd_init_query.h | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result new file mode 100644 index 00000000000..3db28c0f08e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result @@ -0,0 +1,4 @@ +set @old_sql_mode=@@global.sql_mode; +set global sql_mode=(SELECT CONCAT (@@sql_mode,',no_zero_date')); +install soname 'ha_spider'; +set global sql_mode=@old_sql_mode; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test new file mode 100644 index 00000000000..30beca77f35 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test @@ -0,0 +1,11 @@ +# This test tests spider init with global no_zero_date sql mode +set @old_sql_mode=@@global.sql_mode; +set global sql_mode=(SELECT CONCAT (@@sql_mode,',no_zero_date')); +install soname 'ha_spider'; +set global sql_mode=@old_sql_mode; + +--disable_query_log +--disable_result_log +--source ../../include/clean_up_spider.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/spd_init_query.h b/storage/spider/spd_init_query.h index b8d1751a21b..c83bf56c4dd 100644 --- a/storage/spider/spd_init_query.h +++ b/storage/spider/spd_init_query.h @@ -21,7 +21,7 @@ static LEX_STRING spider_init_queries[] = { {C_STRING_WITH_LEN( - "SET @@SQL_MODE = REPLACE(@@SQL_MODE, 'ORACLE', '');" + "SET @@SQL_MODE = REGEXP_REPLACE(@@SQL_MODE, '(ORACLE|NO_ZERO_DATE)', '');" )}, {C_STRING_WITH_LEN( "create table if not exists mysql.spider_xa(" From db0b9ec37ba16bb17fc41a39522a7a1898df6902 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 27 Mar 2024 11:40:41 +1100 Subject: [PATCH 02/25] MDEV-33584 Use the default SQL_MODE for spider init queries This should fix all future problems caused by a non-default global sql_mode from the server where spider is to be installed. --- .../mysql-test/spider/bugfix/r/mdev_33584.result | 4 ++++ .../spider/mysql-test/spider/bugfix/t/mdev_33584.test | 11 +++++++++++ storage/spider/spd_init_query.h | 4 +++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result new file mode 100644 index 00000000000..796c75cc560 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result @@ -0,0 +1,4 @@ +set @old_sql_mode=@@global.sql_mode; +set global sql_mode='traditional'; +install soname 'ha_spider'; +set global sql_mode=@old_sql_mode; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test new file mode 100644 index 00000000000..886449716eb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test @@ -0,0 +1,11 @@ +# This test tests spider init with global no_zero_date sql mode +set @old_sql_mode=@@global.sql_mode; +set global sql_mode='traditional'; +install soname 'ha_spider'; +set global sql_mode=@old_sql_mode; + +--disable_query_log +--disable_result_log +--source ../../include/clean_up_spider.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/spd_init_query.h b/storage/spider/spd_init_query.h index c83bf56c4dd..1311384c7ce 100644 --- a/storage/spider/spd_init_query.h +++ b/storage/spider/spd_init_query.h @@ -20,8 +20,10 @@ */ static LEX_STRING spider_init_queries[] = { + /* Use the default SQL_MODE for this connection. */ {C_STRING_WITH_LEN( - "SET @@SQL_MODE = REGEXP_REPLACE(@@SQL_MODE, '(ORACLE|NO_ZERO_DATE)', '');" + "SET @@SQL_MODE = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO," + "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';" )}, {C_STRING_WITH_LEN( "create table if not exists mysql.spider_xa(" From c71dc395292f41685530c0fa92c5ce4d78eabfa0 Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Thu, 24 Nov 2022 14:47:18 +0100 Subject: [PATCH 03/25] MDEV-26499 Fix error "mysql_shutdown failed" during MTR tests - Fix to avoid mysqltest client getting killed abruptly during mysql_shutdown(). When Galera replication is shutdown, wait for THDs with `thd->stmt_da()->is_eof()` to disconnect (these are about to disconnect anyway). - Extract duplicate code from `wsrep_stop_replication()` and `wsrep_shutdown_replication()` in a new function. - No need to use a custom `shutdown_mysqld.inc` in galera suite. Delete it, so that the one in `mysql-test/include/` is used. Signed-off-by: Julius Goryavsky --- .../suite/galera/include/shutdown_mysqld.inc | 18 ----- mysql-test/suite/galera/r/MDEV-26499.result | 6 ++ mysql-test/suite/galera/t/MDEV-26499.test | 20 ++++++ sql/sql_parse.cc | 1 + sql/wsrep_mysqld.cc | 70 ++++++++++--------- 5 files changed, 64 insertions(+), 51 deletions(-) delete mode 100644 mysql-test/suite/galera/include/shutdown_mysqld.inc create mode 100644 mysql-test/suite/galera/r/MDEV-26499.result create mode 100644 mysql-test/suite/galera/t/MDEV-26499.test diff --git a/mysql-test/suite/galera/include/shutdown_mysqld.inc b/mysql-test/suite/galera/include/shutdown_mysqld.inc deleted file mode 100644 index 793be8d76ac..00000000000 --- a/mysql-test/suite/galera/include/shutdown_mysqld.inc +++ /dev/null @@ -1,18 +0,0 @@ -# This is the first half of include/restart_mysqld.inc. -if ($rpl_inited) -{ - if (!$allow_rpl_inited) - { - --die ERROR IN TEST: When using the replication test framework (master-slave.inc, rpl_init.inc etc), use rpl_restart_server.inc instead of restart_mysqld.inc. If you know what you are doing and you really have to use restart_mysqld.inc, set allow_rpl_inited=1 before you source restart_mysqld.inc - } -} - -# Write file to make mysql-test-run.pl expect the "crash", but don't start it ---let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect ---exec echo "wait" > $_expect_file_name - -# Send shutdown to the connected server ---shutdown_server ---source include/wait_until_disconnected.inc - diff --git a/mysql-test/suite/galera/r/MDEV-26499.result b/mysql-test/suite/galera/r/MDEV-26499.result new file mode 100644 index 00000000000..15d372470a4 --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-26499.result @@ -0,0 +1,6 @@ +connection node_2; +connection node_1; +connection node_1; +connection node_2; +connection node_2; +SET GLOBAL debug_dbug="+d,simulate_slow_client_at_shutdown"; diff --git a/mysql-test/suite/galera/t/MDEV-26499.test b/mysql-test/suite/galera/t/MDEV-26499.test new file mode 100644 index 00000000000..824b28c14f3 --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-26499.test @@ -0,0 +1,20 @@ +# +# MDEV-26499 +# +# This test reproduces some failure on mysql_shutdown() call +# which manifests sporadically in some galera MTR tests during +# restart of a node. +# + +--source include/galera_cluster.inc +--source include/have_debug_sync.inc + +--let $node_1=node_1 +--let $node_2=node_2 +--source include/auto_increment_offset_save.inc + +--connection node_2 +SET GLOBAL debug_dbug="+d,simulate_slow_client_at_shutdown"; +--source include/restart_mysqld.inc + +--source include/auto_increment_offset_restore.inc diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 4d52e515710..0fa793cea1a 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2208,6 +2208,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, my_eof(thd); kill_mysql(thd); error=TRUE; + DBUG_EXECUTE_IF("simulate_slow_client_at_shutdown", my_sleep(2000000);); break; } #endif diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 5ec96478e4a..2e5bf3f426e 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -1014,10 +1014,8 @@ void wsrep_recover() WSREP_INFO("Recovered position: %s", oss.str().c_str()); } - -void wsrep_stop_replication(THD *thd) +static void wsrep_stop_replication_common(THD *thd) { - WSREP_INFO("Stop replication by %llu", (thd) ? thd->thread_id : 0); if (Wsrep_server_state::instance().state() != Wsrep_server_state::s_disconnected) { @@ -1030,40 +1028,30 @@ void wsrep_stop_replication(THD *thd) } } - /* my connection, should not terminate with wsrep_close_client_connection(), - make transaction to rollback - */ - if (thd && !thd->wsrep_applier) trans_rollback(thd); + /* my connection, should not terminate with + wsrep_close_client_connections(), make transaction to rollback */ + if (thd && !thd->wsrep_applier) + trans_rollback(thd); wsrep_close_client_connections(TRUE, thd); - + /* wait until appliers have stopped */ wsrep_wait_appliers_close(thd); node_uuid= WSREP_UUID_UNDEFINED; } +void wsrep_stop_replication(THD *thd) +{ + WSREP_INFO("Stop replication by %llu", (thd) ? thd->thread_id : 0); + wsrep_stop_replication_common(thd); +} + void wsrep_shutdown_replication() { WSREP_INFO("Shutdown replication"); - if (Wsrep_server_state::instance().state() != wsrep::server_state::s_disconnected) - { - WSREP_DEBUG("Disconnect provider"); - Wsrep_server_state::instance().disconnect(); - if (Wsrep_server_state::instance().wait_until_state( - Wsrep_server_state::s_disconnected)) - { - WSREP_WARN("Wsrep interrupted while waiting for disconnected state"); - } - } - - wsrep_close_client_connections(TRUE); - - /* wait until appliers have stopped */ - wsrep_wait_appliers_close(NULL); - node_uuid= WSREP_UUID_UNDEFINED; - + wsrep_stop_replication_common(nullptr); /* Undocking the thread specific data. */ - my_pthread_setspecific_ptr(THR_THD, NULL); + my_pthread_setspecific_ptr(THR_THD, nullptr); } bool wsrep_start_replication(const char *wsrep_cluster_address) @@ -2644,14 +2632,19 @@ static my_bool have_client_connections(THD *thd, void*) { DBUG_PRINT("quit",("Informing thread %lld that it's time to die", (longlong) thd->thread_id)); - if (is_client_connection(thd) && thd->killed == KILL_CONNECTION) + if (is_client_connection(thd)) { - WSREP_DEBUG("Informing thread %lld that it's time to die", - thd->thread_id); - (void)abort_replicated(thd); - return true; + if (thd->killed == KILL_CONNECTION) + { + (void)abort_replicated(thd); + return true; + } + if (thd->get_stmt_da()->is_eof()) + { + return true; + } } - return 0; + return false; } static void wsrep_close_thread(THD *thd) @@ -2691,14 +2684,24 @@ static my_bool kill_all_threads(THD *thd, THD *caller_thd) /* We skip slave threads & scheduler on this first loop through. */ if (is_client_connection(thd) && thd != caller_thd) { + if (thd->get_stmt_da()->is_eof()) + { + return 0; + } + if (is_replaying_connection(thd)) + { thd->set_killed(KILL_CONNECTION); - else if (!abort_replicated(thd)) + return 0; + } + + if (!abort_replicated(thd)) { /* replicated transactions must be skipped */ WSREP_DEBUG("closing connection %lld", (longlong) thd->thread_id); /* instead of wsrep_close_thread() we do now soft kill by THD::awake */ thd->awake(KILL_CONNECTION); + return 0; } } return 0; @@ -2710,6 +2713,7 @@ static my_bool kill_remaining_threads(THD *thd, THD *caller_thd) if (is_client_connection(thd) && !abort_replicated(thd) && !is_replaying_connection(thd) && + !thd->get_stmt_da()->is_eof() && thd_is_connection_alive(thd) && thd != caller_thd) { From fa1ae367f174e6b9c9d6c0274d61a56c8dba13b3 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Wed, 27 Mar 2024 01:23:42 +0100 Subject: [PATCH 04/25] galera: wsrep-lib submodule update --- wsrep-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsrep-lib b/wsrep-lib index a5d95f0175f..dfc4bdb8a5d 160000 --- a/wsrep-lib +++ b/wsrep-lib @@ -1 +1 @@ -Subproject commit a5d95f0175f10b6127ea039c542725f6c4aa5cb9 +Subproject commit dfc4bdb8a5dcbd6fbea007ad3beff899a6b5b7bd From 0b627377a95d01c3f1dd1bfff52523bb48d5d5e7 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 13 Mar 2024 13:10:47 +1100 Subject: [PATCH 05/25] MDEV-33661 MENT-1591 Documenting spider_mon_table_cache and friends. Partial documentation due to time constraints. Will improve over time. Also removed a redundant parameter link_idx from spider_get_sys_tables_connect_info(). And deleted some commented out code. --- storage/spider/spd_copy_tables.cc | 2 +- storage/spider/spd_include.h | 1 + storage/spider/spd_ping_table.cc | 128 ++++++++++++++++++++---------- storage/spider/spd_sys_table.cc | 71 ++++++++++------- storage/spider/spd_sys_table.h | 3 +- storage/spider/spd_table.cc | 48 ++++------- 6 files changed, 150 insertions(+), 103 deletions(-) diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc index 34e3cb66712..d205cd244ca 100644 --- a/storage/spider/spd_copy_tables.cc +++ b/storage/spider/spd_copy_tables.cc @@ -307,7 +307,7 @@ int spider_udf_get_copy_tgt_tables( if ( (error_num = spider_get_sys_tables_connect_info( - table_tables, tmp_share, 0, mem_root)) || + table_tables, tmp_share, mem_root)) || (error_num = spider_get_sys_tables_link_status( table_tables, tmp_share, 0, mem_root)) || (error_num = spider_get_sys_tables_link_idx( diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 0e72ce26696..51fac2a4cea 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -1606,6 +1606,7 @@ typedef struct st_spider_table_mon st_spider_table_mon *next; } SPIDER_TABLE_MON; +/* List of `SPIDER_TABLE_MON's */ typedef struct st_spider_table_mon_list { char *key; diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc index 34d643d3555..92f5ff9e69f 100644 --- a/storage/spider/spd_ping_table.cc +++ b/storage/spider/spd_ping_table.cc @@ -54,6 +54,8 @@ extern PSI_mutex_key spd_key_mutex_mon_list_update_status; extern PSI_mutex_key spd_key_mutex_mon_table_cache; #endif +/* Array (of size `spider_udf_table_mon_mutex_count') of hashes of +`SPIDER_TABLE_MON_LIST'. */ HASH *spider_udf_table_mon_list_hash; uint spider_udf_table_mon_list_hash_id; const char *spider_udf_table_mon_list_hash_func_name; @@ -63,23 +65,43 @@ pthread_mutex_t *spider_udf_table_mon_mutexes; pthread_cond_t *spider_udf_table_mon_conds; pthread_mutex_t spider_mon_table_cache_mutex; +/* A cache to store distinct SPIDER_MON_KEYs with db name, table name +and link id read from mysql.spider_link_mon_servers table. Initialised +and populated in spider_init_ping_table_mon_cache(), and used in +spider_ping_table_cache_compare(). The udf +spider_flush_table_mon_cache is used to flag a initialisation. */ DYNAMIC_ARRAY spider_mon_table_cache; uint spider_mon_table_cache_id; const char *spider_mon_table_cache_func_name; const char *spider_mon_table_cache_file_name; ulong spider_mon_table_cache_line_no; +/* The mon table cache version, initialised at 0, and always no +greater than spider_mon_table_cache_version_req. When the inequality +is strict, an initialisation of spider_mon_table_cache will be +triggered. */ volatile ulonglong spider_mon_table_cache_version = 0; +/* The required mon table cache version, incremented by one by the +udf spider_flush_table_mon_cache */ volatile ulonglong spider_mon_table_cache_version_req = 1; + /* Get or create a `SPIDER_TABLE_MON_LIST' for a key `str' */ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( SPIDER_TRX *trx, THD *thd, - spider_string *str, + spider_string *str, /* The key to search in + `spider_udf_table_mon_list_hash', + usually in the format of + "./$db_name/$table_name000000000$link_idx" */ uint conv_name_length, int link_idx, char *static_link_id, uint static_link_id_length, - uint32 server_id, + uint32 server_id, /* The server id of the monitor + server, used for creating a new + table mon list having a + `SPIDER_TABLE_MON' corresponding to + the server id as the `current' + field */ bool need_lock, int *error_num ) { @@ -91,6 +113,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( my_hash_value_type hash_value; #endif DBUG_ENTER("spider_get_ping_table_mon_list"); + /* Reset the cache if the version does not match the requirement */ if (spider_mon_table_cache_version != spider_mon_table_cache_version_req) { SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); @@ -103,6 +126,9 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( free_root(&mem_root, MYF(0)); } + /* Search for the table mon list in the hash, if one is not found or + if it is found but has the wrong cache version, create and + initialise a new one. */ mutex_hash = spider_udf_calc_hash(str->c_ptr(), spider_param_udf_table_mon_mutex_count()); DBUG_PRINT("info",("spider hash key=%s", str->c_ptr())); @@ -129,12 +155,15 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( ) #endif { + /* If table_mon_list is found but the cache version does not + match, remove it from the hash and free it. */ if ( table_mon_list && table_mon_list->mon_table_cache_version != mon_table_cache_version ) spider_release_ping_table_mon_list_loop(mutex_hash, table_mon_list); - + /* create and initialise `table_mon_list' and insert it into the + hash */ if (!(table_mon_list = spider_get_ping_table_tgt(thd, str->c_ptr(), conv_name_length, link_idx, static_link_id, static_link_id_length, server_id, str, need_lock, error_num))) @@ -277,6 +306,14 @@ int spider_release_ping_table_mon_list( DBUG_RETURN(0); } +/* + Look for a `SPIDER_MON_KEY` in `spider_mon_table_cache' whose db and + table name and link_idx matching `name' and `link_idx' with wild + card matching. If a match is found, create `SPIDER_TABLE_MON's from + all rows in mysql.spider_link_mon_servers that match the info in the + `SPIDER_MON_KEY' and populate the `table_mon_list' with these + `SPIDER_TABLE_MON's. +*/ int spider_get_ping_table_mon( THD *thd, SPIDER_TABLE_MON_LIST *table_mon_list, @@ -357,6 +394,8 @@ int spider_get_ping_table_mon( goto error; create_table_mon: + /* Find the first row in mysql.spider_link_mon_servers matching the + db name, table name and link_idx */ if ((error_num = spider_get_sys_table_by_idx(table_link_mon, table_key, table_link_mon->s->primary_key, 3))) { @@ -364,6 +403,9 @@ create_table_mon: goto error; } + /* create one `SPIDER_TABLE_MON' per row in + mysql.spider_link_mon_servers with matching db name, table name and + link_idx, and add it to `table_mon_list'. */ do { if (!(table_mon = (SPIDER_TABLE_MON *) spider_bulk_malloc(spider_current_trx, SPD_MID_GET_PING_TABLE_MON_1, MYF(MY_WME | MY_ZEROFILL), @@ -394,7 +436,7 @@ create_table_mon: (error_num = spider_get_sys_link_mon_server_id( table_link_mon, &table_mon->server_id, mem_root)) || (error_num = spider_get_sys_link_mon_connect_info( - table_link_mon, tmp_share, 0, mem_root)) + table_link_mon, tmp_share, mem_root)) ) { table_link_mon->file->print_error(error_num, MYF(0)); spider_sys_index_end(table_link_mon); @@ -458,15 +500,21 @@ error: DBUG_RETURN(error_num); } +/* + creates and return table_mon_list associated with table with `name' + and `link_idx'th link. +*/ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( THD *thd, - char *name, + char *name, /* The table name, usually fully qualified */ uint name_length, int link_idx, char *static_link_id, uint static_link_id_length, - uint32 server_id, - spider_string *str, + uint32 server_id, /* The server_id will determine the + `current' field of the returned + `SPIDER_TABLE_MON_LIST'. */ + spider_string *str, /* str->c_ptr() == name */ bool need_lock, int *error_num ) { @@ -511,6 +559,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( memcpy(key_str, str->ptr(), table_mon_list->key_length); tmp_share->access_charset = thd->variables.character_set_client; + /* Open mysql.spider_tables */ if ( !(table_tables = spider_open_sys_table( thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, @@ -520,6 +569,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( my_error(*error_num, MYF(0)); goto error; } + /* store db and table names and link idx in mysql.spider_tables for + reading */ spider_store_tables_name(table_tables, name, name_length); if (static_link_id) { @@ -543,9 +594,10 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( goto error; } } + /* Populate tmp_share with info read from mysql.spider_tables */ if ( (*error_num = spider_get_sys_tables_connect_info( - table_tables, tmp_share, 0, &mem_root)) || + table_tables, tmp_share, &mem_root)) || (*error_num = spider_get_sys_tables_link_status( table_tables, tmp_share, 0, &mem_root)) ) { @@ -569,9 +621,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( tmp_share, name, name_length )) || (*error_num = spider_create_conn_keys(tmp_share)) || -/* - (*error_num = spider_db_create_table_names_str(tmp_share)) || -*/ + /* Pinally, populate `table_mon_list' with newly created + `SPIDER_TABLE_MON's */ (*error_num = spider_get_ping_table_mon( thd, table_mon_list, name, name_length, link_idx, server_id, &mem_root, need_lock)) @@ -836,6 +887,11 @@ error_open_table_tables: DBUG_RETURN(error_num); } +/* + Initialise `spider_mon_table_cache' by scanning the + mysql.spider_link_mon_servers table, creating distinct + `SPIDER_MON_KEY's with the info and inserting them into the cache. +*/ int spider_init_ping_table_mon_cache( THD *thd, MEM_ROOT *mem_root, @@ -867,6 +923,7 @@ int spider_init_ping_table_mon_cache( /* reset */ spider_mon_table_cache.elements = 0; + /* start at the first row */ if ((error_num = spider_sys_index_first(table_link_mon, table_link_mon->s->primary_key))) { @@ -883,10 +940,16 @@ int spider_init_ping_table_mon_cache( mon_key.table_name_length = SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE + 1; mon_key.link_id_length = SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE + 1; do { + /* update content of `mon_key' */ if ((error_num = spider_get_sys_link_mon_key(table_link_mon, &mon_key, mem_root, &same))) goto error_get_sys_link_mon_key; + /* `mon_key' has changed content. since + mysql.spider_link_mon_servers is indexed by db_name, + table_name, link_idx, and server_id, it is possible that + different server_ids share the same mon_key which only has + db_name, table_name, link_idx */ if (!same) { mon_key.sort = spider_calc_for_sort(3, mon_key.db_name, @@ -941,6 +1004,13 @@ error_open_sys_table: DBUG_RETURN(error_num); } +/* + Read from msyql.spider_link_mon_servers table fields the db name, + table name and link_id and search for them with wild card matching + in `spider_mon_table_cache'. store the db name, table name, and + link_id of the matching `SPIDER_MON_KEY' back to the table field on + success. +*/ int spider_ping_table_cache_compare( TABLE *table, MEM_ROOT *mem_root @@ -1239,9 +1309,6 @@ long long spider_ping_table_body( DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 2")); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1256,9 +1323,6 @@ long long spider_ping_table_body( conv_name.c_ptr(), conv_name_length, link_idx, TRUE); status_changed_to_ng = TRUE; } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (status_changed_to_ng) { @@ -1312,9 +1376,6 @@ long long spider_ping_table_body( DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 3")); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1329,9 +1390,6 @@ long long spider_ping_table_body( conv_name.c_ptr(), conv_name_length, link_idx, TRUE); status_changed_to_ng = TRUE; } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (status_changed_to_ng) { @@ -1375,9 +1433,6 @@ long long spider_ping_table_body( mon_table_result->result_status == SPIDER_LINK_MON_NG && table_mon_list->mon_status != SPIDER_LINK_MON_NG ) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1392,9 +1447,6 @@ long long spider_ping_table_body( conv_name.c_ptr(), conv_name_length, link_idx, TRUE); status_changed_to_ng = TRUE; } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (status_changed_to_ng) { @@ -1565,9 +1617,9 @@ int spider_ping_table_mon_from_table( SPIDER_SHARE *share, int base_link_idx, uint32 server_id, - char *conv_name, + char *conv_name, /* Usually fully qualified table name */ uint conv_name_length, - int link_idx, + int link_idx, /* The link id to ping */ char *where_clause, uint where_clause_length, long monitoring_kind, @@ -1577,9 +1629,6 @@ int spider_ping_table_mon_from_table( ) { int error_num = 0, current_mon_count, flags; uint32 first_sid; -/* - THD *thd = trx->thd; -*/ SPIDER_TABLE_MON_LIST *table_mon_list; SPIDER_TABLE_MON *table_mon; SPIDER_MON_TABLE_RESULT mon_table_result; @@ -1648,6 +1697,7 @@ int spider_ping_table_mon_from_table( if (monitoring_flag & 1) flags |= SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES; + /* Get or create `table_mon_list' for `conv_name_str'. */ if (!(table_mon_list = spider_get_ping_table_mon_list(trx, thd, &conv_name_str, conv_name_length, link_idx, share->static_link_ids[link_idx], @@ -1679,6 +1729,8 @@ int spider_ping_table_mon_from_table( table_mon = table_mon_list->current; first_sid = table_mon->server_id; current_mon_count = 1; + /* Call spider_ping_table on each table_mon of `table_mon_list', + until one succeeds */ while (TRUE) { DBUG_PRINT("info",("spider thd->killed=%s", @@ -1723,16 +1775,13 @@ int spider_ping_table_mon_from_table( if (!spider_db_udf_ping_table_mon_next( thd, table_mon, mon_conn, &mon_table_result, conv_name, conv_name_length, link_idx, - where_clause, where_clause_length, -1, table_mon_list->list_size, + where_clause, where_clause_length, /*first_sid=*/-1, table_mon_list->list_size, 0, 0, 0, flags, monitoring_limit)) { if ( mon_table_result.result_status == SPIDER_LINK_MON_NG && table_mon_list->mon_status != SPIDER_LINK_MON_NG ) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1747,9 +1796,6 @@ int spider_ping_table_mon_from_table( spider_sys_log_tables_link_failed(thd, conv_name, conv_name_length, link_idx, need_lock); } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); } table_mon_list->last_caller_result = mon_table_result.result_status; diff --git a/storage/spider/spd_sys_table.cc b/storage/spider/spd_sys_table.cc index f33a5373168..10f9fdedd5b 100644 --- a/storage/spider/spd_sys_table.cc +++ b/storage/spider/spd_sys_table.cc @@ -570,6 +570,11 @@ int spider_check_sys_table_for_update_all_columns( #endif } +/* + Creates a key (`table_key') consisting of `col_count' key parts of + `idx'th index of the table, then positions an index cursor to that + key. +*/ int spider_get_sys_table_by_idx( TABLE *table, char *table_key, @@ -602,17 +607,6 @@ int spider_get_sys_table_by_idx( key_length); if ( -/* -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 - (error_num = table->file->ha_index_read_idx_map( - table->record[0], idx, (uchar *) table_key, - make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#else - (error_num = table->file->index_read_idx_map( - table->record[0], idx, (uchar *) table_key, - make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#endif -*/ #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = table->file->ha_index_read_map( table->record[0], (uchar *) table_key, @@ -649,7 +643,7 @@ int spider_sys_index_next_same( int spider_sys_index_first( TABLE *table, - const int idx + const int idx /* which index to use */ ) { int error_num; DBUG_ENTER("spider_sys_index_first"); @@ -870,6 +864,10 @@ void spider_store_xa_member_info( DBUG_VOID_RETURN; } +/* + Store db and table names from `name' to `table's corresponding + fields +*/ void spider_store_tables_name( TABLE *table, const char *name, @@ -2064,14 +2062,16 @@ int spider_get_sys_tables( DBUG_RETURN(0); } +/* Read table info from mysql.spider_tables into a `SPIDER_SHARE' */ int spider_get_sys_tables_connect_info( - TABLE *table, - SPIDER_SHARE *share, - int link_idx, + TABLE *table, /* The mysql.spider_tables table */ + SPIDER_SHARE *share, /* The `SPIDER_SHARE' to + update info */ MEM_ROOT *mem_root ) { char *ptr; int error_num = 0; + const int link_idx= 0; DBUG_ENTER("spider_get_sys_tables_connect_info"); if ((ptr = get_field(mem_root, table->field[3]))) { @@ -2297,9 +2297,14 @@ int spider_get_sys_tables_monitoring_binlog_pos_at_failing( DBUG_RETURN(error_num); } +/* + Read the link status from mysql.spider_tables into a `SPIDER_SHARE' + with default value 1 (`SPIDER_LINK_STATUS_OK') +*/ int spider_get_sys_tables_link_status( - TABLE *table, - SPIDER_SHARE *share, + TABLE *table, /* The mysql.spider_tables table */ + SPIDER_SHARE *share, /* The share to read link + status into */ int link_idx, MEM_ROOT *mem_root ) { @@ -2484,11 +2489,17 @@ error: DBUG_RETURN(error_num); } +/* Populate `mon_key' from the current row in `table' */ int spider_get_sys_link_mon_key( - TABLE *table, - SPIDER_MON_KEY *mon_key, + TABLE *table, /* the mysql.spider_link_mon_servers + table */ + SPIDER_MON_KEY *mon_key, /* output, to be populated in this + function */ MEM_ROOT *mem_root, - int *same + int *same /* output, true if the data from the + current row in the table agrees with + existing data in `mon_key' and false + otherwise */ ) { char *db_name, *table_name, *link_id; uint db_name_length, table_name_length, link_id_length; @@ -2504,6 +2515,7 @@ int spider_get_sys_link_mon_key( DBUG_RETURN(ER_SPIDER_SYS_TABLE_VERSION_NUM); } + /* get data for `mon_key' from the table record */ if (!(db_name = get_field(mem_root, table->field[0]))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); if (!(table_name = get_field(mem_root, table->field[1]))) @@ -2549,9 +2561,12 @@ int spider_get_sys_link_mon_key( DBUG_RETURN(0); } +/* Get the server id from the spider_link_mon_servers table field */ int spider_get_sys_link_mon_server_id( - TABLE *table, - uint32 *server_id, + TABLE *table, /* the + mysql.spider_link_mon_servers + table */ + uint32 *server_id, /* output to server_id */ MEM_ROOT *mem_root ) { char *ptr; @@ -2564,14 +2579,17 @@ int spider_get_sys_link_mon_server_id( DBUG_RETURN(error_num); } +/* Get connect info from the spider_link_mon_servers table fields */ int spider_get_sys_link_mon_connect_info( - TABLE *table, - SPIDER_SHARE *share, - int link_idx, + TABLE *table, /* The + mysql.spider_link_mon_servers + table */ + SPIDER_SHARE *share, /* The output spider_share */ MEM_ROOT *mem_root ) { char *ptr; int error_num = 0; + const int link_idx= 0; DBUG_ENTER("spider_get_sys_link_mon_connect_info"); if ( !table->field[4]->is_null() && @@ -2753,9 +2771,6 @@ int spider_get_link_statuses( if ( (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE) ) { -/* - table->file->print_error(error_num, MYF(0)); -*/ DBUG_RETURN(error_num); } } else if ((error_num = diff --git a/storage/spider/spd_sys_table.h b/storage/spider/spd_sys_table.h index 53ef3b82465..fca38c67683 100644 --- a/storage/spider/spd_sys_table.h +++ b/storage/spider/spd_sys_table.h @@ -56,6 +56,7 @@ #define SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE 64 #define SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE 64 +/* For insertion into `spider_mon_table_cache'. */ class SPIDER_MON_KEY: public SPIDER_SORT { public: @@ -425,7 +426,6 @@ int spider_get_sys_tables( int spider_get_sys_tables_connect_info( TABLE *table, SPIDER_SHARE *share, - int link_idx, MEM_ROOT *mem_root ); @@ -502,7 +502,6 @@ int spider_get_sys_link_mon_server_id( int spider_get_sys_link_mon_connect_info( TABLE *table, SPIDER_SHARE *share, - int link_idx, MEM_ROOT *mem_root ); diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index fae239c57db..610fbeda1f3 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -3421,13 +3421,15 @@ error_alloc_conn_string: DBUG_RETURN(error_num); } +/* Set default connect info of a SPIDER_SHARE if needed */ int spider_set_connect_info_default( - SPIDER_SHARE *share, + SPIDER_SHARE *share, /* The `SPIDER_SHARE' to set + default connect info */ #ifdef WITH_PARTITION_STORAGE_ENGINE - partition_element *part_elem, - partition_element *sub_elem, + partition_element *part_elem, /* partition info used as input */ + partition_element *sub_elem, /* subpartition info used as input */ #endif - TABLE_SHARE *table_share + TABLE_SHARE *table_share /* table share info used as input */ ) { int error_num, roop_count; DBUG_ENTER("spider_set_connect_info_default"); @@ -3558,22 +3560,6 @@ int spider_set_connect_info_default( } } -/* - if (!share->static_link_ids[roop_count]) - { - DBUG_PRINT("info",("spider create default static_link_ids")); - share->static_link_ids_lengths[roop_count] = - SPIDER_DB_STATIC_LINK_ID_LEN; - if ( - !(share->static_link_ids[roop_count] = spider_create_string( - SPIDER_DB_STATIC_LINK_ID_STR, - share->static_link_ids_lengths[roop_count])) - ) { - DBUG_RETURN(HA_ERR_OUT_OF_MEM); - } - } -*/ - if (share->tgt_ports[roop_count] == -1) { share->tgt_ports[roop_count] = MYSQL_PORT; @@ -3705,6 +3691,11 @@ int spider_set_connect_info_default( DBUG_RETURN(0); } +/* + This function is a no-op if all share->tgt_dbs and + share->tgt_table_names are non-null, otherwise it may assign them + with db_name and table_name +*/ int spider_set_connect_info_default_db_table( SPIDER_SHARE *share, const char *db_name, @@ -3748,6 +3739,11 @@ int spider_set_connect_info_default_db_table( DBUG_RETURN(0); } +/* + Parse `dbtable_name' into db name and table name, and call + spider_set_connect_info_default_db_table() to set the db/table name + values of `share' if needed +*/ int spider_set_connect_info_default_dbtable( SPIDER_SHARE *share, const char *dbtable_name, @@ -6062,7 +6058,7 @@ int spider_open_all_tables( (error_num = spider_get_sys_tables( table_tables, &db_name, &table_name, &mem_root)) || (error_num = spider_get_sys_tables_connect_info( - table_tables, &tmp_share, 0, &mem_root)) || + table_tables, &tmp_share, &mem_root)) || (error_num = spider_set_connect_info_default( &tmp_share, #ifdef WITH_PARTITION_STORAGE_ENGINE @@ -6676,16 +6672,6 @@ int spider_db_init( #ifdef HTON_CAN_READ_CONNECT_STRING_IN_PARTITION spider_hton->flags |= HTON_CAN_READ_CONNECT_STRING_IN_PARTITION; #endif - /* spider_hton->db_type = DB_TYPE_SPIDER; */ - /* - spider_hton->savepoint_offset; - spider_hton->savepoint_set = spider_savepoint_set; - spider_hton->savepoint_rollback = spider_savepoint_rollback; - spider_hton->savepoint_release = spider_savepoint_release; - spider_hton->create_cursor_read_view = spider_create_cursor_read_view; - spider_hton->set_cursor_read_view = spider_set_cursor_read_view; - spider_hton->close_cursor_read_view = spider_close_cursor_read_view; - */ spider_hton->panic = spider_panic; spider_hton->close_connection = spider_close_connection; spider_hton->start_consistent_snapshot = spider_start_consistent_snapshot; From e6d12bb45947fd9358e0925c9a513ca66c705686 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 13 Mar 2024 13:11:07 +1100 Subject: [PATCH 06/25] MDEV-33661 MENT-1591 Fix spider/bugfix.mdev_28856 because of MDEV-29718. The failure should be table not found, rather than no spider same server link --- storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result | 3 +++ storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result index 7e4fd3cd084..5fd412b69ea 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result @@ -5,6 +5,8 @@ for master_1 for child2 for child3 set spider_same_server_link=1; +set @old_spider_same_server_link=@@global.spider_same_server_link; +set global spider_same_server_link=1; CREATE SERVER srv FOREIGN DATA WRAPPER mysql OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); # testing monitoring_* @@ -173,6 +175,7 @@ max(d) 93 drop table t1, t2; drop server srv; +set global spider_same_server_link=@old_spider_same_server_link; for master_1 for child2 for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test index a1642f7a9cd..9ccfc3784ef 100644 --- a/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test @@ -10,6 +10,9 @@ # This test covers some table params under consideration for inclusion # in the engine-defined options to be implemented in MDEV-28856. set spider_same_server_link=1; +set @old_spider_same_server_link=@@global.spider_same_server_link; +set global spider_same_server_link=1; + evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); @@ -153,6 +156,7 @@ select max(d) from t1; drop table t1, t2; drop server srv; +set global spider_same_server_link=@old_spider_same_server_link; --disable_query_log --disable_result_log From c81139357a4bb5bb1c774fa6d813166ef32e3735 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Thu, 28 Mar 2024 11:48:32 +0700 Subject: [PATCH 07/25] MDEV-14959: the follow-up patch to turn on the option -DWITH_PROTECT_STATEMENT_MEMROOT by default --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9605d786c93..6f668139b50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,9 +197,10 @@ OPTION(NOT_FOR_DISTRIBUTION "Allow linking with GPLv2-incompatible system librar # Enable protection of statement's memory root after first SP/PS execution. # Can be switched on only for debug build. # -OPTION(WITH_PROTECT_STATEMENT_MEMROOT "Enable protection of statement's memory root after first SP/PS execution. Turned into account only for debug build" OFF) -IF (CMAKE_BUILD_TYPE MATCHES "Debug" AND WITH_PROTECT_STATEMENT_MEMROOT) - ADD_DEFINITIONS(-DPROTECT_STATEMENT_MEMROOT) +OPTION(WITH_PROTECT_STATEMENT_MEMROOT "Enable protection of statement's memory root after first SP/PS execution. Turned into account only for debug build" ON) +IF (WITH_PROTECT_STATEMENT_MEMROOT) + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DPROTECT_STATEMENT_MEMROOT") + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DPROTECT_STATEMENT_MEMROOT") ENDIF() INCLUDE(check_compiler_flag) From a618ff2b1c3980d20d258d7da0afb1e7b7ec1516 Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Wed, 10 Jan 2024 14:34:12 +0100 Subject: [PATCH 08/25] MDEV-33216 stack-use-after-return in Wsrep_schema_impl::open_table() Fix a case of stack-use-after-return reported by ASAN in Wsrep_schema_impl::open_table(). This function has a stack allocated TABLE_LIST object and return TABLE_LIST::table to the caller. Changed the function to take a TABLE_LIST pointer as argument. Signed-off-by: Julius Goryavsky --- sql/wsrep_schema.cc | 143 +++++++++++++++++++++++++++----------------- 1 file changed, 89 insertions(+), 54 deletions(-) diff --git a/sql/wsrep_schema.cc b/sql/wsrep_schema.cc index 1c4f827ae97..6d435a3a1b5 100644 --- a/sql/wsrep_schema.cc +++ b/sql/wsrep_schema.cc @@ -245,58 +245,51 @@ static void finish_stmt(THD* thd) { close_thread_tables(thd); } -static int open_table(THD* thd, - const LEX_CSTRING *schema_name, - const LEX_CSTRING *table_name, - enum thr_lock_type const lock_type, - TABLE** table) { - assert(table); - *table= NULL; - +static int open_table(THD *thd, const LEX_CSTRING *schema_name, + const LEX_CSTRING *table_name, + enum thr_lock_type const lock_type, + TABLE_LIST *table_list) +{ + assert(table_list); DBUG_ENTER("Wsrep_schema::open_table()"); - - TABLE_LIST tables; - uint flags= (MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | - MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | - MYSQL_OPEN_IGNORE_FLUSH | - MYSQL_LOCK_IGNORE_TIMEOUT); - - tables.init_one_table(schema_name, - table_name, - NULL, lock_type); + const uint flags= (MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | + MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | + MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT); + table_list->init_one_table(schema_name, table_name, NULL, lock_type); thd->lex->query_tables_own_last= 0; - - if (!open_n_lock_single_table(thd, &tables, tables.lock_type, flags)) { + if (!open_n_lock_single_table(thd, table_list, table_list->lock_type, flags)) + { close_thread_tables(thd); DBUG_RETURN(1); } - *table= tables.table; - (*table)->use_all_columns(); + table_list->table->use_all_columns(); DBUG_RETURN(0); } - -static int open_for_write(THD* thd, const char* table_name, TABLE** table) { +static int open_for_write(THD* thd, const char* table_name, TABLE_LIST* table_list) +{ LEX_CSTRING schema_str= { wsrep_schema_str.c_str(), wsrep_schema_str.length() }; LEX_CSTRING table_str= { table_name, strlen(table_name) }; if (Wsrep_schema_impl::open_table(thd, &schema_str, &table_str, TL_WRITE, - table)) { + table_list)) + { // No need to log an error if the query was bf aborted, // thd client will get ER_LOCK_DEADLOCK in the end. const bool interrupted= thd->killed || (thd->is_error() && (thd->get_stmt_da()->sql_errno() == ER_QUERY_INTERRUPTED)); - if (!interrupted) { + if (!interrupted) + { WSREP_ERROR("Failed to open table %s.%s for writing", schema_str.str, table_name); } return 1; } - empty_record(*table); - (*table)->use_all_columns(); - restore_record(*table, s->default_values); + empty_record(table_list->table); + table_list->table->use_all_columns(); + restore_record(table_list->table, s->default_values); return 0; } @@ -438,19 +431,21 @@ static int delete_row(TABLE* table) { return 0; } -static int open_for_read(THD* thd, const char* table_name, TABLE** table) { - +static int open_for_read(THD *thd, const char *table_name, + TABLE_LIST *table_list) +{ LEX_CSTRING schema_str= { wsrep_schema_str.c_str(), wsrep_schema_str.length() }; LEX_CSTRING table_str= { table_name, strlen(table_name) }; if (Wsrep_schema_impl::open_table(thd, &schema_str, &table_str, TL_READ, - table)) { + table_list)) + { WSREP_ERROR("Failed to open table %s.%s for reading", schema_str.str, table_name); return 1; } - empty_record(*table); - (*table)->use_all_columns(); - restore_record(*table, s->default_values); + empty_record(table_list->table); + table_list->table->use_all_columns(); + restore_record(table_list->table, s->default_values); return 0; } @@ -706,8 +701,10 @@ int Wsrep_schema::store_view(THD* thd, const Wsrep_view& view) assert(view.status() == Wsrep_view::primary); int ret= 1; int error; + TABLE_LIST cluster_table_l; TABLE* cluster_table= 0; - TABLE* members_table= 0; + TABLE_LIST members_table_l; + TABLE* members_table = 0; #ifdef WSREP_SCHEMA_MEMBERS_HISTORY TABLE* members_history_table= 0; #endif /* WSREP_SCHEMA_MEMBERS_HISTORY */ @@ -732,11 +729,13 @@ int Wsrep_schema::store_view(THD* thd, const Wsrep_view& view) Store cluster view info */ Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_write(thd, cluster_table_str.c_str(), &cluster_table)) + if (Wsrep_schema_impl::open_for_write(thd, cluster_table_str.c_str(), &cluster_table_l)) { goto out; } + cluster_table= cluster_table_l.table; + Wsrep_schema_impl::store(cluster_table, 0, view.state_id().id()); Wsrep_schema_impl::store(cluster_table, 1, view.view_seqno().get()); Wsrep_schema_impl::store(cluster_table, 2, view.state_id().seqno().get()); @@ -756,12 +755,14 @@ int Wsrep_schema::store_view(THD* thd, const Wsrep_view& view) */ Wsrep_schema_impl::init_stmt(thd); if (Wsrep_schema_impl::open_for_write(thd, members_table_str.c_str(), - &members_table)) + &members_table_l)) { WSREP_ERROR("failed to open wsrep.members table"); goto out; } + members_table= members_table_l.table; + for (size_t i= 0; i < view.members().size(); ++i) { Wsrep_schema_impl::store(members_table, 0, view.members()[i].id()); @@ -815,8 +816,10 @@ Wsrep_view Wsrep_schema::restore_view(THD* thd, const Wsrep_id& own_id) const { int ret= 1; int error; + TABLE_LIST cluster_table_l; TABLE* cluster_table= 0; bool end_cluster_scan= false; + TABLE_LIST members_table_l; TABLE* members_table= 0; bool end_members_scan= false; @@ -842,8 +845,12 @@ Wsrep_view Wsrep_schema::restore_view(THD* thd, const Wsrep_id& own_id) const { Read cluster info from cluster table */ Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_read(thd, cluster_table_str.c_str(), &cluster_table) || - Wsrep_schema_impl::init_for_scan(cluster_table)) { + if (Wsrep_schema_impl::open_for_read(thd, cluster_table_str.c_str(), &cluster_table_l)) { + goto out; + } + cluster_table = cluster_table_l.table; + + if (Wsrep_schema_impl::init_for_scan(cluster_table)) { goto out; } @@ -867,8 +874,14 @@ Wsrep_view Wsrep_schema::restore_view(THD* thd, const Wsrep_id& own_id) const { Read members from members table */ Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_read(thd, members_table_str.c_str(), &members_table) || - Wsrep_schema_impl::init_for_scan(members_table)) { + if (Wsrep_schema_impl::open_for_read(thd, members_table_str.c_str(), + &members_table_l)) + { + goto out; + } + + members_table= members_table_l.table; + if (Wsrep_schema_impl::init_for_scan(members_table)) { goto out; } end_members_scan= true; @@ -972,14 +985,15 @@ int Wsrep_schema::append_fragment(THD* thd, Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd); Wsrep_schema_impl::init_stmt(thd); - TABLE* frag_table= 0; - if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table)) + TABLE_LIST frag_table_l; + if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table_l)) { trans_rollback_stmt(thd); thd->lex->restore_backup_query_tables_list(&query_tables_list_backup); DBUG_RETURN(1); } + TABLE* frag_table= frag_table_l.table; Wsrep_schema_impl::store(frag_table, 0, server_id); Wsrep_schema_impl::store(frag_table, 1, transaction_id.get()); Wsrep_schema_impl::store(frag_table, 2, seqno.get()); @@ -1023,13 +1037,15 @@ int Wsrep_schema::update_fragment_meta(THD* thd, uchar *key=NULL; key_part_map key_map= 0; TABLE* frag_table= 0; + TABLE_LIST frag_table_l; Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table)) + if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table_l)) { thd->lex->restore_backup_query_tables_list(&query_tables_list_backup); DBUG_RETURN(1); } + frag_table= frag_table_l.table; /* Find record with the given uuid, trx id, and seqno -1 */ Wsrep_schema_impl::store(frag_table, 0, ws_meta.server_id()); @@ -1152,12 +1168,14 @@ int Wsrep_schema::remove_fragments(THD* thd, thd->reset_n_backup_open_tables_state(&open_tables_backup); TABLE* frag_table= 0; - if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table)) + TABLE_LIST frag_table_l; + if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table_l)) { ret= 1; } else { + frag_table= frag_table_l.table; for (std::vector::const_iterator i= fragments.begin(); i != fragments.end(); ++i) { @@ -1218,6 +1236,7 @@ int Wsrep_schema::replay_transaction(THD* orig_thd, int ret= 1; int error; TABLE* frag_table= 0; + TABLE_LIST frag_table_l; uchar *key=NULL; key_part_map key_map= 0; @@ -1225,12 +1244,13 @@ int Wsrep_schema::replay_transaction(THD* orig_thd, i != fragments.end(); ++i) { Wsrep_schema_impl::init_stmt(&thd); - if ((error= Wsrep_schema_impl::open_for_read(&thd, sr_table_str.c_str(), &frag_table))) + if ((error= Wsrep_schema_impl::open_for_read(&thd, sr_table_str.c_str(), &frag_table_l))) { WSREP_WARN("Could not open SR table for read: %d", error); Wsrep_schema_impl::finish_stmt(&thd); DBUG_RETURN(1); } + frag_table= frag_table_l.table; Wsrep_schema_impl::store(frag_table, 0, ws_meta.server_id()); Wsrep_schema_impl::store(frag_table, 1, ws_meta.transaction_id().get()); @@ -1276,12 +1296,13 @@ int Wsrep_schema::replay_transaction(THD* orig_thd, if ((error= Wsrep_schema_impl::open_for_write(&thd, sr_table_str.c_str(), - &frag_table))) + &frag_table_l))) { WSREP_WARN("Could not open SR table for write: %d", error); Wsrep_schema_impl::finish_stmt(&thd); DBUG_RETURN(1); } + frag_table= frag_table_l.table; error= Wsrep_schema_impl::init_for_index_scan(frag_table, key, @@ -1323,7 +1344,9 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd) (char*) &storage_thd); wsrep_assign_from_threadvars(&storage_thd); TABLE* frag_table= 0; + TABLE_LIST frag_table_l; TABLE* cluster_table= 0; + TABLE_LIST cluster_table_l; Wsrep_storage_service storage_service(&storage_thd); Wsrep_schema_impl::binlog_off binlog_off(&storage_thd); Wsrep_schema_impl::wsrep_off wsrep_off(&storage_thd); @@ -1338,10 +1361,15 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd) Wsrep_schema_impl::init_stmt(&storage_thd); storage_thd.wsrep_skip_locking= FALSE; - if (Wsrep_schema_impl::open_for_read(&storage_thd, - cluster_table_str.c_str(), - &cluster_table) || - Wsrep_schema_impl::init_for_scan(cluster_table)) + if (Wsrep_schema_impl::open_for_read(&storage_thd, cluster_table_str.c_str(), + &cluster_table_l)) + { + Wsrep_schema_impl::finish_stmt(&storage_thd); + DBUG_RETURN(1); + } + cluster_table= cluster_table_l.table; + + if (Wsrep_schema_impl::init_for_scan(cluster_table)) { Wsrep_schema_impl::finish_stmt(&storage_thd); DBUG_RETURN(1); @@ -1379,12 +1407,19 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd) Open the table for reading and writing so that fragments without valid seqno can be deleted. */ - if (Wsrep_schema_impl::open_for_write(&storage_thd, sr_table_str.c_str(), &frag_table) || - Wsrep_schema_impl::init_for_scan(frag_table)) + if (Wsrep_schema_impl::open_for_write(&storage_thd, sr_table_str.c_str(), + &frag_table_l)) { WSREP_ERROR("Failed to open SR table for write"); goto out; } + frag_table= frag_table_l.table; + + if (Wsrep_schema_impl::init_for_scan(frag_table)) + { + WSREP_ERROR("Failed to init for index scan"); + goto out; + } while (true) { From 8cc36fb7434114fce06725cc607c2f7c65ac3ac7 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Wed, 20 Mar 2024 13:09:12 +0300 Subject: [PATCH 09/25] MDEV-21102: Server crashes in JOIN_CACHE::write_record_data upon EXPLAIN with subqueries JOIN_CACHE has a light-weight initialization mode that's targeted at EXPLAINs. In that mode, JOIN_CACHE objects are not able to execute. Light-weight mode was used whenever the statement was an EXPLAIN. However the EXPLAIN can execute subqueries, provided they enumerate less than @@expensive_subquery_limit rows. Make sure we use light-weight initialization mode only when the select is more expensive @@expensive_subquery_limit. Also add an assert into JOIN_CACHE::put_record() which prevents its use if it was initialized for EXPLAIN only. --- mysql-test/main/join_cache.result | 22 ++++++++++++++++++++++ mysql-test/main/join_cache.test | 21 +++++++++++++++++++++ sql/item_subselect.cc | 2 ++ sql/sql_join_cache.cc | 1 + sql/sql_select.cc | 23 ++++++++++++++++++++++- 5 files changed, 68 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/join_cache.result b/mysql-test/main/join_cache.result index c07a8b1bf6b..49f3b0910fa 100644 --- a/mysql-test/main/join_cache.result +++ b/mysql-test/main/join_cache.result @@ -6396,5 +6396,27 @@ b b d c c 10 NULL NULL NULL NULL DROP TABLE t1,t2,t3,t4; # +# MDEV-21102: Server crashes in JOIN_CACHE::write_record_data upon EXPLAIN with subqueries and constant tables +# +CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; +CREATE TABLE t2 (c int, d int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,10); +CREATE TABLE t3 (e int, key (e)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (2),(3); +# Must not crash, must use join buffer in subquery +EXPLAIN +SELECT * FROM t1 +WHERE a > b OR a IN ( +SELECT c FROM t2 WHERE EXISTS ( +SELECT * FROM t3 t3a JOIN t3 t3b WHERE t3a.e < d +) +); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 +3 SUBQUERY t3a index e e 5 NULL 2 Using where; Using index +3 SUBQUERY t3b index NULL e 5 NULL 2 Using index; Using join buffer (flat, BNL join) +DROP TABLE t1,t2,t3; +# # End of 10.4 tests # diff --git a/mysql-test/main/join_cache.test b/mysql-test/main/join_cache.test index 868fc3f7e8a..8d341c9e0fc 100644 --- a/mysql-test/main/join_cache.test +++ b/mysql-test/main/join_cache.test @@ -4305,6 +4305,27 @@ eval $q2; DROP TABLE t1,t2,t3,t4; +--echo # +--echo # MDEV-21102: Server crashes in JOIN_CACHE::write_record_data upon EXPLAIN with subqueries and constant tables +--echo # +CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; + +CREATE TABLE t2 (c int, d int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,10); + +CREATE TABLE t3 (e int, key (e)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (2),(3); + +--echo # Must not crash, must use join buffer in subquery +EXPLAIN +SELECT * FROM t1 +WHERE a > b OR a IN ( + SELECT c FROM t2 WHERE EXISTS ( + SELECT * FROM t3 t3a JOIN t3 t3b WHERE t3a.e < d + ) +); +DROP TABLE t1,t2,t3; + --echo # --echo # End of 10.4 tests --echo # diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index a8824adbdd8..d39c85e6f76 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -562,6 +562,8 @@ void Item_subselect::recalc_used_tables(st_select_lex *new_parent, This measure is used instead of JOIN::read_time, because it is considered to be much more reliable than the cost estimate. + Note: the logic in this function must agree with JOIN::init_join_caches(). + @return true if the subquery is expensive @return false otherwise */ diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 41d7dd89f55..c33c2f029cd 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -1589,6 +1589,7 @@ bool JOIN_CACHE::put_record() { bool is_full; uchar *link= 0; + DBUG_ASSERT(!for_explain_only); if (prev_cache) link= prev_cache->get_curr_rec_link(); write_record_data(link, &is_full); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 9e8b8e4ebe0..efcd42be074 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1876,6 +1876,26 @@ JOIN::init_range_rowid_filters() int JOIN::init_join_caches() { + bool init_for_explain= false; + + /* + Can we use lightweight initalization mode just for EXPLAINs? We can if + we're certain that the optimizer will not execute the subquery. + The optimzier will not execute the subquery if it's too expensive. For + the exact criteria, see Item_subselect::is_expensive(). + Note that the subquery might be a UNION and we might not yet know if it is + expensive. + What we do know is that if this SELECT is too expensive, then the whole + subquery will be too expensive as well. + So, we can use lightweight initialization (init_for_explain=true) if this + SELECT examines more than @@expensive_subquery_limit rows. + */ + if ((select_options & SELECT_DESCRIBE) && + get_examined_rows() >= thd->variables.expensive_subquery_limit) + { + init_for_explain= true; + } + JOIN_TAB *tab; for (tab= first_linear_tab(this, WITH_BUSH_ROOTS, WITHOUT_CONST_TABLES); @@ -1895,7 +1915,8 @@ int JOIN::init_join_caches() { table->prepare_for_keyread(tab->index, table->read_set); } - if (tab->cache && tab->cache->init(select_options & SELECT_DESCRIBE)) + + if (tab->cache && tab->cache->init(init_for_explain)) revise_cache_usage(tab); else tab->remove_redundant_bnl_scan_conds(); From 9b5d711ac384e4f3ce397746aa1711cdf284b9ab Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Fri, 5 Apr 2024 16:09:56 +0530 Subject: [PATCH 10/25] MDEV-20094 InnoDB blob allocation allocates extra extents - InnoDB reserves the free extents unnecessarily during blob page allocation even though btr_page_alloc() can handle reserving the extent when the existing ran out of pages to be used. --- .../innodb/r/check_ibd_filesize,32k.rdiff | 6 +++--- .../innodb/r/check_ibd_filesize,4k.rdiff | 6 +++--- .../innodb/r/check_ibd_filesize,64k.rdiff | 6 +++--- .../innodb/r/check_ibd_filesize,8k.rdiff | 6 +++--- .../suite/innodb/r/check_ibd_filesize.result | 2 +- storage/innobase/btr/btr0cur.cc | 20 ++++++++----------- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff index 44446602b9f..ad1f3a447c2 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:29:25.129637040 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,12 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -14,7 +14,7 @@ -# bytes: 65536 +# bytes: 131072 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; --# bytes: 4194304 +-# bytes: 2097152 -DROP TABLE t1; -CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) -ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff index ef55ad971fe..1412df393ff 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:31:39.288769153 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,18 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -13,7 +13,7 @@ -# bytes: 65536 +# bytes: 16384 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; - # bytes: 4194304 + # bytes: 2097152 DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff index bcdcea31160..156925597ab 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:30:28.957174270 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,12 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -14,7 +14,7 @@ -# bytes: 65536 +# bytes: 262144 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; --# bytes: 4194304 +-# bytes: 2097152 -DROP TABLE t1; -CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) -ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff index 7b699ef4cea..55cf59737d3 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:31:03.516962339 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,18 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -13,7 +13,7 @@ -# bytes: 65536 +# bytes: 32768 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; - # bytes: 4194304 + # bytes: 2097152 DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize.result b/mysql-test/suite/innodb/r/check_ibd_filesize.result index 0d224d6ac5f..b0f376183ea 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize.result +++ b/mysql-test/suite/innodb/r/check_ibd_filesize.result @@ -10,7 +10,7 @@ DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB; # bytes: 65536 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; -# bytes: 4194304 +# bytes: 2097152 DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 38bbf2d1bc1..bd88582d4f4 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -7684,7 +7684,6 @@ btr_store_big_rec_extern_fields( buf_block_t* block; page_t* page; const ulint commit_freq = 4; - ulint r_extents; ut_ad(page_align(field_ref) == page_align(rec)); @@ -7723,20 +7722,17 @@ btr_store_big_rec_extern_fields( alloc_mtr = &mtr; } - if (!fsp_reserve_free_extents(&r_extents, - index->table->space, 1, - FSP_BLOB, alloc_mtr, - 1)) { - - alloc_mtr->commit(); - error = DB_OUT_OF_FILE_SPACE; - goto func_exit; - } - block = btr_page_alloc(index, hint_page_no, FSP_NO_DIR, 0, alloc_mtr, &mtr); - index->table->space->release_free_extents(r_extents); + if (!block) { + error = DB_OUT_OF_FILE_SPACE; + alloc_mtr->commit(); + if (op == BTR_STORE_INSERT_BULK) { + mtr.commit(); + } + goto func_exit; + } if (UNIV_UNLIKELY(op == BTR_STORE_INSERT_BULK)) { mtr_bulk.commit(); From 504925c416e50e78275ae75a7c8ffdb4255b1ab1 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 19 Feb 2024 15:12:16 +1100 Subject: [PATCH 11/25] MDEV-33434 spider direct sql: Check length before memcpy similar to MDEV-30981 --- .../spider/bugfix/r/mdev_33434.result | 12 ++ .../spider/bugfix/t/mdev_33434.test | 15 +++ storage/spider/spd_direct_sql.cc | 115 +++++++----------- 3 files changed, 74 insertions(+), 68 deletions(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result new file mode 100644 index 00000000000..2cbcff38752 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result @@ -0,0 +1,12 @@ +# +# MDEV-33434 MDEV-33434 UBSAN null pointer passed as argument 2, which is declared to never be null in spider_udf_direct_sql_create_conn +# +INSTALL SONAME 'ha_spider'; +SET character_set_connection=ucs2; +SELECT SPIDER_DIRECT_SQL('SELECT SLEEP(1)', '', 'srv "dummy", port "3307"'); +ERROR HY000: Unable to connect to foreign data source: localhost +Warnings: +Warning 1620 Plugin is busy and will be uninstalled on shutdown +# +# end of test mdev_33434 +# diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test new file mode 100644 index 00000000000..dd9f882f42e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test @@ -0,0 +1,15 @@ +--echo # +--echo # MDEV-33434 MDEV-33434 UBSAN null pointer passed as argument 2, which is declared to never be null in spider_udf_direct_sql_create_conn +--echo # + +INSTALL SONAME 'ha_spider'; +SET character_set_connection=ucs2; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +SELECT SPIDER_DIRECT_SQL('SELECT SLEEP(1)', '', 'srv "dummy", port "3307"'); +--disable_query_log +--source ../../include/clean_up_spider.inc +--enable_query_log + +--echo # +--echo # end of test mdev_33434 +--echo # diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc index 6639fcee79c..c0c37581865 100644 --- a/storage/spider/spd_direct_sql.cc +++ b/storage/spider/spd_direct_sql.cc @@ -387,6 +387,23 @@ int spider_udf_direct_sql_create_conn_key( DBUG_RETURN(0); } +static inline void spider_maybe_memcpy_string( + char **dest, + char *src, + char *tmp, + uint *dest_len, + uint src_len) +{ + *dest_len= src_len; + if (src_len) + { + *dest= tmp; + memcpy(*dest, src, src_len); + } else + *dest= NULL; +} + + SPIDER_CONN *spider_udf_direct_sql_create_conn( const SPIDER_DIRECT_SQL *direct_sql, int *error_num @@ -469,74 +486,36 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn( { #endif conn->tgt_port = direct_sql->tgt_port; - conn->tgt_socket_length = direct_sql->tgt_socket_length; - conn->tgt_socket = tmp_socket; - memcpy(conn->tgt_socket, direct_sql->tgt_socket, - direct_sql->tgt_socket_length); - conn->tgt_username_length = direct_sql->tgt_username_length; - conn->tgt_username = tmp_username; - memcpy(conn->tgt_username, direct_sql->tgt_username, - direct_sql->tgt_username_length); - conn->tgt_password_length = direct_sql->tgt_password_length; - conn->tgt_password = tmp_password; - memcpy(conn->tgt_password, direct_sql->tgt_password, - direct_sql->tgt_password_length); - conn->tgt_ssl_ca_length = direct_sql->tgt_ssl_ca_length; - if (conn->tgt_ssl_ca_length) - { - conn->tgt_ssl_ca = tmp_ssl_ca; - memcpy(conn->tgt_ssl_ca, direct_sql->tgt_ssl_ca, - direct_sql->tgt_ssl_ca_length); - } else - conn->tgt_ssl_ca = NULL; - conn->tgt_ssl_capath_length = direct_sql->tgt_ssl_capath_length; - if (conn->tgt_ssl_capath_length) - { - conn->tgt_ssl_capath = tmp_ssl_capath; - memcpy(conn->tgt_ssl_capath, direct_sql->tgt_ssl_capath, - direct_sql->tgt_ssl_capath_length); - } else - conn->tgt_ssl_capath = NULL; - conn->tgt_ssl_cert_length = direct_sql->tgt_ssl_cert_length; - if (conn->tgt_ssl_cert_length) - { - conn->tgt_ssl_cert = tmp_ssl_cert; - memcpy(conn->tgt_ssl_cert, direct_sql->tgt_ssl_cert, - direct_sql->tgt_ssl_cert_length); - } else - conn->tgt_ssl_cert = NULL; - conn->tgt_ssl_cipher_length = direct_sql->tgt_ssl_cipher_length; - if (conn->tgt_ssl_cipher_length) - { - conn->tgt_ssl_cipher = tmp_ssl_cipher; - memcpy(conn->tgt_ssl_cipher, direct_sql->tgt_ssl_cipher, - direct_sql->tgt_ssl_cipher_length); - } else - conn->tgt_ssl_cipher = NULL; - conn->tgt_ssl_key_length = direct_sql->tgt_ssl_key_length; - if (conn->tgt_ssl_key_length) - { - conn->tgt_ssl_key = tmp_ssl_key; - memcpy(conn->tgt_ssl_key, direct_sql->tgt_ssl_key, - direct_sql->tgt_ssl_key_length); - } else - conn->tgt_ssl_key = NULL; - conn->tgt_default_file_length = direct_sql->tgt_default_file_length; - if (conn->tgt_default_file_length) - { - conn->tgt_default_file = tmp_default_file; - memcpy(conn->tgt_default_file, direct_sql->tgt_default_file, - direct_sql->tgt_default_file_length); - } else - conn->tgt_default_file = NULL; - conn->tgt_default_group_length = direct_sql->tgt_default_group_length; - if (conn->tgt_default_group_length) - { - conn->tgt_default_group = tmp_default_group; - memcpy(conn->tgt_default_group, direct_sql->tgt_default_group, - direct_sql->tgt_default_group_length); - } else - conn->tgt_default_group = NULL; + spider_maybe_memcpy_string( + &conn->tgt_socket, direct_sql->tgt_socket, tmp_socket, + &conn->tgt_socket_length, direct_sql->tgt_socket_length); + spider_maybe_memcpy_string( + &conn->tgt_username, direct_sql->tgt_username, tmp_username, + &conn->tgt_username_length, direct_sql->tgt_username_length); + spider_maybe_memcpy_string( + &conn->tgt_password, direct_sql->tgt_password, tmp_password, + &conn->tgt_password_length, direct_sql->tgt_password_length); + spider_maybe_memcpy_string( + &conn->tgt_ssl_ca, direct_sql->tgt_ssl_ca, tmp_ssl_ca, + &conn->tgt_ssl_ca_length, direct_sql->tgt_ssl_ca_length); + spider_maybe_memcpy_string( + &conn->tgt_ssl_capath, direct_sql->tgt_ssl_capath, tmp_ssl_capath, + &conn->tgt_ssl_capath_length, direct_sql->tgt_ssl_capath_length); + spider_maybe_memcpy_string( + &conn->tgt_ssl_cert, direct_sql->tgt_ssl_cert, tmp_ssl_cert, + &conn->tgt_ssl_cert_length, direct_sql->tgt_ssl_cert_length); + spider_maybe_memcpy_string( + &conn->tgt_ssl_cipher, direct_sql->tgt_ssl_cipher, tmp_ssl_cipher, + &conn->tgt_ssl_cipher_length, direct_sql->tgt_ssl_cipher_length); + spider_maybe_memcpy_string( + &conn->tgt_ssl_key, direct_sql->tgt_ssl_key, tmp_ssl_key, + &conn->tgt_ssl_key_length, direct_sql->tgt_ssl_key_length); + spider_maybe_memcpy_string( + &conn->tgt_default_file, direct_sql->tgt_default_file, tmp_default_file, + &conn->tgt_default_file_length, direct_sql->tgt_default_file_length); + spider_maybe_memcpy_string( + &conn->tgt_default_group, direct_sql->tgt_default_group, tmp_default_group, + &conn->tgt_default_group_length, direct_sql->tgt_default_group_length); conn->tgt_ssl_vsc = direct_sql->tgt_ssl_vsc; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } else { From 11fe2ee0af6d27cae17a85fc3874b27550cef3b7 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 21 Feb 2024 14:17:34 +1100 Subject: [PATCH 12/25] MDEV-33493 Spider: Make a symlink result file a normal file --- .../r/udf_mysql_func_early_init_file.result | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) mode change 120000 => 100644 storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result diff --git a/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result b/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result deleted file mode 120000 index 045ddc4372c..00000000000 --- a/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result +++ /dev/null @@ -1 +0,0 @@ -udf_mysql_func_early.result \ No newline at end of file diff --git a/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result b/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result new file mode 100644 index 00000000000..b84f60a67fb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result @@ -0,0 +1,43 @@ +# +# Test that udf created by inserting into mysql_func works as expected +# +CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS ( +HOST 'localhost', +DATABASE 'auto_test_local', +USER 'root', +PASSWORD '', +SOCKET '$MASTER_1_MYSOCK' + ); +CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS ( +HOST 'localhost', +DATABASE 'auto_test_remote', +USER 'root', +PASSWORD '', +SOCKET '$CHILD2_1_MYSOCK' + ); +connect master_1, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK; +connect child2_1, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK; +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +a INT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +insert into tbl_a values (42); +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +a INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +create temporary table results (a int); +SELECT SPIDER_DIRECT_SQL('select * from tbl_a', 'results', 'srv "s_2_1", database "auto_test_remote"'); +SPIDER_DIRECT_SQL('select * from tbl_a', 'results', 'srv "s_2_1", database "auto_test_remote"') +1 +select * from results; +a +42 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; From 44c88faecaa76ad2368101001f30bcb504ff2c7e Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 20 Mar 2024 10:36:25 +1100 Subject: [PATCH 13/25] MDEV-28992 Spider group by handler: Push down TIMESTAMPDIFF function Also removed ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC. Similar to pr#2225, with the testcase adapted from that patch: --8<---------------cut here---------------start------------->8--- From 884f7c6df16236748ca975339e0b1c267e195309 Mon Sep 17 00:00:00 2001 From: "Norio Akagi (norakagi)" Date: Wed, 3 Aug 2022 23:30:34 -0700 Subject: [PATCH] [MDEV-28992] Push down TIMESTAMP_DIFF in spider This changes so that TIMESTAMP_DIFF function in a query is pushed down and works natively in Spider. Instead of directly accessing item's member, now we can rely on a public accessor method to make it work. Unit tests are added under spider.pushdown_timestamp_diff. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --8<---------------cut here---------------end--------------->8--- --- .../feature/r/pushdown_timestamp_diff.result | 111 ++++++++++++++++++ .../feature/t/pushdown_timestamp_diff.test | 93 +++++++++++++++ storage/spider/spd_db_handlersocket.cc | 6 +- storage/spider/spd_db_mysql.cc | 34 +----- storage/spider/spd_db_oracle.cc | 6 +- 5 files changed, 208 insertions(+), 42 deletions(-) create mode 100644 storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result create mode 100644 storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test diff --git a/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result b/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result new file mode 100644 index 00000000000..3acd89127c0 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result @@ -0,0 +1,111 @@ +# +# MDEV-28992 Spider: Push down TIMESTAMPDIFF function +# +for master_1 +for child2 +for child3 +set spider_same_server_link= 1; +CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +create table t2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +); +CREATE TABLE t1 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +INSERT INTO t1 (a, b, c) VALUES +(1, 'a', '2018-11-01 10:21:39'), +(2, 'b', '2015-06-30 23:59:59'), +(3, 'c', '2013-11-01 01:01:01'); +interval year +explain select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(year, '2000-01-01 00:00:00', c) +1 a 18 +2 b 15 +3 c 13 +interval quarter +explain select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(quarter, '2000-01-01 00:00:00', c) +1 a 75 +2 b 61 +3 c 55 +interval month +explain select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(month, '2000-01-01 00:00:00', c) +1 a 226 +2 b 185 +3 c 166 +interval week +explain select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(week, '2000-01-01 00:00:00', c) +1 a 982 +2 b 808 +3 c 721 +interval day +explain select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(day, '2000-01-01 00:00:00', c) +1 a 6879 +2 b 5659 +3 c 5053 +internal hour +explain select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(hour, '2000-01-01 00:00:00', c) +1 a 165106 +2 b 135839 +3 c 121273 +internal minute +explain select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(minute, '2000-01-01 00:00:00', c) +1 a 9906381 +2 b 8150399 +3 c 7276381 +internal second +explain select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(second, '2000-01-01 00:00:00', c) +1 a 594382899 +2 b 489023999 +3 c 436582861 +internal microsecond +explain select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(microsecond, '2000-01-01 00:00:00', c) +1 a 594382899000000 +2 b 489023999000000 +3 c 436582861000000 +drop table t1, t2; +drop server srv; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test b/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test new file mode 100644 index 00000000000..81251860f74 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test @@ -0,0 +1,93 @@ +--echo # +--echo # MDEV-28992 Spider: Push down TIMESTAMPDIFF function +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +set spider_same_server_link= 1; +evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +create table t2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +); +CREATE TABLE t1 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; + +INSERT INTO t1 (a, b, c) VALUES + (1, 'a', '2018-11-01 10:21:39'), + (2, 'b', '2015-06-30 23:59:59'), + (3, 'c', '2013-11-01 01:01:01'); + +--echo interval year +let $query= +select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval quarter +let $query= +select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval month +let $query= +select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval week +let $query= +select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval day +let $query= +select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal hour +let $query= +select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal minute +let $query= +select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal second +let $query= +select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal microsecond +let $query= +select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +drop table t1, t2; +drop server srv; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/spd_db_handlersocket.cc b/storage/spider/spd_db_handlersocket.cc index 03d8b505bfe..137aa47e3d6 100644 --- a/storage/spider/spd_db_handlersocket.cc +++ b/storage/spider/spd_db_handlersocket.cc @@ -3178,14 +3178,13 @@ int spider_db_handlersocket_util::open_item_func( alias, alias_length, dbton_id, use_fields, fields)); } else if (!strncasecmp("timestampdiff", func_name, func_name_length)) { -#ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC Item_func_timestamp_diff *item_func_timestamp_diff = (Item_func_timestamp_diff *) item_func; if (str) { const char *interval_str; uint interval_len; - switch (item_func_timestamp_diff->int_type) + switch (item_func_timestamp_diff->get_int_type()) { case INTERVAL_YEAR: interval_str = SPIDER_SQL_YEAR_STR; @@ -3257,9 +3256,6 @@ int spider_db_handlersocket_util::open_item_func( SPIDER_SQL_CLOSE_PAREN_LEN); } DBUG_RETURN(0); -#else - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); -#endif } } else if (func_name_length == 14) { diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index a7bf14b7fed..68f5821d47e 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -5533,14 +5533,6 @@ int spider_db_mbase_util::open_item_func( alias_length, use_fields, fields)); } -static bool item_func_is_timestampdiff( - const char *func_name, - int func_name_length -) { - return func_name_length == 13 && - !strncasecmp("timestampdiff", func_name, func_name_length); -} - static bool not_func_should_be_skipped( Item_func *item_func ){ @@ -5610,10 +5602,6 @@ int spider_db_mbase_util::check_item_func( Item_func::Functype func_type = item_func->functype(); DBUG_PRINT("info",("spider functype = %d", func_type)); - const char *func_name = (char*) item_func->func_name(); - int func_name_length = strlen(func_name); - DBUG_PRINT("info",("spider func_name = %s", func_name)); - /* The blacklist of the functions that cannot be pushed down */ switch (func_type) { @@ -5628,14 +5616,6 @@ int spider_db_mbase_util::check_item_func( break; case Item_func::FUNC_SP: case Item_func::UDF_FUNC: - /* Notes on merging regarding MDEV-29447: please refer to the - following commits for build error or merge conflicts: - 10.5: d7b564da2a634dcf86798d6b86bd127e7eef9286 - 10.6: 1ed20b993b0dd4e95450cab2e8347e5bf4617a69 - 10.9: dd316b6e20265cfd832bb5585cb4c96e716387c8 - 10.10-11: 3f67f110ba1b23a89c5ede0fbeeb203cf5e164f4 - 11.0-1: 17ba6748afa8834df5658361088e6c8e65aca16f - Please remove this comment after merging. */ use_pushdown_udf= spider_param_use_pushdown_udf( spider->trx->thd, spider->share->use_pushdown_udf); if (!use_pushdown_udf) @@ -5645,12 +5625,6 @@ int spider_db_mbase_util::check_item_func( if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY) DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); break; -#ifndef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC - case Item_func::UNKNOWN_FUNC: - if (item_func_is_timestampdiff(func_name, func_name_length)) - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); - break; -#endif default: break; } @@ -6015,12 +5989,11 @@ int spider_db_mbase_util::print_item_func( alias, alias_length, dbton_id, use_fields, fields)); } else if (!strncasecmp("timestampdiff", func_name, func_name_length)) { -#ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC Item_func_timestamp_diff *item_func_timestamp_diff = (Item_func_timestamp_diff *) item_func; const char *interval_str; uint interval_len; - switch (item_func_timestamp_diff->int_type) + switch (item_func_timestamp_diff->get_int_type()) { case INTERVAL_YEAR: interval_str = SPIDER_SQL_YEAR_STR; @@ -6071,7 +6044,7 @@ int spider_db_mbase_util::print_item_func( str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); str->q_append(interval_str, interval_len); str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); - + if ((error_num = spider_db_print_item_type(item_list[0], NULL, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); @@ -6092,9 +6065,6 @@ int spider_db_mbase_util::print_item_func( SPIDER_SQL_CLOSE_PAREN_LEN); } DBUG_RETURN(0); -#else - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); -#endif } } else if (func_name_length == 14) { diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index 6d52f3827ea..769aab21c46 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -3424,14 +3424,13 @@ int spider_db_oracle_util::open_item_func( alias, alias_length, dbton_id, use_fields, fields)); } else if (!strncasecmp("timestampdiff", func_name, func_name_length)) { -#ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC Item_func_timestamp_diff *item_func_timestamp_diff = (Item_func_timestamp_diff *) item_func; if (str) { const char *interval_str; uint interval_len; - switch (item_func_timestamp_diff->int_type) + switch (item_func_timestamp_diff->get_int_type()) { case INTERVAL_YEAR: interval_str = SPIDER_SQL_YEAR_STR; @@ -3503,9 +3502,6 @@ int spider_db_oracle_util::open_item_func( SPIDER_SQL_CLOSE_PAREN_LEN); } DBUG_RETURN(0); -#else - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); -#endif } } else if (func_name_length == 14) { From 9c93d41ad7b6efcbad38fe19a994a76c1c4b5c32 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 20 Mar 2024 14:03:52 +1100 Subject: [PATCH 14/25] MDEV-33728 spider: remove use of MYSQL_VERSION_ID and MARIADB_BASE_VERSION change created by: unifdef -DMYSQL_VERSION_ID=100400 -DMARIADB_BASE_VERSION -m storage/spider/spd_* storage/spider/ha_spider.* storage/spider/hs_client/* basically MDEV-27637, MDEV-27641, MDEV-27655 --- storage/spider/ha_spider.cc | 162 --------------------- storage/spider/ha_spider.h | 37 ----- storage/spider/hs_client/config.cpp | 5 - storage/spider/hs_client/config.hpp | 5 - storage/spider/hs_client/fatal.cpp | 5 - storage/spider/hs_client/fatal.hpp | 5 - storage/spider/hs_client/hs_compat.h | 12 -- storage/spider/hs_client/hstcpcli.cpp | 5 - storage/spider/hs_client/hstcpcli.hpp | 5 - storage/spider/hs_client/socket.cpp | 7 - storage/spider/hs_client/socket.hpp | 5 - storage/spider/hs_client/string_util.cpp | 5 - storage/spider/spd_conn.cc | 102 ------------- storage/spider/spd_copy_tables.cc | 39 ----- storage/spider/spd_db_conn.cc | 70 --------- storage/spider/spd_db_handlersocket.cc | 21 --- storage/spider/spd_db_include.cc | 5 - storage/spider/spd_db_include.h | 24 --- storage/spider/spd_db_mysql.cc | 63 -------- storage/spider/spd_db_oracle.cc | 25 ---- storage/spider/spd_direct_sql.cc | 59 -------- storage/spider/spd_environ.h | 12 -- storage/spider/spd_group_by_handler.cc | 5 - storage/spider/spd_i_s.cc | 9 -- storage/spider/spd_include.h | 114 --------------- storage/spider/spd_malloc.cc | 5 - storage/spider/spd_param.cc | 130 ----------------- storage/spider/spd_param.h | 3 - storage/spider/spd_ping_table.cc | 61 -------- storage/spider/spd_sys_table.cc | 177 ----------------------- storage/spider/spd_sys_table.h | 19 --- storage/spider/spd_table.cc | 176 ---------------------- storage/spider/spd_trx.cc | 64 -------- 33 files changed, 1441 deletions(-) diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 90dd37b78aa..b0671cb6f1a 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -22,10 +22,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -33,7 +29,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #include "ha_partition.h" #include "spd_param.h" #include "spd_err.h" @@ -48,15 +43,9 @@ #include "spd_ping_table.h" #include "spd_malloc.h" -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 #define SPIDER_CAN_BG_SEARCH (1LL << 37) #define SPIDER_CAN_BG_INSERT (1LL << 38) #define SPIDER_CAN_BG_UPDATE (1LL << 39) -#else -#define SPIDER_CAN_BG_SEARCH (LL(1) << 37) -#define SPIDER_CAN_BG_INSERT (LL(1) << 38) -#define SPIDER_CAN_BG_UPDATE (LL(1) << 39) -#endif extern handlerton *spider_hton_ptr; extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; @@ -1253,9 +1242,6 @@ int ha_spider::external_lock( DBUG_ENTER("ha_spider::external_lock"); DBUG_PRINT("info",("spider this=%p", this)); DBUG_PRINT("info",("spider lock_type=%x", lock_type)); -#if MYSQL_VERSION_ID < 50500 - DBUG_PRINT("info",("spider thd->options=%x", (int) thd->options)); -#endif #ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC info_auto_called = FALSE; #endif @@ -1943,14 +1929,11 @@ int ha_spider::extra( if (!(trx = spider_get_trx(ha_thd(), TRUE, &error_num))) DBUG_RETURN(error_num); break; -#if MYSQL_VERSION_ID < 50500 -#else case HA_EXTRA_ADD_CHILDREN_LIST: DBUG_PRINT("info",("spider HA_EXTRA_ADD_CHILDREN_LIST")); if (!(trx = spider_get_trx(ha_thd(), TRUE, &error_num))) DBUG_RETURN(error_num); break; -#endif #if defined(HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN) || defined(HA_EXTRA_HAS_HA_EXTRA_USE_CMP_REF) #ifdef HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN case HA_EXTRA_STARTING_ORDERED_INDEX_SCAN: @@ -4430,7 +4413,6 @@ bool ha_spider::check_no_where_cond() } #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows ha_spider::multi_range_read_info_const( uint keyno, RANGE_SEQ_IF *seq, @@ -4440,17 +4422,6 @@ ha_rows ha_spider::multi_range_read_info_const( uint *flags, Cost_estimate *cost ) -#else -ha_rows ha_spider::multi_range_read_info_const( - uint keyno, - RANGE_SEQ_IF *seq, - void *seq_init_param, - uint n_ranges, - uint *bufsz, - uint *flags, - COST_VECT *cost -) -#endif { DBUG_ENTER("ha_spider::multi_range_read_info_const"); DBUG_PRINT("info",("spider this=%p", this)); @@ -4494,7 +4465,6 @@ ha_rows ha_spider::multi_range_read_info_const( DBUG_RETURN(rows); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows ha_spider::multi_range_read_info( uint keyno, uint n_ranges, @@ -4504,17 +4474,6 @@ ha_rows ha_spider::multi_range_read_info( uint *flags, Cost_estimate *cost ) -#else -ha_rows ha_spider::multi_range_read_info( - uint keyno, - uint n_ranges, - uint keys, - uint key_parts, - uint *bufsz, - uint *flags, - COST_VECT *cost -) -#endif { DBUG_ENTER("ha_spider::multi_range_read_info"); DBUG_PRINT("info",("spider this=%p", this)); @@ -4586,16 +4545,10 @@ int ha_spider::multi_range_read_init( #endif #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int ha_spider::multi_range_read_next_first( range_id_t *range_info ) #else -int ha_spider::multi_range_read_next_first( - char **range_info -) -#endif -#else int ha_spider::read_multi_range_first_internal( uchar *buf, KEY_MULTI_RANGE **found_range_p, @@ -5081,19 +5034,11 @@ int ha_spider::read_multi_range_first_internal( DBUG_PRINT("info",("spider free multi_range_keys=%p", multi_range_keys)); spider_free(spider_current_trx, multi_range_keys, MYF(0)); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 if (!(multi_range_keys = (range_id_t *) spider_malloc(spider_current_trx, SPD_MID_HA_SPIDER_MULTI_RANGE_READ_NEXT_FIRST_1, sizeof(range_id_t) * (multi_range_num < result_list.multi_split_read ? multi_range_num : result_list.multi_split_read), MYF(MY_WME))) ) -#else - if (!(multi_range_keys = (char **) - spider_malloc(spider_current_trx, SPD_MID_HA_SPIDER_MULTI_RANGE_READ_NEXT_FIRST_2, sizeof(char *) * - (multi_range_num < result_list.multi_split_read ? - multi_range_num : result_list.multi_split_read), MYF(MY_WME))) - ) -#endif DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_PRINT("info",("spider alloc multi_range_keys=%p", multi_range_keys)); if (!mrr_key_buff) @@ -5311,11 +5256,7 @@ int ha_spider::read_multi_range_first_internal( } #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if (bka_mode == 2) { @@ -5438,11 +5379,7 @@ int ha_spider::read_multi_range_first_internal( { #ifdef HA_MRR_USE_DEFAULT_IMPL DBUG_PRINT("info",("spider range_res7=%d", range_res)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if ((error_num = spider_db_append_select(this))) DBUG_RETURN(error_num); @@ -5986,15 +5923,9 @@ int ha_spider::pre_multi_range_read_next( DBUG_RETURN(0); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int ha_spider::multi_range_read_next( range_id_t *range_info ) -#else -int ha_spider::multi_range_read_next( - char **range_info -) -#endif { int error_num; DBUG_ENTER("ha_spider::multi_range_read_next"); @@ -6072,16 +6003,10 @@ int ha_spider::read_multi_range_first( #endif #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int ha_spider::multi_range_read_next_next( range_id_t *range_info ) #else -int ha_spider::multi_range_read_next_next( - char **range_info -) -#endif -#else int ha_spider::read_multi_range_next( KEY_MULTI_RANGE **found_range_p ) @@ -6797,11 +6722,7 @@ int ha_spider::read_multi_range_next( } #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if (bka_mode == 2) { @@ -6922,11 +6843,7 @@ int ha_spider::read_multi_range_next( #endif { #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if ((error_num = spider_db_append_select(this))) DBUG_RETURN(error_num); @@ -9952,29 +9869,15 @@ int ha_spider::write_row( bulk_access_pre_called = FALSE; DBUG_RETURN(spider_db_bulk_bulk_insert(this)); } -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_exec_tgt->spider->ha_write_row(buf); -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif #ifndef SPIDER_WITHOUT_HA_STATISTIC_INCREMENT ha_statistic_increment(&SSV::ha_write_count); -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) - table->timestamp_field->set_time(); #endif if (!bulk_insert) store_last_insert_id = 0; @@ -10069,21 +9972,12 @@ int ha_spider::pre_write_row( THD *thd = trx->thd; DBUG_ENTER("ha_spider::pre_write_row"); DBUG_PRINT("info",("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_current->spider->ha_write_row(buf); bulk_access_link_current->spider->bulk_access_pre_called = TRUE; bulk_access_link_current->called = TRUE; -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif @@ -10206,20 +10100,11 @@ int ha_spider::update_row( bulk_access_link_exec_tgt->called ) { ulonglong option_backup = 0; -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_exec_tgt->spider->ha_update_row( old_data, new_data); -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif @@ -10228,11 +10113,6 @@ int ha_spider::update_row( #endif #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS do_direct_update = FALSE; -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) - table->timestamp_field->set_time(); #endif if ((error_num = spider_db_update(this, table, old_data))) DBUG_RETURN(check_error_mode(error_num)); @@ -10349,14 +10229,10 @@ int ha_spider::direct_update_rows_init( direct_update_fields ) { if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -10516,14 +10392,10 @@ int ha_spider::direct_update_rows_init() if (direct_update_fields) { if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -10843,19 +10715,10 @@ int ha_spider::delete_row( bulk_access_link_exec_tgt->called ) { ulonglong option_backup = 0; -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_exec_tgt->spider->ha_delete_row(buf); -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif @@ -10920,14 +10783,10 @@ int ha_spider::direct_delete_rows_init( if (!range_count) { if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -11020,14 +10879,10 @@ int ha_spider::direct_delete_rows_init() cond_check = FALSE; spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit); if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -11441,11 +11296,7 @@ int ha_spider::create( uint sql_command = thd_sql_command(thd), roop_count; SPIDER_TRX *trx; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool need_lock = FALSE; DBUG_ENTER("ha_spider::create"); DBUG_PRINT("info",("spider this=%p", this)); @@ -11686,11 +11537,7 @@ int ha_spider::rename_table( TABLE *table_tables = NULL; SPIDER_ALTER_TABLE *alter_table_from, *alter_table_to; SPIDER_LGTM_TBLHND_SHARE *from_lgtm_tblhnd_share, *to_lgtm_tblhnd_share; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool need_lock = FALSE; DBUG_ENTER("ha_spider::rename_table"); DBUG_PRINT("info",("spider this=%p", this)); @@ -11914,11 +11761,7 @@ int ha_spider::delete_table( TABLE *table_tables = NULL; uint sql_command = thd_sql_command(thd); SPIDER_ALTER_TABLE *alter_table; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool need_lock = FALSE; DBUG_ENTER("ha_spider::delete_table"); DBUG_PRINT("info",("spider this=%p", this)); @@ -15854,13 +15697,8 @@ int ha_spider::bulk_tmp_table_rnd_next() if (tmp_table[roop_count]) { if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 !(error_num = tmp_table[roop_count]->file->ha_rnd_next( tmp_table[roop_count]->record[0])) -#else - !(error_num = tmp_table[roop_count]->file->rnd_next( - tmp_table[roop_count]->record[0])) -#endif ) { DBUG_RETURN(error_num); } diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index 543b92629da..f5a597b88a7 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -147,11 +147,7 @@ public: bool have_second_range; KEY_MULTI_RANGE mrr_second_range; spider_string *mrr_key_buff; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 range_id_t *multi_range_keys; -#else - char **multi_range_keys; -#endif #else KEY_MULTI_RANGE *multi_range_ranges; #endif @@ -357,7 +353,6 @@ public: void reset_no_where_cond(); bool check_no_where_cond(); #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows multi_range_read_info_const( uint keyno, RANGE_SEQ_IF *seq, @@ -376,26 +371,6 @@ public: uint *flags, Cost_estimate *cost ); -#else - ha_rows multi_range_read_info_const( - uint keyno, - RANGE_SEQ_IF *seq, - void *seq_init_param, - uint n_ranges, - uint *bufsz, - uint *flags, - COST_VECT *cost - ); - ha_rows multi_range_read_info( - uint keyno, - uint n_ranges, - uint keys, - uint key_parts, - uint *bufsz, - uint *flags, - COST_VECT *cost - ); -#endif int multi_range_read_init( RANGE_SEQ_IF *seq, void *seq_init_param, @@ -403,7 +378,6 @@ public: uint mode, HANDLER_BUFFER *buf ); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int multi_range_read_next( range_id_t *range_info ); @@ -413,17 +387,6 @@ public: int multi_range_read_next_next( range_id_t *range_info ); -#else - int multi_range_read_next( - char **range_info - ); - int multi_range_read_next_first( - char **range_info - ); - int multi_range_read_next_next( - char **range_info - ); -#endif #else int read_multi_range_first( KEY_MULTI_RANGE **found_range_p, diff --git a/storage/spider/hs_client/config.cpp b/storage/spider/hs_client/config.cpp index d2759e37d8f..9c6f936b8a8 100644 --- a/storage/spider/hs_client/config.cpp +++ b/storage/spider/hs_client/config.cpp @@ -9,13 +9,8 @@ #include #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "config.hpp" diff --git a/storage/spider/hs_client/config.hpp b/storage/spider/hs_client/config.hpp index 2880f2f5a33..a3a986cc1fd 100644 --- a/storage/spider/hs_client/config.hpp +++ b/storage/spider/hs_client/config.hpp @@ -11,14 +11,9 @@ #define DENA_CONFIG_HPP #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif #define DENA_VERBOSE(lv, x) if (dena::verbose_level >= (lv)) { (x); } diff --git a/storage/spider/hs_client/fatal.cpp b/storage/spider/hs_client/fatal.cpp index cfbc14df64a..1ed20189a93 100644 --- a/storage/spider/hs_client/fatal.cpp +++ b/storage/spider/hs_client/fatal.cpp @@ -9,13 +9,8 @@ #include #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "fatal.hpp" diff --git a/storage/spider/hs_client/fatal.hpp b/storage/spider/hs_client/fatal.hpp index 38fc149e98e..859b695baf3 100644 --- a/storage/spider/hs_client/fatal.hpp +++ b/storage/spider/hs_client/fatal.hpp @@ -11,14 +11,9 @@ #define DENA_FATAL_HPP #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif namespace dena { diff --git a/storage/spider/hs_client/hs_compat.h b/storage/spider/hs_client/hs_compat.h index 8505d7978b7..e466dee67a7 100644 --- a/storage/spider/hs_client/hs_compat.h +++ b/storage/spider/hs_client/hs_compat.h @@ -16,21 +16,9 @@ #ifndef HS_COMPAT_H #define HS_COMPAT_H -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100213 #define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ my_init_dynamic_array2(A, B, C, D, E, F) #define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ init_alloc_root(A, "spider", B, C, D) -#elif defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ - my_init_dynamic_array2(A, B, C, D, E, F) -#define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ - init_alloc_root(A, B, C, D) -#else -#define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ - my_init_dynamic_array2(A, B, C, D, E) -#define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ - init_alloc_root(A, B, C) -#endif #endif diff --git a/storage/spider/hs_client/hstcpcli.cpp b/storage/spider/hs_client/hstcpcli.cpp index 4c93b5a3a49..791ee9a9e4c 100644 --- a/storage/spider/hs_client/hstcpcli.cpp +++ b/storage/spider/hs_client/hstcpcli.cpp @@ -10,14 +10,9 @@ #include #include "mysql_version.h" #include "hs_compat.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif #include "hstcpcli.hpp" #include "auto_file.hpp" diff --git a/storage/spider/hs_client/hstcpcli.hpp b/storage/spider/hs_client/hstcpcli.hpp index aac02ce7f46..06044f169a3 100644 --- a/storage/spider/hs_client/hstcpcli.hpp +++ b/storage/spider/hs_client/hstcpcli.hpp @@ -13,13 +13,8 @@ #define HANDLERSOCKET_MYSQL_UTIL 1 #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "config.hpp" #include "socket.hpp" diff --git a/storage/spider/hs_client/socket.cpp b/storage/spider/hs_client/socket.cpp index 45b8100e64c..469acb2725f 100644 --- a/storage/spider/hs_client/socket.cpp +++ b/storage/spider/hs_client/socket.cpp @@ -16,16 +16,9 @@ #include "mysql_version.h" #include "hs_compat.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 #include -#endif #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "socket.hpp" #include "string_util.hpp" diff --git a/storage/spider/hs_client/socket.hpp b/storage/spider/hs_client/socket.hpp index a3e6527a46d..e4f7530aec9 100644 --- a/storage/spider/hs_client/socket.hpp +++ b/storage/spider/hs_client/socket.hpp @@ -11,13 +11,8 @@ #define DENA_SOCKET_HPP #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "auto_addrinfo.hpp" #include "auto_file.hpp" diff --git a/storage/spider/hs_client/string_util.cpp b/storage/spider/hs_client/string_util.cpp index 39934148cb8..647cf877805 100644 --- a/storage/spider/hs_client/string_util.cpp +++ b/storage/spider/hs_client/string_util.cpp @@ -10,13 +10,8 @@ #include #include "mysql_version.h" #include "hs_compat.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "string_util.hpp" diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index ba8a579b1ac..be9b27d83ad 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -18,16 +18,11 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "tztime.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -733,12 +728,8 @@ SPIDER_CONN *spider_create_conn( else conn->need_mon = need_mon; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mta_conn, &conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_mta_conn_mutex_init; @@ -1883,43 +1874,27 @@ int spider_create_conn_thread( DBUG_ENTER("spider_create_conn_thread"); if (conn && !conn->bg_init) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_conn_chain_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_conn_chain, &conn->bg_conn_chain_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_chain_mutex_init; } conn->bg_conn_chain_mutex_ptr = NULL; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_conn_sync_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_conn_sync, &conn->bg_conn_sync_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_conn, &conn->bg_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_job_stack_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_job_stack, &conn->bg_job_stack_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_job_stack_mutex_init; @@ -1936,36 +1911,22 @@ int spider_create_conn_thread( conn->bg_job_stack.max_element * conn->bg_job_stack.size_of_element); conn->bg_job_stack_cur_pos = 0; -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&conn->bg_conn_sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_conn_sync, &conn->bg_conn_sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&conn->bg_conn_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_conn, &conn->bg_conn_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } pthread_mutex_lock(&conn->bg_conn_mutex); -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&conn->bg_thread, &spider_pt_attr, - spider_bg_conn_action, (void *) conn) - ) -#else if (mysql_thread_create(spd_key_thd_bg, &conn->bg_thread, &spider_pt_attr, spider_bg_conn_action, (void *) conn) ) -#endif { pthread_mutex_unlock(&conn->bg_conn_mutex); error_num = HA_ERR_OUT_OF_MEM; @@ -2936,35 +2897,21 @@ int spider_create_sts_thread( DBUG_ENTER("spider_create_sts_thread"); if (!share->bg_sts_init) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_sts_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_sts, &share->bg_sts_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_sts_sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_sts_sync, &share->bg_sts_sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&share->bg_sts_thread, &spider_pt_attr, - spider_bg_sts_action, (void *) share) - ) -#else if (mysql_thread_create(spd_key_thd_bg_sts, &share->bg_sts_thread, &spider_pt_attr, spider_bg_sts_action, (void *) share) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; @@ -3301,35 +3248,21 @@ int spider_create_crd_thread( DBUG_ENTER("spider_create_crd_thread"); if (!share->bg_crd_init) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_crd_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crd, &share->bg_crd_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_crd_sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crd_sync, &share->bg_crd_sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&share->bg_crd_thread, &spider_pt_attr, - spider_bg_crd_action, (void *) share) - ) -#else if (mysql_thread_create(spd_key_thd_bg_crd, &share->bg_crd_thread, &spider_pt_attr, spider_bg_crd_action, (void *) share) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; @@ -3743,13 +3676,8 @@ int spider_create_mon_threads( { if ( share->monitoring_bg_kind[roop_count] && -#if MYSQL_VERSION_ID < 50500 - pthread_mutex_init(&share->bg_mon_mutexes[roop_count], - MY_MUTEX_INIT_FAST) -#else mysql_mutex_init(spd_key_mutex_bg_mon, &share->bg_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST) -#endif ) { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -3761,12 +3689,8 @@ int spider_create_mon_threads( { if ( share->monitoring_bg_kind[roop_count] && -#if MYSQL_VERSION_ID < 50500 - pthread_cond_init(&share->bg_mon_conds[roop_count], NULL) -#else mysql_cond_init(spd_key_cond_bg_mon, &share->bg_mon_conds[roop_count], NULL) -#endif ) { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -3778,12 +3702,8 @@ int spider_create_mon_threads( { if ( share->monitoring_bg_kind[roop_count] && -#if MYSQL_VERSION_ID < 50500 - pthread_cond_init(&share->bg_mon_sleep_conds[roop_count], NULL) -#else mysql_cond_init(spd_key_cond_bg_mon_sleep, &share->bg_mon_sleep_conds[roop_count], NULL) -#endif ) { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -3798,16 +3718,10 @@ int spider_create_mon_threads( { link_pack.link_idx = roop_count; pthread_mutex_lock(&share->bg_mon_mutexes[roop_count]); -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&share->bg_mon_threads[roop_count], - &spider_pt_attr, spider_bg_mon_action, (void *) &link_pack) - ) -#else if (mysql_thread_create(spd_key_thd_bg_mon, &share->bg_mon_threads[roop_count], &spider_pt_attr, spider_bg_mon_action, (void *) &link_pack) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -4061,17 +3975,9 @@ int spider_conn_first_link_idx( my_afree(link_idxs); DBUG_RETURN(-1); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 DBUG_PRINT("info",("spider server_id=%lu", thd->variables.server_id)); -#else - DBUG_PRINT("info",("spider server_id=%u", thd->server_id)); -#endif DBUG_PRINT("info",("spider thread_id=%lu", thd_get_thread_id(thd))); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 rand_val = spider_rand(thd->variables.server_id + thd_get_thread_id(thd)); -#else - rand_val = spider_rand(thd->server_id + thd_get_thread_id(thd)); -#endif DBUG_PRINT("info",("spider rand_val=%f", rand_val)); balance_val = (longlong) (rand_val * balance_total); DBUG_PRINT("info",("spider balance_val=%lld", balance_val)); @@ -4597,21 +4503,13 @@ SPIDER_IP_PORT_CONN* spider_create_ipport_conn(SPIDER_CONN *conn) goto err_return_direct; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&ret->mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_conn_i, &ret->mutex, MY_MUTEX_INIT_FAST)) -#endif { //error goto err_malloc_key; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&ret->cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_conn_i, &ret->cond, NULL)) -#endif { pthread_mutex_destroy(&ret->mutex); goto err_malloc_key; diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc index d205cd244ca..a63d63ca430 100644 --- a/storage/spider/spd_copy_tables.cc +++ b/storage/spider/spd_copy_tables.cc @@ -17,17 +17,12 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_base.h" #include "sql_partition.h" #include "transaction.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -250,11 +245,7 @@ int spider_udf_get_copy_tgt_tables( ) { int error_num, roop_count; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif char table_key[MAX_KEY_LENGTH]; SPIDER_COPY_TABLE_CONN *table_conn = NULL, *src_table_conn_prev = NULL, *dst_table_conn_prev = NULL; @@ -744,13 +735,8 @@ long long spider_copy_tables_body( thd->handler_tables_hash.records != 0 || thd->derived_tables != 0 || thd->lock != 0 || -#if MYSQL_VERSION_ID < 50500 - thd->locked_tables != 0 || - thd->prelocked_mode != NON_PRELOCKED -#else thd->locked_tables_list.locked_tables() || thd->locked_tables_mode != LTM_NONE -#endif ) { if (thd->open_tables != 0) { @@ -773,18 +759,6 @@ long long spider_copy_tables_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), "thd->lock", thd->lock); -#if MYSQL_VERSION_ID < 50500 - } else if (thd->locked_tables != 0) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), - "thd->locked_tables", thd->locked_tables); - } else if (thd->prelocked_mode != NON_PRELOCKED) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), - "thd->prelocked_mode", (longlong) thd->prelocked_mode); -#else } else if (thd->locked_tables_list.locked_tables()) { my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, @@ -796,7 +770,6 @@ long long spider_copy_tables_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), "thd->locked_tables_mode", (longlong) thd->locked_tables_mode); -#endif } goto error; } @@ -888,9 +861,6 @@ long long spider_copy_tables_body( copy_tables->trx->trx_start = TRUE; copy_tables->trx->updated_in_this_trx = FALSE; DBUG_PRINT("info",("spider trx->updated_in_this_trx=FALSE")); -#if MYSQL_VERSION_ID < 50500 - if (open_and_lock_tables(thd, table_list)) -#else table_list->mdl_request.init( MDL_key::TABLE, SPIDER_TABLE_LIST_db_str(table_list), @@ -899,7 +869,6 @@ long long spider_copy_tables_body( MDL_TRANSACTION ); if (open_and_lock_tables(thd, table_list, FALSE, 0)) -#endif { thd->m_reprepare_observer = reprepare_observer_backup; copy_tables->trx->trx_start = FALSE; @@ -1099,11 +1068,7 @@ long long spider_copy_tables_body( if (table_list->table) { -#if MYSQL_VERSION_ID < 50500 - ha_autocommit_or_rollback(thd, 0); -#else (thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd)); -#endif close_thread_tables(thd); } if (spider) @@ -1149,11 +1114,7 @@ error: } if (table_list && table_list->table) { -#if MYSQL_VERSION_ID < 50500 - ha_autocommit_or_rollback(thd, 0); -#else (thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd)); -#endif close_thread_tables(thd); } if (spider) diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 52fde02ad0c..40dc15a2149 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -18,10 +18,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -33,7 +29,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #include "sql_common.h" #include #include "spd_err.h" @@ -1930,10 +1925,8 @@ int spider_db_append_key_where_internal( DBUG_PRINT("info", ("spider start_key->flag=%d", start_key->flag)); switch (start_key->flag) { -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 case HA_READ_PREFIX_LAST: result_list->desc_flg = TRUE; -#endif /* fall through */ case HA_READ_KEY_EXACT: if (sql_kind == SPIDER_SQL_KIND_SQL) @@ -2169,12 +2162,6 @@ int spider_db_append_key_where_internal( } #endif break; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - case HA_READ_PREFIX_LAST: - result_list->limit_num = 1; - /* fall through */ -#endif case HA_READ_KEY_OR_PREV: case HA_READ_PREFIX_LAST_OR_PREV: result_list->desc_flg = TRUE; @@ -3016,13 +3003,8 @@ int spider_db_get_row_from_tmp_tbl( current->result_tmp_tbl_inited = 1; } if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = current->result_tmp_tbl->file->ha_rnd_next( current->result_tmp_tbl->record[0])) -#else - (error_num = current->result_tmp_tbl->file->rnd_next( - current->result_tmp_tbl->record[0])) -#endif ) { DBUG_RETURN(error_num); } @@ -3050,13 +3032,8 @@ int spider_db_get_row_from_tmp_tbl_pos( result->result_tmp_tbl_inited = 2; } if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = tmp_tbl->file->ha_rnd_pos(tmp_tbl->record[0], (uchar *) &pos->tmp_tbl_pos)) -#else - (error_num = tmp_tbl->file->rnd_pos(tmp_tbl->record[0], - (uchar *) &pos->tmp_tbl_pos)) -#endif ) { DBUG_RETURN(error_num); } @@ -6573,11 +6550,7 @@ int spider_db_update_auto_increment( if ( table->s->next_number_keypart == 0 && mysql_bin_log.is_open() && -#if MYSQL_VERSION_ID < 50500 - !thd->current_stmt_binlog_row_based -#else !thd->is_current_stmt_binlog_format_row() -#endif ) { if ( spider->check_partitioned() && @@ -6606,11 +6579,7 @@ int spider_db_update_auto_increment( if ( table->s->next_number_keypart == 0 && mysql_bin_log.is_open() && -#if MYSQL_VERSION_ID < 50500 - !thd->current_stmt_binlog_row_based -#else !thd->is_current_stmt_binlog_format_row() -#endif ) { for (roop_count = 0; roop_count < (int) affected_rows; roop_count++) push_warning_printf(thd, SPIDER_WARN_LEVEL_NOTE, @@ -6849,9 +6818,7 @@ int spider_db_update( ) { conn = spider->conns[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 conn->ignore_dup_key = spider->ignore_dup_key; -#endif pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_UPDATE_SQL, roop_count))) @@ -8980,11 +8947,7 @@ int spider_db_print_item_type_default( { if (spider->share->access_charset->cset == system_charset_info->cset) { -#if MYSQL_VERSION_ID < 50500 - item->print(str->get_str(), QT_IS); -#else item->print(str->get_str(), QT_TO_SYSTEM_CHARSET); -#endif } else { item->print(str->get_str(), QT_ORDINARY); } @@ -10155,13 +10118,8 @@ int spider_db_udf_direct_sql( spider_param_ping_interval_at_trx_start(thd); time_t tmp_time = (time_t) time((time_t*) 0); bool need_trx_end, need_all_commit, insert_start = FALSE; -#if MYSQL_VERSION_ID < 50500 -#else enum_sql_command sql_command_backup; -#endif DBUG_ENTER("spider_db_udf_direct_sql"); -#if MYSQL_VERSION_ID < 50500 -#else if (direct_sql->real_table_used) { if (spider_sys_open_tables(c_thd, &direct_sql->table_list_first, @@ -10180,7 +10138,6 @@ int spider_db_udf_direct_sql( direct_sql->open_tables_thd = c_thd; roop_count = 0; } -#endif if (c_thd != thd) { @@ -10188,21 +10145,15 @@ int spider_db_udf_direct_sql( need_trx_end = TRUE; } else { need_all_commit = FALSE; -#if MYSQL_VERSION_ID < 50500 -#else if (direct_sql->real_table_used) { need_trx_end = TRUE; } else { -#endif if (c_thd->transaction.stmt.ha_list) need_trx_end = FALSE; else need_trx_end = TRUE; -#if MYSQL_VERSION_ID < 50500 -#else } -#endif } if (!conn->disable_reconnect) @@ -10222,11 +10173,8 @@ int spider_db_udf_direct_sql( DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); } -#if MYSQL_VERSION_ID < 50500 -#else sql_command_backup = c_thd->lex->sql_command; c_thd->lex->sql_command = SQLCOM_INSERT; -#endif pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); @@ -10252,10 +10200,7 @@ int spider_db_udf_direct_sql( if ((error_num = conn->db_conn->append_sql( direct_sql->sql, direct_sql->sql_length, &request_key))) { -#if MYSQL_VERSION_ID < 50500 -#else c_thd->lex->sql_command = sql_command_backup; -#endif DBUG_RETURN(error_num); } } @@ -10329,9 +10274,6 @@ int spider_db_udf_direct_sql( for (; roop_count2 < set_off; roop_count2++) bitmap_clear_bit(table->write_set, (uint) roop_count2); -#if MYSQL_VERSION_ID < 50500 - if (table->file->has_transactions()) -#endif { THR_LOCK_DATA *to[2]; table->file->store_lock(table->in_use, to, @@ -10342,8 +10284,6 @@ int spider_db_udf_direct_sql( table->file->print_error(error_num, MYF(0)); break; } -#if MYSQL_VERSION_ID < 50500 -#else if ( table->s->tmp_table == NO_TMP_TABLE && table->pos_in_table_list @@ -10365,7 +10305,6 @@ int spider_db_udf_direct_sql( next_tables = next_tables->next_global; } } -#endif } if (direct_sql->iop) @@ -10427,13 +10366,8 @@ int spider_db_udf_direct_sql( else if (direct_sql->iop[roop_count] == 2) table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); } -#if MYSQL_VERSION_ID < 50500 - if (table->file->has_transactions()) -#endif { table->file->ha_external_lock(table->in_use, F_UNLCK); -#if MYSQL_VERSION_ID < 50500 -#else if ( table->s->tmp_table == NO_TMP_TABLE && table->pos_in_table_list @@ -10449,7 +10383,6 @@ int spider_db_udf_direct_sql( next_tables = next_tables->next_global; } } -#endif } table->file->ha_reset(); table->in_use = thd; @@ -10512,10 +10445,7 @@ int spider_db_udf_direct_sql( } } } -#if MYSQL_VERSION_ID < 50500 -#else c_thd->lex->sql_command = sql_command_backup; -#endif DBUG_RETURN(error_num); } diff --git a/storage/spider/spd_db_handlersocket.cc b/storage/spider/spd_db_handlersocket.cc index 137aa47e3d6..5d04fa8084d 100644 --- a/storage/spider/spd_db_handlersocket.cc +++ b/storage/spider/spd_db_handlersocket.cc @@ -17,14 +17,9 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_analyse.h" -#endif #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) #include "spd_err.h" @@ -3297,11 +3292,7 @@ int spider_db_handlersocket_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3431,11 +3422,7 @@ int spider_db_handlersocket_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3585,11 +3572,7 @@ int spider_db_handlersocket_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3720,11 +3703,7 @@ int spider_db_handlersocket_util::open_item_func( last_str = SPIDER_SQL_CLOSE_PAREN_STR; last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; break; -#ifdef MARIADB_BASE_VERSION case Item_func::XOR_FUNC: -#else - case Item_func::COND_XOR_FUNC: -#endif if (str) str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); DBUG_RETURN( diff --git a/storage/spider/spd_db_include.cc b/storage/spider/spd_db_include.cc index 7f600142187..7363564aa04 100644 --- a/storage/spider/spd_db_include.cc +++ b/storage/spider/spd_db_include.cc @@ -17,14 +17,9 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif #include "sql_common.h" #include #include diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index 5add9fac3e4..20bd82e48da 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -23,56 +23,32 @@ #define SPIDER_DB_WRAPPER_MYSQL "mysql" #define SPIDER_DB_WRAPPER_MARIADB "mariadb" -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100204 #define PLUGIN_VAR_CAN_MEMALLOC /* #define ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC #define HASH_UPDATE_WITH_HASH_VALUE */ -#else -#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS -#define HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS -#endif -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 #define SPIDER_HAS_DISCOVER_TABLE_STRUCTURE #define SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE #define SPIDER_HAS_SHOW_SIMPLE_FUNC #define SPIDER_HAS_JT_HASH_INDEX_MERGE #define SPIDER_HAS_EXPR_CACHE_ITEM -#else -#define SPIDER_NEED_CHECK_CONDITION_AT_CHECKING_DIRECT_ORDER_LIMIT -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100007 #define SPIDER_ITEM_HAS_CMP_TYPE -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100004 #define SPIDER_HAS_TIME_STATUS #define SPIDER_HAS_DECIMAL_OPERATION_RESULTS_VALUE_TYPE -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100014 #define SPIDER_ITEM_STRING_WITHOUT_SET_STR_WITH_COPY -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100 #define SPIDER_ITEM_STRING_WITHOUT_SET_STR_WITH_COPY_AND_THDPTR -#endif -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100108 #define SPIDER_HAS_GROUP_BY_HANDLER -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200 #define SPIDER_ORDER_HAS_ENUM_ORDER -#endif -#if defined(MARIADB_BASE_VERSION) #define SPIDER_ITEM_GEOFUNC_NAME_HAS_MBR #define SPIDER_HANDLER_AUTO_REPAIR_HAS_ERROR -#endif class spider_db_conn; typedef spider_db_conn SPIDER_DB_CONN; diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 68f5821d47e..c239baf636d 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -17,10 +17,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -31,7 +27,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #include "sql_common.h" #include #include @@ -811,11 +806,7 @@ int spider_db_mbase_result::fetch_table_status( int error_num; MYSQL_ROW mysql_row; MYSQL_TIME mysql_time; -#ifdef MARIADB_BASE_VERSION uint not_used_uint; -#else - my_bool not_used_my_bool; -#endif #ifdef SPIDER_HAS_TIME_STATUS MYSQL_TIME_STATUS time_status; #else @@ -893,13 +884,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[11], strlen(mysql_row[11]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.create_time = (time_t) 0; #ifdef DBUG_TRACE @@ -918,13 +904,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[12], strlen(mysql_row[12]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.update_time = (time_t) 0; #ifndef DBUG_OFF @@ -943,13 +924,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[13], strlen(mysql_row[13]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.check_time = (time_t) 0; #ifdef DBUG_TRACE @@ -1022,13 +998,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[6], strlen(mysql_row[6]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.create_time = (time_t) 0; #ifdef DBUG_TRACE @@ -1047,13 +1018,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[7], strlen(mysql_row[7]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.update_time = (time_t) 0; #ifdef DBUG_TRACE @@ -1072,13 +1038,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[8], strlen(mysql_row[8]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.check_time = (time_t) 0; #ifdef DBUG_TRACE @@ -2391,11 +2352,7 @@ int spider_db_mbase::next_result() strmov(db_conn->net.sqlstate, "00000"); db_conn->affected_rows = ~(my_ulonglong) 0; -#if MYSQL_VERSION_ID < 50500 - if (db_conn->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS) -#else if (db_conn->server_status & SERVER_MORE_RESULTS_EXISTS) -#endif { if ((status = db_conn->methods->read_query_result(db_conn)) > 0) DBUG_RETURN(spider_db_errorno(conn)); @@ -2409,11 +2366,7 @@ uint spider_db_mbase::affected_rows() MYSQL *last_used_con; DBUG_ENTER("spider_db_mbase::affected_rows"); DBUG_PRINT("info",("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif DBUG_RETURN((uint) last_used_con->affected_rows); } @@ -2422,11 +2375,7 @@ uint spider_db_mbase::matched_rows() MYSQL *last_used_con; DBUG_ENTER("spider_db_mysql::matched_rows"); DBUG_PRINT("info", ("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif /* Rows matched: 65 Changed: 65 Warnings: 0 */ const char *info = last_used_con->info; if (!info) @@ -2451,11 +2400,7 @@ bool spider_db_mbase::inserted_info( { DBUG_RETURN(TRUE); } -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif /* Records: 10 Duplicates: 4 Warnings: 0 */ const char *info = last_used_con->info; if (!info) @@ -2497,11 +2442,7 @@ ulonglong spider_db_mbase::last_insert_id() MYSQL *last_used_con; DBUG_ENTER("spider_db_mbase::last_insert_id"); DBUG_PRINT("info",("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif DBUG_RETURN((uint) last_used_con->insert_id); } @@ -12891,11 +12832,7 @@ int spider_mbase_handler::bulk_tmp_table_rnd_next() int error_num; DBUG_ENTER("spider_mbase_handler::bulk_tmp_table_rnd_next"); DBUG_PRINT("info",("spider this=%p", this)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = upd_tmp_tbl->file->ha_rnd_next(upd_tmp_tbl->record[0]); -#else - error_num = upd_tmp_tbl->file->rnd_next(upd_tmp_tbl->record[0]); -#endif if (!error_num) { error_num = restore_sql_from_bulk_tmp_table(&insert_sql, upd_tmp_tbl); diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index 769aab21c46..b15bda5e77d 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -17,10 +17,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_partition.h" @@ -28,7 +24,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #ifdef HAVE_ORACLE_OCI #if (defined(WIN32) || defined(_WIN32) || defined(WINDOWS) || defined(_WINDOWS)) @@ -3543,11 +3538,7 @@ int spider_db_oracle_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3677,11 +3668,7 @@ int spider_db_oracle_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3967,11 +3954,7 @@ int spider_db_oracle_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -4102,11 +4085,7 @@ int spider_db_oracle_util::open_item_func( last_str = SPIDER_SQL_CLOSE_PAREN_STR; last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; break; -#ifdef MARIADB_BASE_VERSION case Item_func::XOR_FUNC: -#else - case Item_func::COND_XOR_FUNC: -#endif if (str) str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); DBUG_RETURN( @@ -10446,11 +10425,7 @@ int spider_oracle_handler::bulk_tmp_table_rnd_next() int error_num; DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_rnd_next"); DBUG_PRINT("info",("spider this=%p", this)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = upd_tmp_tbl->file->ha_rnd_next(upd_tmp_tbl->record[0]); -#else - error_num = upd_tmp_tbl->file->rnd_next(upd_tmp_tbl->record[0]); -#endif if (!error_num) { error_num = restore_sql_from_bulk_tmp_table(&insert_sql, upd_tmp_tbl); diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc index c0c37581865..d23b7053840 100644 --- a/storage/spider/spd_direct_sql.cc +++ b/storage/spider/spd_direct_sql.cc @@ -17,10 +17,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -28,7 +24,6 @@ #include "sql_base.h" #include "sql_servers.h" #include "tztime.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -43,9 +38,7 @@ #include "spd_udf.h" #include "spd_malloc.h" -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100004 #define SPIDER_NEED_INIT_ONE_TABLE_FOR_FIND_TEMPORARY_TABLE -#endif extern const char **spd_defaults_extra_file; extern const char **spd_defaults_file; @@ -114,21 +107,6 @@ int spider_udf_direct_sql_create_table_list( } else break; } -#if MYSQL_VERSION_ID < 50500 - if (!(direct_sql->db_names = (char**) - spider_bulk_malloc(spider_current_trx, SPD_MID_UDF_DIRECT_SQL_CREATE_TABLE_LIST_1, MYF(MY_WME | MY_ZEROFILL), - &direct_sql->db_names, sizeof(char*) * table_count, - &direct_sql->table_names, sizeof(char*) * table_count, - &direct_sql->tables, sizeof(TABLE*) * table_count, - &tmp_name_ptr, sizeof(char) * ( - table_name_list_length + - thd->db_length * table_count + - 2 * table_count - ), - &direct_sql->iop, sizeof(int) * table_count, - NullS)) - ) -#else if (!(direct_sql->db_names = (char**) spider_bulk_malloc(spider_current_trx, SPD_MID_UDF_DIRECT_SQL_CREATE_TABLE_LIST_2, MYF(MY_WME | MY_ZEROFILL), &direct_sql->db_names, sizeof(char*) * table_count, @@ -144,7 +122,6 @@ int spider_udf_direct_sql_create_table_list( &direct_sql->real_table_bitmap, sizeof(uchar) * ((table_count + 7) / 8), NullS)) ) -#endif DBUG_RETURN(HA_ERR_OUT_OF_MEM); tmp_ptr = table_name_list; @@ -561,12 +538,8 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn( } #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mta_conn, &conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_mta_conn_mutex_init; @@ -1061,10 +1034,7 @@ static void spider_minus_1(SPIDER_DIRECT_SQL *direct_sql) #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) direct_sql->access_mode = -1; #endif -#if MYSQL_VERSION_ID < 50500 -#else direct_sql->use_real_table = -1; -#endif direct_sql->error_rw_mode = -1; for (int i = 0; i < direct_sql->table_count; i++) direct_sql->iop[i] = -1; @@ -1132,10 +1102,7 @@ int spider_udf_parse_direct_sql_param( SPIDER_PARAM_STR("srv", server_name); SPIDER_PARAM_INT_WITH_MAX("svc", tgt_ssl_vsc, 0, 1); SPIDER_PARAM_INT_WITH_MAX("tlm", table_loop_mode, 0, 2); -#if MYSQL_VERSION_ID < 50500 -#else SPIDER_PARAM_INT_WITH_MAX("urt", use_real_table, 0, 1); -#endif SPIDER_PARAM_INT("wto", net_write_timeout, 0); error_num= parse.fail(true); goto error; @@ -1186,10 +1153,7 @@ int spider_udf_parse_direct_sql_param( error_num= parse.fail(true); goto error; case 14: -#if MYSQL_VERSION_ID < 50500 -#else SPIDER_PARAM_INT_WITH_MAX("use_real_table", use_real_table, 0, 1); -#endif error_num= parse.fail(true); goto error; case 15: @@ -1394,14 +1358,11 @@ void spider_udf_free_direct_sql_alloc( pthread_mutex_unlock(direct_sql->bg_mutex); } #endif -#if MYSQL_VERSION_ID < 50500 -#else if (direct_sql->real_table_used && direct_sql->open_tables_thd) { spider_sys_close_table(direct_sql->open_tables_thd, &direct_sql->open_tables_backup); } -#endif if (direct_sql->server_name) { spider_free(spider_current_trx, direct_sql->server_name, MYF(0)); @@ -1485,11 +1446,8 @@ long long spider_direct_sql_body( char *sql; TABLE_LIST table_list; SPIDER_BG_DIRECT_SQL *bg_direct_sql; -#if MYSQL_VERSION_ID < 50500 -#else TABLE_LIST *real_table_list_last = NULL; uint use_real_table = 0; -#endif DBUG_ENTER("spider_direct_sql_body"); SPIDER_BACKUP_DASTATUS; if (!(direct_sql = (SPIDER_DIRECT_SQL *) @@ -1580,11 +1538,8 @@ long long spider_direct_sql_body( #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } #endif -#if MYSQL_VERSION_ID < 50500 -#else use_real_table = spider_param_udf_ds_use_real_table(thd, direct_sql->use_real_table); -#endif for (roop_count = 0; roop_count < direct_sql->table_count; roop_count++) { #ifdef SPIDER_NEED_INIT_ONE_TABLE_FOR_FIND_TEMPORARY_TABLE @@ -1615,19 +1570,14 @@ long long spider_direct_sql_body( if (!(direct_sql->tables[roop_count] = spider_find_temporary_table(thd, &table_list))) { -#if MYSQL_VERSION_ID < 50500 -#else if (!use_real_table) { -#endif error_num = ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_NUM; my_printf_error(ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_NUM, ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_STR, MYF(0), SPIDER_TABLE_LIST_db_str(&table_list), SPIDER_TABLE_LIST_table_name_str(&table_list)); goto error; -#if MYSQL_VERSION_ID < 50500 -#else } TABLE_LIST *tables = &direct_sql->table_list[roop_count]; tables->mdl_request.init(MDL_key::TABLE, @@ -1643,7 +1593,6 @@ long long spider_direct_sql_body( real_table_list_last = tables; spider_set_bit(direct_sql->real_table_bitmap, roop_count); direct_sql->real_table_used = TRUE; -#endif } } if ((error_num = spider_udf_direct_sql_create_conn_key(direct_sql))) @@ -1760,22 +1709,14 @@ my_bool spider_direct_sql_init_body( strcpy(message, "spider_bg_direct_sql() out of memory"); goto error; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&bg_direct_sql->bg_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_direct_sql, &bg_direct_sql->bg_mutex, MY_MUTEX_INIT_FAST)) -#endif { strcpy(message, "spider_bg_direct_sql() out of memory"); goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&bg_direct_sql->bg_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_direct_sql, &bg_direct_sql->bg_cond, NULL)) -#endif { strcpy(message, "spider_bg_direct_sql() out of memory"); goto error_cond_init; diff --git a/storage/spider/spd_environ.h b/storage/spider/spd_environ.h index 728cc7e1781..5a6b824fd30 100644 --- a/storage/spider/spd_environ.h +++ b/storage/spider/spd_environ.h @@ -19,16 +19,11 @@ #ifndef SPD_ENVIRON_INCLUDED -#if (defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000) #define SPIDER_HANDLER_START_BULK_INSERT_HAS_FLAGS -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100 #define SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE #define SPIDER_NET_HAS_THD -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100211 #define HANDLER_HAS_TOP_TABLE_FIELDS #define HANDLER_HAS_DIRECT_UPDATE_ROWS #define HANDLER_HAS_DIRECT_AGGREGATE @@ -37,20 +32,13 @@ #define HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN #define HANDLER_HAS_NEED_INFO_FOR_AUTO_INC #define HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100300 #define SPIDER_UPDATE_ROW_HAS_CONST_NEW_DATA -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100309 #define SPIDER_MDEV_16246 -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100400 #define SPIDER_USE_CONST_ITEM_FOR_STRING_INT_REAL_DECIMAL_DATE_ITEM #define SPIDER_SQL_CACHE_IS_IN_LEX #define SPIDER_LIKE_FUNC_HAS_GET_NEGATED #define HA_HAS_CHECKSUM_EXTENDED -#endif #endif /* SPD_ENVIRON_INCLUDED */ diff --git a/storage/spider/spd_group_by_handler.cc b/storage/spider/spd_group_by_handler.cc index 2985c9f1302..167f8c3adff 100644 --- a/storage/spider/spd_group_by_handler.cc +++ b/storage/spider/spd_group_by_handler.cc @@ -17,17 +17,12 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "sql_select.h" #include "ha_partition.h" -#endif #include "sql_common.h" #include #include "spd_err.h" diff --git a/storage/spider/spd_i_s.cc b/storage/spider/spd_i_s.cc index c43c666601f..c4d66f01fb6 100644 --- a/storage/spider/spd_i_s.cc +++ b/storage/spider/spd_i_s.cc @@ -17,16 +17,11 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "sql_show.h" -#endif #include "spd_db_include.h" #include "spd_include.h" #include "spd_table.h" @@ -144,12 +139,9 @@ struct st_mysql_plugin spider_i_s_alloc_mem = NULL, NULL, NULL, -#if MYSQL_VERSION_ID >= 50600 0, -#endif }; -#ifdef MARIADB_BASE_VERSION struct st_maria_plugin spider_i_s_alloc_mem_maria = { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -166,4 +158,3 @@ struct st_maria_plugin spider_i_s_alloc_mem_maria = "1.0", MariaDB_PLUGIN_MATURITY_STABLE, }; -#endif diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 51fac2a4cea..76844b6b428 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -17,11 +17,6 @@ #define SPIDER_DETAIL_VERSION "3.3.15" #define SPIDER_HEX_VERSION 0x0303 -#if MYSQL_VERSION_ID < 50500 -#define spider_my_free(A,B) my_free(A,B) -#define pthread_mutex_assert_owner(A) -#define pthread_mutex_assert_not_owner(A) -#else #define spider_my_free(A,B) my_free(A) #ifdef pthread_mutex_t #undef pthread_mutex_t @@ -70,129 +65,50 @@ #endif #define pthread_cond_destroy mysql_cond_destroy #define my_sprintf(A,B) sprintf B -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100004 #define spider_stmt_da_message(A) thd_get_error_message(A) #define spider_stmt_da_sql_errno(A) thd_get_error_number(A) #define spider_user_defined_key_parts(A) (A)->user_defined_key_parts #define spider_join_table_count(A) (A)->table_count #define SPIDER_CAN_BG_UPDATE (1LL << 39) -#if MYSQL_VERSION_ID >= 100304 #define SPIDER_ALTER_PARTITION_ADD ALTER_PARTITION_ADD #define SPIDER_ALTER_PARTITION_DROP ALTER_PARTITION_DROP #define SPIDER_ALTER_PARTITION_COALESCE ALTER_PARTITION_COALESCE #define SPIDER_ALTER_PARTITION_REORGANIZE ALTER_PARTITION_REORGANIZE #define SPIDER_ALTER_PARTITION_TABLE_REORG ALTER_PARTITION_TABLE_REORG #define SPIDER_ALTER_PARTITION_REBUILD ALTER_PARTITION_REBUILD -#else -#define SPIDER_ALTER_PARTITION_ADD Alter_info::ALTER_ADD_PARTITION -#define SPIDER_ALTER_PARTITION_DROP Alter_info::ALTER_DROP_PARTITION -#define SPIDER_ALTER_PARTITION_COALESCE Alter_info::ALTER_COALESCE_PARTITION -#define SPIDER_ALTER_PARTITION_REORGANIZE Alter_info::ALTER_REORGANIZE_PARTITION -#define SPIDER_ALTER_PARTITION_TABLE_REORG Alter_info::ALTER_TABLE_REORG -#define SPIDER_ALTER_PARTITION_REBUILD Alter_info::ALTER_REBUILD_PARTITION -#endif #define SPIDER_WARN_LEVEL_WARN Sql_condition::WARN_LEVEL_WARN #define SPIDER_WARN_LEVEL_NOTE Sql_condition::WARN_LEVEL_NOTE #define SPIDER_THD_KILL_CONNECTION KILL_CONNECTION -#else -#if MYSQL_VERSION_ID < 50500 -#define spider_stmt_da_message(A) (A)->main_da.message() -#define spider_stmt_da_sql_errno(A) (A)->main_da.sql_errno() -#else -#if MYSQL_VERSION_ID < 50600 -#define spider_stmt_da_message(A) (A)->stmt_da->message() -#define spider_stmt_da_sql_errno(A) (A)->stmt_da->sql_errno() -#else -#define spider_stmt_da_message(A) (A)->get_stmt_da()->message() -#define spider_stmt_da_sql_errno(A) (A)->get_stmt_da()->sql_errno() -#endif -#endif -#define spider_user_defined_key_parts(A) (A)->key_parts -#define spider_join_table_count(A) (A)->tables -#define SPIDER_ALTER_PARTITION_ADD ALTER_ADD_PARTITION -#define SPIDER_ALTER_PARTITION_DROP ALTER_DROP_PARTITION -#define SPIDER_ALTER_PARTITION_COALESCE ALTER_COALESCE_PARTITION -#define SPIDER_ALTER_PARTITION_REORGANIZE ALTER_REORGANIZE_PARTITION -#define SPIDER_ALTER_PARTITION_TABLE_REORG ALTER_TABLE_REORG -#define SPIDER_ALTER_PARTITION_REBUILD ALTER_REBUILD_PARTITION -#define SPIDER_WARN_LEVEL_WARN MYSQL_ERROR::WARN_LEVEL_WARN -#define SPIDER_WARN_LEVEL_NOTE MYSQL_ERROR::WARN_LEVEL_NOTE -#define SPIDER_THD_KILL_CONNECTION THD::KILL_CONNECTION -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100005 #define SPIDER_HAS_EXPLAIN_QUERY -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100009 #define SPIDER_TEST(A) MY_TEST(A) -#else -#define SPIDER_TEST(A) test(A) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100 #define SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR #define SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #define SPIDER_XID_USES_xid_cache_iterate -#else -#define SPIDER_XID_STATE_HAS_in_thd -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100108 #define SPIDER_Item_args_arg_count_IS_PROTECTED -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100112 #define SPIDER_Item_func_conv_charset_conv_charset collation.collation -#else -#define SPIDER_Item_func_conv_charset_conv_charset conv_charset -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200 #define SPIDER_WITHOUT_HA_STATISTIC_INCREMENT #define SPIDER_init_read_record(A,B,C,D,E,F,G,H) init_read_record(A,B,C,D,E,F,G,H) #define SPIDER_HAS_NEXT_THREAD_ID #define SPIDER_new_THD(A) (new THD(A)) #define SPIDER_order_direction_is_asc(A) (A->direction == ORDER::ORDER_ASC) -#else -#define SPIDER_init_read_record(A,B,C,D,E,F,G,H) init_read_record(A,B,C,D,F,G,H) -#define SPIDER_new_THD(A) (new THD()) -#define SPIDER_order_direction_is_asc(A) (A->asc) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100201 #define SPIDER_HAS_MY_CHARLEN #define SPIDER_open_temporary_table -#endif -#if defined(MARIADB_BASE_VERSION) -#if MYSQL_VERSION_ID >= 100209 #define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(A,B,C,E,F,G) -#elif MYSQL_VERSION_ID >= 100200 -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(A,B,C,D,E,F,G,H) -#elif MYSQL_VERSION_ID >= 100007 -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(B,C,D,E,F,G,H) -#else -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(B,C,D,E,F,G) -#endif -#else -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100209 #define SPIDER_create_partition_name(A,B,C,D,E,F) create_partition_name(A,B,C,D,E,F) #define SPIDER_create_subpartition_name(A,B,C,D,E,F) create_subpartition_name(A,B,C,D,E,F) #define SPIDER_free_part_syntax(A,B) -#else -#define SPIDER_create_partition_name(A,B,C,D,E,F) create_partition_name(A,C,D,E,F) -#define SPIDER_create_subpartition_name(A,B,C,D,E,F) create_subpartition_name(A,C,D,E,F) -#define SPIDER_free_part_syntax(A,B) spider_my_free(A,B) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100306 #define SPIDER_read_record_read_record(A) read_record() #define SPIDER_has_Item_with_subquery #define SPIDER_use_LEX_CSTRING_for_KEY_Field_name @@ -211,36 +127,12 @@ #define SPIDER_item_name_str(A) (A)->name.str #define SPIDER_item_name_length(A) (A)->name.length const LEX_CSTRING SPIDER_empty_string = {"", 0}; -#else -#define SPIDER_read_record_read_record(A) read_record(A) -#define SPIDER_THD_db_str(A) (A)->db -#define SPIDER_THD_db_length(A) (A)->db_length -#define SPIDER_TABLE_LIST_db_str(A) (A)->db -#define SPIDER_TABLE_LIST_db_length(A) (A)->db_length -#define SPIDER_TABLE_LIST_table_name_str(A) (A)->table_name -#define SPIDER_TABLE_LIST_table_name_length(A) (A)->table_name_length -#define SPIDER_TABLE_LIST_alias_str(A) (A)->alias -#define SPIDER_TABLE_LIST_alias_length(A) strlen((A)->alias) -#define SPIDER_field_name_str(A) (A)->field_name -#define SPIDER_field_name_length(A) strlen((A)->field_name) -#define SPIDER_item_name_str(A) (A)->name -#define SPIDER_item_name_length(A) strlen((A)->name) -const char SPIDER_empty_string = ""; -#endif -#if MYSQL_VERSION_ID >= 50500 #define SPIDER_HAS_HASH_VALUE_TYPE -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100400 #define SPIDER_date_mode_t(A) date_mode_t(A) #define SPIDER_str_to_datetime(A,B,C,D,E) str_to_datetime_or_date(A,B,C,D,E) #define SPIDER_get_linkage(A) A->get_linkage() -#else -#define SPIDER_date_mode_t(A) A -#define SPIDER_str_to_datetime(A,B,C,D,E) str_to_datetime(A,B,C,D,E) -#define SPIDER_get_linkage(A) A->linkage -#endif #define spider_bitmap_size(A) ((A + 7) / 8) #define spider_set_bit(BITMAP, BIT) \ @@ -1501,8 +1393,6 @@ typedef struct st_spider_direct_sql TABLE **tables; int *iop; -#if MYSQL_VERSION_ID < 50500 -#else /* for using real table */ bool real_table_used; TABLE_LIST *table_list_first; @@ -1510,7 +1400,6 @@ typedef struct st_spider_direct_sql uchar *real_table_bitmap; Open_tables_backup open_tables_backup; THD *open_tables_thd; -#endif char *sql; ulong sql_length; @@ -1530,10 +1419,7 @@ typedef struct st_spider_direct_sql #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) int access_mode; #endif -#if MYSQL_VERSION_ID < 50500 -#else int use_real_table; -#endif int error_rw_mode; char *server_name; diff --git a/storage/spider/spd_malloc.cc b/storage/spider/spd_malloc.cc index f43131d630d..a4aec9a3712 100644 --- a/storage/spider/spd_malloc.cc +++ b/storage/spider/spd_malloc.cc @@ -18,15 +18,10 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_analyse.h" -#endif #include "spd_db_include.h" #include "spd_include.h" #include "spd_malloc.h" diff --git a/storage/spider/spd_param.cc b/storage/spider/spd_param.cc index 5c86af68c0a..ce87afbdee7 100644 --- a/storage/spider/spd_param.cc +++ b/storage/spider/spd_param.cc @@ -38,15 +38,10 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" -#endif #include #include "spd_err.h" #include "spd_db_include.h" @@ -56,9 +51,7 @@ #include "spd_trx.h" extern struct st_mysql_plugin spider_i_s_alloc_mem; -#ifdef MARIADB_BASE_VERSION extern struct st_maria_plugin spider_i_s_alloc_mem_maria; -#endif extern volatile ulonglong spider_mon_table_cache_version; extern volatile ulonglong spider_mon_table_cache_version_req; @@ -231,13 +224,8 @@ struct st_mysql_show_var spider_status_variables[] = }; typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_int_t, int); -#if MYSQL_VERSION_ID < 50500 -extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd, - const char *name, long long val); -#else extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed, bool is_unsignd, longlong v); -#endif static my_bool spider_support_xa; static MYSQL_SYSVAR_BOOL( @@ -700,14 +688,9 @@ static int spider_param_semi_table_lock_check( (long) ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->blk_sz; options.arg_type = REQUIRED_ARG; *((int *) save) = (int) getopt_ll_limit_value(tmp, &options, &fixed); -#if MYSQL_VERSION_ID < 50500 - DBUG_RETURN(throw_bounds_warning(thd, fixed, FALSE, - ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, (long long) tmp)); -#else DBUG_RETURN(throw_bounds_warning(thd, ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE, (longlong) tmp)); -#endif } /* @@ -758,14 +741,9 @@ static int spider_param_semi_table_lock_connection_check( (long) ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->blk_sz; options.arg_type = REQUIRED_ARG; *((int *) save) = (int) getopt_ll_limit_value(tmp, &options, &fixed); -#if MYSQL_VERSION_ID < 50500 - DBUG_RETURN(throw_bounds_warning(thd, fixed, FALSE, - ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, (long long) tmp)); -#else DBUG_RETURN(throw_bounds_warning(thd, ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE, (longlong) tmp)); -#endif } /* @@ -1738,7 +1716,6 @@ SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, udf_ds_table_loop_mode) static char *spider_remote_access_charset; /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_SYSVAR_STR( remote_access_charset, spider_remote_access_charset, @@ -1749,30 +1726,6 @@ static MYSQL_SYSVAR_STR( NULL, NULL ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_SYSVAR_STR( - remote_access_charset, - spider_remote_access_charset, - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Set remote access charset at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#else -static MYSQL_SYSVAR_STR( - remote_access_charset, - spider_remote_access_charset, - PLUGIN_VAR_RQCMDARG, - "Set remote access charset at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#endif -#endif SPIDER_SYSVAR_VALUE_FUNC(char*, remote_access_charset) @@ -1800,7 +1753,6 @@ SPIDER_SYSVAR_VALUE_FUNC(int, remote_autocommit) static char *spider_remote_time_zone; /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_SYSVAR_STR( remote_time_zone, spider_remote_time_zone, @@ -1811,30 +1763,6 @@ static MYSQL_SYSVAR_STR( NULL, NULL ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_SYSVAR_STR( - remote_time_zone, - spider_remote_time_zone, - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Set remote time_zone at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#else -static MYSQL_SYSVAR_STR( - remote_time_zone, - spider_remote_time_zone, - PLUGIN_VAR_RQCMDARG, - "Set remote time_zone at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#endif -#endif SPIDER_SYSVAR_VALUE_FUNC(char *, remote_time_zone) @@ -1885,7 +1813,6 @@ SPIDER_SYSVAR_VALUE_FUNC(int, remote_trx_isolation) static char *spider_remote_default_database; /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_SYSVAR_STR( remote_default_database, spider_remote_default_database, @@ -1896,30 +1823,6 @@ static MYSQL_SYSVAR_STR( NULL, NULL ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_SYSVAR_STR( - remote_default_database, - spider_remote_default_database, - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Set remote database at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#else -static MYSQL_SYSVAR_STR( - remote_default_database, - spider_remote_default_database, - PLUGIN_VAR_RQCMDARG, - "Set remote database at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#endif -#endif SPIDER_SYSVAR_VALUE_FUNC(char *, remote_default_database) @@ -1973,7 +1876,6 @@ int spider_param_connect_retry_count( /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_THDVAR_STR( bka_engine, /* name */ PLUGIN_VAR_MEMALLOC | @@ -1983,28 +1885,6 @@ static MYSQL_THDVAR_STR( NULL, /* update */ NULL /* def */ ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_THDVAR_STR( - bka_engine, /* name */ - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Temporary table's engine for BKA", /* comment */ - NULL, /* check */ - NULL, /* update */ - NULL /* def */ -); -#else -static MYSQL_THDVAR_STR( - bka_engine, /* name */ - PLUGIN_VAR_RQCMDARG, - "Temporary table's engine for BKA", /* comment */ - NULL, /* check */ - NULL, /* update */ - NULL /* def */ -); -#endif -#endif char *spider_param_bka_engine( THD *thd, @@ -2365,8 +2245,6 @@ static MYSQL_SYSVAR_INT( SPIDER_SYSVAR_OVERRIDE_VALUE_FUN(int, bulk_access_free) #endif -#if MYSQL_VERSION_ID < 50500 -#else /* -1 :fallback to default 0 :can not use @@ -2385,7 +2263,6 @@ static MYSQL_THDVAR_INT( ); SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, udf_ds_use_real_table) -#endif static my_bool spider_general_log; static MYSQL_SYSVAR_BOOL( @@ -2950,10 +2827,7 @@ static struct st_mysql_sys_var* spider_system_variables[] = { #ifdef HA_CAN_BULK_ACCESS MYSQL_SYSVAR(bulk_access_free), #endif -#if MYSQL_VERSION_ID < 50500 -#else MYSQL_SYSVAR(udf_ds_use_real_table), -#endif MYSQL_SYSVAR(general_log), MYSQL_SYSVAR(index_hint_pushdown), MYSQL_SYSVAR(max_connections), @@ -2993,14 +2867,11 @@ mysql_declare_plugin(spider) spider_status_variables, spider_system_variables, NULL, -#if MYSQL_VERSION_ID >= 50600 0, -#endif }, spider_i_s_alloc_mem mysql_declare_plugin_end; -#ifdef MARIADB_BASE_VERSION maria_declare_plugin(spider) { MYSQL_STORAGE_ENGINE_PLUGIN, @@ -3019,4 +2890,3 @@ maria_declare_plugin(spider) }, spider_i_s_alloc_mem_maria maria_declare_plugin_end; -#endif diff --git a/storage/spider/spd_param.h b/storage/spider/spd_param.h index 9ffb9e8c278..e4f5fde1110 100644 --- a/storage/spider/spd_param.h +++ b/storage/spider/spd_param.h @@ -371,13 +371,10 @@ int spider_param_bulk_access_free( int bulk_access_free ); #endif -#if MYSQL_VERSION_ID < 50500 -#else int spider_param_udf_ds_use_real_table( THD *thd, int udf_ds_use_real_table ); -#endif my_bool spider_param_general_log(); my_bool spider_param_index_hint_pushdown( THD *thd diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc index 92f5ff9e69f..4d2c826aa28 100644 --- a/storage/spider/spd_ping_table.cc +++ b/storage/spider/spd_ping_table.cc @@ -17,16 +17,11 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "sql_acl.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -326,11 +321,7 @@ int spider_get_ping_table_mon( ) { int error_num; TABLE *table_link_mon = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif char table_key[MAX_KEY_LENGTH]; SPIDER_TABLE_MON *table_mon, *table_mon_prev = NULL; SPIDER_SHARE *tmp_share; @@ -519,11 +510,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( int *error_num ) { TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif char table_key[MAX_KEY_LENGTH]; SPIDER_TABLE_MON_LIST *table_mon_list = NULL; @@ -632,43 +619,26 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( if (tmp_share->link_statuses[0] == SPIDER_LINK_STATUS_NG) table_mon_list->mon_status = SPIDER_LINK_MON_NG; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->caller_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_caller, &table_mon_list->caller_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_caller_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->receptor_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_receptor, &table_mon_list->receptor_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_receptor_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->monitor_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_monitor, &table_mon_list->monitor_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_monitor_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->update_status_mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_update_status, &table_mon_list->update_status_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_update_status_mutex_init; @@ -741,13 +711,8 @@ int spider_get_ping_table_gtid_pos( int error_num, source_link_idx, need_mon; char table_key[MAX_KEY_LENGTH]; TABLE *table_tables, *table_gtid_pos; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup_tables; - Open_tables_state open_tables_backup_gtid_pos; -#else Open_tables_backup open_tables_backup_tables; Open_tables_backup open_tables_backup_gtid_pos; -#endif MEM_ROOT mem_root; long link_status; long monitoring_binlog_pos_at_failing; @@ -899,11 +864,7 @@ int spider_init_ping_table_mon_cache( ) { int error_num, same; TABLE *table_link_mon = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif SPIDER_MON_KEY mon_key; DBUG_ENTER("spider_init_ping_table_mon_cache"); @@ -1101,23 +1062,14 @@ long long spider_ping_table_body( conv_name.init_calc_mem(SPD_MID_PING_TABLE_BODY_1); tmp_str.init_calc_mem(SPD_MID_PING_TABLE_BODY_2); conv_name.length(0); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 server_id = global_system_variables.server_id; -#else - server_id = thd->server_id; -#endif if ( thd->open_tables != 0 || thd->handler_tables_hash.records != 0 || thd->derived_tables != 0 || thd->lock != 0 || -#if MYSQL_VERSION_ID < 50500 - thd->locked_tables != 0 || - thd->prelocked_mode != NON_PRELOCKED -#else thd->locked_tables_list.locked_tables() || thd->locked_tables_mode != LTM_NONE -#endif ) { if (thd->open_tables != 0) { @@ -1140,18 +1092,6 @@ long long spider_ping_table_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), "thd->lock", thd->lock); -#if MYSQL_VERSION_ID < 50500 - } else if (thd->locked_tables != 0) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), - "thd->locked_tables", thd->locked_tables); - } else if (thd->prelocked_mode != NON_PRELOCKED) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), - "thd->prelocked_mode", (longlong) thd->prelocked_mode); -#else } else if (thd->locked_tables_list.locked_tables()) { my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, @@ -1163,7 +1103,6 @@ long long spider_ping_table_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), "thd->locked_tables_mode", (longlong) thd->locked_tables_mode); -#endif } goto error; } diff --git a/storage/spider/spd_sys_table.cc b/storage/spider/spd_sys_table.cc index 10f9fdedd5b..a0440c294c2 100644 --- a/storage/spider/spd_sys_table.cc +++ b/storage/spider/spd_sys_table.cc @@ -17,17 +17,12 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "key.h" #include "sql_base.h" #include "tztime.h" -#endif #include "sql_select.h" #include "spd_err.h" #include "spd_param.h" @@ -121,17 +116,6 @@ inline int spider_delete_sys_table_row(TABLE *table, int record_number = 0, return error_num; } -#if MYSQL_VERSION_ID < 50500 -TABLE *spider_open_sys_table( - THD *thd, - const char *table_name, - int table_name_length, - bool write, - Open_tables_state *open_tables_backup, - bool need_lock, - int *error_num -) -#else TABLE *spider_open_sys_table( THD *thd, const char *table_name, @@ -141,26 +125,11 @@ TABLE *spider_open_sys_table( bool need_lock, int *error_num ) -#endif { TABLE *table; TABLE_LIST tables; -#if MYSQL_VERSION_ID < 50500 - TABLE_SHARE *table_share; - char table_key[MAX_DBKEY_LENGTH]; - uint table_key_length; -#endif DBUG_ENTER("spider_open_sys_table"); -#if MYSQL_VERSION_ID < 50500 - memset(&tables, 0, sizeof(TABLE_LIST)); - SPIDER_TABLE_LIST_db_str(&tables) = (char*)"mysql"; - SPIDER_TABLE_LIST_db_length(&tables) = sizeof("mysql") - 1; - SPIDER_TABLE_LIST_alias_str(&tables) = - SPIDER_TABLE_LIST_table_name_str(&tables) = (char *) table_name; - SPIDER_TABLE_LIST_table_name_length(&tables) = table_name_length; - tables.lock_type = (write ? TL_WRITE : TL_READ); -#else #ifdef SPIDER_use_LEX_CSTRING_for_database_tablename_alias LEX_CSTRING db_name = { @@ -178,18 +147,8 @@ TABLE *spider_open_sys_table( "mysql", sizeof("mysql") - 1, table_name, table_name_length, table_name, (write ? TL_WRITE : TL_READ)); #endif -#endif -#if MYSQL_VERSION_ID < 50500 - if (need_lock) - { -#endif -#if MYSQL_VERSION_ID < 50500 - if (!(table = open_performance_schema_table(thd, &tables, - open_tables_backup))) -#else if (!(table = spider_sys_open_table(thd, &tables, open_tables_backup))) -#endif { my_printf_error(ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM, ER_SPIDER_CANT_OPEN_SYS_TABLE_STR, MYF(0), @@ -197,38 +156,6 @@ TABLE *spider_open_sys_table( *error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM; DBUG_RETURN(NULL); } -#if MYSQL_VERSION_ID < 50500 - } else { - thd->reset_n_backup_open_tables_state(open_tables_backup); - - if (!(table = (TABLE*) spider_malloc(spider_current_trx, SPD_MID_OPEN_SYS_TABLE_1, - sizeof(*table), MYF(MY_WME)))) - { - *error_num = HA_ERR_OUT_OF_MEM; - goto error_malloc; - } - - table_key_length = - create_table_def_key(thd, table_key, &tables, FALSE); - - if (!(table_share = get_table_share(thd, - &tables, table_key, table_key_length, 0, error_num))) - goto error; - if (open_table_from_share(thd, table_share, tables.alias, - (uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX), - READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD, - (uint) HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_FROM_SQL_LAYER, - table, FALSE) - ) { - release_table_share(table_share, RELEASE_NORMAL); - my_printf_error(ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM, - ER_SPIDER_CANT_OPEN_SYS_TABLE_STR, MYF(0), - "mysql", table_name); - *error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM; - goto error; - } - } -#endif switch (table_name_length) { case 9: @@ -370,51 +297,22 @@ TABLE *spider_open_sys_table( } DBUG_RETURN(table); -#if MYSQL_VERSION_ID < 50500 -error: - spider_free(spider_current_trx, table, MYF(0)); -error_malloc: - thd->restore_backup_open_tables_state(open_tables_backup); -#endif error_col_num_chk: DBUG_RETURN(NULL); } -#if MYSQL_VERSION_ID < 50500 -void spider_close_sys_table( - THD *thd, - TABLE *table, - Open_tables_state *open_tables_backup, - bool need_lock -) -#else void spider_close_sys_table( THD *thd, TABLE *table, Open_tables_backup *open_tables_backup, bool need_lock ) -#endif { DBUG_ENTER("spider_close_sys_table"); -#if MYSQL_VERSION_ID < 50500 - if (need_lock) - { - close_performance_schema_table(thd, open_tables_backup); - } else { - table->file->ha_reset(); - closefrm(table, TRUE); - spider_free(spider_current_trx, table, MYF(0)); - thd->restore_backup_open_tables_state(open_tables_backup); - } -#else spider_sys_close_table(thd, open_tables_backup); -#endif DBUG_VOID_RETURN; } -#if MYSQL_VERSION_ID < 50500 -#else bool spider_sys_open_tables( THD *thd, TABLE_LIST **tables, @@ -467,7 +365,6 @@ void spider_sys_close_table( thd->restore_backup_open_tables_state(open_tables_backup); DBUG_VOID_RETURN; } -#endif int spider_sys_index_init( TABLE *table, @@ -512,15 +409,9 @@ int spider_check_sys_table( table->key_info, table->key_info->key_length); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_read_idx_map( table->record[0], 0, (uchar *) table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#else - DBUG_RETURN(table->file->index_read_idx_map( - table->record[0], 0, (uchar *) table_key, - HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#endif } int spider_check_sys_table_with_find_flag( @@ -536,15 +427,9 @@ int spider_check_sys_table_with_find_flag( table->key_info, table->key_info->key_length); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_read_idx_map( table->record[0], 0, (uchar *) table_key, HA_WHOLE_KEY, find_flag)); -#else - DBUG_RETURN(table->file->index_read_idx_map( - table->record[0], 0, (uchar *) table_key, - HA_WHOLE_KEY, find_flag)); -#endif } int spider_check_sys_table_for_update_all_columns( @@ -559,15 +444,9 @@ int spider_check_sys_table_for_update_all_columns( table->key_info, table->key_info->key_length); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_read_idx_map( table->record[1], 0, (uchar *) table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#else - DBUG_RETURN(table->file->index_read_idx_map( - table->record[1], 0, (uchar *) table_key, - HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#endif } /* @@ -607,15 +486,9 @@ int spider_get_sys_table_by_idx( key_length); if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = table->file->ha_index_read_map( table->record[0], (uchar *) table_key, make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#else - (error_num = table->file->index_read_map( - table->record[0], (uchar *) table_key, - make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#endif ) { spider_sys_index_end(table); DBUG_RETURN(error_num); @@ -628,17 +501,10 @@ int spider_sys_index_next_same( char *table_key ) { DBUG_ENTER("spider_sys_index_next_same"); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_next_same( table->record[0], (const uchar*) table_key, table->key_info->key_length)); -#else - DBUG_RETURN(table->file->index_next_same( - table->record[0], - (const uchar*) table_key, - table->key_info->key_length)); -#endif } int spider_sys_index_first( @@ -651,11 +517,7 @@ int spider_sys_index_first( DBUG_RETURN(error_num); if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = table->file->ha_index_first(table->record[0])) -#else - (error_num = table->file->index_first(table->record[0])) -#endif ) { spider_sys_index_end(table); DBUG_RETURN(error_num); @@ -673,11 +535,7 @@ int spider_sys_index_last( DBUG_RETURN(error_num); if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = table->file->ha_index_last(table->record[0])) -#else - (error_num = table->file->index_last(table->record[0])) -#endif ) { spider_sys_index_end(table); DBUG_RETURN(error_num); @@ -689,11 +547,7 @@ int spider_sys_index_next( TABLE *table ) { DBUG_ENTER("spider_sys_index_next"); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_next(table->record[0])); -#else - DBUG_RETURN(table->file->index_next(table->record[0])); -#endif } void spider_store_xa_pk( @@ -1412,11 +1266,6 @@ int spider_log_tables_link_failed( table->use_all_columns(); spider_store_tables_name(table, name, name_length); spider_store_tables_link_idx(table, link_idx); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->field[3] == table->timestamp_field) - table->timestamp_field->set_time(); -#endif if ((error_num = spider_write_sys_table_row(table))) { DBUG_RETURN(error_num); @@ -1449,11 +1298,6 @@ int spider_log_xa_failed( (uint) strlen(status), system_charset_info); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->field[20] == table->timestamp_field) - table->timestamp_field->set_time(); -#endif if ((error_num = spider_write_sys_table_row(table))) { DBUG_RETURN(error_num); @@ -2385,11 +2229,7 @@ int spider_sys_update_tables_link_status( ) { int error_num; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif DBUG_ENTER("spider_sys_update_tables_link_status"); if ( !(table_tables = spider_open_sys_table( @@ -2423,11 +2263,7 @@ int spider_sys_log_tables_link_failed( ) { int error_num; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif DBUG_ENTER("spider_sys_log_tables_link_failed"); if ( !(table_tables = spider_open_sys_table( @@ -2462,11 +2298,7 @@ int spider_sys_log_xa_failed( ) { int error_num; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif DBUG_ENTER("spider_sys_log_xa_failed"); if ( !(table_tables = spider_open_sys_table( @@ -2802,12 +2634,8 @@ int spider_sys_replace( if (table->file->ha_table_flags() & HA_DUPLICATE_POS) { -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = table->file->ha_rnd_pos(table->record[1], table->file->dup_ref); -#else - error_num = table->file->rnd_pos(table->record[1], table->file->dup_ref); -#endif if (error_num) { if (error_num == HA_ERR_RECORD_DELETED) @@ -2820,13 +2648,8 @@ int spider_sys_replace( key_copy((uchar*)table_key, table->record[0], table->key_info + key_num, 0); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = table->file->ha_index_read_idx_map(table->record[1], key_num, (const uchar*)table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT); -#else - error_num = table->file->index_read_idx_map(table->record[1], key_num, - (const uchar*)table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT); -#endif if (error_num) { if (error_num == HA_ERR_RECORD_DELETED) diff --git a/storage/spider/spd_sys_table.h b/storage/spider/spd_sys_table.h index fca38c67683..f0d0d19439e 100644 --- a/storage/spider/spd_sys_table.h +++ b/storage/spider/spd_sys_table.h @@ -68,24 +68,6 @@ public: uint link_id_length; }; -#if MYSQL_VERSION_ID < 50500 -TABLE *spider_open_sys_table( - THD *thd, - const char *table_name, - int table_name_length, - bool write, - Open_tables_state *open_tables_backup, - bool need_lock, - int *error_num -); - -void spider_close_sys_table( - THD *thd, - TABLE *table, - Open_tables_state *open_tables_backup, - bool need_lock -); -#else TABLE *spider_open_sys_table( THD *thd, const char *table_name, @@ -119,7 +101,6 @@ void spider_sys_close_table( THD *thd, Open_tables_backup *open_tables_backup ); -#endif int spider_sys_index_init( TABLE *table, diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 610fbeda1f3..60e1ce6bad2 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -18,10 +18,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "my_getopt.h" @@ -31,7 +27,6 @@ #include "sql_select.h" #include "tztime.h" #include "sql_parse.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -3612,11 +3607,7 @@ int spider_set_connect_info_default( if (share->monitoring_limit[roop_count] == -1) share->monitoring_limit[roop_count] = 1; if (share->monitoring_sid[roop_count] == -1) -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 share->monitoring_sid[roop_count] = global_system_variables.server_id; -#else - share->monitoring_sid[roop_count] = current_thd->server_id; -#endif #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (share->hs_read_ports[roop_count] == -1) @@ -4257,34 +4248,22 @@ SPIDER_SHARE *spider_create_share( if (share->table_count_mode & 2) share->additional_table_flags |= HA_HAS_RECORDS; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share, &share->mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_mutex; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&share->sts_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share_sts, &share->sts_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_sts_mutex; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&share->crd_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share_crd, &share->crd_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_crd_mutex; @@ -4411,11 +4390,7 @@ SPIDER_SHARE *spider_get_share( int semi_table_lock_conn; int search_link_idx; uint sql_command = thd_sql_command(thd); -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif MEM_ROOT mem_root; TABLE *table_tables = NULL; bool init_mem_root = FALSE; @@ -5714,13 +5689,8 @@ SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share( lgtm_tblhnd_share->table_path_hash_value = hash_value; #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&lgtm_tblhnd_share->auto_increment_mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share_auto_increment, &lgtm_tblhnd_share->auto_increment_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_auto_increment_mutex; @@ -5830,35 +5800,22 @@ SPIDER_PARTITION_SHARE *spider_get_pt_share( partition_share->crd_get_time = partition_share->sts_get_time = share->crd_get_time; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&partition_share->sts_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_pt_share_sts, &partition_share->sts_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_sts_mutex; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&partition_share->crd_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_pt_share_crd, &partition_share->crd_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_crd_mutex; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&partition_share->pt_handler_mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_pt_handler, &partition_share->pt_handler_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_pt_handler_mutex; @@ -6012,11 +5969,7 @@ int spider_open_all_tables( long *long_info; longlong *longlong_info; MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif DBUG_ENTER("spider_open_all_tables"); if ( !(table_tables = spider_open_sys_table( @@ -6722,13 +6675,8 @@ int spider_db_init( GetProcAddress(current_module, "?xid_cache@@3PAUst_hash@@A")); #else spd_db_att_LOCK_xid_cache = (pthread_mutex_t *) -#if MYSQL_VERSION_ID < 50500 - GetProcAddress(current_module, - "?LOCK_xid_cache@@3U_RTL_CRITICAL_SECTION@@A"); -#else GetProcAddress(current_module, "?LOCK_xid_cache@@3Ust_mysql_mutex@@A"); -#endif spd_db_att_xid_cache = (HASH *) GetProcAddress(current_module, "?xid_cache@@3Ust_hash@@A"); #endif @@ -6788,117 +6736,61 @@ int spider_db_init( */ #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_tbl_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_tbl, &spider_tbl_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_tbl_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_thread_id_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_thread_id, &spider_thread_id_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_thread_id_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_conn_id_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_conn_id, &spider_conn_id_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_conn_id_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_ipport_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_ipport_count, &spider_ipport_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_ipport_count_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_init_error_tbl, &spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_init_error_tbl_mutex_init; #ifdef WITH_PARTITION_STORAGE_ENGINE -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_pt_share_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_pt_share, &spider_pt_share_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_pt_share_mutex_init; #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_lgtm_tblhnd_share, &spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_lgtm_tblhnd_share_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_conn, &spider_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_conn_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_open_conn, &spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_open_conn_mutex_init; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_hs_r_conn, &spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_hs_r_conn_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_hs_w_conn, &spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_hs_w_conn_mutex_init; #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_allocated_thds, &spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_allocated_thds_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_table_cache, &spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_mon_table_cache_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mem_calc, &spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_mem_calc_mutex_init; if (my_hash_init(&spider_open_tables, spd_charset_utf8_bin, 32, 0, 0, @@ -7011,25 +6903,16 @@ int spider_db_init( roop_count < (int) spider_param_udf_table_mon_mutex_count(); roop_count++) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_udf_table_mon_mutexes[roop_count], - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_udf_table_mon, &spider_udf_table_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST)) -#endif goto error_init_udf_table_mon_mutex; } for (roop_count = 0; roop_count < (int) spider_param_udf_table_mon_mutex_count(); roop_count++) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_udf_table_mon_conds[roop_count], NULL)) -#else if (mysql_cond_init(spd_key_cond_udf_table_mon, &spider_udf_table_mon_conds[roop_count], NULL)) -#endif goto error_init_udf_table_mon_cond; } for (roop_count = 0; @@ -8492,10 +8375,8 @@ bool spider_check_direct_order_limit( spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); bool first_check = TRUE; DBUG_PRINT("info",("spider select_lex=%p", select_lex)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 DBUG_PRINT("info",("spider leaf_tables.elements=%u", select_lex ? select_lex->leaf_tables.elements : 0)); -#endif if (select_lex && (select_lex->options & SELECT_DISTINCT)) { @@ -8508,22 +8389,16 @@ bool spider_check_direct_order_limit( DBUG_PRINT("info",("spider select_limit=%lld", select_limit)); DBUG_PRINT("info",("spider offset_limit=%lld", offset_limit)); if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || #endif -#endif #ifdef SPIDER_NEED_CHECK_CONDITION_AT_CHECKING_DIRECT_ORDER_LIMIT !spider->condition || #endif !select_lex || -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 select_lex->leaf_tables.elements != 1 || -#endif select_lex->table_list.elements != 1 ) { DBUG_PRINT("info",("spider first_check is FALSE")); @@ -8802,14 +8677,10 @@ int spider_set_direct_limit_offset( // contain where if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif spider->condition // conditions is null may be no where condition in rand_init ) @@ -8955,20 +8826,11 @@ ulong spider_calc_for_sort( double spider_rand( uint32 rand_source ) { -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 struct my_rnd_struct rand; -#else - struct rand_struct rand; -#endif DBUG_ENTER("spider_rand"); /* generate same as rand function for applications */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 my_rnd_init(&rand, (uint32) (rand_source * 65537L + 55555555L), (uint32) (rand_source * 268435457L)); -#else - randominit(&rand, (uint32) (rand_source * 65537L + 55555555L), - (uint32) (rand_source * 268435457L)); -#endif DBUG_RETURN(my_rnd(&rand)); } @@ -9499,46 +9361,27 @@ int spider_create_sts_threads( ) { int error_num; DBUG_ENTER("spider_create_sts_threads"); -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_thread->mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_stss, &spider_thread->mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_stss, &spider_thread->cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_sts_syncs, &spider_thread->sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&spider_thread->thread, &spider_pt_attr, - spider_table_bg_sts_action, (void *) spider_thread) - ) -#else if (mysql_thread_create(spd_key_thd_bg_stss, &spider_thread->thread, &spider_pt_attr, spider_table_bg_sts_action, (void *) spider_thread) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; @@ -9586,46 +9429,27 @@ int spider_create_crd_threads( ) { int error_num; DBUG_ENTER("spider_create_crd_threads"); -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_thread->mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_crds, &spider_thread->mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crds, &spider_thread->cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crd_syncs, &spider_thread->sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&spider_thread->thread, &spider_pt_attr, - spider_table_bg_crd_action, (void *) spider_thread) - ) -#else if (mysql_thread_create(spd_key_thd_bg_crds, &spider_thread->thread, &spider_pt_attr, spider_table_bg_crd_action, (void *) spider_thread) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc index 29b5497dd81..bdea13e7d3b 100644 --- a/storage/spider/spd_trx.cc +++ b/storage/spider/spd_trx.cc @@ -18,16 +18,11 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "records.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -1194,13 +1189,8 @@ SPIDER_TRX *spider_get_trx( roop_count < (int) spider_param_udf_table_lock_mutex_count(); roop_count++) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&trx->udf_table_mutexes[roop_count], - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_udf_table, &trx->udf_table_mutexes[roop_count], MY_MUTEX_INIT_FAST)) -#endif goto error_init_udf_table_mutex; } @@ -1898,17 +1888,10 @@ int spider_internal_start_trx( (trx->xid.data, "%lx%016llx", thd_get_thread_id(thd), thd->query_id)); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 trx->xid.bqual_length = my_sprintf(trx->xid.data + trx->xid.gtrid_length, (trx->xid.data + trx->xid.gtrid_length, "%lx", thd->variables.server_id)); -#else - trx->xid.bqual_length - = my_sprintf(trx->xid.data + trx->xid.gtrid_length, - (trx->xid.data + trx->xid.gtrid_length, "%x", - thd->server_id)); -#endif #ifdef SPIDER_XID_STATE_HAS_in_thd trx->internal_xid_state.in_thd = 1; @@ -2018,11 +2001,7 @@ int spider_internal_xa_commit( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_commit"); @@ -2206,11 +2185,7 @@ int spider_internal_xa_rollback( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool server_lost = FALSE; bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; @@ -2448,11 +2423,7 @@ int spider_internal_xa_prepare( int error_num; SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_prepare"); @@ -2623,11 +2594,7 @@ int spider_internal_xa_recover( int cnt = 0; char xa_key[MAX_KEY_LENGTH]; MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif DBUG_ENTER("spider_internal_xa_recover"); /* select @@ -2685,21 +2652,13 @@ int spider_initinal_xa_recover( static THD *thd = NULL; static TABLE *table_xa = NULL; static READ_RECORD *read_record = NULL; -#if MYSQL_VERSION_ID < 50500 - static Open_tables_state *open_tables_backup = NULL; -#else static Open_tables_backup *open_tables_backup = NULL; -#endif int cnt = 0; MEM_ROOT mem_root; DBUG_ENTER("spider_initinal_xa_recover"); if (!open_tables_backup) { -#if MYSQL_VERSION_ID < 50500 - if (!(open_tables_backup = new Open_tables_state)) -#else if (!(open_tables_backup = new Open_tables_backup)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_create_state; @@ -2810,11 +2769,7 @@ int spider_internal_xa_commit_by_xid( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_commit_by_xid"); @@ -3045,11 +3000,7 @@ int spider_internal_xa_rollback_by_xid( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_rollback_by_xid"); @@ -4109,19 +4060,8 @@ THD *spider_create_tmp_thd() DBUG_ENTER("spider_create_tmp_thd"); if (!(thd = SPIDER_new_THD((my_thread_id) 0))) DBUG_RETURN(NULL); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 thd->killed = NOT_KILLED; -#else - thd->killed = THD::NOT_KILLED; -#endif -#if MYSQL_VERSION_ID < 50500 - thd->locked_tables = FALSE; -#endif thd->proc_info = ""; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200 -#else - thd->thread_id = thd->variables.pseudo_thread_id = 0; -#endif thd->thread_stack = (char*) &thd; if (thd->store_globals()) DBUG_RETURN(NULL); @@ -4134,11 +4074,7 @@ void spider_free_tmp_thd( ) { DBUG_ENTER("spider_free_tmp_thd"); thd->cleanup(); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 thd->reset_globals(); -#else - thd->restore_globals(); -#endif delete thd; DBUG_VOID_RETURN; } From 860c1ca9ad90654f5064796e0989f29dd3ac1b59 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 18 Mar 2024 13:11:49 +1100 Subject: [PATCH 15/25] MDEV-33679 Spider group by handler: skip on multiple equalities The spider group by handler is created in JOIN::make_aggr_tables_info(), by which time calls to substitute_for_best_equal_field() should have already removed all the multiple equalities (i.e. Item_equal, with MULT_EQUAL_FUNC func_type). Therefore, if there is still such items, it is deemed as an optimizer bug and should be skipped. --- .../spider/bugfix/r/mdev_33679.result | 27 +++++++++++++++++ .../spider/bugfix/t/mdev_33679.test | 29 +++++++++++++++++++ storage/spider/spd_db_mysql.cc | 22 ++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result new file mode 100644 index 00000000000..0a11fe429cb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result @@ -0,0 +1,27 @@ +# +# MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to () +# +for master_1 +for child2 +for child3 +CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM; +CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM; +SET spider_same_server_link= on; +CREATE TABLE `t1_spider` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) COMMENT='wrapper "mysql",srv "srv", table "t1"' ENGINE=SPIDER; +CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL +, PRIMARY KEY (`a`) USING BTREE +) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER; +INSERT INTO t1_spider VALUES(1,'oooo'); +INSERT INTO t2_spider VALUES(1,1); +SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1; +a c +1 1 +Warnings: +Warning 1815 Internal error: Spider group by handler: Encountered multiple equalities, likely an optimizer bug +drop table t1, t2, t1_spider, t2_spider; +drop server srv; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test new file mode 100644 index 00000000000..eee47a21163 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test @@ -0,0 +1,29 @@ +--echo # +--echo # MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to () +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM; +CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM; +SET spider_same_server_link= on; +CREATE TABLE `t1_spider` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) COMMENT='wrapper "mysql",srv "srv", table "t1"' ENGINE=SPIDER; +CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL +, PRIMARY KEY (`a`) USING BTREE +) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER; +INSERT INTO t1_spider VALUES(1,'oooo'); +INSERT INTO t2_spider VALUES(1,1); +SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1; + +drop table t1, t2, t1_spider, t2_spider; +drop server srv; +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index c239baf636d..a2262956d44 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -5566,6 +5566,17 @@ int spider_db_mbase_util::check_item_func( if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY) DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); break; + case Item_func::MULT_EQUAL_FUNC: + /* If there is still Item_equal by the time of + JOIN::make_aggr_tables_info() where the spider group by handler + is created, it indicates a bug in the optimizer, because there + shouldn't be any. */ + push_warning_printf( + spider->trx->thd, SPIDER_WARN_LEVEL_WARN, ER_INTERNAL_ERROR, + ER_THD(spider->trx->thd, ER_INTERNAL_ERROR), + "Spider group by handler: Encountered multiple equalities, likely " + "an optimizer bug"); + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); default: break; } @@ -6492,6 +6503,17 @@ int spider_db_mbase_util::print_item_func( last_str = SPIDER_SQL_CLOSE_PAREN_STR; last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; break; + case Item_func::MULT_EQUAL_FUNC: + /* If there is still Item_equal by the time of + JOIN::make_aggr_tables_info() where the spider group by handler + is created, it indicates a bug in the optimizer, because there + shouldn't be any. */ + push_warning_printf( + spider->trx->thd, SPIDER_WARN_LEVEL_WARN, ER_INTERNAL_ERROR, + ER_THD(spider->trx->thd, ER_INTERNAL_ERROR), + "Spider group by handler: Encountered multiple equalities, likely " + "an optimizer bug"); + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); default: THD *thd = spider->trx->thd; SPIDER_SHARE *share = spider->share; From e865ef6a04db3d54acd43b748633376f85a6689e Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 25 Mar 2024 14:06:27 +1100 Subject: [PATCH 16/25] MDEV-33742 Remove macro PARTITION_HAS_GET_CHILD_HANDLERS Similar to MDEV-27658. Also fixing the positioning of #ifdef WITH_PARTITION_STORAGE_ENGINE blocks and add missing ones. --- storage/spider/spd_environ.h | 1 - storage/spider/spd_group_by_handler.cc | 30 ++++++-------------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/storage/spider/spd_environ.h b/storage/spider/spd_environ.h index 5a6b824fd30..247b3bc525f 100644 --- a/storage/spider/spd_environ.h +++ b/storage/spider/spd_environ.h @@ -27,7 +27,6 @@ #define HANDLER_HAS_TOP_TABLE_FIELDS #define HANDLER_HAS_DIRECT_UPDATE_ROWS #define HANDLER_HAS_DIRECT_AGGREGATE -#define PARTITION_HAS_GET_CHILD_HANDLERS #define PARTITION_HAS_GET_PART_SPEC #define HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN #define HANDLER_HAS_NEED_INFO_FOR_AUTO_INC diff --git a/storage/spider/spd_group_by_handler.cc b/storage/spider/spd_group_by_handler.cc index 167f8c3adff..2f8f40eaa97 100644 --- a/storage/spider/spd_group_by_handler.cc +++ b/storage/spider/spd_group_by_handler.cc @@ -1433,38 +1433,32 @@ group_by_handler *spider_create_group_by_handler( break; } -#ifdef WITH_PARTITION_STORAGE_ENGINE from = query->from; do { DBUG_PRINT("info",("spider from=%p", from)); ++table_count; +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { DBUG_PRINT("info",("spider partition handler")); -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) partition_info *part_info = from->table->part_info; uint bits = bitmap_bits_set(&part_info->read_partitions); DBUG_PRINT("info",("spider bits=%u", bits)); if (bits != 1) { DBUG_PRINT("info",("spider using multiple partitions is not supported by this feature yet")); -#else - DBUG_PRINT("info",("spider partition is not supported by this feature yet")); -#endif DBUG_RETURN(NULL); -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } -#endif } - } while ((from = from->next_local)); #endif + } while ((from = from->next_local)); if (!(table_holder= spider_create_table_holder(table_count))) DBUG_RETURN(NULL); table_idx = 0; from = query->from; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1473,9 +1467,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1499,7 +1491,7 @@ group_by_handler *spider_create_group_by_handler( } while ((from = from->next_local)) { -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1508,9 +1500,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1541,7 +1531,7 @@ group_by_handler *spider_create_group_by_handler( from = query->from; do { -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1550,9 +1540,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1684,7 +1672,7 @@ group_by_handler *spider_create_group_by_handler( goto skip_free_table_holder; from = query->from; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1693,9 +1681,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1758,7 +1744,7 @@ group_by_handler *spider_create_group_by_handler( { fields->clear_conn_holder_from_conn(); -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1767,9 +1753,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; From f9e0ebeca49b706fa6c8b39d29eb86b57dcf957d Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 8 Apr 2024 14:28:23 +1000 Subject: [PATCH 17/25] MDEV-33742 Do not create group by handler when all tables are constant --- sql/sql_select.cc | 2 +- storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result | 2 -- storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result | 2 -- .../r/partition_join_pushdown_for_single_partition.result | 2 -- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index efcd42be074..af51c3334a8 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3367,7 +3367,7 @@ bool JOIN::make_aggr_tables_info() distinct in the engine, so we do this for all queries, not only GROUP BY queries. */ - if (tables_list && top_join_tab_count && !procedure) + if (tables_list && top_join_tab_count && !only_const_tables() && !procedure) { /* At the moment we only support push down for queries where diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result index edb45e4a62a..5d483481edd 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result @@ -72,7 +72,6 @@ SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; argument select `pkey`,`val` from `auto_test_remote`.`tbl_a` select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 1 -select 1 from (select 1) t0 select `pkey`,`val` from `auto_test_remote`.`tbl_a` select `pkey`,`val` from `auto_test_remote`.`tbl_a` SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' @@ -86,7 +85,6 @@ argument select `pkey`,`val` from `auto_test_remote2`.`tbl_a` select `pkey`,`val` from `auto_test_remote2`.`tbl_a` select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 2 -select 1 from (select 1) t0 select `pkey`,`val` from `auto_test_remote2`.`tbl_a` SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' SELECT pkey, val FROM tbl_a ORDER BY pkey; diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result index 0a11fe429cb..c021bc70e57 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result @@ -18,8 +18,6 @@ INSERT INTO t2_spider VALUES(1,1); SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1; a c 1 1 -Warnings: -Warning 1815 Internal error: Spider group by handler: Encountered multiple equalities, likely an optimizer bug drop table t1, t2, t1_spider, t2_spider; drop server srv; for master_1 diff --git a/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result b/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result index 5026025dfd0..899788ae1c1 100644 --- a/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result +++ b/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result @@ -86,10 +86,8 @@ SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; argument select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5 select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5 -select sum('5') `sum(a.value)`,count('5') `count(b.value2)` from (select 1) t0 join (select 1) t1 select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5 select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5 -select sum('5') `sum(a.value)`,count('5') `count(b.value2)` from (select 1) t0 join (select 1) t1 SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' SELECT value FROM tbl_a ORDER BY value; value From a73c3f1077d3dd46f9a51e53a1666ab76b7d52e0 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 8 Apr 2024 16:35:21 +1000 Subject: [PATCH 18/25] MDEV-21007 Do not assert auto_increment_value unless all parts open Commit 6dce6aecebe6ef78a14cb5c5c5daa8a355551e40 breaks out of a loop in ha_partition::info when some partitions aren't opened, in which case auto_increment_value assertion will fail. This commit patches that hole. --- mysql-test/suite/parts/r/mdev_21007.result | 5 +++++ mysql-test/suite/parts/t/mdev_21007.test | 9 +++++++++ sql/ha_partition.cc | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/parts/r/mdev_21007.result create mode 100644 mysql-test/suite/parts/t/mdev_21007.test diff --git a/mysql-test/suite/parts/r/mdev_21007.result b/mysql-test/suite/parts/r/mdev_21007.result new file mode 100644 index 00000000000..fb2417ac3ae --- /dev/null +++ b/mysql-test/suite/parts/r/mdev_21007.result @@ -0,0 +1,5 @@ +CREATE TABLE t1 (a INT) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (1), PARTITION p1 VALUES LESS THAN (MAXVALUE)); +INSERT INTO t1 VALUES (1),(2); +ALTER TABLE t1 MODIFY a INT AUTO_INCREMENT PRIMARY KEY; +UPDATE t1 PARTITION (p1) SET a=9 ORDER BY a LIMIT 1; +DROP TABLE t1; diff --git a/mysql-test/suite/parts/t/mdev_21007.test b/mysql-test/suite/parts/t/mdev_21007.test new file mode 100644 index 00000000000..ec6fbe4d108 --- /dev/null +++ b/mysql-test/suite/parts/t/mdev_21007.test @@ -0,0 +1,9 @@ +--source include/have_partition.inc + +CREATE TABLE t1 (a INT) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (1), PARTITION p1 VALUES LESS THAN (MAXVALUE)); +INSERT INTO t1 VALUES (1),(2); +ALTER TABLE t1 MODIFY a INT AUTO_INCREMENT PRIMARY KEY; +UPDATE t1 PARTITION (p1) SET a=9 ORDER BY a LIMIT 1; + +# Cleanup +DROP TABLE t1; diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index f0421fa4026..f6acaa8c77e 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -8416,7 +8416,7 @@ int ha_partition::info(uint flag) file->stats.auto_increment_value); } while (*(++file_array)); - DBUG_ASSERT(auto_increment_value); + DBUG_ASSERT(!all_parts_opened || auto_increment_value); stats.auto_increment_value= auto_increment_value; if (all_parts_opened && auto_inc_is_first_in_idx) { From 662bb176b412993a085fe329af559ddc3dc83ec3 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 13 Mar 2024 13:11:15 +1100 Subject: [PATCH 19/25] MDEV-33661 MENT-1591 Keep spider in memory until exit in ASAN builds Same as MDEV-29579. For some reason, libodbc does not clean up properly if unloaded too early with the dlclose() of spider. So we add UNIQUE symbols to spider so the spider does not reload in dlclose(). This change, however, uncovers some hidden problems in the spider codebase, for which we move the initialisation of some spider global variables into the initialisation of spider itself. Spider has some global variables. Their initialisation should be done in the initialisation of spider itself, otherwise, if spider were re-initialised without these symbol being unloaded, the values could be inconsistent and causing issues. One such issue is caused by the variables spider_mon_table_cache_version and spider_mon_table_cache_version_req. They are used for resetting the spider monitoring table cache and have initial values of 0 and 1 respectively. We have that always spider_mon_table_cache_version_req >= spider_mon_table_cache_version, and when the relation is strict, the cache is reset, spider_mon_table_cache_version is brought to be equal to spider_mon_table_cache_version_req, and the cache is searched for matching table_name, db_name and link_idx. If the relation is equal, no reset would happen and the cache would be searched directly. When spider is re-inited without resetting the values of spider_mon_table_cache_version and spider_mon_table_cache_version_req that were set to be equal in the previous cache reset action, the cache was emptied in the previous spider deinit, which would result in HA_ERR_KEY_NOT_FOUND unexpectedly. An alternative way to fix this issue would be to call the spider udf spider_flush_mon_cache_table(), which increments spider_mon_table_cache_version_req thus making sure the inequality is strict. However, there's no reason for spider to initialise these global variables on dlopen(), rather than on spider init, which is cleaner and "purer". To reproduce this issue, simply revert the changes involving the two variables and then run: mtr --no-reorder spider.ha{,_part} --- storage/spider/ha_spider.h | 23 +++++++++++++++++++++++ storage/spider/spd_conn.cc | 4 ++-- storage/spider/spd_db_conn.cc | 2 +- storage/spider/spd_ping_table.cc | 4 ++-- storage/spider/spd_table.cc | 11 +++++++++++ storage/spider/spd_trx.cc | 2 +- 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index f5a597b88a7..3434add965c 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -1219,3 +1219,26 @@ public: int init_union_table_name_pos_sql(); int set_union_table_name_pos_sql(); }; + + +/* This is a hack for ASAN + * Libraries such as libxml2 and libodbc do not like being unloaded before + * exit and will show as a leak in ASAN with no stack trace (as the plugin + * has been unloaded from memory). + * + * The below is designed to trick the compiler into adding a "UNIQUE" symbol + * which can be seen using: + * readelf -s storage/spider/ha_spider.so | grep UNIQUE + * + * Having this symbol means that the plugin remains in memory after dlclose() + * has been called. Thereby letting the libraries clean up properly. + */ +#if defined(__SANITIZE_ADDRESS__) +__attribute__((__used__)) +inline int dummy(void) +{ + static int d; + d++; + return d; +} +#endif diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index be9b27d83ad..b55dc0fd4db 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -53,7 +53,7 @@ extern handlerton *spider_hton_ptr; extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; pthread_mutex_t spider_conn_id_mutex; pthread_mutex_t spider_ipport_conn_mutex; -ulonglong spider_conn_id = 1; +ulonglong spider_conn_id; #ifndef WITHOUT_SPIDER_BG_SEARCH extern pthread_attr_t spider_pt_attr; @@ -93,7 +93,7 @@ extern sql_mode_t pushdown_sql_mode; HASH spider_open_connections; uint spider_open_connections_id; HASH spider_ipport_conns; -long spider_conn_mutex_id = 0; +long spider_conn_mutex_id; const char *spider_open_connections_func_name; const char *spider_open_connections_file_name; diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 40dc15a2149..fd10c7cee8b 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -67,7 +67,7 @@ pthread_mutex_t spider_open_conn_mutex; const char spider_dig_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /* UTC time zone for timestamp columns */ -Time_zone *UTC = 0; +Time_zone *UTC; int spider_db_connect( const SPIDER_SHARE *share, diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc index 4d2c826aa28..1f5230829c3 100644 --- a/storage/spider/spd_ping_table.cc +++ b/storage/spider/spd_ping_table.cc @@ -74,10 +74,10 @@ ulong spider_mon_table_cache_line_no; greater than spider_mon_table_cache_version_req. When the inequality is strict, an initialisation of spider_mon_table_cache will be triggered. */ -volatile ulonglong spider_mon_table_cache_version = 0; +volatile ulonglong spider_mon_table_cache_version; /* The required mon table cache version, incremented by one by the udf spider_flush_table_mon_cache */ -volatile ulonglong spider_mon_table_cache_version_req = 1; +volatile ulonglong spider_mon_table_cache_version_req; /* Get or create a `SPIDER_TABLE_MON_LIST' for a key `str' */ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 60e1ce6bad2..c1435e0216e 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -139,6 +139,11 @@ extern SPIDER_DBTON spider_dbton_oracle; SPIDER_THREAD *spider_table_sts_threads; SPIDER_THREAD *spider_table_crd_threads; #endif +extern volatile ulonglong spider_mon_table_cache_version; +extern volatile ulonglong spider_mon_table_cache_version_req; +extern ulonglong spider_conn_id; +extern Time_zone *UTC; +extern ulonglong spider_thread_id; #ifdef HAVE_PSI_INTERFACE PSI_mutex_key spd_key_mutex_tbl; @@ -6614,6 +6619,12 @@ int spider_db_init( handlerton *spider_hton = (handlerton *)p; DBUG_ENTER("spider_db_init"); + spider_mon_table_cache_version= 0; + spider_mon_table_cache_version_req= 1; + spider_conn_id= 1; + spider_conn_mutex_id= 0; + UTC = 0; + spider_thread_id = 1; const LEX_CSTRING aria_name={STRING_WITH_LEN("Aria")}; if (!plugin_is_ready(&aria_name, MYSQL_STORAGE_ENGINE_PLUGIN)) DBUG_RETURN(HA_ERR_RETRY_INIT); diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc index bdea13e7d3b..7a92a6e3f17 100644 --- a/storage/spider/spd_trx.cc +++ b/storage/spider/spd_trx.cc @@ -49,7 +49,7 @@ extern struct charset_info_st *spd_charset_utf8_bin; extern handlerton *spider_hton_ptr; extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; pthread_mutex_t spider_thread_id_mutex; -ulonglong spider_thread_id = 1; +ulonglong spider_thread_id; #ifdef HAVE_PSI_INTERFACE extern PSI_mutex_key spd_key_mutex_udf_table; From d8249775980f9a6cb1a85e4799e1c1be452c2f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 10 Apr 2024 09:47:44 +0300 Subject: [PATCH 20/25] MDEV-33512 Corrupted table after IMPORT TABLESPACE and restart In commit d74d95961a31b47986d943216489513896108782 (MDEV-18543) there was an error that would cause the hidden metadata record to be deleted, and therefore cause the table to appear corrupted when it is reloaded into the data dictionary cache. PageConverter::update_records(): Do not delete the metadata record, but do validate it. RecIterator::open(): Make the API more similar to 10.6, to simplify merges. --- .../innodb/r/instant_alter_import.result | 1 + .../suite/innodb/t/instant_alter_import.test | 1 + storage/innobase/row/row0import.cc | 46 +++++++++++++++---- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/innodb/r/instant_alter_import.result b/mysql-test/suite/innodb/r/instant_alter_import.result index 9a20ed606bd..55a49e81057 100644 --- a/mysql-test/suite/innodb/r/instant_alter_import.result +++ b/mysql-test/suite/innodb/r/instant_alter_import.result @@ -61,6 +61,7 @@ alter table t1 discard tablespace; flush tables t2 for export; unlock tables; alter table t1 import tablespace; +# restart select * from t1; z 42 diff --git a/mysql-test/suite/innodb/t/instant_alter_import.test b/mysql-test/suite/innodb/t/instant_alter_import.test index 7bd5645436c..50eda83f4b0 100644 --- a/mysql-test/suite/innodb/t/instant_alter_import.test +++ b/mysql-test/suite/innodb/t/instant_alter_import.test @@ -79,6 +79,7 @@ flush tables t2 for export; unlock tables; alter table t1 import tablespace; +--source include/restart_mysqld.inc select * from t1; drop table t2; diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc index a029873da90..b47333113aa 100644 --- a/storage/innobase/row/row0import.cc +++ b/storage/innobase/row/row0import.cc @@ -252,13 +252,13 @@ public: } /** Position the cursor on the first user record. */ - void open(buf_block_t* block) UNIV_NOTHROW + rec_t* open(buf_block_t* block, const dict_index_t* index) noexcept + MY_ATTRIBUTE((warn_unused_result)) { + m_cur.index = const_cast(index); page_cur_set_before_first(block, &m_cur); - - if (!end()) { - next(); - } + next(); + return page_cur_get_rec(&m_cur); } /** Move to the next record. */ @@ -1848,12 +1848,39 @@ PageConverter::update_records( bool clust_index = m_index->m_srv_index == m_cluster_index; /* This will also position the cursor on the first user record. */ + rec_t* rec = m_rec_iter.open(block, m_index->m_srv_index); - m_rec_iter.open(block); + if (!rec) { + return DB_CORRUPTION; + } + + ulint deleted; + + if (!page_has_prev(block->frame) + && m_index->m_srv_index->is_instant()) { + /* Expect to find the hidden metadata record */ + if (page_rec_is_supremum(rec)) { + return DB_CORRUPTION; + } + + const ulint info_bits = rec_get_info_bits(rec, comp); + + if (!(info_bits & REC_INFO_MIN_REC_FLAG)) { + return DB_CORRUPTION; + } + + if (!(info_bits & REC_INFO_DELETED_FLAG) + != !m_index->m_srv_index->table->instant) { + return DB_CORRUPTION; + } + + deleted = 0; + goto first; + } while (!m_rec_iter.end()) { - rec_t* rec = m_rec_iter.current(); - ibool deleted = rec_get_deleted_flag(rec, comp); + rec = m_rec_iter.current(); + deleted = rec_get_deleted_flag(rec, comp); /* For the clustered index we have to adjust the BLOB reference and the system fields irrespective of the @@ -1861,6 +1888,7 @@ PageConverter::update_records( cluster records is required for purge to work later. */ if (deleted || clust_index) { +first: m_offsets = rec_get_offsets( rec, m_index->m_srv_index, m_offsets, m_index->m_srv_index->n_core_fields, @@ -3158,7 +3186,7 @@ static size_t get_buf_size() ; } -/* find, parse instant metadata, performing variaous checks, +/* find, parse instant metadata, performing various checks, and apply it to dict_table_t @return DB_SUCCESS or some error */ static dberr_t handle_instant_metadata(dict_table_t *table, From d7fc975cfe3326c7cdbc188250a8a0bed9d9968d Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Tue, 2 Apr 2024 20:45:29 +0300 Subject: [PATCH 21/25] MDEV-33802 Weird read view after ROLLBACK of other transactions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the case if some unique key fields are nullable, there can be several records with the same key fields in unique index with at least one key field equal to NULL, as NULL != NULL. When transaction is resumed after waiting on the record with at least one key field equal to NULL, and stored in persistent cursor record is deleted, persistent cursor can be restored to the record with all key fields equal to the stored ones, but with at least one field equal to NULL. And such record is wrongly treated as a record with the same unique key as stored in persistent cursor record one, what is wrong as NULL != NULL. The fix is to check if at least one unique field is NULL in restored persistent cursor position, and, if so, then don't treat the record as one with the same unique key as in the stored record key. dict_index_t::nulls_equal was removed, as it was initially developed for never existed in MariaDB "intrinsic tables", and there is no code, which would set it to "true". Reviewed by Marko Mäkelä. --- .../r/cursor-restore-unique-null.result | 24 +++++++++++++ .../innodb/t/cursor-restore-unique-null.test | 36 +++++++++++++++++++ storage/innobase/btr/btr0pcur.cc | 11 ++++-- storage/innobase/dict/dict0dict.cc | 1 - storage/innobase/include/data0data.h | 13 +++---- storage/innobase/include/data0data.inl | 30 ++++++---------- storage/innobase/include/dict0mem.h | 2 -- storage/innobase/include/dict0mem.inl | 1 - storage/innobase/row/row0ins.cc | 14 ++------ 9 files changed, 87 insertions(+), 45 deletions(-) create mode 100644 mysql-test/suite/innodb/r/cursor-restore-unique-null.result create mode 100644 mysql-test/suite/innodb/t/cursor-restore-unique-null.test diff --git a/mysql-test/suite/innodb/r/cursor-restore-unique-null.result b/mysql-test/suite/innodb/r/cursor-restore-unique-null.result new file mode 100644 index 00000000000..b5e2de88e7a --- /dev/null +++ b/mysql-test/suite/innodb/r/cursor-restore-unique-null.result @@ -0,0 +1,24 @@ +CREATE TABLE t(a INT PRIMARY KEY, b INT, c INT, UNIQUE KEY `b_c` (`b`,`c`)) +ENGINE=InnoDB, STATS_PERSISTENT=0; +INSERT INTO t SET a = 1, c = 2; +connect con1,localhost,root; +BEGIN; +INSERT INTO t SET a=2, c=2; +connection default; +BEGIN; +SET DEBUG_SYNC="lock_wait_suspend_thread_enter SIGNAL select_locked"; +SELECT * FROM t FORCE INDEX(b) FOR UPDATE; +connection con1; +SET DEBUG_SYNC="now WAIT_FOR select_locked"; +ROLLBACK; +connection default; +# If the bug is not fixed, and the both unique index key fields are +# NULL, there will be two (1, NULL, 2) rows in the result, +# because cursor will be restored to (NULL, 2, 1) position for +# secondary key instead of "supremum". +a b c +1 NULL 2 +COMMIT; +SET DEBUG_SYNC="RESET"; +disconnect con1; +DROP TABLE t; diff --git a/mysql-test/suite/innodb/t/cursor-restore-unique-null.test b/mysql-test/suite/innodb/t/cursor-restore-unique-null.test new file mode 100644 index 00000000000..c22ddf89d8f --- /dev/null +++ b/mysql-test/suite/innodb/t/cursor-restore-unique-null.test @@ -0,0 +1,36 @@ +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc +--source include/count_sessions.inc + + +CREATE TABLE t(a INT PRIMARY KEY, b INT, c INT, UNIQUE KEY `b_c` (`b`,`c`)) + ENGINE=InnoDB, STATS_PERSISTENT=0; +INSERT INTO t SET a = 1, c = 2; + +--connect con1,localhost,root +BEGIN; + INSERT INTO t SET a=2, c=2; + +--connection default +BEGIN; +SET DEBUG_SYNC="lock_wait_suspend_thread_enter SIGNAL select_locked"; +--send SELECT * FROM t FORCE INDEX(b) FOR UPDATE + +--connection con1 +SET DEBUG_SYNC="now WAIT_FOR select_locked"; +ROLLBACK; + +--connection default +--echo # If the bug is not fixed, and the both unique index key fields are +--echo # NULL, there will be two (1, NULL, 2) rows in the result, +--echo # because cursor will be restored to (NULL, 2, 1) position for +--echo # secondary key instead of "supremum". +--reap +COMMIT; + +SET DEBUG_SYNC="RESET"; + +--disconnect con1 +DROP TABLE t; +--source include/wait_until_count_sessions.inc diff --git a/storage/innobase/btr/btr0pcur.cc b/storage/innobase/btr/btr0pcur.cc index 90084ef4379..4296d94fe5e 100644 --- a/storage/innobase/btr/btr0pcur.cc +++ b/storage/innobase/btr/btr0pcur.cc @@ -453,8 +453,15 @@ btr_pcur_t::restore_position(ulint restore_latch_mode, const char *file, return SAME_ALL; } - if (n_matched_fields >= index->n_uniq) - ret_val= SAME_UNIQ; + if (n_matched_fields >= index->n_uniq + /* Unique indexes can contain "NULL" keys, and if all + unique fields are NULL and not all tuple + fields match to record fields, then treat it as if + restored cursor position points to the record with + not the same unique key. */ + && !(index->n_nullable + && dtuple_contains_null(tuple, index->n_uniq))) + ret_val= SAME_UNIQ; } mem_heap_free(heap); diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index d0f8ac21dd8..26671d85b3d 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -1849,7 +1849,6 @@ dict_index_add_to_cache( new_index->n_fields = new_index->n_def; new_index->trx_id = index->trx_id; new_index->set_committed(index->is_committed()); - new_index->nulls_equal = index->nulls_equal; #ifdef MYSQL_INDEX_DISABLE_AHI new_index->disable_ahi = index->disable_ahi; #endif diff --git a/storage/innobase/include/data0data.h b/storage/innobase/include/data0data.h index c2b8c3e00b6..a2c39ecaed8 100644 --- a/storage/innobase/include/data0data.h +++ b/storage/innobase/include/data0data.h @@ -349,15 +349,12 @@ dtuple_set_types_binary( dtuple_t* tuple, /*!< in: data tuple */ ulint n) /*!< in: number of fields to set */ MY_ATTRIBUTE((nonnull)); -/**********************************************************************//** -Checks if a dtuple contains an SQL null value. -@return TRUE if some field is SQL null */ +/** Checks if a dtuple contains an SQL null value. +@param tuple tuple +@param fields_number number of fields in the tuple to check +@return true if some field is SQL null */ UNIV_INLINE -ibool -dtuple_contains_null( -/*=================*/ - const dtuple_t* tuple) /*!< in: dtuple */ - MY_ATTRIBUTE((nonnull, warn_unused_result)); +bool dtuple_contains_null(const dtuple_t *tuple, ulint fields_number = 0); /**********************************************************//** Checks that a data field is typed. Asserts an error if not. @return TRUE if ok */ diff --git a/storage/innobase/include/data0data.inl b/storage/innobase/include/data0data.inl index 39ade7b1e09..f4ae7528d3f 100644 --- a/storage/innobase/include/data0data.inl +++ b/storage/innobase/include/data0data.inl @@ -599,28 +599,18 @@ data_write_sql_null( memset(data, 0, len); } -/**********************************************************************//** -Checks if a dtuple contains an SQL null value. -@return TRUE if some field is SQL null */ +/** Checks if a dtuple contains an SQL null value. +@param tuple tuple +@param fields_number number of fields in the tuple to check +@return true if some field is SQL null */ UNIV_INLINE -ibool -dtuple_contains_null( -/*=================*/ - const dtuple_t* tuple) /*!< in: dtuple */ +bool dtuple_contains_null(const dtuple_t *tuple, ulint fields_number) { - ulint n; - ulint i; - - n = dtuple_get_n_fields(tuple); - - for (i = 0; i < n; i++) { - if (dfield_is_null(dtuple_get_nth_field(tuple, i))) { - - return(TRUE); - } - } - - return(FALSE); + ulint n= fields_number ? fields_number : dtuple_get_n_fields(tuple); + for (ulint i= 0; i < n; i++) + if (dfield_is_null(dtuple_get_nth_field(tuple, i))) + return true; + return false; } /**************************************************************//** diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index f0d4eb7bebf..d81bbb51b43 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -1011,8 +1011,6 @@ struct dict_index_t { /*!< number of columns the user defined to be in the index: in the internal representation we add more columns */ - unsigned nulls_equal:1; - /*!< if true, SQL NULL == SQL NULL */ #ifdef BTR_CUR_HASH_ADAPT #ifdef MYSQL_INDEX_DISABLE_AHI unsigned disable_ahi:1; diff --git a/storage/innobase/include/dict0mem.inl b/storage/innobase/include/dict0mem.inl index 090ec73278b..28900c9062f 100644 --- a/storage/innobase/include/dict0mem.inl +++ b/storage/innobase/include/dict0mem.inl @@ -63,7 +63,6 @@ dict_mem_fill_index_struct( index->n_core_fields = (unsigned int) n_fields; /* The '1 +' above prevents allocation of an empty mem block */ - index->nulls_equal = false; #ifdef BTR_CUR_HASH_ADAPT #ifdef MYSQL_INDEX_DISABLE_AHI index->disable_ahi = false; diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 088981e5b5b..6e68f46825a 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -2038,7 +2038,7 @@ row_ins_dupl_error_with_rec( /* In a unique secondary index we allow equal key values if they contain SQL NULLs */ - if (!dict_index_is_clust(index) && !index->nulls_equal) { + if (!dict_index_is_clust(index)) { for (i = 0; i < n_unique; i++) { if (dfield_is_null(dtuple_get_nth_field(entry, i))) { @@ -2143,16 +2143,8 @@ row_ins_scan_sec_index_for_duplicate( /* If the secondary index is unique, but one of the fields in the n_unique first fields is NULL, a unique key violation cannot occur, since we define NULL != NULL in this case */ - - if (!index->nulls_equal) { - for (ulint i = 0; i < n_unique; i++) { - if (UNIV_SQL_NULL == dfield_get_len( - dtuple_get_nth_field(entry, i))) { - - DBUG_RETURN(DB_SUCCESS); - } - } - } + if (index->n_nullable && dtuple_contains_null(entry, n_unique)) + DBUG_RETURN(DB_SUCCESS); /* Store old value on n_fields_cmp */ From 99dc0f030f049ba41e19f31d82734a96a1082da0 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 20 Mar 2024 17:23:49 +1100 Subject: [PATCH 22/25] MDEV-28993 spider: revert removal of ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC It was done in MDEV-29447. --- storage/spider/spd_db_mysql.cc | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index a2262956d44..2691f62a5c1 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -5548,7 +5548,9 @@ int spider_db_mbase_util::check_item_func( { case Item_func::TRIG_COND_FUNC: case Item_func::CASE_SEARCHED_FUNC: +#ifndef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC case Item_func::CASE_SIMPLE_FUNC: +#endif DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); case Item_func::NOT_FUNC: /* Why the following check is necessary? */ @@ -6488,7 +6490,70 @@ int spider_db_mbase_util::print_item_func( DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); case Item_func::CASE_SEARCHED_FUNC: case Item_func::CASE_SIMPLE_FUNC: +#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC + Item_func_case *item_func_case = (Item_func_case *) item_func; + if (str) + { + if (str->reserve(SPIDER_SQL_CASE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN); + } + if (item_func_case->first_expr_num != -1) + { + if ((error_num = spider_db_print_item_type( + item_list[item_func_case->first_expr_num], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + } + for (roop_count = 0; roop_count < item_func_case->ncases; + roop_count += 2) + { + if (str) + { + if (str->reserve(SPIDER_SQL_WHEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[roop_count], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(SPIDER_SQL_THEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[roop_count + 1], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + } + if (item_func_case->else_expr_num != -1) + { + if (str) + { + if (str->reserve(SPIDER_SQL_ELSE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[item_func_case->else_expr_num], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + } + if (str) + { + if (str->reserve(SPIDER_SQL_END_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_END_STR, SPIDER_SQL_END_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); +#else DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); +#endif case Item_func::JSON_EXTRACT_FUNC: func_name = (char*) item_func->func_name(); func_name_length = strlen(func_name); From 18b93d6eb074ab183e08ed0da0d9106017aa648d Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 20 Mar 2024 17:20:39 +1100 Subject: [PATCH 23/25] MDEV-28993 Spider: Push down CASE statement --- .../spider/bugfix/r/mdev_27172.result | 6 +- .../spider/feature/r/pushdown_case.result | 57 +++++++++++++++++++ .../spider/feature/t/pushdown_case.test | 50 ++++++++++++++++ storage/spider/spd_db_include.h | 3 - storage/spider/spd_db_mysql.cc | 57 +++++++++++-------- 5 files changed, 143 insertions(+), 30 deletions(-) create mode 100644 storage/spider/mysql-test/spider/feature/r/pushdown_case.result create mode 100644 storage/spider/mysql-test/spider/feature/t/pushdown_case.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result index d4c8c7e8ec2..1be2b98964a 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result @@ -66,9 +66,9 @@ id greeting connection child2_1; SELECT argument FROM mysql.general_log WHERE argument LIKE 'select %'; argument -select `id`,`greeting` from `auto_test_remote`.`tbl_a` where `greeting` = 'Aloha!' and ((`greeting` = 'Aloha!')) -select `id`,`greeting` from `auto_test_remote`.`tbl_b` where `greeting` like 'Aloha%' and ((`greeting` = 'Aloha!')) -select `id`,`greeting` from `auto_test_remote`.`tbl_c` where `greeting` like 'Aloha%' and ((`greeting` = 'Aloha!')) +select t0.`id` `id`,t0.`greeting` `greeting` from `auto_test_remote`.`tbl_a` t0 where ((t0.`greeting` = 'Aloha!') and ((case t0.`greeting` when 'Aloha!' then _latin1'one' else _latin1'more' end) = _latin1'one')) +select t0.`id` `id`,t0.`greeting` `greeting` from `auto_test_remote`.`tbl_b` t0 where ((t0.`greeting` = 'Aloha!') and ((case t0.`greeting` when 'Aloha!' then _latin1'one' else _latin1'more' end) = _latin1'one')) +select t0.`id` `id`,t0.`greeting` `greeting` from `auto_test_remote`.`tbl_c` t0 where ((t0.`greeting` = 'Aloha!') and ((case t0.`greeting` when 'Aloha!' then _latin1'one' else _latin1'more' end) = _latin1'one')) SELECT argument FROM mysql.general_log WHERE argument LIKE 'select %' connection child2_1; SET @@global.general_log = @general_log_backup; diff --git a/storage/spider/mysql-test/spider/feature/r/pushdown_case.result b/storage/spider/mysql-test/spider/feature/r/pushdown_case.result new file mode 100644 index 00000000000..613ce377865 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/r/pushdown_case.result @@ -0,0 +1,57 @@ +# +# MDEV-28993 Spider: Push down CASE statement +# +for master_1 +for child2 +for child3 +set spider_same_server_link= 1; +CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +create table t2 (c int); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +insert into t1 values (42), (3), (848), (100); +explain select case c when 3 then "three" when 42 then "answer" else "other" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case c when 3 then "three" when 42 then "answer" else "other" end from t1; +case c when 3 then "three" when 42 then "answer" else "other" end +answer +three +other +other +explain select case c when 3 then "three" when 42 then "answer" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case c when 3 then "three" when 42 then "answer" end from t1; +case c when 3 then "three" when 42 then "answer" end +answer +three +NULL +NULL +explain select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1; +case when c = 3 then "three" when c = 42 then "answer" else "other" end +answer +three +other +other +explain select case when c = 3 then "three" when c = 42 then "answer" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case when c = 3 then "three" when c = 42 then "answer" end from t1; +case when c = 3 then "three" when c = 42 then "answer" end +answer +three +NULL +NULL +drop table t1, t2; +drop server srv; +for master_1 +for child2 +for child3 +# +# end of test pushdown_case +# diff --git a/storage/spider/mysql-test/spider/feature/t/pushdown_case.test b/storage/spider/mysql-test/spider/feature/t/pushdown_case.test new file mode 100644 index 00000000000..b86edceb615 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/pushdown_case.test @@ -0,0 +1,50 @@ +--echo # +--echo # MDEV-28993 Spider: Push down CASE statement +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +set spider_same_server_link= 1; +evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +create table t2 (c int); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +insert into t1 values (42), (3), (848), (100); + +# everything +let $query= +select case c when 3 then "three" when 42 then "answer" else "other" end from t1; +eval explain $query; +eval $query; + +# no else +let $query= +select case c when 3 then "three" when 42 then "answer" end from t1; +eval explain $query; +eval $query; + +# no value +let $query= +select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1; +eval explain $query; +eval $query; + +# neither +let $query= +select case when c = 3 then "three" when c = 42 then "answer" end from t1; +eval explain $query; +eval $query; + +drop table t1, t2; +drop server srv; +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--echo # +--echo # end of test pushdown_case +--echo # diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index 20bd82e48da..7c07b6998d4 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -25,7 +25,6 @@ #define PLUGIN_VAR_CAN_MEMALLOC /* -#define ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC #define HASH_UPDATE_WITH_HASH_VALUE */ @@ -106,7 +105,6 @@ typedef st_spider_result SPIDER_RESULT; #define SPIDER_SQL_HS_LTEQUAL_STR "<=" #define SPIDER_SQL_HS_LTEQUAL_LEN (sizeof(SPIDER_SQL_HS_LTEQUAL_STR) - 1) -#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC #define SPIDER_SQL_CASE_STR "case " #define SPIDER_SQL_CASE_LEN (sizeof(SPIDER_SQL_CASE_STR) - 1) #define SPIDER_SQL_WHEN_STR " when " @@ -117,7 +115,6 @@ typedef st_spider_result SPIDER_RESULT; #define SPIDER_SQL_ELSE_LEN (sizeof(SPIDER_SQL_ELSE_STR) - 1) #define SPIDER_SQL_END_STR " end" #define SPIDER_SQL_END_LEN (sizeof(SPIDER_SQL_END_STR) - 1) -#endif #define SPIDER_SQL_USING_STR " using " #define SPIDER_SQL_USING_LEN (sizeof(SPIDER_SQL_USING_STR) - 1) diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 2691f62a5c1..2624190f432 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -5547,10 +5547,6 @@ int spider_db_mbase_util::check_item_func( switch (func_type) { case Item_func::TRIG_COND_FUNC: - case Item_func::CASE_SEARCHED_FUNC: -#ifndef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC - case Item_func::CASE_SIMPLE_FUNC: -#endif DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); case Item_func::NOT_FUNC: /* Why the following check is necessary? */ @@ -5620,15 +5616,15 @@ int spider_db_mbase_util::print_item_func( Item *item, **item_list = item_func->arguments(); Field *field; spider_string tmp_str; - uint roop_count, item_count = item_func->argument_count(), start_item = 0; + uint i, item_count = item_func->argument_count(), start_item = 0; const char *func_name = SPIDER_SQL_NULL_CHAR_STR, *separator_str = SPIDER_SQL_NULL_CHAR_STR, *last_str = SPIDER_SQL_NULL_CHAR_STR; int func_name_length = SPIDER_SQL_NULL_CHAR_LEN, separator_str_length = SPIDER_SQL_NULL_CHAR_LEN, last_str_length = SPIDER_SQL_NULL_CHAR_LEN; - int use_pushdown_udf; - bool merge_func = FALSE; + int use_pushdown_udf, case_when_start, case_when_count; + bool merge_func = FALSE, case_with_else; DBUG_ENTER("spider_db_mbase_util::print_item_func"); DBUG_ASSERT(!check_item_func(item_func, spider, alias, alias_length, use_fields, fields)); @@ -6490,23 +6486,39 @@ int spider_db_mbase_util::print_item_func( DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); case Item_func::CASE_SEARCHED_FUNC: case Item_func::CASE_SIMPLE_FUNC: -#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC - Item_func_case *item_func_case = (Item_func_case *) item_func; + /* + Arrangement of arguments: + - Item_func_case_searched: + when1 when2 ... whenk then1 then2 .. thenk [else] + - Item_func_case_simple: + value when1 when2 ... whenk then1 then2 .. thenk [else] + */ + if (item_func->functype() == Item_func::CASE_SEARCHED_FUNC) + { + case_when_start= 0; + case_when_count= item_count / 2; + case_with_else= item_count % 2; + } + else + { + case_when_start= 1; + case_when_count= (item_count - 1) / 2; + case_with_else= item_count % 2 == 0; + } if (str) { if (str->reserve(SPIDER_SQL_CASE_LEN)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN); } - if (item_func_case->first_expr_num != -1) + if (case_when_start > 0) { if ((error_num = spider_db_print_item_type( - item_list[item_func_case->first_expr_num], NULL, spider, str, + item_list[0], NULL, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); } - for (roop_count = 0; roop_count < item_func_case->ncases; - roop_count += 2) + for (i = 0; i < (uint) case_when_count; i++) { if (str) { @@ -6515,7 +6527,7 @@ int spider_db_mbase_util::print_item_func( str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN); } if ((error_num = spider_db_print_item_type( - item_list[roop_count], NULL, spider, str, + item_list[i + case_when_start], NULL, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); if (str) @@ -6525,11 +6537,11 @@ int spider_db_mbase_util::print_item_func( str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN); } if ((error_num = spider_db_print_item_type( - item_list[roop_count + 1], NULL, spider, str, + item_list[i + case_when_start + case_when_count], NULL, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); } - if (item_func_case->else_expr_num != -1) + if (case_with_else) { if (str) { @@ -6538,7 +6550,7 @@ int spider_db_mbase_util::print_item_func( str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN); } if ((error_num = spider_db_print_item_type( - item_list[item_func_case->else_expr_num], NULL, spider, str, + item_list[item_count - 1], NULL, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); } @@ -6551,9 +6563,6 @@ int spider_db_mbase_util::print_item_func( SPIDER_SQL_CLOSE_PAREN_LEN); } DBUG_RETURN(0); -#else - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); -#endif case Item_func::JSON_EXTRACT_FUNC: func_name = (char*) item_func->func_name(); func_name_length = strlen(func_name); @@ -6607,13 +6616,13 @@ int spider_db_mbase_util::print_item_func( Loop through the items of the current function expression to print its portion of the statement */ - for (roop_count = start_item; roop_count < item_count; roop_count++) + for (i = start_item; i < item_count; i++) { - item = item_list[roop_count]; + item = item_list[i]; if ((error_num = spider_db_print_item_type(item, field, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); - if (roop_count == 1) + if (i == 1) { /* Remaining operands need to be preceded by the separator */ func_name = separator_str; @@ -6627,7 +6636,7 @@ int spider_db_mbase_util::print_item_func( } /* Print the last operand value */ - item = item_list[roop_count]; + item = item_list[i]; if ((error_num = spider_db_print_item_type(item, field, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); From 051a1fa0e9fb61a3347d7ca8c41ddc8d95261729 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 27 Mar 2024 11:15:25 +1100 Subject: [PATCH 24/25] MDEV-33777 Spider: Correct checks for show index column numbers It was updated for 10.6+ in MDEV-7317. Because a lower version spider node may connect to a higher version data node, we need to change this for 10.4 and 10.5 as well. --- storage/spider/spd_db_mysql.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 2624190f432..aa51b369712 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -1186,9 +1186,9 @@ int spider_db_mbase_result::fetch_table_cardinality( if (mode == 1) { uint num_fields = this->num_fields(); - if (num_fields < 12 || num_fields > 13) + if (num_fields < 12 || num_fields > 14) { - DBUG_PRINT("info",("spider num_fields < 12 || num_fields > 13")); + DBUG_PRINT("info",("spider num_fields < 12 || num_fields > 14")); DBUG_RETURN(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM); } From 50998a6c6f82d40c72370bb017669af704565ea0 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Mon, 15 Apr 2024 16:39:01 +0200 Subject: [PATCH 25/25] MDEV-33861 main.query_cache fails with embedded after enabling WITH_PROTECT_STATEMENT_MEMROOT Synopsis: If SELECT returned answer from Query Cache it is not really executed. The reason for firing of assertion DBUG_ASSERT((mem_root->flags & ROOT_FLAG_READ_ONLY) == 0); is that in case the query_cache is on and the same query run by different stored routines the following use case can take place: First, lets say that bodies of routines used by the test case are the same and contains the only query 'SELECT * FROM t1'; call p1() -- a result set is stored in query cache for further use. call p2() -- the same query is run against the table t1, that result in not running the actual query but using its cached result. On finishing execution of this routine, its memory root is marked for read only since every SP instruction that this routine contains has been executed. INSERT INT t1 VALUE (1); -- force following invalidation of query cache call p2() -- query the table t1 will result in assertion failure since its execution would require allocation on the memory root that has been already marked as read only memory root The root cause of firing the assertion is that memory root of the stored routine 'p2' was marked as read only although actual execution of the query contained inside hadn't been performed. To fix the issue, mark a SP instruction as not yet run in case its execution doesn't result in real query processing and a result set got from query cache instead. Note that, this issue relates server built in debug mode AND with the protect statement memory root feature turned on. It doesn't affect server built in release mode. --- mysql-test/main/query_cache.result | 27 +++++++++++++++++++++++ mysql-test/main/query_cache.test | 35 ++++++++++++++++++++++++++++++ sql/sp_head.cc | 3 +++ sql/sp_head.h | 18 ++++++++++----- 4 files changed, 78 insertions(+), 5 deletions(-) diff --git a/mysql-test/main/query_cache.result b/mysql-test/main/query_cache.result index fc7ca726c48..a98ab3cab76 100644 --- a/mysql-test/main/query_cache.result +++ b/mysql-test/main/query_cache.result @@ -2207,6 +2207,33 @@ Variable_name Value Qcache_queries_in_cache 0 DROP FUNCTION foo; drop table t1; +# +# MDEV-33861: main.query_cache fails with embedded after +# enabling WITH_PROTECT_STATEMENT_MEMROOT +# +create table t1 (s1 int); +create procedure f3 () begin +select * from t1; +end; +// +create procedure f4 () begin +select * from t1; +end; +// +Call f4(); +s1 +cAll f3(); +s1 +insert into t1 values (2); +caLl f3(); +s1 +2 +drop procedure f3; +drop procedure f4; +drop table t1; +# +# End of 10.4 tests +# restore defaults SET GLOBAL query_cache_type= default; SET GLOBAL query_cache_size=@save_query_cache_size; diff --git a/mysql-test/main/query_cache.test b/mysql-test/main/query_cache.test index f4913c99d1c..5d523764dce 100644 --- a/mysql-test/main/query_cache.test +++ b/mysql-test/main/query_cache.test @@ -1803,6 +1803,41 @@ show status like "Qcache_queries_in_cache"; DROP FUNCTION foo; drop table t1; + +--echo # +--echo # MDEV-33861: main.query_cache fails with embedded after +--echo # enabling WITH_PROTECT_STATEMENT_MEMROOT +--echo # + +create table t1 (s1 int); +--delimiter // +create procedure f3 () begin +select * from t1; +end; +// +create procedure f4 () begin +select * from t1; +end; +// +--delimiter ; + +Call f4(); + +cAll f3(); + +insert into t1 values (2); + +caLl f3(); + +drop procedure f3; +drop procedure f4; +drop table t1; + + +--echo # +--echo # End of 10.4 tests +--echo # + --echo restore defaults SET GLOBAL query_cache_type= default; SET GLOBAL query_cache_size=@save_query_cache_size; diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 312d779b05a..faf483c4a35 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -3702,6 +3702,9 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) thd->update_stats(); thd->lex->sql_command= save_sql_command; *nextp= m_ip+1; +#ifdef PROTECT_STATEMENT_MEMROOT + mark_as_qc_used(); +#endif } thd->set_query(query_backup); thd->query_name_consts= 0; diff --git a/sql/sp_head.h b/sql/sp_head.h index 693a5e78703..c9b6ae63c2b 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -1100,7 +1100,7 @@ public: sp_instr(uint ip, sp_pcontext *ctx) :Query_arena(0, STMT_INITIALIZED_FOR_SP), marked(0), m_ip(ip), m_ctx(ctx) #ifdef PROTECT_STATEMENT_MEMROOT - , m_has_been_run(false) + , m_has_been_run(NON_RUN) #endif {} @@ -1194,21 +1194,29 @@ public: #ifdef PROTECT_STATEMENT_MEMROOT bool has_been_run() const { - return m_has_been_run; + return m_has_been_run == RUN; + } + + void mark_as_qc_used() + { + m_has_been_run= QC; } void mark_as_run() { - m_has_been_run= true; + if (m_has_been_run == QC) + m_has_been_run= NON_RUN; // answer was from WC => not really executed + else + m_has_been_run= RUN; } void mark_as_not_run() { - m_has_been_run= false; + m_has_been_run= NON_RUN; } private: - bool m_has_been_run; + enum {NON_RUN, QC, RUN} m_has_been_run; #endif }; // class sp_instr : public Sql_alloc