fix for the limit bug in UNION's and some additional syntax

checkings
parent 2222dd94
...@@ -77,6 +77,8 @@ a b ...@@ -77,6 +77,8 @@ a b
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1); (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1);
a b a b
1 a 1 a
2 b
3 c
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc;
a b a b
3 c 3 c
...@@ -157,3 +159,22 @@ testtt ...@@ -157,3 +159,22 @@ testtt
tsestset tsestset
1 1
drop table t1; drop table t1;
drop table if exists t1,t2;
create table t1 (a int);
create table t2 (a int);
insert into t1 values (1),(2),(3),(4),(5);
insert into t2 values (11),(12),(13),(14),(15);
(select * from t1 limit 2) union (select * from t2 limit 3) limit 4;
a
1
2
11
12
(select * from t1 limit 2) union (select * from t2 limit 3);
a
1
2
11
12
13
drop table t1,t2;
...@@ -77,3 +77,11 @@ SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION SELECT pseudo FROM t1 WHERE pse ...@@ -77,3 +77,11 @@ SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION SELECT pseudo FROM t1 WHERE pse
SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION ALL SELECT pseudo FROM t1 WHERE pseudo1='joce'; SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION ALL SELECT pseudo FROM t1 WHERE pseudo1='joce';
SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION SELECT 1; SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION SELECT 1;
drop table t1; drop table t1;
drop table if exists t1,t2;
create table t1 (a int);
create table t2 (a int);
insert into t1 values (1),(2),(3),(4),(5);
insert into t2 values (11),(12),(13),(14),(15);
(select * from t1 limit 2) union (select * from t2 limit 3) limit 4;
(select * from t1 limit 2) union (select * from t2 limit 3);
drop table t1,t2;
...@@ -185,6 +185,8 @@ int mysql_union(THD *thd, LEX *lex,select_result *result) ...@@ -185,6 +185,8 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
if (thd->select_limit == HA_POS_ERROR) if (thd->select_limit == HA_POS_ERROR)
thd->options&= ~OPTION_FOUND_ROWS; thd->options&= ~OPTION_FOUND_ROWS;
} }
else
thd->select_limit= HA_POS_ERROR; // no limit
if (describe) if (describe)
thd->select_limit= HA_POS_ERROR; // no limit thd->select_limit= HA_POS_ERROR; // no limit
res=mysql_select(thd,&result_table_list, res=mysql_select(thd,&result_table_list,
......
...@@ -1430,22 +1430,22 @@ select_option_list: ...@@ -1430,22 +1430,22 @@ select_option_list:
select_option: select_option:
STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; } STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
| HIGH_PRIORITY { Lex->lock_option= TL_READ_HIGH_PRIORITY; } | HIGH_PRIORITY { if (Select != &Lex->select_lex) YYABORT; Lex->lock_option= TL_READ_HIGH_PRIORITY; }
| DISTINCT { Select->options|= SELECT_DISTINCT; } | DISTINCT { Select->options|= SELECT_DISTINCT; }
| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; } | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; } | SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
| SQL_BUFFER_RESULT { Select->options|= OPTION_BUFFER_RESULT; } | SQL_BUFFER_RESULT { if (Select != &Lex->select_lex) YYABORT; Select->options|= OPTION_BUFFER_RESULT; }
| SQL_CALC_FOUND_ROWS { Select->options|= OPTION_FOUND_ROWS; } | SQL_CALC_FOUND_ROWS { if (Select != &Lex->select_lex) YYABORT; Select->options|= OPTION_FOUND_ROWS; }
| SQL_NO_CACHE_SYM { current_thd->safe_to_cache_query=0; } | SQL_NO_CACHE_SYM { if (Select != &Lex->select_lex) YYABORT; current_thd->safe_to_cache_query=0; }
| SQL_CACHE_SYM { Select->options |= OPTION_TO_QUERY_CACHE; } | SQL_CACHE_SYM { if (Select != &Lex->select_lex) YYABORT; Select->options |= OPTION_TO_QUERY_CACHE; }
| ALL {} | ALL {}
select_lock_type: select_lock_type:
/* empty */ /* empty */
| FOR_SYM UPDATE_SYM | FOR_SYM UPDATE_SYM
{ Lex->lock_option= TL_WRITE; current_thd->safe_to_cache_query=0; } { if (Select != &Lex->select_lex) YYABORT; Lex->lock_option= TL_WRITE; current_thd->safe_to_cache_query=0; }
| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
{ Lex->lock_option= TL_READ_WITH_SHARED_LOCKS; current_thd->safe_to_cache_query=0; } { if (Select != &Lex->select_lex) YYABORT; Lex->lock_option= TL_READ_WITH_SHARED_LOCKS; current_thd->safe_to_cache_query=0; }
select_item_list: select_item_list:
select_item_list ',' select_item select_item_list ',' select_item
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment