diff options
author | Kentoku <kentokushiba@gmail.com> | 2019-11-29 08:22:13 +0900 |
---|---|---|
committer | Kentoku <kentokushiba@gmail.com> | 2019-11-29 23:23:57 +0900 |
commit | e066723a4149b05f212850dcf8ecf55b3ce2524d (patch) | |
tree | f790ac3d0bff3938429eefb8c20900e310fcec40 /storage | |
parent | 3826178da89f987ebf641bcd92d4a714d51b3ecb (diff) | |
download | mariadb-git-e066723a4149b05f212850dcf8ecf55b3ce2524d.tar.gz |
MDEV-18973 CLIENT_FOUND_ROWS wrong in spiderbb-10.4-MDEV-18973_2
Get count from last_used_con->info
Contributed by willhan at Tencent Games
Diffstat (limited to 'storage')
21 files changed, 734 insertions, 27 deletions
diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 5457bc0ba50..d2d0ddf376f 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -9778,6 +9778,7 @@ void ha_spider::start_bulk_insert( bulk_insert = TRUE; bulk_size = -1; store_last_insert_id = 0; + bzero(©_info, sizeof(copy_info)); DBUG_VOID_RETURN; } @@ -9790,7 +9791,7 @@ int ha_spider::end_bulk_insert() bulk_insert = FALSE; if (bulk_size == -1) DBUG_RETURN(0); - if ((error_num = spider_db_bulk_insert(this, table, TRUE))) + if ((error_num = spider_db_bulk_insert(this, table, ©_info, TRUE))) DBUG_RETURN(check_error_mode(error_num)); DBUG_RETURN(0); } @@ -9924,7 +9925,7 @@ int ha_spider::write_row( else bulk_size = 0; } - if ((error_num = spider_db_bulk_insert(this, table, FALSE))) + if ((error_num = spider_db_bulk_insert(this, table, ©_info, FALSE))) DBUG_RETURN(check_error_mode(error_num)); #ifdef HA_CAN_BULK_ACCESS @@ -10549,7 +10550,8 @@ int ha_spider::direct_update_rows( uint range_count, bool sorted, uchar *new_data, - ha_rows *update_rows + ha_rows *update_rows, + ha_rows *found_rows ) { int error_num; THD *thd = ha_thd(); @@ -10576,17 +10578,17 @@ int ha_spider::direct_update_rows( if (is_bulk_access_clone) { bulk_access_pre_called = FALSE; - DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows)); + DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows, found_rows)); } DBUG_RETURN(bulk_access_link_exec_tgt->spider->ha_direct_update_rows( - ranges, range_count, sorted, new_data, update_rows)); + ranges, range_count, sorted, new_data, update_rows, found_rows)); } #endif if ( (active_index != MAX_KEY && (error_num = index_handler_init())) || (active_index == MAX_KEY && (error_num = rnd_handler_init())) || (error_num = spider_db_direct_update(this, table, ranges, range_count, - update_rows)) + update_rows, found_rows)) ) DBUG_RETURN(check_error_mode(error_num)); @@ -10594,14 +10596,15 @@ int ha_spider::direct_update_rows( if (bulk_access_executing && is_bulk_access_clone) { bulk_req_exec(); - DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows)); + DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows, found_rows)); } #endif DBUG_RETURN(0); } #else int ha_spider::direct_update_rows( - ha_rows *update_rows + ha_rows *update_rows, + ha_rows *found_rows ) { int error_num; THD *thd = ha_thd(); @@ -10628,16 +10631,16 @@ int ha_spider::direct_update_rows( if (is_bulk_access_clone) { bulk_access_pre_called = FALSE; - DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows)); + DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows, found_rows)); } DBUG_RETURN(bulk_access_link_exec_tgt->spider->ha_direct_update_rows( - update_rows)); + update_rows, found_rows)); } #endif if ( (active_index != MAX_KEY && (error_num = index_handler_init())) || (active_index == MAX_KEY && (error_num = rnd_handler_init())) || - (error_num = spider_db_direct_update(this, table, update_rows)) + (error_num = spider_db_direct_update(this, table, update_rows, found_rows)) ) DBUG_RETURN(check_error_mode(error_num)); @@ -10645,7 +10648,7 @@ int ha_spider::direct_update_rows( if (bulk_access_executing && is_bulk_access_clone) { bulk_req_exec(); - DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows)); + DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows, found_rows)); } #endif DBUG_RETURN(0); @@ -10659,21 +10662,23 @@ int ha_spider::pre_direct_update_rows( uint range_count, bool sorted, uchar *new_data, - ha_rows *update_rows + ha_rows *update_rows, + ha_rows *found_rows ) { DBUG_ENTER("ha_spider::pre_direct_update_rows"); DBUG_PRINT("info",("spider this=%p", this)); DBUG_RETURN(bulk_access_link_current->spider->ha_direct_update_rows(ranges, - range_count, sorted, new_data, update_rows)); + range_count, sorted, new_data, update_rows, found_rows)); } #else int ha_spider::pre_direct_update_rows() { uint update_rows; + uint found_rows; DBUG_ENTER("ha_spider::pre_direct_update_rows"); DBUG_PRINT("info",("spider this=%p", this)); DBUG_RETURN(bulk_access_link_current->spider->ha_direct_update_rows( - &update_rows)); + &update_rows, &found_rows)); } #endif #endif diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index a146745aa97..edd7b8c881f 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -685,20 +685,22 @@ public: #endif #endif #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS - inline int direct_update_rows(ha_rows *update_rows) + inline int direct_update_rows(ha_rows *update_rows, ha_rows *found_rows) { - return direct_update_rows(NULL, 0, FALSE, NULL, update_rows); + return direct_update_rows(NULL, 0, FALSE, NULL, update_rows, found_rows); } int direct_update_rows( KEY_MULTI_RANGE *ranges, uint range_count, bool sorted, uchar *new_data, - ha_rows *update_rows + ha_rows *update_rows, + ha_rows *found_row ); #else int direct_update_rows( - ha_rows *update_rows + ha_rows *update_rows, + ha_rows *found_row ); #endif #ifdef HA_CAN_BULK_ACCESS @@ -706,15 +708,18 @@ public: inline int pre_direct_update_rows() { ha_rows update_rows; + ha_rows found_rows; - return pre_direct_update_rows(NULL, 0, FALSE, NULL, &update_rows); + return pre_direct_update_rows(NULL, 0, FALSE, NULL, &update_rows, + &found_rows); } int pre_direct_update_rows( KEY_MULTI_RANGE *ranges, uint range_count, bool sorted, uchar *new_data, - ha_rows *update_rows + ha_rows *update_rows, + ha_rows *found_row ); #else int pre_direct_update_rows(); diff --git a/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_deinit.inc new file mode 100644 index 00000000000..76b7582abfe --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_init.inc b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_init.inc new file mode 100644 index 00000000000..da6778de504 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_init.inc @@ -0,0 +1,27 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + skey int NOT NULL, + dt date NOT NULL, + tm time NOT NULL, + PRIMARY KEY (skey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT skey, dt, tm FROM tbl_a ORDER BY skey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' OR argument LIKE '%replace %'; +--let $MASTER_1_SET_COMMAND=set session spider_direct_dup_insert=1 $STR_SEMICOLON diff --git a/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_deinit.inc new file mode 100644 index 00000000000..76b7582abfe --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_init.inc b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_init.inc new file mode 100644 index 00000000000..884ef74c47e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_init.inc @@ -0,0 +1,26 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + skey int NOT NULL, + dt date NOT NULL, + tm time NOT NULL, + KEY idx1 (skey,dt) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT skey, dt, tm FROM tbl_a ORDER BY skey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; diff --git a/storage/spider/mysql-test/spider/bugfix/r/return_found_rows_insert.result b/storage/spider/mysql-test/spider/bugfix/r/return_found_rows_insert.result new file mode 100644 index 00000000000..df88d7a5165 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/return_found_rows_insert.result @@ -0,0 +1,179 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-18973 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +skey int NOT NULL, +dt date NOT NULL, +tm time NOT NULL, +PRIMARY KEY (skey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-01-01', '12:00:00'),(1, '2012-02-01', '12:00:00'),(2, '2012-03-01', '12:00:00'),(3, '2012-04-01', '12:00:00'),(4, '2012-05-01', '12:00:00'),(5, '2012-06-01', '12:00:00'),(6, '2012-07-01', '12:00:00'),(7, '2012-08-01', '12:00:00'),(8, '2012-09-01', '12:00:00'),(9, '2012-10-01', '12:00:00'); +FLUSH TABLES; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +EXE_MYSQL -v -v -u root -h localhost -P MASTER_1_MYPORT -S MASTER_1_MYSOCK -e "MASTER_1_SET_COMMAND INSERT IGNORE INTO tbl_a (skey, dt, tm) VALUES (0, '2013-01-01', '13:00:00'),(2, '2013-02-01', '13:00:00'),(4, '2013-03-01', '13:00:00'),(7, '2013-04-01', '13:00:00'),(8, '2013-05-01', '13:00:00'),(10, '2013-06-01', '13:00:00'),(11, '2013-07-01', '13:00:00'),(12, '2013-08-01', '13:00:00'),(13, '2013-09-01', '13:00:00'),(14, '2013-10-01', '13:00:00')" auto_test_local +-------------- +set session spider_direct_dup_insert=1 +-------------- + +Query OK, 0 rows affected + +-------------- +INSERT IGNORE INTO tbl_a (skey, dt, tm) VALUES (0, '2013-01-01', '13:00:00'),(2, '2013-02-01', '13:00:00'),(4, '2013-03-01', '13:00:00'),(7, '2013-04-01', '13:00:00'),(8, '2013-05-01', '13:00:00'),(10, '2013-06-01', '13:00:00'),(11, '2013-07-01', '13:00:00'),(12, '2013-08-01', '13:00:00'),(13, '2013-09-01', '13:00:00'),(14, '2013-10-01', '13:00:00') +-------------- + +Query OK, 5 rows affected +Records: 10 Duplicates: 5 Warnings: 0 + +Bye +connection child2_1; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' OR argument LIKE '%replace %'; +argument +insert ignore into `auto_test_remote`.`tbl_a`(`skey`,`dt`,`tm`)values(0,_latin1'2013-01-01',_latin1'13:00:00'),(2,_latin1'2013-02-01',_latin1'13:00:00'),(4,_latin1'2013-03-01',_latin1'13:00:00'),(7,_latin1'2013-04-01',_latin1'13:00:00'),(8,_latin1'2013-05-01',_latin1'13:00:00'),(10,_latin1'2013-06-01',_latin1'13:00:00'),(11,_latin1'2013-07-01',_latin1'13:00:00'),(12,_latin1'2013-08-01',_latin1'13:00:00'),(13,_latin1'2013-09-01',_latin1'13:00:00'),(14,_latin1'2013-10-01',_latin1'13:00:00') +SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' OR argument LIKE '%replace %' +SELECT skey, dt, tm FROM tbl_a ORDER BY skey; +skey dt tm +0 2012-01-01 12:00:00 +1 2012-02-01 12:00:00 +2 2012-03-01 12:00:00 +3 2012-04-01 12:00:00 +4 2012-05-01 12:00:00 +5 2012-06-01 12:00:00 +6 2012-07-01 12:00:00 +7 2012-08-01 12:00:00 +8 2012-09-01 12:00:00 +9 2012-10-01 12:00:00 +10 2013-06-01 13:00:00 +11 2013-07-01 13:00:00 +12 2013-08-01 13:00:00 +13 2013-09-01 13:00:00 +14 2013-10-01 13:00:00 +TRUNCATE TABLE mysql.general_log; +EXE_MYSQL -v -v -u root -h localhost -P MASTER_1_MYPORT -S MASTER_1_MYSOCK -e "MASTER_1_SET_COMMAND REPLACE INTO tbl_a (skey, dt, tm) VALUES (1, '2012-02-01', '12:00:00'),(3, '2012-12-01', '11:00:00'),(8, '2012-11-30', '11:00:00'),(9, '2012-11-29', '11:00:00'),(10, '2012-11-28', '11:00:00'),(15, '2012-11-27', '11:00:00'),(16, '2012-11-26', '11:00:00'),(17, '2012-11-25', '11:00:00'),(18, '2012-11-24', '11:00:00'),(19, '2012-11-23', '11:00:00')" auto_test_local +-------------- +set session spider_direct_dup_insert=1 +-------------- + +Query OK, 0 rows affected + +-------------- +REPLACE INTO tbl_a (skey, dt, tm) VALUES (1, '2012-02-01', '12:00:00'),(3, '2012-12-01', '11:00:00'),(8, '2012-11-30', '11:00:00'),(9, '2012-11-29', '11:00:00'),(10, '2012-11-28', '11:00:00'),(15, '2012-11-27', '11:00:00'),(16, '2012-11-26', '11:00:00'),(17, '2012-11-25', '11:00:00'),(18, '2012-11-24', '11:00:00'),(19, '2012-11-23', '11:00:00') +-------------- + +Query OK, 14 rows affected +Records: 10 Duplicates: 4 Warnings: 0 + +Bye +connection child2_1; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' OR argument LIKE '%replace %'; +argument +replace into `auto_test_remote`.`tbl_a`(`skey`,`dt`,`tm`)values(1,_latin1'2012-02-01',_latin1'12:00:00'),(3,_latin1'2012-12-01',_latin1'11:00:00'),(8,_latin1'2012-11-30',_latin1'11:00:00'),(9,_latin1'2012-11-29',_latin1'11:00:00'),(10,_latin1'2012-11-28',_latin1'11:00:00'),(15,_latin1'2012-11-27',_latin1'11:00:00'),(16,_latin1'2012-11-26',_latin1'11:00:00'),(17,_latin1'2012-11-25',_latin1'11:00:00'),(18,_latin1'2012-11-24',_latin1'11:00:00'),(19,_latin1'2012-11-23',_latin1'11:00:00') +SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' OR argument LIKE '%replace %' +SELECT skey, dt, tm FROM tbl_a ORDER BY skey; +skey dt tm +0 2012-01-01 12:00:00 +1 2012-02-01 12:00:00 +2 2012-03-01 12:00:00 +3 2012-12-01 11:00:00 +4 2012-05-01 12:00:00 +5 2012-06-01 12:00:00 +6 2012-07-01 12:00:00 +7 2012-08-01 12:00:00 +8 2012-11-30 11:00:00 +9 2012-11-29 11:00:00 +10 2012-11-28 11:00:00 +11 2013-07-01 13:00:00 +12 2013-08-01 13:00:00 +13 2013-09-01 13:00:00 +14 2013-10-01 13:00:00 +15 2012-11-27 11:00:00 +16 2012-11-26 11:00:00 +17 2012-11-25 11:00:00 +18 2012-11-24 11:00:00 +19 2012-11-23 11:00:00 +TRUNCATE TABLE mysql.general_log; +EXE_MYSQL -v -v -u root -h localhost -P MASTER_1_MYPORT -S MASTER_1_MYSOCK -e "MASTER_1_SET_COMMAND INSERT INTO tbl_a (skey, dt, tm) VALUES (1, '2012-11-01', '11:00:00'),(3, '2012-12-01', '11:00:00'),(11, '2012-11-30', '11:00:00'),(15, '2012-11-29', '11:00:00'),(16, '2012-11-28', '11:00:00'),(20, '2012-11-27', '11:00:00'),(21, '2012-11-26', '11:00:00'),(22, '2012-11-25', '11:00:00'),(23, '2012-11-24', '11:00:00'),(24, '2012-11-23', '11:00:00') ON DUPLICATE KEY UPDATE dt=VALUE(dt), tm=VALUE(tm)" auto_test_local +-------------- +set session spider_direct_dup_insert=1 +-------------- + +Query OK, 0 rows affected + +-------------- +INSERT INTO tbl_a (skey, dt, tm) VALUES (1, '2012-11-01', '11:00:00'),(3, '2012-12-01', '11:00:00'),(11, '2012-11-30', '11:00:00'),(15, '2012-11-29', '11:00:00'),(16, '2012-11-28', '11:00:00'),(20, '2012-11-27', '11:00:00'),(21, '2012-11-26', '11:00:00'),(22, '2012-11-25', '11:00:00'),(23, '2012-11-24', '11:00:00'),(24, '2012-11-23', '11:00:00') ON DUPLICATE KEY UPDATE dt=VALUE(dt), tm=VALUE(tm) +-------------- + +Query OK, 13 rows affected +Records: 10 Duplicates: 4 Warnings: 0 + +Bye +connection child2_1; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' OR argument LIKE '%replace %'; +argument +insert high_priority into `auto_test_remote`.`tbl_a`(`skey`,`dt`,`tm`)values(1,_latin1'2012-11-01',_latin1'11:00:00'),(3,_latin1'2012-12-01',_latin1'11:00:00'),(11,_latin1'2012-11-30',_latin1'11:00:00'),(15,_latin1'2012-11-29',_latin1'11:00:00'),(16,_latin1'2012-11-28',_latin1'11:00:00'),(20,_latin1'2012-11-27',_latin1'11:00:00'),(21,_latin1'2012-11-26',_latin1'11:00:00'),(22,_latin1'2012-11-25',_latin1'11:00:00'),(23,_latin1'2012-11-24',_latin1'11:00:00'),(24,_latin1'2012-11-23',_latin1'11:00:00') on duplicate key update `dt` = values(`dt`),`tm` = values(`tm`) +SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' OR argument LIKE '%replace %' +SELECT skey, dt, tm FROM tbl_a ORDER BY skey; +skey dt tm +0 2012-01-01 12:00:00 +1 2012-11-01 11:00:00 +2 2012-03-01 12:00:00 +3 2012-12-01 11:00:00 +4 2012-05-01 12:00:00 +5 2012-06-01 12:00:00 +6 2012-07-01 12:00:00 +7 2012-08-01 12:00:00 +8 2012-11-30 11:00:00 +9 2012-11-29 11:00:00 +10 2012-11-28 11:00:00 +11 2012-11-30 11:00:00 +12 2013-08-01 13:00:00 +13 2013-09-01 13:00:00 +14 2013-10-01 13:00:00 +15 2012-11-29 11:00:00 +16 2012-11-28 11:00:00 +17 2012-11-25 11:00:00 +18 2012-11-24 11:00:00 +19 2012-11-23 11:00:00 +20 2012-11-27 11:00:00 +21 2012-11-26 11:00:00 +22 2012-11-25 11:00:00 +23 2012-11-24 11:00:00 +24 2012-11-23 11:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/return_found_rows_update.result b/storage/spider/mysql-test/spider/bugfix/r/return_found_rows_update.result new file mode 100644 index 00000000000..2ebc2693dc5 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/return_found_rows_update.result @@ -0,0 +1,99 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-18973 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +skey int NOT NULL, +dt date NOT NULL, +tm time NOT NULL, +KEY idx1 (skey,dt) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-01-01', '12:00:00'),(1, '2012-02-01', '12:00:00'),(2, '2012-03-01', '12:00:00'),(3, '2012-04-01', '12:00:00'),(4, '2012-05-01', '12:00:00'),(5, '2012-06-01', '12:00:00'),(6, '2012-07-01', '12:00:00'),(7, '2012-08-01', '12:00:00'),(8, '2012-09-01', '12:00:00'),(9, '2012-10-01', '12:00:00'); +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2013-01-01', '13:00:00'),(1, '2013-02-01', '13:00:00'),(2, '2013-03-01', '13:00:00'),(3, '2013-04-01', '13:00:00'),(4, '2013-05-01', '13:00:00'),(5, '2013-06-01', '13:00:00'),(6, '2013-07-01', '13:00:00'),(7, '2013-08-01', '13:00:00'),(8, '2013-09-01', '13:00:00'),(9, '2013-10-01', '13:00:00'); +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-11-01', '11:00:00'),(1, '2012-12-01', '11:00:00'),(2, '2012-11-30', '11:00:00'),(3, '2012-11-29', '11:00:00'),(4, '2012-11-28', '11:00:00'),(5, '2012-11-27', '11:00:00'),(6, '2012-11-26', '11:00:00'),(7, '2012-11-25', '11:00:00'),(8, '2012-11-24', '11:00:00'),(9, '2012-11-23', '11:00:00'); +FLUSH TABLES; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +EXE_MYSQL -v -v -u root -h localhost -P MASTER_1_MYPORT -S MASTER_1_MYSOCK -e "UPDATE tbl_a SET tm = '12:00:00' WHERE skey = 0" auto_test_local +-------------- +UPDATE tbl_a SET tm = '12:00:00' WHERE skey = 0 +-------------- + +Query OK, 2 rows affected +Rows matched: 3 Changed: 2 Warnings: 0 + +Bye +connection child2_1; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; +argument +update `auto_test_remote`.`tbl_a` set `tm` = _latin1'12:00:00' where (`skey` = 0) +SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %' +SELECT skey, dt, tm FROM tbl_a ORDER BY skey; +skey dt tm +0 2012-01-01 12:00:00 +0 2013-01-01 12:00:00 +0 2012-11-01 12:00:00 +1 2012-12-01 11:00:00 +1 2013-02-01 13:00:00 +1 2012-02-01 12:00:00 +2 2013-03-01 13:00:00 +2 2012-11-30 11:00:00 +2 2012-03-01 12:00:00 +3 2012-11-29 11:00:00 +3 2013-04-01 13:00:00 +3 2012-04-01 12:00:00 +4 2012-11-28 11:00:00 +4 2012-05-01 12:00:00 +4 2013-05-01 13:00:00 +5 2012-11-27 11:00:00 +5 2012-06-01 12:00:00 +5 2013-06-01 13:00:00 +6 2013-07-01 13:00:00 +6 2012-11-26 11:00:00 +6 2012-07-01 12:00:00 +7 2012-11-25 11:00:00 +7 2012-08-01 12:00:00 +7 2013-08-01 13:00:00 +8 2012-09-01 12:00:00 +8 2013-09-01 13:00:00 +8 2012-11-24 11:00:00 +9 2012-10-01 12:00:00 +9 2013-10-01 13:00:00 +9 2012-11-23 11:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_insert.cnf b/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_insert.cnf new file mode 100644 index 00000000000..05dfd8a0bce --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_insert.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_insert.test b/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_insert.test new file mode 100644 index 00000000000..ea2a2147910 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_insert.test @@ -0,0 +1,98 @@ +--source ../include/return_found_rows_insert_init.inc +--echo +--echo this test is for MDEV-18973 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + skey int NOT NULL, + dt date NOT NULL, + tm time NOT NULL, + PRIMARY KEY (skey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + skey int NOT NULL, + dt date NOT NULL, + tm time NOT NULL, + PRIMARY KEY (skey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-01-01', '12:00:00'),(1, '2012-02-01', '12:00:00'),(2, '2012-03-01', '12:00:00'),(3, '2012-04-01', '12:00:00'),(4, '2012-05-01', '12:00:00'),(5, '2012-06-01', '12:00:00'),(6, '2012-07-01', '12:00:00'),(7, '2012-08-01', '12:00:00'),(8, '2012-09-01', '12:00:00'),(9, '2012-10-01', '12:00:00'); +FLUSH TABLES; + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--disable_query_log +echo EXE_MYSQL -v -v -u root -h localhost -P MASTER_1_MYPORT -S MASTER_1_MYSOCK -e "MASTER_1_SET_COMMAND INSERT IGNORE INTO tbl_a (skey, dt, tm) VALUES (0, '2013-01-01', '13:00:00'),(2, '2013-02-01', '13:00:00'),(4, '2013-03-01', '13:00:00'),(7, '2013-04-01', '13:00:00'),(8, '2013-05-01', '13:00:00'),(10, '2013-06-01', '13:00:00'),(11, '2013-07-01', '13:00:00'),(12, '2013-08-01', '13:00:00'),(13, '2013-09-01', '13:00:00'),(14, '2013-10-01', '13:00:00')" auto_test_local; +exec $EXE_MYSQL -v -v -u root -h localhost -P $MASTER_1_MYPORT -S $MASTER_1_MYSOCK -e "$MASTER_1_SET_COMMAND INSERT IGNORE INTO tbl_a (skey, dt, tm) VALUES (0, '2013-01-01', '13:00:00'),(2, '2013-02-01', '13:00:00'),(4, '2013-03-01', '13:00:00'),(7, '2013-04-01', '13:00:00'),(8, '2013-05-01', '13:00:00'),(10, '2013-06-01', '13:00:00'),(11, '2013-07-01', '13:00:00'),(12, '2013-08-01', '13:00:00'),(13, '2013-09-01', '13:00:00'),(14, '2013-10-01', '13:00:00')" auto_test_local; +--enable_query_log + +--connection child2_1 +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; + +TRUNCATE TABLE mysql.general_log; + +--disable_query_log +echo EXE_MYSQL -v -v -u root -h localhost -P MASTER_1_MYPORT -S MASTER_1_MYSOCK -e "MASTER_1_SET_COMMAND REPLACE INTO tbl_a (skey, dt, tm) VALUES (1, '2012-02-01', '12:00:00'),(3, '2012-12-01', '11:00:00'),(8, '2012-11-30', '11:00:00'),(9, '2012-11-29', '11:00:00'),(10, '2012-11-28', '11:00:00'),(15, '2012-11-27', '11:00:00'),(16, '2012-11-26', '11:00:00'),(17, '2012-11-25', '11:00:00'),(18, '2012-11-24', '11:00:00'),(19, '2012-11-23', '11:00:00')" auto_test_local; +exec $EXE_MYSQL -v -v -u root -h localhost -P $MASTER_1_MYPORT -S $MASTER_1_MYSOCK -e "$MASTER_1_SET_COMMAND REPLACE INTO tbl_a (skey, dt, tm) VALUES (1, '2012-02-01', '12:00:00'),(3, '2012-12-01', '11:00:00'),(8, '2012-11-30', '11:00:00'),(9, '2012-11-29', '11:00:00'),(10, '2012-11-28', '11:00:00'),(15, '2012-11-27', '11:00:00'),(16, '2012-11-26', '11:00:00'),(17, '2012-11-25', '11:00:00'),(18, '2012-11-24', '11:00:00'),(19, '2012-11-23', '11:00:00')" auto_test_local; +--enable_query_log + +--connection child2_1 +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; + +TRUNCATE TABLE mysql.general_log; + +--disable_query_log +echo EXE_MYSQL -v -v -u root -h localhost -P MASTER_1_MYPORT -S MASTER_1_MYSOCK -e "MASTER_1_SET_COMMAND INSERT INTO tbl_a (skey, dt, tm) VALUES (1, '2012-11-01', '11:00:00'),(3, '2012-12-01', '11:00:00'),(11, '2012-11-30', '11:00:00'),(15, '2012-11-29', '11:00:00'),(16, '2012-11-28', '11:00:00'),(20, '2012-11-27', '11:00:00'),(21, '2012-11-26', '11:00:00'),(22, '2012-11-25', '11:00:00'),(23, '2012-11-24', '11:00:00'),(24, '2012-11-23', '11:00:00') ON DUPLICATE KEY UPDATE dt=VALUE(dt), tm=VALUE(tm)" auto_test_local; +exec $EXE_MYSQL -v -v -u root -h localhost -P $MASTER_1_MYPORT -S $MASTER_1_MYSOCK -e "$MASTER_1_SET_COMMAND INSERT INTO tbl_a (skey, dt, tm) VALUES (1, '2012-11-01', '11:00:00'),(3, '2012-12-01', '11:00:00'),(11, '2012-11-30', '11:00:00'),(15, '2012-11-29', '11:00:00'),(16, '2012-11-28', '11:00:00'),(20, '2012-11-27', '11:00:00'),(21, '2012-11-26', '11:00:00'),(22, '2012-11-25', '11:00:00'),(23, '2012-11-24', '11:00:00'),(24, '2012-11-23', '11:00:00') ON DUPLICATE KEY UPDATE dt=VALUE(dt), tm=VALUE(tm)" auto_test_local; +--enable_query_log + +--connection child2_1 +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/return_found_rows_insert_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_update.cnf b/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_update.cnf new file mode 100644 index 00000000000..05dfd8a0bce --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_update.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_update.test b/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_update.test new file mode 100644 index 00000000000..31f1d9c4c6c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/return_found_rows_update.test @@ -0,0 +1,78 @@ +--source ../include/return_found_rows_update_init.inc +--echo +--echo this test is for MDEV-18973 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + skey int NOT NULL, + dt date NOT NULL, + tm time NOT NULL, + KEY idx1 (skey,dt) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + skey int NOT NULL, + dt date NOT NULL, + tm time NOT NULL, + KEY idx1 (skey,dt) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-01-01', '12:00:00'),(1, '2012-02-01', '12:00:00'),(2, '2012-03-01', '12:00:00'),(3, '2012-04-01', '12:00:00'),(4, '2012-05-01', '12:00:00'),(5, '2012-06-01', '12:00:00'),(6, '2012-07-01', '12:00:00'),(7, '2012-08-01', '12:00:00'),(8, '2012-09-01', '12:00:00'),(9, '2012-10-01', '12:00:00'); +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2013-01-01', '13:00:00'),(1, '2013-02-01', '13:00:00'),(2, '2013-03-01', '13:00:00'),(3, '2013-04-01', '13:00:00'),(4, '2013-05-01', '13:00:00'),(5, '2013-06-01', '13:00:00'),(6, '2013-07-01', '13:00:00'),(7, '2013-08-01', '13:00:00'),(8, '2013-09-01', '13:00:00'),(9, '2013-10-01', '13:00:00'); +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-11-01', '11:00:00'),(1, '2012-12-01', '11:00:00'),(2, '2012-11-30', '11:00:00'),(3, '2012-11-29', '11:00:00'),(4, '2012-11-28', '11:00:00'),(5, '2012-11-27', '11:00:00'),(6, '2012-11-26', '11:00:00'),(7, '2012-11-25', '11:00:00'),(8, '2012-11-24', '11:00:00'),(9, '2012-11-23', '11:00:00'); +FLUSH TABLES; + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--disable_query_log +echo EXE_MYSQL -v -v -u root -h localhost -P MASTER_1_MYPORT -S MASTER_1_MYSOCK -e "UPDATE tbl_a SET tm = '12:00:00' WHERE skey = 0" auto_test_local; +exec $EXE_MYSQL -v -v -u root -h localhost -P $MASTER_1_MYPORT -S $MASTER_1_MYSOCK -e "UPDATE tbl_a SET tm = '12:00:00' WHERE skey = 0" auto_test_local; +--enable_query_log + +--connection child2_1 +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/return_found_rows_update_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 6be75dad17f..70e125b6def 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -5973,6 +5973,7 @@ int spider_db_bulk_insert_init( int spider_db_bulk_insert( ha_spider *spider, TABLE *table, + ha_copy_info *copy_info, bool bulk_end ) { int error_num, first_insert_link_idx = -1; @@ -6019,6 +6020,7 @@ int spider_db_bulk_insert( if (!spider->is_bulk_access_clone) { #endif + bool insert_info = FALSE; for ( roop_count2 = spider_conn_link_idx_next(share->link_statuses, spider->conn_link_idx, -1, share->link_count, @@ -6167,6 +6169,11 @@ int spider_db_bulk_insert( } conn->mta_conn_mutex_lock_already = mta_conn_mutex_lock_already_backup; conn->mta_conn_mutex_unlock_later = mta_conn_mutex_unlock_later_backup; + if (!insert_info && copy_info) + { + insert_info = + conn->db_conn->inserted_info(dbton_handler, copy_info); + } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind != SPIDER_CONN_KIND_MYSQL) { @@ -6920,7 +6927,8 @@ int spider_db_direct_update( TABLE *table, KEY_MULTI_RANGE *ranges, uint range_count, - ha_rows *update_rows + ha_rows *update_rows, + ha_rows *found_rows ) { int error_num, roop_count; SPIDER_SHARE *share = spider->share; @@ -7193,6 +7201,8 @@ int spider_db_direct_update( { *update_rows = spider->conns[roop_count]->db_conn->affected_rows(); DBUG_PRINT("info", ("spider update_rows = %llu", *update_rows)); + *found_rows = spider->conns[roop_count]->db_conn->matched_rows(); + DBUG_PRINT("info", ("spider found_rows = %llu", *found_rows)); counted = TRUE; } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) @@ -7214,6 +7224,8 @@ int spider_db_direct_update( { *update_rows = conn->db_conn->affected_rows(); DBUG_PRINT("info", ("spider update_rows = %llu", *update_rows)); + *found_rows = conn->db_conn->matched_rows(); + DBUG_PRINT("info", ("spider found_rows = %llu", *found_rows)); counted = TRUE; } result->free_result(); @@ -7251,7 +7263,8 @@ int spider_db_direct_update( int spider_db_direct_update( ha_spider *spider, TABLE *table, - ha_rows *update_rows + ha_rows *update_rows, + ha_rows *found_rows ) { int error_num, roop_count; SPIDER_SHARE *share = spider->share; @@ -7444,6 +7457,8 @@ int spider_db_direct_update( { *update_rows = spider->conns[roop_count]->db_conn->affected_rows(); DBUG_PRINT("info", ("spider update_rows = %llu", *update_rows)); + *found_rows = spider->conns[roop_count]->db_conn->matched_rows(); + DBUG_PRINT("info", ("spider found_rows = %llu", *found_rows)); counted = TRUE; } #ifdef HA_CAN_BULK_ACCESS @@ -7463,7 +7478,8 @@ int spider_db_direct_update( #ifdef HA_CAN_BULK_ACCESS int spider_db_bulk_direct_update( ha_spider *spider, - ha_rows *update_rows + ha_rows *update_rows, + ha_rows *found_rows ) { int error_num = 0, roop_count, tmp_error_num; SPIDER_SHARE *share = spider->share; @@ -7508,6 +7524,8 @@ int spider_db_bulk_direct_update( { *update_rows = spider->conns[roop_count]->db_conn->affected_rows(); DBUG_PRINT("info", ("spider update_rows = %llu", *update_rows)); + *found_rows = spider->conns[roop_count]->db_conn->matched_rows(); + DBUG_PRINT("info", ("spider found_rows = %llu", *found_rows)); counted = TRUE; } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) @@ -7529,6 +7547,8 @@ int spider_db_bulk_direct_update( { *update_rows = conn->db_conn->affected_rows(); DBUG_PRINT("info", ("spider update_rows = %llu", *update_rows)); + *found_rows = conn->db_conn->matched_rows(); + DBUG_PRINT("info", ("spider found_rows = %llu", *found_rows)); counted = TRUE; } result->free_result(); diff --git a/storage/spider/spd_db_conn.h b/storage/spider/spd_db_conn.h index 0300dc6c407..6fdb4b694ae 100644 --- a/storage/spider/spd_db_conn.h +++ b/storage/spider/spd_db_conn.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2008-2018 Kentoku Shiba +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -745,6 +746,7 @@ int spider_db_bulk_insert_init( int spider_db_bulk_insert( ha_spider *spider, TABLE *table, + ha_copy_info *copy_info, bool bulk_end ); @@ -788,13 +790,15 @@ int spider_db_direct_update( TABLE *table, KEY_MULTI_RANGE *ranges, uint range_count, - ha_rows *update_rows + ha_rows *update_rows, + ha_rows *found_rows ); #else int spider_db_direct_update( ha_spider *spider, TABLE *table, - ha_rows *update_rows + ha_rows *update_rows, + ha_rows *found_rows ); #endif #endif diff --git a/storage/spider/spd_db_handlersocket.cc b/storage/spider/spd_db_handlersocket.cc index d4872e6ae81..b8e4c0e705a 100644 --- a/storage/spider/spd_db_handlersocket.cc +++ b/storage/spider/spd_db_handlersocket.cc @@ -1655,6 +1655,22 @@ uint spider_db_handlersocket::affected_rows() DBUG_RETURN((uint) my_strtoll10(hs_row->begin(), (char**) NULL, &error_num)); } +uint spider_db_handlersocket::matched_rows() +{ + DBUG_ENTER("spider_db_handlersocket::matched_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +bool spider_db_handlersocket::inserted_info( + spider_db_handler *handler, + ha_copy_info *copy_info +) { + DBUG_ENTER("spider_db_handlersocket::inserted_info"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + ulonglong spider_db_handlersocket::last_insert_id() { DBUG_ENTER("spider_db_handlersocket::last_insert_id"); diff --git a/storage/spider/spd_db_handlersocket.h b/storage/spider/spd_db_handlersocket.h index d2beb2124c0..19a4a391ed6 100644 --- a/storage/spider/spd_db_handlersocket.h +++ b/storage/spider/spd_db_handlersocket.h @@ -335,6 +335,11 @@ public: ); int next_result(); uint affected_rows(); + uint matched_rows(); + bool inserted_info( + spider_db_handler *handler, + spider_copy_info *copy_info + ); ulonglong last_insert_id(); int set_character_set( const char *csname diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index 2f401fa8ff8..046fe66435c 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -255,6 +255,7 @@ typedef struct st_spider_transaction SPIDER_TRX; typedef struct st_spider_share SPIDER_SHARE; class ha_spider; class spider_db_copy_table; +class spider_db_handler; class spider_string { @@ -1105,6 +1106,11 @@ public: ) = 0; virtual int next_result() = 0; virtual uint affected_rows() = 0; + virtual uint matched_rows() = 0; + virtual bool inserted_info( + spider_db_handler *handler, + ha_copy_info *copy_info + ) = 0; virtual ulonglong last_insert_id() = 0; virtual int set_character_set( const char *csname diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index c4d6f08c394..0a634a60f42 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -184,6 +184,11 @@ static uchar SPIDER_SQL_LINESTRING_HEAD_STR[] = {0x00,0x00,0x00,0x00,0x01,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00}; #define SPIDER_SQL_LINESTRING_HEAD_LEN sizeof(SPIDER_SQL_LINESTRING_HEAD_STR) +#define SPIDER_SQL_DIRECT_INSERT_KIND_INSERT 0 +#define SPIDER_SQL_DIRECT_INSERT_KIND_REPLACE 1 +#define SPIDER_SQL_DIRECT_INSERT_KIND_IGNORE 2 +#define SPIDER_SQL_DIRECT_INSERT_KIND_DUP_UPDATE 3 + static const char *spider_db_table_lock_str[] = { " read local,", @@ -2444,6 +2449,81 @@ uint spider_db_mbase::affected_rows() DBUG_RETURN((uint) last_used_con->affected_rows); } +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) + DBUG_RETURN(0); + DBUG_PRINT("info", ("spider info=%s", info)); + const char *begin = strstr(info, "Rows matched: "); + if (!begin) + DBUG_RETURN(0); + DBUG_RETURN(atoi(begin + strlen("Rows matched: "))); +} + +bool spider_db_mbase::inserted_info( + spider_db_handler *handler, + ha_copy_info *copy_info +) { + MYSQL *last_used_con; + uchar direct_insert_kind = + ((spider_mbase_handler *) handler)->direct_insert_kind; + DBUG_ENTER("spider_db_mysql::inserted_info"); + DBUG_PRINT("info", ("spider this=%p", this)); + if (direct_insert_kind == SPIDER_SQL_DIRECT_INSERT_KIND_INSERT) + { + 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) + DBUG_RETURN(FALSE); + DBUG_PRINT("info", ("spider info=%s", info)); + const char *begin = strstr(info, "Records: "); + if (!begin) + DBUG_RETURN(FALSE); + begin += strlen("Records: "); + uint records = atoi(begin); + begin = strstr(begin, "Duplicates: "); + if (!begin) + DBUG_RETURN(FALSE); + uint duplicates = atoi(begin + strlen("Duplicates: ")); + copy_info->records+= records; + switch (direct_insert_kind) + { + case SPIDER_SQL_DIRECT_INSERT_KIND_IGNORE: + copy_info->copied+= duplicates; + break; + case SPIDER_SQL_DIRECT_INSERT_KIND_REPLACE: + copy_info->copied+= records; + copy_info->deleted+= duplicates; + break; + case SPIDER_SQL_DIRECT_INSERT_KIND_DUP_UPDATE: + copy_info->touched+= (last_used_con->affected_rows - (duplicates * 2)); + copy_info->copied+= (last_used_con->affected_rows - duplicates); + copy_info->updated+= duplicates; + break; + default: + DBUG_ASSERT(0); + DBUG_RETURN(FALSE); + } + DBUG_RETURN(TRUE); +} + ulonglong spider_db_mbase::last_insert_id() { MYSQL *last_used_con; @@ -9017,6 +9097,7 @@ int spider_mbase_handler::append_insert( ) { SPIDER_SHARE *share = spider->share; DBUG_ENTER("spider_mbase_handler::append_insert"); + direct_insert_kind = SPIDER_SQL_DIRECT_INSERT_KIND_INSERT; if ( ( spider->write_can_replace || @@ -9026,6 +9107,7 @@ int spider_mbase_handler::append_insert( ) && spider->direct_dup_insert ) { + direct_insert_kind = SPIDER_SQL_DIRECT_INSERT_KIND_REPLACE; if (str->reserve(SPIDER_SQL_REPLACE_LEN)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_REPLACE_STR, SPIDER_SQL_REPLACE_LEN); @@ -9073,6 +9155,7 @@ int spider_mbase_handler::append_insert( spider->sql_command != SQLCOM_REPLACE && spider->sql_command != SQLCOM_REPLACE_SELECT ) { + direct_insert_kind = SPIDER_SQL_DIRECT_INSERT_KIND_IGNORE; if (str->reserve(SPIDER_SQL_SQL_IGNORE_LEN)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_SQL_IGNORE_STR, SPIDER_SQL_SQL_IGNORE_LEN); @@ -11911,6 +11994,7 @@ int spider_mbase_handler::append_insert_terminator( dup_update_sql.length() ) { DBUG_PRINT("info",("spider add duplicate key update")); + direct_insert_kind = SPIDER_SQL_DIRECT_INSERT_KIND_DUP_UPDATE; str->length(str->length() - SPIDER_SQL_COMMA_LEN); if (str->reserve(SPIDER_SQL_DUPLICATE_KEY_UPDATE_LEN + dup_update_sql.length())) diff --git a/storage/spider/spd_db_mysql.h b/storage/spider/spd_db_mysql.h index 51db3b1f2fa..626bb4d5624 100644 --- a/storage/spider/spd_db_mysql.h +++ b/storage/spider/spd_db_mysql.h @@ -453,6 +453,11 @@ public: ); int next_result(); uint affected_rows(); + uint matched_rows(); + bool inserted_info( + spider_db_handler *handler, + ha_copy_info *copy_info + ); ulonglong last_insert_id(); int set_character_set( const char *csname @@ -801,6 +806,7 @@ public: spider_mbase_share *mysql_share; SPIDER_LINK_FOR_HASH *link_for_hash; uchar *minimum_select_bitmap; + uchar direct_insert_kind; spider_mbase_handler( ha_spider *spider, spider_mbase_share *share, diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index 097130169c7..dff0060b0c7 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -1731,6 +1731,22 @@ uint spider_db_oracle::affected_rows() DBUG_RETURN(update_rows); } +uint spider_db_oracle::matched_rows() +{ + DBUG_ENTER("spider_db_oracle::matched_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +bool spider_db_oracle::inserted_info( + spider_db_handler *handler, + ha_copy_info *copy_info +) { + DBUG_ENTER("spider_db_oracle::inserted_info"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + ulonglong spider_db_oracle::last_insert_id() { DBUG_ENTER("spider_db_oracle::last_insert_id"); diff --git a/storage/spider/spd_db_oracle.h b/storage/spider/spd_db_oracle.h index a4be417bc67..ebdc23a9bfa 100644 --- a/storage/spider/spd_db_oracle.h +++ b/storage/spider/spd_db_oracle.h @@ -385,6 +385,11 @@ public: ); int next_result(); uint affected_rows(); + uint matched_rows(); + bool inserted_info( + spider_db_handler *handler, + ha_copy_info *copy_info + ); ulonglong last_insert_id(); int set_character_set( const char *csname |