Below is the list of changes that have just been committed into a local
5.0 repository of mattiasj. When mattiasj does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2008-02-29 11:21:57+01:00,
mattiasj@stripped +4 -0
Bug#24159: Altered AUTO_INCREMENT not effective when inserting in MERGE
Problem was that it used the default handler::get_auto_increment,
which gets next higher value, instead of using the auto_increment directly
from myisam.
Solved by adding ha_myisammrg::get_auto_increment and using the
share->state.auto_increment variable (that is what myisam really does,
and should be safe since there should be a table lock taken.)
Will probably have to rewrite/update this in 5.1+ when merging, due to
changes in the get_auto_increment call.
(Updated with DBUG_RETURN in ha_myisammrg.cc)
mysql-test/r/merge.result@stripped, 2008-02-29 11:21:55+01:00,
mattiasj@stripped +58 -0
Bug#24159: Altered AUTO_INCREMENT not effective when inserting in MERGE
Test result
mysql-test/t/merge.test@stripped, 2008-02-29 11:21:56+01:00,
mattiasj@stripped +41 -0
Bug#24159: Altered AUTO_INCREMENT not effective when inserting in MERGE
Test file
sql/ha_myisammrg.cc@stripped, 2008-02-29 11:21:56+01:00,
mattiasj@stripped +18 -0
Bug#24159: Altered AUTO_INCREMENT not effective when inserting in MERGE
Problem was that it used the default handler::get_auto_increment,
which gets next higher value, instead of using the auto_increment directly
from myisam.
Solved by adding ha_myisammrg::get_auto_increment and using the
share->state.auto_increment variable (that is what myisam really does,
and should be safe since there should be a table lock taken.)
(Updated with DBUG_RETURN)
sql/ha_myisammrg.h@stripped, 2008-02-29 11:21:56+01:00,
mattiasj@stripped +1 -0
Bug#24159: Altered AUTO_INCREMENT not effective when inserting in MERGE
Added ha_myisammrg::get_auto_increment
diff -Nrup a/mysql-test/r/merge.result b/mysql-test/r/merge.result
--- a/mysql-test/r/merge.result 2007-11-26 17:35:04 +01:00
+++ b/mysql-test/r/merge.result 2008-02-29 11:21:55 +01:00
@@ -1,5 +1,63 @@
drop table if exists t1,t2,t3,t4,t5,t6;
drop database if exists mysqltest;
+create table t1 (a int not null auto_increment primary key)
+ENGINE=MyISAM AUTO_INCREMENT=1000;
+create table t2 (a int not null auto_increment primary key)
+ENGINE=MyISAM AUTO_INCREMENT=200;
+create table t3 (a int not null auto_increment primary key)
+ENGINE=MRG_MyISAM INSERT_METHOD=LAST UNION=(t1,t2);
+alter table t2 AUTO_INCREMENT=2000;
+flush tables;
+insert into t3 values ();
+select * from t3 order by a;
+a
+2000
+insert into t1 values ();
+insert into t2 values ();
+select * from t3 order by a;
+a
+1000
+2000
+2001
+insert into t3 values ();
+select * from t3 order by a;
+a
+1000
+2000
+2001
+2002
+drop table t1,t2,t3;
+create table t1 (a int not null auto_increment primary key)
+ENGINE=MyISAM AUTO_INCREMENT=1000;
+create table t2 (a int not null auto_increment primary key)
+ENGINE=MyISAM AUTO_INCREMENT=200;
+create table t3 (a int not null auto_increment primary key)
+ENGINE=MRG_MyISAM INSERT_METHOD=FIRST UNION=(t1,t2);
+alter table t2 AUTO_INCREMENT=2000;
+flush tables;
+insert into t3 values ();
+select * from t3 order by a;
+a
+1000
+insert into t1 values ();
+insert into t2 values ();
+select * from t3 order by a;
+a
+1000
+1001
+2000
+insert into t3 values ();
+select * from t3 order by a;
+a
+1000
+1001
+1002
+2000
+create table t4 (a int not null auto_increment primary key)
+ENGINE=MRG_MyISAM UNION=(t1,t2);
+insert into t4 values ();
+ERROR HY000: Table 't4' is read only
+drop table t1,t2,t3,t4;
create table t1 (a int not null primary key auto_increment, message char(20));
create table t2 (a int not null primary key auto_increment, message char(20));
INSERT INTO t1 (message) VALUES ("Testing"),("table"),("t1");
diff -Nrup a/mysql-test/t/merge.test b/mysql-test/t/merge.test
--- a/mysql-test/t/merge.test 2007-12-13 11:49:11 +01:00
+++ b/mysql-test/t/merge.test 2008-02-29 11:21:56 +01:00
@@ -7,6 +7,47 @@ drop table if exists t1,t2,t3,t4,t5,t6;
drop database if exists mysqltest;
--enable_warnings
+#
+# Bug#24159: Altered base table AUTO_INCREMENT not taking effect when
+# inserting into MERGE
+#
+create table t1 (a int not null auto_increment primary key)
+ ENGINE=MyISAM AUTO_INCREMENT=1000;
+create table t2 (a int not null auto_increment primary key)
+ ENGINE=MyISAM AUTO_INCREMENT=200;
+create table t3 (a int not null auto_increment primary key)
+ ENGINE=MRG_MyISAM INSERT_METHOD=LAST UNION=(t1,t2);
+alter table t2 AUTO_INCREMENT=2000;
+flush tables;
+insert into t3 values ();
+select * from t3 order by a;
+insert into t1 values ();
+insert into t2 values ();
+select * from t3 order by a;
+insert into t3 values ();
+select * from t3 order by a;
+drop table t1,t2,t3;
+create table t1 (a int not null auto_increment primary key)
+ ENGINE=MyISAM AUTO_INCREMENT=1000;
+create table t2 (a int not null auto_increment primary key)
+ ENGINE=MyISAM AUTO_INCREMENT=200;
+create table t3 (a int not null auto_increment primary key)
+ ENGINE=MRG_MyISAM INSERT_METHOD=FIRST UNION=(t1,t2);
+alter table t2 AUTO_INCREMENT=2000;
+flush tables;
+insert into t3 values ();
+select * from t3 order by a;
+insert into t1 values ();
+insert into t2 values ();
+select * from t3 order by a;
+insert into t3 values ();
+select * from t3 order by a;
+create table t4 (a int not null auto_increment primary key)
+ ENGINE=MRG_MyISAM UNION=(t1,t2);
+--error ER_OPEN_AS_READONLY
+insert into t4 values ();
+drop table t1,t2,t3,t4;
+
create table t1 (a int not null primary key auto_increment, message char(20));
create table t2 (a int not null primary key auto_increment, message char(20));
INSERT INTO t1 (message) VALUES ("Testing"),("table"),("t1");
diff -Nrup a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc
--- a/sql/ha_myisammrg.cc 2007-11-26 16:58:51 +01:00
+++ b/sql/ha_myisammrg.cc 2008-02-29 11:21:56 +01:00
@@ -634,3 +634,21 @@ int ha_myisammrg::check(THD* thd, HA_CHE
{
return HA_ADMIN_OK;
}
+
+
+ulonglong ha_myisammrg::get_auto_increment()
+{
+ DBUG_ENTER("ha_myisammrg::get_auto_increment");
+
+ /* use default if secondary part of multi column index */
+ if (table->s->next_number_key_offset)
+ DBUG_RETURN(handler::get_auto_increment());
+
+ if (file->merge_insert_method == MERGE_INSERT_TO_FIRST)
+ file->current_table= file->open_tables;
+ else if (file->merge_insert_method == MERGE_INSERT_TO_LAST)
+ file->current_table= file->end_table-1;
+ else /* unsupported insertion method, will fail in myrg_write */
+ DBUG_RETURN(~(ulonglong) 0);
+ DBUG_RETURN(file->current_table->table->s->state.auto_increment+1);
+}
diff -Nrup a/sql/ha_myisammrg.h b/sql/ha_myisammrg.h
--- a/sql/ha_myisammrg.h 2007-06-06 01:42:39 +02:00
+++ b/sql/ha_myisammrg.h 2008-02-29 11:21:56 +01:00
@@ -82,4 +82,5 @@ class ha_myisammrg: public handler
void append_create_info(String *packet);
MYRG_INFO *myrg_info() { return file; }
int check(THD* thd, HA_CHECK_OPT* check_opt);
+ virtual ulonglong get_auto_increment();
};