Commit f672d6b7 authored by Sergei Golubchik's avatar Sergei Golubchik

restore ha_example::check_if_incompatible_data(), create_info->fields_option_struct,

create_info->indexes_option_struct lost in the merge.
add test cases.
parent f4d5dacf
......@@ -130,12 +130,16 @@ t1 CREATE TABLE `t1` (
) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ULL`=10000000000000000000 `one_or_two`='ttt' `YESNO`=SSS
#alter table
alter table t1 ULL=10000000;
Warnings:
Note 1105 EXAMPLE DEBUG: ULL 4294967290 -> 10000000
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `one_or_two`='ttt' `YESNO`=SSS `ULL`=10000000
alter table t1 change a a int complex='c,c,c';
Warnings:
Note 1105 EXAMPLE DEBUG: Field `a` COMPLEX '(null)' -> 'c,c,c'
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
......@@ -160,6 +164,8 @@ select create_options from information_schema.tables where table_schema='test' a
create_options
`ULL`=4660
ALTER TABLE t1 ULL=DEFAULT;
Warnings:
Note 1105 EXAMPLE DEBUG: ULL 4660 -> 4294967295
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
......
......@@ -5422,6 +5422,9 @@ static bool fill_alter_inplace_info(THD *thd,
if (new_field)
{
ha_alter_info->create_info->fields_option_struct[f_ptr - table->field]=
new_field->option_struct;
/* Field is not dropped. Evaluate changes bitmap for it. */
/*
......@@ -5661,6 +5664,9 @@ static bool fill_alter_inplace_info(THD *thd,
new_key - ha_alter_info->key_info_buffer;
DBUG_PRINT("info", ("index added: '%s'", new_key->name));
}
else
ha_alter_info->create_info->indexes_option_struct[table_key - table->key_info]=
new_key->option_struct;
}
/*
......@@ -6535,8 +6541,15 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
restore_record(table, s->default_values); // Empty record for DEFAULT
if ((create_info->fields_option_struct= (ha_field_option_struct**)
thd->calloc(sizeof(void*) * table->s->fields)) == NULL ||
(create_info->indexes_option_struct= (ha_index_option_struct**)
thd->calloc(sizeof(void*) * table->s->keys)) == NULL)
DBUG_RETURN(1);
create_info->option_list= merge_engine_table_options(table->s->option_list,
create_info->option_list, thd->mem_root);
/*
First collect all fields from table which isn't in drop_list
*/
......
......@@ -899,6 +899,89 @@ int ha_example::create(const char *name, TABLE *table_arg,
}
/**
check_if_incompatible_data() called if ALTER TABLE can't detect otherwise
if new and old definition are compatible
@details If there are no other explicit signs like changed number of
fields this function will be called by compare_tables()
(sql/sql_tables.cc) to decide should we rewrite whole table or only .frm
file.
*/
bool ha_example::check_if_incompatible_data(HA_CREATE_INFO *info,
uint table_changes)
{
ha_table_option_struct *param_old, *param_new;
DBUG_ENTER("ha_example::check_if_incompatible_data");
/*
This example shows how custom engine specific table and field
options can be accessed from this function to be compared.
*/
param_new= info->option_struct;
DBUG_PRINT("info", ("new strparam: '%-.64s' ullparam: %llu enumparam: %u "
"boolparam: %u",
(param_new->strparam ? param_new->strparam : "<NULL>"),
param_new->ullparam, param_new->enumparam,
param_new->boolparam));
param_old= table->s->option_struct;
DBUG_PRINT("info", ("old strparam: '%-.64s' ullparam: %llu enumparam: %u "
"boolparam: %u",
(param_old->strparam ? param_old->strparam : "<NULL>"),
param_old->ullparam, param_old->enumparam,
param_old->boolparam));
/*
check important parameters:
for this example engine, we'll assume that changing ullparam or
boolparam requires a table to be rebuilt, while changing strparam
or enumparam - does not.
For debugging purposes we'll announce this to the client
(don't do it in your engine!)
*/
if (param_new->ullparam != param_old->ullparam)
{
push_warning_printf(ha_thd(), Sql_condition::WARN_LEVEL_NOTE,
ER_UNKNOWN_ERROR, "EXAMPLE DEBUG: ULL %llu -> %llu",
param_old->ullparam, param_new->ullparam);
DBUG_RETURN(COMPATIBLE_DATA_NO);
}
if (param_new->boolparam != param_old->boolparam)
{
push_warning_printf(ha_thd(), Sql_condition::WARN_LEVEL_NOTE,
ER_UNKNOWN_ERROR, "EXAMPLE DEBUG: YESNO %u -> %u",
param_old->boolparam, param_new->boolparam);
DBUG_RETURN(COMPATIBLE_DATA_NO);
}
#ifndef DBUG_OFF
for (uint i= 0; i < table->s->fields; i++)
{
ha_field_option_struct *f_old, *f_new;
f_old= table->s->field[i]->option_struct;
DBUG_ASSERT(f_old);
if (info->fields_option_struct[i])
{
f_new= info->fields_option_struct[i];
push_warning_printf(ha_thd(), Sql_condition::WARN_LEVEL_NOTE,
ER_UNKNOWN_ERROR, "EXAMPLE DEBUG: Field %`s COMPLEX '%s' -> '%s'",
table->s->field[i]->field_name,
f_old->complex_param_to_parse_it_in_engine,
f_new->complex_param_to_parse_it_in_engine);
}
else
DBUG_PRINT("info", ("old field %i did not changed", i));
}
#endif
DBUG_RETURN(COMPATIBLE_DATA_YES);
}
struct st_mysql_storage_engine example_storage_engine=
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
......
......@@ -252,6 +252,8 @@ class ha_example: public handler
int delete_table(const char *from);
int create(const char *name, TABLE *form,
HA_CREATE_INFO *create_info); ///< required
bool check_if_incompatible_data(HA_CREATE_INFO *info,
uint table_changes);
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
enum thr_lock_type lock_type); ///< required
......
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