diff --git a/mysql-test/r/archive.result b/mysql-test/r/archive.result index 77d3cba63d52ad7cbd83399dfe42ebd5dbb9788d..5782941fd688e1390c1b613b2e29ff10a26fd6e6 100644 --- a/mysql-test/r/archive.result +++ b/mysql-test/r/archive.result @@ -12665,7 +12665,7 @@ t6 CREATE TABLE `t6` ( `b` tinyblob, `c` int(11) DEFAULT NULL, KEY `a` (`a`) -) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 +) ENGINE=ARCHIVE AUTO_INCREMENT=36 DEFAULT CHARSET=latin1 DROP TABLE t1, t2, t4, t5, t6; create table t1 (i int) engine=archive; insert into t1 values (1); diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index ba7327692f862d1af1282d3c7b8fa2b01eb39c14..f90bd2de661f490251dbeb826e7f30fa6fd72b3b 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -1338,4 +1338,19 @@ int_column char_column 545592 zZzSD 39868 zZZRW DROP TABLE t1; +CREATE TABLE t1(id MEDIUMINT NOT NULL AUTO_INCREMENT, +user CHAR(25), PRIMARY KEY(id)) +PARTITION BY RANGE(id) +SUBPARTITION BY hash(id) subpartitions 2 +(PARTITION pa1 values less than (10), +PARTITION pa2 values less than (20), +PARTITION pa11 values less than MAXVALUE); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` mediumint(9) NOT NULL AUTO_INCREMENT, + `user` char(25) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (id) SUBPARTITION BY HASH (id) SUBPARTITIONS 2 (PARTITION pa1 VALUES LESS THAN (10) ENGINE = MyISAM, PARTITION pa2 VALUES LESS THAN (20) ENGINE = MyISAM, PARTITION pa11 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */ +drop table t1; End of 5.1 tests diff --git a/mysql-test/r/partition_archive.result b/mysql-test/r/partition_archive.result index dd063f6224cbaa5cc5701dd25e2f0daca26ac224..5c84b41e81baa58decc342e8481333e07f27f9bb 100644 --- a/mysql-test/r/partition_archive.result +++ b/mysql-test/r/partition_archive.result @@ -1,4 +1,5 @@ drop database if exists db99; +drop table if exists t1; create database db99; use db99; create table t1 (a int not null) @@ -11,3 +12,80 @@ alter table t1 add partition (partition p2 values in (3)); alter table t1 drop partition p2; use test; drop database db99; +create table t1 (f1 integer) engine= ARCHIVE partition by list(f1) +( +partition p1 values in (1), +partition p2 values in (NULL), +partition p3 values in (2), +partition p4 values in (3), +partition p5 values in (4) +); +insert into t1 values (1),(2),(3),(4),(null); +select * from t1; +f1 +1 +NULL +2 +3 +4 +select * from t1 where f1 < 3; +f1 +1 +2 +drop table t1; +CREATE TABLE t1 ( +a int not null, +b int not null, +c int not null) engine=ARCHIVE +partition by hash (a + 2) +partitions 3 +(partition x1 tablespace ts1, +partition x2 tablespace ts2, +partition x3 tablespace ts3); +insert into t1 values (1,1,1); +insert into t1 values (2,1,1); +insert into t1 values (3,1,1); +insert into t1 values (4,1,1); +insert into t1 values (5,1,1); +select * from t1; +a b c +1 1 1 +4 1 1 +2 1 1 +5 1 1 +3 1 1 +drop table t1; +create table t1 (a int) engine=archive partition by hash(a); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (a) */ +drop table t1; +CREATE TABLE t1(id MEDIUMINT NOT NULL AUTO_INCREMENT, +f1 VARCHAR(25), +PRIMARY KEY(id)) ENGINE=ARCHIVE +PARTITION BY RANGE(id) +SUBPARTITION BY hash(id) subpartitions 2 +(PARTITION pa1 values less than (10), +PARTITION pa2 values less than (20), +PARTITION pa3 values less than (30), +PARTITION pa4 values less than (40), +PARTITION pa5 values less than (50), +PARTITION pa6 values less than (60), +PARTITION pa7 values less than (70), +PARTITION pa8 values less than (80), +PARTITION pa9 values less than (90), +PARTITION pa10 values less than (100), +PARTITION pa11 values less than MAXVALUE); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` mediumint(9) NOT NULL AUTO_INCREMENT, + `f1` varchar(25) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=ARCHIVE AUTO_INCREMENT=101 DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (id) SUBPARTITION BY HASH (id) SUBPARTITIONS 2 (PARTITION pa1 VALUES LESS THAN (10) ENGINE = ARCHIVE, PARTITION pa2 VALUES LESS THAN (20) ENGINE = ARCHIVE, PARTITION pa3 VALUES LESS THAN (30) ENGINE = ARCHIVE, PARTITION pa4 VALUES LESS THAN (40) ENGINE = ARCHIVE, PARTITION pa5 VALUES LESS THAN (50) ENGINE = ARCHIVE, PARTITION pa6 VALUES LESS THAN (60) ENGINE = ARCHIVE, PARTITION pa7 VALUES LESS THAN (70) ENGINE = ARCHIVE, PARTITION pa8 VALUES LESS THAN (80) ENGINE = ARCHIVE, PARTITION pa9 VALUES LESS THAN (90) ENGINE = ARCHIVE, PARTITION pa10 VALUES LESS THAN (100) ENGINE = ARCHIVE, PARTITION pa11 VALUES LESS THAN MAXVALUE ENGINE = ARCHIVE) */ +select count(*) from t1; +count(*) +100 +drop table t1; diff --git a/mysql-test/suite/rpl/r/rpl_innodb_bug28430.result b/mysql-test/suite/rpl/r/rpl_innodb_bug28430.result index fb2782ed9f44afb455c2c3873ebb004aad7fa581..99d14b638ada48fa5cf445dd5d51f2f5e7b47e99 100644 --- a/mysql-test/suite/rpl/r/rpl_innodb_bug28430.result +++ b/mysql-test/suite/rpl/r/rpl_innodb_bug28430.result @@ -113,7 +113,7 @@ Create Table CREATE TABLE `byrange_tbl` ( `fkid` mediumint(9) DEFAULT NULL, `filler` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (id) SUBPARTITION BY HASH (id) SUBPARTITIONS 2 (PARTITION pa1 VALUES LESS THAN (10) ENGINE = InnoDB, PARTITION pa2 VALUES LESS THAN (20) ENGINE = InnoDB, PARTITION pa3 VALUES LESS THAN (30) ENGINE = InnoDB, PARTITION pa4 VALUES LESS THAN (40) ENGINE = InnoDB, PARTITION pa5 VALUES LESS THAN (50) ENGINE = InnoDB, PARTITION pa6 VALUES LESS THAN (60) ENGINE = InnoDB, PARTITION pa7 VALUES LESS THAN (70) ENGINE = InnoDB, PARTITION pa8 VALUES LESS THAN (80) ENGINE = InnoDB, PARTITION pa9 VALUES LESS THAN (90) ENGINE = InnoDB, PARTITION pa10 VALUES LESS THAN (100) ENGINE = InnoDB, PARTITION pa11 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */ +) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (id) SUBPARTITION BY HASH (id) SUBPARTITIONS 2 (PARTITION pa1 VALUES LESS THAN (10) ENGINE = InnoDB, PARTITION pa2 VALUES LESS THAN (20) ENGINE = InnoDB, PARTITION pa3 VALUES LESS THAN (30) ENGINE = InnoDB, PARTITION pa4 VALUES LESS THAN (40) ENGINE = InnoDB, PARTITION pa5 VALUES LESS THAN (50) ENGINE = InnoDB, PARTITION pa6 VALUES LESS THAN (60) ENGINE = InnoDB, PARTITION pa7 VALUES LESS THAN (70) ENGINE = InnoDB, PARTITION pa8 VALUES LESS THAN (80) ENGINE = InnoDB, PARTITION pa9 VALUES LESS THAN (90) ENGINE = InnoDB, PARTITION pa10 VALUES LESS THAN (100) ENGINE = InnoDB, PARTITION pa11 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */ show slave status; Slave_IO_State Waiting for master to send event Master_Host 127.0.0.1 diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 0b06fa9f70c1dbb579a8c04fc0fdd13b395689ec..ab6cba529ad9605122d39d6775b1898e7207b73b 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -1577,4 +1577,25 @@ INSERT INTO t1 (int_column, char_column) VALUES SELECT * FROM t1 ORDER BY char_column DESC; DROP TABLE t1; +# +# Bug #32247 Test reports wrong value of "AUTO_INCREMENT" (on a partitioned InnoDB table) +# + +CREATE TABLE t1(id MEDIUMINT NOT NULL AUTO_INCREMENT, + user CHAR(25), PRIMARY KEY(id)) + PARTITION BY RANGE(id) + SUBPARTITION BY hash(id) subpartitions 2 + (PARTITION pa1 values less than (10), + PARTITION pa2 values less than (20), + PARTITION pa11 values less than MAXVALUE); +--disable_query_log +let $n= 15; +while ($n) +{ + insert into t1 (user) values ('mysql'); + dec $n; +} +--enable_query_log +show create table t1; +drop table t1; --echo End of 5.1 tests diff --git a/mysql-test/t/partition_archive.test b/mysql-test/t/partition_archive.test index 3109894d9c9af4b35598f4503bc7266148c9fbfe..fad57107b7d076e4922e3bd19b7e035c2037e5c3 100644 --- a/mysql-test/t/partition_archive.test +++ b/mysql-test/t/partition_archive.test @@ -16,7 +16,9 @@ # --disable_warnings drop database if exists db99; +drop table if exists t1; --enable_warnings + create database db99; use db99; create table t1 (a int not null) @@ -30,3 +32,76 @@ alter table t1 add partition (partition p2 values in (3)); alter table t1 drop partition p2; use test; drop database db99; + +create table t1 (f1 integer) engine= ARCHIVE partition by list(f1) +( + partition p1 values in (1), + partition p2 values in (NULL), + partition p3 values in (2), + partition p4 values in (3), + partition p5 values in (4) +); + +insert into t1 values (1),(2),(3),(4),(null); +select * from t1; +select * from t1 where f1 < 3; +drop table t1; + +CREATE TABLE t1 ( +a int not null, +b int not null, +c int not null) engine=ARCHIVE +partition by hash (a + 2) +partitions 3 +(partition x1 tablespace ts1, + partition x2 tablespace ts2, + partition x3 tablespace ts3); + +insert into t1 values (1,1,1); +insert into t1 values (2,1,1); +insert into t1 values (3,1,1); +insert into t1 values (4,1,1); +insert into t1 values (5,1,1); + +select * from t1; + +drop table t1; + +# +# Bug #32247 Test reports wrong value of "AUTO_INCREMENT" (on a partitioned InnoDB table) +# (though reported as InnoDB bug, requires some ARCHIVE tests + +create table t1 (a int) engine=archive partition by hash(a); +show create table t1; +drop table t1; + +CREATE TABLE t1(id MEDIUMINT NOT NULL AUTO_INCREMENT, + f1 VARCHAR(25), + PRIMARY KEY(id)) ENGINE=ARCHIVE + PARTITION BY RANGE(id) + SUBPARTITION BY hash(id) subpartitions 2 + (PARTITION pa1 values less than (10), + PARTITION pa2 values less than (20), + PARTITION pa3 values less than (30), + PARTITION pa4 values less than (40), + PARTITION pa5 values less than (50), + PARTITION pa6 values less than (60), + PARTITION pa7 values less than (70), + PARTITION pa8 values less than (80), + PARTITION pa9 values less than (90), + PARTITION pa10 values less than (100), + PARTITION pa11 values less than MAXVALUE); + +--disable_query_log +let $n= 100; +while ($n) +{ + insert into t1 (f1) values (repeat('a',25)); + dec $n; +} +--enable_query_log + +show create table t1; +select count(*) from t1; +drop table t1; + diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 7234222b79ffc00dda056c50835d6858bbec6b84..76668a5b8104080155a84856758b49ad4a4abe92 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -1598,7 +1598,11 @@ int ha_partition::copy_partitions(ulonglong *copied, ulonglong *deleted) void ha_partition::update_create_info(HA_CREATE_INFO *create_info) { - m_file[0]->update_create_info(create_info); + info(HA_STATUS_AUTO); + + if (!(create_info->used_fields & HA_CREATE_USED_AUTO)) + create_info->auto_increment_value= stats.auto_increment_value; + create_info->data_file_name= create_info->index_file_name = NULL; return; } diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index 84298e785d190cb9c22806e90b41f64f3c872b70..967e315d4a4c020822defddd91f8336b37bb998d 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -357,7 +357,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc) { DBUG_RETURN(NULL); } - stats.auto_increment_value= archive_tmp.auto_increment; + stats.auto_increment_value= archive_tmp.auto_increment + 1; share->rows_recorded= (ha_rows)archive_tmp.rows; share->crashed= archive_tmp.dirty; azclose(&archive_tmp); @@ -586,9 +586,7 @@ int ha_archive::create(const char *name, TABLE *table_arg, DBUG_ENTER("ha_archive::create"); - stats.auto_increment_value= (create_info->auto_increment_value ? - create_info->auto_increment_value -1 : - (ulonglong) 0); + stats.auto_increment_value= create_info->auto_increment_value; for (uint key= 0; key < table_arg->s->keys; key++) { @@ -673,7 +671,8 @@ int ha_archive::create(const char *name, TABLE *table_arg, Yes you need to do this, because the starting value for the autoincrement may not be zero. */ - create_stream.auto_increment= stats.auto_increment_value; + create_stream.auto_increment= stats.auto_increment_value ? + stats.auto_increment_value - 1 : 0; if (azclose(&create_stream)) { error= errno; @@ -871,8 +870,8 @@ int ha_archive::write_row(uchar *buf) else { if (temp_auto > share->archive_write.auto_increment) - stats.auto_increment_value= share->archive_write.auto_increment= - temp_auto; + stats.auto_increment_value= + (share->archive_write.auto_increment= temp_auto) + 1; } } @@ -896,7 +895,7 @@ void ha_archive::get_auto_increment(ulonglong offset, ulonglong increment, ulonglong *first_value, ulonglong *nb_reserved_values) { - *nb_reserved_values= 1; + *nb_reserved_values= ULONGLONG_MAX; *first_value= share->archive_write.auto_increment + 1; } @@ -1315,7 +1314,8 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt) if (!rc) { share->rows_recorded= 0; - stats.auto_increment_value= share->archive_write.auto_increment= 0; + stats.auto_increment_value= 1; + share->archive_write.auto_increment= 0; my_bitmap_map *org_bitmap= dbug_tmp_use_all_columns(table, table->read_set); while (!(rc= get_row(&archive, table->record[0]))) @@ -1332,8 +1332,8 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt) (ulonglong) field->val_int(table->record[0] + field->offset(table->record[0])); if (share->archive_write.auto_increment < auto_value) - stats.auto_increment_value= share->archive_write.auto_increment= - auto_value; + stats.auto_increment_value= + (share->archive_write.auto_increment= auto_value) + 1; } } @@ -1418,18 +1418,9 @@ void ha_archive::update_create_info(HA_CREATE_INFO *create_info) DBUG_ENTER("ha_archive::update_create_info"); ha_archive::info(HA_STATUS_AUTO); - if (create_info->used_fields & HA_CREATE_USED_AUTO) + if (!(create_info->used_fields & HA_CREATE_USED_AUTO)) { - /* - Internally Archive keeps track of last used, not next used. - To make the output look like MyISAM we add 1 here. - - This is not completely compatible with MYISAM though, since - MyISAM will record on "SHOW CREATE TABLE" the last position, - where we will report the original position the table was - created with. - */ - create_info->auto_increment_value= stats.auto_increment_value + 1; + create_info->auto_increment_value= stats.auto_increment_value; } if (!(my_readlink(share->real_path, share->data_file_name, MYF(0)))) @@ -1494,7 +1485,7 @@ int ha_archive::info(uint flag) pthread_mutex_lock(&share->mutex); azflush(&archive, Z_SYNC_FLUSH); pthread_mutex_unlock(&share->mutex); - stats.auto_increment_value= archive.auto_increment; + stats.auto_increment_value= archive.auto_increment + 1; } DBUG_RETURN(0);