1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-18 23:03:28 +03:00

cleanup: move checksum code to handler class

make live checksum to be returned in handler::info(),
and slow table-scan checksum to be calculated in handler::checksum().

part of
MDEV-16249 CHECKSUM TABLE for a spider table is not parallel and saves all data in memory in the spider head by default
This commit is contained in:
Sergei Golubchik
2019-05-02 13:09:27 +02:00
parent 651a43e0a0
commit ffb83ba650
10 changed files with 121 additions and 143 deletions

View File

@ -10630,18 +10630,6 @@ bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy)
}
static void flush_checksum(ha_checksum *row_crc, uchar **checksum_start,
size_t *checksum_length)
{
if (*checksum_start)
{
*row_crc= my_checksum(*row_crc, *checksum_start, *checksum_length);
*checksum_start= NULL;
*checksum_length= 0;
}
}
bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
HA_CHECK_OPT *check_opt)
{
@ -10718,96 +10706,31 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
if (!(check_opt->flags & T_EXTEND) &&
(((t->file->ha_table_flags() & HA_HAS_OLD_CHECKSUM) && thd->variables.old_mode) ||
((t->file->ha_table_flags() & HA_HAS_NEW_CHECKSUM) && !thd->variables.old_mode)))
protocol->store((ulonglong)t->file->checksum());
{
if (t->file->info(HA_STATUS_VARIABLE))
protocol->store_null();
else
protocol->store((longlong)t->file->stats.checksum);
}
else if (check_opt->flags & T_QUICK)
protocol->store_null();
else
{
/* calculating table's checksum */
ha_checksum crc= 0;
DBUG_ASSERT(t->s->last_null_bit_pos < 8);
uchar null_mask= (t->s->last_null_bit_pos ?
(256 - (1 << t->s->last_null_bit_pos)):
0);
t->use_all_columns();
if (t->file->ha_rnd_init(1))
int error= t->file->calculate_checksum();
if (thd->killed)
{
/*
we've been killed; let handler clean up, and remove the
partial current row from the recordset (embedded lib)
*/
t->file->ha_rnd_end();
thd->protocol->remove_last_row();
goto err;
}
if (error)
protocol->store_null();
else
{
for (;;)
{
if (thd->killed)
{
/*
we've been killed; let handler clean up, and remove the
partial current row from the recordset (embedded lib)
*/
t->file->ha_rnd_end();
thd->protocol->remove_last_row();
goto err;
}
ha_checksum row_crc= 0;
int error= t->file->ha_rnd_next(t->record[0]);
if (unlikely(error))
{
break;
}
if (t->s->null_bytes)
{
/* fix undefined null bits */
t->record[0][t->s->null_bytes-1] |= null_mask;
if (!(t->s->db_create_options & HA_OPTION_PACK_RECORD))
t->record[0][0] |= 1;
row_crc= my_checksum(row_crc, t->record[0], t->s->null_bytes);
}
uchar *checksum_start= NULL;
size_t checksum_length= 0;
for (uint i= 0; i < t->s->fields; i++ )
{
Field *f= t->field[i];
if (! thd->variables.old_mode && f->is_real_null(0))
{
flush_checksum(&row_crc, &checksum_start, &checksum_length);
continue;
}
/*
BLOB and VARCHAR have pointers in their field, we must convert
to string; GEOMETRY is implemented on top of BLOB.
BIT may store its data among NULL bits, convert as well.
*/
switch (f->type()) {
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_GEOMETRY:
case MYSQL_TYPE_BIT:
{
flush_checksum(&row_crc, &checksum_start, &checksum_length);
String tmp;
f->val_str(&tmp);
row_crc= my_checksum(row_crc, (uchar*) tmp.ptr(),
tmp.length());
break;
}
default:
if (!checksum_start)
checksum_start= f->ptr;
DBUG_ASSERT(checksum_start + checksum_length == f->ptr);
checksum_length+= f->pack_length();
break;
}
}
flush_checksum(&row_crc, &checksum_start, &checksum_length);
crc+= row_crc;
}
protocol->store((ulonglong)crc);
t->file->ha_rnd_end();
}
protocol->store((longlong)t->file->stats.checksum);
}
trans_rollback_stmt(thd);
close_thread_tables(thd);