Code cleanup

parent 55094f90
......@@ -722,20 +722,6 @@ bool Item::fix_fields(THD *thd,
return 0;
}
bool Item_ref_on_list_position::fix_fields(THD *thd,
struct st_table_list *tables,
Item ** reference)
{
if (select_lex->item_list.elements <= pos)
{
ref= 0;
my_error(ER_CARDINALITY_COL, MYF(0), pos);
return 1;
}
ref= select_lex->ref_pointer_array + pos;
return Item_ref_null_helper::fix_fields(thd, tables, reference);
}
double Item_ref_null_helper::val()
{
double tmp= (*ref)->val_result();
......
......@@ -637,33 +637,6 @@ class Item_null_helper :public Item_ref_null_helper
{}
};
/*
Used to find item in list of select items after '*' items processing.
Because item '*' can be used in item list. when we create
Item_ref_on_list_position we do not know how item list will be changed, but
we know number of item position (I mean queries like "select * from t").
*/
class Item_ref_on_list_position: public Item_ref_null_helper
{
protected:
/*
select_lex used for:
1) receiving expanded variant of item list (to check max possible
number of elements);
2) to have access to ref_pointer_array, via wich item will refered.
*/
st_select_lex *select_lex;
uint pos;
public:
Item_ref_on_list_position(Item_in_subselect* master,
st_select_lex *sl, uint num,
char *table_name, char *field_name):
Item_ref_null_helper(master, 0, table_name, field_name),
select_lex(sl), pos(num) {}
bool fix_fields(THD *, struct st_table_list *, Item ** ref);
};
/*
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
......
......@@ -650,15 +650,17 @@ Item_in_subselect::row_value_transformer(JOIN *join,
uint n= left_expr->cols();
select_lex->dependent= 1;
select_lex->setup_ref_array(thd,
select_lex->order_list.elements +
select_lex->group_list.elements);
Item *item= 0;
List_iterator_fast<Item> li(select_lex->item_list);
for (uint i= 0; i < n; i++)
{
Item *func=
new Item_ref_on_list_position(this, select_lex, i,
(char *) "<no matter>",
(char *) "<list ref>");
Item *func= new Item_ref_null_helper(this,
select_lex->ref_pointer_array+i,
(char *) "<no matter>",
(char *) "<list ref>");
func=
Item_bool_func2::eq_creator(new Item_ref((*optimizer->get_cache())->
addr(i),
......
......@@ -411,7 +411,6 @@ int mysql_preload_keys(THD* thd, TABLE_LIST* table_list);
bool check_simple_select();
SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length);
int setup_ref_array(THD *thd, Item ***rref_pointer_array, uint elements);
int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
List<Item> &fields, List <Item> &all_fields, ORDER *order);
int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
......
......@@ -126,8 +126,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order,
table->sort.io_cache = (IO_CACHE *) my_malloc(sizeof(IO_CACHE),
MYF(MY_FAE | MY_ZEROFILL));
if (setup_ref_array(thd, &thd->lex.select_lex.ref_pointer_array,
all_fields.elements)||
if (thd->lex.select_lex.setup_ref_array(thd, 0) ||
setup_order(thd, thd->lex.select_lex.ref_pointer_array, &tables,
fields, all_fields, order) ||
!(sortorder=make_unireg_sortorder(order, &length)) ||
......
......@@ -135,11 +135,9 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit,
item_list= select_cursor->item_list;
select_cursor->with_wild= 0;
if (setup_ref_array(thd, &select_cursor->ref_pointer_array,
(item_list.elements +
select_cursor->select_n_having_items +
select_cursor->order_list.elements +
select_cursor->group_list.elements)) ||
if (select_cursor->setup_ref_array(thd,
select_cursor->order_list.elements +
select_cursor->group_list.elements) ||
setup_fields(thd, select_cursor->ref_pointer_array, first_table,
item_list, 0, 0, 1))
{
......
......@@ -981,6 +981,7 @@ void st_select_lex::init_query()
resolve_mode= NOMATTER_MODE;
cond_count= with_wild= 0;
ref_pointer_array= 0;
select_n_having_items= 0;
}
void st_select_lex::init_select()
......@@ -989,7 +990,6 @@ void st_select_lex::init_select()
group_list.empty();
type= db= db1= table1= db2= table2= 0;
having= 0;
group_list.empty();
use_index_ptr= ignore_index_ptr= 0;
table_join_options= 0;
in_sum_expr= with_wild= 0;
......@@ -1007,7 +1007,6 @@ void st_select_lex::init_select()
order_list.next= (byte**) &order_list.first;
select_limit= HA_POS_ERROR;
offset_limit= 0;
select_n_having_items= 0;
with_sum_func= 0;
parsing_place= SELECT_LEX_NODE::NO_MATTER;
}
......@@ -1410,6 +1409,17 @@ ulong st_select_lex::get_table_join_options()
return table_join_options;
}
bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
{
if (ref_pointer_array)
return 0;
return (ref_pointer_array=
(Item **)thd->alloc(sizeof(Item*) *
(item_list.elements +
select_n_having_items +
order_group_num)* 5)) == 0;
}
/*
There are st_select_lex::add_table_to_list &
st_select_lex::set_lock_for_tables in sql_parse.cc
......
......@@ -449,6 +449,7 @@ class st_select_lex: public st_select_lex_node
init_query();
init_select();
}
bool setup_ref_array(THD *thd, uint order_group_num);
};
typedef class st_select_lex SELECT_LEX;
......
......@@ -294,10 +294,7 @@ JOIN::prepare(Item ***rref_pointer_array,
setup_wild(thd, tables_list,
fields_list,
&all_fields, wild_num))) ||
setup_ref_array(thd, rref_pointer_array, (fields_list.elements +
select_lex->
select_n_having_items +
og_num)) ||
select_lex->setup_ref_array(thd, og_num) ||
setup_fields(thd, (*rref_pointer_array), tables_list, fields_list, 1,
&all_fields, 1) ||
setup_without_group(thd, (*rref_pointer_array), tables_list, fields_list,
......@@ -7483,19 +7480,6 @@ find_order_in_list(THD *thd, Item **ref_pointer_array,
return 0;
}
/*
Allocate array of references to address all_fileds list elements
*/
int setup_ref_array(THD* thd, Item ***rref_pointer_array, uint elements)
{
if (*rref_pointer_array)
return 0;
return (*rref_pointer_array=
(Item **)thd->alloc(sizeof(Item*) * elements * 5)) == 0;
}
/*
Change order to point at item in select list. If item isn't a number
and doesn't exits in the select list, add it the the field list.
......
......@@ -2501,8 +2501,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
tables.db = from->table_cache_key;
error=1;
if (setup_ref_array(thd, &thd->lex.select_lex.ref_pointer_array,
order_num)||
if (thd->lex.select_lex.setup_ref_array(thd, order_num) ||
setup_order(thd, thd->lex.select_lex.ref_pointer_array,
&tables, fields, all_fields, order) ||
!(sortorder=make_unireg_sortorder(order, &length)) ||
......
......@@ -156,11 +156,9 @@ int st_select_lex_unit::prepare(THD *thd, select_result *sel_result,
Item *item;
item_list= select_cursor->item_list;
select_cursor->with_wild= 0;
if (setup_ref_array(thd, &select_cursor->ref_pointer_array,
(item_list.elements +
select_cursor->select_n_having_items +
select_cursor->order_list.elements +
select_cursor->group_list.elements)) ||
if (select_cursor->setup_ref_array(thd,
select_cursor->order_list.elements +
select_cursor->group_list.elements) ||
setup_fields(thd, select_cursor->ref_pointer_array, first_table,
item_list, 0, 0, 1))
goto err;
......
......@@ -94,8 +94,7 @@ int mysql_update(THD *thd,
if (setup_tables(update_table_list) ||
setup_conds(thd,update_table_list,&conds) ||
setup_ref_array(thd, &thd->lex.select_lex.ref_pointer_array,
order_num) ||
thd->lex.select_lex.setup_ref_array(thd, order_num) ||
setup_order(thd, thd->lex.select_lex.ref_pointer_array,
&tables, all_fields, all_fields, order) ||
setup_ftfuncs(&thd->lex.select_lex))
......
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