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

Item_in_optimizer is changed to be used with row IN subselect (SCRUM)

removed unused items
parent 4cfb6d97
...@@ -47,11 +47,6 @@ Item::Item(): ...@@ -47,11 +47,6 @@ Item::Item():
loop_id= 0; loop_id= 0;
} }
Item_ref_in_optimizer::Item_ref_in_optimizer(Item_in_optimizer *master,
char *table_name_par,
char *field_name_par):
Item_ref(master->args, table_name_par, field_name_par), owner(master) {}
bool Item::check_loop(uint id) bool Item::check_loop(uint id)
{ {
...@@ -437,20 +432,6 @@ String *Item_copy_string::val_str(String *str) ...@@ -437,20 +432,6 @@ String *Item_copy_string::val_str(String *str)
return &str_value; return &str_value;
} }
double Item_ref_in_optimizer::val()
{
return owner->get_cache();
}
longlong Item_ref_in_optimizer::val_int()
{
return owner->get_cache_int();
}
String* Item_ref_in_optimizer::val_str(String* s)
{
return owner->get_cache_str(s);
}
/* /*
Functions to convert item to field (for send_fields) Functions to convert item to field (for send_fields)
*/ */
...@@ -464,18 +445,6 @@ bool Item::fix_fields(THD *thd, ...@@ -464,18 +445,6 @@ bool Item::fix_fields(THD *thd,
return 0; return 0;
} }
bool Item_outer_select_context_saver::fix_fields(THD *thd,
struct st_table_list *list,
Item ** ref)
{
DBUG_ENTER("Item_outer_select_context_saver::fix_fields");
bool res= item->fix_fields(thd,
0, // do not show current subselect fields
&item);
*ref= item;
DBUG_RETURN(res);
}
bool Item_asterisk_remover::fix_fields(THD *thd, bool Item_asterisk_remover::fix_fields(THD *thd,
struct st_table_list *list, struct st_table_list *list,
Item ** ref) Item ** ref)
......
...@@ -109,60 +109,6 @@ public: ...@@ -109,60 +109,6 @@ public:
}; };
/*
Wrapper base class
*/
class Item_wrapper :public Item
{
protected:
Item *item;
public:
/*
Following methods should not be used, because fix_fields exclude this
item (it assign '*ref' with field 'item' in derived classes)
*/
enum Type type() const { return item->type(); }
enum_field_types field_type() const { return item->field_type(); }
double val() { return item->val(); }
longlong val_int() { return item->val_int(); }
String* val_str(String* s) { return item->val_str(s); }
bool check_cols(uint col) { return item->check_cols(col); }
bool eq(const Item *item, bool binary_cmp) const
{ return item->eq(item, binary_cmp); }
bool is_null()
{
item->val_int();
return item->null_value;
}
bool get_date(TIME *ltime, bool fuzzydate)
{
return (null_value=item->get_date(ltime, fuzzydate));
}
bool send(Protocol *prot, String *tmp) { return item->send(prot, tmp); }
int save_in_field(Field *field, bool no_conversions)
{
return item->save_in_field(field, no_conversions);
}
void save_org_in_field(Field *field) { item->save_org_in_field(field); }
enum Item_result result_type () const { return item->result_type(); }
table_map used_tables() const { return item->used_tables(); }
};
/*
Save context of name resolution for Item, used in subselect transformer.
*/
class Item_outer_select_context_saver :public Item_wrapper
{
public:
Item_outer_select_context_saver(Item *it)
{
item= it;
}
bool fix_fields(THD *, struct st_table_list *, Item ** ref);
};
class st_select_lex; class st_select_lex;
class Item_ident :public Item class Item_ident :public Item
{ {
...@@ -579,24 +525,6 @@ public: ...@@ -579,24 +525,6 @@ public:
bool fix_fields(THD *, struct st_table_list *, Item ** ref); bool fix_fields(THD *, struct st_table_list *, Item ** ref);
}; };
class Item_in_optimizer;
class Item_ref_in_optimizer: public Item_ref
{
protected:
Item_in_optimizer* owner;
public:
Item_ref_in_optimizer(Item_in_optimizer* master,
char *table_name_par,char *field_name_par);
double val();
longlong val_int();
String* val_str(String* s);
bool fix_fields(THD *, struct st_table_list *, Item ** ref)
{
fixed= 1;
return 0;
}
};
/* /*
The following class is used to optimize comparing of date columns The following class is used to optimize comparing of date columns
We need to save the original item, to be able to set the field to the We need to save the original item, to be able to set the field to the
......
...@@ -274,13 +274,41 @@ int Arg_comparator::compare_e_row() ...@@ -274,13 +274,41 @@ int Arg_comparator::compare_e_row()
return 1; return 1;
} }
bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables,
Item ** ref)
{
if (args[0]->check_cols(allowed_arg_cols) ||
args[0]->fix_fields(thd, tables, args))
return 1;
if (args[0]->maybe_null)
maybe_null=1;
if (args[0]->binary())
set_charset(my_charset_bin);
with_sum_func= args[0]->with_sum_func;
used_tables_cache= args[0]->used_tables();
const_item_cache= args[0]->const_item();
if (!(cache= Item_cache::get_cache(args[0]->result_type())))
{
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
thd->fatal_error= 1;
return 1;
}
if (args[1]->check_cols(allowed_arg_cols) ||
args[1]->fix_fields(thd, tables, args))
return 1;
if (args[1]->maybe_null)
maybe_null=1;
with_sum_func= with_sum_func || args[1]->with_sum_func;
used_tables_cache|= args[1]->used_tables();
const_item_cache&= args[1]->const_item();
return 0;
}
longlong Item_in_optimizer::val_int() longlong Item_in_optimizer::val_int()
{ {
int_cache_ok= 1; cache->store(args[0]);
flt_cache_ok= 0; if (cache->null_value)
str_cache_ok= 0;
int_cache= args[0]->val_int_result();
if (args[0]->null_value)
{ {
null_value= 1; null_value= 1;
return 0; return 0;
...@@ -290,44 +318,10 @@ longlong Item_in_optimizer::val_int() ...@@ -290,44 +318,10 @@ longlong Item_in_optimizer::val_int()
return tmp; return tmp;
} }
longlong Item_in_optimizer::get_cache_int() bool Item_in_optimizer::is_null()
{ {
if (!int_cache_ok) cache->store(args[0]);
{ return (null_value= (cache->null_value || args[1]->is_null()));
int_cache_ok= 1;
flt_cache_ok= 0;
str_cache_ok= 0;
int_cache= args[0]->val_int_result();
null_value= args[0]->null_value;
}
return int_cache;
}
double Item_in_optimizer::get_cache()
{
if (!flt_cache_ok)
{
flt_cache_ok= 1;
int_cache_ok= 0;
str_cache_ok= 0;
flt_cache= args[0]->val_result();
null_value= args[0]->null_value;
}
return flt_cache;
}
String *Item_in_optimizer::get_cache_str(String *s)
{
if (!str_cache_ok)
{
str_cache_ok= 1;
int_cache_ok= 0;
flt_cache_ok= 0;
str_value.set(buffer, sizeof(buffer), s->charset());
str_cache= args[0]->str_result(&str_value);
null_value= args[0]->null_value;
}
return str_cache;
} }
longlong Item_func_eq::val_int() longlong Item_func_eq::val_int()
......
...@@ -85,25 +85,20 @@ public: ...@@ -85,25 +85,20 @@ public:
void fix_length_and_dec() { decimals=0; max_length=1; } void fix_length_and_dec() { decimals=0; max_length=1; }
}; };
class Item_cache;
class Item_in_optimizer: public Item_bool_func class Item_in_optimizer: public Item_bool_func
{ {
protected: protected:
char buffer[80]; Item_cache *cache;
longlong int_cache;
double flt_cache;
String *str_cache;
bool int_cache_ok, flt_cache_ok, str_cache_ok;
public: public:
Item_in_optimizer(Item *a,Item *b): Item_in_optimizer(Item *a,Item *b):
Item_bool_func(a,b), int_cache_ok(0), flt_cache_ok(0), str_cache_ok(0) {} Item_bool_func(a,b), cache(0) {}
bool is_null() { return test(args[0]->is_null() || args[1]->is_null()); } bool fix_fields(THD *, struct st_table_list *, Item **);
bool is_null();
longlong val_int(); longlong val_int();
Item **get_cache() { return (Item**)&cache; }
double get_cache();
longlong get_cache_int();
String *get_cache_str(String *s);
friend class Item_ref_in_optimizer;
}; };
class Item_bool_func2 :public Item_int_func class Item_bool_func2 :public Item_int_func
......
...@@ -409,8 +409,9 @@ void Item_in_subselect::single_value_transformer(st_select_lex *select_lex, ...@@ -409,8 +409,9 @@ void Item_in_subselect::single_value_transformer(st_select_lex *select_lex,
As far as Item_ref_in_optimizer do not substitude itself on fix_fields As far as Item_ref_in_optimizer do not substitude itself on fix_fields
we can use same item for all selects. we can use same item for all selects.
*/ */
Item *expr= new Item_ref_in_optimizer(optimizer, (char *)"<no matter>", Item *expr= new Item_ref(optimizer->get_cache(),
(char*)"<left expr>"); (char *)"<no matter>",
(char*)"<left expr>");
select_lex->master_unit()->dependent= 1; select_lex->master_unit()->dependent= 1;
for (SELECT_LEX * sl= select_lex; sl; sl= sl->next_select()) for (SELECT_LEX * sl= select_lex; sl; sl= sl->next_select())
{ {
......
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