summaryrefslogtreecommitdiff
path: root/sql/item_subselect.cc
diff options
context:
space:
mode:
authorunknown <bell@sanja.is.com.ua>2002-11-28 19:29:26 +0200
committerunknown <bell@sanja.is.com.ua>2002-11-28 19:29:26 +0200
commit6f80b711692d99d5d197cece8fe978eab6f1f3ec (patch)
tree00a9de3df37ec79df37b41b63cb2971efe86b0a1 /sql/item_subselect.cc
parent5a1b9e1d05ec4c52e89df1adf40312a55f8b7d3f (diff)
downloadmariadb-git-6f80b711692d99d5d197cece8fe978eab6f1f3ec.tar.gz
fixed * without tables in IN bug
fixed sunction-test select in IN bug fixed unions in subselect bug include/mysqld_error.h: new warning mysql-test/r/subselect.result: test of * without tables in IN test of sunction-test select in IN test of unions in subselect mysql-test/t/subselect.test: test of * without tables in IN test of sunction-test select in IN test of unions in subselect sql/item.cc: fixed * substitution without tables sql/item_subselect.cc: fixed subselect rewriting with function-test subselect sql/item_subselect.h: mechanism for subselect removing sql/share/czech/errmsg.txt: new warning sql/share/danish/errmsg.txt: new warning sql/share/dutch/errmsg.txt: new warning sql/share/english/errmsg.txt: new warning sql/share/estonian/errmsg.txt: new warning sql/share/french/errmsg.txt: new warning sql/share/german/errmsg.txt: new warning sql/share/greek/errmsg.txt: new warning sql/share/hungarian/errmsg.txt: new warning sql/share/italian/errmsg.txt: new warning sql/share/japanese/errmsg.txt: new warning sql/share/korean/errmsg.txt: new warning sql/share/norwegian-ny/errmsg.txt: new warning sql/share/norwegian/errmsg.txt: new warning sql/share/polish/errmsg.txt: new warning sql/share/portuguese/errmsg.txt: new warning sql/share/romanian/errmsg.txt: new warning sql/share/russian/errmsg.txt: new warning sql/share/serbian/errmsg.txt: new warning sql/share/slovak/errmsg.txt: new warning sql/share/spanish/errmsg.txt: new warning sql/share/swedish/errmsg.txt: new warning sql/share/ukrainian/errmsg.txt: new warning sql/sql_base.cc: fixed case on no name field in UNION subselect sql/sql_lex.cc: mechanisp of removing single subselect for optimisation purposes sql/sql_lex.h: mechanisp of removing single subselect for optimisation purposes sql/sql_parse.cc: error handling sql/sql_union.cc: fixed unions in subselect sql/sql_yacc.yy: fixed Lex->describe flag appearence
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r--sql/item_subselect.cc66
1 files changed, 59 insertions, 7 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 555b7ae45c3..e0bfbe01c9b 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -33,7 +33,7 @@ SUBSELECT TODO:
#include "sql_select.h"
Item_subselect::Item_subselect():
- Item_result_field(), engine_owner(1), value_assigned(0)
+ Item_result_field(), engine_owner(1), value_assigned(0), substitution(0)
{
assign_null();
/*
@@ -89,6 +89,13 @@ void Item_subselect::make_field (Send_field *tmp_field)
bool Item_subselect::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
+ if (substitution)
+ {
+ (*ref)= substitution;
+ engine->exclude();
+ return substitution->fix_fields(thd, tables, ref);
+ }
+
char const *save_where= thd->where;
int res= engine->prepare();
if (!res)
@@ -291,12 +298,12 @@ void Item_in_subselect::single_value_transformer(st_select_lex *select_lex,
else
item= (Item*) sl->item_list.pop();
- left_expr= new Item_outer_select_context_saver(left_expr);
+ Item *expr= new Item_outer_select_context_saver(left_expr);
if (sl->having || sl->with_sum_func || sl->group_list.first)
{
sl->item_list.push_back(item);
- item= (*func)(left_expr, new Item_ref(sl->item_list.head_ref(),
+ item= (*func)(expr, new Item_ref(sl->item_list.head_ref(),
0, "<result>"));
if (sl->having)
sl->having= new Item_cond_and(sl->having, item);
@@ -307,11 +314,42 @@ void Item_in_subselect::single_value_transformer(st_select_lex *select_lex,
{
sl->item_list.empty();
sl->item_list.push_back(new Item_int(1));
- item= (*func)(left_expr, new Item_asterisk_remover(item));
- if (sl->where)
- sl->where= new Item_cond_and(sl->where, item);
+ if (sl->table_list.elements)
+ {
+ item= (*func)(expr, new Item_asterisk_remover(item));
+ if (sl->where)
+ sl->where= new Item_cond_and(sl->where, item);
+ else
+ sl->where= item;
+ }
else
- sl->where= item;
+ {
+ if (item->type() == Item::FIELD_ITEM &&
+ ((Item_field*) item)->field_name[0] == '*')
+ {
+ my_error(ER_NO_TABLES_USED, MYF(0));
+ DBUG_VOID_RETURN;
+ }
+ if (select_lex->next_select())
+ {
+ // it is in union => we should perform it
+ sl->having= (*func)(expr, item);
+ }
+ else
+ {
+ // it is single select without tables => possible optimization
+ item= (*func)(left_expr, item);
+ substitution= item;
+ THD *thd= current_thd;
+ if (thd->lex.describe)
+ {
+ char warn_buff[MYSQL_ERRMSG_SIZE];
+ sprintf(warn_buff, ER(ER_SELECT_REDUCED), sl->select_number);
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+ ER_SELECT_REDUCED, warn_buff);
+ }
+ }
+ }
}
}
DBUG_VOID_RETURN;
@@ -502,3 +540,17 @@ bool subselect_union_engine::check_loop(uint id)
DBUG_RETURN(1);
DBUG_RETURN(0);
}
+
+void subselect_single_select_engine::exclude()
+{
+ select_lex->master_unit()->exclude_level();
+ //if (current_thd->lex->describe)
+}
+
+void subselect_union_engine::exclude()
+{
+ unit->exclude_level();
+ // for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select())
+ // if (sl->join && sl->join->check_loop(id))
+ // DBUG_RETURN(1);
+}