Hello,
Sergey Glukhov a écrit, Le 06.12.2010 11:32:
> #At file:///home/gluh/MySQL/mysql-5.1-bugteam-new/ based on
> revid:mats.kindahl@stripped
>
> 3512 Sergey Glukhov 2010-12-06
> Bug#39828 : Autoinc wraps around when offset and increment > 1
> Auto increment value wraps when performing a bulk insert with
> auto_increment_increment and auto_increment_offset greater than
> one.
> === modified file 'sql/handler.cc'
> --- a/sql/handler.cc 2010-11-10 21:14:47 +0000
> +++ b/sql/handler.cc 2010-12-06 10:32:13 +0000
> @@ -2175,13 +2175,23 @@ int handler::read_first_row(uchar * buf,
> inline ulonglong
> compute_next_insert_id(ulonglong nr,struct system_variables *variables)
> {
> + const ulonglong save_nr= nr;
> +
> if (variables->auto_increment_increment == 1)
> - return (nr+1); // optimization of the formula below
> - nr= (((nr+ variables->auto_increment_increment -
> - variables->auto_increment_offset)) /
> - (ulonglong) variables->auto_increment_increment);
> - return (nr* (ulonglong) variables->auto_increment_increment +
> - variables->auto_increment_offset);
> + nr= nr + 1; // optimization of the formula below
> + else
> + {
> + nr= (((nr+ variables->auto_increment_increment -
> + 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) 0; // return MAX_ULONGLONG in case of overflow
This "//" comment could be moved to the function's comment.
Ok to push.
For the manual: I suggest to document that an autogenerated value can
never be MAX_ULONGLONG (it was partially true before, always true after
this fix).