Below is the list of changes that have just been committed into a local
5.1 repository of tsmith. When tsmith 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-03-12 01:39:13-06:00, tsmith@stripped +12 -0
Apply InnoDB snapshot innodb-5.1-ss2360.
Fixes:
- Bug #34920: auto_increment resets to 1 on foreign key creation
We need to use/inherit the passed in autoinc counter for ALTER TABLE
statements too.
mysql-test/r/innodb-autoinc.result@stripped, 2008-03-12 01:34:25-06:00,
tsmith@stripped +89 -0
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2353:
branches/5.1: Change the InnoDB autoinc type to ulint64. For this added a
new typedef to univ.i (ib_ulonglong). Added checks for overflow and removed
the assertion where it crashed previously, since the type has now changed
to unsigned, it doesn't make sense to check for < 0. Added new tests, to
check for overflow, for the different INT types supported for both
signed and unsigned.
Revision r2359:
branches/5.1: Checked in the wrong test results in r2353. This commit has
the correct result set.
mysql-test/r/innodb-autoinc.result@stripped, 2008-03-12 01:34:25-06:00,
tsmith@stripped +0 -0
mysql-test/r/innodb.result@stripped, 2008-03-12 01:34:24-06:00, tsmith@stripped
+19 -0
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2345:
branches/5.1: Fix Bug# 34920. We need to use/inherit the passed in autoinc
counter for ALTER TABLE statements too.
mysql-test/t/innodb-autoinc.test@stripped, 2008-03-12 01:34:25-06:00,
tsmith@stripped +107 -0
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2353:
branches/5.1: Change the InnoDB autoinc type to ulint64. For this added a
new typedef to univ.i (ib_ulonglong). Added checks for overflow and removed
the assertion where it crashed previously, since the type has now changed
to unsigned, it doesn't make sense to check for < 0. Added new tests, to
check for overflow, for the different INT types supported for both
signed and unsigned.
mysql-test/t/innodb-autoinc.test@stripped, 2008-03-12 01:34:25-06:00,
tsmith@stripped +0 -0
mysql-test/t/innodb.test@stripped, 2008-03-12 01:34:24-06:00, tsmith@stripped +23
-0
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2345:
branches/5.1: Fix Bug# 34920. We need to use/inherit the passed in autoinc
counter for ALTER TABLE statements too.
storage/innobase/dict/dict0dict.c@stripped, 2008-03-12 01:34:24-06:00,
tsmith@stripped +3 -3
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2353:
branches/5.1: Change the InnoDB autoinc type to ulint64. For this added a
new typedef to univ.i (ib_ulonglong). Added checks for overflow and removed
the assertion where it crashed previously, since the type has now changed
to unsigned, it doesn't make sense to check for < 0. Added new tests, to
check for overflow, for the different INT types supported for both
signed and unsigned.
storage/innobase/handler/ha_innodb.cc@stripped, 2008-03-12 01:34:24-06:00,
tsmith@stripped +43 -16
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2345:
branches/5.1: Fix Bug# 34920. We need to use/inherit the passed in autoinc
counter for ALTER TABLE statements too.
Revision r2353:
branches/5.1: Change the InnoDB autoinc type to ulint64. For this added a
new typedef to univ.i (ib_ulonglong). Added checks for overflow and removed
the assertion where it crashed previously, since the type has now changed
to unsigned, it doesn't make sense to check for < 0. Added new tests, to
check for overflow, for the different INT types supported for both
signed and unsigned.
storage/innobase/handler/ha_innodb.h@stripped, 2008-03-12 01:34:24-06:00,
tsmith@stripped +1 -1
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2353:
branches/5.1: Change the InnoDB autoinc type to ulint64. For this added a
new typedef to univ.i (ib_ulonglong). Added checks for overflow and removed
the assertion where it crashed previously, since the type has now changed
to unsigned, it doesn't make sense to check for < 0. Added new tests, to
check for overflow, for the different INT types supported for both
signed and unsigned.
storage/innobase/include/dict0dict.h@stripped, 2008-03-12 01:34:24-06:00,
tsmith@stripped +3 -3
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2353:
branches/5.1: Change the InnoDB autoinc type to ulint64. For this added a
new typedef to univ.i (ib_ulonglong). Added checks for overflow and removed
the assertion where it crashed previously, since the type has now changed
to unsigned, it doesn't make sense to check for < 0. Added new tests, to
check for overflow, for the different INT types supported for both
signed and unsigned.
storage/innobase/include/dict0mem.h@stripped, 2008-03-12 01:34:24-06:00,
tsmith@stripped +1 -1
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2353:
branches/5.1: Change the InnoDB autoinc type to ulint64. For this added a
new typedef to univ.i (ib_ulonglong). Added checks for overflow and removed
the assertion where it crashed previously, since the type has now changed
to unsigned, it doesn't make sense to check for < 0. Added new tests, to
check for overflow, for the different INT types supported for both
signed and unsigned.
storage/innobase/include/row0sel.h@stripped, 2008-03-12 01:34:24-06:00,
tsmith@stripped +1 -1
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2353:
branches/5.1: Change the InnoDB autoinc type to ulint64. For this added a
new typedef to univ.i (ib_ulonglong). Added checks for overflow and removed
the assertion where it crashed previously, since the type has now changed
to unsigned, it doesn't make sense to check for < 0. Added new tests, to
check for overflow, for the different INT types supported for both
signed and unsigned.
storage/innobase/include/univ.i@stripped, 2008-03-12 01:34:25-06:00,
tsmith@stripped +3 -0
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2353:
branches/5.1: Change the InnoDB autoinc type to ulint64. For this added a
new typedef to univ.i (ib_ulonglong). Added checks for overflow and removed
the assertion where it crashed previously, since the type has now changed
to unsigned, it doesn't make sense to check for < 0. Added new tests, to
check for overflow, for the different INT types supported for both
signed and unsigned.
storage/innobase/row/row0sel.c@stripped, 2008-03-12 01:34:25-06:00,
tsmith@stripped +5 -5
Apply InnoDB snapshot innodb-5.1-ss2360.
Revision r2353:
branches/5.1: Change the InnoDB autoinc type to ulint64. For this added a
new typedef to univ.i (ib_ulonglong). Added checks for overflow and removed
the assertion where it crashed previously, since the type has now changed
to unsigned, it doesn't make sense to check for < 0. Added new tests, to
check for overflow, for the different INT types supported for both
signed and unsigned.
diff -Nrup a/mysql-test/r/innodb-autoinc.result b/mysql-test/r/innodb-autoinc.result
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/mysql-test/r/innodb-autoinc.result 2008-03-12 01:34:25 -06:00
@@ -0,0 +1,89 @@
+drop table if exists t1;
+CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (9223372036854775807, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1 c2
+9223372036854775807 NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 TINYINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (127, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1 c2
+127 NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10))
ENGINE=InnoDB;
+INSERT INTO t1 VALUES (255, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1 c2
+255 NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 SMALLINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (32767, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1 c2
+32767 NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10))
ENGINE=InnoDB;
+INSERT INTO t1 VALUES (65535, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1 c2
+65535 NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 MEDIUMINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (8388607, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1 c2
+8388607 NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10))
ENGINE=InnoDB;
+INSERT INTO t1 VALUES (16777215, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1 c2
+16777215 NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (2147483647, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1 c2
+2147483647 NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10))
ENGINE=InnoDB;
+INSERT INTO t1 VALUES (4294967295, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1 c2
+4294967295 NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (9223372036854775807, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1 c2
+9223372036854775807 NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10))
ENGINE=InnoDB;
+INSERT INTO t1 VALUES (18446744073709551615, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1 c2
+18446744073709551615 NULL
+DROP TABLE t1;
diff -Nrup a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result
--- a/mysql-test/r/innodb.result 2008-02-18 19:11:25 -07:00
+++ b/mysql-test/r/innodb.result 2008-03-12 01:34:24 -06:00
@@ -3244,3 +3244,22 @@ where table_schema='test' and table_name
table_comment data_free_is_set
this is a comment 1
drop table t1;
+CREATE TABLE t1 (
+c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+c2 VARCHAR(128) NOT NULL,
+PRIMARY KEY(c1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100;
+CREATE TABLE t2 (
+c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+c2 INT(10) UNSIGNED DEFAULT NULL,
+PRIMARY KEY(c1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200;
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
+AUTO_INCREMENT
+200
+ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1);
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
+AUTO_INCREMENT
+200
+DROP TABLE t2;
+DROP TABLE t1;
diff -Nrup a/mysql-test/t/innodb-autoinc.test b/mysql-test/t/innodb-autoinc.test
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/mysql-test/t/innodb-autoinc.test 2008-03-12 01:34:25 -06:00
@@ -0,0 +1,107 @@
+-- source include/have_innodb.inc
+# embedded server ignores 'delayed', so skip this
+-- source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+#
+# Bug #34335
+#
+CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (9223372036854775807, null);
+-- error ER_DUP_ENTRY,1062
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+## Test AUTOINC overflow
+##
+
+# TINYINT
+CREATE TABLE t1 (c1 TINYINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (127, null);
+-- error ER_DUP_ENTRY,1062
+-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10))
ENGINE=InnoDB;
+INSERT INTO t1 VALUES (255, null);
+-- error ER_DUP_ENTRY,1062
+-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# SMALLINT
+#
+CREATE TABLE t1 (c1 SMALLINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (32767, null);
+-- error ER_DUP_ENTRY,1062
+-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10))
ENGINE=InnoDB;
+INSERT INTO t1 VALUES (65535, null);
+-- error ER_DUP_ENTRY,1062
+-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# MEDIUMINT
+#
+CREATE TABLE t1 (c1 MEDIUMINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (8388607, null);
+-- error ER_DUP_ENTRY,1062
+-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10))
ENGINE=InnoDB;
+INSERT INTO t1 VALUES (16777215, null);
+-- error ER_DUP_ENTRY,1062
+-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# INT
+#
+CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (2147483647, null);
+-- error ER_DUP_ENTRY,1062
+-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10))
ENGINE=InnoDB;
+INSERT INTO t1 VALUES (4294967295, null);
+-- error ER_DUP_ENTRY,1062
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# BIGINT
+#
+CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (9223372036854775807, null);
+-- error ER_DUP_ENTRY,1062
+-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10))
ENGINE=InnoDB;
+INSERT INTO t1 VALUES (18446744073709551615, null);
+-- error ER_AUTOINC_READ_FAILED,1467
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
diff -Nrup a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test
--- a/mysql-test/t/innodb.test 2008-02-18 19:11:25 -07:00
+++ b/mysql-test/t/innodb.test 2008-03-12 01:34:24 -06:00
@@ -2436,6 +2436,29 @@ select table_comment, data_free > 0 as d
where table_schema='test' and table_name = 't1';
drop table t1;
+#
+# Bug 34920 test
+#
+CONNECTION default;
+CREATE TABLE t1 (
+ c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ c2 VARCHAR(128) NOT NULL,
+ PRIMARY KEY(c1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100;
+
+CREATE TABLE t2 (
+ c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ c2 INT(10) UNSIGNED DEFAULT NULL,
+ PRIMARY KEY(c1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200;
+
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
+ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1);
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
+DROP TABLE t2;
+DROP TABLE t1;
+# End 34920 test
+
#######################################################################
# #
# Please, DO NOT TOUCH this file as well as the innodb.result file. #
diff -Nrup a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c
--- a/storage/innobase/dict/dict0dict.c 2007-11-20 12:02:16 -07:00
+++ b/storage/innobase/dict/dict0dict.c 2008-03-12 01:34:24 -06:00
@@ -429,7 +429,7 @@ void
dict_table_autoinc_initialize(
/*==========================*/
dict_table_t* table, /* in: table */
- ib_longlong value) /* in: next value to assign to a row */
+ ib_ulonglong value) /* in: next value to assign to a row */
{
ut_ad(mutex_own(&table->autoinc_mutex));
@@ -441,7 +441,7 @@ dict_table_autoinc_initialize(
Reads the next autoinc value (== autoinc counter value), 0 if not yet
initialized. */
-ib_longlong
+ib_ulonglong
dict_table_autoinc_read(
/*====================*/
/* out: value for a new row, or 0 */
@@ -470,7 +470,7 @@ dict_table_autoinc_update(
/*======================*/
dict_table_t* table, /* in: table */
- ib_longlong value) /* in: value which was assigned to a row */
+ ib_ulonglong value) /* in: value which was assigned to a row */
{
if (table->autoinc_inited && value > table->autoinc) {
diff -Nrup a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
--- a/storage/innobase/handler/ha_innodb.cc 2008-02-18 19:11:25 -07:00
+++ b/storage/innobase/handler/ha_innodb.cc 2008-03-12 01:34:24 -06:00
@@ -3545,7 +3545,19 @@ no_commit:
if (auto_inc > prebuilt->last_value) {
set_max_autoinc:
ut_a(prebuilt->table->autoinc_increment > 0);
- auto_inc += prebuilt->table->autoinc_increment;
+
+ ulonglong have;
+ ulonglong need;
+
+ /* Check for overflow conditions. */
+ need = prebuilt->table->autoinc_increment;
+ have = ~0x0ULL - auto_inc;
+
+ if (have < need) {
+ need = have;
+ }
+
+ auto_inc += need;
err = innobase_set_max_autoinc(auto_inc);
@@ -5105,8 +5117,15 @@ ha_innobase::create(
DBUG_ASSERT(innobase_table != 0);
- if ((create_info->used_fields & HA_CREATE_USED_AUTO) &&
- (create_info->auto_increment_value != 0)) {
+ /* Note: We can't call update_thd() as prebuilt will not be
+ setup at this stage and so we use thd. */
+
+ /* We need to copy the AUTOINC value from the old table if
+ this is an ALTER TABLE. */
+
+ if (((create_info->used_fields & HA_CREATE_USED_AUTO)
+ || thd_sql_command(thd) == SQLCOM_ALTER_TABLE)
+ && create_info->auto_increment_value != 0) {
/* Query was ALTER TABLE...AUTO_INCREMENT = x; or
CREATE TABLE ...AUTO_INCREMENT = x; Find out a table
@@ -5856,7 +5875,7 @@ ha_innobase::info(
}
if (flag & HA_STATUS_AUTO && table->found_next_number_field) {
- longlong auto_inc;
+ ulonglong auto_inc;
int ret;
/* The following function call can the first time fail in
@@ -7207,9 +7226,9 @@ ha_innobase::innobase_read_and_init_auto
/*=========================================*/
/* out: 0 or generic MySQL
error code */
- longlong* value) /* out: the autoinc value */
+ ulonglong* value) /* out: the autoinc value */
{
- longlong auto_inc;
+ ulonglong auto_inc;
ibool stmt_start;
int mysql_error = 0;
dict_table_t* innodb_table = prebuilt->table;
@@ -7260,7 +7279,9 @@ ha_innobase::innobase_read_and_init_auto
index, autoinc_col_name, &auto_inc);
if (error == DB_SUCCESS) {
- ++auto_inc;
+ if (auto_inc < ~0x0ULL) {
+ ++auto_inc;
+ }
dict_table_autoinc_initialize(innodb_table, auto_inc);
} else {
ut_print_timestamp(stderr);
@@ -7313,14 +7334,14 @@ ha_innobase::innobase_get_auto_increment
error = innobase_autoinc_lock();
if (error == DB_SUCCESS) {
- ib_longlong autoinc;
+ ulonglong autoinc;
/* Determine the first value of the interval */
autoinc = dict_table_autoinc_read(prebuilt->table);
/* We need to initialize the AUTO-INC value, for
that we release all locks.*/
- if (autoinc <= 0) {
+ if (autoinc == 0) {
trx_t* trx;
trx = prebuilt->trx;
@@ -7339,14 +7360,11 @@ ha_innobase::innobase_get_auto_increment
mysql_error = innobase_read_and_init_auto_inc(
&autoinc);
- if (!mysql_error) {
- /* Should have read the proper value */
- ut_a(autoinc > 0);
- } else {
+ if (mysql_error) {
error = DB_ERROR;
}
} else {
- *value = (ulonglong) autoinc;
+ *value = autoinc;
}
/* A deadlock error during normal processing is OK
and can be ignored. */
@@ -7431,10 +7449,19 @@ ha_innobase::get_auto_increment(
/* With old style AUTOINC locking we only update the table's
AUTOINC counter after attempting to insert the row. */
if (innobase_autoinc_lock_mode != AUTOINC_OLD_STYLE_LOCKING) {
+ ulonglong have;
+ ulonglong need;
+
+ /* Check for overflow conditions. */
+ need = *nb_reserved_values * increment;
+ have = ~0x0ULL - *first_value;
+
+ if (have < need) {
+ need = have;
+ }
/* Compute the last value in the interval */
- prebuilt->last_value = *first_value +
- (*nb_reserved_values * increment);
+ prebuilt->last_value = *first_value + need;
ut_a(prebuilt->last_value >= *first_value);
diff -Nrup a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h
--- a/storage/innobase/handler/ha_innodb.h 2007-11-06 15:23:45 -07:00
+++ b/storage/innobase/handler/ha_innodb.h 2008-03-12 01:34:24 -06:00
@@ -72,7 +72,7 @@ class ha_innobase: public handler
int update_thd(THD* thd);
int change_active_index(uint keynr);
int general_fetch(uchar* buf, uint direction, uint match_mode);
- int innobase_read_and_init_auto_inc(longlong* ret);
+ int innobase_read_and_init_auto_inc(ulonglong* ret);
ulong innobase_autoinc_lock();
ulong innobase_set_max_autoinc(ulonglong auto_inc);
ulong innobase_reset_autoinc(ulonglong auto_inc);
diff -Nrup a/storage/innobase/include/dict0dict.h b/storage/innobase/include/dict0dict.h
--- a/storage/innobase/include/dict0dict.h 2007-08-24 19:14:48 -06:00
+++ b/storage/innobase/include/dict0dict.h 2008-03-12 01:34:24 -06:00
@@ -185,12 +185,12 @@ void
dict_table_autoinc_initialize(
/*==========================*/
dict_table_t* table, /* in: table */
- ib_longlong value); /* in: next value to assign to a row */
+ ib_ulonglong value); /* in: next value to assign to a row */
/************************************************************************
Reads the next autoinc value (== autoinc counter value), 0 if not yet
initialized. */
-ib_longlong
+ib_ulonglong
dict_table_autoinc_read(
/*====================*/
/* out: value for a new row, or 0 */
@@ -204,7 +204,7 @@ dict_table_autoinc_update(
/*======================*/
dict_table_t* table, /* in: table */
- ib_longlong value); /* in: value which was assigned to a row */
+ ib_ulonglong value); /* in: value which was assigned to a row */
/************************************************************************
Release the autoinc lock.*/
diff -Nrup a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h
--- a/storage/innobase/include/dict0mem.h 2007-08-25 03:55:35 -06:00
+++ b/storage/innobase/include/dict0mem.h 2008-03-12 01:34:24 -06:00
@@ -409,7 +409,7 @@ struct dict_table_struct{
/* TRUE if the autoinc counter has been
inited; MySQL gets the init value by executing
SELECT MAX(auto inc column) */
- ib_longlong autoinc;/* autoinc counter value to give to the
+ ib_ulonglong autoinc;/* autoinc counter value to give to the
next inserted row */
ib_longlong autoinc_increment;
diff -Nrup a/storage/innobase/include/row0sel.h b/storage/innobase/include/row0sel.h
--- a/storage/innobase/include/row0sel.h 2007-08-24 19:14:48 -06:00
+++ b/storage/innobase/include/row0sel.h 2008-03-12 01:34:24 -06:00
@@ -181,7 +181,7 @@ row_search_max_autoinc(
error code */
dict_index_t* index, /* in: index to search */
const char* col_name, /* in: autoinc column name */
- ib_longlong* value); /* out: AUTOINC value read */
+ ib_ulonglong* value); /* out: AUTOINC value read */
/* A structure for caching column values for prefetched rows */
struct sel_buf_struct{
diff -Nrup a/storage/innobase/include/univ.i b/storage/innobase/include/univ.i
--- a/storage/innobase/include/univ.i 2007-11-06 16:33:49 -07:00
+++ b/storage/innobase/include/univ.i 2008-03-12 01:34:25 -06:00
@@ -212,8 +212,11 @@ typedef long int lint;
#ifdef __WIN__
typedef __int64 ib_longlong;
+typedef unsigned __int64 ib_ulonglong;
#else
+/* Note: longlong and ulonglong come from MySQL headers. */
typedef longlong ib_longlong;
+typedef ulonglong ib_ulonglong;
#endif
typedef unsigned long long int ullint;
diff -Nrup a/storage/innobase/row/row0sel.c b/storage/innobase/row/row0sel.c
--- a/storage/innobase/row/row0sel.c 2007-11-06 16:33:49 -07:00
+++ b/storage/innobase/row/row0sel.c 2008-03-12 01:34:25 -06:00
@@ -4529,7 +4529,7 @@ row_search_check_if_query_cache_permitte
Read the AUTOINC column from the current row. If the value is less than
0 and the type is not unsigned then we reset the value to 0. */
static
-ib_longlong
+ib_ulonglong
row_search_autoinc_read_column(
/*===========================*/
/* out: value read from the column */
@@ -4540,7 +4540,7 @@ row_search_autoinc_read_column(
{
ulint len;
const byte* data;
- ib_longlong value;
+ ib_ulonglong value;
mem_heap_t* heap = NULL;
/* Our requirement is that dest should be word aligned. */
byte dest[sizeof(value)];
@@ -4567,7 +4567,7 @@ row_search_autoinc_read_column(
and that dest is word aligned. */
switch (len) {
case 8:
- value = *(ib_longlong*) dest;
+ value = *(ib_ulonglong*) dest;
break;
case 4:
@@ -4595,7 +4595,7 @@ row_search_autoinc_read_column(
mem_heap_free(heap);
}
- if (!unsigned_type && value < 0) {
+ if (!unsigned_type && (ib_longlong) value < 0) {
value = 0;
}
@@ -4634,7 +4634,7 @@ row_search_max_autoinc(
column name can't be found in index */
dict_index_t* index, /* in: index to search */
const char* col_name, /* in: name of autoinc column */
- ib_longlong* value) /* out: AUTOINC value read */
+ ib_ulonglong* value) /* out: AUTOINC value read */
{
ulint i;
ulint n_cols;
| Thread |
|---|
| • bk commit into 5.1 tree (tsmith:1.2555) BUG#34920 | tim | 12 Mar |