3 messages in com.mysql.lists.bugsRe: Bug in Union?!
FromSent OnAttachments
Georg Richter22 Dec 2002 07:07 
Sinisa Milivojevic23 Dec 2002 12:16 
Sinisa Milivojevic24 Dec 2002 10:41 
Subject:Re: Bug in Union?!
From:Sinisa Milivojevic (sin@mysql.com)
Date:12/23/2002 12:16:13 PM
List:com.mysql.lists.bugs

Georg Richter writes:

Hi,

I'm not sure if this an error... if not it should be documented

how-to-repeat:

mysql> create table foo (bar int); Query OK, 0 rows affected (0.00 sec)

mysql> insert into foo values (1),(2),(3),(4),(5); Query OK, 5 rows affected (0.00 sec) Records: 5 Duplicates: 0 Warnings: 0

mysql> (select * from foo limit 1,1) union select * from foo limit 3,1; Empty set (0.00 sec)

(select * from foo limit 1,1) union (select * from foo limit 3,1) works ok, also (select * from foo limit 1,1) union (select * from foo) limit 3,1.

Regards

Hi!

I do not think that mixing UNION with and without braces should be allowed. For many reasons, although standard is not clear on this one.

Therefore, I will propose the following patch:

===== sql/sql_yacc.yy 1.209 vs edited ===== *** /tmp/sql_yacc.yy-1.209-23919 Wed Dec 18 16:26:45 2002 --- edited/sql/sql_yacc.yy Mon Dec 23 21:59:45 2002 *************** *** 1668,1679 **** '(' SELECT_SYM select_part2 ')' { LEX *lex= Lex; ! SELECT_LEX_NODE * sel= lex->current_select; if (sel->set_braces(1)) { send_error(lex->thd, ER_SYNTAX_ERROR); YYABORT; } /* select in braces, can't contain global parameters */ sel->master_unit()->global_parameters= sel->master_unit(); --- 1668,1684 ---- '(' SELECT_SYM select_part2 ')' { LEX *lex= Lex; ! SELECT_LEX * sel= lex->current_select->select_lex(); if (sel->set_braces(1)) { send_error(lex->thd, ER_SYNTAX_ERROR); YYABORT; } + if (sel->linkage == UNION_TYPE &&
!sel->master_unit()->first_select()->braces) + { + send_error(lex->thd, ER_SYNTAX_ERROR); + YYABORT; + } /* select in braces, can't contain global parameters */ sel->master_unit()->global_parameters= sel->master_unit(); *************** *** 1683,1693 **** --- 1688,1704 ---- select_part2 { LEX *lex= Lex; + SELECT_LEX * sel= lex->current_select->select_lex(); if (lex->current_select->set_braces(0)) { send_error(lex->thd, ER_SYNTAX_ERROR); YYABORT; } + if (sel->linkage == UNION_TYPE &&
sel->master_unit()->first_select()->braces) + { + send_error(lex->thd, ER_SYNTAX_ERROR); + YYABORT; + } } union_clause ; *************** *** 1695,1700 **** --- 1706,1712 ---- select_part2: { LEX *lex=Lex; + SELECT_LEX * sel= lex->current_select->select_lex(); if (lex->current_select == &lex->select_lex) lex->lock_option= TL_READ; /* Only for global SELECT */ mysql_init_select(lex); *************** *** 2509,2515 **** lex->current_select= unit->outer_select(); if (!($$= lex->current_select-> add_table_to_list(lex->thd, new Table_ident(unit), $5, 0, ! lex->lock_option))) YYABORT; };

--- 2521,2529 ---- lex->current_select= unit->outer_select(); if (!($$= lex->current_select-> add_table_to_list(lex->thd, new Table_ident(unit), $5, 0, ! lex->lock_option,(List<String> *)0, ! (List<String> *)0))) ! YYABORT; };

May be I fix this in 4.0 too, only fix will be different.

Join MySQL Users Conference and Expo: http://www.mysql.com/events/uc2003/