Commit a1b9fb51 authored by unknown's avatar unknown

Bug fix for bug#3912

parent ef2ed501
......@@ -15,14 +15,20 @@ 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) ENGINE=ndbcluster;
insert into t1 values (2,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7), (25, 4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7);
col6 int not null, to_be_deleted int) ENGINE=ndbcluster;
insert into t1 values
(0,4,3,5,"PENDING",1,7),(NULL,4,3,5,"PENDING",1,7),(31,4,3,5,"PENDING",1,7), (7,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7), (100,4,3,5,"PENDING",1,7), (99,4,3,5,"PENDING",1,7), (8,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7);
select * from t1 order by col1;
col1 col2 col3 col4 col5 col6 to_be_deleted
2 4 3 5 PENDING 1 7
3 4 3 5 PENDING 1 7
25 4 3 5 PENDING 1 7
26 4 3 5 PENDING 1 7
0 4 3 5 PENDING 1 7
1 4 3 5 PENDING 1 7
7 4 3 5 PENDING 1 7
8 4 3 5 PENDING 1 7
31 4 3 5 PENDING 1 7
32 4 3 5 PENDING 1 7
99 4 3 5 PENDING 1 7
100 4 3 5 PENDING 1 7
101 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,
......@@ -31,16 +37,26 @@ change column col2 fourth varchar(30) not null after col3,
modify column col6 int not null first;
select * from t1 order by col1;
col6 col1 col3 fourth col4 col4_5 col5 col7 col8
1 2 3 4 5 PENDING 0000-00-00 00:00:00
1 3 3 4 5 PENDING 0000-00-00 00:00:00
1 25 3 4 5 PENDING 0000-00-00 00:00:00
1 26 3 4 5 PENDING 0000-00-00 00:00:00
1 0 3 4 5 PENDING 0000-00-00 00:00:00
1 1 3 4 5 PENDING 0000-00-00 00:00:00
1 7 3 4 5 PENDING 0000-00-00 00:00:00
1 8 3 4 5 PENDING 0000-00-00 00:00:00
1 31 3 4 5 PENDING 0000-00-00 00:00:00
1 32 3 4 5 PENDING 0000-00-00 00:00:00
1 99 3 4 5 PENDING 0000-00-00 00:00:00
1 100 3 4 5 PENDING 0000-00-00 00:00:00
1 101 3 4 5 PENDING 0000-00-00 00:00:00
insert into t1 values (2, NULL,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00');
select * from t1 order by col1;
col6 col1 col3 fourth col4 col4_5 col5 col7 col8
1 2 3 4 5 PENDING 0000-00-00 00:00:00
1 3 3 4 5 PENDING 0000-00-00 00:00:00
1 25 3 4 5 PENDING 0000-00-00 00:00:00
1 26 3 4 5 PENDING 0000-00-00 00:00:00
2 27 4 3 5 99 PENDING EXTRA 2004-01-01 00:00:00
1 0 3 4 5 PENDING 0000-00-00 00:00:00
1 1 3 4 5 PENDING 0000-00-00 00:00:00
1 7 3 4 5 PENDING 0000-00-00 00:00:00
1 8 3 4 5 PENDING 0000-00-00 00:00:00
1 31 3 4 5 PENDING 0000-00-00 00:00:00
1 32 3 4 5 PENDING 0000-00-00 00:00:00
1 99 3 4 5 PENDING 0000-00-00 00:00:00
1 100 3 4 5 PENDING 0000-00-00 00:00:00
1 101 3 4 5 PENDING 0000-00-00 00:00:00
2 102 4 3 5 99 PENDING EXTRA 2004-01-01 00:00:00
drop table t1;
......@@ -29,8 +29,9 @@ 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) ENGINE=ndbcluster;
insert into t1 values (2,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7), (25, 4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7);
col6 int not null, to_be_deleted int) ENGINE=ndbcluster;
insert into t1 values
(0,4,3,5,"PENDING",1,7),(NULL,4,3,5,"PENDING",1,7),(31,4,3,5,"PENDING",1,7), (7,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7), (100,4,3,5,"PENDING",1,7), (99,4,3,5,"PENDING",1,7), (8,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7);
select * from t1 order by col1;
alter table t1
add column col4_5 varchar(20) not null after col4,
......
......@@ -788,7 +788,7 @@ Ndb::setTupleIdInNdb(Uint32 aTableId, Uint64 val, bool increase )
{
// We have a cache sequence
if (val <= theFirstTupleId[aTableId]+1)
return true;
return false;
if (val <= theLastTupleId[aTableId])
{
theFirstTupleId[aTableId] = val - 1;
......@@ -811,7 +811,7 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op)
NdbOperation* tOperation;
Uint64 tValue;
NdbRecAttr* tRecAttrResult;
int result;
Uint64 ret;
CHECK_STATUS_MACRO_ZERO;
......@@ -865,8 +865,8 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op)
if (tConnection->execute( Commit ) == -1 )
goto error_handler;
theFirstTupleId[aTableId] = ~0;
theLastTupleId[aTableId] = ~0;
theFirstTupleId[aTableId] = ~(Uint64)0;
theLastTupleId[aTableId] = ~(Uint64)0;
ret = opValue;
break;
case 2:
......@@ -876,15 +876,20 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op)
tOperation->read_attr("NEXTID", 2);
tOperation->branch_le(2, 1, 0);
tOperation->write_attr("NEXTID", 1);
tOperation->def_label(0);
tOperation->interpret_exit_ok();
tOperation->def_label(0);
tOperation->interpret_exit_nok(9999);
if (tConnection->execute( Commit ) == -1 )
goto error_handler;
theFirstTupleId[aTableId] = ~0;
theLastTupleId[aTableId] = ~0;
ret = opValue;
if (result == 9999)
ret = ~(Uint64)0;
else
{
theFirstTupleId[aTableId] = theLastTupleId[aTableId] = opValue - 1;
ret = opValue;
}
break;
default:
goto error_handler;
......
......@@ -1281,7 +1281,7 @@ int ha_ndbcluster::define_read_attrs(byte* buf, NdbOperation* op)
int ha_ndbcluster::write_row(byte *record)
{
bool has_auto_increment;
bool has_auto_increment, auto_increment_field_not_null;
uint i;
NdbConnection *trans= m_active_trans;
NdbOperation *op;
......@@ -1292,7 +1292,8 @@ int ha_ndbcluster::write_row(byte *record)
if (table->timestamp_default_now)
update_timestamp(record+table->timestamp_default_now-1);
has_auto_increment= (table->next_number_field && record == table->record[0]);
if (has_auto_increment)
auto_increment_field_not_null= table->auto_increment_field_not_null;
if ((has_auto_increment) && (!auto_increment_field_not_null))
update_auto_increment();
if (!(op= trans->getNdbOperation(m_tabname)))
......@@ -1346,11 +1347,14 @@ int ha_ndbcluster::write_row(byte *record)
if (trans->execute(NoCommit) != 0)
DBUG_RETURN(ndb_err(trans));
}
if ( (has_auto_increment) && (!auto_increment_column_changed) )
{
if ((has_auto_increment) && (auto_increment_field_not_null))
{
Uint64 next_val= (Uint64) table->next_number_field->val_int() + 1;
DBUG_PRINT("info", ("Setting next auto increment value to %u", next_val));
m_ndb->setAutoIncrementValue(m_tabname, next_val, true);
DBUG_PRINT("info",
("Trying to set next auto increment value to %u", next_val));
if (m_ndb->setAutoIncrementValue(m_tabname, next_val, true))
DBUG_PRINT("info",
("Setting next auto increment value to %u", next_val));
}
DBUG_RETURN(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment