::reset(), HA_FAST_KEY_READ, disable_indexes(), enable_indexes(), start_bulk_insert(), end_bulk_insert()

Field::val_str simplification, comment


include/my_base.h:
  typos fixed
mysql-test/r/myisam.result:
  alter table enable/disable keys
mysql-test/t/help.test:
  cleanup
mysql-test/t/myisam.test:
  alter table enable/disable keys
sql/field.cc:
  Field::val_str() simplification
sql/field.h:
  Field::val_str() simplification and comment
sql/field_conv.cc:
  Field::val_str() simplification
sql/ha_berkeley.cc:
  ::reset(), HA_FAST_KEY_READ
sql/ha_berkeley.h:
  ::reset(), HA_FAST_KEY_READ
sql/ha_heap.cc:
  ::reset(), HA_FAST_KEY_READ
sql/ha_heap.h:
  ::reset(), HA_FAST_KEY_READ
sql/ha_innodb.cc:
  ::reset(), HA_FAST_KEY_READ
sql/ha_innodb.h:
  ::reset(), HA_FAST_KEY_READ
sql/ha_isam.cc:
  ::reset(), HA_FAST_KEY_READ
sql/ha_isam.h:
  ::reset(), HA_FAST_KEY_READ
sql/ha_isammrg.cc:
  ::reset(), HA_FAST_KEY_READ
sql/ha_isammrg.h:
  ::reset(), HA_FAST_KEY_READ
sql/ha_myisam.cc:
  ::reset(), HA_FAST_KEY_READ, disable_indexes(), enable_indexes(), start_bulk_insert(), end_bulk_insert()
sql/ha_myisam.h:
  ::reset(), HA_FAST_KEY_READ, disable_indexes(), enable_indexes(), start_bulk_insert(), end_bulk_insert()
sql/ha_myisammrg.cc:
  ::reset(), HA_FAST_KEY_READ
sql/ha_myisammrg.h:
  ::reset(), HA_FAST_KEY_READ
sql/handler.h:
  ::reset(), HA_FAST_KEY_READ, disable_indexes(), enable_indexes(), start_bulk_insert(), end_bulk_insert()
sql/item.cc:
  Field::val_str() simplification
sql/item_sum.cc:
  Field::val_str() simplification
sql/key.cc:
  Field::val_str() simplification
sql/opt_range.cc:
  Field::val_str() simplification
sql/protocol.cc:
  Field::val_str() simplification
sql/records.cc:
  HA_FAST_KEY_READ
sql/sql_acl.cc:
  Field::val_str() simplification
sql/sql_base.cc:
  ::reset
sql/sql_insert.cc:
  ::reset(), start_bulk_insert(), end_bulk_insert()
sql/sql_load.cc:
  start_bulk_insert(), end_bulk_insert()
sql/sql_show.cc:
  Field::val_str() simplification
sql/sql_table.cc:
  disable_indexes(), enable_indexes(), start_bulk_insert(), end_bulk_insert()
sql/table.cc:
  Field::val_str() simplification
This commit is contained in:
unknown 2004-04-06 21:35:26 +02:00
parent f463848913
commit c627054340
35 changed files with 200 additions and 178 deletions

View file

@ -105,8 +105,8 @@ enum ha_extra_function {
HA_EXTRA_NORMAL=0, /* Optimize for space (def) */ HA_EXTRA_NORMAL=0, /* Optimize for space (def) */
HA_EXTRA_QUICK=1, /* Optimize for speed */ HA_EXTRA_QUICK=1, /* Optimize for speed */
HA_EXTRA_RESET=2, /* Reset database to after open */ HA_EXTRA_RESET=2, /* Reset database to after open */
HA_EXTRA_CACHE=3, /* Cash record in HA_rrnd() */ HA_EXTRA_CACHE=3, /* Cache record in HA_rrnd() */
HA_EXTRA_NO_CACHE=4, /* End cacheing of records (def) */ HA_EXTRA_NO_CACHE=4, /* End caching of records (def) */
HA_EXTRA_NO_READCHECK=5, /* No readcheck on update */ HA_EXTRA_NO_READCHECK=5, /* No readcheck on update */
HA_EXTRA_READCHECK=6, /* Use readcheck (def) */ HA_EXTRA_READCHECK=6, /* Use readcheck (def) */
HA_EXTRA_KEYREAD=7, /* Read only key to database */ HA_EXTRA_KEYREAD=7, /* Read only key to database */

View file

@ -504,3 +504,27 @@ test.t1 968604391
test.t2 968604391 test.t2 968604391
test.t3 NULL test.t3 NULL
drop table t1,t2; drop table t1,t2;
create table t1 (a int, key (a));
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
t1 1 a 1 a A NULL NULL NULL YES BTREE
alter table t1 disable keys;
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
t1 1 a 1 a A NULL NULL NULL YES BTREE disabled
create table t2 (a int);
insert t1 select * from t2;
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
t1 1 a 1 a A NULL NULL NULL YES BTREE disabled
alter table t1 enable keys;
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
t1 1 a 1 a A 1000 NULL NULL YES BTREE
alter table t1 engine=heap;
alter table t1 disable keys;
ERROR HY000: Table storage engine for 't1' doesn't have this option
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
t1 1 a 1 a NULL NULL NULL NULL YES HASH
drop table t1,t2;

View file

@ -1,5 +1,3 @@
-- source include/have_innodb.inc
# category: topic: keyword: # category: topic: keyword:
# #
# impossible_category_1 # impossible_category_1
@ -65,10 +63,12 @@ help 'impossible_function_1';
help 'impossible_category_1'; help 'impossible_category_1';
############## ##############
--disable_warnings
alter table mysql.help_relation engine=innodb; alter table mysql.help_relation engine=innodb;
alter table mysql.help_keyword engine=innodb; alter table mysql.help_keyword engine=innodb;
alter table mysql.help_topic engine=innodb; alter table mysql.help_topic engine=innodb;
alter table mysql.help_category engine=innodb; alter table mysql.help_category engine=innodb;
--enable_warnings
############## ##############
help 'function_of_my_dream'; help 'function_of_my_dream';

View file

@ -479,3 +479,27 @@ checksum table t1, t2, t3;
checksum table t1, t2, t3 extended; checksum table t1, t2, t3 extended;
#show table status; #show table status;
drop table t1,t2; drop table t1,t2;
create table t1 (a int, key (a));
show keys from t1;
alter table t1 disable keys;
show keys from t1;
create table t2 (a int);
let $i=1000;
--disable_query_log
while ($i)
{
dec $i;
eval insert t2 values (rand()*100000);
}
--enable_query_log
insert t1 select * from t2;
show keys from t1;
alter table t1 enable keys;
show keys from t1;
alter table t1 engine=heap;
--error 1031
alter table t1 disable keys;
show keys from t1;
drop table t1,t2;

View file

@ -327,7 +327,7 @@ bool Field::send_binary(Protocol *protocol)
{ {
char buff[MAX_FIELD_WIDTH]; char buff[MAX_FIELD_WIDTH];
String tmp(buff,sizeof(buff),charset()); String tmp(buff,sizeof(buff),charset());
val_str(&tmp,&tmp); val_str(&tmp);
return protocol->store(tmp.ptr(), tmp.length(), tmp.charset()); return protocol->store(tmp.ptr(), tmp.length(), tmp.charset());
} }
@ -396,8 +396,8 @@ uint Field::fill_cache_field(CACHE_FIELD *copy)
bool Field::get_date(TIME *ltime,uint fuzzydate) bool Field::get_date(TIME *ltime,uint fuzzydate)
{ {
char buff[40]; char buff[40];
String tmp(buff,sizeof(buff),&my_charset_bin),tmp2,*res; String tmp(buff,sizeof(buff),&my_charset_bin),*res;
if (!(res=val_str(&tmp,&tmp2)) || if (!(res=val_str(&tmp)) ||
str_to_TIME(res->ptr(),res->length(),ltime,fuzzydate) <= str_to_TIME(res->ptr(),res->length(),ltime,fuzzydate) <=
TIMESTAMP_DATETIME_ERROR) TIMESTAMP_DATETIME_ERROR)
return 1; return 1;
@ -407,8 +407,8 @@ bool Field::get_date(TIME *ltime,uint fuzzydate)
bool Field::get_time(TIME *ltime) bool Field::get_time(TIME *ltime)
{ {
char buff[40]; char buff[40];
String tmp(buff,sizeof(buff),&my_charset_bin),tmp2,*res; String tmp(buff,sizeof(buff),&my_charset_bin),*res;
if (!(res=val_str(&tmp,&tmp2)) || if (!(res=val_str(&tmp)) ||
str_to_time(res->ptr(),res->length(),ltime)) str_to_time(res->ptr(),res->length(),ltime))
return 1; return 1;
return 0; return 0;
@ -3119,8 +3119,8 @@ String *Field_timestamp::val_str(String *val_buffer,
if (temp == 0L) if (temp == 0L)
{ /* Zero time is "000000" */ { /* Zero time is "000000" */
val_ptr->set("0000-00-00 00:00:00", 19, &my_charset_bin); val_buffer->set("0000-00-00 00:00:00", 19, &my_charset_bin);
return val_ptr; return val_buffer;
} }
val_buffer->set_charset(&my_charset_bin); // Safety val_buffer->set_charset(&my_charset_bin); // Safety
time_arg=(time_t) temp; time_arg=(time_t) temp;
@ -5788,7 +5788,7 @@ create_field::create_field(Field *old_field,Field *orig_field)
my_ptrdiff_t diff= (my_ptrdiff_t) (orig_field->table->rec_buff_length*2); my_ptrdiff_t diff= (my_ptrdiff_t) (orig_field->table->rec_buff_length*2);
orig_field->move_field(diff); // Points now at default_values orig_field->move_field(diff); // Points now at default_values
bool is_null=orig_field->is_real_null(); bool is_null=orig_field->is_real_null();
orig_field->val_str(&tmp,&tmp); orig_field->val_str(&tmp);
orig_field->move_field(-diff); // Back to record[0] orig_field->move_field(-diff); // Back to record[0]
if (!is_null) if (!is_null)
{ {

View file

@ -98,6 +98,18 @@ public:
virtual void store_time(TIME *ltime,timestamp_type t_type); virtual void store_time(TIME *ltime,timestamp_type t_type);
virtual double val_real(void)=0; virtual double val_real(void)=0;
virtual longlong val_int(void)=0; virtual longlong val_int(void)=0;
String *val_str(String *str) { return val_str(str, str); }
/* val_str(buf1, buf2) gets two buffers and should use them as follows:
if it needs a temp buffer to convert result to string - use buf1
example Field_tiny::val_str()
if the value exists as a string already - use buf2
example Field_string::val_str()
consequently, buf2 may be created as 'String buf;' - no memory
will be allocated for it. buf1 will be allocated to hold a
value if it's too small. Using allocated buffer for buf2 may result in
an unnecessary free (and later, may be an alloc).
This trickery is used to decrease a number of malloc calls.
*/
virtual String *val_str(String*,String *)=0; virtual String *val_str(String*,String *)=0;
virtual Item_result result_type () const=0; virtual Item_result result_type () const=0;
virtual Item_result cmp_type () const { return result_type(); } virtual Item_result cmp_type () const { return result_type(); }

View file

@ -274,7 +274,7 @@ static void do_copy_blob(Copy_field *copy)
static void do_conv_blob(Copy_field *copy) static void do_conv_blob(Copy_field *copy)
{ {
copy->from_field->val_str(&copy->tmp,&copy->tmp); copy->from_field->val_str(&copy->tmp);
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(), ((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
copy->tmp.length(), copy->tmp.length(),
copy->tmp.charset()); copy->tmp.charset());
@ -286,7 +286,7 @@ static void do_save_blob(Copy_field *copy)
{ {
char buff[MAX_FIELD_WIDTH]; char buff[MAX_FIELD_WIDTH];
String res(buff,sizeof(buff),copy->tmp.charset()); String res(buff,sizeof(buff),copy->tmp.charset());
copy->from_field->val_str(&res,&res); copy->from_field->val_str(&res);
copy->tmp.copy(res); copy->tmp.copy(res);
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(), ((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
copy->tmp.length(), copy->tmp.length(),
@ -298,7 +298,7 @@ static void do_field_string(Copy_field *copy)
{ {
char buff[MAX_FIELD_WIDTH]; char buff[MAX_FIELD_WIDTH];
copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset()); copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset());
copy->from_field->val_str(&copy->tmp,&copy->tmp); copy->from_field->val_str(&copy->tmp);
copy->to_field->store(copy->tmp.c_ptr_quick(),copy->tmp.length(),copy->tmp.charset()); copy->to_field->store(copy->tmp.c_ptr_quick(),copy->tmp.length(),copy->tmp.charset());
} }
@ -559,7 +559,7 @@ void field_conv(Field *to,Field *from)
if (to->type() == FIELD_TYPE_BLOB) if (to->type() == FIELD_TYPE_BLOB)
{ // Be sure the value is stored { // Be sure the value is stored
Field_blob *blob=(Field_blob*) to; Field_blob *blob=(Field_blob*) to;
from->val_str(&blob->value,&blob->value); from->val_str(&blob->value);
if (!blob->value.is_alloced() && if (!blob->value.is_alloced() &&
from->real_type() != FIELD_TYPE_STRING) from->real_type() != FIELD_TYPE_STRING)
blob->value.copy(); blob->value.copy();
@ -574,7 +574,7 @@ void field_conv(Field *to,Field *from)
{ {
char buff[MAX_FIELD_WIDTH]; char buff[MAX_FIELD_WIDTH];
String result(buff,sizeof(buff),from->charset()); String result(buff,sizeof(buff),from->charset());
from->val_str(&result,&result); from->val_str(&result);
to->store(result.c_ptr_quick(),result.length(),from->charset()); to->store(result.c_ptr_quick(),result.length(),from->charset());
} }
else if (from->result_type() == REAL_RESULT) else if (from->result_type() == REAL_RESULT)

View file

@ -1709,6 +1709,7 @@ int ha_berkeley::extra(enum ha_extra_function operation)
int ha_berkeley::reset(void) int ha_berkeley::reset(void)
{ {
ha_berkeley::extra(HA_EXTRA_RESET);
key_read=0; // Reset to state after open key_read=0; // Reset to state after open
return 0; return 0;
} }

View file

@ -88,7 +88,7 @@ class ha_berkeley: public handler
public: public:
ha_berkeley(TABLE *table): handler(table), alloc_ptr(0),rec_buff(0), file(0), ha_berkeley(TABLE *table): handler(table), alloc_ptr(0),rec_buff(0), file(0),
int_table_flags(HA_REC_NOT_IN_SEQ | int_table_flags(HA_REC_NOT_IN_SEQ |
HA_KEYPOS_TO_RNDPOS | HA_LASTKEY_ORDER | HA_KEYPOS_TO_RNDPOS | HA_LASTKEY_ORDER | HA_FAST_KEY_READ |
HA_NULL_KEY | HA_BLOB_KEY | HA_NOT_EXACT_COUNT | HA_NULL_KEY | HA_BLOB_KEY | HA_NOT_EXACT_COUNT |
HA_PRIMARY_KEY_IN_READ_INDEX | HA_DROP_BEFORE_CREATE | HA_PRIMARY_KEY_IN_READ_INDEX | HA_DROP_BEFORE_CREATE |
HA_AUTO_PART_KEY | HA_TABLE_SCAN_ON_INDEX | HA_AUTO_PART_KEY | HA_TABLE_SCAN_ON_INDEX |
@ -107,7 +107,6 @@ class ha_berkeley: public handler
uint max_key_length() const { return MAX_KEY_LENGTH; } uint max_key_length() const { return MAX_KEY_LENGTH; }
uint extra_rec_buf_length() { return BDB_HIDDEN_PRIMARY_KEY_LENGTH; } uint extra_rec_buf_length() { return BDB_HIDDEN_PRIMARY_KEY_LENGTH; }
ha_rows estimate_number_of_rows(); ha_rows estimate_number_of_rows();
bool fast_key_read() { return 1;}
const key_map *keys_to_use_for_scanning() { return &key_map_full; } const key_map *keys_to_use_for_scanning() { return &key_map_full; }
bool has_transactions() { return 1;} bool has_transactions() { return 1;}

View file

@ -196,11 +196,6 @@ int ha_heap::extra(enum ha_extra_function operation)
return heap_extra(file,operation); return heap_extra(file,operation);
} }
int ha_heap::reset(void)
{
return heap_extra(file,HA_EXTRA_RESET);
}
int ha_heap::delete_all_rows() int ha_heap::delete_all_rows()
{ {
heap_clear(file); heap_clear(file);

View file

@ -40,7 +40,7 @@ class ha_heap: public handler
const char **bas_ext() const; const char **bas_ext() const;
ulong table_flags() const ulong table_flags() const
{ {
return (HA_READ_RND_SAME | HA_NO_INDEX | HA_KEYPOS_TO_RNDPOS | return (HA_READ_RND_SAME | HA_FAST_KEY_READ | HA_KEYPOS_TO_RNDPOS |
HA_NO_BLOBS | HA_NULL_KEY | HA_REC_NOT_IN_SEQ); HA_NO_BLOBS | HA_NULL_KEY | HA_REC_NOT_IN_SEQ);
} }
ulong index_flags(uint inx) const ulong index_flags(uint inx) const
@ -58,7 +58,6 @@ class ha_heap: public handler
double scan_time() { return (double) (records+deleted) / 20.0+10; } double scan_time() { return (double) (records+deleted) / 20.0+10; }
double read_time(uint index, uint ranges, ha_rows rows) double read_time(uint index, uint ranges, ha_rows rows)
{ return (double) rows / 20.0+1; } { return (double) rows / 20.0+1; }
virtual bool fast_key_read() { return 1;}
int open(const char *name, int mode, uint test_if_locked); int open(const char *name, int mode, uint test_if_locked);
int close(void); int close(void);
@ -81,7 +80,6 @@ class ha_heap: public handler
void position(const byte *record); void position(const byte *record);
void info(uint); void info(uint);
int extra(enum ha_extra_function operation); int extra(enum ha_extra_function operation);
int reset(void);
int external_lock(THD *thd, int lock_type); int external_lock(THD *thd, int lock_type);
int delete_all_rows(void); int delete_all_rows(void);
ha_rows records_in_range(int inx, const byte *start_key,uint start_key_len, ha_rows records_in_range(int inx, const byte *start_key,uint start_key_len,

View file

@ -4540,16 +4540,6 @@ ha_innobase::extra(
return(0); return(0);
} }
/**********************************************************************
????????????? */
int
ha_innobase::reset(void)
/*====================*/
{
return(0);
}
/********************************************************************** /**********************************************************************
MySQL calls this function at the start of each SQL statement inside LOCK MySQL calls this function at the start of each SQL statement inside LOCK
TABLES. Inside LOCK TABLES the ::external_lock method does not work to TABLES. Inside LOCK TABLES the ::external_lock method does not work to

View file

@ -89,7 +89,7 @@ class ha_innobase: public handler
int_table_flags(HA_REC_NOT_IN_SEQ | int_table_flags(HA_REC_NOT_IN_SEQ |
HA_KEYPOS_TO_RNDPOS | HA_KEYPOS_TO_RNDPOS |
HA_LASTKEY_ORDER | HA_LASTKEY_ORDER |
HA_NULL_KEY | HA_NULL_KEY | HA_FAST_KEY_READ |
HA_BLOB_KEY | HA_BLOB_KEY |
HA_CAN_SQL_HANDLER | HA_CAN_SQL_HANDLER |
HA_NOT_EXACT_COUNT | HA_NOT_EXACT_COUNT |
@ -123,7 +123,6 @@ class ha_innobase: public handler
whose size is > MAX_KEY_LENGTH */ whose size is > MAX_KEY_LENGTH */
uint max_key_length() const { return((MAX_KEY_LENGTH <= 3500) ? uint max_key_length() const { return((MAX_KEY_LENGTH <= 3500) ?
MAX_KEY_LENGTH : 3500);} MAX_KEY_LENGTH : 3500);}
bool fast_key_read() { return 1;}
const key_map *keys_to_use_for_scanning() { return &key_map_full; } const key_map *keys_to_use_for_scanning() { return &key_map_full; }
bool has_transactions() { return 1;} bool has_transactions() { return 1;}
@ -161,7 +160,6 @@ class ha_innobase: public handler
int optimize(THD* thd,HA_CHECK_OPT* check_opt); int optimize(THD* thd,HA_CHECK_OPT* check_opt);
int discard_or_import_tablespace(my_bool discard); int discard_or_import_tablespace(my_bool discard);
int extra(enum ha_extra_function operation); int extra(enum ha_extra_function operation);
int reset(void);
int external_lock(THD *thd, int lock_type); int external_lock(THD *thd, int lock_type);
int start_stmt(THD *thd); int start_stmt(THD *thd);

View file

@ -237,11 +237,6 @@ int ha_isam::extra(enum ha_extra_function operation)
return nisam_extra(file,operation); return nisam_extra(file,operation);
} }
int ha_isam::reset(void)
{
return nisam_extra(file,HA_EXTRA_RESET);
}
int ha_isam::external_lock(THD *thd, int lock_type) int ha_isam::external_lock(THD *thd, int lock_type)
{ {
if (!table->tmp_table) if (!table->tmp_table)

View file

@ -69,7 +69,6 @@ class ha_isam: public handler
my_off_t row_position() { return nisam_position(file); } my_off_t row_position() { return nisam_position(file); }
void info(uint); void info(uint);
int extra(enum ha_extra_function operation); int extra(enum ha_extra_function operation);
int reset(void);
int external_lock(THD *thd, int lock_type); int external_lock(THD *thd, int lock_type);
ha_rows records_in_range(int inx, ha_rows records_in_range(int inx,
const byte *start_key,uint start_key_len, const byte *start_key,uint start_key_len,

View file

@ -171,11 +171,6 @@ int ha_isammrg::extra(enum ha_extra_function operation)
return !mrg_extra(file,operation) ? 0 : my_errno ? my_errno : -1; return !mrg_extra(file,operation) ? 0 : my_errno ? my_errno : -1;
} }
int ha_isammrg::reset(void)
{
return !mrg_extra(file,HA_EXTRA_RESET) ? 0 : my_errno ? my_errno : -1;
}
int ha_isammrg::external_lock(THD *thd, int lock_type) int ha_isammrg::external_lock(THD *thd, int lock_type)
{ {
return !mrg_lock_database(file,lock_type) ? 0 : my_errno ? my_errno : -1; return !mrg_lock_database(file,lock_type) ? 0 : my_errno ? my_errno : -1;

View file

@ -63,7 +63,6 @@ class ha_isammrg: public handler
my_off_t row_position() { return mrg_position(file); } my_off_t row_position() { return mrg_position(file); }
void info(uint); void info(uint);
int extra(enum ha_extra_function operation); int extra(enum ha_extra_function operation);
int reset(void);
int external_lock(THD *thd, int lock_type); int external_lock(THD *thd, int lock_type);
uint lock_count(void) const; uint lock_count(void) const;
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);

View file

@ -810,66 +810,31 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt)
} }
} }
/* /* disable indexes, making it persistent if requested
Deactive all not unique index that can be recreated fast
SYNOPSIS SYNOPSIS
deactivate_non_unique_index() disable_indexes(all, save)
rows Rows to be inserted all disable all indexes
0 if we don't know if not set only non-unique indexes will be disabled
HA_POS_ERROR if we want to force disabling [all=1 is NOT IMPLEMENTED YET]
and make it permanent (save on disk) save save the disabled state, so that it will persist
between queries/threads/reboots
[save=0 is NOT IMPLEMENTED YET]
*/ */
int ha_myisam::disable_indexes(bool all, bool save)
void ha_myisam::deactivate_non_unique_index(ha_rows rows)
{ {
MYISAM_SHARE* share = file->s;
if (share->state.key_map == ((ulonglong) 1L << share->base.keys)-1)
{
if (!(specialflag & SPECIAL_SAFE_MODE))
{
if (rows == HA_POS_ERROR) // force disable and save it on disk!
mi_extra(file, HA_EXTRA_NO_KEYS, 0); mi_extra(file, HA_EXTRA_NO_KEYS, 0);
else
{
/*
Only disable old index if the table was empty and we are inserting
a lot of rows.
We should not do this for only a few rows as this is slower and
we don't want to update the key statistics based of only a few rows.
*/
if (file->state->records == 0 &&
(!rows || rows >= MI_MIN_ROWS_TO_DISABLE_INDEXES))
mi_disable_non_unique_index(file,rows);
else
if (!file->bulk_insert &&
(!rows || rows >= MI_MIN_ROWS_TO_USE_BULK_INSERT))
{
mi_init_bulk_insert(file,
current_thd->variables.bulk_insert_buff_size,
rows);
}
}
}
enable_activate_all_index=1;
info(HA_STATUS_CONST); // Read new key info info(HA_STATUS_CONST); // Read new key info
} return 0;
else
enable_activate_all_index=0;
} }
int ha_myisam::enable_indexes()
bool ha_myisam::activate_all_index(THD *thd)
{ {
if (file->s->state.key_map == set_bits(ulonglong, file->s->base.keys))
return 0;
int error=0; int error=0;
THD *thd=current_thd;
MI_CHECK param; MI_CHECK param;
MYISAM_SHARE* share = file->s;
DBUG_ENTER("activate_all_index");
mi_end_bulk_insert(file);
if (enable_activate_all_index &&
share->state.key_map != set_bits(ulonglong, share->base.keys))
{
const char *save_proc_info=thd->proc_info; const char *save_proc_info=thd->proc_info;
thd->proc_info="Creating index"; thd->proc_info="Creating index";
myisamchk_init(&param); myisamchk_init(&param);
@ -882,10 +847,52 @@ bool ha_myisam::activate_all_index(THD *thd)
error=repair(thd,param,0) != HA_ADMIN_OK; error=repair(thd,param,0) != HA_ADMIN_OK;
info(HA_STATUS_CONST); info(HA_STATUS_CONST);
thd->proc_info=save_proc_info; thd->proc_info=save_proc_info;
return error;
} }
/*
prepare for a many-rows insert operation
e.g. - disable indexes (if they can be recreated fast) or
activate special bulk-insert optimizations
SYNOPSIS
start_bulk_insert(rows)
rows Rows to be inserted
0 if we don't know
*/
void ha_myisam::start_bulk_insert(ha_rows rows)
{
if (!(specialflag & SPECIAL_SAFE_MODE))
{
can_enable_indexes= (file->s->state.key_map ==
set_bits(ulonglong, file->s->base.keys));
/*
Only disable old index if the table was empty and we are inserting
a lot of rows.
We should not do this for only a few rows as this is slower and
we don't want to update the key statistics based of only a few rows.
*/
if (file->state->records == 0 && can_enable_indexes &&
(!rows || rows >= MI_MIN_ROWS_TO_DISABLE_INDEXES))
mi_disable_non_unique_index(file,rows);
else else
enable_activate_all_index=1; if (!file->bulk_insert &&
DBUG_RETURN(error); (!rows || rows >= MI_MIN_ROWS_TO_USE_BULK_INSERT))
{
mi_init_bulk_insert(file,
current_thd->variables.bulk_insert_buff_size,
rows);
}
}
}
int ha_myisam::end_bulk_insert()
{
mi_end_bulk_insert(file);
return can_enable_indexes ? enable_indexes() : 0;
} }
@ -1118,12 +1125,6 @@ int ha_myisam::extra_opt(enum ha_extra_function operation, ulong cache_size)
return mi_extra(file, operation, (void*) &cache_size); return mi_extra(file, operation, (void*) &cache_size);
} }
int ha_myisam::reset(void)
{
return mi_extra(file, HA_EXTRA_RESET, 0);
}
int ha_myisam::delete_all_rows() int ha_myisam::delete_all_rows()
{ {
return mi_delete_all_rows(file); return mi_delete_all_rows(file);

View file

@ -39,7 +39,7 @@ class ha_myisam: public handler
MI_INFO *file; MI_INFO *file;
ulong int_table_flags; ulong int_table_flags;
char *data_file_name, *index_file_name; char *data_file_name, *index_file_name;
bool enable_activate_all_index; bool can_enable_indexes;
int repair(THD *thd, MI_CHECK &param, bool optimize); int repair(THD *thd, MI_CHECK &param, bool optimize);
public: public:
@ -48,7 +48,7 @@ class ha_myisam: public handler
HA_NULL_KEY | HA_CAN_FULLTEXT | HA_CAN_SQL_HANDLER | HA_NULL_KEY | HA_CAN_FULLTEXT | HA_CAN_SQL_HANDLER |
HA_DUPP_POS | HA_BLOB_KEY | HA_AUTO_PART_KEY | HA_DUPP_POS | HA_BLOB_KEY | HA_AUTO_PART_KEY |
HA_FILE_BASED | HA_HAS_GEOMETRY), HA_FILE_BASED | HA_HAS_GEOMETRY),
enable_activate_all_index(1) can_enable_indexes(1)
{} {}
~ha_myisam() {} ~ha_myisam() {}
const char *table_type() const { return "MyISAM"; } const char *table_type() const { return "MyISAM"; }
@ -103,11 +103,12 @@ class ha_myisam: public handler
void info(uint); void info(uint);
int extra(enum ha_extra_function operation); int extra(enum ha_extra_function operation);
int extra_opt(enum ha_extra_function operation, ulong cache_size); int extra_opt(enum ha_extra_function operation, ulong cache_size);
int reset(void);
int external_lock(THD *thd, int lock_type); int external_lock(THD *thd, int lock_type);
int delete_all_rows(void); int delete_all_rows(void);
void deactivate_non_unique_index(ha_rows rows); int disable_indexes(bool all, bool save);
bool activate_all_index(THD *thd); int enable_indexes();
void start_bulk_insert(ha_rows rows);
int end_bulk_insert();
ha_rows records_in_range(int inx, ha_rows records_in_range(int inx,
const byte *start_key,uint start_key_len, const byte *start_key,uint start_key_len,
enum ha_rkey_function start_search_flag, enum ha_rkey_function start_search_flag,

View file

@ -271,12 +271,6 @@ int ha_myisammrg::extra_opt(enum ha_extra_function operation, ulong cache_size)
return myrg_extra(file, operation, (void*) &cache_size); return myrg_extra(file, operation, (void*) &cache_size);
} }
int ha_myisammrg::reset(void)
{
return myrg_extra(file,HA_EXTRA_RESET,0);
}
int ha_myisammrg::external_lock(THD *thd, int lock_type) int ha_myisammrg::external_lock(THD *thd, int lock_type)
{ {
return myrg_lock_database(file,lock_type); return myrg_lock_database(file,lock_type);

View file

@ -79,7 +79,6 @@ class ha_myisammrg: public handler
void info(uint); void info(uint);
int extra(enum ha_extra_function operation); int extra(enum ha_extra_function operation);
int extra_opt(enum ha_extra_function operation, ulong cache_size); int extra_opt(enum ha_extra_function operation, ulong cache_size);
int reset(void);
int external_lock(THD *thd, int lock_type); int external_lock(THD *thd, int lock_type);
uint lock_count(void) const; uint lock_count(void) const;
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);

View file

@ -51,7 +51,7 @@
#define HA_REC_NOT_IN_SEQ 8 /* ha_info don't return recnumber; #define HA_REC_NOT_IN_SEQ 8 /* ha_info don't return recnumber;
It returns a position to ha_r_rnd */ It returns a position to ha_r_rnd */
#define HA_HAS_GEOMETRY (1 << 4) #define HA_HAS_GEOMETRY (1 << 4)
#define HA_NO_INDEX (1 << 5) /* No index needed for next/prev */ #define HA_FAST_KEY_READ (1 << 5) /* no need for a record cache in filesort */
#define HA_KEY_READ_WRONG_STR (1 << 6) /* keyread returns converted strings */ #define HA_KEY_READ_WRONG_STR (1 << 6) /* keyread returns converted strings */
#define HA_NULL_KEY (1 << 7) /* One can have keys with NULL */ #define HA_NULL_KEY (1 << 7) /* One can have keys with NULL */
#define HA_DUPP_POS (1 << 8) /* ha_position() gives dupp row */ #define HA_DUPP_POS (1 << 8) /* ha_position() gives dupp row */
@ -256,7 +256,6 @@ public:
{ return ulonglong2double(data_file_length) / IO_SIZE + 2; } { return ulonglong2double(data_file_length) / IO_SIZE + 2; }
virtual double read_time(uint index, uint ranges, ha_rows rows) virtual double read_time(uint index, uint ranges, ha_rows rows)
{ return rows2double(ranges+rows); } { return rows2double(ranges+rows); }
virtual bool fast_key_read() { return 0;}
virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; } virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; }
virtual bool has_transactions(){ return 0;} virtual bool has_transactions(){ return 0;}
virtual uint extra_rec_buf_length() { return 0; } virtual uint extra_rec_buf_length() { return 0; }
@ -310,7 +309,7 @@ public:
{ {
return extra(operation); return extra(operation);
} }
virtual int reset()=0; virtual int reset() { return extra(HA_EXTRA_RESET); }
virtual int external_lock(THD *thd, int lock_type)=0; virtual int external_lock(THD *thd, int lock_type)=0;
virtual void unlock_row() {} virtual void unlock_row() {}
virtual int start_stmt(THD *thd) {return 0;} virtual int start_stmt(THD *thd) {return 0;}
@ -331,8 +330,10 @@ public:
*/ */
virtual int restore(THD* thd, HA_CHECK_OPT* check_opt); virtual int restore(THD* thd, HA_CHECK_OPT* check_opt);
virtual int dump(THD* thd, int fd = -1) { return ER_DUMP_NOT_IMPLEMENTED; } virtual int dump(THD* thd, int fd = -1) { return ER_DUMP_NOT_IMPLEMENTED; }
virtual void deactivate_non_unique_index(ha_rows rows) {} virtual int disable_indexes(bool all, bool save) { return HA_ERR_WRONG_COMMAND; }
virtual bool activate_all_index(THD *thd) {return 0;} virtual int enable_indexes() { return HA_ERR_WRONG_COMMAND; }
virtual void start_bulk_insert(ha_rows rows) {}
virtual int end_bulk_insert() {return 0; }
virtual int discard_or_import_tablespace(my_bool discard) {return -1;} virtual int discard_or_import_tablespace(my_bool discard) {return -1;}
// not implemented by default // not implemented by default
virtual int net_read_dump(NET* net) virtual int net_read_dump(NET* net)

View file

@ -1971,7 +1971,7 @@ bool field_is_equal_to_item(Field *field,Item *item)
item_result=item->val_str(&item_tmp); item_result=item->val_str(&item_tmp);
if (item->null_value) if (item->null_value)
return 1; // This must be true return 1; // This must be true
field->val_str(&field_tmp,&field_tmp); field->val_str(&field_tmp);
return !stringcmp(&field_tmp,item_result); return !stringcmp(&field_tmp,item_result);
} }
if (res_type == INT_RESULT) if (res_type == INT_RESULT)

View file

@ -890,7 +890,7 @@ Item_sum_hybrid::min_max_update_str_field()
if (!args[0]->null_value) if (!args[0]->null_value)
{ {
res_str->strip_sp(); res_str->strip_sp();
result_field->val_str(&tmp_value,&tmp_value); result_field->val_str(&tmp_value);
if (result_field->is_null() || if (result_field->is_null() ||
(cmp_sign * sortcmp(res_str,&tmp_value,cmp_charset)) < 0) (cmp_sign * sortcmp(res_str,&tmp_value,cmp_charset)) < 0)
@ -1601,8 +1601,7 @@ int dump_leaf_key(byte* key, uint32 count __attribute__((unused)),
Item_func_group_concat *item) Item_func_group_concat *item)
{ {
char buff[MAX_FIELD_WIDTH]; char buff[MAX_FIELD_WIDTH];
String tmp((char *)&buff,sizeof(buff),default_charset_info); String tmp((char *)&buff,sizeof(buff),default_charset_info), tmp2;
String tmp2((char *)&buff,sizeof(buff),default_charset_info);
uint *field_offsets= (item->field_offsets + uint *field_offsets= (item->field_offsets +
item->field_list_offset); item->field_list_offset);
tmp.length(0); tmp.length(0);

View file

@ -233,7 +233,7 @@ void key_unpack(String *to,TABLE *table,uint idx)
} }
if ((field=key_part->field)) if ((field=key_part->field))
{ {
field->val_str(&tmp,&tmp); field->val_str(&tmp);
if (key_part->length < field->pack_length()) if (key_part->length < field->pack_length())
tmp.length(min(tmp.length(),key_part->length)); tmp.length(min(tmp.length(),key_part->length));
to->append(tmp); to->append(tmp);

View file

@ -2968,7 +2968,7 @@ print_key(KEY_PART *key_part,const char *key,uint used_length)
((field->type() == FIELD_TYPE_BLOB) ? ((field->type() == FIELD_TYPE_BLOB) ?
HA_KEY_BLOB_LENGTH : 0), HA_KEY_BLOB_LENGTH : 0),
field->charset()); field->charset());
field->val_str(&tmp,&tmp); field->val_str(&tmp);
fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE); fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE);
} }
} }

View file

@ -822,7 +822,7 @@ bool Protocol_simple::store(Field *field)
String str(buff,sizeof(buff), &my_charset_bin); String str(buff,sizeof(buff), &my_charset_bin);
CHARSET_INFO *tocs= this->thd->variables.character_set_results; CHARSET_INFO *tocs= this->thd->variables.character_set_results;
field->val_str(&str,&str); field->val_str(&str);
if (tocs && !my_charset_same(field->charset(), tocs) && if (tocs && !my_charset_same(field->charset(), tocs) &&
(field->charset() != &my_charset_bin) && (field->charset() != &my_charset_bin) &&
(tocs != &my_charset_bin)) (tocs != &my_charset_bin))

View file

@ -80,7 +80,7 @@ void init_read_record(READ_RECORD *info,THD *thd, TABLE *table,
if (!table->sort.addon_field && if (!table->sort.addon_field &&
! (specialflag & SPECIAL_SAFE_MODE) && ! (specialflag & SPECIAL_SAFE_MODE) &&
thd->variables.read_rnd_buff_size && thd->variables.read_rnd_buff_size &&
!table->file->fast_key_read() && !(table->file->table_flags() & HA_FAST_KEY_READ) &&
(table->db_stat & HA_READ_ONLY || (table->db_stat & HA_READ_ONLY ||
table->reginfo.lock_type <= TL_READ_NO_INSERT) && table->reginfo.lock_type <= TL_READ_NO_INSERT) &&
(ulonglong) table->reclength*(table->file->records+ (ulonglong) table->reclength*(table->file->records+

View file

@ -505,7 +505,7 @@ static ulong get_access(TABLE *form, uint fieldnr)
((Field_enum*) (*pos))->typelib->count == 2 ; ((Field_enum*) (*pos))->typelib->count == 2 ;
pos++ , bit<<=1) pos++ , bit<<=1)
{ {
(*pos)->val_str(&res,&res); (*pos)->val_str(&res);
if (my_toupper(&my_charset_latin1, res[0]) == 'Y') if (my_toupper(&my_charset_latin1, res[0]) == 'Y')
access_bits|= bit; access_bits|= bit;
} }
@ -1787,7 +1787,7 @@ public:
String *res,column_name; String *res,column_name;
GRANT_COLUMN *mem_check; GRANT_COLUMN *mem_check;
/* As column name is a string, we don't have to supply a buffer */ /* As column name is a string, we don't have to supply a buffer */
res=col_privs->field[4]->val_str(&column_name,&column_name); res=col_privs->field[4]->val_str(&column_name);
ulong priv= (ulong) col_privs->field[6]->val_int(); ulong priv= (ulong) col_privs->field[6]->val_int();
if (!(mem_check = new GRANT_COLUMN(*res, if (!(mem_check = new GRANT_COLUMN(*res,
fix_rights_for_column(priv)))) fix_rights_for_column(priv))))
@ -1990,7 +1990,7 @@ static int replace_column_table(GRANT_TABLE *g_t,
privileges&= ~rights; privileges&= ~rights;
table->field[6]->store((longlong) table->field[6]->store((longlong)
get_rights_for_column(privileges)); get_rights_for_column(privileges));
table->field[4]->val_str(&column_name,&column_name); table->field[4]->val_str(&column_name);
grant_column = column_hash_search(g_t, grant_column = column_hash_search(g_t,
column_name.ptr(), column_name.ptr(),
column_name.length()); column_name.length());

View file

@ -443,7 +443,7 @@ bool close_thread_table(THD *thd, TABLE **table_ptr)
else else
{ {
// Free memory and reset for next loop // Free memory and reset for next loop
table->file->extra(HA_EXTRA_RESET); table->file->reset();
} }
table->in_use=0; table->in_use=0;
if (unused_tables) if (unused_tables)

View file

@ -270,7 +270,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
table->file->extra_opt(HA_EXTRA_WRITE_CACHE, table->file->extra_opt(HA_EXTRA_WRITE_CACHE,
min(thd->variables.read_buff_size, min(thd->variables.read_buff_size,
table->avg_row_length*values_list.elements)); table->avg_row_length*values_list.elements));
table->file->deactivate_non_unique_index(values_list.elements); table->file->start_bulk_insert(values_list.elements);
bulk_insert=1; bulk_insert=1;
} }
else else
@ -362,7 +362,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
error=1; error=1;
} }
} }
if (table->file->activate_all_index(thd)) if (table->file->end_bulk_insert())
{ {
if (!error) if (!error)
{ {
@ -1444,7 +1444,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
if (info.handle_duplicates == DUP_IGNORE || if (info.handle_duplicates == DUP_IGNORE ||
info.handle_duplicates == DUP_REPLACE) info.handle_duplicates == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
table->file->deactivate_non_unique_index((ha_rows) 0); table->file->start_bulk_insert((ha_rows) 0);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
@ -1453,7 +1453,7 @@ select_insert::~select_insert()
if (table) if (table)
{ {
table->next_number_field=0; table->next_number_field=0;
table->file->extra(HA_EXTRA_RESET); table->file->reset();
} }
thd->count_cuted_fields= CHECK_FIELD_IGNORE; thd->count_cuted_fields= CHECK_FIELD_IGNORE;
} }
@ -1498,7 +1498,7 @@ void select_insert::send_error(uint errcode,const char *err)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
table->file->extra(HA_EXTRA_NO_CACHE); table->file->extra(HA_EXTRA_NO_CACHE);
table->file->activate_all_index(thd); table->file->end_bulk_insert();
/* /*
If at least one row has been inserted/modified and will stay in the table If at least one row has been inserted/modified and will stay in the table
(the table doesn't have transactions) (example: we got a duplicate key (the table doesn't have transactions) (example: we got a duplicate key
@ -1533,7 +1533,7 @@ bool select_insert::send_eof()
DBUG_ENTER("select_insert::send_eof"); DBUG_ENTER("select_insert::send_eof");
if (!(error=table->file->extra(HA_EXTRA_NO_CACHE))) if (!(error=table->file->extra(HA_EXTRA_NO_CACHE)))
error=table->file->activate_all_index(thd); error=table->file->end_bulk_insert();
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
/* /*
@ -1618,7 +1618,7 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
if (info.handle_duplicates == DUP_IGNORE || if (info.handle_duplicates == DUP_IGNORE ||
info.handle_duplicates == DUP_REPLACE) info.handle_duplicates == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
table->file->deactivate_non_unique_index((ha_rows) 0); table->file->start_bulk_insert((ha_rows) 0);
DBUG_RETURN(0); DBUG_RETURN(0);
} }

View file

@ -283,7 +283,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
if (handle_duplicates == DUP_IGNORE || if (handle_duplicates == DUP_IGNORE ||
handle_duplicates == DUP_REPLACE) handle_duplicates == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
table->file->deactivate_non_unique_index((ha_rows) 0); table->file->start_bulk_insert((ha_rows) 0);
table->copy_blobs=1; table->copy_blobs=1;
if (!field_term->length() && !enclosed->length()) if (!field_term->length() && !enclosed->length())
error=read_fixed_length(thd,info,table,fields,read_info, error=read_fixed_length(thd,info,table,fields,read_info,
@ -293,7 +293,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
skip_lines); skip_lines);
if (table->file->extra(HA_EXTRA_NO_CACHE)) if (table->file->extra(HA_EXTRA_NO_CACHE))
error=1; /* purecov: inspected */ error=1; /* purecov: inspected */
if (table->file->activate_all_index(thd)) if (table->file->end_bulk_insert())
error=1; /* purecov: inspected */ error=1; /* purecov: inspected */
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
table->next_number_field=0; table->next_number_field=0;

View file

@ -739,7 +739,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
!field->is_null()) !field->is_null())
{ // Not null by default { // Not null by default
type.set(tmp, sizeof(tmp), field->charset()); type.set(tmp, sizeof(tmp), field->charset());
field->val_str(&type,&type); field->val_str(&type);
protocol->store(type.ptr(),type.length(),type.charset()); protocol->store(type.ptr(),type.length(),type.charset());
} }
else if (field->unireg_check == Field::NEXT_NUMBER || else if (field->unireg_check == Field::NEXT_NUMBER ||
@ -1298,7 +1298,7 @@ store_create_info(THD *thd, TABLE *table, String *packet)
else if (!field->is_null()) else if (!field->is_null())
{ // Not null by default { // Not null by default
type.set(tmp, sizeof(tmp), field->charset()); type.set(tmp, sizeof(tmp), field->charset());
field->val_str(&type,&type); field->val_str(&type);
if (type.length()) if (type.length())
{ {
String def_val; String def_val;

View file

@ -2259,22 +2259,15 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
VOID(pthread_mutex_lock(&LOCK_open)); VOID(pthread_mutex_lock(&LOCK_open));
wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN); wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
error= table->file->activate_all_index(thd); error= table->file->enable_indexes();
/* COND_refresh will be signaled in close_thread_tables() */ /* COND_refresh will be signaled in close_thread_tables() */
break; break;
case DISABLE: case DISABLE:
if (table->db_type == DB_TYPE_MYISAM)
{
VOID(pthread_mutex_lock(&LOCK_open)); VOID(pthread_mutex_lock(&LOCK_open));
wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN); wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
table->file->deactivate_non_unique_index(HA_POS_ERROR); error=table->file->disable_indexes(0, 1);
/* COND_refresh will be signaled in close_thread_tables() */ /* COND_refresh will be signaled in close_thread_tables() */
}
else
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA,
ER(ER_ILLEGAL_HA), table->table_name);
break; break;
} }
} }
@ -2289,6 +2282,11 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
} }
send_ok(thd); send_ok(thd);
} }
else
{
table->file->print_error(error, MYF(0));
error=-1;
}
table_list->table=0; // For query cache table_list->table=0; // For query cache
query_cache_invalidate3(thd, table_list, 0); query_cache_invalidate3(thd, table_list, 0);
DBUG_RETURN(error); DBUG_RETURN(error);
@ -2870,7 +2868,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
to->file->external_lock(thd,F_WRLCK); to->file->external_lock(thd,F_WRLCK);
to->file->extra(HA_EXTRA_WRITE_CACHE); to->file->extra(HA_EXTRA_WRITE_CACHE);
from->file->info(HA_STATUS_VARIABLE); from->file->info(HA_STATUS_VARIABLE);
to->file->deactivate_non_unique_index(from->file->records); to->file->start_bulk_insert(from->file->records);
List_iterator<create_field> it(create); List_iterator<create_field> it(create);
create_field *def; create_field *def;
@ -2960,7 +2958,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
error=1; error=1;
} }
to->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); to->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
if (to->file->activate_all_index(thd)) if (to->file->end_bulk_insert())
error=1; error=1;
tmp_error = ha_recovery_logging(thd,TRUE); tmp_error = ha_recovery_logging(thd,TRUE);
@ -3053,7 +3051,7 @@ int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt)
if (f->type() == FIELD_TYPE_BLOB) if (f->type() == FIELD_TYPE_BLOB)
{ {
String tmp; String tmp;
f->val_str(&tmp,&tmp); f->val_str(&tmp);
row_crc= my_checksum(row_crc, (byte*) tmp.ptr(), tmp.length()); row_crc= my_checksum(row_crc, (byte*) tmp.ptr(), tmp.length());
} }
else else

View file

@ -1229,7 +1229,7 @@ bool get_field(MEM_ROOT *mem, Field *field, String *res)
String str(buff,sizeof(buff),&my_charset_bin); String str(buff,sizeof(buff),&my_charset_bin);
uint length; uint length;
field->val_str(&str,&str); field->val_str(&str);
if (!(length= str.length())) if (!(length= str.length()))
return 1; return 1;
to= strmake_root(mem, str.ptr(), length); to= strmake_root(mem, str.ptr(), length);
@ -1257,7 +1257,7 @@ char *get_field(MEM_ROOT *mem, Field *field)
String str(buff,sizeof(buff),&my_charset_bin); String str(buff,sizeof(buff),&my_charset_bin);
uint length; uint length;
field->val_str(&str,&str); field->val_str(&str);
length= str.length(); length= str.length();
if (!length || !(to= (char*) alloc_root(mem,length+1))) if (!length || !(to= (char*) alloc_root(mem,length+1)))
return NullS; return NullS;