Bug #24491 | using alias from source table in insert..on duplicate key | ||
---|---|---|---|
Submitted: | 21 Nov 2006 23:20 | Modified: | 3 Feb 2007 2:34 |
Reporter: | Thomas Johnson | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Stored Routines | Severity: | S3 (Non-critical) |
Version: | 5.0.27, 5.1 BK | OS: | Linux (Linux, Windows) |
Assigned to: | Dmitry Lenev | CPU Architecture: | Any |
Tags: | alias, duplicate, insert, key |
[21 Nov 2006 23:20]
Thomas Johnson
[22 Nov 2006 10:13]
Sveta Smirnova
Thank you for the report. Verified as described on Linux using last 5.0 and 5.1 BK sources.
[9 Jan 2007 8:43]
Dmitry Lenev
Note that prepared statements are also affected by this bug, so it is not something specific to SP but rather issue with general re-execution of INSERT .. SELECT .. ON DUPLICATE KEY UPDATE ... .
[10 Jan 2007 14:15]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/17847 ChangeSet@1.2322, 2007-01-10 17:16:51+03:00, dlenev@mockturtle.local +3 -0 Proposed fix for bug#24491 "using alias from source table in insert ... on duplicate key". INSERT ... SELECT ... ON DUPLICATE KEY UPDATE which was used in stored routine or as prepared statement and which in its ON DUPLICATE KEY clause erroneously tried to assign value to a column mentioned only in its SELECT part was properly emitting error on the first execution but succeeded on the second and following executions. Code which is responsible for name resolution of fields mentioned in UPDATE clause (e.g. see select_insert::prepare()) modifies table list and Name_resolution_context used in this process. It uses Name_resolution_context_state::save_state/restore_state() to revert these modifications. Unfortunately those two methods failed to revert properly modifications to TABLE_LIST::next_name_resolution_table and this broke name resolution process for successive executions. This patch fixes Name_resolution_context_state::save_state/restore_state() in such way that it properly handles TABLE_LIST::next_name_resolution_table.
[23 Jan 2007 12:02]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/18614 ChangeSet@1.2322, 2007-01-23 15:03:48+03:00, dlenev@mockturtle.local +5 -0 Proposed fix for bug#24491 "using alias from source table in insert ... on duplicate key". INSERT ... SELECT ... ON DUPLICATE KEY UPDATE which was used in stored routine or as prepared statement and which in its ON DUPLICATE KEY clause erroneously tried to assign value to a column mentioned only in its SELECT part was properly emitting error on the first execution but succeeded on the second and following executions. Code which is responsible for name resolution of fields mentioned in UPDATE clause (e.g. see select_insert::prepare()) modifies table list and Name_resolution_context used in this process. It uses Name_resolution_context_state::save_state/restore_state() to revert these modifications. Unfortunately those two methods failed to revert properly modifications to TABLE_LIST::next_name_resolution_table and this broke name resolution process for successive executions. This patch fixes Name_resolution_context_state::save_state/restore_state() in such way that it properly handles TABLE_LIST::next_name_resolution_table.
[24 Jan 2007 7:45]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/18688 ChangeSet@1.2412, 2007-01-24 10:46:25+03:00, dlenev@mockturtle.local +1 -0 Fixed test case after merging fix for bug#24491 "using alias from source table in insert ... on duplicate key" in 5.1 tree.
[3 Feb 2007 2:34]
Paul DuBois
Noted in 5.0.36, 5.1.16 changelogs. Within stored routines or prepared statements, inconsistent results occurred with multiple use of INSERT ... SELECT ... ON DUPLICATE KEY UPDATE when the ON DUPLICATE KEY UPDATE clause erroneously tried to assign a value to a column mentioned only in its SELECT part.