Commit 1b61cb6d authored by vva@eagle.mysql.r18.ru's avatar vva@eagle.mysql.r18.ru

Merge vvagin@bk-internal.mysql.com:/home/bk/mysql-4.1

into eagle.mysql.r18.ru:/home/vva/work/TASK_ALTER_INFO/mysql-4.1
parents 1acbfeaf e2488c03
......@@ -519,13 +519,10 @@ int mysql_alter_table(THD *thd, char *new_db, char *new_name,
HA_CREATE_INFO *create_info,
TABLE_LIST *table_list,
List<create_field> &fields,
List<Key> &keys,List<Alter_drop> &drop_list,
List<Alter_column> &alter_list,
uint order_num, ORDER *order, uint alter_flags,
List<Key> &keys,
uint order_num, ORDER *order,
enum enum_duplicates handle_duplicates,
enum enum_enable_or_disable keys_onoff=LEAVE_AS_IS,
enum tablespace_op_type tablespace_op=NO_TABLESPACE_OP,
bool simple_alter=0);
ALTER_INFO *alter_info);
int mysql_create_like_table(THD *thd, TABLE_LIST *table,
HA_CREATE_INFO *create_info,
Table_ident *src_table);
......@@ -536,7 +533,7 @@ bool mysql_rename_table(enum db_type base,
const char * new_name);
int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys);
int mysql_drop_index(THD *thd, TABLE_LIST *table_list,
List<Alter_drop> &drop_list);
ALTER_INFO *alter_info);
int mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
TABLE_LIST *update_table_list,
Item **conds, uint order_num, ORDER *order);
......
......@@ -532,6 +532,20 @@ typedef class st_select_lex SELECT_LEX;
#define ALTER_ORDER 64
#define ALTER_OPTIONS 128
typedef struct st_alter_info
{
List<Alter_drop> drop_list;
List<Alter_column> alter_list;
uint flags;
enum enum_enable_or_disable keys_onoff;
enum tablespace_op_type tablespace_op;
bool is_simple;
st_alter_info(){clear();}
void clear(){keys_onoff= LEAVE_AS_IS;tablespace_op= NO_TABLESPACE_OP;}
void reset(){drop_list.empty();alter_list.empty();clear();}
} ALTER_INFO;
/* The state of the lex parsing. This is saved in the THD struct */
typedef struct st_lex
......@@ -564,8 +578,6 @@ typedef struct st_lex
List<key_part_spec> col_list;
List<key_part_spec> ref_list;
List<Alter_drop> drop_list;
List<Alter_column> alter_list;
List<String> interval_list;
List<LEX_USER> users_list;
List<LEX_COLUMN> columns;
......@@ -593,19 +605,17 @@ typedef struct st_lex
enum enum_tx_isolation tx_isolation;
enum enum_ha_read_modes ha_read_mode;
enum ha_rkey_function ha_rkey_mode;
enum enum_enable_or_disable alter_keys_onoff;
enum enum_var_type option_type;
enum tablespace_op_type tablespace_op;
uint uint_geom_type;
uint grant, grant_tot_col, which_columns;
uint fk_delete_opt, fk_update_opt, fk_match_option;
uint slave_thd_opt;
uint alter_flags;
uint8 describe;
bool drop_if_exists, drop_temporary, local_file;
bool in_comment, ignore_space, verbose, simple_alter, no_write_to_binlog;
bool in_comment, ignore_space, verbose, no_write_to_binlog;
bool derived_tables;
bool safe_to_cache_query;
ALTER_INFO alter_info;
st_lex() {}
inline void uncacheable(uint8 cause)
{
......
......@@ -2368,14 +2368,10 @@ unsent_create_error:
res= mysql_alter_table(thd, select_lex->db, lex->name,
&lex->create_info,
tables, lex->create_list,
lex->key_list, lex->drop_list, lex->alter_list,
lex->key_list,
select_lex->order_list.elements,
(ORDER *) select_lex->order_list.first,
lex->alter_flags,
lex->duplicates,
lex->alter_keys_onoff,
lex->tablespace_op,
lex->simple_alter);
lex->duplicates, &lex->alter_info);
}
break;
}
......@@ -2514,17 +2510,15 @@ unsent_create_error:
lex->create_list.empty();
lex->key_list.empty();
lex->col_list.empty();
lex->drop_list.empty();
lex->alter_list.empty();
lex->alter_info.reset();
bzero((char*) &create_info,sizeof(create_info));
create_info.db_type=DB_TYPE_DEFAULT;
create_info.row_type=ROW_TYPE_DEFAULT;
create_info.default_table_charset=default_charset_info;
res= mysql_alter_table(thd, NullS, NullS, &create_info,
tables, lex->create_list,
lex->key_list, lex->drop_list, lex->alter_list,
0, (ORDER *) 0, 0,
DUP_ERROR);
lex->key_list, 0, (ORDER *) 0,
DUP_ERROR, &lex->alter_info);
}
else
res = mysql_optimize_table(thd, tables, &lex->check_opt);
......@@ -2754,7 +2748,7 @@ unsent_create_error:
if (end_active_trans(thd))
res= -1;
else
res = mysql_drop_index(thd, tables, lex->drop_list);
res = mysql_drop_index(thd, tables, &lex->alter_info);
break;
case SQLCOM_SHOW_DATABASES:
#if defined(DONT_ALLOW_SHOW_COMMANDS)
......@@ -4903,8 +4897,9 @@ Item * all_any_subquery_creator(Item *left_expr,
int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
{
List<create_field> fields;
List<Alter_drop> drop;
List<Alter_column> alter;
ALTER_INFO alter_info;
alter_info.flags= ALTER_ADD_INDEX;
alter_info.is_simple= 0;
HA_CREATE_INFO create_info;
DBUG_ENTER("mysql_create_index");
bzero((char*) &create_info,sizeof(create_info));
......@@ -4912,25 +4907,27 @@ int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
create_info.default_table_charset= thd->variables.collation_database;
DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
&create_info, table_list,
fields, keys, drop, alter, 0, (ORDER*)0,
ALTER_ADD_INDEX, DUP_ERROR));
fields, keys, 0, (ORDER*)0,
DUP_ERROR, &alter_info));
}
int mysql_drop_index(THD *thd, TABLE_LIST *table_list, List<Alter_drop> &drop)
int mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info)
{
List<create_field> fields;
List<Key> keys;
List<Alter_column> alter;
HA_CREATE_INFO create_info;
DBUG_ENTER("mysql_drop_index");
bzero((char*) &create_info,sizeof(create_info));
create_info.db_type=DB_TYPE_DEFAULT;
create_info.default_table_charset= thd->variables.collation_database;
alter_info->clear();
alter_info->flags= ALTER_DROP_INDEX;
alter_info->is_simple= 0;
DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
&create_info, table_list,
fields, keys, drop, alter, 0, (ORDER*)0,
ALTER_DROP_INDEX, DUP_ERROR));
fields, keys, 0, (ORDER*)0,
DUP_ERROR, alter_info));
}
......
......@@ -2467,14 +2467,10 @@ int mysql_drop_indexes(THD *thd, TABLE_LIST *table_list,
int mysql_alter_table(THD *thd,char *new_db, char *new_name,
HA_CREATE_INFO *create_info,
TABLE_LIST *table_list,
List<create_field> &fields,
List<Key> &keys,List<Alter_drop> &drop_list,
List<Alter_column> &alter_list,
uint order_num, ORDER *order, uint alter_flags,
List<create_field> &fields, List<Key> &keys,
uint order_num, ORDER *order,
enum enum_duplicates handle_duplicates,
enum enum_enable_or_disable keys_onoff,
enum tablespace_op_type tablespace_op,
bool simple_alter)
ALTER_INFO *alter_info)
{
TABLE *table,*new_table;
int error;
......@@ -2499,9 +2495,9 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
mysql_ha_closeall(thd, table_list);
/* DISCARD/IMPORT TABLESPACE is always alone in an ALTER TABLE */
if (tablespace_op != NO_TABLESPACE_OP)
if (alter_info->tablespace_op != NO_TABLESPACE_OP)
DBUG_RETURN(mysql_discard_or_import_tablespace(thd,table_list,
tablespace_op));
alter_info->tablespace_op));
if (!(table=open_ltable(thd,table_list,TL_WRITE_ALLOW_READ)))
DBUG_RETURN(-1);
......@@ -2570,7 +2566,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
create_info->row_type=table->row_type;
thd->proc_info="setup";
if (simple_alter && !table->tmp_table)
if (alter_info->is_simple && !table->tmp_table)
{
error=0;
if (new_name != table_name || new_db != db)
......@@ -2596,7 +2592,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (!error)
{
switch (keys_onoff) {
switch (alter_info->keys_onoff) {
case LEAVE_AS_IS:
break;
case ENABLE:
......@@ -2656,9 +2652,9 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
create_info->default_table_charset= table->table_charset;
restore_record(table,default_values); // Empty record for DEFAULT
List_iterator<Alter_drop> drop_it(drop_list);
List_iterator<Alter_drop> drop_it(alter_info->drop_list);
List_iterator<create_field> def_it(fields);
List_iterator<Alter_column> alter_it(alter_list);
List_iterator<Alter_column> alter_it(alter_info->alter_list);
List<create_field> create_list; // Add new fields here
List<Key> key_list; // Add new keys here
create_field *def;
......@@ -2762,9 +2758,10 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
find_it.after(def); // Put element after this
}
}
if (alter_list.elements)
if (alter_info->alter_list.elements)
{
my_error(ER_BAD_FIELD_ERROR,MYF(0),alter_list.head()->name,table_name);
my_error(ER_BAD_FIELD_ERROR,MYF(0),alter_info->alter_list.head()->name,
table_name);
DBUG_RETURN(-1);
}
if (!create_list.elements)
......@@ -2864,14 +2861,16 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
}
if (drop_list.elements)
if (alter_info->drop_list.elements)
{
my_error(ER_CANT_DROP_FIELD_OR_KEY,MYF(0),drop_list.head()->name);
my_error(ER_CANT_DROP_FIELD_OR_KEY,MYF(0),
alter_info->drop_list.head()->name);
goto err;
}
if (alter_list.elements)
if (alter_info->alter_list.elements)
{
my_error(ER_CANT_DROP_FIELD_OR_KEY,MYF(0),alter_list.head()->name);
my_error(ER_CANT_DROP_FIELD_OR_KEY,MYF(0),
alter_info->alter_list.head()->name);
goto err;
}
......
......@@ -1455,25 +1455,25 @@ attribute:
{
LEX *lex=Lex;
lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
lex->alter_flags|= ALTER_ADD_INDEX;
lex->alter_info.flags|= ALTER_ADD_INDEX;
}
| opt_primary KEY_SYM
{
LEX *lex=Lex;
lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
lex->alter_flags|= ALTER_ADD_INDEX;
lex->alter_info.flags|= ALTER_ADD_INDEX;
}
| UNIQUE_SYM
{
LEX *lex=Lex;
lex->type|= UNIQUE_FLAG;
lex->alter_flags|= ALTER_ADD_INDEX;
lex->alter_info.flags|= ALTER_ADD_INDEX;
}
| UNIQUE_SYM KEY_SYM
{
LEX *lex=Lex;
lex->type|= UNIQUE_KEY_FLAG;
lex->alter_flags|= ALTER_ADD_INDEX;
lex->alter_info.flags|= ALTER_ADD_INDEX;
}
| COMMENT_SYM TEXT_STRING_sys { Lex->comment= &$2; }
| BINARY { Lex->type|= BINCMP_FLAG; }
......@@ -1721,18 +1721,15 @@ alter:
lex->create_list.empty();
lex->key_list.empty();
lex->col_list.empty();
lex->drop_list.empty();
lex->alter_list.empty();
lex->select_lex.init_order();
lex->select_lex.db=lex->name=0;
bzero((char*) &lex->create_info,sizeof(lex->create_info));
lex->create_info.db_type= DB_TYPE_DEFAULT;
lex->create_info.default_table_charset= thd->variables.collation_database;
lex->create_info.row_type= ROW_TYPE_NOT_USED;
lex->alter_keys_onoff=LEAVE_AS_IS;
lex->tablespace_op=NO_TABLESPACE_OP;
lex->simple_alter=1;
lex->alter_flags=0;
lex->alter_info.clear();
lex->alter_info.is_simple= 1;
lex->alter_info.flags= 0;
}
alter_list
{}
......@@ -1745,8 +1742,8 @@ alter:
alter_list:
| DISCARD TABLESPACE { Lex->tablespace_op=DISCARD_TABLESPACE; }
| IMPORT TABLESPACE { Lex->tablespace_op=IMPORT_TABLESPACE; }
| DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
| IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
| alter_list_item
| alter_list ',' alter_list_item;
......@@ -1755,24 +1752,24 @@ add_column:
{
LEX *lex=Lex;
lex->change=0;
lex->alter_flags|= ALTER_ADD_COLUMN;
lex->alter_info.flags|= ALTER_ADD_COLUMN;
};
alter_list_item:
add_column column_def opt_place { Lex->simple_alter=0; }
add_column column_def opt_place { Lex->alter_info.is_simple= 0; }
| ADD key_def
{
LEX *lex=Lex;
lex->simple_alter=0;
lex->alter_flags|= ALTER_ADD_INDEX;
lex->alter_info.is_simple= 0;
lex->alter_info.flags|= ALTER_ADD_INDEX;
}
| add_column '(' field_list ')' { Lex->simple_alter=0; }
| add_column '(' field_list ')' { Lex->alter_info.is_simple= 0; }
| CHANGE opt_column field_ident
{
LEX *lex=Lex;
lex->change= $3.str;
lex->simple_alter=0;
lex->alter_flags|= ALTER_CHANGE_COLUMN;
lex->alter_info.is_simple= 0;
lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
}
field_spec opt_place
| MODIFY_SYM opt_column field_ident
......@@ -1782,8 +1779,8 @@ alter_list_item:
lex->default_value= lex->on_update_value= 0;
lex->comment=0;
lex->charset= NULL;
lex->simple_alter=0;
lex->alter_flags|= ALTER_CHANGE_COLUMN;
lex->alter_info.is_simple= 0;
lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
}
type opt_attribute
{
......@@ -1801,50 +1798,51 @@ alter_list_item:
| DROP opt_column field_ident opt_restrict
{
LEX *lex=Lex;
lex->drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
$3.str));
lex->simple_alter=0;
lex->alter_flags|= ALTER_DROP_COLUMN;
lex->alter_info.is_simple= 0;
lex->alter_info.flags|= ALTER_DROP_COLUMN;
}
| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
| DROP FOREIGN KEY_SYM opt_ident { Lex->alter_info.is_simple= 0; }
| DROP PRIMARY_SYM KEY_SYM
{
LEX *lex=Lex;
lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
primary_key_name));
lex->simple_alter=0;
lex->alter_flags|= ALTER_DROP_INDEX;
lex->alter_info.is_simple= 0;
lex->alter_info.flags|= ALTER_DROP_INDEX;
}
| DROP key_or_index field_ident
{
LEX *lex=Lex;
lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
$3.str));
lex->simple_alter=0;
lex->alter_flags|= ALTER_DROP_INDEX;
lex->alter_info.is_simple= 0;
lex->alter_info.flags|= ALTER_DROP_INDEX;
}
| DISABLE_SYM KEYS { Lex->alter_keys_onoff=DISABLE; }
| ENABLE_SYM KEYS { Lex->alter_keys_onoff=ENABLE; }
| DISABLE_SYM KEYS { Lex->alter_info.keys_onoff= DISABLE; }
| ENABLE_SYM KEYS { Lex->alter_info.keys_onoff= ENABLE; }
| ALTER opt_column field_ident SET DEFAULT signed_literal
{
LEX *lex=Lex;
lex->alter_list.push_back(new Alter_column($3.str,$6));
lex->simple_alter=0;
lex->alter_flags|= ALTER_CHANGE_COLUMN;
lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
lex->alter_info.is_simple= 0;
lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
}
| ALTER opt_column field_ident DROP DEFAULT
{
LEX *lex=Lex;
lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
lex->simple_alter=0;
lex->alter_flags|= ALTER_CHANGE_COLUMN;
lex->alter_info.alter_list.push_back(new Alter_column($3.str,
(Item*) 0));
lex->alter_info.is_simple= 0;
lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
}
| RENAME opt_to table_ident
{
LEX *lex=Lex;
lex->select_lex.db=$3->db.str;
lex->name= $3->table.str;
lex->alter_flags|= ALTER_RENAME;
lex->alter_info.flags|= ALTER_RENAME;
}
| CONVERT_SYM TO_SYM charset charset_name_or_default opt_collate
{
......@@ -1865,19 +1863,19 @@ alter_list_item:
lex->create_info.default_table_charset= $5;
lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
HA_CREATE_USED_DEFAULT_CHARSET);
lex->simple_alter= 0;
lex->alter_info.is_simple= 0;
}
| create_table_options_space_separated
{
LEX *lex=Lex;
lex->simple_alter=0;
lex->alter_flags|= ALTER_OPTIONS;
lex->alter_info.is_simple= 0;
lex->alter_info.flags|= ALTER_OPTIONS;
}
| order_clause
{
LEX *lex=Lex;
lex->simple_alter=0;
lex->alter_flags|= ALTER_ORDER;
lex->alter_info.is_simple= 0;
lex->alter_info.flags|= ALTER_ORDER;
};
opt_column:
......@@ -3776,8 +3774,8 @@ drop:
{
LEX *lex=Lex;
lex->sql_command= SQLCOM_DROP_INDEX;
lex->drop_list.empty();
lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
lex->alter_info.drop_list.empty();
lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
$3.str));
if (!lex->current_select->add_table_to_list(lex->thd, $5, NULL,
TL_OPTION_UPDATING))
......
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