1
0
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:
serg@serg.mylan
2003-09-03 11:34:32 +02:00
parent 8424aec8db
commit 2fcab1c2ee
11 changed files with 138 additions and 28 deletions

View File

@ -50,7 +50,7 @@ ha_checksum mi_checksum(MI_INFO *info, const byte *buf)
pos=buf; pos=buf;
break; break;
} }
crc=my_checksum(crc, pos, length); crc=my_checksum(crc, pos ? pos : "", length);
} }
return crc; return crc;
} }

View File

@ -1341,3 +1341,28 @@ ERROR HY000: Table storage engine for 't1' doesn't have this option
select * from t1; select * from t1;
c1 c2 stamp c1 c2 stamp
drop table t1; drop table t1;
create table t1 (a int, b varchar(200), c text not null) checksum=1 type=myisam;
create table t2 (a int, b varchar(200), c text not null) checksum=0 type=innodb;
create table t3 (a int, b varchar(200), c text not null) checksum=1 type=innodb;
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
insert t2 select * from t1;
insert t3 select * from t1;
checksum table t1, t2, t3, t4 quick;
Table Checksum
test.t1 968604391
test.t2 NULL
test.t3 NULL
test.t4 NULL
checksum table t1, t2, t3, t4;
Table Checksum
test.t1 968604391
test.t2 968604391
test.t3 968604391
test.t4 NULL
checksum table t1, t2, t3, t4 extended;
Table Checksum
test.t1 968604391
test.t2 968604391
test.t3 968604391
test.t4 NULL
drop table t1,t2,t3;

View File

@ -394,6 +394,23 @@ id select_type table type possible_keys key key_len ref rows Extra
drop table t1,t2; drop table t1,t2;
CREATE TABLE t1 (`a` int(11) NOT NULL default '0', `b` int(11) NOT NULL default '0', UNIQUE KEY `a` USING RTREE (`a`,`b`)) TYPE=MyISAM; CREATE TABLE t1 (`a` int(11) NOT NULL default '0', `b` int(11) NOT NULL default '0', UNIQUE KEY `a` USING RTREE (`a`,`b`)) TYPE=MyISAM;
ERROR 42000: This version of MySQL doesn't yet support 'RTREE INDEX' ERROR 42000: This version of MySQL doesn't yet support 'RTREE INDEX'
DROP TABLE IF EXISTS t1; create table t1 (a int, b varchar(200), c text not null) checksum=1;
Warnings: create table t2 (a int, b varchar(200), c text not null) checksum=0;
Note 1051 Unknown table 't1' insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
insert t2 select * from t1;
checksum table t1, t2, t3 quick;
Table Checksum
test.t1 968604391
test.t2 NULL
test.t3 NULL
checksum table t1, t2, t3;
Table Checksum
test.t1 968604391
test.t2 968604391
test.t3 NULL
checksum table t1, t2, t3 extended;
Table Checksum
test.t1 968604391
test.t2 968604391
test.t3 NULL
drop table t1,t2;

View File

@ -43,7 +43,7 @@ wait_timeout 28800
show variables like "this_doesn't_exists%"; show variables like "this_doesn't_exists%";
Variable_name Value Variable_name Value
show table status from test like "this_doesn't_exists%"; show table status from test like "this_doesn't_exists%";
Name Type Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Charset Create_options Comment Name Type Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Charset Checksum Create_options Comment
show databases; show databases;
Database Database
mysql mysql

View File

@ -920,3 +920,15 @@ replace delayed into t1 (c1, c2) values ( "text1","12"),( "text2","13"),( "text
select * from t1; select * from t1;
drop table t1; drop table t1;
create table t1 (a int, b varchar(200), c text not null) checksum=1 type=myisam;
create table t2 (a int, b varchar(200), c text not null) checksum=0 type=innodb;
create table t3 (a int, b varchar(200), c text not null) checksum=1 type=innodb;
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
insert t2 select * from t1;
insert t3 select * from t1;
checksum table t1, t2, t3, t4 quick;
checksum table t1, t2, t3, t4;
checksum table t1, t2, t3, t4 extended;
#show table status;
drop table t1,t2,t3;

View File

@ -360,4 +360,15 @@ drop table t1,t2;
CREATE TABLE t1 (`a` int(11) NOT NULL default '0', `b` int(11) NOT NULL default '0', UNIQUE KEY `a` USING RTREE (`a`,`b`)) TYPE=MyISAM; CREATE TABLE t1 (`a` int(11) NOT NULL default '0', `b` int(11) NOT NULL default '0', UNIQUE KEY `a` USING RTREE (`a`,`b`)) TYPE=MyISAM;
# INSERT INTO t1 VALUES (1,1),(1,1); # INSERT INTO t1 VALUES (1,1),(1,1);
# DELETE FROM rt WHERE a<1; # DELETE FROM rt WHERE a<1;
DROP TABLE IF EXISTS t1; # DROP TABLE IF EXISTS t1;
create table t1 (a int, b varchar(200), c text not null) checksum=1;
create table t2 (a int, b varchar(200), c text not null) checksum=0;
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
insert t2 select * from t1;
checksum table t1, t2, t3 quick;
checksum table t1, t2, t3;
checksum table t1, t2, t3 extended;
#show table status;
drop table t1,t2;

View File

@ -30,9 +30,11 @@
ha_checksum my_checksum(ha_checksum crc, const byte *pos, uint length) ha_checksum my_checksum(ha_checksum crc, const byte *pos, uint length)
{ {
const byte *end=pos+length; /* const byte *end=pos+length;
for ( ; pos != end ; pos++) for ( ; pos != end ; pos++)
crc=((crc << 8) + *((uchar*) pos)) + (crc >> (8*sizeof(ha_checksum)-8)); crc=((crc << 8) + *((uchar*) pos)) + (crc >> (8*sizeof(ha_checksum)-8));
return crc; return crc;
*/
return (ha_checksum)crc32((uint)crc, (const uchar *)pos, length);
} }

View File

@ -398,7 +398,8 @@ bool check_global_access(THD *thd, ulong want_access);
int mysql_backup_table(THD* thd, TABLE_LIST* table_list); int mysql_backup_table(THD* thd, TABLE_LIST* table_list);
int mysql_restore_table(THD* thd, TABLE_LIST* table_list); int mysql_restore_table(THD* thd, TABLE_LIST* table_list);
int mysql_checksum_table(THD* thd, TABLE_LIST* table_list); int mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
HA_CHECK_OPT* check_opt);
int mysql_check_table(THD* thd, TABLE_LIST* table_list, int mysql_check_table(THD* thd, TABLE_LIST* table_list,
HA_CHECK_OPT* check_opt); HA_CHECK_OPT* check_opt);
int mysql_repair_table(THD* thd, TABLE_LIST* table_list, int mysql_repair_table(THD* thd, TABLE_LIST* table_list,

View File

@ -2269,7 +2269,7 @@ mysql_execute_command(THD *thd)
if (check_db_used(thd,tables) || if (check_db_used(thd,tables) ||
check_table_access(thd, SELECT_ACL | EXTRA_ACL , tables)) check_table_access(thd, SELECT_ACL | EXTRA_ACL , tables))
goto error; /* purecov: inspected */ goto error; /* purecov: inspected */
res = mysql_checksum_table(thd, tables); res = mysql_checksum_table(thd, tables, &lex->check_opt);
break; break;
} }
case SQLCOM_REPAIR: case SQLCOM_REPAIR:

View File

@ -350,10 +350,10 @@ static int sort_keys(KEY *a, KEY *b)
fields List of fields to create fields List of fields to create
keys List of keys to create keys List of keys to create
tmp_table Set to 1 if this is an internal temporary table 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. no_log Don't log the query to binary log.
DESCRIPTION DESCRIPTION
If one creates a temporary table, this is automaticly opened If one creates a temporary table, this is automaticly opened
no_log is needed for the case of CREATE ... SELECT, 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 Make SPATIAL to be RTREE by default
SPATIAL only on BLOB or at least BINARY, this 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 in near future when new frm file is ready
checking for proper key parts number: checking for proper key parts number:
*/ */
if (key_info->flags == HA_SPATIAL) if (key_info->flags == HA_SPATIAL)
{ {
if (key_info->key_parts != 1) 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"); MYF(0), "RTREE INDEX");
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
List_iterator<key_part_spec> cols(key->columns); List_iterator<key_part_spec> cols(key->columns);
for (uint column_nr=0 ; (column=cols++) ; column_nr++) 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 ) if (!column->length )
{ {
/* /*
BAR: 4 is: (Xmin,Xmax,Ymin,Ymax), this is for 2D case 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); 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 || 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) && ((file->table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
(key_info->flags & HA_NOSAME))) && (key_info->flags & HA_NOSAME))) &&
column->length != length)) column->length != length))
@ -2588,7 +2588,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
DBUG_RETURN(error > 0 ? -1 : 0); 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; TABLE_LIST *table;
List<Item> field_list; 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 table_name[NAME_LEN*2+2];
char* db = (table->db) ? table->db : thd->db; char* db = (table->db) ? table->db : thd->db;
bool fatal_error=0; bool fatal_error=0;
TABLE *t;
strxmov(table_name,db ? db : "",".",table->real_name,NullS); 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 #ifdef EMBEDDED_LIBRARY
thd->net.last_errno= 0; // these errors shouldn't get client thd->net.last_errno= 0; // these errors shouldn't get client
#endif #endif
@ -2618,19 +2619,54 @@ int mysql_checksum_table(THD* thd, TABLE_LIST* tables)
protocol->prepare_for_resend(); protocol->prepare_for_resend();
protocol->store(table_name, system_charset_info); protocol->store(table_name, system_charset_info);
if (!table->table) if (!t)
{ {
protocol->store_null(); protocol->store_null();
thd->net.last_error[0]=0; thd->net.last_error[0]=0;
} }
else else
{ {
table->table->pos_in_table_list= table; t->pos_in_table_list= table;
if (table->table->file->table_flags() & HA_HAS_CHECKSUM) if (t->file->table_flags() & HA_HAS_CHECKSUM &&
protocol->store((ulonglong)table->table->file->checksum()); !(check_opt->flags & T_EXTEND))
else protocol->store((ulonglong)t->file->checksum());
else if (!(t->file->table_flags() & HA_HAS_CHECKSUM) &&
check_opt->flags & T_QUICK)
protocol->store_null(); 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 #ifdef EMBEDDED_LIBRARY
thd->net.last_errno= 0; // these errors shouldn't get client thd->net.last_errno= 0; // these errors shouldn't get client
#endif #endif

View File

@ -1080,7 +1080,7 @@ opt_select_from:
| select_from select_lock_type; | select_from select_lock_type;
udf_func_type: udf_func_type:
/* empty */ { $$ = UDFTYPE_FUNCTION; } /* empty */ { $$ = UDFTYPE_FUNCTION; }
| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; }; | AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
udf_type: udf_type:
@ -1547,7 +1547,7 @@ opt_ident:
opt_component: opt_component:
/* empty */ { $$.str= 0; $$.length= 0; } /* empty */ { $$.str= 0; $$.length= 0; }
| '.' ident { $$=$2; }; | '.' ident { $$=$2; };
string_list: string_list:
text_string { Lex->interval_list.push_back($1); } text_string { Lex->interval_list.push_back($1); }
| string_list ',' text_string { Lex->interval_list.push_back($3); }; | string_list ',' text_string { Lex->interval_list.push_back($3); };
@ -1760,10 +1760,16 @@ checksum:
LEX *lex=Lex; LEX *lex=Lex;
lex->sql_command = SQLCOM_CHECKSUM; lex->sql_command = SQLCOM_CHECKSUM;
} }
table_list table_list opt_checksum_type
{} {}
; ;
opt_checksum_type:
/* nothing */ { Lex->check_opt.flags= 0; }
| QUICK { Lex->check_opt.flags= T_QUICK; }
| EXTENDED_SYM { Lex->check_opt.flags= T_EXTEND; }
;
repair: repair:
REPAIR opt_no_write_to_binlog table_or_tables REPAIR opt_no_write_to_binlog table_or_tables
{ {