Commit graph

30 commits

Author SHA1 Message Date
guilhem@gbichot3.local
b3a03dada9 Fix for BUG#24432
"INSERT... ON DUPLICATE KEY UPDATE skips auto_increment values".
When in an INSERT ON DUPLICATE KEY UPDATE, using
an autoincrement column, we inserted some autogenerated values and
also updated some rows, some autogenerated values were not used
(for example, even if 10 was the largest autoinc value in the table
at the start of the statement, 12 could be the first autogenerated
value inserted by the statement, instead of 11). One autogenerated
value was lost per updated row. Led to exhausting the range of the
autoincrement column faster.
Bug introduced by fix of BUG#20188; present since 5.0.24 and 5.1.12.
This bug breaks replication from a pre-5.0.24 master.
But the present bugfix, as it makes INSERT ON DUP KEY UPDATE
behave like pre-5.0.24, breaks replication from a [5.0.24,5.0.34]
master to a fixed (5.0.36) slave! To warn users against this when
they upgrade their slave, as agreed with the support team, we add
code for a fixed slave to detect that it is connected to a buggy
master in a situation (INSERT ON DUP KEY UPDATE into autoinc column)
likely to break replication, in which case it cannot replicate so
stops and prints a message to the slave's error log and to SHOW SLAVE
STATUS.
For 5.0.36->[5.0.24,5.0.34] replication we cannot warn as master
does not know the slave's version (but we always recommended to users
to have slave at least as new as master).
As agreed with support, I'll also ask for an alert to be put into
the MySQL Network Monitoring and Advisory Service.
2007-02-08 15:53:14 +01:00
kroki/tomash@moonlight.intranet
8798b462b5 Fix for the patch for bug#21726: Incorrect result with multiple
invocations of LAST_INSERT_ID.

Reding of LAST_INSERT_ID inside stored function wasn't noted by caller,
and no LAST_INSERT_ID_EVENT was issued for binary log.

The solution is to add THD::last_insert_id_used_bin_log, which is much
like THD::last_insert_id_used, but is reset only for upper-level
statements.  This new variable is used to issue LAST_INSERT_ID_EVENT.
2006-10-03 13:38:16 +04:00
kroki/tomash@moonlight.intranet
5ea8adfae7 BUG#21726: Incorrect result with multiple invocations of LAST_INSERT_ID
Non-upper-level INSERTs (the ones in the body of stored procedure,
stored function, or trigger) into a table that have AUTO_INCREMENT
column didn't affected the result of LAST_INSERT_ID() on this level.

The problem was introduced with the fix of bug 6880, which in turn was
introduced with the fix of bug 3117, where current insert_id value was
remembered on the first call to LAST_INSERT_ID() (bug 3117) and was
returned from that function until it was reset before the next
_upper-level_ statement (bug 6880).

The fix for bug#21726 brings back the behaviour of version 4.0, and
implements the following: remember insert_id value at the beginning
of the statement or expression (which at that point equals to
the first insert_id value generated by the previous statement), and
return that remembered value from LAST_INSERT_ID() or @@LAST_INSERT_ID.

Thus, the value returned by LAST_INSERT_ID() is not affected by values
generated by current statement, nor by LAST_INSERT_ID(expr) calls in
this statement.

Version 5.1 does not have this bug (it was fixed by WL 3146).
2006-10-02 14:28:23 +04:00
lars/lthalmann@mysql.com/dl145j.mysql.com
738cd74b52 After merge fixes 2006-09-21 13:38:01 +02:00
lars/lthalmann@mysql.com/dl145j.mysql.com
2c5dc57e27 Merge mysql.com:/users/lthalmann/bk/MERGE/mysql-4.1-merge
into  mysql.com:/users/lthalmann/bk/MERGE/mysql-5.0-merge
2006-09-21 13:28:16 +02:00
lars/lthalmann@mysql.com/dl145h.mysql.com
9538acf5dc Adding proper setup phase for test case rpl_insert_id 2006-09-21 13:19:52 +02:00
evgen@moonbone.local
8394aec4e6 Merge epotemkin@bk-internal.mysql.com:/home/bk/mysql-5.0
into  moonbone.local:/work/tmp_merge-5.0-opt-mysql
2006-07-13 18:16:16 +04:00
gkodinov/kgeorge@macbook.gmz
6b84456a35 more 4.1->5.0 merge fixes for bug#14553 2006-07-10 17:45:09 +03:00
gkodinov/kgeorge@macbook.gmz
8f71e47a0d Merge macbook.gmz:/Users/kgeorge/mysql/work/B14553-4.1-opt
into  macbook.gmz:/Users/kgeorge/mysql/work/B14553-5.0-opt
2006-07-10 16:44:05 +03:00
gkodinov/kgeorge@mysql.com/rakia.(none)
2c9f5cc706 BUG#14553: NULL in WHERE resets LAST_INSERT_ID
To make MySQL compatible with some ODBC applications, you can find
the AUTO_INCREMENT value for the last inserted row with the following query:
 SELECT * FROM tbl_name WHERE auto_col IS NULL.
This is done with a special code that replaces 'auto_col IS NULL' with
'auto_col = LAST_INSERT_ID'.
However this also resets the LAST_INSERT_ID to 0 as it uses it for a flag
so as to ensure that only the first SELECT ... WHERE auto_col IS NULL
after an INSERT has this special behaviour.
In order to avoid resetting the LAST_INSERT_ID a special flag is introduced
in the THD class. This flag is used to restrict the second and subsequent
SELECTs instead of LAST_INSERT_ID.
2006-07-10 16:27:03 +03:00
guilhem@mysql.com
a43c4b0265 Fix for BUG#20188 "REPLACE or ON DUPLICATE KEY UPDATE in
auto_increment breaks binlog":
if slave's table had a higher auto_increment counter than master's (even
though all rows of the two tables were identical), then in some cases,
REPLACE and INSERT ON DUPLICATE KEY UPDATE failed to replicate
statement-based (it inserted different values on slave from on master).
write_record() contained a "thd->next_insert_id=0" to force an adjustment
of thd->next_insert_id after the update or replacement. But it is this
assigment introduced indeterminism of the statement on the slave, thus
the bug. For ON DUPLICATE, we replace that assignment by a call to
handler::adjust_next_insert_id_after_explicit_value() which is deterministic
(does not depend on slave table's autoinc counter). For REPLACE, this
assignment can simply be removed (as REPLACE can't insert a number larger
than thd->next_insert_id).
We also move a too early restore_auto_increment() down to when we really know
that we can restore the value.
2006-07-05 14:41:35 +02:00
kroki@mysql.com
b0c1e49a11 Bug#15728: LAST_INSERT_ID function inside a stored function returns 0
Do not reset value of LAST_INSERT_ID() in sub-statement.
2006-04-21 18:55:04 +04:00
msvensson@neptunus.(none)
9304785c10 Add new option "check-testcases" to mysql-test-run.pl
Cleanup the sideeffects from most of the  testcases with sideeffects.
2006-01-26 17:54:34 +01:00
lars@mysql.com
c99c44805c Fix of an incorrect merge 2005-02-24 17:25:06 +01:00
bell@51.0.168.192.in-addr.arpa
cfdf5bcdc8 fixed test results 2005-02-24 04:07:58 +02:00
mats@mysql.com
6ad51ffb3c Bug#8412: Merge from 4.0 2005-02-23 19:58:54 +01:00
mats@mysql.com
30bf28202c Bug#8412: For replication to work correctly, the prologue and
epilogue to an SQL statement should not have an error code even
when the SQL statement itself has an error code.
2005-02-14 18:39:33 +01:00
monty@mysql.com
ce14578909 Merge with 4.0.18 2004-02-11 00:06:46 +01:00
heikki@hundin.mysql.fi
be760becac rpl_insert_id.test, rpl_insert_id.result:
Change tests so that tables are dropped in an order respecting the FOREIGN KEY constraints
2004-02-02 01:41:35 +02:00
antony@ltantony.rdg.cyberkinetica.homeunix.net
fcf96dbb18 WorkLog#1323
Deprecate the use of TYPE=... Preferred syntax is ENGINE=
2003-12-10 04:31:42 +00:00
monty@mashka.mysql.fi
2263e3e51f Merge with 4.0.14 2003-08-11 22:44:43 +03:00
guilhem@mysql.com
34352d0c21 Make rpl_insert_id.test use InnoDB, and added foreign keys to the table,
so that it really tests replication of SET FOREIGN_KEY_CHECKS (previously
it used MyISAM).
2003-07-26 17:59:05 +02:00
monty@narttu.mysql.fi
40109c574a Merge with 4.0.13 2003-06-04 19:21:51 +03:00
guilhem@mysql.com
97f9aa2aaf temporary update of the test to satisfy merge; will commit a final update
soon.
2003-05-27 14:50:14 +02:00
monty@narttu.mysql.fi
4ead61f873 code cleanup 2003-05-26 15:08:17 +03:00
guilhem@mysql.com
8a1e18f4cb Fix for bug #490 and #491 (see details below) 2003-05-24 16:43:53 +02:00
monty@mashka.mysql.fi
c4e7cbe158 after merge fix 2003-02-08 02:09:21 +02:00
monty@mashka.mysql.fi
25de9c19b2 After merge fixes & remove compiler warnings
Added lengths for all MYSQL_FIELD string parameters
Changed field length to 2 byte in .frm files
2003-02-07 15:47:24 +02:00
monty@mashka.mysql.fi
279f43a198 Updated results for 4.0 2003-01-28 09:17:10 +02:00
monty@mashka.mysql.fi
710ffb2d89 Fix when using auto_increment and last_insert_id() in the same insert statement. 2003-01-28 06:48:26 +02:00