Commit 90ced854 authored by unknown's avatar unknown

Prevent needless rexecuting empty subselects

parent 4a1dec3d
...@@ -36,7 +36,7 @@ SUBSELECT TODO: ...@@ -36,7 +36,7 @@ SUBSELECT TODO:
#include "sql_select.h" #include "sql_select.h"
Item_subselect::Item_subselect(THD *thd, st_select_lex *select_lex): Item_subselect::Item_subselect(THD *thd, st_select_lex *select_lex):
executed(0), optimized(0), error(0) assigned(0), executed(0), optimized(0), error(0)
{ {
DBUG_ENTER("Item_subselect::Item_subselect"); DBUG_ENTER("Item_subselect::Item_subselect");
DBUG_PRINT("subs", ("select_lex 0x%xl", (long) select_lex)); DBUG_PRINT("subs", ("select_lex 0x%xl", (long) select_lex));
...@@ -141,7 +141,7 @@ int Item_subselect::exec() ...@@ -141,7 +141,7 @@ int Item_subselect::exec()
return 1; return 1;
} }
assign_null(); assign_null();
executed= 0; executed= assigned= 0;
} }
if (!executed) if (!executed)
{ {
...@@ -149,6 +149,7 @@ int Item_subselect::exec() ...@@ -149,6 +149,7 @@ int Item_subselect::exec()
join->thd->lex.select= select_lex; join->thd->lex.select= select_lex;
join->exec(); join->exec();
join->thd->lex.select= save_select; join->thd->lex.select= save_select;
executed= 1;
return join->error; return join->error;
} }
return 0; return 0;
......
...@@ -31,6 +31,7 @@ class Item_subselect :public Item ...@@ -31,6 +31,7 @@ class Item_subselect :public Item
protected: protected:
longlong int_value; longlong int_value;
double real_value; double real_value;
my_bool assigned; /* value already assigned to subselect */
my_bool executed; /* simple subselect is executed */ my_bool executed; /* simple subselect is executed */
my_bool optimized; /* simple subselect is optimized */ my_bool optimized; /* simple subselect is optimized */
my_bool error; /* error in query */ my_bool error; /* error in query */
...@@ -59,6 +60,7 @@ public: ...@@ -59,6 +60,7 @@ public:
max_length= item->max_length; max_length= item->max_length;
decimals= item->decimals; decimals= item->decimals;
res_type= item->res_type; res_type= item->res_type;
assigned= item->assigned;
executed= item->executed; executed= item->executed;
select_lex= item->select_lex; select_lex= item->select_lex;
join= item->join; join= item->join;
......
...@@ -785,7 +785,7 @@ select_subselect::select_subselect(Item_subselect *item) ...@@ -785,7 +785,7 @@ select_subselect::select_subselect(Item_subselect *item)
bool select_subselect::send_data(List<Item> &items) bool select_subselect::send_data(List<Item> &items)
{ {
DBUG_ENTER("select_subselect::send_data"); DBUG_ENTER("select_subselect::send_data");
if (item->executed){ if (item->assigned){
my_printf_error(ER_SUBSELECT_NO_1_ROW, ER(ER_SUBSELECT_NO_1_ROW), MYF(0)); my_printf_error(ER_SUBSELECT_NO_1_ROW, ER(ER_SUBSELECT_NO_1_ROW), MYF(0));
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -812,6 +812,6 @@ bool select_subselect::send_data(List<Item> &items) ...@@ -812,6 +812,6 @@ bool select_subselect::send_data(List<Item> &items)
item->int_value= val_item->val_int(); item->int_value= val_item->val_int();
item->res_type= val_item->result_type(); item->res_type= val_item->result_type();
} }
item->executed= 1; item->assigned= 1;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
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