Commit bebac6db authored by unknown's avatar unknown

changed compare engine in basic row items (SCRUM)

fixed layout


sql/item_cmpfunc.cc:
  changed compare engine in basic row items
BitKeeper/etc/ignore:
  Added libmysqld/item_row.cc to the ignore list
sql/item_cmpfunc.h:
  changed compare engine in basic row items
sql/item_func.h:
  changed compare engine in basic row items
  fixed layout
sql/sql_select.cc:
  changed compare engine in basic row items
parent 8b2be4e4
......@@ -567,3 +567,4 @@ bkpull.log.5
bkpull.log.6
bkpush.log
sql/sql_yacc.output
libmysqld/item_row.cc
......@@ -107,7 +107,7 @@ void Item_bool_func2::fix_length_and_dec()
{
if (convert_constant_item(field,&args[1]))
{
cmp_func= new Compare_func_int(this); // Works for all types.
arg_store.set_compare_func(this, INT_RESULT); // Works for all types.
return;
}
}
......@@ -119,52 +119,63 @@ void Item_bool_func2::fix_length_and_dec()
{
if (convert_constant_item(field,&args[0]))
{
cmp_func= new Compare_func_int(this); // Works for all types.
arg_store.set_compare_func(this, INT_RESULT); // Works for all types.
return;
}
}
}
set_cmp_func(args[0], args[1]);
set_cmp_func();
}
Compare_func* Compare_func::get_compare_func(Item_bool_func2 *owner,
Item *a, Item* b)
int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type)
{
switch (item_cmp_type(a->result_type(), b->result_type()))
owner= item;
switch (type)
{
case STRING_RESULT:
return new Compare_func_string(owner);
func= &Arg_comparator::compare_string;
break;
case REAL_RESULT:
return new Compare_func_real(owner);
func= &Arg_comparator::compare_real;
break;
case INT_RESULT:
return new Compare_func_int(owner);
func= &Arg_comparator::compare_int;
break;
case ROW_RESULT:
return new Compare_func_row(owner, a, b);
}
return 0;
}
Compare_func_row::Compare_func_row(Item_bool_func2 *owner, Item *a, Item* b):
Compare_func(owner)
{
uint n= a->cols();
if (n != b->cols())
{
func= &Arg_comparator::compare_row;
uint n= args[0]->cols();
if (n != args[1]->cols())
{
my_error(ER_CARDINALITY_COL, MYF(0), n);
cmp_func= 0;
return;
comparators= 0;
return 1;
}
cmp_func= (Compare_func **) sql_alloc(sizeof(Compare_func*)*n);
if ((comparators= (Arg_comparator *) sql_alloc(sizeof(Arg_comparator)*n)))
for (uint i=0; i < n; i++)
cmp_func[i]= Compare_func::get_compare_func(owner, a->el(i), b->el(i));
{
comparators[i].set_arg(0, args[0]->el(i));
comparators[i].set_arg(1, args[1]->el(i));
comparators[i].set_compare_func(owner);
}
else
{
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
current_thd->fatal_error= 1;
return 1;
}
break;
}
}
return 0;
}
int Compare_func_string::compare(Item *a, Item *b)
int Arg_comparator::compare_string()
{
String *res1,*res2;
if ((res1= a->val_str(&owner->tmp_value1)))
if ((res1= args[0]->val_str(&owner->tmp_value1)))
{
if ((res2= b->val_str(&owner->tmp_value2)))
if ((res2= args[1]->val_str(&owner->tmp_value2)))
{
owner->null_value= 0;
return owner->binary() ? stringcmp(res1,res2) : sortcmp(res1,res2);
......@@ -174,13 +185,13 @@ int Compare_func_string::compare(Item *a, Item *b)
return -1;
}
int Compare_func_real::compare(Item *a, Item *b)
int Arg_comparator::compare_real()
{
double val1= a->val();
if (!a->null_value)
double val1= args[0]->val();
if (!args[0]->null_value)
{
double val2= b->val();
if (!b->null_value)
double val2= args[1]->val();
if (!args[1]->null_value)
{
owner->null_value= 0;
if (val1 < val2) return -1;
......@@ -193,13 +204,13 @@ int Compare_func_real::compare(Item *a, Item *b)
}
int Compare_func_int::compare(Item *a, Item *b)
int Arg_comparator::compare_int()
{
longlong val1= a->val_int();
if (!a->null_value)
longlong val1= args[0]->val_int();
if (!args[0]->null_value)
{
longlong val2= b->val_int();
if (!b->null_value)
longlong val2= args[1]->val_int();
if (!args[1]->null_value)
{
owner->null_value= 0;
if (val1 < val2) return -1;
......@@ -211,13 +222,13 @@ int Compare_func_int::compare(Item *a, Item *b)
return -1;
}
int Compare_func_row::compare(Item *a, Item *b)
int Arg_comparator::compare_row()
{
int res= 0;
uint n= a->cols();
uint n= args[0]->cols();
for (uint i= 0; i<n; i++)
{
if ((res= cmp_func[i]->compare(a->el(i), b->el(i))))
if ((res= comparators[i].compare()))
return res;
if (owner->null_value)
return -1;
......@@ -227,7 +238,7 @@ int Compare_func_row::compare(Item *a, Item *b)
longlong Item_func_eq::val_int()
{
int value= cmp_func->compare(args[0], args[1]);
int value= arg_store.compare();
return value == 0 ? 1 : 0;
}
......@@ -281,34 +292,34 @@ longlong Item_func_equal::val_int()
longlong Item_func_ne::val_int()
{
int value= cmp_func->compare(args[0], args[1]);
int value= arg_store.compare();
return value != 0 && !null_value ? 1 : 0;
}
longlong Item_func_ge::val_int()
{
int value= cmp_func->compare(args[0], args[1]);
int value= arg_store.compare();
return value >= 0 ? 1 : 0;
}
longlong Item_func_gt::val_int()
{
int value= cmp_func->compare(args[0], args[1]);
int value= arg_store.compare();
return value > 0 ? 1 : 0;
}
longlong Item_func_le::val_int()
{
int value= cmp_func->compare(args[0], args[1]);
int value= arg_store.compare();
return value <= 0 && !null_value ? 1 : 0;
}
longlong Item_func_lt::val_int()
{
int value= cmp_func->compare(args[0], args[1]);
int value= arg_store.compare();
return value < 0 && !null_value ? 1 : 0;
}
......@@ -657,7 +668,7 @@ double
Item_func_nullif::val()
{
double value;
if (!cmp_func->compare(args[0], args[1]) || null_value)
if (!arg_store.compare() || null_value)
{
null_value=1;
return 0.0;
......@@ -671,7 +682,7 @@ longlong
Item_func_nullif::val_int()
{
longlong value;
if (!cmp_func->compare(args[0], args[1]) || null_value)
if (!arg_store.compare() || null_value)
{
null_value=1;
return 0;
......@@ -685,7 +696,7 @@ String *
Item_func_nullif::val_str(String *str)
{
String *res;
if (!cmp_func->compare(args[0], args[1]) || null_value)
if (!arg_store.compare() || null_value)
{
null_value=1;
return 0;
......
......@@ -30,61 +30,6 @@ class Item_bool_func :public Item_int_func
void fix_length_and_dec() { decimals=0; max_length=1; }
};
class Item_bool_func2;
class Compare_func
{
protected:
Item_bool_func2 *owner;
public:
static void *operator new(size_t size)
{
return (void*) sql_alloc((uint) size);
}
static void operator delete(void *ptr,size_t size) {}
Compare_func(Item_bool_func2 *o) { owner= o; }
virtual ~Compare_func() {};
virtual int compare(Item *, Item*)= 0;
static Compare_func* get_compare_func(Item_bool_func2 *owner,
Item* a, Item* b);
};
class Compare_func_string: public Compare_func
{
public:
Compare_func_string(Item_bool_func2 *owner): Compare_func(owner) {};
int compare(Item *, Item*);
};
class Compare_func_real: public Compare_func
{
public:
Compare_func_real(Item_bool_func2 *owner): Compare_func(owner) {};
int compare(Item *, Item*);
};
class Compare_func_int: public Compare_func
{
public:
Compare_func_int(Item_bool_func2 *owner): Compare_func(owner) {};
int compare(Item *, Item*);
};
class Compare_func_row: public Compare_func
{
Compare_func **cmp_func;
public:
Compare_func_row(Item_bool_func2 *owner, Item* a, Item* b);
~Compare_func_row()
{
if(cmp_func)
sql_element_free(cmp_func);
}
int compare(Item *, Item*);
};
class Item_bool_func2 :public Item_int_func
{ /* Bool with 2 string args */
protected:
......@@ -92,10 +37,9 @@ class Item_bool_func2 :public Item_int_func
public:
Item_bool_func2(Item *a,Item *b) :Item_int_func(a,b) {}
void fix_length_and_dec();
Compare_func *cmp_func;
void set_cmp_func(Item *a, Item *b)
void set_cmp_func()
{
cmp_func= Compare_func::get_compare_func(this, args[0], args[1]);
arg_store.set_compare_func(this);
}
optimize_type select_optimize() const { return OPTIMIZE_OP; }
virtual enum Functype rev_functype() const { return UNKNOWN_FUNC; }
......@@ -103,13 +47,14 @@ class Item_bool_func2 :public Item_int_func
void print(String *str) { Item_func::print_op(str); }
bool is_null() { return test(args[0]->is_null() || args[1]->is_null()); }
friend class Compare_func_string;
static Item_bool_func2* eq_creator(Item *a, Item *b);
static Item_bool_func2* ne_creator(Item *a, Item *b);
static Item_bool_func2* gt_creator(Item *a, Item *b);
static Item_bool_func2* lt_creator(Item *a, Item *b);
static Item_bool_func2* ge_creator(Item *a, Item *b);
static Item_bool_func2* le_creator(Item *a, Item *b);
friend class Arg_comparator;
};
class Item_bool_rowready_func2 :public Item_bool_func2
......
......@@ -28,10 +28,42 @@ extern "C" /* Bug in BSDI include file */
}
#endif
extern Item_result item_cmp_type(Item_result a,Item_result b);
class Item_bool_func2;
class Arg_comparator;
typedef int (Arg_comparator::*arg_cmp_func)();
class Arg_comparator: public Sql_alloc
{
Item *args[2];
arg_cmp_func func;
Item_bool_func2 *owner;
Arg_comparator *comparators; // used only for compare_row()
public:
inline void set_arg(int i, Item *item) { args[i]= item; }
int set_compare_func(Item_bool_func2 *owner, Item_result type);
inline int set_compare_func(Item_bool_func2 *owner)
{
return set_compare_func(owner, item_cmp_type(args[0]->result_type(),
args[1]->result_type()));
}
inline int compare() { return (this->*func)(); }
int compare_string(); // compare args[0] & args[1]
int compare_real(); // compare args[0] & args[1]
int compare_int(); // compare args[0] & args[1]
int compare_row(); // compare args[0] & args[1]
friend class Item_func;
};
class Item_func :public Item_result_field
{
protected:
Item **args,*tmp_arg[2];
Item **args;
Arg_comparator arg_store;
uint allowed_arg_cols;
public:
uint arg_count;
......@@ -53,54 +85,54 @@ class Item_func :public Item_result_field
Item_func(void):
allowed_arg_cols(1), arg_count(0)
{
with_sum_func=0;
with_sum_func= 0;
}
Item_func(Item *a):
allowed_arg_cols(1), arg_count(1)
{
args=tmp_arg;
args[0]=a;
with_sum_func=a->with_sum_func;
args= arg_store.args;
args[0]= a;
with_sum_func= a->with_sum_func;
}
Item_func(Item *a,Item *b):
allowed_arg_cols(1), arg_count(2)
{
args=tmp_arg;
args[0]=a; args[1]=b;
with_sum_func=a->with_sum_func || b->with_sum_func;
args= arg_store.args;
args[0]= a; args[1]= b;
with_sum_func= a->with_sum_func || b->with_sum_func;
}
Item_func(Item *a,Item *b,Item *c):
allowed_arg_cols(1)
{
arg_count=0;
if ((args=(Item**) sql_alloc(sizeof(Item*)*3)))
arg_count= 0;
if ((args= (Item**) sql_alloc(sizeof(Item*)*3)))
{
arg_count=3;
args[0]=a; args[1]=b; args[2]=c;
with_sum_func=a->with_sum_func || b->with_sum_func || c->with_sum_func;
arg_count= 3;
args[0]= a; args[1]= b; args[2]= c;
with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
}
}
Item_func(Item *a,Item *b,Item *c,Item *d):
allowed_arg_cols(1)
{
arg_count=0;
if ((args=(Item**) sql_alloc(sizeof(Item*)*4)))
arg_count= 0;
if ((args= (Item**) sql_alloc(sizeof(Item*)*4)))
{
arg_count=4;
args[0]=a; args[1]=b; args[2]=c; args[3]=d;
with_sum_func=a->with_sum_func || b->with_sum_func || c->with_sum_func ||
d->with_sum_func;
arg_count= 4;
args[0]= a; args[1]= b; args[2]= c; args[3]= d;
with_sum_func= a->with_sum_func || b->with_sum_func ||
c->with_sum_func || d->with_sum_func;
}
}
Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
allowed_arg_cols(1)
{
arg_count=5;
if ((args=(Item**) sql_alloc(sizeof(Item*)*5)))
arg_count= 5;
if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
{
args[0]=a; args[1]=b; args[2]=c; args[3]=d; args[4]=e;
with_sum_func=a->with_sum_func || b->with_sum_func || c->with_sum_func ||
d->with_sum_func || e->with_sum_func ;
args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
with_sum_func= a->with_sum_func || b->with_sum_func ||
c->with_sum_func || d->with_sum_func || e->with_sum_func ;
}
}
Item_func(List<Item> &list);
......
......@@ -3340,7 +3340,7 @@ change_cond_ref_to_const(I_List<COND_CMP> *save_list,Item *and_father,
if ((tmp2=new COND_CMP(and_father,func)))
save_list->push_back(tmp2);
}
func->set_cmp_func(func->arguments()[0],func->arguments()[1]);
func->set_cmp_func();
}
}
else if (left_item->eq(field,0) && right_item != value)
......@@ -3360,7 +3360,7 @@ change_cond_ref_to_const(I_List<COND_CMP> *save_list,Item *and_father,
if ((tmp2=new COND_CMP(and_father,func)))
save_list->push_back(tmp2);
}
func->set_cmp_func(func->arguments()[0], func->arguments()[1]);
func->set_cmp_func();
}
}
}
......
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