Commit f8ff8fc6 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

after review changes in IN/ALL/ANY/SOME (SCRUM)

parent aa9bfb44
...@@ -457,30 +457,52 @@ bool Item_asterisk_remover::fix_fields(THD *thd, ...@@ -457,30 +457,52 @@ bool Item_asterisk_remover::fix_fields(THD *thd,
{ {
DBUG_ENTER("Item_asterisk_remover::fix_fields"); DBUG_ENTER("Item_asterisk_remover::fix_fields");
bool res; bool res= 1;
if (item) if (item)
if (item->type() == Item::FIELD_ITEM && if (item->type() == Item::FIELD_ITEM &&
((Item_field*) item)->field_name[0] == '*') ((Item_field*) item)->field_name[0] == '*')
{ {
List<Item> fields; Item_field *fitem= (Item_field*) item;
fields.push_back(item); if (!list->next || fitem->db_name || fitem->table_name)
List_iterator<Item> it(fields); {
it++; TABLE_LIST *table= find_table_in_list(thd, list,
uint elem=fields.elements; fitem->db_name,
if (insert_fields(thd, list, ((Item_field*) item)->db_name, fitem->table_name);
((Item_field*) item)->table_name, &it)) if (table)
res= -1;
else
if (fields.elements > 1)
{ {
my_message(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL), MYF(0)); TABLE * tb= table->table;
res= -1; if (find_table_in_list(thd, table->next, fitem->db_name,
fitem->table_name) != 0 ||
tb->fields == 1)
{
if ((item= new Item_field(tb->field[0])))
{
res= 0;
tb->field[0]->query_id= thd->query_id;
tb->used_keys&= tb->field[0]->part_of_key;
tb->used_fields= tb->fields;
}
else
thd->fatal_error= 1; // can't create Item => out of memory
}
else
my_message(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL),
MYF(0));
} }
} else
if (!fitem->table_name)
my_error(ER_NO_TABLES_USED, MYF(0));
else
my_error(ER_BAD_TABLE_ERROR, MYF(0), fitem->table_name);
}
else
my_message(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL),
MYF(0));
}
else else
res= item->fix_fields(thd, list, &item); res= item->fix_fields(thd, list, &item);
else else
res= -1; thd->fatal_error= 1; // no item given => out of memory
*ref= item; *ref= item;
DBUG_RETURN(res); DBUG_RETURN(res);
} }
......
...@@ -124,9 +124,9 @@ public: ...@@ -124,9 +124,9 @@ public:
class Item_outer_select_context_saver :public Item_wrapper class Item_outer_select_context_saver :public Item_wrapper
{ {
public: public:
Item_outer_select_context_saver(Item *i) Item_outer_select_context_saver(Item *it)
{ {
item= i; item= it;
} }
bool fix_fields(THD *, struct st_table_list *, Item ** ref); bool fix_fields(THD *, struct st_table_list *, Item ** ref);
}; };
...@@ -137,9 +137,9 @@ public: ...@@ -137,9 +137,9 @@ public:
class Item_asterisk_remover :public Item_wrapper class Item_asterisk_remover :public Item_wrapper
{ {
public: public:
Item_asterisk_remover(Item *i) Item_asterisk_remover(Item *it)
{ {
item= i; item= it;
} }
bool fix_fields(THD *, struct st_table_list *, Item ** ref); bool fix_fields(THD *, struct st_table_list *, Item ** ref);
}; };
......
...@@ -280,13 +280,13 @@ void Item_in_subselect::single_value_transformer(st_select_lex *select_lex, ...@@ -280,13 +280,13 @@ void Item_in_subselect::single_value_transformer(st_select_lex *select_lex,
compare_func_creator func) compare_func_creator func)
{ {
DBUG_ENTER("Item_in_subselect::single_value_transformer"); DBUG_ENTER("Item_in_subselect::single_value_transformer");
for(SELECT_LEX * sl= select_lex; sl; sl= sl->next_select()) for (SELECT_LEX * sl= select_lex; sl; sl= sl->next_select())
{ {
Item *item; Item *item;
if (sl->item_list.elements > 1) if (sl->item_list.elements > 1)
{ {
my_message(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL), MYF(0)); my_message(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL), MYF(0));
item= 0; // Item_asterisk_remover mast fail item= 0; // Item_asterisk_remover must fail
} }
else else
item= (Item*) sl->item_list.pop(); item= (Item*) sl->item_list.pop();
...@@ -408,7 +408,7 @@ void subselect_union_engine::fix_length_and_dec() ...@@ -408,7 +408,7 @@ void subselect_union_engine::fix_length_and_dec()
{ {
uint32 mlen= 0, len; uint32 mlen= 0, len;
Item *sel_item= 0; Item *sel_item= 0;
for(SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select()) for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select())
{ {
List_iterator_fast<Item> li(sl->item_list); List_iterator_fast<Item> li(sl->item_list);
Item *s_item= li++; Item *s_item= li++;
......
...@@ -578,6 +578,8 @@ bool close_thread_table(THD *thd, TABLE **table_ptr); ...@@ -578,6 +578,8 @@ bool close_thread_table(THD *thd, TABLE **table_ptr);
void close_thread_tables(THD *thd,bool locked=0); void close_thread_tables(THD *thd,bool locked=0);
bool close_thread_table(THD *thd, TABLE **table_ptr); bool close_thread_table(THD *thd, TABLE **table_ptr);
void close_temporary_tables(THD *thd); void close_temporary_tables(THD *thd);
TABLE_LIST * find_table_in_list(TABLE_LIST *table,
const char *db_name, const char *table_name);
TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name); TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name);
bool close_temporary_table(THD *thd, const char *db, const char *table_name); bool close_temporary_table(THD *thd, const char *db, const char *table_name);
void close_temporary(TABLE *table, bool delete_table=1); void close_temporary(TABLE *table, bool delete_table=1);
......
...@@ -743,6 +743,29 @@ void close_temporary_tables(THD *thd) ...@@ -743,6 +743,29 @@ void close_temporary_tables(THD *thd)
thd->temporary_tables=0; thd->temporary_tables=0;
} }
/*
Find first suitable table in given list.
SYNOPSIS
find_table_in_list()
table - pointer to table list
db_name - data base name or 0 for any
table_name - table name or 0 for any
RETURN VALUES
NULL Table not found
# Pointer to found table.
*/
TABLE_LIST * find_table_in_list(TABLE_LIST *table,
const char *db_name, const char *table_name)
{
for (; table; table= table->next)
if ((!db_name || !strcmp(table->db, db_name)) &&
(!table_name || !strcmp(table->alias, table_name)))
break;
return table;
}
TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name) TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name)
{ {
......
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