Skip to content

Commit be5c432

Browse files
authored
MDEV-16249 CHECKSUM TABLE for a spider table is not parallel and saves all data in memory in the spider head by default (#1328)
add checksum_null for setting null value of checksum
1 parent 5e9090e commit be5c432

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1303
-472
lines changed

sql/ha_partition.cc

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8200,6 +8200,7 @@ int ha_partition::info(uint flag)
82008200
stats.delete_length= 0;
82018201
stats.check_time= 0;
82028202
stats.checksum= 0;
8203+
stats.checksum_null= TRUE;
82038204
for (i= bitmap_get_first_set(&m_part_info->read_partitions);
82048205
i < m_tot_parts;
82058206
i= bitmap_get_next_set(&m_part_info->read_partitions, i))
@@ -8213,7 +8214,11 @@ int ha_partition::info(uint flag)
82138214
stats.delete_length+= file->stats.delete_length;
82148215
if (file->stats.check_time > stats.check_time)
82158216
stats.check_time= file->stats.check_time;
8216-
stats.checksum+= file->stats.checksum;
8217+
if (!file->stats.checksum_null)
8218+
{
8219+
stats.checksum+= file->stats.checksum;
8220+
stats.checksum_null= FALSE;
8221+
}
82178222
}
82188223
if (stats.records && stats.records < 2 &&
82198224
!(m_file[0]->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT))
@@ -8370,6 +8375,7 @@ void ha_partition::get_dynamic_partition_info(PARTITION_STATS *stat_info,
83708375
stat_info->update_time= file->stats.update_time;
83718376
stat_info->check_time= file->stats.check_time;
83728377
stat_info->check_sum= file->stats.checksum;
8378+
stat_info->check_sum_null= file->stats.checksum_null;
83738379
}
83748380

83758381

@@ -10599,6 +10605,66 @@ void ha_partition::init_table_handle_for_HANDLER()
1059910605
}
1060010606

1060110607

10608+
/**
10609+
Calculate the checksum of the table (all partitions)
10610+
*/
10611+
10612+
int ha_partition::pre_calculate_checksum()
10613+
{
10614+
int error;
10615+
DBUG_ENTER("ha_partition::pre_calculate_checksum");
10616+
m_pre_calling= TRUE;
10617+
if ((table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM)))
10618+
{
10619+
handler **file= m_file;
10620+
do
10621+
{
10622+
if ((error= (*file)->pre_calculate_checksum()))
10623+
{
10624+
DBUG_RETURN(error);
10625+
}
10626+
} while (*(++file));
10627+
}
10628+
DBUG_RETURN(0);
10629+
}
10630+
10631+
10632+
int ha_partition::calculate_checksum()
10633+
{
10634+
int error;
10635+
stats.checksum= 0;
10636+
stats.checksum_null= TRUE;
10637+
10638+
DBUG_ENTER("ha_partition::calculate_checksum");
10639+
if (!m_pre_calling)
10640+
{
10641+
if ((error= pre_calculate_checksum()))
10642+
{
10643+
m_pre_calling= FALSE;
10644+
DBUG_RETURN(error);
10645+
}
10646+
}
10647+
m_pre_calling= FALSE;
10648+
if ((table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM)))
10649+
{
10650+
handler **file= m_file;
10651+
do
10652+
{
10653+
if ((error= (*file)->calculate_checksum()))
10654+
{
10655+
DBUG_RETURN(error);
10656+
}
10657+
if (!(*file)->stats.checksum_null)
10658+
{
10659+
stats.checksum+= (*file)->stats.checksum;
10660+
stats.checksum_null= FALSE;
10661+
}
10662+
} while (*(++file));
10663+
}
10664+
DBUG_RETURN(0);
10665+
}
10666+
10667+
1060210668
/****************************************************************************
1060310669
MODULE enable/disable indexes
1060410670
****************************************************************************/

sql/ha_partition.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,9 @@ class ha_partition :public handler
14431443
void append_row_to_str(String &str);
14441444
public:
14451445

1446+
virtual int pre_calculate_checksum();
1447+
virtual int calculate_checksum();
1448+
14461449
/* Enabled keycache for performance reasons, WL#4571 */
14471450
virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt);
14481451
virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt);

sql/handler.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4899,6 +4899,7 @@ void handler::get_dynamic_partition_info(PARTITION_STATS *stat_info,
48994899
stat_info->update_time= stats.update_time;
49004900
stat_info->check_time= stats.check_time;
49014901
stat_info->check_sum= stats.checksum;
4902+
stat_info->check_sum_null= stats.checksum_null;
49024903
}
49034904

49044905

sql/handler.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,7 @@ typedef struct {
19221922
time_t check_time;
19231923
time_t update_time;
19241924
ulonglong check_sum;
1925+
bool check_sum_null;
19251926
} PARTITION_STATS;
19261927

19271928
#define UNDEF_NODEGROUP 65535
@@ -2881,6 +2882,7 @@ class ha_statistics
28812882
time_t update_time;
28822883
uint block_size;/* index block size */
28832884
ha_checksum checksum;
2885+
bool checksum_null;
28842886

28852887
/*
28862888
number of buffer bytes that native mrr implementation needs,
@@ -2892,7 +2894,7 @@ class ha_statistics
28922894
index_file_length(0), max_index_file_length(0), delete_length(0),
28932895
auto_increment_value(0), records(0), deleted(0), mean_rec_length(0),
28942896
create_time(0), check_time(0), update_time(0), block_size(0),
2895-
mrr_length_per_rec(0)
2897+
checksum(0), checksum_null(FALSE), mrr_length_per_rec(0)
28962898
{}
28972899
};
28982900

@@ -3925,6 +3927,7 @@ class handler :public Sql_alloc
39253927
virtual uint max_supported_key_part_length() const { return 255; }
39263928
virtual uint min_record_length(uint options) const { return 1; }
39273929

3930+
virtual int pre_calculate_checksum() { return 0; }
39283931
virtual int calculate_checksum();
39293932
virtual bool is_crashed() const { return 0; }
39303933
virtual bool auto_repair(int error) const { return 0; }

sql/sql_show.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5668,7 +5668,9 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
56685668
table->field[16]->store_time(&time);
56695669
table->field[16]->set_notnull();
56705670
}
5671-
if (file->ha_table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM))
5671+
if ((file->ha_table_flags() &
5672+
(HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM)) &&
5673+
!file->stats.checksum_null)
56725674
{
56735675
table->field[18]->store((longlong) file->stats.checksum, TRUE);
56745676
table->field[18]->set_notnull();

sql/sql_table.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10936,7 +10936,7 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
1093610936
(((t->file->ha_table_flags() & HA_HAS_OLD_CHECKSUM) && thd->variables.old_mode) ||
1093710937
((t->file->ha_table_flags() & HA_HAS_NEW_CHECKSUM) && !thd->variables.old_mode)))
1093810938
{
10939-
if (t->file->info(HA_STATUS_VARIABLE))
10939+
if (t->file->info(HA_STATUS_VARIABLE) || t->file->stats.checksum_null)
1094010940
protocol->store_null();
1094110941
else
1094210942
protocol->store((longlong)t->file->stats.checksum);
@@ -10956,7 +10956,7 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
1095610956
thd->protocol->remove_last_row();
1095710957
goto err;
1095810958
}
10959-
if (error)
10959+
if (error || t->file->stats.checksum_null)
1096010960
protocol->store_null();
1096110961
else
1096210962
protocol->store((longlong)t->file->stats.checksum);

storage/spider/ha_spider.cc

Lines changed: 97 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Copyright (C) 2008-2018 Kentoku Shiba
1+
/* Copyright (C) 2008-2019 Kentoku Shiba
2+
Copyright (C) 2019 MariaDB corp
23
34
This program is free software; you can redistribute it and/or modify
45
it under the terms of the GNU General Public License as published by
@@ -116,7 +117,7 @@ ha_spider::ha_spider(
116117
use_fields = FALSE;
117118
#endif
118119
use_pre_call = FALSE;
119-
use_pre_records = FALSE;
120+
use_pre_action = FALSE;
120121
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
121122
do_direct_update = FALSE;
122123
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
@@ -228,7 +229,7 @@ ha_spider::ha_spider(
228229
use_fields = FALSE;
229230
#endif
230231
use_pre_call = FALSE;
231-
use_pre_records = FALSE;
232+
use_pre_action = FALSE;
232233
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
233234
do_direct_update = FALSE;
234235
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
@@ -1805,7 +1806,7 @@ int ha_spider::reset()
18051806
high_priority = FALSE;
18061807
insert_delayed = FALSE;
18071808
use_pre_call = FALSE;
1808-
use_pre_records = FALSE;
1809+
use_pre_action = FALSE;
18091810
pre_bitmap_checked = FALSE;
18101811
bulk_insert = FALSE;
18111812
clone_bitmap_init = FALSE;
@@ -8760,22 +8761,24 @@ int ha_spider::info(
87608761
}
87618762

87628763
if (flag & HA_STATUS_TIME)
8763-
stats.update_time = (ulong) share->update_time;
8764+
stats.update_time = (ulong) share->stat.update_time;
87648765
if (flag & (HA_STATUS_CONST | HA_STATUS_VARIABLE))
87658766
{
8766-
stats.max_data_file_length = share->max_data_file_length;
8767-
stats.create_time = (ulong) share->create_time;
8767+
stats.max_data_file_length = share->stat.max_data_file_length;
8768+
stats.create_time = share->stat.create_time;
87688769
stats.block_size = spider_param_block_size(thd);
87698770
}
87708771
if (flag & HA_STATUS_VARIABLE)
87718772
{
8772-
stats.data_file_length = share->data_file_length;
8773-
stats.index_file_length = share->index_file_length;
8774-
stats.records = share->records;
8775-
stats.mean_rec_length = share->mean_rec_length;
8776-
stats.check_time = (ulong) share->check_time;
8773+
stats.data_file_length = share->stat.data_file_length;
8774+
stats.index_file_length = share->stat.index_file_length;
8775+
stats.records = share->stat.records;
8776+
stats.mean_rec_length = share->stat.mean_rec_length;
8777+
stats.check_time = share->stat.check_time;
87778778
if (stats.records <= 1 /* && (flag & HA_STATUS_NO_LOCK) */ )
87788779
stats.records = 2;
8780+
stats.checksum = share->stat.checksum;
8781+
stats.checksum_null = share->stat.checksum_null;
87798782
}
87808783
if (flag & HA_STATUS_AUTO)
87818784
{
@@ -9014,7 +9017,7 @@ ha_rows ha_spider::records_in_range(
90149017
key_part_map tgt_key_part_map;
90159018
KEY_PART_INFO *key_part;
90169019
Field *field = NULL;
9017-
double rows = (double) share->records;
9020+
double rows = (double) share->stat.records;
90189021
double weight, rate;
90199022
DBUG_PRINT("info",("spider rows1=%f", rows));
90209023
if (start_key)
@@ -9323,11 +9326,12 @@ int ha_spider::pre_records()
93239326
result_list.casual_read[search_link_idx] =
93249327
spider_param_casual_read(thd, share->casual_read);
93259328
}
9326-
if ((error_num = spider_db_show_records(this, search_link_idx, TRUE)))
9329+
if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_RECORDS, this,
9330+
search_link_idx, TRUE)))
93279331
{
93289332
DBUG_RETURN(check_error_mode(error_num));
93299333
}
9330-
use_pre_records = TRUE;
9334+
use_pre_action = TRUE;
93319335
DBUG_RETURN(0);
93329336
}
93339337

@@ -9339,14 +9343,14 @@ ha_rows ha_spider::records()
93399343
DBUG_PRINT("info",("spider this=%p", this));
93409344
if (sql_command == SQLCOM_ALTER_TABLE)
93419345
{
9342-
use_pre_records = FALSE;
9346+
use_pre_action = FALSE;
93439347
DBUG_RETURN(0);
93449348
}
93459349
if (!(share->additional_table_flags & HA_HAS_RECORDS) && !this->result_list.direct_limit_offset)
93469350
{
93479351
DBUG_RETURN(handler::records());
93489352
}
9349-
if (!use_pre_records && !this->result_list.direct_limit_offset)
9353+
if (!use_pre_action && !this->result_list.direct_limit_offset)
93509354
{
93519355
THD *thd = trx->thd;
93529356
if (
@@ -9357,17 +9361,84 @@ ha_rows ha_spider::records()
93579361
spider_param_casual_read(thd, share->casual_read);
93589362
}
93599363
}
9360-
if ((error_num = spider_db_show_records(this, search_link_idx, FALSE)))
9364+
if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_RECORDS, this,
9365+
search_link_idx, FALSE)))
93619366
{
9362-
use_pre_records = FALSE;
9367+
use_pre_action = FALSE;
93639368
check_error_mode(error_num);
93649369
DBUG_RETURN(HA_POS_ERROR);
93659370
}
9366-
use_pre_records = FALSE;
9367-
share->records = table_rows;
9371+
use_pre_action = FALSE;
9372+
share->stat.records = table_rows;
93689373
DBUG_RETURN(table_rows);
93699374
}
93709375

9376+
#ifdef HA_HAS_CHECKSUM_EXTENDED
9377+
int ha_spider::pre_calculate_checksum()
9378+
{
9379+
int error_num;
9380+
backup_error_status();
9381+
DBUG_ENTER("ha_spider::pre_calculate_checksum");
9382+
DBUG_PRINT("info",("spider this=%p", this));
9383+
THD *thd = trx->thd;
9384+
if (
9385+
spider_param_sync_autocommit(thd) &&
9386+
(!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
9387+
) {
9388+
result_list.casual_read[search_link_idx] =
9389+
spider_param_casual_read(thd, share->casual_read);
9390+
}
9391+
action_flags = T_EXTEND;
9392+
if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, this,
9393+
search_link_idx, TRUE)))
9394+
{
9395+
DBUG_RETURN(check_error_mode(error_num));
9396+
}
9397+
use_pre_action = TRUE;
9398+
DBUG_RETURN(0);
9399+
}
9400+
9401+
int ha_spider::calculate_checksum()
9402+
{
9403+
int error_num;
9404+
backup_error_status();
9405+
DBUG_ENTER("ha_spider::calculate_checksum");
9406+
DBUG_PRINT("info",("spider this=%p", this));
9407+
if (!use_pre_action && !this->result_list.direct_limit_offset)
9408+
{
9409+
THD *thd = trx->thd;
9410+
if (
9411+
spider_param_sync_autocommit(thd) &&
9412+
(!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
9413+
) {
9414+
result_list.casual_read[search_link_idx] =
9415+
spider_param_casual_read(thd, share->casual_read);
9416+
}
9417+
}
9418+
action_flags = T_EXTEND;
9419+
if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, this,
9420+
search_link_idx, FALSE)))
9421+
{
9422+
use_pre_action = FALSE;
9423+
DBUG_RETURN(check_error_mode(error_num));
9424+
}
9425+
use_pre_action = FALSE;
9426+
if (checksum_null)
9427+
{
9428+
share->stat.checksum_null = TRUE;
9429+
share->stat.checksum = 0;
9430+
stats.checksum_null = TRUE;
9431+
stats.checksum = 0;
9432+
} else {
9433+
share->stat.checksum_null = FALSE;
9434+
share->stat.checksum = checksum_val;
9435+
stats.checksum_null = FALSE;
9436+
stats.checksum = checksum_val;
9437+
}
9438+
DBUG_RETURN(0);
9439+
}
9440+
#endif
9441+
93719442
const char *ha_spider::table_type() const
93729443
{
93739444
DBUG_ENTER("ha_spider::table_type");
@@ -11172,8 +11243,9 @@ double ha_spider::scan_time()
1117211243
DBUG_ENTER("ha_spider::scan_time");
1117311244
DBUG_PRINT("info",("spider this=%p", this));
1117411245
DBUG_PRINT("info",("spider scan_time = %.6f",
11175-
share->scan_rate * share->records * share->mean_rec_length + 2));
11176-
DBUG_RETURN(share->scan_rate * share->records * share->mean_rec_length + 2);
11246+
share->scan_rate * share->stat.records * share->stat.mean_rec_length + 2));
11247+
DBUG_RETURN(share->scan_rate * share->stat.records *
11248+
share->stat.mean_rec_length + 2);
1117711249
}
1117811250

1117911251
double ha_spider::read_time(
@@ -11192,8 +11264,8 @@ double ha_spider::read_time(
1119211264
rows / 2 + 2);
1119311265
} else {
1119411266
DBUG_PRINT("info",("spider read_time = %.6f",
11195-
share->read_rate * share->mean_rec_length * rows + 2));
11196-
DBUG_RETURN(share->read_rate * share->mean_rec_length * rows + 2);
11267+
share->read_rate * share->stat.mean_rec_length * rows + 2));
11268+
DBUG_RETURN(share->read_rate * share->stat.mean_rec_length * rows + 2);
1119711269
}
1119811270
}
1119911271

0 commit comments

Comments
 (0)