MCPcopy Create free account
hub / github.com/MariaDB/server / compute_next_insert_id

Function compute_next_insert_id

sql/handler.cc:4386–4412  ·  view source on GitHub ↗

Generate the next auto-increment number based on increment and offset. computes the lowest number - strictly greater than "nr" - 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: @verbatim 1,2,3,4,5,... @endverbatim If increm

Source from the content-addressed store, hash-verified

4384 @verbatim 1,5,15,25,35,... @endverbatim
4385*/
4386inline ulonglong
4387compute_next_insert_id(ulonglong nr,struct system_variables *variables)
4388{
4389 const ulonglong save_nr= nr;
4390
4391 if (variables->auto_increment_increment == 1)
4392 nr= nr + 1; // optimization of the formula below
4393 else
4394 {
4395 /*
4396 Calculating the number of complete auto_increment_increment extents:
4397 */
4398 nr= (nr + variables->auto_increment_increment -
4399 variables->auto_increment_offset) /
4400 (ulonglong) variables->auto_increment_increment;
4401 /*
4402 Adding an offset to the auto_increment_increment extent boundary:
4403 */
4404 nr= nr * (ulonglong) variables->auto_increment_increment +
4405 variables->auto_increment_offset;
4406 }
4407
4408 if (unlikely(nr <= save_nr))
4409 return ULONGLONG_MAX;
4410
4411 return nr;
4412}
4413
4414
4415void handler::adjust_next_insert_id_after_explicit_value(ulonglong nr)

Calls

no outgoing calls

Tested by

no test coverage detected