diff options
author | Michael Widenius <monty@askmonty.org> | 2012-09-18 23:34:16 +0300 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2012-09-18 23:34:16 +0300 |
commit | af4eeaf548c523934d335d18d390c30ef8f2bf23 (patch) | |
tree | 9eb6787f9bc4ceba7c25b8d8a7db0aad024b66da /sql/table.h | |
parent | 6f57fc505412ead94bd76c91c79c3cbd0a7f992f (diff) | |
download | mariadb-git-af4eeaf548c523934d335d18d390c30ef8f2bf23.tar.gz |
This fix+comments was originally made by Alexey Kopytov
LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE +
innodb_autoinc_lock_mode=1 is broken
The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE
were executed concurrently on a table containing an AUTO_INCREMENT
column as a primary key, InnoDB would correctly reserve non-overlapping
AUTO_INCREMENT intervals for each statement, but when the server
encountered the first duplicate key error on the secondary key in one of
the statements and performed an UPDATE, it also updated the internal
AUTO_INCREMENT value to the one from the existing row that caused a
duplicate key error, even though the AUTO_INCREMENT value was not
specified explicitly in the UPDATE clause. It would then proceed with
using AUTO_INCREMENT values the range reserved previously by another
statement, causing duplicate key errors on the AUTO_INCREMENT column.
Fixed by changing write_record() to ensure that in case of a duplicate
key error the internal AUTO_INCREMENT counter is only updated when the
AUTO_INCREMENT value was explicitly updated by the UPDATE
clause. Otherwise it is restored to what it was before the duplicate key
error, as that value is unused and can be reused for subsequent
successfully inserted rows.
sql/sql_insert.cc:
Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE.
sql/sql_parse.cc:
Added DBUG_SYNC
sql/table.h:
Added next_number_field_updated flag to detect changing of auto increment fields.
Moved fields a bit to get bool fields after each other (better alignment)
Diffstat (limited to 'sql/table.h')
-rw-r--r-- | sql/table.h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/sql/table.h b/sql/table.h index f5ae3bcebb3..0259e063748 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1053,15 +1053,20 @@ public: uint db_stat; /* mode of file as in handler.h */ /* number of select if it is derived table */ uint derived_select_number; - int current_lock; /* Type of lock on table */ - bool copy_blobs; /* copy_blobs when storing */ - /* 0 or JOIN_TYPE_{LEFT|RIGHT}. Currently this is only compared to 0. If maybe_null !=0, this table is inner w.r.t. some outer join operation, and null_row may be true. */ uint maybe_null; + int current_lock; /* Type of lock on table */ + bool copy_blobs; /* copy_blobs when storing */ + /* + Set if next_number_field is in the UPDATE fields of INSERT ... ON DUPLICATE + KEY UPDATE. + */ + bool next_number_field_updated; + /* If true, the current table row is considered to have all columns set to NULL, including columns declared as "not null" (see maybe_null). |