Bug #5263 Views: crash if INSERT ... ON DUPLICATE KEY
Submitted: 27 Aug 2004 20:12 Modified: 6 Sep 2004 13:41
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.2-alpha-debug OS:Linux (SuSE 8.2)
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[27 Aug 2004 20:12] Peter Gulutzan
If I use MySQL's ON DUPLICATE KEY clause in INSERT, if the target of the INSERT is a 
view, if there is a duplicate, then there is a crash. 

How to repeat:
mysql> create table t (s1 int, primary key (s1)); 
Query OK, 0 rows affected (0.29 sec) 
mysql> create view v as select * from t; 
Query OK, 0 rows affected (0.00 sec) 
mysql> insert into v values (1) on duplicate key update s1 = 7; 
Query OK, 1 row affected (0.00 sec) 
mysql> insert into v values (1) on duplicate key update s1 = 7; 
ERROR 2013 (HY000): Lost connection to MySQL server during query 

Suggested fix:
Throw away the ON DUPLICATE KEY clause. It's not standard SQL anyway.
[27 Aug 2004 20:45] Alexander Keremidarski
(gdb) bt
#0  fill_record(List<Item>&, List<Item>&, bool) (fields=@0x86ec2f0, values=@0x0, ignore_errors=false) at sql_base.cc:3000
#1  0x081f612f in write_record(st_table*, st_copy_info*) (table=0x86f30a0, info=0x410b41c0) at sql_insert.cc:654
#2  0x081f545f in mysql_insert(THD*, st_table_list*, List<Item>&, List<List<Item> >&, List<Item>&, List<Item>&, enum_duplicates) (thd=0x86bd8b0, table_list=0x86ec0b0, fields=@0x86bdc8c, values_list=@0x86bdca4, update_fields=@0x86bdae8, update_values=@0x86bdc98, duplic=DUP_UPDATE) at sql_insert.cc:313
#3  0x081a9e38 in mysql_execute_command(THD*) (thd=0x86bd8b0) at sql_parse.cc:2733
#4  0x081ae33a in mysql_parse(THD*, char*, unsigned) (thd=0x86bd8b0, inBuf=0x86ec030 "insert into v values (1) on duplicate key update s1 = 7", length=141285604) at sql_parse.cc:4432
#5  0x081a66f7 in dispatch_command(enum_server_command, THD*, char*, unsigned) (command=COM_QUERY, thd=0x86bd8b0, packet=0x86e3fd1 "insert into v values (1) on duplicate key update s1 = 7", packet_length=56) at sql_parse.cc:1486
#6  0x081a5fec in do_command(THD*) (thd=0x86bd8b0) at sql_parse.cc:1296
#7  0x081a545d in handle_one_connection (arg=0x86ec2f0) at sql_parse.cc:1032
#8  0x4e5c798c in start_thread () from /lib/tls/libpthread.so.0
#9  0x4e44616a in clone () from /lib/tls/libc.so.6
[6 Sep 2004 13:41] Oleksandr Byelkin
  1.1747 04/09/06 14:37:10 bell@sanja.is.com.ua +3 -0 
  do not use Item_ref for view fields if it is UPDATE of INSERT (BUG#5263) 
Thank you for bug report, bug is fixed and patch is pushed into source repository.