Commit 46460026 authored by unknown's avatar unknown

Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-4.1

into sanja.is.com.ua:/home/bell/mysql/bk/work-alloc_group-4.1


mysql-test/t/subselect.test:
  Auto merged
sql/sql_select.cc:
  Auto merged
parents b41eb006 f89848bb
...@@ -168,8 +168,8 @@ insert into T_REQUEST values (1,4), (5,4), (5,5); ...@@ -168,8 +168,8 @@ insert into T_REQUEST values (1,4), (5,4), (5,5);
select REQ_ID, Group_Concat(URL) as URL from T_URL, T_REQUEST where select REQ_ID, Group_Concat(URL) as URL from T_URL, T_REQUEST where
T_REQUEST.URL_ID = T_URL.URL_ID group by REQ_ID; T_REQUEST.URL_ID = T_URL.URL_ID group by REQ_ID;
REQ_ID URL REQ_ID URL
1 www.host.com 1 X
5 www.google.com,www.help.com,www.host.com 5 X,X,X
drop table T_URL; drop table T_URL;
drop table T_REQUEST; drop table T_REQUEST;
select group_concat(sum(a)) from t1 group by grp; select group_concat(sum(a)) from t1 group by grp;
......
drop table if exists t1; drop table if exists t1;
set names latin1;
select 'hello',"'hello'",'""hello""','''h''e''l''l''o''',"hel""lo",'hel\'lo'; select 'hello',"'hello'",'""hello""','''h''e''l''l''o''',"hel""lo",'hel\'lo';
hello 'hello' ""hello"" 'h'e'l'l'o' hel"lo hel'lo hello 'hello' ""hello"" 'h'e'l'l'o' hel"lo hel'lo
hello 'hello' ""hello"" 'h'e'l'l'o' hel"lo hel'lo hello 'hello' ""hello"" 'h'e'l'l'o' hel"lo hel'lo
...@@ -249,6 +250,59 @@ INSERT INTO t1 VALUES (1, 'a545f661efdd1fb66fdee3aab79945bf'); ...@@ -249,6 +250,59 @@ INSERT INTO t1 VALUES (1, 'a545f661efdd1fb66fdee3aab79945bf');
SELECT 1 FROM t1 WHERE tmp=AES_DECRYPT(tmp,"password"); SELECT 1 FROM t1 WHERE tmp=AES_DECRYPT(tmp,"password");
1 1
DROP TABLE t1; DROP TABLE t1;
select 1=_latin1'1';
1=_latin1'1'
1
select _latin1'1'=1;
_latin1'1'=1
1
select _latin2'1'=1;
_latin2'1'=1
1
select 1=_latin2'1';
1=_latin2'1'
1
select _latin1'1'=_latin2'1';
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin2_general_ci,COERCIBLE) for operation '='
select row('a','b','c') = row('a','b','c');
row('a','b','c') = row('a','b','c')
1
select row('A','b','c') = row('a','b','c');
row('A','b','c') = row('a','b','c')
1
select row('A' COLLATE latin1_bin,'b','c') = row('a','b','c');
row('A' COLLATE latin1_bin,'b','c') = row('a','b','c')
0
select row('A','b','c') = row('a' COLLATE latin1_bin,'b','c');
row('A','b','c') = row('a' COLLATE latin1_bin,'b','c')
0
select row('A' COLLATE latin1_general_ci,'b','c') = row('a' COLLATE latin1_bin,'b','c');
ERROR HY000: Illegal mix of collations (latin1_general_ci,EXPLICIT) and (latin1_bin,EXPLICIT) for operation '='
select concat(_latin1'a',_latin2'a');
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin2_general_ci,COERCIBLE) for operation 'concat'
select concat(_latin1'a',_latin2'a',_latin5'a');
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE), (latin2_general_ci,COERCIBLE), (latin5_turkish_ci,COERCIBLE) for operation 'concat'
select concat(_latin1'a',_latin2'a',_latin5'a',_latin7'a');
ERROR HY000: Illegal mix of collations for operation 'concat'
select FIELD('b','A','B');
FIELD('b','A','B')
2
select FIELD('B','A','B');
FIELD('B','A','B')
2
select FIELD('b' COLLATE latin1_bin,'A','B');
FIELD('b' COLLATE latin1_bin,'A','B')
0
select FIELD('b','A' COLLATE latin1_bin,'B');
FIELD('b','A' COLLATE latin1_bin,'B')
0
select FIELD(_latin2'b','A','B');
ERROR HY000: Illegal mix of collations for operation 'field'
select FIELD('b',_latin2'A','B');
ERROR HY000: Illegal mix of collations for operation 'field'
select FIELD('b',_latin2'A','B',1);
FIELD('b',_latin2'A','B',1)
1
select POSITION(_latin1'B' IN _latin1'abcd'); select POSITION(_latin1'B' IN _latin1'abcd');
POSITION(_latin1'B' IN _latin1'abcd') POSITION(_latin1'B' IN _latin1'abcd')
2 2
......
...@@ -148,3 +148,22 @@ alter table t1 type=MyISAM; ...@@ -148,3 +148,22 @@ alter table t1 type=MyISAM;
handler t2 read first; handler t2 read first;
ERROR 42S02: Unknown table 't2' in HANDLER ERROR 42S02: Unknown table 't2' in HANDLER
drop table t1; drop table t1;
create table t1 (a int);
insert into t1 values (1),(2),(3),(4),(5),(6);
delete from t1 limit 2;
handler t1 open;
handler t1 read first;
a
3
handler t1 read first limit 1,1;
a
4
handler t1 read first limit 2,2;
a
5
6
delete from t1 limit 3;
handler t1 read first;
a
6
drop table t1;
...@@ -78,6 +78,8 @@ drop table if exists T_REQUEST; ...@@ -78,6 +78,8 @@ drop table if exists T_REQUEST;
create table T_REQUEST ( REQ_ID int(11), URL_ID int(11)); create table T_REQUEST ( REQ_ID int(11), URL_ID int(11));
insert into T_URL values (4,'www.host.com'), (5,'www.google.com'),(5,'www.help.com'); insert into T_URL values (4,'www.host.com'), (5,'www.google.com'),(5,'www.help.com');
insert into T_REQUEST values (1,4), (5,4), (5,5); insert into T_REQUEST values (1,4), (5,4), (5,5);
# Make this order independent
--replace_result www.help.com X www.host.com X www.google.com X
select REQ_ID, Group_Concat(URL) as URL from T_URL, T_REQUEST where select REQ_ID, Group_Concat(URL) as URL from T_URL, T_REQUEST where
T_REQUEST.URL_ID = T_URL.URL_ID group by REQ_ID; T_REQUEST.URL_ID = T_URL.URL_ID group by REQ_ID;
drop table T_URL; drop table T_URL;
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
drop table if exists t1; drop table if exists t1;
--enable_warnings --enable_warnings
set names latin1;
select 'hello',"'hello'",'""hello""','''h''e''l''l''o''',"hel""lo",'hel\'lo'; select 'hello',"'hello'",'""hello""','''h''e''l''l''o''',"hel""lo",'hel\'lo';
select 'hello' 'monty'; select 'hello' 'monty';
select length('\n\t\r\b\0\_\%\\'); select length('\n\t\r\b\0\_\%\\');
...@@ -136,6 +138,42 @@ DROP TABLE t1; ...@@ -136,6 +138,42 @@ DROP TABLE t1;
# #
# Test collation and coercibility # Test collation and coercibility
# #
select 1=_latin1'1';
select _latin1'1'=1;
select _latin2'1'=1;
select 1=_latin2'1';
--error 1265
select _latin1'1'=_latin2'1';
select row('a','b','c') = row('a','b','c');
select row('A','b','c') = row('a','b','c');
select row('A' COLLATE latin1_bin,'b','c') = row('a','b','c');
select row('A','b','c') = row('a' COLLATE latin1_bin,'b','c');
--error 1265
select row('A' COLLATE latin1_general_ci,'b','c') = row('a' COLLATE latin1_bin,'b','c');
--error 1265
select concat(_latin1'a',_latin2'a');
--error 1268
select concat(_latin1'a',_latin2'a',_latin5'a');
--error 1269
select concat(_latin1'a',_latin2'a',_latin5'a',_latin7'a');
#
# Test FIELD() and collations
#
select FIELD('b','A','B');
select FIELD('B','A','B');
select FIELD('b' COLLATE latin1_bin,'A','B');
select FIELD('b','A' COLLATE latin1_bin,'B');
--error 1269
select FIELD(_latin2'b','A','B');
--error 1269
select FIELD('b',_latin2'A','B');
select FIELD('b',_latin2'A','B',1);
select POSITION(_latin1'B' IN _latin1'abcd'); select POSITION(_latin1'B' IN _latin1'abcd');
select POSITION(_latin1'B' IN _latin1'abcd' COLLATE latin1_bin); select POSITION(_latin1'B' IN _latin1'abcd' COLLATE latin1_bin);
select POSITION(_latin1'B' COLLATE latin1_bin IN _latin1'abcd'); select POSITION(_latin1'B' COLLATE latin1_bin IN _latin1'abcd');
......
...@@ -85,3 +85,17 @@ alter table t1 type=MyISAM; ...@@ -85,3 +85,17 @@ alter table t1 type=MyISAM;
handler t2 read first; handler t2 read first;
drop table t1; drop table t1;
#
# test case for the bug #787
#
create table t1 (a int);
insert into t1 values (1),(2),(3),(4),(5),(6);
delete from t1 limit 2;
handler t1 open;
handler t1 read first;
handler t1 read first limit 1,1;
handler t1 read first limit 2,2;
delete from t1 limit 3;
handler t1 read first;
drop table t1;
...@@ -781,6 +781,7 @@ drop table if exists t1; ...@@ -781,6 +781,7 @@ drop table if exists t1;
# #
# key field overflow test # key field overflow test
# #
--disable_warnings
CREATE TABLE t1 CREATE TABLE t1
( (
FOLDERID VARCHAR(32)BINARY NOT NULL FOLDERID VARCHAR(32)BINARY NOT NULL
...@@ -798,6 +799,7 @@ FOLDERID VARCHAR(32)BINARY NOT NULL ...@@ -798,6 +799,7 @@ FOLDERID VARCHAR(32)BINARY NOT NULL
, PRIMARY KEY ( FOLDERID ) , PRIMARY KEY ( FOLDERID )
) TYPE=InnoDB; ) TYPE=InnoDB;
--enable_warnings
CREATE INDEX FFOLDERID_IDX ON t1 (FOLDERID); CREATE INDEX FFOLDERID_IDX ON t1 (FOLDERID);
CREATE INDEX CMFLDRPARNT_IDX ON t1 (PARENTID); CREATE INDEX CMFLDRPARNT_IDX ON t1 (PARENTID);
INSERT INTO t1 VALUES("0c9aab05b15048c59bc35c8461507deb", "System", "System", "2003-06-05 16:30:00", "The system content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "9c9aab05b15048c59bc35c8461507deb", "1"); INSERT INTO t1 VALUES("0c9aab05b15048c59bc35c8461507deb", "System", "System", "2003-06-05 16:30:00", "The system content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "9c9aab05b15048c59bc35c8461507deb", "1");
......
...@@ -32,18 +32,6 @@ static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fnam ...@@ -32,18 +32,6 @@ static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fnam
fname); fname);
} }
static void my_coll_agg3_error(DTCollation &c1,
DTCollation &c2,
DTCollation &c3,
const char *fname)
{
my_error(ER_CANT_AGGREGATE_3COLLATIONS,MYF(0),
c1.collation->name,c1.derivation_name(),
c2.collation->name,c2.derivation_name(),
c3.collation->name,c3.derivation_name(),
fname);
}
Item_bool_func2* Item_bool_func2::eq_creator(Item *a, Item *b) Item_bool_func2* Item_bool_func2::eq_creator(Item *a, Item *b)
{ {
return new Item_func_eq(a, b); return new Item_func_eq(a, b);
...@@ -109,15 +97,6 @@ static bool convert_constant_item(Field *field, Item **item) ...@@ -109,15 +97,6 @@ static bool convert_constant_item(Field *field, Item **item)
} }
bool Item_bool_func2::fix_fields(THD *thd, struct st_table_list *tables,
Item ** ref)
{
if (Item_int_func::fix_fields(thd, tables, ref))
return 1;
return 0;
}
void Item_bool_func2::fix_length_and_dec() void Item_bool_func2::fix_length_and_dec()
{ {
max_length= 1; // Function returns 0 or 1 max_length= 1; // Function returns 0 or 1
...@@ -191,8 +170,6 @@ void Item_bool_func2::fix_length_and_dec() ...@@ -191,8 +170,6 @@ void Item_bool_func2::fix_length_and_dec()
{ {
cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
INT_RESULT); // Works for all types. INT_RESULT); // Works for all types.
cmp_collation.set(&my_charset_bin,
DERIVATION_NONE); // For test in fix_fields
return; return;
} }
} }
...@@ -206,23 +183,11 @@ void Item_bool_func2::fix_length_and_dec() ...@@ -206,23 +183,11 @@ void Item_bool_func2::fix_length_and_dec()
{ {
cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
INT_RESULT); // Works for all types. INT_RESULT); // Works for all types.
cmp_collation.set(&my_charset_bin,
DERIVATION_NONE); // For test in fix_fields
return; return;
} }
} }
} }
set_cmp_func(); set_cmp_func();
/*
We must set cmp_charset here as we may be called from for an automatic
generated item, like in natural join
*/
if (cmp_collation.set(args[0]->collation, args[1]->collation))
{
/* set_cmp_charset() failed */
my_coll_agg_error(args[0]->collation, args[1]->collation, func_name());
return;
}
} }
...@@ -252,6 +217,18 @@ int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type) ...@@ -252,6 +217,18 @@ int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type)
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 if (type == STRING_RESULT)
{
/*
We must set cmp_charset here as we may be called from for an automatic
generated item, like in natural join
*/
if (cmp_collation.set((*a)->collation, (*b)->collation))
{
my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
return 1;
}
}
return 0; return 0;
} }
...@@ -264,7 +241,7 @@ int Arg_comparator::compare_string() ...@@ -264,7 +241,7 @@ int Arg_comparator::compare_string()
if ((res2= (*b)->val_str(&owner->tmp_value2))) if ((res2= (*b)->val_str(&owner->tmp_value2)))
{ {
owner->null_value= 0; owner->null_value= 0;
return sortcmp(res1,res2,owner->cmp_collation.collation); return sortcmp(res1,res2,cmp_collation.collation);
} }
} }
owner->null_value= 1; owner->null_value= 1;
...@@ -278,7 +255,7 @@ int Arg_comparator::compare_e_string() ...@@ -278,7 +255,7 @@ int Arg_comparator::compare_e_string()
res2= (*b)->val_str(&owner->tmp_value2); res2= (*b)->val_str(&owner->tmp_value2);
if (!res1 || !res2) if (!res1 || !res2)
return test(res1 == res2); return test(res1 == res2);
return test(sortcmp(res1, res2, owner->cmp_collation.collation) == 0); return test(sortcmp(res1, res2, cmp_collation.collation) == 0);
} }
...@@ -502,7 +479,7 @@ longlong Item_func_strcmp::val_int() ...@@ -502,7 +479,7 @@ longlong Item_func_strcmp::val_int()
null_value=1; null_value=1;
return 0; return 0;
} }
int value= sortcmp(a,b,cmp_collation.collation); int value= sortcmp(a,b,cmp.cmp_collation.collation);
null_value=0; null_value=0;
return !value ? 0 : (value < 0 ? (longlong) -1 : (longlong) 1); return !value ? 0 : (value < 0 ? (longlong) -1 : (longlong) 1);
} }
...@@ -583,18 +560,9 @@ void Item_func_between::fix_length_and_dec() ...@@ -583,18 +560,9 @@ void Item_func_between::fix_length_and_dec()
item_cmp_type(args[1]->result_type(), item_cmp_type(args[1]->result_type(),
args[2]->result_type())); args[2]->result_type()));
if (cmp_type == STRING_RESULT) if (cmp_type == STRING_RESULT &&
{ agg_arg_collations_for_comparison(cmp_collation, args, 3))
cmp_collation.set(args[0]->collation);
if (!cmp_collation.aggregate(args[1]->collation))
cmp_collation.aggregate(args[2]->collation);
if (cmp_collation.derivation == DERIVATION_NONE)
{
my_coll_agg3_error(args[0]->collation, args[1]->collation,
args[2]->collation, func_name());
return; return;
}
}
/* /*
Make a special case of compare with date/time and longlong fields. Make a special case of compare with date/time and longlong fields.
...@@ -702,8 +670,8 @@ Item_func_ifnull::fix_length_and_dec() ...@@ -702,8 +670,8 @@ Item_func_ifnull::fix_length_and_dec()
args[1]->result_type())) != args[1]->result_type())) !=
REAL_RESULT) REAL_RESULT)
decimals= 0; decimals= 0;
if (collation.set(args[0]->collation,args[1]->collation)) if (cached_result_type == STRING_RESULT)
my_coll_agg_error(args[0]->collation, args[1]->collation, func_name()); agg_arg_collations(collation, args, arg_count);
} }
...@@ -779,12 +747,9 @@ Item_func_if::fix_length_and_dec() ...@@ -779,12 +747,9 @@ Item_func_if::fix_length_and_dec()
else if (arg1_type == STRING_RESULT || arg2_type == STRING_RESULT) else if (arg1_type == STRING_RESULT || arg2_type == STRING_RESULT)
{ {
cached_result_type = STRING_RESULT; cached_result_type = STRING_RESULT;
if (collation.set(args[1]->collation, args[2]->collation)) if (agg_arg_collations(collation, args+1, 2))
{
my_coll_agg_error(args[0]->collation, args[1]->collation, func_name());
return; return;
} }
}
else else
{ {
set_charset(&my_charset_bin); // Number set_charset(&my_charset_bin); // Number
...@@ -1893,7 +1858,7 @@ longlong Item_func_like::val_int() ...@@ -1893,7 +1858,7 @@ longlong Item_func_like::val_int()
null_value=0; null_value=0;
if (canDoTurboBM) if (canDoTurboBM)
return turboBM_matches(res->ptr(), res->length()) ? 1 : 0; return turboBM_matches(res->ptr(), res->length()) ? 1 : 0;
return my_wildcmp(cmp_collation.collation, return my_wildcmp(cmp.cmp_collation.collation,
res->ptr(),res->ptr()+res->length(), res->ptr(),res->ptr()+res->length(),
res2->ptr(),res2->ptr()+res2->length(), res2->ptr(),res2->ptr()+res2->length(),
escape,wild_one,wild_many) ? 0 : 1; escape,wild_one,wild_many) ? 0 : 1;
...@@ -1983,11 +1948,8 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) ...@@ -1983,11 +1948,8 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
max_length= 1; max_length= 1;
decimals= 0; decimals= 0;
if (cmp_collation.set(args[0]->collation, args[1]->collation)) if (agg_arg_collations(cmp_collation, args, 2))
{
my_coll_agg_error(args[0]->collation, args[1]->collation, func_name());
return 1; return 1;
}
used_tables_cache=args[0]->used_tables() | args[1]->used_tables(); used_tables_cache=args[0]->used_tables() | args[1]->used_tables();
const_item_cache=args[0]->const_item() && args[1]->const_item(); const_item_cache=args[0]->const_item() && args[1]->const_item();
...@@ -2103,7 +2065,7 @@ void Item_func_like::turboBM_compute_suffixes(int *suff) ...@@ -2103,7 +2065,7 @@ void Item_func_like::turboBM_compute_suffixes(int *suff)
*splm1 = pattern_len; *splm1 = pattern_len;
if (cmp_collation.collation == &my_charset_bin) if (cmp.cmp_collation.collation == &my_charset_bin)
{ {
int i; int i;
for (i = pattern_len - 2; i >= 0; i--) for (i = pattern_len - 2; i >= 0; i--)
...@@ -2206,7 +2168,7 @@ void Item_func_like::turboBM_compute_bad_character_shifts() ...@@ -2206,7 +2168,7 @@ void Item_func_like::turboBM_compute_bad_character_shifts()
for (i = bmBc; i < end; i++) for (i = bmBc; i < end; i++)
*i = pattern_len; *i = pattern_len;
if (cmp_collation.collation == &my_charset_bin) if (cmp.cmp_collation.collation == &my_charset_bin)
{ {
for (j = 0; j < plm1; j++) for (j = 0; j < plm1; j++)
bmBc[(uint) (uchar) pattern[j]] = plm1 - j; bmBc[(uint) (uchar) pattern[j]] = plm1 - j;
...@@ -2237,7 +2199,7 @@ bool Item_func_like::turboBM_matches(const char* text, int text_len) const ...@@ -2237,7 +2199,7 @@ bool Item_func_like::turboBM_matches(const char* text, int text_len) const
const int tlmpl= text_len - pattern_len; const int tlmpl= text_len - pattern_len;
/* Searching */ /* Searching */
if (cmp_collation.collation == &my_charset_bin) if (cmp.cmp_collation.collation == &my_charset_bin)
{ {
while (j <= tlmpl) while (j <= tlmpl)
{ {
......
...@@ -35,6 +35,8 @@ class Arg_comparator: public Sql_alloc ...@@ -35,6 +35,8 @@ class Arg_comparator: public Sql_alloc
Arg_comparator *comparators; // used only for compare_row() Arg_comparator *comparators; // used only for compare_row()
public: public:
DTCollation cmp_collation;
Arg_comparator() {}; Arg_comparator() {};
Arg_comparator(Item **a1, Item **a2): a(a1), b(a2) {}; Arg_comparator(Item **a1, Item **a2): a(a1), b(a2) {};
...@@ -112,13 +114,10 @@ class Item_bool_func2 :public Item_int_func ...@@ -112,13 +114,10 @@ class Item_bool_func2 :public Item_int_func
protected: protected:
Arg_comparator cmp; Arg_comparator cmp;
String tmp_value1,tmp_value2; String tmp_value1,tmp_value2;
DTCollation cmp_collation;
public: public:
Item_bool_func2(Item *a,Item *b): Item_bool_func2(Item *a,Item *b):
Item_int_func(a,b), cmp(tmp_arg, tmp_arg+1) Item_int_func(a,b), cmp(tmp_arg, tmp_arg+1) {}
{ cmp_collation.set(0,DERIVATION_NONE);}
bool fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref);
void fix_length_and_dec(); void fix_length_and_dec();
void set_cmp_func() void set_cmp_func()
{ {
......
...@@ -39,6 +39,61 @@ static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fnam ...@@ -39,6 +39,61 @@ static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fnam
fname); fname);
} }
static void my_coll_agg_error(DTCollation &c1,
DTCollation &c2,
DTCollation &c3,
const char *fname)
{
my_error(ER_CANT_AGGREGATE_3COLLATIONS,MYF(0),
c1.collation->name,c1.derivation_name(),
c2.collation->name,c2.derivation_name(),
c3.collation->name,c3.derivation_name(),
fname);
}
static void my_coll_agg_error(Item** args, uint ac, const char *fname)
{
if (2 == ac)
my_coll_agg_error(args[0]->collation, args[1]->collation, fname);
else if (3 == ac)
my_coll_agg_error(args[0]->collation,
args[1]->collation,
args[2]->collation,
fname);
else
my_error(ER_CANT_AGGREGATE_NCOLLATIONS,MYF(0),fname);
}
bool Item_func::agg_arg_collations(DTCollation &c, Item **av, uint ac)
{
uint i;
c.set(av[0]->collation);
for (i= 1; i < ac; i++)
{
if (c.aggregate(av[i]->collation))
{
my_coll_agg_error(av, ac, func_name());
return TRUE;
}
}
return FALSE;
}
bool Item_func::agg_arg_collations_for_comparison(DTCollation &c,
Item **av, uint ac)
{
if (agg_arg_collations(c, av, ac))
return TRUE;
if (c.derivation == DERIVATION_NONE)
{
my_coll_agg_error(av, ac, func_name());
return TRUE;
}
return FALSE;
}
/* return TRUE if item is a constant */ /* return TRUE if item is a constant */
bool bool
...@@ -866,14 +921,9 @@ void Item_func_min_max::fix_length_and_dec() ...@@ -866,14 +921,9 @@ void Item_func_min_max::fix_length_and_dec()
if (!args[i]->maybe_null) if (!args[i]->maybe_null)
maybe_null=0; maybe_null=0;
cmp_type=item_cmp_type(cmp_type,args[i]->result_type()); cmp_type=item_cmp_type(cmp_type,args[i]->result_type());
if (i==0)
collation.set(args[0]->collation);
if (collation.aggregate(args[i]->collation))
{
my_coll_agg_error(collation, args[i]->collation, func_name());
break;
}
} }
if (cmp_type == STRING_RESULT)
agg_arg_collations_for_comparison(collation, args, arg_count);
} }
...@@ -1048,8 +1098,7 @@ longlong Item_func_coercibility::val_int() ...@@ -1048,8 +1098,7 @@ longlong Item_func_coercibility::val_int()
void Item_func_locate::fix_length_and_dec() void Item_func_locate::fix_length_and_dec()
{ {
maybe_null=0; max_length=11; maybe_null=0; max_length=11;
if (cmp_collation.set(args[0]->collation, args[1]->collation)) agg_arg_collations_for_comparison(cmp_collation, args, 2);
my_coll_agg_error(args[0]->collation, args[1]->collation, func_name());
} }
longlong Item_func_locate::val_int() longlong Item_func_locate::val_int()
...@@ -1118,6 +1167,8 @@ longlong Item_func_locate::val_int() ...@@ -1118,6 +1167,8 @@ longlong Item_func_locate::val_int()
longlong Item_func_field::val_int() longlong Item_func_field::val_int()
{ {
if (cmp_type == STRING_RESULT)
{
String *field; String *field;
if (!(field=item->val_str(&value))) if (!(field=item->val_str(&value)))
return 0; // -1 if null ? return 0; // -1 if null ?
...@@ -1125,12 +1176,56 @@ longlong Item_func_field::val_int() ...@@ -1125,12 +1176,56 @@ longlong Item_func_field::val_int()
{ {
String *tmp_value=args[i]->val_str(&tmp); String *tmp_value=args[i]->val_str(&tmp);
if (tmp_value && field->length() == tmp_value->length() && if (tmp_value && field->length() == tmp_value->length() &&
!memcmp(field->ptr(),tmp_value->ptr(),tmp_value->length())) !sortcmp(field,tmp_value,cmp_collation.collation))
return (longlong) (i+1); return (longlong) (i+1);
} }
}
else if (cmp_type == INT_RESULT)
{
longlong val= item->val_int();
for (uint i=0; i < arg_count ; i++)
{
if (val == args[i]->val_int())
return (longlong) (i+1);
}
}
else
{
double val= item->val();
for (uint i=0; i < arg_count ; i++)
{
if (val == args[i]->val())
return (longlong) (i+1);
}
}
return 0; return 0;
} }
void Item_func_field::fix_length_and_dec()
{
maybe_null=0; max_length=3;
used_tables_cache|= item->used_tables();
const_item_cache&= item->const_item();
with_sum_func= with_sum_func || item->with_sum_func;
cmp_type= item->result_type();
for (uint i=0; i < arg_count ; i++)
cmp_type= item_cmp_type(cmp_type, args[i]->result_type());
if (cmp_type == STRING_RESULT)
{
cmp_collation.set(item->collation);
for (uint i=0 ; i < arg_count ; i++)
{
if (cmp_collation.aggregate(args[i]->collation))
{
my_error(ER_CANT_AGGREGATE_NCOLLATIONS,MYF(0),func_name());
return;
}
}
}
}
void Item_func_field::split_sum_func(Item **ref_pointer_array, void Item_func_field::split_sum_func(Item **ref_pointer_array,
List<Item> &fields) List<Item> &fields)
...@@ -1209,8 +1304,7 @@ void Item_func_find_in_set::fix_length_and_dec() ...@@ -1209,8 +1304,7 @@ void Item_func_find_in_set::fix_length_and_dec()
} }
} }
} }
if (cmp_collation.set(args[0]->collation, args[1]->collation)) agg_arg_collations_for_comparison(cmp_collation, args, 2);
my_coll_agg_error(args[0]->collation, args[1]->collation, func_name());
} }
static const char separator=','; static const char separator=',';
......
...@@ -135,6 +135,9 @@ class Item_func :public Item_result_field ...@@ -135,6 +135,9 @@ class Item_func :public Item_result_field
Field *tmp_table_field(TABLE *t_arg); Field *tmp_table_field(TABLE *t_arg);
void set_outer_resolving(); void set_outer_resolving();
Item *get_tmp_table_item(THD *thd); Item *get_tmp_table_item(THD *thd);
bool agg_arg_collations(DTCollation &c, Item **items, uint nitems);
bool agg_arg_collations_for_comparison(DTCollation &c, Item **items, uint nitems);
}; };
...@@ -624,6 +627,8 @@ class Item_func_field :public Item_int_func ...@@ -624,6 +627,8 @@ class Item_func_field :public Item_int_func
{ {
Item *item; Item *item;
String value,tmp; String value,tmp;
Item_result cmp_type;
DTCollation cmp_collation;
public: public:
Item_func_field(Item *a,List<Item> &list) :Item_int_func(list),item(a) {} Item_func_field(Item *a,List<Item> &list) :Item_int_func(list),item(a) {}
~Item_func_field() { delete item; } ~Item_func_field() { delete item; }
...@@ -641,13 +646,7 @@ class Item_func_field :public Item_int_func ...@@ -641,13 +646,7 @@ class Item_func_field :public Item_int_func
const_item_cache&= item->const_item(); const_item_cache&= item->const_item();
} }
const char *func_name() const { return "field"; } const char *func_name() const { return "field"; }
void fix_length_and_dec() void fix_length_and_dec();
{
maybe_null=0; max_length=3;
used_tables_cache|= item->used_tables();
const_item_cache&= item->const_item();
with_sum_func= with_sum_func || item->with_sum_func;
}
void set_outer_resolving() void set_outer_resolving()
{ {
item->set_outer_resolving(); item->set_outer_resolving();
......
...@@ -44,18 +44,6 @@ static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fnam ...@@ -44,18 +44,6 @@ static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fnam
fname); fname);
} }
static void my_coll_agg3_error(DTCollation &c1,
DTCollation &c2,
DTCollation &c3,
const char *fname)
{
my_error(ER_CANT_AGGREGATE_3COLLATIONS,MYF(0),
c1.collation->name,c1.derivation_name(),
c2.collation->name,c2.derivation_name(),
c3.collation->name,c3.derivation_name(),
fname);
}
uint nr_of_decimals(const char *str) uint nr_of_decimals(const char *str)
{ {
if ((str=strchr(str,'.'))) if ((str=strchr(str,'.')))
...@@ -336,16 +324,11 @@ void Item_func_concat::fix_length_and_dec() ...@@ -336,16 +324,11 @@ void Item_func_concat::fix_length_and_dec()
bool first_coll= 1; bool first_coll= 1;
max_length=0; max_length=0;
collation.set(args[0]->collation); if (agg_arg_collations(collation, args, arg_count))
return;
for (uint i=0 ; i < arg_count ; i++) for (uint i=0 ; i < arg_count ; i++)
{
max_length+=args[i]->max_length; max_length+=args[i]->max_length;
if (collation.aggregate(args[i]->collation))
{
my_coll_agg_error(collation, args[i]->collation, func_name());
break;
}
}
if (max_length > MAX_BLOB_WIDTH) if (max_length > MAX_BLOB_WIDTH)
{ {
...@@ -840,13 +823,8 @@ void Item_func_replace::fix_length_and_dec() ...@@ -840,13 +823,8 @@ void Item_func_replace::fix_length_and_dec()
maybe_null=1; maybe_null=1;
} }
collation.set(args[0]->collation); if (agg_arg_collations_for_comparison(collation, args, 3))
if (!collation.aggregate(args[1]->collation)) return;
collation.aggregate(args[2]->collation);
if (collation.derivation == DERIVATION_NONE)
my_coll_agg3_error(args[0]->collation, args[1]->collation,
args[2]->collation, func_name());
} }
...@@ -1050,9 +1028,9 @@ void Item_func_substr::fix_length_and_dec() ...@@ -1050,9 +1028,9 @@ void Item_func_substr::fix_length_and_dec()
void Item_func_substr_index::fix_length_and_dec() void Item_func_substr_index::fix_length_and_dec()
{ {
max_length= args[0]->max_length; max_length= args[0]->max_length;
if (collation.set(args[0]->collation, args[1]->collation) ||
(collation.derivation == DERIVATION_NONE)) if (agg_arg_collations_for_comparison(collation, args, 2))
my_coll_agg_error(args[0]->collation, args[1]->collation, func_name()); return;
} }
...@@ -1339,7 +1317,8 @@ void Item_func_trim::fix_length_and_dec() ...@@ -1339,7 +1317,8 @@ void Item_func_trim::fix_length_and_dec()
remove.set_ascii(" ",1); remove.set_ascii(" ",1);
} }
else else
if (collation.set(args[1]->collation, args[0]->collation)) if (collation.set(args[1]->collation, args[0]->collation) ||
collation.derivation == DERIVATION_NONE)
{ {
my_coll_agg_error(args[1]->collation, args[0]->collation, func_name()); my_coll_agg_error(args[1]->collation, args[0]->collation, func_name());
} }
...@@ -1680,20 +1659,13 @@ void Item_func_elt::fix_length_and_dec() ...@@ -1680,20 +1659,13 @@ void Item_func_elt::fix_length_and_dec()
max_length=0; max_length=0;
decimals=0; decimals=0;
if (agg_arg_collations(collation, args, arg_count))
return;
for (uint i=0 ; i < arg_count ; i++) for (uint i=0 ; i < arg_count ; i++)
{ {
set_if_bigger(max_length,args[i]->max_length); set_if_bigger(max_length,args[i]->max_length);
set_if_bigger(decimals,args[i]->decimals); set_if_bigger(decimals,args[i]->decimals);
if (i == 0)
collation.set(args[0]->collation);
else
{
if (collation.aggregate(args[i]->collation))
{
my_coll_agg_error(collation, args[i]->collation, func_name());
break;
}
}
} }
maybe_null=1; // NULL if wrong first arg maybe_null=1; // NULL if wrong first arg
with_sum_func= with_sum_func || item->with_sum_func; with_sum_func= with_sum_func || item->with_sum_func;
...@@ -1786,16 +1758,13 @@ void Item_func_make_set::split_sum_func(Item **ref_pointer_array, ...@@ -1786,16 +1758,13 @@ void Item_func_make_set::split_sum_func(Item **ref_pointer_array,
void Item_func_make_set::fix_length_and_dec() void Item_func_make_set::fix_length_and_dec()
{ {
max_length=arg_count-1; max_length=arg_count-1;
collation.set(args[0]->collation);
if (agg_arg_collations(collation, args, arg_count))
return;
for (uint i=0 ; i < arg_count ; i++) for (uint i=0 ; i < arg_count ; i++)
{
max_length+=args[i]->max_length; max_length+=args[i]->max_length;
if (collation.aggregate(args[i]->collation))
{
my_coll_agg_error(collation, args[i]->collation, func_name());
break;
}
}
used_tables_cache|=item->used_tables(); used_tables_cache|=item->used_tables();
const_item_cache&=item->const_item(); const_item_cache&=item->const_item();
with_sum_func= with_sum_func || item->with_sum_func; with_sum_func= with_sum_func || item->with_sum_func;
...@@ -2463,15 +2432,8 @@ void Item_func_export_set::fix_length_and_dec() ...@@ -2463,15 +2432,8 @@ void Item_func_export_set::fix_length_and_dec()
uint sep_length=(arg_count > 3 ? args[3]->max_length : 1); uint sep_length=(arg_count > 3 ? args[3]->max_length : 1);
max_length=length*64+sep_length*63; max_length=length*64+sep_length*63;
collation.set(args[1]->collation); if (agg_arg_collations(collation, args+1, min(4,arg_count)-1))
for (i=2 ; i < 4 && i < arg_count ; i++) return;
{
if (collation.aggregate(args[i]->collation))
{
my_coll_agg_error(collation, args[i]->collation, func_name());
break;
}
}
} }
String* Item_func_inet_ntoa::val_str(String* str) String* Item_func_inet_ntoa::val_str(String* str)
......
...@@ -2001,22 +2001,6 @@ static int init_common_variables(const char *conf_file_name, int argc, ...@@ -2001,22 +2001,6 @@ static int init_common_variables(const char *conf_file_name, int argc,
DBUG_PRINT("info",("%s Ver %s for %s on %s\n",my_progname, DBUG_PRINT("info",("%s Ver %s for %s on %s\n",my_progname,
server_version, SYSTEM_TYPE,MACHINE_TYPE)); server_version, SYSTEM_TYPE,MACHINE_TYPE));
#ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE
{
/* Retrieve used stack size; Needed for checking stack overflows */
size_t stack_size= 0;
pthread_attr_getstacksize(&connection_attrib, &stack_size);
/* We must check if stack_size = 0 as Solaris 2.9 can return 0 here */
if (stack_size && stack_size < thread_stack)
{
if (global_system_variables.log_warnings)
sql_print_error("Warning: Asked for %ld thread stack, but got %ld",
thread_stack, stack_size);
thread_stack= stack_size;
}
}
#endif
#if defined( SET_RLIMIT_NOFILE) || defined( OS2) #if defined( SET_RLIMIT_NOFILE) || defined( OS2)
/* connections and databases needs lots of files */ /* connections and databases needs lots of files */
{ {
...@@ -2366,6 +2350,21 @@ int main(int argc, char **argv) ...@@ -2366,6 +2350,21 @@ int main(int argc, char **argv)
if (!(opt_specialflag & SPECIAL_NO_PRIOR)) if (!(opt_specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),CONNECT_PRIOR); my_pthread_setprio(pthread_self(),CONNECT_PRIOR);
pthread_attr_setstacksize(&connection_attrib,thread_stack); pthread_attr_setstacksize(&connection_attrib,thread_stack);
#ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE
{
/* Retrieve used stack size; Needed for checking stack overflows */
size_t stack_size= 0;
pthread_attr_getstacksize(&connection_attrib, &stack_size);
/* We must check if stack_size = 0 as Solaris 2.9 can return 0 here */
if (stack_size && stack_size < thread_stack)
{
if (global_system_variables.log_warnings)
sql_print_error("Warning: Asked for %ld thread stack, but got %ld",
thread_stack, stack_size);
thread_stack= stack_size;
}
}
#endif
(void) thr_setconcurrency(concurrency); // 10 by default (void) thr_setconcurrency(concurrency); // 10 by default
select_thread=pthread_self(); select_thread=pthread_self();
......
...@@ -2637,7 +2637,7 @@ int QUICK_SELECT_DESC::get_next() ...@@ -2637,7 +2637,7 @@ int QUICK_SELECT_DESC::get_next()
else else
{ {
DBUG_ASSERT(range->flag & NEAR_MAX || range_reads_after_key(range)); DBUG_ASSERT(range->flag & NEAR_MAX || range_reads_after_key(range));
#ifdef NOT_IMPLEMENTED_YET #ifndef NOT_IMPLEMENTED_YET
result=file->index_read(record, (byte*) range->max_key, result=file->index_read(record, (byte*) range->max_key,
range->max_length, range->max_length,
((range->flag & NEAR_MAX) ? ((range->flag & NEAR_MAX) ?
......
...@@ -222,6 +222,8 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -222,6 +222,8 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
goto err; goto err;
} }
if (err == HA_ERR_RECORD_DELETED)
continue;
if (err) if (err)
{ {
if (err != HA_ERR_KEY_NOT_FOUND && err != HA_ERR_END_OF_FILE) if (err != HA_ERR_KEY_NOT_FOUND && err != HA_ERR_END_OF_FILE)
...@@ -233,15 +235,9 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -233,15 +235,9 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
} }
goto ok; goto ok;
} }
if (cond) if (cond && !cond->val_int())
{
err=err;
if (!cond->val_int())
continue; continue;
} if (!err && num_rows >= offset_limit)
if (num_rows >= offset_limit)
{
if (!err)
{ {
String *packet = &thd->packet; String *packet = &thd->packet;
Item *item; Item *item;
...@@ -258,7 +254,6 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -258,7 +254,6 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
} }
protocol->write(); protocol->write();
} }
}
num_rows++; num_rows++;
} }
ok: ok:
......
...@@ -659,10 +659,13 @@ static bool mysql_test_select_fields(PREP_STMT *stmt, TABLE_LIST *tables, ...@@ -659,10 +659,13 @@ static bool mysql_test_select_fields(PREP_STMT *stmt, TABLE_LIST *tables,
wild_num, conds, og_num, order, group, having, proc, wild_num, conds, og_num, order, group, having, proc,
select_lex, unit, 0)) select_lex, unit, 0))
DBUG_RETURN(1); DBUG_RETURN(1);
#ifndef EMBEDDED_LIBRARY
if (send_prep_stmt(stmt, fields.elements) || if (send_prep_stmt(stmt, fields.elements) ||
thd->protocol_simple.send_fields(&fields, 0) || thd->protocol_simple.send_fields(&fields, 0) ||
net_flush(&thd->net) ||
send_item_params(stmt)) send_item_params(stmt))
DBUG_RETURN(1); DBUG_RETURN(1);
#endif
join->cleanup(); join->cleanup();
} }
DBUG_RETURN(0); DBUG_RETURN(0);
......
...@@ -2032,9 +2032,7 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level, ...@@ -2032,9 +2032,7 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level,
break; break;
case Item_func::OPTIMIZE_KEY: case Item_func::OPTIMIZE_KEY:
if (cond_func->key_item()->real_item()->type() == Item::FIELD_ITEM && if (cond_func->key_item()->real_item()->type() == Item::FIELD_ITEM &&
// field from outer query can't be used as key !(cond_func->used_tables() & OUTER_REF_TABLE_BIT))
!((Item_field*) (cond_func->key_item()->real_item()))
->depended_from)
add_key_field(key_fields,*and_level, add_key_field(key_fields,*and_level,
((Item_field*) (cond_func->key_item()->real_item())) ((Item_field*) (cond_func->key_item()->real_item()))
->field, ->field,
...@@ -2046,9 +2044,7 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level, ...@@ -2046,9 +2044,7 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level,
cond_func->functype() == Item_func::EQUAL_FUNC); cond_func->functype() == Item_func::EQUAL_FUNC);
if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM && if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM &&
// field from outer query can't be used as key !(cond_func->arguments()[0]->used_tables() & OUTER_REF_TABLE_BIT))
!((Item_field*) (cond_func->arguments()[0]->real_item()))
->depended_from)
{ {
add_key_field(key_fields,*and_level, add_key_field(key_fields,*and_level,
((Item_field*) (cond_func->arguments()[0])->real_item()) ((Item_field*) (cond_func->arguments()[0])->real_item())
...@@ -2058,9 +2054,7 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level, ...@@ -2058,9 +2054,7 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level,
} }
if (cond_func->arguments()[1]->real_item()->type() == Item::FIELD_ITEM && if (cond_func->arguments()[1]->real_item()->type() == Item::FIELD_ITEM &&
cond_func->functype() != Item_func::LIKE_FUNC && cond_func->functype() != Item_func::LIKE_FUNC &&
// field from outer query can't be used as key !(cond_func->arguments()[1]->used_tables() & OUTER_REF_TABLE_BIT))
!((Item_field*) (cond_func->arguments()[1]->real_item()))
->depended_from)
{ {
add_key_field(key_fields,*and_level, add_key_field(key_fields,*and_level,
((Item_field*) (cond_func->arguments()[1])->real_item()) ((Item_field*) (cond_func->arguments()[1])->real_item())
...@@ -2073,9 +2067,7 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level, ...@@ -2073,9 +2067,7 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level,
case Item_func::OPTIMIZE_NULL: case Item_func::OPTIMIZE_NULL:
/* column_name IS [NOT] NULL */ /* column_name IS [NOT] NULL */
if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM && if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM &&
// field from outer query can't be used as key !(cond_func->used_tables() & OUTER_REF_TABLE_BIT))
!((Item_field*) (cond_func->arguments()[0]->real_item()))
->depended_from)
{ {
add_key_field(key_fields,*and_level, add_key_field(key_fields,*and_level,
((Item_field*) (cond_func->arguments()[0])->real_item()) ((Item_field*) (cond_func->arguments()[0])->real_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