Commit c3039e80 authored by serg@serg.mysql.com's avatar serg@serg.mysql.com

ALTER TABLE ... DISABLE/ENABLE KEYS, code cleanup

parent f2dee22a
......@@ -198,7 +198,7 @@ FT_DOCLIST *ft_boolean_search(MI_INFO *info, uint keynr, byte *query,
aio.end=query+query_len;
aio.total_yes=aio.total_no=0;
init_tree(&aio.dtree,0,sizeof(FT_SUPERDOC),(qsort_cmp)&FT_SUPERDOC_cmp,0,
init_tree(&aio.dtree,0,sizeof(FT_SUPERDOC),(qsort_cmp2)&FT_SUPERDOC_cmp,0,
NULL);
if (do_boolean(&aio,0,0,0,0))
......
......@@ -219,9 +219,17 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function)
}
if (share->state.key_map)
{
share->state.key_map=0;
info->state->key_file_length=share->state.state.key_file_length=
share->base.keystart;
MI_KEYDEF *key=share->keyinfo;
uint i;
for (i=0 ; i < share->base.keys ; i++,key++)
{
if (!(key->flag & HA_NOSAME) && info->s->base.auto_key != i+1)
{
share->state.key_map&= ~ ((ulonglong) 1 << i);
info->update|= HA_STATE_CHANGED;
}
}
if (!share->changed)
{
share->state.changed|= STATE_CHANGED | STATE_NOT_ANALYZED;
......
......@@ -331,7 +331,7 @@ static int examine_log(my_string file_name, char **table_names)
init_io_cache(&cache,file,0,READ_CACHE,start_offset,0,MYF(0));
bzero((gptr) com_count,sizeof(com_count));
init_tree(&tree,0,sizeof(file_info),(qsort_cmp) file_info_compare,1,
init_tree(&tree,0,sizeof(file_info),(qsort_cmp2) file_info_compare,1,
(void(*)(void*)) file_info_free);
VOID(init_key_cache(KEY_CACHE_SIZE,(uint) (10*4*(IO_SIZE+MALLOC_OVERHEAD))));
......
......@@ -637,8 +637,18 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
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)
mi_extra(file, HA_EXTRA_NO_KEYS);
else
mi_disable_non_unique_index(file,rows);
enable_activate_all_index=1;
}
else
enable_activate_all_index=0;
}
......@@ -648,7 +658,8 @@ bool ha_myisam::activate_all_index(THD *thd)
MI_CHECK param;
MYISAM_SHARE* share = file->s;
DBUG_ENTER("activate_all_index");
if (share->state.key_map != ((ulonglong) 1L << share->base.keys)-1)
if (enable_activate_all_index &&
share->state.key_map != ((ulonglong) 1L << share->base.keys)-1)
{
const char *save_proc_info=thd->proc_info;
thd->proc_info="Creating index";
......@@ -663,6 +674,8 @@ bool ha_myisam::activate_all_index(THD *thd)
error=repair(thd,param,0) != HA_ADMIN_OK;
thd->proc_info=save_proc_info;
}
else
enable_activate_all_index=1;
DBUG_RETURN(error);
}
......
......@@ -37,11 +37,11 @@ extern ulong myisam_recover_options;
class ha_myisam: public handler
{
MI_INFO *file;
uint int_option_flag;
uint int_option_flag,enable_activate_all_index;
int repair(THD *thd, MI_CHECK &param, bool optimize);
public:
ha_myisam(TABLE *table): handler(table), file(0),
ha_myisam(TABLE *table): handler(table), file(0),enable_activate_all_index(1),
int_option_flag(HA_READ_NEXT | HA_READ_PREV | HA_READ_RND_SAME |
HA_KEYPOS_TO_RNDPOS | HA_READ_ORDER | HA_LASTKEY_ORDER |
HA_HAVE_KEY_READ_ONLY | HA_READ_NOT_EXACT_KEY |
......
......@@ -1189,9 +1189,11 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
switch (keys_onoff)
{
case LEAVE_AS_IS: break;
case ENABLE: error=table->file->activate_all_index(thd); break;
case ENABLE:
error=table->file->activate_all_index(thd);
break;
case DISABLE:
table->file->deactivate_non_unique_index(table->file->records);
table->file->deactivate_non_unique_index(HA_POS_ERROR);
break;
}
}
......
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