Skip to content

Commit e066723

Browse files
committed
MDEV-18973 CLIENT_FOUND_ROWS wrong in spider
Get count from last_used_con->info Contributed by willhan at Tencent Games
1 parent 3826178 commit e066723

27 files changed

+846
-43
lines changed

sql/ha_partition.cc

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4822,6 +4822,42 @@ ha_rows ha_partition::guess_bulk_insert_rows()
48224822
}
48234823

48244824

4825+
void ha_partition::sum_copy_info(handler *file)
4826+
{
4827+
copy_info.records+= file->copy_info.records;
4828+
copy_info.touched+= file->copy_info.touched;
4829+
copy_info.copied+= file->copy_info.copied;
4830+
copy_info.deleted+= file->copy_info.deleted;
4831+
copy_info.updated+= file->copy_info.updated;
4832+
}
4833+
4834+
4835+
void ha_partition::sum_copy_infos()
4836+
{
4837+
handler **file_array;
4838+
bzero(&copy_info, sizeof(copy_info));
4839+
file_array= m_file;
4840+
do
4841+
{
4842+
if (bitmap_is_set(&(m_opened_partitions), (uint)(file_array - m_file)))
4843+
sum_copy_info(*file_array);
4844+
} while (*(++file_array));
4845+
}
4846+
4847+
void ha_partition::reset_copy_info()
4848+
{
4849+
handler **file_array;
4850+
bzero(&copy_info, sizeof(copy_info));
4851+
file_array= m_file;
4852+
do
4853+
{
4854+
if (bitmap_is_set(&(m_opened_partitions), (uint)(file_array - m_file)))
4855+
bzero(&(*file_array)->copy_info, sizeof(copy_info));
4856+
} while (*(++file_array));
4857+
}
4858+
4859+
4860+
48254861
/*
48264862
Finish a large batch of insert rows
48274863
@@ -4853,6 +4889,7 @@ int ha_partition::end_bulk_insert()
48534889
int tmp;
48544890
if ((tmp= m_file[i]->ha_end_bulk_insert()))
48554891
error= tmp;
4892+
sum_copy_info(m_file[i]);
48564893
}
48574894
bitmap_clear_all(&m_bulk_insert_started);
48584895
DBUG_RETURN(error);
@@ -11164,6 +11201,7 @@ bool ha_partition::start_bulk_update()
1116411201

1116511202
do
1116611203
{
11204+
bzero(&(*file)->copy_info, sizeof((*file)->copy_info));
1116711205
if ((*file)->start_bulk_update())
1116811206
DBUG_RETURN(TRUE);
1116911207
} while (*(++file));
@@ -11221,6 +11259,7 @@ int ha_partition::end_bulk_update()
1122111259
if ((tmp= (*file)->end_bulk_update()))
1122211260
error= tmp;
1122311261
} while (*(++file));
11262+
sum_copy_infos();
1122411263
DBUG_RETURN(error);
1122511264
}
1122611265

@@ -11317,6 +11356,7 @@ int ha_partition::end_bulk_delete()
1131711356
if ((tmp= (*file)->end_bulk_delete()))
1131811357
error= tmp;
1131911358
} while (*(++file));
11359+
sum_copy_infos();
1132011360
DBUG_RETURN(error);
1132111361
}
1132211362

@@ -11433,11 +11473,13 @@ int ha_partition::pre_direct_update_rows_init(List<Item> *update_fields)
1143311473
0 Success
1143411474
*/
1143511475

11436-
int ha_partition::direct_update_rows(ha_rows *update_rows_result)
11476+
int ha_partition::direct_update_rows(ha_rows *update_rows_result,
11477+
ha_rows *found_rows_result)
1143711478
{
1143811479
int error;
1143911480
bool rnd_seq= FALSE;
1144011481
ha_rows update_rows= 0;
11482+
ha_rows found_rows= 0;
1144111483
uint32 i;
1144211484
DBUG_ENTER("ha_partition::direct_update_rows");
1144311485

@@ -11449,6 +11491,7 @@ int ha_partition::direct_update_rows(ha_rows *update_rows_result)
1144911491
}
1145011492

1145111493
*update_rows_result= 0;
11494+
*found_rows_result= 0;
1145211495
for (i= m_part_spec.start_part; i <= m_part_spec.end_part; i++)
1145311496
{
1145411497
handler *file= m_file[i];
@@ -11464,7 +11507,8 @@ int ha_partition::direct_update_rows(ha_rows *update_rows_result)
1146411507
}
1146511508
if (unlikely((error= (m_pre_calling ?
1146611509
(file)->pre_direct_update_rows() :
11467-
(file)->ha_direct_update_rows(&update_rows)))))
11510+
(file)->ha_direct_update_rows(&update_rows,
11511+
&found_rows)))))
1146811512
{
1146911513
if (rnd_seq)
1147011514
{
@@ -11476,6 +11520,7 @@ int ha_partition::direct_update_rows(ha_rows *update_rows_result)
1147611520
DBUG_RETURN(error);
1147711521
}
1147811522
*update_rows_result+= update_rows;
11523+
*found_rows_result+= found_rows;
1147911524
}
1148011525
if (rnd_seq)
1148111526
{
@@ -11511,7 +11556,7 @@ int ha_partition::pre_direct_update_rows()
1151111556
DBUG_ENTER("ha_partition::pre_direct_update_rows");
1151211557
save_m_pre_calling= m_pre_calling;
1151311558
m_pre_calling= TRUE;
11514-
error= direct_update_rows(&not_used);
11559+
error= direct_update_rows(&not_used, &not_used);
1151511560
m_pre_calling= save_m_pre_calling;
1151611561
DBUG_RETURN(error);
1151711562
}

sql/ha_partition.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ class ha_partition :public handler
391391
part_share->next_auto_inc_val= part_share->prev_auto_inc_val;
392392
handler::restore_auto_increment();
393393
}
394+
void sum_copy_info(handler *file);
395+
void sum_copy_infos();
396+
void reset_copy_info();
394397
/** Temporary storage for new partitions Handler_shares during ALTER */
395398
List<Parts_share_refs> m_new_partitions_share_refs;
396399
/** Sorted array of partition ids in descending order of number of rows. */
@@ -657,7 +660,7 @@ class ha_partition :public handler
657660
virtual int update_row(const uchar * old_data, const uchar * new_data);
658661
virtual int direct_update_rows_init(List<Item> *update_fields);
659662
virtual int pre_direct_update_rows_init(List<Item> *update_fields);
660-
virtual int direct_update_rows(ha_rows *update_rows);
663+
virtual int direct_update_rows(ha_rows *update_rows, ha_rows *found_rows);
661664
virtual int pre_direct_update_rows();
662665
virtual bool start_bulk_delete();
663666
virtual int end_bulk_delete();

sql/handler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6812,14 +6812,14 @@ int handler::ha_delete_row(const uchar *buf)
68126812
@retval != 0 Failure.
68136813
*/
68146814

6815-
int handler::ha_direct_update_rows(ha_rows *update_rows)
6815+
int handler::ha_direct_update_rows(ha_rows *update_rows, ha_rows *found_rows)
68166816
{
68176817
int error;
68186818

68196819
MYSQL_UPDATE_ROW_START(table_share->db.str, table_share->table_name.str);
68206820
mark_trx_read_write();
68216821

6822-
error = direct_update_rows(update_rows);
6822+
error = direct_update_rows(update_rows, found_rows);
68236823
MYSQL_UPDATE_ROW_DONE(error);
68246824
return error;
68256825
}

sql/handler.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,16 @@ enum tablespace_access_mode
927927
TS_NOT_ACCESSIBLE = 2
928928
};
929929

930+
/* Statistics about batch operations like bulk_insert */
931+
struct ha_copy_info
932+
{
933+
ha_rows records; /* Used to check if rest of variables can be used */
934+
ha_rows touched;
935+
ha_rows copied;
936+
ha_rows deleted;
937+
ha_rows updated;
938+
};
939+
930940
struct handlerton;
931941
class st_alter_tablespace : public Sql_alloc
932942
{
@@ -3061,6 +3071,7 @@ class handler :public Sql_alloc
30613071
ulonglong rows_changed;
30623072
/* One bigger than needed to avoid to test if key == MAX_KEY */
30633073
ulonglong index_rows_read[MAX_KEY+1];
3074+
ha_copy_info copy_info;
30643075

30653076
private:
30663077
/* ANALYZE time tracker, if present */
@@ -3276,6 +3287,7 @@ class handler :public Sql_alloc
32763287
{
32773288
DBUG_ENTER("handler::ha_start_bulk_insert");
32783289
estimation_rows_to_insert= rows;
3290+
bzero(&copy_info,sizeof(copy_info));
32793291
start_bulk_insert(rows, flags);
32803292
DBUG_VOID_RETURN;
32813293
}
@@ -3347,6 +3359,13 @@ class handler :public Sql_alloc
33473359
{
33483360
rows_read= rows_changed= rows_tmp_read= 0;
33493361
bzero(index_rows_read, sizeof(index_rows_read));
3362+
bzero(&copy_info, sizeof(copy_info));
3363+
}
3364+
virtual void reset_copy_info() {}
3365+
void ha_reset_copy_info()
3366+
{
3367+
bzero(&copy_info, sizeof(copy_info));
3368+
reset_copy_info();
33503369
}
33513370
virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share)
33523371
{
@@ -4599,7 +4618,7 @@ class handler :public Sql_alloc
45994618

46004619
/* Perform initialization for a direct update request */
46014620
public:
4602-
int ha_direct_update_rows(ha_rows *update_rows);
4621+
int ha_direct_update_rows(ha_rows *update_rows, ha_rows *found_rows);
46034622
virtual int direct_update_rows_init(List<Item> *update_fields)
46044623
{
46054624
return HA_ERR_WRONG_COMMAND;
@@ -4609,7 +4628,8 @@ class handler :public Sql_alloc
46094628
{
46104629
return HA_ERR_WRONG_COMMAND;
46114630
}
4612-
virtual int direct_update_rows(ha_rows *update_rows __attribute__((unused)))
4631+
virtual int direct_update_rows(ha_rows *update_rows __attribute__((unused)),
4632+
ha_rows *found_rows __attribute__((unused)))
46134633
{
46144634
return HA_ERR_WRONG_COMMAND;
46154635
}

sql/sql_insert.cc

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
904904
using_bulk_insert= 1;
905905
table->file->ha_start_bulk_insert(values_list.elements);
906906
}
907+
else
908+
table->file->ha_reset_copy_info();
907909
}
908910

909911
thd->abort_on_warning= !ignore && thd->is_strict_mode();
@@ -1107,11 +1109,23 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
11071109
auto_inc values from the delayed_insert thread as they share TABLE.
11081110
*/
11091111
table->file->ha_release_auto_increment();
1110-
if (using_bulk_insert && unlikely(table->file->ha_end_bulk_insert()) &&
1111-
!error)
1112+
if (using_bulk_insert)
1113+
{
1114+
if (unlikely(table->file->ha_end_bulk_insert()) &&
1115+
!error)
1116+
{
1117+
table->file->print_error(my_errno,MYF(0));
1118+
error=1;
1119+
}
1120+
}
1121+
/* Get better status from handler if handler supports it */
1122+
if (table->file->copy_info.records)
11121123
{
1113-
table->file->print_error(my_errno,MYF(0));
1114-
error=1;
1124+
DBUG_ASSERT(info.copied >= table->file->copy_info.copied);
1125+
info.touched= table->file->copy_info.touched;
1126+
info.copied= table->file->copy_info.copied;
1127+
info.deleted= table->file->copy_info.deleted;
1128+
info.updated= table->file->copy_info.updated;
11151129
}
11161130
if (duplic != DUP_ERROR || ignore)
11171131
{
@@ -1234,8 +1248,12 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
12341248
retval= thd->lex->explain->send_explain(thd);
12351249
goto abort;
12361250
}
1237-
if ((iteration * values_list.elements) == 1 && (!(thd->variables.option_bits & OPTION_WARNINGS) ||
1238-
!thd->cuted_fields))
1251+
DBUG_PRINT("info", ("touched: %llu copied: %llu updated: %llu deleted: %llu",
1252+
(ulonglong) info.touched, (ulonglong) info.copied,
1253+
(ulonglong) info.updated, (ulonglong) info.deleted));
1254+
1255+
if ((iteration * values_list.elements) == 1 &&
1256+
(!(thd->variables.option_bits & OPTION_WARNINGS) || !thd->cuted_fields))
12391257
{
12401258
my_ok(thd, info.copied + info.deleted +
12411259
((thd->client_capabilities & CLIENT_FOUND_ROWS) ?

sql/sql_update.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,11 @@ int mysql_update(THD *thd,
718718
719719
Later we also ensure that we are only using one table (no sub queries)
720720
*/
721+
DBUG_PRINT("info", ("HA_CAN_DIRECT_UPDATE_AND_DELETE: %s", (table->file->ha_table_flags() & HA_CAN_DIRECT_UPDATE_AND_DELETE) ? "TRUE" : "FALSE"));
722+
DBUG_PRINT("info", ("using_io_buffer: %s", query_plan.using_io_buffer ? "TRUE" : "FALSE"));
723+
DBUG_PRINT("info", ("ignore: %s", ignore ? "TRUE" : "FALSE"));
724+
DBUG_PRINT("info", ("virtual_columns_marked_for_read: %s", table->check_virtual_columns_marked_for_read() ? "TRUE" : "FALSE"));
725+
DBUG_PRINT("info", ("virtual_columns_marked_for_write: %s", table->check_virtual_columns_marked_for_write() ? "TRUE" : "FALSE"));
721726
if ((table->file->ha_table_flags() & HA_CAN_DIRECT_UPDATE_AND_DELETE) &&
722727
!has_triggers && !binlog_is_row &&
723728
!query_plan.using_io_buffer && !ignore &&
@@ -928,11 +933,16 @@ int mysql_update(THD *thd,
928933
if (do_direct_update)
929934
{
930935
/* Direct updating is supported */
936+
ha_rows update_rows= 0, found_rows= 0;
931937
DBUG_PRINT("info", ("Using direct update"));
932938
table->reset_default_fields();
933-
if (unlikely(!(error= table->file->ha_direct_update_rows(&updated))))
939+
if (unlikely(!(error= table->file->ha_direct_update_rows(&update_rows,
940+
&found_rows))))
934941
error= -1;
935-
found= updated;
942+
updated= update_rows;
943+
found= found_rows;
944+
if (found < updated)
945+
found= updated;
936946
goto update_end;
937947
}
938948

0 commit comments

Comments
 (0)