From 95d61f64d8a8b7cb329627e9853e9ee3540d0316 Mon Sep 17 00:00:00 2001 From: "mskold@mysql.com" <> Date: Tue, 13 Jun 2006 16:44:30 +0200 Subject: [PATCH 1/4] Fixed incorrect handling of renamed fields, forcing copy of table if needed and added optional system variable ndb_use_copying_alter_table --- sql/ha_ndbcluster.cc | 11 +++++++++++ sql/mysqld.cc | 7 +++++++ sql/set_var.cc | 4 ++++ sql/sql_class.h | 1 + 4 files changed, 23 insertions(+) diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 94fb7e6eb5c..b3ff91cb823 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -9824,10 +9824,21 @@ bool ha_ndbcluster::check_if_incompatible_data(HA_CREATE_INFO *info, uint i; const NDBTAB *tab= (const NDBTAB *) m_table; + if (current_thd->variables.ndb_use_copying_alter_table) + { + DBUG_PRINT("info", ("On-line alter table disabled")); + DBUG_RETURN(COMPATIBLE_DATA_NO); + } + for (i= 0; i < table->s->fields; i++) { Field *field= table->field[i]; const NDBCOL *col= tab->getColumn(field->field_name); + if (!col) + { + DBUG_PRINT("info", ("Field has been renamed, copy table")); + DBUG_RETURN(COMPATIBLE_DATA_NO); + } if ((field->flags & FIELD_IN_ADD_INDEX) && col->getStorageType() == NdbDictionary::Column::StorageTypeDisk) { diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 56c3b1857a8..1a576616966 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4695,6 +4695,7 @@ enum options_mysqld OPT_NDB_EXTRA_LOGGING, OPT_NDB_REPORT_THRESH_BINLOG_EPOCH_SLIP, OPT_NDB_REPORT_THRESH_BINLOG_MEM_USAGE, + OPT_NDB_USE_COPYING_ALTER_TABLE, OPT_SKIP_SAFEMALLOC, OPT_TEMP_POOL, OPT_TX_ISOLATION, OPT_COMPLETION_TYPE, OPT_SKIP_STACK_TRACE, OPT_SKIP_SYMLINKS, @@ -5430,6 +5431,12 @@ Disable with --skip-ndbcluster (will save memory).", (gptr*) &max_system_variables.ndb_index_stat_update_freq, 0, GET_ULONG, OPT_ARG, 20, 0, ~0L, 0, 0, 0}, #endif + {"nb-use-copying-alter-table", + OPT_NDB_USE_COPYING_ALTER_TABLE, + "Force ndbcluster to always copy tables at alter table (used for ensuring that operations such as renaming fields are propagated to ndb data dictionary).", + (gptr*) &global_system_variables.ndb_use_copying_alter_table, + (gptr*) &global_system_variables.ndb_use_copying_alter_table, + 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"new", 'n', "Use very new possible 'unsafe' functions.", (gptr*) &global_system_variables.new_mode, (gptr*) &max_system_variables.new_mode, diff --git a/sql/set_var.cc b/sql/set_var.cc index 53b4b395c37..a44395c74ca 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -548,6 +548,8 @@ sys_ndb_index_stat_update_freq("ndb_index_stat_update_freq", &SV::ndb_index_stat_update_freq); sys_var_long_ptr sys_ndb_extra_logging("ndb_extra_logging", &ndb_extra_logging); +sys_var_thd_bool +sys_ndb_use_copying_alter_table("ndb_use_copying_alter_table", &SV::ndb_use_copying_alter_table); /* Time/date/datetime formats */ @@ -917,6 +919,8 @@ SHOW_VAR init_vars[]= { {sys_ndb_report_thresh_binlog_mem_usage.name, (char*) &sys_ndb_report_thresh_binlog_mem_usage, SHOW_SYS}, #endif + {sys_ndb_use_copying_alter_table.name, + (char*) &sys_ndb_use_copying_alter_table, SHOW_SYS}, {sys_ndb_use_exact_count.name,(char*) &sys_ndb_use_exact_count, SHOW_SYS}, {sys_ndb_use_transactions.name,(char*) &sys_ndb_use_transactions, SHOW_SYS}, {sys_net_buffer_length.name,(char*) &sys_net_buffer_length, SHOW_SYS}, diff --git a/sql/sql_class.h b/sql/sql_class.h index 03a8439db58..450a8d041c9 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -244,6 +244,7 @@ struct system_variables my_bool innodb_table_locks; my_bool innodb_support_xa; my_bool ndb_force_send; + my_bool ndb_use_copying_alter_table; my_bool ndb_use_exact_count; my_bool ndb_use_transactions; my_bool ndb_index_stat_enable; From a6ebed7cea2194268f24a2440ebba7bd2588ed43 Mon Sep 17 00:00:00 2001 From: "mskold@mysql.com" <> Date: Wed, 14 Jun 2006 11:08:36 +0200 Subject: [PATCH 2/4] Added flag to detect renaming of fields (not supported as fast alter table for ndbcluster) --- include/mysql_com.h | 1 + sql/ha_ndbcluster.cc | 4 ++-- sql/sql_table.cc | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/mysql_com.h b/include/mysql_com.h index 623aaf43783..c65f5944747 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -99,6 +99,7 @@ enum enum_server_command #define GET_FIXED_FIELDS_FLAG (1 << 18) /* Used to get fields in item tree */ #define FIELD_IN_PART_FUNC_FLAG (1 << 19)/* Field part of partition func */ #define FIELD_IN_ADD_INDEX (1<< 20) /* Intern: Field used in ADD INDEX */ +#define FIELD_IS_RENAMED (1<< 21) /* Intern: Field is being renamed */ #define REFRESH_GRANT 1 /* Refresh grant tables */ #define REFRESH_LOG 2 /* Start on new log file */ diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index b3ff91cb823..e07c696d46e 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -9833,8 +9833,8 @@ bool ha_ndbcluster::check_if_incompatible_data(HA_CREATE_INFO *info, for (i= 0; i < table->s->fields; i++) { Field *field= table->field[i]; - const NDBCOL *col= tab->getColumn(field->field_name); - if (!col) + const NDBCOL *col= tab->getColumn(i); + if (field->flags & FIELD_IS_RENAMED) { DBUG_PRINT("info", ("Field has been renamed, copy table")); DBUG_RETURN(COMPATIBLE_DATA_NO); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index e9c89b4983d..c0db7120b86 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4744,6 +4744,11 @@ static uint compare_tables(TABLE *table, List *create_list, create_info->row_type != ROW_TYPE_FIXED) create_info->table_options|= HA_OPTION_PACK_RECORD; + /* Check if field was renamed */ + if (my_strcasecmp(system_charset_info, + field->field_name, + new_field->field_name)) + field->flags|= FIELD_IS_RENAMED; /* Evaluate changes bitmap and send to check_if_incompatible_data() */ if (!(tmp= field->is_equal(new_field))) DBUG_RETURN(ALTER_TABLE_DATA_CHANGED); From de28afe25b2c470a7bfe75e79edb10fd2c6b1722 Mon Sep 17 00:00:00 2001 From: "mskold@mysql.com" <> Date: Wed, 14 Jun 2006 11:38:55 +0200 Subject: [PATCH 3/4] Added flag to detect renaming of fields (not supported as fast alter table for ndbcluster): added test case --- mysql-test/r/ndb_alter_table.result | 7 ++++++- mysql-test/t/ndb_alter_table.test | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/ndb_alter_table.result b/mysql-test/r/ndb_alter_table.result index e506973f347..7facb5fa286 100644 --- a/mysql-test/r/ndb_alter_table.result +++ b/mysql-test/r/ndb_alter_table.result @@ -320,8 +320,13 @@ LOAD DATA INFILE 'tmp.dat' INTO TABLE ndb_show_tables; set @t1_id = (select id from ndb_show_tables where name like '%t1%'); truncate ndb_show_tables; alter table t1 change tiny new_tiny tinyint(4) DEFAULT '0' NOT NULL; +LOAD DATA INFILE 'tmp.dat' INTO TABLE ndb_show_tables; +select 'no_copy' from ndb_show_tables where id = @t1_id and name like '%t1%'; +no_copy +set @t1_id = (select id from ndb_show_tables where name like '%t1%'); +truncate ndb_show_tables; create index i1 on t1(medium); -alter table t1 add index i2(long_int); +alter table t1 add index i2(new_tiny); drop index i1 on t1; LOAD DATA INFILE 'tmp.dat' INTO TABLE ndb_show_tables; select 'no_copy' from ndb_show_tables where id = @t1_id and name like '%t1%'; diff --git a/mysql-test/t/ndb_alter_table.test b/mysql-test/t/ndb_alter_table.test index 8e3b4a6ca89..73c612b203f 100644 --- a/mysql-test/t/ndb_alter_table.test +++ b/mysql-test/t/ndb_alter_table.test @@ -367,12 +367,23 @@ CREATE TEMPORARY TABLE ndb_show_tables (id INT, type VARCHAR(20), state VARCHAR( LOAD DATA INFILE 'tmp.dat' INTO TABLE ndb_show_tables; --enable_warnings +# Ndb doesn't support renaming attributes on-line set @t1_id = (select id from ndb_show_tables where name like '%t1%'); truncate ndb_show_tables; alter table t1 change tiny new_tiny tinyint(4) DEFAULT '0' NOT NULL; +--disable_warnings +--exec $NDB_TOOLS_DIR/ndb_show_tables --p > $MYSQLTEST_VARDIR/master-data/test/tmp.dat +LOAD DATA INFILE 'tmp.dat' INTO TABLE ndb_show_tables; +--enable_warnings + +select 'no_copy' from ndb_show_tables where id = @t1_id and name like '%t1%'; + +set @t1_id = (select id from ndb_show_tables where name like '%t1%'); +truncate ndb_show_tables; + create index i1 on t1(medium); -alter table t1 add index i2(long_int); +alter table t1 add index i2(new_tiny); drop index i1 on t1; --disable_warnings From 5660fa6b46f2f8ace3423e7969e21a847c3467ed Mon Sep 17 00:00:00 2001 From: "mskold@mysql.com" <> Date: Wed, 14 Jun 2006 12:01:06 +0200 Subject: [PATCH 4/4] Added flag to detect renaming of fields (not supported as fast alter table for ndbcluster): psot review comment: cleared flag before checking --- sql/sql_table.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index c0db7120b86..3ac41d2910f 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4745,10 +4745,12 @@ static uint compare_tables(TABLE *table, List *create_list, create_info->table_options|= HA_OPTION_PACK_RECORD; /* Check if field was renamed */ + field->flags&= ~FIELD_IS_RENAMED; if (my_strcasecmp(system_charset_info, field->field_name, new_field->field_name)) field->flags|= FIELD_IS_RENAMED; + /* Evaluate changes bitmap and send to check_if_incompatible_data() */ if (!(tmp= field->is_equal(new_field))) DBUG_RETURN(ALTER_TABLE_DATA_CHANGED);