summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-07-12 11:36:54 +0200
committerSergei Golubchik <sergii@pisem.net>2013-07-12 11:36:54 +0200
commitf672d6b7d8b2a2f4570d5407481b3cdaaaa44e43 (patch)
tree4a3c22abc592aadf4437de7bfbe3ef79de6e8ae2
parentf4d5dacf43ef180de11aab20fcbc0cb2629f2dc2 (diff)
downloadmariadb-git-f672d6b7d8b2a2f4570d5407481b3cdaaaa44e43.tar.gz
restore ha_example::check_if_incompatible_data(), create_info->fields_option_struct,
create_info->indexes_option_struct lost in the merge. add test cases.
-rw-r--r--mysql-test/r/plugin.result6
-rw-r--r--sql/sql_table.cc13
-rw-r--r--storage/example/ha_example.cc83
-rw-r--r--storage/example/ha_example.h2
4 files changed, 104 insertions, 0 deletions
diff --git a/mysql-test/r/plugin.result b/mysql-test/r/plugin.result
index 2c9c3d4946d..23e9315feed 100644
--- a/mysql-test/r/plugin.result
+++ b/mysql-test/r/plugin.result
@@ -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` (
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 4d39fded1b6..4b0e0205eb7 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -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
*/
diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc
index b37845bf9ec..ac36f0bc864 100644
--- a/storage/example/ha_example.cc
+++ b/storage/example/ha_example.cc
@@ -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 };
diff --git a/storage/example/ha_example.h b/storage/example/ha_example.h
index 361e4b3a848..5a66d15e54f 100644
--- a/storage/example/ha_example.h
+++ b/storage/example/ha_example.h
@@ -252,6 +252,8 @@ public:
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