From: Date: May 19 2006 5:41pm Subject: bk commit into 5.0 tree (gkodinov:1.2130) BUG#14654 List-Archive: http://lists.mysql.com/commits/6643 X-Bug: 14654 Message-Id: <200605191541.k4JFfFR7005652@localhost.localdomain> Below is the list of changes that have just been committed into a local 5.0 repository of kgeorge. When kgeorge does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2130 06/05/19 18:41:02 gkodinov@stripped +3 -0 Bug#14654 : Cannot select from the same table twice within a UNION statement Made the parser to support parenthesis around UNION branches. This is done by amending the rules of the parser so it generates the correct structure. sql/sql_yacc.yy 1.470 06/05/19 18:40:49 gkodinov@stripped +50 -52 shuffle around the rules for the parenthesis mysql-test/t/subselect2.test 1.7 06/05/19 18:40:49 gkodinov@stripped +15 -0 Test suite for the bug mysql-test/r/subselect2.result 1.13 06/05/19 18:40:49 gkodinov@stripped +10 -0 Test suite for the bug # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: gkodinov # Host: rakia.(none) # Root: /home/kgeorge/mysql/5.0/B14654 --- 1.469/sql/sql_yacc.yy 2006-05-14 23:51:02 +03:00 +++ 1.470/sql/sql_yacc.yy 2006-05-19 18:40:49 +03:00 @@ -725,8 +725,8 @@ predicate bit_expr bit_term bit_factor value_expr term factor table_wild simple_expr udf_expr expr_or_default set_expr_or_default interval_expr - param_marker singlerow_subselect singlerow_subselect_init - exists_subselect exists_subselect_init geometry_function + param_marker singlerow_subselect + exists_subselect geometry_function signed_literal now_or_signed_literal opt_escape sp_opt_default simple_ident_nospvar simple_ident_q @@ -791,7 +791,7 @@ %type internal_variable_name -%type in_subselect in_subselect_init +%type in_subselect subselect_start get_select_lex %type comp_op @@ -825,7 +825,7 @@ handler_rkey_function handler_read_or_scan single_multi table_wild_list table_wild_one opt_wild union_clause union_list - precision subselect_start opt_and charset + precision opt_and charset subselect_end select_var_list select_var_list_init help opt_len opt_extended_describe prepare prepare_src execute deallocate @@ -4127,27 +4127,27 @@ | predicate ; predicate: - bit_expr IN_SYM '(' expr_list ')' + bit_expr IN_SYM '(' expr ')' + { + $$= new Item_func_eq($1, $4); + } + | bit_expr IN_SYM '(' expr ',' expr_list ')' { - if ($4->elements == 1) - $$= new Item_func_eq($1, $4->head()); - else - { - $4->push_front($1); - $$= new Item_func_in(*$4); - } + $6->push_front($4); + $6->push_front($1); + $$= new Item_func_in(*$6); } - | bit_expr not IN_SYM '(' expr_list ')' + | bit_expr not IN_SYM '(' expr ')' { - if ($5->elements == 1) - $$= new Item_func_ne($1, $5->head()); - else - { - $5->push_front($1); - Item_func_in *item = new Item_func_in(*$5); + $$= new Item_func_ne($1, $5); + } + | bit_expr not IN_SYM '(' expr ',' expr_list ')' + { + $7->push_front($5); + $7->push_front($1); + Item_func_in *item = new Item_func_in(*$7); item->negate(); $$= item; - } } | bit_expr IN_SYM in_subselect { $$= new Item_in_subselect($1, $3); } @@ -8812,45 +8812,22 @@ ; singlerow_subselect: - subselect_start singlerow_subselect_init - subselect_end + subselect_start subselect_end { - $$= $2; - }; - -singlerow_subselect_init: - select_init2 - { - $$= new Item_singlerow_subselect(Lex->current_select-> - master_unit()->first_select()); + $$= new Item_singlerow_subselect($1); }; exists_subselect: - subselect_start exists_subselect_init - subselect_end + subselect_start subselect_end { - $$= $2; - }; - -exists_subselect_init: - select_init2 - { - $$= new Item_exists_subselect(Lex->current_select->master_unit()-> - first_select()); + $$= new Item_exists_subselect($1); }; in_subselect: - subselect_start in_subselect_init - subselect_end - { - $$= $2; - }; - -in_subselect_init: - select_init2 - { - $$= Lex->current_select->master_unit()->first_select(); - }; + subselect_start subselect_end + { + $$= $1; + }; subselect_start: '(' SELECT_SYM @@ -8864,7 +8841,28 @@ } if (mysql_new_select(Lex, 1)) YYABORT; - }; + } + select_init2 + { + $$=Lex->current_select->master_unit()->first_select(); + } + | + '(' '(' + { + LEX *lex=Lex; + if (lex->sql_command == (int)SQLCOM_HA_READ || + lex->sql_command == (int)SQLCOM_KILL) + { + yyerror(ER(ER_SYNTAX_ERROR)); + YYABORT; + } + if (mysql_new_select(Lex, 1)) + YYABORT; + } + select_paren ')' union_opt + { + $$=Lex->current_select->master_unit()->first_select(); + }; subselect_end: ')' --- 1.12/mysql-test/r/subselect2.result 2005-10-10 20:38:26 +03:00 +++ 1.13/mysql-test/r/subselect2.result 2006-05-19 18:40:49 +03:00 @@ -132,3 +132,13 @@ 5 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,FFOLDERID_IDX PRIMARY 34 func 1 Using index; Using where 6 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 func 1 Using index; Using where drop table t1, t2, t3, t4; +CREATE TABLE t1 (i INT); +(SELECT i FROM t1) UNION (SELECT i FROM t1); +i +SELECT sql_no_cache * FROM t1 WHERE NOT EXISTS +( +(SELECT i FROM t1) UNION +(SELECT i FROM t1) +); +i +DROP TABLE t1; --- 1.6/mysql-test/t/subselect2.test 2006-05-12 19:26:48 +03:00 +++ 1.7/mysql-test/t/subselect2.test 2006-05-19 18:40:49 +03:00 @@ -150,3 +150,18 @@ drop table t1, t2, t3, t4; # End of 4.1 tests + +# +# Bug#14654 : Cannot select from the same table twice within a UNION +# statement +# +CREATE TABLE t1 (i INT); + +(SELECT i FROM t1) UNION (SELECT i FROM t1); +SELECT sql_no_cache * FROM t1 WHERE NOT EXISTS + ( + (SELECT i FROM t1) UNION + (SELECT i FROM t1) + ); + +DROP TABLE t1;