mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
BUG# 3658 ALTER TABLE corrupts table
Added test file for ALTER TABLE, engine = ndbcluster sql/ha_ndbcluster.cc: Add code to retriev all fields if HA_EXTRA_RETRIEVE_ALL_COLS are set. sql/ha_ndbcluster.h: Add var for retreiving all fields sql/sql_table.cc: Send HA_EXTRA_RETRIEVE_ALL_COLS to handler in copy_data_between_tables
This commit is contained in:
parent
4e4262cca9
commit
9d99ebe394
5 changed files with 84 additions and 2 deletions
29
mysql-test/r/ndb_alter_table.result
Normal file
29
mysql-test/r/ndb_alter_table.result
Normal file
|
@ -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;
|
41
mysql-test/t/ndb_alter_table.test
Normal file
41
mysql-test/t/ndb_alter_table.test
Normal file
|
@ -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;
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue