Commit e1134143 authored by unknown's avatar unknown

after-review changes (577 SCRUM)


sql/item.cc:
  typo fix
sql/item.h:
  typo fix
sql/item_cmpfunc.cc:
  comment
sql/item_func.cc:
  new interface
sql/item_subselect.cc:
  comment inserted
sql/item_sum.cc:
  layout fixed
  comment inserted
sql/mysql_priv.h:
  names changed
sql/sql_base.cc:
  some optimization
sql/sql_delete.cc:
  name changed
sql/sql_insert.cc:
  name changed
sql/sql_lex.h:
  name changed
sql/sql_prepare.cc:
  layout fixed
sql/sql_select.cc:
  layout fixed
  names changed
  comments inserted
  debugging code removed
sql/sql_select.h:
  name changed
sql/sql_union.cc:
  name changed
  layout fixed
sql/sql_update.cc:
  name changed
sql/sql_yacc.yy:
  typo fixed
parent 98226233
...@@ -673,7 +673,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) ...@@ -673,7 +673,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
return 1; return 1;
if (r->fix_fields(thd, tables, ref) || r->check_cols(1)) if (r->fix_fields(thd, tables, ref) || r->check_cols(1))
return 1; return 1;
// store pointer on SELECT_LEX from wich item is dependent // store pointer on SELECT_LEX from which item is dependent
r->depended_from= last; r->depended_from= last;
cursel->mark_as_dependent(last); cursel->mark_as_dependent(last);
return 0; return 0;
......
...@@ -535,7 +535,7 @@ protected: ...@@ -535,7 +535,7 @@ protected:
/* /*
select_lex used for: select_lex used for:
1) receiving expanded variant of item list (to check max possible 1) receiving expanded variant of item list (to check max possible
nunber of elements); number of elements);
2) to have access to ref_pointer_array, via wich item will refered. 2) to have access to ref_pointer_array, via wich item will refered.
*/ */
st_select_lex *select_lex; st_select_lex *select_lex;
......
...@@ -1071,6 +1071,7 @@ in_string::~in_string() ...@@ -1071,6 +1071,7 @@ in_string::~in_string()
{ {
if (base) if (base)
{ {
// base was allocated with help of sql_alloc => following is OK
for (uint i=0 ; i < count ; i++) for (uint i=0 ; i < count ; i++)
((String*) base)[i].free(); ((String*) base)[i].free();
} }
......
...@@ -2213,7 +2213,7 @@ void Item_func_get_user_var::fix_length_and_dec() ...@@ -2213,7 +2213,7 @@ void Item_func_get_user_var::fix_length_and_dec()
} }
return; return;
err: err:
thd->fatal_error= 1; thd->fatal_error();
return; return;
} }
......
...@@ -150,7 +150,13 @@ void Item_singlerow_subselect::select_transformer(THD *thd, ...@@ -150,7 +150,13 @@ void Item_singlerow_subselect::select_transformer(THD *thd,
if (!select_lex->next_select() && !select_lex->table_list.elements && if (!select_lex->next_select() && !select_lex->table_list.elements &&
select_lex->item_list.elements == 1 && select_lex->item_list.elements == 1 &&
// TODO: mark subselect items from item list separately /*
We cant change name of Item_field or Item_ref, because it will
prevent it's correct resolving, but we should save name of
removed item => we do not make optimization if top item of
list is field or reference.
TODO: solve above problem
*/
!(select_lex->item_list.head()->type() == FIELD_ITEM || !(select_lex->item_list.head()->type() == FIELD_ITEM ||
select_lex->item_list.head()->type() == REF_ITEM) select_lex->item_list.head()->type() == REF_ITEM)
) )
......
...@@ -51,7 +51,7 @@ Item_sum::Item_sum(THD *thd, Item_sum &item): ...@@ -51,7 +51,7 @@ Item_sum::Item_sum(THD *thd, Item_sum &item):
else else
if (!(args=(Item**) sql_alloc(sizeof(Item*)*arg_count))) if (!(args=(Item**) sql_alloc(sizeof(Item*)*arg_count)))
return; return;
for(uint i= 0; i < arg_count; i++) for (uint i= 0; i < arg_count; i++)
args[i]= item.args[i]; args[i]= item.args[i];
} }
...@@ -999,6 +999,10 @@ int dump_leaf(byte* key, uint32 count __attribute__((unused)), ...@@ -999,6 +999,10 @@ int dump_leaf(byte* key, uint32 count __attribute__((unused)),
Item_sum_count_distinct::~Item_sum_count_distinct() Item_sum_count_distinct::~Item_sum_count_distinct()
{ {
/*
Free table and tree if they belong to this item (if item have not pointer
to original item from which was made copy => it own its objects )
*/
if (!original) if (!original)
{ {
if (table) if (table)
......
...@@ -404,8 +404,8 @@ int mysql_select(THD *thd, Item ***rref_pointer_array, ...@@ -404,8 +404,8 @@ int mysql_select(THD *thd, Item ***rref_pointer_array,
Item *having, ORDER *proc_param, ulong select_type, Item *having, ORDER *proc_param, ulong select_type,
select_result *result, SELECT_LEX_UNIT *unit, select_result *result, SELECT_LEX_UNIT *unit,
SELECT_LEX *select_lex, bool fake_select_lex, SELECT_LEX *select_lex, bool fake_select_lex,
bool tables_OK); bool tables_and_fields_initied);
void free_ulderlayed_joins(THD *thd, SELECT_LEX *select); void free_underlaid_joins(THD *thd, SELECT_LEX *select);
void fix_tables_pointers(SELECT_LEX *select_lex); void fix_tables_pointers(SELECT_LEX *select_lex);
void fix_tables_pointers(SELECT_LEX_UNIT *select_lex); void fix_tables_pointers(SELECT_LEX_UNIT *select_lex);
int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
...@@ -413,7 +413,7 @@ int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, ...@@ -413,7 +413,7 @@ int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type, int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type,
select_result *result); select_result *result);
int mysql_union(THD *thd, LEX *lex, select_result *result, int mysql_union(THD *thd, LEX *lex, select_result *result,
SELECT_LEX_UNIT *unit, bool tables_OK); SELECT_LEX_UNIT *unit, bool tables_and_fields_initied);
int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *s, TABLE_LIST *t); int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *s, TABLE_LIST *t);
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
Item_result_field ***copy_func, Field **from_field, Item_result_field ***copy_func, Field **from_field,
......
...@@ -1949,14 +1949,15 @@ int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, ...@@ -1949,14 +1949,15 @@ int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
thd->allow_sum_func= allow_sum_func; thd->allow_sum_func= allow_sum_func;
thd->where="field list"; thd->where="field list";
for (uint i= 0; (item= it++); i++) Item **ref= ref_pointer_array;
while ((item= it++))
{ {
if (item->fix_fields(thd, tables, it.ref()) || if (item->fix_fields(thd, tables, it.ref()) ||
item->check_cols(1)) item->check_cols(1))
DBUG_RETURN(-1); /* purecov: inspected */ DBUG_RETURN(-1); /* purecov: inspected */
item= *(it.ref()); //Item can be chenged in fix fields item= *(it.ref()); //Item can be changed in fix fields
if (ref_pointer_array) if (ref)
ref_pointer_array[i]= item; *(ref++)= item;
if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM && if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM &&
sum_func_list) sum_func_list)
item->split_sum_func(ref_pointer_array, *sum_func_list); item->split_sum_func(ref_pointer_array, *sum_func_list);
......
...@@ -92,7 +92,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order, ...@@ -92,7 +92,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order,
if ((select && select->check_quick(safe_update, limit)) || !limit) if ((select && select->check_quick(safe_update, limit)) || !limit)
{ {
delete select; delete select;
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
send_ok(thd,0L); send_ok(thd,0L);
DBUG_RETURN(0); // Nothing to delete DBUG_RETURN(0); // Nothing to delete
} }
...@@ -104,7 +104,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order, ...@@ -104,7 +104,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order,
if (safe_update && !using_limit) if (safe_update && !using_limit)
{ {
delete select; delete select;
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
send_error(thd,ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE); send_error(thd,ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -134,7 +134,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order, ...@@ -134,7 +134,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order,
== HA_POS_ERROR) == HA_POS_ERROR)
{ {
delete select; delete select;
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
DBUG_RETURN(-1); // This will force out message DBUG_RETURN(-1); // This will force out message
} }
} }
...@@ -210,7 +210,7 @@ cleanup: ...@@ -210,7 +210,7 @@ cleanup:
thd->lock=0; thd->lock=0;
} }
delete select; delete select;
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
if (error >= 0 || thd->net.report_error) if (error >= 0 || thd->net.report_error)
send_error(thd,thd->killed ? ER_SERVER_SHUTDOWN: 0); send_error(thd,thd->killed ? ER_SERVER_SHUTDOWN: 0);
else else
......
...@@ -376,13 +376,13 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, ...@@ -376,13 +376,13 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
thd->cuted_fields); thd->cuted_fields);
::send_ok(thd,info.copied+info.deleted,(ulonglong)id,buff); ::send_ok(thd,info.copied+info.deleted,(ulonglong)id,buff);
} }
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
DBUG_RETURN(0); DBUG_RETURN(0);
abort: abort:
if (lock_type == TL_WRITE_DELAYED) if (lock_type == TL_WRITE_DELAYED)
end_delayed_insert(thd); end_delayed_insert(thd);
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
......
...@@ -312,7 +312,7 @@ public: ...@@ -312,7 +312,7 @@ public:
void exclude_level(); void exclude_level();
/* UNION methods */ /* UNION methods */
int prepare(THD *thd, select_result *result, bool tables_OK); int prepare(THD *thd, select_result *result, bool tables_and_fields_initied);
int exec(); int exec();
int cleanup(); int cleanup();
......
...@@ -438,7 +438,6 @@ static bool setup_params_data(PREP_STMT *stmt) ...@@ -438,7 +438,6 @@ static bool setup_params_data(PREP_STMT *stmt)
} }
/* /*
Validate the following information for INSERT statement: Validate the following information for INSERT statement:
- field existance - field existance
- fields count - fields count
......
...@@ -222,7 +222,7 @@ void fix_tables_pointers(SELECT_LEX_UNIT *unit) ...@@ -222,7 +222,7 @@ void fix_tables_pointers(SELECT_LEX_UNIT *unit)
for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select()) for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select())
{ {
relink_tables(sl); relink_tables(sl);
for(SELECT_LEX_UNIT *un= sl->first_inner_unit(); un; un= un->next_unit()) for (SELECT_LEX_UNIT *un= sl->first_inner_unit(); un; un= un->next_unit())
fix_tables_pointers(un); fix_tables_pointers(un);
} }
} }
...@@ -268,7 +268,7 @@ JOIN::prepare(Item ***rref_pointer_array, ...@@ -268,7 +268,7 @@ JOIN::prepare(Item ***rref_pointer_array,
Item *having_init, Item *having_init,
ORDER *proc_param_init, SELECT_LEX *select, ORDER *proc_param_init, SELECT_LEX *select,
SELECT_LEX_UNIT *unit, SELECT_LEX_UNIT *unit,
bool fake_select_lex, bool tables_OK) bool fake_select_lex, bool tables_and_fields_initied)
{ {
DBUG_ENTER("JOIN::prepare"); DBUG_ENTER("JOIN::prepare");
...@@ -285,8 +285,9 @@ JOIN::prepare(Item ***rref_pointer_array, ...@@ -285,8 +285,9 @@ JOIN::prepare(Item ***rref_pointer_array,
/* Check that all tables, fields, conds and order are ok */ /* Check that all tables, fields, conds and order are ok */
if ((tables_OK?0:(setup_tables(tables_list) || if ((tables_and_fields_initied ? 0 : (setup_tables(tables_list) ||
setup_wild(thd, tables_list, fields_list, setup_wild(thd, tables_list,
fields_list,
&all_fields, wild_num))) || &all_fields, wild_num))) ||
setup_ref_array(thd, rref_pointer_array, (fields_list.elements + setup_ref_array(thd, rref_pointer_array, (fields_list.elements +
select_lex->with_sum_func + select_lex->with_sum_func +
...@@ -419,6 +420,7 @@ int ...@@ -419,6 +420,7 @@ int
JOIN::optimize() JOIN::optimize()
{ {
DBUG_ENTER("JOIN::optimize"); DBUG_ENTER("JOIN::optimize");
// to prevent double initialization on EXPLAIN
if (optimized) if (optimized)
DBUG_RETURN(0); DBUG_RETURN(0);
optimized= 1; optimized= 1;
...@@ -1280,7 +1282,8 @@ mysql_select(THD *thd, Item ***rref_pointer_array, ...@@ -1280,7 +1282,8 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
COND *conds, uint og_num, ORDER *order, ORDER *group, COND *conds, uint og_num, ORDER *order, ORDER *group,
Item *having, ORDER *proc_param, ulong select_options, Item *having, ORDER *proc_param, ulong select_options,
select_result *result, SELECT_LEX_UNIT *unit, select_result *result, SELECT_LEX_UNIT *unit,
SELECT_LEX *select_lex, bool fake_select_lex, bool tables_OK) SELECT_LEX *select_lex, bool fake_select_lex,
bool tables_and_fields_initied)
{ {
int err; int err;
bool free_join= 1; bool free_join= 1;
...@@ -1307,7 +1310,8 @@ mysql_select(THD *thd, Item ***rref_pointer_array, ...@@ -1307,7 +1310,8 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
if (join->prepare(rref_pointer_array, tables, wild_num, if (join->prepare(rref_pointer_array, tables, wild_num,
conds, og_num, order, group, having, proc_param, conds, og_num, order, group, having, proc_param,
select_lex, unit, fake_select_lex, tables_OK)) select_lex, unit, fake_select_lex,
tables_and_fields_initied))
{ {
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
...@@ -4311,11 +4315,9 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -4311,11 +4315,9 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
{ {
uint alloc_length=ALIGN_SIZE(reclength+MI_UNIQUE_HASH_LENGTH+1); uint alloc_length=ALIGN_SIZE(reclength+MI_UNIQUE_HASH_LENGTH+1);
table->rec_buff_length=alloc_length; table->rec_buff_length=alloc_length;
byte * t; if (!(table->record[0]= (byte *) my_malloc(alloc_length*3, MYF(MY_WME))))
if (!(t= table->record[0]= (byte *) my_malloc(alloc_length*3, MYF(MY_WME))))
goto err; goto err;
table->record[1]= t+alloc_length; table->record[1]= table->record[0]+alloc_length;
//table->record[1]= table->record[0]+alloc_length;
table->record[2]= table->record[1]+alloc_length; table->record[2]= table->record[1]+alloc_length;
} }
copy_func[0]=0; // End marker copy_func[0]=0; // End marker
...@@ -4853,9 +4855,11 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure) ...@@ -4853,9 +4855,11 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
if (!join->select_lex->dependent || if (!join->select_lex->dependent ||
((!join->conds || join->conds->val_int()) && ((!join->conds || join->conds->val_int()) &&
(!join->having || join->having->val_int()))) (!join->having || join->having->val_int())))
{
if (!(error=(*end_select)(join,join_tab,0)) || error == -3) if (!(error=(*end_select)(join,join_tab,0)) || error == -3)
error=(*end_select)(join,join_tab,1); error=(*end_select)(join,join_tab,1);
} }
}
else else
{ {
error= sub_select(join,join_tab,0); error= sub_select(join,join_tab,0);
...@@ -7099,12 +7103,8 @@ int setup_ref_array(THD* thd, Item ***rref_pointer_array, uint elements) ...@@ -7099,12 +7103,8 @@ int setup_ref_array(THD* thd, Item ***rref_pointer_array, uint elements)
if (*rref_pointer_array) if (*rref_pointer_array)
return 0; return 0;
/* TODO: may be better allocate only one and all other on demand? */ return (*rref_pointer_array=
if (!(*rref_pointer_array= (Item **)thd->alloc(sizeof(Item*) * elements * 5)) == 0;
(Item **)thd->alloc(sizeof(Item*) * elements * 5)))
return -1;
else
return 0;
} }
/* /*
...@@ -7441,26 +7441,42 @@ test_if_group_changed(List<Item_buff> &list) ...@@ -7441,26 +7441,42 @@ test_if_group_changed(List<Item_buff> &list)
/* /*
Setup copy_fields to save fields at start of new group Setup copy_fields to save fields at start of new group
setup_copy_fields()
thd - THD pointer
param - temporary table parameters
ref_pointer_array - array of pointers to top elements of filed list
res_selected_fields - new list of items of select item list
res_all_fields - new list of all items
elements - number of elements in select item list
all_fields - all fields list
DESCRIPTION
Setup copy_fields to save fields at start of new group
Only FIELD_ITEM:s and FUNC_ITEM:s needs to be saved between groups. Only FIELD_ITEM:s and FUNC_ITEM:s needs to be saved between groups.
Change old item_field to use a new field with points at saved fieldvalue Change old item_field to use a new field with points at saved fieldvalue
This function is only called before use of send_fields This function is only called before use of send_fields
RETURN
0 - ok
!=0 - error
*/ */
bool bool
setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param, setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
Item **ref_pointer_array, Item **ref_pointer_array,
List<Item> &new_list1, List<Item> &new_list2, List<Item> &res_selected_fields, List<Item> &res_all_fields,
uint elements, List<Item> &fields) uint elements, List<Item> &all_fields)
{ {
Item *pos; Item *pos;
List_iterator_fast<Item> li(fields); List_iterator_fast<Item> li(all_fields);
Copy_field *copy; Copy_field *copy;
DBUG_ENTER("setup_copy_fields"); DBUG_ENTER("setup_copy_fields");
new_list1.empty(); res_selected_fields.empty();
new_list2.empty(); res_all_fields.empty();
List_iterator_fast<Item> itr(new_list2); List_iterator_fast<Item> itr(res_all_fields);
uint i, border= fields.elements - elements; uint i, border= all_fields.elements - elements;
if (!(copy=param->copy_field= new Copy_field[param->field_count])) if (!(copy=param->copy_field= new Copy_field[param->field_count]))
goto err2; goto err2;
...@@ -7512,15 +7528,15 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param, ...@@ -7512,15 +7528,15 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
if (param->copy_funcs.push_back(pos)) if (param->copy_funcs.push_back(pos))
goto err; goto err;
} }
new_list2.push_back(pos); res_all_fields.push_back(pos);
ref_pointer_array[((i < border)? fields.elements-i-1 : i-border)]= ref_pointer_array[((i < border)? all_fields.elements-i-1 : i-border)]=
pos; pos;
} }
param->copy_field_end= copy; param->copy_field_end= copy;
for (i= 0; i < border; i++) for (i= 0; i < border; i++)
itr++; itr++;
itr.sublist(new_list1, elements); itr.sublist(res_selected_fields, elements);
DBUG_RETURN(0); DBUG_RETURN(0);
err: err:
...@@ -7586,20 +7602,33 @@ make_sum_func_list(JOIN *join,List<Item> &fields) ...@@ -7586,20 +7602,33 @@ make_sum_func_list(JOIN *join,List<Item> &fields)
/* /*
Change all funcs and sum_funcs to fields in tmp table, and create Change all funcs and sum_funcs to fields in tmp table, and create
new list of all items new list of all items.
change_to_use_tmp_fields()
thd - THD pointer
ref_pointer_array - array of pointers to top elements of filed list
res_selected_fields - new list of items of select item list
res_all_fields - new list of all items
elements - number of elements in select item list
all_fields - all fields list
RETURN
0 - ok
!=0 - error
*/ */
static bool static bool
change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array, change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
List<Item> &new_list1, List<Item> &new_list2, List<Item> &res_selected_fields,
uint elements, List<Item> &items) List<Item> &res_all_fields,
uint elements, List<Item> &all_fields)
{ {
List_iterator_fast<Item> it(items); List_iterator_fast<Item> it(all_fields);
Item *item_field,*item; Item *item_field,*item;
new_list1.empty(); res_selected_fields.empty();
new_list2.empty(); res_all_fields.empty();
uint i, border= items.elements - elements; uint i, border= all_fields.elements - elements;
for (i= 0; (item= it++); i++) for (i= 0; (item= it++); i++)
{ {
Field *field; Field *field;
...@@ -7607,6 +7636,7 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array, ...@@ -7607,6 +7636,7 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM) if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM)
item_field= item; item_field= item;
else else
{
if (item->type() == Item::FIELD_ITEM) if (item->type() == Item::FIELD_ITEM)
{ {
item_field= item->get_tmp_table_item(thd); item_field= item->get_tmp_table_item(thd);
...@@ -7633,15 +7663,16 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array, ...@@ -7633,15 +7663,16 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
} }
else else
item_field= item; item_field= item;
new_list2.push_back(item_field); }
ref_pointer_array[((i < border)? items.elements-i-1 : i-border)]= res_all_fields.push_back(item_field);
ref_pointer_array[((i < border)? all_fields.elements-i-1 : i-border)]=
item_field; item_field;
} }
List_iterator_fast<Item> itr(new_list2); List_iterator_fast<Item> itr(res_all_fields);
for (i= 0; i < border; i++) for (i= 0; i < border; i++)
itr++; itr++;
itr.sublist(new_list1, elements); itr.sublist(res_selected_fields, elements);
return FALSE; return FALSE;
} }
...@@ -7649,31 +7680,43 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array, ...@@ -7649,31 +7680,43 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
/* /*
Change all sum_func refs to fields to point at fields in tmp table Change all sum_func refs to fields to point at fields in tmp table
Change all funcs to be fields in tmp table Change all funcs to be fields in tmp table
change_refs_to_tmp_fields()
thd - THD pointer
ref_pointer_array - array of pointers to top elements of filed list
res_selected_fields - new list of items of select item list
res_all_fields - new list of all items
elements - number of elements in select item list
all_fields - all fields list
RETURN
0 - ok
!=0 - error
*/ */
static bool static bool
change_refs_to_tmp_fields(THD *thd, Item **ref_pointer_array, change_refs_to_tmp_fields(THD *thd, Item **ref_pointer_array,
List<Item> &new_list1, List<Item> &res_selected_fields,
List<Item> &new_list2, uint elements, List<Item> &res_all_fields, uint elements,
List<Item> &items) List<Item> &all_fields)
{ {
List_iterator_fast<Item> it(items); List_iterator_fast<Item> it(all_fields);
Item *item, *new_item; Item *item, *new_item;
new_list1.empty(); res_selected_fields.empty();
new_list2.empty(); res_all_fields.empty();
uint i, border= items.elements - elements; uint i, border= all_fields.elements - elements;
for (i= 0; (item= it++); i++) for (i= 0; (item= it++); i++)
{ {
new_list2.push_back(new_item= item->get_tmp_table_item(thd)); res_all_fields.push_back(new_item= item->get_tmp_table_item(thd));
ref_pointer_array[((i < border)? items.elements-i-1 : i-border)]= ref_pointer_array[((i < border)? all_fields.elements-i-1 : i-border)]=
new_item; new_item;
} }
List_iterator_fast<Item> itr(new_list2); List_iterator_fast<Item> itr(res_all_fields);
for (i= 0; i < border; i++) for (i= 0; i < border; i++)
itr++; itr++;
itr.sublist(new_list1, elements); itr.sublist(res_selected_fields, elements);
return thd->is_fatal_error; return thd->is_fatal_error;
} }
...@@ -8037,10 +8080,14 @@ int mysql_explain_select(THD *thd, SELECT_LEX *select_lex, char const *type, ...@@ -8037,10 +8080,14 @@ int mysql_explain_select(THD *thd, SELECT_LEX *select_lex, char const *type,
} }
/* /*
Free joins of subselect of this select.
free_underlaid_joins()
thd - THD pointer
select - pointer to st_select_lex which subselects joins we will free
*/ */
void free_ulderlayed_joins(THD *thd, SELECT_LEX *select) void free_underlaid_joins(THD *thd, SELECT_LEX *select)
{ {
for (SELECT_LEX_UNIT *unit= select->first_inner_unit(); for (SELECT_LEX_UNIT *unit= select->first_inner_unit();
unit; unit;
......
...@@ -256,7 +256,8 @@ class JOIN :public Sql_alloc ...@@ -256,7 +256,8 @@ class JOIN :public Sql_alloc
int prepare(Item ***rref_pointer_array, TABLE_LIST *tables, uint wind_num, int prepare(Item ***rref_pointer_array, TABLE_LIST *tables, uint wind_num,
COND *conds, uint og_num, ORDER *order, ORDER *group, COND *conds, uint og_num, ORDER *order, ORDER *group,
Item *having, ORDER *proc_param, SELECT_LEX *select, Item *having, ORDER *proc_param, SELECT_LEX *select,
SELECT_LEX_UNIT *unit, bool fake_select_lex, bool tables_OK); SELECT_LEX_UNIT *unit, bool fake_select_lex,
bool tables_and_fields_initied);
int optimize(); int optimize();
int reinit(); int reinit();
void exec(); void exec();
......
...@@ -25,11 +25,11 @@ ...@@ -25,11 +25,11 @@
#include "sql_select.h" #include "sql_select.h"
int mysql_union(THD *thd, LEX *lex, select_result *result, int mysql_union(THD *thd, LEX *lex, select_result *result,
SELECT_LEX_UNIT *unit, bool tables_OK) SELECT_LEX_UNIT *unit, bool tables_and_fields_initied)
{ {
DBUG_ENTER("mysql_union"); DBUG_ENTER("mysql_union");
int res= 0; int res= 0;
if (!(res= unit->prepare(thd, result, tables_OK))) if (!(res= unit->prepare(thd, result, tables_and_fields_initied)))
res= unit->exec(); res= unit->exec();
res|= unit->cleanup(); res|= unit->cleanup();
DBUG_RETURN(res); DBUG_RETURN(res);
...@@ -109,7 +109,7 @@ bool select_union::flush() ...@@ -109,7 +109,7 @@ bool select_union::flush()
} }
int st_select_lex_unit::prepare(THD *thd, select_result *result, int st_select_lex_unit::prepare(THD *thd, select_result *result,
bool tables_OK) bool tables_and_fields_initied)
{ {
DBUG_ENTER("st_select_lex_unit::prepare"); DBUG_ENTER("st_select_lex_unit::prepare");
...@@ -132,8 +132,9 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result, ...@@ -132,8 +132,9 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result,
if (found_rows_for_union) if (found_rows_for_union)
first_select()->options ^= OPTION_FOUND_ROWS; first_select()->options ^= OPTION_FOUND_ROWS;
} }
if (tables_OK) if (tables_and_fields_initied)
{ {
// Item list and tables will be initialized by mysql_derived
item_list= sl->item_list; item_list= sl->item_list;
} }
else else
...@@ -153,7 +154,7 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result, ...@@ -153,7 +154,7 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result,
setup_fields(thd, sl->ref_pointer_array, first_table, item_list, setup_fields(thd, sl->ref_pointer_array, first_table, item_list,
0, 0, 1)) 0, 0, 1))
goto err; goto err;
tables_OK= 1; tables_and_fields_initied= 1;
} }
bzero((char*) &tmp_table_param,sizeof(tmp_table_param)); bzero((char*) &tmp_table_param,sizeof(tmp_table_param));
...@@ -201,8 +202,8 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result, ...@@ -201,8 +202,8 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result,
(ORDER*) sl->group_list.first, (ORDER*) sl->group_list.first,
sl->having, sl->having,
(ORDER*) NULL, (ORDER*) NULL,
sl, this, 0, tables_OK); sl, this, 0, tables_and_fields_initied);
tables_OK= 0; tables_and_fields_initied= 0;
if (res | thd->is_fatal_error) if (res | thd->is_fatal_error)
goto err; goto err;
} }
...@@ -231,7 +232,7 @@ int st_select_lex_unit::exec() ...@@ -231,7 +232,7 @@ int st_select_lex_unit::exec()
DBUG_ENTER("st_select_lex_unit::exec"); DBUG_ENTER("st_select_lex_unit::exec");
SELECT_LEX_NODE *lex_select_save= thd->lex.current_select; SELECT_LEX_NODE *lex_select_save= thd->lex.current_select;
if (executed && !(dependent||uncacheable)) if (executed && !(dependent || uncacheable))
DBUG_RETURN(0); DBUG_RETURN(0);
executed= 1; executed= 1;
......
...@@ -124,7 +124,7 @@ int mysql_update(THD *thd, ...@@ -124,7 +124,7 @@ int mysql_update(THD *thd,
table->grant.want_privilege=(SELECT_ACL & ~table->grant.privilege); table->grant.want_privilege=(SELECT_ACL & ~table->grant.privilege);
if (setup_fields(thd, 0, update_table_list, values, 0, 0, 0)) if (setup_fields(thd, 0, update_table_list, values, 0, 0, 0))
{ {
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
DBUG_RETURN(-1); /* purecov: inspected */ DBUG_RETURN(-1); /* purecov: inspected */
} }
...@@ -135,7 +135,7 @@ int mysql_update(THD *thd, ...@@ -135,7 +135,7 @@ int mysql_update(THD *thd,
(select && select->check_quick(safe_update, limit)) || !limit) (select && select->check_quick(safe_update, limit)) || !limit)
{ {
delete select; delete select;
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
if (error) if (error)
{ {
DBUG_RETURN(-1); // Error in where DBUG_RETURN(-1); // Error in where
...@@ -150,7 +150,7 @@ int mysql_update(THD *thd, ...@@ -150,7 +150,7 @@ int mysql_update(THD *thd,
if (safe_update && !using_limit) if (safe_update && !using_limit)
{ {
delete select; delete select;
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
send_error(thd,ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE); send_error(thd,ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -178,7 +178,7 @@ int mysql_update(THD *thd, ...@@ -178,7 +178,7 @@ int mysql_update(THD *thd,
DISK_BUFFER_SIZE, MYF(MY_WME))) DISK_BUFFER_SIZE, MYF(MY_WME)))
{ {
delete select; /* purecov: inspected */ delete select; /* purecov: inspected */
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
if (old_used_keys & ((key_map) 1 << used_index)) if (old_used_keys & ((key_map) 1 << used_index))
...@@ -212,7 +212,7 @@ int mysql_update(THD *thd, ...@@ -212,7 +212,7 @@ int mysql_update(THD *thd,
== HA_POS_ERROR) == HA_POS_ERROR)
{ {
delete select; delete select;
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
} }
...@@ -267,7 +267,7 @@ int mysql_update(THD *thd, ...@@ -267,7 +267,7 @@ int mysql_update(THD *thd,
if (error >= 0) if (error >= 0)
{ {
delete select; delete select;
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
} }
...@@ -353,7 +353,7 @@ int mysql_update(THD *thd, ...@@ -353,7 +353,7 @@ int mysql_update(THD *thd,
} }
delete select; delete select;
free_ulderlayed_joins(thd, &thd->lex.select_lex); free_underlaid_joins(thd, &thd->lex.select_lex);
if (error >= 0) if (error >= 0)
send_error(thd,thd->killed ? ER_SERVER_SHUTDOWN : 0); /* purecov: inspected */ send_error(thd,thd->killed ? ER_SERVER_SHUTDOWN : 0); /* purecov: inspected */
else else
......
...@@ -1797,7 +1797,7 @@ select_option: ...@@ -1797,7 +1797,7 @@ select_option:
YYABORT; YYABORT;
Select->options|= OPTION_FOUND_ROWS; Select->options|= OPTION_FOUND_ROWS;
} }
| SQL_NO_CACHE_SYM { Lex->uncacheable();; } | SQL_NO_CACHE_SYM { Lex->uncacheable(); }
| SQL_CACHE_SYM { Select->options|= OPTION_TO_QUERY_CACHE; } | SQL_CACHE_SYM { Select->options|= OPTION_TO_QUERY_CACHE; }
| ALL {} | ALL {}
; ;
......
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