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

Method update_auto_increment

sql/handler.cc:4551–4777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4549#define AUTO_INC_DEFAULT_NB_MAX ((1 << AUTO_INC_DEFAULT_NB_MAX_BITS) - 1)
4550
4551int handler::update_auto_increment()
4552{
4553 ulonglong nr, nb_reserved_values;
4554 bool append= FALSE;
4555 THD *thd= table->in_use;
4556 struct system_variables *variables= &thd->variables;
4557 int result=0, tmp;
4558 DBUG_ENTER("handler::update_auto_increment");
4559
4560 /*
4561 next_insert_id is a "cursor" into the reserved interval, it may go greater
4562 than the interval, but not smaller.
4563 */
4564 DBUG_ASSERT(next_insert_id >= auto_inc_interval_for_cur_row.minimum());
4565
4566 if ((nr= table->next_number_field->val_int()) != 0 ||
4567 (table->auto_increment_field_not_null &&
4568 thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO))
4569 {
4570
4571 /*
4572 There could be an error reported because value was truncated
4573 when strict mode is enabled.
4574 */
4575 if (thd->is_error())
4576 DBUG_RETURN(HA_ERR_AUTOINC_ERANGE);
4577 /*
4578 Update next_insert_id if we had already generated a value in this
4579 statement (case of INSERT VALUES(null),(3763),(null):
4580 the last NULL needs to insert 3764, not the value of the first NULL plus
4581 1).
4582 Ignore negative values.
4583 */
4584 if ((longlong) nr > 0 || (table->next_number_field->flags & UNSIGNED_FLAG))
4585 adjust_next_insert_id_after_explicit_value(nr);
4586 insert_id_for_cur_row= 0; // didn't generate anything
4587 DBUG_RETURN(0);
4588 }
4589
4590 if (table->versioned())
4591 {
4592 Field *end= table->vers_end_field();
4593 DBUG_ASSERT(end);
4594 bitmap_set_bit(table->read_set, end->field_index);
4595 if (!end->is_max())
4596 {
4597 if (thd->lex->sql_command == SQLCOM_ALTER_TABLE)
4598 {
4599 if (!table->next_number_field->real_maybe_null())
4600 DBUG_RETURN(HA_ERR_UNSUPPORTED);
4601 table->next_number_field->set_null();
4602 }
4603 DBUG_RETURN(0);
4604 }
4605 }
4606
4607 // ALTER TABLE ... ADD COLUMN ... AUTO_INCREMENT
4608 if (thd->lex->sql_command == SQLCOM_ALTER_TABLE)

Callers 1

Calls 15

bitmap_set_bitFunction · 0.85
compute_next_insert_idFunction · 0.85
prev_insert_idFunction · 0.85
real_maybe_nullMethod · 0.80
set_notnullMethod · 0.80
valuesMethod · 0.80
minimumMethod · 0.45
val_intMethod · 0.45
is_errorMethod · 0.45
versionedMethod · 0.45
vers_end_fieldMethod · 0.45

Tested by

no test coverage detected