Commit 43b99e58 authored by unknown's avatar unknown

changes based on partial revie of task 577 (SCRUM)


sql/item.cc:
  Fixed Item usual constructor to call current_thd only once.
  Fixed copy constructor to receive THD pointer via arguments.
  added comments
  removed counter-1 and unnessesary initializaton of counter
sql/item.h:
  Fixed copy constructor to receive THD pointer via arguments.
  Renamed get_same to copy_or_same.
  THD pointetr added to copy_or_same and get_tmp_table_item.
sql/item_cmpfunc.cc:
  fixed layout
  fixed direct call of destructor
sql/item_func.cc:
  fiex layout
  THD pointetr added to get_tmp_table_item.
sql/item_func.h:
  THD pointetr added to get_tmp_table_item.
sql/item_sum.cc:
  Fixed copy constructor to receive THD pointer via arguments.
  Renamed get_same to copy_or_same.
  THD pointetr added to copy_or_same and get_tmp_table_item.
sql/item_sum.h:
  fixed layout
  Fixed copy constructor to receive THD pointer via arguments.
  Renamed get_same to copy_or_same.
  THD pointetr added to copy_or_same and get_tmp_table_item.
sql/item_uniq.h:
  Fixed copy constructor to receive THD pointer via arguments.
  Renamed get_same to copy_or_same.
  THD pointetr added to copy_or_same and get_tmp_table_item.
sql/sql_base.cc:
  count from 0
sql/sql_select.cc:
  removed counter-1 and unnessesary initializaton of counter
  THD pointetr added to get_tmp_table_item and change_to_use_tmp_fields.
parent a0ddb72d
......@@ -37,16 +37,22 @@ void item_init(void)
Item::Item():
fixed(0)
{
marker=0;
marker= 0;
maybe_null=null_value=with_sum_func=unsigned_flag=0;
name=0;
decimals=0; max_length=0;
next=current_thd->free_list; // Put in free list
current_thd->free_list=this;
name= 0;
decimals= 0; max_length= 0;
THD *thd= current_thd;
next= thd->free_list; // Put in free list
thd->free_list= this;
loop_id= 0;
}
Item::Item(Item &item):
/*
Constructor used by Item_field, Item_ref & agregate (sum) functions.
Used for duplicating lists in processing queries with temporary
tables
*/
Item::Item(THD *thd, Item &item):
loop_id(0),
str_value(item.str_value),
name(item.name),
......@@ -59,12 +65,13 @@ Item::Item(Item &item):
with_sum_func(item.with_sum_func),
fixed(item.fixed)
{
next=current_thd->free_list; // Put in free list
current_thd->free_list= this;
next=thd->free_list; // Put in free list
thd->free_list= this;
}
Item_ident::Item_ident(Item_ident &item):
Item(item),
// Constructor used by Item_field & Item_ref (see Item comment)
Item_ident::Item_ident(THD *thd, Item_ident &item):
Item(thd, item),
db_name(item.db_name),
table_name(item.table_name),
field_name(item.field_name),
......@@ -165,8 +172,9 @@ Item_field::Item_field(Field *f) :Item_ident(NullS,f->table_name,f->field_name)
fixed= 1; // This item is not needed in fix_fields
}
Item_field::Item_field(Item_field &item):
Item_ident(item),
// Constructor need to process subselect with temporary tables (see Item)
Item_field::Item_field(THD *thd, Item_field &item):
Item_ident(thd, item),
field(item.field),
result_field(item.result_field)
{}
......@@ -281,9 +289,9 @@ table_map Item_field::used_tables() const
return (depended_from? RAND_TABLE_BIT : field->table->map);
}
Item * Item_field::get_tmp_table_item()
Item *Item_field::get_tmp_table_item(THD *thd)
{
Item_field *new_item= new Item_field(*this);
Item_field *new_item= new Item_field(thd, *this);
if (new_item)
new_item->field= new_item->result_field;
return new_item;
......@@ -617,7 +625,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
thd->net.last_errno= 0;
#endif
Item **refer= (Item **)not_found_item;
uint counter= 0;
uint counter;
// Prevent using outer fields in subselects, that is not supported now
SELECT_LEX *cursel=(SELECT_LEX *) thd->lex.current_select;
if (outer_resolving ||
......@@ -658,19 +666,21 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
}
Item_ref *r;
*ref= r= new Item_ref(last->ref_pointer_array + counter-1
*ref= r= new Item_ref(last->ref_pointer_array + counter
, (char *)table_name,
(char *)field_name);
if (!r)
return 1;
if (r->fix_fields(thd, tables, ref) || r->check_cols(1))
return 1;
// store pointer on SELECT_LEX from wich item is dependent
r->depended_from= last;
cursel->mark_as_dependent(last);
return 0;
}
else
{
// store pointer on SELECT_LEX from wich item is dependent
depended_from= last;
/*
Mark all selects from resolved to 1 before select where was
......@@ -1071,7 +1081,7 @@ bool Item_field::send(Protocol *protocol, String *buffer)
bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
{
uint counter= 0;
uint counter;
if (!ref)
{
TABLE_LIST *where= 0;
......@@ -1142,6 +1152,7 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
Item_field* f;
if (!((*reference)= f= new Item_field(tmp)))
return 1;
// store pointer on SELECT_LEX from wich item is dependent
f->depended_from= last;
thd->lex.current_select->mark_as_dependent(last);
return 0;
......@@ -1154,7 +1165,10 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
"forward reference in item list");
return -1;
}
ref= (depended_from= last)->ref_pointer_array + counter-1;
/*
depended_from: pointer on SELECT_LEX from wich item is dependent
*/
ref= (depended_from= last)->ref_pointer_array + counter;
thd->lex.current_select->mark_as_dependent(last);
}
}
......@@ -1168,7 +1182,7 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
"forward reference in item list");
return -1;
}
ref= thd->lex.current_select->ref_pointer_array + counter-1;
ref= thd->lex.current_select->ref_pointer_array + counter;
}
}
......
......@@ -53,8 +53,12 @@ class Item {
// alloc & destruct is done as start of select using sql_alloc
Item();
// copy constructor used by Item_field, Item_ref & agregate (sum) functions
Item(Item &item);
/*
Constructor used by Item_field, Item_ref & agregate (sum) functions.
Used for duplicating lists in processing queries with temporary
tables
*/
Item(THD *thd, Item &item);
virtual ~Item() { name=0; } /*lint -e1509 */
void set_name(const char *str,uint length=0);
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
......@@ -93,8 +97,8 @@ class Item {
virtual bool get_time(TIME *ltime);
virtual bool is_null() { return 0; };
virtual void top_level_item() {}
virtual Item * get_same() { return this; }
virtual Item * get_tmp_table_item() { return get_same(); }
virtual Item *copy_or_same(THD *thd) { return this; }
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
virtual bool binary() const
{ return str_value.charset()->state & MY_CS_BINSORT ? 1 : 0 ; }
......@@ -129,8 +133,8 @@ class Item_ident :public Item
:db_name(db_name_par), table_name(table_name_par),
field_name(field_name_par), depended_from(0), outer_resolving(0)
{ name = (char*) field_name_par; }
// copy constructor used by Item_field & Item_ref
Item_ident(Item_ident &item);
// Constructor used by Item_field & Item_ref (see Item comment)
Item_ident(THD *thd, Item_ident &item);
const char *full_name() const;
void set_outer_resolving() { outer_resolving= 1; }
};
......@@ -147,8 +151,8 @@ class Item_field :public Item_ident
const char *field_name_par)
:Item_ident(db_par,table_name_par,field_name_par),field(0),result_field(0)
{}
// copy constructor need to process subselect with temporary tables
Item_field(Item_field &item);
// Constructor need to process subselect with temporary tables (see Item)
Item_field(THD *thd, Item_field &item);
Item_field(Field *field);
enum Type type() const { return FIELD_ITEM; }
bool eq(const Item *item, bool binary_cmp) const;
......@@ -177,7 +181,7 @@ class Item_field :public Item_ident
bool get_date(TIME *ltime,bool fuzzydate);
bool get_time(TIME *ltime);
bool is_null() { return field->is_null(); }
Item * get_tmp_table_item();
Item *get_tmp_table_item(THD *thd);
friend class Item_default_value;
};
......@@ -437,10 +441,10 @@ class Item_result_field :public Item /* Item with result field */
public:
Field *result_field; /* Save result here */
Item_result_field() :result_field(0) {}
Item_result_field(Item_result_field &item): Item(item)
{
result_field= item.result_field;
}
// Constructor used for Item_sum (see Item comment)
Item_result_field(THD *thd, Item_result_field &item):
Item(thd, item), result_field(item.result_field)
{}
~Item_result_field() {} /* Required with gcc 2.95 */
Field *tmp_table_field() { return result_field; }
Field *tmp_table_field(TABLE *t_arg) { return result_field; }
......@@ -457,8 +461,9 @@ class Item_ref :public Item_ident
:Item_ident(db_par,table_name_par,field_name_par),ref(0) {}
Item_ref(Item **item, char *table_name_par,char *field_name_par)
:Item_ident(NullS,table_name_par,field_name_par),ref(item) {}
// copy constructor need to process subselect with temporary tables
Item_ref(Item_ref &item): Item_ident(item), ref(item.ref) {}
// Constructor need to process subselect with temporary tables (see Item)
Item_ref(THD *thd, Item_ref &item)
:Item_ident(thd, item), ref(item.ref) {}
enum Type type() const { return REF_ITEM; }
bool eq(const Item *item, bool binary_cmp) const
{ return ref && (*ref)->eq(item, binary_cmp); }
......@@ -527,6 +532,12 @@ class Item_ref_null_helper: public Item_ref
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
nunber of elements);
2) to have access to ref_pointer_array, via wich item will refered.
*/
st_select_lex *select_lex;
uint pos;
public:
......
......@@ -1063,7 +1063,8 @@ int in_vector::find(Item *item)
}
in_string::in_string(uint elements,qsort_cmp cmp_func)
:in_vector(elements,sizeof(String),cmp_func),tmp(buff,sizeof(buff),default_charset_info)
:in_vector(elements, sizeof(String), cmp_func),
tmp(buff, sizeof(buff), default_charset_info)
{}
in_string::~in_string()
......@@ -1102,11 +1103,7 @@ in_row::in_row(uint elements, Item * item)
in_row::~in_row()
{
if (base)
{
cmp_item_row *arr= (cmp_item_row *) base;
for (uint i=0 ; i < count ; i++)
arr[i].~cmp_item_row();
}
delete [] (cmp_item_row*) base;
}
byte *in_row::get_value(Item *item)
......
......@@ -294,14 +294,11 @@ void Item_func::fix_num_length_and_dec()
max_length=float_length(decimals);
}
Item * Item_func::get_tmp_table_item()
Item *Item_func::get_tmp_table_item(THD *thd)
{
if (!with_sum_func && !const_item())
{
return new Item_field(result_field);
}
else
return get_same();
return copy_or_same(thd);
}
String *Item_int_func::val_str(String *str)
......
......@@ -134,7 +134,7 @@ class Item_func :public Item_result_field
Field *tmp_table_field() { return result_field; }
Field *tmp_table_field(TABLE *t_arg);
void set_outer_resolving();
Item * get_tmp_table_item();
Item *get_tmp_table_item(THD *thd);
};
......
......@@ -41,8 +41,9 @@ Item_sum::Item_sum(List<Item> &list)
list.empty(); // Fields are used
}
Item_sum::Item_sum(Item_sum &item):
Item_result_field(item), quick_group(item.quick_group)
// Constructor used in processing select with temporary tebles
Item_sum::Item_sum(THD *thd, Item_sum &item):
Item_result_field(thd, item), quick_group(item.quick_group)
{
arg_count= item.arg_count;
if (arg_count <= 2)
......@@ -96,9 +97,9 @@ void Item_sum::fix_num_length_and_dec()
max_length=float_length(decimals);
}
Item * Item_sum::get_tmp_table_item()
Item *Item_sum::get_tmp_table_item(THD *thd)
{
Item_sum* sum_item= (Item_sum *) get_same();
Item_sum* sum_item= (Item_sum *) copy_or_same(thd);
if (sum_item && sum_item->result_field) // If not a const sum func
{
Field *result_field= sum_item->result_field;
......
This diff is collapsed.
......@@ -37,7 +37,8 @@ class Item_sum_unique_users :public Item_sum_num
public:
Item_sum_unique_users(Item *name_arg,int start,int end,Item *item_arg)
:Item_sum_num(item_arg) {}
Item_sum_unique_users(Item_sum_unique_users &item): Item_sum_num(item) {}
Item_sum_unique_users(THD *thd, Item_sum_unique_users &item)
:Item_sum_num(thd, item) {}
double val() { return 0.0; }
enum Sumfunctype sum_func () const {return UNIQUE_USERS_FUNC;}
void reset() {}
......@@ -49,5 +50,8 @@ class Item_sum_unique_users :public Item_sum_num
fixed= 1;
return 0;
}
Item_sum * get_same() { return new Item_sum_unique_users(*this); }
Item_sum *copy_or_same(THD* thd)
{
return new Item_sum_unique_users(thd, *this);
}
};
......@@ -1845,10 +1845,8 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
table_name= ((Item_ident*) find)->table_name;
}
uint i= 0;
while ((item=li++))
for (uint i= 0; (item=li++); i++)
{
i++;
if (field_name && item->type() == Item::FIELD_ITEM)
{
if (!my_strcasecmp(system_charset_info,
......
......@@ -140,7 +140,7 @@ static void calc_group_buffer(JOIN *join,ORDER *group);
static bool alloc_group_fields(JOIN *join,ORDER *group);
static bool make_sum_func_list(JOIN *join,List<Item> &fields);
// Create list for using with tempory table
static bool change_to_use_tmp_fields(Item **ref_pointer_array,
static bool change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
List<Item> &new_list1,
List<Item> &new_list2,
uint elements, List<Item> &items);
......@@ -968,7 +968,7 @@ JOIN::exec()
items1= items0 + all_fields.elements;
if (sort_and_group || curr_tmp_table->group)
{
if (change_to_use_tmp_fields(items1,
if (change_to_use_tmp_fields(thd, items1,
tmp_fields_list1, tmp_all_fields1,
fields_list.elements, all_fields))
DBUG_VOID_RETURN;
......@@ -1088,7 +1088,7 @@ JOIN::exec()
if (!items2)
{
items2= items1 + all_fields.elements;
if (change_to_use_tmp_fields(items2,
if (change_to_use_tmp_fields(thd, items2,
tmp_fields_list2, tmp_all_fields2,
fields_list.elements, tmp_all_fields1))
DBUG_VOID_RETURN;
......@@ -7069,12 +7069,12 @@ find_order_in_list(THD *thd, Item **ref_pointer_array,
order->in_field_list= 1;
return 0;
}
uint counter= 0;
uint counter;
Item **item= find_item_in_list(*order->item, fields, &counter,
IGNORE_ERRORS);
if (item)
{
order->item= ref_pointer_array + counter-1;
order->item= ref_pointer_array + counter;
order->in_field_list=1;
return 0;
}
......@@ -7192,7 +7192,7 @@ setup_new_fields(THD *thd,TABLE_LIST *tables,List<Item> &fields,
DBUG_ENTER("setup_new_fields");
thd->set_query_id=1; // Not really needed, but...
uint counter= 0;
uint counter;
for (; new_field ; new_field= new_field->next)
{
if ((item= find_item_in_list(*new_field->item, fields, &counter,
......@@ -7471,7 +7471,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
if (pos->type() == Item::FIELD_ITEM)
{
Item_field *item;
if (!(item= new Item_field(*((Item_field*) pos))))
if (!(item= new Item_field(thd, *((Item_field*) pos))))
goto err;
pos= item;
if (item->field->flags & BLOB_FLAG)
......@@ -7590,7 +7590,7 @@ make_sum_func_list(JOIN *join,List<Item> &fields)
*/
static bool
change_to_use_tmp_fields(Item **ref_pointer_array,
change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
List<Item> &new_list1, List<Item> &new_list2,
uint elements, List<Item> &items)
{
......@@ -7609,7 +7609,7 @@ change_to_use_tmp_fields(Item **ref_pointer_array,
else
if (item->type() == Item::FIELD_ITEM)
{
item_field= item->get_tmp_table_item();
item_field= item->get_tmp_table_item(thd);
}
else if ((field= item->tmp_table_field()))
{
......@@ -7665,7 +7665,7 @@ change_refs_to_tmp_fields(THD *thd, Item **ref_pointer_array,
uint i, border= items.elements - elements;
for (i= 0; (item= it++); i++)
{
new_list2.push_back(new_item= item->get_tmp_table_item());
new_list2.push_back(new_item= item->get_tmp_table_item(thd));
ref_pointer_array[((i < border)? items.elements-i-1 : i-border)]=
new_item;
}
......
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