Commit 48519303 authored by Marko Mäkelä's avatar Marko Mäkelä

Bug#14758405: ALTER TABLE: ADDING SERIAL NULL DATATYPE: ASSERTION:

LEN <= SIZEOF(ULONGLONG)

This bug was caught in the WL#6255 ALTER TABLE...ADD COLUMN in MySQL
5.6, but there is a bug in all InnoDB versions that support
auto-increment columns.

row_search_autoinc_read_column(): When reading the maximum value of
the auto-increment column, and the column only contains NULL values,
return 0. This corresponds to the case when the table is empty in
row_search_max_autoinc().

rb:1415 approved by Sunny Bains
parent c2ab8441
......@@ -4660,14 +4660,18 @@ row_search_autoinc_read_column(
/* TODO: We have to cast away the const of rec for now. This needs
to be fixed later.*/
offsets = rec_get_offsets(
(rec_t*) rec, index, offsets, ULINT_UNDEFINED, &heap);
(rec_t*) rec, index, offsets, col_no + 1, &heap);
if (rec_offs_nth_sql_null(offsets, col_no)) {
/* There is no non-NULL value in the auto-increment column. */
value = 0;
goto func_exit;
}
/* TODO: We have to cast away the const of rec for now. This needs
to be fixed later.*/
data = rec_get_nth_field((rec_t*)rec, offsets, col_no, &len);
ut_a(len != UNIV_SQL_NULL);
switch (mtype) {
case DATA_INT:
ut_a(len <= sizeof value);
......@@ -4688,15 +4692,16 @@ row_search_autoinc_read_column(
ut_error;
}
if (UNIV_LIKELY_NULL(heap)) {
mem_heap_free(heap);
}
/* We assume that the autoinc counter can't be negative. */
if (!unsigned_type && (ib_longlong) value < 0) {
value = 0;
}
func_exit:
if (UNIV_LIKELY_NULL(heap)) {
mem_heap_free(heap);
}
return(value);
}
......
2012-10-18 The InnoDB Team
* row/row0sel.c:
Fix Bug#14758405: ALTER TABLE: ADDING SERIAL NULL DATATYPE: ASSERTION:
LEN <= SIZEOF(ULONGLONG)
2012-10-16 The InnoDB Team
* dict/dict0dict.c, handler/handler0alter.cc, include/dict0dict.h:
......
......@@ -4833,11 +4833,15 @@ row_search_autoinc_read_column(
rec_offs_init(offsets_);
offsets = rec_get_offsets(rec, index, offsets, ULINT_UNDEFINED, &heap);
offsets = rec_get_offsets(rec, index, offsets, col_no + 1, &heap);
data = rec_get_nth_field(rec, offsets, col_no, &len);
if (rec_offs_nth_sql_null(offsets, col_no)) {
/* There is no non-NULL value in the auto-increment column. */
value = 0;
goto func_exit;
}
ut_a(len != UNIV_SQL_NULL);
data = rec_get_nth_field(rec, offsets, col_no, &len);
switch (mtype) {
case DATA_INT:
......@@ -4859,14 +4863,15 @@ row_search_autoinc_read_column(
ut_error;
}
if (UNIV_LIKELY_NULL(heap)) {
mem_heap_free(heap);
}
if (!unsigned_type && (ib_int64_t) value < 0) {
value = 0;
}
func_exit:
if (UNIV_LIKELY_NULL(heap)) {
mem_heap_free(heap);
}
return(value);
}
......
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