mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
CHECKSUM TABLE table1, table2, ... [ QUICK | EXTENDED ]
This commit is contained in:
@ -350,10 +350,10 @@ static int sort_keys(KEY *a, KEY *b)
|
||||
fields List of fields to create
|
||||
keys List of keys to create
|
||||
tmp_table Set to 1 if this is an internal temporary table
|
||||
(From ALTER TABLE)
|
||||
(From ALTER TABLE)
|
||||
no_log Don't log the query to binary log.
|
||||
|
||||
DESCRIPTION
|
||||
DESCRIPTION
|
||||
If one creates a temporary table, this is automaticly opened
|
||||
|
||||
no_log is needed for the case of CREATE ... SELECT,
|
||||
@ -672,11 +672,11 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
|
||||
/*
|
||||
Make SPATIAL to be RTREE by default
|
||||
SPATIAL only on BLOB or at least BINARY, this
|
||||
actually should be replaced by special GEOM type
|
||||
actually should be replaced by special GEOM type
|
||||
in near future when new frm file is ready
|
||||
checking for proper key parts number:
|
||||
*/
|
||||
|
||||
|
||||
if (key_info->flags == HA_SPATIAL)
|
||||
{
|
||||
if (key_info->key_parts != 1)
|
||||
@ -699,7 +699,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
|
||||
MYF(0), "RTREE INDEX");
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
|
||||
|
||||
List_iterator<key_part_spec> cols(key->columns);
|
||||
for (uint column_nr=0 ; (column=cols++) ; column_nr++)
|
||||
{
|
||||
@ -745,9 +745,9 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
|
||||
{
|
||||
if (!column->length )
|
||||
{
|
||||
/*
|
||||
/*
|
||||
BAR: 4 is: (Xmin,Xmax,Ymin,Ymax), this is for 2D case
|
||||
Lately we'll extend this code to support more dimensions
|
||||
Lately we'll extend this code to support more dimensions
|
||||
*/
|
||||
column->length=4*sizeof(double);
|
||||
}
|
||||
@ -797,7 +797,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
|
||||
{
|
||||
}
|
||||
else if (column->length > length ||
|
||||
((f_is_packed(sql_field->pack_flag) ||
|
||||
((f_is_packed(sql_field->pack_flag) ||
|
||||
((file->table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
|
||||
(key_info->flags & HA_NOSAME))) &&
|
||||
column->length != length))
|
||||
@ -2588,7 +2588,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
|
||||
DBUG_RETURN(error > 0 ? -1 : 0);
|
||||
}
|
||||
|
||||
int mysql_checksum_table(THD* thd, TABLE_LIST* tables)
|
||||
int mysql_checksum_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT *check_opt)
|
||||
{
|
||||
TABLE_LIST *table;
|
||||
List<Item> field_list;
|
||||
@ -2608,9 +2608,10 @@ int mysql_checksum_table(THD* thd, TABLE_LIST* tables)
|
||||
char table_name[NAME_LEN*2+2];
|
||||
char* db = (table->db) ? table->db : thd->db;
|
||||
bool fatal_error=0;
|
||||
TABLE *t;
|
||||
strxmov(table_name,db ? db : "",".",table->real_name,NullS);
|
||||
|
||||
table->table = open_ltable(thd, table, TL_READ_NO_INSERT);
|
||||
t=table->table = open_ltable(thd, table, TL_READ_NO_INSERT);
|
||||
#ifdef EMBEDDED_LIBRARY
|
||||
thd->net.last_errno= 0; // these errors shouldn't get client
|
||||
#endif
|
||||
@ -2618,19 +2619,54 @@ int mysql_checksum_table(THD* thd, TABLE_LIST* tables)
|
||||
protocol->prepare_for_resend();
|
||||
protocol->store(table_name, system_charset_info);
|
||||
|
||||
if (!table->table)
|
||||
if (!t)
|
||||
{
|
||||
protocol->store_null();
|
||||
thd->net.last_error[0]=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
table->table->pos_in_table_list= table;
|
||||
t->pos_in_table_list= table;
|
||||
|
||||
if (table->table->file->table_flags() & HA_HAS_CHECKSUM)
|
||||
protocol->store((ulonglong)table->table->file->checksum());
|
||||
else
|
||||
if (t->file->table_flags() & HA_HAS_CHECKSUM &&
|
||||
!(check_opt->flags & T_EXTEND))
|
||||
protocol->store((ulonglong)t->file->checksum());
|
||||
else if (!(t->file->table_flags() & HA_HAS_CHECKSUM) &&
|
||||
check_opt->flags & T_QUICK)
|
||||
protocol->store_null();
|
||||
else
|
||||
{
|
||||
/* calculating table's checksum */
|
||||
ha_checksum crc=0;
|
||||
if (t->file->rnd_init(1))
|
||||
protocol->store_null();
|
||||
else
|
||||
{
|
||||
while (!t->file->rnd_next(t->record[0]))
|
||||
{
|
||||
ha_checksum row_crc=0;
|
||||
if (t->record[0] != t->field[0]->ptr)
|
||||
row_crc=my_checksum(row_crc, t->record[0],
|
||||
t->field[0]->ptr - t->record[0]);
|
||||
|
||||
for (uint i=0; i < t->fields; i++ )
|
||||
{
|
||||
Field *f=t->field[i];
|
||||
if (f->type() == FIELD_TYPE_BLOB)
|
||||
{
|
||||
String tmp;
|
||||
f->val_str(&tmp,&tmp);
|
||||
row_crc=my_checksum(row_crc, tmp.ptr(), tmp.length());
|
||||
}
|
||||
else
|
||||
row_crc=my_checksum(row_crc, f->ptr, f->pack_length());
|
||||
}
|
||||
|
||||
crc+=row_crc;
|
||||
}
|
||||
protocol->store((ulonglong)crc);
|
||||
}
|
||||
}
|
||||
#ifdef EMBEDDED_LIBRARY
|
||||
thd->net.last_errno= 0; // these errors shouldn't get client
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user