Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
e52e64ac
Commit
e52e64ac
authored
Dec 13, 2010
by
Sergey Glukhov
Browse files
Options
Browse Files
Download
Plain Diff
5.1-bugteam->5.5-bugteam merge
parents
8394b6a2
1faf910e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
63 deletions
+76
-63
mysql-test/r/auto_increment.result
mysql-test/r/auto_increment.result
+21
-0
mysql-test/suite/innodb/r/innodb-autoinc.result
mysql-test/suite/innodb/r/innodb-autoinc.result
+6
-12
mysql-test/suite/innodb/t/innodb-autoinc.test
mysql-test/suite/innodb/t/innodb-autoinc.test
+6
-43
mysql-test/t/auto_increment.test
mysql-test/t/auto_increment.test
+21
-0
sql/handler.cc
sql/handler.cc
+22
-8
No files found.
mysql-test/r/auto_increment.result
View file @
e52e64ac
...
@@ -476,3 +476,24 @@ SELECT a FROM t2;
...
@@ -476,3 +476,24 @@ SELECT a FROM t2;
a
a
2
2
DROP TABLE t1, t2;
DROP TABLE t1, t2;
#
# Bug#39828 autoinc wraps around when offset and increment > 1
#
CREATE TABLE t1 (c1 BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) engine=MyISAM;
INSERT INTO t1 VALUES(1);
INSERT INTO t1 VALUES (18446744073709551601);
SET @@SESSION.AUTO_INCREMENT_INCREMENT=10;
SELECT @@SESSION.AUTO_INCREMENT_OFFSET;
@@SESSION.AUTO_INCREMENT_OFFSET
1
INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
ERROR 22003: Out of range value for column 't1' at row 167
SELECT * FROM t1;
c1
1
18446744073709551601
18446744073709551611
SET @@SESSION.AUTO_INCREMENT_INCREMENT=default;
SET @@SESSION.AUTO_INCREMENT_OFFSET=default;
DROP TABLE t1;
End of 5.1 tests
mysql-test/suite/innodb/r/innodb-autoinc.result
View file @
e52e64ac
...
@@ -471,17 +471,12 @@ SHOW VARIABLES LIKE "%auto_inc%";
...
@@ -471,17 +471,12 @@ SHOW VARIABLES LIKE "%auto_inc%";
Variable_name Value
Variable_name Value
auto_increment_increment 2
auto_increment_increment 2
auto_increment_offset 10
auto_increment_offset 10
INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
ERROR HY000: Failed to read auto-increment value from storage engine
SELECT * FROM t1;
SELECT * FROM t1;
c1
c1
1
1
18446744073709551603
18446744073709551603
18446744073709551604
18446744073709551606
18446744073709551608
18446744073709551610
18446744073709551612
18446744073709551614
DROP TABLE t1;
DROP TABLE t1;
SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
SET @@INSERT_ID=1;
SET @@INSERT_ID=1;
...
@@ -504,13 +499,12 @@ SHOW VARIABLES LIKE "%auto_inc%";
...
@@ -504,13 +499,12 @@ SHOW VARIABLES LIKE "%auto_inc%";
Variable_name Value
Variable_name Value
auto_increment_increment 5
auto_increment_increment 5
auto_increment_offset 7
auto_increment_offset 7
INSERT INTO t1 VALUES (NULL),(NULL);
INSERT INTO t1 VALUES (NULL),(NULL), (NULL);
ERROR HY000: Failed to read auto-increment value from storage engine
SELECT * FROM t1;
SELECT * FROM t1;
c1
c1
1
1
18446744073709551603
18446744073709551603
18446744073709551607
18446744073709551612
DROP TABLE t1;
DROP TABLE t1;
SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
SET @@INSERT_ID=1;
SET @@INSERT_ID=1;
...
@@ -572,12 +566,12 @@ SHOW VARIABLES LIKE "%auto_inc%";
...
@@ -572,12 +566,12 @@ SHOW VARIABLES LIKE "%auto_inc%";
Variable_name Value
Variable_name Value
auto_increment_increment 65535
auto_increment_increment 65535
auto_increment_offset 65535
auto_increment_offset 65535
INSERT INTO t1 VALUES (NULL);
INSERT INTO t1 VALUES (NULL),(NULL);
ERROR 22003: Out of range value for column 't1' at row 167
SELECT * FROM t1;
SELECT * FROM t1;
c1
c1
1
1
18446744073709551610
18446744073709551610
18446744073709551615
DROP TABLE t1;
DROP TABLE t1;
SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
SET @@INSERT_ID=1;
SET @@INSERT_ID=1;
...
...
mysql-test/suite/innodb/t/innodb-autoinc.test
View file @
e52e64ac
...
@@ -293,21 +293,8 @@ INSERT INTO t1 VALUES (18446744073709551603); #-- 2^64 - 13
...
@@ -293,21 +293,8 @@ INSERT INTO t1 VALUES (18446744073709551603); #-- 2^64 - 13
SELECT
*
FROM
t1
;
SELECT
*
FROM
t1
;
SET
@@
SESSION
.
AUTO_INCREMENT_INCREMENT
=
2
,
@@
SESSION
.
AUTO_INCREMENT_OFFSET
=
10
;
SET
@@
SESSION
.
AUTO_INCREMENT_INCREMENT
=
2
,
@@
SESSION
.
AUTO_INCREMENT_OFFSET
=
10
;
SHOW
VARIABLES
LIKE
"%auto_inc%"
;
SHOW
VARIABLES
LIKE
"%auto_inc%"
;
# This should fail because of overflow but it doesn't, it seems to be
--
error
ER_AUTOINC_READ_FAILED
# a MySQL server bug. It wraps around to 0 for the last value.
INSERT
INTO
t1
VALUES
(
NULL
),(
NULL
),(
NULL
),(
NULL
),(
NULL
),(
NULL
),(
NULL
);
# See MySQL Bug# 39828
#
# Instead of wrapping around, it asserts when MySQL is compiled --with-debug
# (see sql/handler.cc:handler::update_auto_increment()). Don't test for
# overflow until Bug #39828 is fixed.
#
# Since this asserts when compiled --with-debug, we can't properly test this
# until Bug #39828 is fixed. For now, this test is meaningless.
#if Bug #39828 is fixed
#INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
#else
INSERT
INTO
t1
VALUES
(
NULL
),(
NULL
),(
NULL
),(
NULL
),(
NULL
),(
NULL
);
#endif
SELECT
*
FROM
t1
;
SELECT
*
FROM
t1
;
DROP
TABLE
t1
;
DROP
TABLE
t1
;
...
@@ -325,20 +312,8 @@ INSERT INTO t1 VALUES (18446744073709551603); #-- 2^64 - 13
...
@@ -325,20 +312,8 @@ INSERT INTO t1 VALUES (18446744073709551603); #-- 2^64 - 13
SELECT
*
FROM
t1
;
SELECT
*
FROM
t1
;
SET
@@
SESSION
.
AUTO_INCREMENT_INCREMENT
=
5
,
@@
SESSION
.
AUTO_INCREMENT_OFFSET
=
7
;
SET
@@
SESSION
.
AUTO_INCREMENT_INCREMENT
=
5
,
@@
SESSION
.
AUTO_INCREMENT_OFFSET
=
7
;
SHOW
VARIABLES
LIKE
"%auto_inc%"
;
SHOW
VARIABLES
LIKE
"%auto_inc%"
;
# This should fail because of overflow but it doesn't. It fails with
--
error
ER_AUTOINC_READ_FAILED
# a duplicate entry message because of a MySQL server bug, it wraps
INSERT
INTO
t1
VALUES
(
NULL
),(
NULL
),
(
NULL
);
# around. See MySQL Bug# 39828, once MySQL fix the bug we can replace
# the ER_DUP_ENTRY, 1062 below with the appropriate error message
#
# Since this asserts when compiled --with-debug, we can't properly test this
# until Bug #39828 is fixed. For now, this test is meaningless.
#if Bug #39828 is fixed
# Still need to fix this error code, error should mention overflow
#-- error ER_DUP_ENTRY,1062
#INSERT INTO t1 VALUES (NULL),(NULL), (NULL);
#else
INSERT
INTO
t1
VALUES
(
NULL
),(
NULL
);
#endif
SELECT
*
FROM
t1
;
SELECT
*
FROM
t1
;
DROP
TABLE
t1
;
DROP
TABLE
t1
;
...
@@ -376,20 +351,8 @@ INSERT INTO t1 VALUES (18446744073709551610); #-- 2^64 - 2
...
@@ -376,20 +351,8 @@ INSERT INTO t1 VALUES (18446744073709551610); #-- 2^64 - 2
SELECT
*
FROM
t1
;
SELECT
*
FROM
t1
;
SET
@@
SESSION
.
AUTO_INCREMENT_INCREMENT
=
1152921504606846976
,
@@
SESSION
.
AUTO_INCREMENT_OFFSET
=
1152921504606846976
;
SET
@@
SESSION
.
AUTO_INCREMENT_INCREMENT
=
1152921504606846976
,
@@
SESSION
.
AUTO_INCREMENT_OFFSET
=
1152921504606846976
;
SHOW
VARIABLES
LIKE
"%auto_inc%"
;
SHOW
VARIABLES
LIKE
"%auto_inc%"
;
# This should fail because of overflow but it doesn't. It wraps around
--
error
ER_WARN_DATA_OUT_OF_RANGE
# and the autoinc values look bogus too.
INSERT
INTO
t1
VALUES
(
NULL
),(
NULL
);
# See MySQL Bug# 39828, once MySQL fix the bug we can enable the error
# code expected test.
# -- error ER_AUTOINC_READ_FAILED,1467
#
# Since this asserts when compiled --with-debug, we can't properly test this
# until Bug #39828 is fixed. For now, this test is meaningless.
#if Bug #39828 is fixed
#-- error ER_AUTOINC_READ_FAILED,1467
#INSERT INTO t1 VALUES (NULL),(NULL);
#else
INSERT
INTO
t1
VALUES
(
NULL
);
#endif
SELECT
*
FROM
t1
;
SELECT
*
FROM
t1
;
DROP
TABLE
t1
;
DROP
TABLE
t1
;
...
...
mysql-test/t/auto_increment.test
View file @
e52e64ac
...
@@ -342,3 +342,24 @@ SELECT a FROM t2;
...
@@ -342,3 +342,24 @@ SELECT a FROM t2;
DROP
TABLE
t1
,
t2
;
DROP
TABLE
t1
,
t2
;
--
echo
#
--
echo
# Bug#39828 autoinc wraps around when offset and increment > 1
--
echo
#
CREATE
TABLE
t1
(
c1
BIGINT
UNSIGNED
AUTO_INCREMENT
,
PRIMARY
KEY
(
c1
))
engine
=
MyISAM
;
INSERT
INTO
t1
VALUES
(
1
);
INSERT
INTO
t1
VALUES
(
18446744073709551601
);
SET
@@
SESSION
.
AUTO_INCREMENT_INCREMENT
=
10
;
SELECT
@@
SESSION
.
AUTO_INCREMENT_OFFSET
;
--
error
ER_WARN_DATA_OUT_OF_RANGE
INSERT
INTO
t1
VALUES
(
NULL
),
(
NULL
),
(
NULL
);
SELECT
*
FROM
t1
;
SET
@@
SESSION
.
AUTO_INCREMENT_INCREMENT
=
default
;
SET
@@
SESSION
.
AUTO_INCREMENT_OFFSET
=
default
;
DROP
TABLE
t1
;
--
echo
End
of
5.1
tests
sql/handler.cc
View file @
e52e64ac
...
@@ -2209,7 +2209,8 @@ int handler::read_first_row(uchar * buf, uint primary_key)
...
@@ -2209,7 +2209,8 @@ int handler::read_first_row(uchar * buf, uint primary_key)
computes the lowest number
computes the lowest number
- strictly greater than "nr"
- strictly greater than "nr"
- of the form: auto_increment_offset + N * auto_increment_increment
- of the form: auto_increment_offset + N * auto_increment_increment
If overflow happened then return MAX_ULONGLONG value as an
indication of overflow.
In most cases increment= offset= 1, in which case we get:
In most cases increment= offset= 1, in which case we get:
@verbatim 1,2,3,4,5,... @endverbatim
@verbatim 1,2,3,4,5,... @endverbatim
If increment=10 and offset=5 and previous number is 1, we get:
If increment=10 and offset=5 and previous number is 1, we get:
...
@@ -2218,13 +2219,23 @@ int handler::read_first_row(uchar * buf, uint primary_key)
...
@@ -2218,13 +2219,23 @@ int handler::read_first_row(uchar * buf, uint primary_key)
inline
ulonglong
inline
ulonglong
compute_next_insert_id
(
ulonglong
nr
,
struct
system_variables
*
variables
)
compute_next_insert_id
(
ulonglong
nr
,
struct
system_variables
*
variables
)
{
{
const
ulonglong
save_nr
=
nr
;
if
(
variables
->
auto_increment_increment
==
1
)
if
(
variables
->
auto_increment_increment
==
1
)
return
(
nr
+
1
);
// optimization of the formula below
nr
=
nr
+
1
;
// optimization of the formula below
nr
=
(((
nr
+
variables
->
auto_increment_increment
-
else
variables
->
auto_increment_offset
))
/
{
(
ulonglong
)
variables
->
auto_increment_increment
);
nr
=
(((
nr
+
variables
->
auto_increment_increment
-
return
(
nr
*
(
ulonglong
)
variables
->
auto_increment_increment
+
variables
->
auto_increment_offset
))
/
variables
->
auto_increment_offset
);
(
ulonglong
)
variables
->
auto_increment_increment
);
nr
=
(
nr
*
(
ulonglong
)
variables
->
auto_increment_increment
+
variables
->
auto_increment_offset
);
}
if
(
unlikely
(
nr
<=
save_nr
))
return
ULONGLONG_MAX
;
return
nr
;
}
}
...
@@ -2435,7 +2446,7 @@ int handler::update_auto_increment()
...
@@ -2435,7 +2446,7 @@ int handler::update_auto_increment()
variables
->
auto_increment_increment
,
variables
->
auto_increment_increment
,
nb_desired_values
,
&
nr
,
nb_desired_values
,
&
nr
,
&
nb_reserved_values
);
&
nb_reserved_values
);
if
(
nr
==
~
(
ulonglong
)
0
)
if
(
nr
==
ULONGLONG_MAX
)
DBUG_RETURN
(
HA_ERR_AUTOINC_READ_FAILED
);
// Mark failure
DBUG_RETURN
(
HA_ERR_AUTOINC_READ_FAILED
);
// Mark failure
/*
/*
...
@@ -2466,6 +2477,9 @@ int handler::update_auto_increment()
...
@@ -2466,6 +2477,9 @@ int handler::update_auto_increment()
}
}
}
}
if
(
unlikely
(
nr
==
ULONGLONG_MAX
))
DBUG_RETURN
(
HA_ERR_AUTOINC_ERANGE
);
DBUG_PRINT
(
"info"
,(
"auto_increment: %lu"
,
(
ulong
)
nr
));
DBUG_PRINT
(
"info"
,(
"auto_increment: %lu"
,
(
ulong
)
nr
));
if
(
unlikely
(
table
->
next_number_field
->
store
((
longlong
)
nr
,
TRUE
)))
if
(
unlikely
(
table
->
next_number_field
->
store
((
longlong
)
nr
,
TRUE
)))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment