@brief Computes the largest number X: - smaller than or equal to "nr" - of the form: auto_increment_offset + N * auto_increment_increment where N>=0. SYNOPSIS prev_insert_id nr Number to "round down" variables variables struct containing auto_increment_increment and auto_increment_offset RETURN The number X if it exists, "nr" oth
| 4440 | The number X if it exists, "nr" otherwise. |
| 4441 | */ |
| 4442 | inline ulonglong |
| 4443 | prev_insert_id(ulonglong nr, struct system_variables *variables) |
| 4444 | { |
| 4445 | if (unlikely(nr < variables->auto_increment_offset)) |
| 4446 | { |
| 4447 | /* |
| 4448 | There's nothing good we can do here. That is a pathological case, where |
| 4449 | the offset is larger than the column's max possible value, i.e. not even |
| 4450 | the first sequence value may be inserted. User will receive warning. |
| 4451 | */ |
| 4452 | DBUG_PRINT("info",("auto_increment: nr: %lu cannot honour " |
| 4453 | "auto_increment_offset: %lu", |
| 4454 | (ulong) nr, variables->auto_increment_offset)); |
| 4455 | return nr; |
| 4456 | } |
| 4457 | if (variables->auto_increment_increment == 1) |
| 4458 | return nr; // optimization of the formula below |
| 4459 | /* |
| 4460 | Calculating the number of complete auto_increment_increment extents: |
| 4461 | */ |
| 4462 | nr= (nr - variables->auto_increment_offset) / |
| 4463 | (ulonglong) variables->auto_increment_increment; |
| 4464 | /* |
| 4465 | Adding an offset to the auto_increment_increment extent boundary: |
| 4466 | */ |
| 4467 | return (nr * (ulonglong) variables->auto_increment_increment + |
| 4468 | variables->auto_increment_offset); |
| 4469 | } |
| 4470 | |
| 4471 | |
| 4472 | /** |
no outgoing calls
no test coverage detected