Commit 87eea667 authored by Sinisa@sinisa.nasamreza.org's avatar Sinisa@sinisa.nasamreza.org
Browse files

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

checkings
parent 2222dd94
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -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);
a	b
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;
a	b
3	c
@@ -157,3 +159,22 @@ testtt
tsestset
1
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;
+8 −0
Original line number Diff line number Diff line
@@ -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 SELECT 1;
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;
+2 −0
Original line number Diff line number Diff line
@@ -185,6 +185,8 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
	if (thd->select_limit == HA_POS_ERROR)
	  thd->options&= ~OPTION_FOUND_ROWS;
      }
      else 
	thd->select_limit= HA_POS_ERROR;		// no limit
      if (describe)
	thd->select_limit= HA_POS_ERROR;		// no limit
      res=mysql_select(thd,&result_table_list,
+7 −7
Original line number Diff line number Diff line
@@ -1430,22 +1430,22 @@ select_option_list:

select_option:
	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; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
	| SQL_BUFFER_RESULT { Select->options|= OPTION_BUFFER_RESULT; }
	| SQL_CALC_FOUND_ROWS { Select->options|= OPTION_FOUND_ROWS; }
	| SQL_NO_CACHE_SYM { current_thd->safe_to_cache_query=0; }
	| SQL_CACHE_SYM { Select->options |= OPTION_TO_QUERY_CACHE; }
	| SQL_BUFFER_RESULT { if (Select != &Lex->select_lex) YYABORT; Select->options|= OPTION_BUFFER_RESULT; }
	| SQL_CALC_FOUND_ROWS {  if (Select != &Lex->select_lex) YYABORT; Select->options|= OPTION_FOUND_ROWS; }
	| SQL_NO_CACHE_SYM {  if (Select != &Lex->select_lex) YYABORT; current_thd->safe_to_cache_query=0; }
	| SQL_CACHE_SYM {  if (Select != &Lex->select_lex) YYABORT; Select->options |= OPTION_TO_QUERY_CACHE; }
	| ALL		{}

select_lock_type:
	/* empty */
	| 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
	  { 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