mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 21:12:26 +01:00
Merge from fix of Bug #9675 Auto-increment not working with INSERT..SELECT and NDB storage
This commit is contained in:
parent
43d926029f
commit
497f2684d8
4 changed files with 101 additions and 2 deletions
|
@ -40,7 +40,7 @@ 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);
|
||||
show table status;
|
||||
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
|
||||
t1 ndbcluster 10 Dynamic 9 96 # # 0 # 101 # # # latin1_swedish_ci NULL #
|
||||
t1 ndbcluster 10 Dynamic 9 96 # # 0 # 102 # # # latin1_swedish_ci NULL #
|
||||
select * from t1 order by col1;
|
||||
col1 col2 col3 col4 col5 col6 to_be_deleted
|
||||
0 4 3 5 PENDING 1 7
|
||||
|
|
|
@ -607,3 +607,63 @@ primary key (a))
|
|||
engine=ndb
|
||||
max_rows=1;
|
||||
drop table t1;
|
||||
create table t1
|
||||
(counter int(64) NOT NULL auto_increment,
|
||||
datavalue char(40) default 'XXXX',
|
||||
primary key (counter)
|
||||
) ENGINE=ndbcluster;
|
||||
insert into t1 (datavalue) values ('newval');
|
||||
insert into t1 (datavalue) values ('newval');
|
||||
select * from t1 order by counter;
|
||||
counter datavalue
|
||||
1 newval
|
||||
2 newval
|
||||
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
|
||||
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
|
||||
select * from t1 order by counter;
|
||||
counter datavalue
|
||||
1 newval
|
||||
2 newval
|
||||
3 newval
|
||||
4 newval
|
||||
5 newval
|
||||
6 newval
|
||||
7 newval
|
||||
8 newval
|
||||
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
|
||||
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
|
||||
select * from t1 order by counter;
|
||||
counter datavalue
|
||||
1 newval
|
||||
2 newval
|
||||
3 newval
|
||||
4 newval
|
||||
5 newval
|
||||
6 newval
|
||||
7 newval
|
||||
8 newval
|
||||
35 newval
|
||||
36 newval
|
||||
37 newval
|
||||
38 newval
|
||||
39 newval
|
||||
40 newval
|
||||
41 newval
|
||||
42 newval
|
||||
43 newval
|
||||
44 newval
|
||||
45 newval
|
||||
46 newval
|
||||
47 newval
|
||||
48 newval
|
||||
49 newval
|
||||
50 newval
|
||||
51 newval
|
||||
52 newval
|
||||
53 newval
|
||||
54 newval
|
||||
55 newval
|
||||
56 newval
|
||||
57 newval
|
||||
58 newval
|
||||
drop table t1;
|
||||
|
|
|
@ -577,3 +577,30 @@ create table t1
|
|||
engine=ndb
|
||||
max_rows=1;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Test auto_increment
|
||||
#
|
||||
|
||||
connect (con1,localhost,,,test);
|
||||
connect (con2,localhost,,,test);
|
||||
|
||||
create table t1
|
||||
(counter int(64) NOT NULL auto_increment,
|
||||
datavalue char(40) default 'XXXX',
|
||||
primary key (counter)
|
||||
) ENGINE=ndbcluster;
|
||||
|
||||
connection con1;
|
||||
insert into t1 (datavalue) values ('newval');
|
||||
insert into t1 (datavalue) values ('newval');
|
||||
select * from t1 order by counter;
|
||||
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
|
||||
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
|
||||
select * from t1 order by counter;
|
||||
connection con2;
|
||||
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
|
||||
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
|
||||
select * from t1 order by counter;
|
||||
|
||||
drop table t1;
|
||||
|
|
|
@ -1919,8 +1919,12 @@ int ha_ndbcluster::write_row(byte *record)
|
|||
|
||||
if (has_auto_increment)
|
||||
{
|
||||
THD *thd= table->in_use;
|
||||
|
||||
m_skip_auto_increment= FALSE;
|
||||
update_auto_increment();
|
||||
/* Ensure that handler is always called for auto_increment values */
|
||||
thd->next_insert_id= 0;
|
||||
m_skip_auto_increment= !auto_increment_column_changed;
|
||||
}
|
||||
|
||||
|
@ -2970,7 +2974,11 @@ void ha_ndbcluster::start_bulk_insert(ha_rows rows)
|
|||
DBUG_PRINT("enter", ("rows: %d", (int)rows));
|
||||
|
||||
m_rows_inserted= 0;
|
||||
m_rows_to_insert= rows;
|
||||
if (rows == 0)
|
||||
/* We don't know how many will be inserted, guess */
|
||||
m_rows_to_insert= m_autoincrement_prefetch;
|
||||
else
|
||||
m_rows_to_insert= rows;
|
||||
|
||||
/*
|
||||
Calculate how many rows that should be inserted
|
||||
|
@ -4080,6 +4088,10 @@ ulonglong ha_ndbcluster::get_auto_increment()
|
|||
DBUG_ENTER("get_auto_increment");
|
||||
DBUG_PRINT("enter", ("m_tabname: %s", m_tabname));
|
||||
Ndb *ndb= get_ndb();
|
||||
|
||||
if (m_rows_inserted > m_rows_to_insert)
|
||||
/* We guessed too low */
|
||||
m_rows_to_insert+= m_autoincrement_prefetch;
|
||||
cache_size=
|
||||
(m_rows_to_insert - m_rows_inserted < m_autoincrement_prefetch) ?
|
||||
m_rows_to_insert - m_rows_inserted
|
||||
|
|
Loading…
Reference in a new issue