diff options
author | unknown <evgen@moonbone.local> | 2007-02-16 19:39:28 +0300 |
---|---|---|
committer | unknown <evgen@moonbone.local> | 2007-02-16 19:39:28 +0300 |
commit | d5813a06f67d6478fed95aa9d10c44e1c1eb1076 (patch) | |
tree | fe56857c4485542a116a67f02ccbeb1373ca47bb /mysql-test/t/insert_select.test | |
parent | dd6feec4f40e89ae7d830b0a15d009ea2e66759e (diff) | |
download | mariadb-git-d5813a06f67d6478fed95aa9d10c44e1c1eb1076.tar.gz |
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.
sql/item.cc:
Bug#16630: The update fields of the INSERT .. SELECT .. ON DUPLICATE KEY
UPDATE contains wrong data if the SELECT employs a temporary table.
The new method Item_field::update_value_transformer() is added. It
substitutes fields in the update values list for references
(Item_ref objects) to them.
sql/item.h:
Bug#16630: The update fields of the INSERT .. SELECT .. ON DUPLICATE KEY
UPDATE contains wrong data if the SELECT employs a temporary table.
The update_value_transformer() method is added to the Item and to the
Item_field classes.
sql/sql_insert.cc:
Bug#16630: The update fields of the INSERT .. SELECT .. ON DUPLICATE KEY
UPDATE contains wrong data if the SELECT employs a temporary table.
Traverse update values and substitute fields from the select for
references (Item_ref objects) to them.
sql/sql_select.cc:
Bug#16630: The update fields of the INSERT .. SELECT .. ON DUPLICATE KEY
UPDATE contains wrong data if the SELECT employs a temporary table.
Traverse update values and substitute fields from the select for
references (Item_ref objects) to them.
mysql-test/r/insert_select.result:
Added a test case for bug#16630: The update fields of the INSERT .. SELECT ..
ON DUPLICATE KEY UPDATE contains wrong data if the SELECT employs a
temporary table.
mysql-test/t/insert_select.test:
Added a test case for bug#16630: The update fields of the INSERT .. SELECT ..
ON DUPLICATE KEY UPDATE contains wrong data if the SELECT employs a
temporary table.
Diffstat (limited to 'mysql-test/t/insert_select.test')
-rw-r--r-- | mysql-test/t/insert_select.test | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/mysql-test/t/insert_select.test b/mysql-test/t/insert_select.test index 5c60fc8e1f0..31508b3d6c4 100644 --- a/mysql-test/t/insert_select.test +++ b/mysql-test/t/insert_select.test @@ -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; + + |