Below is the list of changes that have just been committed into a local
5.0 repository of guilhem. When guilhem does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet
1.2192 06/07/06 14:42:47 guilhem@stripped +3 -0
Merge gbichot3.local:/home/mysql_src/mysql-5.0-20524
into gbichot3.local:/home/mysql_src/mysql-5.0
sql/sql_insert.cc
1.193 06/07/06 14:42:41 guilhem@stripped +0 -0
Auto merged
sql/handler.h
1.172 06/07/06 14:42:41 guilhem@stripped +0 -0
Auto merged
sql/handler.cc
1.214 06/07/06 14:42:41 guilhem@stripped +0 -0
Auto merged
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: guilhem
# Host: gbichot3.local
# Root: /home/mysql_src/mysql-5.0/RESYNC
--- 1.213/sql/handler.cc 2006-07-05 14:40:58 +02:00
+++ 1.214/sql/handler.cc 2006-07-06 14:42:41 +02:00
@@ -1492,6 +1492,46 @@
/*
+ 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" otherwise.
+*/
+
+inline ulonglong
+prev_insert_id(ulonglong nr, struct system_variables *variables)
+{
+ if (unlikely(nr < variables->auto_increment_offset))
+ {
+ /*
+ There's nothing good we can do here. That is a pathological case, where
+ the offset is larger than the column's max possible value, i.e. not even
+ the first sequence value may be inserted. User will receive warning.
+ */
+ DBUG_PRINT("info",("auto_increment: nr: %lu cannot honour "
+ "auto_increment_offset: %lu",
+ nr, variables->auto_increment_offset));
+ return nr;
+ }
+ if (variables->auto_increment_increment == 1)
+ return nr; // optimization of the formula below
+ nr= (((nr - variables->auto_increment_offset)) /
+ (ulonglong) variables->auto_increment_increment);
+ return (nr * (ulonglong) variables->auto_increment_increment +
+ variables->auto_increment_offset);
+}
+
+
+/*
Update the auto_increment field if necessary
SYNOPSIS
@@ -1590,10 +1630,19 @@
/* Mark that we should clear next_insert_id before next stmt */
thd->clear_next_insert_id= 1;
- if (!table->next_number_field->store((longlong) nr, TRUE))
+ if (likely(!table->next_number_field->store((longlong) nr, TRUE)))
thd->insert_id((ulonglong) nr);
else
- thd->insert_id(table->next_number_field->val_int());
+ {
+ /*
+ overflow of the field; we'll use the max value, however we try to
+ decrease it to honour auto_increment_* variables:
+ */
+ nr= prev_insert_id(table->next_number_field->val_int(), variables);
+ thd->insert_id(nr);
+ if (unlikely(table->next_number_field->store((longlong) nr, TRUE)))
+ thd->insert_id(nr= table->next_number_field->val_int());
+ }
/*
We can't set next_insert_id if the auto-increment key is not the
--- 1.171/sql/handler.h 2006-06-02 09:02:48 +02:00
+++ 1.172/sql/handler.h 2006-07-06 14:42:41 +02:00
@@ -563,6 +563,7 @@
{}
virtual ~handler(void) { /* TODO: DBUG_ASSERT(inited == NONE); */ }
int ha_open(const char *name, int mode, int test_if_locked);
+ void adjust_next_insert_id_after_explicit_value(ulonglong nr);
bool update_auto_increment();
virtual void print_error(int error, myf errflag);
virtual bool get_error_message(int error, String *buf);
--- 1.192/sql/sql_insert.cc 2006-06-19 14:57:36 +02:00
+++ 1.193/sql/sql_insert.cc 2006-07-06 14:42:41 +02:00
@@ -955,7 +955,6 @@
uint key_nr;
if (error != HA_WRITE_SKIP)
goto err;
- table->file->restore_auto_increment();
if ((int) (key_nr = table->file->get_dup_key(error)) < 0)
{
error=HA_WRITE_SKIP; /* Database can't find key */
@@ -1028,20 +1027,20 @@
if (res == VIEW_CHECK_ERROR)
goto before_trg_err;
- if (thd->clear_next_insert_id)
- {
- /* Reset auto-increment cacheing if we do an update */
- thd->clear_next_insert_id= 0;
- thd->next_insert_id= 0;
- }
if ((error=table->file->update_row(table->record[1],table->record[0])))
{
if ((error == HA_ERR_FOUND_DUPP_KEY) && info->ignore)
+ {
+ table->file->restore_auto_increment();
goto ok_or_after_trg_err;
+ }
goto err;
}
info->updated++;
+ if (table->next_number_field)
+ table->file->adjust_next_insert_id_after_explicit_value(table->next_number_field->val_int());
+
trg_error= (table->triggers &&
table->triggers->process_triggers(thd, TRG_EVENT_UPDATE,
TRG_ACTION_AFTER, TRUE));
@@ -1070,12 +1069,6 @@
table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH) &&
(!table->triggers || !table->triggers->has_delete_triggers()))
{
- if (thd->clear_next_insert_id)
- {
- /* Reset auto-increment cacheing if we do an update */
- thd->clear_next_insert_id= 0;
- thd->next_insert_id= 0;
- }
if ((error=table->file->update_row(table->record[1],
table->record[0])))
goto err;
@@ -1139,6 +1132,7 @@
table->file->print_error(error,MYF(0));
before_trg_err:
+ table->file->restore_auto_increment();
if (key)
my_safe_afree(key, table->s->max_unique_length, MAX_KEY_LENGTH);
DBUG_RETURN(1);
| Thread |
|---|
| • bk commit into 5.0 tree (guilhem:1.2192) | guilhem | 6 Jul |