Merge branch '10.4' into 10.5

This commit is contained in:
Oleksandr Byelkin 2024-04-16 11:04:14 +02:00
commit 9b18275623
85 changed files with 1178 additions and 1726 deletions

View file

@ -209,9 +209,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)

View file

@ -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 range 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
#

View file

@ -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 #

View file

@ -4,6 +4,9 @@
--source include/not_embedded.inc
--source include/have_debug_sync.inc
let $wait_condition=select count(*) = 1 from information_schema.processlist;
source include/wait_condition.inc;
# Ensure no lingering connections from an earlier test run, which can very
# rarely still be visible in SHOW PROCESSLIST here.
--let $wait_condition= SELECT COUNT(*) = 1 from information_schema.processlist

View file

@ -2208,9 +2208,39 @@ 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
#
#
# MDEV-24858 SIGABRT in DbugExit from my_malloc in Query_cache::init_cache Regression
#
set global Query_cache_size=18446744073709547520;
#
# End of 10.5 tests
#
restore defaults
SET GLOBAL query_cache_type= default;
SET GLOBAL query_cache_size=@save_query_cache_size;

View file

@ -1803,6 +1803,40 @@ 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 #
--echo # MDEV-24858 SIGABRT in DbugExit from my_malloc in Query_cache::init_cache Regression
--echo #
@ -1810,6 +1844,10 @@ drop table t1;
set global Query_cache_size=18446744073709547520;
--enable_warnings
--echo #
--echo # End of 10.5 tests
--echo #
--echo restore defaults
SET GLOBAL query_cache_type= default;
SET GLOBAL query_cache_size=@save_query_cache_size;

View file

@ -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

View file

@ -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";

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -8516,7 +8516,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)
{

View file

@ -564,6 +564,9 @@ 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_cache_and_keyread().
@return true if the subquery is expensive
@return false otherwise
*/

View file

@ -3780,6 +3780,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;

View file

@ -1125,7 +1125,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
{}
@ -1220,21 +1220,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

View file

@ -1590,6 +1590,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);

View file

@ -2240,6 +2240,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

View file

@ -3341,7 +3341,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
@ -30574,7 +30574,26 @@ void JOIN::init_join_cache_and_keyread()
if (!(table->file->index_flags(table->file->keyread, 0, 1) & HA_CLUSTERED_INDEX))
table->mark_index_columns(table->file->keyread, table->read_set);
}
if (tab->cache && tab->cache->init(select_options & SELECT_DESCRIBE))
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;
}
if (tab->cache && tab->cache->init(init_for_explain))
revise_cache_usage(tab);
else
tab->remove_redundant_bnl_scan_conds();

View file

@ -1105,10 +1105,8 @@ void wsrep_recover()
}
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)
{
@ -1121,38 +1119,28 @@ 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. */
set_current_thd(nullptr);
}
@ -2890,16 +2878,20 @@ 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 ||
thd->killed == KILL_CONNECTION_HARD))
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 ||
thd->killed == KILL_CONNECTION_HARD)
{
(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)
@ -2939,14 +2931,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_HARD);
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_HARD);
return 0;
}
}
return 0;
@ -2958,6 +2960,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)
{

View file

@ -264,25 +264,17 @@ 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;
// No need to open table if the query was bf aborted,
@ -292,37 +284,39 @@ static int open_table(THD* thd,
(thd->get_stmt_da()->sql_errno() == ER_QUERY_INTERRUPTED));
if (interrupted ||
!open_n_lock_single_table(thd, &tables, tables.lock_type, flags)) {
!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;
}
@ -464,19 +458,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;
}
@ -731,8 +727,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 */
@ -757,11 +755,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());
@ -781,12 +781,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());
@ -840,8 +842,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;
@ -867,8 +871,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;
}
@ -892,8 +900,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;
@ -997,14 +1011,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());
@ -1048,13 +1063,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());
@ -1177,12 +1194,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<wsrep::seqno>::const_iterator i= fragments.begin();
i != fragments.end(); ++i)
{
@ -1246,6 +1265,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;
@ -1253,12 +1273,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());
@ -1304,12 +1325,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,
@ -1351,7 +1373,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);
@ -1366,10 +1390,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);
@ -1407,12 +1436,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 (0 == error)
{

View file

@ -7396,7 +7396,6 @@ btr_store_big_rec_extern_fields(
for (ulint blob_npages = 0;; ++blob_npages) {
buf_block_t* block;
const ulint commit_freq = 4;
uint32_t r_extents;
ut_ad(page_align(field_ref) == page_align(rec));
@ -7422,18 +7421,17 @@ btr_store_big_rec_extern_fields(
hint_prev = rec_block->page.id().page_no();
}
if (!fsp_reserve_free_extents(&r_extents,
index->table->space, 1,
FSP_BLOB, &mtr, 1)) {
mtr.commit();
error = DB_OUT_OF_FILE_SPACE;
goto func_exit;
}
block = btr_page_alloc(index, hint_prev + 1,
FSP_NO_DIR, 0, &mtr, &mtr);
index->table->space->release_free_extents(r_extents);
if (!block) {
error = DB_OUT_OF_FILE_SPACE;
mtr.commit();
if (op == BTR_STORE_INSERT_BULK) {
mtr.commit();
}
goto func_exit;
}
ut_a(block != NULL);

View file

@ -458,8 +458,15 @@ btr_pcur_t::restore_position(ulint restore_latch_mode, const char *file,
return restore_status::SAME_ALL;
}
if (n_matched_fields >= index->n_uniq)
ret_val= restore_status::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= restore_status::SAME_UNIQ;
}
mem_heap_free(heap);

View file

@ -2062,7 +2062,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

View file

@ -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 */

View file

@ -596,28 +596,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;
}
/**************************************************************//**

View file

@ -1009,8 +1009,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;

View file

@ -63,7 +63,6 @@ dict_mem_fill_index_struct(
& index->MAX_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;

View file

@ -257,13 +257,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<dict_index_t*>(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. */
@ -1871,12 +1871,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
@ -1884,6 +1911,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,
@ -3150,7 +3178,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,

View file

@ -2037,7 +2037,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))) {
@ -2142,16 +2142,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 */

View file

@ -22,10 +22,6 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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];
@ -1587,14 +1576,11 @@ int ha_spider::extra(
if (!(wide_handler->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 (!(wide_handler->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:
@ -4088,7 +4074,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,
@ -4098,17 +4083,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));
@ -4153,7 +4127,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,
@ -4163,17 +4136,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));
@ -4246,16 +4208,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,
@ -4742,19 +4698,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)
@ -4972,11 +4920,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)
{
@ -5099,11 +5043,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);
@ -5648,15 +5588,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");
@ -5734,16 +5668,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
)
@ -6460,11 +6388,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)
{
@ -6585,11 +6509,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);
@ -9687,19 +9607,10 @@ 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
@ -9712,11 +9623,6 @@ int ha_spider::write_row(
}
#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;
@ -9813,21 +9719,12 @@ int ha_spider::pre_write_row(
THD *thd = wide_handler->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
@ -9950,20 +9847,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
@ -9972,11 +9860,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));
@ -10122,14 +10005,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 ||
@ -10297,14 +10176,10 @@ int ha_spider::direct_update_rows_init()
if (wide_handler->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 ||
@ -10639,19 +10514,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
@ -10745,14 +10611,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 ||
@ -10851,14 +10713,10 @@ int ha_spider::direct_delete_rows_init()
wide_handler->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 ||
@ -15698,13 +15556,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);
}

View file

@ -140,11 +140,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
@ -332,7 +328,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,
@ -351,26 +346,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,
@ -378,7 +353,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
);
@ -388,17 +362,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,
@ -1251,3 +1214,26 @@ public:
void bulk_access_end();
#endif
};
/* 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

View file

@ -9,13 +9,8 @@
#include <my_global.h>
#include "mysql_version.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#endif
#include "config.hpp"

View file

@ -11,14 +11,9 @@
#define DENA_CONFIG_HPP
#include "mysql_version.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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); }

View file

@ -9,13 +9,8 @@
#include <my_global.h>
#include "mysql_version.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#endif
#include "fatal.hpp"

View file

@ -11,14 +11,9 @@
#define DENA_FATAL_HPP
#include "mysql_version.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_class.h"
#endif
namespace dena {

View file

@ -16,26 +16,9 @@
#ifndef HS_COMPAT_H
#define HS_COMPAT_H
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500
#define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \
my_init_dynamic_array2(PSI_INSTRUMENT_ME, A, B, C, D, E, F)
#define SPD_INIT_ALLOC_ROOT(A, B, C, D) \
init_alloc_root(PSI_INSTRUMENT_ME, A, B, C, D)
#elif 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

View file

@ -10,14 +10,9 @@
#include <my_global.h>
#include "mysql_version.h"
#include "hs_compat.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_class.h"
#endif
#include "hstcpcli.hpp"
#include "auto_file.hpp"

View file

@ -13,13 +13,8 @@
#define HANDLERSOCKET_MYSQL_UTIL 1
#include "mysql_version.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#endif
#include "config.hpp"
#include "socket.hpp"

View file

@ -16,16 +16,9 @@
#include "mysql_version.h"
#include "hs_compat.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
#include <my_global.h>
#endif
#include "sql_priv.h"
#include "probes_mysql.h"
#endif
#include "socket.hpp"
#include "string_util.hpp"

View file

@ -11,13 +11,8 @@
#define DENA_SOCKET_HPP
#include "mysql_version.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#endif
#include "auto_addrinfo.hpp"
#include "auto_file.hpp"

View file

@ -10,13 +10,8 @@
#include <my_global.h>
#include "mysql_version.h"
#include "hs_compat.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#endif
#include "string_util.hpp"

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -0,0 +1,25 @@
#
# 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
drop table t1, t2, t1_spider, t2_spider;
drop server srv;
for master_1
for child2
for child3

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
#

View file

@ -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

View file

@ -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 #

View file

@ -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

View file

@ -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

View file

@ -18,17 +18,12 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_class.h"
#include "sql_partition.h"
#include "sql_table.h"
#include "tztime.h"
#endif
#include "spd_err.h"
#include "spd_param.h"
#include "spd_db_include.h"
@ -61,7 +56,7 @@ extern struct charset_info_st *spd_charset_utf8mb3_bin;
extern LEX_CSTRING spider_unique_id;
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;
@ -102,7 +97,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;
@ -174,12 +169,8 @@ int spider_conn_init(
) {
int error_num = HA_ERR_OUT_OF_MEM;
DBUG_ENTER("spider_conn_init");
#if MYSQL_VERSION_ID < 50500
if (pthread_mutex_init(&conn->loop_check_mutex, MY_MUTEX_INIT_FAST))
#else
if (mysql_mutex_init(spd_key_mutex_conn_loop_check, &conn->loop_check_mutex,
MY_MUTEX_INIT_FAST))
#endif
{
goto error_loop_check_mutex_init;
}
@ -868,12 +859,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;
@ -2449,43 +2436,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;
@ -2502,36 +2473,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;
@ -3532,35 +3489,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;
@ -3899,35 +3842,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;
@ -4346,13 +4275,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);
@ -4364,12 +4288,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);
@ -4381,12 +4301,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);
@ -4401,16 +4317,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);
@ -4664,17 +4574,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));
@ -5202,21 +5104,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;

View file

@ -18,17 +18,12 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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"
@ -307,7 +302,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(
@ -745,13 +740,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)
{
@ -774,18 +764,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,
@ -797,7 +775,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;
}
@ -889,9 +866,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
MDL_REQUEST_INIT(&table_list->mdl_request,
MDL_key::TABLE,
SPIDER_TABLE_LIST_db_str(table_list),
@ -900,7 +874,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;
@ -1104,11 +1077,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)
@ -1154,11 +1123,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)

View file

@ -18,10 +18,6 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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 <errmsg.h>
#include "spd_err.h"
@ -72,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,
@ -1947,10 +1942,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)
@ -2186,12 +2179,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;
@ -3057,13 +3044,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);
}
@ -3091,13 +3073,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);
}
@ -7076,11 +7053,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() &&
@ -7109,11 +7082,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,
@ -7352,9 +7321,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->wide_handler->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)))
@ -9498,11 +9465,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);
}
@ -10701,13 +10664,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_and_lock_tables(c_thd, &direct_sql->table_list_first,
@ -10726,7 +10684,6 @@ int spider_db_udf_direct_sql(
direct_sql->open_tables_thd = c_thd;
roop_count = 0;
}
#endif
if (c_thd != thd)
{
@ -10734,21 +10691,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)
@ -10768,11 +10719,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);
@ -10798,10 +10746,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);
}
}
@ -10875,9 +10820,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,
@ -10888,8 +10830,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
@ -10911,7 +10851,6 @@ int spider_db_udf_direct_sql(
next_tables = next_tables->next_global;
}
}
#endif
}
if (direct_sql->iop)
@ -10973,13 +10912,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_unlock(table->in_use);
#if MYSQL_VERSION_ID < 50500
#else
if (
table->s->tmp_table == NO_TMP_TABLE &&
table->pos_in_table_list
@ -10995,7 +10929,6 @@ int spider_db_udf_direct_sql(
next_tables = next_tables->next_global;
}
}
#endif
}
table->file->ha_reset();
table->in_use = thd;
@ -11058,10 +10991,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);
}

View file

@ -17,14 +17,9 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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"
@ -3182,14 +3177,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;
@ -3261,9 +3255,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)
{
@ -3305,11 +3296,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);
@ -3439,11 +3426,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);
@ -3593,11 +3576,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);
@ -3728,11 +3707,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(

View file

@ -18,14 +18,9 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_class.h"
#endif
#include "sql_common.h"
#include <mysql.h>
#include <errmsg.h>

View file

@ -28,56 +28,31 @@
#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;
@ -139,7 +114,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 "
@ -150,7 +124,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)

View file

@ -18,10 +18,6 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_class.h"
@ -32,7 +28,6 @@
#ifdef HANDLER_HAS_DIRECT_AGGREGATE
#include "sql_select.h"
#endif
#endif
#include "sql_common.h"
#include <mysql.h>
#include <errmsg.h>
@ -824,11 +819,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
@ -906,13 +897,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,
&not_used_long, &not_used_uint);
#else
stat.create_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
stat.create_time = (time_t) 0;
#ifdef DBUG_TRACE
@ -931,13 +917,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,
&not_used_long, &not_used_uint);
#else
stat.update_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
stat.update_time = (time_t) 0;
#ifndef DBUG_OFF
@ -956,13 +937,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,
&not_used_long, &not_used_uint);
#else
stat.check_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
stat.check_time = (time_t) 0;
#ifdef DBUG_TRACE
@ -1035,13 +1011,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,
&not_used_long, &not_used_uint);
#else
stat.create_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
stat.create_time = (time_t) 0;
#ifdef DBUG_TRACE
@ -1060,13 +1031,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,
&not_used_long, &not_used_uint);
#else
stat.update_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
stat.update_time = (time_t) 0;
#ifdef DBUG_TRACE
@ -1085,13 +1051,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,
&not_used_long, &not_used_uint);
#else
stat.check_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
stat.check_time = (time_t) 0;
#ifdef DBUG_TRACE
@ -1238,9 +1199,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);
}
@ -2425,11 +2386,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));
@ -2443,11 +2400,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);
}
@ -2456,11 +2409,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)
@ -2485,11 +2434,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)
@ -2531,11 +2476,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);
}
@ -5609,14 +5550,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
){
@ -5686,16 +5619,10 @@ 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)
{
case Item_func::TRIG_COND_FUNC:
case Item_func::CASE_SEARCHED_FUNC:
case Item_func::CASE_SIMPLE_FUNC:
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
case Item_func::NOT_FUNC:
/* Why the following check is necessary? */
@ -5704,13 +5631,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.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->wide_handler->trx->thd, spider->share->use_pushdown_udf);
if (!use_pushdown_udf)
@ -5720,12 +5640,18 @@ 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
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->wide_handler->trx->thd, SPIDER_WARN_LEVEL_WARN,
ER_INTERNAL_ERROR,
ER_THD(spider->wide_handler->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;
}
@ -5767,15 +5693,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));
@ -6090,12 +6016,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;
@ -6146,7 +6071,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);
@ -6167,9 +6092,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)
{
@ -6642,7 +6564,83 @@ 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:
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
/*
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 (case_when_start > 0)
{
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);
}
for (i = 0; i < (uint) case_when_count; i++)
{
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[i + case_when_start], 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[i + case_when_start + case_when_count], NULL, spider, str,
alias, alias_length, dbton_id, use_fields, fields)))
DBUG_RETURN(error_num);
}
if (case_with_else)
{
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_count - 1], 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);
case Item_func::JSON_EXTRACT_FUNC:
func_name = (char*) item_func->func_name();
func_name_length = strlen(func_name);
@ -6657,6 +6655,18 @@ 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->wide_handler->trx->thd,
SPIDER_WARN_LEVEL_WARN, ER_INTERNAL_ERROR,
ER_THD(spider->wide_handler->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->wide_handler->trx->thd;
SPIDER_SHARE *share = spider->share;
@ -6685,13 +6695,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;
@ -6705,7 +6715,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);
@ -13248,11 +13258,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);

View file

@ -18,10 +18,6 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_partition.h"
@ -29,7 +25,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))
@ -3430,14 +3425,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;
@ -3509,9 +3503,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)
{
@ -3553,11 +3544,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);
@ -3687,11 +3674,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);
@ -3977,11 +3960,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);
@ -4113,11 +4092,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(
@ -10460,11 +10435,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);

View file

@ -18,10 +18,6 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_class.h"
@ -29,7 +25,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"
@ -44,9 +39,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;
@ -115,21 +108,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, (uint) (sizeof(char*) * table_count),
&direct_sql->table_names, (uint) (sizeof(char*) * table_count),
&direct_sql->tables, (uint) (sizeof(TABLE*) * table_count),
&tmp_name_ptr, (uint) (sizeof(char) * (
table_name_list_length +
thd->db_length * table_count +
2 * table_count
)),
&direct_sql->iop, (uint) (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, (uint) (sizeof(char*) * table_count),
@ -146,7 +124,6 @@ int spider_udf_direct_sql_create_table_list(
(uint) (sizeof(uchar) * ((table_count + 7) / 8)),
NullS))
)
#endif
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
tmp_ptr = table_name_list;
@ -603,12 +580,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;
@ -1110,10 +1083,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;
@ -1182,10 +1152,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;
@ -1236,10 +1203,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:
@ -1501,14 +1465,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));
@ -1596,11 +1557,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 *)
@ -1691,11 +1649,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
@ -1726,19 +1681,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];
MDL_REQUEST_INIT(&tables->mdl_request, MDL_key::TABLE,
@ -1754,7 +1704,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)))
@ -1871,22 +1820,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;

View file

@ -20,42 +20,27 @@
#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
#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
#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
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500
#define SPIDER_I_S_USE_SHOW_FOR_COLUMN
#endif
#endif /* SPD_ENVIRON_INCLUDED */

View file

@ -18,17 +18,12 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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 <errmsg.h>
#include "spd_err.h"
@ -1441,38 +1436,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;
@ -1481,9 +1470,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;
@ -1507,7 +1494,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;
@ -1516,9 +1503,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;
@ -1549,7 +1534,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;
@ -1558,9 +1543,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;
@ -1692,7 +1675,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;
@ -1701,9 +1684,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;
@ -1771,7 +1752,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;
@ -1780,9 +1761,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;

View file

@ -18,16 +18,11 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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"
@ -162,12 +157,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,
@ -184,7 +176,6 @@ struct st_maria_plugin spider_i_s_alloc_mem_maria =
"1.0",
MariaDB_PLUGIN_MATURITY_STABLE,
};
#endif
extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
@ -286,12 +277,9 @@ struct st_mysql_plugin spider_i_s_wrapper_protocols =
NULL,
NULL,
NULL,
#if MYSQL_VERSION_ID >= 50600
0,
#endif
};
#ifdef MARIADB_BASE_VERSION
struct st_maria_plugin spider_i_s_wrapper_protocols_maria =
{
MYSQL_INFORMATION_SCHEMA_PLUGIN,
@ -308,4 +296,3 @@ struct st_maria_plugin spider_i_s_wrapper_protocols_maria =
"1.0",
MariaDB_PLUGIN_MATURITY_STABLE,
};
#endif

View file

@ -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,46 +127,15 @@
#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
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500
typedef start_new_trans *SPIDER_Open_tables_backup;
#elif MYSQL_VERSION_ID < 50500
typedef Open_tables_state SPIDER_Open_tables_backup;
#else
typedef Open_tables_backup SPIDER_Open_tables_backup;
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500
#define SPIDER_reset_n_backup_open_tables_state(A,B,C) do { \
if (!(*(B) = new start_new_trans(A))) \
{ \
@ -262,12 +147,6 @@ typedef Open_tables_backup SPIDER_Open_tables_backup;
delete *(B); \
} while (0)
#define SPIDER_sys_close_thread_tables(A) (A)->commit_whole_transaction_and_close_tables()
#else
#define SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP
#define SPIDER_reset_n_backup_open_tables_state(A,B,C) (A)->reset_n_backup_open_tables_state(B)
#define SPIDER_restore_backup_open_tables_state(A,B) (A)->restore_backup_open_tables_state(B)
#define SPIDER_sys_close_thread_tables(A) close_thread_tables(A)
#endif
#define spider_bitmap_size(A) ((A + 7) / 8)
#define spider_set_bit(BITMAP, BIT) \
@ -1632,8 +1511,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;
@ -1641,7 +1518,6 @@ typedef struct st_spider_direct_sql
uchar *real_table_bitmap;
SPIDER_Open_tables_backup open_tables_backup;
THD *open_tables_thd;
#endif
char *sql;
ulong sql_length;
@ -1661,10 +1537,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;
@ -1739,6 +1612,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;

View file

@ -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("

View file

@ -18,15 +18,10 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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"

View file

@ -38,15 +38,10 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_class.h"
#include "sql_partition.h"
#endif
#include <my_getopt.h>
#include "spd_err.h"
#include "spd_db_include.h"
@ -57,10 +52,8 @@
extern struct st_mysql_plugin spider_i_s_alloc_mem;
extern struct st_mysql_plugin spider_i_s_wrapper_protocols;
#ifdef MARIADB_BASE_VERSION
extern struct st_maria_plugin spider_i_s_alloc_mem_maria;
extern struct st_maria_plugin spider_i_s_wrapper_protocols_maria;
#endif
extern volatile ulonglong spider_mon_table_cache_version;
extern volatile ulonglong spider_mon_table_cache_version_req;
@ -233,13 +226,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(
@ -702,14 +690,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
}
/*
@ -760,14 +743,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
}
/*
@ -1745,7 +1723,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,
@ -1756,30 +1733,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)
@ -1807,7 +1760,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,
@ -1818,30 +1770,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)
@ -1892,7 +1820,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,
@ -1903,30 +1830,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)
@ -1980,7 +1883,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 |
@ -1990,28 +1892,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,
@ -2352,8 +2232,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
@ -2372,7 +2250,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(
@ -2973,10 +2850,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),
@ -3018,15 +2892,12 @@ mysql_declare_plugin(spider)
spider_status_variables,
spider_system_variables,
NULL,
#if MYSQL_VERSION_ID >= 50600
0,
#endif
},
spider_i_s_alloc_mem,
spider_i_s_wrapper_protocols
mysql_declare_plugin_end;
#ifdef MARIADB_BASE_VERSION
maria_declare_plugin(spider)
{
MYSQL_STORAGE_ENGINE_PLUGIN,
@ -3046,4 +2917,3 @@ maria_declare_plugin(spider)
spider_i_s_alloc_mem_maria,
spider_i_s_wrapper_protocols_maria
maria_declare_plugin_end;
#endif

View file

@ -375,13 +375,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

View file

@ -18,16 +18,11 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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"
@ -55,6 +50,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;
@ -64,23 +61,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;
volatile ulonglong spider_mon_table_cache_version = 0;
volatile ulonglong spider_mon_table_cache_version_req = 1;
/* 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;
/* 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;
/* 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
) {
@ -92,6 +109,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));
@ -104,6 +122,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()));
@ -130,12 +151,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)))
@ -278,6 +302,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,
@ -354,6 +386,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)))
{
@ -361,6 +395,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 +431,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 +495,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 +554,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 +564,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 +589,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 +616,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))
@ -581,43 +627,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;
@ -878,6 +907,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,
@ -906,6 +940,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)))
{
@ -922,10 +957,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,
@ -996,6 +1037,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
@ -1086,23 +1134,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)
{
@ -1125,18 +1164,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,
@ -1148,7 +1175,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;
}
@ -1294,9 +1320,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)
{
@ -1311,9 +1334,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)
{
@ -1367,9 +1387,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)
{
@ -1384,9 +1401,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)
{
@ -1430,9 +1444,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)
{
@ -1447,9 +1458,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)
{
@ -1620,9 +1628,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,
@ -1632,9 +1640,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;
@ -1703,6 +1708,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],
@ -1734,6 +1740,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",
@ -1778,16 +1786,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)
{
@ -1802,9 +1807,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;

View file

@ -17,17 +17,12 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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"
@ -239,22 +234,8 @@ TABLE *spider_open_sys_table(
) {
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 =
{
@ -272,18 +253,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),
@ -291,38 +262,6 @@ TABLE *spider_open_sys_table(
*error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM;
DBUG_RETURN(NULL);
}
#if MYSQL_VERSION_ID < 50500
} else {
SPIDER_reset_n_backup_open_tables_state(thd, open_tables_backup, NULL);
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:
@ -464,12 +403,6 @@ TABLE *spider_open_sys_table(
}
DBUG_RETURN(table);
#if MYSQL_VERSION_ID < 50500
error:
spider_free(spider_current_trx, table, MYF(0));
error_malloc:
SPIDER_restore_backup_open_tables_state(thd, open_tables_backup);
#endif
error_col_num_chk:
DBUG_RETURN(NULL);
}
@ -481,24 +414,10 @@ void spider_close_sys_table(
bool need_lock
) {
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));
SPIDER_restore_backup_open_tables_state(thd, 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_and_lock_tables(
THD *thd,
TABLE_LIST **tables,
@ -566,7 +485,6 @@ void spider_sys_close_table(
}
DBUG_VOID_RETURN;
}
#endif
int spider_sys_index_init(
TABLE *table,
@ -611,15 +529,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(
@ -635,15 +547,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(
@ -658,17 +564,16 @@ 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
}
/*
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,
@ -701,26 +606,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_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,
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);
@ -733,22 +621,15 @@ 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(
TABLE *table,
const int idx
const int idx /* which index to use */
) {
int error_num;
DBUG_ENTER("spider_sys_index_first");
@ -756,11 +637,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);
@ -778,11 +655,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);
@ -794,11 +667,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(
@ -980,6 +849,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,
@ -1539,12 +1412,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[SPIDER_LINK_FAILED_LOG_FAILED_TIME_POS] ==
table->timestamp_field)
table->timestamp_field->set_time();
#endif
if ((error_num = spider_write_sys_table_row(table)))
{
DBUG_RETURN(error_num);
@ -1578,12 +1445,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[SPIDER_XA_FAILED_LOG_FAILED_TIME_POS] ==
table->timestamp_field)
table->timestamp_field->set_time();
#endif
if ((error_num = spider_write_sys_table_row(table)))
{
DBUG_RETURN(error_num);
@ -2226,14 +2087,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");
DBUG_PRINT("info",("spider link_idx:%d", link_idx));
if ((ptr = get_field(mem_root, table->field[SPIDER_TABLES_PRIORITY_POS])))
@ -2486,9 +2349,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
) {
@ -2662,11 +2530,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;
@ -2682,6 +2556,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[SPIDER_LINK_MON_SERVERS_DB_NAME_POS])))
@ -2733,9 +2608,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;
@ -2749,14 +2627,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[SPIDER_LINK_MON_SERVERS_SERVER_POS]->is_null() &&
@ -2963,9 +2844,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 =
@ -2997,12 +2875,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)
@ -3015,13 +2889,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)

View file

@ -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:
@ -84,8 +85,6 @@ void spider_close_sys_table(
bool need_lock
);
#if MYSQL_VERSION_ID < 50500
#else
bool spider_sys_open_and_lock_tables(
THD *thd,
TABLE_LIST **tables,
@ -102,7 +101,6 @@ void spider_sys_close_table(
THD *thd,
SPIDER_Open_tables_backup *open_tables_backup
);
#endif
int spider_sys_index_init(
TABLE *table,
@ -404,7 +402,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
);
@ -481,7 +478,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
);

View file

@ -18,10 +18,6 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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"
@ -144,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;
@ -3564,13 +3564,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 */
) {
bool check_socket;
bool check_database;
@ -3763,22 +3765,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;
@ -3829,11 +3815,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)
@ -3908,6 +3890,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,
@ -3993,6 +3980,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,
@ -4557,34 +4549,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;
@ -6050,13 +6030,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;
@ -6166,23 +6141,15 @@ SPIDER_WIDE_SHARE *spider_get_wide_share(
wide_share->crd_get_time = wide_share->sts_get_time =
share->crd_get_time;
#if MYSQL_VERSION_ID < 50500
if (pthread_mutex_init(&wide_share->sts_mutex, MY_MUTEX_INIT_FAST))
#else
if (mysql_mutex_init(spd_key_mutex_wide_share_sts,
&wide_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(&wide_share->crd_mutex, MY_MUTEX_INIT_FAST))
#else
if (mysql_mutex_init(spd_key_mutex_wide_share_crd,
&wide_share->crd_mutex, MY_MUTEX_INIT_FAST))
#endif
{
*error_num = HA_ERR_OUT_OF_MEM;
goto error_init_crd_mutex;
@ -6353,7 +6320,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
@ -6960,6 +6927,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);
@ -6970,16 +6943,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;
@ -7057,117 +7020,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_wide_share_mutex, MY_MUTEX_INIT_FAST))
#else
if (mysql_mutex_init(spd_key_mutex_wide_share,
&spider_wide_share_mutex, MY_MUTEX_INIT_FAST))
#endif
goto error_wide_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(PSI_INSTRUMENT_ME, &spider_open_tables, spd_charset_utf8mb3_bin, 32, 0, 0,
@ -7281,25 +7188,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;
@ -8773,10 +8671,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))
{
@ -8789,22 +8685,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"));
@ -9071,14 +8961,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
// conditions is null may be no where condition in rand_init
spider->wide_handler->condition
@ -9225,20 +9111,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));
}
@ -9775,46 +9652,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;
@ -9862,46 +9720,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;

View file

@ -18,16 +18,11 @@
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#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"
@ -54,7 +49,7 @@ extern struct charset_info_st *spd_charset_utf8mb3_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;
@ -1157,13 +1152,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;
}
@ -1841,17 +1831,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;
@ -4031,19 +4014,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;
thd->store_globals();
lex_start(thd);
@ -4055,11 +4027,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;
}