summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKentoku <kentokushiba@gmail.com>2019-11-08 10:27:07 +0900
committerKentoku <kentokushiba@gmail.com>2019-11-09 05:57:16 +0900
commit0cf2ebd18acd945b04111133ccbb479cbc81d405 (patch)
tree769a262ef5322079f594cd6665aede8b065221e4
parentc24ec3cece6d8bf70dac7519b6fd397c464f7a82 (diff)
downloadmariadb-git-bb-10.4-MDEV-18973.tar.gz
MDEV-18973 CLIENT_FOUND_ROWS wrong in spiderbb-10.4-MDEV-18973
Get count from last_used_con->info Contributed by willhan at Tencent Games
-rw-r--r--sql/ha_partition.cc35
-rw-r--r--sql/ha_partition.h4
-rw-r--r--sql/handler.cc15
-rw-r--r--sql/handler.h25
-rw-r--r--sql/sql_insert.cc54
-rw-r--r--sql/sql_load.cc2
-rw-r--r--sql/sql_update.cc14
-rw-r--r--storage/spider/ha_spider.cc55
-rw-r--r--storage/spider/ha_spider.h24
-rw-r--r--storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_deinit.inc11
-rw-r--r--storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_init.inc27
-rw-r--r--storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_deinit.inc11
-rw-r--r--storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_init.inc26
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/return_found_rows_insert.result179
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/return_found_rows_update.result99
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/return_found_rows_insert.cnf3
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/return_found_rows_insert.test98
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/return_found_rows_update.cnf3
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/return_found_rows_update.test78
-rw-r--r--storage/spider/spd_db_conn.cc26
-rw-r--r--storage/spider/spd_db_conn.h10
-rw-r--r--storage/spider/spd_db_handlersocket.cc16
-rw-r--r--storage/spider/spd_db_handlersocket.h5
-rw-r--r--storage/spider/spd_db_include.h6
-rw-r--r--storage/spider/spd_db_mysql.cc83
-rw-r--r--storage/spider/spd_db_mysql.h6
-rw-r--r--storage/spider/spd_db_oracle.cc16
-rw-r--r--storage/spider/spd_db_oracle.h5
28 files changed, 887 insertions, 49 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index baf8f88c00c..256a9fff69d 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -4270,6 +4270,13 @@ void ha_partition::try_semi_consistent_read(bool yes)
int ha_partition::write_row(const uchar * buf)
{
+ DBUG_ENTER("ha_partition::write_row");
+ DBUG_RETURN(write_row_ext(buf, NULL));
+}
+
+
+int ha_partition::write_row_ext(const uchar * buf, COPY_INFO *info)
+{
uint32 part_id;
int error;
longlong func_value;
@@ -4278,7 +4285,7 @@ int ha_partition::write_row(const uchar * buf)
THD *thd= ha_thd();
sql_mode_t saved_sql_mode= thd->variables.sql_mode;
bool saved_auto_inc_field_not_null= table->auto_increment_field_not_null;
- DBUG_ENTER("ha_partition::write_row");
+ DBUG_ENTER("ha_partition::write_row_ext");
DBUG_PRINT("enter", ("partition this: %p", this));
/*
@@ -4336,7 +4343,8 @@ int ha_partition::write_row(const uchar * buf)
start_part_bulk_insert(thd, part_id);
tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
- error= m_file[part_id]->ha_write_row(buf);
+ error= info ? m_file[part_id]->ha_write_row_ext(buf, info) :
+ m_file[part_id]->ha_write_row(buf);
if (have_auto_increment && !table->s->next_number_keypart)
set_auto_increment_if_higher(table->next_number_field);
reenable_binlog(thd);
@@ -4839,9 +4847,16 @@ ha_rows ha_partition::guess_bulk_insert_rows()
int ha_partition::end_bulk_insert()
{
+ DBUG_ENTER("ha_partition::end_bulk_insert");
+ DBUG_RETURN(end_bulk_insert_ext(NULL));
+}
+
+
+int ha_partition::end_bulk_insert_ext(COPY_INFO *info)
+{
int error= 0;
uint i;
- DBUG_ENTER("ha_partition::end_bulk_insert");
+ DBUG_ENTER("ha_partition::end_bulk_insert_ext");
if (!bitmap_is_set(&m_bulk_insert_started, m_tot_parts))
DBUG_RETURN(error);
@@ -4851,7 +4866,8 @@ int ha_partition::end_bulk_insert()
i= bitmap_get_next_set(&m_bulk_insert_started, i))
{
int tmp;
- if ((tmp= m_file[i]->ha_end_bulk_insert()))
+ if ((tmp= info ? m_file[i]->ha_end_bulk_insert_ext(info) :
+ m_file[i]->ha_end_bulk_insert()))
error= tmp;
}
bitmap_clear_all(&m_bulk_insert_started);
@@ -11420,11 +11436,13 @@ int ha_partition::pre_direct_update_rows_init(List<Item> *update_fields)
0 Success
*/
-int ha_partition::direct_update_rows(ha_rows *update_rows_result)
+int ha_partition::direct_update_rows(ha_rows *update_rows_result,
+ ha_rows *found_rows_result)
{
int error;
bool rnd_seq= FALSE;
ha_rows update_rows= 0;
+ ha_rows found_rows= 0;
uint32 i;
DBUG_ENTER("ha_partition::direct_update_rows");
@@ -11436,6 +11454,7 @@ int ha_partition::direct_update_rows(ha_rows *update_rows_result)
}
*update_rows_result= 0;
+ *found_rows_result= 0;
for (i= m_part_spec.start_part; i <= m_part_spec.end_part; i++)
{
handler *file= m_file[i];
@@ -11451,7 +11470,8 @@ int ha_partition::direct_update_rows(ha_rows *update_rows_result)
}
if (unlikely((error= (m_pre_calling ?
(file)->pre_direct_update_rows() :
- (file)->ha_direct_update_rows(&update_rows)))))
+ (file)->ha_direct_update_rows(&update_rows,
+ &found_rows)))))
{
if (rnd_seq)
{
@@ -11463,6 +11483,7 @@ int ha_partition::direct_update_rows(ha_rows *update_rows_result)
DBUG_RETURN(error);
}
*update_rows_result+= update_rows;
+ *found_rows_result+= found_rows;
}
if (rnd_seq)
{
@@ -11498,7 +11519,7 @@ int ha_partition::pre_direct_update_rows()
DBUG_ENTER("ha_partition::pre_direct_update_rows");
save_m_pre_calling= m_pre_calling;
m_pre_calling= TRUE;
- error= direct_update_rows(&not_used);
+ error= direct_update_rows(&not_used, &not_used);
m_pre_calling= save_m_pre_calling;
DBUG_RETURN(error);
}
diff --git a/sql/ha_partition.h b/sql/ha_partition.h
index 598c63837c7..fea4d284e06 100644
--- a/sql/ha_partition.h
+++ b/sql/ha_partition.h
@@ -649,6 +649,7 @@ public:
number of calls to write_row.
*/
virtual int write_row(const uchar * buf);
+ virtual int write_row_ext(const uchar * buf, COPY_INFO *info);
virtual bool start_bulk_update();
virtual int exec_bulk_update(ha_rows *dup_key_found);
virtual int end_bulk_update();
@@ -657,7 +658,7 @@ public:
virtual int update_row(const uchar * old_data, const uchar * new_data);
virtual int direct_update_rows_init(List<Item> *update_fields);
virtual int pre_direct_update_rows_init(List<Item> *update_fields);
- virtual int direct_update_rows(ha_rows *update_rows);
+ virtual int direct_update_rows(ha_rows *update_rows, ha_rows *found_rows);
virtual int pre_direct_update_rows();
virtual bool start_bulk_delete();
virtual int end_bulk_delete();
@@ -670,6 +671,7 @@ public:
virtual int truncate();
virtual void start_bulk_insert(ha_rows rows, uint flags);
virtual int end_bulk_insert();
+ virtual int end_bulk_insert_ext(COPY_INFO *info);
private:
ha_rows guess_bulk_insert_rows();
void start_part_bulk_insert(THD *thd, uint part_id);
diff --git a/sql/handler.cc b/sql/handler.cc
index 72b11098060..cb7ac02a1ea 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -6652,11 +6652,18 @@ static int check_duplicate_long_entries_update(TABLE *table, handler *h, uchar *
int handler::ha_write_row(const uchar *buf)
{
+ DBUG_ENTER("handler::ha_write_row");
+ DBUG_RETURN(ha_write_row_ext(buf, NULL));
+}
+
+
+int handler::ha_write_row_ext(const uchar *buf, COPY_INFO *info)
+{
int error;
Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
m_lock_type == F_WRLCK);
- DBUG_ENTER("handler::ha_write_row");
+ DBUG_ENTER("handler::ha_write_row_ext");
DEBUG_SYNC_C("ha_write_row_start");
MYSQL_INSERT_ROW_START(table_share->db.str, table_share->table_name.str);
@@ -6672,7 +6679,7 @@ int handler::ha_write_row(const uchar *buf)
DBUG_RETURN(error);
}
TABLE_IO_WAIT(tracker, m_psi, PSI_TABLE_WRITE_ROW, MAX_KEY, 0,
- { error= write_row(buf); })
+ { error= info ? write_row_ext(buf, info) : write_row(buf); })
MYSQL_INSERT_ROW_DONE(error);
if (likely(!error) && !row_already_logged)
@@ -6812,14 +6819,14 @@ int handler::ha_delete_row(const uchar *buf)
@retval != 0 Failure.
*/
-int handler::ha_direct_update_rows(ha_rows *update_rows)
+int handler::ha_direct_update_rows(ha_rows *update_rows, ha_rows *found_rows)
{
int error;
MYSQL_UPDATE_ROW_START(table_share->db.str, table_share->table_name.str);
mark_trx_read_write();
- error = direct_update_rows(update_rows);
+ error = direct_update_rows(update_rows, found_rows);
MYSQL_UPDATE_ROW_DONE(error);
return error;
}
diff --git a/sql/handler.h b/sql/handler.h
index 2d25568488b..07ef73b9b27 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -2927,6 +2927,9 @@ public:
};
+typedef struct st_copy_info COPY_INFO;
+
+
/**
The handler class is the interface for dynamically loadable
storage engines. Do not add ifdefs and take care when adding or
@@ -3248,6 +3251,7 @@ public:
*/
int ha_external_lock(THD *thd, int lock_type);
int ha_write_row(const uchar * buf);
+ int ha_write_row_ext(const uchar * buf, COPY_INFO *info);
int ha_update_row(const uchar * old_data, const uchar * new_data);
int ha_delete_row(const uchar * buf);
void ha_release_auto_increment();
@@ -3286,6 +3290,13 @@ public:
int ret= end_bulk_insert();
DBUG_RETURN(ret);
}
+ int ha_end_bulk_insert_ext(COPY_INFO *info)
+ {
+ DBUG_ENTER("handler::ha_end_bulk_insert_ext");
+ estimation_rows_to_insert= 0;
+ int ret= end_bulk_insert_ext(info);
+ DBUG_RETURN(ret);
+ }
int ha_bulk_update_row(const uchar *old_data, const uchar *new_data,
ha_rows *dup_key_found);
int ha_delete_all_rows();
@@ -4571,6 +4582,11 @@ private:
{
return HA_ERR_WRONG_COMMAND;
}
+ virtual int write_row_ext(const uchar *buf,
+ COPY_INFO *info __attribute__((unused)))
+ {
+ return write_row(buf);
+ }
/**
Update a single row.
@@ -4599,7 +4615,7 @@ private:
/* Perform initialization for a direct update request */
public:
- int ha_direct_update_rows(ha_rows *update_rows);
+ int ha_direct_update_rows(ha_rows *update_rows, ha_rows *found_rows);
virtual int direct_update_rows_init(List<Item> *update_fields)
{
return HA_ERR_WRONG_COMMAND;
@@ -4609,7 +4625,8 @@ private:
{
return HA_ERR_WRONG_COMMAND;
}
- virtual int direct_update_rows(ha_rows *update_rows __attribute__((unused)))
+ virtual int direct_update_rows(ha_rows *update_rows __attribute__((unused)),
+ ha_rows *found_rows __attribute__((unused)))
{
return HA_ERR_WRONG_COMMAND;
}
@@ -4692,6 +4709,10 @@ private:
}
virtual void start_bulk_insert(ha_rows rows, uint flags) {}
virtual int end_bulk_insert() { return 0; }
+ virtual int end_bulk_insert_ext(COPY_INFO *info)
+ {
+ return end_bulk_insert();
+ }
protected:
virtual int index_read(uchar * buf, const uchar * key, uint key_len,
enum ha_rkey_function find_flag)
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 3ad3cf9151f..7c807e4d454 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -1107,7 +1107,8 @@ values_loop_end:
auto_inc values from the delayed_insert thread as they share TABLE.
*/
table->file->ha_release_auto_increment();
- if (using_bulk_insert && unlikely(table->file->ha_end_bulk_insert()) &&
+ if (using_bulk_insert &&
+ unlikely(table->file->ha_end_bulk_insert_ext(&info)) &&
!error)
{
table->file->print_error(my_errno,MYF(0));
@@ -1234,6 +1235,9 @@ values_loop_end:
retval= thd->lex->explain->send_explain(thd);
goto abort;
}
+ DBUG_PRINT("info", ("touched:%llu copied:%llu updated:%llu deleted:%llu",
+ (ulonglong) info.touched, (ulonglong) info.copied,
+ (ulonglong) info.updated, (ulonglong) info.deleted));
if ((iteration * values_list.elements) == 1 && (!(thd->variables.option_bits & OPTION_WARNINGS) ||
!thd->cuted_fields))
{
@@ -1709,7 +1713,8 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
if (info->handle_duplicates == DUP_REPLACE ||
info->handle_duplicates == DUP_UPDATE)
{
- while (unlikely(error=table->file->ha_write_row(table->record[0])))
+ while (unlikely(error=table->file->ha_write_row_ext(table->record[0],
+ info)))
{
uint key_nr;
/*
@@ -1850,6 +1855,10 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
table->file->restore_auto_increment();
info->touched++;
+ DBUG_PRINT("info",
+ ("touched:%llu copied:%llu updated:%llu deleted:%llu",
+ (ulonglong) info->touched, (ulonglong) info->copied,
+ (ulonglong) info->updated, (ulonglong) info->deleted));
if (different_records)
{
if (unlikely(error=table->file->ha_update_row(table->record[1],
@@ -1870,6 +1879,10 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
if (error != HA_ERR_RECORD_IS_THE_SAME)
{
info->updated++;
+ DBUG_PRINT("info",
+ ("touched:%llu copied:%llu updated:%llu deleted:%llu",
+ (ulonglong) info->touched, (ulonglong) info->copied,
+ (ulonglong) info->updated, (ulonglong) info->deleted));
if (table->versioned())
{
if (table->versioned(VERS_TIMESTAMP))
@@ -1886,10 +1899,18 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
restore_record(table, record[2]);
}
info->copied++;
+ DBUG_PRINT("info",
+ ("touched:%llu copied:%llu updated:%llu deleted:%llu",
+ (ulonglong) info->touched, (ulonglong) info->copied,
+ (ulonglong) info->updated,
+ (ulonglong) info->deleted));
}
}
else
+ {
+ DBUG_PRINT("info", ("HA_ERR_RECORD_IS_THE_SAME"));
error= 0;
+ }
/*
If ON DUP KEY UPDATE updates a row instead of inserting
one, it's like a regular UPDATE statement: it should not
@@ -1904,6 +1925,10 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
table->triggers->process_triggers(thd, TRG_EVENT_UPDATE,
TRG_ACTION_AFTER, TRUE));
info->copied++;
+ DBUG_PRINT("info",
+ ("touched:%llu copied:%llu updated:%llu deleted:%llu",
+ (ulonglong) info->touched, (ulonglong) info->copied,
+ (ulonglong) info->updated, (ulonglong) info->deleted));
}
/*
@@ -1959,6 +1984,10 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
if (likely(!error))
{
info->deleted++;
+ DBUG_PRINT("info",
+ ("touched:%llu copied:%llu updated:%llu deleted:%llu",
+ (ulonglong) info->touched, (ulonglong) info->copied,
+ (ulonglong) info->updated, (ulonglong) info->deleted));
if (table->versioned(VERS_TIMESTAMP))
{
store_record(table, record[2]);
@@ -1969,7 +1998,10 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
}
}
else
+ {
+ DBUG_PRINT("info", ("HA_ERR_RECORD_IS_THE_SAME"));
error= 0; // error was HA_ERR_RECORD_IS_THE_SAME
+ }
/*
Since we pretend that we have done insert we should call
its after triggers.
@@ -1997,9 +2029,21 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
if (unlikely(error))
goto err;
if (!table->versioned(VERS_TIMESTAMP))
+ {
info->deleted++;
+ DBUG_PRINT("info",
+ ("touched:%llu copied:%llu updated:%llu deleted:%llu",
+ (ulonglong) info->touched, (ulonglong) info->copied,
+ (ulonglong) info->updated, (ulonglong) info->deleted));
+ }
else
+ {
info->updated++;
+ DBUG_PRINT("info",
+ ("touched:%llu copied:%llu updated:%llu deleted:%llu",
+ (ulonglong) info->touched, (ulonglong) info->copied,
+ (ulonglong) info->updated, (ulonglong) info->deleted));
+ }
if (!table->file->has_transactions())
thd->transaction.stmt.modified_non_trans_table= TRUE;
if (table->triggers &&
@@ -2033,7 +2077,8 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
table->write_set != save_write_set)
table->column_bitmaps_set(save_read_set, save_write_set);
}
- else if (unlikely((error=table->file->ha_write_row(table->record[0]))))
+ else if (unlikely((error=table->file->ha_write_row_ext(table->record[0],
+ info))))
{
DEBUG_SYNC(thd, "write_row_noreplace");
if (!info->ignore ||
@@ -2048,6 +2093,9 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
after_trg_n_copied_inc:
info->copied++;
+ DBUG_PRINT("info", ("touched:%llu copied:%llu updated:%llu deleted:%llu",
+ (ulonglong) info->touched, (ulonglong) info->copied,
+ (ulonglong) info->updated, (ulonglong) info->deleted));
thd->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
trg_error= (table->triggers &&
table->triggers->process_triggers(thd, TRG_EVENT_INSERT,
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 89cc3f8da64..98f895af8be 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -677,7 +677,7 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list,
if (likely(!error))
thd_progress_next_stage(thd);
if (thd->locked_tables_mode <= LTM_LOCK_TABLES &&
- table->file->ha_end_bulk_insert() && !error)
+ table->file->ha_end_bulk_insert_ext(&info) && !error)
{
table->file->print_error(my_errno, MYF(0));
error= 1;
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index f5bb298fdba..cfe3ce1e4f3 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -718,6 +718,11 @@ int mysql_update(THD *thd,
Later we also ensure that we are only using one table (no sub queries)
*/
+ DBUG_PRINT("info", ("HA_CAN_DIRECT_UPDATE_AND_DELETE: %s", (table->file->ha_table_flags() & HA_CAN_DIRECT_UPDATE_AND_DELETE) ? "TRUE" : "FALSE"));
+ DBUG_PRINT("info", ("using_io_buffer: %s", query_plan.using_io_buffer ? "TRUE" : "FALSE"));
+ DBUG_PRINT("info", ("ignore: %s", ignore ? "TRUE" : "FALSE"));
+ DBUG_PRINT("info", ("virtual_columns_marked_for_read: %s", table->check_virtual_columns_marked_for_read() ? "TRUE" : "FALSE"));
+ DBUG_PRINT("info", ("virtual_columns_marked_for_write: %s", table->check_virtual_columns_marked_for_write() ? "TRUE" : "FALSE"));
if ((table->file->ha_table_flags() & HA_CAN_DIRECT_UPDATE_AND_DELETE) &&
!has_triggers && !binlog_is_row &&
!query_plan.using_io_buffer && !ignore &&
@@ -928,11 +933,16 @@ update_begin:
if (do_direct_update)
{
/* Direct updating is supported */
+ ha_rows update_rows= 0, found_rows= 0;
DBUG_PRINT("info", ("Using direct update"));
table->reset_default_fields();
- if (unlikely(!(error= table->file->ha_direct_update_rows(&updated))))
+ if (unlikely(!(error= table->file->ha_direct_update_rows(&update_rows,
+ &found_rows))))
error= -1;
- found= updated;
+ updated= update_rows;
+ found= found_rows;
+ if (found < updated)
+ found= updated;
goto update_end;
}
diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc
index 5457bc0ba50..f61ec4af458 100644
--- a/storage/spider/ha_spider.cc
+++ b/storage/spider/ha_spider.cc
@@ -9783,14 +9783,22 @@ void ha_spider::start_bulk_insert(
int ha_spider::end_bulk_insert()
{
+ DBUG_ENTER("ha_spider::end_bulk_insert");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(end_bulk_insert_ext(NULL));
+}
+
+int ha_spider::end_bulk_insert_ext(
+ COPY_INFO *copy_info
+) {
int error_num;
backup_error_status();
- DBUG_ENTER("ha_spider::end_bulk_insert");
+ DBUG_ENTER("ha_spider::end_bulk_insert_ext");
DBUG_PRINT("info",("spider this=%p", this));
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, copy_info, TRUE)))
DBUG_RETURN(check_error_mode(error_num));
DBUG_RETURN(0);
}
@@ -9798,6 +9806,15 @@ int ha_spider::end_bulk_insert()
int ha_spider::write_row(
const uchar *buf
) {
+ DBUG_ENTER("ha_spider::write_row");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(write_row_ext(buf, NULL));
+}
+
+int ha_spider::write_row_ext(
+ const uchar *buf,
+ COPY_INFO *copy_info
+) {
int error_num;
THD *thd = ha_thd();
int auto_increment_mode = spider_param_auto_increment_mode(thd,
@@ -9805,7 +9822,7 @@ int ha_spider::write_row(
bool auto_increment_flag =
table->next_number_field && buf == table->record[0];
backup_error_status();
- DBUG_ENTER("ha_spider::write_row");
+ DBUG_ENTER("ha_spider::write_row_ext");
DBUG_PRINT("info",("spider this=%p", this));
if (spider_param_read_only_mode(thd, share->read_only_mode))
{
@@ -9924,7 +9941,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, copy_info, FALSE)))
DBUG_RETURN(check_error_mode(error_num));
#ifdef HA_CAN_BULK_ACCESS
@@ -10549,7 +10566,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 +10594,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 +10612,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 +10647,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 +10664,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 +10678,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..aadd0bc6c0c 100644
--- a/storage/spider/ha_spider.h
+++ b/storage/spider/ha_spider.h
@@ -567,9 +567,16 @@ public:
);
#endif
int end_bulk_insert();
+ int end_bulk_insert_ext(
+ COPY_INFO *copy_info
+ );
int write_row(
const uchar *buf
);
+ int write_row_ext(
+ const uchar *buf,
+ COPY_INFO *copy_info
+ );
#ifdef HA_CAN_BULK_ACCESS
int pre_write_row(
uchar *buf
@@ -685,20 +692,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 +715,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..8098e532591 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,
+ 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..b884d2f8a36 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,
+ 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..e38b7e36a41 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,
+ 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..677705872bc 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,
+ 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..e917cfd6d99 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,
+ 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..26d8a064ba4 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,80 @@ 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,
+ 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: "));
+ switch (direct_insert_kind)
+ {
+ case SPIDER_SQL_DIRECT_INSERT_KIND_IGNORE:
+ copy_info->copied -= (records - duplicates);
+ break;
+ case SPIDER_SQL_DIRECT_INSERT_KIND_REPLACE:
+ 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 -=
+ (records + duplicates - last_used_con->affected_rows);
+ 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 +9096,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 +9106,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 +9154,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 +11993,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..8430131a9a4 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,
+ 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..580c717e076 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,
+ 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..95ffe4bacdd 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,
+ COPY_INFO *copy_info
+ );
ulonglong last_insert_id();
int set_character_set(
const char *csname