Commit ae439e4b authored by sunny's avatar sunny

branches/5.1: Fix BUG#49032 - auto_increment field does not initialize to last...

branches/5.1: Fix BUG#49032 - auto_increment field does not initialize to last value in InnoDB Storage Engine.

We use the appropriate function to read the column value for non-integer
autoinc column types, namely float and double.

rb://208. Approved by Marko.
parent 2dc8cfb8
......@@ -1126,3 +1126,31 @@ SELECT * FROM T1;
c1 c2
10 0
DROP TABLE T1;
DROP TABLE IF EXISTS T1;
Warnings:
Note 1051 Unknown table 'T1'
CREATE TABLE T1(C1 DOUBLE AUTO_INCREMENT KEY, C2 CHAR(10)) ENGINE=InnoDB;
INSERT INTO T1(C1, C2) VALUES (1, 'innodb'), (3, 'innodb');
INSERT INTO T1(C1) VALUES ('innodb');
Warnings:
Warning 1265 Data truncated for column 'C1' at row 1
SHOW CREATE TABLE T1;
Table Create Table
T1 CREATE TABLE `T1` (
`C1` double NOT NULL AUTO_INCREMENT,
`C2` char(10) DEFAULT NULL,
PRIMARY KEY (`C1`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
DROP TABLE T1;
CREATE TABLE T1(C1 FLOAT AUTO_INCREMENT KEY, C2 CHAR(10)) ENGINE=InnoDB;
INSERT INTO T1(C1, C2) VALUES (1, 'innodb'), (3, 'innodb');
INSERT INTO T1(C1) VALUES ('innodb');
Warnings:
Warning 1265 Data truncated for column 'C1' at row 1
SHOW CREATE TABLE T1;
Table Create Table
T1 CREATE TABLE `T1` (
`C1` float NOT NULL AUTO_INCREMENT,
`C2` char(10) DEFAULT NULL,
PRIMARY KEY (`C1`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
......@@ -620,3 +620,23 @@ SHOW CREATE TABLE T1;
INSERT INTO T1 (c2) values (0);
SELECT * FROM T1;
DROP TABLE T1;
##
# 49032: Use the correct function to read the AUTOINC column value
#
DROP TABLE IF EXISTS T1;
CREATE TABLE T1(C1 DOUBLE AUTO_INCREMENT KEY, C2 CHAR(10)) ENGINE=InnoDB;
INSERT INTO T1(C1, C2) VALUES (1, 'innodb'), (3, 'innodb');
# Restart the server
-- source include/restart_mysqld.inc
INSERT INTO T1(C1) VALUES ('innodb');
SHOW CREATE TABLE T1;
DROP TABLE T1;
CREATE TABLE T1(C1 FLOAT AUTO_INCREMENT KEY, C2 CHAR(10)) ENGINE=InnoDB;
INSERT INTO T1(C1, C2) VALUES (1, 'innodb'), (3, 'innodb');
# Restart the server
-- source include/restart_mysqld.inc
INSERT INTO T1(C1) VALUES ('innodb');
SHOW CREATE TABLE T1;
......@@ -4514,6 +4514,7 @@ row_search_autoinc_read_column(
dict_index_t* index, /* in: index to read from */
const rec_t* rec, /* in: current rec */
ulint col_no, /* in: column number */
ulint mtype, /*!< in: column main type */
ibool unsigned_type) /* in: signed or unsigned flag */
{
ulint len;
......@@ -4537,7 +4538,22 @@ row_search_autoinc_read_column(
ut_a(len != UNIV_SQL_NULL);
ut_a(len <= sizeof value);
switch (mtype) {
case DATA_INT:
value = mach_read_int_type(data, len, unsigned_type);
break;
case DATA_FLOAT:
value = mach_float_read(data);
break;
case DATA_DOUBLE:
value = mach_double_read(data);
break;
default:
ut_error;
}
if (UNIV_LIKELY_NULL(heap)) {
mem_heap_free(heap);
......@@ -4625,7 +4641,8 @@ row_search_max_autoinc(
dfield->col->prtype & DATA_UNSIGNED);
*value = row_search_autoinc_read_column(
index, rec, i, unsigned_type);
index, rec, i,
dfield->col->mtype, unsigned_type);
}
}
......
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