Bug #32247 Test reports wrong value of "AUTO_INCREMENT" (on a partitioned InnoDB table).

ha_partition::update_create_info() just calls update_create_info
of a first partition, so only get the autoincrement maximum
of the first partition, so SHOW CREATE TABLE can show
small AUTO_INCREMENT parameters.
Fixed by implementing ha_partition::update_create_info() in a way
other handlers work.
HA_ARCHIVE:stats.auto_increment handling made consistent with other engines
parent bc08ff04
......@@ -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);
......
......@@ -1291,4 +1291,19 @@ t1 CREATE TABLE `t1` (
`b` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (b) (PARTITION p1 VALUES LESS THAN (10) ENGINE = MyISAM, PARTITION p2 VALUES LESS THAN (20) ENGINE = MyISAM) */
drop table t1, t2;
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
......@@ -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
......
......@@ -1528,4 +1528,25 @@ PARTITION BY RANGE (b) (
show create table t1;
drop table t1, t2;
#
# 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
......@@ -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;
return;
}
......
......@@ -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);
......
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