diff --git a/mysql-test/r/ndb_alter_table.result b/mysql-test/r/ndb_alter_table.result new file mode 100644 index 00000000000..6cc6a89d5ad --- /dev/null +++ b/mysql-test/r/ndb_alter_table.result @@ -0,0 +1,29 @@ +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +a INT NOT NULL, +b INT NOT NULL +) ENGINE=ndbcluster; +INSERT INTO t1 VALUES (9410,9412); +ALTER TABLE t1 ADD COLUMN c int not null; +SELECT * FROM t1; +a b c +9410 9412 0 +DROP TABLE t1; +create table t1 ( +col1 int not null auto_increment primary key, +col2 varchar(30) not null, +col3 varchar (20) not null, +col4 varchar(4) not null, +col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null, +col6 int not null, to_be_deleted int); +insert into t1 values (2,4,3,5,"PENDING",1,7); +alter table t1 +add column col4_5 varchar(20) not null after col4, +add column col7 varchar(30) not null after col5, +add column col8 datetime not null, drop column to_be_deleted, +change column col2 fourth varchar(30) not null after col3, +modify column col6 int not null first; +select * from t1; +col6 col1 col3 fourth col4 col4_5 col5 col7 col8 +1 2 3 4 5 PENDING 0000-00-00 00:00:00 +drop table t1; diff --git a/mysql-test/t/ndb_alter_table.test b/mysql-test/t/ndb_alter_table.test new file mode 100644 index 00000000000..f95aa82b7cc --- /dev/null +++ b/mysql-test/t/ndb_alter_table.test @@ -0,0 +1,41 @@ +-- source include/have_ndb.inc + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +# Basic test to show that the ALTER TABLE +# is working +# +CREATE TABLE t1 ( + a INT NOT NULL, + b INT NOT NULL +) ENGINE=ndbcluster; + +INSERT INTO t1 VALUES (9410,9412); + +ALTER TABLE t1 ADD COLUMN c int not null; +SELECT * FROM t1; + +DROP TABLE t1; + +# +# More advanced test +# +create table t1 ( +col1 int not null auto_increment primary key, +col2 varchar(30) not null, +col3 varchar (20) not null, +col4 varchar(4) not null, +col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null, +col6 int not null, to_be_deleted int); +insert into t1 values (2,4,3,5,"PENDING",1,7); +alter table t1 +add column col4_5 varchar(20) not null after col4, +add column col7 varchar(30) not null after col5, +add column col8 datetime not null, drop column to_be_deleted, +change column col2 fourth varchar(30) not null after col3, +modify column col6 int not null first; +select * from t1; +drop table t1; diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index fc0f92994cd..2fd80b85b33 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -951,7 +951,8 @@ int ha_ndbcluster::full_table_scan(byte *buf) { Field *field= table->field[i]; if ((thd->query_id == field->query_id) || - (field->flags & PRI_KEY_FLAG)) + (field->flags & PRI_KEY_FLAG) || + retrieve_all_fields) { if (get_ndb_value(op, i, field->ptr)) ERR_RETURN(op->getNdbError()); @@ -1779,6 +1780,7 @@ int ha_ndbcluster::extra(enum ha_extra_function operation) where field->query_id is the same as the current query id */ DBUG_PRINT("info", ("HA_EXTRA_RETRIEVE_ALL_COLS")); + retrieve_all_fields = TRUE; break; case HA_EXTRA_PREPARE_FOR_DELETE: DBUG_PRINT("info", ("HA_EXTRA_PREPARE_FOR_DELETE")); @@ -2025,6 +2027,8 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) (NdbConnection*)thd->transaction.all.ndb_tid: (NdbConnection*)thd->transaction.stmt.ndb_tid; DBUG_ASSERT(m_active_trans); + + retrieve_all_fields = FALSE; } else @@ -2076,6 +2080,8 @@ int ha_ndbcluster::start_stmt(THD *thd) thd->transaction.stmt.ndb_tid= trans; } m_active_trans= trans; + + retrieve_all_fields = FALSE; DBUG_RETURN(error); } @@ -2553,6 +2559,7 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg): HA_DROP_BEFORE_CREATE | HA_NOT_READ_AFTER_KEY), m_use_write(false), + retrieve_all_fields(FALSE), rows_to_insert(0), rows_inserted(0), bulk_insert_rows(1024) diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index f9109244492..afb62b1347b 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -208,6 +208,7 @@ class ha_ndbcluster: public handler const char* m_unique_index_name[MAX_KEY]; NdbRecAttr *m_value[NDB_MAX_ATTRIBUTES_IN_TABLE]; bool m_use_write; + bool retrieve_all_fields; ha_rows rows_to_insert; ha_rows rows_inserted; ha_rows bulk_insert_rows; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 0d0be1b7e10..3cb3afafc09 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3219,7 +3219,11 @@ copy_data_between_tables(TABLE *from,TABLE *to, error= 1; goto err; } - + + /* Handler must be told explicitly to retrieve all columns, because + this function does not set field->query_id in the columns to the + current query id */ + from->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS); init_read_record(&info, thd, from, (SQL_SELECT *) 0, 1,1); if (handle_duplicates == DUP_IGNORE || handle_duplicates == DUP_REPLACE)