summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <bell@sanja.is.com.ua>2002-05-28 22:38:17 +0300
committerunknown <bell@sanja.is.com.ua>2002-05-28 22:38:17 +0300
commit3d9cd36f47649a5693695576d3e6fb9dfd6648d9 (patch)
tree2920912526f6ed9cefd75065e939d7cd718a01b8
parent807b50855c4db0759aa93b84881c2559c24d01d4 (diff)
downloadmariadb-git-3d9cd36f47649a5693695576d3e6fb9dfd6648d9.tar.gz
limit clause fixed
-rw-r--r--mysql-test/r/subselect.result4
-rw-r--r--mysql-test/t/subselect.test7
-rw-r--r--sql/item_subselect.cc13
-rw-r--r--sql/sql_class.cc11
-rw-r--r--sql/sql_parse.cc9
5 files changed, 33 insertions, 11 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index cda4300d5f4..64ceea72498 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -36,4 +36,8 @@ a b
1 7
2 7
3 8
+select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2;
+(select a from t3 where a<t2.a*4 order by 1 desc limit 1) a
+3 1
+7 2
drop table t1,t2,t3,t4;
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index d4358a14e64..7383608ed9e 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -14,7 +14,10 @@ select (select a from t1), a from t2;
select (select a from t3), a from t2;
select * from t2 where t2.a=(select a from t1);
insert into t3 values (6),(7),(3);
-select * from t2 where t2.b=(select a from t3 order by 1 limit 1);
-select * from t2 where t2.b=(select a from t3 order by 1 limit 1)
+select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1);
+select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)
union (select * from t4 order by a limit 2) limit 3;
+select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2;
+select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from
+(select * from t2 where a>1) as tt;
drop table t1,t2,t3,t4;
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 777e46ce6b0..72bbbcba5a7 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -24,7 +24,6 @@ SUBSELECT TODO:
(sql_select.h/sql_select.cc)
- add subselect union select (sql_union.cc)
- - depended from outer select subselects
*/
@@ -41,6 +40,14 @@ Item_subselect::Item_subselect(THD *thd, st_select_lex *select_lex):
DBUG_ENTER("Item_subselect::Item_subselect");
DBUG_PRINT("subs", ("select_lex 0x%xl", (long) select_lex));
result= new select_subselect(this);
+ SELECT_LEX_UNIT *unit= select_lex->master_unit();
+ unit->offset_limit_cnt= unit->global_parameters->offset_limit;
+ unit->select_limit_cnt= unit->global_parameters->select_limit+
+ select_lex->offset_limit;
+ if (unit->select_limit_cnt < unit->global_parameters->select_limit)
+ unit->select_limit_cnt= HA_POS_ERROR; // no limit
+ if (unit->select_limit_cnt == HA_POS_ERROR)
+ select_lex->options&= ~OPTION_FOUND_ROWS;
join= new JOIN(thd, select_lex->item_list, select_lex->options, result);
this->select_lex= select_lex;
maybe_null= 1;
@@ -141,9 +148,9 @@ int Item_subselect::exec()
join->thd->lex.select= select_lex;
join->exec();
join->thd->lex.select= save_select;
- if (!executed)
+ //if (!executed)
//No rows returned => value is null (returned as inited)
- executed= 1;
+ // executed= 1;
return join->error;
}
return 0;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 751e4d25d41..975d36069f9 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -784,9 +784,15 @@ select_subselect::select_subselect(Item_subselect *item)
bool select_subselect::send_data(List<Item> &items)
{
+ DBUG_ENTER("select_subselect::send_data");
if (item->executed){
my_printf_error(ER_SUBSELECT_NO_1_ROW, ER(ER_SUBSELECT_NO_1_ROW), MYF(0));
- return 1;
+ DBUG_RETURN(1);
+ }
+ if (unit->offset_limit_cnt)
+ { // using limit offset,count
+ unit->offset_limit_cnt--;
+ DBUG_RETURN(0);
}
Item *val_item= (Item *)item->select_lex->item_list.head();
if ((item->null_value= val_item->is_null()))
@@ -801,5 +807,6 @@ bool select_subselect::send_data(List<Item> &items)
item->real_value= val_item->val();
item->res_type= val_item->result_type();
}
- return 0;
+ item->executed= 1;
+ DBUG_RETURN(0);
}
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 6affc0199a5..3492854329a 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1275,9 +1275,10 @@ mysql_execute_command(void)
break; // Error message is given
}
- unit->offset_limit_cnt =select_lex->offset_limit;
- unit->select_limit_cnt =select_lex->select_limit+select_lex->offset_limit;
- if (unit->select_limit_cnt < select_lex->select_limit)
+ unit->offset_limit_cnt= unit->global_parameters->offset_limit;
+ unit->select_limit_cnt= unit->global_parameters->select_limit+
+ unit->global_parameters->offset_limit;
+ if (unit->select_limit_cnt < unit->global_parameters->select_limit)
unit->select_limit_cnt= HA_POS_ERROR; // no limit
if (unit->select_limit_cnt == HA_POS_ERROR)
select_lex->options&= ~OPTION_FOUND_ROWS;
@@ -2672,7 +2673,7 @@ mysql_init_query(THD *thd)
thd->lex.unit.init_select();
thd->lex.select_lex.init_query();
thd->lex.unit.slave= &thd->lex.select_lex;
- thd->lex.unit.select_limit= thd->default_select_limit; //Global limit
+ thd->lex.unit.global_parameters= &thd->lex.select_lex; //Global limit & order
thd->lex.select_lex.master= &thd->lex.unit;
thd->lex.select_lex.prev= &thd->lex.unit.slave;
thd->lex.value_list.empty();