mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
Bug#16630: The update fields of the INSERT .. SELECT .. ON DUPLICATE KEY
UPDATE contains wrong data if the SELECT employs a temporary table. If the UPDATE values of the INSERT .. SELECT .. ON DUPLICATE KEY UPDATE statement contains fields from the SELECT part and the select employs a temporary table then those fields will contain wrong values because they aren't corrected to get data from the temporary table. The solution is to add these fields to the selects all_fields list, to store pointers to those fields in the selects ref_pointer_array and to access them via Item_ref objects. The substitution for Item_ref objects is done in the new function called Item_field::update_value_transformer(). It is called through the item->transform() mechanism at the end of the select_insert::prepare() function.
This commit is contained in:
@ -731,3 +731,16 @@ select @@identity;
|
||||
@@identity
|
||||
0
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (f1 INT, f2 INT );
|
||||
CREATE TABLE t2 (f1 INT PRIMARY KEY, f2 INT);
|
||||
INSERT INTO t1 VALUES (1,1),(2,2),(10,10);
|
||||
INSERT INTO t2 (f1, f2) SELECT f1, f2 FROM t1;
|
||||
INSERT INTO t2 (f1, f2)
|
||||
SELECT f1, f1 FROM t2 src WHERE f1 < 2
|
||||
ON DUPLICATE KEY UPDATE f1 = 100 + src.f1;
|
||||
SELECT * FROM t2;
|
||||
f1 f2
|
||||
101 1
|
||||
2 2
|
||||
10 10
|
||||
DROP TABLE t1, t2;
|
||||
|
@ -292,3 +292,18 @@ select @@identity;
|
||||
insert ignore t1(f2) select 1;
|
||||
select @@identity;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Bug#16630: wrong result, when INSERT t1 SELECT ... FROM t1 ON DUPLICATE
|
||||
#
|
||||
CREATE TABLE t1 (f1 INT, f2 INT );
|
||||
CREATE TABLE t2 (f1 INT PRIMARY KEY, f2 INT);
|
||||
INSERT INTO t1 VALUES (1,1),(2,2),(10,10);
|
||||
INSERT INTO t2 (f1, f2) SELECT f1, f2 FROM t1;
|
||||
INSERT INTO t2 (f1, f2)
|
||||
SELECT f1, f1 FROM t2 src WHERE f1 < 2
|
||||
ON DUPLICATE KEY UPDATE f1 = 100 + src.f1;
|
||||
SELECT * FROM t2;
|
||||
DROP TABLE t1, t2;
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user