From 5a4dce62917e18da2d595bde49bfed7b77e8b15b Mon Sep 17 00:00:00 2001 From: "mskold@mysql.com" <> Date: Mon, 3 Apr 2006 13:25:28 +0200 Subject: [PATCH 1/4] Fix for bug#18133: Adding index to unsigned int causes on-line add index not to be used --- sql/field.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sql/field.cc b/sql/field.cc index 708b239b494..85562ef0b8a 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5970,7 +5970,7 @@ int Field_str::store(double nr) uint Field::is_equal(create_field *new_field) { - return (new_field->sql_type == type()); + return (new_field->sql_type == real_type()); } @@ -5982,7 +5982,7 @@ uint Field_str::is_equal(create_field *new_field) (flags & (BINCMP_FLAG | BINARY_FLAG)))) return 0; /* One of the fields is binary and the other one isn't */ - return ((new_field->sql_type == type()) && + return ((new_field->sql_type == real_type()) && new_field->charset == field_charset && new_field->length == max_length()); } @@ -6779,7 +6779,7 @@ Field *Field_varstring::new_key_field(MEM_ROOT *root, uint Field_varstring::is_equal(create_field *new_field) { - if (new_field->sql_type == type() && + if (new_field->sql_type == real_type() && new_field->charset == field_charset) { if (new_field->length == max_length()) @@ -7938,12 +7938,12 @@ bool Field_num::eq_def(Field *field) uint Field_num::is_equal(create_field *new_field) { - return ((new_field->sql_type == type()) && + return ((new_field->sql_type == real_type()) && ((new_field->flags & UNSIGNED_FLAG) == (uint) (flags & UNSIGNED_FLAG)) && ((new_field->flags & AUTO_INCREMENT_FLAG) == (uint) (flags & AUTO_INCREMENT_FLAG)) && - (new_field->length >= max_length())); + (new_field->length <= max_length())); } From 68d4b5762f3d0d63a73172b68a233b7082f37cd7 Mon Sep 17 00:00:00 2001 From: "mskold@mysql.com" <> Date: Thu, 6 Apr 2006 10:47:48 +0200 Subject: [PATCH 2/4] Fix for bug#16445 schema version error 241 after mysqld restart, always invalidate dictionary cache when receiving changed schema events drop table or alter table, regardless if done remotely or not (also includes cluster failures, but refreshing cache is a safe operation) --- mysql-test/t/ndb_basic.test | 11 ---- sql/ha_ndbcluster_binlog.cc | 117 ++++++++++++++++++------------------ 2 files changed, 59 insertions(+), 69 deletions(-) diff --git a/mysql-test/t/ndb_basic.test b/mysql-test/t/ndb_basic.test index df94545abea..ab62e3dd13a 100644 --- a/mysql-test/t/ndb_basic.test +++ b/mysql-test/t/ndb_basic.test @@ -6,17 +6,6 @@ DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; drop database if exists mysqltest; --enable_warnings -# workaround for bug#16445 -# remove to reproduce bug and run tests drom ndb start -# and with ndb_autodiscover disabled -CREATE TABLE t1 ( - pk1 INT NOT NULL PRIMARY KEY, - attr1 INT NOT NULL, - attr2 INT, - attr3 VARCHAR(10) -) ENGINE=ndbcluster; -drop table t1; - # # Basic test to show that the NDB # table handler is working diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc index ca3dcf605b0..1f416e1816d 100644 --- a/sql/ha_ndbcluster_binlog.cc +++ b/sql/ha_ndbcluster_binlog.cc @@ -1372,6 +1372,9 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, NDB_SHARE *share) { DBUG_ENTER("ndb_handle_schema_change"); + TABLE* table= share->table; + TABLE_SHARE *table_share= table->s; + const char *dbname= table_share->db.str; bool do_close_cached_tables= FALSE; bool is_online_alter_table= FALSE; bool is_rename_table= FALSE; @@ -1391,70 +1394,68 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, } } - if (is_remote_change) /* includes CLUSTER_FAILURE */ + /* + Refresh local dictionary cache by + invalidating table and all it's indexes + */ + ndb->setDatabaseName(dbname); + Thd_ndb *thd_ndb= get_thd_ndb(thd); + DBUG_ASSERT(thd_ndb != NULL); + Ndb* old_ndb= thd_ndb->ndb; + thd_ndb->ndb= ndb; + ha_ndbcluster table_handler(table_share); + table_handler.set_dbname(share->key); + table_handler.set_tabname(share->key); + table_handler.open_indexes(ndb, table, TRUE); + table_handler.invalidate_dictionary_cache(TRUE); + thd_ndb->ndb= old_ndb; + + /* + Refresh local frm file and dictionary cache if + remote on-line alter table + */ + if (is_remote_change && is_online_alter_table) { - TABLE* table= share->table; - TABLE_SHARE *table_share= table->s; - const char *dbname= table_share->db.str; + const char *tabname= table_share->table_name.str; + char key[FN_REFLEN]; + const void *data= 0, *pack_data= 0; + uint length, pack_length; + int error; + NDBDICT *dict= ndb->getDictionary(); + const NDBTAB *altered_table= pOp->getTable(); - /* - Invalidate table and all it's indexes + DBUG_PRINT("info", ("Detected frm change of table %s.%s", + dbname, tabname)); + build_table_filename(key, FN_LEN-1, dbname, tabname, NullS); + /* + If the frm of the altered table is different than the one on + disk then overwrite it with the new table definition */ - ndb->setDatabaseName(dbname); - Thd_ndb *thd_ndb= get_thd_ndb(thd); - DBUG_ASSERT(thd_ndb != NULL); - Ndb* old_ndb= thd_ndb->ndb; - thd_ndb->ndb= ndb; - ha_ndbcluster table_handler(table_share); - table_handler.set_dbname(share->key); - table_handler.set_tabname(share->key); - table_handler.open_indexes(ndb, table, TRUE); - table_handler.invalidate_dictionary_cache(TRUE); - thd_ndb->ndb= old_ndb; - - if (is_online_alter_table) + if (readfrm(key, &data, &length) == 0 && + packfrm(data, length, &pack_data, &pack_length) == 0 && + cmp_frm(altered_table, pack_data, pack_length)) { - const char *tabname= table_share->table_name.str; - char key[FN_REFLEN]; - const void *data= 0, *pack_data= 0; - uint length, pack_length; - int error; - NDBDICT *dict= ndb->getDictionary(); - const NDBTAB *altered_table= pOp->getTable(); - - DBUG_PRINT("info", ("Detected frm change of table %s.%s", - dbname, tabname)); - build_table_filename(key, FN_LEN-1, dbname, tabname, NullS); - /* - If the frm of the altered table is different than the one on - disk then overwrite it with the new table definition - */ - if (readfrm(key, &data, &length) == 0 && - packfrm(data, length, &pack_data, &pack_length) == 0 && - cmp_frm(altered_table, pack_data, pack_length)) + DBUG_DUMP("frm", (char*)altered_table->getFrmData(), + altered_table->getFrmLength()); + pthread_mutex_lock(&LOCK_open); + const NDBTAB *old= dict->getTable(tabname); + if (!old && + old->getObjectVersion() != altered_table->getObjectVersion()) + dict->putTable(altered_table); + + if ((error= unpackfrm(&data, &length, altered_table->getFrmData())) || + (error= writefrm(key, data, length))) { - DBUG_DUMP("frm", (char*)altered_table->getFrmData(), - altered_table->getFrmLength()); - pthread_mutex_lock(&LOCK_open); - const NDBTAB *old= dict->getTable(tabname); - if (!old && - old->getObjectVersion() != altered_table->getObjectVersion()) - dict->putTable(altered_table); - - if ((error= unpackfrm(&data, &length, altered_table->getFrmData())) || - (error= writefrm(key, data, length))) - { - sql_print_information("NDB: Failed write frm for %s.%s, error %d", - dbname, tabname, error); - } - ndbcluster_binlog_close_table(thd, share); - close_cached_tables((THD*) 0, 0, (TABLE_LIST*) 0, TRUE); - if ((error= ndbcluster_binlog_open_table(thd, share, - table_share, table))) - sql_print_information("NDB: Failed to re-open table %s.%s", - dbname, tabname); - pthread_mutex_unlock(&LOCK_open); + sql_print_information("NDB: Failed write frm for %s.%s, error %d", + dbname, tabname, error); } + ndbcluster_binlog_close_table(thd, share); + close_cached_tables((THD*) 0, 0, (TABLE_LIST*) 0, TRUE); + if ((error= ndbcluster_binlog_open_table(thd, share, + table_share, table))) + sql_print_information("NDB: Failed to re-open table %s.%s", + dbname, tabname); + pthread_mutex_unlock(&LOCK_open); } } From 2a924b8c153ea52fc728806c3e42f03e266cb1d9 Mon Sep 17 00:00:00 2001 From: "mskold@mysql.com" <> Date: Tue, 18 Apr 2006 08:57:37 +0200 Subject: [PATCH 3/4] Invalidate old table at rename --- sql/ha_ndbcluster_binlog.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc index cfa22617093..ace6eeb5db0 100644 --- a/sql/ha_ndbcluster_binlog.cc +++ b/sql/ha_ndbcluster_binlog.cc @@ -1376,6 +1376,7 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, TABLE* table= share->table; TABLE_SHARE *table_share= table->s; const char *dbname= table_share->db.str; + const char *tabname= table_share->table_name.str; bool do_close_cached_tables= FALSE; bool is_online_alter_table= FALSE; bool is_rename_table= FALSE; @@ -1405,8 +1406,8 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, Ndb* old_ndb= thd_ndb->ndb; thd_ndb->ndb= ndb; ha_ndbcluster table_handler(table_share); - table_handler.set_dbname(share->key); - table_handler.set_tabname(share->key); + (void)strxmov(table_handler.m_dbname, dbname, NullS); + (void)strxmov(table_handler.m_tabname, tabname, NullS); table_handler.open_indexes(ndb, table, TRUE); table_handler.invalidate_dictionary_cache(TRUE); thd_ndb->ndb= old_ndb; @@ -1484,6 +1485,21 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, share->table->s->db.length= strlen(share->db); share->table->s->table_name.str= share->table_name; share->table->s->table_name.length= strlen(share->table_name); + /* + Refresh local dictionary cache by invalidating any + old table with same name and all it's indexes + */ + ndb->setDatabaseName(dbname); + Thd_ndb *thd_ndb= get_thd_ndb(thd); + DBUG_ASSERT(thd_ndb != NULL); + Ndb* old_ndb= thd_ndb->ndb; + thd_ndb->ndb= ndb; + ha_ndbcluster table_handler(table_share); + table_handler.set_dbname(share->key); + table_handler.set_tabname(share->key); + table_handler.open_indexes(ndb, table, TRUE); + table_handler.invalidate_dictionary_cache(TRUE); + thd_ndb->ndb= old_ndb; } DBUG_ASSERT(share->op == pOp || share->op_old == pOp); if (share->op_old == pOp) From 1516bb1318e2cd69c7aa380aab333b9f6a45cf54 Mon Sep 17 00:00:00 2001 From: "mskold@mysql.com" <> Date: Tue, 18 Apr 2006 12:16:27 +0200 Subject: [PATCH 4/4] Updated result file --- mysql-test/r/ndb_basic.result | 7 ------- 1 file changed, 7 deletions(-) diff --git a/mysql-test/r/ndb_basic.result b/mysql-test/r/ndb_basic.result index 9477caf97ab..4a1f5f587df 100644 --- a/mysql-test/r/ndb_basic.result +++ b/mysql-test/r/ndb_basic.result @@ -6,13 +6,6 @@ attr1 INT NOT NULL, attr2 INT, attr3 VARCHAR(10) ) ENGINE=ndbcluster; -drop table t1; -CREATE TABLE t1 ( -pk1 INT NOT NULL PRIMARY KEY, -attr1 INT NOT NULL, -attr2 INT, -attr3 VARCHAR(10) -) ENGINE=ndbcluster; SHOW INDEX FROM t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment t1 0 PRIMARY 1 pk1 A 0 NULL NULL BTREE