From e103da7acc6f3563a2f7207e59c34b9d9ff64295 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 21 Aug 2003 16:15:06 +0200 Subject: fixed a crash on COMPRESS() and other zlib-dependent functions when compiled w/o zlib moved them all from different places to item_strfunc.{h,cc} checksum table command Com_xxx status variables updated sql/item_create.cc: fixed a crash on COMPRESS() and other zlib-dependent functions when compiled w/o zlib moved them all from different places to item_strfunc.{h,cc} sql/item_func.cc: fixed a crash on COMPRESS() and other zlib-dependent functions when compiled w/o zlib moved them all from different places to item_strfunc.{h,cc} sql/item_func.h: fixed a crash on COMPRESS() and other zlib-dependent functions when compiled w/o zlib moved them all from different places to item_strfunc.{h,cc} sql/item_geofunc.h: fixed a crash on COMPRESS() and other zlib-dependent functions when compiled w/o zlib moved them all from different places to item_strfunc.{h,cc} sql/item_strfunc.cc: fixed a crash on COMPRESS() and other zlib-dependent functions when compiled w/o zlib moved them all from different places to item_strfunc.{h,cc} sql/item_strfunc.h: fixed a crash on COMPRESS() and other zlib-dependent functions when compiled w/o zlib moved them all from different places to item_strfunc.{h,cc} sql/mysql_priv.h: checksum table command sql/mysqld.cc: Com_xxx updated sql/sql_lex.h: checksum table command sql/sql_parse.cc: checksum table command sql/sql_table.cc: checksum table command sql/sql_yacc.yy: checksum table command --- sql/sql_table.cc | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 7cb8dfaae0d..d63a15c13a8 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2555,7 +2555,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, delete_count++; } else - found_count++; + found_count++; } end_read_record(&info); free_io_cache(from); @@ -2587,3 +2587,67 @@ copy_data_between_tables(TABLE *from,TABLE *to, *deleted=delete_count; DBUG_RETURN(error > 0 ? -1 : 0); } + +int mysql_checksum_table(THD* thd, TABLE_LIST* tables) +{ + TABLE_LIST *table; + List field_list; + Item *item; + Protocol *protocol= thd->protocol; + DBUG_ENTER("mysql_admin_table"); + + field_list.push_back(item = new Item_empty_string("Table", NAME_LEN*2)); + item->maybe_null= 1; + field_list.push_back(item=new Item_int("Checksum",(longlong) 1,21)); + item->maybe_null= 1; + if (protocol->send_fields(&field_list, 1)) + DBUG_RETURN(-1); + + for (table = tables; table; table = table->next) + { + char table_name[NAME_LEN*2+2]; + char* db = (table->db) ? table->db : thd->db; + bool fatal_error=0; + strxmov(table_name,db ? db : "",".",table->real_name,NullS); + + 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 + + protocol->prepare_for_resend(); + protocol->store(table_name, system_charset_info); + + if (!table->table) + { + protocol->store_null(); + thd->net.last_error[0]=0; + } + else + { + table->table->pos_in_table_list= table; + + if (table->table->file->table_flags() & HA_HAS_CHECKSUM) + protocol->store((ulonglong)table->table->file->checksum()); + else + protocol->store_null(); +#ifdef EMBEDDED_LIBRARY + thd->net.last_errno= 0; // these errors shouldn't get client +#endif + + close_thread_tables(thd); + table->table=0; // For query cache + } + if (protocol->write()) + goto err; + } + + send_eof(thd); + DBUG_RETURN(0); + err: + close_thread_tables(thd); // Shouldn't be needed + if (table) + table->table=0; + DBUG_RETURN(-1); +} + -- cgit v1.2.1 From 4a21b30e47cfb2905ac1e6a3e9a220164067b595 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 3 Sep 2003 11:34:32 +0200 Subject: 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 --- sql/sql_table.cc | 66 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 15 deletions(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index d63a15c13a8..48a99cfaad5 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -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 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 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 -- cgit v1.2.1