Commit 814510d5 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

optimized IN with Rows (SCRUM)

NULL with row (IN)
cardinality error of row inside row
new[]
fixed layout
parent 67eebb43
...@@ -4,6 +4,35 @@ row(1,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3)) ...@@ -4,6 +4,35 @@ row(1,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3))
select row(10,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3)); select row(10,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3));
row(10,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3)) row(10,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3))
0 0
select row(1,2,3) IN (row(3,NULL,3), row(1,2,3), row(1,3,3));
row(1,2,3) IN (row(3,NULL,3), row(1,2,3), row(1,3,3))
1
select row(10,2,3) IN (row(3,NULL,3), row(1,2,3), row(1,3,3));
row(10,2,3) IN (row(3,NULL,3), row(1,2,3), row(1,3,3))
NULL
select row('a',1.5,3) IN (row(1,2,3), row('a',1.5,3), row('a','a','a'));
row('a',1.5,3) IN (row(1,2,3), row('a',1.5,3), row('a','a','a'))
1
select row('a',0,3) IN (row(3,2,3), row('a','0','3'), row(1,3,3));
row('a',0,3) IN (row(3,2,3), row('a','0','3'), row(1,3,3))
1
select row('a',0,3) IN (row(3,2,3), row('a','a','3'), row(1,3,3));
row('a',0,3) IN (row(3,2,3), row('a','a','3'), row(1,3,3))
1
select row('a',1.5,3) IN (row(3,NULL,3), row('a',1.5,3), row(1,3,3));
row('a',1.5,3) IN (row(3,NULL,3), row('a',1.5,3), row(1,3,3))
1
select row('b',1.5,3) IN (row(3,NULL,3), row('a',1.5,3), row(1,3,3));
row('b',1.5,3) IN (row(3,NULL,3), row('a',1.5,3), row(1,3,3))
NULL
select row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,4)));
row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,4)))
1
select row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,4));
Cardinality error (more/less than 2 columns)
select row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,NULL)));
row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,NULL)))
NULL
SELECT ROW(1,2,3)=ROW(1,2,3); SELECT ROW(1,2,3)=ROW(1,2,3);
ROW(1,2,3)=ROW(1,2,3) ROW(1,2,3)=ROW(1,2,3)
1 1
...@@ -42,9 +71,20 @@ ROW('test',2,3.33)=ROW('test',2,3.33) ...@@ -42,9 +71,20 @@ ROW('test',2,3.33)=ROW('test',2,3.33)
1 1
SELECT ROW('test',2,3.33)=ROW('test',2,3.33,4); SELECT ROW('test',2,3.33)=ROW('test',2,3.33,4);
Cardinality error (more/less than 3 columns) Cardinality error (more/less than 3 columns)
SELECT ROW('test',2,ROW(3,33))=ROW('test',2,ROW(3,33));
ROW('test',2,ROW(3,33))=ROW('test',2,ROW(3,33))
1
SELECT ROW('test',2,ROW(3,33))=ROW('test',2,ROW(3,3));
ROW('test',2,ROW(3,33))=ROW('test',2,ROW(3,3))
0
SELECT ROW('test',2,ROW(3,33))=ROW('test',2,ROW(3,NULL));
ROW('test',2,ROW(3,33))=ROW('test',2,ROW(3,NULL))
NULL
SELECT ROW('test',2,ROW(3,33))=ROW('test',2,4);
Cardinality error (more/less than 2 columns)
drop table if exists t1; drop table if exists t1;
create table t1 ( a int, b int, c int); create table t1 ( a int, b int, c int);
insert into t1 values (1,2,3), (2,3,1), (3,2,1); insert into t1 values (1,2,3), (2,3,1), (3,2,1), (1,2,NULL);
select * from t1 where ROW(1,2,3)=ROW(a,b,c); select * from t1 where ROW(1,2,3)=ROW(a,b,c);
a b c a b c
1 2 3 1 2 3
...@@ -54,16 +94,30 @@ select * from t1 where ROW(1,2,3)<ROW(a,b,c); ...@@ -54,16 +94,30 @@ select * from t1 where ROW(1,2,3)<ROW(a,b,c);
a b c a b c
2 3 1 2 3 1
3 2 1 3 2 1
select * from t1 where ROW(a,2,3) IN(row(1,b,c), row(2,3,1)); select ROW(a,2,3) IN(row(1,b,c), row(2,3,1)) from t1;
a b c ROW(a,2,3) IN(row(1,b,c), row(2,3,1))
1 2 3 1
select * from t1 where ROW(c,2,3) IN(row(1,b,a), row(2,3,1)); 0
a b c 0
3 2 1 NULL
select * from t1 where ROW(a,b,c) IN(row(1,2,3), row(3,2,1)); select ROW(c,2,3) IN(row(1,b,a), row(2,3,1)) from t1;
a b c ROW(c,2,3) IN(row(1,b,a), row(2,3,1))
1 2 3 0
3 2 1 0
1
NULL
select ROW(a,b,c) IN(row(1,2,3), row(3,2,1)) from t1;
ROW(a,b,c) IN(row(1,2,3), row(3,2,1))
1
0
1
NULL
select ROW(1,2,3) IN(row(a,b,c), row(1,2,3)) from t1;
ROW(1,2,3) IN(row(a,b,c), row(1,2,3))
1
1
1
1
drop table t1; drop table t1;
select ROW(1,1); select ROW(1,1);
Cardinality error (more/less than 1 columns) Cardinality error (more/less than 1 columns)
......
select row(1,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3)); select row(1,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3));
select row(10,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3)); select row(10,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3));
select row(1,2,3) IN (row(3,NULL,3), row(1,2,3), row(1,3,3));
select row(10,2,3) IN (row(3,NULL,3), row(1,2,3), row(1,3,3));
select row('a',1.5,3) IN (row(1,2,3), row('a',1.5,3), row('a','a','a'));
select row('a',0,3) IN (row(3,2,3), row('a','0','3'), row(1,3,3));
select row('a',0,3) IN (row(3,2,3), row('a','a','3'), row(1,3,3));
select row('a',1.5,3) IN (row(3,NULL,3), row('a',1.5,3), row(1,3,3));
select row('b',1.5,3) IN (row(3,NULL,3), row('a',1.5,3), row(1,3,3));
select row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,4)));
-- error 1239
select row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,4));
select row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,NULL)));
SELECT ROW(1,2,3)=ROW(1,2,3); SELECT ROW(1,2,3)=ROW(1,2,3);
SELECT ROW(2,2,3)=ROW(1+1,2,3); SELECT ROW(2,2,3)=ROW(1+1,2,3);
...@@ -15,15 +26,21 @@ SELECT ROW(1,2,ROW(3,4,5))=ROW(1,2,ROW(3,4,5)); ...@@ -15,15 +26,21 @@ SELECT ROW(1,2,ROW(3,4,5))=ROW(1,2,ROW(3,4,5));
SELECT ROW('test',2,3.33)=ROW('test',2,3.33); SELECT ROW('test',2,3.33)=ROW('test',2,3.33);
-- error 1239 -- error 1239
SELECT ROW('test',2,3.33)=ROW('test',2,3.33,4); SELECT ROW('test',2,3.33)=ROW('test',2,3.33,4);
SELECT ROW('test',2,ROW(3,33))=ROW('test',2,ROW(3,33));
SELECT ROW('test',2,ROW(3,33))=ROW('test',2,ROW(3,3));
SELECT ROW('test',2,ROW(3,33))=ROW('test',2,ROW(3,NULL));
-- error 1239
SELECT ROW('test',2,ROW(3,33))=ROW('test',2,4);
drop table if exists t1; drop table if exists t1;
create table t1 ( a int, b int, c int); create table t1 ( a int, b int, c int);
insert into t1 values (1,2,3), (2,3,1), (3,2,1); insert into t1 values (1,2,3), (2,3,1), (3,2,1), (1,2,NULL);
select * from t1 where ROW(1,2,3)=ROW(a,b,c); select * from t1 where ROW(1,2,3)=ROW(a,b,c);
select * from t1 where ROW(0,2,3)=ROW(a,b,c); select * from t1 where ROW(0,2,3)=ROW(a,b,c);
select * from t1 where ROW(1,2,3)<ROW(a,b,c); select * from t1 where ROW(1,2,3)<ROW(a,b,c);
select * from t1 where ROW(a,2,3) IN(row(1,b,c), row(2,3,1)); select ROW(a,2,3) IN(row(1,b,c), row(2,3,1)) from t1;
select * from t1 where ROW(c,2,3) IN(row(1,b,a), row(2,3,1)); select ROW(c,2,3) IN(row(1,b,a), row(2,3,1)) from t1;
select * from t1 where ROW(a,b,c) IN(row(1,2,3), row(3,2,1)); select ROW(a,b,c) IN(row(1,2,3), row(3,2,1)) from t1;
select ROW(1,2,3) IN(row(a,b,c), row(1,2,3)) from t1;
drop table t1; drop table t1;
-- error 1239 -- error 1239
......
...@@ -144,7 +144,14 @@ int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type) ...@@ -144,7 +144,14 @@ int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type)
} }
if ((comparators= (Arg_comparator *) sql_alloc(sizeof(Arg_comparator)*n))) if ((comparators= (Arg_comparator *) sql_alloc(sizeof(Arg_comparator)*n)))
for (uint i=0; i < n; i++) for (uint i=0; i < n; i++)
{
if ((*a)->cols() != (*a)->cols())
{
my_error(ER_CARDINALITY_COL, MYF(0), (*a)->cols());
return 1;
}
comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i)); comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
}
else else
{ {
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
...@@ -1033,6 +1040,11 @@ static int cmp_double(double *a,double *b) ...@@ -1033,6 +1040,11 @@ static int cmp_double(double *a,double *b)
return *a < *b ? -1 : *a == *b ? 0 : 1; return *a < *b ? -1 : *a == *b ? 0 : 1;
} }
static int cmp_row(cmp_item_row* a, cmp_item_row* b)
{
return a->compare(b);
}
int in_vector::find(Item *item) int in_vector::find(Item *item)
{ {
byte *result=get_value(item); byte *result=get_value(item);
...@@ -1055,7 +1067,6 @@ int in_vector::find(Item *item) ...@@ -1055,7 +1067,6 @@ int in_vector::find(Item *item)
return (int) ((*compare)(base+start*size,result) == 0); return (int) ((*compare)(base+start*size,result) == 0);
} }
in_string::in_string(uint elements,qsort_cmp cmp_func) 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)
{} {}
...@@ -1082,6 +1093,29 @@ byte *in_string::get_value(Item *item) ...@@ -1082,6 +1093,29 @@ byte *in_string::get_value(Item *item)
return (byte*) item->val_str(&tmp); return (byte*) item->val_str(&tmp);
} }
in_row::in_row(uint elements, Item * item)
{
DBUG_ENTER("in_row::in_row");
base= (char*) new cmp_item_row[elements];
size= sizeof(cmp_item_row);
compare= (qsort_cmp) cmp_row;
tmp.store_value(item);
DBUG_VOID_RETURN;
}
byte *in_row::get_value(Item *item)
{
tmp.store_value(item);
return (byte *)&tmp;
}
void in_row::set(uint pos, Item *item)
{
DBUG_ENTER("in_row::set");
DBUG_PRINT("enter", ("pos %u item 0x%lx", pos, (ulong) item));
((cmp_item_row*) base)[pos].store_value_by_template(&tmp, item);
DBUG_VOID_RETURN;
}
in_longlong::in_longlong(uint elements) in_longlong::in_longlong(uint elements)
:in_vector(elements,sizeof(longlong),(qsort_cmp) cmp_longlong) :in_vector(elements,sizeof(longlong),(qsort_cmp) cmp_longlong)
...@@ -1094,13 +1128,12 @@ void in_longlong::set(uint pos,Item *item) ...@@ -1094,13 +1128,12 @@ void in_longlong::set(uint pos,Item *item)
byte *in_longlong::get_value(Item *item) byte *in_longlong::get_value(Item *item)
{ {
tmp=item->val_int(); tmp= item->val_int();
if (item->null_value) if (item->null_value)
return 0; /* purecov: inspected */ return 0;
return (byte*) &tmp; return (byte*) &tmp;
} }
in_double::in_double(uint elements) in_double::in_double(uint elements)
:in_vector(elements,sizeof(double),(qsort_cmp) cmp_double) :in_vector(elements,sizeof(double),(qsort_cmp) cmp_double)
{} {}
...@@ -1112,7 +1145,7 @@ void in_double::set(uint pos,Item *item) ...@@ -1112,7 +1145,7 @@ void in_double::set(uint pos,Item *item)
byte *in_double::get_value(Item *item) byte *in_double::get_value(Item *item)
{ {
tmp=item->val(); tmp= item->val();
if (item->null_value) if (item->null_value)
return 0; /* purecov: inspected */ return 0; /* purecov: inspected */
return (byte*) &tmp; return (byte*) &tmp;
...@@ -1140,14 +1173,77 @@ cmp_item* cmp_item::get_comparator (Item *item) ...@@ -1140,14 +1173,77 @@ cmp_item* cmp_item::get_comparator (Item *item)
return 0; // to satisfy compiler :) return 0; // to satisfy compiler :)
} }
cmp_item* cmp_item_sort_string::make_same()
{
return new cmp_item_sort_string_in_static();
}
cmp_item* cmp_item_binary_string::make_same()
{
return new cmp_item_binary_string_in_static();
}
cmp_item* cmp_item_int::make_same()
{
return new cmp_item_int();
}
cmp_item* cmp_item_real::make_same()
{
return new cmp_item_real();
}
cmp_item* cmp_item_row::make_same()
{
return new cmp_item_row();
}
void cmp_item_row::store_value(Item *item) void cmp_item_row::store_value(Item *item)
{ {
n= item->cols(); n= item->cols();
if ((comparators= (cmp_item **) sql_alloc(sizeof(cmp_item *)*n))) if ((comparators= (cmp_item **) sql_alloc(sizeof(cmp_item *)*n)))
{ {
item->null_value= 0;
for (uint i=0; i < n; i++) for (uint i=0; i < n; i++)
if ((comparators[i]= cmp_item::get_comparator(item->el(i)))) if ((comparators[i]= cmp_item::get_comparator(item->el(i))))
{
comparators[i]->store_value(item->el(i)); comparators[i]->store_value(item->el(i));
item->null_value|= item->el(i)->null_value;
}
else
{
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
current_thd->fatal_error= 1;
return;
}
}
else
{
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
current_thd->fatal_error= 1;
return;
}
}
void cmp_item_row::store_value_by_template(cmp_item *t, Item *item)
{
cmp_item_row *tmpl= (cmp_item_row*) t;
if (tmpl->n != item->cols())
{
my_error(ER_CARDINALITY_COL, MYF(0), tmpl->n);
return;
}
n= tmpl->n;
if ((comparators= (cmp_item **) sql_alloc(sizeof(cmp_item *)*n)))
{
item->null_value= 0;
for (uint i=0; i < n; i++)
if ((comparators[i]= tmpl->comparators[i]->make_same()))
{
comparators[i]->store_value_by_template(tmpl->comparators[i],
item->el(i));
item->null_value|= item->el(i)->null_value;
}
else else
{ {
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
...@@ -1165,15 +1261,34 @@ void cmp_item_row::store_value(Item *item) ...@@ -1165,15 +1261,34 @@ void cmp_item_row::store_value(Item *item)
int cmp_item_row::cmp(Item *arg) int cmp_item_row::cmp(Item *arg)
{ {
arg->null_value= 0;
if (arg->cols() != n)
{
my_error(ER_CARDINALITY_COL, MYF(0), n);
return 1;
}
for(uint i=0; i < n; i++) for(uint i=0; i < n; i++)
if(comparators[i]->cmp(arg->el(i))) if(comparators[i]->cmp(arg->el(i)))
{
arg->null_value|= arg->el(i)->null_value;
return 1; return 1;
}
return 0;
}
int cmp_item_row::compare(cmp_item *c)
{
int res;
cmp_item_row *cmp= (cmp_item_row *) c;
for(uint i=0; i < n; i++)
if((res= comparators[i]->compare(cmp->comparators[i])))
return res;
return 0; return 0;
} }
void Item_func_in::fix_length_and_dec() void Item_func_in::fix_length_and_dec()
{ {
if (const_item() && item->result_type()!=ROW_RESULT) if (const_item())
{ {
switch (item->result_type()) { switch (item->result_type()) {
case STRING_RESULT: case STRING_RESULT:
...@@ -1189,8 +1304,7 @@ void Item_func_in::fix_length_and_dec() ...@@ -1189,8 +1304,7 @@ void Item_func_in::fix_length_and_dec()
array= new in_double(arg_count); array= new in_double(arg_count);
break; break;
case ROW_RESULT: case ROW_RESULT:
// This case should never be choosen array= new in_row(arg_count, item);
DBUG_ASSERT(0);
break; break;
} }
uint j=0; uint j=0;
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
/* compare and test functions */ /* compare and test functions */
#include "assert.h"
#ifdef __GNUC__ #ifdef __GNUC__
#pragma interface /* gcc class implementation */ #pragma interface /* gcc class implementation */
#endif #endif
...@@ -375,6 +377,7 @@ class in_vector :public Sql_alloc ...@@ -375,6 +377,7 @@ class in_vector :public Sql_alloc
uint count; uint count;
public: public:
uint used_count; uint used_count;
in_vector() {}
in_vector(uint elements,uint element_length,qsort_cmp cmp_func) in_vector(uint elements,uint element_length,qsort_cmp cmp_func)
:base((char*) sql_calloc(elements*element_length)), :base((char*) sql_calloc(elements*element_length)),
size(element_length), compare(cmp_func), count(elements), size(element_length), compare(cmp_func), count(elements),
...@@ -389,7 +392,6 @@ class in_vector :public Sql_alloc ...@@ -389,7 +392,6 @@ class in_vector :public Sql_alloc
int find(Item *item); int find(Item *item);
}; };
class in_string :public in_vector class in_string :public in_vector
{ {
char buff[80]; char buff[80];
...@@ -401,7 +403,6 @@ class in_string :public in_vector ...@@ -401,7 +403,6 @@ class in_string :public in_vector
byte *get_value(Item *item); byte *get_value(Item *item);
}; };
class in_longlong :public in_vector class in_longlong :public in_vector
{ {
longlong tmp; longlong tmp;
...@@ -411,7 +412,6 @@ class in_longlong :public in_vector ...@@ -411,7 +412,6 @@ class in_longlong :public in_vector
byte *get_value(Item *item); byte *get_value(Item *item);
}; };
class in_double :public in_vector class in_double :public in_vector
{ {
double tmp; double tmp;
...@@ -421,7 +421,6 @@ class in_double :public in_vector ...@@ -421,7 +421,6 @@ class in_double :public in_vector
byte *get_value(Item *item); byte *get_value(Item *item);
}; };
/* /*
** Classes for easy comparing of non const items ** Classes for easy comparing of non const items
*/ */
...@@ -431,30 +430,55 @@ class cmp_item :public Sql_alloc ...@@ -431,30 +430,55 @@ class cmp_item :public Sql_alloc
public: public:
cmp_item() {} cmp_item() {}
virtual ~cmp_item() {} virtual ~cmp_item() {}
virtual void store_value(Item *item)=0; virtual void store_value(Item *item)= 0;
virtual int cmp(Item *item)=0; virtual int cmp(Item *item)= 0;
// for optimized IN with row
virtual int compare(cmp_item *item)= 0;
static cmp_item* get_comparator(Item *); static cmp_item* get_comparator(Item *);
virtual cmp_item *make_same()= 0;
virtual void store_value_by_template(cmp_item *tmpl, Item *item)
{
store_value(item);
}
}; };
class cmp_item_string :public cmp_item
{
protected:
String *value_res;
public:
friend class cmp_item_sort_string;
friend class cmp_item_binary_string;
friend class cmp_item_sort_string_in_static;
friend class cmp_item_binary_string_in_static;
};
class cmp_item_sort_string :public cmp_item { class cmp_item_sort_string :public cmp_item_string
protected: {
protected:
char value_buff[80]; char value_buff[80];
String value,*value_res; String value;
public: public:
cmp_item_sort_string() :value(value_buff,sizeof(value_buff),default_charset_info) {} cmp_item_sort_string():
value(value_buff, sizeof(value_buff), default_charset_info) {}
void store_value(Item *item) void store_value(Item *item)
{ {
value_res=item->val_str(&value); value_res= item->val_str(&value);
} }
int cmp(Item *arg) int cmp(Item *arg)
{ {
char buff[80]; char buff[80];
String tmp(buff,sizeof(buff),default_charset_info),*res; String tmp(buff, sizeof(buff), default_charset_info), *res;
if (!(res=arg->val_str(&tmp))) if (!(res= arg->val_str(&tmp)))
return 1; /* Can't be right */ return 1; /* Can't be right */
return sortcmp(value_res,res); return sortcmp(value_res, res);
} }
int compare(cmp_item *c)
{
cmp_item_string *cmp= (cmp_item_string *)c;
return sortcmp(value_res, cmp->value_res);
}
cmp_item *make_same();
}; };
class cmp_item_binary_string :public cmp_item_sort_string { class cmp_item_binary_string :public cmp_item_sort_string {
...@@ -468,24 +492,34 @@ class cmp_item_binary_string :public cmp_item_sort_string { ...@@ -468,24 +492,34 @@ class cmp_item_binary_string :public cmp_item_sort_string {
return 1; /* Can't be right */ return 1; /* Can't be right */
return stringcmp(value_res,res); return stringcmp(value_res,res);
} }
int compare(cmp_item *c)
{
cmp_item_string *cmp= (cmp_item_string *)c;
return stringcmp(value_res, cmp->value_res);
}
cmp_item *make_same();
}; };
class cmp_item_int :public cmp_item class cmp_item_int :public cmp_item
{ {
longlong value; longlong value;
public: public:
void store_value(Item *item) void store_value(Item *item)
{ {
value=item->val_int(); value= item->val_int();
} }
int cmp(Item *arg) int cmp(Item *arg)
{ {
return value != arg->val_int(); return value != arg->val_int();
} }
int compare(cmp_item *c)
{
cmp_item_int *cmp= (cmp_item_int *)c;
return (value < cmp->value) ? -1 : ((value == cmp->value) ? 0 : 1);
}
cmp_item *make_same();
}; };
class cmp_item_real :public cmp_item class cmp_item_real :public cmp_item
{ {
double value; double value;
...@@ -498,6 +532,12 @@ class cmp_item_real :public cmp_item ...@@ -498,6 +532,12 @@ class cmp_item_real :public cmp_item
{ {
return value != arg->val(); return value != arg->val();
} }
int compare(cmp_item *c)
{
cmp_item_real *cmp= (cmp_item_real *)c;
return (value < cmp->value)? -1 : ((value == cmp->value) ? 0 : 1);
}
cmp_item *make_same();
}; };
class cmp_item_row :public cmp_item class cmp_item_row :public cmp_item
...@@ -505,8 +545,75 @@ class cmp_item_row :public cmp_item ...@@ -505,8 +545,75 @@ class cmp_item_row :public cmp_item
cmp_item **comparators; cmp_item **comparators;
uint n; uint n;
public: public:
cmp_item_row(): comparators(0), n(0) {}
~cmp_item_row()
{
if(comparators)
for(uint i= 0; i < n; i++)
if (comparators[i])
delete comparators[i];
}
void store_value(Item *item); void store_value(Item *item);
int cmp(Item *arg); int cmp(Item *arg);
int compare(cmp_item *arg);
cmp_item *make_same();
void store_value_by_template(cmp_item *tmpl, Item *);
};
class in_row :public in_vector
{
cmp_item_row tmp;
public:
in_row(uint elements, Item *);
void set(uint pos,Item *item);
byte *get_value(Item *item);
};
/*
cmp_item for optimized IN with row (right part string, which never
be changed)
*/
class cmp_item_sort_string_in_static :public cmp_item_string
{
protected:
String value;
public:
cmp_item_sort_string_in_static() {}
void store_value(Item *item)
{
value_res= item->val_str(&value);
}
int cmp(Item *item)
{
// Should never be called
DBUG_ASSERT(0);
return 1;
}
int compare(cmp_item *c)
{
cmp_item_string *cmp= (cmp_item_string *)c;
return sortcmp(value_res, cmp->value_res);
}
cmp_item * make_same()
{
return new cmp_item_sort_string_in_static();
}
};
class cmp_item_binary_string_in_static :public cmp_item_sort_string_in_static {
public:
cmp_item_binary_string_in_static() {}
int compare(cmp_item *c)
{
cmp_item_string *cmp= (cmp_item_string *)c;
return stringcmp(value_res, cmp->value_res);
}
cmp_item * make_same()
{
return new cmp_item_binary_string_in_static();
}
}; };
class Item_func_in :public Item_int_func class Item_func_in :public Item_int_func
...@@ -546,8 +653,6 @@ class Item_func_in :public Item_int_func ...@@ -546,8 +653,6 @@ class Item_func_in :public Item_int_func
} }
}; };
/* Functions used by where clause */ /* Functions used by where clause */
class Item_func_isnull :public Item_bool_func class Item_func_isnull :public Item_bool_func
......
...@@ -25,8 +25,16 @@ ...@@ -25,8 +25,16 @@
class Sql_alloc class Sql_alloc
{ {
public: public:
static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); } static void *operator new(size_t size)
{
return (void*) sql_alloc((uint) size);
}
static void *operator new[](size_t size)
{
return (void*) sql_alloc((uint) size);
}
static void operator delete(void *ptr, size_t size) {} /*lint -e715 */ static void operator delete(void *ptr, size_t size) {} /*lint -e715 */
static void operator delete[](void *ptr, size_t size) {}
#ifdef HAVE_purify #ifdef HAVE_purify
bool dummy; bool dummy;
inline Sql_alloc() :dummy(0) {} inline Sql_alloc() :dummy(0) {}
......
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