Bug #8849 | problem with insert statement with table alias's | ||
---|---|---|---|
Submitted: | 28 Feb 2005 19:11 | Modified: | 3 Mar 2005 13:42 |
Reporter: | Shane Bester (Platinum Quality Contributor) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S2 (Serious) |
Version: | 5.0.3 Alpha | OS: | Windows (Windows XP) |
Assigned to: | Konstantin Osipov | CPU Architecture: | Any |
[28 Feb 2005 19:11]
Shane Bester
[2 Mar 2005 21:11]
Konstantin Osipov
Sinisa, Shane, simplification of the test case will ease and speed up fixing a lot. Which query makes the server fail? Does the procedure with this query only crashes the server? Is it possible to reduce the data set? Thank you in advance for your help.
[2 Mar 2005 22:00]
Konstantin Osipov
Update: you need no data in the tables to make the stored procedure in question crash.
[2 Mar 2005 22:59]
Konstantin Osipov
A simple test case: drop table if exists t1,t3,t2; drop procedure if exists p8849; CREATE TABLE t1 ( lpitnumber int(11) default NULL, lrecordtype int(11) default NULL ); CREATE TABLE t2 ( lbsiid int(11) NOT NULL default '0', ltradingmodeid int(11) NOT NULL default '0', ltradingareaid int(11) NOT NULL default '0', csellingprice decimal(19,4) default NULL, PRIMARY KEY (lbsiid,ltradingmodeid,ltradingareaid) ); CREATE TABLE t3 ( lbsiid int(11) NOT NULL default '0', ltradingareaid int(11) NOT NULL default '0', PRIMARY KEY (lbsiid,ltradingareaid) ); delimiter |; CREATE PROCEDURE p8849() begin insert into t3 ( t3.lbsiid, t3.ltradingareaid ) select distinct t1.lpitnumber, t2.ltradingareaid from t2 join t1 on t1.lpitnumber = t2.lbsiid and t1.lrecordtype = 1 left join t2 as price01 on price01.lbsiid = t2.lbsiid and price01.ltradingmodeid = 1 and t2.ltradingareaid = price01.ltradingareaid; end| delimiter ;| call p8849(); call p8849(); On attempt to prepare and execute this statement the server does not crash. The backtrace clearly shows that the crash happens due to damaged parse tree: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 1085615024 (LWP 17048)] 0x0817fd35 in Item_cond::fix_fields (this=0x8859978, thd=0x8824540, tables=0x8858438, ref=0x8858fd8) at item_cmpfunc.cc:2310 2310 while (item->type() == Item::COND_ITEM && (gdb) bt #0 0x0817fd35 in Item_cond::fix_fields (this=0x8859978, thd=0x8824540, tables=0x8858438, ref=0x8858fd8) at item_cmpfunc.cc:2310 #1 0x0821ce03 in setup_conds (thd=0x8824540, tables=0x8858438, leaves=0x8858438, conds=0x8848708) at sql_base.cc:3291 #2 0x08244b13 in setup_without_group (thd=0x8824540, ref_pointer_array=0x8846680, tables=0x8858438, leaves=0x8858438, fields=@0x88518fc, all_fields=@0x8848684, conds=0x8848708, order=0x0, group=0x0, hidden_group_fields=0x884866a) at sql_select.cc:272 #3 0x08224393 in JOIN::prepare (this=0x8847960, rref_pointer_array=0x88519b4, tables_init=0x8858438, wild_num=0, conds_init=0x8847520, og_num=0, order_init=0x0, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x8851890, unit_arg=0x88516bc) at sql_select.cc:321 #4 0x08229acc in mysql_select (thd=0x8824540, rref_pointer_array=0x88519b4, tables=0x8858438, wild_num=0, fields=@0x88518fc, conds=0x8847520, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=3500427777, result=0x88475e0, unit=0x88516bc, select_lex=0x8851890) at sql_select.cc:2026 #5 0x08224000 in handle_select (thd=0x8824540, lex=0x88516b0, result=0x88475e0, setup_tables_done_option=1073741824) at sql_select.cc:227 #6 0x081f4c2e in mysql_execute_command (thd=0x8824540) at sql_parse.cc:3294 #7 0x083361a7 in sp_instr_stmt::exec_stmt (this=0x8859c78, thd=0x8824540, lex=0x88516b0) at sp_head.cc:1198 #8 0x0833603f in sp_instr_stmt::execute (this=0x8859c78, thd=0x8824540, (...)
[3 Mar 2005 13:29]
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/internals/22616
[3 Mar 2005 13:31]
Konstantin Osipov
Subject: bk commit - 5.0 tree (konstantin:1.1786) BUG#8849 ChangeSet 1.1786 05/03/03 16:28:27 konstantin@mysql.com +11 -0 Fixes for bug#8115 "Server Crash with prepared statement" and bug#8849 "problem with insert statement with table alias's": make equality propagation work in stored procedures and prepared statements. Equality propagation can change AND/OR structure of ON expressions, so the fix is to provide each execution of PS/SP with it's own copy of AND/OR tree. We have been doing that already for WHERE clauses, now ON clauses are also copied.