Commit 4a21b30e authored by unknown's avatar unknown

CHECKSUM TABLE table1, table2, ... [ QUICK | EXTENDED ]


myisam/mi_checksum.c:
  workaround for zlib's crc32 glitch
mysql-test/r/show_check.result:
  results updated
mysys/checksum.c:
  switching to crc32 as a checksum algorithm
parent 710d4f14
...@@ -50,7 +50,7 @@ ha_checksum mi_checksum(MI_INFO *info, const byte *buf) ...@@ -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;
} }
......
...@@ -1341,3 +1341,28 @@ ERROR HY000: Table storage engine for 't1' doesn't have this option ...@@ -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;
...@@ -394,6 +394,23 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -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;
...@@ -43,7 +43,7 @@ wait_timeout 28800 ...@@ -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
......
...@@ -920,3 +920,15 @@ replace delayed into t1 (c1, c2) values ( "text1","12"),( "text2","13"),( "text ...@@ -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;
...@@ -360,4 +360,15 @@ drop table t1,t2; ...@@ -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;
...@@ -30,9 +30,11 @@ ...@@ -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);
} }
...@@ -398,7 +398,8 @@ bool check_global_access(THD *thd, ulong want_access); ...@@ -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,
......
...@@ -2269,7 +2269,7 @@ mysql_execute_command(THD *thd) ...@@ -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:
......
...@@ -2588,7 +2588,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, ...@@ -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) ...@@ -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) ...@@ -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))
protocol->store((ulonglong)t->file->checksum());
else if (!(t->file->table_flags() & HA_HAS_CHECKSUM) &&
check_opt->flags & T_QUICK)
protocol->store_null();
else else
{
/* calculating table's checksum */
ha_checksum crc=0;
if (t->file->rnd_init(1))
protocol->store_null(); 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
......
...@@ -1760,10 +1760,16 @@ checksum: ...@@ -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
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment