Bug #1564 CREATE TABLE + UNION + same table name = crash
Submitted: 15 Oct 2003 19:48 Modified: 8 Dec 2003 0:02
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.1 OS:Linux (SuSE 8.2)
Assigned to: Sergei Glukhov CPU Architecture:Any

[15 Oct 2003 19:48] Peter Gulutzan
CREATE TABLE ... AS SELECT ... crashes if the SELECT contains the same table name 
that you're creating. This is possible only with UNIONed SELECTs. 

How to repeat:
create table t97 as select 1 union select * from t97; 

Suggested fix:
Disallow use of same table name that you're creating. That's already the case for a 
[16 Oct 2003 7:28] Alexander Keremidarski
It happens even with nonexisting table.

Here is Backtrace.

(gdb) bt
#0  setup_tables(st_table_list*) (tables=0x85e7e90) at mysql_priv.h:1031
#1  0x0818c636 in JOIN::prepare(Item***, st_table_list*, unsigned, Item*, unsigned, st_order*, st_order*, Item*, st_order*, st_select_lex*, st_select_lex_unit*, bool) (this=0x85e8c08, rref_pointer_array=0x85e7cd0, tables_init=0x403be194, wild_num=1077666196, conds_init=0x403be194, og_num=1077666196, order_init=0x403be194, group_init=0x403be194, having_init=0x403be194, proc_param_init=0x403be194, select=0x85e7bf0, unit=0x85c4ec4, tables_and_fields_initied=false) at sql_select.cc:303
#2  0x08227051 in st_select_lex_unit::prepare(THD*, select_result*, bool) (this=0x85c4ec4, thd=0x85c4c40, sel_result=0x403be194, tables_and_fields_initied=false) at sql_union.cc:203
#3  0x0822655c in mysql_union(THD*, st_lex*, select_result*, st_select_lex_unit*, bool) (thd=0x403be194, lex=0x85c4eb8, result=0x403be194, unit=0x85c4ec4, tables_and_fields_initied=false) at sql_union.cc:32
#4  0x0818c397 in handle_select(THD*, st_lex*, select_result*) (thd=0x85c4c40, lex=0x85c4eb8, result=0x85e7f40) at sql_select.cc:178
#5  0x08166a52 in mysql_execute_command(THD*) (thd=0x85c4c40) at sql_parse.cc:2082
#6  0x0816b6fd in mysql_parse(THD*, char*, unsigned) (thd=0x85c4c40, inBuf=0x85e7ad0 "create table t97 as select 1 union select * from t97", length=140267192) at sql_parse.cc:3768
#7  0x08164a0b in dispatch_command(enum_server_command, THD*, char*, unsigned) (command=COM_QUERY, thd=0x85c4c40, packet=0x85dfa71 "create table t97 as select 1 union select * from t97", packet_length=53) at sql_parse.cc:1295
#8  0x08164356 in do_command(THD*) (thd=0x85c4c40) at sql_parse.cc:1129
#9  0x08163857 in handle_one_connection (arg=0x403be194) at sql_parse.cc:899
#10 0x40173332 in start_thread () from /lib/tls/libpthread.so.0
#11 0x420de867 in clone () from /lib/tls/libc.so.6
[26 Nov 2003 0:41] Sergei Glukhov
ChangeSet 1.1618 03/11/17
[8 Dec 2003 0:02] Sergei Glukhov
Fixed in 4.0
[14 Jan 2004 2:50] [ name withheld ]
4.1 is not stable yet - do you plan to fix it in 4.0.x?